policy_token.l revision 78064
162583Sitojun/*	$FreeBSD: head/lib/libipsec/policy_token.l 78064 2001-06-11 12:39:29Z ume $	*/
278064Sume/*	$KAME: policy_token.l,v 1.11 2000/12/01 10:08:29 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
4962583Sitojun#ifndef __NetBSD__
5055505Sshin#include "y.tab.h"
5162583Sitojun#else
5262583Sitojun#include "policy_parse.h"
5362583Sitojun#endif
5462583Sitojun#define yylval __libipsecyylval	/* XXX */
5562583Sitojun
5662583Sitojunint yylex __P((void));
5755505Sshin%}
5855505Sshin
5955505Sshin%option noyywrap
6078064Sume%option nounput
6155505Sshin
6255505Sshin/* common section */
6355505Sshinnl		\n
6455505Sshinws		[ \t]+
6555505Sshindigit		[0-9]
6655505Sshinhexdigit	[0-9A-Fa-f]
6755505Sshinspecial		[()+\|\?\*,]
6855505Sshindot		\.
6955505Sshincomma		\,
7055505Sshinhyphen		\-
7155505Sshincolon		\:
7255505Sshinslash		\/
7355505Sshinbcl		\{
7455505Sshinecl		\}
7555505Sshinblcl		\[
7655505Sshinelcl		\]
7755505Sshinpercent		\%
7855505Sshinsemi		\;
7955505Sshinusec		{dot}{digit}{1,6}
8055505Sshincomment		\#.*
8155505Sshinccomment	"/*"
8255505Sshinbracketstring	\<[^>]*\>
8355505Sshinquotedstring	\"[^"]*\"
8455505Sshindecstring	{digit}+
8555505Sshinhexpair		{hexdigit}{hexdigit}
8655505Sshinhexstring	0[xX]{hexdigit}+
8755505Sshinoctetstring	{octet}({dot}{octet})+
8862583Sitojunipaddress	[a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)?
8955505Sshin
9055505Sshin%%
9155505Sshin
9255505Sshinin		{ yylval.num = IPSEC_DIR_INBOUND; return(DIR); }
9355505Sshinout		{ yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); }
9455505Sshin
9555505Sshindiscard		{ yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); }
9655505Sshinnone		{ yylval.num = IPSEC_POLICY_NONE; return(ACTION); }
9755505Sshinipsec		{ yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); }
9855505Sshinbypass		{ yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); }
9955505Sshinentrust		{ yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); }
10055505Sshin
10155505Sshinesp		{ yylval.num = IPPROTO_ESP; return(PROTOCOL); }
10255505Sshinah		{ yylval.num = IPPROTO_AH; return(PROTOCOL); }
10355505Sshinipcomp		{ yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); }
10455505Sshin
10555505Sshintransport	{ yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
10655505Sshintunnel		{ yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
10755505Sshin
10855505Sshinme		{ return(ME); }
10955505Sshinany		{ return(ANY); }
11055505Sshin
11155505Sshindefault		{ yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); }
11255505Sshinuse		{ yylval.num = IPSEC_LEVEL_USE; return(LEVEL); }
11355505Sshinrequire		{ yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); }
11462583Sitojununique{colon}{decstring} {
11562583Sitojun			yylval.val.len = strlen(yytext + 7);
11662583Sitojun			yylval.val.buf = yytext + 7;
11762583Sitojun			return(LEVEL_SPECIFY);
11862583Sitojun		}
11955505Sshinunique		{ yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
12055505Sshin{slash}		{ return(SLASH); }
12155505Sshin
12255505Sshin{ipaddress}	{
12355505Sshin			yylval.val.len = strlen(yytext);
12462583Sitojun			yylval.val.buf = yytext;
12555505Sshin			return(IPADDRESS);
12655505Sshin		}
12755505Sshin
12855505Sshin{hyphen}	{ return(HYPHEN); }
12955505Sshin
13055505Sshin{ws}		{ ; }
13155505Sshin{nl}		{ ; }
13255505Sshin
13355505Sshin%%
13455505Sshin
13562583Sitojunvoid __policy__strbuffer__init__ __P((char *));
13662583Sitojun
13755505Sshinvoid
13855505Sshin__policy__strbuffer__init__(msg)
13955505Sshin	char *msg;
14055505Sshin{
14155505Sshin	YY_BUFFER_STATE yyb;
14255505Sshin
14355505Sshin	yyb = (YY_BUFFER_STATE)yy_scan_string(msg);
14455505Sshin	yy_switch_to_buffer(yyb);
14555505Sshin
14655505Sshin	return;
14755505Sshin}
14855505Sshin
149