#!/bin/bash # # Check if this system (still) is a gateway and update mesh mode if necessary (Salt managed) # # Rewritten by: Maximilian Wilhelm # -- Sat, 07 Mar 2015 23:21:53 +0100 # # Default to "off" new_state="off" # # If there is a default route via an IP from our address space # we assume that this gateway has an internet connection. As a # default route would be propagated in via iBGP and/or OSPF it # will only be present if at least one border router has an up # and running connection to AS201701. if ip route show | grep "^default via 10.132." -q; then new_state="server" fi # Make sure the following glob isn't interpreted as a literal string if there isn't # any meshable interface. shopt -s nullglob for mesh_int in /sys/class/net/*/mesh; do ifname=$(IFS="/";set -- ${mesh_int};printf "$5\n") # Ignore any external BATMAN instance, if present if echo "${ifname}" | grep -q '-ext$'; then continue fi if [ "${new_state}" == "off" -a "$(tail -n 1 /sys/kernel/debug/batman_adv/${ifname}/gateways)" == "No gateways in range ..." ] ; then logger "No other B.A.T.M.A.N. gateways present, forcing gateway mode to server on ${ifname}" new_state="server" fi old_state="$(cat ${mesh_int}/gw_mode)" [ "$old_state" == "$new_state" ] && continue echo "${new_state}" > "${mesh_int}/gw_mode" echo "54MBit/54MBit" > "${mesh_int}/gw_bandwidth" logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${ifname}" done