[v2] fff-hoods: Provide support for more than one gateway

Submitted by Adrian Schmutzler on Nov. 2, 2017, 1:56 p.m.

Details

Message ID 1509630991-3415-1-git-send-email-freifunk@adrianschmutzler.de
State Deferred
Headers show

Commit Message

Adrian Schmutzler Nov. 2, 2017, 1:56 p.m.
This patch uses the information accessible through batctl.

This has the advantage that no additional data sources are
required (hood file, ...) and thus no one has to put additional
information anywhere.

Semi-tested: Tested via console, but not in connection with
configurehood.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

Changes in v2:
- Filter multicast addresses
---
 src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange | 11 +++++++++++
 src/packages/fff/fff-hoods/files/usr/sbin/configurehood       |  4 ++--
 2 files changed, 13 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
index 9aeb434..d7851b5 100644
--- a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
+++ b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
@@ -31,3 +31,14 @@  getUpgradePath() {
 	fi
 	return 0
 }
+
+getJsonGateway() {
+	regex='s/^\s*[^ ]*\s*\([^ ]*\)\s.*/\1/p'
+	batctl gwl | grep "Bit" | sed -n -e "$regex" | while read -r line ; do
+		gwmac="$(batctl tg | grep -v -e " 0[01]:00:5e" -e " 01:80:c2" -e " 33:33" | grep -m 1 "$line" | sed -n -e "$regex")"
+		# remove reserved Multicast MAC adresses (https://en.wikipedia.org/wiki/Multicast_address#Ethernet)
+		eui="$(echo "$gwmac" | awk -F: '{ printf("%02x%s:%sff:fe%s:%s%s\n", xor(("0x"$1),2), $2, $3, $4, $5, $6) }')"
+		gwaddr="fe80::${eui}%br-mesh"
+		wget -T15 -t5 "http://[$gwaddr]:2342/keyxchangev2data" -O "$hoodfile" && break
+	done
+}
\ No newline at end of file
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index 8ffaced..762aede 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -115,8 +115,8 @@  else
 			wget -T15 -t5 "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectortmp" || wget -T15 -t5 "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectortmp"
 		fi
 	else
-		echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1"
-		wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$hoodfile"
+		echo "We have a Gateway in Range, we load the keyxchangev2data based on batctl"
+		getJsonGateway
 		#UPLINK: Do nothing
 	fi
 fi