+-------------------- Init --------------------
+
+--
+-- Find link-local address
+--
+LL_PREFIX = luci.ip.IPv6("fe80::/64")
+function find_ll()
+ for _, r in ipairs(luci.sys.net.routes6()) do
+ if LL_PREFIX:contains(r.dest) and r.dest:higher(LL_PREFIX) then
+ return r.dest:sub(LL_PREFIX)
+ end
+ end
+ return luci.ip.IPv6("::")
+end
+
+--
+-- Determine defaults
+--
+local ula_prefix = uci:get("siit", "ipv6", "ula_prefix") or "fd00::"
+local ula_global = uci:get("siit", "ipv6", "ula_global") or "00ca:ffee:babe::" -- = Freifunk
+local ula_subnet = uci:get("siit", "ipv6", "ula_subnet") or "0000:0000:0000:4223::" -- = Berlin
+local siit_prefix = uci:get("siit", "ipv6", "siit_prefix") or "::ffff:0000:0000"
+local ipv4_pool = uci:get("siit", "ipv4", "pool") or "172.16.0.0/12"
+local ipv4_netsz = uci:get("siit", "ipv4", "netsize") or "24"
+
+--
+-- Find IPv4 allocation pool
+--
+local gv4_net = luci.ip.IPv4(ipv4_pool)
+local lan_net
+
+--
+-- Generate ULA
+--
+local ula = luci.ip.IPv6("::/64")
+
+for _, prefix in ipairs({ ula_prefix, ula_global, ula_subnet }) do
+ ula = ula:add(luci.ip.IPv6(prefix))
+end
+
+ula = ula:add(find_ll())
+
+