2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
17 local uci = require "luci.model.uci".cursor()
18 local tools = require "luci.tools.ffwizard"
19 local util = require "luci.util"
21 local io = require "io"
24 -------------------- View --------------------
25 f = SimpleForm("siitwizward", "4over6-Assistent",
26 "Dieser Assistent unterstüzt bei der Einrichtung von IPv4-over-IPv6 Translation.")
28 mode = f:field(ListValue, "mode", "Betriebsmodus")
29 mode:value("gateway", "Gateway")
30 mode:value("client", "Client")
32 dev = f:field(ListValue, "device", "WLAN-Gerät")
33 uci:foreach("network", "interface",
35 if section[".name"] ~= "siit0" then
36 dev:value(section[".name"])
41 -------------------- Control --------------------
42 LL_PREFIX = luci.ip.IPv6("fe80::/16")
45 -- find link-local address
48 for _, r in ipairs(luci.sys.net.routes6()) do
49 if r.device == dev and LL_PREFIX:contains(r.dest) then
50 return r.dest:sub(LL_PREFIX)
53 return luci.ip.IPv6("::")
58 function f.handle(self, state, data)
59 if state == FORM_VALID then
60 luci.http.redirect(luci.dispatcher.build_url("admin", "uci", "changes"))
62 elseif state == FORM_INVALID then
63 self.errmessage = "Ungültige Eingabe: Bitte die Formularfelder auf Fehler prüfen."
68 function mode.write(self, section, value)
73 local ula_prefix = uci:get("siit", "defaults", "ula_prefix") or "fd00::"
74 local ula_global = uci:get("siit", "defaults", "ula_global") or "00ca:ffee:babe::" -- = Freifunk
75 local ula_subnet = uci:get("siit", "defaults", "ula_subnet") or "0000:0000:0000:4223::" -- = Berlin
76 local siit_prefix = uci:get("siit", "defaults", "siit_prefix") or "::ffff:ffff:0000:0000"
77 local siit_route = luci.ip.IPv6(siit_prefix .. "/96")
79 -- Find wifi interface
80 local device = dev:formvalue(section)
85 local ula = luci.ip.IPv6("::")
87 for _, prefix in ipairs({ ula_prefix, ula_global, ula_subnet }) do
88 ula = ula:add(luci.ip.IPv6(prefix))
91 ula = ula:add(find_ll(uci:get("network", device, "ifname") or device))
97 -- * wan port is dhcp, lan port is 172.23.1.1/24
98 -- * siit0 gets a dummy address: 169.254.42.42
99 -- * wl0 gets an ipv6 address, in this case the fdca:ffee:babe::1:1/64
100 -- * we do a ::ffff:ffff:0/96 route into siit0, so everything from 6mesh goes into translation.
101 -- * an HNA6 of ::ffff:ffff:0:0/96 announces the mapped 0.0.0.0/0 ipv4 space.
102 -- * MTU on WAN, LAN down to 1400, ipv6 headers are slighly larger.
104 if value == "gateway" then
106 uci:set("network", "wan", "mtu", 1400)
112 -- * 172.23.2.1/24 on its lan, fdca:ffee:babe::1:2 on wl0 and the usual dummy address on siit0.
113 -- * we do a ::ffff:ffff:172.13.2.0/120 to siit0, because in this case, only traffic directed to clients needs to go into translation.
114 -- * same route as HNA6 announcement to catch the traffic out of the mesh.
115 -- * Also, MTU on LAN reduced to 1400.
118 local lan_ip = luci.ip.IPv4(
119 uci:get("network", "lan", "ipaddr"),
120 uci:get("network", "lan", "netmask")
123 siit_route = luci.ip.IPv6(
124 siit_prefix .. "/" .. (96 + lan_ip:prefix())
130 uci:delete_all("network", "interface",
131 function(s) return ( s.ifname == "siit0" ) end)
133 uci:section("network", "interface", "siit0", {
136 ipaddr = "169.254.42.42",
137 netmask = "255.255.255.0"
141 uci:delete_all("network", "route6",
142 function(s) return siit_route:contains(luci.ip.IPv6(s.target)) end)
144 uci:section("network", "route6", nil, {
146 target = siit_route:string()
150 uci:set("network", device, "ip6addr", ula:string())
151 uci:set("network", "lan", "mtu", 1400)
153 uci:set("olsrd", "general", "IpVersion", 6)
154 uci:foreach("olsrd", "Interface",
156 if s.interface == device then
157 uci:set("olsrd", s[".name"], "Ip6AddrType", "global")
159 uci:delete("olsrd", s[".name"], "Ip4Broadcast")
163 uci:delete_all("olsrd", "Hna6",
165 if s.netaddr and s.prefix then
166 return siit_route:contains(luci.ip.IPv6(s.netaddr.."/"..s.prefix))
170 uci:section("olsrd", "Hna6", nil, {
171 netaddr = siit_route:host():string(),
172 prefix = siit_route:prefix()