1 --- dhcp-3.1.0a3/client/scripts/linux.orig 2006-07-22 04:24:16.000000000 +0200
2 +++ dhcp-3.1.0a3/client/scripts/linux 2007-04-16 17:25:06.000000000 +0200
6 # dhclient-script for Linux. Dan Halbert, March, 1997.
7 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
8 -# No guarantees about this. I'm a novice at the details of Linux
13 # 0. This script is based on the netbsd script supplied with dhcp-970306.
15 -# 1. ifconfig down apparently deletes all relevant routes and flushes
16 -# the arp cache, so this doesn't need to be done explicitly.
17 +# 1. This script was modified to work with iproute2
19 -# 2. The alias address handling here has not been tested AT ALL.
20 -# I'm just going by the doc of modern Linux ip aliasing, which uses
21 -# notations like eth0:0, eth0:1, for each alias.
23 -# 3. I have to calculate the network address, and calculate the broadcast
24 -# address if it is not supplied. This might be much more easily done
25 -# by the dhclient C code, and passed on.
27 -# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
28 -# of the $1 in its args.
33 + local netmask=$(echo $1)
39 + for n in $netmask ; do
40 + for i in 128 64 32 16 8 4 2 1 ; do
41 + if [ $(($n & $i)) -ne 0 ]; then
42 + if [ $endp -eq 0 ]; then
57 - if [ x"$new_domain_name_servers" != x ]; then
58 - cat /dev/null > /etc/resolv.conf.dhclient
59 - chmod 644 /etc/resolv.conf.dhclient
60 - if [ x"$new_domain_search" != x ]; then
61 - echo search $new_domain_search >> /etc/resolv.conf.dhclient
62 - elif [ x"$new_domain_name" != x ]; then
63 - # Note that the DHCP 'Domain Name Option' is really just a domain
64 - # name, and that this practice of using the domain name option as
65 - # a search path is both nonstandard and deprecated.
66 - echo search $new_domain_name >> /etc/resolv.conf.dhclient
68 - for nameserver in $new_domain_name_servers; do
69 - echo nameserver $nameserver >>/etc/resolv.conf.dhclient
72 - mv /etc/resolv.conf.dhclient /etc/resolv.conf
74 + if [ -n "$new_domain_name_servers" ]; then
75 + :> /etc/resolv.conf.dhclient
76 + chmod 644 /etc/resolv.conf.dhclient
77 + if [ -n "$new_domain_search" ]; then
78 + echo search $new_domain_search >> /etc/resolv.conf.dhclient
79 + elif [ -n "$new_domain_name" ]; then
80 + # Note that the DHCP 'Domain Name Option' is really just a domain
81 + # name, and that this practice of using the domain name option as
82 + # a search path is both nonstandard and deprecated.
83 + echo search $new_domain_name >> /etc/resolv.conf.dhclient
85 + for nameserver in $new_domain_name_servers; do
86 + echo nameserver $nameserver >>/etc/resolv.conf.dhclient
88 + mv /etc/resolv.conf.dhclient /etc/resolv.conf
92 -# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
93 +# Must be used on exit.
94 +# Invokes the local dhcp client exit hooks, if any.
97 - if [ -f /etc/dhclient-exit-hooks ]; then
98 - . /etc/dhclient-exit-hooks
100 -# probably should do something with exit status of the local script
103 + if [ -f /etc/dhclient-exit-hooks ]; then
104 + . /etc/dhclient-exit-hooks
106 + # probably should do something with exit status of the local script
110 # Invoke the local dhcp client enter hooks, if they exist.
111 if [ -f /etc/dhclient-enter-hooks ]; then
113 - . /etc/dhclient-enter-hooks
114 - # allow the local script to abort processing of this state
115 - # local script must set exit_status variable to nonzero.
116 - if [ $exit_status -ne 0 ]; then
122 -release=`expr $release : '\(.*\)\..*'`
123 -relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
124 -relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
126 -if [ x$new_broadcast_address != x ]; then
127 - new_broadcast_arg="broadcast $new_broadcast_address"
129 -if [ x$old_broadcast_address != x ]; then
130 - old_broadcast_arg="broadcast $old_broadcast_address"
132 -if [ x$new_subnet_mask != x ]; then
133 - new_subnet_arg="netmask $new_subnet_mask"
135 -if [ x$old_subnet_mask != x ]; then
136 - old_subnet_arg="netmask $old_subnet_mask"
138 -if [ x$alias_subnet_mask != x ]; then
139 - alias_subnet_arg="netmask $alias_subnet_mask"
142 -if [ x$reason = xMEDIUM ]; then
143 - # Linux doesn't do mediums (ok, ok, media).
147 -if [ x$reason = xPREINIT ]; then
148 - if [ x$alias_ip_address != x ]; then
149 - # Bring down alias interface. Its routes will disappear too.
150 - ifconfig $interface:0- inet 0
152 - if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
154 - ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
155 - broadcast 255.255.255.255 up
156 - # Add route to make broadcast work. Do not omit netmask.
157 - route add default dev $interface netmask 0.0.0.0
159 - ifconfig $interface 0 up
162 - # We need to give the kernel some time to get the interface up.
168 -if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
172 -if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
173 - [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
174 - current_hostname=`hostname`
175 - if [ x$current_hostname = x ] || \
176 - [ x$current_hostname = x$old_host_name ]; then
177 - if [ x$current_hostname = x ] || \
178 - [ x$new_host_name != x$old_host_name ]; then
179 - hostname $new_host_name
183 - if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
184 - [ x$alias_ip_address != x$old_ip_address ]; then
185 - # Possible new alias. Remove old alias.
186 - ifconfig $interface:0- inet 0
188 - if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
189 - # IP address changed. Bringing down the interface will delete all routes,
190 - # and clear the ARP cache.
191 - ifconfig $interface inet 0 down
194 - if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
195 - [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
197 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
199 - # Add a network route to the computed network address.
200 - if [ $relmajor -lt 2 ] || \
201 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
202 - route add -net $new_network_number $new_subnet_arg dev $interface
204 - for router in $new_routers; do
205 - route add default gw $router
208 - if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
210 - ifconfig $interface:0- inet 0
211 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
212 - route add -host $alias_ip_address $interface:0
218 -if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
219 - || [ x$reason = xSTOP ]; then
220 - if [ x$alias_ip_address != x ]; then
221 - # Turn off alias interface.
222 - ifconfig $interface:0- inet 0
224 - if [ x$old_ip_address != x ]; then
225 - # Shut down interface, which will delete routes and clear arp cache.
226 - ifconfig $interface inet 0 down
228 - if [ x$alias_ip_address != x ]; then
229 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
230 - route add -host $alias_ip_address $interface:0
235 -if [ x$reason = xTIMEOUT ]; then
236 - if [ x$alias_ip_address != x ]; then
237 - ifconfig $interface:0- inet 0
239 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
242 - ############## what is -w in ping?
243 - if ping -q -c 1 $1; then
244 - if [ x$new_ip_address != x$alias_ip_address ] && \
245 - [ x$alias_ip_address != x ]; then
246 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
247 - route add -host $alias_ip_address dev $interface:0
249 - if [ $relmajor -lt 2 ] || \
250 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
251 - route add -net $new_network_number
253 - for router in $new_routers; do
254 - route add default gw $router
259 - ifconfig $interface inet 0 down
263 + . /etc/dhclient-enter-hooks
264 + # allow the local script to abort processing of this state
265 + # local script must set exit_status variable to nonzero.
266 + if [ $exit_status -ne 0 ]; then
271 +if [ -n "$new_broadcast_address" ]; then
272 + new_broadcast_arg="broadcast $new_broadcast_address"
274 +if [ -n "$old_broadcast_address" ]; then
275 + old_broadcast_arg="broadcast $old_broadcast_address"
277 +if [ -n "$new_subnet_mask" ]; then
278 + new_subnet_arg="$(calc_prefix $new_subnet_mask)"
280 +if [ -n "$old_subnet_mask" ]; then
281 + old_subnet_arg="$(calc_prefix $old_subnet_mask)"
283 +if [ -n "$alias_subnet_mask" ]; then
284 + alias_subnet_arg="$(calc_prefix $alias_subnet_mask)"
286 +[ -z "new_subnet_arg" ] && $new_subnet_arg="32"
287 +[ -z "old_subnet_arg" ] && $old_subnet_arg="32"
288 +[ -z "alias_subnet_arg" ] && $alias_subnet_arg="32"
292 + # Linux doesn't do mediums (ok, ok, media).
296 + if [ -n "$alias_ip_address" ]; then
297 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
299 + /sbin/ip link set $interface up
301 + # We need to give the kernel some time to get the interface up.
305 + BOUND|RENEW|REBIND|REBOOT)
306 + current_hostname=`hostname`
307 + if [ -z "$current_hostname" ]; then
308 + hostname $new_host_name
309 + elif [ "$current_hostname" = "$old_host_name" -a \
310 + "$new_host_name" != "$old_host_name" ]; then
311 + hostname $new_host_name
314 + if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
315 + "$alias_ip_address" != "$old_ip_address" ]; then
316 + # Possible new alias. Remove old alias.
317 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
319 + if [ -n "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
320 + # IP address changed.
321 + /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
322 + for router in $old_routers; do
323 + /sbin/ip route del default via $router
325 + if [ -n "$old_static_routes" ]; then
326 + set -- $old_static_routes
327 + while [ $# -gt 1 ]; do
328 + /sbin/ip route del $1 via $2
333 + if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
334 + "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
335 + /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
336 + # Add a network route to the computed network address.
337 + for router in $new_routers; do
338 + /sbin/ip route add default via $router
340 + if [ -n "$new_static_routes" ]; then
341 + set -- $new_static_routes
342 + while [ $# -gt 1 ]; do
343 + /sbin/ip route add $1 via $2
348 + if [ -n "$alias_ip_address" -a "$new_ip_address" != "$alias_ip_address" ]; then
349 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
354 + EXPIRE|FAIL|RELEASE|STOP)
355 + if [ -n "$alias_ip_address" ]; then
356 + # Turn off alias interface.
357 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
359 + if [ -n "$old_ip_address" ]; then
360 + /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
361 + for router in $old_routers; do
362 + /sbin/ip route del default via $router
364 + if [ -n "$old_static_routes" ]; then
365 + set -- $old_static_routes
366 + while [ $# -gt 1 ]; do
367 + /sbin/ip route del $1 via $2
372 + if [ -n "$alias_ip_address" ]; then
373 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
378 + if [ -n "$alias_ip_address" ]; then
379 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
381 + /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
384 + if ping -q -c 1 $1; then
385 + if [ "$new_ip_address" != "$alias_ip_address" ] && \
386 + [ -n "$alias_ip_address" ]; then
387 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
389 + for router in $new_routers; do
390 + /sbin/ip route add default via $router
392 + if [ -n "$new_static_routes" ]; then
393 + set -- $new_static_routes
394 + while [ $# -gt 1 ]; do
395 + /sbin/ip route add $1 via $2
403 + /sbin/ip addr del $new_ip_address/$new_subnet_arg dev $interface
404 + for router in $old_routers; do
405 + /sbin/ip route del default via $router
407 + if [ -n "$old_static_routes" ]; then
408 + set -- $old_static_routes
409 + while [ $# -gt 1 ]; do
410 + /sbin/ip route del $1 via $2