aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2016-10-24 15:25:08 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2016-10-24 15:25:08 -0700
commit8a92e2a697c2f250e39917442a365f8e666da3fb (patch)
tree4d71265e59bdd398d674b741a03f4e398906e97a
parentdoc: resolvconf-gentoo is now openresolv. (diff)
downloadnetifrc-8a92e2a697c2f250e39917442a365f8e666da3fb.tar.gz
netifrc-8a92e2a697c2f250e39917442a365f8e666da3fb.tar.bz2
netifrc-8a92e2a697c2f250e39917442a365f8e666da3fb.zip
sh/udhcpc-hook.sh: classless static routes
Support RFC3442 (DHCP classless static routes). Thanks to Jack Suter <gentoo-bugs@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@gentoo.org>
-rw-r--r--sh/udhcpc-hook.sh.in26
1 files changed, 25 insertions, 1 deletions
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