Adapt IPv6 interface to new architecture

This commit is contained in:
Steven Barth 2014-01-17 15:46:56 +00:00
parent ecbd62be12
commit 493b7d4ee9
4 changed files with 69 additions and 133 deletions

View file

@ -58,6 +58,34 @@ local function dhcp_leases_common(family)
fd:close()
end
local fd = io.open("/tmp/hosts/odhcpd", "r")
if fd then
while true do
local ln = fd:read("*l")
if not ln then
break
else
local iface, duid, iaid, name, ts, id, length, ip = ln:match("^# (%S+) (%S+) (%S+) (%S+) (%d+) (%S+) (%S+) (.*)")
if ip and iaid ~= "ipv4" and family == 6 then
rv[#rv+1] = {
expires = os.difftime(tonumber(ts) or 0, os.time()),
duid = duid,
ip6addr = ip,
hostname = (name ~= "-") and name
}
elseif ip and iaid == "ipv4" and family == 4 then
rv[#rv+1] = {
expires = os.difftime(tonumber(ts) or 0, os.time()),
macaddr = duid,
ipaddr = ip,
hostname = (name ~= "-") and name
}
end
end
end
fd:close()
end
return rv
end
@ -66,35 +94,7 @@ function dhcp_leases()
end
function dhcp6_leases()
local nfs = require "nixio.fs"
local leasefile = "/tmp/hosts/6relayd"
local rv = {}
if nfs.access(leasefile, "r") then
local fd = io.open(leasefile, "r")
if fd then
while true do
local ln = fd:read("*l")
if not ln then
break
else
local iface, duid, iaid, name, ts, id, length, ip = ln:match("^# (%S+) (%S+) (%S+) (%S+) (%d+) (%S+) (%S+) (.*)")
if ip then
rv[#rv+1] = {
expires = os.difftime(tonumber(ts) or 0, os.time()),
duid = duid,
ip6addr = ip,
hostname = (name ~= "-") and name
}
end
end
end
fd:close()
end
return rv
elseif luci.sys.call("dnsmasq --version 2>/dev/null | grep -q ' DHCPv6 '") == 0 then
return dhcp_leases_common(6)
end
return dhcp_leases_common(6)
end
function wifi_networks()

View file

