contrib: don't use bpf_usdt_readarg_p

This commit is contained in:
0xb10c committed 2025-02-12 16:28:28 +01:00
1 parent 35ae6ff60f
commit ec47ba349d
3 files changed
+51 -26

No files matched your search

+19 -8
View File
@@ -78,6 +78,7 @@ BPF_PERF_OUTPUT(outbound_messages);
int trace_inbound_message(struct pt_regs *ctx) {
int idx = 0;
struct p2p_message *msg = msg_arr.lookup(&idx);
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL;
// lookup() does not return a NULL pointer. However, the BPF verifier
// requires an explicit check that that the `msg` pointer isn't a NULL
@@ -85,11 +86,15 @@ int trace_inbound_message(struct pt_regs *ctx) {
if (msg == NULL) return 1;
bpf_usdt_readarg(1, ctx, &msg->peer_id);
bpf_usdt_readarg_p(2, ctx, &msg->peer_addr, MAX_PEER_ADDR_LENGTH);
bpf_usdt_readarg_p(3, ctx, &msg->peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
bpf_usdt_readarg_p(4, ctx, &msg->msg_type, MAX_MSG_TYPE_LENGTH);
bpf_usdt_readarg(2, ctx, &paddr);
bpf_probe_read_user_str(&msg->peer_addr, sizeof(msg->peer_addr), paddr);
bpf_usdt_readarg(3, ctx, &pconn_type);
bpf_probe_read_user_str(&msg->peer_conn_type, sizeof(msg->peer_conn_type), pconn_type);
bpf_usdt_readarg(4, ctx, &pmsg_type);
bpf_probe_read_user_str(&msg->msg_type, sizeof(msg->msg_type), pmsg_type);
bpf_usdt_readarg(5, ctx, &msg->msg_size);
bpf_usdt_readarg_p(6, ctx, &msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH));
bpf_usdt_readarg(6, ctx, &pmsg);
bpf_probe_read_user(&msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH), pmsg);
inbound_messages.perf_submit(ctx, msg, sizeof(*msg));
return 0;
@@ -99,17 +104,23 @@ int trace_outbound_message(struct pt_regs *ctx) {
int idx = 0;
struct p2p_message *msg = msg_arr.lookup(&idx);
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL;
// lookup() does not return a NULL pointer. However, the BPF verifier
// requires an explicit check that that the `msg` pointer isn't a NULL
// pointer. See https://github.com/iovisor/bcc/issues/2595
if (msg == NULL) return 1;
bpf_usdt_readarg(1, ctx, &msg->peer_id);
bpf_usdt_readarg_p(2, ctx, &msg->peer_addr, MAX_PEER_ADDR_LENGTH);
bpf_usdt_readarg_p(3, ctx, &msg->peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
bpf_usdt_readarg_p(4, ctx, &msg->msg_type, MAX_MSG_TYPE_LENGTH);
bpf_usdt_readarg(2, ctx, &paddr);
bpf_probe_read_user_str(&msg->peer_addr, sizeof(msg->peer_addr), paddr);
bpf_usdt_readarg(3, ctx, &pconn_type);
bpf_probe_read_user_str(&msg->peer_conn_type, sizeof(msg->peer_conn_type), pconn_type);
bpf_usdt_readarg(4, ctx, &pmsg_type);
bpf_probe_read_user_str(&msg->msg_type, sizeof(msg->msg_type), pmsg_type);
bpf_usdt_readarg(5, ctx, &msg->msg_size);
bpf_usdt_readarg_p(6, ctx, &msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH));
bpf_usdt_readarg(6, ctx, &pmsg);
bpf_probe_read_user(&msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH), pmsg);
outbound_messages.perf_submit(ctx, msg, sizeof(*msg));
return 0;