1
0

radvd.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. m = Map("radvd", translate("Radvd"),
  4. translate("Radvd is a router advertisement daemon for IPv6. " ..
  5. "It listens to router solicitations and sends router advertisements " ..
  6. "as described in RFC 4861."))
  7. local nm = require "luci.model.network".init(m.uci)
  8. local ut = require "luci.util"
  9. --
  10. -- Interfaces
  11. --
  12. s = m:section(TypedSection, "interface", translate("Interfaces"))
  13. s.template = "cbi/tblsection"
  14. s.extedit = luci.dispatcher.build_url("admin/network/radvd/interface/%s")
  15. s.anonymous = true
  16. s.addremove = true
  17. function s.create(...)
  18. local id = TypedSection.create(...)
  19. luci.http.redirect(s.extedit % id)
  20. end
  21. function s.remove(self, section)
  22. if m.uci:get("radvd", section) == "interface" then
  23. local iface = m.uci:get("radvd", section, "interface")
  24. if iface then
  25. m.uci:delete_all("radvd", "prefix",
  26. function(s) return s.interface == iface end)
  27. m.uci:delete_all("radvd", "route",
  28. function(s) return s.interface == iface end)
  29. m.uci:delete_all("radvd", "rdnss",
  30. function(s) return s.interface == iface end)
  31. end
  32. end
  33. return TypedSection.remove(self, section)
  34. end
  35. o = s:option(Flag, "ignore", translate("Enable"))
  36. o.rmempty = false
  37. o.width = "30px"
  38. function o.cfgvalue(...)
  39. local v = Flag.cfgvalue(...)
  40. return v == "1" and "0" or "1"
  41. end
  42. function o.write(self, section, value)
  43. Flag.write(self, section, value == "1" and "0" or "1")
  44. end
  45. o = s:option(DummyValue, "interface", translate("Interface"))
  46. o.template = "cbi/network_netinfo"
  47. o.width = "10%"
  48. o = s:option(DummyValue, "UnicastOnly", translate("Multicast"))
  49. function o.cfgvalue(self, section)
  50. local v = Value.cfgvalue(self, section)
  51. local v2 = m.uci:get("radvd", section, "client")
  52. return (v == "1" or (v2 and #v2 > 0)) and translate("no") or translate("yes")
  53. end
  54. o = s:option(DummyValue, "AdvSendAdvert", translate("Advertising"))
  55. function o.cfgvalue(...)
  56. local v = Value.cfgvalue(...)
  57. return v == "1" and translate("yes") or translate("no")
  58. end
  59. o = s:option(DummyValue, "MaxRtrAdvInterval", translate("Max. interval"))
  60. function o.cfgvalue(...)
  61. local v = Value.cfgvalue(...) or "600"
  62. return v .. "s"
  63. end
  64. o = s:option(DummyValue, "AdvHomeAgentFlag", translate("Mobile IPv6"))
  65. function o.cfgvalue(...)
  66. local v = Value.cfgvalue(...)
  67. return v == "1" and translate("yes") or translate("no")
  68. end
  69. o = s:option(DummyValue, "AdvDefaultPreference", translate("Preference"))
  70. function o.cfgvalue(...)
  71. local v = Value.cfgvalue(...) or "medium"
  72. return translate(v)
  73. end
  74. --
  75. -- Prefixes
  76. --
  77. s2 = m:section(TypedSection, "prefix", translate("Prefixes"))
  78. s2.template = "cbi/tblsection"
  79. s2.extedit = luci.dispatcher.build_url("admin/network/radvd/prefix/%s")
  80. s2.addremove = true
  81. s2.anonymous = true
  82. function s2.create(...)
  83. local id = TypedSection.create(...)
  84. luci.http.redirect(s2.extedit % id)
  85. end
  86. o = s2:option(Flag, "ignore", translate("Enable"))
  87. o.rmempty = false
  88. o.width = "30px"
  89. function o.cfgvalue(...)
  90. local v = Flag.cfgvalue(...)
  91. return v == "1" and "0" or "1"
  92. end
  93. function o.write(self, section, value)
  94. Flag.write(self, section, value == "1" and "0" or "1")
  95. end
  96. o = s2:option(DummyValue, "interface", translate("Interface"))
  97. o.template = "cbi/network_netinfo"
  98. o.width = "10%"
  99. pfx = s2:option(DummyValue, "prefix", translate("Prefix"))
  100. pfx.width = "60%"
  101. function pfx.cfgvalue(self, section)
  102. local v = m.uci:get_list("radvd", section, self.option)
  103. local l = { }
  104. if not v or #v == 0 or (#v == 1 and #v[1] == 0) then
  105. local net = nm:get_network(m.uci:get("radvd", section, "interface"))
  106. if net then
  107. local ifc = nm:get_interface(net:ifname())
  108. if ifc then
  109. local adr
  110. for _, adr in ipairs(ifc:ip6addrs()) do
  111. if not adr:is6linklocal() then
  112. v = adr:string()
  113. break
  114. end
  115. end
  116. end
  117. end
  118. end
  119. for v in ut.imatch(v) do
  120. v = luci.ip.IPv6(v)
  121. if v then
  122. l[#l+1] = v:string()
  123. end
  124. end
  125. if #l == 0 then
  126. l[1] = "?"
  127. end
  128. return table.concat(l, ", ")
  129. end
  130. o = s2:option(DummyValue, "AdvAutonomous", translate("Autonomous"))
  131. function o.cfgvalue(...)
  132. local v = Value.cfgvalue(...)
  133. return v == "1" and translate("yes") or translate("no")
  134. end
  135. o = s2:option(DummyValue, "AdvOnLink", translate("On-link"))
  136. function o.cfgvalue(...)
  137. local v = Value.cfgvalue(...)
  138. return v == "1" and translate("yes") or translate("no")
  139. end
  140. o = s2:option(DummyValue, "AdvValidLifetime", translate("Validity time"))
  141. function o.cfgvalue(...)
  142. local v = Value.cfgvalue(...) or "86400"
  143. return translate(v)
  144. end
  145. --
  146. -- Routes
  147. --
  148. s3 = m:section(TypedSection, "route", translate("Routes"))
  149. s3.template = "cbi/tblsection"
  150. s3.extedit = luci.dispatcher.build_url("admin/network/radvd/route/%s")
  151. s3.addremove = true
  152. s3.anonymous = true
  153. function s3.create(...)
  154. local id = TypedSection.create(...)
  155. luci.http.redirect(s3.extedit % id)
  156. end
  157. o = s3:option(Flag, "ignore", translate("Enable"))
  158. o.rmempty = false
  159. o.width = "30px"
  160. function o.cfgvalue(...)
  161. local v = Flag.cfgvalue(...)
  162. return v == "1" and "0" or "1"
  163. end
  164. function o.write(self, section, value)
  165. Flag.write(self, section, value == "1" and "0" or "1")
  166. end
  167. o = s3:option(DummyValue, "interface", translate("Interface"))
  168. o.template = "cbi/network_netinfo"
  169. o.width = "10%"
  170. o = s3:option(DummyValue, "prefix", translate("Prefix"))
  171. o.width = "60%"
  172. o.cfgvalue = pfx.cfgvalue
  173. o = s3:option(DummyValue, "AdvRouteLifetime", translate("Lifetime"))
  174. function o.cfgvalue(self, section)
  175. local v = Value.cfgvalue(self, section) or "1800"
  176. return translate(v)
  177. end
  178. o = s3:option(DummyValue, "AdvRoutePreference", translate("Preference"))
  179. function o.cfgvalue(self, section)
  180. local v = Value.cfgvalue(self, section) or "medium"
  181. return translate(v)
  182. end
  183. --
  184. -- RDNSS
  185. --
  186. s4 = m:section(TypedSection, "rdnss", translate("RDNSS"))
  187. s4.template = "cbi/tblsection"
  188. s4.extedit = luci.dispatcher.build_url("admin/network/radvd/rdnss/%s")
  189. s4.addremove = true
  190. s4.anonymous = true
  191. function s4.create(...)
  192. local id = TypedSection.create(...)
  193. luci.http.redirect(s4.extedit % id)
  194. end
  195. o = s4:option(Flag, "ignore", translate("Enable"))
  196. o.rmempty = false
  197. o.width = "30px"
  198. function o.cfgvalue(...)
  199. local v = Flag.cfgvalue(...)
  200. return v == "1" and "0" or "1"
  201. end
  202. function o.write(self, section, value)
  203. Flag.write(self, section, value == "1" and "0" or "1")
  204. end
  205. o = s4:option(DummyValue, "interface", translate("Interface"))
  206. o.template = "cbi/network_netinfo"
  207. o.width = "10%"
  208. o = s4:option(DummyValue, "addr", translate("Address"))
  209. o.width = "60%"
  210. o.cfgvalue = pfx.cfgvalue
  211. o = s4:option(DummyValue, "AdvRDNSSLifetime", translate("Lifetime"))
  212. function o.cfgvalue(self, section)
  213. local v = Value.cfgvalue(self, section) or "1200"
  214. return translate(v)
  215. end
  216. --
  217. -- DNSSL
  218. --
  219. s5 = m:section(TypedSection, "dnssl", translate("DNSSL"))
  220. s5.template = "cbi/tblsection"
  221. s5.extedit = luci.dispatcher.build_url("admin/network/radvd/dnssl/%s")
  222. s5.addremove = true
  223. s5.anonymous = true
  224. function s5.create(...)
  225. local id = TypedSection.create(...)
  226. luci.http.redirect(s5.extedit % id)
  227. end
  228. o = s5:option(Flag, "ignore", translate("Enable"))
  229. o.rmempty = false
  230. o.width = "30px"
  231. function o.cfgvalue(...)
  232. local v = Flag.cfgvalue(...)
  233. return v == "1" and "0" or "1"
  234. end
  235. function o.write(self, section, value)
  236. Flag.write(self, section, value == "1" and "0" or "1")
  237. end
  238. o = s5:option(DummyValue, "interface", translate("Interface"))
  239. o.template = "cbi/network_netinfo"
  240. o.width = "10%"
  241. o = s5:option(DummyValue, "suffix", translate("Suffix"))
  242. o.width = "60%"
  243. function o.cfgvalue(self, section)
  244. local v = m.uci:get_list("radvd", section, "suffix")
  245. local l = { }
  246. for v in ut.imatch(v) do
  247. l[#l+1] = v
  248. end
  249. if #l == 0 then
  250. l[1] = "?"
  251. end
  252. return table.concat(l, ", ")
  253. end
  254. o = s5:option(DummyValue, "AdvDNSSLLifetime", translate("Lifetime"))
  255. function o.cfgvalue(self, section)
  256. local v = Value.cfgvalue(self, section) or "1200"
  257. return translate(v)
  258. end
  259. return m