3
# $Id: freebsd,v 1.22 2008/05/23 13:56:07 fdupont Exp $
7
if [ -x /usr/bin/logger ]; then
8
LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
14
if [ x"$new_domain_name_servers" != x ]; then
15
( cat /dev/null > /etc/resolv.conf.dhclient )
17
if [ $exit_status -ne 0 ]; then
18
$LOGGER "Unable to create /etc/resolv.conf.dhclient: Error $exit_status"
20
if [ "x$new_domain_search" != x ]; then
21
( echo search $new_domain_search >> /etc/resolv.conf.dhclient )
23
elif [ "x$new_domain_name" != x ]; then
24
# Note that the DHCP 'Domain Name Option' is really just a domain
25
# name, and that this practice of using the domain name option as
26
# a search path is both nonstandard and deprecated.
27
( echo search $new_domain_name >> /etc/resolv.conf.dhclient )
30
for nameserver in $new_domain_name_servers; do
31
if [ $exit_status -ne 0 ]; then
34
( echo nameserver $nameserver >>/etc/resolv.conf.dhclient )
38
# If there were no errors, attempt to mv the new file into place.
39
if [ $exit_status -eq 0 ]; then
40
( mv /etc/resolv.conf.dhclient /etc/resolv.conf )
44
if [ $exit_status -ne 0 ]; then
45
$LOGGER "Error while writing new /etc/resolv.conf."
48
elif [ "x${new_dhcp6_name_servers}" != x ] ; then
49
( cat /dev/null > /etc/resolv.conf.dhclient6 )
51
if [ $exit_status -ne 0 ] ; then
52
$LOGGER "Unable to create /etc/resolv.conf.dhclient6: Error $exit_status"
54
if [ "x${new_dhcp6_domain_search}" != x ] ; then
55
( echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6 )
58
for nameserver in ${new_dhcp6_name_servers} ; do
59
if [ $exit_status -ne 0 ] ; then
62
( echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6 )
66
if [ $exit_status -eq 0 ] ; then
67
( mv /etc/resolv.conf.dhclient6 /etc/resolv.conf )
71
if [ $exit_status -ne 0 ] ; then
72
$LOGGER "Error while writing new /etc/resolv.conf."
78
# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
81
if [ -f /etc/dhclient-exit-hooks ]; then
82
. /etc/dhclient-exit-hooks
84
# probably should do something with exit status of the local script
88
# Invoke the local dhcp client enter hooks, if they exist.
89
if [ -f /etc/dhclient-enter-hooks ]; then
91
. /etc/dhclient-enter-hooks
92
# allow the local script to abort processing of this state
93
# local script must set exit_status variable to nonzero.
94
if [ $exit_status -ne 0 ]; then
99
if [ x$new_network_number != x ]; then
100
$LOGGER New Network Number: $new_network_number
103
if [ x$new_broadcast_address != x ]; then
104
$LOGGER New Broadcast Address: $new_broadcast_address
105
new_broadcast_arg="broadcast $new_broadcast_address"
107
if [ x$old_broadcast_address != x ]; then
108
old_broadcast_arg="broadcast $old_broadcast_address"
110
if [ x$new_subnet_mask != x ]; then
111
new_netmask_arg="netmask $new_subnet_mask"
113
if [ x$old_subnet_mask != x ]; then
114
old_netmask_arg="netmask $old_subnet_mask"
116
if [ x$alias_subnet_mask != x ]; then
117
alias_subnet_arg="netmask $alias_subnet_mask"
120
if [ x$reason = xMEDIUM ]; then
121
eval "ifconfig $interface $medium"
122
eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
131
if [ x$reason = xPREINIT ]; then
132
if [ x$alias_ip_address != x ]; then
133
ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
134
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
136
ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
137
broadcast 255.255.255.255 up
141
if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
145
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
146
[ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
147
current_hostname=`/bin/hostname`
148
if [ x$current_hostname = x ] || \
149
[ x$current_hostname = x$old_host_name ]; then
150
if [ x$current_hostname = x ] || \
151
[ x$new_host_name != x$old_host_name ]; then
152
$LOGGER "New Hostname: $new_host_name"
153
hostname $new_host_name
156
if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
157
[ x$alias_ip_address != x$old_ip_address ]; then
158
ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
159
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
161
if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
163
eval "ifconfig $interface inet -alias $old_ip_address $medium"
164
route delete $old_ip_address 127.1 >/dev/null 2>&1
165
for router in $old_routers; do
166
route delete default $router >/dev/null 2>&1
168
if [ -n "$old_static_routes" ]; then
169
set -- $old_static_routes
170
while [ $# -gt 1 ]; do
175
arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
177
if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
178
[ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
179
eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
180
$new_broadcast_arg $medium"
181
$LOGGER "New IP Address ($interface): $new_ip_address"
182
$LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
183
$LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
184
if [ -n "$new_routers" ]; then
185
$LOGGER "New Routers: $new_routers"
187
route add $new_ip_address 127.1 >/dev/null 2>&1
188
for router in $new_routers; do
189
# If the subnet is captive, eg the netmask is /32 but the default
190
# gateway is (obviously) outside of this, then we need to produce a
191
# host route to reach the gateway.
192
if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
193
route add -host $router -interface $interface
195
route add default $router >/dev/null 2>&1
197
if [ -n "$new_static_routes" ]; then
198
$LOGGER "New Static Routes: $new_static_routes"
199
set -- $new_static_routes
200
while [ $# -gt 1 ]; do
206
if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
208
ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
209
route add $alias_ip_address 127.0.0.1
215
if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
216
|| [ x$reason = xSTOP ]; then
217
if [ x$alias_ip_address != x ]; then
218
ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
219
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
221
if [ x$old_ip_address != x ]; then
222
eval "ifconfig $interface inet -alias $old_ip_address $medium"
223
route delete $old_ip_address 127.1 >/dev/null 2>&1
224
for router in $old_routers; do
225
route delete default $router >/dev/null 2>&1
227
if [ -n "$old_static_routes" ]; then
228
set -- $old_static_routes
229
while [ $# -gt 1 ]; do
234
arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
237
if [ x$alias_ip_address != x ]; then
238
ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
239
route add $alias_ip_address 127.0.0.1
244
if [ x$reason = xTIMEOUT ]; then
245
if [ x$alias_ip_address != x ]; then
246
ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
247
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
249
eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
250
$new_broadcast_arg $medium"
251
$LOGGER "New IP Address ($interface): $new_ip_address"
252
$LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
253
$LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
255
if [ -n "$new_routers" ]; then
256
$LOGGER "New Routers: $new_routers"
258
if ping -q -c 1 $1; then
259
if [ x$new_ip_address != x$alias_ip_address ] && \
260
[ x$alias_ip_address != x ]; then
261
ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
262
route add $alias_ip_address 127.0.0.1
264
route add $new_ip_address 127.1 >/dev/null 2>&1
265
for router in $new_routers; do
266
if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
267
route add -host $router -interface $interface
269
route add default $router >/dev/null 2>&1
271
set -- $new_static_routes
272
while [ $# -gt 1 ]; do
280
eval "ifconfig $interface inet -alias $new_ip_address $medium"
281
for router in $old_routers; do
282
route delete default $router >/dev/null 2>&1
284
if [ -n "$old_static_routes" ]; then
285
set -- $old_static_routes
286
while [ $# -gt 1 ]; do
291
arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
300
if [ ${reason} = PREINIT6 ] ; then
301
# Ensure interface is up.
302
ifconfig ${interface} up
304
# XXX: Remove any stale addresses from aborted clients.
309
if [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then
310
echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix}
315
if [ ${reason} = BOUND6 ] ; then
316
if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
320
ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias
322
# Check for nameserver options.
328
if [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then
329
# Make sure nothing has moved around on us.
331
# Nameservers/domains/etc.
332
if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
333
[ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
340
if [ ${reason} = DEPREF6 ] ; then
341
if [ x${new_ip6_address} = x ] ; then
345
ifconfig ${interface} inet6 ${new_ip6_address} deprecated
350
if [ ${reason} = EXPIRE6 -o ${reason} = RELEASE6 -o ${reason} = STOP6 ] ; then
351
if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
355
ifconfig ${interface} inet6 ${old_ip6_address}/${old_ip6_prefixlen} -alias