gluon-core: primary-mac: add fallback to netdev address to interface()

In most cases, board.json does not contain any MAC addresses; in this
case, the default MAC address of the underlying interface is to be used.
This commit is contained in:
Matthias Schiffer 2020-05-06 23:08:54 +02:00
parent 2250665d18
commit 02e4a13069
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C

View File

@ -26,6 +26,10 @@ local function get_netdev_addr(ifname)
return read('/sys/class/net/%s/address', ifname)
end
local function strip_vlan(ifname)
return (ifname:gsub('%..*', ''))
end
local function netdev(ifname)
return function()
@ -44,6 +48,8 @@ local function interface(name)
local ifdata = network_data[name] or {}
if ifdata.macaddr then
return ifdata.macaddr
elseif ifdata.ifname then
return get_netdev_addr(strip_vlan(ifdata.ifname))
end
end
end