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