From 69ba8e3cfe2feda393bca400d75d8bd08a120cf3 Mon Sep 17 00:00:00 2001
From: David Bauer <mail@david-bauer.net>
Date: Sat, 26 Jun 2021 19:36:59 +0200
Subject: [PATCH] gluon-core: fix handling of multi-port interfaces

Multi-port interfaces are stored in the network config as an array using
the ports key.
---
 .../luasrc/lib/gluon/upgrade/020-interfaces   | 26 ++++++++++++++++---
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces b/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces
index 41e2150bc..2947150d1 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces
@@ -20,17 +20,35 @@ local network_data = (board_data or {}).network
 
 local function iface_exists(ifaces)
 	if not ifaces then return nil end
+	local ifnames = table.concat(ifaces, ' ')
 
-	for iface in ifaces:gmatch('%S+') do
+	for _, iface in ipairs(ifaces) do
 		if unistd.access('/sys/class/net/' .. iface:gsub('%..*$', '')) then
-			return ifaces
+			return ifnames
 		end
 	end
 end
 
+local lan_data = network_data.lan or {}
+local wan_data = network_data.wan or {}
 
-local lan_ifname = iface_exists((network_data.lan or {}).device)
-local wan_ifname = iface_exists((network_data.wan or {}).device)
+local lan_interfaces = lan_data.ports
+local wan_interfaces = wan_data.ports
+
+-- In case we have a single port for either WAN or LAN,
+-- add it to the respective empty table, as devices and
+-- ports is XOR in board.json
+
+if lan_data.device ~= nil then
+	lan_interfaces = {lan_data.device}
+end
+
+if wan_data.device ~= nil then
+	wan_interfaces = {wan_data.device}
+end
+
+local lan_ifname = iface_exists(lan_interfaces)
+local wan_ifname = iface_exists(wan_interfaces)
 
 if platform.match('ar71xx', 'generic', {
 	'cpe210',
-- 
GitLab