]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - config/firewall/firewall-policy
firewall: Load conntrack modules in firewall script.
[people/teissler/ipfire-2.x.git] / config / firewall / firewall-policy
CommitLineData
5d7faa45 1#!/bin/sh
dc21519f
AM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5bee9a9d 5# Copyright (C) 2013 Alexander Marx <amarx@ipfire.org> #
dc21519f
AM
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###############################################################################
dc21519f 21
52c5ec83 22eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
6d8eb5de 23eval $(/usr/local/bin/readhash /var/ipfire/firewall/settings)
5d7faa45
AM
24eval $(/usr/local/bin/readhash /var/ipfire/optionsfw/settings)
25
26iptables -F POLICYFWD
27iptables -F POLICYOUT
d47bb8a1 28iptables -F POLICYIN
53f4c74d
AM
29
30if [ -f "/var/ipfire/red/iface" ]; then
52c5ec83 31 IFACE="$(</var/ipfire/red/iface)"
53f4c74d 32fi
5d7faa45 33
52c5ec83
MT
34# Figure out what devices are configured.
35HAVE_BLUE="false"
36HAVE_ORANGE="false"
37
38case "${CONFIG_TYPE}" in
39 2)
40 HAVE_BLUE="true"
41 ;;
42 3)
43 HAVE_ORANGE="true"
44 ;;
45 4)
46 HAVE_BLUE="true"
47 HAVE_ORANGE="true"
48 ;;
49esac
50
51# INPUT
52case "${FWPOLICY2}" in
53 REJECT)
54 if [ "${DROPINPUT}" = "on" ]; then
55 /sbin/iptables -A POLICYIN -m limit --limit 10/minute -j LOG --log-prefix "REJECT_INPUT"
5d7faa45 56 fi
52c5ec83
MT
57 /sbin/iptables -A POLICYIN -j REJECT --reject-with icmp-host-unreachable -m comment --comment "DROP_INPUT"
58 ;;
59 *) # DROP
60 if [ "${DROPINPUT}" = "on" ]; then
61 /sbin/iptables -A POLICYIN -m limit --limit 10/minute -j LOG --log-prefix "DROP_INPUT"
5d7faa45 62 fi
52c5ec83
MT
63 /sbin/iptables -A POLICYIN -j DROP -m comment --comment "DROP_INPUT"
64 ;;
65esac
93b75f31 66
52c5ec83
MT
67# FORWARD
68case "${POLICY}" in
69 MODE1)
70 case "${FWPOLICY}" in
71 REJECT)
72 if [ "${DROPFORWARD}" = "on" ]; then
73 /sbin/iptables -A POLICYFWD -m limit --limit 10/minute -j LOG --log-prefix "REJECT_FORWARD"
74 fi
75 /sbin/iptables -A POLICYFWD -j REJECT --reject-with icmp-host-unreachable -m comment --comment "DROP_FORWARD"
76 ;;
77 *) # DROP
78 if [ "${DROPFORWARD}" = "on" ]; then
79 /sbin/iptables -A POLICYFWD -m limit --limit 10/minute -j LOG --log-prefix "DROP_FORWARD"
80 fi
81 /sbin/iptables -A POLICYFWD -j DROP -m comment --comment "DROP_FORWARD"
82 ;;
83 esac
84 ;;
85
86 *)
87 if [ -n "${IFACE}" ]; then
88 if [ "${HAVE_BLUE}" = "true" ] && [ -n "${BLUE_DEV}" ]; then
89 /sbin/iptables -A POLICYFWD -i "${BLUE_DEV}" ! -o "${IFACE}" -j DROP
90 fi
91 if [ "${HAVE_ORANGE}" = "true" ] && [ -n "${ORANGE_DEV}" ]; then
92 /sbin/iptables -A POLICYFWD -i "${ORANGE_DEV}" ! -o "${IFACE}" -j DROP
93 fi
5d7faa45 94 fi
52c5ec83
MT
95 /sbin/iptables -A POLICYFWD -j ACCEPT
96 /sbin/iptables -A POLICYFWD -m comment --comment "DROP_FORWARD" -j DROP
97 ;;
98esac
99
100# OUTGOING
101case "${POLICY1}" in
102 MODE1)
103 case "${FWPOLICY1}" in
104 REJECT)
105 if [ "${DROPOUTGOING}" = "on" ]; then
106 /sbin/iptables -A POLICYOUT -m limit --limit 10/minute -j LOG --log-prefix "REJECT_OUTPUT"
107 fi
108 /sbin/iptables -A POLICYOUT -j REJECT --reject-with icmp-host-unreachable -m comment --comment "DROP_OUTPUT"
109 ;;
110 *) # DROP
111 if [ "${DROPOUTGOING}" == "on" ]; then
112 /sbin/iptables -A POLICYOUT -m limit --limit 10/minute -j LOG --log-prefix "DROP_OUTPUT"
113 fi
114 /sbin/iptables -A POLICYOUT -j DROP -m comment --comment "DROP_OUTPUT"
115 ;;
116 esac
117 ;;
118 *)
119 /sbin/iptables -A POLICYOUT -j ACCEPT
120 /sbin/iptables -A POLICYOUT -m comment --comment "DROP_OUTPUT" -j DROP
121 ;;
122esac
aff15def
AM
123
124exit 0