3 # $Id: freebsd,v 1.13.2.4 2002/06/09 22:37:55 murray Exp $
5 # $FreeBSD: src/contrib/isc-dhcp/client/scripts/freebsd,v 1.9.2.6 2003/03/02 16:42:38 murray 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 if [ "x$new_domain_name" != x ]; then
16 echo search $new_domain_name >/etc/resolv.conf
20 for nameserver in $new_domain_name_servers; do
21 echo nameserver $nameserver >>/etc/resolv.conf
26 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
29 if [ -f /etc/dhclient-exit-hooks ]; then
30 . /etc/dhclient-exit-hooks
32 # probably should do something with exit status of the local script
36 # Invoke the local dhcp client enter hooks, if they exist.
37 if [ -f /etc/dhclient-enter-hooks ]; then
39 . /etc/dhclient-enter-hooks
40 # allow the local script to abort processing of this state
41 # local script must set exit_status variable to nonzero.
42 if [ $exit_status -ne 0 ]; then
47 if [ x$new_network_number != x ]; then
48 $LOGGER New Network Number: $new_network_number
51 if [ x$new_broadcast_address != x ]; then
52 $LOGGER New Broadcast Address: $new_broadcast_address
53 new_broadcast_arg="broadcast $new_broadcast_address"
55 if [ x$old_broadcast_address != x ]; then
56 old_broadcast_arg="broadcast $old_broadcast_address"
58 if [ x$new_subnet_mask != x ]; then
59 new_netmask_arg="netmask $new_subnet_mask"
61 if [ x$old_subnet_mask != x ]; then
62 old_netmask_arg="netmask $old_subnet_mask"
64 if [ x$alias_subnet_mask != x ]; then
65 alias_subnet_arg="netmask $alias_subnet_mask"
68 if [ x$reason = xMEDIUM ]; then
69 eval "ifconfig $interface $medium"
70 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
75 if [ x$reason = xPREINIT ]; then
76 if [ x$alias_ip_address != x ]; then
77 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
78 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
80 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
81 broadcast 255.255.255.255 up
85 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
89 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
90 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
91 current_hostname=`/bin/hostname`
92 if [ x$current_hostname = x ] || \
93 [ x$current_hostname = x$old_host_name ]; then
94 if [ x$current_hostname = x ] || \
95 [ x$new_host_name != x$old_host_name ]; then
96 $LOGGER "New Hostname: $new_host_name"
97 hostname $new_host_name
100 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
101 [ x$alias_ip_address != x$old_ip_address ]; then
102 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
103 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
105 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
107 eval "ifconfig $interface inet -alias $old_ip_address $medium"
108 route delete $old_ip_address 127.1 >/dev/null 2>&1
109 for router in $old_routers; do
110 route delete default $router >/dev/null 2>&1
112 if [ -n "$old_static_routes" ]; then
113 set -- $old_static_routes
114 while [ $# -gt 1 ]; do
119 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
121 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
122 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
123 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
124 $new_broadcast_arg $medium"
125 $LOGGER "New IP Address ($interface): $new_ip_address"
126 $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
127 $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
128 if [ -n "$new_routers" ]; then
129 $LOGGER "New Routers: $new_routers"
131 route add $new_ip_address 127.1 >/dev/null 2>&1
132 for router in $new_routers; do
133 route add default $router >/dev/null 2>&1
135 if [ -n "$new_static_routes" ]; then
136 $LOGGER "New Static Routes: $new_static_routes"
137 set -- $new_static_routes
138 while [ $# -gt 1 ]; do
144 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
146 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
147 route add $alias_ip_address 127.0.0.1
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 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
157 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
159 if [ x$old_ip_address != x ]; then
160 eval "ifconfig $interface inet -alias $old_ip_address $medium"
161 route delete $old_ip_address 127.1 >/dev/null 2>&1
162 for router in $old_routers; do
163 route delete default $router >/dev/null 2>&1
165 if [ -n "$old_static_routes" ]; then
166 set -- $old_static_routes
167 while [ $# -gt 1 ]; do
172 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
175 if [ x$alias_ip_address != x ]; then
176 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
177 route add $alias_ip_address 127.0.0.1
182 if [ x$reason = xTIMEOUT ]; then
183 if [ x$alias_ip_address != x ]; then
184 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
185 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
187 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
188 $new_broadcast_arg $medium"
189 $LOGGER "New IP Address ($interface): $new_ip_address"
190 $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
191 $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
193 if [ -n "$new_routers" ]; then
194 $LOGGER "New Routers: $new_routers"
196 if ping -q -c 1 $1; then
197 if [ x$new_ip_address != x$alias_ip_address ] && \
198 [ x$alias_ip_address != x ]; then
199 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
200 route add $alias_ip_address 127.0.0.1
202 route add $new_ip_address 127.1 >/dev/null 2>&1
203 for router in $new_routers; do
204 route add default $router >/dev/null 2>&1
206 set -- $new_static_routes
207 while [ $# -gt 1 ]; do
215 eval "ifconfig $interface inet -alias $new_ip_address $medium"
216 for router in $old_routers; do
217 route delete default $router >/dev/null 2>&1
219 if [ -n "$old_static_routes" ]; then
220 set -- $old_static_routes
221 while [ $# -gt 1 ]; do
226 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \