1 # Copyright (C) 2009-2010 OpenWrt.org
4 [ "${rule_NAME}" != "$1" ] ||
return
5 fw_config_get_section
"$1" rule
{ \
16 string proto
"tcpudp" \
20 string limit_burst
"" \
23 [ -n "$rule_name" ] || rule_name
=$rule__name
27 fw_config_get_rule
"$1"
29 [ "$rule_target" != "NOTRACK" ] ||
[ -n "$rule_src" ] ||
[ "$rule_src" != "*" ] ||
{
30 fw_log error
"NOTRACK rule ${rule_name}: needs src, skipping"
38 local target
="${rule_target:-REJECT}"
39 if [ "$target" == "NOTRACK" ]; then
41 chain
="zone_${rule_src}_notrack"
43 if [ -n "$rule_src" ]; then
44 if [ "$rule_src" != "*" ]; then
45 chain
="zone_${rule_src}${rule_dest:+_forward}"
47 chain
="${rule_dest:+forward}"
48 chain
="${chain:-input}"
52 if [ -n "$rule_dest" ]; then
53 if [ "$rule_dest" != "*" ]; then
54 target
="zone_${rule_dest}_${target}"
55 elif [ "$target" = REJECT
]; then
62 fw_get_family_mode mode
${rule_family:-x} $rule_src I
64 local src_spec dest_spec
65 fw_get_negation src_spec
'-s' "${rule_src_ip:+$rule_src_ip/$rule_src_ip_prefixlen}"
66 fw_get_negation dest_spec
'-d' "${rule_dest_ip:+$rule_dest_ip/$rule_dest_ip_prefixlen}"
68 local rule_src_port_copy
69 local rule_dest_port_copy
71 [ "$rule_proto" == "tcpudp" ] && rule_proto
="tcp udp"
72 rule_src_port_copy
="$rule_src_port"
73 rule_dest_port_copy
="$rule_dest_port"
74 for rule_proto
in $rule_proto; do
75 rule_src_port
="$rule_src_port_copy"
76 rule_dest_port
="$rule_dest_port_copy"
77 fw_get_negation rule_proto
'-p' "$rule_proto"
78 for rule_src_port
in ${rule_src_port:-""}; do
79 fw_get_port_range rule_src_port
$rule_src_port
80 fw_get_negation rule_src_port
'--sport' "$rule_src_port"
81 for rule_dest_port
in ${rule_dest_port:-""}; do
82 fw_get_port_range rule_dest_port
$rule_dest_port
83 fw_get_negation rule_dest_port
'--dport' "$rule_dest_port"
84 for rule_src_mac
in ${rule_src_mac:-""}; do
85 fw_get_negation rule_src_mac
'--mac-source' "$rule_src_mac"
86 for rule_icmp_type
in ${rule_icmp_type:-""}; do
87 [ "$rule_proto" = "-p icmp" ] || rule_icmp_type
=""
88 fw add
$mode $table $chain $target + \
89 { $rule_src_ip $rule_dest_ip } { \
90 $src_spec $dest_spec $rule_proto \
91 $rule_src_port $rule_dest_port \
92 ${rule_src_mac:+-m mac $rule_src_mac} \
93 ${rule_icmp_type:+--icmp-type $rule_icmp_type} \
94 $
{rule_limit
:+-m limit
--limit $rule_limit \
95 ${rule_limit_burst:+--limit-burst $rule_limit_burst}} \
104 fw_callback post rule