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)
38 + for n in $netmask ; do
39 + for i in 128 64 32 16 8 4 2 1 ; do
40 + if [ $(($n & $i)) -ne 0 ]; then
41 + if [ $endp -eq 0 ]; then
56 - if [ x"$new_domain_name_servers" != x ]; then
57 - cat /dev/null > /etc/resolv.conf.dhclient
58 - chmod 644 /etc/resolv.conf.dhclient
59 - if [ x"$new_domain_search" != x ]; then
60 - echo search $new_domain_search >> /etc/resolv.conf.dhclient
61 - elif [ x"$new_domain_name" != x ]; then
62 - # Note that the DHCP 'Domain Name Option' is really just a domain
63 - # name, and that this practice of using the domain name option as
64 - # a search path is both nonstandard and deprecated.
65 - echo search $new_domain_name >> /etc/resolv.conf.dhclient
67 - for nameserver in $new_domain_name_servers; do
68 - echo nameserver $nameserver >>/etc/resolv.conf.dhclient
71 - mv /etc/resolv.conf.dhclient /etc/resolv.conf
73 + if [ -n "$new_domain_name_servers" ]; then
74 + :> /etc/resolv.conf.dhclient
75 + chmod 644 /etc/resolv.conf.dhclient
76 + if [ -n "$new_domain_search" ]; then
77 + echo search $new_domain_search >> /etc/resolv.conf.dhclient
78 + elif [ -n "$new_domain_name" ]; then
79 + # Note that the DHCP 'Domain Name Option' is really just a domain
80 + # name, and that this practice of using the domain name option as
81 + # a search path is both nonstandard and deprecated.
82 + echo search $new_domain_name >> /etc/resolv.conf.dhclient
84 + for nameserver in $new_domain_name_servers; do
85 + echo nameserver $nameserver >>/etc/resolv.conf.dhclient
87 + mv /etc/resolv.conf.dhclient /etc/resolv.conf
91 -# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
92 +# Must be used on exit.
93 +# Invokes the local dhcp client exit hooks, if any.
96 - if [ -f /etc/dhclient-exit-hooks ]; then
97 - . /etc/dhclient-exit-hooks
99 -# probably should do something with exit status of the local script
102 + if [ -f /etc/dhclient-exit-hooks ]; then
103 + . /etc/dhclient-exit-hooks
105 + # probably should do something with exit status of the local script
109 # Invoke the local dhcp client enter hooks, if they exist.
110 if [ -f /etc/dhclient-enter-hooks ]; then
112 - . /etc/dhclient-enter-hooks
113 - # allow the local script to abort processing of this state
114 - # local script must set exit_status variable to nonzero.
115 - if [ $exit_status -ne 0 ]; then
121 -release=`expr $release : '\(.*\)\..*'`
122 -relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
123 -relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
125 -if [ x$new_broadcast_address != x ]; then
126 - new_broadcast_arg="broadcast $new_broadcast_address"
128 -if [ x$old_broadcast_address != x ]; then
129 - old_broadcast_arg="broadcast $old_broadcast_address"
131 -if [ x$new_subnet_mask != x ]; then
132 - new_subnet_arg="netmask $new_subnet_mask"
134 -if [ x$old_subnet_mask != x ]; then
135 - old_subnet_arg="netmask $old_subnet_mask"
137 -if [ x$alias_subnet_mask != x ]; then
138 - alias_subnet_arg="netmask $alias_subnet_mask"
141 -if [ x$reason = xMEDIUM ]; then
142 - # Linux doesn't do mediums (ok, ok, media).
146 -if [ x$reason = xPREINIT ]; then
147 - if [ x$alias_ip_address != x ]; then
148 - # Bring down alias interface. Its routes will disappear too.
149 - ifconfig $interface:0- inet 0
151 - if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
153 - ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
154 - broadcast 255.255.255.255 up
155 - # Add route to make broadcast work. Do not omit netmask.
156 - route add default dev $interface netmask 0.0.0.0
158 - ifconfig $interface 0 up
161 - # We need to give the kernel some time to get the interface up.
167 -if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
171 -if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
172 - [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
173 - current_hostname=`hostname`
174 - if [ x$current_hostname = x ] || \
175 - [ x$current_hostname = x$old_host_name ]; then
176 - if [ x$current_hostname = x ] || \
177 - [ x$new_host_name != x$old_host_name ]; then
178 - hostname $new_host_name
182 - if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
183 - [ x$alias_ip_address != x$old_ip_address ]; then
184 - # Possible new alias. Remove old alias.
185 - ifconfig $interface:0- inet 0
187 - if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
188 - # IP address changed. Bringing down the interface will delete all routes,
189 - # and clear the ARP cache.
190 - ifconfig $interface inet 0 down
193 - if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
194 - [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
196 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
198 - # Add a network route to the computed network address.
199 - if [ $relmajor -lt 2 ] || \
200 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
201 - route add -net $new_network_number $new_subnet_arg dev $interface
203 - for router in $new_routers; do
204 - route add default gw $router
207 - if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
209 - ifconfig $interface:0- inet 0
210 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
211 - route add -host $alias_ip_address $interface:0
217 -if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
218 - || [ x$reason = xSTOP ]; then
219 - if [ x$alias_ip_address != x ]; then
220 - # Turn off alias interface.
221 - ifconfig $interface:0- inet 0
223 - if [ x$old_ip_address != x ]; then
224 - # Shut down interface, which will delete routes and clear arp cache.
225 - ifconfig $interface inet 0 down
227 - if [ x$alias_ip_address != x ]; then
228 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
229 - route add -host $alias_ip_address $interface:0
234 -if [ x$reason = xTIMEOUT ]; then
235 - if [ x$alias_ip_address != x ]; then
236 - ifconfig $interface:0- inet 0
238 - ifconfig $interface inet $new_ip_address $new_subnet_arg \
241 - ############## what is -w in ping?
242 - if ping -q -c 1 $1; then
243 - if [ x$new_ip_address != x$alias_ip_address ] && \
244 - [ x$alias_ip_address != x ]; then
245 - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
246 - route add -host $alias_ip_address dev $interface:0
248 - if [ $relmajor -lt 2 ] || \
249 - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
250 - route add -net $new_network_number
252 - for router in $new_routers; do
253 - route add default gw $router
258 - ifconfig $interface inet 0 down
262 + . /etc/dhclient-enter-hooks
263 + # allow the local script to abort processing of this state
264 + # local script must set exit_status variable to nonzero.
265 + if [ $exit_status -ne 0 ]; then
270 +if [ -n "$new_broadcast_address" ]; then
271 + new_broadcast_arg="broadcast $new_broadcast_address"
273 +if [ -n "$old_broadcast_address" ]; then
274 + old_broadcast_arg="broadcast $old_broadcast_address"
276 +if [ -n "$new_subnet_mask" ]; then
277 + new_subnet_arg="$(calc_prefix $new_subnet_mask)"
279 +if [ -n "$old_subnet_mask" ]; then
280 + old_subnet_arg="$(calc_prefix $old_subnet_mask)"
282 +if [ -n "$alias_subnet_mask" ]; then
283 + alias_subnet_arg="$(calc_prefix $alias_subnet_mask)"
285 +[ -z "new_subnet_arg" ] && $new_subnet_arg="32"
286 +[ -z "old_subnet_arg" ] && $old_subnet_arg="32"
287 +[ -z "alias_subnet_arg" ] && $alias_subnet_arg="32"
291 + # Linux doesn't do mediums (ok, ok, media).
295 + if [ -n "$alias_ip_address" ]; then
296 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
298 + /sbin/ip link set $interface up
300 + # We need to give the kernel some time to get the interface up.
304 + BOUND|RENEW|REBIND|REBOOT)
305 + current_hostname=`hostname`
306 + if [ -z "$current_hostname" ]; then
307 + hostname $new_host_name
308 + elif [ "$current_hostname" = "$old_host_name" -a \
309 + "$new_host_name" != "$old_host_name" ]; then
310 + hostname $new_host_name
313 + if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
314 + "$alias_ip_address" != "$old_ip_address" ]; then
315 + # Possible new alias. Remove old alias.
316 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
318 + if [ -n "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
319 + # IP address changed.
320 + /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
321 + for router in $old_routers; do
322 + /sbin/ip route del default via $router
324 + if [ -n "$old_static_routes" ]; then
325 + set -- $old_static_routes
326 + while [ $# -gt 1 ]; do
327 + /sbin/ip route del $1 via $2
332 + if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
333 + "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
334 + /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
335 + # Add a network route to the computed network address.
336 + for router in $new_routers; do
337 + /sbin/ip route add default via $router
339 + if [ -n "$new_static_routes" ]; then
340 + set -- $new_static_routes
341 + while [ $# -gt 1 ]; do
342 + /sbin/ip route add $1 via $2
347 + if [ -n "$alias_ip_address" -a "$new_ip_address" != "$alias_ip_address" ]; then
348 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
353 + EXPIRE|FAIL|RELEASE|STOP)
354 + if [ -n "$alias_ip_address" ]; then
355 + # Turn off alias interface.
356 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
358 + if [ -n "$old_ip_address" ]; then
359 + /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
360 + for router in $old_routers; do
361 + /sbin/ip route del default via $router
363 + if [ -n "$old_static_routes" ]; then
364 + set -- $old_static_routes
365 + while [ $# -gt 1 ]; do
366 + /sbin/ip route del $1 via $2
371 + if [ -n "$alias_ip_address" ]; then
372 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
377 + if [ -n "$alias_ip_address" ]; then
378 + /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
380 + /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
383 + if ping -q -c 1 $1; then
384 + if [ "$new_ip_address" != "$alias_ip_address" ] && \
385 + [ -n "$alias_ip_address" ]; then
386 + /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
388 + for router in $new_routers; do
389 + /sbin/ip route add default via $router
391 + if [ -n "$new_static_routes" ]; then
392 + set -- $new_static_routes
393 + while [ $# -gt 1 ]; do
394 + /sbin/ip route add $1 via $2
402 + /sbin/ip addr del $new_ip_address/$new_subnet_arg dev $interface
403 + for router in $old_routers; do
404 + /sbin/ip route del default via $router
406 + if [ -n "$old_static_routes" ]; then
407 + set -- $old_static_routes
408 + while [ $# -gt 1 ]; do
409 + /sbin/ip route del $1 via $2