commit:     8a92e2a697c2f250e39917442a365f8e666da3fb
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 24 22:25:08 2016 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Mon Oct 24 22:25:08 2016 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=8a92e2a6

sh/udhcpc-hook.sh: classless static routes

Support RFC3442 (DHCP classless static routes).

Thanks to Jack Suter <gentoo-bugs <AT> suter.io>.

X-Gentoo-Bug: 524156
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524156
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 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

Reply via email to