diff --git a/net/iproute2.sh b/net/iproute2.sh index 7dea195..a68203c 100644 --- a/net/iproute2.sh +++ b/net/iproute2.sh @@ -204,6 +204,14 @@ _add_address() return $rc } +_nodev_route_type() +{ + case "$1" in + throw|unreachable|prohibit|blackhole) return 0 ;; + *) return 1 ;; + esac +} + _add_route() { local family= @@ -219,7 +227,11 @@ _add_route() shift fi - if [ $# -eq 3 ]; then + local nodev=false + + if _nodev_route_type "$2"; then + nodev=true + elif [ $# -eq 3 ]; then set -- "$1" "$2" via "$3" elif [ "$3" = "gw" ]; then local one=$1 two=$2 @@ -233,6 +245,7 @@ _add_route() metric) metric=$2 ; cmd="${cmd} metric $2" ; shift ; have_metric=true ;; netmask) x="/$(_netmask2cidr "$2")" ; cmd="${cmd}${x}" ; cmd_nometric="${cmd}${x}" ; shift;; -host|-net);; + throw|unreachable|prohibit|blackhole) cmd="${cmd} ${1}" ;; *) cmd="${cmd} ${1}" ; cmd_nometric="${cmd_nometric} ${1}" ;; esac shift @@ -247,13 +260,21 @@ _add_route() fi # Check for route already existing: - ip ${family} route show ${cmd_nometric} dev "${IFACE}" 2>/dev/null | \ + ip ${family} route show ${cmd_nometric} 2>/dev/null | \ fgrep -sq "${cmd%% *}" route_already_exists=$? - veinfo ip ${family} route append ${cmd} dev "${IFACE}" - ip ${family} route append ${cmd} dev "${IFACE}" - rc=$? + # Some routes are incompatible with dev option + if yesno "${nodev}"; then + veinfo ip ${family} route append ${cmd} + ip ${family} route append ${cmd} + rc=$? + else + veinfo ip ${family} route append ${cmd} dev "${IFACE}" + ip ${family} route append ${cmd} dev "${IFACE}" + rc=$? + fi + # Check return code in some cases if [ $rc -ne 0 ]; then # If the route already exists, our default behavior is to WARN but continue. @@ -268,7 +289,7 @@ _add_route() *) msgfunc=eerror rc=1 ; eerror "Unknown error behavior: $eh_behavior" ;; esac eval $msgfunc "Route '$cmd_nometric' already existed:" - eval $msgfunc \"$(ip $family route show ${cmd_nometric} dev "${IFACE}" 2>&1)\" + eval $msgfunc \"$(ip $family route show ${cmd_nometric} 2>&1)\" else : # TODO: Handle other errors fi