Skip to content
Snippets Groups Projects
Commit d5bf2061 authored by Maciej Żenczykowski's avatar Maciej Żenczykowski
Browse files

more classic bpf macros


Test: TreeHugger
Signed-off-by: default avatarMaciej Żenczykowski <maze@google.com>
Change-Id: I5c7fd55301cd5aa44502f8481923c86bc49ea914
parent f24beefe
No related branches found
No related tags found
No related merge requests found
......@@ -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), \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment