From 3ab880352eb0526f3cc1e91a0ed0b68c61e9f9dc Mon Sep 17 00:00:00 2001 From: lemoer Date: Thu, 19 May 2022 22:34:50 +0200 Subject: [PATCH] gluon-core: create interfaces for each "port" in /etc/config/gluon This commit enables (migration-safe) role assignment for individual "lan" and "wan" interfaces. This is helpful especially on devices with multiple "lan" or "wan" interfaces (as they appear for devices with DSA support). For interfaces in /lib/gluon/lan_ifname, we now create individual entries in /etc/config/gluon using the "/lan[0]", "/lan[1]", ... syntax (introduced in the last commit). Before this commit, all interfaces were referenced in a single interface "/lan" in /etc/config/gluon. The same is done for wan_ifname and single_ifname. Migration strategy: If new interfaces show up during gluon-reconfigure, the assigned roles of prior existing interfaces in the same category will be applied to the new interface. --- .../lib/gluon/upgrade/021-interface-roles | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/021-interface-roles b/package/gluon-core/luasrc/lib/gluon/upgrade/021-interface-roles index 5d27fb70..a551127b 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/021-interface-roles +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/021-interface-roles @@ -52,14 +52,35 @@ local interfaces = { single = sysconfig.single_ifname, } -for iface in pairs(interfaces) do - local section_name = 'iface_' .. iface - if not uci:get('gluon', section_name) then - uci:section('gluon', 'interface', section_name, { - -- / prefix refers to sysconfig ifnames - name = '/' .. iface, - role = roles[iface], - }) +for iface, ifnames in pairs(interfaces) do + local default_roles = roles[iface] + + -- migration from intermediate gluon master + local section_name_old = 'iface_' .. iface + if uci:get('gluon', section_name_old) then + default_roles = uci:get('gluon', section_name_old, 'role') + uci:delete('gluon', section_name_old) + end + + local interface_count = 1 + if type(ifnames) == 'table' then + interface_count = #ifnames + end + + for i = 0, interface_count-1 do + local section_name = 'iface_' .. iface .. '_' .. tostring(i) + + if not uci:get('gluon', section_name) then + uci:section('gluon', 'interface', section_name, { + -- / prefix refers to sysconfig ifnames + name = '/' .. iface .. '[' .. tostring(i) .. ']', + role = default_roles, + }) + else + -- In case we have existing interfaces in that category, we want to + -- use their roles as default for other new interfaces in that category. + default_roles = uci:get('gluon', section_name, 'role') + end end end