Skip to content

Commit ec47ba3

Browse files
committed
contrib: don't use bpf_usdt_readarg_p
1 parent 35ae6ff commit ec47ba3

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

contrib/tracing/log_raw_p2p_msgs.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,23 @@
7878
int trace_inbound_message(struct pt_regs *ctx) {
7979
int idx = 0;
8080
struct p2p_message *msg = msg_arr.lookup(&idx);
81+
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL;
8182
8283
// lookup() does not return a NULL pointer. However, the BPF verifier
8384
// requires an explicit check that that the `msg` pointer isn't a NULL
8485
// pointer. See https://github.com/iovisor/bcc/issues/2595
8586
if (msg == NULL) return 1;
8687
8788
bpf_usdt_readarg(1, ctx, &msg->peer_id);
88-
bpf_usdt_readarg_p(2, ctx, &msg->peer_addr, MAX_PEER_ADDR_LENGTH);
89-
bpf_usdt_readarg_p(3, ctx, &msg->peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
90-
bpf_usdt_readarg_p(4, ctx, &msg->msg_type, MAX_MSG_TYPE_LENGTH);
89+
bpf_usdt_readarg(2, ctx, &paddr);
90+
bpf_probe_read_user_str(&msg->peer_addr, sizeof(msg->peer_addr), paddr);
91+
bpf_usdt_readarg(3, ctx, &pconn_type);
92+
bpf_probe_read_user_str(&msg->peer_conn_type, sizeof(msg->peer_conn_type), pconn_type);
93+
bpf_usdt_readarg(4, ctx, &pmsg_type);
94+
bpf_probe_read_user_str(&msg->msg_type, sizeof(msg->msg_type), pmsg_type);
9195
bpf_usdt_readarg(5, ctx, &msg->msg_size);
92-
bpf_usdt_readarg_p(6, ctx, &msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH));
96+
bpf_usdt_readarg(6, ctx, &pmsg);
97+
bpf_probe_read_user(&msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH), pmsg);
9398
9499
inbound_messages.perf_submit(ctx, msg, sizeof(*msg));
95100
return 0;
@@ -99,17 +104,23 @@
99104
int idx = 0;
100105
struct p2p_message *msg = msg_arr.lookup(&idx);
101106
107+
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL, *pmsg = NULL;
108+
102109
// lookup() does not return a NULL pointer. However, the BPF verifier
103110
// requires an explicit check that that the `msg` pointer isn't a NULL
104111
// pointer. See https://github.com/iovisor/bcc/issues/2595
105112
if (msg == NULL) return 1;
106113
107114
bpf_usdt_readarg(1, ctx, &msg->peer_id);
108-
bpf_usdt_readarg_p(2, ctx, &msg->peer_addr, MAX_PEER_ADDR_LENGTH);
109-
bpf_usdt_readarg_p(3, ctx, &msg->peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
110-
bpf_usdt_readarg_p(4, ctx, &msg->msg_type, MAX_MSG_TYPE_LENGTH);
115+
bpf_usdt_readarg(2, ctx, &paddr);
116+
bpf_probe_read_user_str(&msg->peer_addr, sizeof(msg->peer_addr), paddr);
117+
bpf_usdt_readarg(3, ctx, &pconn_type);
118+
bpf_probe_read_user_str(&msg->peer_conn_type, sizeof(msg->peer_conn_type), pconn_type);
119+
bpf_usdt_readarg(4, ctx, &pmsg_type);
120+
bpf_probe_read_user_str(&msg->msg_type, sizeof(msg->msg_type), pmsg_type);
111121
bpf_usdt_readarg(5, ctx, &msg->msg_size);
112-
bpf_usdt_readarg_p(6, ctx, &msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH));
122+
bpf_usdt_readarg(6, ctx, &pmsg);
123+
bpf_probe_read_user(&msg->msg, _TRACEPOINT_TEST_MIN(msg->msg_size, MAX_MSG_DATA_LENGTH), pmsg);
113124
114125
outbound_messages.perf_submit(ctx, msg, sizeof(*msg));
115126
return 0;

