Ansify some function definitions that were previously overlooked.
[dragonfly.git] / usr.sbin / setkey / token.l
CommitLineData
984263bc
MD
1/* $FreeBSD: src/usr.sbin/setkey/token.l,v 1.2.2.3 2001/07/03 11:02:17 ume Exp $ */
2/* $KAME: token.l,v 1.21 2001/05/18 05:35:01 sakane Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33%{
34#include <sys/types.h>
35#include <sys/param.h>
36#include <sys/socket.h>
37#include <net/route.h>
38#include <net/pfkeyv2.h>
39#include <netkey/keydb.h>
40#include <netkey/key_debug.h>
41#include <netinet/in.h>
42#include <netinet6/ipsec.h>
43
44#include <stdlib.h>
45#include <limits.h>
46#include <string.h>
47#include <unistd.h>
48#include <errno.h>
49#include "vchar.h"
50#ifdef __NetBSD__
51#include "parse.h"
52#else
53#include "y.tab.h"
54#endif
55
56#define DECHO \
57 if (f_debug) {printf("<%d>", yy_start); ECHO ; printf("\n"); }
58
59#define CMDARG \
60{ \
61 char *__buf__ = strdup(yytext), *__p__; \
3641b7ca 62 for (__p__ = __buf__; *__p__ != 0; __p__++) \
984263bc
MD
63 if (*__p__ == '\n' || *__p__ == '\t') \
64 *__p__ = ' '; \
65 strcat(cmdarg, __buf__); \
66 free(__buf__); \
67}
68
69#define PREPROC DECHO CMDARG
70
74c418a6
SW
71#define YY_NO_INPUT
72
984263bc
MD
73int lineno = 1;
74char cmdarg[8192]; /* XXX: BUFSIZ is the better ? */
75
76extern u_char m_buf[BUFSIZ];
77extern u_int m_len;
78extern int f_debug;
79
2d8a3be7
EN
80int yylex(void);
81void yyfatal(const char *s);
82void yyerror(const char *s);
83extern void parse_init(void);
84int parse(FILE **);
85int yyparse(void);
984263bc
MD
86
87%}
88
89/* common section */
90nl \n
91ws [ \t]+
92digit [0-9]
93letter [0-9A-Za-z]
94hexdigit [0-9A-Fa-f]
95/*octet (([01]?{digit}?{digit})|((2([0-4]{digit}))|(25[0-5])))*/
96special [()+\|\?\*,]
97dot \.
98comma \,
99hyphen \-
100colon \:
101slash \/
102bcl \{
103ecl \}
104blcl \[
105elcl \]
106percent \%
107semi \;
108usec {dot}{digit}{1,6}
109comment \#.*
110ccomment "/*"
111bracketstring \<[^>]*\>
112quotedstring \"[^"]*\"
113decstring {digit}+
114hexpair {hexdigit}{hexdigit}
115hexstring 0[xX]{hexdigit}+
116octetstring {octet}({dot}{octet})+
117ipaddress [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
118ipaddrmask {slash}{digit}{1,3}
119ipaddrport {blcl}{decstring}{elcl}
120keyword {letter}{letter}+
121name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
122hostname {name}(({dot}{name})+{dot}?)?
123
124%s S_PL
125
126%%
127
128add { PREPROC; return(ADD); }
129delete { PREPROC; return(DELETE); }
130deleteall { PREPROC; return(DELETEALL); }
131get { PREPROC; return(GET); }
132flush { PREPROC; return(FLUSH); }
133dump { PREPROC; return(DUMP); }
134
135 /* for management SPD */
136spdadd { PREPROC; return(SPDADD); }
137spddelete { PREPROC; return(SPDDELETE); }
138spddump { PREPROC; return(SPDDUMP); }
139spdflush { PREPROC; return(SPDFLUSH); }
140{hyphen}P { BEGIN S_PL; PREPROC; return(F_POLICY); }
141<S_PL>[a-zA-Z0-9:\.\-_/ \n\t][a-zA-Z0-9:\.\-_/ \n\t]* {
142 yymore();
143
144 /* count up for nl */
145 {
146 char *p;
3641b7ca 147 for (p = yytext; *p != 0; p++)
984263bc
MD
148 if (*p == '\n')
149 lineno++;
150 }
151
152 yylval.val.len = strlen(yytext);
153 yylval.val.buf = strdup(yytext);
154
155 return(PL_REQUESTS);
156}
157<S_PL>{semi} { PREPROC; BEGIN INITIAL; return(EOT); }
158
159 /* security protocols */
160ah { PREPROC; yylval.num = 0; return(PR_AH); }
161esp { PREPROC; yylval.num = 0; return(PR_ESP); }
162ah-old { PREPROC; yylval.num = 1; return(PR_AH); }
163esp-old { PREPROC; yylval.num = 1; return(PR_ESP); }
164ipcomp { PREPROC; yylval.num = 0; return(PR_IPCOMP); }
51006084 165tcp { PREPROC; yylval.num = 0; return(PR_TCP); }
984263bc
MD
166
167 /* authentication alogorithm */
168{hyphen}A { PREPROC; return(F_AUTH); }
169hmac-md5 { PREPROC; yylval.num = SADB_AALG_MD5HMAC; return(ALG_AUTH); }
170hmac-sha1 { PREPROC; yylval.num = SADB_AALG_SHA1HMAC; return(ALG_AUTH); }
171keyed-md5 { PREPROC; yylval.num = SADB_X_AALG_MD5; return(ALG_AUTH); }
172keyed-sha1 { PREPROC; yylval.num = SADB_X_AALG_SHA; return(ALG_AUTH); }
173hmac-sha2-256 { PREPROC; yylval.num = SADB_X_AALG_SHA2_256; return(ALG_AUTH); }
174hmac-sha2-384 { PREPROC; yylval.num = SADB_X_AALG_SHA2_384; return(ALG_AUTH); }
175hmac-sha2-512 { PREPROC; yylval.num = SADB_X_AALG_SHA2_512; return(ALG_AUTH); }
51006084 176tcp-md5 { PREPROC; yylval.num = SADB_X_AALG_TCP_MD5; return(ALG_AUTH); }
984263bc
MD
177null { PREPROC; yylval.num = SADB_X_AALG_NULL; return(ALG_AUTH); }
178
179 /* encryption alogorithm */
180{hyphen}E { PREPROC; return(F_ENC); }
181des-cbc { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC); }
1823des-cbc { PREPROC; yylval.num = SADB_EALG_3DESCBC; return(ALG_ENC); }
183simple { PREPROC; yylval.num = SADB_EALG_NULL; return(ALG_ENC); }
184blowfish-cbc { PREPROC; yylval.num = SADB_X_EALG_BLOWFISHCBC; return(ALG_ENC); }
185cast128-cbc { PREPROC; yylval.num = SADB_X_EALG_CAST128CBC; return(ALG_ENC); }
186des-deriv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DESDERIV); }
187des-32iv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DES32IV); }
188rijndael-cbc { PREPROC; yylval.num = SADB_X_EALG_RIJNDAELCBC; return(ALG_ENC); }
189
190 /* compression algorithms */
191{hyphen}C { PREPROC; return(F_COMP); }
192oui { PREPROC; yylval.num = SADB_X_CALG_OUI; return(ALG_COMP); }
193deflate { PREPROC; yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); }
194lzs { PREPROC; yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); }
195{hyphen}R { PREPROC; return(F_RAWCPI); }
196
197 /* extension */
198{hyphen}m { PREPROC; return(F_MODE); }
199transport { PREPROC; yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
200tunnel { PREPROC; yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
201{hyphen}u { PREPROC; return(F_REQID); }
202{hyphen}f { PREPROC; return(F_EXT); }
203random-pad { PREPROC; yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); }
204seq-pad { PREPROC; yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); }
205zero-pad { PREPROC; yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); }
206nocyclic-seq { PREPROC; return(NOCYCLICSEQ); }
207{hyphen}r { PREPROC; return(F_REPLAY); }
208{hyphen}lh { PREPROC; return(F_LIFETIME_HARD); }
209{hyphen}ls { PREPROC; return(F_LIFETIME_SOFT); }
210
211 /* ... */
212any { PREPROC; return(ANY); }
213{ws} { PREPROC; }
214{nl} { lineno++; }
215{comment}
216{semi} { PREPROC; return(EOT); }
217
218 /* parameter */
219{decstring} {
220 char *bp;
221
222 PREPROC;
223 yylval.num = strtoul(yytext, &bp, 10);
224 return(DECSTRING);
225 }
226
227{ipaddress} {
228 PREPROC;
229
230 yylval.val.len = yyleng;
231 yylval.val.buf = strdup(yytext);
232
233 return(ADDRESS);
234 }
235
236{ipaddrmask} {
237 PREPROC;
238 yytext++;
239 yylval.num = atoi(yytext);
240 return(PREFIX);
241 }
242
243{ipaddrport} {
244 char *p = yytext;
245 PREPROC;
246 while (*++p != ']') ;
3641b7ca 247 *p = 0;
984263bc
MD
248 yytext++;
249 yylval.num = atoi(yytext);
250 return(PORT);
251 }
252
253{blcl}any{elcl} {
254 PREPROC;
255 return(PORTANY);
256 }
257
258{hexstring} {
259 int len = yyleng - 2; /* (str - "0x") */
260 PREPROC;
261 yylval.val.len = (len & 1) + (len / 2);
262 /* fixed string if length is odd. */
263 if (len & 1) {
264 yytext[1] = '0';
265 yylval.val.buf = strdup(yytext + 1);
266 } else
267 yylval.val.buf = strdup(yytext + 2);
268
269 return(HEXSTRING);
270 }
271
272{quotedstring} {
273 char *p = yytext;
274 PREPROC;
275 while (*++p != '"') ;
3641b7ca 276 *p = 0;
984263bc
MD
277 yytext++;
278 yylval.val.len = yyleng - 2;
279 yylval.val.buf = strdup(yytext);
280
281 return(QUOTEDSTRING);
282 }
283
284[a-z0-9.\-]* {
285 yylval.val.len = yyleng;
286 yylval.val.buf = strdup(yytext);
287 return(STRING);
288 }
289
290. {
291 yyfatal("Syntax error");
292 /*NOTREACHED*/
293 }
294
295%%
296
297void
89a89091 298yyfatal(const char *s)
984263bc
MD
299{
300 yyerror(s);
301 exit(1);
302}
303
304void
89a89091 305yyerror(const char *s)
984263bc
MD
306{
307 printf("line %d: %s at [%s]\n", lineno, s, yytext);
308}
309
310int
89a89091 311parse(FILE **fp)
984263bc
MD
312{
313 yyin = *fp;
314
315 parse_init();
316
317 if (yyparse()) {
318 printf("parse failed, line %d.\n", lineno);
319 return(-1);
320 }
321
322 return(0);
323}