gluon-core: allow subindexing sysconfig references for interface roles
This allows to specify something like "/lan[1]" as interface role: root@platzhalter-525400123457:/# cat /lib/gluon/core/sysconfig/lan_ifname eth0 eth2 root@platzhalter-525400123457:/# cat /etc/config/gluon ... config interface 'iface_lan_1' option name '/lan[1]' # this references eth2 list role 'client' ...
This commit is contained in:
		
							parent
							
								
									c982e7e0ff
								
							
						
					
					
						commit
						cbe49cb9a4
					
				@ -147,13 +147,26 @@ function M.get_role_interfaces(uci, role, exclusive)
 | 
			
		||||
	local ret = {}
 | 
			
		||||
 | 
			
		||||
	local function add(name)
 | 
			
		||||
		local subindex = nil
 | 
			
		||||
 | 
			
		||||
		-- Interface names with a / prefix refer to sysconfig interfaces
 | 
			
		||||
		-- (lan_ifname/wan_ifname/single_ifname)
 | 
			
		||||
		if string.sub(name, 1, 1) == '/' then
 | 
			
		||||
			subindex = tonumber(string.match(name, "%[(%d+)%]"))
 | 
			
		||||
			if subindex then
 | 
			
		||||
				-- handle something like "/lan[10]":
 | 
			
		||||
				name = string.gsub(name, "%[%d+%]", "")
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			name = sysconfig[string.sub(name, 2) .. '_ifname'] or ''
 | 
			
		||||
		end
 | 
			
		||||
		local i = 0
 | 
			
		||||
		for iface in string.gmatch(name, '%S+') do
 | 
			
		||||
			M.add_to_set(ret, iface)
 | 
			
		||||
			if not subindex or subindex == i then
 | 
			
		||||
				M.add_to_set(ret, iface)
 | 
			
		||||
			end
 | 
			
		||||
 | 
			
		||||
			i = i + 1
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user