Subject: dhclient-script needlessly deletes/re-adds addresses
To: None <tech-net@NetBSD.org>
From: David Young <dyoung@pobox.com>
List: tech-net
Date: 10/02/2005 17:13:00
--9amGYk9869ThD9tj
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Sun, Oct 02, 2005 at 05:25:57PM -0400, Thor Lancelot Simon wrote:
> On Mon, Oct 03, 2005 at 06:46:25AM +0930, Berndt Josef Wulf wrote:
> > This didn't fix. It's still loosing the connection. It appears to coincide
> > with the renewal of the IP address lease.
>
> This is a bug in both iwi *and* in dhclient, one which has been fixed in
> many other network interface drivers.
>
> Dhclient should not ifconfig the interface up and down -- or, in fact,
> touch it with ifconfig *at all* -- if the IP address remains the same
> on renewal of the DHCP lease.
Thor,
I don't think dhclient ever puts the interface down. Maybe I missed
something.
I have noticed that dhclient-script needlessly adds and removes interface
addresses, especially the "alias" address set by dhclient.conf, which
should IMO be added once and never removed. I have attached the patches
I apply to fix that problem, and others.
Dave
--
David Young OJC Technologies
dyoung@ojctech.com Urbana, IL * (217) 278-3933
--9amGYk9869ThD9tj
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=dhclient-script-patch
--- /u3/dyoung/radix-nbsd/src/usr.sbin/dhcp/clientscript/dhclient-script 2005-08-17 19:17:17.000000000 -0500
+++ extras/sbin/dhclient-script 2005-10-02 16:43:48.000000000 -0500
@@ -126,11 +126,22 @@
alias_subnet_arg="netmask $alias_subnet_mask"
fi
+#
+# Remove the 0/8 alias except on PREINIT->(any) transitions, since it
+# interferes with IPFilter's NAT.
+#
+case "$reason" in
+ARPCHECK|ARPSEND|PREINIT)
+ ;;
+*)
+ eval "ifconfig $interface inet -alias 0.0.0.0" >/dev/null 2>&1
+ ;;
+esac
+
case "$reason" in
MEDIUM)
test -z "$medium" && exit_with_hooks 0
eval "ifconfig $interface $medium"
- eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
sleep 1
@@ -139,12 +150,11 @@
PREINIT)
if [ ! -z "$alias_ip_address" ]; then
- ifconfig $interface inet \
- -alias $alias_ip_address >/dev/null 2>&1
- route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
+ ifconfig $interface inet alias $alias_ip_address \
+ >/dev/null 2>&1
fi
- ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
+ ifconfig $interface inet alias 0.0.0.0 netmask 0.0.0.0 \
broadcast 255.255.255.255 up
exit_with_hooks 0
@@ -162,7 +172,7 @@
fi
if type hostname > /dev/null 2>&1; then
- if [ \( -z "$current_hostname" \) -o \
+ if [ \( "x$current_hostname" = "x" \) -o \
\( "x$new_host_name" = "x$old_hostname" \) ]; then
current_hostname=`hostname`
fi
@@ -171,38 +181,26 @@
hostname $new_host_name
fi
fi
-
- if [ \( ! -z "$old_ip_address" \) -a \( ! -z "$alias_ip_address" \) -a \
- \( "x$alias_ip_address" != "x$old_ip_address" \) ]; then
- ifconfig $interface inet \
- -alias $alias_ip_address > /dev/null 2>&1
- route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
- fi
- if [ \( ! -z "$old_ip_address" \) -a \
- \( "x$old_ip_address" != "x$new_ip_address" \) ]; then
+ if [ \( "x$old_ip_address" != "x" \) -a \
+ \( "x$old_ip_address" != "x$new_ip_address" \) -a \
+ \( "x$old_ip_address" != "x$alias_ip_address" \) ]; then
eval "ifconfig $interface inet -alias $old_ip_address $medium"
route delete $old_ip_address 127.0.0.1 >/dev/null 2>&1
delete_old_routes
fi
- if [ \( -z "$old_ip_address" \) -o \
- \( "x$old_ip_address" != "x$new_ip_address" \) -o \
+ if [ \( \( "x$old_ip_address" != "x$new_ip_address" \) -a \
+ \( "x$alias_ip_address" != "x$new_ip_address" \) \) -o \
\( "x$reason" = "xBOUND" \) -o \( "x$reason" = "xREBOOT" \) ]; then
- eval "ifconfig $interface inet $new_ip_address \
+ eval "ifconfig $interface inet alias $new_ip_address \
$new_netmask_arg $new_broadcast_arg $medium"
route add $new_ip_address 127.0.0.1 >/dev/null 2>&1
add_new_routes
fi
- if [ \( ! -z "$alias_ip_address" \) -a \
- \( "x$new_ip_address" != "x$alias_ip_address" \) ]; then
- ifconfig $interface inet alias $alias_ip_address \
- $alias_subnet_arg
- route add $alias_ip_address 127.0.0.1
- fi
make_resolv_conf
exit_with_hooks 0
;;
@@ -215,34 +213,19 @@
fi
fi
- if [ ! -z "$alias_ip_address" ]; then
- ifconfig $interface inet -alias $alias_ip_address
- route delete $alias_ip_address 127.0.0.1
- fi > /dev/null 2>&1
-
- if [ ! -z "$old_ip_address" ]; then
+ if [ ! -z "$old_ip_address" -a \
+ \( "x$old_ip_address" != "x$alias_ip_address" \) ]; then
eval "ifconfig $interface inet -alias $old_ip_address $medium"
route delete $old_ip_address 127.0.0.1 >/dev/null 2>&1
delete_old_routes
fi
- if [ ! -z "$alias_ip_address" ]; then
- ifconfig $interface inet alias $alias_ip_address \
- $alias_subnet_arg
- route add $alias_ip_address 127.0.0.1
- fi
-
restore_resolv_conf
exit_with_hooks 0
;;
TIMEOUT)
- if [ ! -z "$alias_ip_address" ]; then
- ifconfig $interface inet -alias $alias_ip_address
- route delete $alias_ip_address 127.0.0.1
- fi > /dev/null 2>&1
-
if [ ! -z "$new_host_name" ]; then
if type hostname > /dev/null 2>&1; then
hostname $new_host_name
@@ -255,30 +238,36 @@
fi
fi
- eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
- $new_broadcast_arg $medium"
+ if [ \( -z "$alias_ip_address" \) -o \
+ \( "x$new_ip_address" != "x$alias_ip_address" \) ]
+ then
+ eval "ifconfig $interface inet alias $new_ip_address \
+ $new_netmask_arg $new_broadcast_arg $medium"
+ fi
+
sleep 1
if [ ! -z "$new_routers" ]; then
set -- $new_routers
if ping -n -q -c 1 -w 1 $1; then
- if [ \( ! -z "$alias_ip_address" \) -a \
+ if [ \( -z "$alias_ip_address" \) -o \
\( "x$new_ip_address" != "x$alias_ip_address" \) ]
then
- ifconfig $interface inet alias \
- $alias_ip_address $alias_subnet_arg
- route add $alias_ip_address 127.0.0.1
+ route add $new_ip_address 127.0.0.1 \
+ >/dev/null 2>&1
fi
- route add $new_ip_address 127.0.0.1 >/dev/null 2>&1
-
add_new_routes
make_resolv_conf
exit_with_hooks 0
fi
fi
- eval "ifconfig $interface inet -alias $new_ip_address $medium"
+ if [ \( -z "$alias_ip_address" \) -o \
+ \( "x$new_ip_address" != "x$alias_ip_address" \) ]
+ then
+ eval "ifconfig $interface inet -alias $new_ip_address $medium"
+ fi
delete_old_routes
--9amGYk9869ThD9tj--