00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "builddata/data.h"
00043 #include "olsr_cfg_gen.h"
00044 #include "olsr_protocol.h"
00045 #include "ipcalc.h"
00046 #include "olsr_ip_prefix_list.h"
00047 #include "olsr_clock.h"
00048
00049 #include <errno.h>
00050
00051 static INLINE void
00052 append_reltime(struct autobuf *abuf, const char *name, uint32_t val, uint32_t deflt, bool first)
00053 {
00054 struct millitxt_buf buf;
00055
00056 if (val != deflt) {
00057 abuf_appendf(abuf, " %s\t%s\n", name, olsr_clock_to_string(&buf, val));
00058 } else if (first) {
00059 abuf_appendf(abuf, " #%s\t%s\n", name, olsr_clock_to_string(&buf, val));
00060 }
00061 }
00062
00063 void
00064 olsr_write_cnf_buf(struct autobuf *abuf, struct olsr_config *cnf, bool write_more_comments)
00065 {
00066 char ipv6_buf[INET6_ADDRSTRLEN];
00067 struct millitxt_buf tbuf;
00068 const char *s;
00069
00070 abuf_appendf(abuf, "#\n" "# Generated config file for %s\n" "#\n\n", get_olsrd_version());
00071
00072
00073 abuf_appendf(abuf, "# IP version to use (4 or 6)\n" "IpVersion\t%d\n\n", cnf->ip_version == AF_INET ? 4 : 6);
00074
00075
00076 abuf_appendf(abuf, "# FIBMetric (\"%s\", \"%s\", or \"%s\")\n"
00077 "FIBMetric\t\"%s\"\n\n",
00078 CFG_FIBM_FLAT, CFG_FIBM_CORRECT, CFG_FIBM_APPROX,
00079 FIBM_FLAT == cnf->fib_metric ? CFG_FIBM_FLAT : FIBM_CORRECT == cnf->fib_metric ? CFG_FIBM_CORRECT : CFG_FIBM_APPROX);
00080
00081
00082 abuf_appendf(abuf, "# HNA IPv%d routes\n"
00083 "# syntax: netaddr/prefix\n" "Hna%d {\n", cnf->ip_version == AF_INET ? 4 : 6, cnf->ip_version == AF_INET ? 4 : 6);
00084 if (!list_is_empty(&cnf->hna_entries)) {
00085 struct ip_prefix_entry *h, *iterator;
00086
00087 OLSR_FOR_ALL_IPPREFIX_ENTRIES(&cnf->hna_entries, h, iterator) {
00088 struct ipprefix_str strbuf;
00089 abuf_appendf(abuf, " %s\n", ip_prefix_to_string(cnf->ip_version, &strbuf, &h->net));
00090 }
00091 }
00092 abuf_appendf(abuf, "}\n\n");
00093
00094
00095 abuf_appendf(abuf, "# Should olsrd keep on running even if there are\n"
00096 "# no interfaces available? This is a good idea\n"
00097 "# for a PCMCIA/USB hotswap environment.\n"
00098 "# \"yes\" OR \"no\"\n" "AllowNoInt\t%s\n\n", cnf->allow_no_interfaces ? "yes" : "no");
00099
00100
00101 abuf_appendf(abuf, "# TOS(type of service) to use. Default is 16\n" "TosValue\t%d\n\n", cnf->tos);
00102
00103
00104 abuf_appendf(abuf, "# Routing proto flag to use. Operating system default is 0\n" "RtProto\t\t%d\n\n", cnf->rt_proto);
00105
00106
00107 abuf_appendf(abuf, "# Policy Routing Table to use. Default is 254\n" "RtTable\t\t%d\n\n", cnf->rt_table);
00108
00109
00110 abuf_appendf(abuf,
00111 "# Policy Routing Table to use for the default Route. Default is 0 (Take the same table as specified by RtTable)\n"
00112 "RtTableDefault\t\t%d\n\n", cnf->rt_table_default);
00113
00114
00115 abuf_appendf(abuf, "# The fixed willingness to use(0-7)\n"
00116 "# If not set willingness will be calculated\n"
00117 "# dynammically based on battery/power status\n"
00118 "%sWillingness\t%d\n\n", cnf->willingness_auto ? "#" : "", cnf->willingness_auto ? 4 : cnf->willingness);
00119
00120
00121 abuf_appendf(abuf, "# Polling rate in seconds(float).\n"
00122 "# Auto uses default value 0.05 sec\n" "Pollrate\t%s\n",
00123 olsr_clock_to_string(&tbuf, cnf->pollrate));
00124
00125
00126 abuf_appendf(abuf, "# Interval to poll network interfaces for configuration\n"
00127 "# changes. Defaults to 2.5 seconds\n" "NicChgsPollInt\t%s\n",
00128 olsr_clock_to_string(&tbuf, cnf->nic_chgs_pollrate));
00129
00130
00131 abuf_appendf(abuf, "# TC redundancy\n"
00132 "# Specifies how much neighbor info should\n"
00133 "# be sent in TC messages\n"
00134 "# Possible values are:\n"
00135 "# 0 - only send MPR selectors\n"
00136 "# 1 - send MPR selectors and MPRs\n"
00137 "# 2 - send all neighbors\n" "# defaults to 0\n" "TcRedundancy\t%d\n\n", cnf->tc_redundancy);
00138
00139
00140 abuf_appendf(abuf, "# MPR coverage\n"
00141 "# Specifies how many MPRs a node should\n"
00142 "# try select to reach every 2 hop neighbor\n"
00143 "# Can be set to any integer >0\n" "# defaults to 1\n" "MprCoverage\t%d\n\n", cnf->mpr_coverage);
00144
00145 abuf_appendf(abuf, "# Fish Eye algorithm\n"
00146 "# 0 = do not use fish eye\n" "# 1 = use fish eye\n" "LinkQualityFishEye\t%d\n\n", cnf->lq_fish);
00147
00148 abuf_appendf(abuf, "# NAT threshold\n" "NatThreshold\t%s\n\n", olsr_clock_to_string(&tbuf, cnf->lq_nat_thresh));
00149
00150 abuf_appendf(abuf, "# Clear screen when printing debug output?\n" "ClearScreen\t%s\n\n", cnf->clear_screen ? "yes" : "no");
00151
00152
00153 abuf_appendf(abuf, "# Olsrd plugins to load\n"
00154 "# This must be the absolute path to the file\n"
00155 "# or the loader will use the following scheme:\n"
00156 "# - Try the paths in the LD_LIBRARY_PATH \n"
00157 "# environment variable.\n"
00158 "# - The list of libraries cached in /etc/ld.so.cache\n" "# - /lib, followed by /usr/lib\n\n");
00159 if (cnf->plugins) {
00160 struct plugin_entry *pe;
00161 for (pe = cnf->plugins; pe != NULL; pe = pe->next) {
00162 struct plugin_param *pp;
00163 abuf_appendf(abuf, "LoadPlugin \"%s\" {\n", pe->name);
00164 for (pp = pe->params; pp != NULL; pp = pp->next) {
00165 abuf_appendf(abuf, " PlParam \"%s\"\t\"%s\"\n", pp->key, pp->value);
00166 }
00167 abuf_appendf(abuf, "}\n");
00168 }
00169 }
00170 abuf_appendf(abuf, "\n");
00171
00172 append_reltime(abuf, "TcInterval", cnf->tc_params.emission_interval, TC_INTERVAL, true);
00173 append_reltime(abuf, "TcValidityTime", cnf->tc_params.validity_time, TOP_HOLD_TIME, true);
00174 append_reltime(abuf, "MidInterval", cnf->mid_params.emission_interval, MID_INTERVAL, true);
00175 append_reltime(abuf, "MidValidityTime", cnf->mid_params.validity_time, MID_HOLD_TIME, true);
00176 append_reltime(abuf, "HnaInterval", cnf->hna_params.emission_interval, HNA_INTERVAL, true);
00177 append_reltime(abuf, "HnaValidityTime", cnf->hna_params.validity_time, HNA_HOLD_TIME, true);
00178
00179 abuf_puts(abuf, "\n");
00180
00181
00182 abuf_appendf(abuf, "# Interfaces\n"
00183 "# Multiple interfaces with the same configuration\n"
00184 "# can shar the same config block. Just list the\n" "# interfaces(e.g. Interface \"eth0\" \"eth2\"\n");
00185
00186 if (cnf->if_configs) {
00187 struct olsr_if_config *in;
00188 bool first;
00189 for (in = cnf->if_configs, first = write_more_comments; in != NULL; in = in->next, first = false) {
00190 abuf_appendf(abuf, "Interface \"%s\" {\n", in->name);
00191
00192 if (first) {
00193 abuf_appendf(abuf, " # IPv4 broadcast address to use. The\n"
00194 " # one usefull example would be 255.255.255.255\n"
00195 " # If not defined the broadcastaddress\n" " # every card is configured with is used\n\n");
00196 }
00197
00198 if (in->cnf->ipv4_broadcast.v4.s_addr) {
00199 abuf_appendf(abuf, " Ip4Broadcast\t%s\n", inet_ntoa(in->cnf->ipv4_broadcast.v4));
00200 } else if (first) {
00201 abuf_appendf(abuf, " #Ip4Broadcast\t255.255.255.255\n");
00202 }
00203
00204 if (first) {
00205 abuf_appendf(abuf, "\n # IPv6 address type to use.\n"
00206 " # Must be 'auto', 'site-local', 'unique-local' or 'global'\n\n");
00207 }
00208 if (in->cnf->ipv6_addrtype == OLSR_IP6T_SITELOCAL)
00209 s = CFG_IP6T_SITELOCAL;
00210 else if (in->cnf->ipv6_addrtype == OLSR_IP6T_UNIQUELOCAL)
00211 s = CFG_IP6T_UNIQUELOCAL;
00212 else if (in->cnf->ipv6_addrtype == OLSR_IP6T_GLOBAL)
00213 s = CFG_IP6T_GLOBAL;
00214 else
00215 s = CFG_IP6T_AUTO;
00216 abuf_appendf(abuf, " Ip6AddrType\t%s\n\n", s);
00217
00218 if (first) {
00219 abuf_appendf(abuf, "\n"
00220 " # IPv6 multicast address to use when\n"
00221 " # using site-local addresses.\n" " # If not defined, ff05::15 is used\n");
00222 }
00223 abuf_appendf(abuf, " Ip6MulticastSite\t%s\n",
00224 inet_ntop(AF_INET6, &in->cnf->ipv6_multi_site.v6, ipv6_buf, sizeof(ipv6_buf)));
00225 if (first) {
00226 abuf_appendf(abuf, "\n # IPv6 multicast address to use when\n"
00227 " # using global addresses\n" " # If not defined, ff0e::1 is used\n");
00228 }
00229 abuf_appendf(abuf, " Ip6MulticastGlobal\t%s\n",
00230 inet_ntop(AF_INET6, &in->cnf->ipv6_multi_glbl.v6, ipv6_buf, sizeof(ipv6_buf)));
00231 if (first) {
00232 abuf_appendf(abuf, "\n");
00233 }
00234 abuf_appendf(abuf, " # Olsrd can autodetect changes in\n"
00235 " # interface configurations. Enabled by default\n"
00236 " # turn off to save CPU.\n" " AutoDetectChanges: %s\n\n", in->cnf->autodetect_chg ? "yes" : "no");
00237
00238 if (first) {
00239 abuf_appendf(abuf, " # Emission and validity intervals.\n"
00240 " # If not defined, RFC proposed values will\n" " # in most cases be used.\n");
00241 }
00242 append_reltime(abuf, "HelloInterval", in->cnf->hello_params.emission_interval, HELLO_INTERVAL, first);
00243 append_reltime(abuf, "HelloValidityTime", in->cnf->hello_params.validity_time, NEIGHB_HOLD_TIME, first);
00244 if (in->cnf->lq_mult == NULL) {
00245 if (first) {
00246 abuf_appendf(abuf, " #LinkQualityMult\tdefault 1.0\n");
00247 }
00248 } else {
00249 struct olsr_lq_mult *mult;
00250 for (mult = in->cnf->lq_mult; mult != NULL; mult = mult->next) {
00251 abuf_appendf(abuf, " LinkQualityMult\t%s %0.2f\n",
00252 inet_ntop(cnf->ip_version, &mult->addr, ipv6_buf, sizeof(ipv6_buf)), (float)mult->value / 65536.0);
00253 }
00254 }
00255
00256 if (first) {
00257 abuf_appendf(abuf, " # When multiple links exist between hosts\n"
00258 " # the weight of interface is used to determine\n"
00259 " # the link to use. Normally the weight is\n"
00260 " # automatically calculated by olsrd based\n"
00261 " # on the characteristics of the interface,\n"
00262 " # but here you can specify a fixed value.\n"
00263 " # Olsrd will choose links with the lowest value.\n"
00264 " # Note:\n"
00265 " # Interface weight is used only when LinkQualityLevel is 0.\n"
00266 " # For any other value of LinkQualityLevel, the interface ETX\n" " # value is used instead.\n\n");
00267 }
00268 if (in->cnf->weight.fixed) {
00269 abuf_appendf(abuf, " Weight\t %d\n", in->cnf->weight.value);
00270 } else if (first) {
00271 abuf_appendf(abuf, " #Weight\t 0\n");
00272 }
00273
00274 abuf_appendf(abuf, "}\n\n");
00275 }
00276 }
00277 }
00278
00279
00280
00281
00282
00283
00284