[PATCH v3 10/14] Add support for second port of Nanostation M

Adrian Schmutzler freifunk at adrianschmutzler.de
Mo Apr 22 14:35:33 CEST 2019


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

---

This is not tested.

Changes in v2:
- Added patch

Changes in v3:
- Merged with "Fix/improve setup of one- and two-port devices"
  from FritzBox patchset
- Fixed uci -q

Please re-review after this merge
---
 .../files/etc/uci-defaults/22a-config-ports        |  6 +++-
 .../files/lib/functions/fff/networksetup           | 37 ++++++++++++++++++++++
 .../fff/fff-network/files/usr/sbin/settwoeth       | 34 ++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100755 src/packages/fff/fff-network/files/usr/sbin/settwoeth

diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
index cc7ab277..4cd1387a 100644
--- a/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
+++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22a-config-ports
@@ -71,6 +71,11 @@ case "$BOARD" in
 		setupSwitch "eth0" "1 2 0t" "3 4 0t" "5 0t"
 		setupWan "eth0.2"
 		;;
+	ubnt-nano-m)
+		setupOnePort "eth0" "WAN"
+		setup2ndEth "eth1" "CLIENT"
+		uci set "fff.ui.portsetup=twoeth"
+		;;
 	cpe210-v2|\
 	cpe210-v3|\
 	tl-mr3020-v1|\
@@ -80,7 +85,6 @@ case "$BOARD" in
 	ubnt-bullet-m|\
 	ubnt-loco-m|\
 	ubnt-loco-m-xw|\
-	ubnt-nano-m|\
 	ubnt-pico-m|\
 	ubnt-power-m-xw|\
 	ubnt-unifi|\
diff --git a/src/packages/fff/fff-network/files/lib/functions/fff/networksetup b/src/packages/fff/fff-network/files/lib/functions/fff/networksetup
index ccc943df..4ce96953 100644
--- a/src/packages/fff/fff-network/files/lib/functions/fff/networksetup
+++ b/src/packages/fff/fff-network/files/lib/functions/fff/networksetup
@@ -161,3 +161,40 @@ setupOnePort() {
 	fi
 	uci commit network
 }
+
+setup2ndEth() {
+	# Set up second port for devices with to ports directly connected to ethX (no switch)
+	# This is intended for initial setup and for updates
+	#
+	# Use this in combination with setupOnePort() for the first port.
+	# Calling setupOnePort() will overwrite the settings made here, so always call in succession, e.g.
+	# setupOnePort eth0 "WAN"
+	# setup2ndEth eth1 "BATMAN"
+	#
+	# Usage: setup2ndEth <DEV, e.g. eth1> <ETHMODE: BATMAN or CLIENT>
+
+	local DEV=$1
+	local ETHMODE=$2
+
+	uci set "network.$DEV=interface"
+	uci set "network.$DEV.ifname=$DEV"
+
+	local meshif="$(uci -q get network.mesh.ifname)"
+
+	if [ "$ETHMODE" = "CLIENT" ] ; then
+		# Only write if not only there
+		echo "$meshif" | grep -q "$DEV" || uci set network.mesh.ifname="$meshif $DEV"
+	else
+		# Remove if there
+		uci set network.mesh.ifname="$(echo "$meshif" | sed "s/ *$DEV//")"
+	fi
+
+	if [ "$ETHMODE" = "BATMAN" ] ; then
+		# Always overwrite (if both ports are set to BATMAN, only the second will be)
+		uci set network.ethmesh.ifname="$DEV"
+	else
+		uci -q get network.ethmesh.ifname | grep -q "$DEV" && uci del network.ethmesh.ifname
+	fi
+
+	uci commit network
+}
diff --git a/src/packages/fff/fff-network/files/usr/sbin/settwoeth b/src/packages/fff/fff-network/files/usr/sbin/settwoeth
new file mode 100755
index 00000000..4b7478af
--- /dev/null
+++ b/src/packages/fff/fff-network/files/usr/sbin/settwoeth
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+if ! [ "$(uci -q get fff.ui.portsetup)" = "twoeth" ] ; then
+	echo "Wrong device. This is for devices with two ethX without switch!"
+	exit 1
+fi
+
+. /lib/functions/fff/networksetup
+
+ETHMODE1=$1
+ETHMODE2=$2
+DEV1=$3
+DEV2=$4
+
+[ -n "$DEV1" ] || DEV1="eth0"
+[ -n "$DEV2" ] || DEV2="eth1"
+
+if ! ([ "$ETHMODE1" = "WAN" ] || [ "$ETHMODE1" = "CLIENT" ] || [ "$ETHMODE1" = "BATMAN" ]); then
+	echo "Wrong port mode for first port. Choose one of: WAN, CLIENT, BATMAN"
+	exit 1
+fi
+if ! ([ "$ETHMODE2" = "CLIENT" ] || [ "$ETHMODE2" = "BATMAN" ]); then
+	echo "Wrong port mode for second port. Choose one of: CLIENT, BATMAN"
+	exit 1
+fi
+if [ "$ETHMODE1" = "BATMAN" ] && [ "$ETHMODE2" = "BATMAN" ]; then
+	echo "Only one port can be set to BATMAN!"
+	exit 1
+fi
+
+setupOnePort "$DEV1" "$ETHMODE1"
+setup2ndEth "$DEV2" "$ETHMODE2"
+/etc/init.d/network restart
+echo "Port updated successfully."
-- 
2.11.0



Mehr Informationen über die Mailingliste franken-dev