From d4757b140364cd277f7f7f373475eb427003cb42 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Fri, 9 Jun 2023 18:52:16 +0200 Subject: cooker: Pass arguments to filter Signed-off-by: Stefano Brivio --- cooker/emit.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'cooker/emit.c') diff --git a/cooker/emit.c b/cooker/emit.c index 41b64a6..57533a1 100644 --- a/cooker/emit.c +++ b/cooker/emit.c @@ -11,6 +11,7 @@ #include "cooker.h" #include "gluten.h" +#include "filter.h" #include "util.h" #include "emit.h" @@ -536,6 +537,32 @@ static void gluten_link(struct gluten_ctx *g, enum jump_type type, } } +void emit_bpf_arg(int index, enum type type, union value v, union value mask, + enum op_cmp_type cmp) +{ + struct bpf_arg bpf; + + /* gluten uses the comparison to skip to the next match, the BPF filter + * uses it to notify instead. + */ + if (mask.v_num) + bpf.cmp = (cmp == CMP_EQ) ? AND_NE : AND_EQ; + else + bpf.cmp = (cmp == CMP_EQ) ? NE : EQ; + + if (TYPE_IS_64BIT(type)) { + bpf.value.v64 = v.v_num; + bpf.op2.v64 = mask.v_num; + bpf.type = BPF_U64; + } else { + bpf.value.v32 = v.v_num; + bpf.op2.v32 = mask.v_num; + bpf.type = BPF_U32; + } + + filter_add_arg(index, bpf); +} + void link_block(struct gluten_ctx *g) { debug(" Linking block..."); -- cgit v1.2.3