summaryrefslogtreecommitdiff
path: root/src/validators
diff options
context:
space:
mode:
authorsarthurdev <965089+sarthurdev@users.noreply.github.com>2022-01-09 23:37:12 +0100
committersarthurdev <965089+sarthurdev@users.noreply.github.com>2022-01-10 21:18:03 +0100
commitda370b63b266254d9a7a7ae15274a9a70bcf5417 (patch)
treeb1e6cfd25e179db5d6421791e47f46f2f380b98f /src/validators
parenta5ad98b2307af974dd498a84caec94fa613f7491 (diff)
downloadvyos-1x-da370b63b266254d9a7a7ae15274a9a70bcf5417.tar.gz
vyos-1x-da370b63b266254d9a7a7ae15274a9a70bcf5417.zip
validators: T4148: Add text output when validators fail
Diffstat (limited to 'src/validators')
-rwxr-xr-xsrc/validators/ipv4-range13
-rwxr-xr-xsrc/validators/port-range2
2 files changed, 11 insertions, 4 deletions
diff --git a/src/validators/ipv4-range b/src/validators/ipv4-range
index cc59039f1..6492bfc52 100755
--- a/src/validators/ipv4-range
+++ b/src/validators/ipv4-range
@@ -7,6 +7,11 @@ ip2dec () {
printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
}
+error_exit() {
+ echo "Error: $1 is not a valid IPv4 address range"
+ exit 1
+}
+
# Only run this if there is a hypen present in $1
if [[ "$1" =~ "-" ]]; then
# This only works with real bash (<<<) - split IP addresses into array with
@@ -15,21 +20,21 @@ if [[ "$1" =~ "-" ]]; then
ipaddrcheck --is-ipv4-single ${strarr[0]}
if [ $? -gt 0 ]; then
- exit 1
+ error_exit $1
fi
ipaddrcheck --is-ipv4-single ${strarr[1]}
if [ $? -gt 0 ]; then
- exit 1
+ error_exit $1
fi
start=$(ip2dec ${strarr[0]})
stop=$(ip2dec ${strarr[1]})
if [ $start -ge $stop ]; then
- exit 1
+ error_exit $1
fi
exit 0
fi
-exit 1
+error_exit $1
diff --git a/src/validators/port-range b/src/validators/port-range
index abf0b09d5..6e68c8733 100755
--- a/src/validators/port-range
+++ b/src/validators/port-range
@@ -9,9 +9,11 @@ if __name__ == '__main__':
if re.search('[0-9]{1,5}-[0-9]{1,5}', port_range):
for tmp in port_range.split('-'):
if int(tmp) not in range(1, 65535):
+ print(f'Error: {port_range} is not a valid port range')
sys.exit(1)
else:
if int(port_range) not in range(1, 65535):
+ print(f'Error: {port_range} is not a valid port')
sys.exit(1)
else:
sys.exit(2)