Allow DHCP for Local Network (preparing WDS client)
Use niulib-wrapper for finding available interfaces
This commit is contained in:
Steven Barth 2009-11-23 13:52:53 +00:00
parent 840d8c89b5
commit 952836d1ef
3 changed files with 52 additions and 25 deletions

View file

@ -30,14 +30,14 @@ s.addremove = false
s:tab("general", translate("General Settings")) s:tab("general", translate("General Settings"))
s:tab("expert", translate("Expert Settings")) s:tab("expert", translate("Expert Settings"))
p = s:taboption("general", ListValue, "proto", "Connection Type") p = s:taboption("general", ListValue, "proto", translate("Connection Protocol"))
p.override_scheme = true p.override_scheme = true
p.default = "dhcp" p.default = "dhcp"
p:value("dhcp", "Cable / Ethernet / DHCP") p:value("dhcp", translate("Cable / Ethernet / DHCP"))
if has_pppoe then p:value("pppoe", "DSL / PPPoE") end if has_pppoe then p:value("pppoe", "DSL / PPPoE") end
if has_pppoa then p:value("pppoa", "PPPoA") end if has_pppoa then p:value("pppoa", "PPPoA") end
if has_pptp then p:value("pptp", "PPTP") end if has_pptp then p:value("pptp", "PPTP") end
p:value("static", "Static Ethernet") p:value("static", translate("Static Ethernet"))

View file

@ -19,6 +19,23 @@ function d.on_done()
cs:save("network") cs:save("network")
end end
if cursor:get("network", "lan", "proto") == "dhcp" then
local emergv4 = cursor:get("network", "lan", "_emergv4")
if emergv4 then
if cursor:get("network", "lan_ea") then
cursor:set("network", "lan_ea", "ipaddr", emergv4)
else
cursor:section("network", "alias", "lan_ea", {
ipaddr = emergv4,
netmask = "255.255.255.0",
network = "lan"
})
end
else
cursor:delete("network", "lan_ea")
end
end
cursor:set("network", "lan", "type", "bridge") cursor:set("network", "lan", "type", "bridge")
cursor:commit("network") cursor:commit("network")
cursor:commit("dhcp") cursor:commit("dhcp")

View file

