Merge pull request #2058 from freifunk-gluon/board-json-ifnames

Use LAN/WAN interfaces from board.json, add lantiq special case
This commit is contained in:
Andreas Ziegler 2020-08-09 00:37:40 +02:00 committed by GitHub
commit 6346d20b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,9 +11,12 @@ end
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local site = require 'gluon.site' local site = require 'gluon.site'
local json = require 'jsonc'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local unistd = require 'posix.unistd' local unistd = require 'posix.unistd'
local board_data = json.load('/etc/board.json')
local network_data = (board_data or {}).network
local function iface_exists(ifaces) local function iface_exists(ifaces)
if not ifaces then return nil end if not ifaces then return nil end
@ -26,8 +29,8 @@ local function iface_exists(ifaces)
end end
local lan_ifname = iface_exists(uci:get('network', 'lan', 'ifname')) local lan_ifname = iface_exists((network_data.lan or {}).ifname)
local wan_ifname = iface_exists(uci:get('network', 'wan', 'ifname')) local wan_ifname = iface_exists((network_data.wan or {}).ifname)
if platform.match('ar71xx', 'generic', { if platform.match('ar71xx', 'generic', {
'cpe210', 'cpe210',
@ -42,6 +45,16 @@ if platform.match('ar71xx', 'generic', {
'unifiac-pro', 'unifiac-pro',
}) then }) then
lan_ifname, wan_ifname = wan_ifname, lan_ifname lan_ifname, wan_ifname = wan_ifname, lan_ifname
elseif platform.match('lantiq') then
local switch_data = board_data.switch or {}
local switch0_data = switch_data.switch0 or {}
local roles_data = switch0_data.roles or {}
for _, role_data in ipairs(roles_data) do
if role_data.role == 'wan' then
wan_ifname = iface_exists(role_data.device)
break
end
end
end end
if wan_ifname and lan_ifname then if wan_ifname and lan_ifname then