Browse Source

batman: fix and improve ff_check_gatewa

force gateway mode to server if there is no other gateway in range.
Karsten Böddeker 7 years ago
parent
commit
40e3c70e3a
1 changed files with 8 additions and 2 deletions
  1. 8 2
      batman/ff_check_gateway

+ 8 - 2
batman/ff_check_gateway

@@ -23,15 +23,21 @@ fi
 # any meshable interface.
 shopt -s nullglob
 for mesh_int in /sys/class/net/*/mesh; do
+	ifname=$(IFS="/";set -- ${mesh_int};printf "$5\n")
 	# Ignore any external BATMAN instance, if present
-	if echo "${mesh_int}" | grep -q '-ext$'; then
+	if echo "${ifname}" | grep -q '-ext$'; then
 		continue
 	fi
 
+	if [ "${new_state}" == "off" -a "$(tail -n 1 /sys/kernel/debug/batman_adv/${ifname}/gateways)" == "No gateways in range ..." ] ; then
+		logger "No other B.A.T.M.A.N. gateways present, forcing gateway mode to server on ${ifname}"
+		new_state="server"
+	fi
+
 	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}"
+	logger "B.A.T.M.A.N. gateway mode changed from ${old_state} to ${new_state} on ${ifname}"
 done