1 | #!/bin/sh -
|
---|
2 | #
|
---|
3 | # An normal proxy should not have an defaultrouter configured, as all calls to
|
---|
4 | # the outside world are handled via PF redirects.
|
---|
5 | #
|
---|
6 | # Rick van der Zwet <rick@wirelessleiden.nl>
|
---|
7 |
|
---|
8 | . /etc/rc.subr
|
---|
9 |
|
---|
10 | : ${service_proxy_normal="NO"}
|
---|
11 | : ${service_proxy_ileiden="NO"}
|
---|
12 | : ${service_accesspoint="NO"}
|
---|
13 |
|
---|
14 | load_rc_config 'ileiden'
|
---|
15 |
|
---|
16 | update_pf_conf() {
|
---|
17 | $LOGGER "reason: $reason"
|
---|
18 | if is_default_interface 2>/dev/null; then
|
---|
19 | $LOGGER "is_default_interface: TRUE"
|
---|
20 | $LOGGER "`sysctl net.my_fib`"
|
---|
21 | new_ext_if_gw=`route -n get default 2>/dev/null | awk '/gateway/ {print $2}'`
|
---|
22 | $LOGGER "prev default gateway: $ext_if_gw"
|
---|
23 | $LOGGER "curr default gateway: $new_ext_if_gw"
|
---|
24 | if [ -n "$new_ext_if_gw" -a "$new_ext_if_gw" != "$ext_if_gw" ]; then
|
---|
25 | $LOGGER "Syncing new default route ($new_ext_if_gw) to routing table 1"
|
---|
26 | { grep -v '^ext_if_gw=' $rc_conf_running; echo "ext_if_gw=$new_ext_if_gw"; } > $rc_conf_running
|
---|
27 | $LOGGER "`setfib 1 route -q del default 2>&1`"
|
---|
28 | $LOGGER "`setfib 1 route -q add default $new_ext_if_gw 2>&1`"
|
---|
29 | fi
|
---|
30 | else
|
---|
31 | $LOGGER "is_default_interface: FALSE"
|
---|
32 | fi
|
---|
33 |
|
---|
34 | # Make sure not to nuke the default route on an ileiden proxy,
|
---|
35 | # as it will rendering it usefull
|
---|
36 | checkyesno "service_proxy_ileiden" && return
|
---|
37 |
|
---|
38 | if [ -n "$new_ext_if_gw" ] && checkyesno "service_proxy_normal" && checkyesno "service_accesspoint"; then
|
---|
39 | $LOGGER "Removing default route from routing table 0 as machine is marked as service_proxy AND service_accesspoint"
|
---|
40 | $LOGGER "`setfib 0 route -q del default 2>&1`"
|
---|
41 | fi
|
---|
42 | }
|
---|
43 |
|
---|
44 | reason=${reason:-${REASON:-"BOUND"}}
|
---|
45 | case $reason in
|
---|
46 | BOUND|RENEW|REBIND|REBOOT)
|
---|
47 | update_pf_conf
|
---|
48 | ;;
|
---|
49 | TIMEOUT)
|
---|
50 | update_pf_conf
|
---|
51 | ;;
|
---|
52 | esac
|
---|
53 |
|
---|