4 * The olsr.org Optimized Link-State Routing daemon(olsrd)
5 * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of olsr.org, olsrd nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * Visit http://www.olsr.org for more information.
37 * If you find this software useful feel free to make a donation
38 * to the project. For more information see the website or contact
39 * the copyright holders.
41 * $Id: oparse.y,v 1.22 2004/11/29 20:10:35 kattemat Exp $
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
54 #include "olsrd_conf.h"
56 #define PARSER_DEBUG 0
58 #define YYSTYPE struct conf_token *
88 %token TOK_WILLINGNESS
95 %token TOK_TCREDUNDANCY
96 %token TOK_MPRCOVERAGE
99 %token TOK_CLEAR_SCREEN
107 %token TOK_IP4BROADCAST
108 %token TOK_IP6ADDRTYPE
109 %token TOK_IP6MULTISITE
110 %token TOK_IP6MULTIGLOBAL
150 block: TOK_HNA4 hna4body
157 hna4body: TOK_OPEN hna4stmts TOK_CLOSE
160 hna4stmts: | hna4stmts hna4stmt
167 hna6body: TOK_OPEN hna6stmts TOK_CLOSE
170 hna6stmts: | hna6stmts hna6stmt
177 ipcbody: TOK_OPEN ipcstmts TOK_CLOSE
180 ipcstmts: | ipcstmts ipcstmt
189 ifbody: TOK_OPEN ifstmts TOK_CLOSE
192 ifstmts: | ifstmts ifstmt
210 plbody: TOK_OPEN plstmts TOK_CLOSE
213 plstmts: | plstmts plstmt
221 imaxipc: TOK_MAXIPC TOK_INTEGER
223 cnf->ipc_connections = $2->integer;
225 cnf->open_ipc = cnf->ipc_connections ? OLSR_TRUE : OLSR_FALSE;
232 ipchost: TOK_HOSTLABEL TOK_IP4_ADDR
235 struct ipc_host *ipch;
237 if(PARSER_DEBUG) printf("\tIPC host: %s\n", $2->string);
239 if(inet_aton($2->string, &in) == 0)
241 fprintf(stderr, "Failed converting IP address IPC %s\n", $2->string);
245 ipch = malloc(sizeof(struct ipc_host));
246 ipch->host.v4 = in.s_addr;
248 ipch->next = cnf->ipc_hosts;
249 cnf->ipc_hosts = ipch;
257 ipcnet: TOK_NETLABEL TOK_IP4_ADDR TOK_IP4_ADDR
259 struct in_addr in1, in2;
260 struct ipc_net *ipcn;
262 if(PARSER_DEBUG) printf("\tIPC net: %s/%s\n", $2->string, $3->string);
264 if(inet_aton($2->string, &in1) == 0)
266 fprintf(stderr, "Failed converting IP net IPC %s\n", $2->string);
270 if(inet_aton($3->string, &in2) == 0)
272 fprintf(stderr, "Failed converting IP mask IPC %s\n", $3->string);
276 ipcn = malloc(sizeof(struct ipc_net));
277 ipcn->net.v4 = in1.s_addr;
278 ipcn->mask.v4 = in2.s_addr;
280 ipcn->next = cnf->ipc_nets;
281 cnf->ipc_nets = ipcn;
291 isetip4br: TOK_IP4BROADCAST TOK_IP4_ADDR
295 if(PARSER_DEBUG) printf("\tIPv4 broadcast: %s\n", $2->string);
297 if(inet_aton($2->string, &in) == 0)
299 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
303 cnf->interfaces->cnf->ipv4_broadcast.v4 = in.s_addr;
310 isetip6addrt: TOK_IP6ADDRTYPE TOK_IP6TYPE
313 cnf->interfaces->cnf->ipv6_addrtype = IPV6_ADDR_SITELOCAL;
315 cnf->interfaces->cnf->ipv6_addrtype = 0;
321 isetip6mults: TOK_IP6MULTISITE TOK_IP6_ADDR
325 if(PARSER_DEBUG) printf("\tIPv6 site-local multicast: %s\n", $2->string);
327 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
329 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
332 memcpy(&cnf->interfaces->cnf->ipv6_multi_site.v6, &in6, sizeof(struct in6_addr));
341 isetip6multg: TOK_IP6MULTIGLOBAL TOK_IP6_ADDR
345 if(PARSER_DEBUG) printf("\tIPv6 global multicast: %s\n", $2->string);
347 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
349 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
352 memcpy(&cnf->interfaces->cnf->ipv6_multi_glbl.v6, &in6, sizeof(struct in6_addr));
359 isethelloint: TOK_HELLOINT TOK_FLOAT
361 if(PARSER_DEBUG) printf("\tHELLO interval: %0.2f\n", $2->floating);
362 cnf->interfaces->cnf->hello_params.emission_interval = $2->floating;
366 isethelloval: TOK_HELLOVAL TOK_FLOAT
368 if(PARSER_DEBUG) printf("\tHELLO validity: %0.2f\n", $2->floating);
369 cnf->interfaces->cnf->hello_params.validity_time = $2->floating;
373 isettcint: TOK_TCINT TOK_FLOAT
375 if(PARSER_DEBUG) printf("\tTC interval: %0.2f\n", $2->floating);
376 cnf->interfaces->cnf->tc_params.emission_interval = $2->floating;
380 isettcval: TOK_TCVAL TOK_FLOAT
382 if(PARSER_DEBUG) printf("\tTC validity: %0.2f\n", $2->floating);
383 cnf->interfaces->cnf->tc_params.validity_time = $2->floating;
387 isetmidint: TOK_MIDINT TOK_FLOAT
389 if(PARSER_DEBUG) printf("\tMID interval: %0.2f\n", $2->floating);
390 cnf->interfaces->cnf->mid_params.emission_interval = $2->floating;
394 isetmidval: TOK_MIDVAL TOK_FLOAT
396 if(PARSER_DEBUG) printf("\tMID validity: %0.2f\n", $2->floating);
397 cnf->interfaces->cnf->mid_params.validity_time = $2->floating;
401 isethnaint: TOK_HNAINT TOK_FLOAT
403 if(PARSER_DEBUG) printf("\tHNA interval: %0.2f\n", $2->floating);
404 cnf->interfaces->cnf->hna_params.emission_interval = $2->floating;
408 isethnaval: TOK_HNAVAL TOK_FLOAT
410 if(PARSER_DEBUG) printf("\tHNA validity: %0.2f\n", $2->floating);
411 cnf->interfaces->cnf->hna_params.validity_time = $2->floating;
417 idebug: TOK_DEBUGLEVEL TOK_INTEGER
420 cnf->debug_level = $2->integer;
421 if(PARSER_DEBUG) printf("Debug level: %d\n", cnf->debug_level);
427 iipversion: TOK_IPVERSION TOK_INTEGER
430 cnf->ip_version = AF_INET;
431 else if($2->integer == 6)
432 cnf->ip_version = AF_INET6;
435 fprintf(stderr, "IPversion must be 4 or 6!\n");
439 if(PARSER_DEBUG) printf("IpVersion: %d\n", $2->integer);
445 ihna4entry: TOK_IP4_ADDR TOK_IP4_ADDR
447 struct hna4_entry *h = malloc(sizeof(struct hna4_entry));
450 if(PARSER_DEBUG) printf("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
454 fprintf(stderr, "Out of memory(HNA4)\n");
458 if(inet_aton($1->string, &in) == 0)
460 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
463 h->net.v4 = in.s_addr;
464 if(inet_aton($2->string, &in) == 0)
466 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
469 h->netmask.v4 = in.s_addr;
471 h->next = cnf->hna4_entries;
472 cnf->hna4_entries = h;
482 ihna6entry: TOK_IP6_ADDR TOK_INTEGER
484 struct hna6_entry *h = malloc(sizeof(struct hna6_entry));
487 if(PARSER_DEBUG) printf("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
491 fprintf(stderr, "Out of memory(HNA6)\n");
495 if(inet_pton(AF_INET6, $1->string, &in6) < 0)
497 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
500 memcpy(&h->net, &in6, sizeof(struct in6_addr));
502 if(($2->integer < 0) || ($2->integer > 128))
504 fprintf(stderr, "Illegal IPv6 prefix length %d\n", $2->integer);
508 h->prefix_len = $2->integer;
510 h->next = cnf->hna6_entries;
511 cnf->hna6_entries = h;
520 ifblock: TOK_INTERFACE TOK_STRING
522 struct olsr_if *in = malloc(sizeof(struct olsr_if));
526 fprintf(stderr, "Out of memory(ADD IF)\n");
530 in->cnf = get_default_if_config();
534 fprintf(stderr, "Out of memory(ADD IFRULE)\n");
538 in->name = $2->string;
541 in->next = cnf->interfaces;
542 cnf->interfaces = in;
548 bnoint: TOK_NOINT TOK_BOOLEAN
550 if(PARSER_DEBUG) printf("Noint set to %d\n", $2->boolean);
552 cnf->allow_no_interfaces = $2->boolean;
558 atos: TOK_TOS TOK_INTEGER
560 if(PARSER_DEBUG) printf("TOS: %d\n", $2->integer);
561 cnf->tos = $2->integer;
568 awillingness: TOK_WILLINGNESS TOK_INTEGER
570 cnf->willingness_auto = OLSR_FALSE;
572 if(PARSER_DEBUG) printf("Willingness: %d\n", $2->integer);
573 cnf->willingness = $2->integer;
582 busehyst: TOK_USEHYST TOK_BOOLEAN
584 cnf->use_hysteresis = $2->boolean;
585 if(cnf->use_hysteresis)
587 if(PARSER_DEBUG) printf("Hysteresis enabled\n");
591 if(PARSER_DEBUG) printf("Hysteresis disabled\n");
599 fhystscale: TOK_HYSTSCALE TOK_FLOAT
601 cnf->hysteresis_param.scaling = $2->floating;
602 if(PARSER_DEBUG) printf("Hysteresis Scaling: %0.2f\n", $2->floating);
608 fhystupper: TOK_HYSTUPPER TOK_FLOAT
610 cnf->hysteresis_param.thr_high = $2->floating;
611 if(PARSER_DEBUG) printf("Hysteresis UpperThr: %0.2f\n", $2->floating);
617 fhystlower: TOK_HYSTLOWER TOK_FLOAT
619 cnf->hysteresis_param.thr_low = $2->floating;
620 if(PARSER_DEBUG) printf("Hysteresis LowerThr: %0.2f\n", $2->floating);
625 fpollrate: TOK_POLLRATE TOK_FLOAT
627 if(PARSER_DEBUG) printf("Pollrate %0.2f\n", $2->floating);
628 cnf->pollrate = $2->floating;
635 atcredundancy: TOK_TCREDUNDANCY TOK_INTEGER
637 if(PARSER_DEBUG) printf("TC redundancy %d\n", $2->integer);
638 cnf->tc_redundancy = $2->integer;
643 amprcoverage: TOK_MPRCOVERAGE TOK_INTEGER
645 if(PARSER_DEBUG) printf("MPR coverage %d\n", $2->integer);
646 cnf->mpr_coverage = $2->integer;
651 alq_level: TOK_LQ_LEVEL TOK_INTEGER
653 if(PARSER_DEBUG) printf("Link quality level %d\n", $2->integer);
654 cnf->lq_level = $2->integer;
659 alq_wsize: TOK_LQ_WSIZE TOK_INTEGER
661 if(PARSER_DEBUG) printf("Link quality window size %d\n", $2->integer);
662 cnf->lq_wsize = $2->integer;
667 bclear_screen: TOK_CLEAR_SCREEN TOK_BOOLEAN
669 cnf->clear_screen = $2->boolean;
672 printf("Clear screen %s\n", cnf->clear_screen ? "enabled" : "disabled");
678 plblock: TOK_PLUGIN TOK_STRING
680 struct plugin_entry *pe = malloc(sizeof(struct plugin_entry));
684 fprintf(stderr, "Out of memory(ADD PL)\n");
688 pe->name = $2->string;
692 if(PARSER_DEBUG) printf("Plugin: %s\n", $2->string);
695 pe->next = cnf->plugins;
702 plparam: TOK_PLPARAM TOK_STRING TOK_STRING
704 struct plugin_param *pp = malloc(sizeof(struct plugin_param));
708 fprintf(stderr, "Out of memory(ADD PP)\n");
712 if(PARSER_DEBUG) printf("Plugin param key:\"%s\" val: \"%s\"\n", $2->string, $3->string);
714 pp->key = $2->string;
715 pp->value = $3->string;
718 pp->next = cnf->plugins->params;
719 cnf->plugins->params = pp;
726 vcomment: TOK_COMMENT
728 //if(PARSER_DEBUG) printf("Comment\n");
736 void yyerror (char *string)
738 fprintf(stderr, "Config line %d: %s\n", current_line, string);