Skip to content

Commit

Permalink
Enforce proto.configure is onetime
Browse files Browse the repository at this point in the history
  • Loading branch information
G10h4ck committed Jan 15, 2015
1 parent 03202c8 commit 94bea82
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 86 deletions.
46 changes: 23 additions & 23 deletions packages/lime-proto-batadv/src/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ local utils = require("lime.utils")

batadv = {}

batadv.configured = false

function batadv.configure(args)
if batadv.configured then return end
batadv.configured = true

if not fs.lstat("/etc/config/batman-adv") then fs.writefile("/etc/config/batman-adv", "") end

local uci = libuci:cursor()
uci:set("batman-adv", "bat0", "mesh")
uci:set("batman-adv", "bat0", "bridge_loop_avoidance", "1")
uci:set("batman-adv", "bat0", "multicast_mode", "0")

-- if anygw enabled disable DAT that doesn't play well with it
for _,proto in pairs(config.get("network", "protocols")) do
if proto == "anygw" then uci:set("batman-adv", "bat0", "distributed_arp_table", "0") end
end

lan.setup_interface("bat0", nil)

uci:save("batman-adv")
end

function batadv.setup_interface(ifname, args)
if ifname:match("^wlan%d+_ap") then return end
local vlanId = args[2] or "%N1"
Expand All @@ -29,28 +52,5 @@ function batadv.setup_interface(ifname, args)
uci:save("network")
end

function batadv.clean()
if not fs.lstat("/etc/config/batman-adv") then fs.writefile("/etc/config/batman-adv", "") end
end


function batadv.configure(args)
batadv.clean()

local uci = libuci:cursor()
uci:set("batman-adv", "bat0", "mesh")
uci:set("batman-adv", "bat0", "bridge_loop_avoidance", "1")
uci:set("batman-adv", "bat0", "multicast_mode", "0")

-- if anygw enabled disable DAT that doesn't play well with it
for _,proto in pairs(config.get("network", "protocols")) do
if proto == "anygw" then uci:set("batman-adv", "bat0", "distributed_arp_table", "0") end
end

lan.setup_interface("bat0", nil)

uci:save("batman-adv")
end


return batadv
74 changes: 36 additions & 38 deletions packages/lime-proto-bmx6/src/bmx6.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,16 @@ local wireless = require("lime.wireless")

bmx6 = {}

function bmx6.setup_interface(ifname, args)
if ifname:match("^wlan%d+_ap") then return end
vlanId = args[2] or 13
vlanProto = args[3] or "8021ad"
nameSuffix = args[4] or "_bmx6"

local owrtInterfaceName, linux802adIfName, owrtDeviceName = network.createVlanIface(ifname, vlanId, nameSuffix, vlanProto)

local uci = libuci:cursor()
uci:set("network", owrtDeviceName, "mtu", "1398")

-- BEGIN [Workaround issue 38]
if ifname:match("^wlan%d+") then
local macAddr = wireless.get_phy_mac("phy"..ifname:match("%d+"))
local vlanIp = { 169, 254, tonumber(macAddr[5], 16), tonumber(macAddr[6], 16) }
uci:set("network", owrtInterfaceName, "proto", "static")
uci:set("network", owrtInterfaceName, "ipaddr", table.concat(vlanIp, "."))
uci:set("network", owrtInterfaceName, "netmask", "255.255.255.255")
end
--- END [Workaround issue 38]

uci:save("network")

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

function bmx6.clean()
print("Clearing bmx6 config...")
fs.writefile("/etc/config/bmx6", "")
local uci = libuci:cursor()
uci:delete("firewall", "bmxtun")
uci:save("firewall")
end
bmx6.configured = false

function bmx6.configure(args)
if bmx6.configured then return end
bmx6.configured = true

bmx6.clean()

local uci = libuci:cursor()
local ipv4, ipv6 = network.primary_address()

local uci = libuci:cursor()
fs.writefile("/etc/config/bmx6", "")

uci:set("bmx6", "general", "bmx6")
uci:set("bmx6", "general", "dbgMuteTimeout", "1000000")
Expand Down Expand Up @@ -123,6 +90,9 @@ function bmx6.configure(args)

uci:save("bmx6")


uci:delete("firewall", "bmxtun")

uci:set("firewall", "bmxtun", "zone")
uci:set("firewall", "bmxtun", "name", "bmxtun")
uci:set("firewall", "bmxtun", "input", "ACCEPT")
Expand All @@ -135,6 +105,34 @@ function bmx6.configure(args)
uci:save("firewall")
end

