gluon-core: primary_mac is now hashed before the VIF macs are generated.
This commit is contained in:
parent
6058736100
commit
d3c98b7ab6
@ -12,7 +12,7 @@ define Package/gluon-core
|
|||||||
SECTION:=gluon
|
SECTION:=gluon
|
||||||
CATEGORY:=Gluon
|
CATEGORY:=Gluon
|
||||||
TITLE:=Base files of Gluon
|
TITLE:=Base files of Gluon
|
||||||
DEPENDS:=+gluon-site +libgluonutil +lua-platform-info +luci-base +luci-lib-jsonc +odhcp6c +firewall
|
DEPENDS:=+gluon-site +libgluonutil +lua-platform-info +lua-hash +luci-base +luci-lib-jsonc +odhcp6c +firewall
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,9 +10,8 @@ end
|
|||||||
|
|
||||||
local platform = require 'gluon.platform'
|
local platform = require 'gluon.platform'
|
||||||
|
|
||||||
local sys = require 'luci.sys'
|
local fs = require 'nixio.fs'
|
||||||
local util = require 'luci.util'
|
local util = require 'luci.util'
|
||||||
local nixio = require 'nixio'
|
|
||||||
|
|
||||||
|
|
||||||
local try_files = {
|
local try_files = {
|
||||||
@ -33,15 +32,9 @@ end
|
|||||||
|
|
||||||
|
|
||||||
for _, file in ipairs(try_files) do
|
for _, file in ipairs(try_files) do
|
||||||
local addr = nixio.fs.readfile(file)
|
local addr = fs.readfile(file)
|
||||||
|
|
||||||
if addr then
|
if addr then
|
||||||
if platform.match('ramips', 'rt305x', {'vocore'}) then
|
|
||||||
-- Hash the mac address since we need to iterate in the last bits for
|
|
||||||
-- the VIF. (This chip uses a hardware mac filter)
|
|
||||||
addr = util.hash_mac(addr)
|
|
||||||
end
|
|
||||||
|
|
||||||
sysconfig.primary_mac = util.trim(addr)
|
sysconfig.primary_mac = util.trim(addr)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -30,6 +30,7 @@ local ipairs = ipairs
|
|||||||
local table = table
|
local table = table
|
||||||
|
|
||||||
local nixio = require 'nixio'
|
local nixio = require 'nixio'
|
||||||
|
local hash = require 'hash'
|
||||||
local sysconfig = require 'gluon.sysconfig'
|
local sysconfig = require 'gluon.sysconfig'
|
||||||
local platform = require 'gluon.platform'
|
local platform = require 'gluon.platform'
|
||||||
local site = require 'gluon.site_config'
|
local site = require 'gluon.site_config'
|
||||||
@ -82,36 +83,25 @@ end
|
|||||||
-- (4, 0): mesh VPN
|
-- (4, 0): mesh VPN
|
||||||
-- (5, n): mesh interface for n'th radio (802.11s)
|
-- (5, n): mesh interface for n'th radio (802.11s)
|
||||||
function generate_mac(f, i)
|
function generate_mac(f, i)
|
||||||
local m1, m2, m3, m4, m5, m6 = string.match(sysconfig.primary_mac, '(%x%x):(%x%x):(%x%x):(%x%x):(%x%x):(%x%x)')
|
local hashed = string.sub(hash.md5(sysconfig.primary_mac), 0, 12)
|
||||||
m1 = nixio.bit.bor(tonumber(m1, 16), 0x02)
|
local m1, m2, m3, m4, m5, m6 = string.match(hashed, '(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)')
|
||||||
m2 = tonumber(m2, 16)
|
|
||||||
m3 = (tonumber(m3, 16)+i) % 0x100
|
m1 = tonumber(m1, 16)
|
||||||
|
m3 = tonumber(m3, 16)
|
||||||
m6 = tonumber(m6, 16)
|
m6 = tonumber(m6, 16)
|
||||||
|
|
||||||
if platform.match('ramips', 'rt305x', {'vocore'}) then
|
m1 = nixio.bit.bor(m1, 0x02) -- set locally administered bit
|
||||||
-- We need to iterate in the last byte, since the vocore does
|
m1 = nixio.bit.band(m1, 0xFE) -- unset the multicast bit
|
||||||
-- hardware mac filtering on the wlan interface.
|
m3 = (m3+i) % 0x100 -- add interface identifier
|
||||||
m6 = (m6+f) % 0x100
|
|
||||||
else
|
|
||||||
m2 = (m2+f) % 0x100
|
|
||||||
end
|
|
||||||
|
|
||||||
return string.format('%02x:%02x:%02x:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
|
-- It's necessary that the last bits of the mac do
|
||||||
end
|
-- not vary on a single interface, since some chips are using
|
||||||
|
|
||||||
-- Generates a mac hashed from the original
|
|
||||||
-- The last three bits will be zeroed, since these bits are
|
|
||||||
-- iterated on some devices for the VIF.
|
|
||||||
function hash_mac(original)
|
|
||||||
local hashed = string.sub(sys.exec('echo -n "' .. original .. '" | sha512sum'),0,12)
|
|
||||||
local m1, m2, m3, m4, m5, m6 = string.match(hashed, '(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)')
|
|
||||||
local m1 = nixio.bit.bor(tonumber(m1, 16), 0x02)
|
|
||||||
local m6 = nixio.bit.band(tonumber(m6, 16), 0xF8) -- zero the last three bits
|
|
||||||
-- It's necessary that the upper bits of the mac do
|
|
||||||
-- not vary on a single interface, since they are using
|
|
||||||
-- a hardware mac filter. (e.g 'ramips-rt305x')
|
-- a hardware mac filter. (e.g 'ramips-rt305x')
|
||||||
|
|
||||||
return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
|
m6 = nixio.bit.band(m6, 0xF8) -- zero the last three bits (space needed for counting)
|
||||||
|
m6 = (m6+f) % 0x100 -- add virtual interface id
|
||||||
|
|
||||||
|
return string.format('%02x:%s:%02x:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Iterate over all radios defined in UCI calling
|
-- Iterate over all radios defined in UCI calling
|
||||||
|
Loading…
Reference in New Issue
Block a user