4 * OLSR ad-hoc routing table management protocol config parser
5 * Copyright (C) 2004 Andreas Tønnesen (andreto@olsr.org)
7 * This file is part of the olsr.org OLSR daemon.
9 * olsr.org is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * olsr.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with olsr.org; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * $Id: oparse.y,v 1.17 2004/11/20 18:46:03 kattemat Exp $
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
38 #include "olsrd_conf.h"
40 #define PARSER_DEBUG 0
42 #define YYSTYPE struct conf_token *
72 %token TOK_WILLINGNESS
79 %token TOK_TCREDUNDANCY
80 %token TOK_MPRCOVERAGE
83 %token TOK_CLEAR_SCREEN
91 %token TOK_IP4BROADCAST
92 %token TOK_IP6ADDRTYPE
93 %token TOK_IP6MULTISITE
94 %token TOK_IP6MULTIGLOBAL
134 block: TOK_HNA4 hna4body
141 hna4body: TOK_OPEN hna4stmts TOK_CLOSE
144 hna4stmts: | hna4stmts hna4stmt
151 hna6body: TOK_OPEN hna6stmts TOK_CLOSE
154 hna6stmts: | hna6stmts hna6stmt
161 ipcbody: TOK_OPEN ipcstmts TOK_CLOSE
164 ipcstmts: | ipcstmts ipcstmt
173 ifbody: TOK_OPEN ifstmts TOK_CLOSE
176 ifstmts: | ifstmts ifstmt
194 plbody: TOK_OPEN plstmts TOK_CLOSE
197 plstmts: | plstmts plstmt
205 imaxipc: TOK_MAXIPC TOK_INTEGER
207 cnf->ipc_connections = $2->integer;
209 cnf->open_ipc = cnf->ipc_connections ? OLSR_TRUE : OLSR_FALSE;
216 ipchost: TOK_HOSTLABEL TOK_IP4_ADDR
219 struct ipc_host *ipch;
221 if(PARSER_DEBUG) printf("\tIPC host: %s\n", $2->string);
223 if(inet_aton($2->string, &in) == 0)
225 fprintf(stderr, "Failed converting IP address IPC %s\n", $2->string);
229 ipch = malloc(sizeof(struct ipc_host));
230 ipch->host.v4 = in.s_addr;
232 ipch->next = cnf->ipc_hosts;
233 cnf->ipc_hosts = ipch;
241 ipcnet: TOK_NETLABEL TOK_IP4_ADDR TOK_IP4_ADDR
243 struct in_addr in1, in2;
244 struct ipc_net *ipcn;
246 if(PARSER_DEBUG) printf("\tIPC net: %s/%s\n", $2->string, $3->string);
248 if(inet_aton($2->string, &in1) == 0)
250 fprintf(stderr, "Failed converting IP net IPC %s\n", $2->string);
254 if(inet_aton($3->string, &in2) == 0)
256 fprintf(stderr, "Failed converting IP mask IPC %s\n", $3->string);
260 ipcn = malloc(sizeof(struct ipc_net));
261 ipcn->net.v4 = in1.s_addr;
262 ipcn->mask.v4 = in2.s_addr;
264 ipcn->next = cnf->ipc_nets;
265 cnf->ipc_nets = ipcn;
275 isetip4br: TOK_IP4BROADCAST TOK_IP4_ADDR
279 if(PARSER_DEBUG) printf("\tIPv4 broadcast: %s\n", $2->string);
281 if(inet_aton($2->string, &in) == 0)
283 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
287 cnf->interfaces->cnf->ipv4_broadcast.v4 = in.s_addr;
294 isetip6addrt: TOK_IP6ADDRTYPE TOK_IP6TYPE
297 cnf->interfaces->cnf->ipv6_addrtype = IPV6_ADDR_SITELOCAL;
299 cnf->interfaces->cnf->ipv6_addrtype = 0;
305 isetip6mults: TOK_IP6MULTISITE TOK_IP6_ADDR
309 if(PARSER_DEBUG) printf("\tIPv6 site-local multicast: %s\n", $2->string);
311 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
313 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
316 memcpy(&cnf->interfaces->cnf->ipv6_multi_site.v6, &in6, sizeof(struct in6_addr));
325 isetip6multg: TOK_IP6MULTIGLOBAL TOK_IP6_ADDR
329 if(PARSER_DEBUG) printf("\tIPv6 global multicast: %s\n", $2->string);
331 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
333 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
336 memcpy(&cnf->interfaces->cnf->ipv6_multi_glbl.v6, &in6, sizeof(struct in6_addr));
343 isethelloint: TOK_HELLOINT TOK_FLOAT
345 if(PARSER_DEBUG) printf("\tHELLO interval: %0.2f\n", $2->floating);
346 if($2->floating < MIN_INTERVAL)
348 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
351 cnf->interfaces->cnf->hello_params.emission_interval = $2->floating;
355 isethelloval: TOK_HELLOVAL TOK_FLOAT
357 if(PARSER_DEBUG) printf("\tHELLO validity: %0.2f\n", $2->floating);
358 if($2->floating < MIN_INTERVAL)
360 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
363 cnf->interfaces->cnf->hello_params.validity_time = $2->floating;
367 isettcint: TOK_TCINT TOK_FLOAT
369 if(PARSER_DEBUG) printf("\tTC interval: %0.2f\n", $2->floating);
370 if($2->floating < MIN_INTERVAL)
372 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
375 cnf->interfaces->cnf->tc_params.emission_interval = $2->floating;
379 isettcval: TOK_TCVAL TOK_FLOAT
381 if(PARSER_DEBUG) printf("\tTC validity: %0.2f\n", $2->floating);
382 if($2->floating < MIN_INTERVAL)
384 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
387 cnf->interfaces->cnf->tc_params.validity_time = $2->floating;
391 isetmidint: TOK_MIDINT TOK_FLOAT
393 if(PARSER_DEBUG) printf("\tMID interval: %0.2f\n", $2->floating);
394 if($2->floating < MIN_INTERVAL)
396 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
399 cnf->interfaces->cnf->mid_params.emission_interval = $2->floating;
403 isetmidval: TOK_MIDVAL TOK_FLOAT
405 if(PARSER_DEBUG) printf("\tMID validity: %0.2f\n", $2->floating);
406 if($2->floating < MIN_INTERVAL)
408 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
411 cnf->interfaces->cnf->mid_params.validity_time = $2->floating;
415 isethnaint: TOK_HNAINT TOK_FLOAT
417 if(PARSER_DEBUG) printf("\tHNA interval: %0.2f\n", $2->floating);
418 if($2->floating < MIN_INTERVAL)
420 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
423 cnf->interfaces->cnf->hna_params.emission_interval = $2->floating;
427 isethnaval: TOK_HNAVAL TOK_FLOAT
429 if(PARSER_DEBUG) printf("\tHNA validity: %0.2f\n", $2->floating);
430 if($2->floating < MIN_INTERVAL)
432 fprintf(stderr, "%0.2f is not allowed\n", $2->floating);
435 cnf->interfaces->cnf->hna_params.validity_time = $2->floating;
441 idebug: TOK_DEBUGLEVEL TOK_INTEGER
444 cnf->debug_level = $2->integer;
445 if(PARSER_DEBUG) printf("Debug level: %d\n", cnf->debug_level);
446 if($2->integer < MIN_DEBUGLVL ||
447 $2->integer > MAX_DEBUGLVL)
449 fprintf(stderr, "Debuglevel %d is not allowed\n", $2->integer);
458 iipversion: TOK_IPVERSION TOK_INTEGER
461 cnf->ip_version = AF_INET;
462 else if($2->integer == 6)
463 cnf->ip_version = AF_INET6;
466 fprintf(stderr, "IPversion must be 4 or 6!\n");
470 if(PARSER_DEBUG) printf("IpVersion: %d\n", $2->integer);
476 ihna4entry: TOK_IP4_ADDR TOK_IP4_ADDR
478 struct hna4_entry *h = malloc(sizeof(struct hna4_entry));
481 if(PARSER_DEBUG) printf("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
485 fprintf(stderr, "Out of memory(HNA4)\n");
489 if(inet_aton($1->string, &in) == 0)
491 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
494 h->net.v4 = in.s_addr;
495 if(inet_aton($2->string, &in) == 0)
497 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
500 h->netmask.v4 = in.s_addr;
502 h->next = cnf->hna4_entries;
503 cnf->hna4_entries = h;
512 ihna6entry: TOK_IP6_ADDR TOK_INTEGER
514 struct hna6_entry *h = malloc(sizeof(struct hna6_entry));
517 if(PARSER_DEBUG) printf("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
521 fprintf(stderr, "Out of memory(HNA6)\n");
525 if(inet_pton(AF_INET6, $1->string, &in6) < 0)
527 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
530 memcpy(&h->net, &in6, sizeof(struct in6_addr));
532 if(($2->integer < 0) || ($2->integer > 128))
534 fprintf(stderr, "Illegal IPv6 prefix length %d\n", $2->integer);
538 h->prefix_len = $2->integer;
540 h->next = cnf->hna6_entries;
541 cnf->hna6_entries = h;
549 ifblock: TOK_INTERFACE TOK_STRING
551 struct olsr_if *in = malloc(sizeof(struct olsr_if));
555 fprintf(stderr, "Out of memory(ADD IF)\n");
559 in->cnf = get_default_if_config();
563 fprintf(stderr, "Out of memory(ADD IFRULE)\n");
567 in->name = $2->string;
570 in->next = cnf->interfaces;
571 cnf->interfaces = in;
576 bnoint: TOK_NOINT TOK_BOOLEAN
578 if(PARSER_DEBUG) printf("Noint set to %d\n", $2->boolean);
580 cnf->allow_no_interfaces = $2->boolean;
586 atos: TOK_TOS TOK_INTEGER
588 if(PARSER_DEBUG) printf("TOS: %d\n", $2->integer);
589 if($2->integer < MIN_TOS ||
590 $2->integer > MAX_TOS)
592 fprintf(stderr, "%d is not allowed\n", $2->integer);
596 cnf->tos = $2->integer;
603 awillingness: TOK_WILLINGNESS TOK_INTEGER
605 cnf->willingness_auto = OLSR_FALSE;
607 if(PARSER_DEBUG) printf("Willingness: %d\n", $2->integer);
608 if($2->integer < MIN_WILLINGNESS ||
609 $2->integer > MAX_WILLINGNESS)
611 fprintf(stderr, "willingness %d is not allowed\n", $2->integer);
614 cnf->willingness = $2->integer;
623 busehyst: TOK_USEHYST TOK_BOOLEAN
625 cnf->use_hysteresis = $2->boolean;
626 if(cnf->use_hysteresis)
628 if(PARSER_DEBUG) printf("Hysteresis enabled\n");
632 if(PARSER_DEBUG) printf("Hysteresis disabled\n");
640 fhystscale: TOK_HYSTSCALE TOK_FLOAT
642 cnf->hysteresis_param.scaling = $2->floating;
643 if(PARSER_DEBUG) printf("Hysteresis Scaling: %0.2f\n", $2->floating);
644 if($2->floating < MIN_HYST_PARAM ||
645 $2->floating > MAX_HYST_PARAM)
647 fprintf(stderr, "Hyst scaling %0.2f is not allowed\n", $2->floating);
656 fhystupper: TOK_HYSTUPPER TOK_FLOAT
658 cnf->hysteresis_param.thr_high = $2->floating;
659 if(PARSER_DEBUG) printf("Hysteresis UpperThr: %0.2f\n", $2->floating);
660 if($2->floating < MIN_HYST_PARAM ||
661 $2->floating > MAX_HYST_PARAM)
663 fprintf(stderr, "Hyst upper thr %0.2f is not allowed\n", $2->floating);
671 fhystlower: TOK_HYSTLOWER TOK_FLOAT
673 cnf->hysteresis_param.thr_low = $2->floating;
674 if(PARSER_DEBUG) printf("Hysteresis LowerThr: %0.2f\n", $2->floating);
675 if($2->floating < MIN_HYST_PARAM ||
676 $2->floating > MAX_HYST_PARAM)
678 fprintf(stderr, "Hyst lower thr %0.2f is not allowed\n", $2->floating);
685 fpollrate: TOK_POLLRATE TOK_FLOAT
687 if(PARSER_DEBUG) printf("Pollrate %0.2f\n", $2->floating);
688 if($2->floating < MIN_POLLRATE ||
689 $2->floating > MAX_POLLRATE)
691 fprintf(stderr, "Pollrate %0.2f is not allowed\n", $2->floating);
694 cnf->pollrate = $2->floating;
701 atcredundancy: TOK_TCREDUNDANCY TOK_INTEGER
703 if(PARSER_DEBUG) printf("TC redundancy %d\n", $2->integer);
704 if($2->integer < MIN_TC_REDUNDANCY ||
705 $2->integer > MAX_TC_REDUNDANCY)
707 fprintf(stderr, "TC redundancy %d is not allowed\n", $2->integer);
711 cnf->tc_redundancy = $2->integer;
718 amprcoverage: TOK_MPRCOVERAGE TOK_INTEGER
720 if(PARSER_DEBUG) printf("MPR coverage %d\n", $2->integer);
721 if($2->integer < MIN_MPR_COVERAGE ||
722 $2->integer > MAX_MPR_COVERAGE)
724 fprintf(stderr, "MPR coverage %d is not allowed\n", $2->integer);
728 cnf->mpr_coverage = $2->integer;
734 alq_level: TOK_LQ_LEVEL TOK_INTEGER
736 if(PARSER_DEBUG) printf("Link quality level %d\n", $2->integer);
737 cnf->lq_level = $2->integer;
743 alq_wsize: TOK_LQ_WSIZE TOK_INTEGER
745 if(PARSER_DEBUG) printf("Link quality window size %d\n", $2->integer);
746 cnf->lq_wsize = $2->integer;
752 bclear_screen: TOK_CLEAR_SCREEN TOK_BOOLEAN
754 cnf->clear_screen = $2->boolean;
757 printf("Clear screen %s\n", cnf->clear_screen ? "enabled" : "disabled");
763 plblock: TOK_PLUGIN TOK_STRING
765 struct plugin_entry *pe = malloc(sizeof(struct plugin_entry));
769 fprintf(stderr, "Out of memory(ADD PL)\n");
773 pe->name = $2->string;
777 if(PARSER_DEBUG) printf("Plugin: %s\n", $2->string);
780 pe->next = cnf->plugins;
787 plparam: TOK_PLPARAM TOK_STRING TOK_STRING
789 struct plugin_param *pp = malloc(sizeof(struct plugin_param));
793 fprintf(stderr, "Out of memory(ADD PP)\n");
797 if(PARSER_DEBUG) printf("Plugin param key:\"%s\" val: \"%s\"\n", $2->string, $3->string);
799 pp->key = $2->string;
800 pp->value = $3->string;
803 pp->next = cnf->plugins->params;
804 cnf->plugins->params = pp;
811 vcomment: TOK_COMMENT
813 //if(PARSER_DEBUG) printf("Comment\n");
821 void yyerror (char *string)
823 fprintf(stderr, "Config line %d: %s\n", current_line, string);