]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/system/firewall
firewall: Always enable connection tracking for GRE
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / firewall
CommitLineData
3a1019f6
MT
1#!/bin/sh
2
0f5c5ce7
MT
3. /etc/sysconfig/rc
4. ${rc_functions}
5
3a1019f6
MT
6eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
7eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
fe0cd647 8eval $(/usr/local/bin/readhash /var/ipfire/optionsfw/settings)
3a1019f6
MT
9IFACE=`/bin/cat /var/ipfire/red/iface 2> /dev/null | /usr/bin/tr -d '\012'`
10
11if [ -f /var/ipfire/red/device ]; then
12 DEVICE=`/bin/cat /var/ipfire/red/device 2> /dev/null | /usr/bin/tr -d '\012'`
13fi
14
c581b670
MT
15function iptables() {
16 /sbin/iptables --wait "$@"
17}
18
3a1019f6
MT
19iptables_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 36 iptables -N LOG_DROP
8ee3a135 37 iptables -A LOG_DROP -m limit --limit 10/second -j LOG
c581b670
MT
38 iptables -A LOG_DROP -j DROP
39 iptables -N LOG_REJECT
8ee3a135 40 iptables -A LOG_REJECT -m limit --limit 10/second -j LOG
c581b670 41 iptables -A LOG_REJECT -j REJECT
3a1019f6
MT
42
43 # This chain will log, then DROPs packets with certain bad combinations
ef7e9e52 44 # of flags might indicate a port-scan attempt (xmas, null, etc.)
c581b670 45 iptables -N PSCAN
5595bc03 46 if [ "$DROPPORTSCAN" == "on" ]; then
ef7e9e52
PM
47 iptables -A PSCAN -p tcp -m limit --limit 10/second -j LOG --log-prefix "DROP_TCP Scan " -m comment --comment "DROP_TCP PScan"
48 iptables -A PSCAN -p udp -m limit --limit 10/second -j LOG --log-prefix "DROP_UDP Scan " -m comment --comment "DROP_UDP PScan"
8ee3a135
PM
49 iptables -A PSCAN -p icmp -m limit --limit 10/second -j LOG --log-prefix "DROP_ICMP Scan " -m comment --comment "DROP_ICMP PScan"
50 iptables -A PSCAN -f -m limit --limit 10/second -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
ef7e9e52 55 # that's not covered above, may just be a broken Windows machine
c581b670 56 iptables -N NEWNOTSYN
5595bc03 57 if [ "$DROPNEWNOTSYN" == "on" ]; then
8ee3a135 58 iptables -A NEWNOTSYN -m limit --limit 10/second -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
a5a0c8a5
MT
99 # GRE (always enabled)
100 modprobe nf_conntrack_proto_gre
101
b1109b8a 102 # SIP
d57c6162 103 if [ "${CONNTRACK_SIP}" = "on" ]; then
23bb6839 104 modprobe nf_nat_sip
d57c6162
MT
105 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
106 -m helper --helper sip -j ACCEPT
107 for proto in udp tcp; do
108 iptables -t raw -A CONNTRACK -p "${proto}" --dport 5060 -j CT --helper sip
109 done
110 fi
b1109b8a 111
c8f8bf32
MT
112 # H.323
113 if [ "${CONNTRACK_H323}" = "on" ]; then
23bb6839 114 modprobe nf_nat_h323
c8f8bf32
MT
115 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
116 -m helper --helper h323 -j ACCEPT
117
118 # Gatekeeper RAS
e2c72362 119 iptables -t raw -A CONNTRACK -p udp --dport 1719 -j CT --helper RAS
c8f8bf32
MT
120
121 # Q.931
e2c72362 122 iptables -t raw -A CONNTRACK -p tcp --dport 1720 -j CT --helper Q.931
c8f8bf32
MT
123 fi
124
b1109b8a 125 # FTP
d57c6162 126 if [ "${CONNTRACK_FTP}" = "on" ]; then
23bb6839 127 modprobe nf_nat_ftp
d57c6162
MT
128 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
129 -m helper --helper ftp -p tcp --dport 1024: -j ACCEPT
130 iptables -t raw -A CONNTRACK -p tcp --dport 21 -j CT --helper ftp
131 fi
b1109b8a
MT
132
133 # PPTP
d57c6162 134 if [ "${CONNTRACK_PPTP}" = "on" ]; then
23bb6839 135 modprobe nf_nat_pptp
d57c6162
MT
136 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
137 -m helper --helper pptp -j ACCEPT
8e7c5e65 138 iptables -t raw -A CONNTRACK -p tcp --dport 1723 -j CT --helper pptp
d57c6162 139 fi
b1109b8a
MT
140
141 # TFTP
d57c6162 142 if [ "${CONNTRACK_TFTP}" = "on" ]; then
23bb6839 143 modprobe nf_nat_tftp
d57c6162
MT
144 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
145 -m helper --helper tftp -j ACCEPT
146 iptables -t raw -A CONNTRACK -p udp --dport 69 -j CT --helper tftp
147 fi
3a1019f6 148
50354ffe
MT
149 # IRC
150 if [ "${CONNTRACK_IRC}" = "on" ]; then
23bb6839 151 modprobe nf_nat_irc
50354ffe
MT
152 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
153 -m helper --helper irc -j ACCEPT
154 iptables -t raw -A CONNTRACK -p tcp --dport 6667 -j CT --helper irc
155 fi
156
a93bf696
MT
157 # Amanda
158 if [ "${CONNTRACK_AMANDA}" = "on" ]; then
23bb6839 159 modprobe nf_nat_amanda
a93bf696
MT
160 iptables -A CONNTRACK -m conntrack --ctstate RELATED \
161 -m helper --helper amanda -j ACCEPT
2c4b9c50 162 iptables -t raw -A CONNTRACK -p tcp -j CT --helper amanda
a93bf696 163 fi
3a1019f6 164
ef7e9e52 165 # Fix for braindead ISPs
c581b670 166 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
3a1019f6
MT
167
168 # CUSTOM chains, can be used by the users themselves
c581b670
MT
169 iptables -N CUSTOMINPUT
170 iptables -A INPUT -j CUSTOMINPUT
171 iptables -N CUSTOMFORWARD
172 iptables -A FORWARD -j CUSTOMFORWARD
173 iptables -N CUSTOMOUTPUT
174 iptables -A OUTPUT -j CUSTOMOUTPUT
175 iptables -t nat -N CUSTOMPREROUTING
176 iptables -t nat -A PREROUTING -j CUSTOMPREROUTING
177 iptables -t nat -N CUSTOMPOSTROUTING
178 iptables -t nat -A POSTROUTING -j CUSTOMPOSTROUTING
3a1019f6 179
2a5b19c5
AF
180 # P2PBLOCK
181 iptables -N P2PBLOCK
182 iptables -A INPUT -j P2PBLOCK
183 iptables -A FORWARD -j P2PBLOCK
184 iptables -A OUTPUT -j P2PBLOCK
185
ef7e9e52 186 # IPS (Guardian) chains
c581b670
MT
187 iptables -N GUARDIAN
188 iptables -A INPUT -j GUARDIAN
189 iptables -A FORWARD -j GUARDIAN
815eaff4 190
80fbd899
MT
191 # Block non-established IPsec networks
192 iptables -N IPSECBLOCK
193 iptables -A FORWARD -m policy --dir out --pol none -j IPSECBLOCK
194 iptables -A OUTPUT -m policy --dir out --pol none -j IPSECBLOCK
195
1e555330 196 # Block OpenVPN transfer networks
c581b670 197 iptables -N OVPNBLOCK
a0a5c14f 198 iptables -A INPUT -i tun+ -j OVPNBLOCK
a0a5c14f
MT
199 iptables -A FORWARD -i tun+ -j OVPNBLOCK
200 iptables -A FORWARD -o tun+ -j OVPNBLOCK
1e555330 201
ef7e9e52 202 # IPS (Suricata) chains
5dba8382
PM
203 iptables -N IPS_INPUT
204 iptables -N IPS_FORWARD
205 iptables -N IPS_OUTPUT
206 iptables -A INPUT -j IPS_INPUT
207 iptables -A FORWARD -j IPS_FORWARD
208 iptables -A OUTPUT -j IPS_OUTPUT
209
51ab1de1 210 # OpenVPN transfer network translation
c581b670
MT
211 iptables -t nat -N OVPNNAT
212 iptables -t nat -A POSTROUTING -j OVPNNAT
51ab1de1 213
daa1ceba 214 # IPTV chains for IGMPPROXY
c581b670
MT
215 iptables -N IPTVINPUT
216 iptables -A INPUT -j IPTVINPUT
217 iptables -N IPTVFORWARD
218 iptables -A FORWARD -j IPTVFORWARD
daa1ceba 219
8e59a602
MT
220 # Allow to ping the firewall.
221 iptables -N ICMPINPUT
222 iptables -A INPUT -j ICMPINPUT
223 iptables -A ICMPINPUT -p icmp --icmp-type 8 -j ACCEPT
3a1019f6 224
afc611d4 225 # Accept everything on loopback
c581b670
MT
226 iptables -N LOOPBACK
227 iptables -A LOOPBACK -i lo -j ACCEPT
228 iptables -A LOOPBACK -o lo -j ACCEPT
afc611d4 229
3b9a23ce 230 # Filter all packets with loopback addresses on non-loopback interfaces.
c581b670
MT
231 iptables -A LOOPBACK -s 127.0.0.0/8 -j DROP
232 iptables -A LOOPBACK -d 127.0.0.0/8 -j DROP
3b9a23ce
MT
233
234 for i in INPUT FORWARD OUTPUT; do
c581b670 235 iptables -A ${i} -j LOOPBACK
3b9a23ce 236 done
afc611d4 237
bbaa3613
AM
238 # Captive portal
239 iptables -N CAPTIVE_PORTAL
240 iptables -N CAPTIVE_PORTAL_CLIENTS
241 for i in INPUT FORWARD; do
242 iptables -A ${i} -j CAPTIVE_PORTAL
243 done
244
3a1019f6 245 # Accept everything connected
b85d2a98 246 for i in INPUT FORWARD OUTPUT; do
c581b670 247 iptables -A ${i} -j CONNTRACK
b85d2a98
MT
248 done
249
8490e496
MT
250 # Allow DHCP
251 iptables -N DHCPINPUT
252 iptables -A DHCPINPUT -p udp --sport 68 --dport 67 -j ACCEPT
253 iptables -A DHCPINPUT -p tcp --sport 68 --dport 67 -j ACCEPT
254
255 iptables -N DHCPOUTPUT
256 iptables -A DHCPOUTPUT -p udp --sport 67 --dport 68 -j ACCEPT
257 iptables -A DHCPOUTPUT -p tcp --sport 67 --dport 68 -j ACCEPT
258
259 # Allow DHCP on GREEN
260 iptables -N DHCPGREENINPUT
261 iptables -N DHCPGREENOUTPUT
262 if [ -n "${GREEN_DEV}" ]; then
263 iptables -A INPUT -i "${GREEN_DEV}" -j DHCPGREENINPUT
264 iptables -A OUTPUT -o "${GREEN_DEV}" -j DHCPGREENOUTPUT
265 fi
266
ef7e9e52 267 # Allow DHCP on BLUE to be turned on/off
8490e496
MT
268 iptables -N DHCPBLUEINPUT
269 iptables -N DHCPBLUEOUTPUT
270 if [ -n "${BLUE_DEV}" ]; then
271 iptables -A INPUT -i "${BLUE_DEV}" -j DHCPBLUEINPUT
272 iptables -A OUTPUT -o "${BLUE_DEV}" -j DHCPBLUEOUTPUT
273 fi
274
cab02e2a
SS
275 # GeoIP block
276 iptables -N GEOIPBLOCK
277 iptables -A INPUT -j GEOIPBLOCK
278 iptables -A FORWARD -j GEOIPBLOCK
279
5fd30232 280 # trafic from ipsecX/TUN/TAP interfaces, before "-i GREEN_DEV" accept everything
c581b670
MT
281 iptables -N IPSECINPUT
282 iptables -N IPSECFORWARD
283 iptables -N IPSECOUTPUT
284 iptables -A INPUT -j IPSECINPUT
285 iptables -A FORWARD -j IPSECFORWARD
286 iptables -A OUTPUT -j IPSECOUTPUT
287 iptables -t nat -N IPSECNAT
288 iptables -t nat -A POSTROUTING -j IPSECNAT
b68e5c14 289
3a1019f6 290 # localhost and ethernet.
c0e0848f
MT
291 # Always allow accessing the web GUI from GREEN.
292 iptables -N GUIINPUT
293 iptables -A INPUT -j GUIINPUT
48a7737f
MT
294 if [ -n "${GREEN_DEV}" ]; then
295 iptables -A GUIINPUT -i "${GREEN_DEV}" -p tcp --dport 444 -j ACCEPT
296 fi
8490e496 297
81393987 298 # WIRELESS chains
c581b670
MT
299 iptables -N WIRELESSINPUT
300 iptables -A INPUT -m conntrack --ctstate NEW -j WIRELESSINPUT
301 iptables -N WIRELESSFORWARD
302 iptables -A FORWARD -m conntrack --ctstate NEW -j WIRELESSFORWARD
987b75bc 303
ab4876ad 304 # OpenVPN
c581b670
MT
305 iptables -N OVPNINPUT
306 iptables -A INPUT -j OVPNINPUT
ab4876ad 307
5fc5f703 308 # Tor (inbound and outbound)
c581b670
MT
309 iptables -N TOR_INPUT
310 iptables -A INPUT -j TOR_INPUT
5fc5f703
PM
311 iptables -N TOR_OUTPUT
312 iptables -A OUTPUT -j TOR_OUTPUT
12dcfbbd 313
d5f1422d 314 # Jump into the actual firewall ruleset.
c581b670
MT
315 iptables -N INPUTFW
316 iptables -A INPUT -j INPUTFW
d5f1422d 317
c581b670
MT
318 iptables -N OUTGOINGFW
319 iptables -A OUTPUT -j OUTGOINGFW
d5f1422d 320
c581b670
MT
321 iptables -N FORWARDFW
322 iptables -A FORWARD -j FORWARDFW
d5f1422d 323
fac38614 324 # SNAT rules
c581b670
MT
325 iptables -t nat -N NAT_SOURCE
326 iptables -t nat -A POSTROUTING -j NAT_SOURCE
fac38614 327
9bb40553
MT
328 # Captive Portal
329 iptables -t nat -N CAPTIVE_PORTAL
330 iptables -t nat -A PREROUTING -j CAPTIVE_PORTAL
331
bb12dd7b 332 # Custom prerouting chains (for transparent proxy)
c581b670
MT
333 iptables -t nat -N SQUID
334 iptables -t nat -A PREROUTING -j SQUID
bb12dd7b
MT
335
336 # DNAT rules
c581b670
MT
337 iptables -t nat -N NAT_DESTINATION
338 iptables -t nat -A PREROUTING -j NAT_DESTINATION
99f11a16 339 iptables -t nat -A OUTPUT -j NAT_DESTINATION
bb12dd7b 340
6e87f0aa
MT
341 iptables -t mangle -N NAT_DESTINATION
342 iptables -t mangle -A PREROUTING -j NAT_DESTINATION
343
344 iptables -t nat -N NAT_DESTINATION_FIX
345 iptables -t nat -A POSTROUTING -j NAT_DESTINATION_FIX
346
48a7737f
MT
347 if [ -n "${GREEN_ADDRESS}" ]; then
348 iptables -t nat -A NAT_DESTINATION_FIX \
349 -m mark --mark 1 -j SNAT --to-source "${GREEN_ADDRESS}"
350 fi
6e87f0aa
MT
351
352 if [ -n "${BLUE_ADDRESS}" ]; then
353 iptables -t nat -A NAT_DESTINATION_FIX \
354 -m mark --mark 2 -j SNAT --to-source "${BLUE_ADDRESS}"
355 fi
356
357 if [ -n "${ORANGE_ADDRESS}" ]; then
358 iptables -t nat -A NAT_DESTINATION_FIX \
359 -m mark --mark 3 -j SNAT --to-source "${ORANGE_ADDRESS}"
360 fi
361
7e7495b3 362 # upnp chain for our upnp daemon
c581b670
MT
363 iptables -t nat -N UPNPFW
364 iptables -t nat -A PREROUTING -j UPNPFW
365 iptables -N UPNPFW
366 iptables -A FORWARD -m conntrack --ctstate NEW -j UPNPFW
3a1019f6 367
6e87f0aa
MT
368 # RED chain, used for the red interface
369 iptables -N REDINPUT
370 iptables -A INPUT -j REDINPUT
371 iptables -N REDFORWARD
372 iptables -A FORWARD -j REDFORWARD
373 iptables -t nat -N REDNAT
374 iptables -t nat -A POSTROUTING -j REDNAT
375
6c920b19
MT
376 # Populate IPsec chains
377 /usr/lib/firewall/ipsec-policy
80fbd899 378
ab4876ad
MT
379 # Apply OpenVPN firewall rules
380 /usr/local/bin/openvpnctrl --firewall-rules
ff4770c7
AM
381
382 # run wirelessctrl
383 /usr/local/bin/wirelessctrl
384
1722701a
AM
385 # run captivectrl
386 /usr/local/bin/captivectrl
387
c581b670
MT
388 # POLICY CHAIN
389 iptables -N POLICYIN
390 iptables -A INPUT -j POLICYIN
391 iptables -N POLICYFWD
392 iptables -A FORWARD -j POLICYFWD
393 iptables -N POLICYOUT
394 iptables -A OUTPUT -j POLICYOUT
b324de14 395
bb383423 396 # Initialize firewall policies.
5d7faa45 397 /usr/sbin/firewall-policy
690b0bd7 398
bb383423 399 # Install firewall rules for the red interface.
4b12aa41
TE
400 iptables_red_up
401
402 # If red has not been brought up yet, we will
403 # add the blocking rules for MASQUERADE
404 if [ ! -e "/var/ipfire/red/active" ]; then
405 iptables_red_down
406 fi
ff4770c7 407}
3a1019f6 408
4b12aa41 409iptables_red_up() {
c581b670
MT
410 iptables -F REDINPUT
411 iptables -F REDFORWARD
412 iptables -t nat -F REDNAT
3a1019f6 413
ff4770c7
AM
414 # PPPoE / PPTP Device
415 if [ "$IFACE" != "" ]; then
416 # PPPoE / PPTP
417 if [ "$DEVICE" != "" ]; then
c581b670 418 iptables -A REDINPUT -i $DEVICE -j ACCEPT
ff4770c7
AM
419 fi
420 if [ "$RED_TYPE" == "PPTP" -o "$RED_TYPE" == "PPPOE" ]; then
421 if [ "$RED_DEV" != "" ]; then
c581b670 422 iptables -A REDINPUT -i $RED_DEV -j ACCEPT
ff4770c7
AM
423 fi
424 fi
3a1019f6 425 fi
ff4770c7
AM
426
427 # PPTP over DHCP
428 if [ "$DEVICE" != "" -a "$TYPE" == "PPTP" -a "$METHOD" == "DHCP" ]; then
c581b670
MT
429 iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
430 iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i $DEVICE -j ACCEPT
3a1019f6
MT
431 fi
432
ff4770c7
AM
433 if [ "$IFACE" != "" -a -f /var/ipfire/red/active ]; then
434 # DHCP
435 if [ "$RED_DEV" != "" -a "$RED_TYPE" == "DHCP" ]; then
c581b670
MT
436 iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
437 iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
ff4770c7
AM
438 fi
439 if [ "$METHOD" == "DHCP" -a "$PROTOCOL" == "RFC1483" ]; then
c581b670
MT
440 iptables -A REDINPUT -p tcp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
441 iptables -A REDINPUT -p udp --source-port 67 --destination-port 68 -i $IFACE -j ACCEPT
ff4770c7
AM
442 fi
443
ef7e9e52 444 # Outgoing masquerading (don't masqerade IPsec (mark 50))
c581b670 445 iptables -t nat -A REDNAT -m mark --mark 50 -o $IFACE -j RETURN
c926c637 446
60fcb241
AF
447 if [ "${IFACE}" = "${GREEN_DEV}" ]; then
448 iptables -t nat -A REDNAT -i "${GREEN_DEV}" -o "${IFACE}" -j RETURN
c926c637 449 fi
c400fe4c 450
983d471f 451 local NO_MASQ_NETWORKS
83ef9c40
MT
452
453 if [ "${MASQUERADE_GREEN}" = "off" ]; then
983d471f 454 NO_MASQ_NETWORKS="${NO_MASQ_NETWORKS} ${GREEN_NETADDRESS}/${GREEN_NETMASK}"
83ef9c40
MT
455 fi
456
457 if [ "${MASQUERADE_BLUE}" = "off" ]; then
983d471f 458 NO_MASQ_NETWORKS="${NO_MASQ_NETWORKS} ${BLUE_NETADDRESS}/${BLUE_NETMASK}"
83ef9c40
MT
459 fi
460
461 if [ "${MASQUERADE_ORANGE}" = "off" ]; then
983d471f 462 NO_MASQ_NETWORKS="${NO_MASQ_NETWORKS} ${ORANGE_NETADDRESS}/${ORANGE_NETMASK}"
83ef9c40
MT
463 fi
464
983d471f
MT
465 local network
466 for network in ${NO_MASQ_NETWORKS}; do
467 iptables -t nat -A REDNAT -s "${network}" -o "${IFACE}" -j RETURN
83ef9c40
MT
468 done
469
470 # Masquerade everything else
471 iptables -t nat -A REDNAT -o $IFACE -j MASQUERADE
6be0579b 472 fi
66f6b279
MT
473
474 # Reload all rules.
55a5bcae 475 /usr/local/bin/firewallctrl
ff4770c7
AM
476}
477
4b12aa41
TE
478iptables_red_down() {
479 # Prohibit packets to reach the masquerading rule
e01e07ec 480 # while the WAN interface is down - this is required to
4b12aa41
TE
481 # circumvent udp related NAT issues
482 # http://forum.ipfire.org/index.php?topic=11127.0
e7204c2d
MT
483 if [ -n "${IFACE}" ]; then
484 iptables -F REDFORWARD
485 iptables -A REDFORWARD -o "${IFACE}" -j DROP
486 fi
4b12aa41
TE
487
488 # Reload all rules.
489 /usr/local/bin/firewallctrl
490}
491
ff4770c7
AM
492# See how we were called.
493case "$1" in
494 start)
7d7740a4 495 boot_mesg "Setting up firewall"
ff4770c7 496 iptables_init
7d7740a4 497 evaluate_retval
6be0579b 498 ;;
4b12aa41 499 reload|up)
7d7740a4 500 boot_mesg "Reloading firewall"
4b12aa41 501 iptables_red_up
7d7740a4 502 evaluate_retval
3a1019f6 503 ;;
4b12aa41
TE
504 down)
505 boot_mesg "Disabling firewall access to RED"
506 iptables_red_down
507 evaluate_retval
508 ;;
3a1019f6 509 restart)
3a1019f6
MT
510 $0 start
511 ;;
512 *)
ff4770c7 513 echo "Usage: $0 {start|reload|restart}"
3a1019f6
MT
514 exit 1
515 ;;
516esac
517
518exit 0