policy_token.l revision 250227
162583Sitojun/* $FreeBSD: head/lib/libipsec/policy_token.l 250227 2013-05-03 23:51:32Z jkim $ */ 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> 39171135Sgnn#include <netipsec/keydb.h> 4055505Sshin#include <netinet/in.h> 41171135Sgnn#include <netipsec/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 57228555Sdim%option noinput 5855505Sshin 5955505Sshin/* common section */ 6055505Sshinnl \n 6155505Sshinws [ \t]+ 6255505Sshindigit [0-9] 6355505Sshinhexdigit [0-9A-Fa-f] 6455505Sshinspecial [()+\|\?\*,] 6555505Sshindot \. 6655505Sshincomma \, 6755505Sshinhyphen \- 6855505Sshincolon \: 6955505Sshinslash \/ 7055505Sshinbcl \{ 7155505Sshinecl \} 7255505Sshinblcl \[ 7355505Sshinelcl \] 7455505Sshinpercent \% 7555505Sshinsemi \; 7655505Sshinusec {dot}{digit}{1,6} 7755505Sshincomment \#.* 7855505Sshinccomment "/*" 7955505Sshinbracketstring \<[^>]*\> 8055505Sshinquotedstring \"[^"]*\" 8155505Sshindecstring {digit}+ 8255505Sshinhexpair {hexdigit}{hexdigit} 8355505Sshinhexstring 0[xX]{hexdigit}+ 8455505Sshinoctetstring {octet}({dot}{octet})+ 8562583Sitojunipaddress [a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)? 8655505Sshin 8755505Sshin%% 8855505Sshin 8955505Sshinin { yylval.num = IPSEC_DIR_INBOUND; return(DIR); } 9055505Sshinout { yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); } 9155505Sshin 9255505Sshindiscard { yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); } 9355505Sshinnone { yylval.num = IPSEC_POLICY_NONE; return(ACTION); } 9455505Sshinipsec { yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); } 9555505Sshinbypass { yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); } 9655505Sshinentrust { yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); } 9755505Sshin 9855505Sshinesp { yylval.num = IPPROTO_ESP; return(PROTOCOL); } 9955505Sshinah { yylval.num = IPPROTO_AH; return(PROTOCOL); } 10055505Sshinipcomp { yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); } 101125681Sbmstcp { yylval.num = IPPROTO_TCP; return(PROTOCOL); } 10255505Sshin 10355505Sshintransport { yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); } 10455505Sshintunnel { yylval.num = IPSEC_MODE_TUNNEL; return(MODE); } 10555505Sshin 10655505Sshinme { return(ME); } 10755505Sshinany { return(ANY); } 10855505Sshin 10955505Sshindefault { yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); } 11055505Sshinuse { yylval.num = IPSEC_LEVEL_USE; return(LEVEL); } 11155505Sshinrequire { yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); } 11262583Sitojununique{colon}{decstring} { 11362583Sitojun yylval.val.len = strlen(yytext + 7); 11462583Sitojun yylval.val.buf = yytext + 7; 11562583Sitojun return(LEVEL_SPECIFY); 11662583Sitojun } 11755505Sshinunique { yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); } 11855505Sshin{slash} { return(SLASH); } 11955505Sshin 12055505Sshin{ipaddress} { 12155505Sshin yylval.val.len = strlen(yytext); 12262583Sitojun yylval.val.buf = yytext; 12355505Sshin return(IPADDRESS); 12455505Sshin } 12555505Sshin 12655505Sshin{hyphen} { return(HYPHEN); } 12755505Sshin 12855505Sshin{ws} { ; } 12955505Sshin{nl} { ; } 13055505Sshin 13155505Sshin%% 13255505Sshin 13392917Sobrienvoid __policy__strbuffer__init__(char *); 134122107Sumevoid __policy__strbuffer__free__(void); 13562583Sitojun 136122107Sumestatic YY_BUFFER_STATE strbuffer; 137122107Sume 13855505Sshinvoid 13955505Sshin__policy__strbuffer__init__(msg) 14055505Sshin char *msg; 14155505Sshin{ 142250227Sjkim if (YY_CURRENT_BUFFER) 143250227Sjkim yy_delete_buffer(YY_CURRENT_BUFFER); 144122107Sume strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg); 145122107Sume yy_switch_to_buffer(strbuffer); 14655505Sshin 147122107Sume return; 148122107Sume} 14955505Sshin 150122107Sumevoid 151122107Sume__policy__strbuffer__free__() 152122107Sume{ 153122107Sume yy_delete_buffer(strbuffer); 154122107Sume 15555505Sshin return; 15655505Sshin} 157