policy_token.l revision 55505
155505Sshin/*
255505Sshin * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
355505Sshin * All rights reserved.
455505Sshin *
555505Sshin * Redistribution and use in source and binary forms, with or without
655505Sshin * modification, are permitted provided that the following conditions
755505Sshin * are met:
855505Sshin * 1. Redistributions of source code must retain the above copyright
955505Sshin *    notice, this list of conditions and the following disclaimer.
1055505Sshin * 2. Redistributions in binary form must reproduce the above copyright
1155505Sshin *    notice, this list of conditions and the following disclaimer in the
1255505Sshin *    documentation and/or other materials provided with the distribution.
1355505Sshin * 3. Neither the name of the project nor the names of its contributors
1455505Sshin *    may be used to endorse or promote products derived from this software
1555505Sshin *    without specific prior written permission.
1655505Sshin *
1755505Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1855505Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1955505Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2055505Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2155505Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2255505Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2355505Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2455505Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2555505Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2655505Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2755505Sshin * SUCH DAMAGE.
2855505Sshin *
2955505Sshin * $FreeBSD: head/lib/libipsec/policy_token.l 55505 2000-01-06 12:40:54Z shin $
3055505Sshin */
3155505Sshin
3255505Sshin%{
3355505Sshin#include <sys/types.h>
3455505Sshin#include <sys/param.h>
3555505Sshin#include <sys/socket.h>
3655505Sshin#include <net/route.h>
3755505Sshin#include <net/pfkeyv2.h>
3855505Sshin#include <netkey/keydb.h>
3955505Sshin#include <netkey/key_debug.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"
5055505Sshin#define	yylval __libyylval	/* XXX */
5155505Sshin%}
5255505Sshin
5355505Sshin%option noyywrap
5455505Sshin
5555505Sshin/* common section */
5655505Sshinnl		\n
5755505Sshinws		[ \t]+
5855505Sshindigit		[0-9]
5955505Sshinletter		[0-9A-Za-z]
6055505Sshinhexdigit	[0-9A-Fa-f]
6155505Sshinspecial		[()+\|\?\*,]
6255505Sshindot		\.
6355505Sshincomma		\,
6455505Sshinhyphen		\-
6555505Sshincolon		\:
6655505Sshinslash		\/
6755505Sshinbcl		\{
6855505Sshinecl		\}
6955505Sshinblcl		\[
7055505Sshinelcl		\]
7155505Sshinpercent		\%
7255505Sshinsemi		\;
7355505Sshinusec		{dot}{digit}{1,6}
7455505Sshincomment		\#.*
7555505Sshinccomment	"/*"
7655505Sshinbracketstring	\<[^>]*\>
7755505Sshinquotedstring	\"[^"]*\"
7855505Sshindecstring	{digit}+
7955505Sshinhexpair		{hexdigit}{hexdigit}
8055505Sshinhexstring	0[xX]{hexdigit}+
8155505Sshinoctetstring	{octet}({dot}{octet})+
8255505Sshinipaddress	[a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(@{letter}{letter}+)?
8355505Sshinname		{letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
8455505Sshinhostname	{name}(({dot}{name})+{dot}?)?
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); }
11055505Sshinunique		{ yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
11155505Sshin{slash}		{ return(SLASH); }
11255505Sshin
11355505Sshin{ipaddress}	{
11455505Sshin			yylval.val.len = strlen(yytext);
11555505Sshin			yylval.val.buf = strdup(yytext);
11655505Sshin			return(IPADDRESS);
11755505Sshin		}
11855505Sshin
11955505Sshin{hyphen}	{ return(HYPHEN); }
12055505Sshin
12155505Sshin{ws}		{ ; }
12255505Sshin{nl}		{ ; }
12355505Sshin
12455505Sshin%%
12555505Sshin
12655505Sshinvoid
12755505Sshin__policy__strbuffer__init__(msg)
12855505Sshin	char *msg;
12955505Sshin{
13055505Sshin	YY_BUFFER_STATE yyb;
13155505Sshin
13255505Sshin	yyb = (YY_BUFFER_STATE)yy_scan_string(msg);
13355505Sshin	yy_switch_to_buffer(yyb);
13455505Sshin
13555505Sshin	return;
13655505Sshin}
13755505Sshin
138