@ -13,31 +13,38 @@ You may obtain a copy of the License at
$Id$ $Id$
]]-- ]]--
local nw = require "luci.model.network" local niulib = require "luci.niulib"
local fs = require "nixio.fs"
local has_ipv6 = nw:has_ipv6() local has_ipv6 = fs.access("/proc/net/ipv6_route")
m = Map("network", "Configure Local Network", "These settings affect the devices in your local network. ".. m = Map("network", "Configure Local Network", "These settings affect the devices in your local network. "..
"Usually you do not need to change anything here for your router to work correctly.") "Usually you do not need to change anything here for your router to work correctly.")
nw.init(m.uci)
s = m:section(NamedSection, "lan", "interface", "Network Settings") s = m:section(NamedSection, "lan", "interface", "Network Settings")
s.addremove = false s.addremove = false
s:tab("general", translate("General Settings")) s:tab("general", translate("General Settings"))
ipaddr = s:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address")) ipaddr = s:taboption("general", Value, "ipaddr", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
ipaddr.default = "192.168.0.1"
ipaddr:depends("proto", "static")
nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask")) nm = s:taboption("general", Value, "netmask", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Netmask"))
nm.default = "255.255.255.0"
nm:value("255.255.255.0") nm:value("255.255.255.0")
nm:value("255.255.0.0") nm:value("255.255.0.0")
nm:value("255.0.0.0") nm:value("255.0.0.0")
nm:depends("proto", "static")
s:tab("expert", translate("Expert Settings")) 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"))
mac = s:taboption("expert", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address")) mac = s:taboption("expert", Value, "macaddr", translate("<abbr title=\"Media Access Control\">MAC</abbr>-Address"))
mtu = s:taboption("expert", Value, "mtu", "MTU") mtu = s:taboption("expert", Value, "mtu", "MTU")
@ -48,37 +55,33 @@ dns:depends("peerdns", "")
gw = s:taboption("expert", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway")) gw = s:taboption("expert", Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Gateway"))
gw:depends("proto", "static")
bcast = s:taboption("expert", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast")) bcast = s:taboption("expert", Value, "bcast", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Broadcast"))
bcast:depends("proto", "static")
if has_ipv6 then if has_ipv6 then
ip6addr = s:taboption("expert", Value, "ip6addr", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix")) ip6addr = s:taboption("expert", Value, "ip6addr", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Address"), translate("<abbr title=\"Classless Inter-Domain Routing\">CIDR</abbr>-Notation: address/prefix"))
ip6addr:depends("proto", "static")
ip6gw = s:taboption("expert", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway")) ip6gw = s:taboption("expert", Value, "ip6gw", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Gateway"))
ip6gw:depends("proto", "static")
end end
emerg = s:taboption("expert", Value, "_emergv4", translate("Emergency Access Address"))
emerg:depends("proto", "dhcp")
emerg.default = "169.254.255.169"
stp = s:taboption("expert", Flag, "stp", translate("Enable <abbr title=\"Spanning Tree Protocol\">STP</abbr>"), stp = s:taboption("expert", Flag, "stp", translate("Enable <abbr title=\"Spanning Tree Protocol\">STP</abbr>"),
translate("Enables the Spanning Tree Protocol on this bridge")) translate("Enables the Spanning Tree Protocol on this bridge"))
ifname_multi = s:taboption("expert", MultiValue, "ifname_multi", translate("Interface")) ifname_multi = s:taboption("expert", MultiValue, "ifname", translate("Interface"))
ifname_multi.template = "cbi/network_ifacelist"
ifname_multi.nobridges = true
ifname_multi.widget = "checkbox" ifname_multi.widget = "checkbox"
for _, eth in ipairs(niulib.eth_get_available("lan")) do
function ifname_multi.cfgvalue(self, s) ifname_multi:value(eth, translate("Ethernet-Adapter (%s)") % eth)
return self.map.uci:get("network", s, "ifname")
end end
function ifname_multi.write(self, s, val)
local n = nw:get_network(s)
if n then n:ifname(val) end
end
for _, d in ipairs(nw:get_interfaces()) do
if not d:is_bridge() then
ifname_multi:value(d:name())
end
end
m2 = Map("dhcp") m2 = Map("dhcp")
@ -93,17 +96,24 @@ s:tab("general", translate("General Settings"))
s:depends("interface", "lan") s:depends("interface", "lan")
enable = s:taboption("general", ListValue, "ignore", "Automatic address assignment for network devices", "") enable = s:taboption("general", ListValue, "ignore", "Automatic address assignment for network devices", "")
enable:value(0, translate("enable")) enable:value(0, translate("enable"), {["network.lan.proto"] = "static"})
enable:value(1, translate("disable")) enable:value(1, translate("disable"))
s:tab("expert", translate("Expert Settings")) s:tab("expert", translate("Expert Settings"))
start = s:taboption("expert", Value, "start", translate("First leased address")) start = s:taboption("expert", Value, "start", translate("First leased address"))
start:depends("ignore", "0")
limit = s:taboption("expert", Value, "limit", translate("Number of leased addresses"), "") limit = s:taboption("expert", Value, "limit", translate("Number of leased addresses"), "")
limit:depends("ignore", "0")
time = s:taboption("expert", Value, "leasetime", "Lease Time") time = s:taboption("expert", Value, "leasetime", "Lease Time")
time:depends("ignore", "0")
local dd = s:taboption("expert", Flag, "dynamicdhcp", "Also generate addresses for unknown devices") local dd = s:taboption("expert", Flag, "dynamicdhcp", "Also generate addresses for unknown devices")
dd.rmempty = false dd.rmempty = false
dd.default = "1" dd.default = "1"
dd:depends("ignore", "0")
return m, m2 return m, m2