|
14 | 14 | #include <errno.h> |
15 | 15 | #include <stdint.h> |
16 | 16 |
|
| 17 | +#include <bpfilter/elfstub.h> |
17 | 18 | #include <bpfilter/helper.h> |
18 | 19 | #include <bpfilter/logger.h> |
19 | 20 | #include <bpfilter/matcher.h> |
| 21 | +#include <bpfilter/rule.h> |
20 | 22 |
|
21 | 23 | #include "cgen/matcher/cmp.h" |
22 | 24 | #include "cgen/matcher/meta.h" |
23 | 25 | #include "cgen/matcher/set.h" |
24 | 26 | #include "cgen/program.h" |
| 27 | +#include "cgen/runtime.h" |
25 | 28 | #include "cgen/stub.h" |
26 | 29 | #include "filter.h" |
27 | 30 |
|
@@ -355,3 +358,25 @@ int bf_packet_gen_inline_matcher(struct bf_program *program, |
355 | 358 | bf_matcher_get_type(matcher)); |
356 | 359 | } |
357 | 360 | } |
| 361 | + |
| 362 | +int bf_packet_gen_inline_log(struct bf_program *program, |
| 363 | + const struct bf_rule *rule) |
| 364 | +{ |
| 365 | + assert(program); |
| 366 | + assert(rule); |
| 367 | + |
| 368 | + EMIT(program, BPF_MOV64_REG(BPF_REG_1, BPF_REG_10)); |
| 369 | + EMIT(program, BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, BF_PROG_CTX_OFF(arg))); |
| 370 | + EMIT(program, BPF_MOV64_IMM(BPF_REG_2, rule->index)); |
| 371 | + EMIT(program, BPF_MOV64_IMM(BPF_REG_3, rule->log)); |
| 372 | + EMIT(program, BPF_MOV64_IMM(BPF_REG_4, rule->verdict)); |
| 373 | + |
| 374 | + // Pack l3_proto and l4_proto |
| 375 | + EMIT(program, BPF_MOV64_REG(BPF_REG_5, BPF_REG_7)); |
| 376 | + EMIT(program, BPF_ALU64_IMM(BPF_LSH, BPF_REG_5, 16)); |
| 377 | + EMIT(program, BPF_ALU64_REG(BPF_OR, BPF_REG_5, BPF_REG_8)); |
| 378 | + |
| 379 | + EMIT_FIXUP_ELFSTUB(program, BF_ELFSTUB_PKT_LOG); |
| 380 | + |
| 381 | + return 0; |
| 382 | +} |
0 commit comments