policy_token.l revision 125681
162583Sitojun/* $FreeBSD: head/lib/libipsec/policy_token.l 125681 2004-02-11 04:34:34Z bms $ */ 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); } 100125681Sbmstcp { yylval.num = IPPROTO_TCP; return(PROTOCOL); } 10155505Sshin 10255505Sshintransport { yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); } 10355505Sshintunnel { yylval.num = IPSEC_MODE_TUNNEL; return(MODE); } 10455505Sshin 10555505Sshinme { return(ME); } 10655505Sshinany { return(ANY); } 10755505Sshin 10855505Sshindefault { yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); } 10955505Sshinuse { yylval.num = IPSEC_LEVEL_USE; return(LEVEL); } 11055505Sshinrequire { yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); } 11162583Sitojununique{colon}{decstring} { 11262583Sitojun yylval.val.len = strlen(yytext + 7); 11362583Sitojun yylval.val.buf = yytext + 7; 11462583Sitojun return(LEVEL_SPECIFY); 11562583Sitojun } 11655505Sshinunique { yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); } 11755505Sshin{slash} { return(SLASH); } 11855505Sshin 11955505Sshin{ipaddress} { 12055505Sshin yylval.val.len = strlen(yytext); 12162583Sitojun yylval.val.buf = yytext; 12255505Sshin return(IPADDRESS); 12355505Sshin } 12455505Sshin 12555505Sshin{hyphen} { return(HYPHEN); } 12655505Sshin 12755505Sshin{ws} { ; } 12855505Sshin{nl} { ; } 12955505Sshin 13055505Sshin%% 13155505Sshin 13292917Sobrienvoid __policy__strbuffer__init__(char *); 133122107Sumevoid __policy__strbuffer__free__(void); 13462583Sitojun 135122107Sumestatic YY_BUFFER_STATE strbuffer; 136122107Sume 13755505Sshinvoid 13855505Sshin__policy__strbuffer__init__(msg) 13955505Sshin char *msg; 14055505Sshin{ 141122107Sume if (yy_current_buffer) 142122107Sume yy_delete_buffer(yy_current_buffer); 143122107Sume strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg); 144122107Sume yy_switch_to_buffer(strbuffer); 14555505Sshin 146122107Sume return; 147122107Sume} 14855505Sshin 149122107Sumevoid 150122107Sume__policy__strbuffer__free__() 151122107Sume{ 152122107Sume yy_delete_buffer(strbuffer); 153122107Sume 15455505Sshin return; 15555505Sshin} 156