local.m4: Promote the NTP server configuration to a proper variable.
[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###--------------------------------------------------------------------------
335b2afe
MW
25### Local configuration.
26
27m4_divert(6)m4_dnl
28## Default NTP servers.
29defconf(ntp_servers,
30 "158.152.1.76 158.152.1.204 194.159.253.2 195.173.57.232")
31
32m4_divert(-1)
33###--------------------------------------------------------------------------
bfdc045d
MW
34### Packet classification.
35
36## Define the available network classes.
37m4_divert(42)m4_dnl
38defnetclass untrusted untrusted trusted
39defnetclass trusted untrusted trusted safe noloop
40defnetclass safe trusted safe noloop
41defnetclass noloop trusted safe
a4d8cae3 42m4_divert(-1)
bfdc045d 43
a4d8cae3 44m4_divert(26)m4_dnl
bfdc045d
MW
45###--------------------------------------------------------------------------
46### Network layout.
47
a4d8cae3
MW
48m4_divert(44)m4_dnl
49## Network definitions.
08926d25
MW
50defiface $if_dmz \
51 trusted:62.49.204.144/28 \
52 trusted:172.29.199.0/25 \
53 untrusted:default
54defiface $if_trusted \
55 trusted:172.29.199.0/25 \
56 untrusted:default
57defiface $if_safe safe:172.29.199.192/26
bfdc045d 58defiface $if_untrusted \
f98dfdf6 59 untrusted:172.29.198.0/25
bfdc045d 60defvpn $if_vpn safe 172.29.199.128/27 \
9ec5456a
MW
61 crybaby:172.29.199.129 \
62 terror:172.29.199.130
f98dfdf6 63defiface $if_iodine untrusted:172.29.198.128/28
bfdc045d
MW
64defiface $if_its_mz safe:172.29.199.160/30
65defiface $if_its_pi safe:192.168.0.0/24
66
1ee6211d 67
a4d8cae3 68m4_divert(80)m4_dnl
bfdc045d
MW
69###--------------------------------------------------------------------------
70### Special forwarding exemptions.
71
c70bfbbb
MW
72## Only allow these packets if they're not fragmented. (Don't trust safe
73## hosts's fragment reassembly to be robust against malicious fragments.)
74## There's a hideous bug in iptables 1.4.11.1 which botches the meaning of
75## `! -f', so we do the negation using early return from a subchain.
76clearchain fwd-spec-nofrag
77run iptables -A fwd-spec-nofrag -j RETURN --fragment
78run ip6tables -A fwd-spec-nofrag -j RETURN \
79 -m ipv6header --soft --header frag
80run iptables -A FORWARD -j fwd-spec-nofrag
81
bfdc045d 82## Allow ping from safe/noloop to untrusted networks.
c70bfbbb
MW
83run iptables -A fwd-spec-nofrag -j ACCEPT \
84 -p icmp --icmp-type echo-request \
bfdc045d 85 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb
MW
86run iptables -A fwd-spec-nofrag -j ACCEPT \
87 -p icmp --icmp-type echo-reply \
bfdc045d
MW
88 -m mark --mark $from_untrusted/$MASK_FROM \
89 -m state --state ESTABLISHED
c70bfbbb 90run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 91 -p ipv6-icmp --icmpv6-type echo-request \
0291d6d5 92 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb 93run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 94 -p ipv6-icmp --icmpv6-type echo-reply \
0291d6d5
MW
95 -m mark --mark $from_untrusted/$MASK_FROM \
96 -m state --state ESTABLISHED
bfdc045d
MW
97
98## Allow SSH from safe/noloop to untrusted networks.
c70bfbbb
MW
99run iptables -A fwd-spec-nofrag -j ACCEPT \
100 -p tcp --destination-port $port_ssh \
bfdc045d 101 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb
MW
102run iptables -A fwd-spec-nofrag -j ACCEPT \
103 -p tcp --source-port $port_ssh \
bfdc045d
MW
104 -m mark --mark $from_untrusted/$MASK_FROM \
105 -m state --state ESTABLISHED
c70bfbbb 106run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 107 -p tcp --destination-port $port_ssh \
0291d6d5 108 -m mark --mark $to_untrusted/$MASK_TO
c70bfbbb 109run ip6tables -A fwd-spec-nofrag -j ACCEPT \
0291d6d5 110 -p tcp --source-port $port_ssh \
0291d6d5
MW
111 -m mark --mark $from_untrusted/$MASK_FROM \
112 -m state --state ESTABLISHED
bfdc045d 113
ade2c052 114m4_divert(60)m4_dnl
a4d8cae3 115m4_divert(80)m4_dnl
ade2c052
MW
116###--------------------------------------------------------------------------
117### Kill things we don't understand properly.
118###
119### I don't like having to do this, but since I don't know how to do proper
120### multicast filtering, I'm just going to ban it from being forwarded.
121
122errorchain poorly-understood REJECT
123
124## Ban multicast destination addresses in forwarding.
125run iptables -A FORWARD -g poorly-understood \
126 -d 224.0.0.0/4
127run ip6tables -A FORWARD -g poorly-understood \
128 -d ff::/8
129
a4d8cae3 130m4_divert(84)m4_dnl
bfdc045d
MW
131###--------------------------------------------------------------------------
132### Locally-bound packet inspection.
133
134clearchain inbound
135
136## Track connections.
ecdca131 137commonrules inbound
bfdc045d
MW
138conntrack inbound
139
140## Allow incoming bootp. Bootp won't be forwarded, so this is obviously a
141## local request.
142run iptables -A inbound -j ACCEPT \
143 -s 0.0.0.0 -d 255.255.255.255 \
144 -p udp --source-port $port_bootpc --destination-port $port_bootps
145run iptables -A inbound -j ACCEPT \
146 -s 172.29.198.0/23 \
147 -p udp --source-port $port_bootpc --destination-port $port_bootps
148
08926d25
MW
149## Incoming multicast on a network interface associated with a trusted
150## network is OK, since it must have originated there (or been forwarded, but
151## we don't do that yet).
152for i in $(echo $if_trusted $if_dmz $if_safe | sed 'y/,/ /'); do
153 echo $i
154done | {
155 seen=:
156 while read i; do
157 case "$seen" in *:$i:*) continue ;; esac
158 seen=$seen$i:
159 run iptables -A inbound -j ACCEPT \
429f4314 160 -s 0.0.0.0 -d 224.0.0.0/24 \
08926d25
MW
161 -i $i
162 done
163}
429f4314 164
bfdc045d 165## Allow incoming ping. This is the only ICMP left.
0291d6d5 166run ip46tables -A inbound -j ACCEPT -p icmp
bfdc045d
MW
167
168m4_divert(88)m4_dnl
169## Allow unusual things.
170openports inbound
171
172## Inspect inbound packets from untrusted sources.
0291d6d5
MW
173run ip46tables -A inbound -j forbidden
174run ip46tables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound
bfdc045d
MW
175
176## Otherwise process as indicated by the mark.
177for i in INPUT FORWARD; do
0291d6d5 178 run ip46tables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT
bfdc045d
MW
179done
180
181m4_divert(-1)
182###----- That's all, folks --------------------------------------------------