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