@ -241,6 +241,8 @@ mac.rmempty = true
ip = s:option(Value, "ip", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-Address"))
ip.datatype = "or(ip4addr,'ignore')"
hostid = s:option(Value, "hostid", translate("<abbr title=\"Internet Protocol Version 6\">IPv6</abbr>-Suffix (hex)"))
sys.net.arptable(function(entry)
ip:value(entry["IP address"])
mac:value(

View file

@ -405,7 +405,7 @@ if has_dnsmasq and net:proto() == "static" then
end
end)
if not has_section then
if not has_section and has_dnsmasq then
s = m2:section(TypedSection, "dhcp", translate("DHCP Server"))
s.anonymous = true
@ -416,13 +416,14 @@ if has_dnsmasq and net:proto() == "static" then
x.inputtitle = translate("Setup DHCP Server")
x.inputstyle = "apply"
else
elseif has_section then
s = m2:section(TypedSection, "dhcp", translate("DHCP Server"))
s.addremove = false
s.anonymous = true
s:tab("general", translate("General Setup"))
s:tab("advanced", translate("Advanced Settings"))
s:tab("ipv6", translate("IPv6 Settings"))
function s.filter(self, section)
return m2.uci:get("dhcp", section, "interface") == arg[1]
@ -481,6 +482,41 @@ if has_dnsmasq and net:proto() == "static" then
end
end
o = s:taboption("ipv6", ListValue, "ra", translate("Router Advertisement-Service"))
o:value("", translate("disabled"))
o:value("server", translate("server mode"))
o:value("relay", translate("relay mode"))
o:value("hybrid", translate("hybrid mode"))
o = s:taboption("ipv6", ListValue, "dhcpv6", translate("DHCPv6-Service"))
o:value("", translate("disabled"))
o:value("server", translate("server mode"))
o:value("relay", translate("relay mode"))
o:value("hybrid", translate("hybrid mode"))
o = s:taboption("ipv6", ListValue, "ndp", translate("NDP-Proxy"))
o:value("", translate("disabled"))
o:value("relay", translate("relay mode"))
o:value("hybrid", translate("hybrid mode"))
o = s:taboption("ipv6", ListValue, "ra_management", translate("DHCPv6-Mode"))
o:value("", translate("stateless"))
o:value("1", translate("stateless + stateful"))
o:value("2", translate("stateful-only"))
o:depends("dhcpv6", "server")
o:depends("dhcpv6", "hybrid")
o.default = "1"
o = s:taboption("ipv6", Flag, "ra_default", translate("Always announce default router"),
translate("Announce as default router even if no public prefix is available."))
o:depends("ra", "server")
o:depends("ra", "hybrid")
s:taboption("ipv6", DynamicList, "dns", translate("Announced DNS servers"))
s:taboption("ipv6", DynamicList, "domain", translate("Announced DNS domains"))
else
m2 = nil
end
end

View file

@ -1,102 +0,0 @@
--[[
LuCI - Lua Configuration Interface
Copyright 2013 Steven Barth <steven@midlink.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
]]--
local m, s, o
m = Map("6relayd", translate("IPv6 RA and DHCPv6"),
translate("6relayd is a daemon for serving and relaying IPv6 management protocols to "..
"configure clients and downstream routers. "..
"It provides server services for RA, stateless and stateful DHCPv6, "..
"prefix delegation and can be used to relay RA, DHCPv6 and NDP between routed "..
"(non-bridged) interfaces in case no delegated prefixes are available."))
s = m:section(TypedSection, "server", translate("Server Settings"))
s.addremove = false
s.anonymous = true
o = s:option(DynamicList, "network", translate("Service Interfaces"),
translate("Interfaces to provide services on or to relay services to."))
o.widget = "checkbox"
o.template = "cbi/network_netlist"
o.nocreate = true
o.nobridges = true
o.novirtual = true
o.optional = false
o = s:option(ListValue, "rd", translate("Router Advertisement-Service"))
o:value("", translate("disabled"))
o:value("server", translate("server mode"))
o:value("relay", translate("relay mode"))
o = s:option(ListValue, "dhcpv6", translate("DHCPv6-Service"))
o:value("", translate("disabled"))
o:value("server", translate("server mode"))
o:value("relay", translate("relay mode"))
o = s:option(ListValue, "management_level", translate("DHCPv6-Mode"))
o:value("", translate("stateless"))
o:value("1", translate("stateless + stateful"))
o:value("2", translate("stateful-only"))
o:depends("dhcpv6", "server")
o = s:option(ListValue, "ndp", translate("NDP-Proxy"))
o:value("", translate("disabled"))
o:value("relay", translate("relay mode"))
o = s:option(Flag, "fallback_relay", translate("Fallback to relay"),
translate("Relay services from master to server interfaces when there is no public prefix available."))
o.enabled = "rd dhcpv6 ndp"
o.disabled = ""
o = s:option(Value, "master", translate("Master Interface"),
translate("Specifies the master interface for services that are relayed."))
o.template = "cbi/network_netlist"
o.nocreate = true
o:depends("rd", "relay")
o:depends("dhcpv6", "relay")
o:depends("ndp", "relay")
o:depends("fallback_relay", "rd dhcpv6 ndp")
o = s:option(Flag, "always_rewrite_dns", translate("Always announce local DNS"),
translate("Announce the local router as DNS server even in relay mode."))
o:depends("rd", "relay")
o:depends("dhcpv6", "relay")
o:depends("fallback_relay", "rd dhcpv6 ndp")
o = s:option(Value, "rewrite_dns_addr", translate("Override announced DNS-server"),
translate("Announce a custom DNS-server instead of the local one."))
o = s:option(Flag, "always_assume_default", translate("Always announce default router"),
translate("Announce as default router even if no public prefix is available."))
o:depends("rd", "server")
o = s:option(Flag, "compat_ula", translate("ULA-preference compatibility"),
translate("Work around IPv6 address-selection issues of some devices."))
m:section(SimpleSection).template = "admin_network/lease_status"
s = m:section(TypedSection, "lease", translate("Static Leases"),
translate("Static leases are used to assign fixed IPv6 Interface-IDs to clients. Interface-IDs are appended to available prefixes to form IPv6-addresses. " ..
" (e.g. a prefix of 2001:db80::/64 combined with Interface-ID 123456 will form the address 2001:db80::12:3456)") .. "<br />" ..
translate("Use the <em>Add</em> Button to add a new lease entry. The <em>DUID</em> " ..
"indentifies the host, the <em>Interface-ID</em> specifies the ID to use in addresses."))
s.addremove = true
s.anonymous = true
s.template = "cbi/tblsection"
s:option(Value, "duid", translate("DUID")).optional = false
s:option(Value, "id", translate("Interface-ID")).optional = false
return m