gluon-core/generate_mac: forbid negative id and improve readability.

This commit is contained in:
lemoer 2016-04-24 19:32:40 +02:00
parent cb6dc47299
commit 755bd82fc5

View File

@ -84,6 +84,8 @@ end
-- 6: mesh-on-lan
-- 7: unused
function 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)')
@ -97,8 +99,6 @@ function generate_mac(i)
-- not vary on a single hardware interface, since some chips are using
-- a hardware mac filter. (e.g 'ramips-rt305x')
if i > 7 then return nil end -- max allowed id (0b111)
m6 = nixio.bit.band(m6, 0xF8) -- zero the last three bits (space needed for counting)
m6 = m6 + i -- add virtual interface id