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