summaryrefslogtreecommitdiff
path: root/src/validators/ipv4-range
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-01-10 22:31:55 +0100
committerGitHub <noreply@github.com>2022-01-10 22:31:55 +0100
commit465939d9c9b413c7033c8833cbb4ebc30b9bcf66 (patch)
tree361079ff54ed2c5516cc86a8644e98ce629d2a73 /src/validators/ipv4-range
parentfd1b1ff19b0ff852d796e979ab3b596651686f2f (diff)
parent0a0e7d789e7e482b65cbca47bff1dcb427891a88 (diff)
downloadvyos-1x-465939d9c9b413c7033c8833cbb4ebc30b9bcf66.tar.gz
vyos-1x-465939d9c9b413c7033c8833cbb4ebc30b9bcf66.zip
Merge pull request #1152 from sarthurdev/firewall_validators
firewall: validators: T4148: Improve validators and firewall validator usage
Diffstat (limited to 'src/validators/ipv4-range')
-rwxr-xr-xsrc/validators/ipv4-range13
1 files changed, 9 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