Add some missing $DragonFly$ keywords.
[dragonfly.git] / usr.sbin / setkey / token.l
CommitLineData
984263bc 1/* $FreeBSD: src/usr.sbin/setkey/token.l,v 1.2.2.3 2001/07/03 11:02:17 ume Exp $ */
1de703da 2/* $DragonFly: src/usr.sbin/setkey/token.l,v 1.2 2003/06/17 04:30:03 dillon Exp $ */
984263bc
MD
3/* $KAME: token.l,v 1.21 2001/05/18 05:35:01 sakane Exp $ */
4
5/*
6 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 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
34%{
35#include <sys/types.h>
36#include <sys/param.h>
37#include <sys/socket.h>
38#include <net/route.h>
39#include <net/pfkeyv2.h>
40#include <netkey/keydb.h>
41#include <netkey/key_debug.h>
42#include <netinet/in.h>
43#include <netinet6/ipsec.h>
44
45#include <stdlib.h>
46#include <limits.h>
47#include <string.h>
48#include <unistd.h>
49#include <errno.h>
50#include "vchar.h"
51#ifdef __NetBSD__
52#include "parse.h"
53#else
54#include "y.tab.h"
55#endif
56
57#define DECHO \
58 if (f_debug) {printf("<%d>", yy_start); ECHO ; printf("\n"); }
59
60#define CMDARG \
61{ \
62 char *__buf__ = strdup(yytext), *__p__; \
63 for (__p__ = __buf__; *__p__ != NULL; __p__++) \
64 if (*__p__ == '\n' || *__p__ == '\t') \
65 *__p__ = ' '; \
66 strcat(cmdarg, __buf__); \
67 free(__buf__); \
68}
69
70#define PREPROC DECHO CMDARG
71
72int lineno = 1;
73char cmdarg[8192]; /* XXX: BUFSIZ is the better ? */
74
75extern u_char m_buf[BUFSIZ];
76extern u_int m_len;
77extern int f_debug;
78
79int yylex __P((void));
80void yyfatal __P((const char *s));
81void yyerror __P((const char *s));
82extern void parse_init __P((void));
83int parse __P((FILE **));
84int yyparse __P((void));
85
86%}
87
88/* common section */
89nl \n
90ws [ \t]+
91digit [0-9]
92letter [0-9A-Za-z]
93hexdigit [0-9A-Fa-f]
94/*octet (([01]?{digit}?{digit})|((2([0-4]{digit}))|(25[0-5])))*/
95special [()+\|\?\*,]
96dot \.
97comma \,
98hyphen \-
99colon \:
100slash \/
101bcl \{
102ecl \}
103blcl \[
104elcl \]
105percent \%
106semi \;
107usec {dot}{digit}{1,6}
108comment \#.*
109ccomment "/*"
110bracketstring \<[^>]*\>
111quotedstring \"[^"]*\"
112decstring {digit}+
113hexpair {hexdigit}{hexdigit}
114hexstring 0[xX]{hexdigit}+
115octetstring {octet}({dot}{octet})+
116ipaddress [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
117ipaddrmask {slash}{digit}{1,3}
118ipaddrport {blcl}{decstring}{elcl}
119keyword {letter}{letter}+
120name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
121hostname {name}(({dot}{name})+{dot}?)?
122
123%s S_PL
124
125%%
126
127add { PREPROC; return(ADD); }
128delete { PREPROC; return(DELETE); }
129deleteall { PREPROC; return(DELETEALL); }
130get { PREPROC; return(GET); }
131flush { PREPROC; return(FLUSH); }
132dump { PREPROC; return(DUMP); }
133
134 /* for management SPD */
135spdadd { PREPROC; return(SPDADD); }
136spddelete { PREPROC; return(SPDDELETE); }
137spddump { PREPROC; return(SPDDUMP); }
138spdflush { PREPROC; return(SPDFLUSH); }
139{hyphen}P { BEGIN S_PL; PREPROC; return(F_POLICY); }
140<S_PL>[a-zA-Z0-9:\.\-_/ \n\t][a-zA-Z0-9:\.\-_/ \n\t]* {
141 yymore();
142
143 /* count up for nl */
144 {
145 char *p;
146 for (p = yytext; *p != NULL; p++)
147 if (*p == '\n')
148 lineno++;
149 }
150
151 yylval.val.len = strlen(yytext);
152 yylval.val.buf = strdup(yytext);
153
154 return(PL_REQUESTS);
155}
156<S_PL>{semi} { PREPROC; BEGIN INITIAL; return(EOT); }
157
158 /* security protocols */
159ah { PREPROC; yylval.num = 0; return(PR_AH); }
160esp { PREPROC; yylval.num = 0; return(PR_ESP); }
161ah-old { PREPROC; yylval.num = 1; return(PR_AH); }
162esp-old { PREPROC; yylval.num = 1; return(PR_ESP); }
163ipcomp { PREPROC; yylval.num = 0; return(PR_IPCOMP); }
164
165 /* authentication alogorithm */
166{hyphen}A { PREPROC; return(F_AUTH); }
167hmac-md5 { PREPROC; yylval.num = SADB_AALG_MD5HMAC; return(ALG_AUTH); }
168hmac-sha1 { PREPROC; yylval.num = SADB_AALG_SHA1HMAC; return(ALG_AUTH); }
169keyed-md5 { PREPROC; yylval.num = SADB_X_AALG_MD5; return(ALG_AUTH); }
170keyed-sha1 { PREPROC; yylval.num = SADB_X_AALG_SHA; return(ALG_AUTH); }
171hmac-sha2-256 { PREPROC; yylval.num = SADB_X_AALG_SHA2_256; return(ALG_AUTH); }
172hmac-sha2-384 { PREPROC; yylval.num = SADB_X_AALG_SHA2_384; return(ALG_AUTH); }
173hmac-sha2-512 { PREPROC; yylval.num = SADB_X_AALG_SHA2_512; return(ALG_AUTH); }
174null { PREPROC; yylval.num = SADB_X_AALG_NULL; return(ALG_AUTH); }
175
176 /* encryption alogorithm */
177{hyphen}E { PREPROC; return(F_ENC); }
178des-cbc { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC); }
1793des-cbc { PREPROC; yylval.num = SADB_EALG_3DESCBC; return(ALG_ENC); }
180simple { PREPROC; yylval.num = SADB_EALG_NULL; return(ALG_ENC); }
181blowfish-cbc { PREPROC; yylval.num = SADB_X_EALG_BLOWFISHCBC; return(ALG_ENC); }
182cast128-cbc { PREPROC; yylval.num = SADB_X_EALG_CAST128CBC; return(ALG_ENC); }
183des-deriv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DESDERIV); }
184des-32iv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DES32IV); }
185rijndael-cbc { PREPROC; yylval.num = SADB_X_EALG_RIJNDAELCBC; return(ALG_ENC); }
186
187 /* compression algorithms */
188{hyphen}C { PREPROC; return(F_COMP); }
189oui { PREPROC; yylval.num = SADB_X_CALG_OUI; return(ALG_COMP); }
190deflate { PREPROC; yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); }
191lzs { PREPROC; yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); }
192{hyphen}R { PREPROC; return(F_RAWCPI); }
193
194 /* extension */
195{hyphen}m { PREPROC; return(F_MODE); }
196transport { PREPROC; yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
197tunnel { PREPROC; yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
198{hyphen}u { PREPROC; return(F_REQID); }
199{hyphen}f { PREPROC; return(F_EXT); }
200random-pad { PREPROC; yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); }
201seq-pad { PREPROC; yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); }
202zero-pad { PREPROC; yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); }
203nocyclic-seq { PREPROC; return(NOCYCLICSEQ); }
204{hyphen}r { PREPROC; return(F_REPLAY); }
205{hyphen}lh { PREPROC; return(F_LIFETIME_HARD); }
206{hyphen}ls { PREPROC; return(F_LIFETIME_SOFT); }
207
208 /* ... */
209any { PREPROC; return(ANY); }
210{ws} { PREPROC; }
211{nl} { lineno++; }
212{comment}
213{semi} { PREPROC; return(EOT); }
214
215 /* parameter */
216{decstring} {
217 char *bp;
218
219 PREPROC;
220 yylval.num = strtoul(yytext, &bp, 10);
221 return(DECSTRING);
222 }
223
224{ipaddress} {
225 PREPROC;
226
227 yylval.val.len = yyleng;
228 yylval.val.buf = strdup(yytext);
229
230 return(ADDRESS);
231 }
232
233{ipaddrmask} {
234 PREPROC;
235 yytext++;
236 yylval.num = atoi(yytext);
237 return(PREFIX);
238 }
239
240{ipaddrport} {
241 char *p = yytext;
242 PREPROC;
243 while (*++p != ']') ;
244 *p = NULL;
245 yytext++;
246 yylval.num = atoi(yytext);
247 return(PORT);
248 }
249
250{blcl}any{elcl} {
251 PREPROC;
252 return(PORTANY);
253 }
254
255{hexstring} {
256 int len = yyleng - 2; /* (str - "0x") */
257 PREPROC;
258 yylval.val.len = (len & 1) + (len / 2);
259 /* fixed string if length is odd. */
260 if (len & 1) {
261 yytext[1] = '0';
262 yylval.val.buf = strdup(yytext + 1);
263 } else
264 yylval.val.buf = strdup(yytext + 2);
265
266 return(HEXSTRING);
267 }
268
269{quotedstring} {
270 char *p = yytext;
271 PREPROC;
272 while (*++p != '"') ;
273 *p = NULL;
274 yytext++;
275 yylval.val.len = yyleng - 2;
276 yylval.val.buf = strdup(yytext);
277
278 return(QUOTEDSTRING);
279 }
280
281[a-z0-9.\-]* {
282 yylval.val.len = yyleng;
283 yylval.val.buf = strdup(yytext);
284 return(STRING);
285 }
286
287. {
288 yyfatal("Syntax error");
289 /*NOTREACHED*/
290 }
291
292%%
293
294void
295yyfatal(s)
296 const char *s;
297{
298 yyerror(s);
299 exit(1);
300}
301
302void
303yyerror(s)
304 const char *s;
305{
306 printf("line %d: %s at [%s]\n", lineno, s, yytext);
307}
308
309int
310parse(fp)
311 FILE **fp;
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}