policy_token.l revision 92917
1/* $FreeBSD: head/lib/libipsec/policy_token.l 92917 2002-03-21 23:54:04Z obrien $ */ 2/* $KAME: policy_token.l,v 1.11 2000/12/01 10:08:29 sakane Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the project nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33%{ 34#include <sys/types.h> 35#include <sys/param.h> 36#include <sys/socket.h> 37#include <net/route.h> 38#include <net/pfkeyv2.h> 39#include <netkey/keydb.h> 40#include <netinet/in.h> 41#include <netinet6/ipsec.h> 42 43#include <stdlib.h> 44#include <limits.h> 45#include <string.h> 46#include <unistd.h> 47#include <errno.h> 48 49#ifndef __NetBSD__ 50#include "y.tab.h" 51#else 52#include "policy_parse.h" 53#endif 54#define yylval __libipsecyylval /* XXX */ 55 56int yylex(void); 57%} 58 59%option noyywrap 60%option nounput 61 62/* common section */ 63nl \n 64ws [ \t]+ 65digit [0-9] 66hexdigit [0-9A-Fa-f] 67special [()+\|\?\*,] 68dot \. 69comma \, 70hyphen \- 71colon \: 72slash \/ 73bcl \{ 74ecl \} 75blcl \[ 76elcl \] 77percent \% 78semi \; 79usec {dot}{digit}{1,6} 80comment \#.* 81ccomment "/*" 82bracketstring \<[^>]*\> 83quotedstring \"[^"]*\" 84decstring {digit}+ 85hexpair {hexdigit}{hexdigit} 86hexstring 0[xX]{hexdigit}+ 87octetstring {octet}({dot}{octet})+ 88ipaddress [a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)? 89 90%% 91 92in { yylval.num = IPSEC_DIR_INBOUND; return(DIR); } 93out { yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); } 94 95discard { yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); } 96none { yylval.num = IPSEC_POLICY_NONE; return(ACTION); } 97ipsec { yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); } 98bypass { yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); } 99entrust { yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); } 100 101esp { yylval.num = IPPROTO_ESP; return(PROTOCOL); } 102ah { yylval.num = IPPROTO_AH; return(PROTOCOL); } 103ipcomp { yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); } 104 105transport { yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); } 106tunnel { yylval.num = IPSEC_MODE_TUNNEL; return(MODE); } 107 108me { return(ME); } 109any { return(ANY); } 110 111default { yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); } 112use { yylval.num = IPSEC_LEVEL_USE; return(LEVEL); } 113require { yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); } 114unique{colon}{decstring} { 115 yylval.val.len = strlen(yytext + 7); 116 yylval.val.buf = yytext + 7; 117 return(LEVEL_SPECIFY); 118 } 119unique { yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); } 120{slash} { return(SLASH); } 121 122{ipaddress} { 123 yylval.val.len = strlen(yytext); 124 yylval.val.buf = yytext; 125 return(IPADDRESS); 126 } 127 128{hyphen} { return(HYPHEN); } 129 130{ws} { ; } 131{nl} { ; } 132 133%% 134 135void __policy__strbuffer__init__(char *); 136 137void 138__policy__strbuffer__init__(msg) 139 char *msg; 140{ 141 YY_BUFFER_STATE yyb; 142 143 yyb = (YY_BUFFER_STATE)yy_scan_string(msg); 144 yy_switch_to_buffer(yyb); 145 146 return; 147} 148 149