Browse Source

br-client: convert option ifname to list ifname

Convert option ifname in br-client to use a list instead. This
simplifies adding and remove interfaces:

uci:add_to_set("network", "client", "ifname", "eth0")
uci:remove_from_set("network", "client", "ifname", "eth0")

An option ifname will be automatically converted to a list when
performing an upgrade.

Packages affected: gluon-mesh-batman-adv-core, gluon-luci-portconfig
Nils Schneider 8 years ago
parent
commit
34752c7e0b

+ 2 - 2
package/gluon-luci-portconfig/files/usr/lib/lua/luci/model/cbi/admin/portconfig.lua

@@ -122,9 +122,9 @@ function f.handle(self, state, data)
       uci:set("network", "mesh_lan", "auto", data.mesh_lan)
 
       if data.mesh_lan == '1' then
-        uci:set("network", "client", "ifname", "bat0")
+        uci:remove_from_set("network", "client", "ifname", sysconfig.lan_ifname)
       else
-        uci:set("network", "client", "ifname", sysconfig.lan_ifname .. " bat0")
+        uci:add_to_set("network", "client", "ifname", sysconfig.lan_ifname)
       end
     end
 

+ 18 - 12
package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/310-gluon-mesh-batman-adv-core-mesh

@@ -20,22 +20,28 @@ uci:commit('batman-adv')
 
 
 if not uci:get('network', 'client') then
-  local ifname
+  uci:section('network', 'interface', 'client',
+    {
+      type = 'bridge',
+      proto = 'dhcpv6',
+      reqprefix = 'no',
+    }
+  )
+
+  uci:add_to_set('network', 'client', 'ifname', 'bat0')
 
   if sysconfig.lan_ifname and not site.mesh_on_lan then
-    ifname = sysconfig.lan_ifname .. ' bat0'
-  else
-    ifname = 'bat0'
+    uci:add_to_set('network', 'client', 'ifname', sysconfig.lan_ifname)
   end
+end
 
-  uci:section('network', 'interface', 'client',
-	      {
-		ifname = ifname,
-		type = 'bridge',
-		proto = 'dhcpv6',
-		reqprefix = 'no',
-	      }
-  )
+local ifname = uci:get('network', 'client', 'ifname')
+
+if type(ifname) == 'string' then
+  uci:delete('network', 'client', 'ifname')
+  for x in ifname:gmatch("[^%s]+") do
+    uci:add_to_set('network', 'client', 'ifname', x)
+  end
 end
 
 uci:set('network', 'client', 'igmp_snooping', 0)

+ 2 - 2
package/gluon-mesh-batman-adv-core/files/lib/gluon/upgrade/340-gluon-mesh-batman-adv-core-mesh-on-lan

@@ -11,9 +11,9 @@ if sysconfig.lan_ifname and not uci:get('network', 'mesh_lan') then
   local enable = site.mesh_on_lan
 
   if enable then
-    local interfaces = uci:get('network', 'client', 'ifname')
+    local interfaces = uci:get_list('network', 'client', 'ifname')
 
-    if interfaces and lutil.contains(interfaces:split(' '), sysconfig.lan_ifname) then
+    if interfaces and lutil.contains(interfaces, sysconfig.lan_ifname) then
       enable = false
     end
   end