]>
Commit | Line | Data |
---|---|---|
3a1019f6 MT |
1 | #!/bin/sh |
2 | ||
0f5c5ce7 MT |
3 | . /etc/sysconfig/rc |
4 | . ${rc_functions} | |
5 | ||
3a1019f6 MT |
6 | eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) |
7 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
fe0cd647 | 8 | eval $(/usr/local/bin/readhash /var/ipfire/optionsfw/settings) |
3a1019f6 MT |
9 | IFACE=`/bin/cat /var/ipfire/red/iface 2> /dev/null | /usr/bin/tr -d '\012'` |
10 | ||
11 | if [ -f /var/ipfire/red/device ]; then | |
12 | DEVICE=`/bin/cat /var/ipfire/red/device 2> /dev/null | /usr/bin/tr -d '\012'` | |
13 | fi | |
14 | ||
c581b670 MT |
15 | function iptables() { |
16 | /sbin/iptables --wait "$@" | |
17 | } | |
18 | ||
3a1019f6 MT |
19 | iptables_init() { |
20 | # Flush all rules and delete all custom chains | |
c581b670 MT |
21 | iptables -F |
22 | iptables -t nat -F | |
23 | iptables -t mangle -F | |
b1109b8a | 24 | iptables -t raw -F |
c581b670 MT |
25 | iptables -X |
26 | iptables -t nat -X | |
27 | iptables -t mangle -X | |
b1109b8a | 28 | iptables -t raw -X |
3a1019f6 MT |
29 | |
30 | # Set up policies | |
c581b670 MT |
31 | iptables -P INPUT DROP |
32 | iptables -P FORWARD DROP | |
33 | iptables -P OUTPUT ACCEPT | |
3a1019f6 MT |
34 | |
35 | # Empty LOG_DROP and LOG_REJECT chains | |
c581b670 MT |
36 | iptables -N LOG_DROP |
37 | iptables -A LOG_DROP -m limit --limit 10/minute -j LOG | |
38 | iptables -A LOG_DROP -j DROP | |
39 | iptables -N LOG_REJECT | |
40 | iptables -A LOG_REJECT -m limit --limit 10/minute -j LOG | |
41 | iptables -A LOG_REJECT -j REJECT | |
3a1019f6 MT |
42 | |
43 | # This chain will log, then DROPs packets with certain bad combinations | |
44 | # of flags might indicate a port-scan attempt (xmas, null, etc) | |
c581b670 | 45 | iptables -N PSCAN |
5595bc03 | 46 | if [ "$DROPPORTSCAN" == "on" ]; then |
c581b670 MT |
47 | iptables -A PSCAN -p tcp -m limit --limit 10/minute -j LOG --log-prefix "DROP_TCP Scan " -m comment --comment "DROP_TCP PScan" |
48 | iptables -A PSCAN -p udp -m limit --limit 10/minute -j LOG --log-prefix "DROP_UDP Scan " -m comment --comment "DROP_UDP PScan" | |
49 | iptables -A PSCAN -p icmp -m limit --limit 10/minute -j LOG --log-prefix "DROP_ICMP Scan " -m comment --comment "DROP_ICMP PScan" | |
50 | iptables -A PSCAN -f -m limit --limit 10/minute -j LOG --log-prefix "DROP_FRAG Scan " -m comment --comment "DROP_FRAG PScan" | |
5595bc03 | 51 | fi |
c581b670 | 52 | iptables -A PSCAN -j DROP -m comment --comment "DROP_PScan" |
3a1019f6 MT |
53 | |
54 | # New tcp packets without SYN set - could well be an obscure type of port scan | |
55 | # that's not covered above, may just be a broken windows machine | |
c581b670 | 56 | iptables -N NEWNOTSYN |
5595bc03 | 57 | if [ "$DROPNEWNOTSYN" == "on" ]; then |
c581b670 | 58 | iptables -A NEWNOTSYN -m limit --limit 10/minute -j LOG --log-prefix "DROP_NEWNOTSYN " |
5595bc03 | 59 | fi |
c581b670 | 60 | iptables -A NEWNOTSYN -j DROP -m comment --comment "DROP_NEWNOTSYN" |
3a1019f6 MT |
61 | |
62 | # Chain to contain all the rules relating to bad TCP flags | |
c581b670 | 63 | iptables -N BADTCP |
3a1019f6 | 64 | |
c581b670 MT |
65 | # Don't check loopback |
66 | iptables -A BADTCP -i lo -j RETURN | |
d8158ca6 | 67 | |
3a1019f6 | 68 | # Disallow packets frequently used by port-scanners |
dccbf1bf AF |
69 | # NMAP FIN/URG/PSH (XMAS scan) |
70 | iptables -A BADTCP -p tcp --tcp-flags ALL FIN,URG,PSH -j PSCAN | |
71 | # SYN/RST/ACK/FIN/URG | |
72 | iptables -A BADTCP -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j PSCAN | |
73 | # ALL/ALL | |
74 | iptables -A BADTCP -p tcp --tcp-flags ALL ALL -j PSCAN | |
75 | # FIN Stealth | |
c581b670 | 76 | iptables -A BADTCP -p tcp --tcp-flags ALL FIN -j PSCAN |
3a1019f6 | 77 | # SYN/RST (also catches xmas variants that set SYN+RST+...) |
c581b670 | 78 | iptables -A BADTCP -p tcp --tcp-flags SYN,RST SYN,RST -j PSCAN |
3a1019f6 | 79 | # SYN/FIN (QueSO or nmap OS probe) |
c581b670 | 80 | iptables -A BADTCP -p tcp --tcp-flags SYN,FIN SYN,FIN -j PSCAN |
dccbf1bf AF |
81 | # Null |
82 | iptables -A BADTCP -p tcp --tcp-flags ALL NONE -j PSCAN | |
3a1019f6 | 83 | # NEW TCP without SYN |
c581b670 | 84 | iptables -A BADTCP -p tcp ! --syn -m conntrack --ctstate NEW -j NEWNOTSYN |
b85d2a98 | 85 | |
c581b670 MT |
86 | iptables -A INPUT -p tcp -j BADTCP |
87 | iptables -A FORWARD -p tcp -j BADTCP | |
c0359d6d | 88 | |
b1109b8a | 89 | # Connection tracking chains |
c581b670 | 90 | iptables -N CONNTRACK |
b1109b8a | 91 | iptables -A CONNTRACK -m conntrack --ctstate ESTABLISHED -j ACCEPT |
dccbf1bf | 92 | iptables -A CONNTRACK -m conntrack --ctstate INVALID -j DROP |
0f535060 | 93 | iptables -A CONNTRACK -p icmp -m conntrack --ctstate RELATED -j ACCEPT |
b1109b8a MT |
94 | iptables -t raw -N CONNTRACK |
95 | iptables -t raw -A PREROUTING -j CONNTRACK | |
96 | ||
97 | # Conntrack helpers (https://home.regit.org/netfilter-en/secure-use-of-helpers/) | |
98 | ||
99 | # SIP | |
d57c6162 MT |
100 | if [ "${CONNTRACK_SIP}" = "on" ]; then |
101 | iptables -A CONNTRACK -m conntrack --ctstate RELATED \ | |
102 | -m helper --helper sip -j ACCEPT | |
103 | for proto in udp tcp; do | |
104 | iptables -t raw -A CONNTRACK -p "${proto}" --dport 5060 -j CT --helper sip | |
105 | done | |
106 | fi | |
b1109b8a MT |
107 | |
108 | # FTP | |
d57c6162 MT |
109 | if [ "${CONNTRACK_FTP}" = "on" ]; then |
110 | iptables -A CONNTRACK -m conntrack --ctstate RELATED \ | |
111 | -m helper --helper ftp -p tcp --dport 1024: -j ACCEPT | |
112 | iptables -t raw -A CONNTRACK -p tcp --dport 21 -j CT --helper ftp | |
113 | fi | |
b1109b8a MT |
114 | |
115 | # PPTP | |
d57c6162 MT |
116 | if [ "${CONNTRACK_PPTP}" = "on" ]; then |
117 | iptables -A CONNTRACK -m conntrack --ctstate RELATED \ | |
118 | -m helper --helper pptp -j ACCEPT | |
119 | iptables -t raw -A CONNTRACK -p udp --dport 1723 -j CT --helper pptp | |
120 | fi | |
b1109b8a MT |
121 | |
122 | # TFTP | |
d57c6162 MT |
123 | if [ "${CONNTRACK_TFTP}" = "on" ]; then |
124 | iptables -A CONNTRACK -m conntrack --ctstate RELATED \ | |
125 | -m helper --helper tftp -j ACCEPT | |
126 | iptables -t raw -A CONNTRACK -p udp --dport 69 -j CT --helper tftp | |
127 | fi | |
3a1019f6 | 128 | |
a93bf696 MT |
129 | # Amanda |
130 | if [ "${CONNTRACK_AMANDA}" = "on" ]; then | |
131 | iptables -A CONNTRACK -m conntrack --ctstate RELATED \ | |
132 | -m helper --helper amanda -j ACCEPT | |
133 | iptables -t raw -A CONNTRACK -j CT --helper amanda | |
134 | fi | |
135 | ||
3a1019f6 | 136 | # Fix for braindead ISP's |
c581b670 | 137 | iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu |
3a1019f6 MT |
138 | |
139 | # CUSTOM chains, can be used by the users themselves | |
c581b670 MT |
140 | iptables -N CUSTOMINPUT |
141 | iptables -A INPUT -j CUSTOMINPUT | |
142 | iptables -N CUSTOMFORWARD | |
143 | iptables -A FORWARD -j CUSTOMFORWARD | |
144 | iptables -N CUSTOMOUTPUT | |
145 | iptables -A OUTPUT -j CUSTOMOUTPUT | |
146 | iptables -t nat -N CUSTOMPREROUTING | |
147 | iptables -t nat -A PREROUTING -j CUSTOMPREROUTING | |
148 | iptables -t nat -N CUSTOMPOSTROUTING | |
149 | iptables -t nat -A POSTROUTING -j CUSTOMPOSTROUTING | |
3a1019f6 | 150 | |
2a5b19c5 AF |
151 | # P2PBLOCK |
152 | iptables -N P2PBLOCK | |
153 | iptables -A INPUT -j P2PBLOCK | |
154 | iptables -A FORWARD -j P2PBLOCK | |
155 | iptables -A OUTPUT -j P2PBLOCK | |
156 | ||
815eaff4 | 157 | # Guardian (IPS) chains |
c581b670 MT |
158 | iptables -N GUARDIAN |
159 | iptables -A INPUT -j GUARDIAN | |
160 | iptables -A FORWARD -j GUARDIAN | |
815eaff4 | 161 | |
1e555330 | 162 | # Block OpenVPN transfer networks |
c581b670 | 163 | iptables -N OVPNBLOCK |
a0a5c14f | 164 | iptables -A INPUT -i tun+ -j OVPNBLOCK |
a0a5c14f MT |
165 | iptables -A FORWARD -i tun+ -j OVPNBLOCK |
166 | iptables -A FORWARD -o tun+ -j OVPNBLOCK | |
1e555330 | 167 | |
51ab1de1 | 168 | # OpenVPN transfer network translation |
c581b670 MT |
169 | iptables -t nat -N OVPNNAT |
170 | iptables -t nat -A POSTROUTING -j OVPNNAT | |
51ab1de1 | 171 | |
daa1ceba | 172 | # IPTV chains for IGMPPROXY |
c581b670 MT |
173 | iptables -N IPTVINPUT |
174 | iptables -A INPUT -j IPTVINPUT | |
175 | iptables -N IPTVFORWARD | |
176 | iptables -A FORWARD -j IPTVFORWARD | |
daa1ceba | 177 | |
8e59a602 MT |
178 | # Allow to ping the firewall. |
179 | iptables -N ICMPINPUT | |
180 | iptables -A INPUT -j ICMPINPUT | |
181 | iptables -A ICMPINPUT -p icmp --icmp-type 8 -j ACCEPT | |
3a1019f6 | 182 | |
afc611d4 | 183 | # Accept everything on loopback |
c581b670 MT |
184 | iptables -N LOOPBACK |
185 | iptables -A LOOPBACK -i lo -j ACCEPT | |
186 | iptables -A LOOPBACK -o lo -j ACCEPT | |
afc611d4 | 187 | |
3b9a23ce | 188 | # Filter all packets with loopback addresses on non-loopback interfaces. |
c581b670 MT |
189 | iptables -A LOOPBACK -s 127.0.0.0/8 -j DROP |
190 | iptables -A LOOPBACK -d 127.0.0.0/8 -j DROP | |
3b9a23ce MT |
191 | |
192 | for i in INPUT FORWARD OUTPUT; do | |
c581b670 | 193 | iptables -A ${i} -j LOOPBACK |
3b9a23ce | 194 | done |
afc611d4 | 195 | |
3a1019f6 | 196 | # Accept everything connected |
b85d2a98 | 197 | for i in INPUT FORWARD OUTPUT; do |
c581b670 | 198 | iptables -A ${i} -j CONNTRACK |
b85d2a98 MT |
199 | done |
200 | ||
8490e496 MT |
201 | # Allow DHCP |
202 | iptables -N DHCPINPUT | |
203 | iptables -A DHCPINPUT -p udp --sport 68 --dport 67 -j ACCEPT | |
204 | iptables -A DHCPINPUT -p tcp --sport 68 --dport 67 -j ACCEPT | |
205 | ||
206 | iptables -N DHCPOUTPUT | |
207 | iptables -A DHCPOUTPUT -p udp --sport 67 --dport 68 -j ACCEPT | |
208 | iptables -A DHCPOUTPUT -p tcp --sport 67 --dport 68 -j ACCEPT | |
209 | ||
210 | # Allow DHCP on GREEN | |
211 | iptables -N DHCPGREENINPUT | |
212 | iptables -N DHCPGREENOUTPUT | |
213 | if [ -n "${GREEN_DEV}" ]; then | |
214 | iptables -A INPUT -i "${GREEN_DEV}" -j DHCPGREENINPUT | |
215 | iptables -A OUTPUT -o "${GREEN_DEV}" -j DHCPGREENOUTPUT | |
216 | fi | |
217 | ||
218 | # allow DHCP on BLUE to be turned on/off | |
219 | iptables -N DHCPBLUEINPUT | |
220 | iptables -N DHCPBLUEOUTPUT | |
221 | if [ -n "${BLUE_DEV}" ]; then | |
222 | iptables -A INPUT -i "${BLUE_DEV}" -j DHCPBLUEINPUT | |
223 | iptables -A OUTPUT -o "${BLUE_DEV}" -j DHCPBLUEOUTPUT | |
224 | fi | |
225 | ||
cab02e2a SS |
226 | # GeoIP block |
227 | iptables -N GEOIPBLOCK | |
228 | iptables -A INPUT -j GEOIPBLOCK | |
229 | iptables -A FORWARD -j GEOIPBLOCK | |
230 | ||
5fd30232 | 231 | # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything |
c581b670 MT |
232 | iptables -N IPSECINPUT |
233 | iptables -N IPSECFORWARD | |
234 | iptables -N IPSECOUTPUT | |
235 | iptables -A INPUT -j IPSECINPUT | |
236 | iptables -A FORWARD -j IPSECFORWARD | |
237 | iptables -A OUTPUT -j IPSECOUTPUT | |
238 | iptables -t nat -N IPSECNAT | |
239 | iptables -t nat -A POSTROUTING -j IPSECNAT | |
b68e5c14 | 240 | |
3a1019f6 | 241 | # localhost and ethernet. |
c0e0848f MT |
242 | # Always allow accessing the web GUI from GREEN. |
243 | iptables -N GUIINPUT | |
244 | iptables -A INPUT -j GUIINPUT | |
245 | iptables -A GUIINPUT -i "${GREEN_DEV}" -p tcp --dport 444 -j ACCEPT | |
8490e496 | 246 | |
81393987 | 247 | # WIRELESS chains |
c581b670 MT |
248 | iptables -N WIRELESSINPUT |
249 | iptables -A INPUT -m conntrack --ctstate NEW -j WIRELESSINPUT | |
250 | iptables -N WIRELESSFORWARD | |
251 | iptables -A FORWARD -m conntrack --ctstate NEW -j WIRELESSFORWARD | |
987b75bc | 252 | |
ab4876ad | 253 | # OpenVPN |
c581b670 MT |
254 | iptables -N OVPNINPUT |
255 | iptables -A INPUT -j OVPNINPUT | |
ab4876ad | 256 | |
987b75bc | 257 | # TOR |
c581b670 MT |
258 | iptables -N TOR_INPUT |
259 | iptables -A INPUT -j TOR_INPUT | |
12dcfbbd | 260 | |
d5f1422d | 261 | # Jump into the actual firewall ruleset. |
c581b670 MT |
262 | iptables -N INPUTFW |
263 | iptables -A INPUT -j INPUTFW | |
d5f1422d | 264 | |
c581b670 MT |
265 | iptables -N OUTGOINGFW |
266 | iptables -A OUTPUT -j OUTGOINGFW | |
d5f1422d | 267 | |
c581b670 MT |
268 | iptables -N FORWARDFW |
269 | iptables -A FORWARD -j FORWARDFW | |
d5f1422d | 270 | |
fac38614 | 271 | # SNAT rules |
c581b670 MT |
272 | iptables -t nat -N NAT_SOURCE |
273 | iptables -t nat -A POSTROUTING -j NAT_SOURCE | |
fac38614 | 274 | |
bb12dd7b | 275 | # Custom prerouting chains (for transparent proxy) |
c581b670 MT |
276 | iptables -t nat -N SQUID |
277 | iptables -t nat -A PREROUTING -j SQUID | |
bb12dd7b MT |
278 | |
279 | # DNAT rules | |
c581b670 MT |
280 | iptables -t nat -N NAT_DESTINATION |
281 | iptables -t nat -A PREROUTING -j NAT_DESTINATION | |
99f11a16 | 282 | iptables -t nat -A OUTPUT -j NAT_DESTINATION |
bb12dd7b | 283 | |
6e87f0aa MT |
284 | iptables -t mangle -N NAT_DESTINATION |
285 | iptables -t mangle -A PREROUTING -j NAT_DESTINATION | |
286 | ||
287 | iptables -t nat -N NAT_DESTINATION_FIX | |
288 | iptables -t nat -A POSTROUTING -j NAT_DESTINATION_FIX | |
289 | ||
290 | iptables -t nat -A NAT_DESTINATION_FIX \ | |
291 | -m mark --mark 1 -j SNAT --to-source "${GREEN_ADDRESS}" | |
292 | ||
293 | if [ -n "${BLUE_ADDRESS}" ]; then | |
294 | iptables -t nat -A NAT_DESTINATION_FIX \ | |
295 | -m mark --mark 2 -j SNAT --to-source "${BLUE_ADDRESS}" | |
296 | fi | |
297 | ||
298 | if [ -n "${ORANGE_ADDRESS}" ]; then | |
299 | iptables -t nat -A NAT_DESTINATION_FIX \ | |
300 | -m mark --mark 3 -j SNAT --to-source "${ORANGE_ADDRESS}" | |
301 | fi | |
302 | ||
7e7495b3 | 303 | # upnp chain for our upnp daemon |
c581b670 MT |
304 | iptables -t nat -N UPNPFW |
305 | iptables -t nat -A PREROUTING -j UPNPFW | |
306 | iptables -N UPNPFW | |
307 | iptables -A FORWARD -m conntrack --ctstate NEW -j UPNPFW | |
3a1019f6 | 308 | |
6e87f0aa MT |
309 | # RED chain, used for the red interface |
310 | iptables -N REDINPUT | |
311 | iptables -A INPUT -j REDINPUT | |
312 | iptables -N REDFORWARD | |
313 | iptables -A FORWARD -j REDFORWARD | |
314 | iptables -t nat -N REDNAT | |
315 | iptables -t nat -A POSTROUTING -j REDNAT | |
316 | ||
ab4876ad MT |
317 | # Apply OpenVPN firewall rules |
318 | /usr/local/bin/openvpnctrl --firewall-rules | |
ff4770c7 AM |
319 | |
320 | # run wirelessctrl | |
321 | /usr/local/bin/wirelessctrl | |
322 | ||
c581b670 MT |
323 | # POLICY CHAIN |
324 | iptables -N POLICYIN | |
325 | iptables -A INPUT -j POLICYIN | |
326 | iptables -N POLICYFWD | |
327 | iptables -A FORWARD -j POLICYFWD | |
328 | iptables -N POLICYOUT | |
329 | iptables -A OUTPUT -j POLICYOUT | |
b324de14 | 330 | |
bb383423 | 331 | # Initialize firewall policies. |
5d7faa45 | 332 | /usr/sbin/firewall-policy |
690b0bd7 | 333 | |
bb383423 | 334 | # Install firewall rules for the red interface. |
4b12aa41 TE |
335 | iptables_red_up |
336 | ||
337 | # If red has not been brought up yet, we will | |
338 | # add the blocking rules for MASQUERADE | |
339 | if [ ! -e "/var/ipfire/red/active" ]; then | |
340 | iptables_red_down | |
341 | fi | |
ff4770c7 | 342 | } |
3a1019f6 | 343 | |
4b12aa41 | 344 | iptables_red_up() { |
c581b670 MT |
345 | iptables -F REDINPUT |
346 | iptables -F REDFORWARD | |
347 | iptables -t nat -F REDNAT | |
3a1019f6 | 348 | |
ff4770c7 AM |
349 | # PPPoE / PPTP Device |
350 | if [ "$IFACE" != "" ]; then | |
351 | # PPPoE / PPTP | |
352 | if [ "$DEVICE" != "" ]; then | |
c581b670 | 353 | iptables -A REDINPUT -i $DEVICE -j ACCEPT |
ff4770c7 AM |
354 | fi |
355 | if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then | |
356 | if [ "$RED_DEV" != "" ]; then | |
c581b670 | 357 | iptables -A REDINPUT -i $RED_DEV -j ACCEPT |
ff4770c7 AM |
358 | fi |
359 | fi | |
3a1019f6 | 360 | fi |
ff4770c7 AM |
361 | |
362 | # PPTP over DHCP | |
363 | if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then | |
c581b670 MT |
364 | iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT |
365 | iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT | |
3a1019f6 MT |
366 | fi |
367 | ||
ff4770c7 AM |
368 | # Orange pinholes |
369 | if [ "$ORANGE_DEV" != "" ]; then | |
370 | # This rule enables a host on ORANGE network to connect to the outside | |
371 | # (only if we have a red connection) | |
372 | if [ "$IFACE" != "" ]; then | |
c581b670 | 373 | iptables -A REDFORWARD -i $ORANGE_DEV -o $IFACE -j ACCEPT |
ff4770c7 | 374 | fi |
3a1019f6 | 375 | fi |
c400fe4c | 376 | |
ff4770c7 AM |
377 | if [ "$IFACE" != "" -a -f /var/ipfire/red/active ]; then |
378 | # DHCP | |
379 | if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then | |
c581b670 MT |
380 | iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT |
381 | iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT | |
ff4770c7 AM |
382 | fi |
383 | if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then | |
c581b670 MT |
384 | iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT |
385 | iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT | |
ff4770c7 AM |
386 | fi |
387 | ||
388 | # Outgoing masquerading (don't masqerade IPSEC (mark 50)) | |
c581b670 | 389 | iptables -t nat -A REDNAT -m mark --mark 50 -o $IFACE -j RETURN |
c926c637 | 390 | |
83ef9c40 MT |
391 | if [ "$IFACE" = "$GREEN_DEV" ]; then |
392 | MASQUERADE_GREEN="off" | |
c926c637 | 393 | fi |
c400fe4c | 394 | |
983d471f | 395 | local NO_MASQ_NETWORKS |
83ef9c40 MT |
396 | |
397 | if [ "${MASQUERADE_GREEN}" = "off" ]; then | |
983d471f | 398 | NO_MASQ_NETWORKS="${NO_MASQ_NETWORKS} ${GREEN_NETADDRESS}/${GREEN_NETMASK}" |
83ef9c40 MT |
399 | fi |
400 | ||
401 | if [ "${MASQUERADE_BLUE}" = "off" ]; then | |
983d471f | 402 | NO_MASQ_NETWORKS="${NO_MASQ_NETWORKS} ${BLUE_NETADDRESS}/${BLUE_NETMASK}" |
83ef9c40 MT |
403 | fi |
404 | ||
405 | if [ "${MASQUERADE_ORANGE}" = "off" ]; then | |
983d471f | 406 | NO_MASQ_NETWORKS="${NO_MASQ_NETWORKS} ${ORANGE_NETADDRESS}/${ORANGE_NETMASK}" |
83ef9c40 MT |
407 | fi |
408 | ||
983d471f MT |
409 | local network |
410 | for network in ${NO_MASQ_NETWORKS}; do | |
411 | iptables -t nat -A REDNAT -s "${network}" -o "${IFACE}" -j RETURN | |
83ef9c40 MT |
412 | done |
413 | ||
414 | # Masquerade everything else | |
415 | iptables -t nat -A REDNAT -o $IFACE -j MASQUERADE | |
6be0579b | 416 | fi |
66f6b279 MT |
417 | |
418 | # Reload all rules. | |
55a5bcae | 419 | /usr/local/bin/firewallctrl |
ff4770c7 AM |
420 | } |
421 | ||
4b12aa41 TE |
422 | iptables_red_down() { |
423 | # Prohibit packets to reach the masquerading rule | |
424 | # while the wan interface is down - this is required to | |
425 | # circumvent udp related NAT issues | |
426 | # http://forum.ipfire.org/index.php?topic=11127.0 | |
e7204c2d MT |
427 | if [ -n "${IFACE}" ]; then |
428 | iptables -F REDFORWARD | |
429 | iptables -A REDFORWARD -o "${IFACE}" -j DROP | |
430 | fi | |
4b12aa41 TE |
431 | |
432 | # Reload all rules. | |
433 | /usr/local/bin/firewallctrl | |
434 | } | |
435 | ||
ff4770c7 AM |
436 | # See how we were called. |
437 | case "$1" in | |
438 | start) | |
7d7740a4 | 439 | boot_mesg "Setting up firewall" |
ff4770c7 | 440 | iptables_init |
7d7740a4 | 441 | evaluate_retval |
6be0579b | 442 | ;; |
4b12aa41 | 443 | reload|up) |
7d7740a4 | 444 | boot_mesg "Reloading firewall" |
4b12aa41 | 445 | iptables_red_up |
7d7740a4 | 446 | evaluate_retval |
3a1019f6 | 447 | ;; |
4b12aa41 TE |
448 | down) |
449 | boot_mesg "Disabling firewall access to RED" | |
450 | iptables_red_down | |
451 | evaluate_retval | |
452 | ;; | |
3a1019f6 | 453 | restart) |
3a1019f6 MT |
454 | $0 start |
455 | ;; | |
456 | *) | |
ff4770c7 | 457 | echo "Usage: $0 {start|reload|restart}" |
3a1019f6 MT |
458 | exit 1 |
459 | ;; | |
460 | esac | |
461 | ||
462 | exit 0 |