olsrd6.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. require("luci.tools.webadmin")
  5. local fs = require "nixio.fs"
  6. local util = require "luci.util"
  7. local ip = require "luci.ip"
  8. local has_ipip = fs.glob("/etc/modules.d/[0-9]*-ipip")()
  9. m = Map("olsrd6", translate("OLSR Daemon"),
  10. translate("The OLSR daemon is an implementation of the Optimized Link State Routing protocol. "..
  11. "As such it allows mesh routing for any network equipment. "..
  12. "It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. "..
  13. "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."))
  14. function m.on_parse()
  15. local has_defaults = false
  16. m.uci:foreach("olsrd6", "InterfaceDefaults",
  17. function(s)
  18. has_defaults = true
  19. return false
  20. end)
  21. if not has_defaults then
  22. m.uci:section("olsrd6", "InterfaceDefaults")
  23. end
  24. end
  25. function write_float(self, section, value)
  26. local n = tonumber(value)
  27. if n ~= nil then
  28. return Value.write(self, section, "%.1f" % n)
  29. end
  30. end
  31. s = m:section(TypedSection, "olsrd6", translate("General settings"))
  32. s.anonymous = true
  33. s:tab("general", translate("General Settings"))
  34. s:tab("lquality", translate("Link Quality Settings"))
  35. s:tab("smartgw", translate("SmartGW"), not has_ipip and translate("Warning: kmod-ipip is not installed. Without kmod-ipip SmartGateway will not work, please install it."))
  36. s:tab("advanced", translate("Advanced Settings"))
  37. poll = s:taboption("advanced", Value, "Pollrate", translate("Pollrate"),
  38. translate("Polling rate for OLSR sockets in seconds. Default is 0.05."))
  39. poll.optional = true
  40. poll.datatype = "ufloat"
  41. poll.placeholder = "0.05"
  42. nicc = s:taboption("advanced", Value, "NicChgsPollInt", translate("Nic changes poll interval"),
  43. translate("Interval to poll network interfaces for configuration changes (in seconds). Default is \"2.5\"."))
  44. nicc.optional = true
  45. nicc.datatype = "ufloat"
  46. nicc.placeholder = "2.5"
  47. tos = s:taboption("advanced", Value, "TosValue", translate("TOS value"),
  48. translate("Type of service value for the IP header of control traffic. Default is \"16\"."))
  49. tos.optional = true
  50. tos.datatype = "uinteger"
  51. tos.placeholder = "16"
  52. fib = s:taboption("general", ListValue, "FIBMetric", translate("FIB metric"),
  53. translate ("FIBMetric controls the metric value of the host-routes OLSRd sets. "..
  54. "\"flat\" means that the metric value is always 2. This is the preferred value "..
  55. "because it helps the linux kernel routing to clean up older routes. "..
  56. "\"correct\" uses the hopcount as the metric value. "..
  57. "\"approx\" use the hopcount as the metric value too, but does only update the hopcount if the nexthop changes too. "..
  58. "Default is \"flat\"."))
  59. fib:value("flat")
  60. fib:value("correct")
  61. fib:value("approx")
  62. lql = s:taboption("lquality", ListValue, "LinkQualityLevel", translate("LQ level"),
  63. translate("Link quality level switch between hopcount and cost-based (mostly ETX) routing.<br />"..
  64. "<b>0</b> = do not use link quality<br />"..
  65. "<b>2</b> = use link quality for MPR selection and routing<br />"..
  66. "Default is \"2\""))
  67. lql:value("2")
  68. lql:value("0")
  69. lqage = s:taboption("lquality", Value, "LinkQualityAging", translate("LQ aging"),
  70. translate("Link quality aging factor (only for lq level 2). Tuning parameter for etx_float and etx_fpm, smaller values "..
  71. "mean slower changes of ETX value. (allowed values are between 0.01 and 1.0)"))
  72. lqage.optional = true
  73. lqage:depends("LinkQualityLevel", "2")
  74. lqa = s:taboption("lquality", ListValue, "LinkQualityAlgorithm", translate("LQ algorithm"),
  75. translate("Link quality algorithm (only for lq level 2).<br />"..
  76. "<b>etx_float</b>: floating point ETX with exponential aging<br />"..
  77. "<b>etx_fpm</b> : same as etx_float, but with integer arithmetic<br />"..
  78. "<b>etx_ff</b> : ETX freifunk, an etx variant which use all OLSR traffic (instead of only hellos) for ETX calculation<br />"..
  79. "<b>etx_ffeth</b>: incompatible variant of etx_ff that allows ethernet links with ETX 0.1.<br />"..
  80. "Defaults to \"etx_ff\""))
  81. lqa.optional = true
  82. lqa:value("etx_ff")
  83. lqa:value("etx_fpm")
  84. lqa:value("etx_float")
  85. lqa:value("etx_ffeth")
  86. lqa:depends("LinkQualityLevel", "2")
  87. lqa.optional = true
  88. lqfish = s:taboption("lquality", Flag, "LinkQualityFishEye", translate("LQ fisheye"),
  89. translate("Fisheye mechanism for TCs (checked means on). Default is \"on\""))
  90. lqfish.default = "1"
  91. lqfish.optional = true
  92. hyst = s:taboption("lquality", Flag, "UseHysteresis", translate("Use hysteresis"),
  93. translate("Hysteresis for link sensing (only for hopcount metric). Hysteresis adds more robustness to the link sensing "..
  94. "but delays neighbor registration. Defaults is \"yes\""))
  95. hyst.default = "yes"
  96. hyst.enabled = "yes"
  97. hyst.disabled = "no"
  98. hyst:depends("LinkQualityLevel", "0")
  99. hyst.optional = true
  100. hyst.rmempty = true
  101. port = s:taboption("general", Value, "OlsrPort", translate("Port"),
  102. translate("The port OLSR uses. This should usually stay at the IANA assigned port 698. It can have a value between 1 and 65535."))
  103. port.optional = true
  104. port.default = "698"
  105. port.rmempty = true
  106. mainip = s:taboption("general", Value, "MainIp", translate("Main IP"),
  107. translate("Sets the main IP (originator ip) of the router. This IP will NEVER change during the uptime of olsrd. "..
  108. "Default is ::, which triggers usage of the IP of the first interface."))
  109. mainip.optional = true
  110. mainip.rmempty = true
  111. mainip.datatype = "ipaddr"
  112. mainip.placeholder = "::"
  113. sgw = s:taboption("smartgw", Flag, "SmartGateway", translate("Enable"), translate("Enable SmartGateway. If it is disabled, then " ..
  114. "all other SmartGateway parameters are ignored. Default is \"no\"."))
  115. sgw.default="no"
  116. sgw.enabled="yes"
  117. sgw.disabled="no"
  118. sgw.rmempty = true
  119. sgwnat = s:taboption("smartgw", Flag, "SmartGatewayAllowNAT", translate("Allow gateways with NAT"), translate("Allow the selection of an outgoing ipv4 gateway with NAT"))
  120. sgwnat:depends("SmartGateway", "yes")
  121. sgwnat.default="yes"
  122. sgwnat.enabled="yes"
  123. sgwnat.disabled="no"
  124. sgwnat.optional = true
  125. sgwnat.rmempty = true
  126. sgwuplink = s:taboption("smartgw", ListValue, "SmartGatewayUplink", translate("Announce uplink"), translate("Which kind of uplink is exported to the other mesh nodes. " ..
  127. "An uplink is detected by looking for a local HNA6 ::ffff:0:0/96 or 2000::/3. Default setting is \"both\"."))
  128. sgwuplink:value("none")
  129. sgwuplink:value("ipv4")
  130. sgwuplink:value("ipv6")
  131. sgwuplink:value("both")
  132. sgwuplink:depends("SmartGateway", "yes")
  133. sgwuplink.default="both"
  134. sgwuplink.optional = true
  135. sgwuplink.rmempty = true
  136. sgwulnat = s:taboption("smartgw", Flag, "SmartGatewayUplinkNAT", translate("Uplink uses NAT"), translate("If this Node uses NAT for connections to the internet. " ..
  137. "Default is \"yes\"."))
  138. sgwulnat:depends("SmartGatewayUplink", "ipv4")
  139. sgwulnat:depends("SmartGatewayUplink", "both")
  140. sgwulnat.default="yes"
  141. sgwulnat.enabled="yes"
  142. sgwulnat.disabled="no"
  143. sgwnat.optional = true
  144. sgwnat.rmempty = true
  145. sgwspeed = s:taboption("smartgw", Value, "SmartGatewaySpeed", translate("Speed of the uplink"), translate("Specifies the speed of "..
  146. "the uplink in kilobits/s. First parameter is upstream, second parameter is downstream. Default is \"128 1024\"."))
  147. sgwspeed:depends("SmartGatewayUplink", "ipv4")
  148. sgwspeed:depends("SmartGatewayUplink", "ipv6")
  149. sgwspeed:depends("SmartGatewayUplink", "both")
  150. sgwspeed.optional = true
  151. sgwspeed.rmempty = true
  152. sgwprefix = s:taboption("smartgw", Value, "SmartGatewayPrefix", translate("IPv6-Prefix of the uplink"), translate("This can be used " ..
  153. "to signal the external IPv6 prefix of the uplink to the clients. This might allow a client to change it's local IPv6 address to " ..
  154. "use the IPv6 gateway without any kind of address translation. The maximum prefix length is 64 bits. " ..
  155. "Default is \"::/0\" (no prefix)."))
  156. sgwprefix:depends("SmartGatewayUplink", "ipv6")
  157. sgwprefix:depends("SmartGatewayUplink", "both")
  158. sgwprefix.optional = true
  159. sgwprefix.rmempty = true
  160. willingness = s:taboption("advanced", ListValue, "Willingness", translate("Willingness"),
  161. translate("The fixed willingness to use. If not set willingness will be calculated dynamically based on battery/power status. Default is \"3\"."))
  162. for i=0,7 do
  163. willingness:value(i)
  164. end
  165. willingness.optional = true
  166. willingness.default = "3"
  167. natthr = s:taboption("advanced", Value, "NatThreshold", translate("NAT threshold"),
  168. translate("If the route to the current gateway is to be changed, the ETX value of this gateway is "..
  169. "multiplied with this value before it is compared to the new one. "..
  170. "The parameter can be a value between 0.1 and 1.0, but should be close to 1.0 if changed.<br />"..
  171. "<b>WARNING:</b> This parameter should not be used together with the etx_ffeth metric!<br />"..
  172. "Defaults to \"1.0\"."))
  173. for i=1,0.1,-0.1 do
  174. natthr:value(i)
  175. end
  176. natthr:depends("LinkQualityAlgorithm", "etx_ff")
  177. natthr:depends("LinkQualityAlgorithm", "etx_float")
  178. natthr:depends("LinkQualityAlgorithm", "etx_fpm")
  179. natthr.default = "1.0"
  180. natthr.optional = true
  181. natthr.write = write_float
  182. i = m:section(TypedSection, "InterfaceDefaults", translate("Interfaces Defaults"))
  183. i.anonymous = true
  184. i.addremove = false
  185. i:tab("general", translate("General Settings"))
  186. i:tab("addrs", translate("IP Addresses"))
  187. i:tab("timing", translate("Timing and Validity"))
  188. mode = i:taboption("general", ListValue, "Mode", translate("Mode"),
  189. translate("Interface Mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. "..
  190. "valid Modes are \"mesh\" and \"ether\". Default is \"mesh\"."))
  191. mode:value("mesh")
  192. mode:value("ether")
  193. mode.optional = true
  194. mode.rmempty = true
  195. weight = i:taboption("general", Value, "Weight", translate("Weight"),
  196. translate("When multiple links exist between hosts the weight of interface is used to determine the link to use. "..
  197. "Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, "..
  198. "but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />"..
  199. "<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. "..
  200. "For any other value of LinkQualityLevel, the interface ETX value is used instead."))
  201. weight.optional = true
  202. weight.datatype = "uinteger"
  203. weight.placeholder = "0"
  204. lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
  205. translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
  206. "It is only used when LQ-Level is greater than 0. Examples:<br />"..
  207. "reduce LQ to fd91:662e:3c58::1 by half: fd91:662e:3c58::1 0.5<br />"..
  208. "reduce LQ to all nodes on this interface by 20%: default 0.8"))
  209. lqmult.optional = true
  210. lqmult.rmempty = true
  211. lqmult.cast = "table"
  212. lqmult.placeholder = "default 1.0"
  213. function lqmult.validate(self, value)
  214. for _, v in pairs(value) do
  215. if v ~= "" then
  216. local val = util.split(v, " ")
  217. local host = val[1]
  218. local mult = val[2]
  219. if not host or not mult then
  220. return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) seperated by space.")
  221. end
  222. if not (host == "default" or ip.IPv6(host)) then
  223. return nil, translate("Can only be a valid IPv6 address or 'default'")
  224. end
  225. if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
  226. return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
  227. end
  228. if not mult:match("[0-1]%.[0-9]+") then
  229. return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
  230. end
  231. end
  232. end
  233. return value
  234. end
  235. ip6m = i:taboption("addrs", Value, "IPv6Multicast", translate("IPv6 multicast"),
  236. translate("IPv6 multicast address. Default is \"FF02::6D\", the manet-router linklocal multicast."))
  237. ip6m.optional = true
  238. ip6m.datatype = "ip6addr"
  239. ip6m.placeholder = "FF02::6D"
  240. ip6s = i:taboption("addrs", Value, "IPv6Src", translate("IPv6 source"),
  241. translate("IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. "..
  242. "Default is \"0::/0\", which triggers the usage of a not-linklocal interface IP."))
  243. ip6s.optional = true
  244. ip6s.datatype = "ip6addr"
  245. ip6s.placeholder = "0::/0"
  246. hi = i:taboption("timing", Value, "HelloInterval", translate("Hello interval"))
  247. hi.optional = true
  248. hi.datatype = "ufloat"
  249. hi.placeholder = "5.0"
  250. hi.write = write_float
  251. hv = i:taboption("timing", Value, "HelloValidityTime", translate("Hello validity time"))
  252. hv.optional = true
  253. hv.datatype = "ufloat"
  254. hv.placeholder = "40.0"
  255. hv.write = write_float
  256. ti = i:taboption("timing", Value, "TcInterval", translate("TC interval"))
  257. ti.optional = true
  258. ti.datatype = "ufloat"
  259. ti.placeholder = "2.0"
  260. ti.write = write_float
  261. tv = i:taboption("timing", Value, "TcValidityTime", translate("TC validity time"))
  262. tv.optional = true
  263. tv.datatype = "ufloat"
  264. tv.placeholder = "256.0"
  265. tv.write = write_float
  266. mi = i:taboption("timing", Value, "MidInterval", translate("MID interval"))
  267. mi.optional = true
  268. mi.datatype = "ufloat"
  269. mi.placeholder = "18.0"
  270. mi.write = write_float
  271. mv = i:taboption("timing", Value, "MidValidityTime", translate("MID validity time"))
  272. mv.optional = true
  273. mv.datatype = "ufloat"
  274. mv.placeholder = "324.0"
  275. mv.write = write_float
  276. ai = i:taboption("timing", Value, "HnaInterval", translate("HNA interval"))
  277. ai.optional = true
  278. ai.datatype = "ufloat"
  279. ai.placeholder = "18.0"
  280. ai.write = write_float
  281. av = i:taboption("timing", Value, "HnaValidityTime", translate("HNA validity time"))
  282. av.optional = true
  283. av.datatype = "ufloat"
  284. av.placeholder = "108.0"
  285. av.write = write_float
  286. ifs = m:section(TypedSection, "Interface", translate("Interfaces"))
  287. ifs.addremove = true
  288. ifs.anonymous = true
  289. ifs.extedit = luci.dispatcher.build_url("admin/services/olsrd6/iface/%s")
  290. ifs.template = "cbi/tblsection"
  291. function ifs.create(...)
  292. local sid = TypedSection.create(...)
  293. luci.http.redirect(ifs.extedit % sid)
  294. end
  295. ign = ifs:option(Flag, "ignore", translate("Enable"))
  296. ign.enabled = "0"
  297. ign.disabled = "1"
  298. ign.rmempty = false
  299. function ign.cfgvalue(self, section)
  300. return Flag.cfgvalue(self, section) or "0"
  301. end
  302. network = ifs:option(DummyValue, "interface", translate("Network"))
  303. network.template = "cbi/network_netinfo"
  304. mode = ifs:option(DummyValue, "Mode", translate("Mode"))
  305. function mode.cfgvalue(...)
  306. return Value.cfgvalue(...) or m.uci:get_first("olsrd6", "InterfaceDefaults", "Mode", "mesh")
  307. end
  308. hello = ifs:option(DummyValue, "_hello", translate("Hello"))
  309. function hello.cfgvalue(self, section)
  310. local i = tonumber(m.uci:get("olsrd6", section, "HelloInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HelloInterval", 5))
  311. local v = tonumber(m.uci:get("olsrd6", section, "HelloValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HelloValidityTime", 40))
  312. return "%.01fs / %.01fs" %{ i, v }
  313. end
  314. tc = ifs:option(DummyValue, "_tc", translate("TC"))
  315. function tc.cfgvalue(self, section)
  316. local i = tonumber(m.uci:get("olsrd6", section, "TcInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "TcInterval", 2))
  317. local v = tonumber(m.uci:get("olsrd6", section, "TcValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "TcValidityTime", 256))
  318. return "%.01fs / %.01fs" %{ i, v }
  319. end
  320. mid = ifs:option(DummyValue, "_mid", translate("MID"))
  321. function mid.cfgvalue(self, section)
  322. local i = tonumber(m.uci:get("olsrd6", section, "MidInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "MidInterval", 18))
  323. local v = tonumber(m.uci:get("olsrd6", section, "MidValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "MidValidityTime", 324))
  324. return "%.01fs / %.01fs" %{ i, v }
  325. end
  326. hna = ifs:option(DummyValue, "_hna", translate("HNA"))
  327. function hna.cfgvalue(self, section)
  328. local i = tonumber(m.uci:get("olsrd6", section, "HnaInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HnaInterval", 18))
  329. local v = tonumber(m.uci:get("olsrd6", section, "HnaValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HnaValidityTime", 108))
  330. return "%.01fs / %.01fs" %{ i, v }
  331. end
  332. return m