Determine forwarding and reverse-path filtering from host definitions.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 5 Mar 2012 23:39:23 +0000 (23:39 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 5 Mar 2012 23:56:03 +0000 (23:56 +0000)
There's an explicit declaration for routers.  Reverse-path filtering is
just turned off: the routing asymmetries break things too badly on
multi-homed hosts, and it's useless for single-homed hosts.

artist.m4
bookends.m4
config.m4
fender.m4
gibson.m4
ibanez.m4
jem.m4
local.m4
radius.m4
roadstar.m4
vampire.m4

index 4adcc21..a04cc9c 100644 (file)
--- a/artist.m4
+++ b/artist.m4
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This host isn't a router.
-setconf(forward, 0)
-
-## This host is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### artist-specific rules.
 
 m4_divert(84)m4_dnl
index 38b4e91..6caad93 100644 (file)
@@ -105,6 +105,10 @@ m4_divert(32)m4_dnl
 
 ## Set forwarding options.  Apparently setting ip_forward clobbers other
 ## settings, so put this first.
+case $host_type_<::>FWHOST in
+  router) forward=1 ;;
+  *) forward=0 ;;
+esac
 setopt ip_forward $forward
 setdevopt forwarding $forward
 
@@ -129,9 +133,11 @@ if [ -x /sbin/brctl ]; then
   fi
 fi
 
-## Turn on the reverse-path filter, and log weird things.
-setdevopt rp_filter $rp_filter
-setdevopt log_martians $log_martians
+## Turn off the reverse-path filter.  It's basically useless: the filter does
+## nothing at all for single-homed hosts; and multi-homed hosts tend to have
+## routing aysmmetries if there's any kind of cycle.
+setdevopt rp_filter 0
+setdevopt log_martians 0
 
 ## Turn off things which can mess with our routing decisions.
 setdevopt accept_source_route 0
@@ -179,26 +185,34 @@ run ip6tables -A INPUT -g bad-destination-address \
        -d ::1
 
 ## We shouldn't be asked to forward things with link-local addresses.
-run iptables -A FORWARD -g bad-source-address \
-       -s 169.254.0.0/16
-run iptables -A FORWARD -g bad-destination-address \
-       -d 169.254.0.0/16
-run ip6tables -A FORWARD -g bad-source-address \
-       -s fe80::/10
-run ip6tables -A FORWARD -g bad-destination-address \
-       -d fe80::/10
+case $forward in
+  1)
+    run iptables -A FORWARD -g bad-source-address \
+           -s 169.254.0.0/16
+    run iptables -A FORWARD -g bad-destination-address \
+           -d 169.254.0.0/16
+    run ip6tables -A FORWARD -g bad-source-address \
+           -s fe80::/10
+    run ip6tables -A FORWARD -g bad-destination-address \
+           -d fe80::/10
+    ;;
+esac
 
 ## Also, don't forward link-local broadcast or multicast.
-run iptables -A FORWARD -g bad-destination-address \
-       -d 255.255.255.255
-run iptables -A FORWARD -g bad-destination-address \
-       -m addrtype --dst-type BROADCAST
-run iptables -A FORWARD -g bad-destination-address \
-       -d 224.0.0.0/24
-for x in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
-  run ip6tables -A FORWARD -g bad-destination-address \
-       -d fe${x}2::/16
-done
+case $forward in
+  1)
+    run iptables -A FORWARD -g bad-destination-address \
+           -d 255.255.255.255
+    run iptables -A FORWARD -g bad-destination-address \
+           -m addrtype --dst-type BROADCAST
+    run iptables -A FORWARD -g bad-destination-address \
+           -d 224.0.0.0/24
+    for x in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do
+      run ip6tables -A FORWARD -g bad-destination-address \
+           -d fe${x}2::/16
+    done
+    ;;
+esac
 
 ## Add a hook for fail2ban.
 clearchain fail2ban
index 4b059df..ee9ef90 100644 (file)
--- a/config.m4
+++ b/config.m4
@@ -39,14 +39,5 @@ defconf(open_port_max, 54999)
 ## Which chains to preserve.
 defconf(preserve_chains, )
 
-## Whether to permit forwarding.
-defconf(forward, 1)
-
-## Whether to turn on the reverse-path filter.
-defconf(rp_filter, 1)
-
-## Whether to turn on logging of martian packets.
-defconf(log_martians, 1)
-
 m4_divert(-1)
 ###----- That's all, folks --------------------------------------------------
