Skip to content

Commit

Permalink
Fix bug #32
Browse files Browse the repository at this point in the history
Conflicts:
	packages/lime-proto-batadv/src/batadv.lua
	packages/lime-system/files/usr/lib/lua/lime/utils.lua
  • Loading branch information
G10h4ck committed Oct 28, 2014
1 parent 89de801 commit 66bde2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/lime-proto-batadv/src/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ function batadv.setup_interface(ifname, args)

uci:set("network", owrtDeviceName, "mtu", mtu)

-- BEGIN
-- Workaround to http://www.libre-mesh.org/issues/32
-- We create a new macaddress for ethernet vlan interface
-- We change the 7nt bit to 1 to give it locally administered meaning
-- Then use it as the new mac address prefix "02"
if ifname:match("^eth") then
local vlanMacAddr = network.get_mac(ifname:gsub("%..*", ""))
vlanMacAddr[1] = "02"
-- BEGIN [Fix issue 32]
local vlanMacAddr = nil
if ifname:match("^eth%d+") then
vlanMacAddr = network.get_mac(ifname)
elseif ifname:match("^wlan%d+") then
vlanMacAddr = wireless.get_phy_mac("phy"..ifname:match("%d+"))
end
if vlanMacAddr then
vlanMacAddr[1] = utils.pseudoEUI8(ifname..vlanId..nameSuffix..vlanProto)
uci:set("network", owrtDeviceName, "macaddr", table.concat(vlanMacAddr, ":"))
end
--- END
--- END [Fix issue 32]

uci:set("network", owrtInterfaceName, "proto", "batadv")
uci:set("network", owrtInterfaceName, "mesh", "bat0")
Expand Down
16 changes: 16 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@
utils = {}

local config = require("lime.config")
local bitop = require("bit")

function utils.split(string, sep)
local ret = {}
for token in string.gmatch(string, "[^"..sep.."]+") do table.insert(ret, token) end
return ret
end

function utils.stringStarts(string, start)
return (string.sub(string, 1, string.len(start)) == start)
end

function utils.stringEnds(string, _end)
return ( _end == '' or string.sub( string, -string.len(_end) ) == _end)
end

function utils.pseudoEUI8(seed)
local sum = math.random(2,257)
if type(seed) == "string" then for c in seed:gmatch(".") do sum = sum + c:byte() end
elseif type(seed) == "number" then sum = sum + seed end
return utils.hex(bitop.bor( bitop.band( sum, 254 ), 2 ))
end

function utils.hex(x)
return string.format("%02x", x)
end
Expand Down

0 comments on commit 66bde2a

Please sign in to comment.