1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/sh
- #
- # Check if this system (still) should be an active B.A.T.M.A.N. gateway
- # and update gw_mode accordingly if necessary (Salt managed)
- #
- # Rewritten by: Maximilian Wilhelm <max@sdn.clinic>
- # -- Sat, 07 Mar 2015 23:21:53 +0100
- #
- node_status_file="/etc/freifunk/status"
- # Default to "off"
- new_state="off"
- force_offline="false"
- #
- # If the status of this machine is not 'active', we should not
- # be an active gateway.
- if [ -f "${node_status_file}" ]; then
- status=$(cat "${node_status_file}")
- if [ "${status}" != "active" ]; then
- force_offline="true"
- fi
- #
- # If there is no DHCP server running here, we should not be an
- # active gateway.
- elif ! systemctl status isc-dhcp-server >/dev/null; then
- force_offline="true"
- #
- # 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.
- elif ip route show | grep "^default via 10.132." -q; then
- new_state="server"
- fi
- for iface in $(ip -br l | awk '/^bat-/ { print $1 }'); do
- # Ignore any external BATMAN instance, if present
- if echo "${iface}" | grep -q '-ext$'; then
- continue
- fi
- old_state="$(batctl -m "${iface}" gw_mode)"
- if [ "$old_state" = "$new_state" ]; then
- # Nothing to do here, carry on
- continue
- fi
- # Set new values
- batctl -m "${iface}" gw_mode "${new_state}"
- logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${iface}"
- done
|