1 /* $FreeBSD$ */ 2 /* $KAME: policy_token.l,v 1.13 2003/05/09 05:19:55 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 #include "y.tab.h" 50 #define yylval __libipsecyylval /* XXX */ 51 52 int yylex(void); 53 %} 54 55 %option noyywrap 56 %option nounput 57 58 /* common section */ 59 nl \n 60 ws [ \t]+ 61 digit [0-9] 62 hexdigit [0-9A-Fa-f] 63 special [()+\|\?\*,] 64 dot \. 65 comma \, 66 hyphen \- 67 colon \: 68 slash \/ 69 bcl \{ 70 ecl \} 71 blcl \[ 72 elcl \] 73 percent \% 74 semi \; 75 usec {dot}{digit}{1,6} 76 comment \#.* 77 ccomment "/*" 78 bracketstring \<[^>]*\> 79 quotedstring \"[^"]*\" 80 decstring {digit}+ 81 hexpair {hexdigit}{hexdigit} 82 hexstring 0[xX]{hexdigit}+ 83 octetstring {octet}({dot}{octet})+ 84 ipaddress [a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)? 85 86 %% 87 88 in { yylval.num = IPSEC_DIR_INBOUND; return(DIR); } 89 out { yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); } 90 91 discard { yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); } 92 none { yylval.num = IPSEC_POLICY_NONE; return(ACTION); } 93 ipsec { yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); } 94 bypass { yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); } 95 entrust { yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); } 96 97 esp { yylval.num = IPPROTO_ESP; return(PROTOCOL); } 98 ah { yylval.num = IPPROTO_AH; return(PROTOCOL); } 99 ipcomp { yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); } 100 tcp { yylval.num = IPPROTO_TCP; return(PROTOCOL); } 101 102 transport { yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); } 103 tunnel { yylval.num = IPSEC_MODE_TUNNEL; return(MODE); } 104 105 me { return(ME); } 106 any { return(ANY); } 107 108 default { yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); } 109 use { yylval.num = IPSEC_LEVEL_USE; return(LEVEL); } 110 require { yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); } 111 unique{colon}{decstring} { 112 yylval.val.len = strlen(yytext + 7); 113 yylval.val.buf = yytext + 7; 114 return(LEVEL_SPECIFY); 115 } 116 unique { yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); } 117 {slash} { return(SLASH); } 118 119 {ipaddress} { 120 yylval.val.len = strlen(yytext); 121 yylval.val.buf = yytext; 122 return(IPADDRESS); 123 } 124 125 {hyphen} { return(HYPHEN); } 126 127 {ws} { ; } 128 {nl} { ; } 129 130 %% 131 132 void __policy__strbuffer__init__(char *); 133 void __policy__strbuffer__free__(void); 134 135 static YY_BUFFER_STATE strbuffer; 136 137 void 138 __policy__strbuffer__init__(msg) 139 char *msg; 140 { 141 if (yy_current_buffer) 142 yy_delete_buffer(yy_current_buffer); 143 strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg); 144 yy_switch_to_buffer(strbuffer); 145 146 return; 147 } 148 149 void 150 __policy__strbuffer__free__() 151 { 152 yy_delete_buffer(strbuffer); 153 154 return; 155 } 156