summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient/dhclient-script
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2007-02-09 17:50:26 +0000
committeremaste <emaste@FreeBSD.org>2007-02-09 17:50:26 +0000
commit4d18a6391e0641145ae2bba5e54e5bf9e763eb57 (patch)
tree5a719d3797670e80a657e26189df5834f2199ca2 /sbin/dhclient/dhclient-script
parent73c99587923d911647ba0ffc401352f2a4e22219 (diff)
downloadFreeBSD-src-4d18a6391e0641145ae2bba5e54e5bf9e763eb57.zip
FreeBSD-src-4d18a6391e0641145ae2bba5e54e5bf9e763eb57.tar.gz
Implement RFC3442, the Classless Static Route option.
The original DHCP specification includes a route option but it supports only class-based routes. RFC3442 adds support for specifying the netmask width for each static route. A variable length encoding is used to minimize the size of this option. PR: bin/99534 Submitted by: Andrey V. Elsukov <bu7cher@yandex.ru> Reviewed by: brooks
Diffstat (limited to 'sbin/dhclient/dhclient-script')
-rw-r--r--sbin/dhclient/dhclient-script60
1 files changed, 60 insertions, 0 deletions
diff --git a/sbin/dhclient/dhclient-script b/sbin/dhclient/dhclient-script
index ced527d..899cb6d 100644
--- a/sbin/dhclient/dhclient-script
+++ b/sbin/dhclient/dhclient-script
@@ -86,8 +86,43 @@ add_new_alias() {
fi
}
+fill_classless_routes() {
+ set $1
+ while [ $# -gt 5 ]; do
+ if [ $1 -eq 0 ]; then
+ route="default"
+ elif [ $1 -le 8 ]; then
+ route="$2.0.0.0/$1"
+ shift
+ elif [ $1 -le 16 ]; then
+ route="$2.$3.0.0/$1"
+ shift; shift
+ elif [ $1 -le 24 ]; then
+ route="$2.$3.$4.0/$1"
+ shift; shift; shift
+ else
+ route="$2.$3.$4.$5/$1"
+ shift; shift; shift; shift
+ fi
+ shift
+ router="$1.$2.$3.$4"
+ classless_routes="$classless_routes $route $router"
+ shift; shift; shift; shift
+ done
+}
+
delete_old_routes() {
#route delete "$old_ip_address" $LOCALHOST >/dev/null 2>&1
+ if [ -n "$old_classless_routes" ]; then
+ fill_classless_routes "$old_classless_routes"
+ set $classless_routes
+ while [ $# -gt 1 ]; do
+ route delete "$1" "$2"
+ shift; shift
+ done
+ return 0;
+ fi
+
for router in $old_routers; do
if [ $if_defaultroute = x -o $if_defaultroute = $interface ]; then
route delete default $route >/dev/null 2>&1
@@ -107,6 +142,31 @@ delete_old_routes() {
add_new_routes() {
#route add $new_ip_address $LOCALHOST >/dev/null 2>&1
+
+ # RFC 3442: If the DHCP server returns both a Classless Static
+ # Routes option and a Router option, the DHCP client MUST ignore
+ # the Router option.
+ #
+ # DHCP clients that support this option (Classless Static Routes)
+ # MUST NOT install the routes specified in the Static Routes
+ # option (option code 33) if both a Static Routes option and the
+ # Classless Static Routes option are provided.
+
+ if [ -n "$new_classless_routes" ]; then
+ fill_classless_routes "$new_classless_routes"
+ $LOGGER "New Classless Static Routes ($interface): $classless_routes"
+ set $classless_routes
+ while [ $# -gt 1 ]; do
+ if [ "0.0.0.0" = "$2" ]; then
+ route add "$1" -iface "$interface"
+ else
+ route add "$1" "$2"
+ fi
+ shift; shift
+ done
+ return
+ fi
+
for router in $new_routers; do
if [ "$new_ip_address" = "$router" ]; then
route add default -iface $router >/dev/null 2>&1
OpenPOWER on IntegriCloud