diff options
author | brooks <brooks@FreeBSD.org> | 2008-03-30 02:42:39 +0000 |
---|---|---|
committer | brooks <brooks@FreeBSD.org> | 2008-03-30 02:42:39 +0000 |
commit | 59722cbdc947c8f9ff1c315e66664b47f105d5d0 (patch) | |
tree | fa0588cbdb302ac140dfca856cbea44a620fdc20 | |
parent | 3847b38de2eb8d014cd365c681e58bd563b90819 (diff) | |
download | FreeBSD-src-59722cbdc947c8f9ff1c315e66664b47f105d5d0.zip FreeBSD-src-59722cbdc947c8f9ff1c315e66664b47f105d5d0.tar.gz |
Add a new function is_default_interface() which determines if this
interface is one with the default route (or there isn't one). Use it to
decide if we should adjust the default route and /etc/resolv.conf.
Fix the delete of the default route. The if statement was totally bogus
and the delete only worked due to a typo. [1]
Reported by: Jordan Coleman <jordan at JordanColeman dot com> [1]
MFC after: 1 week
-rw-r--r-- | sbin/dhclient/dhclient-script | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/sbin/dhclient/dhclient-script b/sbin/dhclient/dhclient-script index 1954e84..f6da4f6 100644 --- a/sbin/dhclient/dhclient-script +++ b/sbin/dhclient/dhclient-script @@ -20,10 +20,8 @@ # ARP=/usr/sbin/arp -AWK=/usr/bin/awk HOSTNAME=/bin/hostname IFCONFIG='/sbin/ifconfig -n' -NETSTAT=/usr/bin/netstat LOCALHOST=127.0.0.1 @@ -124,11 +122,12 @@ delete_old_routes() { 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 - fi - done + # If we supported multiple default routes, we'd be removing each + # one here. We don't so just delete the default route if it's + # through our interface. + if is_default_interface; then + route delete default >/dev/null 2>&1 + fi if [ -n "$old_static_routes" ]; then set $old_static_routes @@ -169,10 +168,13 @@ add_new_routes() { fi for router in $new_routers; do - if [ "$new_ip_address" = "$router" ]; then - route add default -iface $router >/dev/null 2>&1 - else - route add default $router >/dev/null 2>&1 + if is_default_interface; then + + if [ "$new_ip_address" = "$router" ]; then + route add default -iface $router >/dev/null 2>&1 + else + route add default $router >/dev/null 2>&1 + fi fi # 2nd and subsequent default routers error out, so explicitly # stop processing the list after the first one. @@ -254,6 +256,31 @@ exit_with_hooks() { exit $exit_status } +# Get the interface with the current ipv4 default route on it using only +# commands that are available prior to /usr being mounted. +is_default_interface() +{ + routeget="`route get -inet default`" + oldifs="$IFS" + IFS=" +" + defif= + for line in $routeget ; do + case $line in + *interface:*) + defif=${line##*: } + ;; + esac + done + IFS=${oldifs} + + if [ -z "$defif" -o "$defif" = "$interface" ]; then + return 0 + else + return 1 + fi +} + # # Start of active code. # @@ -269,12 +296,6 @@ if [ -f /etc/dhclient-enter-hooks ]; then fi fi -if [ -x $NETSTAT ]; then - if_defaultroute=`$NETSTAT -rnf inet | $AWK '{if ($1=="default") printf $6}'` -else - if_defaultroute="x" -fi - case $reason in MEDIUM) eval "$IFCONFIG $interface $medium" @@ -311,7 +332,9 @@ BOUND|RENEW|REBIND|REBOOT) if [ "$new_ip_address" != "$alias_ip_address" ]; then add_new_alias fi - add_new_resolv_conf + if is_default_interface; then + add_new_resolv_conf + fi ;; EXPIRE|FAIL) @@ -325,8 +348,10 @@ EXPIRE|FAIL) fi # XXX Why add alias we just deleted above? add_new_alias - if [ -f /etc/resolv.conf.save ]; then - cat /etc/resolv.conf.save > /etc/resolv.conf + if is_default_interface; then + if [ -f /etc/resolv.conf.save ]; then + cat /etc/resolv.conf.save > /etc/resolv.conf + fi fi ;; @@ -342,6 +367,9 @@ TIMEOUT) add_new_alias fi add_new_routes + if ! is_default_interface; then + exit_with_hooks 0 + fi if add_new_resolv_conf; then exit_with_hooks 0 fi |