Add NAT features

This commit is contained in:
mar-v-in 2015-06-16 16:46:37 +02:00
parent 8375e82a38
commit e8956e3f5a
3 changed files with 38 additions and 10 deletions

View File

@ -10,7 +10,7 @@ uci:section('network', 'interface', 'wan',
ifname = sysconfig.wan_ifname, ifname = sysconfig.wan_ifname,
type = 'bridge', type = 'bridge',
igmp_snooping = 0, igmp_snooping = 0,
peerdns = 0, peerdns = 1,
auto = 1, auto = 1,
} }
) )
@ -51,6 +51,15 @@ uci:section('network', 'route6', 'wan6_unreachable',
} }
) )
uci:section('network', 'interface', 'lan',
{
type = 'bridge',
proto = 'static',
ipaddr = '192.168.0.1',
netmask = '255.255.255.0',
}
)
uci:save('network') uci:save('network')
uci:commit('network') uci:commit('network')

View File

@ -88,9 +88,14 @@ o.default = uci:get_bool("network", "mesh_wan", "auto") and o.enabled or o.disab
o.rmempty = false o.rmempty = false
if sysconfig.lan_ifname then if sysconfig.lan_ifname then
o = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface")) o = s:option(ListValue, "lan_option", translate("LAN interface"))
o.default = uci:get_bool("network", "mesh_lan", "auto") and o.enabled or o.disabled o:value("client", translate("Client network"))
o.rmempty = false o:value("mesh", translate("Mesh network"))
-- TODO: o:value("bridge", translate("Private network (Bridged)"))
o:value("nat", translate("Private network (NAT)"))
o.default = (uci:get_bool("network", "mesh_lan", "auto") and "mesh") or
(uci.get("network", "lan", "ifname") == sysconfig.lan_ifname and "nat") or
"client"
end end
@ -119,12 +124,22 @@ function f.handle(self, state, data)
uci:set("network", "mesh_wan", "auto", data.mesh_wan) uci:set("network", "mesh_wan", "auto", data.mesh_wan)
if sysconfig.lan_ifname then if sysconfig.lan_ifname then
uci:set("network", "mesh_lan", "auto", data.mesh_lan) if data.lan_option == 'client' then
if data.mesh_lan == '1' then
uci:set("network", "client", "ifname", "bat0")
else
uci:set("network", "client", "ifname", sysconfig.lan_ifname .. " bat0") uci:set("network", "client", "ifname", sysconfig.lan_ifname .. " bat0")
else
uci:set("network", "client", "ifname", "bat0")
end
if data.lan_option == 'nat' then
uci:set("network", "lan", "ifname", sysconfig.lan_ifname)
else
uci:set("network", "lan", "ifname", '')
end
if data.lan_option == 'mesh' then
uci:set("network", "mesh_lan", "auto", '1')
else
uci:set("network", "mesh_lan", "auto", '0')
end end
end end

View File

@ -29,6 +29,10 @@ o:depends("enabled", '1')
o.datatype = "wpakey" o.datatype = "wpakey"
o.default = uci:get(config, primary_iface, "key") o.default = uci:get(config, primary_iface, "key")
o = s:option(Flag, "nat", translate("Use NAT"))
o:depends("enabled", '1')
o.default = uci:get(config, primary_iface, "network") == "lan" and o.enabled or o.disabled
function f.handle(self, state, data) function f.handle(self, state, data)
if state == FORM_VALID then if state == FORM_VALID then
uci:foreach(config, "wifi-device", uci:foreach(config, "wifi-device",
@ -41,7 +45,7 @@ function f.handle(self, state, data)
uci:section(config, "wifi-iface", name, uci:section(config, "wifi-iface", name,
{ {
device = device, device = device,
network = "wan", network = data.nat == '1' and "lan" or "wan",
mode = 'ap', mode = 'ap',
encryption = 'psk2', encryption = 'psk2',
ssid = data.ssid, ssid = data.ssid,