4 * The olsr.org Optimized Link-State Routing daemon(olsrd)
5 * Copyright (c) 2004, Andreas Tonnesen(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.
44 #define YYSTYPE struct conf_token *
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
54 #include "olsrd_conf.h"
58 #define ECHO if(fwrite( yytext, yyleng, 1, yyout )) {}
61 int yyget_lineno(void);
62 FILE * yyget_in(void);
63 FILE* yyget_out(void);
64 char *yyget_text(void);
65 void yyset_lineno(int);
66 void yyset_in(FILE *);
67 void yyset_out(FILE *);
68 int yyget_debug(void);
69 void yyset_debug(int);
70 int yylex_destroy(void);
73 static struct conf_token *get_conf_token(void);
74 static struct conf_token *get_string_token(const char * const s, const size_t n);
75 static struct conf_token *get_integer_token(const char * const s);
76 static struct conf_token *get_floating_token(const char * const s);
77 static struct conf_token *get_boolean_token(const bool b);
79 static struct conf_token *get_conf_token(void)
81 struct conf_token *t = calloc(1, sizeof(struct conf_token));
83 fprintf(stderr, "Cannot allocate %d bytes for an configuration token.\n", (int)sizeof(struct conf_token));
88 static struct conf_token *get_string_token(const char * const s, const size_t n)
90 struct conf_token *rv = get_conf_token();
92 rv->string = malloc(n + 1);
93 if (rv->string == NULL) {
94 fprintf(stderr, "Cannot allocate %lu bytes for string token data.\n", (unsigned long)(n+1)); /* size_t on 64bit */
98 memcpy(rv->string, s, n);
104 static struct conf_token *get_integer_token(const char * const s)
106 struct conf_token *rv = get_conf_token();
108 rv->integer = strtol(s, NULL, 0);
113 static struct conf_token *get_floating_token(const char * const s)
115 struct conf_token *rv = get_conf_token();
118 sscanf(s, "%f", &rv->floating);
123 static struct conf_token *get_boolean_token(const bool b)
125 struct conf_token *rv = get_conf_token();
134 %option never-interactive
135 %option noalways-interactive
141 FLOAT {DECDIGIT}+\.{DECDIGIT}+
145 IPV4ADDR {QUAD}\.{QUAD}\.{QUAD}\.{QUAD}
149 IPV6PAT2 ({HEX16}:){1}:({HEX16}:){0,5}{HEX16}
150 IPV6PAT3 ({HEX16}:){2}:({HEX16}:){0,4}{HEX16}
151 IPV6PAT4 ({HEX16}:){3}:({HEX16}:){0,3}{HEX16}
152 IPV6PAT5 ({HEX16}:){4}:({HEX16}:){0,2}{HEX16}
153 IPV6PAT6 ({HEX16}:){5}:({HEX16}:){0,1}{HEX16}
154 IPV6PAT7 ({HEX16}:){6}:({HEX16})
155 IPV6PAT1 ({HEX16}:){7}{HEX16}
156 IPV6PAT8 ({HEX16}:){1,7}:
159 IPV6ADDR {IPV6PAT1}|{IPV6PAT2}|{IPV6PAT3}|{IPV6PAT4}|{IPV6PAT5}|{IPV6PAT6}|{IPV6PAT7}|{IPV6PAT8}|{IPV6PAT9}
184 yylval = get_string_token(yytext + 1, yyleng - 2);
185 if (yylval == NULL) {
192 yylval = get_integer_token(yytext);
197 yylval = get_floating_token(yytext);
202 yylval = get_string_token(yytext, yyleng + 1);
203 if (yylval == NULL) {
206 return TOK_IPV4_ADDR;
209 yylval = get_string_token(yytext, yyleng + 1);
210 if (yylval == NULL) {
213 return TOK_IPV6_ADDR;
222 yylval = get_integer_token(yytext);
228 yylval = get_boolean_token(true);
233 yylval = get_boolean_token(false);
239 return TOK_HOSTLABEL;
254 return TOK_DEBUGLEVEL;
259 return TOK_IPVERSION;
264 return TOK_NICCHGSPOLLRT;
289 return TOK_INTERFACE;
291 "InterfaceDefaults" {
293 return TOK_INTERFACE_DEFAULTS;
329 return TOK_RTTABLE_DEFAULT;
334 return TOK_RTTABLE_TUNNEL;
339 return TOK_RTTABLE_PRIORITY;
342 "RtTableDefaultOlsrPriority" {
344 return TOK_RTTABLE_DEFAULTOLSR_PRIORITY;
347 "RtTableTunnelPriority" {
349 return TOK_RTTABLE_TUNNEL_PRIORITY;
352 "RtTableDefaultPriority" {
354 return TOK_RTTABLE_DEFAULT_PRIORITY;
359 return TOK_WILLINGNESS;
369 return TOK_FIBMETRIC;
379 return TOK_HYSTSCALE;
384 return TOK_HYSTUPPER;
389 return TOK_HYSTLOWER;
400 return TOK_TCREDUNDANCY;
405 return TOK_MPRCOVERAGE;
413 "LinkQualityFishEye" {
423 "LinkQualityAlgorithm" {
425 return TOK_LQ_PLUGIN;
430 return TOK_LQ_NAT_THRESH;
440 return TOK_MIN_TC_VTIME;
445 return TOK_LOCK_FILE;
450 return TOK_CLEAR_SCREEN;
463 "SmartGatewayAllowNAT" {
465 return TOK_SMART_GW_ALLOW_NAT;
468 "SmartGatewayUplink" {
470 return TOK_SMART_GW_UPLINK;
473 "SmartGatewayUplinkNAT" {
475 return TOK_SMART_GW_UPLINK_NAT;
478 "SmartGatewaySpeed" {
480 return TOK_SMART_GW_SPEED;
483 "SmartGatewayPrefix" {
485 return TOK_SMART_GW_PREFIX;
490 return TOK_SRC_IP_ROUTES;
502 return TOK_IPV4BROADCAST;
506 return TOK_IPV4MULTICAST;
514 return TOK_IPV6MULTICAST;
528 "HelloValidityTime" {
556 "AutoDetectChanges" {
558 return TOK_AUTODETCHG;
570 //fprintf(stderr, "Failed to parse line %d of configuration file.\n",
573 //yy_fatal_error("Parsing failed.\n");
575 /* To avoid compiler warning (stupid...) */