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