Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / dhcp / client / scripts / linux
blob31ddd2fece0a713b5117e31d71121622754aff50
1 #!/bin/bash
2 # dhclient-script for Linux. Dan Halbert, March, 1997.
3 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
4 # No guarantees about this. I'm a novice at the details of Linux
5 # networking.
7 # Notes:
9 # 0. This script is based on the netbsd script supplied with dhcp-970306.
11 # 1. ifconfig down apparently deletes all relevant routes and flushes
12 # the arp cache, so this doesn't need to be done explicitly.
14 # 2. The alias address handling here has not been tested AT ALL.
15 # I'm just going by the doc of modern Linux ip aliasing, which uses
16 # notations like eth0:0, eth0:1, for each alias.
18 # 3. I have to calculate the network address, and calculate the broadcast
19 # address if it is not supplied. This might be much more easily done
20 # by the dhclient C code, and passed on.
22 # 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
23 # of the $1 in its args.
25 make_resolv_conf() {
26 if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
27 echo search $new_domain_name >/etc/resolv.conf
28 chmod 644 /etc/resolv.conf
29 for nameserver in $new_domain_name_servers; do
30 echo nameserver $nameserver >>/etc/resolv.conf
31 done
35 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
36 exit_with_hooks() {
37 exit_status=$1
38 if [ -f /etc/dhclient-exit-hooks ]; then
39 . /etc/dhclient-exit-hooks
41 # probably should do something with exit status of the local script
42 exit $exit_status
45 # Invoke the local dhcp client enter hooks, if they exist.
46 if [ -f /etc/dhclient-enter-hooks ]; then
47 exit_status=0
48 . /etc/dhclient-enter-hooks
49 # allow the local script to abort processing of this state
50 # local script must set exit_status variable to nonzero.
51 if [ $exit_status -ne 0 ]; then
52 exit $exit_status
56 release=`uname -r`
57 release=`expr $release : '\(.*\)\..*'`
58 relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
59 relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
61 if [ x$new_broadcast_address != x ]; then
62 new_broadcast_arg="broadcast $new_broadcast_address"
64 if [ x$old_broadcast_address != x ]; then
65 old_broadcast_arg="broadcast $old_broadcast_address"
67 if [ x$new_subnet_mask != x ]; then
68 new_subnet_arg="netmask $new_subnet_mask"
70 if [ x$old_subnet_mask != x ]; then
71 old_subnet_arg="netmask $old_subnet_mask"
73 if [ x$alias_subnet_mask != x ]; then
74 alias_subnet_arg="netmask $alias_subnet_mask"
77 if [ x$reason = xMEDIUM ]; then
78 # Linux doesn't do mediums (ok, ok, media).
79 exit_with_hooks 0
82 if [ x$reason = xPREINIT ]; then
83 if [ x$alias_ip_address != x ]; then
84 # Bring down alias interface. Its routes will disappear too.
85 ifconfig $interface:0- inet 0
87 if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
88 then
89 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
90 broadcast 255.255.255.255 up
91 # Add route to make broadcast work. Do not omit netmask.
92 route add default dev $interface netmask 0.0.0.0
93 else
94 ifconfig $interface 0 up
97 # We need to give the kernel some time to get the interface up.
98 sleep 1
100 exit_with_hooks 0
103 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
104 exit_with_hooks 0
107 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
108 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
109 current_hostname=`hostname`
110 if [ x$current_hostname = x ] || \
111 [ x$current_hostname = x$old_host_name ]; then
112 if [ x$current_hostname = x ] || \
113 [ x$new_host_name != x$old_host_name ]; then
114 hostname $new_host_name
118 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
119 [ x$alias_ip_address != x$old_ip_address ]; then
120 # Possible new alias. Remove old alias.
121 ifconfig $interface:0- inet 0
123 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
124 # IP address changed. Bringing down the interface will delete all routes,
125 # and clear the ARP cache.
126 ifconfig $interface inet 0 down
129 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
130 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
132 ifconfig $interface inet $new_ip_address $new_subnet_arg \
133 $new_broadcast_arg
134 # Add a network route to the computed network address.
135 if [ $relmajor -lt 2 ] || \
136 ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
137 route add -net $new_network_number $new_subnet_arg dev $interface
139 for router in $new_routers; do
140 route add default gw $router
141 done
143 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
144 then
145 ifconfig $interface:0- inet 0
146 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
147 route add -host $alias_ip_address $interface:0
149 make_resolv_conf
150 exit_with_hooks 0
153 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
154 || [ x$reason = xSTOP ]; then
155 if [ x$alias_ip_address != x ]; then
156 # Turn off alias interface.
157 ifconfig $interface:0- inet 0
159 if [ x$old_ip_address != x ]; then
160 # Shut down interface, which will delete routes and clear arp cache.
161 ifconfig $interface inet 0 down
163 if [ x$alias_ip_address != x ]; then
164 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
165 route add -host $alias_ip_address $interface:0
167 exit_with_hooks 0
170 if [ x$reason = xTIMEOUT ]; then
171 if [ x$alias_ip_address != x ]; then
172 ifconfig $interface:0- inet 0
174 ifconfig $interface inet $new_ip_address $new_subnet_arg \
175 $new_broadcast_arg
176 set $new_routers
177 ############## what is -w in ping?
178 if ping -q -c 1 $1; then
179 if [ x$new_ip_address != x$alias_ip_address ] && \
180 [ x$alias_ip_address != x ]; then
181 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
182 route add -host $alias_ip_address dev $interface:0
184 if [ $relmajor -lt 2 ] || \
185 ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
186 route add -net $new_network_number
188 for router in $new_routers; do
189 route add default gw $router
190 done
191 make_resolv_conf
192 exit_with_hooks 0
194 ifconfig $interface inet 0 down
195 exit_with_hooks 1
198 exit_with_hooks 0