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.
5 require("luci.tools.webadmin")
6 local fs = require "nixio.fs"
7 local util = require "luci.util"
8 local ip = require "luci.ip"
10 local has_ipip = fs.glob("/etc/modules.d/[0-9]*-ipip")()
12 m = Map("olsrd6", translate("OLSR Daemon"),
13 translate("The OLSR daemon is an implementation of the Optimized Link State Routing protocol. "..
14 "As such it allows mesh routing for any network equipment. "..
15 "It runs on any wifi card that supports ad-hoc mode and of course on any ethernet device. "..
16 "Visit <a href='http://www.olsr.org'>olsrd.org</a> for help and documentation."))
19 local has_defaults = false
21 m.uci:foreach("olsrd6", "InterfaceDefaults",
27 if not has_defaults then
28 m.uci:section("olsrd6", "InterfaceDefaults")
32 function write_float(self, section, value)
33 local n = tonumber(value)
35 return Value.write(self, section, "%.1f" % n)
39 s = m:section(TypedSection, "olsrd6", translate("General settings"))
42 s:tab("general", translate("General Settings"))
43 s:tab("lquality", translate("Link Quality Settings"))
44 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."))
45 s:tab("advanced", translate("Advanced Settings"))
47 poll = s:taboption("advanced", Value, "Pollrate", translate("Pollrate"),
48 translate("Polling rate for OLSR sockets in seconds. Default is 0.05."))
50 poll.datatype = "ufloat"
51 poll.placeholder = "0.05"
53 nicc = s:taboption("advanced", Value, "NicChgsPollInt", translate("Nic changes poll interval"),
54 translate("Interval to poll network interfaces for configuration changes (in seconds). Default is \"2.5\"."))
56 nicc.datatype = "ufloat"
57 nicc.placeholder = "2.5"
59 tos = s:taboption("advanced", Value, "TosValue", translate("TOS value"),
60 translate("Type of service value for the IP header of control traffic. Default is \"16\"."))
62 tos.datatype = "uinteger"
63 tos.placeholder = "16"
65 fib = s:taboption("general", ListValue, "FIBMetric", translate("FIB metric"),
66 translate ("FIBMetric controls the metric value of the host-routes OLSRd sets. "..
67 "\"flat\" means that the metric value is always 2. This is the preferred value "..
68 "because it helps the linux kernel routing to clean up older routes. "..
69 "\"correct\" uses the hopcount as the metric value. "..
70 "\"approx\" use the hopcount as the metric value too, but does only update the hopcount if the nexthop changes too. "..
71 "Default is \"flat\"."))
76 lql = s:taboption("lquality", ListValue, "LinkQualityLevel", translate("LQ level"),
77 translate("Link quality level switch between hopcount and cost-based (mostly ETX) routing.<br />"..
78 "<b>0</b> = do not use link quality<br />"..
79 "<b>2</b> = use link quality for MPR selection and routing<br />"..
84 lqage = s:taboption("lquality", Value, "LinkQualityAging", translate("LQ aging"),
85 translate("Link quality aging factor (only for lq level 2). Tuning parameter for etx_float and etx_fpm, smaller values "..
86 "mean slower changes of ETX value. (allowed values are between 0.01 and 1.0)"))
88 lqage:depends("LinkQualityLevel", "2")
90 lqa = s:taboption("lquality", ListValue, "LinkQualityAlgorithm", translate("LQ algorithm"),
91 translate("Link quality algorithm (only for lq level 2).<br />"..
92 "<b>etx_float</b>: floating point ETX with exponential aging<br />"..
93 "<b>etx_fpm</b> : same as etx_float, but with integer arithmetic<br />"..
94 "<b>etx_ff</b> : ETX freifunk, an etx variant which use all OLSR traffic (instead of only hellos) for ETX calculation<br />"..
95 "<b>etx_ffeth</b>: incompatible variant of etx_ff that allows ethernet links with ETX 0.1.<br />"..
96 "Defaults to \"etx_ff\""))
100 lqa:value("etx_float")
101 lqa:value("etx_ffeth")
102 lqa:depends("LinkQualityLevel", "2")
105 lqfish = s:taboption("lquality", Flag, "LinkQualityFishEye", translate("LQ fisheye"),
106 translate("Fisheye mechanism for TCs (checked means on). Default is \"on\""))
108 lqfish.optional = true
110 hyst = s:taboption("lquality", Flag, "UseHysteresis", translate("Use hysteresis"),
111 translate("Hysteresis for link sensing (only for hopcount metric). Hysteresis adds more robustness to the link sensing "..
112 "but delays neighbor registration. Defaults is \"yes\""))
116 hyst:depends("LinkQualityLevel", "0")
120 port = s:taboption("general", Value, "OlsrPort", translate("Port"),
121 translate("The port OLSR uses. This should usually stay at the IANA assigned port 698. It can have a value between 1 and 65535."))
126 mainip = s:taboption("general", Value, "MainIp", translate("Main IP"),
127 translate("Sets the main IP (originator ip) of the router. This IP will NEVER change during the uptime of olsrd. "..
128 "Default is ::, which triggers usage of the IP of the first interface."))
129 mainip.optional = true
130 mainip.rmempty = true
131 mainip.datatype = "ipaddr"
132 mainip.placeholder = "::"
134 sgw = s:taboption("smartgw", Flag, "SmartGateway", translate("Enable"), translate("Enable SmartGateway. If it is disabled, then " ..
135 "all other SmartGateway parameters are ignored. Default is \"no\"."))
141 sgwnat = s:taboption("smartgw", Flag, "SmartGatewayAllowNAT", translate("Allow gateways with NAT"), translate("Allow the selection of an outgoing ipv4 gateway with NAT"))
142 sgwnat:depends("SmartGateway", "yes")
146 sgwnat.optional = true
147 sgwnat.rmempty = true
149 sgwuplink = s:taboption("smartgw", ListValue, "SmartGatewayUplink", translate("Announce uplink"), translate("Which kind of uplink is exported to the other mesh nodes. " ..
150 "An uplink is detected by looking for a local HNA6 ::ffff:0:0/96 or 2000::/3. Default setting is \"both\"."))
151 sgwuplink:value("none")
152 sgwuplink:value("ipv4")
153 sgwuplink:value("ipv6")
154 sgwuplink:value("both")
155 sgwuplink:depends("SmartGateway", "yes")
156 sgwuplink.default="both"
157 sgwuplink.optional = true
158 sgwuplink.rmempty = true
160 sgwulnat = s:taboption("smartgw", Flag, "SmartGatewayUplinkNAT", translate("Uplink uses NAT"), translate("If this Node uses NAT for connections to the internet. " ..
161 "Default is \"yes\"."))
162 sgwulnat:depends("SmartGatewayUplink", "ipv4")
163 sgwulnat:depends("SmartGatewayUplink", "both")
164 sgwulnat.default="yes"
165 sgwulnat.enabled="yes"
166 sgwulnat.disabled="no"
167 sgwnat.optional = true
168 sgwnat.rmempty = true
170 sgwspeed = s:taboption("smartgw", Value, "SmartGatewaySpeed", translate("Speed of the uplink"), translate("Specifies the speed of "..
171 "the uplink in kilobits/s. First parameter is upstream, second parameter is downstream. Default is \"128 1024\"."))
172 sgwspeed:depends("SmartGatewayUplink", "ipv4")
173 sgwspeed:depends("SmartGatewayUplink", "ipv6")
174 sgwspeed:depends("SmartGatewayUplink", "both")
175 sgwspeed.optional = true
176 sgwspeed.rmempty = true
178 sgwprefix = s:taboption("smartgw", Value, "SmartGatewayPrefix", translate("IPv6-Prefix of the uplink"), translate("This can be used " ..
179 "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 " ..
180 "use the IPv6 gateway without any kind of address translation. The maximum prefix length is 64 bits. " ..
181 "Default is \"::/0\" (no prefix)."))
182 sgwprefix:depends("SmartGatewayUplink", "ipv6")
183 sgwprefix:depends("SmartGatewayUplink", "both")
184 sgwprefix.optional = true
185 sgwprefix.rmempty = true
187 willingness = s:taboption("advanced", ListValue, "Willingness", translate("Willingness"),
188 translate("The fixed willingness to use. If not set willingness will be calculated dynamically based on battery/power status. Default is \"3\"."))
192 willingness.optional = true
193 willingness.default = "3"
195 natthr = s:taboption("advanced", Value, "NatThreshold", translate("NAT threshold"),
196 translate("If the route to the current gateway is to be changed, the ETX value of this gateway is "..
197 "multiplied with this value before it is compared to the new one. "..
198 "The parameter can be a value between 0.1 and 1.0, but should be close to 1.0 if changed.<br />"..
199 "<b>WARNING:</b> This parameter should not be used together with the etx_ffeth metric!<br />"..
200 "Defaults to \"1.0\"."))
204 natthr:depends("LinkQualityAlgorithm", "etx_ff")
205 natthr:depends("LinkQualityAlgorithm", "etx_float")
206 natthr:depends("LinkQualityAlgorithm", "etx_fpm")
207 natthr.default = "1.0"
208 natthr.optional = true
209 natthr.write = write_float
212 i = m:section(TypedSection, "InterfaceDefaults", translate("Interfaces Defaults"))
216 i:tab("general", translate("General Settings"))
217 i:tab("addrs", translate("IP Addresses"))
218 i:tab("timing", translate("Timing and Validity"))
220 mode = i:taboption("general", ListValue, "Mode", translate("Mode"),
221 translate("Interface Mode is used to prevent unnecessary packet forwarding on switched ethernet interfaces. "..
222 "valid Modes are \"mesh\" and \"ether\". Default is \"mesh\"."))
229 weight = i:taboption("general", Value, "Weight", translate("Weight"),
230 translate("When multiple links exist between hosts the weight of interface is used to determine the link to use. "..
231 "Normally the weight is automatically calculated by olsrd based on the characteristics of the interface, "..
232 "but here you can specify a fixed value. Olsrd will choose links with the lowest value.<br />"..
233 "<b>Note:</b> Interface weight is used only when LinkQualityLevel is set to 0. "..
234 "For any other value of LinkQualityLevel, the interface ETX value is used instead."))
235 weight.optional = true
236 weight.datatype = "uinteger"
237 weight.placeholder = "0"
239 lqmult = i:taboption("general", DynamicList, "LinkQualityMult", translate("LinkQuality Multiplicator"),
240 translate("Multiply routes with the factor given here. Allowed values are between 0.01 and 1.0. "..
241 "It is only used when LQ-Level is greater than 0. Examples:<br />"..
242 "reduce LQ to fd91:662e:3c58::1 by half: fd91:662e:3c58::1 0.5<br />"..
243 "reduce LQ to all nodes on this interface by 20%: default 0.8"))
244 lqmult.optional = true
245 lqmult.rmempty = true
246 lqmult.cast = "table"
247 lqmult.placeholder = "default 1.0"
249 function lqmult.validate(self, value)
250 for _, v in pairs(value) do
252 local val = util.split(v, " ")
255 if not host or not mult then
256 return nil, translate("LQMult requires two values (IP address or 'default' and multiplicator) separated by space.")
258 if not (host == "default" or ip.IPv6(host)) then
259 return nil, translate("Can only be a valid IPv6 address or 'default'")
261 if not tonumber(mult) or tonumber(mult) > 1 or tonumber(mult) < 0.01 then
262 return nil, translate("Invalid Value for LQMult-Value. Must be between 0.01 and 1.0.")
264 if not mult:match("[0-1]%.[0-9]+") then
265 return nil, translate("Invalid Value for LQMult-Value. You must use a decimal number between 0.01 and 1.0 here.")
272 ip6m = i:taboption("addrs", Value, "IPv6Multicast", translate("IPv6 multicast"),
273 translate("IPv6 multicast address. Default is \"FF02::6D\", the manet-router linklocal multicast."))
275 ip6m.datatype = "ip6addr"
276 ip6m.placeholder = "FF02::6D"
278 ip6s = i:taboption("addrs", Value, "IPv6Src", translate("IPv6 source"),
279 translate("IPv6 src prefix. OLSRd will choose one of the interface IPs which matches the prefix of this parameter. "..
280 "Default is \"0::/0\", which triggers the usage of a not-linklocal interface IP."))
282 ip6s.datatype = "ip6addr"
283 ip6s.placeholder = "0::/0"
286 hi = i:taboption("timing", Value, "HelloInterval", translate("Hello interval"))
288 hi.datatype = "ufloat"
289 hi.placeholder = "5.0"
290 hi.write = write_float
292 hv = i:taboption("timing", Value, "HelloValidityTime", translate("Hello validity time"))
294 hv.datatype = "ufloat"
295 hv.placeholder = "40.0"
296 hv.write = write_float
298 ti = i:taboption("timing", Value, "TcInterval", translate("TC interval"))
300 ti.datatype = "ufloat"
301 ti.placeholder = "2.0"
302 ti.write = write_float
304 tv = i:taboption("timing", Value, "TcValidityTime", translate("TC validity time"))
306 tv.datatype = "ufloat"
307 tv.placeholder = "256.0"
308 tv.write = write_float
310 mi = i:taboption("timing", Value, "MidInterval", translate("MID interval"))
312 mi.datatype = "ufloat"
313 mi.placeholder = "18.0"
314 mi.write = write_float
316 mv = i:taboption("timing", Value, "MidValidityTime", translate("MID validity time"))
318 mv.datatype = "ufloat"
319 mv.placeholder = "324.0"
320 mv.write = write_float
322 ai = i:taboption("timing", Value, "HnaInterval", translate("HNA interval"))
324 ai.datatype = "ufloat"
325 ai.placeholder = "18.0"
326 ai.write = write_float
328 av = i:taboption("timing", Value, "HnaValidityTime", translate("HNA validity time"))
330 av.datatype = "ufloat"
331 av.placeholder = "108.0"
332 av.write = write_float
335 ifs = m:section(TypedSection, "Interface", translate("Interfaces"))
338 ifs.extedit = luci.dispatcher.build_url("admin/services/olsrd6/iface/%s")
339 ifs.template = "cbi/tblsection"
341 function ifs.create(...)
342 local sid = TypedSection.create(...)
343 luci.http.redirect(ifs.extedit % sid)
346 ign = ifs:option(Flag, "ignore", translate("Enable"))
350 function ign.cfgvalue(self, section)
351 return Flag.cfgvalue(self, section) or "0"
354 network = ifs:option(DummyValue, "interface", translate("Network"))
355 network.template = "cbi/network_netinfo"
357 mode = ifs:option(DummyValue, "Mode", translate("Mode"))
358 function mode.cfgvalue(...)
359 return Value.cfgvalue(...) or m.uci:get_first("olsrd6", "InterfaceDefaults", "Mode", "mesh")
362 hello = ifs:option(DummyValue, "_hello", translate("Hello"))
363 function hello.cfgvalue(self, section)
364 local i = tonumber(m.uci:get("olsrd6", section, "HelloInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HelloInterval", 5))
365 local v = tonumber(m.uci:get("olsrd6", section, "HelloValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HelloValidityTime", 40))
366 return "%.01fs / %.01fs" %{ i, v }
369 tc = ifs:option(DummyValue, "_tc", translate("TC"))
370 function tc.cfgvalue(self, section)
371 local i = tonumber(m.uci:get("olsrd6", section, "TcInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "TcInterval", 2))
372 local v = tonumber(m.uci:get("olsrd6", section, "TcValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "TcValidityTime", 256))
373 return "%.01fs / %.01fs" %{ i, v }
376 mid = ifs:option(DummyValue, "_mid", translate("MID"))
377 function mid.cfgvalue(self, section)
378 local i = tonumber(m.uci:get("olsrd6", section, "MidInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "MidInterval", 18))
379 local v = tonumber(m.uci:get("olsrd6", section, "MidValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "MidValidityTime", 324))
380 return "%.01fs / %.01fs" %{ i, v }
383 hna = ifs:option(DummyValue, "_hna", translate("HNA"))
384 function hna.cfgvalue(self, section)
385 local i = tonumber(m.uci:get("olsrd6", section, "HnaInterval")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HnaInterval", 18))
386 local v = tonumber(m.uci:get("olsrd6", section, "HnaValidityTime")) or tonumber(m.uci:get_first("olsrd6", "InterfaceDefaults", "HnaValidityTime", 108))
387 return "%.01fs / %.01fs" %{ i, v }