freebsd revision 1.1.1.1.2.2 1 1.1.1.1.2.2 pgoyette #!/bin/sh
2 1.1.1.1.2.2 pgoyette #
3 1.1.1.1.2.2 pgoyette # Id: freebsd,v 1.24 2011/05/18 19:55:44 sar Exp
4 1.1.1.1.2.2 pgoyette #
5 1.1.1.1.2.2 pgoyette # $FreeBSD$
6 1.1.1.1.2.2 pgoyette
7 1.1.1.1.2.2 pgoyette if [ -x /usr/bin/logger ]; then
8 1.1.1.1.2.2 pgoyette LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
9 1.1.1.1.2.2 pgoyette else
10 1.1.1.1.2.2 pgoyette LOGGER=echo
11 1.1.1.1.2.2 pgoyette fi
12 1.1.1.1.2.2 pgoyette
13 1.1.1.1.2.2 pgoyette make_resolv_conf() {
14 1.1.1.1.2.2 pgoyette if [ x"$new_domain_name_servers" != x ]; then
15 1.1.1.1.2.2 pgoyette ( cat /dev/null > /etc/resolv.conf.dhclient )
16 1.1.1.1.2.2 pgoyette exit_status=$?
17 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ]; then
18 1.1.1.1.2.2 pgoyette $LOGGER "Unable to create /etc/resolv.conf.dhclient: Error $exit_status"
19 1.1.1.1.2.2 pgoyette else
20 1.1.1.1.2.2 pgoyette if [ "x$new_domain_search" != x ]; then
21 1.1.1.1.2.2 pgoyette ( echo search $new_domain_search >> /etc/resolv.conf.dhclient )
22 1.1.1.1.2.2 pgoyette exit_status=$?
23 1.1.1.1.2.2 pgoyette elif [ "x$new_domain_name" != x ]; then
24 1.1.1.1.2.2 pgoyette # Note that the DHCP 'Domain Name Option' is really just a domain
25 1.1.1.1.2.2 pgoyette # name, and that this practice of using the domain name option as
26 1.1.1.1.2.2 pgoyette # a search path is both nonstandard and deprecated.
27 1.1.1.1.2.2 pgoyette ( echo search $new_domain_name >> /etc/resolv.conf.dhclient )
28 1.1.1.1.2.2 pgoyette exit_status=$?
29 1.1.1.1.2.2 pgoyette fi
30 1.1.1.1.2.2 pgoyette for nameserver in $new_domain_name_servers; do
31 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ]; then
32 1.1.1.1.2.2 pgoyette break
33 1.1.1.1.2.2 pgoyette fi
34 1.1.1.1.2.2 pgoyette ( echo nameserver $nameserver >>/etc/resolv.conf.dhclient )
35 1.1.1.1.2.2 pgoyette exit_status=$?
36 1.1.1.1.2.2 pgoyette done
37 1.1.1.1.2.2 pgoyette
38 1.1.1.1.2.2 pgoyette # If there were no errors, attempt to mv the new file into place.
39 1.1.1.1.2.2 pgoyette if [ $exit_status -eq 0 ]; then
40 1.1.1.1.2.2 pgoyette ( mv /etc/resolv.conf.dhclient /etc/resolv.conf )
41 1.1.1.1.2.2 pgoyette exit_status=$?
42 1.1.1.1.2.2 pgoyette fi
43 1.1.1.1.2.2 pgoyette
44 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ]; then
45 1.1.1.1.2.2 pgoyette $LOGGER "Error while writing new /etc/resolv.conf."
46 1.1.1.1.2.2 pgoyette fi
47 1.1.1.1.2.2 pgoyette fi
48 1.1.1.1.2.2 pgoyette elif [ "x${new_dhcp6_name_servers}" != x ] ; then
49 1.1.1.1.2.2 pgoyette ( cat /dev/null > /etc/resolv.conf.dhclient6 )
50 1.1.1.1.2.2 pgoyette exit_status=$?
51 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ] ; then
52 1.1.1.1.2.2 pgoyette $LOGGER "Unable to create /etc/resolv.conf.dhclient6: Error $exit_status"
53 1.1.1.1.2.2 pgoyette else
54 1.1.1.1.2.2 pgoyette if [ "x${new_dhcp6_domain_search}" != x ] ; then
55 1.1.1.1.2.2 pgoyette ( echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6 )
56 1.1.1.1.2.2 pgoyette exit_status=$?
57 1.1.1.1.2.2 pgoyette fi
58 1.1.1.1.2.2 pgoyette for nameserver in ${new_dhcp6_name_servers} ; do
59 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ] ; then
60 1.1.1.1.2.2 pgoyette break
61 1.1.1.1.2.2 pgoyette fi
62 1.1.1.1.2.2 pgoyette # If the nameserver has a link-local address
63 1.1.1.1.2.2 pgoyette # add a <zone_id> (interface name) to it.
64 1.1.1.1.2.2 pgoyette case $nameserver in
65 1.1.1.1.2.2 pgoyette fe80:*) zone_id="%$interface";;
66 1.1.1.1.2.2 pgoyette FE80:*) zone_id="%$interface";;
67 1.1.1.1.2.2 pgoyette *) zone_id="";;
68 1.1.1.1.2.2 pgoyette esac
69 1.1.1.1.2.2 pgoyette ( echo nameserver ${nameserver}$zone_id >> /etc/resolv.conf.dhclient6 )
70 1.1.1.1.2.2 pgoyette exit_status=$?
71 1.1.1.1.2.2 pgoyette done
72 1.1.1.1.2.2 pgoyette
73 1.1.1.1.2.2 pgoyette if [ $exit_status -eq 0 ] ; then
74 1.1.1.1.2.2 pgoyette ( mv /etc/resolv.conf.dhclient6 /etc/resolv.conf )
75 1.1.1.1.2.2 pgoyette exit_status=$?
76 1.1.1.1.2.2 pgoyette fi
77 1.1.1.1.2.2 pgoyette
78 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ] ; then
79 1.1.1.1.2.2 pgoyette $LOGGER "Error while writing new /etc/resolv.conf."
80 1.1.1.1.2.2 pgoyette fi
81 1.1.1.1.2.2 pgoyette fi
82 1.1.1.1.2.2 pgoyette fi
83 1.1.1.1.2.2 pgoyette }
84 1.1.1.1.2.2 pgoyette
85 1.1.1.1.2.2 pgoyette # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
86 1.1.1.1.2.2 pgoyette exit_with_hooks() {
87 1.1.1.1.2.2 pgoyette exit_status=$1
88 1.1.1.1.2.2 pgoyette if [ -f /etc/dhclient-exit-hooks ]; then
89 1.1.1.1.2.2 pgoyette . /etc/dhclient-exit-hooks
90 1.1.1.1.2.2 pgoyette fi
91 1.1.1.1.2.2 pgoyette # probably should do something with exit status of the local script
92 1.1.1.1.2.2 pgoyette exit $exit_status
93 1.1.1.1.2.2 pgoyette }
94 1.1.1.1.2.2 pgoyette
95 1.1.1.1.2.2 pgoyette # This function was largely borrowed from dhclient-script that
96 1.1.1.1.2.2 pgoyette # ships with Centos, authored by Jiri Popelka and David Cantrell
97 1.1.1.1.2.2 pgoyette # of Redhat. Thanks guys.
98 1.1.1.1.2.2 pgoyette add_ipv6_addr_with_DAD() {
99 1.1.1.1.2.2 pgoyette ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias
100 1.1.1.1.2.2 pgoyette
101 1.1.1.1.2.2 pgoyette if [ ${dad_wait_time} -le 0 ]
102 1.1.1.1.2.2 pgoyette then
103 1.1.1.1.2.2 pgoyette # if we're not waiting for DAD, assume we're good
104 1.1.1.1.2.2 pgoyette return 0
105 1.1.1.1.2.2 pgoyette fi
106 1.1.1.1.2.2 pgoyette
107 1.1.1.1.2.2 pgoyette # Repeatedly test whether newly added address passed
108 1.1.1.1.2.2 pgoyette # duplicate address detection (DAD)
109 1.1.1.1.2.2 pgoyette for i in $(seq 1 ${dad_wait_time}); do
110 1.1.1.1.2.2 pgoyette sleep 1 # give the DAD some time
111 1.1.1.1.2.2 pgoyette
112 1.1.1.1.2.2 pgoyette addr=$(ifconfig ${interface} \
113 1.1.1.1.2.2 pgoyette | grep "${new_ip6_address} prefixlen ${new_ip6_prefixlen}")
114 1.1.1.1.2.2 pgoyette
115 1.1.1.1.2.2 pgoyette # tentative flag == DAD is still not complete
116 1.1.1.1.2.2 pgoyette tentative=$(echo "${addr}" | grep tentative)
117 1.1.1.1.2.2 pgoyette # dadfailed flag == address is already in use somewhere else
118 1.1.1.1.2.2 pgoyette dadfailed=$(echo "${addr}" | grep duplicated)
119 1.1.1.1.2.2 pgoyette
120 1.1.1.1.2.2 pgoyette if [ -n "${dadfailed}" ] ; then
121 1.1.1.1.2.2 pgoyette # dad failed, remove the address
122 1.1.1.1.2.2 pgoyette ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} -alias
123 1.1.1.1.2.2 pgoyette exit_with_hooks 3
124 1.1.1.1.2.2 pgoyette fi
125 1.1.1.1.2.2 pgoyette
126 1.1.1.1.2.2 pgoyette if [ -z "${tentative}" ] ; then
127 1.1.1.1.2.2 pgoyette if [ -n "${addr}" ]; then
128 1.1.1.1.2.2 pgoyette # DAD is over
129 1.1.1.1.2.2 pgoyette return 0
130 1.1.1.1.2.2 pgoyette else
131 1.1.1.1.2.2 pgoyette # address was auto-removed (or not added at all)
132 1.1.1.1.2.2 pgoyette exit_with_hooks 3
133 1.1.1.1.2.2 pgoyette fi
134 1.1.1.1.2.2 pgoyette fi
135 1.1.1.1.2.2 pgoyette done
136 1.1.1.1.2.2 pgoyette
137 1.1.1.1.2.2 pgoyette return 0
138 1.1.1.1.2.2 pgoyette }
139 1.1.1.1.2.2 pgoyette
140 1.1.1.1.2.2 pgoyette # Invoke the local dhcp client enter hooks, if they exist.
141 1.1.1.1.2.2 pgoyette if [ -f /etc/dhclient-enter-hooks ]; then
142 1.1.1.1.2.2 pgoyette exit_status=0
143 1.1.1.1.2.2 pgoyette . /etc/dhclient-enter-hooks
144 1.1.1.1.2.2 pgoyette # allow the local script to abort processing of this state
145 1.1.1.1.2.2 pgoyette # local script must set exit_status variable to nonzero.
146 1.1.1.1.2.2 pgoyette if [ $exit_status -ne 0 ]; then
147 1.1.1.1.2.2 pgoyette exit $exit_status
148 1.1.1.1.2.2 pgoyette fi
149 1.1.1.1.2.2 pgoyette fi
150 1.1.1.1.2.2 pgoyette
151 1.1.1.1.2.2 pgoyette if [ x$new_network_number != x ]; then
152 1.1.1.1.2.2 pgoyette $LOGGER New Network Number: $new_network_number
153 1.1.1.1.2.2 pgoyette fi
154 1.1.1.1.2.2 pgoyette
155 1.1.1.1.2.2 pgoyette if [ x$new_broadcast_address != x ]; then
156 1.1.1.1.2.2 pgoyette $LOGGER New Broadcast Address: $new_broadcast_address
157 1.1.1.1.2.2 pgoyette new_broadcast_arg="broadcast $new_broadcast_address"
158 1.1.1.1.2.2 pgoyette fi
159 1.1.1.1.2.2 pgoyette if [ x$old_broadcast_address != x ]; then
160 1.1.1.1.2.2 pgoyette old_broadcast_arg="broadcast $old_broadcast_address"
161 1.1.1.1.2.2 pgoyette fi
162 1.1.1.1.2.2 pgoyette if [ x$new_subnet_mask != x ]; then
163 1.1.1.1.2.2 pgoyette new_netmask_arg="netmask $new_subnet_mask"
164 1.1.1.1.2.2 pgoyette fi
165 1.1.1.1.2.2 pgoyette if [ x$old_subnet_mask != x ]; then
166 1.1.1.1.2.2 pgoyette old_netmask_arg="netmask $old_subnet_mask"
167 1.1.1.1.2.2 pgoyette fi
168 1.1.1.1.2.2 pgoyette if [ x$alias_subnet_mask != x ]; then
169 1.1.1.1.2.2 pgoyette alias_subnet_arg="netmask $alias_subnet_mask"
170 1.1.1.1.2.2 pgoyette fi
171 1.1.1.1.2.2 pgoyette if [ x$new_interface_mtu != x ]; then
172 1.1.1.1.2.2 pgoyette mtu_arg="mtu $new_interface_mtu"
173 1.1.1.1.2.2 pgoyette fi
174 1.1.1.1.2.2 pgoyette if [ x$IF_METRIC != x ]; then
175 1.1.1.1.2.2 pgoyette metric_arg="metric $IF_METRIC"
176 1.1.1.1.2.2 pgoyette fi
177 1.1.1.1.2.2 pgoyette
178 1.1.1.1.2.2 pgoyette if [ x$reason = xMEDIUM ]; then
179 1.1.1.1.2.2 pgoyette eval "ifconfig $interface $medium"
180 1.1.1.1.2.2 pgoyette eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
181 1.1.1.1.2.2 pgoyette sleep 1
182 1.1.1.1.2.2 pgoyette exit_with_hooks 0
183 1.1.1.1.2.2 pgoyette fi
184 1.1.1.1.2.2 pgoyette
185 1.1.1.1.2.2 pgoyette ###
186 1.1.1.1.2.2 pgoyette ### DHCPv4 Handlers
187 1.1.1.1.2.2 pgoyette ###
188 1.1.1.1.2.2 pgoyette
189 1.1.1.1.2.2 pgoyette if [ x$reason = xPREINIT ]; then
190 1.1.1.1.2.2 pgoyette if [ x$alias_ip_address != x ]; then
191 1.1.1.1.2.2 pgoyette ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
192 1.1.1.1.2.2 pgoyette route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
193 1.1.1.1.2.2 pgoyette fi
194 1.1.1.1.2.2 pgoyette ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
195 1.1.1.1.2.2 pgoyette broadcast 255.255.255.255 up
196 1.1.1.1.2.2 pgoyette exit_with_hooks 0
197 1.1.1.1.2.2 pgoyette fi
198 1.1.1.1.2.2 pgoyette
199 1.1.1.1.2.2 pgoyette if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
200 1.1.1.1.2.2 pgoyette exit_with_hooks 0;
201 1.1.1.1.2.2 pgoyette fi
202 1.1.1.1.2.2 pgoyette
203 1.1.1.1.2.2 pgoyette if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
204 1.1.1.1.2.2 pgoyette [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
205 1.1.1.1.2.2 pgoyette current_hostname=`/bin/hostname`
206 1.1.1.1.2.2 pgoyette if [ x$current_hostname = x ] || \
207 1.1.1.1.2.2 pgoyette [ x$current_hostname = x$old_host_name ]; then
208 1.1.1.1.2.2 pgoyette if [ x$current_hostname = x ] || \
209 1.1.1.1.2.2 pgoyette [ x$new_host_name != x$old_host_name ]; then
210 1.1.1.1.2.2 pgoyette $LOGGER "New Hostname: $new_host_name"
211 1.1.1.1.2.2 pgoyette hostname $new_host_name
212 1.1.1.1.2.2 pgoyette fi
213 1.1.1.1.2.2 pgoyette fi
214 1.1.1.1.2.2 pgoyette if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
215 1.1.1.1.2.2 pgoyette [ x$alias_ip_address != x$old_ip_address ]; then
216 1.1.1.1.2.2 pgoyette ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
217 1.1.1.1.2.2 pgoyette route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
218 1.1.1.1.2.2 pgoyette fi
219 1.1.1.1.2.2 pgoyette if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
220 1.1.1.1.2.2 pgoyette then
221 1.1.1.1.2.2 pgoyette eval "ifconfig $interface inet -alias $old_ip_address $medium"
222 1.1.1.1.2.2 pgoyette route delete $old_ip_address 127.1 >/dev/null 2>&1
223 1.1.1.1.2.2 pgoyette for router in $old_routers; do
224 1.1.1.1.2.2 pgoyette route delete default $router >/dev/null 2>&1
225 1.1.1.1.2.2 pgoyette done
226 1.1.1.1.2.2 pgoyette if [ -n "$old_static_routes" ]; then
227 1.1.1.1.2.2 pgoyette set -- $old_static_routes
228 1.1.1.1.2.2 pgoyette while [ $# -gt 1 ]; do
229 1.1.1.1.2.2 pgoyette route delete $1 $2
230 1.1.1.1.2.2 pgoyette shift; shift
231 1.1.1.1.2.2 pgoyette done
232 1.1.1.1.2.2 pgoyette fi
233 1.1.1.1.2.2 pgoyette arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
234 1.1.1.1.2.2 pgoyette fi
235 1.1.1.1.2.2 pgoyette if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
236 1.1.1.1.2.2 pgoyette [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
237 1.1.1.1.2.2 pgoyette eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
238 1.1.1.1.2.2 pgoyette $new_broadcast_arg $mtu_arg $metric_arg $medium"
239 1.1.1.1.2.2 pgoyette $LOGGER "New IP Address ($interface): $new_ip_address"
240 1.1.1.1.2.2 pgoyette $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
241 1.1.1.1.2.2 pgoyette $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
242 1.1.1.1.2.2 pgoyette if [ -n "$new_routers" ]; then
243 1.1.1.1.2.2 pgoyette $LOGGER "New Routers: $new_routers"
244 1.1.1.1.2.2 pgoyette fi
245 1.1.1.1.2.2 pgoyette route add $new_ip_address 127.1 >/dev/null 2>&1
246 1.1.1.1.2.2 pgoyette for router in $new_routers; do
247 1.1.1.1.2.2 pgoyette # If the subnet is captive, eg the netmask is /32 but the default
248 1.1.1.1.2.2 pgoyette # gateway is (obviously) outside of this, then we need to produce a
249 1.1.1.1.2.2 pgoyette # host route to reach the gateway.
250 1.1.1.1.2.2 pgoyette if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
251 1.1.1.1.2.2 pgoyette route add -host $router -interface $interface
252 1.1.1.1.2.2 pgoyette fi
253 1.1.1.1.2.2 pgoyette route add default $router >/dev/null 2>&1
254 1.1.1.1.2.2 pgoyette done
255 1.1.1.1.2.2 pgoyette if [ -n "$new_static_routes" ]; then
256 1.1.1.1.2.2 pgoyette $LOGGER "New Static Routes: $new_static_routes"
257 1.1.1.1.2.2 pgoyette set -- $new_static_routes
258 1.1.1.1.2.2 pgoyette while [ $# -gt 1 ]; do
259 1.1.1.1.2.2 pgoyette route add $1 $2
260 1.1.1.1.2.2 pgoyette shift; shift
261 1.1.1.1.2.2 pgoyette done
262 1.1.1.1.2.2 pgoyette fi
263 1.1.1.1.2.2 pgoyette else
264 1.1.1.1.2.2 pgoyette # we haven't changed the address, have we changed other options
265 1.1.1.1.2.2 pgoyette # that we wish to update?
266 1.1.1.1.2.2 pgoyette if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then
267 1.1.1.1.2.2 pgoyette # if we've changed routers delete the old and add the new.
268 1.1.1.1.2.2 pgoyette $LOGGER "New Routers: $new_routers"
269 1.1.1.1.2.2 pgoyette for router in $old_routers; do
270 1.1.1.1.2.2 pgoyette route delete default $router >/dev/null 2>&1
271 1.1.1.1.2.2 pgoyette done
272 1.1.1.1.2.2 pgoyette for router in $new_routers; do
273 1.1.1.1.2.2 pgoyette # If the subnet is captive, eg the netmask is /32 but the default
274 1.1.1.1.2.2 pgoyette # gateway is (obviously) outside of this, then we need to produce a
275 1.1.1.1.2.2 pgoyette # host route to reach the gateway.
276 1.1.1.1.2.2 pgoyette if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
277 1.1.1.1.2.2 pgoyette route add -host $router -interface $interface
278 1.1.1.1.2.2 pgoyette fi
279 1.1.1.1.2.2 pgoyette route add default $router >/dev/null 2>&1
280 1.1.1.1.2.2 pgoyette done
281 1.1.1.1.2.2 pgoyette fi
282 1.1.1.1.2.2 pgoyette fi
283 1.1.1.1.2.2 pgoyette if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
284 1.1.1.1.2.2 pgoyette then
285 1.1.1.1.2.2 pgoyette ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
286 1.1.1.1.2.2 pgoyette route add $alias_ip_address 127.0.0.1
287 1.1.1.1.2.2 pgoyette fi
288 1.1.1.1.2.2 pgoyette make_resolv_conf
289 1.1.1.1.2.2 pgoyette exit_with_hooks 0
290 1.1.1.1.2.2 pgoyette fi
291 1.1.1.1.2.2 pgoyette
292 1.1.1.1.2.2 pgoyette if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
293 1.1.1.1.2.2 pgoyette || [ x$reason = xSTOP ]; then
294 1.1.1.1.2.2 pgoyette if [ x$alias_ip_address != x ]; then
295 1.1.1.1.2.2 pgoyette ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
296 1.1.1.1.2.2 pgoyette route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
297 1.1.1.1.2.2 pgoyette fi
298 1.1.1.1.2.2 pgoyette if [ x$old_ip_address != x ]; then
299 1.1.1.1.2.2 pgoyette eval "ifconfig $interface inet -alias $old_ip_address $medium"
300 1.1.1.1.2.2 pgoyette route delete $old_ip_address 127.1 >/dev/null 2>&1
301 1.1.1.1.2.2 pgoyette for router in $old_routers; do
302 1.1.1.1.2.2 pgoyette route delete default $router >/dev/null 2>&1
303 1.1.1.1.2.2 pgoyette done
304 1.1.1.1.2.2 pgoyette if [ -n "$old_static_routes" ]; then
305 1.1.1.1.2.2 pgoyette set -- $old_static_routes
306 1.1.1.1.2.2 pgoyette while [ $# -gt 1 ]; do
307 1.1.1.1.2.2 pgoyette route delete $1 $2
308 1.1.1.1.2.2 pgoyette shift; shift
309 1.1.1.1.2.2 pgoyette done
310 1.1.1.1.2.2 pgoyette fi
311 1.1.1.1.2.2 pgoyette arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
312 1.1.1.1.2.2 pgoyette |sh >/dev/null 2>&1
313 1.1.1.1.2.2 pgoyette fi
314 1.1.1.1.2.2 pgoyette if [ x$alias_ip_address != x ]; then
315 1.1.1.1.2.2 pgoyette ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
316 1.1.1.1.2.2 pgoyette route add $alias_ip_address 127.0.0.1
317 1.1.1.1.2.2 pgoyette fi
318 1.1.1.1.2.2 pgoyette exit_with_hooks 0
319 1.1.1.1.2.2 pgoyette fi
320 1.1.1.1.2.2 pgoyette
321 1.1.1.1.2.2 pgoyette if [ x$reason = xTIMEOUT ]; then
322 1.1.1.1.2.2 pgoyette if [ x$alias_ip_address != x ]; then
323 1.1.1.1.2.2 pgoyette ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
324 1.1.1.1.2.2 pgoyette route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
325 1.1.1.1.2.2 pgoyette fi
326 1.1.1.1.2.2 pgoyette eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
327 1.1.1.1.2.2 pgoyette $new_broadcast_arg $mtu_arg $metric_arg $medium"
328 1.1.1.1.2.2 pgoyette $LOGGER "New IP Address ($interface): $new_ip_address"
329 1.1.1.1.2.2 pgoyette $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
330 1.1.1.1.2.2 pgoyette $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
331 1.1.1.1.2.2 pgoyette sleep 1
332 1.1.1.1.2.2 pgoyette if [ -n "$new_routers" ]; then
333 1.1.1.1.2.2 pgoyette $LOGGER "New Routers: $new_routers"
334 1.1.1.1.2.2 pgoyette set -- $new_routers
335 1.1.1.1.2.2 pgoyette if ping -q -c 1 $1; then
336 1.1.1.1.2.2 pgoyette if [ x$new_ip_address != x$alias_ip_address ] && \
337 1.1.1.1.2.2 pgoyette [ x$alias_ip_address != x ]; then
338 1.1.1.1.2.2 pgoyette ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
339 1.1.1.1.2.2 pgoyette route add $alias_ip_address 127.0.0.1
340 1.1.1.1.2.2 pgoyette fi
341 1.1.1.1.2.2 pgoyette route add $new_ip_address 127.1 >/dev/null 2>&1
342 1.1.1.1.2.2 pgoyette for router in $new_routers; do
343 1.1.1.1.2.2 pgoyette if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then
344 1.1.1.1.2.2 pgoyette route add -host $router -interface $interface
345 1.1.1.1.2.2 pgoyette fi
346 1.1.1.1.2.2 pgoyette route add default $router >/dev/null 2>&1
347 1.1.1.1.2.2 pgoyette done
348 1.1.1.1.2.2 pgoyette set -- $new_static_routes
349 1.1.1.1.2.2 pgoyette while [ $# -gt 1 ]; do
350 1.1.1.1.2.2 pgoyette route add $1 $2
351 1.1.1.1.2.2 pgoyette shift; shift
352 1.1.1.1.2.2 pgoyette done
353 1.1.1.1.2.2 pgoyette make_resolv_conf
354 1.1.1.1.2.2 pgoyette exit_with_hooks 0
355 1.1.1.1.2.2 pgoyette fi
356 1.1.1.1.2.2 pgoyette fi
357 1.1.1.1.2.2 pgoyette eval "ifconfig $interface inet -alias $new_ip_address $medium"
358 1.1.1.1.2.2 pgoyette for router in $old_routers; do
359 1.1.1.1.2.2 pgoyette route delete default $router >/dev/null 2>&1
360 1.1.1.1.2.2 pgoyette done
361 1.1.1.1.2.2 pgoyette if [ -n "$old_static_routes" ]; then
362 1.1.1.1.2.2 pgoyette set -- $old_static_routes
363 1.1.1.1.2.2 pgoyette while [ $# -gt 1 ]; do
364 1.1.1.1.2.2 pgoyette route delete $1 $2
365 1.1.1.1.2.2 pgoyette shift; shift
366 1.1.1.1.2.2 pgoyette done
367 1.1.1.1.2.2 pgoyette fi
368 1.1.1.1.2.2 pgoyette arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
369 1.1.1.1.2.2 pgoyette |sh >/dev/null 2>&1
370 1.1.1.1.2.2 pgoyette exit_with_hooks 1
371 1.1.1.1.2.2 pgoyette fi
372 1.1.1.1.2.2 pgoyette
373 1.1.1.1.2.2 pgoyette ###
374 1.1.1.1.2.2 pgoyette ### DHCPv6 Handlers
375 1.1.1.1.2.2 pgoyette ###
376 1.1.1.1.2.2 pgoyette
377 1.1.1.1.2.2 pgoyette if [ ${reason} = PREINIT6 ] ; then
378 1.1.1.1.2.2 pgoyette # Ensure interface is up.
379 1.1.1.1.2.2 pgoyette ifconfig ${interface} up
380 1.1.1.1.2.2 pgoyette
381 1.1.1.1.2.2 pgoyette # XXX: Remove any stale addresses from aborted clients.
382 1.1.1.1.2.2 pgoyette
383 1.1.1.1.2.2 pgoyette # We need to give the kernel some time to active interface
384 1.1.1.1.2.2 pgoyette interface_up_wait_time=5
385 1.1.1.1.2.2 pgoyette for i in $(seq 0 ${interface_up_wait_time})
386 1.1.1.1.2.2 pgoyette do
387 1.1.1.1.2.2 pgoyette ifconfig ${interface} | grep inactive >/dev/null 2>&1
388 1.1.1.1.2.2 pgoyette if [ $? -ne 0 ]; then
389 1.1.1.1.2.2 pgoyette break;
390 1.1.1.1.2.2 pgoyette fi
391 1.1.1.1.2.2 pgoyette sleep 1
392 1.1.1.1.2.2 pgoyette done
393 1.1.1.1.2.2 pgoyette
394 1.1.1.1.2.2 pgoyette # Wait for duplicate address detection for this interface if the
395 1.1.1.1.2.2 pgoyette # --dad-wait-time parameter has been specified and is greater than
396 1.1.1.1.2.2 pgoyette # zero.
397 1.1.1.1.2.2 pgoyette if [ ${dad_wait_time} -gt 0 ]; then
398 1.1.1.1.2.2 pgoyette # Check if any IPv6 address on this interface is marked as
399 1.1.1.1.2.2 pgoyette # tentative.
400 1.1.1.1.2.2 pgoyette ifconfig ${interface} | grep inet6 | grep tentative \
401 1.1.1.1.2.2 pgoyette >/dev/null 2>&1
402 1.1.1.1.2.2 pgoyette if [ $? -eq 0 ]; then
403 1.1.1.1.2.2 pgoyette # Wait for duplicate address detection to complete or for
404 1.1.1.1.2.2 pgoyette # the timeout specified as --dad-wait-time.
405 1.1.1.1.2.2 pgoyette for i in $(seq 0 $dad_wait_time)
406 1.1.1.1.2.2 pgoyette do
407 1.1.1.1.2.2 pgoyette # We're going to poll for the tentative flag every second.
408 1.1.1.1.2.2 pgoyette sleep 1
409 1.1.1.1.2.2 pgoyette ifconfig ${interface} | grep inet6 | grep tentative \
410 1.1.1.1.2.2 pgoyette >/dev/null 2>&1
411 1.1.1.1.2.2 pgoyette if [ $? -ne 0 ]; then
412 1.1.1.1.2.2 pgoyette break;
413 1.1.1.1.2.2 pgoyette fi
414 1.1.1.1.2.2 pgoyette done
415 1.1.1.1.2.2 pgoyette fi
416 1.1.1.1.2.2 pgoyette fi
417 1.1.1.1.2.2 pgoyette
418 1.1.1.1.2.2 pgoyette
419 1.1.1.1.2.2 pgoyette exit_with_hooks 0
420 1.1.1.1.2.2 pgoyette fi
421 1.1.1.1.2.2 pgoyette
422 1.1.1.1.2.2 pgoyette if [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then
423 1.1.1.1.2.2 pgoyette echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix}
424 1.1.1.1.2.2 pgoyette
425 1.1.1.1.2.2 pgoyette exit_with_hooks 0
426 1.1.1.1.2.2 pgoyette fi
427 1.1.1.1.2.2 pgoyette
428 1.1.1.1.2.2 pgoyette if [ ${reason} = BOUND6 ] ; then
429 1.1.1.1.2.2 pgoyette if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
430 1.1.1.1.2.2 pgoyette exit_with_hooks 2;
431 1.1.1.1.2.2 pgoyette fi
432 1.1.1.1.2.2 pgoyette
433 1.1.1.1.2.2 pgoyette # Add address to interface, check for DAD if dad_wait_time > 0
434 1.1.1.1.2.2 pgoyette add_ipv6_addr_with_DAD
435 1.1.1.1.2.2 pgoyette
436 1.1.1.1.2.2 pgoyette # Check for nameserver options.
437 1.1.1.1.2.2 pgoyette make_resolv_conf
438 1.1.1.1.2.2 pgoyette
439 1.1.1.1.2.2 pgoyette exit_with_hooks 0
440 1.1.1.1.2.2 pgoyette fi
441 1.1.1.1.2.2 pgoyette
442 1.1.1.1.2.2 pgoyette if [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then
443 1.1.1.1.2.2 pgoyette # Make sure nothing has moved around on us.
444 1.1.1.1.2.2 pgoyette
445 1.1.1.1.2.2 pgoyette # Nameservers/domains/etc.
446 1.1.1.1.2.2 pgoyette if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
447 1.1.1.1.2.2 pgoyette [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
448 1.1.1.1.2.2 pgoyette make_resolv_conf
449 1.1.1.1.2.2 pgoyette fi
450 1.1.1.1.2.2 pgoyette
451 1.1.1.1.2.2 pgoyette exit_with_hooks 0
452 1.1.1.1.2.2 pgoyette fi
453 1.1.1.1.2.2 pgoyette
454 1.1.1.1.2.2 pgoyette if [ ${reason} = DEPREF6 ] ; then
455 1.1.1.1.2.2 pgoyette if [ x${new_ip6_address} = x ] ; then
456 1.1.1.1.2.2 pgoyette exit_with_hooks 2;
457 1.1.1.1.2.2 pgoyette fi
458 1.1.1.1.2.2 pgoyette
459 1.1.1.1.2.2 pgoyette ifconfig ${interface} inet6 ${new_ip6_address} deprecated
460 1.1.1.1.2.2 pgoyette
461 1.1.1.1.2.2 pgoyette exit_with_hooks 0
462 1.1.1.1.2.2 pgoyette fi
463 1.1.1.1.2.2 pgoyette
464 1.1.1.1.2.2 pgoyette if [ ${reason} = EXPIRE6 -o ${reason} = RELEASE6 -o ${reason} = STOP6 ] ; then
465 1.1.1.1.2.2 pgoyette if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
466 1.1.1.1.2.2 pgoyette exit_with_hooks 2;
467 1.1.1.1.2.2 pgoyette fi
468 1.1.1.1.2.2 pgoyette
469 1.1.1.1.2.2 pgoyette ifconfig ${interface} inet6 ${old_ip6_address}/${old_ip6_prefixlen} -alias
470 1.1.1.1.2.2 pgoyette
471 1.1.1.1.2.2 pgoyette exit_with_hooks 0
472 1.1.1.1.2.2 pgoyette fi
473 1.1.1.1.2.2 pgoyette
474 1.1.1.1.2.2 pgoyette exit_with_hooks 0
475