[package] firewall:
[openwrt/svn-archive/archive.git] / package / firewall / files / lib / core_forwarding.sh
1 # Copyright (C) 2009-2010 OpenWrt.org
2
3 fw_config_get_forwarding() {
4 [ "${forwarding_NAME}" != "$1" ] || return
5 fw_config_get_section "$1" forwarding { \
6 string _name "$1" \
7 string name "" \
8 string src "" \
9 string dest "" \
10 string family "" \
11 } || return
12 [ -n "$forwarding_name" ] || forwarding_name=$forwarding__name
13 }
14
15 fw_load_forwarding() {
16 fw_config_get_forwarding "$1"
17
18 fw_callback pre forwarding
19
20 local chain=forward
21 [ -n "$forwarding_src" ] && {
22 chain=zone_${forwarding_src}_forward
23 }
24
25 local target=ACCEPT
26 [ -n "$forwarding_dest" ] && {
27 target=zone_${forwarding_dest}_ACCEPT
28 }
29
30 local mode=$(fw_get_family_mode ${forwarding_family:-x} ${forwarding_dest:-${forwarding_src:--}} i)
31
32 fw add $mode f $chain $target ^
33
34 # propagate masq zone flag
35 [ -n "$forwarding_src" ] && list_contains CONNTRACK_ZONES $forwarding_src && {
36 append CONNTRACK_ZONES $forwarding_dest
37 }
38 [ -n "$forwarding_dest" ] && list_contains CONNTRACK_ZONES $forwarding_dest && {
39 append CONNTRACK_ZONES $forwarding_src
40 }
41
42 fw_callback post forwarding
43 }