[OpenWrt-Devel] base-files: config_generate: split macaddr with multiple ifaces
diff mbox series

Message ID 20191112235709.60227-1-freifunk@adrianschmutzler.de
State Superseded
Delegated to: Adrian Schmutzler
Headers show
Series
  • [OpenWrt-Devel] base-files: config_generate: split macaddr with multiple ifaces
Related show

Commit Message

Adrian Schmutzler Nov. 12, 2019, 11:57 p.m. UTC
From: Sungbo Eo <mans0n@gorani.run>

netifd does not handle network.@device[x].name properly if it
contains multiple ifaces separated by spaces. Due to this, board.d
lan_mac setup does not work if multiple ifaces are set to LAN by
ucidef_set_interface_lan.

To fix this, create a device node for each member iface when
running config_generate. Those are named based on the member
ifname:

  ucidef_set_interface_lan "eth0 eth1.1"
  ucidef_set_interface_macaddr "lan" "yy:yy:yy:yy:yy:01"

will return

  config device 'eth0_dev'
        option name 'eth0'
        option macaddr 'yy:yy:yy:yy:yy:01'

  config device 'eth1_1_dev'
        option name 'eth1.1'
        option macaddr 'yy:yy:yy:yy:yy:01'

The updated node names are only used for cases where more than
one member iface is specified. The typical single-ifname case
won't be altered (lan_dev, wan_dev).

Signed-off-by: Sungbo Eo <mans0n@gorani.run>
[extended description, changed commit title]
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

---

I plan to also backport this to at least 19.07 and 18.06, as it's
essentially a fix.

Note that it actually would be easier to use the new naming scheme
consistently also for single-member lan/wan. I have not done that
here as it would mean a (cosmetic) change affecting many users,
while the changes shown here would limit the new node names to those
users actually having multiple members in lan.

From the perspective of tidyness however, it would actually be
preferable to switch to the new syntax entirely:
- It will only change for new installations/sysupgrade -n anyway
- It is more logical to extend when the user adds a member to lan
  manually later
- No duplicate setup code
- Uniform names for device nodes

Please share your views on this aspect.
---
 package/base-files/files/bin/config_generate | 27 +++++++++++++++-----
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Adrian Schmutzler Nov. 13, 2019, 12:21 a.m. UTC | #1
> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Adrian Schmutzler
> Sent: Mittwoch, 13. November 2019 00:57
> To: openwrt-devel@lists.openwrt.org
> Cc: Sungbo Eo <mans0n@gorani.run>
> Subject: [OpenWrt-Devel] [PATCH] base-files: config_generate: split
> macaddr with multiple ifaces
> 

base-files package version bump got eaten up by the latest rebase. I will add it for v2/before merge.
(I will also add the version bump to my other pending patches ...)

Adrian

Patch
diff mbox series

diff --git a/package/base-files/files/bin/config_generate b/package/base-files/files/bin/config_generate
index 3ca035ca8b..874ce289cf 100755
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -85,12 +85,27 @@  generate_network() {
 		set network.$1.proto='none'
 	EOF
 
-	[ -n "$macaddr" ] && uci -q batch <<-EOF
-		delete network.$1_dev
-		set network.$1_dev='device'
-		set network.$1_dev.name='$ifname'
-		set network.$1_dev.macaddr='$macaddr'
-	EOF
+	[ -n "$macaddr" ] && case "$ifname" in
+	*\ *)
+		uci -q delete network.$1_dev
+		for name in $ifname; do
+			uci -q batch <<-EOF
+				delete network.${name/./_}_dev
+				set network.${name/./_}_dev='device'
+				set network.${name/./_}_dev.name='$name'
+				set network.${name/./_}_dev.macaddr='$macaddr'
+			EOF
+		done
+		;;
+	*)
+		uci -q batch <<-EOF
+			delete network.$1_dev
+			set network.$1_dev='device'
+			set network.$1_dev.name='$ifname'
+			set network.$1_dev.macaddr='$macaddr'
+		EOF
+		;;
+	esac
 
 	case "$protocol" in
 		static)