Revision 90498252
Added by Renato Botelho about 9 years ago
src/etc/inc/interfaces.inc | ||
---|---|---|
4238 | 4238 |
select-timeout 0; |
4239 | 4239 |
initial-interval 1; |
4240 | 4240 |
{$dhclientconf_hostname} |
4241 |
script "/sbin/dhclient-script";
|
|
4241 |
script "/usr/local/sbin/pfSense-dhclient-script";
|
|
4242 | 4242 |
EOD; |
4243 | 4243 |
|
4244 | 4244 |
if (is_ipaddrv4($wancfg['dhcprejectfrom'])) { |
src/sbin/dhclient-script | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
# $Id$ |
|
3 |
# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $ |
|
4 |
# $FreeBSD: src/sbin/dhclient/dhclient-script,v 1.4 2005/06/10 03:41:18 brooks Exp $ |
|
5 |
# |
|
6 |
# Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org> |
|
7 |
# |
|
8 |
# Permission to use, copy, modify, and distribute this software for any |
|
9 |
# purpose with or without fee is hereby granted, provided that the above |
|
10 |
# copyright notice and this permission notice appear in all copies. |
|
11 |
# |
|
12 |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
13 |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
14 |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
15 |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
16 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
17 |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
18 |
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
19 |
# |
|
20 |
|
|
21 |
HOSTNAME=/bin/hostname |
|
22 |
ROUTE=/sbin/route |
|
23 |
SED=/usr/bin/sed |
|
24 |
ARP=/usr/sbin/arp |
|
25 |
IFCONFIG=/sbin/ifconfig |
|
26 |
PFCTL=/sbin/pfctl |
|
27 |
|
|
28 |
LOCALHOST=127.0.0.1 |
|
29 |
|
|
30 |
if [ -x /usr/bin/logger ]; then |
|
31 |
LOGGER="/usr/bin/logger -s -p user.notice -t dhclient" |
|
32 |
else |
|
33 |
LOGGER="echo" |
|
34 |
fi |
|
35 |
|
|
36 |
# |
|
37 |
# Helper functions that implement common actions. |
|
38 |
# |
|
39 |
|
|
40 |
check_hostname() { |
|
41 |
current_hostname=`$HOSTNAME` |
|
42 |
if [ -z "$current_hostname" ] || \ |
|
43 |
[ "$current_hostname" = "$old_host_name" -a \ |
|
44 |
"$new_hostname" != "$old_host_name" ]; then |
|
45 |
$LOGGER "New Hostname ($interface): $new_host_name" |
|
46 |
$HOSTNAME $new_host_name |
|
47 |
fi |
|
48 |
} |
|
49 |
|
|
50 |
arp_flush() { |
|
51 |
$ARP -an -i $interface | \ |
|
52 |
$SED -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' | \ |
|
53 |
/bin/sh >/dev/null 2>&1 |
|
54 |
} |
|
55 |
|
|
56 |
# NOTE: use of the below has been disabled because rc.newwanip handles this correctly and this |
|
57 |
# unnecessarily killed states in multiple circumstances. Leaving here for now, should be safe |
|
58 |
# to remove later. -cmb 20141105 |
|
59 |
delete_old_states() { |
|
60 |
$LOGGER "Starting delete_old_states()" |
|
61 |
_FLUSHED=0 |
|
62 |
# If the IP changed, remove states from the old one |
|
63 |
if [ -f /var/db/${interface}_ip ]; then |
|
64 |
OLD_IP=`cat /var/db/${interface}_ip` |
|
65 |
$LOGGER "Comparing IPs: Old: ${OLD_IP} New: ${new_ip_address}" |
|
66 |
if [ -n "${OLD_IP}" ] && [ "${OLD_IP}" != "${new_ip_address}" ]; then |
|
67 |
$LOGGER "Removing states from old IP '${OLD_IP}' (new IP '${new_ip_address}')" |
|
68 |
${PFCTL} -i $interface -Fs |
|
69 |
${PFCTL} -K ${OLD_IP}/32 |
|
70 |
_FLUSHED=1 |
|
71 |
fi |
|
72 |
fi |
|
73 |
# Delete states through old gateway if it's not the same |
|
74 |
OLD_ROUTER="" |
|
75 |
if [ -n "${old_routers}" ]; then |
|
76 |
OLD_ROUTER=$old_routers |
|
77 |
elif [ -f /tmp/${interface}_router ]; then |
|
78 |
OLD_ROUTER=`cat /tmp/${interface}_router` |
|
79 |
fi |
|
80 |
if [ ${_FLUSHED} -eq 0 -a -n "${OLD_ROUTER}" ]; then |
|
81 |
$LOGGER "Comparing Routers: Old: ${OLD_ROUTER} New: ${new_routers}" |
|
82 |
if [ "${OLD_ROUTER}" != "${new_routers}" ]; then |
|
83 |
$LOGGER "Removing states through old gateway '${OLD_ROUTER}' (new gateway '${new_routers}')" |
|
84 |
${PFCTL} -i $interface -Fs |
|
85 |
fi |
|
86 |
fi |
|
87 |
} |
|
88 |
|
|
89 |
delete_old_address() { |
|
90 |
/bin/rm -f /var/db/${interface}_ip |
|
91 |
$IFCONFIG $interface inet -alias $old_ip_address $medium |
|
92 |
} |
|
93 |
|
|
94 |
add_new_address() { |
|
95 |
|
|
96 |
$LOGGER "Starting add_new_address()" |
|
97 |
|
|
98 |
$LOGGER "ifconfig $interface inet $new_ip_address netmask $new_subnet_mask broadcast $new_broadcast_address $medium" |
|
99 |
|
|
100 |
$IFCONFIG $interface \ |
|
101 |
inet $new_ip_address \ |
|
102 |
netmask $new_subnet_mask \ |
|
103 |
broadcast $new_broadcast_address \ |
|
104 |
$medium |
|
105 |
$IFCONFIG $interface setfirst $new_ip_address |
|
106 |
|
|
107 |
$LOGGER "New IP Address ($interface): $new_ip_address" |
|
108 |
$LOGGER "New Subnet Mask ($interface): $new_subnet_mask" |
|
109 |
$LOGGER "New Broadcast Address ($interface): $new_broadcast_address" |
|
110 |
$LOGGER "New Routers ($interface): $new_routers" |
|
111 |
|
|
112 |
|
|
113 |
# This is necessary otherwise dpinger will try to ping all 1s address |
|
114 |
if [ -n "$new_routers" ] && [ "$new_routers" != "255.255.255.255" ]; then |
|
115 |
echo $new_routers > /tmp/${interface}_router |
|
116 |
fi |
|
117 |
echo $new_ip_address > /var/db/${interface}_ip |
|
118 |
} |
|
119 |
|
|
120 |
delete_old_alias() { |
|
121 |
if [ -n "$alias_ip_address" ]; then |
|
122 |
$IFCONFIG $interface inet -alias $alias_ip_address > /dev/null 2>&1 |
|
123 |
$ROUTE delete $alias_ip_address $LOCALHOST > /dev/null 2>&1 |
|
124 |
fi |
|
125 |
} |
|
126 |
|
|
127 |
add_new_alias() { |
|
128 |
if [ -n "$alias_ip_address" ]; then |
|
129 |
$IFCONFIG $interface inet alias $alias_ip_address netmask \ |
|
130 |
$alias_subnet_mask |
|
131 |
$ROUTE add $alias_ip_address $LOCALHOST |
|
132 |
fi |
|
133 |
} |
|
134 |
|
|
135 |
fill_classless_routes() { |
|
136 |
set $1 |
|
137 |
while [ $# -ge 5 ]; do |
|
138 |
if [ $1 -eq 0 ]; then |
|
139 |
route="default" |
|
140 |
elif [ $1 -le 8 ]; then |
|
141 |
route="$2.0.0.0/$1" |
|
142 |
shift |
|
143 |
elif [ $1 -le 16 ]; then |
|
144 |
route="$2.$3.0.0/$1" |
|
145 |
shift; shift |
|
146 |
elif [ $1 -le 24 ]; then |
|
147 |
route="$2.$3.$4.0/$1" |
|
148 |
shift; shift; shift |
|
149 |
else |
|
150 |
route="$2.$3.$4.$5/$1" |
|
151 |
shift; shift; shift; shift |
|
152 |
fi |
|
153 |
shift |
|
154 |
router="$1.$2.$3.$4" |
|
155 |
classless_routes="$classless_routes $route $router" |
|
156 |
shift; shift; shift; shift |
|
157 |
done |
|
158 |
} |
|
159 |
|
|
160 |
delete_old_routes() { |
|
161 |
$LOGGER "Deleting old routes" |
|
162 |
|
|
163 |
if [ -n "$old_classless_routes" ]; then |
|
164 |
fill_classless_routes "$old_classless_routes" |
|
165 |
set $classless_routes |
|
166 |
while [ $# -gt 1 ]; do |
|
167 |
route delete "$1" "$2" |
|
168 |
shift; shift |
|
169 |
done |
|
170 |
return 0; |
|
171 |
fi |
|
172 |
|
|
173 |
# Only allow the default route to be overridden if it's on our own interface |
|
174 |
if [ -f "/tmp/${interface}_defaultgw" ]; then |
|
175 |
for router in $old_routers; do |
|
176 |
$ROUTE delete default $router >/dev/null 2>&1 |
|
177 |
/bin/rm -f /tmp/${interface}_router |
|
178 |
done |
|
179 |
fi |
|
180 |
|
|
181 |
if [ -n "$old_static_routes" ]; then |
|
182 |
set $old_static_routes |
|
183 |
while [ $# -gt 1 ]; do |
|
184 |
$ROUTE delete "$1" "$2" |
|
185 |
shift; shift |
|
186 |
/bin/rm -f /tmp/${interface}_router |
|
187 |
done |
|
188 |
fi |
|
189 |
|
|
190 |
arp_flush |
|
191 |
} |
|
192 |
|
|
193 |
add_new_routes() { |
|
194 |
$LOGGER "Adding new routes to interface: $interface" |
|
195 |
|
|
196 |
# RFC 3442: If the DHCP server returns both a Classless Static |
|
197 |
# Routes option and a Router option, the DHCP client MUST ignore |
|
198 |
# the Router option. |
|
199 |
# |
|
200 |
# DHCP clients that support this option (Classless Static Routes) |
|
201 |
# MUST NOT install the routes specified in the Static Routes |
|
202 |
# option (option code 33) if both a Static Routes option and the |
|
203 |
# Classless Static Routes option are provided. |
|
204 |
if [ -n "$new_classless_routes" ]; then |
|
205 |
fill_classless_routes "$new_classless_routes" |
|
206 |
$LOGGER "New Classless Static Routes ($interface): $classless_routes" |
|
207 |
set $classless_routes |
|
208 |
while [ $# -gt 1 ]; do |
|
209 |
if [ "0.0.0.0" = "$2" ]; then |
|
210 |
route add "$1" -iface "$interface" |
|
211 |
else |
|
212 |
route add "$1" "$2" |
|
213 |
fi |
|
214 |
shift; shift |
|
215 |
done |
|
216 |
return |
|
217 |
fi |
|
218 |
|
|
219 |
ADDED_ROUTE=no |
|
220 |
EXISTSGW=`/bin/ls -l /tmp/*_defaultgw | /usr/bin/wc -l` |
|
221 |
# Only allow the default route to be overridden if it's on our own interface |
|
222 |
if [ -f "/tmp/${interface}_defaultgw" -o $EXISTSGW -eq 0 ]; then |
|
223 |
$ROUTE delete default |
|
224 |
for router in $new_routers; do |
|
225 |
if [ "$new_ip_address" = "$router" -o "$router" = "255.255.255.255" ]; then |
|
226 |
$ROUTE add default -iface $interface |
|
227 |
echo $ROUTE add default -iface $interface | $LOGGER |
|
228 |
# NOTE: Do not activate this for all ones address since pf(4) will try to forward packets to it. |
|
229 |
if [ "$new_ip_address" = "$router" ]; then |
|
230 |
echo $router > /tmp/${interface}_router |
|
231 |
fi |
|
232 |
else |
|
233 |
$ROUTE add default $router |
|
234 |
echo $ROUTE add default $router | $LOGGER |
|
235 |
echo $router > /tmp/${interface}_router |
|
236 |
fi |
|
237 |
ADDED_ROUTE=yes |
|
238 |
# 2nd and subsequent default routers error out, so explicitly |
|
239 |
# stop processing the list after the first one. |
|
240 |
break |
|
241 |
done |
|
242 |
fi |
|
243 |
|
|
244 |
if [ -n "$new_static_routes" ]; then |
|
245 |
$LOGGER "New Static Routes ($interface): $new_static_routes" |
|
246 |
set $new_static_routes |
|
247 |
while [ $# -gt 1 ]; do |
|
248 |
$ROUTE add $1 $2 |
|
249 |
if [ "$ADDED_ROUTE" = "no" ]; then |
|
250 |
echo $2 > /tmp/${interface}_router |
|
251 |
fi |
|
252 |
shift; shift |
|
253 |
done |
|
254 |
fi |
|
255 |
} |
|
256 |
|
|
257 |
add_new_resolv_conf() { |
|
258 |
$LOGGER "Creating resolv.conf" |
|
259 |
if [ -f "/var/etc/nameserver_$interface" ]; then |
|
260 |
# Remove old entries |
|
261 |
for nameserver in `cat /var/etc/nameserver_$interface`; do |
|
262 |
$ROUTE delete $nameserver >/dev/null 2>&1 |
|
263 |
done |
|
264 |
fi |
|
265 |
if [ -n "$new_domain_name_servers" ]; then |
|
266 |
/bin/rm -f /var/etc/nameserver_$interface |
|
267 |
ALLOWOVERRIDE=$(/usr/local/sbin/read_xml_tag.sh boolean system/dnsallowoverride) |
|
268 |
for nameserver in $new_domain_name_servers; do |
|
269 |
# Add a route to the nameserver out the correct interface |
|
270 |
# so that mulitple wans work correctly with multiple dns |
|
271 |
# also backup the nameserver for later route removal |
|
272 |
if [ "$ALLOWOVERRIDE" = "true" ]; then |
|
273 |
echo $nameserver >>/var/etc/nameserver_$interface |
|
274 |
$ROUTE add $nameserver -iface $interface |
|
275 |
fi |
|
276 |
done |
|
277 |
echo $new_domain_name >/var/etc/searchdomain_$interface |
|
278 |
fi |
|
279 |
|
|
280 |
return 0 |
|
281 |
} |
|
282 |
|
|
283 |
# Notify rc.newwanip of changes to an interface |
|
284 |
notify_rc_newwanip() { |
|
285 |
/usr/local/sbin/pfSctl -c "interface newip $interface" |
|
286 |
} |
|
287 |
|
|
288 |
# |
|
289 |
# Start of active code. |
|
290 |
# |
|
291 |
|
|
292 |
# Invoke the local dhcp client enter hooks, if they exist. |
|
293 |
if [ -f /etc/dhclient-enter-hooks ]; then |
|
294 |
$LOGGER "dhclient-enter-hooks" |
|
295 |
exit_status=0 |
|
296 |
. /etc/dhclient-enter-hooks |
|
297 |
# allow the local script to abort processing of this state |
|
298 |
# local script must set exit_status variable to nonzero. |
|
299 |
if [ $exit_status -ne 0 ]; then |
|
300 |
exit $exit_status |
|
301 |
fi |
|
302 |
fi |
|
303 |
|
|
304 |
$LOGGER $reason |
|
305 |
case $reason in |
|
306 |
MEDIUM) |
|
307 |
$IFCONFIG $interface $medium |
|
308 |
$IFCONFIG $interface inet -alias 0.0.0.0 $medium >/dev/null 2>&1 |
|
309 |
/bin/sleep 1 |
|
310 |
;; |
|
311 |
|
|
312 |
PREINIT) |
|
313 |
delete_old_alias |
|
314 |
$IFCONFIG $interface inet 0.0.0.0 netmask 255.0.0.0 broadcast 255.255.255.255 up |
|
315 |
/bin/rm -f /tmp/${interface}_router |
|
316 |
;; |
|
317 |
|
|
318 |
ARPCHECK|ARPSEND) |
|
319 |
;; |
|
320 |
|
|
321 |
BOUND|RENEW|REBIND|REBOOT) |
|
322 |
check_hostname |
|
323 |
changes="no" |
|
324 |
if [ -n "$old_ip_address" ]; then |
|
325 |
if [ -n "$alias_ip_address" ] && \ |
|
326 |
[ "$old_ip_address" != "$alias_ip_address" ]; then |
|
327 |
delete_old_alias |
|
328 |
changes="yes" |
|
329 |
fi |
|
330 |
if [ "$old_ip_address" != "$new_ip_address" ]; then |
|
331 |
delete_old_address |
|
332 |
delete_old_routes |
|
333 |
changes="yes" |
|
334 |
fi |
|
335 |
fi |
|
336 |
if [ "$reason" = BOUND ] || \ |
|
337 |
[ "$reason" = REBOOT ] || \ |
|
338 |
[ -z "$old_ip_address" ] || \ |
|
339 |
[ "$old_ip_address" != "$new_ip_address" ]; then |
|
340 |
add_new_address |
|
341 |
add_new_routes |
|
342 |
changes="yes" |
|
343 |
fi |
|
344 |
if [ -n "$alias_ip_address" ] && \ |
|
345 |
[ "$new_ip_address" != "$alias_ip_address" ]; then |
|
346 |
add_new_alias |
|
347 |
changes="yes" |
|
348 |
fi |
|
349 |
add_new_resolv_conf |
|
350 |
if [ "$changes" = "yes" ] ; then |
|
351 |
notify_rc_newwanip |
|
352 |
fi |
|
353 |
;; |
|
354 |
|
|
355 |
EXPIRE|FAIL) |
|
356 |
delete_old_alias |
|
357 |
if [ -n "$old_ip_address" ]; then |
|
358 |
delete_old_address |
|
359 |
delete_old_routes |
|
360 |
fi |
|
361 |
;; |
|
362 |
|
|
363 |
TIMEOUT) |
|
364 |
delete_old_alias |
|
365 |
add_new_address |
|
366 |
/bin/sleep 1 |
|
367 |
if [ -n "$new_routers" ]; then |
|
368 |
$LOGGER "New Routers ($interface): $new_routers" |
|
369 |
set "$new_routers" |
|
370 |
if /sbin/ping -q -c 1 -t 1 "$1"; then |
|
371 |
if [ "$new_ip_address" != "$alias_ip_address" ]; then |
|
372 |
add_new_alias |
|
373 |
fi |
|
374 |
add_new_routes |
|
375 |
if add_new_resolv_conf; then |
|
376 |
notify_rc_newwanip |
|
377 |
fi |
|
378 |
fi |
|
379 |
fi |
|
380 |
$IFCONFIG $interface inet -alias $new_ip_address $medium |
|
381 |
delete_old_routes |
|
382 |
;; |
|
383 |
esac |
|
384 |
|
|
385 |
# Invoke the local dhcp client exit hooks, if they exist. |
|
386 |
if [ -f /etc/dhclient-exit-hooks ]; then |
|
387 |
$LOGGER "dhclient-exit-hooks" |
|
388 |
exit_status=0 |
|
389 |
. /etc/dhclient-exit-hooks |
|
390 |
# allow the local script to abort processing of this state |
|
391 |
# local script must set exit_status variable to nonzero. |
|
392 |
exit $exit_status |
|
393 |
fi |
src/usr/local/sbin/pfSense-dhclient-script | ||
---|---|---|
1 |
#!/bin/sh |
|
2 |
# $Id$ |
|
3 |
# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $ |
|
4 |
# $FreeBSD: src/sbin/dhclient/dhclient-script,v 1.4 2005/06/10 03:41:18 brooks Exp $ |
|
5 |
# |
|
6 |
# Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org> |
|
7 |
# |
|
8 |
# Permission to use, copy, modify, and distribute this software for any |
|
9 |
# purpose with or without fee is hereby granted, provided that the above |
|
10 |
# copyright notice and this permission notice appear in all copies. |
|
11 |
# |
|
12 |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
13 |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
14 |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
15 |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
16 |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
17 |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
18 |
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
19 |
# |
|
20 |
|
|
21 |
HOSTNAME=/bin/hostname |
|
22 |
ROUTE=/sbin/route |
|
23 |
SED=/usr/bin/sed |
|
24 |
ARP=/usr/sbin/arp |
|
25 |
IFCONFIG=/sbin/ifconfig |
|
26 |
PFCTL=/sbin/pfctl |
|
27 |
|
|
28 |
LOCALHOST=127.0.0.1 |
|
29 |
|
|
30 |
if [ -x /usr/bin/logger ]; then |
|
31 |
LOGGER="/usr/bin/logger -s -p user.notice -t dhclient" |
|
32 |
else |
|
33 |
LOGGER="echo" |
|
34 |
fi |
|
35 |
|
|
36 |
# |
|
37 |
# Helper functions that implement common actions. |
|
38 |
# |
|
39 |
|
|
40 |
check_hostname() { |
|
41 |
current_hostname=`$HOSTNAME` |
|
42 |
if [ -z "$current_hostname" ] || \ |
|
43 |
[ "$current_hostname" = "$old_host_name" -a \ |
|
44 |
"$new_hostname" != "$old_host_name" ]; then |
|
45 |
$LOGGER "New Hostname ($interface): $new_host_name" |
|
46 |
$HOSTNAME $new_host_name |
|
47 |
fi |
|
48 |
} |
|
49 |
|
|
50 |
arp_flush() { |
|
51 |
$ARP -an -i $interface | \ |
|
52 |
$SED -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' | \ |
|
53 |
/bin/sh >/dev/null 2>&1 |
|
54 |
} |
|
55 |
|
|
56 |
# NOTE: use of the below has been disabled because rc.newwanip handles this correctly and this |
|
57 |
# unnecessarily killed states in multiple circumstances. Leaving here for now, should be safe |
|
58 |
# to remove later. -cmb 20141105 |
|
59 |
delete_old_states() { |
|
60 |
$LOGGER "Starting delete_old_states()" |
|
61 |
_FLUSHED=0 |
|
62 |
# If the IP changed, remove states from the old one |
|
63 |
if [ -f /var/db/${interface}_ip ]; then |
|
64 |
OLD_IP=`cat /var/db/${interface}_ip` |
|
65 |
$LOGGER "Comparing IPs: Old: ${OLD_IP} New: ${new_ip_address}" |
|
66 |
if [ -n "${OLD_IP}" ] && [ "${OLD_IP}" != "${new_ip_address}" ]; then |
|
67 |
$LOGGER "Removing states from old IP '${OLD_IP}' (new IP '${new_ip_address}')" |
|
68 |
${PFCTL} -i $interface -Fs |
|
69 |
${PFCTL} -K ${OLD_IP}/32 |
|
70 |
_FLUSHED=1 |
|
71 |
fi |
|
72 |
fi |
|
73 |
# Delete states through old gateway if it's not the same |
|
74 |
OLD_ROUTER="" |
|
75 |
if [ -n "${old_routers}" ]; then |
|
76 |
OLD_ROUTER=$old_routers |
|
77 |
elif [ -f /tmp/${interface}_router ]; then |
|
78 |
OLD_ROUTER=`cat /tmp/${interface}_router` |
|
79 |
fi |
|
80 |
if [ ${_FLUSHED} -eq 0 -a -n "${OLD_ROUTER}" ]; then |
|
81 |
$LOGGER "Comparing Routers: Old: ${OLD_ROUTER} New: ${new_routers}" |
|
82 |
if [ "${OLD_ROUTER}" != "${new_routers}" ]; then |
|
83 |
$LOGGER "Removing states through old gateway '${OLD_ROUTER}' (new gateway '${new_routers}')" |
|
84 |
${PFCTL} -i $interface -Fs |
|
85 |
fi |
|
86 |
fi |
|
87 |
} |
|
88 |
|
|
89 |
delete_old_address() { |
|
90 |
/bin/rm -f /var/db/${interface}_ip |
|
91 |
$IFCONFIG $interface inet -alias $old_ip_address $medium |
|
92 |
} |
|
93 |
|
|
94 |
add_new_address() { |
|
95 |
|
|
96 |
$LOGGER "Starting add_new_address()" |
|
97 |
|
|
98 |
$LOGGER "ifconfig $interface inet $new_ip_address netmask $new_subnet_mask broadcast $new_broadcast_address $medium" |
|
99 |
|
|
100 |
$IFCONFIG $interface \ |
|
101 |
inet $new_ip_address \ |
|
102 |
netmask $new_subnet_mask \ |
|
103 |
broadcast $new_broadcast_address \ |
|
104 |
$medium |
|
105 |
$IFCONFIG $interface setfirst $new_ip_address |
|
106 |
|
|
107 |
$LOGGER "New IP Address ($interface): $new_ip_address" |
|
108 |
$LOGGER "New Subnet Mask ($interface): $new_subnet_mask" |
|
109 |
$LOGGER "New Broadcast Address ($interface): $new_broadcast_address" |
|
110 |
$LOGGER "New Routers ($interface): $new_routers" |
|
111 |
|
|
112 |
|
|
113 |
# This is necessary otherwise dpinger will try to ping all 1s address |
|
114 |
if [ -n "$new_routers" ] && [ "$new_routers" != "255.255.255.255" ]; then |
|
115 |
echo $new_routers > /tmp/${interface}_router |
|
116 |
fi |
|
117 |
echo $new_ip_address > /var/db/${interface}_ip |
|
118 |
} |
|
119 |
|
|
120 |
delete_old_alias() { |
|
121 |
if [ -n "$alias_ip_address" ]; then |
|
122 |
$IFCONFIG $interface inet -alias $alias_ip_address > /dev/null 2>&1 |
|
123 |
$ROUTE delete $alias_ip_address $LOCALHOST > /dev/null 2>&1 |
|
124 |
fi |
|
125 |
} |
|
126 |
|
|
127 |
add_new_alias() { |
|
128 |
if [ -n "$alias_ip_address" ]; then |
|
129 |
$IFCONFIG $interface inet alias $alias_ip_address netmask \ |
|
130 |
$alias_subnet_mask |
|
131 |
$ROUTE add $alias_ip_address $LOCALHOST |
|
132 |
fi |
|
133 |
} |
|
134 |
|
|
135 |
fill_classless_routes() { |
|
136 |
set $1 |
|
137 |
while [ $# -ge 5 ]; do |
|
138 |
if [ $1 -eq 0 ]; then |
|
139 |
route="default" |
|
140 |
elif [ $1 -le 8 ]; then |
|
141 |
route="$2.0.0.0/$1" |
|
142 |
shift |
|
143 |
elif [ $1 -le 16 ]; then |
|
144 |
route="$2.$3.0.0/$1" |
|
145 |
shift; shift |
|
146 |
elif [ $1 -le 24 ]; then |
|
147 |
route="$2.$3.$4.0/$1" |
|
148 |
shift; shift; shift |
|
149 |
else |
|
150 |
route="$2.$3.$4.$5/$1" |
|
151 |
shift; shift; shift; shift |
|
152 |
fi |
|
153 |
shift |
|
154 |
router="$1.$2.$3.$4" |
|
155 |
classless_routes="$classless_routes $route $router" |
|
156 |
shift; shift; shift; shift |
|
157 |
done |
|
158 |
} |
|
159 |
|
|
160 |
delete_old_routes() { |
|
161 |
$LOGGER "Deleting old routes" |
|
162 |
|
|
163 |
if [ -n "$old_classless_routes" ]; then |
|
164 |
fill_classless_routes "$old_classless_routes" |
|
165 |
set $classless_routes |
|
166 |
while [ $# -gt 1 ]; do |
|
167 |
route delete "$1" "$2" |
|
168 |
shift; shift |
|
169 |
done |
|
170 |
return 0; |
|
171 |
fi |
|
172 |
|
|
173 |
# Only allow the default route to be overridden if it's on our own interface |
|
174 |
if [ -f "/tmp/${interface}_defaultgw" ]; then |
|
175 |
for router in $old_routers; do |
|
176 |
$ROUTE delete default $router >/dev/null 2>&1 |
|
177 |
/bin/rm -f /tmp/${interface}_router |
|
178 |
done |
|
179 |
fi |
|
180 |
|
|
181 |
if [ -n "$old_static_routes" ]; then |
|
182 |
set $old_static_routes |
|
183 |
while [ $# -gt 1 ]; do |
|
184 |
$ROUTE delete "$1" "$2" |
|
185 |
shift; shift |
|
186 |
/bin/rm -f /tmp/${interface}_router |
|
187 |
done |
|
188 |
fi |
|
189 |
|
|
190 |
arp_flush |
|
191 |
} |
|
192 |
|
|
193 |
add_new_routes() { |
|
194 |
$LOGGER "Adding new routes to interface: $interface" |
|
195 |
|
|
196 |
# RFC 3442: If the DHCP server returns both a Classless Static |
|
197 |
# Routes option and a Router option, the DHCP client MUST ignore |
|
198 |
# the Router option. |
|
199 |
# |
|
200 |
# DHCP clients that support this option (Classless Static Routes) |
|
201 |
# MUST NOT install the routes specified in the Static Routes |
|
202 |
# option (option code 33) if both a Static Routes option and the |
|
203 |
# Classless Static Routes option are provided. |
|
204 |
if [ -n "$new_classless_routes" ]; then |
|
205 |
fill_classless_routes "$new_classless_routes" |
|
206 |
$LOGGER "New Classless Static Routes ($interface): $classless_routes" |
|
207 |
set $classless_routes |
|
208 |
while [ $# -gt 1 ]; do |
|
209 |
if [ "0.0.0.0" = "$2" ]; then |
|
210 |
route add "$1" -iface "$interface" |
|
211 |
else |
|
212 |
route add "$1" "$2" |
|
213 |
fi |
|
214 |
shift; shift |
|
215 |
done |
|
216 |
return |
|
217 |
fi |
|
218 |
|
|
219 |
ADDED_ROUTE=no |
|
220 |
EXISTSGW=`/bin/ls -l /tmp/*_defaultgw | /usr/bin/wc -l` |
|
221 |
# Only allow the default route to be overridden if it's on our own interface |
|
222 |
if [ -f "/tmp/${interface}_defaultgw" -o $EXISTSGW -eq 0 ]; then |
|
223 |
$ROUTE delete default |
|
224 |
for router in $new_routers; do |
|
225 |
if [ "$new_ip_address" = "$router" -o "$router" = "255.255.255.255" ]; then |
|
226 |
$ROUTE add default -iface $interface |
|
227 |
echo $ROUTE add default -iface $interface | $LOGGER |
|
228 |
# NOTE: Do not activate this for all ones address since pf(4) will try to forward packets to it. |
|
229 |
if [ "$new_ip_address" = "$router" ]; then |
|
230 |
echo $router > /tmp/${interface}_router |
|
231 |
fi |
|
232 |
else |
|
233 |
$ROUTE add default $router |
|
234 |
echo $ROUTE add default $router | $LOGGER |
|
235 |
echo $router > /tmp/${interface}_router |
|
236 |
fi |
|
237 |
ADDED_ROUTE=yes |
|
238 |
# 2nd and subsequent default routers error out, so explicitly |
|
239 |
# stop processing the list after the first one. |
|
240 |
break |
|
241 |
done |
|
242 |
fi |
|
243 |
|
|
244 |
if [ -n "$new_static_routes" ]; then |
|
245 |
$LOGGER "New Static Routes ($interface): $new_static_routes" |
|
246 |
set $new_static_routes |
|
247 |
while [ $# -gt 1 ]; do |
|
248 |
$ROUTE add $1 $2 |
|
249 |
if [ "$ADDED_ROUTE" = "no" ]; then |
|
250 |
echo $2 > /tmp/${interface}_router |
|
251 |
fi |
|
252 |
shift; shift |
|
253 |
done |
|
254 |
fi |
|
255 |
} |
|
256 |
|
|
257 |
add_new_resolv_conf() { |
|
258 |
$LOGGER "Creating resolv.conf" |
|
259 |
if [ -f "/var/etc/nameserver_$interface" ]; then |
|
260 |
# Remove old entries |
|
261 |
for nameserver in `cat /var/etc/nameserver_$interface`; do |
|
262 |
$ROUTE delete $nameserver >/dev/null 2>&1 |
|
263 |
done |
|
264 |
fi |
|
265 |
if [ -n "$new_domain_name_servers" ]; then |
|
266 |
/bin/rm -f /var/etc/nameserver_$interface |
|
267 |
ALLOWOVERRIDE=$(/usr/local/sbin/read_xml_tag.sh boolean system/dnsallowoverride) |
|
268 |
for nameserver in $new_domain_name_servers; do |
|
269 |
# Add a route to the nameserver out the correct interface |
|
270 |
# so that mulitple wans work correctly with multiple dns |
|
271 |
# also backup the nameserver for later route removal |
|
272 |
if [ "$ALLOWOVERRIDE" = "true" ]; then |
|
273 |
echo $nameserver >>/var/etc/nameserver_$interface |
|
274 |
$ROUTE add $nameserver -iface $interface |
|
275 |
fi |
|
276 |
done |
|
277 |
echo $new_domain_name >/var/etc/searchdomain_$interface |
|
278 |
fi |
|
279 |
|
|
280 |
return 0 |
|
281 |
} |
|
282 |
|
|
283 |
# Notify rc.newwanip of changes to an interface |
|
284 |
notify_rc_newwanip() { |
|
285 |
/usr/local/sbin/pfSctl -c "interface newip $interface" |
|
286 |
} |
|
287 |
|
|
288 |
# |
|
289 |
# Start of active code. |
|
290 |
# |
|
291 |
|
|
292 |
# Invoke the local dhcp client enter hooks, if they exist. |
|
293 |
if [ -f /etc/dhclient-enter-hooks ]; then |
|
294 |
$LOGGER "dhclient-enter-hooks" |
|
295 |
exit_status=0 |
|
296 |
. /etc/dhclient-enter-hooks |
|
297 |
# allow the local script to abort processing of this state |
|
298 |
# local script must set exit_status variable to nonzero. |
|
299 |
if [ $exit_status -ne 0 ]; then |
|
300 |
exit $exit_status |
|
301 |
fi |
|
302 |
fi |
|
303 |
|
|
304 |
$LOGGER $reason |
|
305 |
case $reason in |
|
306 |
MEDIUM) |
|
307 |
$IFCONFIG $interface $medium |
|
308 |
$IFCONFIG $interface inet -alias 0.0.0.0 $medium >/dev/null 2>&1 |
|
309 |
/bin/sleep 1 |
|
310 |
;; |
|
311 |
|
|
312 |
PREINIT) |
|
313 |
delete_old_alias |
|
314 |
$IFCONFIG $interface inet 0.0.0.0 netmask 255.0.0.0 broadcast 255.255.255.255 up |
|
315 |
/bin/rm -f /tmp/${interface}_router |
|
316 |
;; |
|
317 |
|
|
318 |
ARPCHECK|ARPSEND) |
|
319 |
;; |
|
320 |
|
|
321 |
BOUND|RENEW|REBIND|REBOOT) |
|
322 |
check_hostname |
|
323 |
changes="no" |
|
324 |
if [ -n "$old_ip_address" ]; then |
|
325 |
if [ -n "$alias_ip_address" ] && \ |
|
326 |
[ "$old_ip_address" != "$alias_ip_address" ]; then |
|
327 |
delete_old_alias |
|
328 |
changes="yes" |
|
329 |
fi |
|
330 |
if [ "$old_ip_address" != "$new_ip_address" ]; then |
|
331 |
delete_old_address |
|
332 |
delete_old_routes |
|
333 |
changes="yes" |
|
334 |
fi |
|
335 |
fi |
|
336 |
if [ "$reason" = BOUND ] || \ |
|
337 |
[ "$reason" = REBOOT ] || \ |
|
338 |
[ -z "$old_ip_address" ] || \ |
|
339 |
[ "$old_ip_address" != "$new_ip_address" ]; then |
|
340 |
add_new_address |
|
341 |
add_new_routes |
|
342 |
changes="yes" |
|
343 |
fi |
|
344 |
if [ -n "$alias_ip_address" ] && \ |
|
345 |
[ "$new_ip_address" != "$alias_ip_address" ]; then |
|
346 |
add_new_alias |
|
347 |
changes="yes" |
|
348 |
fi |
|
349 |
add_new_resolv_conf |
|
350 |
if [ "$changes" = "yes" ] ; then |
|
351 |
notify_rc_newwanip |
|
352 |
fi |
|
353 |
;; |
|
354 |
|
|
355 |
EXPIRE|FAIL) |
|
356 |
delete_old_alias |
|
357 |
if [ -n "$old_ip_address" ]; then |
|
358 |
delete_old_address |
|
359 |
delete_old_routes |
|
360 |
fi |
|
361 |
;; |
|
362 |
|
|
363 |
TIMEOUT) |
|
364 |
delete_old_alias |
|
365 |
add_new_address |
|
366 |
/bin/sleep 1 |
|
367 |
if [ -n "$new_routers" ]; then |
|
368 |
$LOGGER "New Routers ($interface): $new_routers" |
|
369 |
set "$new_routers" |
|
370 |
if /sbin/ping -q -c 1 -t 1 "$1"; then |
|
371 |
if [ "$new_ip_address" != "$alias_ip_address" ]; then |
|
372 |
add_new_alias |
|
373 |
fi |
|
374 |
add_new_routes |
|
375 |
if add_new_resolv_conf; then |
|
376 |
notify_rc_newwanip |
|
377 |
fi |
|
378 |
fi |
|
379 |
fi |
|
380 |
$IFCONFIG $interface inet -alias $new_ip_address $medium |
|
381 |
delete_old_routes |
|
382 |
;; |
|
383 |
esac |
|
384 |
|
|
385 |
# Invoke the local dhcp client exit hooks, if they exist. |
|
386 |
if [ -f /etc/dhclient-exit-hooks ]; then |
|
387 |
$LOGGER "dhclient-exit-hooks" |
|
388 |
exit_status=0 |
|
389 |
. /etc/dhclient-exit-hooks |
|
390 |
# allow the local script to abort processing of this state |
|
391 |
# local script must set exit_status variable to nonzero. |
|
392 |
exit $exit_status |
|
393 |
fi |
Also available in: Unified diff
Move our copy of dhclient-script to /usr/local/sbin/pfSense-dhclient-script and change interfaces.inc accordingly