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 olsrd_config *cnf, 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"
157 int saved = cnf->ip_version;
158 cnf->ip_version = AF_INET6;
159 if_appendf(out, comments, " %sIPv6Src %s\n",
160 cnfi->ipv6_src.prefix_len == 0 ? "# " : "",
161 olsr_ip_prefix_to_string(&cnfi->ipv6_src));
162 cnf->ip_version = saved;
164 if (comments) abuf_appendf(out,
166 " # Emission intervals in seconds.\n"
167 " # If not defined, Freifunk network defaults are used.\n"
168 " # (defaults: Hello = %.1f/%.1f, TC = %.1f/%.1f,\n"
169 " # MID = %.1f/%.1f, HNA = %.1f/%.1f)\n"
171 (double)HELLO_INTERVAL, (double)NEIGHB_HOLD_TIME,
172 (double)TC_INTERVAL, (double)TOP_HOLD_TIME,
173 (double)MID_INTERVAL, (double)MID_HOLD_TIME,
174 (double)HNA_INTERVAL, (double)HNA_HOLD_TIME
176 if_appendf(out, comments, " %sHelloInterval %3.1f\n",
177 cnfi->hello_params.emission_interval == HELLO_INTERVAL ? "# " : "",
178 (double)cnfi->hello_params.emission_interval);
179 if_appendf(out, comments, " %sHelloValidityTime %3.1f\n",
180 cnfi->hello_params.validity_time == NEIGHB_HOLD_TIME ? "# " : "",
181 (double)cnfi->hello_params.validity_time);
182 if_appendf(out, comments, " %sTcInterval %3.1f\n",
183 cnfi->tc_params.emission_interval == TC_INTERVAL ? "# " : "",
184 (double)cnfi->tc_params.emission_interval);
185 if_appendf(out, comments, " %sTcValidityTime %3.1f\n",
186 cnfi->tc_params.validity_time == TOP_HOLD_TIME ? "# " : "",
187 (double)cnfi->tc_params.validity_time);
188 if_appendf(out, comments, " %sMidInterval %3.1f\n",
189 cnfi->mid_params.emission_interval == MID_INTERVAL ? "# " : "",
190 (double)cnfi->mid_params.emission_interval);
191 if_appendf(out, comments, " %sMidValidityTime %3.1f\n",
192 cnfi->mid_params.validity_time == MID_HOLD_TIME ? "# " : "",
193 (double)cnfi->mid_params.validity_time);
194 if_appendf(out, comments, " %sHnaInterval %3.1f\n",
195 cnfi->hna_params.emission_interval == HNA_INTERVAL ? "# " : "",
196 (double)cnfi->hna_params.emission_interval);
197 if_appendf(out, comments, " %sHnaValidityTime %3.1f\n",
198 cnfi->hna_params.validity_time == HNA_HOLD_TIME ? "# " : "",
199 (double)cnfi->hna_params.validity_time);
200 if (comments) abuf_puts(out,
202 " # When multiple links exist between hosts\n"
203 " # the weight of interface is used to determine\n"
204 " # the link to use. Normally the weight is\n"
205 " # automatically calculated by olsrd based\n"
206 " # on the characteristics of the interface,\n"
207 " # but here you can specify a fixed value.\n"
208 " # Olsrd will choose links with the lowest value.\n"
210 " # Interface weight is used only when LinkQualityLevel is set to 0.\n"
211 " # For any other value of LinkQualityLevel, the interface ETX\n"
212 " # value is used instead.\n");
213 if_appendf(out, comments, " %sWeight %d\n",
214 !cnfi->weight.fixed ? "# " : "",
216 if (comments) abuf_puts(out,
218 " # If a certain route should be preferred\n"
219 " # or ignored by the mesh, the Link Quality\n"
220 " # value of a node can be multiplied with a factor\n"
221 " # entered here. In the example the route\n"
222 " # using 192.168.0.1 would rather be ignored.\n"
223 " # A multiplier of 0.5 will result in a small\n"
224 " # (bad) LinkQuality value and a high (bad)\n"
227 " # Link quality multiplier is used only when\n"
228 " # LinkQualityLevel is greater than 0.\n"
230 mult = cnfi->lq_mult;
234 abuf_puts(out, " # example 1: reduce LQ to 192.168.0.1 by half\n");
235 abuf_puts(out, " # LinkQualityMult 192.168.0.1 0.5\n");
236 abuf_puts(out, "\n");
237 abuf_puts(out, " # example 2: reduce LQ to all nodes on this interface by 20%\n");
238 abuf_puts(out, " # LinkQualityMult default 0.8\n");
241 while (mult != NULL) {
242 if_appendf(out, comments, " LinkQualityMult %s %0.2f\n",
243 olsr_ip_to_string(&ipbuf, &mult->addr),
244 (double)((float)(mult->value) / 65536.0f));
248 abuf_puts(out, "}\n");
251 void olsrd_write_cnf_autobuf(struct autobuf *out, struct olsrd_config *cnf) {
252 struct ip_prefix_list *hna = cnf->hna_entries;
253 struct olsr_if *interf = cnf->interfaces;
254 struct plugin_entry *plugins = cnf->plugins;
255 struct plugin_param *pl_param;
256 struct ip_prefix_list *ipc_nets = cnf->ipc_nets;
258 struct ipaddr_str ipbuf;
261 abuf_appendf(out, "#\n"
262 "# Configuration file for %s\n"
263 "# automatically generated by olsrd-cnf parser v. %s\n"
266 olsrd_version, PARSER_VERSION);
268 "# OLSR.org routing daemon config file\n"
269 "# This file contains ALL available options and explanations about them\n"
271 "# Lines starting with a # are discarded\n"
274 "#### ATTENTION for IPv6 users ####\n"
275 "# Because of limitations in the parser IPv6 addresses must NOT\n"
276 "# begin with a \":\", so please add a \"0\" as a prefix.\n"
278 "###########################\n"
279 "### Basic configuration ###\n"
280 "###########################\n"
281 "# keep this settings at the beginning of your first configuration file\n"
283 "# Debug level (0-9)\n"
284 "# If set to 0 the daemon runs in the background, unless \"NoFork\" is set to true\n"
285 "# (default is %u)\n"
287 abuf_appendf(out, "%sDebugLevel %d\n",
288 cnf->debug_level == DEF_DEBUGLVL ? "# " : "",
292 "# IP version to use (4 or 6)\n"
293 "# (default is %u)\n"
294 "\n", (DEF_IP_VERSION == AF_INET) ? 4 : 6);
295 abuf_appendf(out, "%sIpVersion %d\n",
296 cnf->ip_version == DEF_IP_VERSION ? "# " : "",
297 cnf->ip_version == AF_INET ? 4 : 6);
300 "#################################\n"
301 "### OLSRd agent configuration ###\n"
302 "#################################\n"
303 "# this parameters control the settings of the routing agent which are not\n"
304 "# related to the OLSR protocol and it's extensions\n"
306 "# Clear the screen each time the internal state changes\n"
307 "# (default is %s)\n"
308 "\n", DEF_CLEAR_SCREEN ? "yes" : "no");
309 abuf_appendf(out, "%sClearScreen %s\n",
310 cnf->clear_screen == DEF_CLEAR_SCREEN ? "# " : "",
311 cnf->clear_screen ? "yes" : "no");
314 "# Should olsrd keep on running even if there are\n"
315 "# no interfaces available? This is a good idea\n"
316 "# for a PCMCIA/USB hotswap environment.\n"
317 "# (default is %s)\n"
318 "\n", DEF_ALLOW_NO_INTS ? "yes" : "no");
319 abuf_appendf(out, "%sAllowNoInt %s\n",
320 cnf->allow_no_interfaces == DEF_ALLOW_NO_INTS ? "# " : "",
321 cnf->allow_no_interfaces ? "yes" : "no");
325 "# The lockfile is used to prevent multiple OLSR instances running at the same\n"
327 "# (Linux/BSD default is \"/var/run/olsrd-ipv(4/6).lock\")\n"
328 "# (Win32 default is \"[configfile]-ipv(4/6).lock\")\n"
331 char * lockfile_default = olsrd_get_default_lockfile(cnf);
332 abuf_appendf(out, "%sLockFile \"%s\"\n",
333 !strcmp(cnf->lock_file, lockfile_default) ? "# " : "",
335 free(lockfile_default);
339 "# Polling rate for OLSR sockets in seconds (float).\n"
340 "# (default is %.2f)\n"
341 "\n", (double)DEF_POLLRATE);
342 abuf_appendf(out, "%sPollrate %.2f\n",
343 cnf->pollrate == (float)DEF_POLLRATE ? "# " : "",
344 (double)cnf->pollrate);
347 "# Interval to poll network interfaces for configuration changes (in seconds).\n"
348 "# Linux systems can detect interface statechange via netlink sockets.\n"
349 "# (default is %.1f)\n"
350 "\n", (double)DEF_NICCHGPOLLRT);
351 abuf_appendf(out, "%sNicChgsPollInt %.1f\n",
352 cnf->nic_chgs_pollrate == (float)DEF_NICCHGPOLLRT ? "# " : "",
353 (double)cnf->nic_chgs_pollrate);
356 "# TOS(type of service) value for the IP header of control traffic.\n"
357 "# (default is %u)\n"
359 abuf_appendf(out, "%sTosValue %u\n",
360 cnf->tos == DEF_TOS ? "# " : "",
364 "# FIBMetric controls the metric value of the host-routes OLSRd sets.\n"
365 "# - \"flat\" means that the metric value is always 2 (or as configured\n"
366 "# with FIBMetricDefault). This is the preferred value because it helps\n"
367 "# the linux kernel routing to clean up older routes\n"
368 "# - \"correct\" use the hopcount as the metric value.\n"
369 "# - \"approx\" use the hopcount as the metric value too, but does only update the\n"
370 "# hopcount if the nexthop changes too\n"
371 "# (default is \"%s\")\n"
372 "\n", FIB_METRIC_TXT[DEF_FIB_METRIC]);
373 abuf_appendf(out, "%sFIBMetric \"%s\"\n",
374 cnf->fib_metric == DEF_FIB_METRIC ? "# " : "",
375 FIB_METRIC_TXT[cnf->fib_metric]);
378 "# Default FIB metric.\n"
379 "# The kernel FIB does not need to know the metric of a route.\n"
380 "# This saves us from enqueuing/dequeueing hopcount only changes.\n"
381 "# (default is %u)\n"
382 "\n", DEF_FIB_METRIC_DEFAULT);
383 abuf_appendf(out, "%sFIBMetricDefault %u\n",
384 cnf->fib_metric_default == DEF_FIB_METRIC_DEFAULT? "# " : "",
385 cnf->fib_metric_default);
388 "#######################################\n"
389 "### Linux specific OLSRd extensions ###\n"
390 "#######################################\n"
391 "# these parameters are only working on linux at the moment, but might become\n"
392 "# useful on BSD in the future\n"
394 "# SrcIpRoutes tells OLSRd to set the Src flag of host routes to the originator-ip\n"
395 "# of the node. In addition to this an additional localhost device is created\n"
396 "# to make sure the returning traffic can be received.\n"
397 "# (default is \"%s\")\n"
398 "\n", DEF_USE_SRCIP_ROUTES ? "yes" : "no");
399 abuf_appendf(out, "%sSrcIpRoutes %s\n",
400 cnf->use_src_ip_routes == DEF_USE_SRCIP_ROUTES ? "# " : "",
401 cnf->use_src_ip_routes ? "yes" : "no");
404 "# Specify the proto tag to be used for routes olsr inserts into kernel\n"
405 "# currently only implemented for linux\n"
406 "# valid values under linux are 1 .. 254\n"
407 "# 1 gets remapped by olsrd to 0 UNSPECIFIED (1 is reserved for ICMP redirects)\n"
408 "# 2 KERNEL routes (not very wise to use)\n"
409 "# 3 BOOT (should in fact not be used by routing daemons)\n"
411 "# 8 .. 15 various routing daemons (gated, zebra, bird, & co)\n"
412 "# (default is %u which gets replaced by an OS-specific default value\n"
413 "# under linux 3 (BOOT) (for backward compatibility)\n"
415 abuf_appendf(out, "%sRtProto %u\n",
416 cnf->rt_proto == DEF_RTPROTO ? "# " : "",
420 "# Specifies the routing Table olsr uses\n"
421 "# RtTable is for host routes, RtTableDefault for the route to the default\n"
422 "# internet gateway (2 in case of IPv6+NIIT) and RtTableTunnel is for\n"
423 "# routes to the ipip tunnels, valid values are 1 to 254\n"
424 "# There is a special parameter \"auto\" (choose default below)\n"
425 "# (with smartgw: default is %u/%u/%u)\n"
426 "# (without smartgw: default is %u/%u/%u, linux main table)\n"
428 DEF_SGW_RT_TABLE_NR, DEF_SGW_RT_TABLE_DEFAULT_NR, DEF_SGW_RT_TABLE_TUNNEL_NR,
429 DEF_RT_TABLE_NR, DEF_RT_TABLE_DEFAULT_NR, DEF_RT_TABLE_TUNNEL_NR);
430 if (!cnf->smart_gw_active) {
431 abuf_appendf(out, "%sRtTable %u\n",
432 cnf->rt_table == DEF_RT_TABLE_NR ? "# " : "",
434 abuf_appendf(out, "%sRtTableDefault %u\n",
435 cnf->rt_table_default == DEF_RT_TABLE_DEFAULT_NR ? "# " : "",
436 cnf->rt_table_default);
437 abuf_appendf(out, "%sRtTableTunnel %u\n",
438 cnf->rt_table_tunnel == DEF_RT_TABLE_TUNNEL_NR ? "# " : "",
439 cnf->rt_table_tunnel);
441 abuf_appendf(out, "%sRtTable %u\n",
442 cnf->rt_table == DEF_SGW_RT_TABLE_NR ? "# " : "",
444 abuf_appendf(out, "%sRtTableDefault %u\n",
445 cnf->rt_table_default == DEF_SGW_RT_TABLE_DEFAULT_NR ? "# " : "",
446 cnf->rt_table_default);
447 abuf_appendf(out, "%sRtTableTunnel %u\n",
448 cnf->rt_table_tunnel == DEF_SGW_RT_TABLE_TUNNEL_NR ? "# " : "",
449 cnf->rt_table_tunnel);
453 "# Specifies the policy rule priorities for the three routing tables and\n"
454 "# a special rule for smartgateway routing (see README-Olsr-Extensions)\n"
455 "# Priorities can only be set if three different routing tables are set.\n"
456 "# if set the values must obey to condition\n"
457 "# RtTablePriority less than RtTableDefaultOlsrPriority\n"
458 "# less than RtTableTunnelPriority less than RtTableDefaultPriority\n"
459 "# There are two special parameters, \"auto\" (choose fitting to SmartGW\n"
460 "# mode) and \"none\" (do not set policy rule)\n"
461 "# (with smartgw: default is %d/%u/%u/%u)\n"
462 "# (without smartgw: default is %d/%d /%d /%d )\n"
464 DEF_SGW_RT_TABLE_PRI,
465 DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER,
466 DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER + DEF_SGW_RT_TABLE_TUNNEL_PRI_ADDER,
467 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,
469 DEF_RT_TABLE_DEFAULTOLSR_PRI,
470 DEF_RT_TABLE_TUNNEL_PRI,
471 DEF_RT_TABLE_DEFAULT_PRI);
472 if (!cnf->smart_gw_active) {
473 if (cnf->rt_table_pri == DEF_RT_TABLE_PRI) {
474 abuf_appendf(out, "# RtTablePriority %d\n",
477 abuf_appendf(out, "RtTablePriority %u\n",
480 if (cnf->rt_table_defaultolsr_pri == DEF_RT_TABLE_DEFAULTOLSR_PRI) {
481 abuf_appendf(out, "# RtTableDefaultOlsrPriority %d\n",
482 cnf->rt_table_defaultolsr_pri);
484 abuf_appendf(out, "RtTableDefaultOlsrPriority %u\n",
485 cnf->rt_table_defaultolsr_pri);
487 if (cnf->rt_table_tunnel_pri == DEF_RT_TABLE_TUNNEL_PRI) {
488 abuf_appendf(out, "# RtTableTunnelPriority %d\n",
489 cnf->rt_table_tunnel_pri);
491 abuf_appendf(out, "RtTableTunnelPriority %u\n",
492 cnf->rt_table_tunnel_pri);
494 if (cnf->rt_table_default_pri == DEF_RT_TABLE_DEFAULT_PRI) {
495 abuf_appendf(out, "# RtTableDefaultPriority %d\n",
496 cnf->rt_table_default_pri);
498 abuf_appendf(out, "RtTableDefaultPriority %u\n",
499 cnf->rt_table_default_pri);
502 if (cnf->rt_table_pri == DEF_SGW_RT_TABLE_PRI) {
503 abuf_appendf(out, "# RtTablePriority %d\n",
506 abuf_appendf(out, "RtTablePriority %u\n",
509 abuf_appendf(out, "%sRtTableDefaultOlsrPriority %u\n",
510 cnf->rt_table_defaultolsr_pri == (DEF_SGW_RT_TABLE_PRI_BASE + DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER) ? "# " : "",
511 cnf->rt_table_defaultolsr_pri);
513 abuf_appendf(out, "%sRtTableTunnelPriority %u\n",
514 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) ? "# " : "",
515 cnf->rt_table_tunnel_pri);
517 abuf_appendf(out, "%sRtTableDefaultPriority %u\n",
518 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) ? "# " : "",
519 cnf->rt_table_default_pri);
523 "# Activates (in IPv6 mode) the automatic use of NIIT\n"
524 "# (see README-Olsr-Extensions)\n"
525 "# (default is \"%s\")\n"
526 "\n", DEF_USE_NIIT ? "yes" : "no");
527 abuf_appendf(out, "%sUseNiit %s\n",
528 cnf->use_niit == DEF_USE_NIIT ? "# " : "",
529 cnf->use_niit ? "yes" : "no");
532 "# Activates the smartgateway ipip tunnel feature.\n"
533 "# See README-Olsr-Extensions for a description of smartgateways.\n"
534 "# (default is \"%s\")\n"
535 "\n", DEF_SMART_GW ? "yes" : "no");
536 abuf_appendf(out, "%sSmartGateway %s\n",
537 cnf->smart_gw_active == DEF_SMART_GW ? "# " : "",
538 cnf->smart_gw_active ? "yes" : "no");
541 "# Signals that the server tunnel must always be removed on shutdown,\n"
542 "# irrespective of the interface up/down state during startup.\n"
543 "# (default is \"%s\")\n"
544 "\n", DEF_SMART_GW_ALWAYS_REMOVE_SERVER_TUNNEL ? "yes" : "no");
545 abuf_appendf(out, "%sSmartGatewayAlwaysRemoveServerTunnel %s\n",
546 cnf->smart_gw_always_remove_server_tunnel == DEF_SMART_GW_ALWAYS_REMOVE_SERVER_TUNNEL ? "# " : "",
547 cnf->smart_gw_always_remove_server_tunnel ? "yes" : "no");
550 "# Determines the maximum number of gateways that can be in use at any given\n"
551 "# time. This setting is used to mitigate the effects of breaking connections\n"
552 "# (due to the selection of a new gateway) on a dynamic network.\n"
553 "# (default is %u)\n"
554 "\n", DEF_GW_USE_COUNT);
555 abuf_appendf(out, "%sSmartGatewayUseCount %d\n",
556 cnf->smart_gw_use_count == DEF_GW_USE_COUNT ? "# " : "",
557 cnf->smart_gw_use_count);
560 "# Determines the take-down percentage for a non-current smart gateway tunnel.\n"
561 "# If the cost of the current smart gateway tunnel is less than this percentage\n"
562 "# of the cost of the non-current smart gateway tunnel, then the non-current smart\n"
563 "# gateway tunnel is taken down because it is then presumed to be 'too expensive'.\n"
564 "# This setting is only relevant when SmartGatewayUseCount is larger than 1;\n"
565 "# a value of 0 will result in the tunnels not being taken down proactively.\n"
566 "# (default is %u)\n"
567 "\n", DEF_GW_TAKEDOWN_PERCENTAGE);
568 abuf_appendf(out, "%sSmartGatewayTakeDownPercentage %d\n",
569 cnf->smart_gw_takedown_percentage == DEF_GW_TAKEDOWN_PERCENTAGE ? "# " : "",
570 cnf->smart_gw_takedown_percentage);
573 "# Determines the policy routing script that is executed during startup and\n"
574 "# shutdown of olsrd. The script is only executed when SmartGatewayUseCount\n"
575 "# is set to a value larger than 1. The script must setup policy routing\n"
576 "# rules such that multi-gateway mode works. A sample script is included.\n"
577 "# (default is not set)\n"
579 abuf_appendf(out, "%sSmartGatewayPolicyRoutingScript %s\n",
580 !cnf->smart_gw_policyrouting_script ? "# " : "",
581 !cnf->smart_gw_policyrouting_script ? "" : cnf->smart_gw_policyrouting_script);
584 "# Determines the egress interfaces that are part of the multi-gateway setup and\n"
585 "# therefore only relevant when SmartGatewayUseCount is larger than 1 (in which\n"
586 "# case it must be explicitly set).\n"
587 "# (default is not set)\n"
589 abuf_appendf(out, "%sSmartGatewayEgressInterfaces",
590 !cnf->smart_gw_egress_interfaces ? "# " : "");
592 struct sgw_egress_if * sgwegressif = olsr_cnf->smart_gw_egress_interfaces;
593 while (sgwegressif) {
594 abuf_appendf(out, " \"%s\"", sgwegressif->name);
595 sgwegressif = sgwegressif->next;
597 abuf_puts(out, "\n");
601 "# SmartGatewayEgressFile declares the file that contains the bandwidth\n"
602 "# parameters of the egress interfaces declared by SmartGatewayEgressInterfaces.\n"
603 "# Every line in the file declares bandwidth parameters of an egress interface,\n"
604 "# with the format:\n"
605 "# # this is a comment\n"
606 "# interface=upstream,downstream,pathcost,network/prefix,gateway\n"
607 "# Only the upstream and downstream fields are mandatory, the other fields are\n"
608 "# optional. An empty field signifies that its default should be used.\n"
609 "# The field defaults are:\n"
610 "# upstream = 0 (Kbps)\n"
611 "# downstream = 0 (Kbps)\n"
612 "# pathcost = 0 (dimensionless, 1024 is equivalent to 1 hop)\n"
613 "# network/prefix = no default / not set\n"
614 "# - network is an IP address\n"
615 "# - prefix is a number in the range [0, 24] for IPv4\n"
616 "# and in the range [0, 128] for IPv6\n"
617 "# gateway = no default / not set (IP address)\n"
618 "# (default is %s)\n"
619 "\n", DEF_GW_EGRESS_FILE);
621 bool def = !cnf->smart_gw_egress_file || !strcmp(cnf->smart_gw_egress_file, DEF_GW_EGRESS_FILE);
622 abuf_appendf(out, "%sSmartGatewayEgressFile %s\n",
623 def ? "# " : "", def ? DEF_GW_EGRESS_FILE : cnf->smart_gw_egress_file);
627 "# SmartGatewayEgressFilePeriod determines the period (in milliseconds) on which\n"
628 "# the SmartGatewayEgressFile is checked for changes and processed if changed.\n"
629 "# (default is %u)\n"
630 "\n", DEF_GW_EGRESS_FILE_PERIOD);
631 abuf_appendf(out, "%sSmartGatewayEgressFilePeriod %u\n",
632 cnf->smart_gw_egress_file_period == DEF_GW_EGRESS_FILE_PERIOD ? "# " : "",
633 cnf->smart_gw_egress_file_period);
636 "# Declares the file that is written by olsrd to contain the status of the smart\n"
637 "# gateways and is only relevant when SmartGatewayUseCount is larger than 1.\n"
638 "# (default is %s)\n"
641 bool def = !cnf->smart_gw_status_file || !strlen(cnf->smart_gw_status_file);
642 abuf_appendf(out, "%sSmartGatewayStatusFile %s\n",
643 def ? "# " : "", def ? "<not set>" : cnf->smart_gw_status_file);
647 "# Determines the routing tables offset for multi-gateway policy routing tables\n"
648 "# See the policy routing script for an explanation.\n"
649 "# (default is %u)\n"
650 "\n", DEF_GW_OFFSET_TABLES);
651 abuf_appendf(out, "%sSmartGatewayTablesOffset %u\n",
652 cnf->smart_gw_offset_tables == DEF_GW_OFFSET_TABLES ? "# " : "",
653 cnf->smart_gw_offset_tables);
656 "# Determines the policy routing rules offset for multi-gateway policy routing\n"
657 "# rules. See the policy routing script for an explanation.\n"
658 "# (default is %u, which indicates that the rules and tables should be aligned and\n"
659 "# puts this value at SmartGatewayTablesOffset - # egress interfaces -\n"
660 "# # olsr interfaces)\n"
661 "\n", DEF_GW_OFFSET_RULES);
662 abuf_appendf(out, "%sSmartGatewayRulesOffset %u\n",
663 cnf->smart_gw_offset_rules == DEF_GW_OFFSET_RULES ? "# " : "",
664 cnf->smart_gw_offset_rules);
667 "# Allows the selection of a smartgateway with NAT (only for IPv4)\n"
668 "# (default is \"%s\")\n"
669 "\n", DEF_GW_ALLOW_NAT ? "yes" : "no");
670 abuf_appendf(out, "%sSmartGatewayAllowNAT %s\n",
671 cnf->smart_gw_allow_nat == DEF_GW_ALLOW_NAT ? "# " : "",
672 cnf->smart_gw_allow_nat ? "yes" : "no");
675 "# Determines the period (in milliseconds) on which a new smart gateway\n"
676 "# selection is performed.\n"
677 "# (default is %u milliseconds)\n"
678 "\n", DEF_GW_PERIOD);
679 abuf_appendf(out, "%sSmartGatewayPeriod %d\n",
680 cnf->smart_gw_period == DEF_GW_PERIOD ? "# " : "",
681 cnf->smart_gw_period);
684 "# Determines the number of times the link state database must be stable\n"
685 "# before a new smart gateway is selected.\n"
686 "# (default is %u)\n"
687 "\n", DEF_GW_STABLE_COUNT);
688 abuf_appendf(out, "%sSmartGatewayStableCount %d\n",
689 cnf->smart_gw_stablecount == DEF_GW_STABLE_COUNT ? "# " : "",
690 cnf->smart_gw_stablecount);
693 "# When another gateway than the current one has a cost of less than the cost\n"
694 "# of the current gateway multiplied by SmartGatewayThreshold then the smart\n"
695 "# gateway is switched to the other gateway. The unit is percentage.\n"
696 "# (default is %u)\n"
697 "\n", DEF_GW_THRESH);
698 abuf_appendf(out, "%sSmartGatewayThreshold %d\n",
699 cnf->smart_gw_thresh == DEF_GW_THRESH ? "# " : "",
700 cnf->smart_gw_thresh);
703 "# The weighing factor for the gateway uplink bandwidth (exit link, uplink).\n"
704 "# See README-Olsr-Extensions for a description of smart gateways.\n"
705 "# (default is %lu)\n"
706 "\n", (long unsigned int)DEF_GW_WEIGHT_EXITLINK_UP);
707 abuf_appendf(out, "%sSmartGatewayWeightExitLinkUp %d\n",
708 cnf->smart_gw_weight_exitlink_up == DEF_GW_WEIGHT_EXITLINK_UP ? "# " : "",
709 cnf->smart_gw_weight_exitlink_up);
712 "# The weighing factor for the gateway downlink bandwidth (exit link, downlink).\n"
713 "# See README-Olsr-Extensions for a description of smart gateways.\n"
714 "# (default is %lu)\n"
715 "\n", (long unsigned int)DEF_GW_WEIGHT_EXITLINK_DOWN);
716 abuf_appendf(out, "%sSmartGatewayWeightExitLinkDown %d\n",
717 cnf->smart_gw_weight_exitlink_down == DEF_GW_WEIGHT_EXITLINK_DOWN ? "# " : "",
718 cnf->smart_gw_weight_exitlink_down);
721 "# The weighing factor for the ETX costs.\n"
722 "# See README-Olsr-Extensions for a description of smart gateways.\n"
723 "# (default is %u)\n"
724 "\n", DEF_GW_WEIGHT_ETX);
725 abuf_appendf(out, "%sSmartGatewayWeightEtx %d\n",
726 cnf->smart_gw_weight_etx == DEF_GW_WEIGHT_ETX ? "# " : "",
727 cnf->smart_gw_weight_etx);
730 "# The divider for the ETX costs.\n"
731 "# See README-Olsr-Extensions for a description of smart gateways.\n"
732 "# (default is %u)\n"
733 "\n", DEF_GW_DIVIDER_ETX);
734 abuf_appendf(out, "%sSmartGatewayDividerEtx %d\n",
735 cnf->smart_gw_divider_etx == DEF_GW_DIVIDER_ETX ? "# " : "",
736 cnf->smart_gw_divider_etx);
739 "# Defines what kind of Uplink this node will publish as a\n"
740 "# smartgateway. The existence of the uplink is detected by\n"
741 "# a route to 0.0.0.0/0, ::ffff:0:0/96 and/or 2000::/3.\n"
742 "# possible values are \"none\", \"ipv4\", \"ipv6\", \"both\"\n"
743 "# (default is \"%s\")\n"
744 "\n", GW_UPLINK_TXT[DEF_GW_TYPE]);
745 abuf_appendf(out, "%sSmartGatewayUplink \"%s\"\n",
746 cnf->smart_gw_type == DEF_GW_TYPE ? "# " : "",
747 GW_UPLINK_TXT[cnf->smart_gw_type]);
750 "# Specifies if the local ipv4 uplink use NAT\n"
751 "# (default is \"%s\")\n"
752 "\n", DEF_GW_UPLINK_NAT ? "yes" : "no");
753 abuf_appendf(out, "%sSmartGatewayUplinkNAT %s\n",
754 cnf->smart_gw_uplink_nat == DEF_GW_UPLINK_NAT ? "# " : "",
755 cnf->smart_gw_uplink_nat ? "yes" : "no");
758 "# Specifies the speed of the uplink in kilobit/s.\n"
759 "# First parameter is upstream, second parameter is downstream\n"
760 "# (default is %u/%u)\n"
761 "\n", DEF_UPLINK_SPEED, DEF_DOWNLINK_SPEED);
762 abuf_appendf(out, "%sSmartGatewaySpeed %d %d\n",
763 cnf->smart_gw_uplink == DEF_UPLINK_SPEED && cnf->smart_gw_downlink == DEF_DOWNLINK_SPEED ? "# " : "",
764 cnf->smart_gw_uplink, cnf->smart_gw_downlink);
767 "# Specifies the EXTERNAL ipv6 prefix of the uplink. A prefix\n"
768 "# length of more than 64 is not allowed.\n"
769 "# (default is 0::/0)\n"
771 abuf_appendf(out, "%sSmartGatewayPrefix %s\n",
772 cnf->smart_gw_prefix.prefix_len == 0 ? "# " : "",
773 olsr_ip_prefix_to_string(&cnf->smart_gw_prefix));
776 "##############################\n"
777 "### OLSR protocol settings ###\n"
778 "##############################\n"
780 "# For testing purposes it may be nice to use another port for olsrd\n"
781 "# for using another port than the IANA assigned one\n"
782 "# for a production network, there should be a good reason!!\n"
783 "# valid values are integers greater than 1, please be careful with\n"
784 "# using reserved port numbers\n"
785 "# (default is %u, the IANA assigned olsr-port)\n"
787 abuf_appendf(out, "%sOlsrPort %u\n",
788 cnf->olsrport == DEF_OLSRPORT ? "# " : "",
792 "# Sets the main IP (originator ip) of the router. This IP will NEVER\n"
793 "# change during the uptime of olsrd.\n"
794 "# (default is 0.0.0.0, which triggers usage of the IP of the first interface)\n"
796 abuf_appendf(out, "MainIp %s\n",
797 olsr_ip_to_string(&ipbuf, &cnf->main_addr));
800 "# The fixed willingness to use (0-7)\n"
801 "# If not set willingness will be calculated\n"
802 "# dynamically based on battery/power status\n"
803 "# (default is %u)\n"
804 "\n", DEF_WILLINGNESS);
805 abuf_appendf(out, "%sWillingness %u\n",
806 cnf->willingness == DEF_WILLINGNESS ? "# " : "",
810 "# HNA (Host network association) allows the OLSR to announce\n"
811 "# additional IPs or IP subnets to the net that are reachable\n"
812 "# through this node.\n"
813 "# Syntax for HNA4 is \"network-address network-mask\"\n"
814 "# Syntax for HNA6 is \"network-address prefix-length\"\n"
815 "# (default is no HNA)\n");
816 abuf_appendf(out, "Hna%u\n"
818 cnf->ip_version == AF_INET ? 4 : 6);
820 struct ipaddr_str strbuf;
821 abuf_appendf(out, " %s\n", olsr_ip_prefix_to_string(&hna->net));
827 "# Hysteresis for link sensing (only for hopcount metric)\n"
828 "# Hysteresis adds more robustness to the link sensing\n"
829 "# but delays neighbor registration.\n"
830 "# (default is %s)\n"
831 "\n", DEF_USE_HYST ? "yes" : "no");
832 abuf_appendf(out, "%sUseHysteresis %s\n",
833 cnf->use_hysteresis == DEF_USE_HYST ? "# " : "",
834 cnf->use_hysteresis ? "yes" : "no");
837 "# Hysteresis parameters (only for hopcount metric)\n"
838 "# Do not alter these unless you know what you are doing!\n"
839 "# Set to auto by default. Allowed values are floating point\n"
840 "# values in the interval 0,1\n"
841 "# THR_LOW must always be lower than THR_HIGH!!\n"
842 "# (default is %.2f/%.2f/%.2f)\n"
843 "\n", (double)HYST_SCALING, (double)HYST_THRESHOLD_HIGH, (double)HYST_THRESHOLD_LOW);
844 abuf_appendf(out, "%sHystScaling %.2f\n",
845 cnf->hysteresis_param.scaling == (float)HYST_SCALING ? "# " : "",
846 (double)cnf->hysteresis_param.scaling);
847 abuf_appendf(out, "%sHystThrHigh %.2f\n",
848 cnf->hysteresis_param.thr_high == (float)HYST_THRESHOLD_HIGH ? "# " : "",
849 (double)cnf->hysteresis_param.thr_high);
850 abuf_appendf(out, "%sHystThrLow %.2f\n",
851 cnf->hysteresis_param.thr_low == (float)HYST_THRESHOLD_LOW ? "# " : "",
852 (double)cnf->hysteresis_param.thr_low);
856 "# Specifies how much neighbor info should be sent in\n"
857 "# TC messages. Because of a design problem in the 0.5.x\n"
858 "# dijkstra implementation this value must be set to 2.\n"
859 "# 2 - send all neighbors\n"
860 "# (default is %u)\n"
861 "\n", TC_REDUNDANCY);
862 abuf_appendf(out, "%sTcRedundancy %d\n",
863 cnf->tc_redundancy == TC_REDUNDANCY ? "# " : "",
867 "# MPR coverage specifies how many MPRs a node should\n"
868 "# try select to reach every 2 hop neighbor. Because of\n"
869 "# a design problem in the 0.5.x dijkstra algorithm this\n"
870 "# value should be set to 7.\n"
871 "# (default is %u)\n"
873 abuf_appendf(out, "%sMprCoverage %d\n",
874 cnf->mpr_coverage == MPR_COVERAGE ? "# " : "",
878 "################################\n"
879 "### OLSR protocol extensions ###\n"
880 "################################\n"
882 "# Link quality level switch between hopcount and\n"
883 "# cost-based (mostly ETX) routing. Because of\n"
884 "# a design problem in the 0.5.x dijkstra algorithm this\n"
885 "# value should not be set to 1.\n"
886 "# 0 = do not use link quality\n"
887 "# 2 = use link quality for MPR selection and routing\n"
888 "# (default is %u)\n"
890 abuf_appendf(out, "%sLinkQualityLevel %d\n",
891 cnf->lq_level == DEF_LQ_LEVEL ? "# " : "",
895 "# Link quality algorithm (only for lq level 2)\n"
896 "# (see README-Olsr-Extensions)\n"
897 "# - \"etx_float\", a floating point ETX with exponential aging\n"
898 "# - \"etx_fpm\", same as ext_float, but with integer arithmetic\n"
899 "# - \"etx_ff\" (ETX freifunk), an etx variant which use all OLSR\n"
900 "# traffic (instead of only hellos) for ETX calculation\n"
901 "# - \"etx_ffeth\", an incompatible variant of etx_ff that allows\n"
902 "# ethernet links with ETX 0.1.\n"
903 "# (default is \"%s\")\n"
904 "\n", DEF_LQ_ALGORITHM);
905 abuf_appendf(out, "%sLinkQualityAlgorithm \"%s\"\n",
906 cnf->lq_algorithm == NULL ? "# " : "",
907 cnf->lq_algorithm == NULL ? DEF_LQ_ALGORITHM : cnf->lq_algorithm);
910 "# Link quality aging factor (only for lq level 2)\n"
911 "# Tuning parameter for etx_float and etx_fpm, smaller values\n"
912 "# mean slower changes of ETX value. (allowed values are\n"
913 "# between 0.01 and 1.0)\n"
914 "# (default is %.2f)\n"
915 "\n", (double)DEF_LQ_AGING);
916 abuf_appendf(out, "%sLinkQualityAging %.2f\n",
917 cnf->lq_aging == (float)DEF_LQ_AGING ? "# " : "",
918 (double)cnf->lq_aging);
921 "# Fisheye mechanism for TCs (0 meansoff, 1 means on)\n"
922 "# (default is %u)\n"
924 abuf_appendf(out, "%sLinkQualityFishEye %d\n",
925 cnf->lq_fish == DEF_LQ_FISH ? "# " : "",
932 "# (currently this is only in the freifunk firmware)\n"
933 "# If the NAT-Endpoint (the preferred 0/0 HNA emitting node)\n"
934 "# is to be changed, the ETX value of the current 0/0 is\n"
935 "# multiplied with the NatThreshold value before being\n"
936 "# compared to the new one.\n"
937 "# The parameter can be a value between 0.1 and 1.0, but\n"
938 "# should be close to 1.0 if changed.\n"
939 "# WARNING: This parameter should not be used together with\n"
940 "# the etx_ffeth metric !!\n"
941 "# (default is %.1f)\n"
942 "\n", (double)DEF_LQ_NAT_THRESH);
943 abuf_appendf(out, "%sNatThreshold %.1f\n",
944 cnf->lq_nat_thresh == (float)DEF_LQ_NAT_THRESH ? "# " : "",
945 (double)cnf->lq_nat_thresh);
949 "#############################################################\n"
950 "### Configuration of the IPC to the windows GUI interface ###\n"
951 "#############################################################\n"
955 " # Determines how many simultaneously\n"
956 " # IPC connections that will be allowed\n"
957 " # Setting this to 0 disables IPC\n"
959 abuf_appendf(out, " %sMaxConnections %d\n",
960 cnf->ipc_connections == DEF_IPC_CONNECTIONS ? "# " : "",
961 cnf->ipc_connections);
964 " # By default only 127.0.0.1 is allowed\n"
965 " # to connect. Here allowed hosts and networks can\n"
970 if (ipc_nets->net.prefix_len == olsr_cnf->maxplen) {
971 abuf_appendf(out, " Host %s\n", olsr_ip_to_string(&ipbuf, &ipc_nets->net.prefix));
973 abuf_appendf(out, " Net %s\n", olsr_ip_prefix_to_string(&ipc_nets->net));
975 ipc_nets = ipc_nets->next;
980 "#####################################\n"
981 "### Example plugin configurations ###\n"
982 "#####################################\n"
983 "# Olsrd plugins to load\n"
984 "# This must be the absolute path to the file\n"
985 "# or the loader will use the following scheme:\n"
986 "# - Try the paths in the LD_LIBRARY_PATH\n"
987 "# environment variable.\n"
988 "# - The list of libraries cached in /etc/ld.so.cache\n"
989 "# - /lib, followed by /usr/lib\n"
993 abuf_appendf(out, "LoadPlugin \"%s\" {\n", plugins->name);
994 pl_param = plugins->params;
996 abuf_appendf(out, " PlParam \"%s\" \"%s\"\n", pl_param->key, pl_param->value);
997 pl_param = pl_param->next;
1001 plugins = plugins->next;
1005 "#############################################\n"
1006 "### OLSRD default interface configuration ###\n"
1007 "#############################################\n"
1008 "# the default interface section can have the same values as the following\n"
1009 "# interface configuration. It will allow you so set common options for all\n"
1012 "InterfaceDefaults\n");
1013 olsrd_write_if_autobuf(out, cnf, cnf->interface_defaults, false);
1016 "######################################\n"
1017 "### OLSRd Interfaces configuration ###\n"
1018 "######################################\n"
1019 "# multiple interfaces can be specified for a single configuration block\n"
1020 "# multiple configuration blocks can be specified\n"
1024 abuf_appendf(out, "Interface \"%s\"\n", interf->name);
1025 olsrd_write_if_autobuf(out, cnf, interf->cnf, first);
1028 interf = interf->next;
1033 "# END AUTOGENERATED CONFIG\n");
1038 * indent-tabs-mode: nil