2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
9 /* lex-func-prefix: yy */
18 #include "bpf_parser.tab.h"
21 extern void yyerror(const char *);
34 number_oct ([0][0-9]+)
35 number_hex ([0][x][a-fA-F0-9]+)
36 number_bin ([0][b][0-1]+)
37 number_dec (([0])|([-+]?[1-9][0-9]*))
39 label [a-zA-Z_][a-zA-Z0-9_]+
43 "ldb" { return OP_LDB; }
44 "ldh" { return OP_LDH; }
45 "ld" { return OP_LD; }
46 "ldi" { return OP_LDI; }
47 "ldx" { return OP_LDX; }
48 "ldxi" { return OP_LDXI; }
49 "ldxb" { return OP_LDXB; }
50 "st" { return OP_ST; }
51 "stx" { return OP_STX; }
52 "jmp"|"ja" { return OP_JMP; }
53 "jeq" { return OP_JEQ; }
54 "jneq"|"jne" { return OP_JNEQ; }
55 "jlt" { return OP_JLT; }
56 "jle" { return OP_JLE; }
57 "jgt" { return OP_JGT; }
58 "jge" { return OP_JGE; }
59 "jset" { return OP_JSET; }
60 "add" { return OP_ADD; }
61 "sub" { return OP_SUB; }
62 "mul" { return OP_MUL; }
63 "div" { return OP_DIV; }
64 "mod" { return OP_MOD; }
65 "neg" { return OP_NEG; }
66 "and" { return OP_AND; }
67 "xor" { return OP_XOR; }
68 "or" { return OP_OR; }
69 "lsh" { return OP_LSH; }
70 "rsh" { return OP_RSH; }
71 "ret" { return OP_RET; }
72 "tax" { return OP_TAX; }
73 "txa" { return OP_TXA; }
74 "len"|"pktlen" { return K_PKT_LEN; }
75 "pto"|"proto" { return K_PROTO; }
76 "type" { return K_TYPE; }
77 "ifx"|"ifidx" { return K_IFIDX; }
78 "nla" { return K_NLATTR; }
79 "nlan" { return K_NLATTR_NEST; }
80 "mark" { return K_MARK; }
81 "que"|"queue" { return K_QUEUE; }
82 "hat"|"hatype" { return K_HATYPE; }
83 "rxh"|"rxhash" { return K_RXHASH; }
84 "cpu" { return K_CPU; }
85 "vlant" { return K_VLANT; }
86 "vlanp" { return K_VLANP; }
103 {number_hex} { yylval.number = strtoul(yytext, NULL, 16);
106 {number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
109 {number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
112 {number_dec} { yylval.number = strtol(yytext, NULL, 10);
115 {label} { yylval.label = xstrdup(yytext);
118 "/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
119 ";"[^\n]* {/* NOP */}
122 . { printf("Unknown character '%s'", yytext);
123 yyerror("lex Unknown character"); }