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_prerouting
-i "$iface" -p tcp
--dport "$dport" -j DNAT
--to "$to"
22 iptables
-A luci_forward
-i "$iface" -p tcp
-d "$ip" $ports -j ACCEPT
25 if ([ "$proto" == "tcpudp" ] ||
[ "$proto" == "udp" ]); then
26 iptables
-t nat
-A luci_prerouting
-i "$iface" -p udp
--dport "$dport" -j DNAT
--to "$to"
27 iptables
-A luci_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_forward"
38 [ "$chain" == "input" ] && cmd
="$cmd -A luci_input"
39 [ "$chain" == "output" ] && cmd
="$cmd -A luci_output"
40 [ "$chain" == "prerouting" ] && cmd
="$cmd -t nat -A luci_prerouting"
41 [ "$chain" == "postrouting" ] && cmd
="$cmd -t nat -A luci_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 jump
"$cfg" jump
71 [ -n "$jump" ] && cmd
="$cmd -j $jump"
73 config_get
command "$cfg" command
74 [ -n "$command" ] && cmd
="$cmd $command"
81 iptables
-N luci_input
82 iptables
-N luci_output
83 iptables
-N luci_forward
84 iptables
-t nat
-N luci_prerouting
85 iptables
-t nat
-N luci_postrouting
87 ### Hook in the chains
88 iptables
-A input_rule
-j luci_input
89 iptables
-A output_rule
-j luci_output
90 iptables
-A forwarding_rule
-j luci_forward
91 iptables
-t nat
-A prerouting_rule
-j luci_prerouting
92 iptables
-t nat
-A postrouting_rule
-j luci_postrouting
94 ### Read chains from config
96 config_foreach apply_portfw portfw
97 config_foreach apply_rule rule
101 ### Hook out the chains
102 iptables
-D input_rule
-j luci_input
103 iptables
-D output_rule
-j luci_output
104 iptables
-D forwarding_rule
-j luci_forward
105 iptables
-t nat
-D prerouting_rule
-j luci_prerouting
106 iptables
-t nat
-D postrouting_rule
-j luci_postrouting
109 iptables
-F luci_input
110 iptables
-F luci_output
111 iptables
-F luci_forward
112 iptables
-t nat
-F luci_prerouting
113 iptables
-t nat
-F luci_postrouting
116 iptables
-X luci_input
117 iptables
-X luci_output
118 iptables
-X luci_forward
119 iptables
-t nat
-X luci_prerouting
120 iptables
-t nat
-X luci_postrouting