diff options
author | Steven Barth <steven@midlink.org> | 2009-11-23 15:37:54 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-11-23 15:37:54 +0000 |
commit | 8b80a623c3526fa40d215f28f0a3cd1312edebea (patch) | |
tree | 10410da416fe3db862e5a1754384dbb28830bc7d | |
parent | edb5427181412a69be73b7ccda199841d1e0092b (diff) |
NIU: Allow automatic unbridging of LAN ethernet for WAN use
-rw-r--r-- | modules/niu/luasrc/model/cbi/niu/network/lan1.lua | 2 | ||||
-rw-r--r-- | modules/niu/luasrc/model/cbi/niu/network/wan.lua | 16 | ||||
-rw-r--r-- | modules/niu/luasrc/model/cbi/niu/network/wandevice.lua | 14 | ||||
-rw-r--r-- | modules/niu/luasrc/niulib.lua | 18 |
4 files changed, 46 insertions, 4 deletions
diff --git a/modules/niu/luasrc/model/cbi/niu/network/lan1.lua b/modules/niu/luasrc/model/cbi/niu/network/lan1.lua index e4005bbcff..423b4dfbe8 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/lan1.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/lan1.lua @@ -42,8 +42,8 @@ s:tab("expert", translate("Expert Settings")) p = s:taboption("expert", ListValue, "proto", translate("Connection Protocol")) p.default = "static" -p:value("dhcp", "DHCP") p:value("static", translate("Static Ethernet")) +p:value("dhcp", "DHCP") mac = s:taboption("expert", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address")) diff --git a/modules/niu/luasrc/model/cbi/niu/network/wan.lua b/modules/niu/luasrc/model/cbi/niu/network/wan.lua index 1724c4a8e1..cb97cc1aae 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/wan.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/wan.lua @@ -21,7 +21,21 @@ local function deviceroute(self) if wd:find("ethernet:") == 1 then cursor:set("network", "wan", "defaultroute", "1") - cursor:set("network", "wan", "ifname", wd:sub(10)) + if wd:find("!", 10) == 10 then --Unbridge from LAN + local ethdev = wd:sub(11) + local ifname = cursor:get("network", "lan", "ifname") + local newifname = {} + for k in ifname:gmatch("[^ ]+") do + if k ~= ifname then + newifname[#newifname+1] = k + end + end + cursor:set("network", "lan", "ifname", table.concat(newifname, " ")) + cursor:set("network", "wan", "_wandev", "ethernet:" .. ethdev) + cursor:set("network", "wan", "ifname", ethdev) + else + cursor:set("network", "wan", "ifname", wd:sub(10)) + end self:set_route("etherwan") else cursor:delete("network", "wan", "ifname") diff --git a/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua b/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua index 9287ba8d0f..8917b97c08 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua @@ -19,7 +19,10 @@ s = m:section(NamedSection, "wan", "interface", "Internet Connection Device") s.anonymous = true s.addremove = false -l = s:option(ListValue, "_wandev", "Internet Connection via") +s:tab("general", translate("General Settings")) +s:tab("expert", translate("Expert Settings")) + +l = s:taboption("general", ListValue, "_wandev", "Internet Connection via") for _, ifc in ipairs(niulib.eth_get_available("wan")) do l:value("ethernet:%s" % ifc, "Cable / DSL / Ethernet-Adapter (%s)" % ifc) @@ -29,7 +32,16 @@ for _, wifi in ipairs(niulib.wifi_get_available("client")) do l:value("wlan:%s" % wifi, "WLAN-Adapter (%s)" % wifi) end +for _, ifc in ipairs(niulib.eth_get_bridged("lan")) do + l:value("ethernet:!%s" % ifc, "Used Ethernet-Adapter (%s)" % ifc, {_showused = "1"}) +end l:value("none", "No Internet Connection") +v = s:taboption("expert", ListValue, "_showused", translate("Show ethernet adapters in use")) +v:value("", translate("never")) +v:value("1", translate("from LAN-bridge, unbridge on-demand")) + + + return m diff --git a/modules/niu/luasrc/niulib.lua b/modules/niu/luasrc/niulib.lua index aef542aa6e..dc3df5ed43 100644 --- a/modules/niu/luasrc/niulib.lua +++ b/modules/niu/luasrc/niulib.lua @@ -15,7 +15,9 @@ $Id$ local ipairs, pairs, require = ipairs, pairs, require local os = require "os" -local cursor = require "luci.model.uci".inst +local uci = require "luci.model.uci" +local cursor = uci.inst +local state = uci.inst_state module "luci.niulib" @@ -36,6 +38,20 @@ function eth_get_available(except) return ifs end +function eth_get_bridged(except) + local devs = state:get("network", except, "device") + + local ifs = {} + local cnt = 0 + for x in devs:gmatch("[^ ]+") do + cnt = cnt + 1 + if x:find("eth") == 1 then + ifs[#ifs+1] = x + end + end + return cnt > 1 and ifs or {} +end + function wifi_get_available(except) cursor:unload("wireless") |