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.18 2004/11/20 21:42:35 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 cnf->interfaces->cnf->hello_params.emission_interval = $2->floating;
350 isethelloval: TOK_HELLOVAL TOK_FLOAT
352 if(PARSER_DEBUG) printf("\tHELLO validity: %0.2f\n", $2->floating);
353 cnf->interfaces->cnf->hello_params.validity_time = $2->floating;
357 isettcint: TOK_TCINT TOK_FLOAT
359 if(PARSER_DEBUG) printf("\tTC interval: %0.2f\n", $2->floating);
360 cnf->interfaces->cnf->tc_params.emission_interval = $2->floating;
364 isettcval: TOK_TCVAL TOK_FLOAT
366 if(PARSER_DEBUG) printf("\tTC validity: %0.2f\n", $2->floating);
367 cnf->interfaces->cnf->tc_params.validity_time = $2->floating;
371 isetmidint: TOK_MIDINT TOK_FLOAT
373 if(PARSER_DEBUG) printf("\tMID interval: %0.2f\n", $2->floating);
374 cnf->interfaces->cnf->mid_params.emission_interval = $2->floating;
378 isetmidval: TOK_MIDVAL TOK_FLOAT
380 if(PARSER_DEBUG) printf("\tMID validity: %0.2f\n", $2->floating);
381 cnf->interfaces->cnf->mid_params.validity_time = $2->floating;
385 isethnaint: TOK_HNAINT TOK_FLOAT
387 if(PARSER_DEBUG) printf("\tHNA interval: %0.2f\n", $2->floating);
388 cnf->interfaces->cnf->hna_params.emission_interval = $2->floating;
392 isethnaval: TOK_HNAVAL TOK_FLOAT
394 if(PARSER_DEBUG) printf("\tHNA validity: %0.2f\n", $2->floating);
395 cnf->interfaces->cnf->hna_params.validity_time = $2->floating;
401 idebug: TOK_DEBUGLEVEL TOK_INTEGER
404 cnf->debug_level = $2->integer;
405 if(PARSER_DEBUG) printf("Debug level: %d\n", cnf->debug_level);
411 iipversion: TOK_IPVERSION TOK_INTEGER
414 cnf->ip_version = AF_INET;
415 else if($2->integer == 6)
416 cnf->ip_version = AF_INET6;
419 fprintf(stderr, "IPversion must be 4 or 6!\n");
423 if(PARSER_DEBUG) printf("IpVersion: %d\n", $2->integer);
429 ihna4entry: TOK_IP4_ADDR TOK_IP4_ADDR
431 struct hna4_entry *h = malloc(sizeof(struct hna4_entry));
434 if(PARSER_DEBUG) printf("HNA IPv4 entry: %s/%s\n", $1->string, $2->string);
438 fprintf(stderr, "Out of memory(HNA4)\n");
442 if(inet_aton($1->string, &in) == 0)
444 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
447 h->net.v4 = in.s_addr;
448 if(inet_aton($2->string, &in) == 0)
450 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
453 h->netmask.v4 = in.s_addr;
455 h->next = cnf->hna4_entries;
456 cnf->hna4_entries = h;
465 ihna6entry: TOK_IP6_ADDR TOK_INTEGER
467 struct hna6_entry *h = malloc(sizeof(struct hna6_entry));
470 if(PARSER_DEBUG) printf("HNA IPv6 entry: %s/%d\n", $1->string, $2->integer);
474 fprintf(stderr, "Out of memory(HNA6)\n");
478 if(inet_pton(AF_INET6, $1->string, &in6) < 0)
480 fprintf(stderr, "Failed converting IP address %s\n", $1->string);
483 memcpy(&h->net, &in6, sizeof(struct in6_addr));
485 if(($2->integer < 0) || ($2->integer > 128))
487 fprintf(stderr, "Illegal IPv6 prefix length %d\n", $2->integer);
491 h->prefix_len = $2->integer;
493 h->next = cnf->hna6_entries;
494 cnf->hna6_entries = h;
502 ifblock: TOK_INTERFACE TOK_STRING
504 struct olsr_if *in = malloc(sizeof(struct olsr_if));
508 fprintf(stderr, "Out of memory(ADD IF)\n");
512 in->cnf = get_default_if_config();
516 fprintf(stderr, "Out of memory(ADD IFRULE)\n");
520 in->name = $2->string;
523 in->next = cnf->interfaces;
524 cnf->interfaces = in;
529 bnoint: TOK_NOINT TOK_BOOLEAN
531 if(PARSER_DEBUG) printf("Noint set to %d\n", $2->boolean);
533 cnf->allow_no_interfaces = $2->boolean;
539 atos: TOK_TOS TOK_INTEGER
541 if(PARSER_DEBUG) printf("TOS: %d\n", $2->integer);
542 cnf->tos = $2->integer;
549 awillingness: TOK_WILLINGNESS TOK_INTEGER
551 cnf->willingness_auto = OLSR_FALSE;
553 if(PARSER_DEBUG) printf("Willingness: %d\n", $2->integer);
554 cnf->willingness = $2->integer;
563 busehyst: TOK_USEHYST TOK_BOOLEAN
565 cnf->use_hysteresis = $2->boolean;
566 if(cnf->use_hysteresis)
568 if(PARSER_DEBUG) printf("Hysteresis enabled\n");
572 if(PARSER_DEBUG) printf("Hysteresis disabled\n");
580 fhystscale: TOK_HYSTSCALE TOK_FLOAT
582 cnf->hysteresis_param.scaling = $2->floating;
583 if(PARSER_DEBUG) printf("Hysteresis Scaling: %0.2f\n", $2->floating);
589 fhystupper: TOK_HYSTUPPER TOK_FLOAT
591 cnf->hysteresis_param.thr_high = $2->floating;
592 if(PARSER_DEBUG) printf("Hysteresis UpperThr: %0.2f\n", $2->floating);
598 fhystlower: TOK_HYSTLOWER TOK_FLOAT
600 cnf->hysteresis_param.thr_low = $2->floating;
601 if(PARSER_DEBUG) printf("Hysteresis LowerThr: %0.2f\n", $2->floating);
606 fpollrate: TOK_POLLRATE TOK_FLOAT
608 if(PARSER_DEBUG) printf("Pollrate %0.2f\n", $2->floating);
609 cnf->pollrate = $2->floating;
616 atcredundancy: TOK_TCREDUNDANCY TOK_INTEGER
618 if(PARSER_DEBUG) printf("TC redundancy %d\n", $2->integer);
619 cnf->tc_redundancy = $2->integer;
624 amprcoverage: TOK_MPRCOVERAGE TOK_INTEGER
626 if(PARSER_DEBUG) printf("MPR coverage %d\n", $2->integer);
627 cnf->mpr_coverage = $2->integer;
632 alq_level: TOK_LQ_LEVEL TOK_INTEGER
634 if(PARSER_DEBUG) printf("Link quality level %d\n", $2->integer);
635 cnf->lq_level = $2->integer;
640 alq_wsize: TOK_LQ_WSIZE TOK_INTEGER
642 if(PARSER_DEBUG) printf("Link quality window size %d\n", $2->integer);
643 cnf->lq_wsize = $2->integer;
648 bclear_screen: TOK_CLEAR_SCREEN TOK_BOOLEAN
650 cnf->clear_screen = $2->boolean;
653 printf("Clear screen %s\n", cnf->clear_screen ? "enabled" : "disabled");
659 plblock: TOK_PLUGIN TOK_STRING
661 struct plugin_entry *pe = malloc(sizeof(struct plugin_entry));
665 fprintf(stderr, "Out of memory(ADD PL)\n");
669 pe->name = $2->string;
673 if(PARSER_DEBUG) printf("Plugin: %s\n", $2->string);
676 pe->next = cnf->plugins;
683 plparam: TOK_PLPARAM TOK_STRING TOK_STRING
685 struct plugin_param *pp = malloc(sizeof(struct plugin_param));
689 fprintf(stderr, "Out of memory(ADD PP)\n");
693 if(PARSER_DEBUG) printf("Plugin param key:\"%s\" val: \"%s\"\n", $2->string, $3->string);
695 pp->key = $2->string;
696 pp->value = $3->string;
699 pp->next = cnf->plugins->params;
700 cnf->plugins->params = pp;
707 vcomment: TOK_COMMENT
709 //if(PARSER_DEBUG) printf("Comment\n");
717 void yyerror (char *string)
719 fprintf(stderr, "Config line %d: %s\n", current_line, string);