Merge pull request #61 from freifunk-gluon/configurable-wan

Configurable WAN
This commit is contained in:
Nils Schneider 2014-08-09 23:31:19 +02:00
commit 9e1d5bb4f3
6 changed files with 135 additions and 26 deletions

View File

@ -1,19 +1,9 @@
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local uci = require('luci.model.uci').cursor()
uci:delete('network', 'lan')
uci:delete('network', 'wan')
uci:section('network', 'interface', 'wan',
{
ifname = sysconfig.wan_ifname,
type = 'bridge',
proto = 'dhcp',
}
)
uci:save('network')
uci:commit('network')

View File

@ -2,22 +2,34 @@
local uci = require('luci.model.uci').cursor()
local sysctl = require 'gluon.sysctl'
local sysconfig = require 'gluon.sysconfig'
if not uci:get('network', 'interface', 'wan6') then
uci:section('network', 'interface', 'wan6',
{
ifname = 'br-wan',
proto = 'dhcpv6',
}
)
uci:section('network', 'interface', 'wan',
{
ifname = sysconfig.wan_ifname,
type = 'bridge',
peerdns = 0,
auto = 1,
}
)
if not uci:get('network', 'wan', 'proto') then
uci:set('network', 'wan', 'proto', 'dhcp')
end
uci:set('network', 'wan', 'peerdns', '0')
uci:section('network', 'interface', 'wan6',
{
ifname = 'br-wan',
peerdns = 0,
ip6table = 1,
}
)
uci:set('network', 'wan6', 'peerdns', '0')
uci:set('network', 'wan6', 'ip6table', '1')
if not uci:get('network', 'wan6', 'proto') then
uci:set('network', 'wan6', 'proto', 'dhcpv6')
end
uci:section('network', 'rule6', 'wan6_lookup',

View File

@ -14,11 +14,74 @@ $Id$
local uci = luci.model.uci.cursor()
f = SimpleForm("portconfig")
local wan = uci:get_all("network", "wan")
local wan6 = uci:get_all("network", "wan6")
local dns = uci:get_first("gluon-wan-dnsmasq", "static")
local f = SimpleForm("portconfig", "WAN-Verbindung")
f.template = "admin/expertmode"
f.submit = "Speichern"
f.reset = "Zurücksetzen"
local s
local o
s = f:section(SimpleSection, nil, nil)
o = s:option(ListValue, "ipv4", "IPv4")
o:value("dhcp", "Automatisch (DHCP)")
o:value("static", "Statisch")
o:value("none", "Deaktiviert")
o.default = wan.proto
o = s:option(Value, "ipv4_addr", "IP-Adresse")
o:depends("ipv4", "static")
o.value = wan.ipaddr
o.datatype = "ip4addr"
o.rmempty = false
o = s:option(Value, "ipv4_netmask", "Netzmaske")
o:depends("ipv4", "static")
o.value = wan.netmask or "255.255.255.0"
o.datatype = "ip4addr"
o.rmempty = false
o = s:option(Value, "ipv4_gateway", "Gateway")
o:depends("ipv4", "static")
o.value = wan.gateway
o.datatype = "ip4addr"
o.rmempty = false
s = f:section(SimpleSection, nil, nil)
o = s:option(ListValue, "ipv6", "IPv6")
o:value("dhcpv6", "Automatisch (RA/DHCPv6)")
o:value("static", "Statisch")
o:value("none", "Deaktiviert")
o.default = wan6.proto
o = s:option(Value, "ipv6_addr", "IP-Adresse")
o:depends("ipv6", "static")
o.value = wan6.ip6addr
o.datatype = "ip6addr"
o.rmempty = false
o = s:option(Value, "ipv6_gateway", "Gateway")
o:depends("ipv6", "static")
o.value = wan6.ip6gw
o.datatype = "ip6addr"
o.rmempty = false
if dns then
s = f:section(SimpleSection, nil, nil)
o = s:option(DynamicList, "dns", "Statische DNS-Server")
o:write(nil, uci:get("gluon-wan-dnsmasq", dns, "server"))
o.datatype = "ipaddr"
end
s = f:section(SimpleSection, nil, nil)
o = s:option(Flag, "mesh_wan", "Mesh auf dem WAN-Port aktivieren")
@ -27,9 +90,41 @@ o.rmempty = false
function f.handle(self, state, data)
if state == FORM_VALID then
uci:set("network", "wan", "proto", data.ipv4)
if data.ipv4 == "static" then
uci:set("network", "wan", "ipaddr", data.ipv4_addr)
uci:set("network", "wan", "netmask", data.ipv4_netmask)
uci:set("network", "wan", "gateway", data.ipv4_gateway)
else
uci:delete("network", "wan", "ipaddr")
uci:delete("network", "wan", "netmask")
uci:delete("network", "wan", "gateway")
end
uci:set("network", "wan6", "proto", data.ipv6)
if data.ipv6 == "static" then
uci:set("network", "wan6", "ip6addr", data.ipv6_addr)
uci:set("network", "wan6", "ip6gw", data.ipv6_gateway)
else
uci:delete("network", "wan6", "ip6addr")
uci:delete("network", "wan6", "ip6gw")
end
uci:set("network", "mesh_wan", "auto", data.mesh_wan)
uci:save("network")
uci:commit("network")
if dns then
if data.dns then
uci:set("gluon-wan-dnsmasq", dns, "server", data.dns)
else
uci:delete("gluon-wan-dnsmasq", dns, "server")
end
uci:save("gluon-wan-dnsmasq")
uci:commit("gluon-wan-dnsmasq")
end
end
return true

View File

@ -0,0 +1,2 @@
config 'static'
# list 'server' '192.168.0.1' # Example

View File

@ -16,7 +16,7 @@ RESOLV_CONF=$RESOLV_CONF_DIR/resolv.conf
start() {
mkdir -p $RESOLV_CONF_DIR
touch $RESOLV_CONF
/lib/gluon/wan-dnsmasq/update.lua
LD_PRELOAD=libpacketmark.so LIBPACKETMARK_MARK=$PACKET_MARK service_start /usr/sbin/dnsmasq -x $SERVICE_PID_FILE -u root -i lo -p $PORT -h -r $RESOLV_CONF
}

View File

@ -5,21 +5,31 @@ local RESOLV_CONF = RESOLV_CONF_DIR .. '/resolv.conf'
local ubus = require('ubus').connect()
local uci = require('luci.model.uci').cursor()
local fs = require 'nixio.fs'
local function write_servers(f, iface)
local servers = ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server']
local function write_servers(f, servers)
for _, server in ipairs(servers) do
f:write('nameserver ', server, '\n')
end
end
local function write_interface_servers(f, iface)
write_servers(f, ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server'])
end
fs.mkdirr(RESOLV_CONF_DIR)
local f = io.open(RESOLV_CONF, 'w+')
pcall(write_servers, f, 'wan6')
pcall(write_servers, f, 'wan')
local static = uci:get_first('gluon-wan-dnsmasq', 'static', 'server')
if type(static) == 'table' and #static > 0 then
write_servers(f, static)
else
pcall(write_interface_servers, f, 'wan6')
pcall(write_interface_servers, f, 'wan')
end
f:close()