index 6fc2e4f..05354bd 100644 (file)
--- a/fender.m4
+++ b/fender.m4
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This host isn't a router.
-setconf(forward, 0)
-
-## This host is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### fender-specific rules.
 
 m4_divert(82)m4_dnl
index 5c82c41..4416aee 100644 (file)
--- a/gibson.m4
+++ b/gibson.m4
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This host isn't a router.
-setconf(forward, 0)
-
-###--------------------------------------------------------------------------
 ### gibson-specific rules.
 
 m4_divert(84)m4_dnl
index e50b56c..93a816e 100644 (file)
--- a/ibanez.m4
+++ b/ibanez.m4
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This host isn't a router.
-setconf(forward, 0)
-
-## This host is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### ibanez-specific rules.
 
 m4_divert(84)m4_dnl
diff --git a/jem.m4 b/jem.m4
index afb8068..7db1ce5 100644 (file)
--- a/jem.m4
+++ b/jem.m4
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This host isn't a router.
-setconf(forward, 0)
-
-## This host is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### jem-specific rules.
 
 m4_divert(84)m4_dnl
index 69122e2..b31b649 100644 (file)
--- a/local.m4
+++ b/local.m4
@@ -148,49 +148,54 @@ m4_divert(80)m4_dnl
 ###--------------------------------------------------------------------------
 ### Special forwarding exemptions.
 
-## Only allow these packets if they're not fragmented.  (Don't trust safe
-## hosts's fragment reassembly to be robust against malicious fragments.)
-## There's a hideous bug in iptables 1.4.11.1 which botches the meaning of
-## `! -f', so we do the negation using early return from a subchain.
-clearchain fwd-spec-nofrag
-run iptables -A fwd-spec-nofrag -j RETURN --fragment
-run ip6tables -A fwd-spec-nofrag -j RETURN \
-       -m ipv6header --soft --header frag
-run iptables -A FORWARD -j fwd-spec-nofrag
-
-## Allow ping from safe/noloop to untrusted networks.
-run iptables -A fwd-spec-nofrag -j ACCEPT \
-       -p icmp --icmp-type echo-request \
-       -m mark --mark $to_untrusted/$MASK_TO
-run iptables -A fwd-spec-nofrag -j ACCEPT \
-       -p icmp --icmp-type echo-reply \
-       -m mark --mark $from_untrusted/$MASK_FROM \
-       -m state --state ESTABLISHED
-run ip6tables -A fwd-spec-nofrag -j ACCEPT \
-       -p ipv6-icmp --icmpv6-type echo-request \
-       -m mark --mark $to_untrusted/$MASK_TO
-run ip6tables -A fwd-spec-nofrag -j ACCEPT \
-       -p ipv6-icmp --icmpv6-type echo-reply \
-       -m mark --mark $from_untrusted/$MASK_FROM \
-       -m state --state ESTABLISHED
-
-## Allow SSH from safe/noloop to untrusted networks.
-run iptables -A fwd-spec-nofrag -j ACCEPT \
-       -p tcp --destination-port $port_ssh \
-       -m mark --mark $to_untrusted/$MASK_TO
-run iptables -A fwd-spec-nofrag -j ACCEPT \
-       -p tcp --source-port $port_ssh \
-       -m mark --mark $from_untrusted/$MASK_FROM \
-       -m state --state ESTABLISHED
-run ip6tables -A fwd-spec-nofrag -j ACCEPT \
-       -p tcp --destination-port $port_ssh \
-       -m mark --mark $to_untrusted/$MASK_TO
-run ip6tables -A fwd-spec-nofrag -j ACCEPT \
-       -p tcp --source-port $port_ssh \
-       -m mark --mark $from_untrusted/$MASK_FROM \
-       -m state --state ESTABLISHED
-
-m4_divert(60)m4_dnl
+case $forward in
+  1)
+
+    ## Only allow these packets if they're not fragmented.  (Don't trust safe
+    ## hosts's fragment reassembly to be robust against malicious fragments.)
+    ## There's a hideous bug in iptables 1.4.11.1 which botches the meaning
+    ## of `! -f', so we do the negation using early return from a subchain.
+    clearchain fwd-spec-nofrag
+    run iptables -A fwd-spec-nofrag -j RETURN --fragment
+    run ip6tables -A fwd-spec-nofrag -j RETURN \
+           -m ipv6header --soft --header frag
+    run iptables -A FORWARD -j fwd-spec-nofrag
+
+    ## Allow ping from safe/noloop to untrusted networks.
+    run iptables -A fwd-spec-nofrag -j ACCEPT \
+           -p icmp --icmp-type echo-request \
+           -m mark --mark $to_untrusted/$MASK_TO
+    run iptables -A fwd-spec-nofrag -j ACCEPT \
+           -p icmp --icmp-type echo-reply \
+           -m mark --mark $from_untrusted/$MASK_FROM \
+           -m state --state ESTABLISHED
+    run ip6tables -A fwd-spec-nofrag -j ACCEPT \
+           -p ipv6-icmp --icmpv6-type echo-request \
+           -m mark --mark $to_untrusted/$MASK_TO
+    run ip6tables -A fwd-spec-nofrag -j ACCEPT \
+           -p ipv6-icmp --icmpv6-type echo-reply \
+           -m mark --mark $from_untrusted/$MASK_FROM \
+           -m state --state ESTABLISHED
+
+    ## Allow SSH from safe/noloop to untrusted networks.
+    run iptables -A fwd-spec-nofrag -j ACCEPT \
+           -p tcp --destination-port $port_ssh \
+           -m mark --mark $to_untrusted/$MASK_TO
+    run iptables -A fwd-spec-nofrag -j ACCEPT \
+           -p tcp --source-port $port_ssh \
+           -m mark --mark $from_untrusted/$MASK_FROM \
+           -m state --state ESTABLISHED
+    run ip6tables -A fwd-spec-nofrag -j ACCEPT \
+           -p tcp --destination-port $port_ssh \
+           -m mark --mark $to_untrusted/$MASK_TO
+    run ip6tables -A fwd-spec-nofrag -j ACCEPT \
+           -p tcp --source-port $port_ssh \
+           -m mark --mark $from_untrusted/$MASK_FROM \
+           -m state --state ESTABLISHED
+
+    ;;
+esac
+
 m4_divert(80)m4_dnl
 ###--------------------------------------------------------------------------
 ### Kill things we don't understand properly.
