prefix.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 - Prefix"),
  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) ~= "prefix" then
  11. luci.http.redirect(m.redirect)
  12. return
  13. end
  14. s = m:section(NamedSection, sid, "interface", translate("Prefix Configuration"))
  15. s.addremove = false
  16. s:tab("general", translate("General"))
  17. s:tab("advanced", translate("Advanced"))
  18. --
  19. -- General
  20. --
  21. o = s:taboption("general", Flag, "ignore", translate("Enable"))
  22. o.rmempty = false
  23. function o.cfgvalue(...)
  24. local v = Flag.cfgvalue(...)
  25. return v == "1" and "0" or "1"
  26. end
  27. function o.write(self, section, value)
  28. Flag.write(self, section, value == "1" and "0" or "1")
  29. end
  30. o = s:taboption("general", Value, "interface", translate("Interface"),
  31. translate("Specifies the logical interface name this section belongs to"))
  32. o.template = "cbi/network_netlist"
  33. o.nocreate = true
  34. o.optional = false
  35. function o.formvalue(...)
  36. return Value.formvalue(...) or "-"
  37. end
  38. function o.validate(self, value)
  39. if value == "-" then
  40. return nil, translate("Interface required")
  41. end
  42. return value
  43. end
  44. function o.write(self, section, value)
  45. m.uci:set("radvd", section, "ignore", 0)
  46. m.uci:set("radvd", section, "interface", value)
  47. end
  48. o = s:taboption("general", DynamicList, "prefix", translate("Prefixes"),
  49. translate("Advertised IPv6 prefixes. If empty, the current interface prefix is used"))
  50. o.optional = true
  51. o.datatype = "ip6addr"
  52. o.placeholder = translate("default")
  53. function o.cfgvalue(self, section)
  54. local l = { }
  55. local v = m.uci:get_list("radvd", section, "prefix")
  56. for v in utl.imatch(v) do
  57. l[#l+1] = v
  58. end
  59. return l
  60. end
  61. o = s:taboption("general", Flag, "AdvOnLink", translate("On-link determination"),
  62. translate("Indicates that this prefix can be used for on-link determination (RFC4861)"))
  63. o.rmempty = false
  64. o.default = "1"
  65. o = s:taboption("general", Flag, "AdvAutonomous", translate("Autonomous"),
  66. translate("Indicates that this prefix can be used for autonomous address configuration (RFC4862)"))
  67. o.rmempty = false
  68. o.default = "1"
  69. --
  70. -- Advanced
  71. --
  72. o = s:taboption("advanced", Flag, "AdvRouterAddr", translate("Advertise router address"),
  73. translate("Indicates that the address of interface is sent instead of network prefix, as is required by Mobile IPv6"))
  74. o = s:taboption("advanced", Value, "AdvValidLifetime", translate("Valid lifetime"),
  75. translate("Advertises the length of time in seconds that the prefix is valid for the purpose of on-link determination."))
  76. o.datatype = 'or(uinteger,"infinity")'
  77. o.placeholder = 86400
  78. o = s:taboption("advanced", Value, "AdvPreferredLifetime", translate("Preferred lifetime"),
  79. translate("Advertises the length of time in seconds that addresses generated from the prefix via stateless address autoconfiguration remain preferred."))
  80. o.datatype = 'or(uinteger,"infinity")'
  81. o.placeholder = 14400
  82. o = s:taboption("advanced", Value, "Base6to4Interface", translate("6to4 interface"),
  83. 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"))
  84. o.template = "cbi/network_netlist"
  85. o.nocreate = true
  86. o.unspecified = true
  87. return m