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