2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2005, Andreas Tonnesen(andreto@olsr.org)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of olsr.org, olsrd nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * Visit http://www.olsr.org for more information.
35 * If you find this software useful feel free to make a donation
36 * to the project. For more information see the website or contact
37 * the copyright holders.
41 #include "olsrd_conf.h"
42 #include "builddata.h"
43 #include "../ipcalc.h"
44 #include "../net_olsr.h"
45 #include "../common/autobuf.h"
46 #include "../egressTypes.h"
52 #include <sys/types.h>
53 #include <netinet/in.h>
54 #include <arpa/inet.h>
56 int olsrd_write_cnf(struct olsrd_config *cnf, const char *fname) {
60 fd = fopen(fname, "w");
63 fprintf(stderr, "Could not open file %s for writing\n%s\n", fname, strerror(errno));
67 printf("Writing config to file \"%s\".... ", fname);
68 abuf_init(&abuf, 1024);
69 olsrd_write_cnf_autobuf(&abuf, cnf);
70 if (fwrite(abuf.buf, abuf.len, 1, fd) < (size_t)abuf.len) {
71 fprintf(stderr, "Error, could not write the complete config file.\n");
82 if_appendf(struct autobuf *autobuf, bool comments, const char *fmt, ...) __attribute__ ((format(printf, 3, 4)));
85 if_appendf(struct autobuf *autobuf, bool comments, const char *fmt, ...)
93 first = va_arg(ap, char*);
101 rv = abuf_vappendf(autobuf, fmt, ap);
106 static void olsrd_write_if_autobuf(struct autobuf *out, struct if_config_options *cnfi, bool comments) {
107 struct ipaddr_str ipbuf;
108 struct olsr_lq_mult *mult;
110 abuf_puts(out, "{\n");
111 if (comments) abuf_appendf(out,
112 " # Interface Mode is used to prevent unnecessary\n"
113 " # packet forwarding on switched ethernet interfaces\n"
114 " # valid Modes are \"mesh\" and \"ether\"\n"
115 " # (default is \"%s\")\n"
116 "\n", OLSR_IF_MODE[DEF_IF_MODE]);
117 if_appendf(out, comments, " %sMode \"%s\"\n",
118 cnfi->mode == DEF_IF_MODE ? "# " : "",
119 OLSR_IF_MODE[cnfi->mode]);
120 if (comments) abuf_puts(out,
122 " # IPv4 broadcast address for outgoing OLSR packets.\n"
123 " # One useful example would be 255.255.255.255\n"
124 " # The second useful value would be to\n"
125 " # specify the peer address of an ptp-tunnel.\n"
126 " # another name of this parameter is \"IPv4Multicast\"\n"
127 " # (default is 0.0.0.0, which triggers the usage of the\n"
128 " # interface broadcast IP)\n"
130 if_appendf(out, comments, " %sIp4Broadcast %s\n",
131 cnfi->ipv4_multicast.v4.s_addr == 0 ? "# " : "",
132 inet_ntop(AF_INET, &cnfi->ipv4_multicast, ipbuf.buf, sizeof(ipbuf)));
133 if (comments) abuf_appendf(out,
135 " # IPv6 multicast address\n"
136 " # (default is %s, the manet-router linklocal multicast)\n"
137 "\n", inet_ntop(AF_INET6, &ipv6_def_multicast, ipbuf.buf, sizeof(ipbuf)));
138 if_appendf(out, comments, " %sIPv6Multicast %s\n",
139 memcmp(&cnfi->ipv6_multicast, &ipv6_def_multicast, sizeof(ipv6_def_multicast)) == 0 ? "# " : "",
140 inet_ntop(AF_INET6, &cnfi->ipv6_multicast, ipbuf.buf, sizeof(ipbuf)));
141 if (comments) abuf_puts(out,
143 " # IPv4 src address for outgoing OLSR packages\n"
144 " # (default is 0.0.0.0, which triggers usage of the interface IP)\n"
146 if_appendf(out, comments, " %sIPv4Src %s\n",
147 cnfi->ipv4_src.v4.s_addr == 0 ? "# " : "",
148 inet_ntop(AF_INET, &cnfi->ipv4_src, ipbuf.buf, sizeof(ipbuf)));
149 if (comments) abuf_puts(out,
151 " # IPv6 src prefix. OLSRd will choose one of the interface IPs\n"
152 " # which matches the prefix of this parameter.\n"
153 " # (default is 0::/0, which triggers the usage\n"
154 " # of a not-linklocal interface IP)\n"
156 if_appendf(out, comments, " %sIPv6Src %s\n",
157 cnfi->ipv6_src.prefix_len == 0 ? "# " : "",
158 inet_ntop(AF_INET6, &cnfi->ipv6_src, ipbuf.buf, sizeof(ipbuf)));
159 if (comments) abuf_appendf(out,
161 " # Emission intervals in seconds.\n"
162 " # If not defined, Freifunk network defaults are used.\n"
163 " # (defaults: Hello = %.1f/%.1f, TC = %.1f/%.1f,\n"
164 " # MID = %.1f/%.1f, HNA = %.1f/%.1f)\n"
166 (double)HELLO_INTERVAL, (double)NEIGHB_HOLD_TIME,
167 (double)TC_INTERVAL, (double)TOP_HOLD_TIME,
168 (double)MID_INTERVAL, (double)MID_HOLD_TIME,
169 (double)HNA_INTERVAL, (double)HNA_HOLD_TIME
171 if_appendf(out, comments, " %sHelloInterval %3.1f\n",
172 cnfi->hello_params.emission_interval == HELLO_INTERVAL ? "# " : "",
173 (double)cnfi->hello_params.emission_interval);
174 if_appendf(out, comments, " %sHelloValidityTime %3.1f\n",
175 cnfi->hello_params.validity_time == NEIGHB_HOLD_TIME ? "# " : "",
176 (double)cnfi->hello_params.validity_time);
177 if_appendf(out, comments, " %sTcInterval %3.1f\n",
178 cnfi->tc_params.emission_interval == TC_INTERVAL ? "# " : "",
179 (double)cnfi->tc_params.emission_interval);
180 if_appendf(out, comments, " %sTcValidityTime %3.1f\n",
181 cnfi->tc_params.validity_time == TOP_HOLD_TIME ? "# " : "",
182 (double)cnfi->tc_params.validity_time);
183 if_appendf(out, comments, " %sMidInterval %3.1f\n",
184 cnfi->mid_params.emission_interval == MID_INTERVAL ? "# " : "",
185 (double)cnfi->mid_params.emission_interval);
186 if_appendf(out, comments, " %sMidValidityTime %3.1f\n",
187 cnfi->mid_params.validity_time == MID_HOLD_TIME ? "# " : "",
188 (double)cnfi->mid_params.validity_time);
189 if_appendf(out, comments, " %sHnaInterval %3.1f\n",
190 cnfi->hna_params.emission_interval == HNA_INTERVAL ? "# " : "",
191 (double)cnfi->hna_params.emission_interval);
192 if_appendf(out, comments, " %sHnaValidityTime %3.1f\n",
193 cnfi->hna_params.validity_time == HNA_HOLD_TIME ? "# " : "",
194 (double)cnfi->hna_params.validity_time);
195 if (comments) abuf_puts(out,
197 " # When multiple links exist between hosts\n"
198 " # the weight of interface is used to determine\n"
199 " # the link to use. Normally the weight is\n"
200 " # automatically calculated by olsrd based\n"
201 " # on the characteristics of the interface,\n"
202 " # but here you can specify a fixed value.\n"
203 " # Olsrd will choose links with the lowest value.\n"
205 " # Interface weight is used only when LinkQualityLevel is set to 0.\n"
206 " # For any other value of LinkQualityLevel, the interface ETX\n"
207 " # value is used instead.\n");
208 if_appendf(out, comments, " %sWeight %d\n",
209 !cnfi->weight.fixed ? "# " : "",
211 if (comments) abuf_puts(out,
213 " # If a certain route should be preferred\n"
214 " # or ignored by the mesh, the Link Quality\n"
215 " # value of a node can be multiplied with a factor\n"
216 " # entered here. In the example the route\n"
217 " # using 192.168.0.1 would rather be ignored.\n"
218 " # A multiplier of 0.5 will result in a small\n"
219 " # (bad) LinkQuality value and a high (bad)\n"
222 " # Link quality multiplier is used only when\n"
223 " # LinkQualityLevel is greater than 0.\n"
225 mult = cnfi->lq_mult;
228 if (comments) abuf_puts(out, " # LinkQualityMult 192.168.0.1 0.5\n");
230 while (mult != NULL) {
231 if_appendf(out, comments, " LinkQualityMult %s %0.2f\n",
232 olsr_ip_to_string(&ipbuf, &mult->addr),
233 (double)((float)(mult->value) / 65536.0f));
237 abuf_puts(out, "}\n");
240 void olsrd_write_cnf_autobuf(struct autobuf *out, struct olsrd_config *cnf) {
241 struct ip_prefix_list *hna = cnf->hna_entries;
242 struct olsr_if *interf = cnf->interfaces;
243 struct plugin_entry *plugins = cnf->plugins;
244 struct plugin_param *pl_param;
245 struct ip_prefix_list *ipc_nets = cnf->ipc_nets;
247 struct ipaddr_str ipbuf;
250 abuf_appendf(out, "#\n"
251 "# Configuration file for %s\n"
252 "# automatically generated by olsrd-cnf parser v. %s\n"
255 olsrd_version, PARSER_VERSION);
257 "# OLSR.org routing daemon config file\n"
258 "# This file contains ALL available options and explanations about them\n"
260 "# Lines starting with a # are discarded\n"
263 "#### ATTENTION for IPv6 users ####\n"
264 "# Because of limitations in the parser IPv6 addresses must NOT\n"
265 "# begin with a \":\", so please add a \"0\" as a prefix.\n"
267 "###########################\n"
268 "### Basic configuration ###\n"
269 "###########################\n"
270 "# keep this settings at the beginning of your first configuration file\n"
272 "# Debug level (0-9)\n"
273 "# If set to 0 the daemon runs in the background, unless \"NoFork\" is set to true\n"
274 "# (default is %u)\n"
276 abuf_appendf(out, "%sDebugLevel %d\n",
277 cnf->debug_level == DEF_DEBUGLVL ? "# " : "",
281 "# IP version to use (4 or 6)\n"
282 "# (default is %u)\n"
283 "\n", (DEF_IP_VERSION == AF_INET) ? 4 : 6);
284 abuf_appendf(out, "%sIpVersion %d\n",
285 cnf->ip_version == DEF_IP_VERSION ? "# " : "",
286 cnf->ip_version == AF_INET ? 4 : 6);
289 "#################################\n"
290 "### OLSRd agent configuration ###\n"
291 "#################################\n"
292 "# this parameters control the settings of the routing agent which are not\n"
293 "# related to the OLSR protocol and it's extensions\n"
295 "# Clear the screen each time the internal state changes\n"
296 "# (default is %s)\n"
297 "\n", DEF_CLEAR_SCREEN ? "yes" : "no");
298 abuf_appendf(out, "%sClearScreen %s\n",
299 cnf->clear_screen == DEF_CLEAR_SCREEN ? "# " : "",
300 cnf->clear_screen ? "yes" : "no");
303 "# Should olsrd keep on running even if there are\n"
304 "# no interfaces available? This is a good idea\n"
305 "# for a PCMCIA/USB hotswap environment.\n"
306 "# (default is %s)\n"
307 "\n", DEF_ALLOW_NO_INTS ? "yes" : "no");
308 abuf_appendf(out, "%sAllowNoInt %s\n",
309 cnf->allow_no_interfaces == DEF_ALLOW_NO_INTS ? "# " : "",
310 cnf->allow_no_interfaces ? "yes" : "no");
314 "# The lockfile is used to prevent multiple OLSR instances running at the same\n"
316 "# (Linux/BSD default is \"/var/run/olsrd-ipv(4/6).lock\")\n"
317 "# (Win32 default is \"[configfile]-ipv(4/6).lock\")\n"
320 char * lockfile_default = olsrd_get_default_lockfile(cnf);
321 abuf_appendf(out, "%sLockFile \"%s\"\n",
322 !strcmp(cnf->lock_file, lockfile_default) ? "# " : "",
324 free(lockfile_default);
328 "# Polling rate for OLSR sockets in seconds (float).\n"
329 "# (default is %.2f)\n"
330 "\n", (double)DEF_POLLRATE);
331 abuf_appendf(out, "%sPollrate %.2f\n",
332 cnf->pollrate == (float)DEF_POLLRATE ? "# " : "",
333 (double)cnf->pollrate);
336 "# Interval to poll network interfaces for configuration changes (in seconds).\n"
337 "# Linux systems can detect interface statechange via netlink sockets.\n"
338 "# (default is %.1f)\n"
339 "\n", (double)DEF_NICCHGPOLLRT);
340 abuf_appendf(out, "%sNicChgsPollInt %.1f\n",
341 cnf->nic_chgs_pollrate == (float)DEF_NICCHGPOLLRT ? "# " : "",
342 (double)cnf->nic_chgs_pollrate);
345 "# TOS(type of service) value for the IP header of control traffic.\n"
346 "# (default is %u)\n"
348 abuf_appendf(out, "%sTosValue %u\n",
349 cnf->tos == DEF_TOS ? "# " : "",
353 "# FIBMetric controls the metric value of the host-routes OLSRd sets.\n"
354 "# - \"flat\" means that the metric value is always 2 (or as configured\n"
355 "# with FIBMetricDefault). This is the preferred value because it helps\n"
356 "# the linux kernel routing to clean up older routes\n"
357 "# - \"correct\" use the hopcount as the metric value.\n"
358 "# - \"approx\" use the hopcount as the metric value too, but does only update the\n"
359 "# hopcount if the nexthop changes too\n"
360 "# (default is \"%s\")\n"
361 "\n", FIB_METRIC_TXT[DEF_FIB_METRIC]);
362 abuf_appendf(out, "%sFIBMetric \"%s\"\n",
363 cnf->fib_metric == DEF_FIB_METRIC ? "# " : "",
364 FIB_METRIC_TXT[cnf->fib_metric]);
367 "# Default FIB metric.\n"
368 "# The kernel FIB does not need to know the metric of a route.\n"
369 "# This saves us from enqueuing/dequeueing hopcount only changes.\n"
370 "# (default is %u)\n"
371 "\n", DEF_FIB_METRIC_DEFAULT);
372 abuf_appendf(out, "%sFIBMetricDefault %u\n",
373 cnf->fib_metric_default == DEF_FIB_METRIC_DEFAULT? "# " : "",
374 cnf->fib_metric_default);
377 "#######################################\n"
378 "### Linux specific OLSRd extensions ###\n"
379 "#######################################\n"
380 "# these parameters are only working on linux at the moment, but might become\n"
381 "# useful on BSD in the future\n"
383 "# SrcIpRoutes tells OLSRd to set the Src flag of host routes to the originator-ip\n"
384 "# of the node. In addition to this an additional localhost device is created\n"
385 "# to make sure the returning traffic can be received.\n"
386 "# (default is \"%s\")\n"
387 "\n", DEF_USE_SRCIP_ROUTES ? "yes" : "no");
388 abuf_appendf(out, "%sSrcIpRoutes %s\n",
389 cnf->use_src_ip_routes == DEF_USE_SRCIP_ROUTES ? "# " : "",
390 cnf->use_src_ip_routes ? "yes" : "no");
393 "# Specify the proto tag to be used for routes olsr inserts into kernel\n"
394 "# currently only implemented for linux\n"
395 "# valid values under linux are 1 .. 254\n"
396 "# 1 gets remapped by olsrd to 0 UNSPECIFIED (1 is reserved for ICMP redirects)\n"
397 "# 2 KERNEL routes (not very wise to use)\n"
398 "# 3 BOOT (should in fact not be used by routing daemons)\n"
400 "# 8 .. 15 various routing daemons (gated, zebra, bird, & co)\n"
401 "# (default is %u which gets replaced by an OS-specific default value\n"
402 "# under linux 3 (BOOT) (for backward compatibility)\n"
404 abuf_appendf(out, "%sRtProto %u\n",
405 cnf->rt_proto == DEF_RTPROTO ? "# " : "",
409 "# Specifies the routing Table olsr uses\n"
410 "# RtTable is for host routes, RtTableDefault for the route to the default\n"
411 "# internet gateway (2 in case of IPv6+NIIT) and RtTableTunnel is for\n"
412 "# routes to the ipip tunnels, valid values are 1 to 254\n"
413 "# There is a special parameter \"auto\" (choose default below)\n"
414 "# (with smartgw: default is %u/%u/%u)\n"
415 "# (without smartgw: default is %u/%u/%u, linux main table)\n"
417 DEF_SGW_RT_TABLE_NR, DEF_SGW_RT_TABLE_DEFAULT_NR, DEF_SGW_RT_TABLE_TUNNEL_NR,
418 DEF_RT_TABLE_NR, DEF_RT_TABLE_DEFAULT_NR, DEF_RT_TABLE_TUNNEL_NR);
419 if (!cnf->smart_gw_active) {
420 abuf_appendf(out, "%sRtTable %u\n",
421 cnf->rt_table == DEF_RT_TABLE_NR ? "# " : "",
423 abuf_appendf(out, "%sRtTableDefault %u\n",
424 cnf->rt_table_default == DEF_RT_TABLE_DEFAULT_NR ? "# " : "",
425 cnf->rt_table_default);
426 abuf_appendf(out, "%sRtTableTunnel %u\n",
427 cnf->rt_table_tunnel == DEF_RT_TABLE_TUNNEL_NR ? "# " : "",
428 cnf->rt_table_tunnel);
430 abuf_appendf(out, "%sRtTable %u\n",
431 cnf->rt_table == DEF_SGW_RT_TABLE_NR ? "# " : "",
433 abuf_appendf(out, "%sRtTableDefault %u\n",
434 cnf->rt_table_default == DEF_SGW_RT_TABLE_DEFAULT_NR ? "# " : "",
435 cnf->rt_table_default);
436 abuf_appendf(out, "%sRtTableTunnel %u\n",
437 cnf->rt_table_tunnel == DEF_SGW_RT_TABLE_TUNNEL_NR ? "# " : "",
438 cnf->rt_table_tunnel);
442 "# Specifies the policy rule priorities for the three routing tables and\n"
443 "# a special rule for smartgateway routing (see README-Olsr-Extensions)\n"
444 "# Priorities can only be set if three different routing tables are set.\n"
445 "# if set the values must obey to condition\n"
446 "# RtTablePriority less than RtTableDefaultOlsrPriority\n"
447 "# less than RtTableTunnelPriority less than RtTableDefaultPriority\n"
448 "# There are two special parameters, \"auto\" (choose fitting to SmartGW\n"
449 "# mode) and \"none\" (do not set policy rule)\n"
450 "# (with smartgw: default is %d/%u/%u/%u)\n"
451 "# (without smartgw: default is %d/%d /%d /%d )\n"
453 DEF_SGW_RT_TABLE_PRI,
454 DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER,
455 DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER + DEF_SGW_RT_TABLE_TUNNEL_PRI_ADDER,
456 DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER + DEF_SGW_RT_TABLE_TUNNEL_PRI_ADDER + DEF_SGW_RT_TABLE_DEFAULT_PRI_ADDER,
458 DEF_RT_TABLE_DEFAULTOLSR_PRI,
459 DEF_RT_TABLE_TUNNEL_PRI,
460 DEF_RT_TABLE_DEFAULT_PRI);
461 if (!cnf->smart_gw_active) {
462 if (cnf->rt_table_pri == DEF_RT_TABLE_PRI) {
463 abuf_appendf(out, "# RtTablePriority %d\n",
466 abuf_appendf(out, "RtTablePriority %u\n",
469 if (cnf->rt_table_defaultolsr_pri == DEF_RT_TABLE_DEFAULTOLSR_PRI) {
470 abuf_appendf(out, "# RtTableDefaultOlsrPriority %d\n",
471 cnf->rt_table_defaultolsr_pri);
473 abuf_appendf(out, "RtTableDefaultOlsrPriority %u\n",
474 cnf->rt_table_defaultolsr_pri);
476 if (cnf->rt_table_tunnel_pri == DEF_RT_TABLE_TUNNEL_PRI) {
477 abuf_appendf(out, "# RtTableTunnelPriority %d\n",
478 cnf->rt_table_tunnel_pri);
480 abuf_appendf(out, "RtTableTunnelPriority %u\n",
481 cnf->rt_table_tunnel_pri);
483 if (cnf->rt_table_default_pri == DEF_RT_TABLE_DEFAULT_PRI) {
484 abuf_appendf(out, "# RtTableDefaultPriority %d\n",
485 cnf->rt_table_default_pri);
487 abuf_appendf(out, "RtTableDefaultPriority %u\n",
488 cnf->rt_table_default_pri);
491 if (cnf->rt_table_pri == DEF_SGW_RT_TABLE_PRI) {
492 abuf_appendf(out, "# RtTablePriority %d\n",
495 abuf_appendf(out, "RtTablePriority %u\n",
498 abuf_appendf(out, "%sRtTableDefaultOlsrPriority %u\n",
499 cnf->rt_table_defaultolsr_pri == (DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER) ? "# " : "",
500 cnf->rt_table_defaultolsr_pri);
502 abuf_appendf(out, "%sRtTableTunnelPriority %u\n",
503 cnf->rt_table_tunnel_pri == (DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER + DEF_SGW_RT_TABLE_TUNNEL_PRI_ADDER) ? "# " : "",
504 cnf->rt_table_tunnel_pri);
506 abuf_appendf(out, "%sRtTableDefaultPriority %u\n",
507 cnf->rt_table_default_pri == (DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER + DEF_SGW_RT_TABLE_TUNNEL_PRI_ADDER + DEF_SGW_RT_TABLE_DEFAULT_PRI_ADDER) ? "# " : "",
508 cnf->rt_table_default_pri);
512 "# Activates (in IPv6 mode) the automatic use of NIIT\n"
513 "# (see README-Olsr-Extensions)\n"
514 "# (default is \"%s\")\n"
515 "\n", DEF_USE_NIIT ? "yes" : "no");
516 abuf_appendf(out, "%sUseNiit %s\n",
517 cnf->use_niit == DEF_USE_NIIT ? "# " : "",
518 cnf->use_niit ? "yes" : "no");
521 "# Activates the smartgateway ipip tunnel feature.\n"
522 "# See README-Olsr-Extensions for a description of smartgateways.\n"
523 "# (default is \"%s\")\n"
524 "\n", DEF_SMART_GW ? "yes" : "no");
525 abuf_appendf(out, "%sSmartGateway %s\n",
526 cnf->smart_gw_active == DEF_SMART_GW ? "# " : "",
527 cnf->smart_gw_active ? "yes" : "no");
530 "# Signals that the server tunnel must always be removed on shutdown,\n"
531 "# irrespective of the interface up/down state during startup.\n"
532 "# (default is \"%s\")\n"
533 "\n", DEF_SMART_GW_ALWAYS_REMOVE_SERVER_TUNNEL ? "yes" : "no");
534 abuf_appendf(out, "%sSmartGatewayAlwaysRemoveServerTunnel %s\n",
535 cnf->smart_gw_always_remove_server_tunnel == DEF_SMART_GW_ALWAYS_REMOVE_SERVER_TUNNEL ? "# " : "",
536 cnf->smart_gw_always_remove_server_tunnel ? "yes" : "no");
539 "# Determines the maximum number of gateways that can be in use at any given\n"
540 "# time. This setting is used to mitigate the effects of breaking connections\n"
541 "# (due to the selection of a new gateway) on a dynamic network.\n"
542 "# (default is %u)\n"
543 "\n", DEF_GW_USE_COUNT);
544 abuf_appendf(out, "%sSmartGatewayUseCount %d\n",
545 cnf->smart_gw_use_count == DEF_GW_USE_COUNT ? "# " : "",
546 cnf->smart_gw_use_count);
549 "# Determines the take-down percentage for a non-current smart gateway tunnel.\n"
550 "# If the cost of the current smart gateway tunnel is less than this percentage\n"
551 "# of the cost of the non-current smart gateway tunnel, then the non-current smart\n"
552 "# gateway tunnel is taken down because it is then presumed to be 'too expensive'.\n"
553 "# This setting is only relevant when SmartGatewayUseCount is larger than 1;\n"
554 "# a value of 0 will result in the tunnels not being taken down proactively.\n"
555 "# (default is %u)\n"
556 "\n", DEF_GW_TAKEDOWN_PERCENTAGE);
557 abuf_appendf(out, "%sSmartGatewayTakeDownPercentage %d\n",
558 cnf->smart_gw_takedown_percentage == DEF_GW_TAKEDOWN_PERCENTAGE ? "# " : "",
559 cnf->smart_gw_takedown_percentage);
562 "# Determines the policy routing script that is executed during startup and\n"
563 "# shutdown of olsrd. The script is only executed when SmartGatewayUseCount\n"
564 "# is set to a value larger than 1. The script must setup policy routing\n"
565 "# rules such that multi-gateway mode works. A sample script is included.\n"
566 "# (default is not set)\n"
568 abuf_appendf(out, "%sSmartGatewayPolicyRoutingScript %s\n",
569 !cnf->smart_gw_policyrouting_script ? "# " : "",
570 !cnf->smart_gw_policyrouting_script ? "" : cnf->smart_gw_policyrouting_script);
573 "# Determines the egress interfaces that are part of the multi-gateway setup and\n"
574 "# therefore only relevant when SmartGatewayUseCount is larger than 1 (in which\n"
575 "# case it must be explicitly set).\n"
576 "# (default is not set)\n"
578 abuf_appendf(out, "%sSmartGatewayEgressInterfaces",
579 !cnf->smart_gw_egress_interfaces ? "# " : "");
581 struct sgw_egress_if * sgwegressif = olsr_cnf->smart_gw_egress_interfaces;
582 while (sgwegressif) {
583 abuf_appendf(out, " \"%s\"", sgwegressif->name);
584 sgwegressif = sgwegressif->next;
586 abuf_puts(out, "\n");
590 "# SmartGatewayEgressFile declares the file that contains the bandwidth\n"
591 "# parameters of the egress interfaces declared by SmartGatewayEgressInterfaces.\n"
592 "# Every line in the file declares bandwidth parameters of an egress interface,\n"
593 "# with the format:\n"
594 "# # this is a comment\n"
595 "# interface=upstream,downstream,pathcost,network/prefix,gateway\n"
596 "# Only the upstream and downstream fields are mandatory, the other fields are\n"
597 "# optional. An empty field signifies that its default should be used.\n"
598 "# The field defaults are:\n"
599 "# upstream = 0 (Kbps)\n"
600 "# downstream = 0 (Kbps)\n"
601 "# pathcost = 0 (dimensionless, 1024 is equivalent to 1 hop)\n"
602 "# network/prefix = no default / not set\n"
603 "# - network is an IP address\n"
604 "# - prefix is a number in the range [0, 24] for IPv4\n"
605 "# and in the range [0, 128] for IPv6\n"
606 "# gateway = no default / not set (IP address)\n"
607 "# (default is %s)\n"
608 "\n", DEF_GW_EGRESS_FILE);
610 bool def = !cnf->smart_gw_egress_file || !strcmp(cnf->smart_gw_egress_file, DEF_GW_EGRESS_FILE);
611 abuf_appendf(out, "%sSmartGatewayEgressFile %s\n",
612 def ? "# " : "", def ? DEF_GW_EGRESS_FILE : cnf->smart_gw_egress_file);
616 "# SmartGatewayEgressFilePeriod determines the period (in milliseconds) on which\n"
617 "# the SmartGatewayEgressFile is checked for changes and processed if changed.\n"
618 "# (default is %u)\n"
619 "\n", DEF_GW_EGRESS_FILE_PERIOD);
620 abuf_appendf(out, "%sSmartGatewayEgressFilePeriod %u\n",
621 cnf->smart_gw_egress_file_period == DEF_GW_EGRESS_FILE_PERIOD ? "# " : "",
622 cnf->smart_gw_egress_file_period);
625 "# Declares the file that is written by olsrd to contain the status of the smart\n"
626 "# gateways and is only relevant when SmartGatewayUseCount is larger than 1.\n"
627 "# (default is %s)\n"
630 bool def = !cnf->smart_gw_status_file || !strlen(cnf->smart_gw_status_file);
631 abuf_appendf(out, "%sSmartGatewayStatusFile %s\n",
632 def ? "# " : "", def ? "<not set>" : cnf->smart_gw_status_file);
636 "# Determines the routing tables offset for multi-gateway policy routing tables\n"
637 "# See the policy routing script for an explanation.\n"
638 "# (default is %u)\n"
639 "\n", DEF_GW_OFFSET_TABLES);
640 abuf_appendf(out, "%sSmartGatewayTablesOffset %u\n",
641 cnf->smart_gw_offset_tables == DEF_GW_OFFSET_TABLES ? "# " : "",
642 cnf->smart_gw_offset_tables);
645 "# Determines the policy routing rules offset for multi-gateway policy routing\n"
646 "# rules. See the policy routing script for an explanation.\n"
647 "# (default is %u, which indicates that the rules and tables should be aligned and\n"
648 "# puts this value at SmartGatewayTablesOffset - # egress interfaces -\n"
649 "# # olsr interfaces)\n"
650 "\n", DEF_GW_OFFSET_RULES);
651 abuf_appendf(out, "%sSmartGatewayRulesOffset %u\n",
652 cnf->smart_gw_offset_rules == DEF_GW_OFFSET_RULES ? "# " : "",
653 cnf->smart_gw_offset_rules);
656 "# Allows the selection of a smartgateway with NAT (only for IPv4)\n"
657 "# (default is \"%s\")\n"
658 "\n", DEF_GW_ALLOW_NAT ? "yes" : "no");
659 abuf_appendf(out, "%sSmartGatewayAllowNAT %s\n",
660 cnf->smart_gw_allow_nat == DEF_GW_ALLOW_NAT ? "# " : "",
661 cnf->smart_gw_allow_nat ? "yes" : "no");
664 "# Determines the period (in milliseconds) on which a new smart gateway\n"
665 "# selection is performed.\n"
666 "# (default is %u milliseconds)\n"
667 "\n", DEF_GW_PERIOD);
668 abuf_appendf(out, "%sSmartGatewayPeriod %d\n",
669 cnf->smart_gw_period == DEF_GW_PERIOD ? "# " : "",
670 cnf->smart_gw_period);
673 "# Determines the number of times the link state database must be stable\n"
674 "# before a new smart gateway is selected.\n"
675 "# (default is %u)\n"
676 "\n", DEF_GW_STABLE_COUNT);
677 abuf_appendf(out, "%sSmartGatewayStableCount %d\n",
678 cnf->smart_gw_stablecount == DEF_GW_STABLE_COUNT ? "# " : "",
679 cnf->smart_gw_stablecount);
682 "# When another gateway than the current one has a cost of less than the cost\n"
683 "# of the current gateway multiplied by SmartGatewayThreshold then the smart\n"
684 "# gateway is switched to the other gateway. The unit is percentage.\n"
685 "# (default is %u)\n"
686 "\n", DEF_GW_THRESH);
687 abuf_appendf(out, "%sSmartGatewayThreshold %d\n",
688 cnf->smart_gw_thresh == DEF_GW_THRESH ? "# " : "",
689 cnf->smart_gw_thresh);
692 "# The weighing factor for the gateway uplink bandwidth (exit link, uplink).\n"
693 "# See README-Olsr-Extensions for a description of smart gateways.\n"
694 "# (default is %lu)\n"
695 "\n", (long unsigned int)DEF_GW_WEIGHT_EXITLINK_UP);
696 abuf_appendf(out, "%sSmartGatewayWeightExitLinkUp %d\n",
697 cnf->smart_gw_weight_exitlink_up == DEF_GW_WEIGHT_EXITLINK_UP ? "# " : "",
698 cnf->smart_gw_weight_exitlink_up);
701 "# The weighing factor for the gateway downlink bandwidth (exit link, downlink).\n"
702 "# See README-Olsr-Extensions for a description of smart gateways.\n"
703 "# (default is %lu)\n"
704 "\n", (long unsigned int)DEF_GW_WEIGHT_EXITLINK_DOWN);
705 abuf_appendf(out, "%sSmartGatewayWeightExitLinkDown %d\n",
706 cnf->smart_gw_weight_exitlink_down == DEF_GW_WEIGHT_EXITLINK_DOWN ? "# " : "",
707 cnf->smart_gw_weight_exitlink_down);
710 "# The weighing factor for the ETX costs.\n"
711 "# See README-Olsr-Extensions for a description of smart gateways.\n"
712 "# (default is %u)\n"
713 "\n", DEF_GW_WEIGHT_ETX);
714 abuf_appendf(out, "%sSmartGatewayWeightEtx %d\n",
715 cnf->smart_gw_weight_etx == DEF_GW_WEIGHT_ETX ? "# " : "",
716 cnf->smart_gw_weight_etx);
719 "# The divider for the ETX costs.\n"
720 "# See README-Olsr-Extensions for a description of smart gateways.\n"
721 "# (default is %u)\n"
722 "\n", DEF_GW_DIVIDER_ETX);
723 abuf_appendf(out, "%sSmartGatewayDividerEtx %d\n",
724 cnf->smart_gw_divider_etx == DEF_GW_DIVIDER_ETX ? "# " : "",
725 cnf->smart_gw_divider_etx);
728 "# Defines what kind of Uplink this node will publish as a\n"
729 "# smartgateway. The existence of the uplink is detected by\n"
730 "# a route to 0.0.0.0/0, ::ffff:0:0/96 and/or 2000::/3.\n"
731 "# possible values are \"none\", \"ipv4\", \"ipv6\", \"both\"\n"
732 "# (default is \"%s\")\n"
733 "\n", GW_UPLINK_TXT[DEF_GW_TYPE]);
734 abuf_appendf(out, "%sSmartGatewayUplink \"%s\"\n",
735 cnf->smart_gw_type == DEF_GW_TYPE ? "# " : "",
736 GW_UPLINK_TXT[cnf->smart_gw_type]);
739 "# Specifies if the local ipv4 uplink use NAT\n"
740 "# (default is \"%s\")\n"
741 "\n", DEF_GW_UPLINK_NAT ? "yes" : "no");
742 abuf_appendf(out, "%sSmartGatewayUplinkNAT %s\n",
743 cnf->smart_gw_uplink_nat == DEF_GW_UPLINK_NAT ? "# " : "",
744 cnf->smart_gw_uplink_nat ? "yes" : "no");
747 "# Specifies the speed of the uplink in kilobit/s.\n"
748 "# First parameter is upstream, second parameter is downstream\n"
749 "# (default is %u/%u)\n"
750 "\n", DEF_UPLINK_SPEED, DEF_DOWNLINK_SPEED);
751 abuf_appendf(out, "%sSmartGatewaySpeed %d %d\n",
752 cnf->smart_gw_uplink == DEF_UPLINK_SPEED && cnf->smart_gw_downlink == DEF_DOWNLINK_SPEED ? "# " : "",
753 cnf->smart_gw_uplink, cnf->smart_gw_downlink);
756 "# Specifies the EXTERNAL ipv6 prefix of the uplink. A prefix\n"
757 "# length of more than 64 is not allowed.\n"
758 "# (default is 0::/0)\n"
760 abuf_appendf(out, "%sSmartGatewayPrefix %s\n",
761 cnf->smart_gw_prefix.prefix_len == 0 ? "# " : "",
762 olsr_ip_prefix_to_string(&cnf->smart_gw_prefix));
765 "##############################\n"
766 "### OLSR protocol settings ###\n"
767 "##############################\n"
769 "# For testing purposes it may be nice to use another port for olsrd\n"
770 "# for using another port than the IANA assigned one\n"
771 "# for a production network, there should be a good reason!!\n"
772 "# valid values are integers greater than 1, please be careful with\n"
773 "# using reserved port numbers\n"
774 "# (default is %u, the IANA assigned olsr-port)\n"
776 abuf_appendf(out, "%sOlsrPort %u\n",
777 cnf->olsrport == DEF_OLSRPORT ? "# " : "",
781 "# Sets the main IP (originator ip) of the router. This IP will NEVER\n"
782 "# change during the uptime of olsrd.\n"
783 "# (default is 0.0.0.0, which triggers usage of the IP of the first interface)\n"
785 abuf_appendf(out, "MainIp %s\n",
786 olsr_ip_to_string(&ipbuf, &cnf->main_addr));
789 "# The fixed willingness to use (0-7)\n"
790 "# If not set willingness will be calculated\n"
791 "# dynamically based on battery/power status\n"
792 "# (default is %u)\n"
793 "\n", DEF_WILLINGNESS);
794 abuf_appendf(out, "%sWillingness %u\n",
795 cnf->willingness == DEF_WILLINGNESS ? "# " : "",
799 "# HNA (Host network association) allows the OLSR to announce\n"
800 "# additional IPs or IP subnets to the net that are reachable\n"
801 "# through this node.\n"
802 "# Syntax for HNA4 is \"network-address network-mask\"\n"
803 "# Syntax for HNA6 is \"network-address prefix-length\"\n"
804 "# (default is no HNA)\n");
805 abuf_appendf(out, "Hna%u\n"
807 cnf->ip_version == AF_INET ? 4 : 6);
809 struct ipaddr_str strbuf;
810 abuf_appendf(out, " %s\n", olsr_ip_prefix_to_string(&hna->net));
816 "# Hysteresis for link sensing (only for hopcount metric)\n"
817 "# Hysteresis adds more robustness to the link sensing\n"
818 "# but delays neighbor registration.\n"
819 "# (default is %s)\n"
820 "\n", DEF_USE_HYST ? "yes" : "no");
821 abuf_appendf(out, "%sUseHysteresis %s\n",
822 cnf->use_hysteresis == DEF_USE_HYST ? "# " : "",
823 cnf->use_hysteresis ? "yes" : "no");
826 "# Hysteresis parameters (only for hopcount metric)\n"
827 "# Do not alter these unless you know what you are doing!\n"
828 "# Set to auto by default. Allowed values are floating point\n"
829 "# values in the interval 0,1\n"
830 "# THR_LOW must always be lower than THR_HIGH!!\n"
831 "# (default is %.2f/%.2f/%.2f)\n"
832 "\n", (double)HYST_SCALING, (double)HYST_THRESHOLD_HIGH, (double)HYST_THRESHOLD_LOW);
833 abuf_appendf(out, "%sHystScaling %.2f\n",
834 cnf->hysteresis_param.scaling == (float)HYST_SCALING ? "# " : "",
835 (double)cnf->hysteresis_param.scaling);
836 abuf_appendf(out, "%sHystThrHigh %.2f\n",
837 cnf->hysteresis_param.thr_high == (float)HYST_THRESHOLD_HIGH ? "# " : "",
838 (double)cnf->hysteresis_param.thr_high);
839 abuf_appendf(out, "%sHystThrLow %.2f\n",
840 cnf->hysteresis_param.thr_low == (float)HYST_THRESHOLD_LOW ? "# " : "",
841 (double)cnf->hysteresis_param.thr_low);
845 "# Specifies how much neighbor info should be sent in\n"
846 "# TC messages. Because of a design problem in the 0.5.x\n"
847 "# dijkstra implementation this value must be set to 2.\n"
848 "# 2 - send all neighbors\n"
849 "# (default is %u)\n"
850 "\n", TC_REDUNDANCY);
851 abuf_appendf(out, "%sTcRedundancy %d\n",
852 cnf->tc_redundancy == TC_REDUNDANCY ? "# " : "",
856 "# MPR coverage specifies how many MPRs a node should\n"
857 "# try select to reach every 2 hop neighbor. Because of\n"
858 "# a design problem in the 0.5.x dijkstra algorithm this\n"
859 "# value should be set to 7.\n"
860 "# (default is %u)\n"
862 abuf_appendf(out, "%sMprCoverage %d\n",
863 cnf->mpr_coverage == MPR_COVERAGE ? "# " : "",
867 "################################\n"
868 "### OLSR protocol extensions ###\n"
869 "################################\n"
871 "# Link quality level switch between hopcount and\n"
872 "# cost-based (mostly ETX) routing. Because of\n"
873 "# a design problem in the 0.5.x dijkstra algorithm this\n"
874 "# value should not be set to 1.\n"
875 "# 0 = do not use link quality\n"
876 "# 2 = use link quality for MPR selection and routing\n"
877 "# (default is %u)\n"
879 abuf_appendf(out, "%sLinkQualityLevel %d\n",
880 cnf->lq_level == DEF_LQ_LEVEL ? "# " : "",
884 "# Link quality algorithm (only for lq level 2)\n"
885 "# (see README-Olsr-Extensions)\n"
886 "# - \"etx_float\", a floating point ETX with exponential aging\n"
887 "# - \"etx_fpm\", same as ext_float, but with integer arithmetic\n"
888 "# - \"etx_ff\" (ETX freifunk), an etx variant which use all OLSR\n"
889 "# traffic (instead of only hellos) for ETX calculation\n"
890 "# - \"etx_ffeth\", an incompatible variant of etx_ff that allows\n"
891 "# ethernet links with ETX 0.1.\n"
892 "# (default is \"%s\")\n"
893 "\n", DEF_LQ_ALGORITHM);
894 abuf_appendf(out, "%sLinkQualityAlgorithm \"%s\"\n",
895 cnf->lq_algorithm == NULL ? "# " : "",
896 cnf->lq_algorithm == NULL ? DEF_LQ_ALGORITHM : cnf->lq_algorithm);
899 "# Link quality aging factor (only for lq level 2)\n"
900 "# Tuning parameter for etx_float and etx_fpm, smaller values\n"
901 "# mean slower changes of ETX value. (allowed values are\n"
902 "# between 0.01 and 1.0)\n"
903 "# (default is %.2f)\n"
904 "\n", (double)DEF_LQ_AGING);
905 abuf_appendf(out, "%sLinkQualityAging %.2f\n",
906 cnf->lq_aging == (float)DEF_LQ_AGING ? "# " : "",
907 (double)cnf->lq_aging);
910 "# Fisheye mechanism for TCs (0 meansoff, 1 means on)\n"
911 "# (default is %u)\n"
913 abuf_appendf(out, "%sLinkQualityFishEye %d\n",
914 cnf->lq_fish == DEF_LQ_FISH ? "# " : "",
921 "# (currently this is only in the freifunk firmware)\n"
922 "# If the NAT-Endpoint (the preferred 0/0 HNA emitting node)\n"
923 "# is to be changed, the ETX value of the current 0/0 is\n"
924 "# multiplied with the NatThreshold value before being\n"
925 "# compared to the new one.\n"
926 "# The parameter can be a value between 0.1 and 1.0, but\n"
927 "# should be close to 1.0 if changed.\n"
928 "# WARNING: This parameter should not be used together with\n"
929 "# the etx_ffeth metric !!\n"
930 "# (default is %.1f)\n"
931 "\n", (double)DEF_LQ_NAT_THRESH);
932 abuf_appendf(out, "%sNatThreshold %.1f\n",
933 cnf->lq_nat_thresh == (float)DEF_LQ_NAT_THRESH ? "# " : "",
934 (double)cnf->lq_nat_thresh);
938 "#############################################################\n"
939 "### Configuration of the IPC to the windows GUI interface ###\n"
940 "#############################################################\n"
944 " # Determines how many simultaneously\n"
945 " # IPC connections that will be allowed\n"
946 " # Setting this to 0 disables IPC\n"
948 abuf_appendf(out, " %sMaxConnections %d\n",
949 cnf->ipc_connections == DEF_IPC_CONNECTIONS ? "# " : "",
950 cnf->ipc_connections);
953 " # By default only 127.0.0.1 is allowed\n"
954 " # to connect. Here allowed hosts and networks can\n"
959 if (ipc_nets->net.prefix_len == olsr_cnf->maxplen) {
960 abuf_appendf(out, " Host %s\n", olsr_ip_to_string(&ipbuf, &ipc_nets->net.prefix));
962 abuf_appendf(out, " Net %s\n", olsr_ip_prefix_to_string(&ipc_nets->net));
964 ipc_nets = ipc_nets->next;
969 "#####################################\n"
970 "### Example plugin configurations ###\n"
971 "#####################################\n"
972 "# Olsrd plugins to load\n"
973 "# This must be the absolute path to the file\n"
974 "# or the loader will use the following scheme:\n"
975 "# - Try the paths in the LD_LIBRARY_PATH\n"
976 "# environment variable.\n"
977 "# - The list of libraries cached in /etc/ld.so.cache\n"
978 "# - /lib, followed by /usr/lib\n"
982 abuf_appendf(out, "LoadPlugin \"%s\" {\n", plugins->name);
983 pl_param = plugins->params;
985 abuf_appendf(out, " PlParam \"%s\" \"%s\"\n", pl_param->key, pl_param->value);
986 pl_param = pl_param->next;
990 plugins = plugins->next;
994 "#############################################\n"
995 "### OLSRD default interface configuration ###\n"
996 "#############################################\n"
997 "# the default interface section can have the same values as the following\n"
998 "# interface configuration. It will allow you so set common options for all\n"
1001 "InterfaceDefaults\n");
1002 olsrd_write_if_autobuf(out, cnf->interface_defaults, false);
1005 "######################################\n"
1006 "### OLSRd Interfaces configuration ###\n"
1007 "######################################\n"
1008 "# multiple interfaces can be specified for a single configuration block\n"
1009 "# multiple configuration blocks can be specified\n"
1013 abuf_appendf(out, "Interface \"%s\"\n", interf->name);
1014 olsrd_write_if_autobuf(out, interf->cnf, first);
1017 interf = interf->next;
1022 "# END AUTOGENERATED CONFIG\n");
1027 * indent-tabs-mode: nil