1/*	$KAME: policy_token.l,v 1.11 2000/12/01 10:08:29 sakane Exp $	*/
2
3/*
4 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
18 *
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
29 * SUCH DAMAGE.
30 */
31
32%{
33#include <sys/types.h>
34#include <sys/param.h>
35#include <sys/socket.h>
36#include <net/pfkeyv2.h>
37#include <netinet/in.h>
38#include <netinet/ipsec.h>
39
40#include <stdlib.h>
41#include <limits.h>
42#include <string.h>
43#include <unistd.h>
44#include <errno.h>
45
46#include "policy_parse.h"
47#define yylval __libyylval	/* XXX */
48
49int yylex __P((void));
50%}
51
52%option noyywrap
53%option nounput
54
55/* common section */
56nl		\n
57ws		[ \t]+
58digit		[0-9]
59hexdigit	[0-9A-Fa-f]
60special		[()+\|\?\*,]
61dot		\.
62comma		\,
63hyphen		\-
64colon		\:
65slash		\/
66bcl		\{
67ecl		\}
68blcl		\[
69elcl		\]
70percent		\%
71semi		\;
72usec		{dot}{digit}{1,6}
73comment		\#.*
74ccomment	"/*"
75bracketstring	\<[^>]*\>
76quotedstring	\"[^"]*\"
77decstring	{digit}+
78hexpair		{hexdigit}{hexdigit}
79hexstring	0[xX]{hexdigit}+
80octetstring	{octet}({dot}{octet})+
81ipaddress	[a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)?
82
83%%
84
85in		{ yylval.num = IPSEC_DIR_INBOUND; return(DIR); }
86out		{ yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); }
87fwd		{ yylval.num = IPSEC_DIR_FWD; return(DIR); }
88
89discard		{ yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); }
90none		{ yylval.num = IPSEC_POLICY_NONE; return(ACTION); }
91ipsec		{ yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); }
92bypass		{ yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); }
93entrust		{ yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); }
94
95esp		{ yylval.num = IPPROTO_ESP; return(PROTOCOL); }
96ah		{ yylval.num = IPPROTO_AH; return(PROTOCOL); }
97ipcomp		{ yylval.num = IPPROTO_COMP; return(PROTOCOL); }
98
99transport	{ yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
100tunnel		{ yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
101
102me		{ return(ME); }
103any		{ return(ANY); }
104
105default		{ yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); }
106use		{ yylval.num = IPSEC_LEVEL_USE; return(LEVEL); }
107require		{ yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); }
108unique{colon}{decstring} {
109			yylval.val.len = strlen(yytext + 7);
110			yylval.val.buf = yytext + 7;
111			return(LEVEL_SPECIFY);
112		}
113unique		{ yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
114{slash}		{ return(SLASH); }
115
116{ipaddress}	{
117			yylval.val.len = strlen(yytext);
118			yylval.val.buf = yytext;
119			return(IPADDRESS);
120		}
121
122{hyphen}	{ return(HYPHEN); }
123
124{ws}		{ ; }
125{nl}		{ ; }
126
127%%
128
129void __policy__strbuffer__init__ __P((char *));
130
131void
132__policy__strbuffer__init__(msg)
133	char *msg;
134{
135	YY_BUFFER_STATE yyb;
136
137	yyb = (YY_BUFFER_STATE)yy_scan_string(msg);
138	yy_switch_to_buffer(yyb);
139
140	return;
141}
142
143