gluon-core: primary-mac: cleanup
- Replace misnamed, closure-returning sysfs() to a reusable read() function - Rename eth() to netdev(), pass full interface name - Rename board() to interface() - Split reuable get_netdev_addr() out of netdev()
This commit is contained in:
parent
0c5b5373bb
commit
2250665d18
@ -15,27 +15,33 @@ local util = require 'gluon.util'
|
|||||||
local board_data = json.load('/etc/board.json')
|
local board_data = json.load('/etc/board.json')
|
||||||
local network_data = (board_data or {}).network
|
local network_data = (board_data or {}).network
|
||||||
|
|
||||||
local function sysfs(...)
|
local function read(...)
|
||||||
local path = string.format(...)
|
local addr = util.readfile(string.format(...))
|
||||||
return function()
|
if addr then
|
||||||
local addr = util.readfile(path)
|
return util.trim(addr)
|
||||||
if addr then
|
|
||||||
return util.trim(addr)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function eth(index)
|
local function get_netdev_addr(ifname)
|
||||||
return sysfs('/sys/class/net/eth%d/address', index)
|
return read('/sys/class/net/%s/address', ifname)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function netdev(ifname)
|
||||||
|
return function()
|
||||||
|
return get_netdev_addr(ifname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function phy(index)
|
local function phy(index)
|
||||||
return sysfs('/sys/class/ieee80211/phy%d/macaddress', index)
|
return function()
|
||||||
|
return read('/sys/class/ieee80211/phy%d/macaddress', index)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function board(iface)
|
local function interface(name)
|
||||||
return function()
|
return function()
|
||||||
local ifdata = network_data[iface] or {}
|
local ifdata = network_data[name] or {}
|
||||||
if ifdata.macaddr then
|
if ifdata.macaddr then
|
||||||
return ifdata.macaddr
|
return ifdata.macaddr
|
||||||
end
|
end
|
||||||
@ -45,7 +51,7 @@ end
|
|||||||
|
|
||||||
-- Entries are matched in the order they are listed
|
-- Entries are matched in the order they are listed
|
||||||
local primary_addrs = {
|
local primary_addrs = {
|
||||||
{eth(0), {
|
{netdev('eth0'), {
|
||||||
{'x86'},
|
{'x86'},
|
||||||
{'brcm2708'},
|
{'brcm2708'},
|
||||||
{'ar71xx', 'generic', {
|
{'ar71xx', 'generic', {
|
||||||
@ -99,7 +105,7 @@ local primary_addrs = {
|
|||||||
'miwifi-mini', 'tplink,c2-v1', 'c20-v1', 'c20i', 'c50',
|
'miwifi-mini', 'tplink,c2-v1', 'c20-v1', 'c20i', 'c50',
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
{eth(1), {
|
{netdev('eth0'), {
|
||||||
{'ar71xx', 'generic', {
|
{'ar71xx', 'generic', {
|
||||||
'archer-c5',
|
'archer-c5',
|
||||||
'archer-c58-v1',
|
'archer-c58-v1',
|
||||||
@ -124,7 +130,7 @@ local primary_addrs = {
|
|||||||
'dir-860l-b1',
|
'dir-860l-b1',
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
{board('lan'), {
|
{interface('lan'), {
|
||||||
{'lantiq', 'xway', {
|
{'lantiq', 'xway', {
|
||||||
'netgear,dgn3500b',
|
'netgear,dgn3500b',
|
||||||
}},
|
}},
|
||||||
@ -139,7 +145,7 @@ local primary_addrs = {
|
|||||||
{}, -- matches everything
|
{}, -- matches everything
|
||||||
}},
|
}},
|
||||||
-- eth0 fallback when phy0 does not exist
|
-- eth0 fallback when phy0 does not exist
|
||||||
{eth(0), {
|
{netdev('eth0'), {
|
||||||
{}, -- matches everything
|
{}, -- matches everything
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user