dissector_eth: also include id into macro
[netsniff-ng.git] / src / bpf_lexer.l
blob936eccd3cee46ac472b9632248a84fcac2e2fd2f
1 /*
2  * netsniff-ng - the packet sniffing beast
3  * By Daniel Borkmann <daniel@netsniff-ng.org>
4  * Copyright 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5  * Swiss federal institute of technology (ETH Zurich)
6  * Subject to the GPL, version 2.
7  */
9 %{
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
16 #include "bpf_parser.tab.h"
17 #include "xmalloc.h"
19 extern void yyerror(const char *);
23 %option align
24 %option nounput
25 %option noyywrap
26 %option noreject
27 %option 8bit
28 %option caseless
29 %option noinput
30 %option nodefault
32 digit           [0-9]
33 digit_s         [1-9]
34 digit_n         [0]
35 hex             [a-fA-F0-9]
36 hex_x           [x]
37 number_dec      {digit_n}|{digit_s}{digit}*
38 number_hex      {digit_n}{hex_x}{hex}+
39 label_s         [a-zA-Z]
40 label_me        [a-zA-Z0-9_]
41 label           {label_s}{label_me}+
45 "ldb"           { return OP_LDB; }
46 "ldh"           { return OP_LDH; }
47 "ld"            { return OP_LD; }
48 "ldx"           { return OP_LDX; }
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 "jgt"           { return OP_JGT; }
55 "jge"           { return OP_JGE; }
56 "jset"          { return OP_JSET; }
57 "add"           { return OP_ADD; }
58 "sub"           { return OP_SUB; }
59 "mul"           { return OP_MUL; }
60 "div"           { return OP_DIV; }
61 "and"           { return OP_AND; }
62 "or"            { return OP_OR; }
63 "lsh"           { return OP_LSH; }
64 "rsh"           { return OP_RSH; }
65 "ret"           { return OP_RET; }
66 "tax"           { return OP_TAX; }
67 "txa"           { return OP_TXA; }
68 "len"|"pktlen"  { return K_PKT_LEN; }
69 "proto"         { return K_PROTO; }
70 "type"          { return K_TYPE; }
71 "ifidx"         { return K_IFIDX; }
72 "nla"           { return K_NLATTR; }
73 "nlan"          { return K_NLATTR_NEST; }
74 "mark"          { return K_MARK; }
75 "queue"         { return K_QUEUE; }
76 "hatype"        { return K_HATYPE; }
77 "rxhash"        { return K_RXHASH; }
78 "cpu"           { return K_CPU; }
80 ":"             { return ':'; }
81 ","             { return ','; }
82 "#"             { return '#'; }
83 "["             { return '['; }
84 "]"             { return ']'; }
85 "("             { return '('; }
86 ")"             { return ')'; }
87 "x"             { return 'x'; }
88 "a"             { return 'a'; }
89 "+"             { return '+'; }
90 "M"             { return 'M'; }
91 "*"             { return '*'; }
92 "&"             { return '&'; }
93 "/*"([^\*]|\*[^/])*"*/" { return K_COMMENT; }
95 {number_hex}    { yylval.number = strtoul(yytext, NULL, 16);
96                   return number_hex; }
98 {number_dec}    { yylval.number = strtol(yytext, NULL, 10);
99                   return number_dec; }
101 {label}         { yylval.label = xstrdup(yytext);
102                   return label; }
104 ";"[^\n]*       {/* NOP */}
105 "\n"            { yylineno++; }
106 [ \t]+          {/* NOP */ }
107 .               { printf("Unknown character '%s'", yytext);
108                   yyerror("lex Unknown character"); }