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.
30 -# 'ip' just looks too weird. /sbin/ip looks less weird.
36 + local netmask=$(echo $1)
41 + for n in $netmask ; do
42 + for i in 128 64 32 16 8 4 2 1 ; do
43 + if [ $(($n & $i)) -ne 0 ]; then
44 + if [ $endp -eq 0 ]; then
59 - if [ x"$new_domain_name_servers" != x ]; then
60 - cat /dev/null > /etc/resolv.conf.dhclient
61 - chmod 644 /etc/resolv.conf.dhclient
62 - if [ x"$new_domain_search" != x ]; then
63 - echo search $new_domain_search >> /etc/resolv.conf.dhclient
64 - elif [ x"$new_domain_name" != x ]; then
65 - # Note that the DHCP 'Domain Name Option' is really just a domain
66 - # name, and that this practice of using the domain name option as
67 - # a search path is both nonstandard and deprecated.
68 - echo search $new_domain_name >> /etc/resolv.conf.dhclient
70 - for nameserver in $new_domain_name_servers; do
71 - echo nameserver $nameserver >>/etc/resolv.conf.dhclient
74 - mv /etc/resolv.conf.dhclient /etc/resolv.conf
75 - elif [ "x${new_dhcp6_name_servers}" != x ] ; then
76 - cat /dev/null > /etc/resolv.conf.dhclient6
77 - chmod 644 /etc/resolv.conf.dhclient6
79 - if [ "x${new_dhcp6_domain_search}" != x ] ; then
80 - echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
82 - for nameserver in ${new_dhcp6_name_servers} ; do
83 - echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
86 - mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
88 + if [ -n "$new_domain_name_servers" ]; then
89 + :> /etc/resolv.conf.dhclient
90 + chmod 644 /etc/resolv.conf.dhclient
91 + if [ -n "$new_domain_search" ]; then
92 + echo search $new_domain_search >> /etc/resolv.conf.dhclient
93 + elif [ -n "$new_domain_name" ]; then
94 + # Note that the DHCP 'Domain Name Option' is really just a domain
95 + # name, and that this practice of using the domain name option as
96 + # a search path is both nonstandard and deprecated.
97 + echo search $new_domain_name >> /etc/resolv.conf.dhclient
99 + for nameserver in $new_domain_name_servers; do
100 + echo nameserver $nameserver >>/etc/resolv.conf.dhclient
102 + mv /etc/resolv.conf.dhclient /etc/resolv.conf
103 + elif [ -n "${new_dhcp6_name_servers}" ] ; then
104 + :> /etc/resolv.conf.dhclient6
105 + chmod 644 /etc/resolv.conf.dhclient6
107 + if [ "x${new_dhcp6_domain_search}" != x ] ; then
108 + echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
110 + for nameserver in ${new_dhcp6_name_servers} ; do
111 + echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
113 + mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
117 -# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
118 +# Must be used on exit.
119 +# Invokes the local dhcp client exit hooks, if any.
122 - if [ -f /etc/dhclient-exit-hooks ]; then
123 - . /etc/dhclient-exit-hooks
125 -# probably should do something with exit status of the local script
128 + if [ -f /etc/dhclient-exit-hooks ]; then
129 + . /etc/dhclient-exit-hooks
131 + # probably should do something with exit status of the local script
135 # Invoke the local dhcp client enter hooks, if they exist.
136 if [ -f /etc/dhclient-enter-hooks ]; then
138 - . /etc/dhclient-enter-hooks
139 - # allow the local script to abort processing of this state
140 - # local script must set exit_status variable to nonzero.
141 - if [ $exit_status -ne 0 ]; then
145 + . /etc/dhclient-enter-hooks
146 + # allow the local script to abort processing of this state
147 + # local script must set exit_status variable to nonzero.
148 + if [ $exit_status -ne 0 ]; then
154 -release=`expr $release : '\(.*\)\..*'`
155 -relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
156 -relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
162 -if [ x$new_broadcast_address != x ]; then
163 - new_broadcast_arg="broadcast $new_broadcast_address"
165 -if [ x$old_broadcast_address != x ]; then
166 - old_broadcast_arg="broadcast $old_broadcast_address"
168 -if [ x$new_subnet_mask != x ]; then
169 - new_subnet_arg="netmask $new_subnet_mask"
171 -if [ x$old_subnet_mask != x ]; then
172 - old_subnet_arg="netmask $old_subnet_mask"
174 -if [ x$alias_subnet_mask != x ]; then
175 - alias_subnet_arg="netmask $alias_subnet_mask"
178 -if [ x$reason = xMEDIUM ]; then
179 - # Linux doesn't do mediums (ok, ok, media).
183 -if [ x$reason = xPREINIT ]; then
184 - if [ x$alias_ip_address != x ]; then
185 - # Bring down alias interface. Its routes will disappear too.
186 - ifconfig $interface:0- inet 0
188 - if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
190 - ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
191 - broadcast 255.255.255.255 up
192 - # Add route to make broadcast work. Do not omit netmask.
193 - route add default dev $interface netmask 0.0.0.0
195 - ifconfig $interface 0 up
198 - # We need to give the kernel some time to get the interface up.
204 -if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
208 -if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
209 - [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
210 - current_hostname=`hostname`
211 - if [ x$current_hostname = x ] || \
212 - [ x$current_hostname = x$old_host_name ]; then
213 - if [ x$current_hostname = x ] || \
214 - [ x$new_host_name != x$old_host_name ]; then
215 - hostname $new_host_name
219 - if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
220 - [ x$alias_ip_address != x$old_ip_address ]; then
221 - # Possible new alias. Remove old alias.
222 - ifconfig $interface:0- inet 0
224 - if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
225 - # IP address changed. Bringing down the interface will delete all routes,
226 - # and clear the ARP cache.
227 - ifconfig $interface inet 0 down
230 - if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
231 - [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
233 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
235 - # Add a network route to the computed network address.
236 - if [ $relmajor -lt 2 ] || \
237 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
238 - route add -net $new_network_number $new_subnet_arg dev $interface
240 - for router in $new_routers; do
241 - route add default gw $router
244 - if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
246 - ifconfig $interface:0- inet 0
247 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
248 - route add -host $alias_ip_address $interface:0
254 -if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
255 - || [ x$reason = xSTOP ]; then
256 - if [ x$alias_ip_address != x ]; then
257 - # Turn off alias interface.
258 - ifconfig $interface:0- inet 0
260 - if [ x$old_ip_address != x ]; then
261 - # Shut down interface, which will delete routes and clear arp cache.
262 - ifconfig $interface inet 0 down
264 - if [ x$alias_ip_address != x ]; then
265 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
266 - route add -host $alias_ip_address $interface:0
269 +if [ -n "$new_broadcast_address" ]; then
270 + new_broadcast_arg="broadcast $new_broadcast_address"
273 -if [ x$reason = xTIMEOUT ]; then
274 - if [ x$alias_ip_address != x ]; then
275 - ifconfig $interface:0- inet 0
277 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
280 - if ping -q -c 1 $1; then
281 - if [ x$new_ip_address != x$alias_ip_address ] && \
282 - [ x$alias_ip_address != x ]; then
283 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
284 - route add -host $alias_ip_address dev $interface:0
286 - if [ $relmajor -lt 2 ] || \
287 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
288 - route add -net $new_network_number
290 - for router in $new_routers; do
291 - route add default gw $router
296 - ifconfig $interface inet 0 down
298 +if [ -n "$old_broadcast_address" ]; then
299 + old_broadcast_arg="broadcast $old_broadcast_address"
306 -if [ ${reason} = PREINIT6 ] ; then
307 - # Ensure interface is up.
308 - ${ip} link set ${interface} up
310 - # Remove any stale addresses from aborted clients.
311 - ${ip} -f inet6 addr flush dev ${interface} scope global permanent
314 +if [ -n "$new_subnet_mask" ]; then
315 + new_subnet_arg="$(calc_prefix $new_subnet_mask)"
317 +if [ -n "$old_subnet_mask" ]; then
318 + old_subnet_arg="$(calc_prefix $old_subnet_mask)"
320 +if [ -n "$alias_subnet_mask" ]; then
321 + alias_subnet_arg="$(calc_prefix $alias_subnet_mask)"
323 +[ -z "new_subnet_arg" ] && $new_subnet_arg="32"
324 +[ -z "old_subnet_arg" ] && $old_subnet_arg="32"
325 +[ -z "alias_subnet_arg" ] && $alias_subnet_arg="32"
329 + # Linux doesn't do mediums (ok, ok, media).
333 + if [ -n "$alias_ip_address" ]; then
334 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
336 + /sbin/ip link set $interface up
338 + # We need to give the kernel some time to get the interface up.
342 + BOUND|RENEW|REBIND|REBOOT)
343 + current_hostname=`hostname`
344 + if [ -z "$current_hostname" ]; then
345 + hostname $new_host_name
346 + elif [ "$current_hostname" = "$old_host_name" -a \
347 + "$new_host_name" != "$old_host_name" ]; then
348 + hostname $new_host_name
351 + if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
352 + "$alias_ip_address" != "$old_ip_address" ]; then
353 + # Possible new alias. Remove old alias.
354 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
356 + if [ -n "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
357 + # IP address changed.
358 + /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
359 + for router in $old_routers; do
360 + /sbin/ip route del default via $router
362 + if [ -n "$old_static_routes" ]; then
363 + set -- $old_static_routes
364 + while [ $# -gt 1 ]; do
365 + /sbin/ip route del $1 via $2
370 + if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
371 + "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
372 + /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
373 + # Add a network route to the computed network address.
374 + for router in $new_routers; do
375 + /sbin/ip route add default via $router
377 + if [ -n "$new_static_routes" ]; then
378 + set -- $new_static_routes
379 + while [ $# -gt 1 ]; do
380 + /sbin/ip route add $1 via $2
385 + if [ -n "$alias_ip_address" -a "$new_ip_address" != "$alias_ip_address" ]; then
386 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
391 + EXPIRE|FAIL|RELEASE|STOP)
392 + if [ -n "$alias_ip_address" ]; then
393 + # Turn off alias interface.
394 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
396 + if [ -n "$old_ip_address" ]; then
397 + /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
398 + for router in $old_routers; do
399 + /sbin/ip route del default via $router
401 + if [ -n "$old_static_routes" ]; then
402 + set -- $old_static_routes
403 + while [ $# -gt 1 ]; do
404 + /sbin/ip route del $1 via $2
409 + if [ -n "$alias_ip_address" ]; then
410 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
415 + if [ -n "$alias_ip_address" ]; then
416 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
418 + /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
421 + if ping -q -c 1 $1; then
422 + if [ "$new_ip_address" != "$alias_ip_address" ] && \
423 + [ -n "$alias_ip_address" ]; then
424 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
426 + for router in $new_routers; do
427 + /sbin/ip route add default via $router
429 + if [ -n "$new_static_routes" ]; then
430 + set -- $new_static_routes
431 + while [ $# -gt 1 ]; do
432 + /sbin/ip route add $1 via $2
440 + /sbin/ip addr del $new_ip_address/$new_subnet_arg dev $interface
441 + for router in $old_routers; do
442 + /sbin/ip route del default via $router
444 + if [ -n "$old_static_routes" ]; then
445 + set -- $old_static_routes
446 + while [ $# -gt 1 ]; do
447 + /sbin/ip route del $1 via $2
455 + # Ensure interface is up.
456 + /sbin/ip link set ${interface} up
458 + # Remove any stale addresses from aborted clients.
459 + /sbin/ip -f inet6 addr flush dev ${interface} scope global permanent
464 + if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
468 -if [ ${reason} = BOUND6 ] ; then
469 - if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
473 - ${ip} -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
474 + /sbin/ip -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
475 dev ${interface} scope global
477 - # Check for nameserver options.
482 + # Check for nameserver options.
485 -if [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then
486 - # Make sure nothing has moved around on us.
490 - # Nameservers/domains/etc.
491 - if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
492 - [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
499 + # Make sure nothing has moved around on us.
501 -if [ ${reason} = DEPREF6 ] ; then
502 - if [ x${new_ip6_prefixlen} = x ] ; then
506 - # There doesn't appear to be a way to update an addr to indicate
508 -# ${ip} -f inet6 addr ??? ${new_ip6_address}/${new_ip6_prefixlen} \
509 -# dev ${interface} scope global deprecated?
510 + # Nameservers/domains/etc.
511 + if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
512 + [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
520 + if [ x${new_ip6_prefixlen} = x ] ; then
524 + # There doesn't appear to be a way to update an addr to indicate
526 + # /sbin/ip -f inet6 addr ??? ${new_ip6_address}/${new_ip6_prefixlen} \
527 + # dev ${interface} scope global deprecated?
532 + EXPIRE6|RELEASE6|STOP6)
533 + if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
540 -if [ ${reason} = EXPIRE6 -o ${reason} = RELEASE6 -o ${reason} = STOP6 ] ; then
541 - if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
545 - ${ip} -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
546 + /sbin/ip -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \