token.l (57340) | token.l (62583) |
---|---|
1/* $FreeBSD: head/sbin/setkey/token.l 62583 2000-07-04 16:22:05Z itojun $ */ 2/* $KAME: token.l,v 1.13 2000/06/07 00:29:14 itojun Exp $ */ 3 |
|
1/* 2 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 3 * All rights reserved. | 4/* 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 6 * All rights reserved. |
4 * | 7 * |
5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. | 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. |
16 * | 19 * |
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. | 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. |
28 * 29 * $FreeBSD: head/sbin/setkey/token.l 57340 2000-02-19 16:10:16Z shin $ | |
30 */ 31 32%{ 33#include <sys/types.h> 34#include <sys/param.h> 35#include <sys/socket.h> 36#include <net/route.h> 37#include <net/pfkeyv2.h> --- 20 unchanged lines hidden (view full) --- 58 if (*__p__ == '\n' || *__p__ == '\t') \ 59 *__p__ = ' '; \ 60 strcat(cmdarg, __buf__); \ 61 free(__buf__); \ 62} 63 64#define PREPROC DECHO CMDARG 65 | 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> --- 20 unchanged lines hidden (view full) --- 59 if (*__p__ == '\n' || *__p__ == '\t') \ 60 *__p__ = ' '; \ 61 strcat(cmdarg, __buf__); \ 62 free(__buf__); \ 63} 64 65#define PREPROC DECHO CMDARG 66 |
66int lineno = 1; 67char cmdarg[8192]; /* XXX: BUFSIZ is the better ? */ | 67int lineno = 1; 68char cmdarg[8192]; /* XXX: BUFSIZ is the better ? */ |
68 | 69 |
69extern u_char m_buf[BUFSIZ]; 70extern u_int m_len; 71extern int f_debug; | 70extern u_char m_buf[BUFSIZ]; 71extern u_int m_len; 72extern int f_debug; |
72 | 73 |
73int yylex __P((void)); 74void yyerror __P((char *s)); 75extern void parse_init __P((void)); 76int parse __P((FILE **)); 77int yyparse __P((void)); | 74int yylex __P((void)); 75void yyfatal __P((const char *s)); 76void yyerror __P((const char *s)); 77extern void parse_init __P((void)); 78int parse __P((FILE **)); 79int yyparse __P((void)); |
78 79%} 80 81/* common section */ 82nl \n 83ws [ \t]+ 84digit [0-9] 85letter [0-9A-Za-z] --- 15 unchanged lines hidden (view full) --- 101comment \#.* 102ccomment "/*" 103bracketstring \<[^>]*\> 104quotedstring \"[^"]*\" 105decstring {digit}+ 106hexpair {hexdigit}{hexdigit} 107hexstring 0[xX]{hexdigit}+ 108octetstring {octet}({dot}{octet})+ | 80 81%} 82 83/* common section */ 84nl \n 85ws [ \t]+ 86digit [0-9] 87letter [0-9A-Za-z] --- 15 unchanged lines hidden (view full) --- 103comment \#.* 104ccomment "/*" 105bracketstring \<[^>]*\> 106quotedstring \"[^"]*\" 107decstring {digit}+ 108hexpair {hexdigit}{hexdigit} 109hexstring 0[xX]{hexdigit}+ 110octetstring {octet}({dot}{octet})+ |
109ipaddress {ipv4addr}|{ipv6addr} 110ipv4addr {digit}{1,3}({dot}{digit}{1,3}){0,3} 111ipv6addr {hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}(%{letter}{letter}+)? | 111ipaddress [a-fA-F0-9:]([a-fA-F0-9:\.]*|[a-fA-F0-9:\.]*%[a-zA-Z0-9]*) |
112ipaddrmask {slash}{digit}{1,3} 113ipaddrport {blcl}{decstring}{elcl} 114keyword {letter}{letter}+ 115name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))* 116hostname {name}(({dot}{name})+{dot}?)? 117 118%s S_PL 119 --- 61 unchanged lines hidden (view full) --- 181deflate { PREPROC; yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); } 182lzs { PREPROC; yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); } 183{hyphen}R { PREPROC; return(F_RAWCPI); } 184 185 /* extension */ 186{hyphen}m { PREPROC; return(F_MODE); } 187transport { PREPROC; yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); } 188tunnel { PREPROC; yylval.num = IPSEC_MODE_TUNNEL; return(MODE); } | 112ipaddrmask {slash}{digit}{1,3} 113ipaddrport {blcl}{decstring}{elcl} 114keyword {letter}{letter}+ 115name {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))* 116hostname {name}(({dot}{name})+{dot}?)? 117 118%s S_PL 119 --- 61 unchanged lines hidden (view full) --- 181deflate { PREPROC; yylval.num = SADB_X_CALG_DEFLATE; return(ALG_COMP); } 182lzs { PREPROC; yylval.num = SADB_X_CALG_LZS; return(ALG_COMP); } 183{hyphen}R { PREPROC; return(F_RAWCPI); } 184 185 /* extension */ 186{hyphen}m { PREPROC; return(F_MODE); } 187transport { PREPROC; yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); } 188tunnel { PREPROC; yylval.num = IPSEC_MODE_TUNNEL; return(MODE); } |
189{hyphen}u { PREPROC; return(F_REQID); } |
|
189{hyphen}f { PREPROC; return(F_EXT); } 190random-pad { PREPROC; yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); } 191seq-pad { PREPROC; yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); } 192zero-pad { PREPROC; yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); } | 190{hyphen}f { PREPROC; return(F_EXT); } 191random-pad { PREPROC; yylval.num = SADB_X_EXT_PRAND; return(EXTENSION); } 192seq-pad { PREPROC; yylval.num = SADB_X_EXT_PSEQ; return(EXTENSION); } 193zero-pad { PREPROC; yylval.num = SADB_X_EXT_PZERO; return(EXTENSION); } |
193cyclic-seq { PREPROC; yylval.num = SADB_X_EXT_CYCSEQ; return(EXTENSION); } | 194nocyclic-seq { PREPROC; return(NOCYCLICSEQ); } |
194{hyphen}r { PREPROC; return(F_REPLAY); } 195{hyphen}lh { PREPROC; return(F_LIFETIME_HARD); } 196{hyphen}ls { PREPROC; return(F_LIFETIME_SOFT); } 197 198 199 /* upper layer protocols */ 200icmp { PREPROC; yylval.num = IPPROTO_ICMP; return(UP_PROTO); } 201icmp6 { PREPROC; yylval.num = IPPROTO_ICMPV6; return(UP_PROTO); } --- 7 unchanged lines hidden (view full) --- 209{comment} 210{semi} { PREPROC; return(EOT); } 211 212 /* parameter */ 213{decstring} { 214 char *bp; 215 216 PREPROC; | 195{hyphen}r { PREPROC; return(F_REPLAY); } 196{hyphen}lh { PREPROC; return(F_LIFETIME_HARD); } 197{hyphen}ls { PREPROC; return(F_LIFETIME_SOFT); } 198 199 200 /* upper layer protocols */ 201icmp { PREPROC; yylval.num = IPPROTO_ICMP; return(UP_PROTO); } 202icmp6 { PREPROC; yylval.num = IPPROTO_ICMPV6; return(UP_PROTO); } --- 7 unchanged lines hidden (view full) --- 210{comment} 211{semi} { PREPROC; return(EOT); } 212 213 /* parameter */ 214{decstring} { 215 char *bp; 216 217 PREPROC; |
217 yylval.num = strtol(yytext, &bp, 10); | 218 yylval.num = strtoul(yytext, &bp, 10); |
218 return(DECSTRING); 219 } 220 | 219 return(DECSTRING); 220 } 221 |
221{ipv4addr} { 222 /* 223 * I can't supprt the type without dot, 224 * because it's umbiguous against {decstring}. 225 * e.g. 127 226 */ | 222{ipaddress} { |
227 PREPROC; 228 | 223 PREPROC; 224 |
229 yylval.val.len = sizeof(struct sockaddr_in); | 225 yylval.val.len = yyleng; |
230 yylval.val.buf = strdup(yytext); 231 | 226 yylval.val.buf = strdup(yytext); 227 |
232 return(IP4_ADDRESS); | 228 return(ADDRESS); |
233 } 234 | 229 } 230 |
235{ipv6addr} { 236#ifdef INET6 237 PREPROC; 238 239 yylval.val.len = sizeof(struct sockaddr_in6); 240 yylval.val.buf = strdup(yytext); 241 242 return(IP6_ADDRESS); 243#else 244 yyerror("IPv6 address not supported"); 245#endif 246 } 247 | |
248{ipaddrmask} { 249 PREPROC; 250 yytext++; 251 yylval.num = atoi(yytext); 252 return(PREFIX); 253 } 254 255{ipaddrport} { 256 char *p = yytext; 257 PREPROC; 258 while (*++p != ']') ; 259 *p = NULL; 260 yytext++; 261 yylval.num = atoi(yytext); 262 return(PORT); 263 } 264 265{blcl}any{elcl} { | 231{ipaddrmask} { 232 PREPROC; 233 yytext++; 234 yylval.num = atoi(yytext); 235 return(PREFIX); 236 } 237 238{ipaddrport} { 239 char *p = yytext; 240 PREPROC; 241 while (*++p != ']') ; 242 *p = NULL; 243 yytext++; 244 yylval.num = atoi(yytext); 245 return(PORT); 246 } 247 248{blcl}any{elcl} { |
266 char *p = yytext; | |
267 PREPROC; 268 return(PORTANY); 269 } 270 271{hexstring} { 272 int len = yyleng - 2; /* (str - "0x") */ 273 PREPROC; 274 yylval.val.len = (len & 1) + (len / 2); --- 14 unchanged lines hidden (view full) --- 289 *p = NULL; 290 yytext++; 291 yylval.val.len = yyleng - 2; 292 yylval.val.buf = strdup(yytext); 293 294 return(QUOTEDSTRING); 295 } 296 | 249 PREPROC; 250 return(PORTANY); 251 } 252 253{hexstring} { 254 int len = yyleng - 2; /* (str - "0x") */ 255 PREPROC; 256 yylval.val.len = (len & 1) + (len / 2); --- 14 unchanged lines hidden (view full) --- 271 *p = NULL; 272 yytext++; 273 yylval.val.len = yyleng - 2; 274 yylval.val.buf = strdup(yytext); 275 276 return(QUOTEDSTRING); 277 } 278 |
297. { yyerror("Syntax error"); } | 279. { 280 yyfatal("Syntax error"); 281 /*NOTREACHED*/ 282 } |
298 299%% 300 301void | 283 284%% 285 286void |
302yyerror(char *s) | 287yyfatal(s) 288 const char *s; |
303{ | 289{ |
290 yyerror(s); 291 exit(1); 292} 293 294void 295yyerror(s) 296 const char *s; 297{ |
|
304 printf("line %d: %s at [%s]\n", lineno, s, yytext); 305} 306 307int 308parse(fp) 309 FILE **fp; 310{ 311 yyin = *fp; 312 313 parse_init(); 314 315 if (yyparse()) { 316 printf("parse failed, line %d.\n", lineno); 317 return(-1); 318 } 319 320 return(0); 321} | 298 printf("line %d: %s at [%s]\n", lineno, s, yytext); 299} 300 301int 302parse(fp) 303 FILE **fp; 304{ 305 yyin = *fp; 306 307 parse_init(); 308 309 if (yyparse()) { 310 printf("parse failed, line %d.\n", lineno); 311 return(-1); 312 } 313 314 return(0); 315} |
322 | |