ff_check_gateway 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. old_state="$(cat ${mesh_int}/gw_mode)"
  24. [ "$old_state" == "$new_state" ] && continue
  25. echo "${new_state}" > "${mesh_int}/gw_mode"
  26. echo "54MBit/54MBit" > "${mesh_int}/gw_bandwidth"
  27. logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${mesh_int}"
  28. done