Skip to content

Commit

Permalink
avoid netifd misunderstoonding and vlan code duplication creating net…
Browse files Browse the repository at this point in the history
…work.createVlanIface
  • Loading branch information
G10h4ck authored and frank95 committed Aug 9, 2014
1 parent 92b731d commit 8c7ff2b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
23 changes: 4 additions & 19 deletions packages/lime-proto-batadv/src/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,14 @@ function batadv.setup_interface(ifname, args)
if ifname:match("^wlan%d_ap") then return end
if not args[2] then return end

local owrtDeviceName = network.limeIfNamePrefix..ifname.."_batadv_dev"
local owrtInterfaceName = network.limeIfNamePrefix..ifname.."_batadv_if"
local linuxBaseIfname = ifname
local vlanId = args[2]
local linux802adIfName = ifname.."."..vlanId

local interface = network.limeIfNamePrefix..ifname.."_batadv"
local owrtFullIfname = ifname
local owrtInterfaceName, _, _ = network.createVlanIface(ifname, args[2], "_batadv")
local mtu = 1532
if linuxBaseIfname:match("^eth") then mtu = 1496 end
if ifname:match("^eth") then mtu = 1496 end

local uci = libuci:cursor()

uci:set("network", owrtDeviceName, "device")
uci:set("network", owrtDeviceName, "type", "8021ad")
uci:set("network", owrtDeviceName, "name", linux802adIfName)
uci:set("network", owrtDeviceName, "ifname", linuxBaseIfname)
uci:set("network", owrtDeviceName, "vid", vlanId)

uci:set("network", owrtInterfaceName, "interface")
uci:set("network", owrtInterfaceName, "proto", "batadv")
uci:set("network", owrtInterfaceName, "mesh", "bat0")
uci:set("network", owrtInterfaceName, "ifname", linux802adIfName)
uci:set("network", owrtInterfaceName, "mtu", mtu)

-- BEGIN
Expand All @@ -41,8 +26,8 @@ function batadv.setup_interface(ifname, args)
-- We use 000049 Unicast MAC prefix reserved by Apricot Ltd
-- We change the 7nt bit to 1 to give it locally administered meaning
-- Then use it as the new mac address prefix "02:00:49"
if linuxBaseIfname:match("^eth") then
local vlanMacAddr = network.get_mac(linuxBaseIfname)
if ifname:match("^eth") then
local vlanMacAddr = network.get_mac(ifname)
vlanMacAddr[1] = "02"
vlanMacAddr[2] = "00"
vlanMacAddr[3] = "49"
Expand Down
19 changes: 1 addition & 18 deletions packages/lime-proto-bmx6/src/bmx6.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,14 @@ function bmx6.setup_interface(ifname, args)
if ifname:match("^wlan%d_ap") then return end
if not args[2] then return end

local owrtDeviceName = network.limeIfNamePrefix..ifname.."_bmx6_dev"
local owrtInterfaceName = network.limeIfNamePrefix..ifname.."_bmx6_if"
local linuxBaseIfname = ifname
local vlanId = args[2]
local linux802adIfName = ifname.."."..vlanId
local owrtInterfaceName, linux802adIfName, _ = network.createVlanIface(ifname, args[2], "_bmx6")

local uci = libuci:cursor()

uci:set("network", owrtDeviceName, "device")
uci:set("network", owrtDeviceName, "type", "8021ad")
uci:set("network", owrtDeviceName, "name", linux802adIfName)
uci:set("network", owrtDeviceName, "ifname", linuxBaseIfname)
uci:set("network", owrtDeviceName, "vid", vlanId)

uci:set("network", owrtInterfaceName, "interface")
uci:set("network", owrtInterfaceName, "ifname", linux802adIfName)
uci:set("network", owrtInterfaceName, "proto", "none")
uci:set("network", owrtInterfaceName, "auto", "1")
uci:set("network", owrtInterfaceName, "mtu", "1398")

uci:save("network")

uci:set("bmx6", owrtInterfaceName, "dev")
uci:set("bmx6", owrtInterfaceName, "dev", linux802adIfName)

uci:save("bmx6")
end

Expand Down
29 changes: 29 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,33 @@ function network.configure()
end
end

function network.createVlanIface(linuxBaseIfname, vid, openwrtNameSuffix, vlanProtocol)

vlanProtocol = vlanProtocol or "8021ad"
openwrtNameSuffix = openwrtNameSuffix or ""

local owrtDeviceName = network.limeIfNamePrefix..linuxBaseIfname..openwrtNameSuffix.."_dev"
local owrtInterfaceName = network.limeIfNamePrefix..linuxBaseIfname..openwrtNameSuffix.."_if"
local vlanId = vid
--! Do not use . as separator as this will make netifd create an 802.1q interface anyway
local linux802adIfName = linuxBaseIfname.."-"..vlanId

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", linuxBaseIfname)
uci:set("network", owrtDeviceName, "vid", vlanId)

uci:set("network", owrtInterfaceName, "interface")
uci:set("network", owrtInterfaceName, "ifname", linux802adIfName)
uci:set("network", owrtInterfaceName, "proto", "none")
uci:set("network", owrtInterfaceName, "auto", "1")

uci:save("network")

return owrtInterfaceName, linux802adIfName, owrtDeviceName
end

return network

0 comments on commit 8c7ff2b

Please sign in to comment.