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