]> git.ipfire.org Git - people/ms/network.git/commitdiff
ip: restructure ip_net_is_valid
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sat, 3 Jun 2017 11:25:08 +0000 (13:25 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Jun 2017 16:32:17 +0000 (18:32 +0200)
Insted of checking the network manually we now just calö ipv4_net_is_valid or
ipv6_net_is_valid

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ip

index ec108ac9000624852bc112c34cef4ab0a6cdd411..5a82114119d774dfc40f8838d52becd1b1d3d249 100644 (file)
@@ -83,23 +83,14 @@ ip_net_is_valid() {
        local network=${1}
        assert isset network
 
-       # Get the address part.
-       local address=$(ip_split_prefix ${network})
-       isset address || return ${EXIT_FALSE}
-
-       # Get the prefix.
-       local prefix=$(ip_get_prefix ${network})
-       isset prefix || return ${EXIT_FALSE}
-
-       # Detect the protocol (if this fails, the
-       # address part is invalid)
-       local proto=$(ip_detect_protocol ${address})
-       isset proto || return ${EXIT_FALSE}
-
-       # Check if the prefix is correct.
-       ip_prefix_is_valid ${proto} ${prefix} || return ${EXIT_FALSE}
+       local protocol
+       for protocol in ${IP_SUPPORTED_PROTOCOLS}; do
+               if ${protocol}_net_is_valid "${network}"; then
+                       return ${EXIT_TRUE}
+               fi
+       done
 
-       return ${EXIT_TRUE}
+       return ${EXIT_FALSE}
 }
 
 ip_prefix_is_valid() {