source: hybrid/branches/releng-9.0/nanobsd/files/etc/dhclient-exit-hooks@ 10608

Last change on this file since 10608 was 10608, checked in by rick, 13 years ago

The conditional statements and variables where not set correctly at all (last
commit properly done too late).

While here:

  • Cleanup logging format to logger, as all but the PREINIT hooks get called in privileged [priv] (forked) environment, where stdout goes to nothing.
  • Print more details to yield more logic to the user.

Related-To: nodefactory#129

  • Property svn:executable set to *
File size: 1.7 KB
RevLine 
[10586]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
[10594]8# Little hack to load the available functions in case we are running this as an
9# standalone script (for testing mostly).
10if [ -z "$exit_status" ]; then
11 grep -v 'exit $exit_status' /sbin/dhclient-script | eval
12fi
13
[10586]14. /etc/rc.subr
15
[10590]16: ${service_proxy_normal="NO"}
[10594]17: ${service_proxy_ileiden="NO"}
[10590]18: ${service_accesspoint="NO"}
[10586]19
20load_rc_config 'ileiden'
21
[10594]22update_pf_conf() {
[10608]23 $LOGGER "reason: $reason"
24 if is_default_interface 2>/dev/null; then
25 $LOGGER "is_default_interface: TRUE"
26 new_ext_if_gw=`route -n get default 2>/dev/null | awk '/gateway/ {print $2}'`
27 $LOGGER "prev default gateway: $ext_if_gw"
28 $LOGGER "curr default gateway: $new_ext_if_gw"
29 if [ -n "$new_ext_if_gw" -a "$new_ext_if_gw" != "$ext_if_gw" ]; then
30 $LOGGER "Reloading PF firewall to load new ext_if_gw=$new_ext_if_gw"
31 { grep -v '^ext_if_gw=' $rc_conf_running; echo "ext_if_gw=$new_ext_if_gw"; } > $rc_conf_running
32 $LOGGER "`/etc/rc.d/pf reload 2>&1`"
[10598]33 fi
[10608]34 else
35 $LOGGER "is_default_interface: FALSE"
[10598]36 fi
37
[10594]38 # Make sure not to nuke the default route on an ileiden proxy,
39 # as it will rendering it usefull
[10595]40 checkyesno "service_proxy_ileiden" && return
[10590]41
[10608]42 if [ -n "$new_ext_if_gw" ] && checkyesno "service_proxy_normal" && checkyesno "service_accesspoint"; then
43 $LOGGER "Removing default route as machine is marked as service_proxy AND service_accesspoint"
44 $LOGGER "`route -q del default 2>&1`"
[10590]45 fi
46}
47
[10608]48reason=${reason:-${REASON:-"BOUND"}}
[10590]49case $reason in
50 BOUND|RENEW|REBIND|REBOOT)
[10608]51 update_pf_conf
[10590]52 ;;
53 TIMEOUT)
54 update_pf_conf
55 ;;
56esac
57
Note: See TracBrowser for help on using the repository browser.