Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / dhcp / client / scripts / bsdos
blobd076d92d01f14243ad2b2c360ca0e344f849ddee
1 #!/bin/sh
3 make_resolv_conf() {
4 if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
5 echo search $new_domain_name >/etc/resolv.conf
6 for nameserver in $new_domain_name_servers; do
7 echo nameserver $nameserver >>/etc/resolv.conf
8 done
9 fi
12 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
13 exit_with_hooks() {
14 exit_status=$1
15 if [ -f /etc/dhclient-exit-hooks ]; then
16 . /etc/dhclient-exit-hooks
18 # probably should do something with exit status of the local script
19 exit $exit_status
22 # Invoke the local dhcp client enter hooks, if they exist.
23 if [ -f /etc/dhclient-enter-hooks ]; then
24 exit_status=0
25 . /etc/dhclient-enter-hooks
26 # allow the local script to abort processing of this state
27 # local script must set exit_status variable to nonzero.
28 if [ $exit_status -ne 0 ]; then
29 exit $exit_status
33 if [ x$new_network_number != x ]; then
34 echo New Network Number: $new_network_number
37 if [ x$new_broadcast_address != x ]; then
38 echo New Broadcast Address: $new_broadcast_address
39 new_broadcast_arg="broadcast $new_broadcast_address"
41 if [ x$old_broadcast_address != x ]; then
42 old_broadcast_arg="broadcast $old_broadcast_address"
44 if [ x$new_subnet_mask != x ]; then
45 new_netmask_arg="netmask $new_subnet_mask"
47 if [ x$old_subnet_mask != x ]; then
48 old_netmask_arg="netmask $old_subnet_mask"
50 if [ x$alias_subnet_mask != x ]; then
51 alias_subnet_arg="netmask $alias_subnet_mask"
54 if [ x$reason = xMEDIUM ]; then
55 eval "ifconfig $interface $medium"
56 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
57 sleep 1
58 exit_with_hooks 0
61 if [ x$reason = xPREINIT ]; then
62 if [ x$alias_ip_address != x ]; then
63 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
64 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
66 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
67 broadcast 255.255.255.255 up
68 exit_with_hooks 0
71 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
72 exit_with_hooks 0;
75 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
76 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
77 current_hostname=`hostname`
78 if [ x$current_hostname = x ] || \
79 [ x$current_hostname = x$old_host_name ]; then
80 if [ x$current_hostname = x ] || \
81 [ x$new_host_name != x$old_host_name ]; then
82 hostname $new_host_name
86 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
87 [ x$alias_ip_address != x$old_ip_address ]; then
88 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
89 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
91 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
92 then
93 eval "ifconfig $interface inet -alias $old_ip_address $medium"
94 route delete $old_ip_address 127.1 >/dev/null 2>&1
95 for router in $old_routers; do
96 route delete default $router >/dev/null 2>&1
97 done
98 if [ "$old_static_routes" != "" ]; then
99 set $old_static_routes
100 while [ $# -gt 1 ]; do
101 route delete $1 $2
102 shift; shift
103 done
105 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' |sh
107 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
108 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
109 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
110 $new_broadcast_arg $medium"
111 route add $new_ip_address 127.1 >/dev/null 2>&1
112 for router in $new_routers; do
113 route add default $router >/dev/null 2>&1
114 done
115 if [ "$new_static_routes" != "" ]; then
116 set $new_static_routes
117 while [ $# -gt 1 ]; do
118 route add $1 $2
119 shift; shift
120 done
123 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
124 then
125 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
126 route add $alias_ip_address 127.0.0.1
128 make_resolv_conf
129 exit_with_hooks 0
132 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
133 || [ x$reason = xSTOP ]; then
134 if [ x$alias_ip_address != x ]; then
135 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
136 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
138 if [ x$old_ip_address != x ]; then
139 eval "ifconfig $interface inet -alias $old_ip_address $medium"
140 route delete $old_ip_address 127.1 >/dev/null 2>&1
141 for router in $old_routers; do
142 route delete default $router >/dev/null 2>&1
143 done
144 if [ "$old_static_routes" != "" ]; then
145 set $old_static_routes
146 while [ $# -gt 1 ]; do
147 route delete $1 $2
148 shift; shift
149 done
151 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
152 |sh >/dev/null 2>&1
154 if [ x$alias_ip_address != x ]; then
155 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
156 route add $alias_ip_address 127.0.0.1
158 exit_with_hooks 0
161 if [ x$reason = xTIMEOUT ]; then
162 if [ x$alias_ip_address != x ]; then
163 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
164 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
166 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
167 $new_broadcast_arg $medium"
168 sleep 1
169 if [ "$new_routers" != "" ]; then
170 set $new_routers
171 if ping -q -c 1 -w 1 $1; then
172 if [ x$new_ip_address != x$alias_ip_address ] && \
173 [ x$alias_ip_address != x ]; then
174 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
175 route add $alias_ip_address 127.0.0.1
177 route add $new_ip_address 127.1 >/dev/null 2>&1
178 for router in $new_routers; do
179 route add default $router >/dev/null 2>&1
180 done
181 set $new_static_routes
182 while [ $# -gt 1 ]; do
183 route add $0 $1
184 shift; shift
185 done
186 make_resolv_conf
187 exit_with_hooks 0
190 eval "ifconfig $interface inet -alias $new_ip_address $medium"
191 for router in $old_routers; do
192 route delete default $router >/dev/null 2>&1
193 done
194 if [ "$old_static_routes" != "" ]; then
195 set $old_static_routes
196 while [ $# -gt 1 ]; do
197 route delete $1 $2
198 shift; shift
199 done
201 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
202 |sh >/dev/null 2>&1
203 exit_with_hooks 1
206 exit_with_hooks 0