wok view udhcpc6-fake/stuff/etc/dhclient-script @ rev 7145

Add udhcpc6-fake
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 06 16:08:43 2010 +0100 (2010-11-06)
parents
children 02c70d036ea0
line source
1 #!/bin/ash
3 # dhclient-script for Linux. Dan Halbert, March, 1997.
4 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
5 # Modified for Debian. Matt Zimmerman and Eloy Paris, December 2003
6 # Modified to remove useless tests for antiquated kernel versions that
7 # this doesn't even work with anyway, and introduces a dependency on /usr
8 # being mounted, which causes cosmetic errors on hosts that NFS mount /usr
9 # Andrew Pollock, February 2005
10 # Modified to work on point-to-point links. Andrew Pollock, June 2005
11 # Modified to support passing the parameters called with to the hooks. Andrew Pollock, November 2005
13 # The alias handling in here probably still sucks. -mdz
15 make_resolv_conf() {
16 if [ -n "$new_domain_name" -o -n "$new_domain_name_servers" ]; then
17 # Find out whether we are going to mount / rw
18 exec 9>&0 </etc/fstab
19 rootmode=rw
20 while read dev mnt type opts dump pass junk; do
21 [ "$mnt" != / ] && continue
22 case "$opts" in
23 ro|ro,*|*,ro|*,ro,*)
24 rootmode=ro
25 ;;
26 esac
27 done
28 exec 0>&9 9>&-
30 # Wait for /etc/resolv.conf to become writable
31 if [ "$rootmode" = "rw" ]; then
32 while [ ! -w /etc ]; do
33 sleep 1
34 done
35 fi
37 local new_resolv_conf=/etc/resolv.conf.dhclient-new
38 rm -f $new_resolv_conf
39 if [ -n "$new_domain_name" ]; then
40 echo search $new_domain_name >>$new_resolv_conf
41 else # keep 'old' search/domain scope
42 egrep -i '^ *[:space:]*(search|domain)' /etc/resolv.conf >> $new_resolv_conf
43 fi
44 if [ -n "$new_domain_name_servers" ]; then
45 for nameserver in $new_domain_name_servers; do
46 echo nameserver $nameserver >>$new_resolv_conf
47 done
48 else # keep 'old' nameservers
49 sed -n /^\w*[Nn][Aa][Mm][Ee][Ss][Ee][Rr][Vv][Ee][Rr]/p /etc/resolv.conf >>$new_resolv_conf
50 fi
51 chown root.root $new_resolv_conf
52 chmod 644 $new_resolv_conf
53 mv -f $new_resolv_conf /etc/resolv.conf
54 fi
55 }
57 run_hook() {
58 local script="$1"
59 local exit_status
60 shift # discard the first argument, then the rest are the script's
62 if [ -f $script ]; then
63 . $script "$@"
64 fi
67 if [ -n "$exit_status" ] && [ "$exit_status" -ne 0 ]; then
68 logger -p daemon.err "$script returned non-zero exit status $exit_status"
69 save_exit_status=$exit_status
70 fi
72 return $exit_status
73 }
75 run_hookdir() {
76 local dir="$1"
77 local exit_status
78 shift # See run_hook
80 if [ -d "$dir" ]; then
81 for script in $(run-parts --list $dir); do
82 run_hook $script "$@" || true
83 exit_status=$?
84 done
85 fi
87 return $exit_status
88 }
90 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
91 exit_with_hooks() {
92 exit_status=$1
94 # Source the documented exit-hook script, if it exists
95 if ! run_hook /etc/dhcp3/dhclient-exit-hooks "$@"; then
96 exit_status=$?
97 fi
99 # Now run scripts in the Debian-specific directory.
100 if ! run_hookdir /etc/dhcp3/dhclient-exit-hooks.d "$@"; then
101 exit_status=$?
102 fi
104 exit $exit_status
105 }
107 set_hostname() {
108 local current_hostname=$(hostname)
109 if [ -z "$current_hostname" -o "$current_hostname" = "(none)" ]; then
110 hostname "$new_host_name"
111 fi
112 }
114 if [ -n "$new_broadcast_address" ]; then
115 new_broadcast_arg="broadcast $new_broadcast_address"
116 fi
117 if [ -n "$old_broadcast_address" ]; then
118 old_broadcast_arg="broadcast $old_broadcast_address"
119 fi
120 if [ -n "$new_subnet_mask" ]; then
121 new_subnet_arg="netmask $new_subnet_mask"
122 fi
123 if [ -n "$old_subnet_mask" ]; then
124 old_subnet_arg="netmask $old_subnet_mask"
125 fi
126 if [ -n "$alias_subnet_mask" ]; then
127 alias_subnet_arg="netmask $alias_subnet_mask"
128 fi
129 if [ -n "$new_interface_mtu" ] && [ $new_interface_mtu -ge 575 ]; then
130 mtu_arg="mtu $new_interface_mtu"
131 fi
132 if [ -n "$IF_METRIC" ]; then
133 metric_arg="metric $IF_METRIC" # interfaces(5), "metric" option
134 fi
137 # The action starts here
139 # Invoke the local dhcp client enter hooks, if they exist.
140 run_hook /etc/dhcp3/dhclient-enter-hooks
141 run_hookdir /etc/dhcp3/dhclient-enter-hooks.d
143 # Execute the operation
144 case "$reason" in
145 MEDIUM|ARPCHECK|ARPSEND)
146 # Do nothing
147 ;;
148 PREINIT)
149 # The DHCP client is requesting that an interface be
150 # configured as required in order to send packets prior to
151 # receiving an actual address. - dhclient-script(8)
153 if [ -n "$alias_ip_address" ]; then
154 # Bring down alias interface. Its routes will disappear too.
155 ifconfig $interface:0- inet 0
156 fi
157 ifconfig $interface inet 0 up
159 # We need to give the kernel some time to get the interface up.
160 sleep 1
161 ;;
162 BOUND|RENEW|REBIND|REBOOT)
164 set_hostname
166 if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
167 "$alias_ip_address" != "$old_ip_address" ]; then
168 # Possible new alias. Remove old alias.
169 ifconfig $interface:0- inet 0
170 fi
172 if [ -n "$old_ip_address" -a \
173 "$old_ip_address" != "$new_ip_address" ]; then
174 # IP address changed. Bringing down the interface will delete all routes,
175 # and clear the ARP cache.
176 ifconfig $interface inet 0
178 fi
180 if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
181 "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
183 ifconfig $interface inet $new_ip_address $new_subnet_arg \
184 $new_broadcast_arg $mtu_arg
186 # point to point
187 if [ "$new_subnet_mask" == "255.255.255.255" ]; then
188 for router in $new_routers; do
189 route add -host $router dev $interface
190 done
191 fi
193 for router in $new_routers; do
194 route add default dev $interface gw $router $metric_arg
195 done
196 fi
198 if [ "$new_ip_address" != "$alias_ip_address" -a -n "$alias_ip_address" ];
199 then
200 ifconfig $interface:0- inet 0
201 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
202 route add -host $alias_ip_address $interface:0
203 fi
205 make_resolv_conf
207 ;;
209 EXPIRE|FAIL|RELEASE|STOP)
210 if [ -n "$alias_ip_address" ]; then
211 # Turn off alias interface.
212 ifconfig $interface:0- inet 0
213 fi
215 if [ -n "$old_ip_address" ]; then
216 # Shut down interface, which will delete routes and clear arp cache.
217 ifconfig $interface inet 0
218 fi
220 if [ -n "$alias_ip_address" ]; then
221 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
222 route add -host $alias_ip_address $interface:0
223 fi
225 ;;
227 TIMEOUT)
228 if [ -n "$alias_ip_address" ]; then
229 ifconfig $interface:0- inet 0
230 fi
232 ifconfig $interface inet $new_ip_address $new_subnet_arg \
233 $new_broadcast_arg $mtu_arg
235 set -- $new_routers
236 first_router="$1"
238 if ping -q -c 1 $first_router; then
239 if [ "$new_ip_address" != "$alias_ip_address" -a \
240 -n "$alias_ip_address" ]; then
241 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
242 route add -host $alias_ip_address dev $interface:0
243 fi
245 # point to point
246 if [ "$new_subnet_mask" == "255.255.255.255" ]; then
247 for router in $new_routers; do
248 route add -host $router dev $interface
249 done
250 fi
252 for router in $new_routers; do
253 route add default dev $interface gw $router $metric_arg
254 done
256 make_resolv_conf
257 else
258 # Changed from 'ifconfig $interface inet 0 down' - see Debian bug #144666
259 ifconfig $interface inet 0
260 exit_with_hooks 2 "$@"
261 fi
263 ;;
264 esac
266 exit_with_hooks 0