make: add flags and fix some warnings
[netsniff-ng.git] / src / bpf_parser.y
blob3a8af66e17b2641b5407001b4b52aa46c0939576
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
7 */
9 /* yaac-func-prefix: yy */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <stdbool.h>
16 #include <signal.h>
17 #include <stdint.h>
18 #include <errno.h>
20 #include "bpf.h"
21 #include "xmalloc.h"
22 #include "bpf_parser.tab.h"
23 #include "built_in.h"
24 #include "die.h"
26 #define MAX_INSTRUCTIONS 4096
28 int compile_filter(char *file, int verbose, int bypass);
30 static int curr_instr = 0;
32 static struct sock_filter out[MAX_INSTRUCTIONS];
34 static char *labels[MAX_INSTRUCTIONS];
36 static char *labels_jt[MAX_INSTRUCTIONS];
37 static char *labels_jf[MAX_INSTRUCTIONS];
38 static char *labels_k[MAX_INSTRUCTIONS];
40 #define YYERROR_VERBOSE 0
41 #define YYDEBUG 0
42 #define YYENABLE_NLS 1
43 #define YYLTYPE_IS_TRIVIAL 1
44 #define ENABLE_NLS 1
46 extern FILE *yyin;
47 extern int yylex(void);
48 extern void yyerror(const char *);
49 extern int yylineno;
50 extern char *yytext;
52 static inline void check_max_instr(void)
54 if (curr_instr >= MAX_INSTRUCTIONS)
55 panic("Exceeded maximal number of instructions!\n");
58 static inline void set_curr_instr(uint16_t code, uint8_t jt, uint8_t jf, uint32_t k)
60 check_max_instr();
62 out[curr_instr].code = code;
63 out[curr_instr].jt = jt;
64 out[curr_instr].jf = jf;
65 out[curr_instr].k = k;
67 curr_instr++;
70 static inline void set_curr_label(char *label)
72 check_max_instr();
74 labels[curr_instr] = label;
77 #define JTL 1
78 #define JFL 2
79 #define JKL 3
81 static inline void set_jmp_label(char *label, int which)
83 check_max_instr();
85 switch (which) {
86 case JTL:
87 labels_jt[curr_instr] = label;
88 break;
89 case JFL:
90 labels_jf[curr_instr] = label;
91 break;
92 case JKL:
93 labels_k[curr_instr] = label;
94 break;
95 default:
96 bug();
100 static int find_intr_offset_or_panic(char *label_to_search)
102 int i, max = curr_instr, ret = -ENOENT;
104 bug_on(!label_to_search);
106 for (i = 0; i < max; ++i) {
107 if (labels[i] != NULL) {
108 /* Both are \0-terminated! */
109 if (!strcmp(label_to_search, labels[i])) {
110 ret = i;
111 break;
116 if (ret == -ENOENT)
117 panic("No such label!\n");
119 return ret;
124 %union {
125 char *label;
126 long int number;
129 %token OP_LDB OP_LDH OP_LD OP_LDX OP_ST OP_STX OP_JMP OP_JEQ OP_JGT OP_JGE
130 %token OP_JSET OP_ADD OP_SUB OP_MUL OP_DIV OP_AND OP_OR OP_XOR OP_LSH OP_RSH
131 %token OP_RET OP_TAX OP_TXA OP_LDXB OP_MOD OP_NEG OP_JNEQ OP_JLT OP_JLE OP_LDI
132 %token OP_LDXI
134 %token K_PKT_LEN K_PROTO K_TYPE K_NLATTR K_NLATTR_NEST K_MARK K_QUEUE K_HATYPE
135 %token K_RXHASH K_CPU K_IFIDX K_VLANT K_VLANP
137 %token ':' ',' '[' ']' '(' ')' 'x' 'a' '+' 'M' '*' '&' '#'
139 %token number label
141 %type <number> number
142 %type <label> label
146 prog
147 : line
148 | prog line
151 line
152 : instr
153 | labelled_instr
156 labelled_instr
157 : labelled instr
160 instr
161 : ldb
162 | ldh
163 | ld
164 | ldi
165 | ldx
166 | ldxi
167 | st
168 | stx
169 | jmp
170 | jeq
171 | jneq
172 | jlt
173 | jle
174 | jgt
175 | jge
176 | jset
177 | add
178 | sub
179 | mul
180 | div
181 | mod
182 | neg
183 | and
184 | or
185 | xor
186 | lsh
187 | rsh
188 | ret
189 | tax
190 | txa
193 labelled
194 : label ':' { set_curr_label($1); }
198 : OP_LDB '[' 'x' '+' number ']' {
199 set_curr_instr(BPF_LD | BPF_B | BPF_IND, 0, 0, $5); }
200 | OP_LDB '[' number ']' {
201 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0, $3); }
202 | OP_LDB K_PROTO {
203 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
204 SKF_AD_OFF + SKF_AD_PROTOCOL); }
205 | OP_LDB K_TYPE {
206 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
207 SKF_AD_OFF + SKF_AD_PKTTYPE); }
208 | OP_LDB K_IFIDX {
209 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
210 SKF_AD_OFF + SKF_AD_IFINDEX); }
211 | OP_LDB K_NLATTR {
212 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
213 SKF_AD_OFF + SKF_AD_NLATTR); }
214 | OP_LDB K_NLATTR_NEST {
215 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
216 SKF_AD_OFF + SKF_AD_NLATTR_NEST); }
217 | OP_LDB K_MARK {
218 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
219 SKF_AD_OFF + SKF_AD_MARK); }
220 | OP_LDB K_QUEUE {
221 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
222 SKF_AD_OFF + SKF_AD_QUEUE); }
223 | OP_LDB K_HATYPE {
224 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
225 SKF_AD_OFF + SKF_AD_HATYPE); }
226 | OP_LDB K_RXHASH {
227 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
228 SKF_AD_OFF + SKF_AD_RXHASH); }
229 | OP_LDB K_CPU {
230 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
231 SKF_AD_OFF + SKF_AD_CPU); }
232 | OP_LDB K_VLANT {
233 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
234 SKF_AD_OFF + SKF_AD_VLAN_TAG); }
235 | OP_LDB K_VLANP {
236 set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0,
237 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT); }
241 : OP_LDH '[' 'x' '+' number ']' {
242 set_curr_instr(BPF_LD | BPF_H | BPF_IND, 0, 0, $5); }
243 | OP_LDH '[' number ']' {
244 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0, $3); }
245 | OP_LDH K_PROTO {
246 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
247 SKF_AD_OFF + SKF_AD_PROTOCOL); }
248 | OP_LDH K_TYPE {
249 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
250 SKF_AD_OFF + SKF_AD_PKTTYPE); }
251 | OP_LDH K_IFIDX {
252 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
253 SKF_AD_OFF + SKF_AD_IFINDEX); }
254 | OP_LDH K_NLATTR {
255 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
256 SKF_AD_OFF + SKF_AD_NLATTR); }
257 | OP_LDH K_NLATTR_NEST {
258 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
259 SKF_AD_OFF + SKF_AD_NLATTR_NEST); }
260 | OP_LDH K_MARK {
261 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
262 SKF_AD_OFF + SKF_AD_MARK); }
263 | OP_LDH K_QUEUE {
264 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
265 SKF_AD_OFF + SKF_AD_QUEUE); }
266 | OP_LDH K_HATYPE {
267 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
268 SKF_AD_OFF + SKF_AD_HATYPE); }
269 | OP_LDH K_RXHASH {
270 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
271 SKF_AD_OFF + SKF_AD_RXHASH); }
272 | OP_LDH K_CPU {
273 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
274 SKF_AD_OFF + SKF_AD_CPU); }
275 | OP_LDH K_VLANT {
276 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
277 SKF_AD_OFF + SKF_AD_VLAN_TAG); }
278 | OP_LDH K_VLANP {
279 set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0,
280 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT); }
284 : OP_LDI number {
285 set_curr_instr(BPF_LD | BPF_IMM, 0, 0, $2); }
289 : OP_LD '#' number {
290 set_curr_instr(BPF_LD | BPF_IMM, 0, 0, $3); }
291 | OP_LD K_PKT_LEN {
292 set_curr_instr(BPF_LD | BPF_W | BPF_LEN, 0, 0, 0); }
293 | OP_LD K_PROTO {
294 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
295 SKF_AD_OFF + SKF_AD_PROTOCOL); }
296 | OP_LD K_TYPE {
297 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
298 SKF_AD_OFF + SKF_AD_PKTTYPE); }
299 | OP_LD K_IFIDX {
300 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
301 SKF_AD_OFF + SKF_AD_IFINDEX); }
302 | OP_LD K_NLATTR {
303 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
304 SKF_AD_OFF + SKF_AD_NLATTR); }
305 | OP_LD K_NLATTR_NEST {
306 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
307 SKF_AD_OFF + SKF_AD_NLATTR_NEST); }
308 | OP_LD K_MARK {
309 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
310 SKF_AD_OFF + SKF_AD_MARK); }
311 | OP_LD K_QUEUE {
312 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
313 SKF_AD_OFF + SKF_AD_QUEUE); }
314 | OP_LD K_HATYPE {
315 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
316 SKF_AD_OFF + SKF_AD_HATYPE); }
317 | OP_LD K_RXHASH {
318 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
319 SKF_AD_OFF + SKF_AD_RXHASH); }
320 | OP_LD K_CPU {
321 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
322 SKF_AD_OFF + SKF_AD_CPU); }
323 | OP_LD K_VLANT {
324 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
325 SKF_AD_OFF + SKF_AD_VLAN_TAG); }
326 | OP_LD K_VLANP {
327 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0,
328 SKF_AD_OFF + SKF_AD_VLAN_TAG_PRESENT); }
329 | OP_LD 'M' '[' number ']' {
330 set_curr_instr(BPF_LD | BPF_MEM, 0, 0, $4); }
331 | OP_LD '[' 'x' '+' number ']' {
332 set_curr_instr(BPF_LD | BPF_W | BPF_IND, 0, 0, $5); }
333 | OP_LD '[' number ']' {
334 set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0, $3); }
337 ldxi
338 : OP_LDXI number {
339 set_curr_instr(BPF_LDX | BPF_IMM, 0, 0, $2); }
343 : OP_LDX '#' number {
344 set_curr_instr(BPF_LDX | BPF_IMM, 0, 0, $3); }
345 | OP_LDX 'M' '[' number ']' {
346 set_curr_instr(BPF_LDX | BPF_MEM, 0, 0, $4); }
347 | OP_LDXB number '*' '(' '[' number ']' '&' number ')' {
348 if ($2 != 4 || $9 != 0xf) {
349 panic("ldxb offset not supported!\n");
350 } else {
351 set_curr_instr(BPF_LDX | BPF_MSH | BPF_B, 0, 0, $6); } }
352 | OP_LDX number '*' '(' '[' number ']' '&' number ')' {
353 if ($2 != 4 || $9 != 0xf) {
354 panic("ldxb offset not supported!\n");
355 } else {
356 set_curr_instr(BPF_LDX | BPF_MSH | BPF_B, 0, 0, $6); } }
360 : OP_ST 'M' '[' number ']' {
361 set_curr_instr(BPF_ST, 0, 0, $4); }
365 : OP_STX 'M' '[' number ']' {
366 set_curr_instr(BPF_STX, 0, 0, $4); }
370 : OP_JMP label {
371 set_jmp_label($2, JKL);
372 set_curr_instr(BPF_JMP | BPF_JA, 0, 0, 0); }
376 : OP_JEQ '#' number ',' label ',' label {
377 set_jmp_label($5, JTL);
378 set_jmp_label($7, JFL);
379 set_curr_instr(BPF_JMP | BPF_JEQ | BPF_K, 0, 0, $3); }
380 | OP_JEQ 'x' ',' label ',' label {
381 set_jmp_label($4, JTL);
382 set_jmp_label($6, JFL);
383 set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
384 | OP_JEQ '#' number ',' label {
385 set_jmp_label($5, JTL);
386 set_curr_instr(BPF_JMP | BPF_JEQ | BPF_K, 0, 0, $3); }
387 | OP_JEQ 'x' ',' label {
388 set_jmp_label($4, JTL);
389 set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
392 jneq
393 : OP_JNEQ '#' number ',' label {
394 set_jmp_label($5, JFL);
395 set_curr_instr(BPF_JMP | BPF_JEQ | BPF_K, 0, 0, $3); }
396 | OP_JNEQ 'x' ',' label {
397 set_jmp_label($4, JFL);
398 set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
402 : OP_JLT '#' number ',' label {
403 set_jmp_label($5, JFL);
404 set_curr_instr(BPF_JMP | BPF_JGE | BPF_K, 0, 0, $3); }
405 | OP_JLT 'x' ',' label {
406 set_jmp_label($4, JFL);
407 set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
411 : OP_JLE '#' number ',' label {
412 set_jmp_label($5, JFL);
413 set_curr_instr(BPF_JMP | BPF_JGT | BPF_K, 0, 0, $3); }
414 | OP_JLE 'x' ',' label {
415 set_jmp_label($4, JFL);
416 set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
420 : OP_JGT '#' number ',' label ',' label {
421 set_jmp_label($5, JTL);
422 set_jmp_label($7, JFL);
423 set_curr_instr(BPF_JMP | BPF_JGT | BPF_K, 0, 0, $3); }
424 | OP_JGT 'x' ',' label ',' label {
425 set_jmp_label($4, JTL);
426 set_jmp_label($6, JFL);
427 set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
428 | OP_JGT '#' number ',' label {
429 set_jmp_label($5, JTL);
430 set_curr_instr(BPF_JMP | BPF_JGT | BPF_K, 0, 0, $3); }
431 | OP_JGT 'x' ',' label {
432 set_jmp_label($4, JTL);
433 set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
437 : OP_JGE '#' number ',' label ',' label {
438 set_jmp_label($5, JTL);
439 set_jmp_label($7, JFL);
440 set_curr_instr(BPF_JMP | BPF_JGE | BPF_K, 0, 0, $3); }
441 | OP_JGE 'x' ',' label ',' label {
442 set_jmp_label($4, JTL);
443 set_jmp_label($6, JFL);
444 set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
445 | OP_JGE '#' number ',' label {
446 set_jmp_label($5, JTL);
447 set_curr_instr(BPF_JMP | BPF_JGE | BPF_K, 0, 0, $3); }
448 | OP_JGE 'x' ',' label {
449 set_jmp_label($4, JTL);
450 set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
453 jset
454 : OP_JSET '#' number ',' label ',' label {
455 set_jmp_label($5, JTL);
456 set_jmp_label($7, JFL);
457 set_curr_instr(BPF_JMP | BPF_JSET | BPF_K, 0, 0, $3); }
458 | OP_JSET 'x' ',' label ',' label {
459 set_jmp_label($4, JTL);
460 set_jmp_label($6, JFL);
461 set_curr_instr(BPF_JMP | BPF_JSET | BPF_X, 0, 0, 0); }
462 | OP_JSET '#' number ',' label {
463 set_jmp_label($5, JTL);
464 set_curr_instr(BPF_JMP | BPF_JSET | BPF_K, 0, 0, $3); }
465 | OP_JSET 'x' ',' label {
466 set_jmp_label($4, JTL);
467 set_curr_instr(BPF_JMP | BPF_JSET | BPF_X, 0, 0, 0); }
471 : OP_ADD '#' number {
472 set_curr_instr(BPF_ALU | BPF_ADD | BPF_K, 0, 0, $3); }
473 | OP_ADD 'x' {
474 set_curr_instr(BPF_ALU | BPF_ADD | BPF_X, 0, 0, 0); }
478 : OP_SUB '#' number {
479 set_curr_instr(BPF_ALU | BPF_SUB | BPF_K, 0, 0, $3); }
480 | OP_SUB 'x' {
481 set_curr_instr(BPF_ALU | BPF_SUB | BPF_X, 0, 0, 0); }
485 : OP_MUL '#' number {
486 set_curr_instr(BPF_ALU | BPF_MUL | BPF_K, 0, 0, $3); }
487 | OP_MUL 'x' {
488 set_curr_instr(BPF_ALU | BPF_MUL | BPF_X, 0, 0, 0); }
492 : OP_DIV '#' number {
493 set_curr_instr(BPF_ALU | BPF_DIV | BPF_K, 0, 0, $3); }
494 | OP_DIV 'x' {
495 set_curr_instr(BPF_ALU | BPF_DIV | BPF_X, 0, 0, 0); }
499 : OP_MOD '#' number {
500 set_curr_instr(BPF_ALU | BPF_MOD | BPF_K, 0, 0, $3); }
501 | OP_MOD 'x' {
502 set_curr_instr(BPF_ALU | BPF_MOD | BPF_X, 0, 0, 0); }
506 : OP_NEG {
507 set_curr_instr(BPF_ALU | BPF_NEG, 0, 0, 0); }
511 : OP_AND '#' number {
512 set_curr_instr(BPF_ALU | BPF_AND | BPF_K, 0, 0, $3); }
513 | OP_AND 'x' {
514 set_curr_instr(BPF_ALU | BPF_AND | BPF_X, 0, 0, 0); }
518 : OP_OR '#' number {
519 set_curr_instr(BPF_ALU | BPF_OR | BPF_K, 0, 0, $3); }
520 | OP_OR 'x' {
521 set_curr_instr(BPF_ALU | BPF_OR | BPF_X, 0, 0, 0); }
525 : OP_XOR '#' number {
526 set_curr_instr(BPF_ALU | BPF_XOR | BPF_K, 0, 0, $3); }
527 | OP_XOR 'x' {
528 set_curr_instr(BPF_ALU | BPF_XOR | BPF_X, 0, 0, 0); }
532 : OP_LSH '#' number {
533 set_curr_instr(BPF_ALU | BPF_LSH | BPF_K, 0, 0, $3); }
534 | OP_LSH 'x' {
535 set_curr_instr(BPF_ALU | BPF_LSH | BPF_X, 0, 0, 0); }
539 : OP_RSH '#' number {
540 set_curr_instr(BPF_ALU | BPF_RSH | BPF_K, 0, 0, $3); }
541 | OP_RSH 'x' {
542 set_curr_instr(BPF_ALU | BPF_RSH | BPF_X, 0, 0, 0); }
546 : OP_RET 'a' {
547 set_curr_instr(BPF_RET | BPF_A, 0, 0, 0); }
548 | OP_RET 'x' {
549 set_curr_instr(BPF_RET | BPF_X, 0, 0, 0); }
550 | OP_RET '#' number {
551 set_curr_instr(BPF_RET | BPF_K, 0, 0, $3); }
555 : OP_TAX {
556 set_curr_instr(BPF_MISC | BPF_TAX, 0, 0, 0); }
560 : OP_TXA {
561 set_curr_instr(BPF_MISC | BPF_TXA, 0, 0, 0); }
566 static void stage_1_inline(void)
568 yyparse();
571 static void stage_2_label_reduce(void)
573 int i, max = curr_instr, off;
575 /* 1. reduce k jumps */
576 for (i = 0; i < max; ++i) {
577 if (labels_k[i] != NULL) {
578 off = find_intr_offset_or_panic(labels_k[i]);
579 out[i].k = (uint32_t) (off - i - 1);
583 /* 1. reduce jt jumps */
584 for (i = 0; i < max; ++i) {
585 if (labels_jt[i] != NULL) {
586 off = find_intr_offset_or_panic(labels_jt[i]);
587 out[i].jt = (uint8_t) (off - i -1);
591 /* 1. reduce jf jumps */
592 for (i = 0; i < max; ++i) {
593 if (labels_jf[i] != NULL) {
594 off = find_intr_offset_or_panic(labels_jf[i]);
595 out[i].jf = (uint8_t) (off - i - 1);
600 int compile_filter(char *file, int verbose, int bypass)
602 int i;
603 struct sock_fprog res;
605 if (!strncmp("-", file, strlen("-")))
606 yyin = stdin;
607 else
608 yyin = fopen(file, "r");
609 if (!yyin)
610 panic("Cannot open file!\n");
612 memset(out, 0, sizeof(out));
613 memset(labels, 0, sizeof(labels));
614 memset(labels_jf, 0, sizeof(labels_jf));
615 memset(labels_jt, 0, sizeof(labels_jt));
616 memset(labels_k, 0, sizeof(labels_k));
618 stage_1_inline();
619 stage_2_label_reduce();
621 res.filter = out;
622 res.len = curr_instr;
624 if (verbose) {
625 printf("Generated program:\n");
626 bpf_dump_all(&res);
629 if (!bypass) {
630 if (verbose) {
631 printf("Validating: ");
632 fflush(stdout);
635 if (bpf_validate(&res) == 0) {
636 if (verbose)
637 whine("Semantic error! BPF validation "
638 "failed!\n");
639 else
640 panic("Semantic error! BPF validation failed! "
641 "Try -V for debugging output!\n");
642 } else if (verbose) {
643 printf("is runnable!\n");
647 if (verbose)
648 printf("Result:\n");
649 for (i = 0; i < res.len; ++i) {
650 printf("{ 0x%x, %u, %u, 0x%08x },\n",
651 res.filter[i].code, res.filter[i].jt,
652 res.filter[i].jf, res.filter[i].k);
653 if (labels[i] != NULL)
654 xfree(labels[i]);
655 if (labels_jt[i] != NULL)
656 xfree(labels_jt[i]);
657 if (labels_jf[i] != NULL)
658 xfree(labels_jf[i]);
659 if (labels_k[i] != NULL)
660 xfree(labels_k[i]);
663 fclose(yyin);
664 return 0;
667 void yyerror(const char *err)
669 panic("Syntax error at line %d: %s! %s!\n",
670 yylineno, yytext, err);