1 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "wan" ]; then
2 pr=`uci get freifunk-policyrouting.pr.enable`
3 strict=`uci get freifunk-policyrouting.pr.strict`
4 zones=`uci get freifunk-policyrouting.pr.zones`
9 if [ -n "`uci -p /var/state get network.wan.ifname`" ]; then
10 wandev=`uci -p /var/state get network.wan.ifname`
12 wandev=`uci -p /var/state get network.wan.device`
15 iptables -t mangle -D PREROUTING -j prerouting_policy > /dev/null 2>&1
16 iptables -t mangle -F prerouting_policy > /dev/null 2>&1
17 iptables -t mangle -N prerouting_policy > /dev/null 2>&1
18 iptables -t mangle -I PREROUTING -j prerouting_policy > /dev/null 2>&1
20 # If no route is in table olsr-default, then usually the hosts local default route is used.
21 # If set to strict then we add a filter which prevents this
22 if [ "$strict" == "1" ]; then
23 ln=$(( `iptables -L FORWARD -v --line-numbers | grep -m 1 reject | awk {' print $1 '}` - 1 ))
24 if [ ! $ln -gt 0 ]; then
27 if [ -z "`iptables -L |grep 'Chain forward_policy'`" ]; then
28 iptables -N forward_policy
30 if [ -z "`iptables -L FORWARD -v |grep forward_policy`" ]; then
31 iptables -I FORWARD $ln -m mark --mark 1 -j forward_policy
33 iptables -F forward_policy
34 iptables -I forward_policy -o $wandev -j REJECT --reject-with icmp-net-prohibited
37 # set mark 1 for all packets coming in via enabled zones
39 # find out which interfaces belong to this zone
40 zone=`uci show firewall |grep "name=$i" |awk {' FS="."; print $1"."$2 '}`
41 interfaces=`uci get $zone.network`
42 if [ "$interfaces" == "" ]; then
45 for int in $interfaces; do
46 if [ "`uci -q get network.$int.type`" == "bridge" ]; then
49 if [ -n "`uci -p /var/state get network.$int.ifname`" ]; then
50 dev=`uci -p /var/state get network.$int.ifname`
52 dev=`uci -p /var/state get network.$int.device`
55 logger -t policyrouting "Add mark 1 to packages coming in via interface $dev"
56 iptables -t mangle -I prerouting_policy -i $dev -j MARK --set-mark 1
60 # Cleanup policy routing stuff that might be lingering around
61 if [ -n "`iptables -t mangle -L PREROUTING |grep _policy`" ]; then
62 logger -t policyrouting "Delete prerouting_policy chain in table mangle"
63 iptables -t mangle -D PREROUTING -j prerouting_policy
64 iptables -t mangle -F prerouting_policy
65 iptables -t mangle -X prerouting_policy
67 if [ -n "`iptables -L FORWARD |grep forward_policy`" ]; then
68 logger -t policyrouting "Delete strict forwarding rules"
69 iptables -D FORWARD -m mark --mark 1 -j forward_policy
70 iptables -F forward_policy
71 iptables -X forward_policy
73 logger -t policyrouting "All firewall rules for policyrouting removed."