olsrd.lua 17 KB

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