applications/luci-radvd: allow the special value "infinity" for preferred lifetime...
[project/luci.git] / applications / luci-radvd / luasrc / model / cbi / radvd / prefix.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14
15 local sid = arg[1]
16 local utl = require "luci.util"
17
18 m = Map("radvd", translatef("Radvd - Prefix"),
19 translate("Radvd is a router advertisement daemon for IPv6. " ..
20 "It listens to router solicitations and sends router advertisements " ..
21 "as described in RFC 4861."))
22
23 m.redirect = luci.dispatcher.build_url("admin/network/radvd")
24
25 if m.uci:get("radvd", sid) ~= "prefix" then
26 luci.http.redirect(m.redirect)
27 return
28 end
29
30
31 s = m:section(NamedSection, sid, "interface", translate("Prefix Configuration"))
32 s.addremove = false
33
34 s:tab("general", translate("General"))
35 s:tab("advanced", translate("Advanced"))
36
37
38 --
39 -- General
40 --
41
42 o = s:taboption("general", Flag, "ignore", translate("Enable"))
43 o.rmempty = false
44
45 function o.cfgvalue(...)
46 local v = Flag.cfgvalue(...)
47 return v == "1" and "0" or "1"
48 end
49
50 function o.write(self, section, value)
51 Flag.write(self, section, value == "1" and "0" or "1")
52 end
53
54
55 o = s:taboption("general", Value, "interface", translate("Interface"),
56 translate("Specifies the logical interface name this section belongs to"))
57
58 o.template = "cbi/network_netlist"
59 o.nocreate = true
60 o.optional = false
61
62 function o.formvalue(...)
63 return Value.formvalue(...) or "-"
64 end
65
66 function o.validate(self, value)
67 if value == "-" then
68 return nil, translate("Interface required")
69 end
70 return value
71 end
72
73 function o.write(self, section, value)
74 m.uci:set("radvd", section, "ignore", 0)
75 m.uci:set("radvd", section, "interface", value)
76 end
77
78
79 o = s:taboption("general", DynamicList, "prefix", translate("Prefixes"),
80 translate("Advertised IPv6 prefixes. If empty, the current interface prefix is used"))
81
82 o.optional = true
83 o.datatype = "ip6addr"
84 o.placeholder = translate("default")
85 function o.cfgvalue(self, section)
86 local l = { }
87 local v = m.uci:get_list("radvd", section, "prefix")
88 for v in utl.imatch(v) do
89 l[#l+1] = v
90 end
91 return l
92 end
93
94
95 o = s:taboption("general", Flag, "AdvOnLink", translate("On-link determination"),
96 translate("Indicates that this prefix can be used for on-link determination (RFC4861)"))
97
98 o.rmempty = false
99 o.default = "1"
100
101
102 o = s:taboption("general", Flag, "AdvAutonomous", translate("Autonomous"),
103 translate("Indicates that this prefix can be used for autonomous address configuration (RFC4862)"))
104
105 o.rmempty = false
106 o.default = "1"
107
108
109 --
110 -- Advanced
111 --
112
113 o = s:taboption("advanced", Flag, "AdvRouterAddr", translate("Advertise router address"),
114 translate("Indicates that the address of interface is sent instead of network prefix, as is required by Mobile IPv6"))
115
116
117 o = s:taboption("advanced", Value, "AdvValidLifetime", translate("Valid lifetime"),
118 translate("Advertises the length of time in seconds that the prefix is valid for the purpose of on-link determination."))
119
120 o.datatype = 'or(uinteger,"infinity")'
121 o.placeholder = 86400
122
123
124 o = s:taboption("advanced", Value, "AdvPreferredLifetime", translate("Preferred lifetime"),
125 translate("Advertises the length of time in seconds that addresses generated from the prefix via stateless address autoconfiguration remain preferred."))
126
127 o.datatype = 'or(uinteger,"infinity")'
128 o.placeholder = 14400
129
130
131 o = s:taboption("advanced", Value, "Base6to4Interface", translate("6to4 interface"),
132 translate("Specifies a logical interface name to derive a 6to4 prefix from. The interfaces public IPv4 address is combined with 2002::/3 and the value of the prefix option"))
133
134 o.template = "cbi/network_netlist"
135 o.nocreate = true
136 o.unspecified = true
137
138
139 return m