1 # Copyright (C) 2009-2010 OpenWrt.org
3 fw_config_get_redirect
() {
4 [ "${redirect_NAME}" != "$1" ] ||
return
5 fw_config_get_section
"$1" redirect
{ \
18 string proto
"tcpudp" \
21 [ -n "$redirect_name" ] || redirect_name
=$redirect__name
25 fw_config_get_redirect
"$1"
27 fw_callback pre redirect
29 [ -n "$redirect_src" -a -n "$redirect_dest_ip" ] ||
{
30 fw_die
"redirect ${redirect_name}: needs src and dest_ip"
33 local mode
=$
(fw_get_family_mode
${redirect_family:-x} $redirect_src I
)
35 local nat_dest_port
=$redirect_dest_port
36 redirect_dest_port
=$
(fw_get_port_range
$redirect_dest_port)
37 redirect_src_port
=$
(fw_get_port_range
$redirect_src_port)
38 redirect_src_dport
=$
(fw_get_port_range
$redirect_src_dport)
39 local fwd_dest_port
=${redirect_dest_port:-$redirect_src_dport}
41 [ "$redirect_proto" == "tcpudp" ] && redirect_proto
="tcp udp"
42 for redirect_proto
in $redirect_proto; do
43 fw add
$mode n zone_
${redirect_src}_prerouting DNAT $
{ $redirect_src_ip $redirect_dest_ip } { \
44 ${redirect_proto:+-p $redirect_proto} \
45 ${redirect_src_ip:+-s $redirect_src_ip} \
46 ${redirect_src_dip:+-d $redirect_src_dip} \
47 ${redirect_src_port:+--sport $redirect_src_port} \
48 ${redirect_src_dport:+--dport $redirect_src_dport} \
49 ${redirect_src_mac:+-m mac --mac-source $redirect_src_mac} \
50 --to-destination ${redirect_dest_ip}${redirect_dest_port:+:$nat_dest_port} \
53 fw add
$mode f zone_
${redirect_src}_forward ACCEPT ^
{ $redirect_src_ip $redirect_dest_ip } { \
54 -d $redirect_dest_ip \
55 ${redirect_proto:+-p $redirect_proto} \
56 ${redirect_src_ip:+-s $redirect_src_ip} \
57 ${redirect_src_port:+--sport $redirect_src_port} \
58 ${fwd_dest_port:+--dport $fwd_dest_port} \
59 ${redirect_src_mac:+-m mac --mac-source $redirect_src_mac} \
63 fw_callback post redirect