Renumber the diversions.
[firewall] / local.m4
CommitLineData
775bd287 1### -*-sh-*-
bfdc045d
MW
2###
3### Local firewall configuration
4###
5### (c) 2008 Mark Wooding
6###
7
8###----- Licensing notice ---------------------------------------------------
9###
10### This program is free software; you can redistribute it and/or modify
11### it under the terms of the GNU General Public License as published by
12### the Free Software Foundation; either version 2 of the License, or
13### (at your option) any later version.
14###
15### This program is distributed in the hope that it will be useful,
16### but WITHOUT ANY WARRANTY; without even the implied warranty of
17### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18### GNU General Public License for more details.
19###
20### You should have received a copy of the GNU General Public License
21### along with this program; if not, write to the Free Software Foundation,
22### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24###--------------------------------------------------------------------------
25### Packet classification.
26
27## Define the available network classes.
28m4_divert(42)m4_dnl
29defnetclass untrusted untrusted trusted
30defnetclass trusted untrusted trusted safe noloop
31defnetclass safe trusted safe noloop
32defnetclass noloop trusted safe
a4d8cae3 33m4_divert(-1)
bfdc045d 34
a4d8cae3 35m4_divert(26)m4_dnl
bfdc045d
MW
36###--------------------------------------------------------------------------
37### Network layout.
38
a4d8cae3
MW
39m4_divert(44)m4_dnl
40## Network definitions.
08926d25
MW
41defiface $if_dmz \
42 trusted:62.49.204.144/28 \
43 trusted:172.29.199.0/25 \
44 untrusted:default
45defiface $if_trusted \
46 trusted:172.29.199.0/25 \
47 untrusted:default
48defiface $if_safe safe:172.29.199.192/26
bfdc045d 49defiface $if_untrusted \
f98dfdf6 50 untrusted:172.29.198.0/25
bfdc045d 51defvpn $if_vpn safe 172.29.199.128/27 \
9ec5456a
MW
52 crybaby:172.29.199.129 \
53 terror:172.29.199.130
f98dfdf6 54defiface $if_iodine untrusted:172.29.198.128/28
bfdc045d
MW
55defiface $if_its_mz safe:172.29.199.160/30
56defiface $if_its_pi safe:192.168.0.0/24
57
1ee6211d
MW
58## Default NTP servers.
59ntp_servers="158.152.1.76 158.152.1.204 194.159.253.2 195.173.57.232"
60
a4d8cae3 61m4_divert(80)m4_dnl
bfdc045d
MW
62###--------------------------------------------------------------------------
63### Special forwarding exemptions.
64
c70bfbbb
MW
65## Only allow these packets if they're not fragmented. (Don't trust safe
66## hosts's fragment reassembly to be robust against malicious fragments.)
67## There's a hideous bug in iptables 1.4.11.1 which botches the meaning of
68## `! -f', so we do the negation using early return from a subchain.
69clearchain fwd-spec-nofrag
70run iptables -A fwd-spec-nofrag -j RETURN --fragment
71run ip6tables -A fwd-spec-nofrag -j RETURN \
72 -m ipv6header --soft --header frag
73run iptables -A FORWARD -j fwd-spec-nofrag
74
bfdc045d 75## Allow ping from safe/noloop to untrusted networks.
c70bfbbb
MW
76run iptables -A fwd-spec-nofrag -j ACCEPT \
77 -p icmp --icmp-type echo-request \
bfdc045d 78 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb
MW
79run iptables -A fwd-spec-nofrag -j ACCEPT \
80 -p icmp --icmp-type echo-reply \
bfdc045d
MW
81 -m mark --mark $from_untrusted/$MASK_FROM \
82 -m state --state ESTABLISHED
c70bfbbb 83run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 84 -p ipv6-icmp --icmpv6-type echo-request \
0291d6d5 85 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb 86run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 87 -p ipv6-icmp --icmpv6-type echo-reply \
0291d6d5
MW
88 -m mark --mark $from_untrusted/$MASK_FROM \
89 -m state --state ESTABLISHED
bfdc045d
MW
90
91## Allow SSH from safe/noloop to untrusted networks.
c70bfbbb
MW
92run iptables -A fwd-spec-nofrag -j ACCEPT \
93 -p tcp --destination-port $port_ssh \
bfdc045d 94 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb
MW
95run iptables -A fwd-spec-nofrag -j ACCEPT \
96 -p tcp --source-port $port_ssh \
bfdc045d
MW
97 -m mark --mark $from_untrusted/$MASK_FROM \
98 -m state --state ESTABLISHED
c70bfbbb 99run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 100 -p tcp --destination-port $port_ssh \
0291d6d5 101 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb 102run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 103 -p tcp --source-port $port_ssh \
0291d6d5
MW
104 -m mark --mark $from_untrusted/$MASK_FROM \
105 -m state --state ESTABLISHED
bfdc045d 106
ade2c052 107m4_divert(60)m4_dnl
a4d8cae3 108m4_divert(80)m4_dnl
ade2c052
MW
109###--------------------------------------------------------------------------
110### Kill things we don't understand properly.
111###
112### I don't like having to do this, but since I don't know how to do proper
113### multicast filtering, I'm just going to ban it from being forwarded.
114
115errorchain poorly-understood REJECT
116
117## Ban multicast destination addresses in forwarding.
118run iptables -A FORWARD -g poorly-understood \
119 -d 224.0.0.0/4
120run ip6tables -A FORWARD -g poorly-understood \
121 -d ff::/8
122
a4d8cae3 123m4_divert(84)m4_dnl
bfdc045d
MW
124###--------------------------------------------------------------------------
125### Locally-bound packet inspection.
126
127clearchain inbound
128
129## Track connections.
ecdca131 130commonrules inbound
bfdc045d
MW
131conntrack inbound
132
133## Allow incoming bootp. Bootp won't be forwarded, so this is obviously a
134## local request.
135run iptables -A inbound -j ACCEPT \
136 -s 0.0.0.0 -d 255.255.255.255 \
137 -p udp --source-port $port_bootpc --destination-port $port_bootps
138run iptables -A inbound -j ACCEPT \
139 -s 172.29.198.0/23 \
140 -p udp --source-port $port_bootpc --destination-port $port_bootps
141
08926d25
MW
142## Incoming multicast on a network interface associated with a trusted
143## network is OK, since it must have originated there (or been forwarded, but
144## we don't do that yet).
145for i in $(echo $if_trusted $if_dmz $if_safe | sed 'y/,/ /'); do
146 echo $i
147done | {
148 seen=:
149 while read i; do
150 case "$seen" in *:$i:*) continue ;; esac
151 seen=$seen$i:
152 run iptables -A inbound -j ACCEPT \
429f4314 153 -s 0.0.0.0 -d 224.0.0.0/24 \
08926d25
MW
154 -i $i
155 done
156}
429f4314 157
bfdc045d 158## Allow incoming ping. This is the only ICMP left.
0291d6d5 159run ip46tables -A inbound -j ACCEPT -p icmp
bfdc045d
MW
160
161m4_divert(88)m4_dnl
162## Allow unusual things.
163openports inbound
164
165## Inspect inbound packets from untrusted sources.
0291d6d5
MW
166run ip46tables -A inbound -j forbidden
167run ip46tables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound
bfdc045d
MW
168
169## Otherwise process as indicated by the mark.
170for i in INPUT FORWARD; do
0291d6d5 171 run ip46tables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT
bfdc045d
MW
172done
173
174m4_divert(-1)
175###----- That's all, folks --------------------------------------------------