]> git.ipfire.org Git - thirdparty/dhcp.git/blob - client/scripts/freebsd
Merge changes between 3.0rc7 and 3.0rc8pl2.
[thirdparty/dhcp.git] / client / scripts / freebsd
1 #!/bin/sh
2
3 if [ -x /usr/bin/logger ]; then
4 LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
5 else
6 LOGGER=echo
7 fi
8
9 make_resolv_conf() {
10 if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then
11 echo search $new_domain_name >/etc/resolv.conf
12 for nameserver in $new_domain_name_servers; do
13 echo nameserver $nameserver >>/etc/resolv.conf
14 done
15 fi
16 }
17
18 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
19 exit_with_hooks() {
20 exit_status=$1
21 if [ -f /etc/dhclient-exit-hooks ]; then
22 . /etc/dhclient-exit-hooks
23 fi
24 # probably should do something with exit status of the local script
25 exit $exit_status
26 }
27
28 # Invoke the local dhcp client enter hooks, if they exist.
29 if [ -f /etc/dhclient-enter-hooks ]; then
30 exit_status=0
31 . /etc/dhclient-enter-hooks
32 # allow the local script to abort processing of this state
33 # local script must set exit_status variable to nonzero.
34 if [ $exit_status -ne 0 ]; then
35 exit $exit_status
36 fi
37 fi
38
39 if [ x$new_network_number != x ]; then
40 $LOGGER New Network Number: $new_network_number
41 fi
42
43 if [ x$new_broadcast_address != x ]; then
44 $LOGGER New Broadcast Address: $new_broadcast_address
45 new_broadcast_arg="broadcast $new_broadcast_address"
46 fi
47 if [ x$old_broadcast_address != x ]; then
48 old_broadcast_arg="broadcast $old_broadcast_address"
49 fi
50 if [ x$new_subnet_mask != x ]; then
51 new_netmask_arg="netmask $new_subnet_mask"
52 fi
53 if [ x$old_subnet_mask != x ]; then
54 old_netmask_arg="netmask $old_subnet_mask"
55 fi
56 if [ x$alias_subnet_mask != x ]; then
57 alias_subnet_arg="netmask $alias_subnet_mask"
58 fi
59
60 if [ x$reason = xMEDIUM ]; then
61 eval "ifconfig $interface $medium"
62 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
63 sleep 1
64 exit_with_hooks 0
65 fi
66
67 if [ x$reason = xPREINIT ]; then
68 if [ x$alias_ip_address != x ]; then
69 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
70 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
71 fi
72 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
73 broadcast 255.255.255.255 up
74 exit_with_hooks 0
75 fi
76
77 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
78 exit_with_hooks 0;
79 fi
80
81 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
82 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
83 current_hostname=`hostname`
84 if [ x$current_hostname = x ] || \
85 [ x$current_hostname = x$old_host_name ]; then
86 if [ x$current_hostname = x ] || \
87 [ x$new_host_name != x$old_host_name ]; then
88 $LOGGER "New Hostname: $new_host_name"
89 hostname $new_host_name
90 fi
91 fi
92 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
93 [ x$alias_ip_address != x$old_ip_address ]; then
94 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
95 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
96 fi
97 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
98 then
99 eval "ifconfig $interface inet -alias $old_ip_address $medium"
100 route delete $old_ip_address 127.1 >/dev/null 2>&1
101 for router in $old_routers; do
102 route delete default $router >/dev/null 2>&1
103 done
104 if [ "$old_static_routes" != "" ]; then
105 set -- $old_static_routes
106 while [ $# -gt 1 ]; do
107 route delete $1 $2
108 shift; shift
109 done
110 fi
111 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
112 fi
113 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
114 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
115 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
116 $new_broadcast_arg $medium"
117 $LOGGER "New IP Address($interface): $new_ip_address"
118 $LOGGER "New Subnet Mask($interface): $new_subnet_mask"
119 $LOGGER "New Broadcast Address($interface): $new_broadcast_address"
120 if [ "$new_routers" != "" ]; then
121 $LOGGER "New Routers: $new_routers"
122 fi
123 route add $new_ip_address 127.1 >/dev/null 2>&1
124 for router in $new_routers; do
125 route add default $router >/dev/null 2>&1
126 done
127 if [ "$new_static_routes" != "" ]; then
128 $LOGGER "New Static Routes: $new_static_routes"
129 set -- $new_static_routes
130 while [ $# -gt 1 ]; do
131 route add $1 $2
132 shift; shift
133 done
134 fi
135 fi
136 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
137 then
138 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
139 route add $alias_ip_address 127.0.0.1
140 fi
141 make_resolv_conf
142 exit_with_hooks 0
143 fi
144
145 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
146 || [ x$reason = xSTOP ]; then
147 if [ x$alias_ip_address != x ]; then
148 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
149 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
150 fi
151 if [ x$old_ip_address != x ]; then
152 eval "ifconfig $interface inet -alias $old_ip_address $medium"
153 route delete $old_ip_address 127.1 >/dev/null 2>&1
154 for router in $old_routers; do
155 route delete default $router >/dev/null 2>&1
156 done
157 if [ "$old_static_routes" != "" ]; then
158 set -- $old_static_routes
159 while [ $# -gt 1 ]; do
160 route delete $1 $2
161 shift; shift
162 done
163 fi
164 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
165 |sh >/dev/null 2>&1
166 fi
167 if [ x$alias_ip_address != x ]; then
168 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
169 route add $alias_ip_address 127.0.0.1
170 fi
171 exit_with_hooks 0
172 fi
173
174 if [ x$reason = xTIMEOUT ]; then
175 if [ x$alias_ip_address != x ]; then
176 ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
177 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
178 fi
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 sleep 1
185 if [ "$new_routers" != "" ]; then
186 $LOGGER "New Routers: $new_routers"
187 set -- $new_routers
188 if ping -q -c 1 $1; then
189 if [ x$new_ip_address != x$alias_ip_address ] && \
190 [ x$alias_ip_address != x ]; then
191 ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
192 route add $alias_ip_address 127.0.0.1
193 fi
194 route add $new_ip_address 127.1 >/dev/null 2>&1
195 for router in $new_routers; do
196 route add default $router >/dev/null 2>&1
197 done
198 set -- $new_static_routes
199 while [ $# -gt 1 ]; do
200 route add $1 $2
201 shift; shift
202 done
203 make_resolv_conf
204 exit_with_hooks 0
205 fi
206 fi
207 eval "ifconfig $interface inet -alias $new_ip_address $medium"
208 for router in $old_routers; do
209 route delete default $router >/dev/null 2>&1
210 done
211 if [ "$old_static_routes" != "" ]; then
212 set -- $old_static_routes
213 while [ $# -gt 1 ]; do
214 route delete $1 $2
215 shift; shift
216 done
217 fi
218 arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
219 |sh >/dev/null 2>&1
220 exit_with_hooks 1
221 fi
222
223 exit_with_hooks 0