summaryrefslogtreecommitdiff
path: root/src/validators/ipv4-range
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-05-12 19:23:15 +0200
committerChristian Poessinger <christian@poessinger.com>2020-05-16 15:30:26 +0200
commit1330898ed095b42b6aba7ba00f9a6932b241a230 (patch)
treecd4e524fd1d91ded256f918007c97184be537fbd /src/validators/ipv4-range
parent728e1c6073cb216d3cb8b66f519bd590458165e6 (diff)
downloadvyos-1x-1330898ed095b42b6aba7ba00f9a6932b241a230.tar.gz
vyos-1x-1330898ed095b42b6aba7ba00f9a6932b241a230.zip
nat: T2198: add ipv4-{address,prefix,rage}-exclude validators
Exclude validators are required to support the ! (not) operator on the CLI to exclude addresses from NAT.
Diffstat (limited to 'src/validators/ipv4-range')
-rwxr-xr-xsrc/validators/ipv4-range33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/validators/ipv4-range b/src/validators/ipv4-range
index 0d707d6c5..ae3f3f163 100755
--- a/src/validators/ipv4-range
+++ b/src/validators/ipv4-range
@@ -7,24 +7,27 @@ ip2dec () {
printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
}
-# This only works with real bash (<<<) - split IP addresses into array with
-# hyphen as delimiter
-readarray -d - -t strarr <<< $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
+ # hyphen as delimiter
+ readarray -d - -t strarr <<< $1
-ipaddrcheck --is-ipv4-single ${strarr[0]}
-if [ $? -gt 0 ]; then
- exit 1
-fi
+ ipaddrcheck --is-ipv4-single ${strarr[0]}
+ if [ $? -gt 0 ]; then
+ exit 1
+ fi
-ipaddrcheck --is-ipv4-single ${strarr[1]}
-if [ $? -gt 0 ]; then
- exit 1
-fi
+ ipaddrcheck --is-ipv4-single ${strarr[1]}
+ if [ $? -gt 0 ]; then
+ exit 1
+ fi
-start=$(ip2dec ${strarr[0]})
-stop=$(ip2dec ${strarr[1]})
-if [ $start -ge $stop ]; then
- exit 1
+ start=$(ip2dec ${strarr[0]})
+ stop=$(ip2dec ${strarr[1]})
+ if [ $start -ge $stop ]; then
+ exit 1
+ fi
fi
exit 0