revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / dhcp / client / scripts / freebsd
blobb76f467fcdc2456f29f845cc0b5baacc3ff93fe9
1 #!/bin/sh
3 # $Id: freebsd,v 1.1.1.1 2005/12/07 10:50:31 sonic_amiga Exp $
5 # $FreeBSD$
7 if [ -x /usr/bin/logger ]; then
8 LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
9 else
10 LOGGER=echo
13 make_resolv_conf() {
14 if [ x"$new_domain_name_servers" != x ]; then
15 if [ "x$new_domain_name" != x ]; then
16 ( echo search $new_domain_name >/etc/resolv.conf )
17 exit_status=$?
18 else
19 if [ -e /etc/resolv.conf ] ; then
20 ( rm /etc/resolv.conf )
21 exit_status=$?
22 else
23 ( touch /etc/resolv.conf )
24 exit_status=$?
27 if [ $exit_status -ne 0 ]; then
28 $LOGGER "WARNING: Unable to update resolv.conf: Error $exit_status"
29 else
30 for nameserver in $new_domain_name_servers; do
31 ( echo nameserver $nameserver >>/etc/resolv.conf )
32 done
37 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
38 exit_with_hooks() {
39 exit_status=$1
40 if [ -f /etc/dhclient-exit-hooks ]; then
41 . /etc/dhclient-exit-hooks
43 # probably should do something with exit status of the local script
44 exit $exit_status
47 # Invoke the local dhcp client enter hooks, if they exist.
48 if [ -f /etc/dhclient-enter-hooks ]; then
49 exit_status=0
50 . /etc/dhclient-enter-hooks
51 # allow the local script to abort processing of this state
52 # local script must set exit_status variable to nonzero.
53 if [ $exit_status -ne 0 ]; then
54 exit $exit_status
58 if [ x$new_network_number != x ]; then
59 $LOGGER New Network Number: $new_network_number
62 if [ x$new_broadcast_address != x ]; then
63 $LOGGER New Broadcast Address: $new_broadcast_address
64 new_broadcast_arg="broadcast $new_broadcast_address"
66 if [ x$old_broadcast_address != x ]; then
67 old_broadcast_arg="broadcast $old_broadcast_address"
69 if [ x$new_subnet_mask != x ]; then
70 new_netmask_arg="netmask $new_subnet_mask"
72 if [ x$old_subnet_mask != x ]; then
73 old_netmask_arg="netmask $old_subnet_mask"
75 if [ x$alias_subnet_mask != x ]; then
76 alias_subnet_arg="netmask $alias_subnet_mask"
79 if [ x$reason = xMEDIUM ]; then
80 eval "ifconfig $interface $medium"
81 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
82 sleep 1
83 exit_with_hooks 0
86 if [ x$reason = xPREINIT ]; then
87 if [ x$alias_ip_address != x ]; 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 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
92 broadcast 255.255.255.255 up
93 exit_with_hooks 0
96 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
97 exit_with_hooks 0;
100 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
101 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
102 current_hostname=`/bin/hostname`
103 if [ x$current_hostname = x ] || \
104 [ x$current_hostname = x$old_host_name ]; then
105 if [ x$current_hostname = x ] || \
106 [ x$new_host_name != x$old_host_name ]; then
107 $LOGGER "New Hostname: $new_host_name"
108 hostname $new_host_name
111 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
112 [ x$alias_ip_address != x$old_ip_address ]; then
113 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
114 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
116 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
117 then
118 eval "ifconfig $interface inet -alias $old_ip_address $medium"
119 route delete $old_ip_address 127.1 >/dev/null 2>&1
120 for router in $old_routers; do
121 route delete default $router >/dev/null 2>&1
122 done
123 if [ -n "$old_static_routes" ]; then
124 set -- $old_static_routes
125 while [ $# -gt 1 ]; do
126 route delete $1 $2
127 shift; shift
128 done
130 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
132 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
133 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
134 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
135 $new_broadcast_arg $medium"
136 $LOGGER "New IP Address ($interface): $new_ip_address"
137 $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
138 $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
139 if [ -n "$new_routers" ]; then
140 $LOGGER "New Routers: $new_routers"
142 route add $new_ip_address 127.1 >/dev/null 2>&1
143 for router in $new_routers; do
144 route add default $router >/dev/null 2>&1
145 done
146 if [ -n "$new_static_routes" ]; then
147 $LOGGER "New Static Routes: $new_static_routes"
148 set -- $new_static_routes
149 while [ $# -gt 1 ]; do
150 route add $1 $2
151 shift; shift
152 done
155 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
156 then
157 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
158 route add $alias_ip_address 127.0.0.1
160 make_resolv_conf
161 exit_with_hooks 0
164 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
165 || [ x$reason = xSTOP ]; then
166 if [ x$alias_ip_address != x ]; then
167 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
168 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
170 if [ x$old_ip_address != x ]; then
171 eval "ifconfig $interface inet -alias $old_ip_address $medium"
172 route delete $old_ip_address 127.1 >/dev/null 2>&1
173 for router in $old_routers; do
174 route delete default $router >/dev/null 2>&1
175 done
176 if [ -n "$old_static_routes" ]; then
177 set -- $old_static_routes
178 while [ $# -gt 1 ]; do
179 route delete $1 $2
180 shift; shift
181 done
183 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
184 |sh >/dev/null 2>&1
186 if [ x$alias_ip_address != x ]; then
187 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
188 route add $alias_ip_address 127.0.0.1
190 exit_with_hooks 0
193 if [ x$reason = xTIMEOUT ]; then
194 if [ x$alias_ip_address != x ]; then
195 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
196 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
198 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
199 $new_broadcast_arg $medium"
200 $LOGGER "New IP Address ($interface): $new_ip_address"
201 $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
202 $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
203 sleep 1
204 if [ -n "$new_routers" ]; then
205 $LOGGER "New Routers: $new_routers"
206 set -- $new_routers
207 if ping -q -c 1 $1; then
208 if [ x$new_ip_address != x$alias_ip_address ] && \
209 [ x$alias_ip_address != x ]; then
210 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
211 route add $alias_ip_address 127.0.0.1
213 route add $new_ip_address 127.1 >/dev/null 2>&1
214 for router in $new_routers; do
215 route add default $router >/dev/null 2>&1
216 done
217 set -- $new_static_routes
218 while [ $# -gt 1 ]; do
219 route add $1 $2
220 shift; shift
221 done
222 make_resolv_conf
223 exit_with_hooks 0
226 eval "ifconfig $interface inet -alias $new_ip_address $medium"
227 for router in $old_routers; do
228 route delete default $router >/dev/null 2>&1
229 done
230 if [ -n "$old_static_routes" ]; then
231 set -- $old_static_routes
232 while [ $# -gt 1 ]; do
233 route delete $1 $2
234 shift; shift
235 done
237 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
238 |sh >/dev/null 2>&1
239 exit_with_hooks 1
242 exit_with_hooks 0