1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
4 ## Please make changes in /etc/firewall.user
9 config_load
/var
/state
/network
11 config_get WAN wan ifname
12 config_get WANDEV wan device
13 config_get LAN lan ifname
14 config_get_bool NAT_LAN lan nat
1
17 config_get LAN_MASK lan netmask
18 config_get LAN_IP lan ipaddr
19 LAN_NET
=$
(/bin
/ipcalc.sh
$LAN_IP $LAN_MASK |
grep NETWORK | cut
-d= -f2)
23 for T
in filter nat
; do
28 iptables
-N input_rule
30 iptables
-N output_rule
31 iptables
-N forwarding_rule
32 iptables
-N forwarding_wan
34 iptables
-t nat
-N NEW
35 iptables
-t nat
-N prerouting_rule
36 iptables
-t nat
-N prerouting_wan
37 iptables
-t nat
-N postrouting_rule
39 iptables
-N LAN_ACCEPT
40 [ -z "$WAN" ] || iptables
-A LAN_ACCEPT
-i "$WAN" -j RETURN
41 [ -z "$WANDEV" -o "$WANDEV" = "$WAN" ] || iptables
-A LAN_ACCEPT
-i "$WANDEV" -j RETURN
42 iptables
-A LAN_ACCEPT
-j ACCEPT
45 ### (connections with the router as destination)
48 iptables
-P INPUT DROP
49 iptables
-A INPUT
-m state
--state INVALID
-j DROP
50 iptables
-A INPUT
-m state
--state RELATED
,ESTABLISHED
-j ACCEPT
51 iptables
-A INPUT
-p tcp
--tcp-flags SYN SYN
--tcp-option \
! 2 -j DROP
54 # insert accept rule or to jump to new accept-check table here
56 iptables
-A INPUT
-j input_rule
57 [ -z "$WAN" ] || iptables
-A INPUT
-i $WAN -j input_wan
60 iptables
-A INPUT
-j LAN_ACCEPT
# allow from lan/wifi interfaces
61 iptables
-A INPUT
-p icmp
-j ACCEPT
# allow ICMP
62 iptables
-A INPUT
-p gre
-j ACCEPT
# allow GRE
64 # reject (what to do with anything not allowed earlier)
65 iptables
-A INPUT
-p tcp
-j REJECT
--reject-with tcp-reset
66 iptables
-A INPUT
-j REJECT
--reject-with icmp-port-unreachable
69 ### (connections with the router as source)
72 iptables
-P OUTPUT DROP
73 iptables
-A OUTPUT
-m state
--state INVALID
-j DROP
74 iptables
-A OUTPUT
-m state
--state RELATED
,ESTABLISHED
-j ACCEPT
77 # insert accept rule or to jump to new accept-check table here
79 iptables
-A OUTPUT
-j output_rule
82 iptables
-A OUTPUT
-j ACCEPT
#allow everything out
84 # reject (what to do with anything not allowed earlier)
85 iptables
-A OUTPUT
-p tcp
-j REJECT
--reject-with tcp-reset
86 iptables
-A OUTPUT
-j REJECT
--reject-with icmp-port-unreachable
89 ### (connections routed through the router)
92 iptables
-P FORWARD DROP
93 iptables
-A FORWARD
-m state
--state INVALID
-j DROP
94 iptables
-A FORWARD
-p tcp
--tcp-flags SYN
,RST SYN
-j TCPMSS
--clamp-mss-to-pmtu
95 iptables
-A FORWARD
-m state
--state RELATED
,ESTABLISHED
-j ACCEPT
98 # insert accept rule or to jump to new accept-check table here
100 iptables
-A FORWARD
-j forwarding_rule
101 [ -z "$WAN" ] || iptables
-A FORWARD
-i $WAN -j forwarding_wan
104 iptables
-A FORWARD
-i $LAN -o $LAN -j ACCEPT
105 [ -z "$WAN" ] || iptables
-A FORWARD
-i $LAN -o $WAN -j ACCEPT
107 # reject (what to do with anything not allowed earlier)
108 # uses the default -P DROP
111 iptables
-t nat
-A PREROUTING
-m state
--state NEW
-p tcp
-j NEW
112 iptables
-t nat
-A PREROUTING
-j prerouting_rule
113 [ -z "$WAN" ] || iptables
-t nat
-A PREROUTING
-i "$WAN" -j prerouting_wan
114 iptables
-t nat
-A POSTROUTING
-j postrouting_rule
115 ### Only LAN, unless told not to
116 if [ $NAT_LAN -ne 0 ]
118 [ -z "$WAN" ] || iptables
-t nat
-A POSTROUTING
--src $LAN_NET/$LAN_MASK -o $WAN -j MASQUERADE
121 iptables
-t nat
-A NEW
-m limit
--limit 50 --limit-burst 100 -j RETURN
&& \
122 iptables
-t nat
-A NEW
-j DROP
125 [ -f /etc
/firewall.user
] && .
/etc
/firewall.user
126 [ -n "$WAN" -a -e /etc
/config
/firewall
] && {
128 awk -f /usr
/lib
/common.
awk -f /usr
/lib
/firewall.
awk /etc
/config
/firewall | ash
133 iptables
-P INPUT ACCEPT
134 iptables
-P OUTPUT ACCEPT
135 iptables
-P FORWARD ACCEPT
138 iptables
-t nat
-P PREROUTING ACCEPT
139 iptables
-t nat
-P POSTROUTING ACCEPT
140 iptables
-t nat
-P OUTPUT ACCEPT