fix(striker-ui): fail gateway check when duplicate IP

main
Tsu-ba-me 2 years ago
parent 1bc475b915
commit 5c0f06be00
  1. 69
      striker-ui/components/NetworkInitForm.tsx

@ -630,22 +630,17 @@ const NetworkInitForm = forwardRef<
fn = 'every',
ip = '',
mask = '',
negateMatch = fn === 'every',
isNegateMatch = fn === 'every',
onMatch,
onMiss,
skipUUID,
}: {
fn?: Extract<keyof Array<NetworkInput>, 'every' | 'some'>;
ip?: string;
isNegateMatch?: boolean;
mask?: string;
negateMatch?: boolean;
onMatch?: (
otherInput: Pick<
NetworkInput,
'inputUUID' | 'name' | 'type' | 'typeCount'
>,
) => void;
onMiss?: (otherInput: Pick<NetworkInput, 'inputUUID'>) => void;
onMatch?: (otherInput: NetworkInput) => void;
onMiss?: (otherInput: NetworkInput) => void;
skipUUID?: string;
}) => {
const skipReturn = fn === 'every';
@ -661,15 +656,10 @@ const NetworkInitForm = forwardRef<
// eslint-disable-next-line no-empty
} catch (netmaskError) {}
return networkInputs[fn](
({
inputUUID,
ipAddressInputRef,
name,
subnetMaskInputRef,
type,
typeCount,
}) => {
return networkInputs[fn]((networkInput) => {
const { inputUUID, ipAddressInputRef, subnetMaskInputRef } =
networkInput;
if (inputUUID === skipUUID) {
return skipReturn;
}
@ -688,14 +678,13 @@ const NetworkInitForm = forwardRef<
} catch (netmaskError) {}
if (isMatch) {
onMatch?.call(null, { inputUUID, name, type, typeCount });
onMatch?.call(null, networkInput);
} else {
onMiss?.call(null, { inputUUID });
onMiss?.call(null, networkInput);
}
return negateMatch ? !isMatch : isMatch;
},
);
return isNegateMatch ? !isMatch : isMatch;
});
},
[networkInputs],
);
@ -739,19 +728,35 @@ const NetworkInitForm = forwardRef<
test: ({ value }) => REP_IPV4.test(value as string),
},
{
onFailure: () => {
setGatewayInputMessage({
children: "Gateway must be in one network's subnet.",
});
},
test: ({ value }) =>
subnetContains({
test: ({ value }) => {
let isDistinctIP = true;
const isIPInOneNetwork = subnetContains({
fn: 'some',
ip: value as string,
onMatch: ({ type, typeCount }) => {
onMatch: ({ ipAddress, name, type, typeCount }) => {
if (value === ipAddress) {
isDistinctIP = false;
setGatewayInputMessage({
children: `Gateway cannot be the same as IP address in ${name}.`,
});
return;
}
setGatewayInterface(`${type}${typeCount}`);
},
}),
});
if (!isIPInOneNetwork) {
setGatewayInputMessage({
children: "Gateway must be in one network's subnet.",
});
}
return isIPInOneNetwork && isDistinctIP;
},
},
{ test: testNotBlank },
],

Loading…
Cancel
Save