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 "#"?("poff") { return K_POFF; }
79 "#"?("ifx"|"ifidx") { return K_IFIDX; }
80 "#"?("nla") { return K_NLATTR; }
81 "#"?("nlan") { return K_NLATTR_NEST; }
82 "#"?("mark") { return K_MARK; }
83 "#"?("que"|"queue"|"Q") { return K_QUEUE; }
84 "#"?("hat"|"hatype") { return K_HATYPE; }
85 "#"?("rxh"|"rxhash") { return K_RXHASH; }
86 "#"?("cpu") { return K_CPU; }
87 "#"?("vlant"|"vlan_tci") { return K_VLANT; }
88 "#"?("vlana"|"vlan_acc") { return K_VLANP; }
89 "#"?("vlanp") { return K_VLANP; }
106 {number_hex} { yylval.number = strtoul(yytext, NULL, 16);
109 {number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
112 {number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
115 {number_dec} { yylval.number = strtol(yytext, NULL, 10);
118 {label} { yylval.label = xstrdup(yytext);
121 "/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
122 ";"[^\n]* {/* NOP */}
126 . { printf("Unknown character '%s'", yytext);
127 yyerror("lex Unknown character"); }