Skip to content

Commit

Permalink
Fix bug #32
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Oct 27, 2014
1 parent 54ca776 commit 95e1306
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 5 additions & 9 deletions packages/lime-proto-batadv/src/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,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"
-- BEGIN [Fix issue 32]
local vlanMacAddr = nil
if ifname:match("^eth") then
if ifname:match("^eth%d+") then
vlanMacAddr = network.get_mac(ifname)
elseif ifname:match("^wlan%d+"..wireless.ifnameModeSeparator.."ap") then
elseif ifname:match("^wlan%d+") then
vlanMacAddr = wireless.get_phy_mac("phy"..ifname:match("%d+"))
end
if vlanMacAddr then
vlanMacAddr[1] = "02"
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
7 changes: 7 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,6 +3,7 @@
utils = {}

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

function utils.split(string, sep)
local ret = {}
Expand All @@ -18,6 +19,12 @@ 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)
Expand Down

0 comments on commit 95e1306

Please sign in to comment.