policy_token.l revision 122107
162583Sitojun/*	$FreeBSD: head/lib/libipsec/policy_token.l 122107 2003-11-05 09:41:23Z ume $	*/
2122107Sume/*	$KAME: policy_token.l,v 1.13 2003/05/09 05:19:55 sakane Exp $	*/
362583Sitojun
455505Sshin/*
555505Sshin * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
655505Sshin * All rights reserved.
755505Sshin *
855505Sshin * Redistribution and use in source and binary forms, with or without
955505Sshin * modification, are permitted provided that the following conditions
1055505Sshin * are met:
1155505Sshin * 1. Redistributions of source code must retain the above copyright
1255505Sshin *    notice, this list of conditions and the following disclaimer.
1355505Sshin * 2. Redistributions in binary form must reproduce the above copyright
1455505Sshin *    notice, this list of conditions and the following disclaimer in the
1555505Sshin *    documentation and/or other materials provided with the distribution.
1655505Sshin * 3. Neither the name of the project nor the names of its contributors
1755505Sshin *    may be used to endorse or promote products derived from this software
1855505Sshin *    without specific prior written permission.
1955505Sshin *
2055505Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2155505Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2255505Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2355505Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2455505Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2555505Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2655505Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2755505Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2855505Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2955505Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3055505Sshin * SUCH DAMAGE.
3155505Sshin */
3255505Sshin
3355505Sshin%{
3455505Sshin#include <sys/types.h>
3555505Sshin#include <sys/param.h>
3655505Sshin#include <sys/socket.h>
3755505Sshin#include <net/route.h>
3855505Sshin#include <net/pfkeyv2.h>
3955505Sshin#include <netkey/keydb.h>
4055505Sshin#include <netinet/in.h>
4155505Sshin#include <netinet6/ipsec.h>
4255505Sshin
4355505Sshin#include <stdlib.h>
4455505Sshin#include <limits.h>
4555505Sshin#include <string.h>
4655505Sshin#include <unistd.h>
4755505Sshin#include <errno.h>
4855505Sshin
4955505Sshin#include "y.tab.h"
5062583Sitojun#define yylval __libipsecyylval	/* XXX */
5162583Sitojun
5292917Sobrienint yylex(void);
5355505Sshin%}
5455505Sshin
5555505Sshin%option noyywrap
5678064Sume%option nounput
5755505Sshin
5855505Sshin/* common section */
5955505Sshinnl		\n
6055505Sshinws		[ \t]+
6155505Sshindigit		[0-9]
6255505Sshinhexdigit	[0-9A-Fa-f]
6355505Sshinspecial		[()+\|\?\*,]
6455505Sshindot		\.
6555505Sshincomma		\,
6655505Sshinhyphen		\-
6755505Sshincolon		\:
6855505Sshinslash		\/
6955505Sshinbcl		\{
7055505Sshinecl		\}
7155505Sshinblcl		\[
7255505Sshinelcl		\]
7355505Sshinpercent		\%
7455505Sshinsemi		\;
7555505Sshinusec		{dot}{digit}{1,6}
7655505Sshincomment		\#.*
7755505Sshinccomment	"/*"
7855505Sshinbracketstring	\<[^>]*\>
7955505Sshinquotedstring	\"[^"]*\"
8055505Sshindecstring	{digit}+
8155505Sshinhexpair		{hexdigit}{hexdigit}
8255505Sshinhexstring	0[xX]{hexdigit}+
8355505Sshinoctetstring	{octet}({dot}{octet})+
8462583Sitojunipaddress	[a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)?
8555505Sshin
8655505Sshin%%
8755505Sshin
8855505Sshinin		{ yylval.num = IPSEC_DIR_INBOUND; return(DIR); }
8955505Sshinout		{ yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); }
9055505Sshin
9155505Sshindiscard		{ yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); }
9255505Sshinnone		{ yylval.num = IPSEC_POLICY_NONE; return(ACTION); }
9355505Sshinipsec		{ yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); }
9455505Sshinbypass		{ yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); }
9555505Sshinentrust		{ yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); }
9655505Sshin
9755505Sshinesp		{ yylval.num = IPPROTO_ESP; return(PROTOCOL); }
9855505Sshinah		{ yylval.num = IPPROTO_AH; return(PROTOCOL); }
9955505Sshinipcomp		{ yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); }
10055505Sshin
10155505Sshintransport	{ yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
10255505Sshintunnel		{ yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
10355505Sshin
10455505Sshinme		{ return(ME); }
10555505Sshinany		{ return(ANY); }
10655505Sshin
10755505Sshindefault		{ yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); }
10855505Sshinuse		{ yylval.num = IPSEC_LEVEL_USE; return(LEVEL); }
10955505Sshinrequire		{ yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); }
11062583Sitojununique{colon}{decstring} {
11162583Sitojun			yylval.val.len = strlen(yytext + 7);
11262583Sitojun			yylval.val.buf = yytext + 7;
11362583Sitojun			return(LEVEL_SPECIFY);
11462583Sitojun		}
11555505Sshinunique		{ yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
11655505Sshin{slash}		{ return(SLASH); }
11755505Sshin
11855505Sshin{ipaddress}	{
11955505Sshin			yylval.val.len = strlen(yytext);
12062583Sitojun			yylval.val.buf = yytext;
12155505Sshin			return(IPADDRESS);
12255505Sshin		}
12355505Sshin
12455505Sshin{hyphen}	{ return(HYPHEN); }
12555505Sshin
12655505Sshin{ws}		{ ; }
12755505Sshin{nl}		{ ; }
12855505Sshin
12955505Sshin%%
13055505Sshin
13192917Sobrienvoid __policy__strbuffer__init__(char *);
132122107Sumevoid __policy__strbuffer__free__(void);
13362583Sitojun
134122107Sumestatic YY_BUFFER_STATE strbuffer;
135122107Sume
13655505Sshinvoid
13755505Sshin__policy__strbuffer__init__(msg)
13855505Sshin	char *msg;
13955505Sshin{
140122107Sume	if (yy_current_buffer)
141122107Sume		yy_delete_buffer(yy_current_buffer);
142122107Sume	strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg);
143122107Sume	yy_switch_to_buffer(strbuffer);
14455505Sshin
145122107Sume	return;
146122107Sume}
14755505Sshin
148122107Sumevoid
149122107Sume__policy__strbuffer__free__()
150122107Sume{
151122107Sume	yy_delete_buffer(strbuffer);
152122107Sume
15355505Sshin	return;
15455505Sshin}
155