@@ -201,10 +206,14 @@ m4_divert(80)m4_dnl
 errorchain poorly-understood REJECT
 
 ## Ban multicast destination addresses in forwarding.
-run iptables -A FORWARD -g poorly-understood \
-       -d 224.0.0.0/4
-run ip6tables -A FORWARD -g poorly-understood \
-       -d ff::/8
+case $forward in
+  1)
+    run iptables -A FORWARD -g poorly-understood \
+           -d 224.0.0.0/4
+    run ip6tables -A FORWARD -g poorly-understood \
+           -d ff::/8
+    ;;
+esac
 
 m4_divert(84)m4_dnl
 ###--------------------------------------------------------------------------
@@ -253,9 +262,12 @@ run ip46tables -A inbound -j forbidden
 run ip46tables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound
 
 ## Otherwise process as indicated by the mark.
-for i in INPUT FORWARD; do
-  run ip46tables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT
-done
+run ip46tables -A INPUT -m mark ! --mark 0/$MASK_MASK -j ACCEPT
+case $forward in
+  1)
+    run ip46tables -A FORWARD -m mark ! --mark 0/$MASK_MASK -j ACCEPT
+    ;;
+esac
 
 m4_divert(-1)
 ###----- That's all, folks --------------------------------------------------
index 72a8e1f..d698998 100644 (file)
--- a/radius.m4
+++ b/radius.m4
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This router is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### radius-specific rules.
 
 m4_divert(84)m4_dnl
index a95cc3b..4947a80 100644 (file)
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This host isn't a router.
-setconf(forward, 0)
-
-## This host is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### roadstar-specific rules.
 
 m4_divert(84)m4_dnl
index 6ddbbf5..fa79ee2 100644 (file)
 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ###--------------------------------------------------------------------------
-### Config settings.
-
-## This router is involved in a routing asymmetry.
-setconf(rp_filter, 0)
-setconf(log_martians, 0)
-
-###--------------------------------------------------------------------------
 ### vampire-specific rules.
 
 m4_divert(86)m4_dnl