Browse Source

Add ff_check_gateway command to handle B.A.T.M.A.N. gateway mode according to presence of default route.

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
Maximilian Wilhelm 7 years ago
parent
commit
2a995cb9bc
3 changed files with 66 additions and 1 deletions
  1. 32 0
      batman/ff_check_gateway
  2. 8 0
      batman/ff_check_gateway.cron
  3. 26 1
      batman/init.sls

+ 32 - 0
batman/ff_check_gateway

@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# Check if this system (still) is a gateway and update mesh mode if necessary (Salt managed)
+#
+# Rewritten by: Maximilian Wilhelm <max@rfc2324.org>
+#  -- Sat, 07 Mar 2015 23:21:53 +0100
+#
+
+# Default to "off"
+new_state="off"
+
+#
+# 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
+
+# Make sure the following glob isn't interpreted as a literal string if there isn't
+# any meshable interface.
+shopt -s nullglob
+for mesh_int in /sys/class/net/*/mesh; do
+	old_state="$(cat ${mesh_int}/gw_mode)"
+	[ "$old_state" == "$new_state" ] && continue
+
+	echo "${new_state}"  > "${mesh_int}/gw_mode"
+	echo "54MBit/54MBit" > "${mesh_int}/gw_bandwidth"
+	logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${mesh_int}"
+done

+ 8 - 0
batman/ff_check_gateway.cron

@@ -0,0 +1,8 @@
+#
+# Check if THE INTERNET is reachable via chosen upstream (Salt managed)
+#
+SHELL=/bin/bash
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+MAILTO={{ salt['pillar.get']("ffho:tech_c_mail") }}
+
+* * * * *       root    /usr/local/sbin/ff_check_gateway

+ 26 - 1
batman/init.sls

@@ -6,7 +6,8 @@
 # Only set up batman and load batman_adv kernel module if the role »batman«
 # has been configured for this node.
 #
-{%- if 'batman' in salt['pillar.get']('nodes:' ~ grains['id']  ~ ':roles', ()) %}
+{%- set roles = salt['pillar.get']('nodes:' ~ grains['id']  ~ ':roles', []) %}
+{%- if 'batman' in roles %}
 include:
   - apt
 
@@ -73,6 +74,24 @@ enable-ff-fix-batman-service:
       - source: salt://batman/batman-adv.module.conf
 
 
+#
+# Is this node a B.A.T.M.A.N. gateway?
+  {%- if 'batman_gw' in roles %}
+
+/etc/cron.d/ff_check_gateway:
+  file.managed:
+    - source: salt://batman/ff_check_gateway.cron
+    - template: jinja
+
+/usr/local/sbin/ff_check_gateway:
+  file.managed:
+    - source: salt://batman/ff_check_gateway
+    - mode: 755
+    - user: root
+    - group: root
+
+  {% endif %}
+
 #
 # If the role »batman» is NOT configured for this node, make sure to purge any
 # traces of a previous installation, if present.
@@ -100,4 +119,10 @@ disable-ff-fix-batman-service:
 
 /etc/bat-hosts:
   file.absent
+
+/etc/cron.d/ff_check_gateway:
+  file.absent
+
+/usr/local/sbin/ff_check_gateway:
+  file.absent
 {% endif %}