1 /* $KAME: token.l,v 1.44 2003/10/21 07:20:58 itojun Exp $ */
4 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/socket.h>
43 #include <System/net/pfkeyv2.h>
45 #include <net/pfkeyv2.h>
47 #include <netinet/in.h>
48 #ifdef HAVE_NETINET6_IPSEC
49 # include <netinet6/ipsec.h>
51 # include <netinet/ipsec.h>
62 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__linux__)
70 /* make the code compile on *BSD-current */
71 #ifndef SADB_X_AALG_SHA2_256
72 #define SADB_X_AALG_SHA2_256 (-1)
74 #ifndef SADB_X_AALG_SHA2_384
75 #define SADB_X_AALG_SHA2_384 (-1)
77 #ifndef SADB_X_AALG_SHA2_512
78 #define SADB_X_AALG_SHA2_512 (-1)
80 #ifndef SADB_X_AALG_RIPEMD160HMAC
81 #define SADB_X_AALG_RIPEMD160HMAC (-1)
83 #ifndef SADB_X_AALG_AES_XCBC_MAC
84 #define SADB_X_AALG_AES_XCBC_MAC (-1)
86 #ifndef SADB_X_EALG_TWOFISHCBC
87 #define SADB_X_EALG_TWOFISHCBC (-1)
89 #ifndef SADB_X_EALG_AESCTR
90 #define SADB_X_EALG_AESCTR (-1)
107 quotedstring \"[^"]*\"
109 hexstring 0[xX]{hexdigit}+
110 ipaddress [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*)
111 ipaddrmask {slash}{digit}{1,3}
112 name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
113 hostname {name}(({dot}{name})+{dot}?)?
115 %s S_PL S_AUTHALG S_ENCALG
120 delete { return(DELETE); }
121 deleteall { return(DELETEALL); }
123 flush { return(FLUSH); }
124 dump { return(DUMP); }
125 exit { return(EXIT); }
126 quit { return(EXIT); }
127 bye { return(EXIT); }
129 /* for management SPD */
130 spdadd { return(SPDADD); }
131 spddelete { return(SPDDELETE); }
132 spddump { return(SPDDUMP); }
133 spdflush { return(SPDFLUSH); }
134 tagged { return(TAGGED); }
135 {hyphen}P { BEGIN S_PL; return(F_POLICY); }
136 <S_PL>[a-zA-Z0-9:\.\-_/ \n\t][a-zA-Z0-9:\.%\-+_/ \n\t\]\[]* {
139 /* count up for nl */
142 for (p = yytext; *p != '\0'; p++)
147 yylval.val.len = strlen(yytext);
148 yylval.val.buf = strdup(yytext);
150 yyfatal("insufficient memory");
154 <S_PL>{semi} { BEGIN INITIAL; return(EOT); }
156 /* address resolution flags */
157 {hyphen}[n46][n46]* {
158 yylval.val.len = strlen(yytext);
159 yylval.val.buf = strdup(yytext);
161 yyfatal("insufficient memory");
165 /* security protocols */
166 ah { yylval.num = 0; return(PR_AH); }
167 esp { yylval.num = 0; return(PR_ESP); }
168 ah-old { yylval.num = 1; return(PR_AH); }
169 esp-old { yylval.num = 1; return(PR_ESP); }
170 esp-udp { yylval.num = 0; return(PR_ESPUDP); }
171 ipcomp { yylval.num = 0; return(PR_IPCOMP); }
173 yylval.num = 0; return(PR_TCP);
176 /* authentication alogorithm */
177 {hyphen}A { BEGIN S_AUTHALG; return(F_AUTH); }
178 <S_AUTHALG>hmac-md5 { yylval.num = SADB_AALG_MD5HMAC; BEGIN INITIAL; return(ALG_AUTH); }
179 <S_AUTHALG>hmac-sha1 { yylval.num = SADB_AALG_SHA1HMAC; BEGIN INITIAL; return(ALG_AUTH); }
180 <S_AUTHALG>keyed-md5 { yylval.num = SADB_X_AALG_MD5; BEGIN INITIAL; return(ALG_AUTH); }
181 <S_AUTHALG>keyed-sha1 { yylval.num = SADB_X_AALG_SHA; BEGIN INITIAL; return(ALG_AUTH); }
182 <S_AUTHALG>hmac-sha2-256 { yylval.num = SADB_X_AALG_SHA2_256; BEGIN INITIAL; return(ALG_AUTH); }
183 <S_AUTHALG>hmac-sha256 { yylval.num = SADB_X_AALG_SHA2_256; BEGIN INITIAL; return(ALG_AUTH); }
184 <S_AUTHALG>hmac-sha2-384 { yylval.num = SADB_X_AALG_SHA2_384; BEGIN INITIAL; return(ALG_AUTH); }
185 <S_AUTHALG>hmac-sha384 { yylval.num = SADB_X_AALG_SHA2_384; BEGIN INITIAL; return(ALG_AUTH); }
186 <S_AUTHALG>hmac-sha2-512 { yylval.num = SADB_X_AALG_SHA2_512; BEGIN INITIAL; return(ALG_AUTH); }
187 <S_AUTHALG>hmac-sha512 { yylval.num = SADB_X_AALG_SHA2_512; BEGIN INITIAL; return(ALG_AUTH); }
188 <S_AUTHALG>hmac-ripemd160 { yylval.num = SADB_X_AALG_RIPEMD160HMAC; BEGIN INITIAL; return(ALG_AUTH); }
189 <S_AUTHALG>aes-xcbc-mac { yylval.num = SADB_X_AALG_AES_XCBC_MAC; BEGIN INITIAL; return(ALG_AUTH); }
191 #ifdef SADB_X_AALG_TCP_MD5
192 yylval.num = SADB_X_AALG_TCP_MD5;
197 <S_AUTHALG>null { yylval.num = SADB_X_AALG_NULL; BEGIN INITIAL; return(ALG_AUTH_NOKEY); }
199 /* encryption alogorithm */
200 {hyphen}E { BEGIN S_ENCALG; return(F_ENC); }
201 <S_ENCALG>des-cbc { yylval.num = SADB_EALG_DESCBC; BEGIN INITIAL; return(ALG_ENC); }
202 <S_ENCALG>3des-cbc { yylval.num = SADB_EALG_3DESCBC; BEGIN INITIAL; return(ALG_ENC); }
203 <S_ENCALG>null { yylval.num = SADB_EALG_NULL; BEGIN INITIAL; return(ALG_ENC_NOKEY); }
204 <S_ENCALG>simple { yylval.num = SADB_EALG_NULL; BEGIN INITIAL; return(ALG_ENC_OLD); }
205 <S_ENCALG>blowfish-cbc { yylval.num = SADB_X_EALG_BLOWFISHCBC; BEGIN INITIAL; return(ALG_ENC); }
206 <S_ENCALG>cast128-cbc { yylval.num = SADB_X_EALG_CAST128CBC; BEGIN INITIAL; return(ALG_ENC); }
207 <S_ENCALG>des-deriv { yylval.num = SADB_EALG_DESCBC; BEGIN INITIAL; return(ALG_ENC_DESDERIV); }
208 <S_ENCALG>des-32iv { yylval.num = SADB_EALG_DESCBC; BEGIN INITIAL; return(ALG_ENC_DES32IV); }
209 <S_ENCALG>twofish-cbc { yylval.num = SADB_X_EALG_TWOFISHCBC; BEGIN INITIAL; return(ALG_ENC); }
211 #ifdef SADB_X_EALG_AESCBC
212 yylval.num = SADB_X_EALG_AESCBC; BEGIN INITIAL; return(ALG_ENC);
215 <S_ENCALG>rijndael-cbc {
216 #ifdef SADB_X_EALG_AESCBC
217 yylval.num = SADB_X_EALG_AESCBC; BEGIN INITIAL; return(ALG_ENC);
220 <S_ENCALG>aes-ctr { yylval.num = SADB_X_EALG_AESCTR; BEGIN INITIAL; return(ALG_ENC); }
222 /* compression algorithms */
223 {hyphen}C { return(F_COMP); }
224 oui { yylval.num = SADB_X_CALG_OUI; return(ALG_COMP); }
225 deflate { yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); }
226 lzs { yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); }
227 {hyphen}R { return(F_RAWCPI); }
230 {hyphen}m { return(F_MODE); }
231 transport { yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
232 tunnel { yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
233 {hyphen}u { return(F_REQID); }
234 {hyphen}f { return(F_EXT); }
235 random-pad { yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); }
236 seq-pad { yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); }
237 zero-pad { yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); }
238 nocyclic-seq { return(NOCYCLICSEQ); }
239 {hyphen}r { return(F_REPLAY); }
240 {hyphen}lh { return(F_LIFETIME_HARD); }
241 {hyphen}ls { return(F_LIFETIME_SOFT); }
242 {hyphen}bh { return(F_LIFEBYTE_HARD); }
243 {hyphen}bs { return(F_LIFEBYTE_SOFT); }
250 {semi} { return(EOT); }
252 /* for address parameters: /prefix, [port] */
253 {slash} { return SLASH; }
254 {blcl} { return BLCL; }
255 {elcl} { return ELCL; }
261 yylval.ulnum = strtoul(yytext, &bp, 10);
266 yylval.val.buf = strdup(yytext + 2);
268 yyfatal("insufficient memory");
269 yylval.val.len = strlen(yylval.val.buf);
276 while (*++p != '"') ;
279 yylval.val.len = yyleng - 2;
280 yylval.val.buf = strdup(yytext);
282 yyfatal("insufficient memory");
284 return(QUOTEDSTRING);
287 [A-Za-z0-9:][A-Za-z0-9:%\.-]* {
288 yylval.val.len = yyleng;
289 yylval.val.buf = strdup(yytext);
291 yyfatal("insufficient memory");
296 yylval.val.len = yyleng;
297 yylval.val.buf = strdup(yytext);
299 yyfatal("insufficient memory");
304 yyfatal("Syntax error");
322 printf("line %d: %s at [%s]\n", lineno, s, yytext);
335 printf("parse failed, line %d.\n", lineno);
343 parse_string (char *src)
346 YY_BUFFER_STATE buf_state;
348 buf_state = yy_scan_string(src);
350 yy_delete_buffer(buf_state);