Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Dec 2004 23:38:26 GMT
From:      Sam Leffler <sam@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 66286 for review
Message-ID:  <200412022338.iB2NcQ7p014643@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=66286

Change 66286 by sam@sam_ebb on 2004/12/02 23:37:30

	o more cleanups to be compatible with old script
	o define common stuff with shell variables
	o announce settings per old script

Affected files ...

.. //depot/projects/wifi/sbin/dhclient/dhclient-script#5 edit

Differences ...

==== //depot/projects/wifi/sbin/dhclient/dhclient-script#5 (text+ko) ====

@@ -21,6 +21,9 @@
 NETSTAT=/usr/bin/netstat
 GREP=/usr/bin/grep
 AWK=/usr/bin/awk
+HOSTNAME=/bin/hostname
+
+LOCALHOST=127.0.0.1
 
 if [ -x /usr/bin/logger ]; then
 	LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
@@ -35,20 +38,23 @@
 check_hostname() {
 	current_hostname=`$HOSTNAME`
 	if [ -z "$current_hostname" ]; then
-		$LOGGER "New Hostname: $new_host_name"
+		$LOGGER "New Hostname ($interface): $new_host_name"
 		$HOSTNAME $new_host_name
 	elif [ "$current_hostname" = "$old_host_name" -a \
 	       "$new_host_name" != "$old_host_name" ]; then
-		$LOGGER "New Hostname: $new_host_name"
+		$LOGGER "New Hostname ($interface): $new_host_name"
 		$HOSTNAME $new_host_name
 	fi
 }
 
+arp_flush() {
+	arp -an -i $interface | \
+		sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' | \
+		sh >/dev/null 2>&1
+}
+
 delete_old_address() {
-	if [ -n "$old_ip_address" ]; then
-		ifconfig $interface inet -alias $old_ip_address $medium
-		route delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1
-	fi
+	ifconfig $interface inet -alias $old_ip_address $medium
 }
 
 add_new_address() {
@@ -58,14 +64,16 @@
 		broadcast $new_broadcast_address \
 		$medium
 
-	# XXX Original TIMEOUT code did not do this unless $new_routers was set?
-	route add $new_ip_address 127.0.0.1 >/dev/null 2>&1
+	$LOGGER "New IP Address ($interface): $new_ip_address"
+	$LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
+	$LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
+	$LOGGER "New Routers ($interface): $new_routers"
 }
 
 delete_old_alias() {
 	if [ -n "$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
+		route delete $alias_ip_address $LOCALHOST > /dev/null 2>&1
 	fi
 }
 
@@ -73,11 +81,12 @@
 	if [ -n "$alias_ip_address" ]; then
 		ifconfig $interface inet alias $alias_ip_address netmask \
 		    $alias_subnet_mask
-		route add $alias_ip_address 127.0.0.1
+		route add $alias_ip_address $LOCALHOST
 	fi
 }
 
 delete_old_routes() {
+	route delete "$old_ip_address" $LOCALHOST >/dev/null 2>&1
 	for router in $old_routers; do
 		if [ $if_defaultroute = x -o $if_defaultroute = $interface ]; then
 			route delete default $route >/dev/null 2>&1
@@ -92,12 +101,11 @@
 		done
 	fi
 
-	arp -an -i $interface | \
-		sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' | \
-		sh >/dev/null 2>&1
+	arp_flush
 }
 
 add_new_routes() {
+	route add $new_ip_address $LOCALHOST >/dev/null 2>&1
 	for router in $new_routers; do
 		if [ "$new_ip_address" = "$router" ]; then
 			route add default -iface $router >/dev/null 2>&1
@@ -110,6 +118,7 @@
 	done
 
 	if [ -n "$new_static_routes" ]; then
+		$LOGGER "New Static Routes ($interface): $new_static_routes"
 		set $new_static_routes
 		while [ $# -gt 1 ]; do
 			route add $1 $2
@@ -166,14 +175,6 @@
 # Start of active code.
 #
 
-if [ -n "$new_network_number" ]; then
-	$LOGGER "New Network Number: $new_network_number"
-fi
-
-if [ -n "$new_broadcast_address" ]; then
-	$LOGGER "New Broadcast Address: $new_broadcast_address"
-fi
-
 if [ -x $NETSTAT ]; then
 	if_defaulroute=`$NETSTAT -rn | $GREP "^default" | $AWK '{print $6}'`
 else
@@ -237,6 +238,7 @@
 	add_new_address
 	sleep 1
 	if [ -n "$new_routers" ]; then
+		$LOGGER "New Routers ($interface): $new_routers"
 		set "$new_routers"
 		if ping -q -c 1 -w 1 "$1"; then
 			if [ "$new_ip_address" != "$alias_ip_address" ]; then
@@ -249,8 +251,6 @@
 		fi
 	fi
 	ifconfig $interface inet -alias $new_ip_address $medium
-	# XXX Why not a delete_old_address as before all other invocations of
-	#     delete_old_routes?
 	delete_old_routes
 	exit 1
 	;;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200412022338.iB2NcQ7p014643>