olsrdiface.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local util = require "luci.util"
  4. local ip = require "luci.ip"
  5. function write_float(self, section, value)
  6. local n = tonumber(value)
  7. if n ~= nil then
  8. return Value.write(self, section, "%.1f" % n)
  9. end
  10. end
  11. m = Map("olsrd", translate("OLSR Daemon - Interface"),
  12. translate("The OLSR daemon is an implementation of the Optimized Link State Routing protocol. "..
  13. "As such it allows mesh routing for any network equipment. "..
  14. "It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. "..
  15. "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."))
  16. m.redirect = luci.dispatcher.build_url("admin/services/olsrd")
  17. if not arg[1] or m.uci:get("olsrd", arg[1]) ~= "Interface" then
  18. luci.http.redirect(m.redirect)
  19. return
  20. end
  21. i = m:section(NamedSection, arg[1], "Interface", translate("Interface"))
  22. i.anonymous = true
  23. i.addremove = false
  24. i:tab("general", translate("General Settings"))
  25. i:tab("addrs", translate("IP Addresses"))
  26. i:tab("timing", translate("Timing and Validity"))
  27. ign = i:taboption("general", Flag, "ignore", translate("Enable"),
  28. translate("Enable this interface."))
  29. ign.enabled = "0"
  30. ign.disabled = "1"
  31. ign.rmempty = false
  32. function ign.cfgvalue(self, section)
  33. return Flag.cfgvalue(self, section) or "0"
  34. end
  35. network = i:taboption("general", Value, "interface", translate("Network"),
  36. translate("The interface OLSRd should serve."))
  37. network.template = "cbi/network_netlist"
  38. network.widget = "radio"
  39. network.nocreate = true
  40. mode = i:taboption("general", ListValue, "Mode", translate("Mode"),
  41. translate("Interface Mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. "..
  42. "valid Modes are \"mesh\" and \"ether\". Default is \"mesh\"."))
  43. mode:value("mesh")
  44. mode:value("ether")
  45. mode.optional = true
  46. mode.rmempty = true
  47. weight = i:taboption("general", Value, "Weight", translate("Weight"),
  48. translate("When multiple links exist between hosts the weight of interface is used to determine the link to use. "..
  49. "Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, "..
  50. "but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />"..
  51. "<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. "..
  52. "For any other value of LinkQualityLevel, the interface ETX value is used instead."))
  53. weight.optional = true
  54. weight.datatype = "uinteger"
  55. weight.placeholder = "0"
  56. lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
  57. translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
  58. "It is only used when LQ-Level is greater than 0. Examples:<br />"..
  59. "reduce LQ to 192.168.0.1 by half: 192.168.0.1 0.5<br />"..
  60. "reduce LQ to all nodes on this interface by 20%: default 0.8"))
  61. lqmult.optional = true
  62. lqmult.rmempty = true
  63. lqmult.cast = "table"
  64. lqmult.placeholder = "default 1.0"
  65. function lqmult.validate(self, value)
  66. for _, v in pairs(value) do
  67. if v ~= "" then
  68. local val = util.split(v, " ")
  69. local host = val[1]
  70. local mult = val[2]
  71. if not host or not mult then
  72. return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) seperated by space.")
  73. end
  74. if not (host == "default" or ip.IPv4(host) or ip.IPv6(host)) then
  75. return nil, translate("Can only be a valid IPv4 or IPv6 address or 'default'")
  76. end
  77. if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
  78. return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
  79. end
  80. if not mult:match("[0-1]%.[0-9]+") then
  81. return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
  82. end
  83. end
  84. end
  85. return value
  86. end
  87. ip4b = i:taboption("addrs", Value, "Ip4Broadcast", translate("IPv4 broadcast"),
  88. translate("IPv4 broadcast address for outgoing OLSR packets. One useful example would be 255.255.255.255. "..
  89. "Default is \"0.0.0.0\", which triggers the usage of the interface broadcast IP."))
  90. ip4b.optional = true
  91. ip4b.datatype = "ip4addr"
  92. ip4b.placeholder = "0.0.0.0"
  93. ip6m = i:taboption("addrs", Value, "IPv6Multicast", translate("IPv6 multicast"),
  94. translate("IPv6 multicast address. Default is \"FF02::6D\", the manet-router linklocal multicast."))
  95. ip6m.optional = true
  96. ip6m.datatype = "ip6addr"
  97. ip6m.placeholder = "FF02::6D"
  98. ip4s = i:taboption("addrs", Value, "IPv4Src", translate("IPv4 source"),
  99. translate("IPv4 src address for outgoing OLSR packages. Default is \"0.0.0.0\", which triggers usage of the interface IP."))
  100. ip4s.optional = true
  101. ip4s.datatype = "ip4addr"
  102. ip4s.placeholder = "0.0.0.0"
  103. ip6s = i:taboption("addrs", Value, "IPv6Src", translate("IPv6 source"),
  104. translate("IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. "..
  105. "Default is \"0::/0\", which triggers the usage of a not-linklocal interface IP."))
  106. ip6s.optional = true
  107. ip6s.datatype = "ip6addr"
  108. ip6s.placeholder = "0::/0"
  109. hi = i:taboption("timing", Value, "HelloInterval", translate("Hello interval"))
  110. hi.optional = true
  111. hi.datatype = "ufloat"
  112. hi.placeholder = "5.0"
  113. hi.write = write_float
  114. hv = i:taboption("timing", Value, "HelloValidityTime", translate("Hello validity time"))
  115. hv.optional = true
  116. hv.datatype = "ufloat"
  117. hv.placeholder = "40.0"
  118. hv.write = write_float
  119. ti = i:taboption("timing", Value, "TcInterval", translate("TC interval"))
  120. ti.optional = true
  121. ti.datatype = "ufloat"
  122. ti.placeholder = "2.0"
  123. ti.write = write_float
  124. tv = i:taboption("timing", Value, "TcValidityTime", translate("TC validity time"))
  125. tv.optional = true
  126. tv.datatype = "ufloat"
  127. tv.placeholder = "256.0"
  128. tv.write = write_float
  129. mi = i:taboption("timing", Value, "MidInterval", translate("MID interval"))
  130. mi.optional = true
  131. mi.datatype = "ufloat"
  132. mi.placeholder = "18.0"
  133. mi.write = write_float
  134. mv = i:taboption("timing", Value, "MidValidityTime", translate("MID validity time"))
  135. mv.optional = true
  136. mv.datatype = "ufloat"
  137. mv.placeholder = "324.0"
  138. mv.write = write_float
  139. ai = i:taboption("timing", Value, "HnaInterval", translate("HNA interval"))
  140. ai.optional = true
  141. ai.datatype = "ufloat"
  142. ai.placeholder = "18.0"
  143. ai.write = write_float
  144. av = i:taboption("timing", Value, "HnaValidityTime", translate("HNA validity time"))
  145. av.optional = true
  146. av.datatype = "ufloat"
  147. av.placeholder = "108.0"
  148. av.write = write_float
  149. return m