From 02e4a130698e89f7d6849cc9c206ce65663de1a7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 6 May 2020 23:08:54 +0200 Subject: [PATCH] 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. --- package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac index 56a383a8..2974a29d 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/010-primary-mac @@ -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