]> git.ipfire.org Git - people/stevee/network.git/blobdiff - functions.ipv4
ipv[46]-static: Sum up some functions.
[people/stevee/network.git] / functions.ipv4
index a29fc3978bbad0b258fdefa78c365f98fe5b7da4..633c5eb4cb1e503e84a8af3e6334c5a38efebbfc 100644 (file)
 
 IP_SUPPORTED_PROTOCOLS="${IP_SUPPORTED_PROTOCOLS} ipv4"
 
-function ipv4_split_prefix() {
-       ip_split_prefix $@
-}
-
 function ipv4_is_valid() {
        local address=${1}
 
        assert isset address
 
-       # Cut the /24 if there is one given
-       address=$(ipv4_split_prefix ${address})
+       # Cut the prefix if there is one given
+       local prefix=$(ip_get_prefix ${address})
+       address=$(ip_split_prefix ${address})
+
+       # If address is larger than 15 characters it cannot be an IPv4 address
+       [ ${#address} -gt 15 ] && return ${EXIT_ERROR}
+
+       # Check for a valid IPv4 prefix if provided
+       if [ -n "${prefix}" ]; then
+               if [ ${prefix} -lt 4 ] || [ ${prefix} -gt 30 ]; then
+                       return ${EXIT_ERROR}
+               fi
+       fi
 
        local IFS="."
        local octet