classify.m4: Correct summary line at the top.
[firewall] / local.m4
CommitLineData
bfdc045d
MW
1### -*-m4-*-
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
33m4_divert(-1)m4_dnl
34
35###--------------------------------------------------------------------------
36### Network layout.
37
38m4_divert(46)m4_dnl
39## Networks and routing.
40
41defiface $if_trusted \
42 trusted:172.29.199.0/26 \
43 safe:172.29.199.64/27 \
44 untrusted:default
45defiface $if_untrusted \
46 untrusted:172.29.198.0/24
47defvpn $if_vpn safe 172.29.199.128/27 \
48 crybaby:172.29.199.129
49defiface $if_its_mz safe:172.29.199.160/30
50defiface $if_its_pi safe:192.168.0.0/24
51
52m4_divert(60)m4_dnl
53###--------------------------------------------------------------------------
54### Special forwarding exemptions.
55
56## Allow ping from safe/noloop to untrusted networks.
57run iptables -A FORWARD -j ACCEPT \
58 -p icmp --icmp-type echo-request \
59 -m mark --mark $to_untrusted/$MASK_TO
60run iptables -A FORWARD -j ACCEPT \
61 -p icmp --icmp-type echo-reply \
62 -m mark --mark $from_untrusted/$MASK_FROM \
63 -m state --state ESTABLISHED
64
65## Allow SSH from safe/noloop to untrusted networks.
66run iptables -A FORWARD -j ACCEPT \
67 -p tcp --destination-port $port_ssh \
68 -m mark --mark $to_untrusted/$MASK_TO
69run iptables -A FORWARD -j ACCEPT \
70 -p tcp --source-port $port_ssh \
71 -m mark --mark $from_untrusted/$MASK_FROM \
72 -m state --state ESTABLISHED
73
74m4_divert(80)m4_dnl
75###--------------------------------------------------------------------------
76### Locally-bound packet inspection.
77
78clearchain inbound
79
80## Track connections.
81conntrack inbound
82
83## Allow incoming bootp. Bootp won't be forwarded, so this is obviously a
84## local request.
85run iptables -A inbound -j ACCEPT \
86 -s 0.0.0.0 -d 255.255.255.255 \
87 -p udp --source-port $port_bootpc --destination-port $port_bootps
88run iptables -A inbound -j ACCEPT \
89 -s 172.29.198.0/23 \
90 -p udp --source-port $port_bootpc --destination-port $port_bootps
91
92## Allow incoming ping. This is the only ICMP left.
93run iptables -A inbound -j ACCEPT -p icmp
94
95m4_divert(88)m4_dnl
96## Allow unusual things.
97openports inbound
98
99## Inspect inbound packets from untrusted sources.
100run iptables -A inbound -j forbidden
101run iptables -A INPUT -m mark --mark $from_untrusted/$MASK_FROM -g inbound
102
103## Otherwise process as indicated by the mark.
104for i in INPUT FORWARD; do
105 run iptables -A $i -m mark ! --mark 0/$MASK_MASK -j ACCEPT
106done
107
108m4_divert(-1)
109###----- That's all, folks --------------------------------------------------