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; }
75 "#"?("len"|"pktlen") { return K_PKT_LEN; }
76 "#"?("pto"|"proto") { return K_PROTO; }
77 "#"?("type") { return K_TYPE; }
78 "#"?("ifx"|"ifidx") { return K_IFIDX; }
79 "#"?("nla") { return K_NLATTR; }
80 "#"?("nlan") { return K_NLATTR_NEST; }
81 "#"?("mark") { return K_MARK; }
82 "#"?("que"|"queue"|"Q") { return K_QUEUE; }
83 "#"?("hat"|"hatype") { return K_HATYPE; }
84 "#"?("rxh"|"rxhash") { return K_RXHASH; }
85 "#"?("cpu") { return K_CPU; }
86 "#"?("vlant"|"vlan_tci") { return K_VLANT; }
87 "#"?("vlana"|"vlan_acc") { return K_VLANP; }
88 "#"?("vlanp") { return K_VLANP; }
104 {number_hex} { yylval.number = strtoul(yytext, NULL, 16);
107 {number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
110 {number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
113 {number_dec} { yylval.number = strtol(yytext, NULL, 10);
116 {label} { yylval.label = xstrdup(yytext);
119 "/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
120 ";"[^\n]* {/* NOP */}
123 . { printf("Unknown character '%s'", yytext);
124 yyerror("lex Unknown character"); }