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