add missing copyright notices
[openwrt-10.03/.git] / package / iptables / files / firewall.awk
1 # Copyright (C) 2006 OpenWrt.org
2
3 BEGIN {
4         print ". /etc/config/network"
5         print "proto=\"$wan_proto\""
6         print "[ -z \"$proto\" -o \"$proto\" = \"none\" ] && exit"
7         print "ifname=\"$wan_ifname\""
8         print "[ -z \"$ifname\" ] && exit"
9         print ""
10         print "iptables -X input_$ifname 2>&- >&-"
11         print "iptables -N input_$ifname"
12         print "iptables -X forward_$ifname 2>&- >&-"
13         print "iptables -N forward_$ifname"
14         print "iptables -t nat -X prerouting_$ifname 2>&- >&-"
15         print "iptables -t nat -N prerouting_$ifname"
16         print ""
17         print "iptables -A input_rule -i \"$ifname\" -j input_$ifname"
18         print "iptables -A forwarding_rule -i \"$ifname\" -j forward_$ifname"
19         print "iptables -t nat -A prerouting_rule -i \"$ifname\" -j prerouting_$ifname"
20         print ""
21         FS=":"
22 }
23
24 ($1 == "accept") || ($1 == "drop") || ($1 == "forward") {
25         delete _opt
26         str2data($2)
27         if ((_l["proto"] == "") && (_l["sport"] _l["dport"] != "")) {
28                 _opt[0] = " -p tcp"
29                 _opt[1] = " -p udp"
30         } else {
31                 _opt[0] = ""
32         }
33 }
34
35 ($1 == "accept") {
36         target = " -j ACCEPT"
37         for (o in _opt) {
38                 print "iptables -t nat -A prerouting_$ifname" _opt[o] str2ipt($2) target
39                 print "iptables        -A input_$ifname     " _opt[o] str2ipt($2) target
40                 print ""
41         }
42 }
43
44 ($1 == "drop") {
45         for (o in _opt) {
46                 print "iptables -t nat -A prerouting_$ifname" _opt[o] str2ipt($2) " -j DROP"
47                 print ""
48         }
49 }
50
51 ($1 == "forward") {
52         target = " -j DNAT --to " $3
53         fwopts = ""
54         if ($4 != "") {
55                 if ((_l["proto"] == "tcp") || (_l["proto"] == "udp") || (_l["proto"] == "")) {
56                         if (_l["proto"] != "") fwopts = " -p " _l["proto"]
57                         fwopts = fwopts " --dport " $4
58                         target = target ":" $4
59                 }
60                 else fwopts = ""
61         }
62         for (o in _opt) {
63                 print "iptables -t nat -A prerouting_$ifname" _opt[o] str2ipt($2) target
64                 print "iptables        -A forward_$ifname   " _opt[o] " -d " $3 fwopts " -j ACCEPT"
65                 print ""
66         }
67 }