route.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local sid = arg[1]
  4. local utl = require "luci.util"
  5. m = Map("radvd", translatef("Radvd - Route"),
  6. translate("Radvd is a router advertisement daemon for IPv6. " ..
  7. "It listens to router solicitations and sends router advertisements " ..
  8. "as described in RFC 4861."))
  9. m.redirect = luci.dispatcher.build_url("admin/network/radvd")
  10. if m.uci:get("radvd", sid) ~= "route" then
  11. luci.http.redirect(m.redirect)
  12. return
  13. end
  14. s = m:section(NamedSection, sid, "interface", translate("Route Configuration"))
  15. s.addremove = false
  16. --
  17. -- General
  18. --
  19. o = s:option(Flag, "ignore", translate("Enable"))
  20. o.rmempty = false
  21. function o.cfgvalue(...)
  22. local v = Flag.cfgvalue(...)
  23. return v == "1" and "0" or "1"
  24. end
  25. function o.write(self, section, value)
  26. Flag.write(self, section, value == "1" and "0" or "1")
  27. end
  28. o = s:option(Value, "interface", translate("Interface"),
  29. translate("Specifies the logical interface name this section belongs to"))
  30. o.template = "cbi/network_netlist"
  31. o.nocreate = true
  32. o.optional = false
  33. function o.formvalue(...)
  34. return Value.formvalue(...) or "-"
  35. end
  36. function o.validate(self, value)
  37. if value == "-" then
  38. return nil, translate("Interface required")
  39. end
  40. return value
  41. end
  42. function o.write(self, section, value)
  43. m.uci:set("radvd", section, "ignore", 0)
  44. m.uci:set("radvd", section, "interface", value)
  45. end
  46. o = s:option(DynamicList, "prefix", translate("Prefixes"),
  47. translate("Advertised IPv6 prefixes"))
  48. o.rmempty = false
  49. o.datatype = "ip6addr"
  50. o.placeholder = translate("default")
  51. function o.cfgvalue(self, section)
  52. local l = { }
  53. local v = m.uci:get_list("radvd", section, "prefix")
  54. for v in utl.imatch(v) do
  55. l[#l+1] = v
  56. end
  57. return l
  58. end
  59. o = s:option(Value, "AdvRouteLifetime", translate("Lifetime"),
  60. translate("Specifies the lifetime associated with the route in seconds."))
  61. o.datatype = 'or(uinteger,"infinity")'
  62. o.placeholder = 1800
  63. o = s:option(ListValue, "AdvRoutePreference", translate("Preference"),
  64. translate("Specifies the preference associated with the default router"))
  65. o.default = "medium"
  66. o:value("low", translate("low"))
  67. o:value("medium", translate("medium"))
  68. o:value("high", translate("high"))
  69. return m