From 8a92e2a697c2f250e39917442a365f8e666da3fb Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 24 Oct 2016 15:25:08 -0700 Subject: sh/udhcpc-hook.sh: classless static routes Support RFC3442 (DHCP classless static routes). Thanks to Jack Suter . X-Gentoo-Bug: 524156 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524156 Signed-off-by: Robin H. Johnson --- sh/udhcpc-hook.sh.in | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sh/udhcpc-hook.sh.in b/sh/udhcpc-hook.sh.in index 0744a04..c756061 100644 --- a/sh/udhcpc-hook.sh.in +++ b/sh/udhcpc-hook.sh.in @@ -61,11 +61,35 @@ update_interface() ifconfig "${interface}" ${ip} ${broadcast} ${netmask} ${mtu} } +update_classless_routes() +{ + if [ -n "${staticroutes}" ] ; then + max_routes=128 + metric= + [ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}" + while [ -n "$1" -a -n "$2" -a $max_routes -gt 0 ]; do + gw_arg= + if [ "$2" != '0.0.0.0' ]; then + gw_arg="gw $2" + fi + + [ ${1##*/} -eq 32 ] && type=host || type=net + route add -$type "$1" ${gw_arg} ${metric} dev "${interface}" + max=$(($max-1)) + shift 2 + done + fi +} update_routes() { peer_var "${PEER_ROUTERS}" && return - if [ -n "${router}" ] ; then + # RFC 3442 + [ -n "${staticroutes}" ] && update_classless_routes $staticroutes + + # If the DHCP server returns both a Classless Static Routes option and + # a Router option, the DHCP client MUST ignore the Router option. + if [ -n "${router}" -a -z "${staticroutes}" ] ; then metric= [ -n "${IF_METRIC}" ] && metric="metric ${IF_METRIC}" for i in ${router} ; do -- cgit v1.2.3-65-gdbad