mirror of https://github.com/aredn/aredn.git
79 lines
2.6 KiB
Plaintext
79 lines
2.6 KiB
Plaintext
|
#!/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 20000 iif $DEVICE lookup 30
|
||
|
ip rule del pref 20001 iif $DEVICE lookup 31
|
||
|
ip rule del pref 20098 iif $DEVICE lookup main
|
||
|
ip rule del pref 20099 iif $DEVICE unreachable
|
||
|
fi
|
||
|
|
||
|
if [ "$INTERFACE" == "lan" ] ; then
|
||
|
ip rule del pref 30000 iif $DEVICE lookup 30
|
||
|
ip rule del pref 30098 iif $DEVICE lookup 31
|
||
|
ip rule del pref 30099 iif $DEVICE lookup main
|
||
|
fi
|
||
|
|
||
|
if [ "$INTERFACE" == "loopback" ] ; then
|
||
|
ip rule del pref 30200 lookup 30
|
||
|
ip rule del pref 30201 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
|
||
|
ip rule add pref 20000 iif $DEVICE lookup 30
|
||
|
ip rule add pref 20001 iif $DEVICE lookup 31
|
||
|
if [ $is_olsrgw -eq 1 ] ; then
|
||
|
ip rule add pref 20098 iif $DEVICE lookup main
|
||
|
fi
|
||
|
ip rule add pref 20099 iif $DEVICE unreachable
|
||
|
|
||
|
fi
|
||
|
|
||
|
# Makes sure the lan interface is allowed to hit the mesh(30), meshgw(31), and local routes (main) Local ethernet is trusted to use additonal rules.
|
||
|
if [ "$INTERFACE" == "lan" ] ; then
|
||
|
ip rule add pref 30000 iif $DEVICE lookup 30
|
||
|
ip rule add pref 30098 iif $DEVICE lookup 31
|
||
|
ip rule add pref 30099 iif $DEVICE lookup main
|
||
|
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 30200 lookup 30
|
||
|
ip rule add pref 30201 lookup main
|
||
|
ip rule add pref 30299 lookup 31
|
||
|
fi
|
||
|
|
||
|
fi
|
||
|
|
||
|
# Ensure we send a good exit code
|
||
|
exit 0;
|
||
|
|