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 "ldx" { return OP_LDX; }
47 "ldxb" { return OP_LDXB; }
48 "st" { return OP_ST; }
49 "stx" { return OP_STX; }
50 "jmp"|"ja" { return OP_JMP; }
51 "jeq" { return OP_JEQ; }
52 "jgt" { return OP_JGT; }
53 "jge" { return OP_JGE; }
54 "jset" { return OP_JSET; }
55 "add" { return OP_ADD; }
56 "sub" { return OP_SUB; }
57 "mul" { return OP_MUL; }
58 "div" { return OP_DIV; }
59 "mod" { return OP_MOD; }
60 "neg" { return OP_NEG; }
61 "and" { return OP_AND; }
62 "xor" { return OP_XOR; }
63 "or" { return OP_OR; }
64 "lsh" { return OP_LSH; }
65 "rsh" { return OP_RSH; }
66 "ret" { return OP_RET; }
67 "tax" { return OP_TAX; }
68 "txa" { return OP_TXA; }
69 "len"|"pktlen" { return K_PKT_LEN; }
70 "pto"|"proto" { return K_PROTO; }
71 "type" { return K_TYPE; }
72 "ifx"|"ifidx" { return K_IFIDX; }
73 "nla" { return K_NLATTR; }
74 "nlan" { return K_NLATTR_NEST; }
75 "mark" { return K_MARK; }
76 "que"|"queue" { return K_QUEUE; }
77 "hat"|"hatype" { return K_HATYPE; }
78 "rxh"|"rxhash" { return K_RXHASH; }
79 "cpu" { return K_CPU; }
80 "vlant" { return K_VLANT; }
81 "vlanp" { return K_VLANP; }
97 {number_hex} { yylval.number = strtoul(yytext, NULL, 16);
100 {number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
103 {number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
106 {number_dec} { yylval.number = strtol(yytext, NULL, 10);
109 {label} { yylval.label = xstrdup(yytext);
112 "/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
113 ";"[^\n]* {/* NOP */}
116 . { printf("Unknown character '%s'", yytext);
117 yyerror("lex Unknown character"); }