xref: /freebsd/lib/libipsec/policy_token.l (revision 23f282aa31e9b6fceacd449020e936e98d6f2298)
1 /*
2  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
3  * All rights reserved.
4  *
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.
16  *
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.
28  *
29  * $FreeBSD$
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>
38 #include <netkey/keydb.h>
39 #include <netkey/key_debug.h>
40 #include <netinet/in.h>
41 #include <netinet6/ipsec.h>
42 
43 #include <stdlib.h>
44 #include <limits.h>
45 #include <string.h>
46 #include <unistd.h>
47 #include <errno.h>
48 
49 #include "y.tab.h"
50 #define	yylval __libipsecyylval	/* XXX */
51 %}
52 
53 %option noyywrap
54 
55 /* common section */
56 nl		\n
57 ws		[ \t]+
58 digit		[0-9]
59 letter		[0-9A-Za-z]
60 hexdigit	[0-9A-Fa-f]
61 special		[()+\|\?\*,]
62 dot		\.
63 comma		\,
64 hyphen		\-
65 colon		\:
66 slash		\/
67 bcl		\{
68 ecl		\}
69 blcl		\[
70 elcl		\]
71 percent		\%
72 semi		\;
73 usec		{dot}{digit}{1,6}
74 comment		\#.*
75 ccomment	"/*"
76 bracketstring	\<[^>]*\>
77 quotedstring	\"[^"]*\"
78 decstring	{digit}+
79 hexpair		{hexdigit}{hexdigit}
80 hexstring	0[xX]{hexdigit}+
81 octetstring	{octet}({dot}{octet})+
82 ipaddress	[a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%{letter}{letter}+)?
83 name		{letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
84 hostname	{name}(({dot}{name})+{dot}?)?
85 
86 %%
87 
88 in		{ yylval.num = IPSEC_DIR_INBOUND; return(DIR); }
89 out		{ yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); }
90 
91 discard		{ yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); }
92 none		{ yylval.num = IPSEC_POLICY_NONE; return(ACTION); }
93 ipsec		{ yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); }
94 bypass		{ yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); }
95 entrust		{ yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); }
96 
97 esp		{ yylval.num = IPPROTO_ESP; return(PROTOCOL); }
98 ah		{ yylval.num = IPPROTO_AH; return(PROTOCOL); }
99 ipcomp		{ yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); }
100 
101 transport	{ yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
102 tunnel		{ yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
103 
104 me		{ return(ME); }
105 any		{ return(ANY); }
106 
107 default		{ yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); }
108 use		{ yylval.num = IPSEC_LEVEL_USE; return(LEVEL); }
109 require		{ yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); }
110 unique		{ yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
111 {slash}		{ return(SLASH); }
112 
113 {ipaddress}	{
114 			yylval.val.len = strlen(yytext);
115 			yylval.val.buf = strdup(yytext);
116 			return(IPADDRESS);
117 		}
118 
119 {hyphen}	{ return(HYPHEN); }
120 
121 {ws}		{ ; }
122 {nl}		{ ; }
123 
124 %%
125 
126 void
127 __policy__strbuffer__init__(msg)
128 	char *msg;
129 {
130 	YY_BUFFER_STATE yyb;
131 
132 	yyb = (YY_BUFFER_STATE)yy_scan_string(msg);
133 	yy_switch_to_buffer(yyb);
134 
135 	return;
136 }
137 
138