Skip to content

Commit

Permalink
Avoid MAC duplication when creating vlan
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Oct 28, 2014
1 parent 706c78f commit 8fb50f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
16 changes: 0 additions & 16 deletions packages/lime-proto-batadv/src/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,9 @@ function batadv.setup_interface(ifname, args)
local owrtInterfaceName, _, owrtDeviceName = network.createVlanIface(ifname, vlanId, nameSuffix, vlanProto)

local uci = libuci:cursor()

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

-- 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 [Fix issue 32]

uci:set("network", owrtInterfaceName, "proto", "batadv")
uci:set("network", owrtInterfaceName, "mesh", "bat0")

uci:save("network")
end

Expand Down
16 changes: 13 additions & 3 deletions packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,30 @@ function network.createVlanIface(linuxBaseIfname, vid, openwrtNameSuffix, vlanPr
owrtDeviceName = owrtDeviceName:gsub("[^%w_]", "_") -- sanitize uci section name
owrtInterfaceName = owrtInterfaceName:gsub("[^%w_]", "_") -- sanitize uci section name

local vlanId = vid
--! Do not use . as separator as this will make netifd create an 802.1q interface anyway
--! and sanitize linuxBaseIfName because it can contain dots as well (i.e. switch ports)
local linux802adIfName = linuxBaseIfname:gsub("[^%w_]", "_")..network.protoVlanSeparator..vlanId
local linux802adIfName = linuxBaseIfname:gsub("[^%w_]", "_")..network.protoVlanSeparator..vid
local ifname = linuxBaseIfname
if string.sub(linuxBaseIfname, 1, 4) == "wlan" then ifname = "@"..network.limeIfNamePrefix..linuxBaseIfname end

-- BEGIN [Fix issue 32,39]
local vlanMacAddr = nil
if linuxBaseIfname:match("^wlan%d+") then
vlanMacAddr = wireless.get_phy_mac("phy"..linuxBaseIfname:match("%d+"))
else
vlanMacAddr = network.get_mac(linuxBaseIfname)
end
vlanMacAddr[1] = utils.pseudoEUI8(linuxBaseIfname..vid..openwrtNameSuffix..vlanProtocol)
--- END [Fix issue 32,39]

local uci = libuci:cursor()

uci:set("network", owrtDeviceName, "device")
uci:set("network", owrtDeviceName, "type", vlanProtocol)
uci:set("network", owrtDeviceName, "name", linux802adIfName)
uci:set("network", owrtDeviceName, "ifname", ifname)
uci:set("network", owrtDeviceName, "vid", vlanId)
uci:set("network", owrtDeviceName, "vid", vid)
uci:set("network", owrtDeviceName, "macaddr", table.concat(vlanMacAddr, ":"))

uci:set("network", owrtInterfaceName, "interface")
uci:set("network", owrtInterfaceName, "ifname", linux802adIfName)
Expand Down

0 comments on commit 8fb50f7

Please sign in to comment.