969cf09323aa96de9fe1769cdf9d327f48f7602c
[olsrd.git] / src / cfgparser / cfgfile_gen.c
1 /*
2  * The olsr.org Optimized Link-State Routing daemon(olsrd)
3  * Copyright (c) 2005, Andreas Tonnesen(andreto@olsr.org)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
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
15  *   distribution.
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.
19  *
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.
32  *
33  * Visit http://www.olsr.org for more information.
34  *
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.
38  *
39  */
40
41 #include "olsrd_conf.h"
42 #include "../ipcalc.h"
43 #include "../net_olsr.h"
44
45 #include <stdio.h>
46 #include <string.h>
47 #include <errno.h>
48 #include <sys/types.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51
52 int
53 olsrd_write_cnf (struct olsrd_config *cnf, const char *fname)
54 {
55   struct ip_prefix_list *h = cnf->hna_entries;
56   struct olsr_if *in = cnf->interfaces;
57   struct plugin_entry *pe = cnf->plugins;
58   struct plugin_param *pp;
59   struct ip_prefix_list *ie = cnf->ipc_nets;
60   struct olsr_lq_mult *mult;
61
62   char ipv6_buf[100];           /* buffer for IPv6 inet_htop */
63
64   FILE *fd;
65
66   fd = fopen (fname, "w");
67
68   if (fd == NULL)
69     {
70       fprintf (stderr, "Could not open file %s for writing\n%s\n", fname,
71                strerror (errno));
72       return -1;
73     }
74
75   printf ("Writing config to file \"%s\".... ", fname);
76
77   fprintf (fd,
78            "#\n# Configuration file for s%s\n# automatically generated by olsrd-cnf parser v. %s\n#\n\n",
79            olsrd_version, PARSER_VERSION);
80
81   /* Debug level */
82   fprintf (fd,
83            "# Debug level(0-9)\n# If set to 0 the daemon runs in the background\n\nDebugLevel\t%d\n\n",
84            cnf->debug_level);
85
86   /* IP version */
87   fprintf (fd, "# IP version to use (4 or 6)\n\nIpVersion\t%d\n\n",
88            cnf->ip_version == AF_INET ? 4 : 6);
89
90   /* FIB Metric */
91   fprintf (fd,
92            "# FIBMetric (\"%s\", \"%s\", or \"%s\")\n\nFIBMetric\t\"%s\"\n\n",
93            CFG_FIBM_FLAT, CFG_FIBM_CORRECT, CFG_FIBM_APPROX,
94            FIBM_FLAT == cnf->fib_metric ? CFG_FIBM_FLAT : FIBM_CORRECT ==
95            cnf->fib_metric ? CFG_FIBM_CORRECT : CFG_FIBM_APPROX);
96
97   /* HNA IPv4/IPv6 */
98   fprintf (fd, "# HNA IPv%d routes\n# syntax: netaddr/prefix\n\nHna%d {\n",
99            cnf->ip_version == AF_INET ? 4 : 6,
100            cnf->ip_version == AF_INET ? 4 : 6);
101   while (h)
102     {
103       struct ipaddr_str strbuf;
104       fprintf (fd, "    %s/%d\n", olsr_ip_to_string (&strbuf, &h->net.prefix),
105                h->net.prefix_len);
106       h = h->next;
107     }
108   fprintf (fd, "}\n\n");
109
110   /* No interfaces */
111   fprintf (fd,
112            "# Should olsrd keep on running even if there are\n# no interfaces available? This is a good idea\n# for a PCMCIA/USB hotswap environment.\n# \"yes\" OR \"no\"\n\nAllowNoInt\t");
113   if (cnf->allow_no_interfaces)
114     fprintf (fd, "yes\n\n");
115   else
116     fprintf (fd, "no\n\n");
117
118   /* TOS */
119   fprintf (fd, "# TOS(type of service) to use. Default is 16\n\n");
120   fprintf (fd, "TosValue\t%d\n\n", cnf->tos);
121
122   /* RtTable */
123   fprintf (fd, "# Policy Routing Table to use. Default is 254\n\n");
124   fprintf (fd, "RtTable\t\t%d\n\n", cnf->rttable);
125
126   /* RtTableDefault */
127   fprintf (fd,
128            "# Policy Routing Table to use for the default Route. Default is 0 (Take the same table as specified by RtTable)\n\n");
129   fprintf (fd, "RtTableDefault\t\t%d\n\n", cnf->rttable_default);
130
131   /* Willingness */
132   fprintf (fd,
133            "# The fixed willingness to use(0-7)\n# If not set willingness will be calculated\n# dynammically based on battery/power status\n\n");
134   if (cnf->willingness_auto)
135     fprintf (fd, "#Willingness\t4\n\n");
136   else
137     fprintf (fd, "Willingness\t%d\n\n", cnf->willingness);
138
139   /* IPC */
140   fprintf (fd,
141            "# Allow processes like the GUI front-end\n# to connect to the daemon.\n\n");
142   fprintf (fd, "IpcConnect {\n");
143   fprintf (fd, "    MaxConnections\t%d\n", cnf->ipc_connections);
144
145   while (ie)
146     {
147       struct ipaddr_str strbuf;
148       if (ie->net.prefix_len == olsr_cnf->maxplen)
149         {
150           fprintf (fd, "    Host\t\t%s\n",
151                    olsr_ip_to_string (&strbuf, &ie->net.prefix));
152         }
153       else
154         {
155           fprintf (fd, "    Net\t\t\t%s/%d\n",
156                    olsr_ip_to_string (&strbuf, &ie->net.prefix),
157                    ie->net.prefix_len);
158         }
159       ie = ie->next;
160     }
161
162   fprintf (fd, "}\n\n");
163
164   /* Hysteresis */
165   fprintf (fd,
166            "# Hysteresis adds more robustness to the\n# link sensing.\n# Used by default. 'yes' or 'no'\n\n");
167
168   if (cnf->use_hysteresis)
169     {
170       fprintf (fd, "UseHysteresis\tyes\n\n");
171       fprintf (fd,
172                "# Hysteresis parameters\n# Do not alter these unless you know \n# what you are doing!\n# Set to auto by default. Allowed\n# values are floating point values\n# in the interval 0,1\n# THR_LOW must always be lower than\n# THR_HIGH!!\n\n");
173       fprintf (fd, "HystScaling\t%0.2f\n", cnf->hysteresis_param.scaling);
174       fprintf (fd, "HystThrHigh\t%0.2f\n", cnf->hysteresis_param.thr_high);
175       fprintf (fd, "HystThrLow\t%0.2f\n\n", cnf->hysteresis_param.thr_low);
176     }
177   else
178     {
179       fprintf (fd, "UseHysteresis\tno\n\n");
180       fprintf (fd,
181                "# Hysteresis parameters\n# Do not alter these unless you know \n# what you are doing!\n# Set to auto by default. Allowed\n# values are floating point values\n# in the interval 0,1\n# THR_LOW must always be lower than\n# THR_HIGH!!\n\n");
182       fprintf (fd, "#HystScaling\t%0.2f\n", cnf->hysteresis_param.scaling);
183       fprintf (fd, "#HystThrHigh\t%0.2f\n", cnf->hysteresis_param.thr_high);
184       fprintf (fd, "#HystThrLow\t%0.2f\n\n", cnf->hysteresis_param.thr_low);
185     }
186
187   /* Pollrate */
188   fprintf (fd,
189            "# Polling rate in seconds(float).\n# Auto uses default value 0.05 sec\n\n");
190   fprintf (fd, "Pollrate\t%0.2f\n", cnf->pollrate);
191
192   /* NIC Changes Pollrate */
193   fprintf (fd,
194            "# Interval to poll network interfaces for configuration\n# changes. Defaults to 2.5 seconds\n");
195   fprintf (fd, "NicChgsPollInt\t%0.2f\n", cnf->nic_chgs_pollrate);
196
197   /* TC redundancy */
198   fprintf (fd,
199            "# TC redundancy\n# Specifies how much neighbor info should\n# be sent in TC messages\n# Possible values are:\n# 0 - only send MPR selectors\n# 1 - send MPR selectors and MPRs\n# 2 - send all neighbors\n#\n# defaults to 0\n\n");
200   fprintf (fd, "TcRedundancy\t%d\n\n", cnf->tc_redundancy);
201
202   /* MPR coverage */
203   fprintf (fd,
204            "# MPR coverage\n# Specifies how many MPRs a node should\n# try select to reach every 2 hop neighbor\n# Can be set to any integer >0\n# defaults to 1\n\n");
205
206   fprintf (fd, "MprCoverage\t%d\n\n", cnf->mpr_coverage);
207
208   fprintf (fd,
209            "# Link quality level\n# 0 = do not use link quality\n# 1 = use link quality for MPR selection\n# 2 = use link quality for MPR selection and routing\n\n");
210   fprintf (fd, "LinkQualityLevel\t%d\n\n", cnf->lq_level);
211
212   fprintf (fd,
213            "# Fish Eye algorithm\n# 0 = do not use fish eye\n# 1 = use fish eye\n\n");
214   fprintf (fd, "LinkQualityFishEye\t%d\n\n", cnf->lq_fish);
215
216   fprintf (fd, "# Link quality aging factor\n\n");
217   fprintf (fd, "LinkQualityAging\t%f\n\n", cnf->lq_aging);
218
219   fprintf (fd, "# NAT threshold\n\n");
220   fprintf (fd, "NatThreshold\t%f\n\n", cnf->lq_nat_thresh);
221
222   fprintf (fd, "# Clear screen when printing debug output?\n\n");
223   fprintf (fd, "ClearScreen\t%s\n\n", cnf->clear_screen ? "yes" : "no");
224
225   /* Plugins */
226   fprintf (fd,
227            "# Olsrd plugins to load\n# This must be the absolute path to the file\n# or the loader will use the following scheme:\n# - Try the paths in the LD_LIBRARY_PATH \n#   environment variable.\n# - The list of libraries cached in /etc/ld.so.cache\n# - /lib, followed by /usr/lib\n\n");
228   if (pe)
229     {
230       while (pe)
231         {
232           fprintf (fd, "LoadPlugin \"%s\" {\n", pe->name);
233           pp = pe->params;
234           while (pp)
235             {
236               fprintf (fd, "    PlParam \"%s\"\t\"%s\"\n", pp->key,
237                        pp->value);
238               pp = pp->next;
239             }
240           fprintf (fd, "}\n");
241           pe = pe->next;
242         }
243     }
244   fprintf (fd, "\n");
245
246   /* Interfaces */
247   fprintf (fd,
248            "# Interfaces\n# Multiple interfaces with the same configuration\n# can shar the same config block. Just list the\n# interfaces(e.g. Interface \"eth0\" \"eth2\"\n\n");
249   /* Interfaces */
250   if (in)
251     {
252       while (in)
253         {
254           fprintf (fd, "Interface \"%s\" {\n", in->name);
255           fprintf (fd, "\n");
256
257           fprintf (fd,
258                    "    # IPv4 broadcast address to use. The\n    # one usefull example would be 255.255.255.255\n    # If not defined the broadcastaddress\n    # every card is configured with is used\n\n");
259
260           if (in->cnf->ipv4_broadcast.v4.s_addr)
261             {
262               fprintf (fd, "    Ip4Broadcast\t%s\n\n",
263                        inet_ntoa (in->cnf->ipv4_broadcast.v4));
264             }
265           else
266             {
267               fprintf (fd, "    #Ip4Broadcast\t255.255.255.255\n\n");
268             }
269
270           fprintf (fd,
271                    "    # IPv6 address scope to use.\n    # Must be 'site-local' or 'global'\n\n");
272           if (in->cnf->ipv6_addrtype)
273             fprintf (fd, "    Ip6AddrType \tsite-local\n\n");
274           else
275             fprintf (fd, "    Ip6AddrType \tglobal\n\n");
276
277           fprintf (fd,
278                    "    # IPv6 multicast address to use when\n    # using site-local addresses.\n    # If not defined, ff05::15 is used\n");
279           fprintf (fd, "    Ip6MulticastSite\t%s\n\n",
280                    inet_ntop (AF_INET6, &in->cnf->ipv6_multi_site.v6,
281                               ipv6_buf, sizeof (ipv6_buf)));
282           fprintf (fd,
283                    "    # IPv6 multicast address to use when\n    # using global addresses\n    # If not defined, ff0e::1 is used\n");
284           fprintf (fd, "    Ip6MulticastGlobal\t%s\n\n",
285                    inet_ntop (AF_INET6, &in->cnf->ipv6_multi_glbl.v6,
286                               ipv6_buf, sizeof (ipv6_buf)));
287
288           fprintf (fd,
289                    "    # Olsrd can autodetect changes in\n    # interface configurations. Enabled by default\n    # turn off to save CPU.\n    AutoDetectChanges: %s\n",
290                    in->cnf->autodetect_chg ? "yes" : "no");
291
292           fprintf (fd,
293                    "    # Emission and validity intervals.\n    # If not defined, RFC proposed values will\n    # in most cases be used.\n\n");
294
295           if (in->cnf->hello_params.emission_interval != HELLO_INTERVAL)
296             fprintf (fd, "    HelloInterval\t%0.2f\n",
297                      in->cnf->hello_params.emission_interval);
298           else
299             fprintf (fd, "    #HelloInterval\t%0.2f\n",
300                      in->cnf->hello_params.emission_interval);
301           if (in->cnf->hello_params.validity_time != NEIGHB_HOLD_TIME)
302             fprintf (fd, "    HelloValidityTime\t%0.2f\n",
303                      in->cnf->hello_params.validity_time);
304           else
305             fprintf (fd, "    #HelloValidityTime\t%0.2f\n",
306                      in->cnf->hello_params.validity_time);
307           if (in->cnf->tc_params.emission_interval != TC_INTERVAL)
308             fprintf (fd, "    TcInterval\t\t%0.2f\n",
309                      in->cnf->tc_params.emission_interval);
310           else
311             fprintf (fd, "    #TcInterval\t\t%0.2f\n",
312                      in->cnf->tc_params.emission_interval);
313           if (in->cnf->tc_params.validity_time != TOP_HOLD_TIME)
314             fprintf (fd, "    TcValidityTime\t%0.2f\n",
315                      in->cnf->tc_params.validity_time);
316           else
317             fprintf (fd, "    #TcValidityTime\t%0.2f\n",
318                      in->cnf->tc_params.validity_time);
319           if (in->cnf->mid_params.emission_interval != MID_INTERVAL)
320             fprintf (fd, "    MidInterval\t\t%0.2f\n",
321                      in->cnf->mid_params.emission_interval);
322           else
323             fprintf (fd, "    #MidInterval\t%0.2f\n",
324                      in->cnf->mid_params.emission_interval);
325           if (in->cnf->mid_params.validity_time != MID_HOLD_TIME)
326             fprintf (fd, "    MidValidityTime\t%0.2f\n",
327                      in->cnf->mid_params.validity_time);
328           else
329             fprintf (fd, "    #MidValidityTime\t%0.2f\n",
330                      in->cnf->mid_params.validity_time);
331           if (in->cnf->hna_params.emission_interval != HNA_INTERVAL)
332             fprintf (fd, "    HnaInterval\t\t%0.2f\n",
333                      in->cnf->hna_params.emission_interval);
334           else
335             fprintf (fd, "    #HnaInterval\t%0.2f\n",
336                      in->cnf->hna_params.emission_interval);
337           if (in->cnf->hna_params.validity_time != HNA_HOLD_TIME)
338             fprintf (fd, "    HnaValidityTime\t%0.2f\n",
339                      in->cnf->hna_params.validity_time);
340           else
341             fprintf (fd, "    #HnaValidityTime\t%0.2f\n",
342                      in->cnf->hna_params.validity_time);
343
344           mult = in->cnf->lq_mult;
345
346           if (mult == NULL)
347             {
348               fprintf (fd, "    #LinkQualityMult\tdefault 1.0\n");
349             }
350           else
351             {
352               while (mult != NULL)
353                 {
354                   fprintf (fd, "    LinkQualityMult\t%s %0.2f\n",
355                            inet_ntop (cnf->ip_version, &mult->addr, ipv6_buf,
356                                       sizeof (ipv6_buf)),
357                            (float) (mult->value) / 65536.0);
358                   mult = mult->next;
359                 }
360             }
361
362           fprintf (fd, "    # When multiple links exist between hosts\n");
363           fprintf (fd,
364                    "    # the weight of interface is used to determine\n");
365           fprintf (fd, "    # the link to use. Normally the weight is\n");
366           fprintf (fd, "    # automatically calculated by olsrd based\n");
367           fprintf (fd, "    # on the characteristics of the interface,\n");
368           fprintf (fd, "    # but here you can specify a fixed value.\n");
369           fprintf (fd,
370                    "    # Olsrd will choose links with the lowest value.\n");
371           fprintf (fd, "    # Note:\n");
372           fprintf (fd,
373                    "    # Interface weight is used only when LinkQualityLevel is 0.\n");
374           fprintf (fd,
375                    "    # For any other value of LinkQualityLevel, the interface ETX\n");
376           fprintf (fd, "    # value is used instead.\n\n");
377           if (in->cnf->weight.fixed)
378             {
379               fprintf (fd, "    Weight\t %d\n\n", in->cnf->weight.value);
380             }
381           else
382             {
383               fprintf (fd, "    #Weight\t 0\n\n");
384             }
385
386           fprintf (fd, "}\n\n");
387           in = in->next;
388         }
389
390     }
391
392   fprintf (fd, "\n# END AUTOGENERATED CONFIG\n");
393
394   fclose (fd);
395   printf ("DONE\n");
396
397   return 1;
398 }
399
400 #define MAX_LINESIZE 250
401
402 #define WRITE_TO_BUF(fmt, args...)                                      \
403     do {                                                                \
404         if((bufsize - size) < MAX_LINESIZE) {                           \
405             return -1;                                                  \
406         }                                                               \
407         size += snprintf(&buf[size], MAX_LINESIZE, fmt, ##args);        \
408     } while (0)
409
410 int
411 olsrd_write_cnf_buf (struct olsrd_config *cnf, char *buf, olsr_u32_t bufsize)
412 {
413   struct ip_prefix_list *h = cnf->hna_entries;
414   struct olsr_if *in = cnf->interfaces;
415   struct plugin_entry *pe = cnf->plugins;
416   struct plugin_param *pp;
417   struct ip_prefix_list *ie = cnf->ipc_nets;
418   struct olsr_lq_mult *mult;
419
420   int size = 0;
421
422   char ipv6_buf[100];           /* buffer for IPv6 inet_htop */
423
424 #if 0
425   printf ("\n\n\n\nolsrd_write_cnf_buf bufsize  %d\n\n\n\n\n", bufsize);
426 #endif
427   if (buf == NULL || bufsize < MAX_LINESIZE)
428     {
429       return -1;
430     }
431
432   WRITE_TO_BUF
433     ("#\n# Configuration file for olsr.org olsrd\n# automatically generated by olsrd-cnf %s\n#\n\n\n",
434      PARSER_VERSION);
435
436   /* Debug level */
437   WRITE_TO_BUF
438     ("# Debug level(0-9)\n# If set to 0 the daemon runs in the background\n\nDebugLevel\t%d\n\n",
439      cnf->debug_level);
440
441   /* IP version */
442   WRITE_TO_BUF ("# IP version to use (4 or 6)\n\nIpVersion\t%d\n\n",
443                 cnf->ip_version == AF_INET ? 4 : 6);
444
445   /* FIB Metric */
446   WRITE_TO_BUF
447     ("# FIBMetric (\"%s\", \"%s\", or \"%s\")\n\nFIBMetric\t\"%s\"\n\n",
448      CFG_FIBM_FLAT, CFG_FIBM_CORRECT, CFG_FIBM_APPROX,
449      FIBM_FLAT == cnf->fib_metric ? CFG_FIBM_FLAT : FIBM_CORRECT ==
450      cnf->fib_metric ? CFG_FIBM_CORRECT : CFG_FIBM_APPROX);
451
452   /* HNA IPv4/IPv6 */
453   WRITE_TO_BUF
454     ("# HNA IPv%1$d routes\n# syntax: netaddr netmask\n\nHna%1$d {\n",
455      cnf->ip_version == AF_INET ? 4 : 6);
456   while (h)
457     {
458       struct ipaddr_str strbuf;
459       WRITE_TO_BUF ("    %s/%d\n",
460                     olsr_ip_to_string (&strbuf, &h->net.prefix),
461                     h->net.prefix_len);
462       h = h->next;
463     }
464   WRITE_TO_BUF ("}\n\n");
465
466   /* No interfaces */
467   WRITE_TO_BUF
468     ("# Should olsrd keep on running even if there are\n# no interfaces available? This is a good idea\n# for a PCMCIA/USB hotswap environment.\n# \"yes\" OR \"no\"\n\nAllowNoInt\t");
469   if (cnf->allow_no_interfaces)
470     WRITE_TO_BUF ("yes\n\n");
471   else
472     WRITE_TO_BUF ("no\n\n");
473
474   /* TOS */
475   WRITE_TO_BUF ("# TOS(type of service) to use. Default is 16\n\n");
476   WRITE_TO_BUF ("TosValue\t%d\n\n", cnf->tos);
477
478   /* RtTable */
479   WRITE_TO_BUF ("# Policy Routing Tableto use. Default is 254\n\n");
480   WRITE_TO_BUF ("RtTable\t\t%d\n\n", cnf->rttable);
481
482   /* Willingness */
483   WRITE_TO_BUF
484     ("# The fixed willingness to use(0-7)\n# If not set willingness will be calculated\n# dynammically based on battery/power status\n\n");
485   if (cnf->willingness_auto)
486     WRITE_TO_BUF ("#Willingness\t4\n\n");
487   else
488     WRITE_TO_BUF ("Willingness\t%d\n\n", cnf->willingness);
489
490   /* IPC */
491   WRITE_TO_BUF
492     ("# Allow processes like the GUI front-end\n# to connect to the daemon.\n\n");
493   WRITE_TO_BUF ("IpcConnect {\n");
494   WRITE_TO_BUF ("    MaxConnections\t%d\n", cnf->ipc_connections);
495   while (ie)
496     {
497       struct ipaddr_str strbuf;
498       if (ie->net.prefix_len == olsr_cnf->maxplen)
499         {
500           WRITE_TO_BUF ("    Host\t\t%s\n",
501                         olsr_ip_to_string (&strbuf, &ie->net.prefix));
502         }
503       else
504         {
505           WRITE_TO_BUF ("    Net\t\t\t%s/%d\n",
506                         olsr_ip_to_string (&strbuf, &ie->net.prefix),
507                         ie->net.prefix_len);
508         }
509       ie = ie->next;
510     }
511
512   WRITE_TO_BUF ("}\n\n");
513
514   /* Hysteresis */
515   WRITE_TO_BUF
516     ("# Hysteresis adds more robustness to the\n# link sensing.\n# Used by default. 'yes' or 'no'\n\n");
517
518   if (cnf->use_hysteresis)
519     {
520       WRITE_TO_BUF ("UseHysteresis\tyes\n\n");
521       WRITE_TO_BUF
522         ("# Hysteresis parameters\n# Do not alter these unless you know \n# what you are doing!\n# Set to auto by default. Allowed\n# values are floating point values\n# in the interval 0,1\n# THR_LOW must always be lower than\n# THR_HIGH!!\n\n");
523       WRITE_TO_BUF ("HystScaling\t%0.2f\n", cnf->hysteresis_param.scaling);
524       WRITE_TO_BUF ("HystThrHigh\t%0.2f\n", cnf->hysteresis_param.thr_high);
525       WRITE_TO_BUF ("HystThrLow\t%0.2f\n\n", cnf->hysteresis_param.thr_low);
526     }
527   else
528     {
529       WRITE_TO_BUF ("UseHysteresis\tno\n\n");
530       WRITE_TO_BUF
531         ("# Hysteresis parameters\n# Do not alter these unless you know \n# what you are doing!\n# Set to auto by default. Allowed\n# values are floating point values\n# in the interval 0,1\n# THR_LOW must always be lower than\n# THR_HIGH!!\n\n");
532       WRITE_TO_BUF ("#HystScaling\t%0.2f\n", cnf->hysteresis_param.scaling);
533       WRITE_TO_BUF ("#HystThrHigh\t%0.2f\n", cnf->hysteresis_param.thr_high);
534       WRITE_TO_BUF ("#HystThrLow\t%0.2f\n\n", cnf->hysteresis_param.thr_low);
535     }
536
537   /* Pollrate */
538   WRITE_TO_BUF
539     ("# Polling rate in seconds(float).\n# Auto uses default value 0.05 sec\n\n");
540   WRITE_TO_BUF ("Pollrate\t%0.2f\n", cnf->pollrate);
541
542   /* TC redundancy */
543   WRITE_TO_BUF
544     ("# TC redundancy\n# Specifies how much neighbor info should\n# be sent in TC messages\n# Possible values are:\n# 0 - only send MPR selectors\n# 1 - send MPR selectors and MPRs\n# 2 - send all neighbors\n#\n# defaults to 0\n\n");
545   WRITE_TO_BUF ("TcRedundancy\t%d\n\n", cnf->tc_redundancy);
546
547   /* MPR coverage */
548   WRITE_TO_BUF
549     ("# MPR coverage\n# Specifies how many MPRs a node should\n# try select to reach every 2 hop neighbor\n# Can be set to any integer >0\n# defaults to 1\n\n");
550
551   WRITE_TO_BUF ("MprCoverage\t%d\n\n", cnf->mpr_coverage);
552
553   WRITE_TO_BUF
554     ("# Link quality level\n# 0 = do not use link quality\n# 1 = use link quality for MPR selection\n# 2 = use link quality for MPR selection and routing\n\n");
555   WRITE_TO_BUF ("LinkQualityLevel\t%d\n\n", cnf->lq_level);
556
557   WRITE_TO_BUF ("# Link quality aging factor\n\n");
558   WRITE_TO_BUF ("LinkQualityAging\t%f\n\n", cnf->lq_aging);
559
560   WRITE_TO_BUF ("# NAT threshold\n\n");
561   WRITE_TO_BUF ("NatThreshold\t%f\n\n", cnf->lq_nat_thresh);
562
563   WRITE_TO_BUF ("# Clear screen when printing debug output?\n\n");
564   WRITE_TO_BUF ("ClearScreen\t%s\n\n", cnf->clear_screen ? "yes" : "no");
565
566   /* Plugins */
567   WRITE_TO_BUF
568     ("# Olsrd plugins to load\n# This must be the absolute path to the file\n# or the loader will use the following scheme:\n");
569   WRITE_TO_BUF
570     ("# - Try the paths in the LD_LIBRARY_PATH \n#   environment variable.\n# - The list of libraries cached in /etc/ld.so.cache\n# - /lib, followed by /usr/lib\n\n");
571   if (pe)
572     {
573       while (pe)
574         {
575           WRITE_TO_BUF ("LoadPlugin \"%s\" {\n", pe->name);
576           pp = pe->params;
577           while (pp)
578             {
579               WRITE_TO_BUF ("    PlParam \"%s\"\t\"%s\"\n", pp->key,
580                             pp->value);
581               pp = pp->next;
582             }
583           WRITE_TO_BUF ("}\n");
584           pe = pe->next;
585         }
586     }
587   WRITE_TO_BUF ("\n");
588
589   /* Interfaces */
590   WRITE_TO_BUF
591     ("# Interfaces\n# Multiple interfaces with the same configuration\n");
592   WRITE_TO_BUF
593     ("# can shar the same config block. Just list the\n# interfaces(e.g. Interface \"eth0\" \"eth2\"\n\n");
594   /* Interfaces */
595   if (in)
596     {
597       olsr_bool first = OLSR_TRUE;
598       while (in)
599         {
600           WRITE_TO_BUF ("Interface \"%s\" {\n", in->name);
601
602           if (first)
603             WRITE_TO_BUF
604               ("    # IPv4 broadcast address to use. The\n    # one usefull example would be 255.255.255.255\n    # If not defined the broadcastaddress\n    # every card is configured with is used\n\n");
605
606           if (in->cnf->ipv4_broadcast.v4.s_addr)
607             {
608               WRITE_TO_BUF ("    Ip4Broadcast\t%s\n",
609                             inet_ntoa (in->cnf->ipv4_broadcast.v4));
610             }
611           else
612             {
613               if (first)
614                 WRITE_TO_BUF ("    #Ip4Broadcast\t255.255.255.255\n");
615             }
616
617           if (first)
618             WRITE_TO_BUF ("\n");
619
620           if (first)
621             WRITE_TO_BUF
622               ("    # IPv6 address scope to use.\n    # Must be 'site-local' or 'global'\n\n");
623           if (in->cnf->ipv6_addrtype)
624             WRITE_TO_BUF ("    Ip6AddrType \tsite-local\n");
625           else
626             WRITE_TO_BUF ("    Ip6AddrType \tglobal\n");
627
628           if (first)
629             WRITE_TO_BUF ("\n");
630
631           if (first)
632             WRITE_TO_BUF
633               ("    # IPv6 multicast address to use when\n    # using site-local addresses.\n    # If not defined, ff05::15 is used\n");
634           WRITE_TO_BUF ("    Ip6MulticastSite\t%s\n",
635                         inet_ntop (AF_INET6, &in->cnf->ipv6_multi_site.v6,
636                                    ipv6_buf, sizeof (ipv6_buf)));
637           if (first)
638             WRITE_TO_BUF ("\n");
639           if (first)
640             WRITE_TO_BUF
641               ("    # IPv6 multicast address to use when\n    # using global addresses\n    # If not defined, ff0e::1 is used\n");
642           WRITE_TO_BUF ("    Ip6MulticastGlobal\t%s\n",
643                         inet_ntop (AF_INET6, &in->cnf->ipv6_multi_glbl.v6,
644                                    ipv6_buf, sizeof (ipv6_buf)));
645           if (first)
646             WRITE_TO_BUF ("\n");
647
648           if (first)
649             WRITE_TO_BUF
650               ("    # Emission and validity intervals.\n    # If not defined, RFC proposed values will\n    # in most cases be used.\n\n");
651
652           if (in->cnf->hello_params.emission_interval != HELLO_INTERVAL)
653             WRITE_TO_BUF ("    HelloInterval\t%0.2f\n",
654                           in->cnf->hello_params.emission_interval);
655           else if (first)
656             WRITE_TO_BUF ("    #HelloInterval\t%0.2f\n",
657                           in->cnf->hello_params.emission_interval);
658           if (in->cnf->hello_params.validity_time != NEIGHB_HOLD_TIME)
659             WRITE_TO_BUF ("    HelloValidityTime\t%0.2f\n",
660                           in->cnf->hello_params.validity_time);
661           else if (first)
662             WRITE_TO_BUF ("    #HelloValidityTime\t%0.2f\n",
663                           in->cnf->hello_params.validity_time);
664           if (in->cnf->tc_params.emission_interval != TC_INTERVAL)
665             WRITE_TO_BUF ("    TcInterval\t\t%0.2f\n",
666                           in->cnf->tc_params.emission_interval);
667           else if (first)
668             WRITE_TO_BUF ("    #TcInterval\t\t%0.2f\n",
669                           in->cnf->tc_params.emission_interval);
670           if (in->cnf->tc_params.validity_time != TOP_HOLD_TIME)
671             WRITE_TO_BUF ("    TcValidityTime\t%0.2f\n",
672                           in->cnf->tc_params.validity_time);
673           else if (first)
674             WRITE_TO_BUF ("    #TcValidityTime\t%0.2f\n",
675                           in->cnf->tc_params.validity_time);
676           if (in->cnf->mid_params.emission_interval != MID_INTERVAL)
677             WRITE_TO_BUF ("    MidInterval\t\t%0.2f\n",
678                           in->cnf->mid_params.emission_interval);
679           else if (first)
680             WRITE_TO_BUF ("    #MidInterval\t%0.2f\n",
681                           in->cnf->mid_params.emission_interval);
682           if (in->cnf->mid_params.validity_time != MID_HOLD_TIME)
683             WRITE_TO_BUF ("    MidValidityTime\t%0.2f\n",
684                           in->cnf->mid_params.validity_time);
685           else if (first)
686             WRITE_TO_BUF ("    #MidValidityTime\t%0.2f\n",
687                           in->cnf->mid_params.validity_time);
688           if (in->cnf->hna_params.emission_interval != HNA_INTERVAL)
689             WRITE_TO_BUF ("    HnaInterval\t\t%0.2f\n",
690                           in->cnf->hna_params.emission_interval);
691           else if (first)
692             WRITE_TO_BUF ("    #HnaInterval\t%0.2f\n",
693                           in->cnf->hna_params.emission_interval);
694           if (in->cnf->hna_params.validity_time != HNA_HOLD_TIME)
695             WRITE_TO_BUF ("    HnaValidityTime\t%0.2f\n",
696                           in->cnf->hna_params.validity_time);
697           else if (first)
698             WRITE_TO_BUF ("    #HnaValidityTime\t%0.2f\n",
699                           in->cnf->hna_params.validity_time);
700
701           mult = in->cnf->lq_mult;
702
703           if (mult == NULL)
704             {
705               if (first)
706                 WRITE_TO_BUF ("    #LinkQualityMult\tdefault 1.0\n");
707             }
708           else
709             {
710               while (mult != NULL)
711                 {
712                   WRITE_TO_BUF ("    LinkQualityMult\t%s %0.2f\n",
713                                 inet_ntop (cnf->ip_version, &mult->addr,
714                                            ipv6_buf, sizeof (ipv6_buf)),
715                                 (float) (mult->value) / 65536.0);
716                   mult = mult->next;
717                 }
718             }
719
720           if (first)
721             {
722               WRITE_TO_BUF
723                 ("    # When multiple links exist between hosts\n");;
724               WRITE_TO_BUF
725                 ("    # the weight of interface is used to determine\n");;
726               WRITE_TO_BUF
727                 ("    # the link to use. Normally the weight is\n");
728               WRITE_TO_BUF
729                 ("    # automatically calculated by olsrd based\n");;
730               WRITE_TO_BUF
731                 ("    # on the characteristics of the interface,\n");;
732               WRITE_TO_BUF
733                 ("    # but here you can specify a fixed value.\n");;
734               WRITE_TO_BUF
735                 ("    # Olsrd will choose links with the lowest value.\n");
736               WRITE_TO_BUF ("    # Note:\n");;
737               WRITE_TO_BUF
738                 ("    # Interface weight is used only when LinkQualityLevel is 0.\n");;
739               WRITE_TO_BUF
740                 ("    # For any other value of LinkQualityLevel, the interface ETX\n");;
741               WRITE_TO_BUF ("    # value is used instead.\n\n");;
742             }
743           if (in->cnf->weight.fixed)
744             {
745               WRITE_TO_BUF ("    Weight\t %d\n\n", in->cnf->weight.value);
746             }
747           else
748             {
749               if (first)
750                 WRITE_TO_BUF ("    #Weight\t 0\n\n");
751             }
752
753           WRITE_TO_BUF ("}\n\n");
754           in = in->next;
755           first = OLSR_FALSE;
756         }
757
758     }
759
760   WRITE_TO_BUF ("\n# END AUTOGENERATED CONFIG\n");
761
762   return size;
763 }