summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-radvd/luasrc/model/cbi/radvd.lua
blob: 041decce5fe8fd4d77b04eaaf16c54cddc16d3d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
--[[
LuCI - Lua Configuration Interface

Copyright 2010 Jo-Philipp Wich <xm@subsignal.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

$Id$
]]--

m = Map("radvd", translate("Radvd"),
	translate("Radvd is a router advertisement daemon for IPv6. " ..
		"It listens to router solicitations and sends router advertisements " ..
		"as described in RFC 4861."))

local nm = require "luci.model.network".init(m.uci)


--
-- Interfaces
--

s = m:section(TypedSection, "interface", translate("Interfaces"))
s.template = "cbi/tblsection"
s.extedit  = luci.dispatcher.build_url("admin/network/radvd/interface/%s")
s.anonymous = true
s.addremove = true

function s.create(...)
	local id = TypedSection.create(...)
	luci.http.redirect(s.extedit % id)
end

function s.remove(self, section)
	if m.uci:get("radvd", section) == "interface" then
		local iface = m.uci:get("radvd", section, "interface")
		if iface then
			m.uci:delete_all("radvd", "prefix",
				function(s) return s.interface == iface end)

			m.uci:delete_all("radvd", "route",
				function(s) return s.interface == iface end)

			m.uci:delete_all("radvd", "rdnss",
				function(s) return s.interface == iface end)
		end
	end

	return TypedSection.remove(self, section)
end


o = s:option(DummyValue, "interface", translate("Interface"))
o.template = "cbi/network_netinfo"

o = s:option(DummyValue, "UnicastOnly", translate("Multicast"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...)
	return v == "1" and translate("no") or translate("yes")
end

o = s:option(DummyValue, "AdvSendAdvert", translate("Advertising"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...)
	return v == "1" and translate("yes") or translate("no")
end

o = s:option(DummyValue, "MaxRtrAdvInterval", translate("Max. interval"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...) or "600"
	return v .. "s"
end

o = s:option(DummyValue, "AdvHomeAgentFlag", translate("Mobile IPv6"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...)
	return v == "1" and translate("yes") or translate("no")
end

o = s:option(DummyValue, "AdvDefaultPreference", translate("Preference"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...) or "medium"
	return translate(v)
end


--
-- Prefixes
--

s2 = m:section(TypedSection, "prefix", translate("Prefixes"))
s2.template = "cbi/tblsection"
s2.extedit  = luci.dispatcher.build_url("admin/network/radvd/prefix/%s")
s2.addremove = true
s2.anonymous = true

function s2.create(...)
	local id = TypedSection.create(...)
	luci.http.redirect(s2.extedit % id)
end


o = s2:option(DummyValue, "interface", translate("Interface"))
o.template = "cbi/network_netinfo"

o = s2:option(DummyValue, "prefix", translate("Prefix"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section)
	if not v then
		local net = nm:get_network(m.uci:get("radvd", section, "interface"))
		if net then
			local ifc = nm:get_interface(net:ifname())
			if ifc then
				local adr
				local lla = luci.ip.IPv6("fe80::/10")
				for _, adr in ipairs(ifc:ip6addrs()) do
					if not lla:contains(adr) then
						v = adr:string()
						break
					end
				end
			end
		end
	else
		v = luci.ip.IPv6(v)
		v = v and v:string()
	end

	return v or "?"
end

o = s2:option(DummyValue, "AdvAutonomous", translate("Autonomous"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...)
	return v == "1" and translate("yes") or translate("no")
end

o = s2:option(DummyValue, "AdvOnLink", translate("On-link"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...)
	return v == "1" and translate("yes") or translate("no")
end

o = s2:option(DummyValue, "AdvValidLifetime", translate("Validity time"))
function o.cfgvalue(...)
	local v = Value.cfgvalue(...) or "86400"
	return translate(v)
end


--
-- Routes
--

s3 = m:section(TypedSection, "route", translate("Routes"))
s3.template = "cbi/tblsection"
s3.extedit  = luci.dispatcher.build_url("admin/network/radvd/route/%s")
s3.addremove = true
s3.anonymous = true

function s3.create(...)
	local id = TypedSection.create(...)
	luci.http.redirect(s3.extedit % id)
end


o = s3:option(DummyValue, "interface", translate("Interface"))
o.template = "cbi/network_netinfo"

o = s3:option(DummyValue, "prefix", translate("Prefix"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section)
	if v then
		v = luci.ip.IPv6(v)
		v = v and v:string()
	end
	return v or "?"
end

o = s3:option(DummyValue, "AdvRouteLifetime", translate("Lifetime"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section) or "1800"
	return translate(v)
end

o = s3:option(DummyValue, "AdvRoutePreference", translate("Preference"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section) or "medium"
	return translate(v)
end


--
-- RDNSS
--

s4 = m:section(TypedSection, "rdnss", translate("RDNSS"))
s4.template = "cbi/tblsection"
s4.extedit  = luci.dispatcher.build_url("admin/network/radvd/rdnss/%s")
s4.addremove = true
s4.anonymous = true

function s.create(...)
	local id = TypedSection.create(...)
	luci.http.redirect(s4.extedit % id)
end


o = s4:option(DummyValue, "interface", translate("Interface"))
o.template = "cbi/network_netinfo"

o = s4:option(DummyValue, "addr", translate("Address"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section)
	if not v then
		local net = nm:get_network(m.uci:get("radvd", section, "interface"))
		if net then
			local ifc = nm:get_interface(net:ifname())
			if ifc then
				local adr
				local lla = luci.ip.IPv6("fe80::/10")
				for _, adr in ipairs(ifc:ip6addrs()) do
					if not lla:contains(adr) then
						v = adr:network(128):string()
						break
					end
				end
			end
		end
	else
		v = luci.ip.IPv6(v)
		v = v and v:network(128):string()
	end

	return v or "?"
end

o = s4:option(DummyValue, "AdvRDNSSOpen", translate("Open"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section)
	return v == "1" and translate("yes") or translate("no")
end

o = s4:option(DummyValue, "AdvRDNSSLifetime", translate("Lifetime"))
function o.cfgvalue(self, section)
	local v = Value.cfgvalue(self, section) or "1200"
	return translate(v)
end


return m