function bmx6.setup_interface(ifname, args)
if ifname:match("^wlan%d+_ap") then return end
vlanId = args[2] or 13
vlanProto = args[3] or "8021ad"
nameSuffix = args[4] or "_bmx6"

local owrtInterfaceName, linux802adIfName, owrtDeviceName = network.createVlanIface(ifname, vlanId, nameSuffix, vlanProto)

local uci = libuci:cursor()
uci:set("network", owrtDeviceName, "mtu", "1398")

-- BEGIN [Workaround issue 38]
if ifname:match("^wlan%d+") then
local macAddr = wireless.get_phy_mac("phy"..ifname:match("%d+"))
local vlanIp = { 169, 254, tonumber(macAddr[5], 16), tonumber(macAddr[6], 16) }
uci:set("network", owrtInterfaceName, "proto", "static")
uci:set("network", owrtInterfaceName, "ipaddr", table.concat(vlanIp, "."))
uci:set("network", owrtInterfaceName, "netmask", "255.255.255.255")
end
--- END [Workaround issue 38]

uci:save("network")

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

function bmx6.apply()
os.execute("killall bmx6 ; sleep 2 ; killall -9 bmx6")
os.execute("bmx6")
Expand Down
17 changes: 9 additions & 8 deletions packages/lime-proto-eigennet/src/eigennet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ local libuci = require("uci")

eigennet = {}

eigennet.configured = false

function eigennet.configure(args)
if eigennet.configured then return end
eigennet.configured = true

batadv.configure(args)
end

function eigennet.setup_interface(ifname, args)
if ifname:match("^wlan%d+_ap") then return end

Expand Down Expand Up @@ -33,13 +42,5 @@ function eigennet.setup_interface(ifname, args)
end
end

function eigennet.clean()
batadv.clean()
end

function eigennet.configure(args)
batadv.configure(args)
end


return eigennet
17 changes: 9 additions & 8 deletions packages/lime-proto-qmp/src/qmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ local bmx6 = require("lime.proto.bmx6")

qmp = {}

qmp.configured = false

function qmp.configure(args)
if qmp.configured then return
qmp.configured = true

bmx6.configure(args)
end

function qmp.setup_interface(ifname, args)
args[2] = args[2] or 12
args[3] = args[3] or "8021q"
Expand All @@ -12,16 +21,8 @@ function qmp.setup_interface(ifname, args)
bmx6.setup_interface(ifname, args)
end

function qmp.clean()
bmx6.clean()
end

function qmp.configure(args)
bmx6.configure(args)
end

function qmp.apply()
bmx6.apply()
end

return qmp
14 changes: 8 additions & 6 deletions packages/lime-proto-wan/src/wan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ local libuci = require("uci")

wan = {}

function wan.setup_interface(ifname, args)
local uci = libuci:cursor()
uci:set("network", "wan", "ifname", ifname)
uci:save("network")
end
wan.configured = false

function wan.configure(args)
if wan.configured then return end
wan.configured = true

local uci = libuci:cursor()
uci:set("network", "wan", "interface")
uci:set("network", "wan", "proto", "dhcp")
uci:save("network")
end

function wan.apply()
function wan.setup_interface(ifname, args)
local uci = libuci:cursor()
uci:set("network", "wan", "ifname", ifname)
uci:save("network")
end

return wan
6 changes: 5 additions & 1 deletion packages/lime-system/files/usr/lib/lua/lime/proto/adhoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ local adhoc_mode = require("lime.mode.adhoc")

local adhoc = {}

function adhoc.configure(args) end
adhoc.configured = false

function adhoc.configure(args)
adhoc.configured = true
end

function adhoc.setup_interface(ifname, args)
if ifname:match("^wlan%d+_"..adhoc_mode.wifi_mode) then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ local ieee80211s_mode = require("lime.mode.ieee80211s")

local ieee80211s = {}

function ieee80211s.configure(args) end
ieee80211s.configured = false

function ieee80211s.configure(args)
ieee80211s.configured = true
end

function ieee80211s.setup_interface(ifname, args)
if ifname:match("^wlan%d+_"..ieee80211s_mode.wifi_mode) then
Expand Down
6 changes: 5 additions & 1 deletion packages/lime-system/files/usr/lib/lua/lime/proto/lan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ lan = {}
local network = require("lime.network")
local libuci = require("uci")

lan.configured = false

function lan.configure(args)
local ipv4, ipv6 = network.primary_address()
if lan.configured then return end
lan.configured = true

local ipv4, ipv6 = network.primary_address()
local uci = libuci:cursor()
uci:set("network", "lan", "ip6addr", ipv6:string())
uci:set("network", "lan", "ipaddr", ipv4:host():string())
Expand Down

0 comments on commit 94bea82

Please sign in to comment.