npf_parse.y revision 1.55 1 1.1 rmind /*-
2 1.55 joe * Copyright (c) 2011-2025 The NetBSD Foundation, Inc.
3 1.1 rmind * All rights reserved.
4 1.1 rmind *
5 1.1 rmind * This code is derived from software contributed to The NetBSD Foundation
6 1.26 rmind * by Martin Husemann, Christos Zoulas and Mindaugas Rasiukevicius.
7 1.1 rmind *
8 1.1 rmind * Redistribution and use in source and binary forms, with or without
9 1.1 rmind * modification, are permitted provided that the following conditions
10 1.1 rmind * are met:
11 1.1 rmind * 1. Redistributions of source code must retain the above copyright
12 1.1 rmind * notice, this list of conditions and the following disclaimer.
13 1.1 rmind * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 rmind * notice, this list of conditions and the following disclaimer in the
15 1.1 rmind * documentation and/or other materials provided with the distribution.
16 1.1 rmind *
17 1.1 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 1.1 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 1.1 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 1.1 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 1.1 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 1.1 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 1.1 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 1.1 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 1.1 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 1.1 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1 rmind * POSSIBILITY OF SUCH DAMAGE.
28 1.1 rmind */
29 1.1 rmind
30 1.1 rmind %{
31 1.1 rmind
32 1.37 joerg #include <err.h>
33 1.37 joerg #include <netdb.h>
34 1.1 rmind #include <stdio.h>
35 1.37 joerg #include <stdlib.h>
36 1.37 joerg #include <string.h>
37 1.42 rmind #ifdef __NetBSD__
38 1.1 rmind #include <vis.h>
39 1.42 rmind #endif
40 1.1 rmind
41 1.1 rmind #include "npfctl.h"
42 1.1 rmind
43 1.12 rmind #define YYSTACKSIZE 4096
44 1.12 rmind
45 1.50 rmind int yystarttoken;
46 1.1 rmind const char * yyfilename;
47 1.1 rmind
48 1.1 rmind extern int yylineno, yycolumn;
49 1.50 rmind extern int yylex(int);
50 1.1 rmind
51 1.1 rmind void
52 1.1 rmind yyerror(const char *fmt, ...)
53 1.1 rmind {
54 1.1 rmind extern int yyleng;
55 1.1 rmind extern char *yytext;
56 1.1 rmind
57 1.15 rmind char *msg, *context = estrndup(yytext, yyleng);
58 1.14 rmind bool eol = (*context == '\n');
59 1.1 rmind va_list ap;
60 1.1 rmind
61 1.1 rmind va_start(ap, fmt);
62 1.1 rmind vasprintf(&msg, fmt, ap);
63 1.1 rmind va_end(ap);
64 1.1 rmind
65 1.14 rmind fprintf(stderr, "%s:%d:%d: %s", yyfilename,
66 1.14 rmind yylineno - (int)eol, yycolumn, msg);
67 1.14 rmind if (!eol) {
68 1.42 rmind #ifdef __NetBSD__
69 1.14 rmind size_t len = strlen(context);
70 1.16 rmind char *dst = ecalloc(1, len * 4 + 1);
71 1.14 rmind
72 1.14 rmind strvisx(dst, context, len, VIS_WHITE|VIS_CSTYLE);
73 1.43 kre context = dst;
74 1.42 rmind #endif
75 1.42 rmind fprintf(stderr, " near '%s'", context);
76 1.14 rmind }
77 1.14 rmind fprintf(stderr, "\n");
78 1.1 rmind exit(EXIT_FAILURE);
79 1.1 rmind }
80 1.1 rmind
81 1.1 rmind %}
82 1.1 rmind
83 1.48 rmind /*
84 1.48 rmind * No conflicts allowed. Keep it this way.
85 1.48 rmind */
86 1.48 rmind %expect 0
87 1.48 rmind %expect-rr 0
88 1.48 rmind
89 1.50 rmind /*
90 1.50 rmind * Depending on the mode of operation, set a different start symbol.
91 1.50 rmind * Workaround yacc limitation by passing the start token.
92 1.50 rmind */
93 1.50 rmind %start input
94 1.50 rmind %token RULE_ENTRY_TOKEN MAP_ENTRY_TOKEN
95 1.50 rmind %lex-param { int yystarttoken }
96 1.50 rmind
97 1.50 rmind /*
98 1.50 rmind * General tokens.
99 1.50 rmind */
100 1.22 christos %token ALG
101 1.32 rmind %token ALGO
102 1.1 rmind %token ALL
103 1.1 rmind %token ANY
104 1.1 rmind %token APPLY
105 1.8 rmind %token ARROWBOTH
106 1.8 rmind %token ARROWLEFT
107 1.8 rmind %token ARROWRIGHT
108 1.1 rmind %token BLOCK
109 1.30 rmind %token CDB
110 1.48 rmind %token CONST
111 1.1 rmind %token CURLY_CLOSE
112 1.1 rmind %token CURLY_OPEN
113 1.1 rmind %token CODE
114 1.1 rmind %token COLON
115 1.1 rmind %token COMMA
116 1.1 rmind %token DEFAULT
117 1.1 rmind %token TDYNAMIC
118 1.8 rmind %token TSTATIC
119 1.1 rmind %token EQ
120 1.39 rmind %token EXCL_MARK
121 1.1 rmind %token TFILE
122 1.1 rmind %token FLAGS
123 1.1 rmind %token FROM
124 1.1 rmind %token GROUP
125 1.1 rmind %token HASH
126 1.1 rmind %token ICMPTYPE
127 1.1 rmind %token ID
128 1.48 rmind %token IFADDRS
129 1.1 rmind %token IN
130 1.29 rmind %token INET4
131 1.1 rmind %token INET6
132 1.1 rmind %token INTERFACE
133 1.51 rmind %token INVALID
134 1.48 rmind %token IPHASH
135 1.48 rmind %token IPSET
136 1.48 rmind %token LPM
137 1.8 rmind %token MAP
138 1.52 christos %token NEWLINE
139 1.46 rmind %token NO_PORTS
140 1.1 rmind %token MINUS
141 1.1 rmind %token NAME
142 1.48 rmind %token NETMAP
143 1.32 rmind %token NPT66
144 1.1 rmind %token ON
145 1.36 christos %token OFF
146 1.1 rmind %token OUT
147 1.1 rmind %token PAR_CLOSE
148 1.1 rmind %token PAR_OPEN
149 1.1 rmind %token PASS
150 1.26 rmind %token PCAP_FILTER
151 1.1 rmind %token PORT
152 1.1 rmind %token PROCEDURE
153 1.1 rmind %token PROTO
154 1.1 rmind %token FAMILY
155 1.7 rmind %token FINAL
156 1.18 rmind %token FORW
157 1.1 rmind %token RETURN
158 1.1 rmind %token RETURNICMP
159 1.1 rmind %token RETURNRST
160 1.48 rmind %token ROUNDROBIN
161 1.21 rmind %token RULESET
162 1.52 christos %token SEMICOLON
163 1.36 christos %token SET
164 1.1 rmind %token SLASH
165 1.7 rmind %token STATEFUL
166 1.49 rmind %token STATEFUL_ALL
167 1.1 rmind %token TABLE
168 1.1 rmind %token TCP
169 1.1 rmind %token TO
170 1.1 rmind %token TREE
171 1.1 rmind %token TYPE
172 1.54 joe %token USER
173 1.11 spz %token <num> ICMP
174 1.11 spz %token <num> ICMP6
175 1.1 rmind
176 1.1 rmind %token <num> HEX
177 1.1 rmind %token <str> IDENTIFIER
178 1.1 rmind %token <str> IPV4ADDR
179 1.1 rmind %token <str> IPV6ADDR
180 1.1 rmind %token <num> NUM
181 1.13 rmind %token <fpnum> FPNUM
182 1.1 rmind %token <str> STRING
183 1.49 rmind %token <str> PARAM
184 1.1 rmind %token <str> TABLE_ID
185 1.1 rmind %token <str> VAR_ID
186 1.1 rmind
187 1.48 rmind %type <str> addr some_name table_store dynamic_ifaddrs
188 1.48 rmind %type <str> proc_param_val opt_apply ifname on_ifname ifref
189 1.48 rmind %type <num> port opt_final number afamily opt_family
190 1.48 rmind %type <num> block_or_pass rule_dir group_dir block_opts
191 1.48 rmind %type <num> maybe_not opt_stateful icmp_type table_type
192 1.48 rmind %type <num> map_sd map_algo map_flags map_type
193 1.54 joe %type <num> param_val op_unary op_binary
194 1.54 joe %type <rid> uid gid
195 1.51 rmind %type <var> static_ifaddrs filt_addr_element
196 1.51 rmind %type <var> filt_port filt_port_list port_range icmp_type_and_code
197 1.48 rmind %type <var> filt_addr addr_and_mask tcp_flags tcp_flags_and_mask
198 1.48 rmind %type <var> procs proc_call proc_param_list proc_param
199 1.52 christos %type <var> element list_elems list_trail list value filt_addr_list
200 1.51 rmind %type <var> opt_proto proto proto_elems
201 1.8 rmind %type <addrport> mapseg
202 1.54 joe %type <uid> uids uid_item uid_list user_id
203 1.54 joe %type <gid> gids gid_item gid_list group_id
204 1.48 rmind %type <filtopts> filt_opts all_or_filt_opts
205 1.51 rmind %type <optproto> rawproto
206 1.26 rmind %type <rulegroup> group_opts
207 1.1 rmind
208 1.1 rmind %union {
209 1.1 rmind char * str;
210 1.1 rmind unsigned long num;
211 1.54 joe uint32_t rid;
212 1.13 rmind double fpnum;
213 1.17 rmind npfvar_t * var;
214 1.8 rmind addr_port_t addrport;
215 1.1 rmind filt_opts_t filtopts;
216 1.1 rmind opt_proto_t optproto;
217 1.1 rmind rule_group_t rulegroup;
218 1.54 joe struct r_id uid;
219 1.54 joe struct r_id gid;
220 1.1 rmind }
221 1.1 rmind
222 1.1 rmind %%
223 1.1 rmind
224 1.1 rmind input
225 1.50 rmind : lines
226 1.50 rmind | RULE_ENTRY_TOKEN rule
227 1.50 rmind | MAP_ENTRY_TOKEN map
228 1.1 rmind ;
229 1.1 rmind
230 1.1 rmind lines
231 1.52 christos : lines sepline line
232 1.1 rmind | line
233 1.1 rmind ;
234 1.1 rmind
235 1.1 rmind line
236 1.28 rmind : vardef
237 1.1 rmind | table
238 1.8 rmind | map
239 1.1 rmind | group
240 1.1 rmind | rproc
241 1.22 christos | alg
242 1.36 christos | set
243 1.1 rmind |
244 1.1 rmind ;
245 1.1 rmind
246 1.28 rmind alg
247 1.28 rmind : ALG STRING
248 1.28 rmind {
249 1.28 rmind npfctl_build_alg($2);
250 1.28 rmind }
251 1.28 rmind ;
252 1.28 rmind
253 1.52 christos sepline
254 1.52 christos : NEWLINE
255 1.52 christos | SEMICOLON
256 1.52 christos ;
257 1.52 christos
258 1.49 rmind param_val
259 1.49 rmind : number { $$ = $1; }
260 1.49 rmind | ON { $$ = true; }
261 1.49 rmind | OFF { $$ = false; }
262 1.36 christos ;
263 1.36 christos
264 1.36 christos set
265 1.49 rmind : SET PARAM param_val {
266 1.49 rmind npfctl_setparam($2, $3);
267 1.36 christos }
268 1.36 christos ;
269 1.36 christos
270 1.28 rmind /*
271 1.28 rmind * A value - an element or a list of elements.
272 1.28 rmind * Can be assigned to a variable or used inline.
273 1.28 rmind */
274 1.28 rmind
275 1.28 rmind vardef
276 1.29 rmind : VAR_ID EQ value
277 1.1 rmind {
278 1.29 rmind npfvar_add($3, $1);
279 1.1 rmind }
280 1.1 rmind ;
281 1.1 rmind
282 1.28 rmind value
283 1.28 rmind : element
284 1.28 rmind | list
285 1.1 rmind ;
286 1.1 rmind
287 1.28 rmind list
288 1.52 christos : CURLY_OPEN opt_nl list_elems CURLY_CLOSE
289 1.29 rmind {
290 1.52 christos $$ = $3;
291 1.29 rmind }
292 1.1 rmind ;
293 1.1 rmind
294 1.1 rmind list_elems
295 1.52 christos : element list_trail
296 1.29 rmind {
297 1.52 christos $$ = npfvar_add_elements($1, $2);
298 1.29 rmind }
299 1.1 rmind ;
300 1.1 rmind
301 1.28 rmind element
302 1.1 rmind : IDENTIFIER
303 1.1 rmind {
304 1.29 rmind $$ = npfvar_create_from_string(NPFVAR_IDENTIFIER, $1);
305 1.1 rmind }
306 1.1 rmind | STRING
307 1.1 rmind {
308 1.29 rmind $$ = npfvar_create_from_string(NPFVAR_STRING, $1);
309 1.1 rmind }
310 1.23 christos | number MINUS number
311 1.5 christos {
312 1.29 rmind $$ = npfctl_parse_port_range($1, $3);
313 1.5 christos }
314 1.23 christos | number
315 1.1 rmind {
316 1.29 rmind $$ = npfvar_create_element(NPFVAR_NUM, &$1, sizeof($1));
317 1.1 rmind }
318 1.1 rmind | VAR_ID
319 1.1 rmind {
320 1.29 rmind $$ = npfvar_create_from_string(NPFVAR_VAR_ID, $1);
321 1.1 rmind }
322 1.29 rmind | TABLE_ID { $$ = npfctl_parse_table_id($1); }
323 1.40 rmind | dynamic_ifaddrs { $$ = npfctl_ifnet_table($1); }
324 1.40 rmind | static_ifaddrs { $$ = $1; }
325 1.29 rmind | addr_and_mask { $$ = $1; }
326 1.1 rmind ;
327 1.1 rmind
328 1.52 christos list_trail
329 1.52 christos : element_sep element list_trail
330 1.52 christos {
331 1.52 christos $$ = npfvar_add_elements($2, $3);
332 1.52 christos }
333 1.52 christos | opt_nl { $$ = NULL; }
334 1.52 christos | element_sep { $$ = NULL; }
335 1.52 christos ;
336 1.52 christos
337 1.52 christos element_sep
338 1.52 christos : opt_nl COMMA opt_nl
339 1.52 christos ;
340 1.52 christos
341 1.52 christos opt_nl
342 1.52 christos : opt_nl NEWLINE
343 1.52 christos |
344 1.52 christos ;
345 1.52 christos
346 1.28 rmind /*
347 1.28 rmind * Table definition.
348 1.28 rmind */
349 1.28 rmind
350 1.1 rmind table
351 1.1 rmind : TABLE TABLE_ID TYPE table_type table_store
352 1.1 rmind {
353 1.1 rmind npfctl_build_table($2, $4, $5);
354 1.1 rmind }
355 1.1 rmind ;
356 1.1 rmind
357 1.1 rmind table_type
358 1.48 rmind : IPSET { $$ = NPF_TABLE_IPSET; }
359 1.48 rmind | HASH
360 1.48 rmind {
361 1.48 rmind warnx("warning - table type \"hash\" is deprecated and may be "
362 1.48 rmind "deleted in\nthe future; please use the \"ipset\" type "
363 1.48 rmind "instead.");
364 1.48 rmind $$ = NPF_TABLE_IPSET;
365 1.48 rmind }
366 1.48 rmind | LPM { $$ = NPF_TABLE_LPM; }
367 1.48 rmind | TREE
368 1.48 rmind {
369 1.48 rmind warnx("warning - table type \"tree\" is deprecated and may be "
370 1.48 rmind "deleted in\nthe future; please use the \"lpm\" type "
371 1.48 rmind "instead.");
372 1.48 rmind $$ = NPF_TABLE_LPM;
373 1.48 rmind }
374 1.48 rmind | CONST { $$ = NPF_TABLE_CONST; }
375 1.48 rmind | CDB
376 1.48 rmind {
377 1.48 rmind warnx("warning -- table type \"cdb\" is deprecated and may be "
378 1.48 rmind "deleted in\nthe future; please use the \"const\" type "
379 1.48 rmind "instead.");
380 1.48 rmind $$ = NPF_TABLE_CONST;
381 1.48 rmind }
382 1.1 rmind ;
383 1.1 rmind
384 1.1 rmind table_store
385 1.48 rmind : TFILE STRING { $$ = $2; }
386 1.48 rmind | TDYNAMIC
387 1.48 rmind {
388 1.48 rmind warnx("warning - the \"dynamic\" keyword for tables is obsolete");
389 1.48 rmind $$ = NULL;
390 1.48 rmind }
391 1.48 rmind | { $$ = NULL; }
392 1.1 rmind ;
393 1.1 rmind
394 1.28 rmind /*
395 1.28 rmind * Map definition.
396 1.28 rmind */
397 1.28 rmind
398 1.8 rmind map_sd
399 1.8 rmind : TSTATIC { $$ = NPFCTL_NAT_STATIC; }
400 1.8 rmind | TDYNAMIC { $$ = NPFCTL_NAT_DYNAMIC; }
401 1.8 rmind | { $$ = NPFCTL_NAT_DYNAMIC; }
402 1.1 rmind ;
403 1.1 rmind
404 1.32 rmind map_algo
405 1.48 rmind : ALGO NETMAP { $$ = NPF_ALGO_NETMAP; }
406 1.48 rmind | ALGO IPHASH { $$ = NPF_ALGO_IPHASH; }
407 1.48 rmind | ALGO ROUNDROBIN { $$ = NPF_ALGO_RR; }
408 1.48 rmind | ALGO NPT66 { $$ = NPF_ALGO_NPT66; }
409 1.48 rmind | { $$ = 0; }
410 1.32 rmind ;
411 1.32 rmind
412 1.46 rmind map_flags
413 1.46 rmind : NO_PORTS { $$ = NPF_NAT_PORTS; }
414 1.46 rmind | { $$ = 0; }
415 1.46 rmind ;
416 1.46 rmind
417 1.8 rmind map_type
418 1.8 rmind : ARROWBOTH { $$ = NPF_NATIN | NPF_NATOUT; }
419 1.8 rmind | ARROWLEFT { $$ = NPF_NATIN; }
420 1.8 rmind | ARROWRIGHT { $$ = NPF_NATOUT; }
421 1.8 rmind ;
422 1.8 rmind
423 1.8 rmind mapseg
424 1.51 rmind : filt_addr filt_port
425 1.1 rmind {
426 1.8 rmind $$.ap_netaddr = $1;
427 1.8 rmind $$.ap_portrange = $2;
428 1.1 rmind }
429 1.1 rmind ;
430 1.1 rmind
431 1.8 rmind map
432 1.46 rmind : MAP ifref map_sd map_algo map_flags mapseg map_type mapseg
433 1.48 rmind PASS opt_family opt_proto all_or_filt_opts
434 1.1 rmind {
435 1.51 rmind npfctl_build_natseg($3, $7, $5, $2, &$6, &$8, $11, &$12, $4);
436 1.1 rmind }
437 1.46 rmind | MAP ifref map_sd map_algo map_flags mapseg map_type mapseg
438 1.44 rmind {
439 1.46 rmind npfctl_build_natseg($3, $7, $5, $2, &$6, &$8, NULL, NULL, $4);
440 1.44 rmind }
441 1.46 rmind | MAP ifref map_sd map_algo map_flags proto mapseg map_type mapseg
442 1.1 rmind {
443 1.51 rmind npfctl_build_natseg($3, $8, $5, $2, &$7, &$9, $6, NULL, $4);
444 1.1 rmind }
445 1.26 rmind | MAP RULESET group_opts
446 1.21 rmind {
447 1.27 rmind npfctl_build_maprset($3.rg_name, $3.rg_attr, $3.rg_ifname);
448 1.21 rmind }
449 1.1 rmind ;
450 1.1 rmind
451 1.28 rmind /*
452 1.28 rmind * Rule procedure definition and its parameters.
453 1.28 rmind */
454 1.28 rmind
455 1.1 rmind rproc
456 1.1 rmind : PROCEDURE STRING CURLY_OPEN procs CURLY_CLOSE
457 1.1 rmind {
458 1.1 rmind npfctl_build_rproc($2, $4);
459 1.1 rmind }
460 1.1 rmind ;
461 1.1 rmind
462 1.1 rmind procs
463 1.52 christos : procs sepline proc_call
464 1.13 rmind {
465 1.13 rmind $$ = npfvar_add_elements($1, $3);
466 1.13 rmind }
467 1.13 rmind | proc_call { $$ = $1; }
468 1.1 rmind ;
469 1.1 rmind
470 1.13 rmind proc_call
471 1.13 rmind : IDENTIFIER COLON proc_param_list
472 1.1 rmind {
473 1.13 rmind proc_call_t pc;
474 1.1 rmind
475 1.15 rmind pc.pc_name = estrdup($1);
476 1.13 rmind pc.pc_opts = $3;
477 1.29 rmind
478 1.29 rmind $$ = npfvar_create_element(NPFVAR_PROC, &pc, sizeof(pc));
479 1.1 rmind }
480 1.29 rmind | { $$ = NULL; }
481 1.1 rmind ;
482 1.1 rmind
483 1.13 rmind proc_param_list
484 1.35 riastrad : proc_param_list COMMA proc_param
485 1.1 rmind {
486 1.1 rmind $$ = npfvar_add_elements($1, $3);
487 1.1 rmind }
488 1.13 rmind | proc_param { $$ = $1; }
489 1.1 rmind | { $$ = NULL; }
490 1.1 rmind ;
491 1.1 rmind
492 1.13 rmind proc_param
493 1.13 rmind : some_name proc_param_val
494 1.1 rmind {
495 1.13 rmind proc_param_t pp;
496 1.1 rmind
497 1.15 rmind pp.pp_param = estrdup($1);
498 1.15 rmind pp.pp_value = $2 ? estrdup($2) : NULL;
499 1.29 rmind
500 1.29 rmind $$ = npfvar_create_element(NPFVAR_PROC_PARAM, &pp, sizeof(pp));
501 1.1 rmind }
502 1.1 rmind ;
503 1.1 rmind
504 1.13 rmind proc_param_val
505 1.13 rmind : some_name { $$ = $1; }
506 1.23 christos | number { (void)asprintf(&$$, "%ld", $1); }
507 1.13 rmind | FPNUM { (void)asprintf(&$$, "%lf", $1); }
508 1.13 rmind | { $$ = NULL; }
509 1.1 rmind ;
510 1.1 rmind
511 1.28 rmind /*
512 1.28 rmind * Group and dynamic ruleset definition.
513 1.28 rmind */
514 1.28 rmind
515 1.1 rmind group
516 1.26 rmind : GROUP group_opts
517 1.1 rmind {
518 1.29 rmind /* Build a group. Increase the nesting level. */
519 1.26 rmind npfctl_build_group($2.rg_name, $2.rg_attr,
520 1.27 rmind $2.rg_ifname, $2.rg_default);
521 1.18 rmind }
522 1.18 rmind ruleset_block
523 1.18 rmind {
524 1.18 rmind /* Decrease the nesting level. */
525 1.18 rmind npfctl_build_group_end();
526 1.1 rmind }
527 1.1 rmind ;
528 1.1 rmind
529 1.21 rmind ruleset
530 1.26 rmind : RULESET group_opts
531 1.21 rmind {
532 1.21 rmind /* Ruleset is a dynamic group. */
533 1.26 rmind npfctl_build_group($2.rg_name, $2.rg_attr | NPF_RULE_DYNAMIC,
534 1.27 rmind $2.rg_ifname, $2.rg_default);
535 1.21 rmind npfctl_build_group_end();
536 1.21 rmind }
537 1.26 rmind ;
538 1.21 rmind
539 1.26 rmind group_dir
540 1.26 rmind : FORW { $$ = NPF_RULE_FORW; }
541 1.26 rmind | rule_dir
542 1.1 rmind ;
543 1.1 rmind
544 1.26 rmind group_opts
545 1.1 rmind : DEFAULT
546 1.1 rmind {
547 1.18 rmind memset(&$$, 0, sizeof(rule_group_t));
548 1.18 rmind $$.rg_default = true;
549 1.1 rmind }
550 1.27 rmind | STRING group_dir on_ifname
551 1.1 rmind {
552 1.18 rmind memset(&$$, 0, sizeof(rule_group_t));
553 1.26 rmind $$.rg_name = $1;
554 1.26 rmind $$.rg_attr = $2;
555 1.27 rmind $$.rg_ifname = $3;
556 1.1 rmind }
557 1.1 rmind ;
558 1.1 rmind
559 1.18 rmind ruleset_block
560 1.21 rmind : CURLY_OPEN ruleset_def CURLY_CLOSE
561 1.18 rmind ;
562 1.18 rmind
563 1.21 rmind ruleset_def
564 1.52 christos : ruleset_def sepline rule_group
565 1.18 rmind | rule_group
566 1.1 rmind ;
567 1.1 rmind
568 1.18 rmind rule_group
569 1.18 rmind : rule
570 1.18 rmind | group
571 1.21 rmind | ruleset
572 1.18 rmind |
573 1.24 rmind ;
574 1.1 rmind
575 1.28 rmind /*
576 1.28 rmind * Rule and misc.
577 1.28 rmind */
578 1.28 rmind
579 1.1 rmind rule
580 1.27 rmind : block_or_pass opt_stateful rule_dir opt_final on_ifname
581 1.17 rmind opt_family opt_proto all_or_filt_opts opt_apply
582 1.1 rmind {
583 1.7 rmind npfctl_build_rule($1 | $2 | $3 | $4, $5,
584 1.51 rmind $6, $7, &$8, NULL, $9);
585 1.26 rmind }
586 1.27 rmind | block_or_pass opt_stateful rule_dir opt_final on_ifname
587 1.26 rmind PCAP_FILTER STRING opt_apply
588 1.26 rmind {
589 1.26 rmind npfctl_build_rule($1 | $2 | $3 | $4, $5,
590 1.26 rmind AF_UNSPEC, NULL, NULL, $7, $8);
591 1.1 rmind }
592 1.1 rmind ;
593 1.1 rmind
594 1.1 rmind block_or_pass
595 1.1 rmind : BLOCK block_opts { $$ = $2; }
596 1.1 rmind | PASS { $$ = NPF_RULE_PASS; }
597 1.1 rmind ;
598 1.1 rmind
599 1.1 rmind rule_dir
600 1.1 rmind : IN { $$ = NPF_RULE_IN; }
601 1.1 rmind | OUT { $$ = NPF_RULE_OUT; }
602 1.1 rmind | { $$ = NPF_RULE_IN | NPF_RULE_OUT; }
603 1.1 rmind ;
604 1.1 rmind
605 1.7 rmind opt_final
606 1.7 rmind : FINAL { $$ = NPF_RULE_FINAL; }
607 1.1 rmind | { $$ = 0; }
608 1.1 rmind ;
609 1.1 rmind
610 1.27 rmind on_ifname
611 1.29 rmind : ON ifref { $$ = $2; }
612 1.27 rmind | { $$ = NULL; }
613 1.1 rmind ;
614 1.1 rmind
615 1.17 rmind afamily
616 1.29 rmind : INET4 { $$ = AF_INET; }
617 1.17 rmind | INET6 { $$ = AF_INET6; }
618 1.17 rmind ;
619 1.17 rmind
620 1.39 rmind maybe_not
621 1.39 rmind : EXCL_MARK { $$ = true; }
622 1.39 rmind | { $$ = false; }
623 1.39 rmind ;
624 1.39 rmind
625 1.9 rmind opt_family
626 1.17 rmind : FAMILY afamily { $$ = $2; }
627 1.9 rmind | { $$ = AF_UNSPEC; }
628 1.1 rmind ;
629 1.1 rmind
630 1.51 rmind rawproto
631 1.51 rmind : TCP tcp_flags_and_mask
632 1.1 rmind {
633 1.1 rmind $$.op_proto = IPPROTO_TCP;
634 1.51 rmind $$.op_opts = $2;
635 1.1 rmind }
636 1.51 rmind | ICMP icmp_type_and_code
637 1.1 rmind {
638 1.1 rmind $$.op_proto = IPPROTO_ICMP;
639 1.51 rmind $$.op_opts = $2;
640 1.1 rmind }
641 1.51 rmind | ICMP6 icmp_type_and_code
642 1.11 spz {
643 1.11 spz $$.op_proto = IPPROTO_ICMPV6;
644 1.51 rmind $$.op_opts = $2;
645 1.11 spz }
646 1.51 rmind | some_name
647 1.9 rmind {
648 1.51 rmind $$.op_proto = npfctl_protono($1);
649 1.9 rmind $$.op_opts = NULL;
650 1.9 rmind }
651 1.51 rmind | number
652 1.1 rmind {
653 1.51 rmind $$.op_proto = $1;
654 1.1 rmind $$.op_opts = NULL;
655 1.1 rmind }
656 1.44 rmind ;
657 1.44 rmind
658 1.51 rmind proto_elems
659 1.51 rmind : proto_elems COMMA rawproto
660 1.51 rmind {
661 1.51 rmind npfvar_t *pvar = npfvar_create_element(
662 1.51 rmind NPFVAR_PROTO, &$3, sizeof($3));
663 1.51 rmind $$ = npfvar_add_elements($1, pvar);
664 1.51 rmind }
665 1.51 rmind | rawproto
666 1.51 rmind {
667 1.51 rmind $$ = npfvar_create_element(NPFVAR_PROTO, &$1, sizeof($1));
668 1.51 rmind }
669 1.51 rmind ;
670 1.51 rmind
671 1.51 rmind proto
672 1.51 rmind : PROTO rawproto
673 1.51 rmind {
674 1.51 rmind $$ = npfvar_create_element(NPFVAR_PROTO, &$2, sizeof($2));
675 1.51 rmind }
676 1.51 rmind | PROTO CURLY_OPEN proto_elems CURLY_CLOSE
677 1.51 rmind {
678 1.51 rmind $$ = $3;
679 1.51 rmind }
680 1.51 rmind ;
681 1.51 rmind
682 1.44 rmind opt_proto
683 1.44 rmind : proto { $$ = $1; }
684 1.51 rmind | { $$ = NULL; }
685 1.1 rmind ;
686 1.1 rmind
687 1.1 rmind all_or_filt_opts
688 1.54 joe : ALL user_id group_id
689 1.1 rmind {
690 1.39 rmind $$.fo_finvert = false;
691 1.8 rmind $$.fo_from.ap_netaddr = NULL;
692 1.8 rmind $$.fo_from.ap_portrange = NULL;
693 1.39 rmind $$.fo_tinvert = false;
694 1.8 rmind $$.fo_to.ap_netaddr = NULL;
695 1.8 rmind $$.fo_to.ap_portrange = NULL;
696 1.54 joe $$.uid = $2;
697 1.54 joe $$.gid = $3;
698 1.1 rmind }
699 1.1 rmind | filt_opts { $$ = $1; }
700 1.1 rmind ;
701 1.1 rmind
702 1.7 rmind opt_stateful
703 1.9 rmind : STATEFUL { $$ = NPF_RULE_STATEFUL; }
704 1.49 rmind | STATEFUL_ALL { $$ = NPF_RULE_STATEFUL | NPF_RULE_GSTATEFUL; }
705 1.1 rmind | { $$ = 0; }
706 1.1 rmind ;
707 1.1 rmind
708 1.1 rmind opt_apply
709 1.1 rmind : APPLY STRING { $$ = $2; }
710 1.1 rmind | { $$ = NULL; }
711 1.1 rmind ;
712 1.1 rmind
713 1.1 rmind block_opts
714 1.1 rmind : RETURNRST { $$ = NPF_RULE_RETRST; }
715 1.1 rmind | RETURNICMP { $$ = NPF_RULE_RETICMP; }
716 1.1 rmind | RETURN { $$ = NPF_RULE_RETRST | NPF_RULE_RETICMP; }
717 1.1 rmind | { $$ = 0; }
718 1.1 rmind ;
719 1.1 rmind
720 1.1 rmind filt_opts
721 1.51 rmind : FROM maybe_not filt_addr filt_port TO maybe_not filt_addr filt_port
722 1.54 joe user_id group_id
723 1.1 rmind {
724 1.39 rmind $$.fo_finvert = $2;
725 1.39 rmind $$.fo_from.ap_netaddr = $3;
726 1.39 rmind $$.fo_from.ap_portrange = $4;
727 1.39 rmind $$.fo_tinvert = $6;
728 1.39 rmind $$.fo_to.ap_netaddr = $7;
729 1.39 rmind $$.fo_to.ap_portrange = $8;
730 1.54 joe $$.uid = $9;
731 1.54 joe $$.gid = $10;
732 1.39 rmind }
733 1.54 joe | FROM maybe_not filt_addr filt_port user_id group_id
734 1.39 rmind {
735 1.39 rmind $$.fo_finvert = $2;
736 1.39 rmind $$.fo_from.ap_netaddr = $3;
737 1.39 rmind $$.fo_from.ap_portrange = $4;
738 1.39 rmind $$.fo_tinvert = false;
739 1.8 rmind $$.fo_to.ap_netaddr = NULL;
740 1.8 rmind $$.fo_to.ap_portrange = NULL;
741 1.54 joe $$.uid = $5;
742 1.54 joe $$.gid = $6;
743 1.1 rmind }
744 1.54 joe | TO maybe_not filt_addr filt_port user_id group_id
745 1.1 rmind {
746 1.39 rmind $$.fo_finvert = false;
747 1.8 rmind $$.fo_from.ap_netaddr = NULL;
748 1.8 rmind $$.fo_from.ap_portrange = NULL;
749 1.39 rmind $$.fo_tinvert = $2;
750 1.39 rmind $$.fo_to.ap_netaddr = $3;
751 1.39 rmind $$.fo_to.ap_portrange = $4;
752 1.54 joe $$.uid = $5;
753 1.54 joe $$.gid = $6;
754 1.1 rmind }
755 1.1 rmind ;
756 1.1 rmind
757 1.51 rmind filt_addr_list
758 1.51 rmind : filt_addr_list COMMA filt_addr_element
759 1.51 rmind {
760 1.51 rmind npfvar_add_elements($1, $3);
761 1.51 rmind }
762 1.51 rmind | filt_addr_element
763 1.51 rmind ;
764 1.51 rmind
765 1.1 rmind filt_addr
766 1.51 rmind : CURLY_OPEN filt_addr_list CURLY_CLOSE
767 1.51 rmind {
768 1.51 rmind $$ = $2;
769 1.51 rmind }
770 1.51 rmind | filt_addr_element { $$ = $1; }
771 1.4 rmind | ANY { $$ = NULL; }
772 1.1 rmind ;
773 1.1 rmind
774 1.1 rmind addr_and_mask
775 1.23 christos : addr SLASH number
776 1.1 rmind {
777 1.1 rmind $$ = npfctl_parse_fam_addr_mask($1, NULL, &$3);
778 1.1 rmind }
779 1.1 rmind | addr SLASH addr
780 1.1 rmind {
781 1.1 rmind $$ = npfctl_parse_fam_addr_mask($1, $3, NULL);
782 1.1 rmind }
783 1.1 rmind | addr
784 1.1 rmind {
785 1.1 rmind $$ = npfctl_parse_fam_addr_mask($1, NULL, NULL);
786 1.1 rmind }
787 1.1 rmind ;
788 1.1 rmind
789 1.51 rmind filt_addr_element
790 1.48 rmind : addr_and_mask { assert($1 != NULL); $$ = $1; }
791 1.40 rmind | static_ifaddrs
792 1.4 rmind {
793 1.41 christos if (npfvar_get_count($1) != 1)
794 1.41 christos yyerror("multiple interfaces are not supported");
795 1.17 rmind ifnet_addr_t *ifna = npfvar_get_data($1, NPFVAR_INTERFACE, 0);
796 1.17 rmind $$ = ifna->ifna_addrs;
797 1.4 rmind }
798 1.48 rmind | dynamic_ifaddrs { $$ = npfctl_ifnet_table($1); }
799 1.48 rmind | TABLE_ID { $$ = npfctl_parse_table_id($1); }
800 1.4 rmind | VAR_ID
801 1.4 rmind {
802 1.4 rmind npfvar_t *vp = npfvar_lookup($1);
803 1.19 christos int type = npfvar_get_type(vp, 0);
804 1.17 rmind ifnet_addr_t *ifna;
805 1.19 christos again:
806 1.4 rmind switch (type) {
807 1.19 christos case NPFVAR_IDENTIFIER:
808 1.19 christos case NPFVAR_STRING:
809 1.19 christos vp = npfctl_parse_ifnet(npfvar_expand_string(vp),
810 1.19 christos AF_UNSPEC);
811 1.19 christos type = npfvar_get_type(vp, 0);
812 1.19 christos goto again;
813 1.4 rmind case NPFVAR_FAM:
814 1.40 rmind case NPFVAR_TABLE:
815 1.4 rmind $$ = vp;
816 1.4 rmind break;
817 1.17 rmind case NPFVAR_INTERFACE:
818 1.33 rmind $$ = NULL;
819 1.33 rmind for (u_int i = 0; i < npfvar_get_count(vp); i++) {
820 1.33 rmind ifna = npfvar_get_data(vp, type, i);
821 1.33 rmind $$ = npfvar_add_elements($$, ifna->ifna_addrs);
822 1.33 rmind }
823 1.17 rmind break;
824 1.4 rmind case -1:
825 1.17 rmind yyerror("undefined variable '%s'", $1);
826 1.4 rmind break;
827 1.4 rmind default:
828 1.17 rmind yyerror("wrong variable '%s' type '%s' for address "
829 1.17 rmind "or interface", $1, npfvar_type(type));
830 1.4 rmind break;
831 1.4 rmind }
832 1.4 rmind }
833 1.1 rmind ;
834 1.1 rmind
835 1.1 rmind addr
836 1.1 rmind : IPV4ADDR { $$ = $1; }
837 1.1 rmind | IPV6ADDR { $$ = $1; }
838 1.1 rmind ;
839 1.1 rmind
840 1.51 rmind filt_port
841 1.51 rmind : PORT CURLY_OPEN filt_port_list CURLY_CLOSE
842 1.51 rmind {
843 1.51 rmind $$ = npfctl_parse_port_range_variable(NULL, $3);
844 1.51 rmind }
845 1.51 rmind | PORT port_range { $$ = $2; }
846 1.51 rmind | { $$ = NULL; }
847 1.51 rmind ;
848 1.51 rmind
849 1.51 rmind filt_port_list
850 1.51 rmind : filt_port_list COMMA port_range
851 1.1 rmind {
852 1.51 rmind npfvar_add_elements($1, $3);
853 1.1 rmind }
854 1.51 rmind | port_range
855 1.51 rmind ;
856 1.51 rmind
857 1.51 rmind port_range
858 1.51 rmind : port /* just port */
859 1.1 rmind {
860 1.51 rmind $$ = npfctl_parse_port_range($1, $1);
861 1.1 rmind }
862 1.51 rmind | port MINUS port /* port from-to */
863 1.8 rmind {
864 1.51 rmind $$ = npfctl_parse_port_range($1, $3);
865 1.5 christos }
866 1.51 rmind | VAR_ID
867 1.1 rmind {
868 1.53 joe npfvar_t *vp;
869 1.53 joe if ((vp = npfvar_lookup($1)) == NULL)
870 1.53 joe yyerror("undefined port variable %s", $1);
871 1.51 rmind $$ = npfctl_parse_port_range_variable($1, vp);
872 1.1 rmind }
873 1.1 rmind ;
874 1.1 rmind
875 1.1 rmind port
876 1.23 christos : number { $$ = $1; }
877 1.1 rmind | IDENTIFIER { $$ = npfctl_portno($1); }
878 1.20 christos | STRING { $$ = npfctl_portno($1); }
879 1.1 rmind ;
880 1.1 rmind
881 1.1 rmind icmp_type_and_code
882 1.1 rmind : ICMPTYPE icmp_type
883 1.1 rmind {
884 1.11 spz $$ = npfctl_parse_icmp($<num>0, $2, -1);
885 1.1 rmind }
886 1.23 christos | ICMPTYPE icmp_type CODE number
887 1.1 rmind {
888 1.11 spz $$ = npfctl_parse_icmp($<num>0, $2, $4);
889 1.1 rmind }
890 1.1 rmind | ICMPTYPE icmp_type CODE IDENTIFIER
891 1.1 rmind {
892 1.17 rmind $$ = npfctl_parse_icmp($<num>0, $2,
893 1.17 rmind npfctl_icmpcode($<num>0, $2, $4));
894 1.1 rmind }
895 1.1 rmind | ICMPTYPE icmp_type CODE VAR_ID
896 1.1 rmind {
897 1.1 rmind char *s = npfvar_expand_string(npfvar_lookup($4));
898 1.17 rmind $$ = npfctl_parse_icmp($<num>0, $2,
899 1.17 rmind npfctl_icmpcode($<num>0, $2, s));
900 1.1 rmind }
901 1.25 rmind | { $$ = NULL; }
902 1.1 rmind ;
903 1.1 rmind
904 1.1 rmind tcp_flags_and_mask
905 1.1 rmind : FLAGS tcp_flags SLASH tcp_flags
906 1.1 rmind {
907 1.1 rmind npfvar_add_elements($2, $4);
908 1.1 rmind $$ = $2;
909 1.1 rmind }
910 1.1 rmind | FLAGS tcp_flags
911 1.1 rmind {
912 1.41 christos if (npfvar_get_count($2) != 1)
913 1.41 christos yyerror("multiple tcpflags are not supported");
914 1.1 rmind char *s = npfvar_get_data($2, NPFVAR_TCPFLAG, 0);
915 1.1 rmind npfvar_add_elements($2, npfctl_parse_tcpflag(s));
916 1.1 rmind $$ = $2;
917 1.1 rmind }
918 1.1 rmind | { $$ = NULL; }
919 1.1 rmind ;
920 1.1 rmind
921 1.1 rmind tcp_flags
922 1.1 rmind : IDENTIFIER { $$ = npfctl_parse_tcpflag($1); }
923 1.1 rmind ;
924 1.1 rmind
925 1.1 rmind icmp_type
926 1.23 christos : number { $$ = $1; }
927 1.11 spz | IDENTIFIER { $$ = npfctl_icmptype($<num>-1, $1); }
928 1.1 rmind | VAR_ID
929 1.1 rmind {
930 1.1 rmind char *s = npfvar_expand_string(npfvar_lookup($1));
931 1.11 spz $$ = npfctl_icmptype($<num>-1, s);
932 1.1 rmind }
933 1.1 rmind ;
934 1.1 rmind
935 1.29 rmind ifname
936 1.29 rmind : some_name
937 1.19 christos {
938 1.29 rmind npfctl_note_interface($1);
939 1.19 christos $$ = $1;
940 1.19 christos }
941 1.19 christos | VAR_ID
942 1.19 christos {
943 1.19 christos npfvar_t *vp = npfvar_lookup($1);
944 1.19 christos const int type = npfvar_get_type(vp, 0);
945 1.29 rmind ifnet_addr_t *ifna;
946 1.48 rmind const char *name;
947 1.48 rmind unsigned *tid;
948 1.48 rmind bool ifaddr;
949 1.19 christos
950 1.19 christos switch (type) {
951 1.19 christos case NPFVAR_STRING:
952 1.19 christos case NPFVAR_IDENTIFIER:
953 1.19 christos $$ = npfvar_expand_string(vp);
954 1.19 christos break;
955 1.29 rmind case NPFVAR_INTERFACE:
956 1.41 christos if (npfvar_get_count(vp) != 1)
957 1.41 christos yyerror(
958 1.41 christos "multiple interfaces are not supported");
959 1.29 rmind ifna = npfvar_get_data(vp, type, 0);
960 1.29 rmind $$ = ifna->ifna_name;
961 1.29 rmind break;
962 1.48 rmind case NPFVAR_TABLE:
963 1.48 rmind tid = npfvar_get_data(vp, type, 0);
964 1.48 rmind name = npfctl_table_getname(npfctl_config_ref(),
965 1.48 rmind *tid, &ifaddr);
966 1.48 rmind if (!ifaddr) {
967 1.48 rmind yyerror("variable '%s' references a table "
968 1.48 rmind "%s instead of an interface", $1, name);
969 1.48 rmind }
970 1.48 rmind $$ = estrdup(name);
971 1.48 rmind break;
972 1.19 christos case -1:
973 1.19 christos yyerror("undefined variable '%s' for interface", $1);
974 1.19 christos break;
975 1.19 christos default:
976 1.29 rmind yyerror("wrong variable '%s' type '%s' for interface",
977 1.19 christos $1, npfvar_type(type));
978 1.19 christos break;
979 1.19 christos }
980 1.29 rmind npfctl_note_interface($$);
981 1.19 christos }
982 1.19 christos ;
983 1.19 christos
984 1.40 rmind static_ifaddrs
985 1.29 rmind : afamily PAR_OPEN ifname PAR_CLOSE
986 1.17 rmind {
987 1.17 rmind $$ = npfctl_parse_ifnet($3, $1);
988 1.17 rmind }
989 1.19 christos ;
990 1.17 rmind
991 1.40 rmind dynamic_ifaddrs
992 1.40 rmind : IFADDRS PAR_OPEN ifname PAR_CLOSE
993 1.40 rmind {
994 1.40 rmind $$ = $3;
995 1.40 rmind }
996 1.40 rmind ;
997 1.40 rmind
998 1.29 rmind ifref
999 1.29 rmind : ifname
1000 1.40 rmind | dynamic_ifaddrs
1001 1.40 rmind | static_ifaddrs
1002 1.17 rmind {
1003 1.49 rmind ifnet_addr_t *ifna;
1004 1.49 rmind
1005 1.49 rmind if (npfvar_get_count($1) != 1) {
1006 1.41 christos yyerror("multiple interfaces are not supported");
1007 1.49 rmind }
1008 1.49 rmind ifna = npfvar_get_data($1, NPFVAR_INTERFACE, 0);
1009 1.27 rmind npfctl_note_interface(ifna->ifna_name);
1010 1.27 rmind $$ = ifna->ifna_name;
1011 1.17 rmind }
1012 1.1 rmind ;
1013 1.1 rmind
1014 1.54 joe user_id
1015 1.54 joe : /* empty */ { $$.op = NPF_OP_NONE; }
1016 1.54 joe | USER uids { $$ = $2; }
1017 1.54 joe ;
1018 1.54 joe
1019 1.54 joe uids
1020 1.54 joe : uid_item { $$ = $1; }
1021 1.54 joe ;
1022 1.54 joe
1023 1.54 joe uid_item
1024 1.54 joe : uid
1025 1.54 joe {
1026 1.54 joe npfctl_init_rid(&$$, $1, $1, NPF_OP_EQ);
1027 1.54 joe }
1028 1.54 joe | op_unary uid
1029 1.54 joe {
1030 1.54 joe npfctl_init_rid(&$$, $2, $2, $1);
1031 1.54 joe }
1032 1.54 joe | uid op_binary uid
1033 1.54 joe {
1034 1.54 joe npfctl_init_rid(&$$, $1, $3, $2);
1035 1.54 joe }
1036 1.54 joe ;
1037 1.54 joe
1038 1.54 joe uid
1039 1.54 joe : NUM
1040 1.54 joe {
1041 1.54 joe if ($1 >= UID_MAX) {
1042 1.54 joe yyerror("illegal uid value %lu", $1);
1043 1.54 joe }
1044 1.54 joe $$ = $1;
1045 1.54 joe }
1046 1.54 joe | IDENTIFIER
1047 1.54 joe {
1048 1.54 joe if (npfctl_parse_user($1, &$$) == -1) {
1049 1.54 joe yyerror("unknown user %s", $1);
1050 1.54 joe }
1051 1.54 joe }
1052 1.54 joe | VAR_ID
1053 1.54 joe {
1054 1.54 joe npf_var_rid($1, npfctl_parse_user, &$$, "user");
1055 1.54 joe }
1056 1.54 joe ;
1057 1.54 joe
1058 1.54 joe group_id
1059 1.54 joe : /* empty */ { $$.op = NPF_OP_NONE; }
1060 1.54 joe | GROUP gids { $$ = $2; }
1061 1.54 joe ;
1062 1.54 joe
1063 1.54 joe gids
1064 1.54 joe : gid_item { $$ = $1; }
1065 1.54 joe ;
1066 1.54 joe
1067 1.54 joe gid_item
1068 1.54 joe : gid
1069 1.54 joe {
1070 1.54 joe npfctl_init_rid(&$$, $1, $1, NPF_OP_EQ);
1071 1.54 joe }
1072 1.54 joe | op_unary gid
1073 1.54 joe {
1074 1.54 joe npfctl_init_rid(&$$, $2, $2, $1);
1075 1.54 joe }
1076 1.54 joe | gid op_binary gid
1077 1.54 joe {
1078 1.54 joe npfctl_init_rid(&$$, $1, $3, $2);
1079 1.54 joe }
1080 1.54 joe ;
1081 1.54 joe
1082 1.54 joe gid
1083 1.54 joe : NUM
1084 1.54 joe {
1085 1.54 joe if ($1 >= GID_MAX) {
1086 1.54 joe yyerror("illegal gid value %lu", $1);
1087 1.54 joe }
1088 1.54 joe $$ = $1;
1089 1.54 joe }
1090 1.54 joe | IDENTIFIER
1091 1.54 joe {
1092 1.54 joe if (npfctl_parse_group($1, &$$) == -1) {
1093 1.54 joe yyerror("unknown group %s", $1);
1094 1.54 joe }
1095 1.54 joe }
1096 1.54 joe | VAR_ID
1097 1.54 joe {
1098 1.54 joe npf_var_rid($1, npfctl_parse_group, &$$, "group");
1099 1.54 joe }
1100 1.54 joe ;
1101 1.54 joe
1102 1.54 joe op_unary
1103 1.54 joe : EQ { $$ = NPF_OP_EQ; }
1104 1.54 joe | EXCL_MARK EQ { $$ = NPF_OP_NE; }
1105 1.54 joe | LT EQ { $$ = NPF_OP_LE; }
1106 1.54 joe | LT { $$ = NPF_OP_LT; }
1107 1.54 joe | GT EQ { $$ = NPF_OP_GE; }
1108 1.54 joe | GT { $$ = NPF_OP_GT; }
1109 1.54 joe ;
1110 1.54 joe
1111 1.54 joe op_binary
1112 1.54 joe : XRG { $$ = NPF_OP_XRG; }
1113 1.54 joe | IRG { $$ = NPF_OP_IRG; }
1114 1.54 joe ;
1115 1.54 joe
1116 1.23 christos number
1117 1.23 christos : HEX { $$ = $1; }
1118 1.23 christos | NUM { $$ = $1; }
1119 1.23 christos ;
1120 1.23 christos
1121 1.9 rmind some_name
1122 1.1 rmind : IDENTIFIER { $$ = $1; }
1123 1.1 rmind | STRING { $$ = $1; }
1124 1.1 rmind ;
1125 1.1 rmind
1126 1.1 rmind %%
1127