xref: /freebsd-src/lib/libipsec/policy_token.l (revision 2a63c3be158216222d89a073dcbd6a72ee4aab5a)
1bd9f52d5SHajimu UMEMOTO /*	$KAME: policy_token.l,v 1.13 2003/05/09 05:19:55 sakane Exp $	*/
23c62e87aSJun-ichiro itojun Hagino 
38a16b7a1SPedro F. Giffuni /*-
48a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
58a16b7a1SPedro F. Giffuni  *
69a4365d0SYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
79a4365d0SYoshinobu Inoue  * All rights reserved.
89a4365d0SYoshinobu Inoue  *
99a4365d0SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
109a4365d0SYoshinobu Inoue  * modification, are permitted provided that the following conditions
119a4365d0SYoshinobu Inoue  * are met:
129a4365d0SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
139a4365d0SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
149a4365d0SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
159a4365d0SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
169a4365d0SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
179a4365d0SYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
189a4365d0SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
199a4365d0SYoshinobu Inoue  *    without specific prior written permission.
209a4365d0SYoshinobu Inoue  *
219a4365d0SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
229a4365d0SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
239a4365d0SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
249a4365d0SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
259a4365d0SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
269a4365d0SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
279a4365d0SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
289a4365d0SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
299a4365d0SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
309a4365d0SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
319a4365d0SYoshinobu Inoue  * SUCH DAMAGE.
329a4365d0SYoshinobu Inoue  */
339a4365d0SYoshinobu Inoue 
349a4365d0SYoshinobu Inoue %{
359a4365d0SYoshinobu Inoue #include <sys/types.h>
369a4365d0SYoshinobu Inoue #include <sys/param.h>
379a4365d0SYoshinobu Inoue #include <sys/socket.h>
389a4365d0SYoshinobu Inoue #include <net/route.h>
399a4365d0SYoshinobu Inoue #include <net/pfkeyv2.h>
408409aedfSGeorge V. Neville-Neil #include <netipsec/keydb.h>
419a4365d0SYoshinobu Inoue #include <netinet/in.h>
428409aedfSGeorge V. Neville-Neil #include <netipsec/ipsec.h>
439a4365d0SYoshinobu Inoue 
449a4365d0SYoshinobu Inoue #include <stdlib.h>
459a4365d0SYoshinobu Inoue #include <limits.h>
469a4365d0SYoshinobu Inoue #include <string.h>
479a4365d0SYoshinobu Inoue #include <unistd.h>
489a4365d0SYoshinobu Inoue #include <errno.h>
499a4365d0SYoshinobu Inoue 
509a4365d0SYoshinobu Inoue #include "y.tab.h"
51f018cfadSYoshinobu Inoue #define yylval __libipsecyylval	/* XXX */
523c62e87aSJun-ichiro itojun Hagino 
5369160b1eSDavid E. O'Brien int yylex(void);
549a4365d0SYoshinobu Inoue %}
559a4365d0SYoshinobu Inoue 
569a4365d0SYoshinobu Inoue %option noyywrap
5733841545SHajimu UMEMOTO %option nounput
587a692f29SDimitry Andric %option noinput
599a4365d0SYoshinobu Inoue 
609a4365d0SYoshinobu Inoue /* common section */
619a4365d0SYoshinobu Inoue nl		\n
629a4365d0SYoshinobu Inoue ws		[ \t]+
639a4365d0SYoshinobu Inoue digit		[0-9]
649a4365d0SYoshinobu Inoue hexdigit	[0-9A-Fa-f]
659a4365d0SYoshinobu Inoue special		[()+\|\?\*,]
669a4365d0SYoshinobu Inoue dot		\.
679a4365d0SYoshinobu Inoue comma		\,
689a4365d0SYoshinobu Inoue hyphen		\-
699a4365d0SYoshinobu Inoue colon		\:
709a4365d0SYoshinobu Inoue slash		\/
719a4365d0SYoshinobu Inoue bcl		\{
729a4365d0SYoshinobu Inoue ecl		\}
739a4365d0SYoshinobu Inoue blcl		\[
749a4365d0SYoshinobu Inoue elcl		\]
759a4365d0SYoshinobu Inoue percent		\%
769a4365d0SYoshinobu Inoue semi		\;
779a4365d0SYoshinobu Inoue usec		{dot}{digit}{1,6}
789a4365d0SYoshinobu Inoue comment		\#.*
799a4365d0SYoshinobu Inoue ccomment	"/*"
809a4365d0SYoshinobu Inoue bracketstring	\<[^>]*\>
819a4365d0SYoshinobu Inoue quotedstring	\"[^"]*\"
829a4365d0SYoshinobu Inoue decstring	{digit}+
839a4365d0SYoshinobu Inoue hexpair		{hexdigit}{hexdigit}
849a4365d0SYoshinobu Inoue hexstring	0[xX]{hexdigit}+
859a4365d0SYoshinobu Inoue octetstring	{octet}({dot}{octet})+
863c62e87aSJun-ichiro itojun Hagino ipaddress	[a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)?
879a4365d0SYoshinobu Inoue 
889a4365d0SYoshinobu Inoue %%
899a4365d0SYoshinobu Inoue 
909a4365d0SYoshinobu Inoue in		{ yylval.num = IPSEC_DIR_INBOUND; return(DIR); }
919a4365d0SYoshinobu Inoue out		{ yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); }
929a4365d0SYoshinobu Inoue 
939a4365d0SYoshinobu Inoue discard		{ yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); }
949a4365d0SYoshinobu Inoue none		{ yylval.num = IPSEC_POLICY_NONE; return(ACTION); }
959a4365d0SYoshinobu Inoue ipsec		{ yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); }
969a4365d0SYoshinobu Inoue bypass		{ yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); }
979a4365d0SYoshinobu Inoue entrust		{ yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); }
989a4365d0SYoshinobu Inoue 
999a4365d0SYoshinobu Inoue esp		{ yylval.num = IPPROTO_ESP; return(PROTOCOL); }
1009a4365d0SYoshinobu Inoue ah		{ yylval.num = IPPROTO_AH; return(PROTOCOL); }
1019a4365d0SYoshinobu Inoue ipcomp		{ yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); }
1021922fd12SBruce M Simpson tcp		{ yylval.num = IPPROTO_TCP; return(PROTOCOL); }
1039a4365d0SYoshinobu Inoue 
1049a4365d0SYoshinobu Inoue transport	{ yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
1059a4365d0SYoshinobu Inoue tunnel		{ yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
1069a4365d0SYoshinobu Inoue 
1079a4365d0SYoshinobu Inoue me		{ return(ME); }
1089a4365d0SYoshinobu Inoue any		{ return(ANY); }
1099a4365d0SYoshinobu Inoue 
1109a4365d0SYoshinobu Inoue default		{ yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); }
1119a4365d0SYoshinobu Inoue use		{ yylval.num = IPSEC_LEVEL_USE; return(LEVEL); }
1129a4365d0SYoshinobu Inoue require		{ yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); }
1133c62e87aSJun-ichiro itojun Hagino unique{colon}{decstring} {
1143c62e87aSJun-ichiro itojun Hagino 			yylval.val.len = strlen(yytext + 7);
1153c62e87aSJun-ichiro itojun Hagino 			yylval.val.buf = yytext + 7;
1163c62e87aSJun-ichiro itojun Hagino 			return(LEVEL_SPECIFY);
1173c62e87aSJun-ichiro itojun Hagino 		}
1189a4365d0SYoshinobu Inoue unique		{ yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
1199a4365d0SYoshinobu Inoue {slash}		{ return(SLASH); }
1209a4365d0SYoshinobu Inoue 
1219a4365d0SYoshinobu Inoue {ipaddress}	{
1229a4365d0SYoshinobu Inoue 			yylval.val.len = strlen(yytext);
1233c62e87aSJun-ichiro itojun Hagino 			yylval.val.buf = yytext;
1249a4365d0SYoshinobu Inoue 			return(IPADDRESS);
1259a4365d0SYoshinobu Inoue 		}
1269a4365d0SYoshinobu Inoue 
1279a4365d0SYoshinobu Inoue {hyphen}	{ return(HYPHEN); }
1289a4365d0SYoshinobu Inoue 
1299a4365d0SYoshinobu Inoue {ws}		{ ; }
1309a4365d0SYoshinobu Inoue {nl}		{ ; }
1319a4365d0SYoshinobu Inoue 
1329a4365d0SYoshinobu Inoue %%
1339a4365d0SYoshinobu Inoue 
13469160b1eSDavid E. O'Brien void __policy__strbuffer__init__(char *);
135bd9f52d5SHajimu UMEMOTO void __policy__strbuffer__free__(void);
136bd9f52d5SHajimu UMEMOTO 
137bd9f52d5SHajimu UMEMOTO static YY_BUFFER_STATE strbuffer;
1383c62e87aSJun-ichiro itojun Hagino 
1399a4365d0SYoshinobu Inoue void
140*58436df3SMateusz Guzik __policy__strbuffer__init__(char *msg)
1419a4365d0SYoshinobu Inoue {
142a7880d59SJung-uk Kim 	if (YY_CURRENT_BUFFER)
143a7880d59SJung-uk Kim 		yy_delete_buffer(YY_CURRENT_BUFFER);
144bd9f52d5SHajimu UMEMOTO 	strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg);
145bd9f52d5SHajimu UMEMOTO 	yy_switch_to_buffer(strbuffer);
1469a4365d0SYoshinobu Inoue 
1479a4365d0SYoshinobu Inoue 	return;
1489a4365d0SYoshinobu Inoue }
1499a4365d0SYoshinobu Inoue 
150bd9f52d5SHajimu UMEMOTO void
151*58436df3SMateusz Guzik __policy__strbuffer__free__(void)
152bd9f52d5SHajimu UMEMOTO {
153bd9f52d5SHajimu UMEMOTO 	yy_delete_buffer(strbuffer);
154bd9f52d5SHajimu UMEMOTO 
155bd9f52d5SHajimu UMEMOTO 	return;
156bd9f52d5SHajimu UMEMOTO }
157