072f411a9fe4748c0d3b587ef8d2719e36351b72
[openwrt/svn-archive/archive.git] / openwrt / target / default / target_skeleton / etc / init.d / S45firewall
1 #!/bin/sh
2 . /etc/functions.sh
3 WAN=$(nvram get wan_ifname)
4 LAN=$(nvram get lan_ifname)
5
6 ## CLEAR TABLES
7 for T in filter nat mangle; do
8 iptables -t $T -F
9 iptables -t $T -X
10 done
11
12 iptables -N input_rule
13 iptables -N output_rule
14 iptables -N forwarding_rule
15
16 iptables -t nat -N prerouting_rule
17 iptables -t nat -N postrouting_rule
18
19 ### INPUT
20 ### (connections with the router as destination)
21
22 # base case
23 iptables -P INPUT DROP
24 iptables -A INPUT -m state --state INVALID -j DROP
25 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
26 iptables -A INPUT -p tcp --syn --tcp-option \! 2 -j DROP
27
28 # allow
29 iptables -A INPUT -i \! $WAN -j ACCEPT # allow from lan/wifi interfaces
30 iptables -A INPUT -p icmp -j ACCEPT # allow ICMP
31 iptables -A INPUT -p gre -j ACCEPT # allow GRE
32 #
33 # insert accept rule or to jump to new accept-check table here
34 #
35 iptables -A INPUT -j input_rule
36
37 # reject (what to do with anything not allowed earlier)
38 iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset
39 iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable
40
41 ### OUTPUT
42 ### (connections with the router as source)
43
44 # base case
45 iptables -P OUTPUT DROP
46 iptables -A OUTPUT -m state --state INVALID -j DROP
47 iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
48
49 # allow
50 iptables -A OUTPUT -j ACCEPT #allow everything out
51 #
52 # insert accept rule or to jump to new accept-check table here
53 #
54 iptables -A OUTPUT -j output_rule
55
56 # reject (what to do with anything not allowed earlier)
57 iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset
58 iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable
59
60 ### FORWARDING
61 ### (connections routed through the router)
62
63 # base case
64 iptables -P FORWARD DROP
65 iptables -A FORWARD -m state --state INVALID -j DROP
66 iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
67 iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
68
69 # allow
70 iptables -A FORWARD -i br0 -o br0 -j ACCEPT
71 iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT
72 #
73 # insert accept rule or to jump to new accept-check table here
74 #
75 iptables -A FORWARD -j forwarding_rule
76
77 # reject (what to do with anything not allowed earlier)
78 # uses the default -P DROP
79
80 ### MASQ
81 iptables -t nat -A PREROUTING -j prerouting_rule
82 iptables -t nat -A POSTROUTING -j postrouting_rule
83 iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
84
85 ## USER RULES
86 . /etc/firewall.user