1 /* $FreeBSD: src/usr.sbin/setkey/token.l,v 1.2.2.3 2001/07/03 11:02:17 ume Exp $ */
2 /* $DragonFly: src/usr.sbin/setkey/token.l,v 1.4 2008/06/05 18:06:33 swildner Exp $ */
3 /* $KAME: token.l,v 1.21 2001/05/18 05:35:01 sakane Exp $ */
6 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 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
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>
58 if (f_debug) {printf("<%d>", yy_start); ECHO ; printf("\n"); }
62 char *__buf__ = strdup(yytext), *__p__; \
63 for (__p__ = __buf__; *__p__ != 0; __p__++) \
64 if (*__p__ == '\n' || *__p__ == '\t') \
66 strcat(cmdarg, __buf__); \
70 #define PREPROC DECHO CMDARG
73 char cmdarg[8192]; /* XXX: BUFSIZ is the better ? */
75 extern u_char m_buf[BUFSIZ];
80 void yyfatal(const char *s);
81 void yyerror(const char *s);
82 extern void parse_init(void);
94 /*octet (([01]?{digit}?{digit})|((2([0-4]{digit}))|(25[0-5])))*/
107 usec {dot}{digit}{1,6}
110 bracketstring \<[^>]*\>
111 quotedstring \"[^"]*\"
113 hexpair {hexdigit}{hexdigit}
114 hexstring 0[xX]{hexdigit}+
115 octetstring {octet}({dot}{octet})+
116 ipaddress [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
117 ipaddrmask {slash}{digit}{1,3}
118 ipaddrport {blcl}{decstring}{elcl}
119 keyword {letter}{letter}+
120 name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
121 hostname {name}(({dot}{name})+{dot}?)?
127 add { PREPROC; return(ADD); }
128 delete { PREPROC; return(DELETE); }
129 deleteall { PREPROC; return(DELETEALL); }
130 get { PREPROC; return(GET); }
131 flush { PREPROC; return(FLUSH); }
132 dump { PREPROC; return(DUMP); }
134 /* for management SPD */
135 spdadd { PREPROC; return(SPDADD); }
136 spddelete { PREPROC; return(SPDDELETE); }
137 spddump { PREPROC; return(SPDDUMP); }
138 spdflush { 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]* {
143 /* count up for nl */
146 for (p = yytext; *p != 0; p++)
151 yylval.val.len = strlen(yytext);
152 yylval.val.buf = strdup(yytext);
156 <S_PL>{semi} { PREPROC; BEGIN INITIAL; return(EOT); }
158 /* security protocols */
159 ah { PREPROC; yylval.num = 0; return(PR_AH); }
160 esp { PREPROC; yylval.num = 0; return(PR_ESP); }
161 ah-old { PREPROC; yylval.num = 1; return(PR_AH); }
162 esp-old { PREPROC; yylval.num = 1; return(PR_ESP); }
163 ipcomp { PREPROC; yylval.num = 0; return(PR_IPCOMP); }
165 /* authentication alogorithm */
166 {hyphen}A { PREPROC; return(F_AUTH); }
167 hmac-md5 { PREPROC; yylval.num = SADB_AALG_MD5HMAC; return(ALG_AUTH); }
168 hmac-sha1 { PREPROC; yylval.num = SADB_AALG_SHA1HMAC; return(ALG_AUTH); }
169 keyed-md5 { PREPROC; yylval.num = SADB_X_AALG_MD5; return(ALG_AUTH); }
170 keyed-sha1 { PREPROC; yylval.num = SADB_X_AALG_SHA; return(ALG_AUTH); }
171 hmac-sha2-256 { PREPROC; yylval.num = SADB_X_AALG_SHA2_256; return(ALG_AUTH); }
172 hmac-sha2-384 { PREPROC; yylval.num = SADB_X_AALG_SHA2_384; return(ALG_AUTH); }
173 hmac-sha2-512 { PREPROC; yylval.num = SADB_X_AALG_SHA2_512; return(ALG_AUTH); }
174 null { PREPROC; yylval.num = SADB_X_AALG_NULL; return(ALG_AUTH); }
176 /* encryption alogorithm */
177 {hyphen}E { PREPROC; return(F_ENC); }
178 des-cbc { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC); }
179 3des-cbc { PREPROC; yylval.num = SADB_EALG_3DESCBC; return(ALG_ENC); }
180 simple { PREPROC; yylval.num = SADB_EALG_NULL; return(ALG_ENC); }
181 blowfish-cbc { PREPROC; yylval.num = SADB_X_EALG_BLOWFISHCBC; return(ALG_ENC); }
182 cast128-cbc { PREPROC; yylval.num = SADB_X_EALG_CAST128CBC; return(ALG_ENC); }
183 des-deriv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DESDERIV); }
184 des-32iv { PREPROC; yylval.num = SADB_EALG_DESCBC; return(ALG_ENC_DES32IV); }
185 rijndael-cbc { PREPROC; yylval.num = SADB_X_EALG_RIJNDAELCBC; return(ALG_ENC); }
187 /* compression algorithms */
188 {hyphen}C { PREPROC; return(F_COMP); }
189 oui { PREPROC; yylval.num = SADB_X_CALG_OUI; return(ALG_COMP); }
190 deflate { PREPROC; yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); }
191 lzs { PREPROC; yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); }
192 {hyphen}R { PREPROC; return(F_RAWCPI); }
195 {hyphen}m { PREPROC; return(F_MODE); }
196 transport { PREPROC; yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
197 tunnel { PREPROC; yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
198 {hyphen}u { PREPROC; return(F_REQID); }
199 {hyphen}f { PREPROC; return(F_EXT); }
200 random-pad { PREPROC; yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); }
201 seq-pad { PREPROC; yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); }
202 zero-pad { PREPROC; yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); }
203 nocyclic-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); }
209 any { PREPROC; return(ANY); }
213 {semi} { PREPROC; return(EOT); }
220 yylval.num = strtoul(yytext, &bp, 10);
227 yylval.val.len = yyleng;
228 yylval.val.buf = strdup(yytext);
236 yylval.num = atoi(yytext);
243 while (*++p != ']') ;
246 yylval.num = atoi(yytext);
256 int len = yyleng - 2; /* (str - "0x") */
258 yylval.val.len = (len & 1) + (len / 2);
259 /* fixed string if length is odd. */
262 yylval.val.buf = strdup(yytext + 1);
264 yylval.val.buf = strdup(yytext + 2);
272 while (*++p != '"') ;
275 yylval.val.len = yyleng - 2;
276 yylval.val.buf = strdup(yytext);
278 return(QUOTEDSTRING);
282 yylval.val.len = yyleng;
283 yylval.val.buf = strdup(yytext);
288 yyfatal("Syntax error");
306 printf("line %d: %s at [%s]\n", lineno, s, yytext);
318 printf("parse failed, line %d.\n", lineno);