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.3 2004/10/17 11:52:41 kattemat Exp $
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
37 #include "olsrd_conf.h"
39 #define PARSER_DEBUG 0
41 #define YYSTYPE struct conf_token *
46 struct if_config_options *
47 get_default_if_config(void);
50 struct if_config_options *
51 get_default_if_config()
53 struct if_config_options *io = malloc(sizeof(struct if_config_options));
56 memset(io, 0, sizeof(struct if_config_options));
58 io->ipv6_addrtype = 1;
60 if(inet_pton(AF_INET6, OLSR_IPV6_MCAST_SITE_LOCAL, &in6) < 0)
62 fprintf(stderr, "Failed converting IP address %s\n", OLSR_IPV6_MCAST_SITE_LOCAL);
65 memcpy(&io->ipv6_multi_site.v6, &in6, sizeof(struct in6_addr));
67 if(inet_pton(AF_INET6, OLSR_IPV6_MCAST_GLOBAL, &in6) < 0)
69 fprintf(stderr, "Failed converting IP address %s\n", OLSR_IPV6_MCAST_GLOBAL);
72 memcpy(&io->ipv6_multi_glbl.v6, &in6, sizeof(struct in6_addr));
75 io->hello_params.emission_interval = HELLO_INTERVAL;
76 io->hello_params.validity_time = NEIGHB_HOLD_TIME;
77 io->tc_params.emission_interval = TC_INTERVAL;
78 io->tc_params.validity_time = TOP_HOLD_TIME;
79 io->mid_params.emission_interval = MID_INTERVAL;
80 io->mid_params.validity_time = MID_HOLD_TIME;
81 io->hna_params.emission_interval = HNA_INTERVAL;
82 io->hna_params.validity_time = HNA_HOLD_TIME;
104 %token TOK_DEBUGLEVEL
109 %token TOK_INTERFACES
113 %token TOK_WILLINGNESS
120 %token TOK_TCREDUNDANCY
121 %token TOK_MPRCOVERAGE
125 %token TOK_IP4BROADCAST
126 %token TOK_IP6ADDRTYPE
127 %token TOK_IP6MULTISITE
128 %token TOK_IP6MULTIGLOBAL
166 block: TOK_HNA4 hna4body
168 | TOK_INTERFACES ifbody
173 hna4body: TOK_OPEN hna4stmts TOK_CLOSE
176 hna4stmts: | hna4stmts ihna4entry
179 hna6body: TOK_OPEN hna6stmts TOK_CLOSE
182 hna6stmts: | hna6stmts ihna6entry
185 ifbody: TOK_OPEN ifstmts TOK_CLOSE
188 ifstmts: | ifstmts ifstmt
195 isetbody: TOK_OPEN isetstmts TOK_CLOSE
198 isetstmts: | isetstmts isetstmt
216 plbody: TOK_OPEN plstmts TOK_CLOSE
219 plstmts: | plstmts plstmt
230 isetblock: TOK_IFSETUP TOK_STRING
232 struct if_config_options *io = get_default_if_config();
235 fprintf(stderr, "Out of memory(ADD IFRULE)\n");
239 if(PARSER_DEBUG) printf("Interface setup: \"%s\"\n", $2->string);
241 io->name = $2->string;
245 io->next = cnf->if_options;
246 cnf->if_options = io;
253 isetip4br: TOK_IP4BROADCAST TOK_IP4_ADDR
257 if(PARSER_DEBUG) printf("\tIPv4 broadcast: %s\n", $2->string);
259 if(inet_aton($2->string, &in) == 0)
261 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
265 cnf->if_options->ipv4_broadcast.v4 = in.s_addr;
272 isetip6addrt: TOK_IP6ADDRTYPE TOK_IP6TYPE
274 cnf->if_options->ipv6_addrtype = $2->boolean;
280 isetip6mults: TOK_IP6MULTISITE TOK_IP6_ADDR
284 if(PARSER_DEBUG) printf("\tIPv6 site-local multicast: %s\n", $2->string);
286 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
288 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
291 memcpy(&cnf->if_options->ipv6_multi_site.v6, &in6, sizeof(struct in6_addr));
300 isetip6multg: TOK_IP6MULTIGLOBAL TOK_IP6_ADDR
304 if(PARSER_DEBUG) printf("\tIPv6 global multicast: %s\n", $2->string);
306 if(inet_pton(AF_INET6, $2->string, &in6) < 0)
308 fprintf(stderr, "Failed converting IP address %s\n", $2->string);
311 memcpy(&cnf->if_options->ipv6_multi_glbl.v6, &in6, sizeof(struct in6_addr));
318 isethelloint: TOK_HELLOINT TOK_FLOAT
320 if(PARSER_DEBUG) printf("\tHELLO interval: %0.2f\n", $2->floating);
321 cnf->if_options->hello_params.emission_interval = $2->floating;
325 isethelloval: TOK_HELLOVAL TOK_FLOAT
327 if(PARSER_DEBUG) printf("\tHELLO validity: %0.2f\n", $2->floating);
328 cnf->if_options->hello_params.validity_time = $2->floating;
332 isettcint: TOK_TCINT TOK_FLOAT
334 if(PARSER_DEBUG) printf("\tTC interval: %0.2f\n", $2->floating);
335 cnf->if_options->tc_params.emission_interval = $2->floating;
339 isettcval: TOK_TCVAL TOK_FLOAT
341 if(PARSER_DEBUG) printf("\tTC validity: %0.2f\n", $2->floating);
342 cnf->if_options->tc_params.validity_time = $2->floating;
346 isetmidint: TOK_MIDINT TOK_FLOAT
348 if(PARSER_DEBUG) printf("\tMID interval: %0.2f\n", $2->floating);
349 cnf->if_options->mid_params.emission_interval = $2->floating;
353 isetmidval: TOK_MIDVAL TOK_FLOAT
355 if(PARSER_DEBUG) printf("\tMID validity: %0.2f\n", $2->floating);
356 cnf->if_options->mid_params.validity_time = $2->floating;
360 isethnaint: TOK_HNAINT TOK_FLOAT
362 if(PARSER_DEBUG) printf("\tHNA interval: %0.2f\n", $2->floating);
363 cnf->if_options->hna_params.emission_interval = $2->floating;
367 isethnaval: TOK_HNAVAL TOK_FLOAT
369 if(PARSER_DEBUG) printf("\tHNA validity: %0.2f\n", $2->floating);
370 cnf->if_options->hna_params.validity_time = $2->floating;
376 idebug: TOK_DEBUGLEVEL TOK_INTEGER
381 if(PARSER_DEBUG) printf("Debug levl AUTO\n");
385 cnf->debug_level = $2->integer;
386 if(PARSER_DEBUG) printf("Debug level: %d\n", cnf->debug_level);
394 iipversion: TOK_IPVERSION TOK_INTEGER
396 if(($2->integer != 4) && ($2->integer != 6))
398 fprintf(stderr, "IPversion must be 4 or 6!\n");
401 cnf->ip_version = $2->integer;
402 if(PARSER_DEBUG) printf("IpVersion: %d\n", cnf->ip_version);
408 ihna4entry: TOK_IP4_ADDR TOK_IP4_ADDR
410 struct hna4_entry *h = malloc(sizeof(struct hna4_entry));
413 if(PARSER_DEBUG) printf("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
417 fprintf(stderr, "Out of memory(HNA4)\n");
421 if(inet_aton($1->string, &in) == 0)
423 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
427 if(inet_aton($2->string, &in) == 0)
429 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
432 h->netmask = in.s_addr;
434 h->next = cnf->hna4_entries;
435 cnf->hna4_entries = h;
444 ihna6entry: TOK_IP6_ADDR TOK_INTEGER
446 struct hna6_entry *h = malloc(sizeof(struct hna6_entry));
449 if(PARSER_DEBUG) printf("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
453 fprintf(stderr, "Out of memory(HNA6)\n");
457 if(inet_pton(AF_INET6, $1->string, &in6) < 0)
459 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
462 memcpy(&h->net, &in6, sizeof(struct in6_addr));
464 if(($2->integer < 0) || ($2->integer > 128))
466 fprintf(stderr, "Illegal IPv6 prefix length %d\n", $2->integer);
470 h->prefix_len = $2->integer;
472 h->next = cnf->hna6_entries;
473 cnf->hna6_entries = h;
481 ifentry: TOK_STRING TOK_STRING
483 struct olsr_if *in = malloc(sizeof(struct olsr_if));
487 fprintf(stderr, "Out of memory(ADD IF)\n");
491 in->name = $1->string;
492 in->config = $2->string;
494 if(PARSER_DEBUG) printf("Interface: %s Ruleset: %s\n", $1->string, $2->string);
497 in->next = cnf->interfaces;
498 cnf->interfaces = in;
505 bnoint: TOK_NOINT TOK_BOOLEAN
507 if(PARSER_DEBUG) printf("Noint set to %d\n", $2->boolean);
512 atos: TOK_TOS TOK_INTEGER
516 if(PARSER_DEBUG) printf("Tos AUTO\n");
520 if(PARSER_DEBUG) printf("TOS: %d\n", $2->integer);
527 awillingness: TOK_WILLINGNESS TOK_INTEGER
531 if(PARSER_DEBUG) printf("Willingness AUTO\n");
535 if(PARSER_DEBUG) printf("Willingness: %d\n", $2->integer);
542 bipccon: TOK_IPCCON TOK_BOOLEAN
546 if(PARSER_DEBUG) printf("IPC allowed\n");
550 if(PARSER_DEBUG) printf("IPC blocked\n");
558 busehyst: TOK_USEHYST TOK_BOOLEAN
562 if(PARSER_DEBUG) printf("Hysteresis enabled\n");
566 if(PARSER_DEBUG) printf("Hysteresis disabled\n");
574 fhystscale: TOK_HYSTSCALE TOK_FLOAT
576 cnf->hysteresis_param.scaling = $2->floating;
577 if(PARSER_DEBUG) printf("Hysteresis Scaling: %0.2f\n", $2->floating);
583 fhystupper: TOK_HYSTUPPER TOK_FLOAT
585 cnf->hysteresis_param.thr_high = $2->floating;
586 if(PARSER_DEBUG) printf("Hysteresis UpperThr: %0.2f\n", $2->floating);
592 fhystlower: TOK_HYSTLOWER TOK_FLOAT
594 cnf->hysteresis_param.thr_low = $2->floating;
595 if(PARSER_DEBUG) printf("Hysteresis LowerThr: %0.2f\n", $2->floating);
600 fpollrate: TOK_POLLRATE TOK_FLOAT
602 if(PARSER_DEBUG) printf("Pollrate %0.2f\n", $2->floating);
603 cnf->pollrate = $2->floating;
610 atcredundancy: TOK_TCREDUNDANCY TOK_INTEGER
614 if(PARSER_DEBUG) printf("TC redundancy AUTO\n");
618 if(PARSER_DEBUG) printf("TC redundancy %d\n", $2->integer);
619 cnf->tc_redundancy = $2->integer;
626 amprcoverage: TOK_MPRCOVERAGE TOK_INTEGER
630 if(PARSER_DEBUG) printf("MPR coverage AUTO\n");
634 if(PARSER_DEBUG) printf("MPR coverage %d\n", $2->integer);
635 cnf->mpr_coverage = $2->integer;
642 plname: TOK_PLNAME TOK_STRING
644 struct plugin_entry *pe = malloc(sizeof(struct plugin_entry));
648 fprintf(stderr, "Out of memory(ADD PL)\n");
652 pe->name = $2->string;
654 if(PARSER_DEBUG) printf("Plugin: %s\n", $2->string);
657 pe->next = cnf->plugins;
664 plparam: TOK_PLPARAM TOK_STRING TOK_STRING
667 if(PARSER_DEBUG) printf("Plugin param key:\"%s\" val: \"%s\"\n", $2->string, $3->string);
676 vcomment: TOK_COMMENT
678 //if(PARSER_DEBUG) printf("Comment\n");
686 void yyerror (char *string)
688 fprintf(stderr, "Config line %d: %s\n", current_line, string);