Reinstate help text to BW Limiter page
[tomato.git] / release / src / router / dhcpv6 / cftoken.l
blob675b710939bde12eccaa3c561c987d115b0e8780
1 /*      $KAME: cftoken.l,v 1.35 2005/01/12 06:06:11 suz Exp $   */
3 %option noyywrap
4 %{
5 /*
6  * Copyright (C) 2002 WIDE Project.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the project nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/socket.h>
36 #include <sys/queue.h>
37 #include <sys/time.h>
39 #include <netinet/in.h>
41 #include <errno.h>
42 #include <syslog.h>
43 #include <string.h>
44 #ifdef HAVE_STDARG_H
45 #include <stdarg.h>
46 #else
47 #include <varargs.h>
48 #endif
50 #include "dhcp6.h"
51 #include "config.h"
52 #include "common.h"
53 #include "y.tab.h"
55 #define YY_NO_UNPUT 1
57 char *configfilename;
58 int lineno = 1;
61 /* Recursion limit for includes */
62 #define MAX_INCLUDE_DEPTH 10
64 static struct include_stack {
65         char *path;
66         YY_BUFFER_STATE state;
67         int lineno;
68 } incstack[MAX_INCLUDE_DEPTH];
69 int incstackp = 0;
72 static int yy_first_time = 1;
73 static int yyerrorcount = 0;
75 #ifndef NOCONFIG_DEBUG
76 #define YYDEBUG 1
78 int cfdebug = 1;
79 #else
80 int cfdebug = 0;
81 #endif
83 extern int yyparse __P((void));
84 extern int cf_post_config __P((void));
86 static void cfdebug_print __P((char *, char *, int));
88 #define DP(str) if (cfdebug) cfdebug_print(str, yytext, yyleng)
89 #define DECHO if (cfdebug) cfdebug_print(NULL, yytext, yyleng);
90 #define DNOECHO if (cfdebug) cfdebug_print(NULL, "****", yyleng);
93 /* abbreviations */
94 nl              \n
95 ws              [ \t]+
96 comma           ,
97 comment         \#.*
98 semi            \;
99 quotedstring    \"[^\"]*\"
100 string          [a-zA-Z0-9:\._\-][a-zA-Z0-9:\._\-]*
101 digit           [0-9]
102 integer         {digit}+
103 number          {integer}|({digit}*\.{integer})
104 hexdigit        [0-9A-Fa-f]
105 hexpair         {hexdigit}{hexdigit}
106 hexstring       0[xX]{hexpair}+
107 duid            {hexpair}(:{hexpair})*
108 ifname          {string}
109 slash           \/
110 bcl             \{
111 ecl             \}
113 %s S_CNF
114 %s S_IFACE
115 %s S_PREF
116 %s S_HOST
117 %s S_DUID
118 %s S_IA
119 %s S_AUTH
120 %s S_KEY
121 %s S_SECRET
122 %s S_ADDRPOOL
123 %s S_INCL
127         if (yy_first_time) {
128                 BEGIN S_CNF;
129                 yy_first_time = 0;
130         }
132         /* interface configuration */
133 <S_CNF>interface { DECHO; BEGIN S_IFACE; return (INTERFACE); }
134 <S_IFACE>{ifname} {
135         DECHO;
136         yylval.str = strdup(yytext);
137         BEGIN S_CNF;
138         return (IFNAME);
141         /* host configuration */
142 <S_CNF>host { DECHO; BEGIN S_HOST; return (HOST); }
143 <S_HOST>{string} {
144         DECHO;
145         yylval.str = strdup(yytext);
146         BEGIN S_CNF;
147         return (HOSTNAME);
150         /* address pool configuration */
151 <S_CNF>pool { DECHO; BEGIN S_ADDRPOOL; return (ADDRPOOL); }  
153 <S_ADDRPOOL>{string} {
154         DECHO;
155         yylval.str = strdup(yytext);
156         BEGIN S_CNF;
157         return (POOLNAME);
160 <S_CNF>duid { DECHO; BEGIN S_DUID; return (DUID); }
161 <S_DUID>{duid} {
162         DECHO;
163         yylval.str = strdup(yytext);
164         BEGIN S_CNF;
165         return (DUID_ID);
168 <S_CNF>address { DECHO; return (ADDRESS); }
170 <S_CNF>prefix { DECHO; return (PREFIX); }
172 <S_CNF>preference { DECHO; return (PREFERENCE); }
174 <S_CNF>script { DECHO; return (SCRIPT); }
176 <S_CNF>delayedkey { DECHO; return (DELAYEDKEY); }
178         /* request */
179 <S_CNF>request { DECHO; return (REQUEST); }
181         /* send */
182 <S_CNF>send { DECHO; return (SEND); }
184         /* range */
185 <S_CNF>range { DECHO; return (RANGE); }
186 <S_CNF>to { DECHO; return (TO); }
188         /* address-pool */
189 <S_CNF>address-pool { DECHO; return (ADDRESS_POOL); }
191         /* DHCP options */
192 <S_CNF>option { DECHO; return (OPTION); }
194 <S_CNF>rapid-commit { DECHO; return (RAPID_COMMIT); }
195 <S_CNF>ia-pd { DECHO; return (IA_PD); }
196 <S_CNF>ia-na { DECHO; return (IA_NA); }
197 <S_CNF>domain-name-servers { DECHO; return (DNS_SERVERS); }
198 <S_CNF>domain-name { DECHO; return (DNS_NAME); }
199 <S_CNF>sip-server-address { DECHO; return (SIP_SERVERS); }
200 <S_CNF>sip-server-domain-name { DECHO; return (SIP_NAME); }
201 <S_CNF>ntp-servers { DECHO; return (NTP_SERVERS); }
202 <S_CNF>nis-server-address { DECHO; return (NIS_SERVERS); }
203 <S_CNF>nis-domain-name { DECHO; return (NIS_NAME); }
204 <S_CNF>nisp-server-address { DECHO; return (NISP_SERVERS); }
205 <S_CNF>nisp-domain-name { DECHO; return (NISP_NAME); }
206 <S_CNF>bcmcs-server-address { DECHO; return (BCMCS_SERVERS); }
207 <S_CNF>bcmcs-server-domain-name { DECHO; return (BCMCS_NAME); }
208 <S_CNF>refreshtime { DECHO; return (REFRESHTIME); }
210         /* provided for a backward compatibility to WIDE-DHCPv6 before Oct 1 2006 */
211 <S_CNF>nis-server-domain-name { DECHO; return (NIS_NAME); }
212 <S_CNF>nisp-server-domain-name { DECHO; return (NISP_NAME); }   
214         /* generic options */
215 <S_CNF>information-only { DECHO; return (INFO_ONLY); }
217 <S_CNF>allow { DECHO; return (ALLOW); }
219         /* identity association */
220 <S_CNF>id-assoc { DECHO; BEGIN S_IA; return(ID_ASSOC); }
221 <S_IA>pd { DECHO; return(IA_PD); }
222 <S_IA>na { DECHO; return(IA_NA); }
223 <S_IA>{number} { DECHO; yylval.str = strdup(yytext); return(IAID); }
224 <S_IA>{bcl} { DP("begin of closure"); BEGIN S_CNF; return (BCL); }
226         /*
227          * interface parameters for delegated prefix configuration.
228          * when lex reads an interface name, the state will be back to
229          * S_CNF.
230          */
231 <S_CNF>prefix-interface { DECHO; BEGIN S_IFACE; return (PREFIX_INTERFACE); }
232 <S_CNF>sla-id { DECHO; return (SLA_ID); }
233 <S_CNF>sla-len { DECHO; return (SLA_LEN); }
235         /* duration */
236 <S_CNF>infinity { DECHO; return (INFINITY); }
238         /* authentication option */
239 <S_CNF>authentication { DECHO; BEGIN S_AUTH; return (AUTHENTICATION); }
240 <S_AUTH>{string} {
241         DECHO;
242         yylval.str = strdup(yytext);
243         BEGIN S_CNF;
244         return (AUTHNAME);
247         /* authentication parameters */
248 <S_CNF>protocol { DECHO; return (PROTOCOL); };
249 <S_CNF>algorithm { DECHO; return (ALGORITHM); };
250 <S_CNF>rdm { DECHO; return (RDM); };
251 <S_CNF>key { DECHO; return (KEY); };
253         /* authentication protocols */
254 <S_CNF>delayed { DECHO; return (DELAYED); };
255 <S_CNF>reconfig { DECHO; return (RECONFIG); };
257         /* authentication algorithms */
258 <S_CNF>hmac-md5 { DECHO; return (HMACMD5); };
259 <S_CNF>HMAC-MD5 { DECHO; return (HMACMD5); };
260 <S_CNF>hmacmd5 { DECHO; return (HMACMD5); };
261 <S_CNF>HMACMD5 { DECHO; return (HMACMD5); };
263         /* authentication RDM */
264 <S_CNF>monocounter { DECHO; return (MONOCOUNTER); };
266         /* secret keys */
267 <S_CNF>keyinfo { DECHO; BEGIN S_KEY; return (KEYINFO); }
268 <S_KEY>{string} {
269         DECHO;
270         yylval.str = strdup(yytext);
271         BEGIN S_CNF;
272         return (KEYNAME);
275         /* key parameters */
276 <S_CNF>realm { DECHO; return (REALM); }
277 <S_CNF>keyid { DECHO; return (KEYID); }
278 <S_CNF>secret { DECHO; BEGIN S_SECRET; return (SECRET); }
279 <S_SECRET>{quotedstring} {
280         DNOECHO;
281         yylval.str = strdup(yytext);
282         BEGIN S_CNF;
283         return (QSTRING);
285 <S_CNF>expire { DECHO; return (EXPIRE); }
287         /* include */
288 <S_CNF>include { DECHO; BEGIN S_INCL; return (INCLUDE); }
289 <S_INCL>{quotedstring} {
290         DECHO;
291         yylval.str = strdup(yytext);
292         BEGIN S_CNF;
293         return (QSTRING);
296         /* quoted string */
297 {quotedstring} {
298                 DECHO;
299                 yylval.str = strdup(yytext);
300                 return (QSTRING);
301         }
303         /* misc */
304 {ws}            { ; }
305 {nl}            { lineno++; }
306 {comment}       { DP("comment"); }
307 {number}        {
308         DECHO;
309         yylval.num = strtoll(yytext, NULL, 10);
310         return (NUMBER);
312 {slash} { DECHO; return (SLASH); }
313 {comma} { DECHO; return (COMMA); }
314 {semi} { DP("end of sentence"); return (EOS); }
315 {bcl} { DP("begin of closure"); return (BCL); }
316 {ecl} { DP("end of closure"); return (ECL); }
318         /* generic string */
319 {string} {
320                 DECHO;
321                 yylval.str = strdup(yytext);
322                 return (STRING);
323         }
325 <<EOF>> {
326                 if (--incstackp < 0)
327                         yyterminate();
328                 else {
329                         yy_delete_buffer(YY_CURRENT_BUFFER);
330                         free(incstack[incstackp + 1].path);
331                         configfilename = incstack[incstackp].path;
332                         lineno = incstack[incstackp].lineno;
333                         yy_switch_to_buffer(incstack[incstackp].state);
334                 }
335         }
338 static void
339 cfdebug_print(w, t, l)
340         char *w, *t;
341         int l;
343         if (w) {
344                 dprintf(LOG_DEBUG, FNAME,
345                     "<%d>%s [%s] (%d)", yy_start, w, t, l);
346         } else {
347                 dprintf(LOG_DEBUG, FNAME,
348                     "<%d>[%s] (%d)", yy_start, t, l);
349         }
352 static void
353 yyerror0(int level, char *s, va_list ap)
355         char ebuf[BUFSIZ], *bp, *ep;
357         bp = ebuf;
358         ep = ebuf + sizeof(ebuf);
359         bp += snprintf(bp, ep - bp, "%s %d: ", configfilename, lineno);
360         if (bp < ep)
361                 bp += vsnprintf(bp, ep - bp, s, ap);
363         dprintf(level, FNAME, ebuf);
366 void
367 yyerror(char *s, ...)
369         va_list ap;
370 #ifdef HAVE_STDARG_H
371         va_start(ap, s);
372 #else
373         va_start(ap);
374 #endif
375         yyerror0(LOG_ERR, s, ap);
376         va_end(ap);
377         yyerrorcount++;
380 void
381 yywarn(char *s, ...)
383         va_list ap;
384 #ifdef HAVE_STDARG_H
385         va_start(ap, s);
386 #else
387         va_start(ap);
388 #endif
389         yyerror0(LOG_WARNING, s, ap);
390         va_end(ap);
394 cfswitch_buffer(incl)
395         char *incl;
397         char *path = qstrdup(incl);
398         FILE *fp;
400         if (incstackp >= MAX_INCLUDE_DEPTH) {
401                 dprintf(LOG_ERR, FNAME, "cfparse: includes nested too deeply");
402                 return (-1);
403         }
404         incstack[incstackp].path = configfilename;
405         incstack[incstackp].state = YY_CURRENT_BUFFER;
406         incstack[incstackp].lineno = lineno;
408         fp = fopen(path, "r");
409         if (fp == NULL) {
410                 dprintf(LOG_ERR, FNAME, "cfparse: fopen(%s): %s",
411                         path, strerror(errno));
412                 if (errno == ENOENT)
413                         return (0);
414                 return (-1);
415         }
416         incstackp++;
417         configfilename = path;
418         lineno = 1;
419         yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
421         BEGIN(S_CNF);
423         return (0);
427 cfparse(conf)
428         char *conf;
430         configfilename = conf;
431         if ((yyin = fopen(configfilename, "r")) == NULL) {
432                 dprintf(LOG_ERR, FNAME, "cfparse: fopen(%s): %s",
433                         configfilename, strerror(errno));
434                 if (errno == ENOENT)
435                         return (0);
436                 return (-1);
437         }
439         if (yyparse() || yyerrorcount) {
440                 if (yyerrorcount) {
441                         yyerror("fatal parse failure: exiting (%d errors)",
442                                 yyerrorcount);
443                 } else
444                         yyerror("fatal parse failure: exiting");
445                 return (-1);
446         }
448         return (cf_post_config());