summaryrefslogtreecommitdiff
path: root/bpf_lexer.l
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-03-15 10:41:48 +0100
committerDaniel Borkmann <dborkman@redhat.com>2013-03-15 10:41:48 +0100
commit1a9fbac03c684f29cff9ac44875bd9504a89f54e (patch)
tree1b2e40dbe5dc1899ef5b62c4325c9b94c9c450fc /bpf_lexer.l
all: import netsniff-ng 0.5.8-rc0 source
We decided to get rid of the old Git history and start a new one for several reasons: *) Allow / enforce only high-quality commits (which was not the case for many commits in the history), have a policy that is more close to the one from the Linux kernel. With high quality commits, we mean code that is logically split into commits and commit messages that are signed-off and have a proper subject and message body. We do not allow automatic Github merges anymore, since they are total bullshit. However, we will either cherry-pick your patches or pull them manually. *) The old archive was about ~27MB for no particular good reason. This basically derived from the bad decision that also some PDF files where stored there. From this moment onwards, no binary objects are allowed to be stored in this repository anymore. The old archive is not wiped away from the Internet. You will still be able to find it, e.g. on git.cryptoism.org etc. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'bpf_lexer.l')
-rw-r--r--bpf_lexer.l126
1 files changed, 126 insertions, 0 deletions
diff --git a/bpf_lexer.l b/bpf_lexer.l
new file mode 100644
index 0000000..d4b6947
--- /dev/null
+++ b/bpf_lexer.l
@@ -0,0 +1,126 @@
+/*
+ * netsniff-ng - the packet sniffing beast
+ * By Daniel Borkmann <daniel@netsniff-ng.org>
+ * Copyright 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
+ * Swiss federal institute of technology (ETH Zurich)
+ * Subject to the GPL, version 2.
+ */
+
+/* lex-func-prefix: yy */
+
+%{
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "bpf_parser.tab.h"
+#include "xmalloc.h"
+
+extern void yyerror(const char *);
+
+%}
+
+%option align
+%option nounput
+%option noyywrap
+%option noreject
+%option 8bit
+%option caseless
+%option noinput
+%option nodefault
+
+number_oct ([0][0-9]+)
+number_hex ([0][x][a-fA-F0-9]+)
+number_bin ([0][b][0-1]+)
+number_dec (([0])|([-+]?[1-9][0-9]*))
+
+label [a-zA-Z_][a-zA-Z0-9_]+
+
+%%
+
+"ldb" { return OP_LDB; }
+"ldh" { return OP_LDH; }
+"ld" { return OP_LD; }
+"ldi" { return OP_LDI; }
+"ldx" { return OP_LDX; }
+"ldxi" { return OP_LDXI; }
+"ldxb" { return OP_LDXB; }
+"st" { return OP_ST; }
+"stx" { return OP_STX; }
+"jmp"|"ja" { return OP_JMP; }
+"jeq" { return OP_JEQ; }
+"jneq"|"jne" { return OP_JNEQ; }
+"jlt" { return OP_JLT; }
+"jle" { return OP_JLE; }
+"jgt" { return OP_JGT; }
+"jge" { return OP_JGE; }
+"jset" { return OP_JSET; }
+"add" { return OP_ADD; }
+"sub" { return OP_SUB; }
+"mul" { return OP_MUL; }
+"div" { return OP_DIV; }
+"mod" { return OP_MOD; }
+"neg" { return OP_NEG; }
+"and" { return OP_AND; }
+"xor" { return OP_XOR; }
+"or" { return OP_OR; }
+"lsh" { return OP_LSH; }
+"rsh" { return OP_RSH; }
+"ret" { return OP_RET; }
+"tax" { return OP_TAX; }
+"txa" { return OP_TXA; }
+
+"#"?("len"|"pktlen") { return K_PKT_LEN; }
+"#"?("pto"|"proto") { return K_PROTO; }
+"#"?("type") { return K_TYPE; }
+"#"?("ifx"|"ifidx") { return K_IFIDX; }
+"#"?("nla") { return K_NLATTR; }
+"#"?("nlan") { return K_NLATTR_NEST; }
+"#"?("mark") { return K_MARK; }
+"#"?("que"|"queue"|"Q") { return K_QUEUE; }
+"#"?("hat"|"hatype") { return K_HATYPE; }
+"#"?("rxh"|"rxhash") { return K_RXHASH; }
+"#"?("cpu") { return K_CPU; }
+"#"?("vlant"|"vlan_tci") { return K_VLANT; }
+"#"?("vlana"|"vlan_acc") { return K_VLANP; }
+"#"?("vlanp") { return K_VLANP; }
+
+":" { return ':'; }
+"," { return ','; }
+"#" { return '#'; }
+"[" { return '['; }
+"]" { return ']'; }
+"(" { return '('; }
+")" { return ')'; }
+"x" { return 'x'; }
+"a" { return 'a'; }
+"+" { return '+'; }
+"M" { return 'M'; }
+"*" { return '*'; }
+"&" { return '&'; }
+
+{number_hex} { yylval.number = strtoul(yytext, NULL, 16);
+ return number; }
+
+{number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
+ return number; }
+
+{number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
+ return number; }
+
+{number_dec} { yylval.number = strtol(yytext, NULL, 10);
+ return number; }
+
+{label} { yylval.label = xstrdup(yytext);
+ return label; }
+
+"/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
+";"[^\n]* {/* NOP */}
+"\n" { yylineno++; }
+[ \t]+ {/* NOP */ }
+. { printf("Unknown character '%s'", yytext);
+ yyerror("lex Unknown character"); }
+
+%%