aredn/files/etc/hotplug.d/iface/11-meshrouting

97 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
configmode=`uci -q -c /etc/local/uci/ get hsmmmesh.settings.config`
if [ "$configmode" != "mesh" ] ; then exit 0; fi
# This section will generate rtnetlink errors when the rule doesn't exist.
# This will be most common in the case of ifup.
# On initial boot no route will be present, and on most interface restarts
# the route should already be gone from ifdown but some scripts do not call
# ifup/ifdown to control the interface so we will want to make sure to
# run a clean before hand to avoid duplicate rules.
if [ "$ACTION" = "ifdown" ] || [ "$ACTION" = "ifup" ] ; then
echo "Deleting specific routing rules that may exist."
if [ "$INTERFACE" == "wifi" ] || [ "$INTERFACE" == "dtdlink" ] ; then
ip rule del pref 20010 iif $DEVICE lookup 29
ip rule del pref 20020 iif $DEVICE lookup 30
ip rule del pref 20080 iif $DEVICE lookup 31
ip rule del pref 20090 iif $DEVICE lookup main
ip rule del pref 20099 iif $DEVICE unreachable
fi
if [ "$INTERFACE" == "lan" ] ; then
ip rule del pref 30010 iif $DEVICE lookup 29
ip rule del pref 30020 iif $DEVICE lookup 30
ip rule del pref 30090 iif $DEVICE lookup main
ip rule del pref 30099 iif $DEVICE lookup 31
fi
if [ "$INTERFACE" == "loopback" ] ; then
ip rule del pref 30210 lookup 29
ip rule del pref 30220 lookup 30
ip rule del pref 30290 lookup main
ip rule del pref 30299 lookup 31
fi
fi
if [ "$ACTION" = "ifup" ] ; then
is_olsrgw=`cat /etc/config.mesh/_setup|grep -i olsrd_gw|cut -d ' ' -f 3`
# Set routes for wifi or device to device linking
# unreachable rule is needed to ensure packets do not traverse a rule later that considers routing to another network.
echo "Setting routing rules."
if [ "$INTERFACE" == "wifi" ] || [ "$INTERFACE" == "dtdlink" ]; then
if [ -e /etc/config/dmz-mode ] ; then
ip rule add pref 20010 iif $DEVICE lookup 29
fi
ip rule add pref 20020 iif $DEVICE lookup 30
ip rule add pref 20080 iif $DEVICE lookup 31
if [ $is_olsrgw -eq 1 ] ; then
ip rule add pref 20090 iif $DEVICE lookup main
fi
ip rule add pref 20099 iif $DEVICE unreachable
fi
# Makes sure the lan interface is allowed to hit the local interfaces(29) mesh(30), meshgw(31), and local routes (main) Local ethernet is trusted to use additonal rules.
if [ "$INTERFACE" == "lan" ] ; then
ip rule add pref 30010 iif $DEVICE lookup 29
ip rule add pref 30020 iif $DEVICE lookup 30
ip rule add pref 30090 iif $DEVICE lookup main
ip rule add pref 30099 iif $DEVICE lookup 31
# Lets go ahead and set the route to the local network here since we only need to be able to route to it after the interface comes up.
lan_ipaddr=`uci -q get network.lan.ipaddr`
lan_netmask=`uci -q get network.lan.netmask`
lan_ifname=`uci -q get network.lan.ifname`
if [ "$lan_ifname" != "" ] && [ "$lan_ipaddr" != "" ] && [ "$lan_netmask" != "" ] ; then
lan_networkip=`ipcalc.sh $lan_ipaddr $lan_netmask|grep NETWORK|cut -d'=' -f2`
ip route add $lan_networkip/$lan_netmask table 29 dev $lan_ifname
fi
fi
# Handles setting up rules for local resolution of routes. MeshGW should be last for localhost otherwise ping test of olsrd will break
if [ "$INTERFACE" == "loopback" ] ; then
ip rule add pref 30210 lookup 29
ip rule add pref 30220 lookup 30
ip rule add pref 30290 lookup main
ip rule add pref 30299 lookup 31
fi
fi
# Ensure we send a good exit code
exit 0;