ff_check_gateway 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. #
  3. # Check if this system (still) should be an active B.A.T.M.A.N. gateway
  4. # and update gw_mode accordingly if necessary (Salt managed)
  5. #
  6. # Rewritten by: Maximilian Wilhelm <max@sdn.clinic>
  7. # -- Sat, 07 Mar 2015 23:21:53 +0100
  8. #
  9. node_status_file="/etc/freifunk/status"
  10. # Default to "off"
  11. new_state="off"
  12. force_offline="false"
  13. #
  14. # If the status of this machine is not 'active', we should not
  15. # be an active gateway.
  16. if [ -f "${node_status_file}" ]; then
  17. status=$(cat "${node_status_file}")
  18. if [ "${status}" != "active" ]; then
  19. force_offline="true"
  20. fi
  21. #
  22. # If there is no DHCP server running here, we should not be an
  23. # active gateway.
  24. elif ! systemctl status isc-dhcp-server >/dev/null; then
  25. force_offline="true"
  26. #
  27. # If there is a default route via an IP from our address space
  28. # we assume that this gateway has an internet connection. As a
  29. # default route would be propagated in via iBGP and/or OSPF it
  30. # will only be present if at least one border router has an up
  31. # and running connection to AS201701.
  32. elif ip route show | grep "^default via 10.132." -q; then
  33. new_state="server"
  34. fi
  35. for iface in $(ip -br l | awk '/^bat-/ { print $1 }'); do
  36. # Ignore any external BATMAN instance, if present
  37. if echo "${iface}" | grep -q '-ext$'; then
  38. continue
  39. fi
  40. old_state="$(batctl -m "${iface}" gw_mode)"
  41. if [ "$old_state" = "$new_state" ]; then
  42. # Nothing to do here, carry on
  43. continue
  44. fi
  45. # Set new values
  46. batctl -m "${iface}" gw_mode "${new_state}"
  47. logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${iface}"
  48. done