From 726108b4d75db0492713815420eb51a63b063994 Mon Sep 17 00:00:00 2001 From: Jonatan Schlag Date: Tue, 30 May 2017 10:30:35 +0200 Subject: [PATCH] route: Fix check of network 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 --- src/functions/functions.route | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/functions/functions.route b/src/functions/functions.route index 1b097129..4c4f7f63 100644 --- a/src/functions/functions.route +++ b/src/functions/functions.route @@ -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" -- 2.47.2