]> git.ipfire.org Git - thirdparty/dhcp.git/blame - client/scripts/netbsd
- Duplicate dhclient-script updates for DHCPv6 to all provided scripts.
[thirdparty/dhcp.git] / client / scripts / netbsd
CommitLineData
b1d4116d
TL
1#!/bin/sh
2
8fddc394 3make_resolv_conf() {
d758ad8c 4 if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
dba5803b
DH
5 cat /dev/null > /etc/resolv.conf.dhclient
6 if [ "x$new_domain_search != x ]; then
7 echo search $new_domain_search >> /etc/resolv.conf.dhclient
8 elif [ "x$new_domain_name != x ]; then
9 # Note that the DHCP 'Domain Name Option' is really just a domain
10 # name, and that this practice of using the domain name option as
11 # a search path is both nonstandard and deprecated.
12 echo search $new_domain_name >> /etc/resolv.conf.dhclient
13 fi
d758ad8c 14 for nameserver in $new_domain_name_servers; do
dba5803b 15 echo nameserver $nameserver >>/etc/resolv.conf.dhclient
d758ad8c 16 done
dba5803b
DH
17
18 mv /etc/resolv.conf.dhclient /etc/resolv.conf
f66f02cc
DH
19 elif [ "x${new_dhcp6_name_servers}" != x ] ; then
20 cat /dev/null > /etc/resolv.conf.dhclient6
21 chmod 644 /etc/resolv.conf.dhclient6
22
23 if [ "x${new_dhcp6_domain_search}" != x ] ; then
24 echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
25 fi
26 for nameserver in ${new_dhcp6_name_servers} ; do
27 echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
28 done
29
30 mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
d758ad8c 31 fi
8fddc394
TL
32}
33
34# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
35exit_with_hooks() {
36 exit_status=$1
06fa897b 37 if [ -f /etc/dhclient-exit-hooks ]; then
8fddc394
TL
38 . /etc/dhclient-exit-hooks
39 fi
40# probably should do something with exit status of the local script
41 exit $exit_status
42}
43
44# Invoke the local dhcp client enter hooks, if they exist.
06fa897b 45if [ -f /etc/dhclient-enter-hooks ]; then
8fddc394
TL
46 exit_status=0
47 . /etc/dhclient-enter-hooks
48 # allow the local script to abort processing of this state
49 # local script must set exit_status variable to nonzero.
50 if [ $exit_status -ne 0 ]; then
51 exit $exit_status
52 fi
53fi
54
bdaa711a
TL
55if [ x$new_network_number != x ]; then
56 echo New Network Number: $new_network_number
57fi
58
64833bc4 59if [ x$new_broadcast_address != x ]; then
bdaa711a 60 echo New Broadcast Address: $new_broadcast_address
64833bc4
TL
61 new_broadcast_arg="broadcast $new_broadcast_address"
62fi
63if [ x$old_broadcast_address != x ]; then
64 old_broadcast_arg="broadcast $old_broadcast_address"
65fi
66if [ x$new_subnet_mask != x ]; then
67 new_netmask_arg="netmask $new_subnet_mask"
68fi
69if [ x$old_subnet_mask != x ]; then
70 old_netmask_arg="netmask $old_subnet_mask"
71fi
72if [ x$alias_subnet_mask != x ]; then
73 alias_subnet_arg="netmask $alias_subnet_mask"
74fi
75
b1d4116d 76if [ x$reason = xMEDIUM ]; then
46b62638
TL
77 eval "ifconfig $interface $medium"
78 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
b1d4116d 79 sleep 1
8fddc394 80 exit_with_hooks 0
b1d4116d
TL
81fi
82
f66f02cc
DH
83###
84### DHCPv4 Handlers
85###
86
b1d4116d
TL
87if [ x$reason = xPREINIT ]; then
88 if [ x$alias_ip_address != x ]; then
89 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
90 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
91 fi
92 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
93 broadcast 255.255.255.255 up
8fddc394 94 exit_with_hooks 0
b1d4116d
TL
95fi
96
8fddc394
TL
97if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
98 exit_with_hooks 0
99fi
100
77967680
TL
101if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
102 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
9f56e437 103 current_hostname=`hostname`
2cd9d72c
TL
104 if [ x$current_hostname = x ] || \
105 [ x$current_hostname = x$old_host_name ]; then
9f56e437
TL
106 if [ x$current_hostname = x ] || \
107 [ x$new_host_name != x$old_host_name ]; then
2cd9d72c
TL
108 hostname $new_host_name
109 fi
110 fi
111
b1d4116d
TL
112 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
113 [ x$alias_ip_address != x$old_ip_address ]; then
114 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
115 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
116 fi
df6e15b7
TL
117 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
118 then
46b62638 119 eval "ifconfig $interface inet -alias $old_ip_address $medium"
b1d4116d
TL
120 route delete $old_ip_address 127.1 >/dev/null 2>&1
121 for router in $old_routers; do
122 route delete default $router >/dev/null 2>&1
123 done
bdaa711a
TL
124 if [ "$old_static_routes" != "" ]; then
125 set $old_static_routes
126 while [ $# -gt 1 ]; do
127 route delete $1 $2
128 shift; shift
129 done
130 fi
73694cd2 131 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' |sh
b1d4116d
TL
132 fi
133 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
77967680 134 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
46b62638
TL
135 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
136 $new_broadcast_arg $medium"
b1d4116d
TL
137 route add $new_ip_address 127.1 >/dev/null 2>&1
138 for router in $new_routers; do
139 route add default $router >/dev/null 2>&1
140 done
bdaa711a
TL
141 if [ "$new_static_routes" != "" ]; then
142 set $new_static_routes
143 while [ $# -gt 1 ]; do
144 route add $1 $2
145 shift; shift
146 done
147 fi
b1d4116d
TL
148 fi
149 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
150 then
64833bc4 151 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
b1d4116d
TL
152 route add $alias_ip_address 127.0.0.1
153 fi
8fddc394
TL
154 make_resolv_conf
155 exit_with_hooks 0
b1d4116d
TL
156fi
157
d758ad8c
TL
158if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
159 || [ x$reason = xSTOP ]; then
b1d4116d
TL
160 if [ x$alias_ip_address != x ]; then
161 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
162 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
163 fi
164 if [ x$old_ip_address != x ]; then
46b62638 165 eval "ifconfig $interface inet -alias $old_ip_address $medium"
b1d4116d
TL
166 route delete $old_ip_address 127.1 >/dev/null 2>&1
167 for router in $old_routers; do
168 route delete default $router >/dev/null 2>&1
169 done
bdaa711a
TL
170 if [ "$old_static_routes" != "" ]; then
171 set $old_static_routes
172 while [ $# -gt 1 ]; do
173 route delete $1 $2
174 shift; shift
175 done
176 fi
54010773 177 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
73694cd2 178 |sh >/dev/null 2>&1
b1d4116d
TL
179 fi
180 if [ x$alias_ip_address != x ]; then
64833bc4 181 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
b1d4116d
TL
182 route add $alias_ip_address 127.0.0.1
183 fi
8fddc394 184 exit_with_hooks 0
b1d4116d
TL
185fi
186
187if [ x$reason = xTIMEOUT ]; then
188 if [ x$alias_ip_address != x ]; then
189 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
190 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
191 fi
46b62638
TL
192 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
193 $new_broadcast_arg $medium"
73694cd2 194 sleep 1
bdaa711a
TL
195 if [ "$new_routers" != "" ]; then
196 set $new_routers
197 if ping -q -c 1 -w 1 $1; then
198 if [ x$new_ip_address != x$alias_ip_address ] && \
b1d4116d 199 [ x$alias_ip_address != x ]; then
bdaa711a
TL
200 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
201 route add $alias_ip_address 127.0.0.1
202 fi
203 route add $new_ip_address 127.1 >/dev/null 2>&1
204 for router in $new_routers; do
205 route add default $router >/dev/null 2>&1
206 done
207 set $new_static_routes
208 while [ $# -gt 1 ]; do
209 route add $0 $1
210 shift; shift
211 done
8fddc394
TL
212 make_resolv_conf
213 exit_with_hooks 0
b1d4116d 214 fi
5689130f 215 fi
46b62638 216 eval "ifconfig $interface inet -alias $new_ip_address $medium"
b1d4116d
TL
217 for router in $old_routers; do
218 route delete default $router >/dev/null 2>&1
219 done
bdaa711a
TL
220 if [ "$old_static_routes" != "" ]; then
221 set $old_static_routes
222 while [ $# -gt 1 ]; do
223 route delete $1 $2
224 shift; shift
225 done
226 fi
73694cd2
TL
227 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
228 |sh >/dev/null 2>&1
8fddc394 229 exit_with_hooks 1
b1d4116d
TL
230fi
231
f66f02cc
DH
232###
233### DHCPv6 Handlers
234###
235
236if [ ${reason} = PREINIT6 ] ; then
237 # Ensure interface is up.
238 ifconfig ${interface} up
239
240 # XXX: Remove any stale addresses from aborted clients.
241
242 exit_with_hooks 0
243fi
244
245if [ ${reason} = BOUND6 ] ; then
246 if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
247 exit_with_hooks 2;
248 fi
249
250 ifconfig ${interface} inet6 add ${new_ip6_address}/${new_ip6_prefixlen}
251
252 # Check for nameserver options.
253 make_resolv_conf
254
255 exit_with_hooks 0
256fi
257
258if [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then
259 # Make sure nothing has moved around on us.
260
261 # Nameservers/domains/etc.
262 if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
263 [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
264 make_resolv_conf
265 fi
266
267 exit_with_hooks 0
268fi
269
270if [ ${reason} = DEPREF6 ] ; then
271 if [ x${new_ip6_prefixlen} = x ] ; then
272 exit_with_hooks 2;
273 fi
274
275 # XXX:
276 # There doesn't appear to be a way to update an addr to indicate
277 # preference.
278
279 exit_with_hooks 0
280fi
281
282if [ ${reason} = EXPIRE6 ] ; then
283 if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
284 exit_with_hooks 2;
285 fi
286
287 ifconfig ${interface} inet6 delete ${old_ip6_address}/${old_ip6_prefixlen}
288
289 exit_with_hooks 0
290fi
291
8fddc394 292exit_with_hooks 0