1 Submitted By: DJ Lucas (dj at linuxfromscratch dot org)
3 Initial Package Version: 3.0.2
4 Origin: Jim Gifford, Bruce Dubbs, DJ Lucas
5 Description: Fixes client script to use iproute2 (added flush to previous
7 Upstream Status: Not submitted
9 --- dhcp-3.0.2-orig/client/scripts/linux 2002-11-14 19:09:09.000000000 -0600
10 +++ dhcp-3.0.2/client/scripts/linux 2005-06-18 22:54:59.000000000 -0500
13 # dhclient-script for Linux. Dan Halbert, March, 1997.
14 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
15 -# No guarantees about this. I'm a novice at the details of Linux
18 +# Updated to iproute2 by Jim Gifford (scripts@jg555.com)
22 # 0. This script is based on the netbsd script supplied with dhcp-970306.
24 -# 1. ifconfig down apparently deletes all relevant routes and flushes
25 -# the arp cache, so this doesn't need to be done explicitly.
27 -# 2. The alias address handling here has not been tested AT ALL.
28 -# I'm just going by the doc of modern Linux ip aliasing, which uses
29 -# notations like eth0:0, eth0:1, for each alias.
31 -# 3. I have to calculate the network address, and calculate the broadcast
32 -# address if it is not supplied. This might be much more easily done
33 -# by the dhclient C code, and passed on.
35 -# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
36 -# of the $1 in its args.
37 +# 1. This script was modified to work with iproute2
38 +# 2. cidr_convert based on a script by Kevin Fleming (kpfleming@linuxfromscratch.org)
39 +# 3. Updated to delete addresses when taking an interface down (bdubbs@linuxfromscratch.org)
42 if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
51 + while [ $n != 0 ]; do
60 + echo `dec2binary $1``dec2binary $2``dec2binary $3``dec2binary $4`
66 + local mask=`mask_to_binary ${netmask//./ }`
71 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
79 -release=`expr $release : '\(.*\)\..*'`
80 -relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
81 -relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
83 if [ x$new_broadcast_address != x ]; then
84 new_broadcast_arg="broadcast $new_broadcast_address"
87 old_broadcast_arg="broadcast $old_broadcast_address"
89 if [ x$new_subnet_mask != x ]; then
90 - new_subnet_arg="netmask $new_subnet_mask"
91 + cidr_convert $new_subnet_mask
92 + new_subnet_arg="$cidr"
94 if [ x$old_subnet_mask != x ]; then
95 - old_subnet_arg="netmask $old_subnet_mask"
97 -if [ x$alias_subnet_mask != x ]; then
98 - alias_subnet_arg="netmask $alias_subnet_mask"
99 + cidr_convert $old_subnet_mask
100 + old_subnet_arg="$cidr"
103 if [ x$reason = xMEDIUM ]; then
105 if [ x$reason = xPREINIT ]; then
106 if [ x$alias_ip_address != x ]; then
107 # Bring down alias interface. Its routes will disappear too.
108 - ifconfig $interface:0- inet 0
110 - if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
112 - ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
113 - broadcast 255.255.255.255 up
114 - # Add route to make broadcast work. Do not omit netmask.
115 - route add default dev $interface netmask 0.0.0.0
117 - ifconfig $interface 0 up
118 + ip link set $interface down
119 + ip addr del $alias_ip_address dev $interface
121 + ip link set $interface up
123 # We need to give the kernel some time to get the interface up.
125 @@ -115,83 +115,51 @@
129 - if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
130 - [ x$alias_ip_address != x$old_ip_address ]; then
131 - # Possible new alias. Remove old alias.
132 - ifconfig $interface:0- inet 0
134 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
135 - # IP address changed. Bringing down the interface will delete all routes,
136 + # IP address changed. Bring down the interface, delete all routes,
137 # and clear the ARP cache.
138 - ifconfig $interface inet 0 down
140 + ip link set $interface down
141 + ip addr flush dev $interface
143 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
144 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
146 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
148 + ip link set $interface up
149 + ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg \
150 + label $interface dev $interface
151 # Add a network route to the computed network address.
152 - if [ $relmajor -lt 2 ] || \
153 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
154 - route add -net $new_network_number $new_subnet_arg dev $interface
156 for router in $new_routers; do
157 - route add default gw $router
158 + ip route add default via $router
161 - if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
163 - ifconfig $interface:0- inet 0
164 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
165 - route add -host $alias_ip_address $interface:0
171 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
172 || [ x$reason = xSTOP ]; then
173 - if [ x$alias_ip_address != x ]; then
174 - # Turn off alias interface.
175 - ifconfig $interface:0- inet 0
177 if [ x$old_ip_address != x ]; then
178 - # Shut down interface, which will delete routes and clear arp cache.
179 - ifconfig $interface inet 0 down
181 - if [ x$alias_ip_address != x ]; then
182 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
183 - route add -host $alias_ip_address $interface:0
184 + # Shut down interface, delete routes, and clear arp cache.
185 + ip link set $interface down
186 + ip addr flush dev $interface
191 if [ x$reason = xTIMEOUT ]; then
192 - if [ x$alias_ip_address != x ]; then
193 - ifconfig $interface:0- inet 0
195 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
197 + ip link set $interface up
198 + ip addr set $new_ip_address/$new_subnet_arg $new_broadcast_arg \
199 + label $interface dev $interface
201 - ############## what is -w in ping?
202 - if ping -q -c 1 $1; then
203 - if [ x$new_ip_address != x$alias_ip_address ] && \
204 - [ x$alias_ip_address != x ]; then
205 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
206 - route add -host $alias_ip_address dev $interface:0
208 - if [ $relmajor -lt 2 ] || \
209 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
210 - route add -net $new_network_number
212 - for router in $new_routers; do
213 - route add default gw $router
218 - ifconfig $interface inet 0 down
220 + for router in $new_routers; do
221 + ip route add default via $router
226 + ip link set $interface down
227 + ip addr flush dev $interface