gluon-core: increase number of available MACs

This commit is contained in:
David Bauer 2019-03-08 00:25:21 +01:00
parent 851dfc6a93
commit 4e6cad050c

View File

@ -178,13 +178,16 @@ end
-- 5: mesh1
-- 6: ibss1
-- 7: wan_radio1 (private WLAN); mesh VPN
-- 8: client2
-- 9: mesh2
-- A: ibss2
-- B: wan_radio2
function M.generate_mac(i)
if i > 7 or i < 0 then return nil end -- max allowed id (0b111)
local hashed = string.sub(hash.md5(sysconfig.primary_mac), 0, 12)
local m1, m2, m3, m4, m5, m6 = string.match(hashed, '(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)')
m1 = tonumber(m1, 16)
m5 = tonumber(m5, 16)
m6 = tonumber(m6, 16)
m1 = bit.bor(m1, 0x02) -- set locally administered bit
@ -197,6 +200,9 @@ function M.generate_mac(i)
m6 = bit.band(m6, 0xF8) -- zero the last three bits (space needed for counting)
m6 = m6 + i -- add virtual interface id
local overflow = math.floor(i/8)
m5 = math.fmod(m5 + overflow, 256)
return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
end