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.25 2005/02/17 17:21:24 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 *
63 static int ifs_in_curr_cfg = 0;
65 static int lq_mult_helper(YYSTYPE ip_addr_arg, YYSTYPE mult_arg);
67 static int lq_mult_helper(YYSTYPE ip_addr_arg, YYSTYPE mult_arg)
69 union olsr_ip_addr addr;
71 struct olsr_if *walker;
72 struct olsr_lq_mult *mult;
75 printf("\tLinkQualityMult %s %0.2f\n",
76 (ip_addr_arg != NULL) ? ip_addr_arg->string : "any",
80 memset(&addr, 0, sizeof (union olsr_ip_addr));
82 if(ip_addr_arg != NULL &&
83 inet_pton(cnf->ip_version, ip_addr_arg->string, &addr) < 0)
85 fprintf(stderr, "Cannot parse IP address %s.\n", ip_addr_arg->string);
89 walker = cnf->interfaces;
91 for (i = 0; i < ifs_in_curr_cfg; i++)
93 mult = malloc(sizeof (struct olsr_lq_mult));
97 fprintf(stderr, "Out of memory (LQ multiplier).\n");
101 memcpy(&mult->addr, &addr, sizeof (union olsr_ip_addr));
102 mult->val = mult_arg->floating;
104 mult->next = walker->cnf->lq_mult;
105 walker->cnf->lq_mult = mult;
107 walker = walker->next;
110 if (ip_addr_arg != NULL)
112 free(ip_addr_arg->string);
133 %token TOK_DEBUGLEVEL
141 %token TOK_WILLINGNESS
148 %token TOK_TCREDUNDANCY
149 %token TOK_MPRCOVERAGE
153 %token TOK_CLEAR_SCREEN
161 %token TOK_IP4BROADCAST
162 %token TOK_IP6ADDRTYPE
163 %token TOK_IP6MULTISITE
164 %token TOK_IP6MULTIGLOBAL
206 block: TOK_HNA4 hna4body
213 hna4body: TOK_OPEN hna4stmts TOK_CLOSE
216 hna4stmts: | hna4stmts hna4stmt
223 hna6body: TOK_OPEN hna6stmts TOK_CLOSE
226 hna6stmts: | hna6stmts hna6stmt
233 ipcbody: TOK_OPEN ipcstmts TOK_CLOSE
236 ipcstmts: | ipcstmts ipcstmt
245 ifblock: ifstart ifnicks
248 ifnicks: | ifnicks ifnick
251 ifbody: TOK_OPEN ifstmts TOK_CLOSE
254 ifstmts: | ifstmts ifstmt
274 plbody: TOK_OPEN plstmts TOK_CLOSE
277 plstmts: | plstmts plstmt
285 imaxipc: TOK_MAXIPC TOK_INTEGER
287 cnf->ipc_connections = $2->integer;
289 cnf->open_ipc = cnf->ipc_connections ? OLSR_TRUE : OLSR_FALSE;
295 ipchost: TOK_HOSTLABEL TOK_IP4_ADDR
298 struct ipc_host *ipch;
300 if(PARSER_DEBUG) printf("\tIPC host: %s\n", $2->string);
302 if(inet_aton($2->string, &in) == 0)
304 fprintf(stderr, "Failed converting IP address IPC %s\n", $2->string);
308 ipch = malloc(sizeof(struct ipc_host));
309 ipch->host.v4 = in.s_addr;
311 ipch->next = cnf->ipc_hosts;
312 cnf->ipc_hosts = ipch;
320 ipcnet: TOK_NETLABEL TOK_IP4_ADDR TOK_IP4_ADDR
322 struct in_addr in1, in2;
323 struct ipc_net *ipcn;
325 if(PARSER_DEBUG) printf("\tIPC net: %s/%s\n", $2->string, $3->string);
327 if(inet_aton($2->string, &in1) == 0)
329 fprintf(stderr, "Failed converting IP net IPC %s\n", $2->string);
333 if(inet_aton($3->string, &in2) == 0)
335 fprintf(stderr, "Failed converting IP mask IPC %s\n", $3->string);
339 ipcn = malloc(sizeof(struct ipc_net));
340 ipcn->net.v4 = in1.s_addr;
341 ipcn->mask.v4 = in2.s_addr;
343 ipcn->next = cnf->ipc_nets;
344 cnf->ipc_nets = ipcn;
354 iifweight: TOK_IFWEIGHT TOK_INTEGER
356 int ifcnt = ifs_in_curr_cfg;
357 struct olsr_if *ifs = cnf->interfaces;
359 if(PARSER_DEBUG) printf("Fixed willingness: %d\n", $2->integer);
363 ifs->cnf->weight.value = $2->integer;
364 ifs->cnf->weight.fixed = OLSR_TRUE;
374 isetip4br: TOK_IP4BROADCAST TOK_IP4_ADDR
377 int ifcnt = ifs_in_curr_cfg;
378 struct olsr_if *ifs = cnf->interfaces;
380 if(PARSER_DEBUG) printf("\tIPv4 broadcast: %s\n", $2->string);
382 if(inet_aton($2->string, &in) == 0)
384 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
390 ifs->cnf->ipv4_broadcast.v4 = in.s_addr;
401 isetip6addrt: TOK_IP6ADDRTYPE TOK_IP6TYPE
403 int ifcnt = ifs_in_curr_cfg;
404 struct olsr_if *ifs = cnf->interfaces;
410 ifs->cnf->ipv6_addrtype = IPV6_ADDR_SITELOCAL;
420 ifs->cnf->ipv6_addrtype = 0;
431 isetip6mults: TOK_IP6MULTISITE TOK_IP6_ADDR
434 int ifcnt = ifs_in_curr_cfg;
435 struct olsr_if *ifs = cnf->interfaces;
437 if(PARSER_DEBUG) printf("\tIPv6 site-local multicast: %s\n", $2->string);
439 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
441 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
447 memcpy(&ifs->cnf->ipv6_multi_site.v6, &in6, sizeof(struct in6_addr));
460 isetip6multg: TOK_IP6MULTIGLOBAL TOK_IP6_ADDR
463 int ifcnt = ifs_in_curr_cfg;
464 struct olsr_if *ifs = cnf->interfaces;
466 if(PARSER_DEBUG) printf("\tIPv6 global multicast: %s\n", $2->string);
468 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
470 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
476 memcpy(&ifs->cnf->ipv6_multi_glbl.v6, &in6, sizeof(struct in6_addr));
487 isethelloint: TOK_HELLOINT TOK_FLOAT
489 int ifcnt = ifs_in_curr_cfg;
490 struct olsr_if *ifs = cnf->interfaces;
492 if(PARSER_DEBUG) printf("\tHELLO interval: %0.2f\n", $2->floating);
496 ifs->cnf->hello_params.emission_interval = $2->floating;
505 isethelloval: TOK_HELLOVAL TOK_FLOAT
507 int ifcnt = ifs_in_curr_cfg;
508 struct olsr_if *ifs = cnf->interfaces;
510 if(PARSER_DEBUG) printf("\tHELLO validity: %0.2f\n", $2->floating);
514 ifs->cnf->hello_params.validity_time = $2->floating;
523 isettcint: TOK_TCINT TOK_FLOAT
525 int ifcnt = ifs_in_curr_cfg;
526 struct olsr_if *ifs = cnf->interfaces;
528 if(PARSER_DEBUG) printf("\tTC interval: %0.2f\n", $2->floating);
532 ifs->cnf->tc_params.emission_interval = $2->floating;
540 isettcval: TOK_TCVAL TOK_FLOAT
542 int ifcnt = ifs_in_curr_cfg;
543 struct olsr_if *ifs = cnf->interfaces;
545 if(PARSER_DEBUG) printf("\tTC validity: %0.2f\n", $2->floating);
548 ifs->cnf->tc_params.validity_time = $2->floating;
557 isetmidint: TOK_MIDINT TOK_FLOAT
559 int ifcnt = ifs_in_curr_cfg;
560 struct olsr_if *ifs = cnf->interfaces;
563 if(PARSER_DEBUG) printf("\tMID interval: %0.2f\n", $2->floating);
566 ifs->cnf->mid_params.emission_interval = $2->floating;
575 isetmidval: TOK_MIDVAL TOK_FLOAT
577 int ifcnt = ifs_in_curr_cfg;
578 struct olsr_if *ifs = cnf->interfaces;
580 if(PARSER_DEBUG) printf("\tMID validity: %0.2f\n", $2->floating);
583 ifs->cnf->mid_params.validity_time = $2->floating;
592 isethnaint: TOK_HNAINT TOK_FLOAT
594 int ifcnt = ifs_in_curr_cfg;
595 struct olsr_if *ifs = cnf->interfaces;
597 if(PARSER_DEBUG) printf("\tHNA interval: %0.2f\n", $2->floating);
600 ifs->cnf->hna_params.emission_interval = $2->floating;
609 isethnaval: TOK_HNAVAL TOK_FLOAT
611 int ifcnt = ifs_in_curr_cfg;
612 struct olsr_if *ifs = cnf->interfaces;
614 if(PARSER_DEBUG) printf("\tHNA validity: %0.2f\n", $2->floating);
617 ifs->cnf->hna_params.validity_time = $2->floating;
627 isetlqmult: TOK_LQ_MULT TOK_DEFAULT TOK_FLOAT
629 if (lq_mult_helper($2, $3) < 0)
633 | TOK_LQ_MULT TOK_IP4_ADDR TOK_FLOAT
635 if (lq_mult_helper($2, $3) < 0)
639 | TOK_LQ_MULT TOK_IP6_ADDR TOK_FLOAT
641 if (lq_mult_helper($2, $3) < 0)
647 idebug: TOK_DEBUGLEVEL TOK_INTEGER
650 cnf->debug_level = $2->integer;
651 if(PARSER_DEBUG) printf("Debug level: %d\n", cnf->debug_level);
657 iipversion: TOK_IPVERSION TOK_INTEGER
660 cnf->ip_version = AF_INET;
661 else if($2->integer == 6)
662 cnf->ip_version = AF_INET6;
665 fprintf(stderr, "IPversion must be 4 or 6!\n");
669 if(PARSER_DEBUG) printf("IpVersion: %d\n", $2->integer);
675 ihna4entry: TOK_IP4_ADDR TOK_IP4_ADDR
677 struct hna4_entry *h = malloc(sizeof(struct hna4_entry));
680 if(PARSER_DEBUG) printf("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
684 fprintf(stderr, "Out of memory(HNA4)\n");
688 if(inet_aton($1->string, &in) == 0)
690 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
693 h->net.v4 = in.s_addr;
694 if(inet_aton($2->string, &in) == 0)
696 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
699 h->netmask.v4 = in.s_addr;
701 h->next = cnf->hna4_entries;
702 cnf->hna4_entries = h;
712 ihna6entry: TOK_IP6_ADDR TOK_INTEGER
714 struct hna6_entry *h = malloc(sizeof(struct hna6_entry));
717 if(PARSER_DEBUG) printf("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
721 fprintf(stderr, "Out of memory(HNA6)\n");
725 if(inet_pton(AF_INET6, $1->string, &in6) < 0)
727 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
730 memcpy(&h->net, &in6, sizeof(struct in6_addr));
732 if(($2->integer < 0) || ($2->integer > 128))
734 fprintf(stderr, "Illegal IPv6 prefix length %d\n", $2->integer);
738 h->prefix_len = $2->integer;
740 h->next = cnf->hna6_entries;
741 cnf->hna6_entries = h;
750 ifstart: TOK_INTERFACE
752 printf("setting ifs_in_curr_cfg = 0\n");
760 struct olsr_if *in = malloc(sizeof(struct olsr_if));
764 fprintf(stderr, "Out of memory(ADD IF)\n");
768 in->cnf = get_default_if_config();
772 fprintf(stderr, "Out of memory(ADD IFRULE)\n");
776 in->name = $1->string;
779 in->next = cnf->interfaces;
780 cnf->interfaces = in;
788 bnoint: TOK_NOINT TOK_BOOLEAN
790 if(PARSER_DEBUG) printf("Noint set to %d\n", $2->boolean);
792 cnf->allow_no_interfaces = $2->boolean;
798 atos: TOK_TOS TOK_INTEGER
800 if(PARSER_DEBUG) printf("TOS: %d\n", $2->integer);
801 cnf->tos = $2->integer;
808 awillingness: TOK_WILLINGNESS TOK_INTEGER
810 cnf->willingness_auto = OLSR_FALSE;
812 if(PARSER_DEBUG) printf("Willingness: %d\n", $2->integer);
813 cnf->willingness = $2->integer;
822 busehyst: TOK_USEHYST TOK_BOOLEAN
824 cnf->use_hysteresis = $2->boolean;
825 if(cnf->use_hysteresis)
827 if(PARSER_DEBUG) printf("Hysteresis enabled\n");
831 if(PARSER_DEBUG) printf("Hysteresis disabled\n");
839 fhystscale: TOK_HYSTSCALE TOK_FLOAT
841 cnf->hysteresis_param.scaling = $2->floating;
842 if(PARSER_DEBUG) printf("Hysteresis Scaling: %0.2f\n", $2->floating);
848 fhystupper: TOK_HYSTUPPER TOK_FLOAT
850 cnf->hysteresis_param.thr_high = $2->floating;
851 if(PARSER_DEBUG) printf("Hysteresis UpperThr: %0.2f\n", $2->floating);
857 fhystlower: TOK_HYSTLOWER TOK_FLOAT
859 cnf->hysteresis_param.thr_low = $2->floating;
860 if(PARSER_DEBUG) printf("Hysteresis LowerThr: %0.2f\n", $2->floating);
865 fpollrate: TOK_POLLRATE TOK_FLOAT
867 if(PARSER_DEBUG) printf("Pollrate %0.2f\n", $2->floating);
868 cnf->pollrate = $2->floating;
875 atcredundancy: TOK_TCREDUNDANCY TOK_INTEGER
877 if(PARSER_DEBUG) printf("TC redundancy %d\n", $2->integer);
878 cnf->tc_redundancy = $2->integer;
883 amprcoverage: TOK_MPRCOVERAGE TOK_INTEGER
885 if(PARSER_DEBUG) printf("MPR coverage %d\n", $2->integer);
886 cnf->mpr_coverage = $2->integer;
891 alq_level: TOK_LQ_LEVEL TOK_INTEGER
893 if(PARSER_DEBUG) printf("Link quality level %d\n", $2->integer);
894 cnf->lq_level = $2->integer;
899 alq_wsize: TOK_LQ_WSIZE TOK_INTEGER
901 if(PARSER_DEBUG) printf("Link quality window size %d\n", $2->integer);
902 cnf->lq_wsize = $2->integer;
907 bclear_screen: TOK_CLEAR_SCREEN TOK_BOOLEAN
909 cnf->clear_screen = $2->boolean;
912 printf("Clear screen %s\n", cnf->clear_screen ? "enabled" : "disabled");
918 plblock: TOK_PLUGIN TOK_STRING
920 struct plugin_entry *pe = malloc(sizeof(struct plugin_entry));
924 fprintf(stderr, "Out of memory(ADD PL)\n");
928 pe->name = $2->string;
932 if(PARSER_DEBUG) printf("Plugin: %s\n", $2->string);
935 pe->next = cnf->plugins;
942 plparam: TOK_PLPARAM TOK_STRING TOK_STRING
944 struct plugin_param *pp = malloc(sizeof(struct plugin_param));
948 fprintf(stderr, "Out of memory(ADD PP)\n");
952 if(PARSER_DEBUG) printf("Plugin param key:\"%s\" val: \"%s\"\n", $2->string, $3->string);
954 pp->key = $2->string;
955 pp->value = $3->string;
958 pp->next = cnf->plugins->params;
959 cnf->plugins->params = pp;
966 vcomment: TOK_COMMENT
968 //if(PARSER_DEBUG) printf("Comment\n");
976 void yyerror (char *string)
978 fprintf(stderr, "Config line %d: %s\n", current_line, string);