source: luci/trunk/contrib/package/freifunk-policyrouting/files/etc/hotplug.d/iface/30-policyrouting @ 6967

Last change on this file since 6967 was 6967, checked in by soma, 8 years ago

Add freifunk-policyrouting and luci-app-freifunk-policyrouting

File size: 2.3 KB
Line 
1[ "$INTERFACE" != "wan" ] && exit 0
2
3case $ACTION in
4        ifup)
5        pr=`uci get freifunk-policyrouting.pr.enable`
6        if [ $pr = "1" ]; then
7            logger -t policyrouting "Starting policy routing on $INTERFACE"
8
9            # Setup new tables
10            tables="/etc/iproute2/rt_tables"
11            if [ -z "`grep "111" $tables`" ]; then
12                echo "111 olsr" >> $tables
13            fi
14            if [ -z "`grep "112" $tables`" ]; then
15                echo "112 olsr-default" >> $tables
16            fi
17
18            # Make sure Rt_tables in olsrd are in place
19            if [ ! "`uci -q get olsrd.@olsrd[0].RtTable`" == "111" ] || [ ! "`uci -q get olsrd.@olsrd[0].RtTableDefault`" == "112" ]; then
20                uci set olsrd.@olsrd[0].RtTable='111'
21                uci set olsrd.@olsrd[0].RtTableDefault='112'
22                uci commit
23                /etc/init.d/olsrd restart
24            fi
25
26            # Disable dyn_gw and dyngw_plain
27            dyngwlib=`uci show olsrd |grep dyn_gw.so |awk {' FS="."; print $1"."$2 '}`
28            if [ -n "$dyngwlib" ]; then
29                uci set $dyngwlib.ignore=1
30                uci commit
31            fi
32
33            dyngwplainlib=`uci show olsrd |grep dyn_gw_plain |awk {' FS="."; print $1"."$2 '}`
34            if [ -n "$dyngwplainlib" ]; then
35                uci set $dyngwplainlib.ignore=1
36                uci commit
37            fi
38   
39            gw=`uci -p /var/state get network.wan.gateway`
40            netmask=`uci -p /var/state get network.wan.netmask`
41            if [ -z "$netmask" ]; then
42                NETMASK="255.255.255.255"
43            fi
44
45            if  [ -n "`uci -p /var/state get network.wan.ifname`" ]; then
46                device=`uci -p /var/state get network.wan.ifname`
47            else
48                device=`uci -p /var/state get network.wan.device`
49            fi
50
51            eval `ipcalc.sh $gw $netmask`
52
53            test -n "`ip r s t default`" && ip r d default t default
54            test -n "`ip r s |grep default`" && ip route del default
55            ip route add $NETWORK/$NETMASK dev $device table default
56            ip route add default via $gw dev $device table default
57
58            ip rule del lookup main
59            ip rule add fwmark 1 lookup olsr-default
60            ip rule add lookup main
61            ip rule add lookup olsr
62        else
63            # Remove custom routing tables from olsrd
64            if [ "`uci -q get olsrd.@olsrd[0].RtTable`" == "111" ] || [ "`uci -q get olsrd.@olsrd[0].RtTableDefault`" == "112" ]; then
65                uci delete olsrd.@olsrd[0].RtTable
66                uci delete olsrd.@olsrd[0].RtTableDefault
67                uci commit
68                /etc/init.d/olsrd restart
69            fi
70        fi
71    ;;
72
73    ifdown)
74    logger -t policyrouting "Deleting policy rules for $INTERFACE"
75    ip rule del fwmark 1 lookup olsr-default > /dev/null 2>&1
76    ip rule del lookup olsr > /dev/null 2>&1
77    ;;
78esac
Note: See TracBrowser for help on using the repository browser.