chiark / gitweb /
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 4adcc21f5146971c3460f0c7ea03cfe61ab8cd14..a04cc9c0fa8fb0f4380de8688ed75f41939d31c0 100644 (file)
--- a/artist.m4
+++ b/artist.m4
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
index 38b4e91a6deca8399657714b03b0a8c3c650b1ed..6caad93f8d8b084fbd1cbea86c6280dd31d0e870 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 4b059dfb4985ba3653ca556ead659124ea876091..ee9ef904c5a44fb4a2af544f6ad1a0487f8f5802 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 6fc2e4f2cc997af005f55d7f3e13abf9afdbc2f7..05354bd731f105b03d34c79909571fe065c457ed 100644 (file)
--- a/fender.m4
+++ b/fender.m4
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
index 5c82c417c0d41b4e2f4851563842c07a3793a796..4416aee71485c78a962dfd53212f52b4eb89ed18 100644 (file)
--- a/gibson.m4
+++ b/gibson.m4
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
index e50b56cc683a1f35bc3a28dd09dff754bbc1d7f8..93a816e7d98105853660436c187e1a2b419a517f 100644 (file)
--- a/ibanez.m4
+++ b/ibanez.m4
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
diff --git a/jem.m4 b/jem.m4
index afb8068439f09ec26e12383843378c6a13f71056..7db1ce5aed7fe8f9df8c337fb09f0a99b187b2c2 100644 (file)
--- a/jem.m4
+++ b/jem.m4
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
index 69122e24f69aae151be467b9e3d30010112cc9af..b31b649a6e111653334d9fd975ee4f7c31ee5332 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 72a8e1f0c7e1d5ec7349b9085b05f1811e293b2e..d6989986f3b6bfba641ecfeffb8e48ae0f124fa2 100644 (file)
--- a/radius.m4
+++ b/radius.m4
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
index a95cc3b74611b33bb17c96a702ed0677e5701fe2..4947a801571e8b193dab38054955d974aab0cc36 100644 (file)
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.
 
index 6ddbbf5223bb624139b5e3d6e71133d42225064b..fa79ee213875bc78fb07ecfd5a02255fea525b49 100644 (file)
 ### along with this program; if not, write to the Free Software Foundation,
 ### 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.