Merge "more classic bpf macros" into main
This commit is contained in:
@@ -22,9 +22,15 @@
|
||||
// Reject the packet
|
||||
#define BPF_REJECT BPF_STMT(BPF_RET | BPF_K, 0)
|
||||
|
||||
// Note arguments to BPF_JUMP(opcode, operand, true_offset, false_offset)
|
||||
|
||||
// If not equal, jump over count instructions
|
||||
#define BPF_JUMP_IF_NOT_EQUAL(v, count) \
|
||||
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (v), 0, (count))
|
||||
|
||||
// *TWO* instructions: compare and if not equal jump over the accept statement
|
||||
#define BPF2_ACCEPT_IF_EQUAL(v) \
|
||||
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (v), 0, 1), \
|
||||
BPF_JUMP_IF_NOT_EQUAL((v), 1), \
|
||||
BPF_ACCEPT
|
||||
|
||||
// *TWO* instructions: compare and if equal jump over the reject statement
|
||||
@@ -32,6 +38,22 @@
|
||||
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (v), 1, 0), \
|
||||
BPF_REJECT
|
||||
|
||||
// *TWO* instructions: compare and if greater or equal jump over the reject statement
|
||||
#define BPF2_REJECT_IF_LESS_THAN(v) \
|
||||
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, (v), 1, 0), \
|
||||
BPF_REJECT
|
||||
|
||||
// *TWO* instructions: compare and if *NOT* greater jump over the reject statement
|
||||
#define BPF2_REJECT_IF_GREATER_THAN(v) \
|
||||
BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, (v), 0, 1), \
|
||||
BPF_REJECT
|
||||
|
||||
// *THREE* instructions: compare and if *NOT* in range [lo, hi], jump over the reject statement
|
||||
#define BPF3_REJECT_IF_NOT_IN_RANGE(lo, hi) \
|
||||
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, (lo), 0, 1), \
|
||||
BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, (hi), 0, 1), \
|
||||
BPF_REJECT
|
||||
|
||||
// *TWO* instructions: compare and if none of the bits are set jump over the reject statement
|
||||
#define BPF2_REJECT_IF_ANY_MASKED_BITS_SET(v) \
|
||||
BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, (v), 0, 1), \
|
||||
|
||||
Reference in New Issue
Block a user