123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #!/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
- fi
- #
- # If there is no DHCP server running here, we should not be an
- # active gateway.
- if ! systemctl status isc-dhcp-server >/dev/null 2>&1; then
- force_offline="true"
- fi
- #
- # 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
- #
- # Forcefully offline?
- if [ "${force_offline}" = "true" ]; then
- new_state="off"
- fi
- #
- # Compatiblity glue: Newer versions of batctl print a deprecation
- # warning when called with -m <batif>. Avoid spamming the log and
- # producting SPAM by silently handling this here.
- mesh_if_param="-m"
- if batctl -h 2>&1 | grep -q "meshif"; then
- mesh_if_param="meshif"
- fi
- #
- # Let's check the interfaces
- 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 "${mesh_if_param}" "${iface}" gw_mode | awk '{ print $1 }')"
- if [ "$old_state" = "$new_state" ]; then
- # Nothing to do here, carry on
- continue
- fi
- # Set new values
- batctl "${mesh_if_param}" "${iface}" gw_mode "${new_state}"
- logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${iface}"
- done
|