1 /* 2 * The olsr.org Optimized Link-State Routing daemon (olsrd) 3 * 4 * (c) by the OLSR project 5 * 6 * See our Git repository to find out who worked on this file 7 * and thus is a copyright holder on it. 8 * 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 15 * * Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * * Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in 19 * the documentation and/or other materials provided with the 20 * distribution. 21 * * Neither the name of olsr.org, olsrd nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 29 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 * 38 * Visit http://www.olsr.org for more information. 39 * 40 * If you find this software useful feel free to make a donation 41 * to the project. For more information see the website or contact 42 * the copyright holders. 43 * 44 */ 45 46 #ifndef _OLSRD_CFGPARSER_H 47 #define _OLSRD_CFGPARSER_H 48 49 #include "compiler.h" 50 #include "defs.h" 51 #include "olsr_types.h" 52 #include "common/autobuf.h" 53 #include "pud/src/receiver.h" 54 55 /* set to 1 to collect all startup sleep into one sleep 56 * (just as long as the longest sleep) 57 * useful if many errors on many interfaces */ 58 #define OLSR_COLLECT_STARTUP_SLEEP 1 59 60 #define TESTLIB_PATH 0 61 #define SYSLOG_NUMBERING 0 62 63 /* Default values not declared in olsr_protocol.h */ 64 #define DEF_IP_VERSION AF_INET 65 #define DEF_POLLRATE 0.05 66 #define DEF_NICCHGPOLLRT 2.5 67 #define DEF_WILL_AUTO false 68 #define DEF_WILLINGNESS 3 69 #define DEF_ALLOW_NO_INTS true 70 #define DEF_TOS 192 71 #define DEF_DEBUGLVL 1 72 #define DEF_IPC_CONNECTIONS 0 73 #define DEF_USE_HYST false 74 #define DEF_FIB_METRIC FIBM_FLAT 75 #define DEF_FIB_METRIC_DEFAULT 2 76 #define DEF_LQ_LEVEL 2 77 #define DEF_LQ_ALGORITHM "etx_ff" 78 #define DEF_LQ_FISH 1 79 #define DEF_LQ_NAT_THRESH 1.0 80 #define DEF_LQ_AGING 0.05 81 #define DEF_CLEAR_SCREEN true 82 #define DEF_OLSRPORT 698 83 #define DEF_RTPROTO 0 /* 0 means OS-specific default */ 84 #define DEF_RT_NONE -1 85 #define DEF_RT_AUTO 0 86 87 #define DEF_RT_TABLE_NR 254 88 #define DEF_RT_TABLE_DEFAULT_NR 254 89 #define DEF_RT_TABLE_TUNNEL_NR 254 90 91 #define DEF_SGW_RT_TABLE_NR 254 92 #define DEF_SGW_RT_TABLE_DEFAULT_NR 223 93 #define DEF_SGW_RT_TABLE_TUNNEL_NR 224 94 95 #define DEF_RT_TABLE_PRI DEF_RT_NONE 96 #define DEF_RT_TABLE_DEFAULTOLSR_PRI DEF_RT_NONE 97 #define DEF_RT_TABLE_TUNNEL_PRI DEF_RT_NONE 98 #define DEF_RT_TABLE_DEFAULT_PRI DEF_RT_NONE 99 100 #define DEF_SGW_RT_TABLE_PRI DEF_RT_NONE 101 #define DEF_SGW_RT_TABLE_PRI_BASE 32766 102 #define DEF_SGW_RT_TABLE_DEFAULTOLSR_PRI_ADDER 10 103 #define DEF_SGW_RT_TABLE_TUNNEL_PRI_ADDER 10 104 #define DEF_SGW_RT_TABLE_DEFAULT_PRI_ADDER 10 105 106 #define DEF_MIN_TC_VTIME 0.0 107 #define DEF_USE_NIIT true 108 #define DEF_SMART_GW false 109 #define DEF_SMART_GW_ALWAYS_REMOVE_SERVER_TUNNEL false 110 #define DEF_GW_USE_COUNT 1 111 #define DEF_GW_TAKEDOWN_PERCENTAGE 25 112 #define DEF_GW_EGRESS_FILE "/var/run/olsrd-sgw-egress.conf" 113 #define DEF_GW_EGRESS_FILE_PERIOD 5000 114 #define DEF_GW_OFFSET_TABLES 90 115 #define DEF_GW_OFFSET_RULES 0 116 #define DEF_GW_PERIOD 10*1000 117 #define DEF_GW_STABLE_COUNT 6 118 #define DEF_GW_ALLOW_NAT true 119 #define DEF_GW_THRESH 0 120 #define DEF_GW_WEIGHT_EXITLINK_UP 1 121 #define DEF_GW_WEIGHT_EXITLINK_DOWN 1 122 #define DEF_GW_WEIGHT_ETX 1 123 #define DEF_GW_DIVIDER_ETX 0 124 #define DEF_GW_MAX_COST_MAX_ETX 2560 125 #define DEF_GW_TYPE GW_UPLINK_IPV46 126 #define DEF_GW_UPLINK_NAT true 127 #define DEF_UPLINK_SPEED 128 128 #define DEF_DOWNLINK_SPEED 1024 129 #define DEF_USE_SRCIP_ROUTES false 130 131 #define DEF_IF_MODE IF_MODE_MESH 132 133 /* Bounds */ 134 135 #define MIN_INTERVAL 0.01 136 137 #define MAX_POLLRATE 1.0 138 #define MIN_POLLRATE 0.01 139 #define MAX_NICCHGPOLLRT 100.0 140 #define MIN_NICCHGPOLLRT 1.0 141 #define MAX_DEBUGLVL 9 142 #define MIN_DEBUGLVL 0 143 #define MAX_TOS 252 144 #define MIN_TOS 0 145 #define MAX_WILLINGNESS 7 146 #define MIN_WILLINGNESS 0 147 #define MAX_MPR_COVERAGE 20 148 #define MIN_MPR_COVERAGE 1 149 #define MAX_TC_REDUNDANCY 2 150 #define MIN_TC_REDUNDANCY 0 151 #define MAX_HYST_PARAM 1.0 152 #define MIN_HYST_PARAM 0.0 153 #define MAX_LQ_LEVEL 2 154 #define MIN_LQ_LEVEL 0 155 #define MAX_LQ_AGING 1.0 156 #define MIN_LQ_AGING 0.01 157 158 #define MIN_SMARTGW_USE_COUNT_MIN 1 159 #define MAX_SMARTGW_USE_COUNT_MAX 64 160 161 #define MIN_SMARTGW_EGRESS_FILE_PERIOD 1000 162 163 #define MAX_SMARTGW_EGRESS_INTERFACE_COUNT_MAX 32 164 165 #define MIN_SMARTGW_PERIOD 1*1000 166 #define MAX_SMARTGW_PERIOD 320000*1000 167 168 #define MIN_SMARTGW_STABLE 1 169 #define MAX_SMARTGW_STABLE 254 170 171 #define MIN_SMARTGW_THRES 10 172 #define MAX_SMARTGW_THRES 100 173 174 #define MIN_SMARTGW_SPEED 1 175 #define MAX_SMARTGW_SPEED 320000000 176 177 #ifndef IPV6_ADDR_SITELOCAL 178 #define IPV6_ADDR_SITELOCAL 0x0040U 179 #endif /* IPV6_ADDR_SITELOCAL */ 180 181 #include "interfaces.h" 182 183 enum smart_gw_uplinktype { 184 GW_UPLINK_NONE, 185 GW_UPLINK_IPV4, 186 GW_UPLINK_IPV6, 187 GW_UPLINK_IPV46, 188 GW_UPLINK_CNT, 189 }; 190 191 192 typedef enum { 193 FIBM_FLAT, 194 FIBM_CORRECT, 195 FIBM_APPROX, 196 FIBM_CNT 197 } olsr_fib_metric_options; 198 199 enum olsr_if_mode { 200 IF_MODE_MESH, 201 IF_MODE_ETHER, 202 IF_MODE_SILENT, 203 IF_MODE_CNT 204 }; 205 206 207 struct olsr_msg_params { 208 float emission_interval; 209 float validity_time; 210 }; 211 212 struct olsr_lq_mult { 213 union olsr_ip_addr addr; 214 uint32_t value; 215 struct olsr_lq_mult *next; 216 }; 217 218 struct olsr_if_weight { 219 int value; 220 bool fixed; 221 }; 222 223 struct if_config_options { 224 union olsr_ip_addr ipv4_multicast; 225 union olsr_ip_addr ipv6_multicast; 226 227 union olsr_ip_addr ipv4_src; 228 struct olsr_ip_prefix ipv6_src; 229 230 int mode; 231 232 struct olsr_if_weight weight; 233 struct olsr_msg_params hello_params; 234 struct olsr_msg_params tc_params; 235 struct olsr_msg_params mid_params; 236 struct olsr_msg_params hna_params; 237 struct olsr_lq_mult *lq_mult; 238 int orig_lq_mult_cnt; 239 bool autodetect_chg; 240 }; 241 242 struct olsr_if { 243 char *name; 244 bool configured; 245 bool host_emul; 246 union olsr_ip_addr hemu_ip; 247 struct interface_olsr *interf; 248 struct if_config_options *cnf, *cnfi; 249 struct olsr_if *next; 250 }; 251 252 struct ip_prefix_list { 253 struct olsr_ip_prefix net; 254 struct ip_prefix_list *next; 255 }; 256 257 struct hyst_param { 258 float scaling; 259 float thr_high; 260 float thr_low; 261 }; 262 263 struct plugin_param { 264 char *key; 265 char *value; 266 struct plugin_param *next; 267 }; 268 269 struct plugin_entry { 270 char *name; 271 struct plugin_param *params; 272 struct plugin_entry *next; 273 }; 274 275 /* 276 * The config struct 277 */ 278 279 struct olsrd_config { 280 char * configuration_file; 281 uint16_t olsrport; 282 int debug_level; 283 bool no_fork; 284 char * pidfile; 285 bool host_emul; 286 int ip_version; 287 bool allow_no_interfaces; 288 uint8_t tos; 289 uint8_t rt_proto; 290 uint8_t rt_table; 291 uint8_t rt_table_default; 292 uint8_t rt_table_tunnel; 293 int32_t rt_table_pri; 294 int32_t rt_table_tunnel_pri; 295 int32_t rt_table_defaultolsr_pri; 296 int32_t rt_table_default_pri; 297 uint8_t willingness; 298 bool willingness_auto; 299 int ipc_connections; 300 bool use_hysteresis; 301 olsr_fib_metric_options fib_metric; 302 int fib_metric_default; 303 struct hyst_param hysteresis_param; 304 struct plugin_entry *plugins; 305 struct ip_prefix_list *hna_entries; 306 struct ip_prefix_list *ipc_nets; 307 struct if_config_options *interface_defaults; 308 struct olsr_if *interfaces; 309 float pollrate; 310 float nic_chgs_pollrate; 311 bool clear_screen; 312 uint8_t tc_redundancy; 313 uint8_t mpr_coverage; 314 uint8_t lq_level; 315 uint8_t lq_fish; 316 float lq_aging; 317 char *lq_algorithm; 318 319 float min_tc_vtime; 320 321 bool set_ip_forward; 322 323 char *lock_file; 324 bool use_niit; 325 326 bool smart_gw_active; 327 bool smart_gw_always_remove_server_tunnel; 328 bool smart_gw_allow_nat; 329 bool smart_gw_uplink_nat; 330 uint8_t smart_gw_use_count; 331 uint8_t smart_gw_takedown_percentage; 332 char *smart_gw_instance_id; 333 char *smart_gw_policyrouting_script; 334 struct sgw_egress_if * smart_gw_egress_interfaces; 335 uint8_t smart_gw_egress_interfaces_count; 336 char *smart_gw_egress_file; 337 uint32_t smart_gw_egress_file_period; 338 char *smart_gw_status_file; 339 uint32_t smart_gw_offset_tables; 340 uint32_t smart_gw_offset_rules; 341 uint32_t smart_gw_period; 342 uint8_t smart_gw_stablecount; 343 uint8_t smart_gw_thresh; 344 uint8_t smart_gw_weight_exitlink_up; 345 uint8_t smart_gw_weight_exitlink_down; 346 uint8_t smart_gw_weight_etx; 347 uint32_t smart_gw_divider_etx; 348 uint32_t smart_gw_path_max_cost_etx_max; 349 enum smart_gw_uplinktype smart_gw_type; 350 uint32_t smart_gw_uplink; 351 uint32_t smart_gw_downlink; 352 bool smart_gateway_bandwidth_zero; 353 struct olsr_ip_prefix smart_gw_prefix; 354 355 /* Main address of this node */ 356 union olsr_ip_addr main_addr; 357 union olsr_ip_addr unicast_src_ip; 358 bool use_src_ip_routes; 359 360 /* Stuff set by olsrd */ 361 uint8_t maxplen; /* maximum prefix len */ 362 size_t ipsize; /* Size of address */ 363 bool del_gws; /* Delete InternetGWs at startup */ 364 float will_int; 365 float max_jitter; 366 int exit_value; /* Global return value for process termination */ 367 float max_tc_vtime; 368 369 int niit4to6_if_index; 370 int niit6to4_if_index; 371 372 /*many potential parameters or helper variables for smartgateway*/ 373 bool has_ipv4_gateway; 374 bool has_ipv6_gateway; 375 376 int ioctl_s; /* Socket used for ioctl calls */ 377 #ifdef __linux__ 378 int rtnl_s; /* Socket used for rtnetlink messages */ 379 int rt_monitor_socket; 380 #endif /* __linux__ */ 381 382 #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ 383 int rts; /* Socket used for route changes on BSDs */ 384 #endif /* defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__ */ 385 float lq_nat_thresh; 386 387 TransmitGpsInformation * pud_position; 388 }; 389 390 #if defined __cplusplus 391 extern "C" { 392 #endif /* defined __cplusplus */ 393 394 extern const char *GW_UPLINK_TXT[]; 395 extern const char *FIB_METRIC_TXT[]; 396 extern const char *OLSR_IF_MODE[]; 397 398 /* 399 * List functions 400 */ 401 402 /** 403 * Count the number of olsr interfaces 404 * 405 * @return the number of olsr interfaces 406 */ getNrOfOlsrInterfaces(struct olsrd_config * cfg)407 static INLINE unsigned int getNrOfOlsrInterfaces(struct olsrd_config * cfg) { 408 struct olsr_if * ifn; 409 unsigned int i = 0; 410 411 for (ifn = cfg->interfaces; ifn; ifn = ifn->next, i++) {} 412 return i; 413 } 414 415 416 void ip_prefix_list_add(struct ip_prefix_list **, const union olsr_ip_addr *, uint8_t); 417 418 int ip_prefix_list_remove(struct ip_prefix_list **, const union olsr_ip_addr *, uint8_t); 419 420 struct ip_prefix_list *ip_prefix_list_find(struct ip_prefix_list *, const union olsr_ip_addr *net, uint8_t prefix_len); 421 422 /* 423 * Interface to parser 424 */ 425 426 int olsrd_parse_cnf(const char *); 427 428 int olsrd_sanity_check_cnf(struct olsrd_config *); 429 430 void olsrd_free_cnf(struct olsrd_config **); 431 432 void olsrd_print_cnf(struct olsrd_config *); 433 434 void olsrd_cfgfile_init(void); 435 436 void olsrd_cfgfile_cleanup(void); 437 438 void olsrd_write_cnf_autobuf(struct autobuf *out, struct olsrd_config *cnf); 439 440 void olsrd_write_cnf_autobuf_uncached(struct autobuf *out, struct olsrd_config *cnf); 441 442 int olsrd_write_cnf(struct olsrd_config *, const char *); 443 444 struct if_config_options *get_default_if_config(void); 445 446 struct olsrd_config *olsrd_get_default_cnf(char * configuration_file); 447 448 #if defined _WIN32 449 void win32_stdio_hack(unsigned int); 450 451 void *win32_olsrd_malloc(size_t size); 452 453 void win32_olsrd_free(void *ptr); 454 #endif /* defined _WIN32 */ 455 456 /* 457 * Smart-Gateway uplink/downlink accessors 458 */ 459 set_smart_gateway_bandwidth_zero(struct olsrd_config * cnf)460 static INLINE void set_smart_gateway_bandwidth_zero(struct olsrd_config *cnf) { 461 cnf->smart_gateway_bandwidth_zero = !cnf->smart_gw_uplink || !cnf->smart_gw_downlink; 462 } 463 smartgw_set_uplink(struct olsrd_config * cnf,uint32_t uplink)464 static INLINE void smartgw_set_uplink(struct olsrd_config *cnf, uint32_t uplink) { 465 cnf->smart_gw_uplink = uplink; 466 set_smart_gateway_bandwidth_zero(cnf); 467 } 468 smartgw_set_downlink(struct olsrd_config * cnf,uint32_t downlink)469 static INLINE void smartgw_set_downlink(struct olsrd_config *cnf, uint32_t downlink) { 470 cnf->smart_gw_downlink = downlink; 471 set_smart_gateway_bandwidth_zero(cnf); 472 } 473 smartgw_is_zero_bandwidth(struct olsrd_config * cnf)474 static INLINE bool smartgw_is_zero_bandwidth(struct olsrd_config *cnf) { 475 return cnf->smart_gateway_bandwidth_zero; 476 } 477 478 #if defined __cplusplus 479 } 480 #endif /* defined __cplusplus */ 481 #endif /* _OLSRD_CFGPARSER_H */ 482 483 /* 484 * Local Variables: 485 * c-basic-offset: 2 486 * indent-tabs-mode: nil 487 * End: 488 */ 489