summaryrefslogtreecommitdiff
path: root/src/validators/ipv4-range
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2024-09-27 16:51:50 +0100
committerDaniil Baturin <daniil@baturin.org>2024-09-27 16:51:50 +0100
commit0b7a2a052d0f07c448b371d35863e0f8a324675e (patch)
tree8e3b272a0d15f30d33e541282c9ce936ffa35cd6 /src/validators/ipv4-range
parent5af1c8c73e1d37ac5fcc24ed60c3cef27bf4feb2 (diff)
downloadvyos-1x-0b7a2a052d0f07c448b371d35863e0f8a324675e.tar.gz
vyos-1x-0b7a2a052d0f07c448b371d35863e0f8a324675e.zip
validators: T6743: use native ipaddrcheck validator options for ranges
Diffstat (limited to 'src/validators/ipv4-range')
-rwxr-xr-xsrc/validators/ipv4-range42
1 files changed, 6 insertions, 36 deletions
diff --git a/src/validators/ipv4-range b/src/validators/ipv4-range
index 6492bfc52..7bf271bbb 100755
--- a/src/validators/ipv4-range
+++ b/src/validators/ipv4-range
@@ -1,40 +1,10 @@
-#!/bin/bash
+#!/bin/sh
-# snippet from https://stackoverflow.com/questions/10768160/ip-address-converter
-ip2dec () {
- local a b c d ip=$@
- IFS=. read -r a b c d <<< "$ip"
- printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
-}
+ipaddrcheck --verbose --is-ipv4-range "$1"
-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
- # hyphen as delimiter
- readarray -d - -t strarr <<< $1
-
- ipaddrcheck --is-ipv4-single ${strarr[0]}
- if [ $? -gt 0 ]; then
- error_exit $1
- fi
-
- ipaddrcheck --is-ipv4-single ${strarr[1]}
- if [ $? -gt 0 ]; then
- error_exit $1
- fi
-
- start=$(ip2dec ${strarr[0]})
- stop=$(ip2dec ${strarr[1]})
- if [ $start -ge $stop ]; then
- error_exit $1
- fi
-
- exit 0
+if [ $? -gt 0 ]; then
+ echo "Error: $1 is not a valid IPv4 address range"
+ exit 1
fi
-error_exit $1
+exit 0