4 * This program is free software; you can distribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * Syntax kept close to:
11 * Steven McCanne and Van Jacobson. 1993. The BSD packet filter: a new
12 * architecture for user-level packet capture. In Proceedings of the
13 * USENIX Winter 1993 Conference Proceedings on USENIX Winter 1993
14 * Conference Proceedings (USENIX'93). USENIX Association, Berkeley,
17 * Copyright 2013 Daniel Borkmann <borkmann@redhat.com>
18 * Licensed under the GNU General Public License, version 2.0 (GPLv2)
28 #include <linux/filter.h>
30 #include "bpf_exp.yacc.h"
32 extern void yyerror(const char *str);
50 "ldb" { return OP_LDB; }
51 "ldh" { return OP_LDH; }
52 "ld" { return OP_LD; }
53 "ldi" { return OP_LDI; }
54 "ldx" { return OP_LDX; }
55 "ldxi" { return OP_LDXI; }
56 "ldxb" { return OP_LDXB; }
57 "st" { return OP_ST; }
58 "stx" { return OP_STX; }
59 "jmp" { return OP_JMP; }
60 "ja" { return OP_JMP; }
61 "jeq" { return OP_JEQ; }
62 "jneq" { return OP_JNEQ; }
63 "jne" { return OP_JNEQ; }
64 "jlt" { return OP_JLT; }
65 "jle" { return OP_JLE; }
66 "jgt" { return OP_JGT; }
67 "jge" { return OP_JGE; }
68 "jset" { return OP_JSET; }
69 "add" { return OP_ADD; }
70 "sub" { return OP_SUB; }
71 "mul" { return OP_MUL; }
72 "div" { return OP_DIV; }
73 "mod" { return OP_MOD; }
74 "neg" { return OP_NEG; }
75 "and" { return OP_AND; }
76 "xor" { return OP_XOR; }
77 "or" { return OP_OR; }
78 "lsh" { return OP_LSH; }
79 "rsh" { return OP_RSH; }
80 "ret" { return OP_RET; }
81 "tax" { return OP_TAX; }
82 "txa" { return OP_TXA; }
84 "#"?("len") { return K_PKT_LEN; }
87 yylval.number = SKF_AD_PROTOCOL;
91 yylval.number = SKF_AD_PKTTYPE;
95 yylval.number = SKF_AD_PAY_OFFSET;
99 yylval.number = SKF_AD_IFINDEX;
103 yylval.number = SKF_AD_NLATTR;
107 yylval.number = SKF_AD_NLATTR_NEST;
111 yylval.number = SKF_AD_MARK;
115 yylval.number = SKF_AD_QUEUE;
119 yylval.number = SKF_AD_HATYPE;
123 yylval.number = SKF_AD_RXHASH;
127 yylval.number = SKF_AD_CPU;
131 yylval.number = SKF_AD_VLAN_TAG;
135 yylval.number = SKF_AD_VLAN_TAG_PRESENT;
139 yylval.number = SKF_AD_VLAN_TAG_PRESENT;
143 yylval.number = SKF_AD_VLAN_TPID;
147 yylval.number = SKF_AD_RANDOM;
166 ([0][x][a-fA-F0-9]+) {
167 yylval.number = strtoul(yytext, NULL, 16);
171 yylval.number = strtol(yytext + 2, NULL, 2);
174 (([0])|([-+]?[1-9][0-9]*)) {
175 yylval.number = strtol(yytext, NULL, 10);
179 yylval.number = strtol(yytext + 1, NULL, 8);
182 [a-zA-Z_][a-zA-Z0-9_]+ {
183 yylval.label = strdup(yytext);
187 "/*"([^\*]|\*[^/])*"*/" { /* NOP */ }
188 ";"[^\n]* { /* NOP */ }
194 printf("unknown character \'%s\'", yytext);
195 yyerror("lex unknown character");