]> git.ipfire.org Git - network.git/commitdiff
route: Fix check of network
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Tue, 30 May 2017 08:30:35 +0000 (10:30 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Tue, 30 May 2017 08:30:35 +0000 (10:30 +0200)
We can use a single IP address or a network as "network",
so we need tho check if it is a valid IP address or a valid network.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
src/functions/functions.route

index 1b097129e8dc072fb4b24b3081d967e318009010..4c4f7f6347de204c4795761be31d10ccff9a7dde 100644 (file)
@@ -58,7 +58,7 @@ route_add() {
 
        assert isset network
 
-       if ! ip_is_valid ${network}; then
+       if ! ip_is_network ${network} && ! ip_is_valid ${network}; then
                error "The given network is invalid: ${network}"
                return ${EXIT_ERROR}
        fi
@@ -279,8 +279,11 @@ route_parse_line() {
        # network must be set.
        isset network || return ${EXIT_ERROR}
 
-       # network must be a valid.
-       ip_is_network ${network} || return ${EXIT_ERROR}
+       # Is network or IP valid?
+       if ! ip_is_network ${network} && ! ip_is_valid ${network}; then
+               error "The given network is invalid: ${network}"
+               return ${EXIT_ERROR}
+       fi
 
        # Check gateway settings.
        if isset gateway; then
@@ -381,13 +384,21 @@ route_entry_add() {
 
        # Validate input.
        assert isoneof type unicast broadcast unreachable prohibit blackhole
-       assert ip_is_network ${network}
+
+       assert isset network
+
+       if ! ip_is_network ${network} && ! ip_is_valid ${network}; then
+               error "The given network is invalid: ${network}"
+               return ${EXIT_ERROR}
+       fi
+
        if isset mtu; then
                assert isinteger mtu
        fi
 
        # Detect the protocol of the given network.
        local protocol=$(ip_detect_protocol ${network})
+
        case "${protocol}" in
                ipv6)
                        command="ip -6 route add"