source: rtems-libbsd/ipsec-tools/src/libipsec/policy_token.l @ b376ae1

55-freebsd-126-freebsd-12
Last change on this file since b376ae1 was b376ae1, checked in by Christian Mauderer <christian.mauderer@…>, on 05/03/18 at 12:15:11

ipsec-tools: Port libipsec, setkey and racoon.

Note that this replaces the libipsec from FreeBSD with the one provided
by ipsec-tools.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*      $NetBSD: policy_token.l,v 1.7 2007/07/18 12:07:50 vanhu Exp $   */
2
3/* Id: policy_token.l,v 1.12 2005/05/05 12:32:18 manubsd Exp */
4
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#ifdef __rtems__
36#include <machine/rtems-bsd-user-space.h>
37#endif /* __rtems__ */
38#ifdef HAVE_CONFIG_H
39#include "config.h"
40#endif
41
42#include <sys/types.h>
43#include <sys/param.h>
44#include <sys/socket.h>
45#include <net/pfkeyv2.h>
46#include <netinet/in.h>
47#include PATH_IPSEC_H
48
49#include <stdlib.h>
50#include <limits.h>
51#include <string.h>
52#include <unistd.h>
53#include <errno.h>
54
55#include "libpfkey.h"
56
57#if !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__linux__)  && \
58!defined(__APPLE__) && !defined(__MACH__)
59#include "y.tab.h"
60#else
61#include "policy_parse.h"
62#endif
63#define yylval __libipseclval   /* XXX */
64
65int yylex __P((void));
66%}
67
68%option noyywrap
69%option nounput
70
71/* common section */
72nl              \n
73ws              [ \t]+
74digit           [0-9]
75hexdigit        [0-9A-Fa-f]
76special         [()+\|\?\*,]
77dot             \.
78comma           \,
79hyphen          \-
80colon           \:
81slash           \/
82bcl             \{
83ecl             \}
84blcl            \[
85elcl            \]
86percent         \%
87semi            \;
88plus    \+
89usec            {dot}{digit}{1,6}
90comment         \#.*
91ccomment        "/*"
92bracketstring   \<[^>]*\>
93quotedstring    \"[^"]*\"
94decstring       {digit}+
95hexpair         {hexdigit}{hexdigit}
96hexstring       0[xX]{hexdigit}+
97octetstring     {octet}({dot}{octet})+
98ipaddress       [a-zA-Z0-9:\._][a-zA-Z0-9:\._]*(%[a-zA-Z0-9]+)?
99
100%%
101
102in              { yylval.num = IPSEC_DIR_INBOUND; return(DIR); }
103out             { yylval.num = IPSEC_DIR_OUTBOUND; return(DIR); }
104fwd             {
105#ifdef HAVE_POLICY_FWD
106                  yylval.num = IPSEC_DIR_FWD; return(DIR);
107#else
108                  yylval.num = IPSEC_DIR_INBOUND; return(DIR);
109#endif
110                }
111
112priority        { return(PRIORITY); }
113prio    { return(PRIORITY); }
114low     { yylval.num32 = PRIORITY_LOW; return(PRIO_BASE); }
115def { yylval.num32 = PRIORITY_DEFAULT; return(PRIO_BASE); }
116high    { yylval.num32 = PRIORITY_HIGH; return(PRIO_BASE); }
117{plus}  { return(PLUS); }
118{decstring}     {
119                        yylval.val.len = strlen(yytext);
120                        yylval.val.buf = yytext;
121                        return(PRIO_OFFSET);
122}
123
124discard         { yylval.num = IPSEC_POLICY_DISCARD; return(ACTION); }
125none            { yylval.num = IPSEC_POLICY_NONE; return(ACTION); }
126ipsec           { yylval.num = IPSEC_POLICY_IPSEC; return(ACTION); }
127bypass          { yylval.num = IPSEC_POLICY_BYPASS; return(ACTION); }
128entrust         { yylval.num = IPSEC_POLICY_ENTRUST; return(ACTION); }
129
130esp             { yylval.num = IPPROTO_ESP; return(PROTOCOL); }
131ah              { yylval.num = IPPROTO_AH; return(PROTOCOL); }
132ipcomp          { yylval.num = IPPROTO_IPCOMP; return(PROTOCOL); }
133
134transport       { yylval.num = IPSEC_MODE_TRANSPORT; return(MODE); }
135tunnel          { yylval.num = IPSEC_MODE_TUNNEL; return(MODE); }
136
137me              { return(ME); }
138any             { return(ANY); }
139
140default         { yylval.num = IPSEC_LEVEL_DEFAULT; return(LEVEL); }
141use             { yylval.num = IPSEC_LEVEL_USE; return(LEVEL); }
142require         { yylval.num = IPSEC_LEVEL_REQUIRE; return(LEVEL); }
143unique{colon}{decstring} {
144                        yylval.val.len = strlen(yytext + 7);
145                        yylval.val.buf = yytext + 7;
146                        return(LEVEL_SPECIFY);
147                }
148unique          { yylval.num = IPSEC_LEVEL_UNIQUE; return(LEVEL); }
149{slash}         { return(SLASH); }
150
151{ipaddress}     {
152                        yylval.val.len = strlen(yytext);
153                        yylval.val.buf = yytext;
154                        return(IPADDRESS);
155                }
156
157{hyphen}        { return(HYPHEN); }
158
159{blcl}{decstring}{elcl} {
160                        /* Remove leading '[' and trailing ']' */
161                        yylval.val.buf = yytext + 1;
162                        yylval.val.len = strlen(yytext) - 2;
163
164                        return(PORT);
165                }
166
167{ws}            { ; }
168{nl}            { ; }
169
170%%
171
172void __policy__strbuffer__init__ __P((char *));
173void __policy__strbuffer__free__ __P((void));
174
175static YY_BUFFER_STATE strbuffer;
176
177void
178__policy__strbuffer__init__(msg)
179        char *msg;
180{
181        if (YY_CURRENT_BUFFER)
182                yy_delete_buffer(YY_CURRENT_BUFFER);
183        strbuffer = (YY_BUFFER_STATE)yy_scan_string(msg);
184        yy_switch_to_buffer(strbuffer);
185
186        return;
187}
188
189void
190__policy__strbuffer__free__()
191{
192        yy_delete_buffer(strbuffer);
193
194        return;
195}
Note: See TracBrowser for help on using the repository browser.