npf_scan.l revision 1.1.4.2 1 /* $NetBSD: npf_scan.l,v 1.1.4.2 2012/04/17 00:09:50 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 2011-2012 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Martin Husemann.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 %{
33 #include <stdio.h>
34 #include <err.h>
35
36 #include "npfctl.h"
37 #include "npf_parse.h"
38
39 int yycolumn;
40
41 #define YY_USER_ACTION yycolumn += yyleng;
42
43 %}
44
45 %option noyywrap nounput noinput
46
47 ID [a-zA-Z_][a-zA-Z_0-9]*
48 NID [a-zA-Z_0-9]+
49 NUMBER [0-9]+
50
51 %%
52 table return TABLE;
53 type return TYPE;
54 hash return HASH;
55 tree return TREE;
56 dynamic return TDYNAMIC;
57 file return TFILE;
58 nat return NAT;
59 binat return BINAT;
60 "->" return ARROW;
61 "-" return MINUS;
62 rdr return RDR;
63 procedure return PROCEDURE;
64 \n yylineno++; yycolumn = 0; return SEPLINE;
65 ; return SEPLINE;
66 name return NAME;
67 group return GROUP;
68 default return DEFAULT;
69 in return IN;
70 out return OUT;
71 interface return INTERFACE;
72 all return ALL;
73 block return BLOCK;
74 pass return PASS;
75 keep return KEEP;
76 state return STATE;
77 apply return APPLY;
78 quick return QUICK;
79 on return ON;
80 inet6 return INET6;
81 inet4 return INET;
82 inet return INET;
83 proto return PROTO;
84 family return FAMILY;
85 tcp return TCP;
86 icmp return ICMP;
87 udp return UDP;
88 return-rst return RETURNRST;
89 return-icmp return RETURNICMP;
90 return return RETURN;
91 from return FROM;
92 to return TO;
93 port return PORT;
94 flags return FLAGS;
95 icmp-type return ICMPTYPE;
96 code return CODE;
97 any return ANY;
98
99 "/" return SLASH;
100 "{" return CURLY_OPEN;
101 "}" return CURLY_CLOSE;
102 "(" return PAR_OPEN;
103 ")" return PAR_CLOSE;
104 "," return COMMA;
105 "=" return EQ;
106
107 "0x"[0-9a-fA-F]+ {
108 char *endp, *buf = zalloc(yyleng + 1);
109 buf[yyleng] = 0;
110 yylval.num = strtoul(buf+2, &endp, 16);
111 free(buf);
112 return HEX;
113 }
114
115 [0-9a-fA-F]+":"[0-9a-fA-F:]* {
116 yylval.str = xstrndup(yytext, yyleng);
117 return IPV6ADDR;
118 }
119
120 {NUMBER}"."[0-9][0-9.]* {
121 yylval.str = xstrndup(yytext, yyleng);
122 return IPV4ADDR;
123 }
124
125 {NUMBER} {
126 char *endp, *buf = xstrndup(yytext, yyleng);
127 yylval.num = strtoul(buf, &endp, 10);
128 free(buf);
129 return NUM;
130 }
131
132 "<"{NID}">" {
133 yylval.str = xstrndup(yytext + 1, yyleng - 2);
134 return TABLE_ID;
135 }
136
137 "$"{NID} {
138 yylval.str = xstrndup(yytext + 1, yyleng - 1);
139 return VAR_ID;
140 }
141
142 {ID} {
143 yylval.str = xstrndup(yytext, yyleng);
144 return IDENTIFIER;
145 }
146
147 \"[^\"]*\" {
148 yylval.str = xstrndup(yytext + 1, yyleng - 2);
149 return STRING;
150 }
151
152 #.*$ /* drop comment until end of line */
153 [ \t] /* eat whitespace */
154
155 : return COLON;
156