-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfentry_fexit.c
58 lines (43 loc) · 1.41 KB
/
fentry_fexit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright 2023 Leon Hwang.
* SPDX-License-Identifier: MIT
*/
//go:build ignore
#include "bpf_all.h"
#include "lib_tp_msg.h"
struct netlink_extack_error_ctx {
unsigned long unused;
/*
* bpf does not support tracepoint __data_loc directly.
*
* Actually, this field is a 32 bit integer whose value encodes
* information on where to find the actual data. The first 2 bytes is
* the size of the data. The last 2 bytes is the offset from the start
* of the tracepoint struct where the data begins.
* -- https://github.com/iovisor/bpftrace/pull/1542
*/
__u32 msg; // __data_loc char[] msg;
};
SEC("fentry/netlink_extack")
int BPF_PROG(fentry_netlink_extack, struct netlink_extack_error_ctx *nl_ctx)
{
bpf_printk("tcpconn, fentry_netlink_extack\n");
/*
* BPF_CORE_READ() is not dedicated to user-defined struct.
*/
__u32 msg;
bpf_probe_read(&msg, sizeof(msg), &nl_ctx->msg);
char *c = (void *)(__u64) ((void *) nl_ctx + (__u64) (msg & 0xFFFF));
__output_msg(ctx, c, PROBE_TYPE_FENTRY, 0);
return 0;
}
SEC("fexit/netlink_extack")
int BPF_PROG(fexit_netlink_extack, struct netlink_extack_error_ctx *nl_ctx, int retval)
{
bpf_printk("tcpconn, fexit_netlink_extack\n");
__u32 msg;
bpf_probe_read(&msg, sizeof(msg), &nl_ctx->msg);
char *c = (void *)(__u64) ((void *) nl_ctx + (__u64) (msg & 0xFFFF));
__output_msg(ctx, c, PROBE_TYPE_FEXIT, retval);
return 0;
}