[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
31 fw_get_family_mode mode ${forwarding_family:-x} ${forwarding_dest:-${forwarding_src:--}} i
32
33 fw add $mode f $chain $target ^
34
35 # propagate masq zone flag
36 [ -n "$forwarding_src" ] && list_contains FW_CONNTRACK_ZONES $forwarding_src && {
37 append FW_CONNTRACK_ZONES $forwarding_dest
38 }
39 [ -n "$forwarding_dest" ] && list_contains FW_CONNTRACK_ZONES $forwarding_dest && {
40 append FW_CONNTRACK_ZONES $forwarding_src
41 }
42
43 fw_callback post forwarding
44 }