]> git.ipfire.org Git - people/stevee/network.git/blob - functions.policy
Remove old comment.
[people/stevee/network.git] / functions.policy
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 function policy_add_zone() {
23 local zone=${1}
24 assert isset zone
25
26 log DEBUG "Creating firewall policy for zone '${zone}'."
27
28 local chain="ZONE_${zone}"
29 chain=${chain^^}
30
31 # Create filter chain.
32 iptables_chain_create ${chain}
33 iptables -A INPUT -i ${zone} -j ${chain}
34 iptables -A FORWARD -i ${zone} -j ${chain}
35 iptables -A FORWARD -o ${zone} -j ${chain}
36 iptables -A OUTPUT -o ${zone} -j ${chain}
37
38 # Leave some space for own rules right at the beginning
39 # to make it possible to overwrite _everything_.
40 iptables_chain_create ${chain}_CUSTOM
41 iptables -A ${chain} -j ${chain}_CUSTOM
42
43 # Intrusion Prevention System
44 iptables_chain_create ${chain}_IPS
45 iptables -A ${chain} -i ${zone} -j ${chain}_IPS
46
47 # Port forwarding chain.
48 iptables_chain_create ${chain}_PORTFW
49 iptables -A ${chain} -i ${zone} -j ${chain}_PORTFW
50
51 # Outgoing firewall
52 iptables_chain_create ${chain}_OUTFW
53 iptables -A ${chain} -o ${zone} -j ${chain}_OUTFW
54
55 # Policy rules
56 iptables_chain_create ${chain}_POLICY
57 iptables -A ${chain} -j ${chain}_POLICY
58
59 # Create mangle chain.
60 iptables_chain_create -t mangle ${chain}
61 iptables -t mangle -A PREROUTING -i ${zone} -j ${chain}
62 iptables -t mangle -A POSTROUTING -o ${zone} -j ${chain}
63
64 # Quality of Service
65 iptables_chain_create -t mangle ${chain}_QOS_INC
66 iptables -t mangle -A ${chain} -i ${zone} -j ${chain}_QOS_INC
67 iptables_chain_create -t mangle ${chain}_QOS_OUT
68 iptables -t mangle -A ${chain} -o ${zone} -j ${chain}_QOS_OUT
69
70 # Create NAT chain.
71 iptables_chain_create -t nat ${chain}
72 iptables -t nat -A PREROUTING -i ${zone} -j ${chain}
73 iptables -t nat -A POSTROUTING -o ${zone} -j ${chain}
74
75 # Network Address Translation
76 iptables_chain_create -t nat ${chain}_NAT
77 iptables -t nat -A ${chain} -i ${zone} -j ${chain}_NAT
78
79 # Portforwarding
80 iptables_chain_create -t nat ${chain}_PORTFW
81 iptables -t nat -A ${chain} -i ${zone} -j ${chain}_PORTFW
82
83 # UPNP
84 iptables_chain_create -t nat ${chain}_UPNP
85 iptables -t nat -A ${chain} -j ${chain}_UPNP
86
87 # After the chains that are always available have been
88 # created, we will add a custom policy to every single
89 # zone.
90
91 # Local zones are currently allowed to access everything.
92 if zone_is_local ${zone}; then
93 policy_allow_all ${zone} ${chain}
94
95 # Uplink connections are not.
96 else
97 : # XXX TODO
98 fi
99 }
100
101 function policy_add_localhost() {
102 log DEBUG "Creating firewall policy for localhost..."
103
104 # Accept everything on lo
105 iptables -A INPUT -i lo -j ACCEPT
106 iptables -A OUTPUT -o lo -j ACCEPT
107 }
108
109 function policy_allow_all() {
110 local zone=${1}
111 assert isset zone
112
113 local chain=${2}
114 assert isset chain
115
116 # Just accept everything.
117 iptables -A ${chain}_POLICY -j ACCEPT
118 }