contrib/tracing/mempool_monitor.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
6666
int trace_added(struct pt_regs *ctx) {
6767
struct added_event added = {};
68-
69-
bpf_usdt_readarg_p(1, ctx, &added.hash, HASH_LENGTH);
68+
void *phash = NULL;
69+
bpf_usdt_readarg(1, ctx, phash);
70+
bpf_probe_read_user(&added.hash, sizeof(added.hash), phash);
7071
bpf_usdt_readarg(2, ctx, &added.vsize);
7172
bpf_usdt_readarg(3, ctx, &added.fee);
7273
@@ -76,9 +77,11 @@
7677
7778
int trace_removed(struct pt_regs *ctx) {
7879
struct removed_event removed = {};
79-
80-
bpf_usdt_readarg_p(1, ctx, &removed.hash, HASH_LENGTH);
81-
bpf_usdt_readarg_p(2, ctx, &removed.reason, MAX_REMOVAL_REASON_LENGTH);
80+
void *phash = NULL, *preason = NULL;
81+
bpf_usdt_readarg(1, ctx, phash);
82+
bpf_probe_read_user(&removed.hash, sizeof(removed.hash), phash);
83+
bpf_usdt_readarg(1, ctx, preason);
84+
bpf_probe_read_user_str(&removed.reason, sizeof(removed.reason), preason);
8285
bpf_usdt_readarg(3, ctx, &removed.vsize);
8386
bpf_usdt_readarg(4, ctx, &removed.fee);
8487
bpf_usdt_readarg(5, ctx, &removed.entry_time);
@@ -89,22 +92,25 @@
8992
9093
int trace_rejected(struct pt_regs *ctx) {
9194
struct rejected_event rejected = {};
92-
93-
bpf_usdt_readarg_p(1, ctx, &rejected.hash, HASH_LENGTH);
94-
bpf_usdt_readarg_p(2, ctx, &rejected.reason, MAX_REJECT_REASON_LENGTH);
95-
95+
void *phash = NULL, *preason = NULL;
96+
bpf_usdt_readarg(1, ctx, phash);
97+
bpf_probe_read_user(&rejected.hash, sizeof(rejected.hash), phash);
98+
bpf_usdt_readarg(1, ctx, preason);
99+
bpf_probe_read_user_str(&rejected.reason, sizeof(rejected.reason), preason);
96100
rejected_events.perf_submit(ctx, &rejected, sizeof(rejected));
97101
return 0;
98102
}
99103
100104
int trace_replaced(struct pt_regs *ctx) {
101105
struct replaced_event replaced = {};
102-
103-
bpf_usdt_readarg_p(1, ctx, &replaced.replaced_hash, HASH_LENGTH);
106+
void *phash_replaced = NULL, *phash_replacement = NULL;
107+
bpf_usdt_readarg(1, ctx, phash_replaced);
108+
bpf_probe_read_user(&replaced.replaced_hash, sizeof(replaced.replaced_hash), phash_replaced);
104109
bpf_usdt_readarg(2, ctx, &replaced.replaced_vsize);
105110
bpf_usdt_readarg(3, ctx, &replaced.replaced_fee);
106111
bpf_usdt_readarg(4, ctx, &replaced.replaced_entry_time);
107-
bpf_usdt_readarg_p(5, ctx, &replaced.replacement_hash, HASH_LENGTH);
112+
bpf_usdt_readarg(5, ctx, phash_replacement);
113+
bpf_probe_read_user(&replaced.replacement_hash, sizeof(replaced.replacement_hash), phash_replacement);
108114
bpf_usdt_readarg(6, ctx, &replaced.replacement_vsize);
109115
bpf_usdt_readarg(7, ctx, &replaced.replacement_fee);
110116

contrib/tracing/p2p_monitor.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@
4747
4848
int trace_inbound_message(struct pt_regs *ctx) {
4949
struct p2p_message msg = {};
50+
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL;
5051
5152
bpf_usdt_readarg(1, ctx, &msg.peer_id);
52-
bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH);
53-
bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
54-
bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH);
53+
bpf_usdt_readarg(2, ctx, &paddr);
54+
bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr);
55+
bpf_usdt_readarg(3, ctx, &pconn_type);
56+
bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type);
57+
bpf_usdt_readarg(4, ctx, &pconn_type);
58+
bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type);
5559
bpf_usdt_readarg(5, ctx, &msg.msg_size);
5660
5761
inbound_messages.perf_submit(ctx, &msg, sizeof(msg));
@@ -60,11 +64,15 @@
6064
6165
int trace_outbound_message(struct pt_regs *ctx) {
6266
struct p2p_message msg = {};
67+
void *paddr = NULL, *pconn_type = NULL, *pmsg_type = NULL;
6368
6469
bpf_usdt_readarg(1, ctx, &msg.peer_id);
65-
bpf_usdt_readarg_p(2, ctx, &msg.peer_addr, MAX_PEER_ADDR_LENGTH);
66-
bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
67-
bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH);
70+
bpf_usdt_readarg(2, ctx, &paddr);
71+
bpf_probe_read_user_str(&msg.peer_addr, sizeof(msg.peer_addr), paddr);
72+
bpf_usdt_readarg(3, ctx, &pconn_type);
73+
bpf_probe_read_user_str(&msg.peer_conn_type, sizeof(msg.peer_conn_type), pconn_type);
74+
bpf_usdt_readarg(4, ctx, &pconn_type);
75+
bpf_probe_read_user_str(&msg.msg_type, sizeof(msg.msg_type), pmsg_type);
6876
bpf_usdt_readarg(5, ctx, &msg.msg_size);
6977
7078
outbound_messages.perf_submit(ctx, &msg, sizeof(msg));

0 commit comments

Comments
 (0)