ifpps: remove unsupported noise display
[netsniff.git] / src / bpf_lexer.l
blob15f03f75b7e7e4134d5983e9b46242d351729ab4
1 /*
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.
7  */
9 /* lex-func-prefix: yy */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <ctype.h>
18 #include "bpf_parser.tab.h"
19 #include "xmalloc.h"
21 extern void yyerror(const char *);
25 %option align
26 %option nounput
27 %option noyywrap
28 %option noreject
29 %option 8bit
30 %option caseless
31 %option noinput
32 %option nodefault
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; }
83 ":"             { return ':'; }
84 ","             { return ','; }
85 "#"             { return '#'; }
86 "["             { return '['; }
87 "]"             { return ']'; }
88 "("             { return '('; }
89 ")"             { return ')'; }
90 "x"             { return 'x'; }
91 "a"             { return 'a'; }
92 "+"             { return '+'; }
93 "M"             { return 'M'; }
94 "*"             { return '*'; }
95 "&"             { return '&'; }
97 {number_hex}    { yylval.number = strtoul(yytext, NULL, 16);
98                   return number; }
100 {number_oct}    { yylval.number = strtol(yytext + 1, NULL, 8);
101                   return number; }
103 {number_bin}    { yylval.number = strtol(yytext + 2, NULL, 2);
104                   return number; }
106 {number_dec}    { yylval.number = strtol(yytext, NULL, 10);
107                   return number; }
109 {label}         { yylval.label = xstrdup(yytext);
110                   return label; }
112 "/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
113 ";"[^\n]*       {/* NOP */}
114 "\n"            { yylineno++; }
115 [ \t]+          {/* NOP */ }
116 .               { printf("Unknown character '%s'", yytext);
117                   yyerror("lex Unknown character"); }