1 #!/bin/sh /etc/rc.common
6 config_get proto
"$cfg" proto
7 config_get dport
"$cfg" dport
8 config_get iface
"$cfg" iface
9 config_get to
"$cfg" to
11 ports
=$
(echo $to | cut
-sd: -f2)
12 if [ -n "$ports" ]; then
13 ports
="--dport $(echo $ports | sed -e 's/-/:/')"
15 ports
="--dport $dport"
18 ip
=$
(echo $to | cut
-d: -f1)
20 if ([ "$proto" == "tcpudp" ] ||
[ "$proto" == "tcp" ]); then
21 iptables
-t nat
-A luci_fw_prerouting
-i "$iface" -p tcp
--dport "$dport" -j DNAT
--to "$to"
22 iptables
-A luci_fw_forward
-i "$iface" -p tcp
-d "$ip" $ports -j ACCEPT
25 if ([ "$proto" == "tcpudp" ] ||
[ "$proto" == "udp" ]); then
26 iptables
-t nat
-A luci_fw_prerouting
-i "$iface" -p udp
--dport "$dport" -j DNAT
--to "$to"
27 iptables
-A luci_fw_forward
-i "$iface" -p udp
-d "$ip" $ports -j ACCEPT
35 config_get chain
"$cfg" chain
36 [ -n "$chain" ] ||
return 0
37 [ "$chain" == "forward" ] && cmd
="$cmd -A luci_fw_forward"
38 [ "$chain" == "input" ] && cmd
="$cmd -A luci_fw_input"
39 [ "$chain" == "output" ] && cmd
="$cmd -A luci_fw_output"
40 [ "$chain" == "prerouting" ] && cmd
="$cmd -t nat -A luci_fw_prerouting"
41 [ "$chain" == "postrouting" ] && cmd
="$cmd -t nat -A luci_fw_postrouting"
43 config_get iface
"$cfg" iface
44 [ -n "$iface" ] && cmd
="$cmd -i $iface"
46 config_get oface
"$cfg" oface
47 [ -n "$oface" ] && cmd
="$cmd -o $oface"
49 config_get proto
"$cfg" proto
50 [ -n "$proto" ] && cmd
="$cmd -p $proto"
52 config_get
source "$cfg" source
53 [ -n "$source" ] && cmd
="$cmd -s $source"
55 config_get destination
"$cfg" destination
56 [ -n "$destination" ] && cmd
="$cmd -d $destination"
58 config_get sport
"$cfg" sport
59 [ -n "$sport" ] && cmd
="$cmd --sport $sport"
61 config_get dport
"$cfg" dport
62 [ -n "$dport" ] && cmd
="$cmd --dport $dport"
64 config_get todest
"$cfg" todest
65 [ -n "$todest" ] && cmd
="$cmd --to-destination $todest"
67 config_get tosrc
"$cfg" tosrc
68 [ -n "$tosrc" ] && cmd
="$cmd --to-source $tosrc"
70 config_get mac
"$cfg" mac
71 [ -n "$mac" ] && cmd
="$cmd -m mac --mac-source $mac"
73 config_get jump
"$cfg" jump
74 [ -n "$jump" ] && cmd
="$cmd -j $jump"
76 config_get
command "$cfg" command
77 [ -n "$command" ] && cmd
="$cmd $command"
84 iptables
-N luci_fw_input
85 iptables
-N luci_fw_output
86 iptables
-N luci_fw_forward
87 iptables
-t nat
-N luci_fw_prerouting
88 iptables
-t nat
-N luci_fw_postrouting
90 ### Hook in the chains
91 iptables
-A input_rule
-j luci_fw_input
92 iptables
-A output_rule
-j luci_fw_output
93 iptables
-A forwarding_rule
-j luci_fw_forward
94 iptables
-t nat
-A prerouting_rule
-j luci_fw_prerouting
95 iptables
-t nat
-A postrouting_rule
-j luci_fw_postrouting
97 ### Read chains from config
99 config_foreach apply_portfw portfw
100 config_foreach apply_rule rule
104 ### Hook out the chains
105 iptables
-D input_rule
-j luci_fw_input
106 iptables
-D output_rule
-j luci_fw_output
107 iptables
-D forwarding_rule
-j luci_fw_forward
108 iptables
-t nat
-D prerouting_rule
-j luci_fw_prerouting
109 iptables
-t nat
-D postrouting_rule
-j luci_fw_postrouting
112 iptables
-F luci_fw_input
113 iptables
-F luci_fw_output
114 iptables
-F luci_fw_forward
115 iptables
-t nat
-F luci_fw_prerouting
116 iptables
-t nat
-F luci_fw_postrouting
119 iptables
-X luci_fw_input
120 iptables
-X luci_fw_output
121 iptables
-X luci_fw_forward
122 iptables
-t nat
-X luci_fw_prerouting
123 iptables
-t nat
-X luci_fw_postrouting