1 /* $KAME: cftoken.l,v 1.35 2005/01/12 06:06:11 suz Exp $ */
6 * Copyright (C) 2002 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/socket.h>
36 #include <sys/queue.h>
39 #include <netinet/in.h>
61 /* Recursion limit for includes */
62 #define MAX_INCLUDE_DEPTH 10
64 static struct include_stack {
66 YY_BUFFER_STATE state;
68 } incstack[MAX_INCLUDE_DEPTH];
72 static int yy_first_time = 1;
73 static int yyerrorcount = 0;
75 #ifndef NOCONFIG_DEBUG
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);
99 quotedstring \"[^\"]*\"
100 string [a-zA-Z0-9:\._\-][a-zA-Z0-9:\._\-]*
103 number {integer}|({digit}*\.{integer})
105 hexpair {hexdigit}{hexdigit}
106 hexstring 0[xX]{hexpair}+
107 duid {hexpair}(:{hexpair})*
132 /* interface configuration */
133 <S_CNF>interface { DECHO; BEGIN S_IFACE; return (INTERFACE); }
136 yylval.str = strdup(yytext);
141 /* host configuration */
142 <S_CNF>host { DECHO; BEGIN S_HOST; return (HOST); }
145 yylval.str = strdup(yytext);
150 /* address pool configuration */
151 <S_CNF>pool { DECHO; BEGIN S_ADDRPOOL; return (ADDRPOOL); }
153 <S_ADDRPOOL>{string} {
155 yylval.str = strdup(yytext);
160 <S_CNF>duid { DECHO; BEGIN S_DUID; return (DUID); }
163 yylval.str = strdup(yytext);
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); }
179 <S_CNF>request { DECHO; return (REQUEST); }
182 <S_CNF>send { DECHO; return (SEND); }
185 <S_CNF>range { DECHO; return (RANGE); }
186 <S_CNF>to { DECHO; return (TO); }
189 <S_CNF>address-pool { DECHO; return (ADDRESS_POOL); }
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); }
227 * interface parameters for delegated prefix configuration.
228 * when lex reads an interface name, the state will be back to
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); }
236 <S_CNF>infinity { DECHO; return (INFINITY); }
238 /* authentication option */
239 <S_CNF>authentication { DECHO; BEGIN S_AUTH; return (AUTHENTICATION); }
242 yylval.str = strdup(yytext);
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); };
267 <S_CNF>keyinfo { DECHO; BEGIN S_KEY; return (KEYINFO); }
270 yylval.str = strdup(yytext);
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} {
281 yylval.str = strdup(yytext);
285 <S_CNF>expire { DECHO; return (EXPIRE); }
288 <S_CNF>include { DECHO; BEGIN S_INCL; return (INCLUDE); }
289 <S_INCL>{quotedstring} {
291 yylval.str = strdup(yytext);
299 yylval.str = strdup(yytext);
306 {comment} { DP("comment"); }
309 yylval.num = strtoll(yytext, NULL, 10);
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); }
321 yylval.str = strdup(yytext);
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);
339 cfdebug_print(w, t, l)
344 dprintf(LOG_DEBUG, FNAME,
345 "<%d>%s [%s] (%d)", yy_start, w, t, l);
347 dprintf(LOG_DEBUG, FNAME,
348 "<%d>[%s] (%d)", yy_start, t, l);
353 yyerror0(int level, char *s, va_list ap)
355 char ebuf[BUFSIZ], *bp, *ep;
358 ep = ebuf + sizeof(ebuf);
359 bp += snprintf(bp, ep - bp, "%s %d: ", configfilename, lineno);
361 bp += vsnprintf(bp, ep - bp, s, ap);
363 dprintf(level, FNAME, ebuf);
367 yyerror(char *s, ...)
375 yyerror0(LOG_ERR, s, ap);
389 yyerror0(LOG_WARNING, s, ap);
394 cfswitch_buffer(incl)
397 char *path = qstrdup(incl);
400 if (incstackp >= MAX_INCLUDE_DEPTH) {
401 dprintf(LOG_ERR, FNAME, "cfparse: includes nested too deeply");
404 incstack[incstackp].path = configfilename;
405 incstack[incstackp].state = YY_CURRENT_BUFFER;
406 incstack[incstackp].lineno = lineno;
408 fp = fopen(path, "r");
410 dprintf(LOG_ERR, FNAME, "cfparse: fopen(%s): %s",
411 path, strerror(errno));
417 configfilename = path;
419 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
430 configfilename = conf;
431 if ((yyin = fopen(configfilename, "r")) == NULL) {
432 dprintf(LOG_ERR, FNAME, "cfparse: fopen(%s): %s",
433 configfilename, strerror(errno));
439 if (yyparse() || yyerrorcount) {
441 yyerror("fatal parse failure: exiting (%d errors)",
444 yyerror("fatal parse failure: exiting");
448 return (cf_post_config());