ff_check_gateway 1.5 KB

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