]>
Commit | Line | Data |
---|---|---|
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 | 22 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) |
6d8eb5de | 23 | eval $(/usr/local/bin/readhash /var/ipfire/firewall/settings) |
5d7faa45 AM |
24 | eval $(/usr/local/bin/readhash /var/ipfire/optionsfw/settings) |
25 | ||
a211fee3 MT |
26 | function iptables() { |
27 | /sbin/iptables --wait "$@" | |
28 | } | |
29 | ||
5d7faa45 AM |
30 | iptables -F POLICYFWD |
31 | iptables -F POLICYOUT | |
d47bb8a1 | 32 | iptables -F POLICYIN |
53f4c74d AM |
33 | |
34 | if [ -f "/var/ipfire/red/iface" ]; then | |
52c5ec83 | 35 | IFACE="$(</var/ipfire/red/iface)" |
53f4c74d | 36 | fi |
5d7faa45 | 37 | |
52c5ec83 MT |
38 | # Figure out what devices are configured. |
39 | HAVE_BLUE="false" | |
40 | HAVE_ORANGE="false" | |
41 | ||
42 | case "${CONFIG_TYPE}" in | |
43 | 2) | |
bcf1a624 | 44 | HAVE_ORANGE="true" |
52c5ec83 MT |
45 | ;; |
46 | 3) | |
bcf1a624 | 47 | HAVE_BLUE="true" |
52c5ec83 MT |
48 | ;; |
49 | 4) | |
50 | HAVE_BLUE="true" | |
51 | HAVE_ORANGE="true" | |
52 | ;; | |
53 | esac | |
54 | ||
2513ae73 MT |
55 | HAVE_OPENVPN="true" |
56 | ||
52c5ec83 MT |
57 | # INPUT |
58 | case "${FWPOLICY2}" in | |
59 | REJECT) | |
60 | if [ "${DROPINPUT}" = "on" ]; then | |
a211fee3 | 61 | iptables -A POLICYIN -m limit --limit 10/minute -j LOG --log-prefix "REJECT_INPUT" |
5d7faa45 | 62 | fi |
a211fee3 | 63 | iptables -A POLICYIN -j REJECT --reject-with icmp-host-unreachable -m comment --comment "DROP_INPUT" |
52c5ec83 MT |
64 | ;; |
65 | *) # DROP | |
2513ae73 MT |
66 | # OpenVPN |
67 | # Allow direct access to the internal IP addresses of the firewall | |
68 | # from remote subnets if forward policy is allowed. | |
69 | case "${HAVE_OPENVPN},${POLICY}" in | |
70 | true,MODE1) ;; | |
71 | true,*) | |
72 | iptables -A POLICYIN -i tun+ -j ACCEPT | |
73 | ;; | |
74 | esac | |
75 | ||
52c5ec83 | 76 | if [ "${DROPINPUT}" = "on" ]; then |
a211fee3 | 77 | iptables -A POLICYIN -m limit --limit 10/minute -j LOG --log-prefix "DROP_INPUT" |
5d7faa45 | 78 | fi |
a211fee3 | 79 | iptables -A POLICYIN -j DROP -m comment --comment "DROP_INPUT" |
52c5ec83 MT |
80 | ;; |
81 | esac | |
93b75f31 | 82 | |
52c5ec83 MT |
83 | # FORWARD |
84 | case "${POLICY}" in | |
85 | MODE1) | |
86 | case "${FWPOLICY}" in | |
87 | REJECT) | |
88 | if [ "${DROPFORWARD}" = "on" ]; then | |
a211fee3 | 89 | iptables -A POLICYFWD -m limit --limit 10/minute -j LOG --log-prefix "REJECT_FORWARD" |
52c5ec83 | 90 | fi |
a211fee3 | 91 | iptables -A POLICYFWD -j REJECT --reject-with icmp-host-unreachable -m comment --comment "DROP_FORWARD" |
52c5ec83 MT |
92 | ;; |
93 | *) # DROP | |
94 | if [ "${DROPFORWARD}" = "on" ]; then | |
a211fee3 | 95 | iptables -A POLICYFWD -m limit --limit 10/minute -j LOG --log-prefix "DROP_FORWARD" |
52c5ec83 | 96 | fi |
a211fee3 | 97 | iptables -A POLICYFWD -j DROP -m comment --comment "DROP_FORWARD" |
52c5ec83 MT |
98 | ;; |
99 | esac | |
100 | ;; | |
101 | ||
102 | *) | |
103 | if [ -n "${IFACE}" ]; then | |
104 | if [ "${HAVE_BLUE}" = "true" ] && [ -n "${BLUE_DEV}" ]; then | |
a211fee3 | 105 | iptables -A POLICYFWD -i "${BLUE_DEV}" ! -o "${IFACE}" -j DROP |
52c5ec83 MT |
106 | fi |
107 | if [ "${HAVE_ORANGE}" = "true" ] && [ -n "${ORANGE_DEV}" ]; then | |
a211fee3 | 108 | iptables -A POLICYFWD -i "${ORANGE_DEV}" ! -o "${IFACE}" -j DROP |
52c5ec83 | 109 | fi |
5d7faa45 | 110 | fi |
a211fee3 MT |
111 | iptables -A POLICYFWD -j ACCEPT |
112 | iptables -A POLICYFWD -m comment --comment "DROP_FORWARD" -j DROP | |
52c5ec83 MT |
113 | ;; |
114 | esac | |
115 | ||
116 | # OUTGOING | |
117 | case "${POLICY1}" in | |
118 | MODE1) | |
119 | case "${FWPOLICY1}" in | |
120 | REJECT) | |
121 | if [ "${DROPOUTGOING}" = "on" ]; then | |
a211fee3 | 122 | iptables -A POLICYOUT -m limit --limit 10/minute -j LOG --log-prefix "REJECT_OUTPUT" |
52c5ec83 | 123 | fi |
a211fee3 | 124 | iptables -A POLICYOUT -j REJECT --reject-with icmp-host-unreachable -m comment --comment "DROP_OUTPUT" |
52c5ec83 MT |
125 | ;; |
126 | *) # DROP | |
127 | if [ "${DROPOUTGOING}" == "on" ]; then | |
a211fee3 | 128 | iptables -A POLICYOUT -m limit --limit 10/minute -j LOG --log-prefix "DROP_OUTPUT" |
52c5ec83 | 129 | fi |
a211fee3 | 130 | iptables -A POLICYOUT -j DROP -m comment --comment "DROP_OUTPUT" |
52c5ec83 MT |
131 | ;; |
132 | esac | |
133 | ;; | |
134 | *) | |
a211fee3 MT |
135 | iptables -A POLICYOUT -j ACCEPT |
136 | iptables -A POLICYOUT -m comment --comment "DROP_OUTPUT" -j DROP | |
52c5ec83 MT |
137 | ;; |
138 | esac | |
aff15def AM |
139 | |
140 | exit 0 |