summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpf_lexer.l1
-rw-r--r--bpf_parser.y69
-rw-r--r--bpfc.84
3 files changed, 71 insertions, 3 deletions
diff --git a/bpf_lexer.l b/bpf_lexer.l
index 185faae..26accbc 100644
--- a/bpf_lexer.l
+++ b/bpf_lexer.l
@@ -91,6 +91,7 @@ label [a-zA-Z_][a-zA-Z0-9_]+
":" { return ':'; }
"," { return ','; }
"#" { return '#'; }
+"%" { return '%'; }
"[" { return '['; }
"]" { return ']'; }
"(" { return '('; }
diff --git a/bpf_parser.y b/bpf_parser.y
index 48a6e4c..c8d2a8f 100644
--- a/bpf_parser.y
+++ b/bpf_parser.y
@@ -135,7 +135,7 @@ static int find_intr_offset_or_panic(char *label_to_search)
%token K_PKT_LEN K_PROTO K_TYPE K_NLATTR K_NLATTR_NEST K_MARK K_QUEUE K_HATYPE
%token K_RXHASH K_CPU K_IFIDX K_VLANT K_VLANP K_POFF
-%token ':' ',' '[' ']' '(' ')' 'x' 'a' '+' 'M' '*' '&' '#'
+%token ':' ',' '[' ']' '(' ')' 'x' 'a' '+' 'M' '*' '&' '#' '%'
%token number label
@@ -198,6 +198,8 @@ labelled
ldb
: OP_LDB '[' 'x' '+' number ']' {
set_curr_instr(BPF_LD | BPF_B | BPF_IND, 0, 0, $5); }
+ | OP_LDB '[' '%' 'x' '+' number ']' {
+ set_curr_instr(BPF_LD | BPF_B | BPF_IND, 0, 0, $6); }
| OP_LDB '[' number ']' {
set_curr_instr(BPF_LD | BPF_B | BPF_ABS, 0, 0, $3); }
| OP_LDB K_PROTO {
@@ -244,6 +246,8 @@ ldb
ldh
: OP_LDH '[' 'x' '+' number ']' {
set_curr_instr(BPF_LD | BPF_H | BPF_IND, 0, 0, $5); }
+ | OP_LDH '[' '%' 'x' '+' number ']' {
+ set_curr_instr(BPF_LD | BPF_H | BPF_IND, 0, 0, $6); }
| OP_LDH '[' number ']' {
set_curr_instr(BPF_LD | BPF_H | BPF_ABS, 0, 0, $3); }
| OP_LDH K_PROTO {
@@ -342,6 +346,8 @@ ld
set_curr_instr(BPF_LD | BPF_MEM, 0, 0, $4); }
| OP_LD '[' 'x' '+' number ']' {
set_curr_instr(BPF_LD | BPF_W | BPF_IND, 0, 0, $5); }
+ | OP_LD '[' '%' 'x' '+' number ']' {
+ set_curr_instr(BPF_LD | BPF_W | BPF_IND, 0, 0, $6); }
| OP_LD '[' number ']' {
set_curr_instr(BPF_LD | BPF_W | BPF_ABS, 0, 0, $3); }
;
@@ -397,12 +403,19 @@ jeq
set_jmp_label($4, JTL);
set_jmp_label($6, JFL);
set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
+ | OP_JEQ '%' 'x' ',' label ',' label {
+ set_jmp_label($5, JTL);
+ set_jmp_label($7, JFL);
+ set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
| OP_JEQ '#' number ',' label {
set_jmp_label($5, JTL);
set_curr_instr(BPF_JMP | BPF_JEQ | BPF_K, 0, 0, $3); }
| OP_JEQ 'x' ',' label {
set_jmp_label($4, JTL);
set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
+ | OP_JEQ '%' 'x' ',' label {
+ set_jmp_label($5, JTL);
+ set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
;
jneq
@@ -412,6 +425,9 @@ jneq
| OP_JNEQ 'x' ',' label {
set_jmp_label($4, JFL);
set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
+ | OP_JNEQ '%' 'x' ',' label {
+ set_jmp_label($5, JFL);
+ set_curr_instr(BPF_JMP | BPF_JEQ | BPF_X, 0, 0, 0); }
;
jlt
@@ -421,6 +437,9 @@ jlt
| OP_JLT 'x' ',' label {
set_jmp_label($4, JFL);
set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
+ | OP_JLT '%' 'x' ',' label {
+ set_jmp_label($5, JFL);
+ set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
;
jle
@@ -430,6 +449,9 @@ jle
| OP_JLE 'x' ',' label {
set_jmp_label($4, JFL);
set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
+ | OP_JLE '%' 'x' ',' label {
+ set_jmp_label($5, JFL);
+ set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
;
jgt
@@ -441,12 +463,19 @@ jgt
set_jmp_label($4, JTL);
set_jmp_label($6, JFL);
set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
+ | OP_JGT '%' 'x' ',' label ',' label {
+ set_jmp_label($5, JTL);
+ set_jmp_label($7, JFL);
+ set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
| OP_JGT '#' number ',' label {
set_jmp_label($5, JTL);
set_curr_instr(BPF_JMP | BPF_JGT | BPF_K, 0, 0, $3); }
| OP_JGT 'x' ',' label {
set_jmp_label($4, JTL);
set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
+ | OP_JGT '%' 'x' ',' label {
+ set_jmp_label($5, JTL);
+ set_curr_instr(BPF_JMP | BPF_JGT | BPF_X, 0, 0, 0); }
;
jge
@@ -458,12 +487,19 @@ jge
set_jmp_label($4, JTL);
set_jmp_label($6, JFL);
set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
+ | OP_JGE '%' 'x' ',' label ',' label {
+ set_jmp_label($5, JTL);
+ set_jmp_label($7, JFL);
+ set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
| OP_JGE '#' number ',' label {
set_jmp_label($5, JTL);
set_curr_instr(BPF_JMP | BPF_JGE | BPF_K, 0, 0, $3); }
| OP_JGE 'x' ',' label {
set_jmp_label($4, JTL);
set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
+ | OP_JGE '%' 'x' ',' label {
+ set_jmp_label($5, JTL);
+ set_curr_instr(BPF_JMP | BPF_JGE | BPF_X, 0, 0, 0); }
;
jset
@@ -475,12 +511,19 @@ jset
set_jmp_label($4, JTL);
set_jmp_label($6, JFL);
set_curr_instr(BPF_JMP | BPF_JSET | BPF_X, 0, 0, 0); }
+ | OP_JSET '%' 'x' ',' label ',' label {
+ set_jmp_label($5, JTL);
+ set_jmp_label($7, JFL);
+ set_curr_instr(BPF_JMP | BPF_JSET | BPF_X, 0, 0, 0); }
| OP_JSET '#' number ',' label {
set_jmp_label($5, JTL);
set_curr_instr(BPF_JMP | BPF_JSET | BPF_K, 0, 0, $3); }
| OP_JSET 'x' ',' label {
set_jmp_label($4, JTL);
set_curr_instr(BPF_JMP | BPF_JSET | BPF_X, 0, 0, 0); }
+ | OP_JSET '%' 'x' ',' label {
+ set_jmp_label($5, JTL);
+ set_curr_instr(BPF_JMP | BPF_JSET | BPF_X, 0, 0, 0); }
;
add
@@ -488,6 +531,8 @@ add
set_curr_instr(BPF_ALU | BPF_ADD | BPF_K, 0, 0, $3); }
| OP_ADD 'x' {
set_curr_instr(BPF_ALU | BPF_ADD | BPF_X, 0, 0, 0); }
+ | OP_ADD '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_ADD | BPF_X, 0, 0, 0); }
;
sub
@@ -495,6 +540,8 @@ sub
set_curr_instr(BPF_ALU | BPF_SUB | BPF_K, 0, 0, $3); }
| OP_SUB 'x' {
set_curr_instr(BPF_ALU | BPF_SUB | BPF_X, 0, 0, 0); }
+ | OP_SUB '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_SUB | BPF_X, 0, 0, 0); }
;
mul
@@ -502,6 +549,8 @@ mul
set_curr_instr(BPF_ALU | BPF_MUL | BPF_K, 0, 0, $3); }
| OP_MUL 'x' {
set_curr_instr(BPF_ALU | BPF_MUL | BPF_X, 0, 0, 0); }
+ | OP_MUL '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_MUL | BPF_X, 0, 0, 0); }
;
div
@@ -509,6 +558,8 @@ div
set_curr_instr(BPF_ALU | BPF_DIV | BPF_K, 0, 0, $3); }
| OP_DIV 'x' {
set_curr_instr(BPF_ALU | BPF_DIV | BPF_X, 0, 0, 0); }
+ | OP_DIV '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_DIV | BPF_X, 0, 0, 0); }
;
mod
@@ -516,6 +567,8 @@ mod
set_curr_instr(BPF_ALU | BPF_MOD | BPF_K, 0, 0, $3); }
| OP_MOD 'x' {
set_curr_instr(BPF_ALU | BPF_MOD | BPF_X, 0, 0, 0); }
+ | OP_MOD '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_MOD | BPF_X, 0, 0, 0); }
;
neg
@@ -528,6 +581,8 @@ and
set_curr_instr(BPF_ALU | BPF_AND | BPF_K, 0, 0, $3); }
| OP_AND 'x' {
set_curr_instr(BPF_ALU | BPF_AND | BPF_X, 0, 0, 0); }
+ | OP_AND '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_AND | BPF_X, 0, 0, 0); }
;
or
@@ -535,6 +590,8 @@ or
set_curr_instr(BPF_ALU | BPF_OR | BPF_K, 0, 0, $3); }
| OP_OR 'x' {
set_curr_instr(BPF_ALU | BPF_OR | BPF_X, 0, 0, 0); }
+ | OP_OR '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_OR | BPF_X, 0, 0, 0); }
;
xor
@@ -542,6 +599,8 @@ xor
set_curr_instr(BPF_ALU | BPF_XOR | BPF_K, 0, 0, $3); }
| OP_XOR 'x' {
set_curr_instr(BPF_ALU | BPF_XOR | BPF_X, 0, 0, 0); }
+ | OP_XOR '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_XOR | BPF_X, 0, 0, 0); }
;
lsh
@@ -549,6 +608,8 @@ lsh
set_curr_instr(BPF_ALU | BPF_LSH | BPF_K, 0, 0, $3); }
| OP_LSH 'x' {
set_curr_instr(BPF_ALU | BPF_LSH | BPF_X, 0, 0, 0); }
+ | OP_LSH '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_LSH | BPF_X, 0, 0, 0); }
;
rsh
@@ -556,13 +617,19 @@ rsh
set_curr_instr(BPF_ALU | BPF_RSH | BPF_K, 0, 0, $3); }
| OP_RSH 'x' {
set_curr_instr(BPF_ALU | BPF_RSH | BPF_X, 0, 0, 0); }
+ | OP_RSH '%' 'x' {
+ set_curr_instr(BPF_ALU | BPF_RSH | BPF_X, 0, 0, 0); }
;
ret
: OP_RET 'a' {
set_curr_instr(BPF_RET | BPF_A, 0, 0, 0); }
+ | OP_RET '%' 'a' {
+ set_curr_instr(BPF_RET | BPF_A, 0, 0, 0); }
| OP_RET 'x' {
set_curr_instr(BPF_RET | BPF_X, 0, 0, 0); }
+ | OP_RET '%' 'x' {
+ set_curr_instr(BPF_RET | BPF_X, 0, 0, 0); }
| OP_RET '#' number {
set_curr_instr(BPF_RET | BPF_K, 0, 0, $3); }
;
diff --git a/bpfc.8 b/bpfc.8
index 5ef7a04..c65fbec 100644
--- a/bpfc.8
+++ b/bpfc.8
@@ -158,7 +158,7 @@ unsigned data structures:
.PP
Addressing mode Syntax Description
.PP
- 0 x Register X
+ 0 x/%x Register X
1 [k] BHW at byte offset k in the packet
2 [x + k] BHW at the offset X + k in the packet
3 M[k] Word at offset k in M[]
@@ -167,7 +167,7 @@ unsigned data structures:
6 L Jump label L
7 #k,Lt,Lf Jump to Lt if true, otherwise jump to Lf
8 #k,Lt Jump to Lt if predicate is true
- 9 a Accumulator A
+ 9 a/%a Accumulator A
10 extension BPF extension (see next table)
.PP
Extension (and alias) Description