Skip to content

Commit fc22bec

Browse files
committed
revert changes to usm code
1 parent 5cc3e71 commit fc22bec

File tree

3 files changed

+152
-206
lines changed

3 files changed

+152
-206
lines changed

pkg/network/ebpf/c/prebuilt/usm.c

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "offsets.h"
88

99
#include "protocols/classification/dispatcher-helpers.h"
10+
#include "protocols/flush.h"
1011
#include "protocols/http/buffer.h"
1112
#include "protocols/http/http.h"
1213
#include "protocols/http2/decoding.h"
@@ -15,8 +16,6 @@
1516
#include "protocols/postgres/decoding.h"
1617
#include "protocols/redis/decoding.h"
1718
#include "protocols/sockfd-probes.h"
18-
#include "protocols/tls/java/erpc_dispatcher.h"
19-
#include "protocols/tls/java/erpc_handlers.h"
2019
#include "protocols/tls/https.h"
2120
#include "protocols/tls/native-tls.h"
2221
#include "protocols/tls/tags-types.h"
@@ -41,39 +40,4 @@ int uprobe__tls_protocol_dispatcher_kafka(struct pt_regs *ctx) {
4140
return 0;
4241
};
4342

44-
SEC("kprobe/tcp_sendmsg")
45-
int BPF_BYPASSABLE_KPROBE(kprobe__tcp_sendmsg, struct sock *sk) {
46-
log_debug("kprobe/tcp_sendmsg: sk=%p", sk);
47-
// map connection tuple during SSL_do_handshake(ctx)
48-
map_ssl_ctx_to_sock(sk);
49-
50-
return 0;
51-
}
52-
53-
static __always_inline int flush(void *ctx) {
54-
// flush batch to userspace
55-
// because perf events can't be sent from socket filter programs
56-
http_batch_flush(ctx);
57-
http2_batch_flush(ctx);
58-
terminated_http2_batch_flush(ctx);
59-
kafka_batch_flush(ctx);
60-
postgres_batch_flush(ctx);
61-
redis_batch_flush(ctx);
62-
return 0;
63-
}
64-
65-
SEC("raw_tracepoint/net/netif_receive_skb")
66-
int BPF_PROG(raw_tracepoint__net__netif_receive_skb) {
67-
CHECK_BPF_PROGRAM_BYPASSED()
68-
log_debug("raw_tracepoint/net/netif_receive_skb");
69-
return flush(ctx);
70-
}
71-
72-
SEC("tracepoint/net/netif_receive_skb")
73-
int tracepoint__net__netif_receive_skb(void *ctx) {
74-
CHECK_BPF_PROGRAM_BYPASSED()
75-
log_debug("tracepoint/net/netif_receive_skb");
76-
return flush(ctx);
77-
}
78-
7943
char _license[] SEC("license") = "GPL";

pkg/network/ebpf/c/runtime/usm.c

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#include "ipv6.h"
1414
#include "sock.h"
1515
#include "port_range.h"
16+
#include "pid_tgid.h"
1617

1718
#include "protocols/classification/dispatcher-helpers.h"
19+
#include "protocols/flush.h"
1820
#include "protocols/http/buffer.h"
1921
#include "protocols/http/http.h"
2022
#include "protocols/http2/decoding.h"
@@ -23,8 +25,6 @@
2325
#include "protocols/postgres/decoding.h"
2426
#include "protocols/redis/decoding.h"
2527
#include "protocols/sockfd-probes.h"
26-
#include "protocols/tls/java/erpc_dispatcher.h"
27-
#include "protocols/tls/java/erpc_handlers.h"
2828
#include "protocols/tls/go-tls-types.h"
2929
#include "protocols/tls/go-tls-goid.h"
3030
#include "protocols/tls/go-tls-location.h"
@@ -56,48 +56,13 @@ int uprobe__tls_protocol_dispatcher_kafka(struct pt_regs *ctx) {
5656
return 0;
5757
};
5858

59-
SEC("kprobe/tcp_sendmsg")
60-
int BPF_BYPASSABLE_KPROBE(kprobe__tcp_sendmsg, struct sock *sk) {
61-
log_debug("kprobe/tcp_sendmsg: sk=%p", sk);
62-
// map connection tuple during SSL_do_handshake(ctx)
63-
map_ssl_ctx_to_sock(sk);
64-
65-
return 0;
66-
}
67-
68-
static __always_inline int flush(void *ctx) {
69-
// flush batch to userspace
70-
// because perf events can't be sent from socket filter programs
71-
http_batch_flush(ctx);
72-
http2_batch_flush(ctx);
73-
terminated_http2_batch_flush(ctx);
74-
kafka_batch_flush(ctx);
75-
postgres_batch_flush(ctx);
76-
redis_batch_flush(ctx);
77-
return 0;
78-
}
79-
80-
SEC("raw_tracepoint/net/netif_receive_skb")
81-
int BPF_PROG(raw_tracepoint__net__netif_receive_skb) {
82-
CHECK_BPF_PROGRAM_BYPASSED()
83-
log_debug("raw_tracepoint/net/netif_receive_skb");
84-
return flush(ctx);
85-
}
86-
87-
SEC("tracepoint/net/netif_receive_skb")
88-
int tracepoint__net__netif_receive_skb(void *ctx) {
89-
CHECK_BPF_PROGRAM_BYPASSED()
90-
log_debug("tracepoint/net/netif_receive_skb");
91-
return flush(ctx);
92-
}
93-
9459
// GO TLS PROBES
9560

9661
// func (c *Conn) Write(b []byte) (int, error)
9762
SEC("uprobe/crypto/tls.(*Conn).Write")
9863
int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Write) {
9964
u64 pid_tgid = bpf_get_current_pid_tgid();
100-
u64 pid = pid_tgid >> 32;
65+
u64 pid = GET_USER_MODE_PID(pid_tgid);
10166
tls_offsets_data_t* od = get_offsets_data();
10267
if (od == NULL) {
10368
log_debug("[go-tls-write] no offsets data in map for pid %llu", pid);
@@ -130,15 +95,15 @@ int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Write) {
13095
return 0;
13196
}
13297

133-
bpf_map_update_elem(&go_tls_write_args, &call_key, &call_data, BPF_ANY);
98+
bpf_map_update_with_telemetry(go_tls_write_args, &call_key, &call_data, BPF_ANY);
13499
return 0;
135100
}
136101

137102
// func (c *Conn) Write(b []byte) (int, error)
138103
SEC("uprobe/crypto/tls.(*Conn).Write/return")
139104
int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Write__return) {
140105
u64 pid_tgid = bpf_get_current_pid_tgid();
141-
u64 pid = pid_tgid >> 32;
106+
u64 pid = GET_USER_MODE_PID(pid_tgid);
142107
tls_offsets_data_t* od = get_offsets_data();
143108
if (od == NULL) {
144109
log_debug("[go-tls-write-return] no offsets data in map for pid %llu", pid);
@@ -213,42 +178,42 @@ int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Write__return) {
213178
SEC("uprobe/crypto/tls.(*Conn).Read")
214179
int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Read) {
215180
u64 pid_tgid = bpf_get_current_pid_tgid();
216-
u64 pid = pid_tgid >> 32;
181+
u64 pid = GET_USER_MODE_PID(pid_tgid);
217182
tls_offsets_data_t* od = get_offsets_data();
218183
if (od == NULL) {
219-
log_debug("[go-tls-read] no offsets data in map for pid %llu", pid_tgid >> 32);
184+
log_debug("[go-tls-read] no offsets data in map for pid %llu", pid);
220185
return 0;
221186
}
222187

223188
// Read the PID and goroutine ID to make the partial call key
224189
go_tls_function_args_key_t call_key = {0};
225190
call_key.pid = pid;
226191
if (read_goroutine_id(ctx, &od->goroutine_id, &call_key.goroutine_id)) {
227-
log_debug("[go-tls-read] failed reading go routine id for pid %llu", pid_tgid >> 32);
192+
log_debug("[go-tls-read] failed reading go routine id for pid %llu", pid);
228193
return 0;
229194
}
230195

231196
// Read the parameters to make the partial call data
232197
// (since the parameters might not be live by the time the return probe is hit).
233198
go_tls_read_args_data_t call_data = {0};
234199
if (read_location(ctx, &od->read_conn_pointer, sizeof(call_data.conn_pointer), &call_data.conn_pointer)) {
235-
log_debug("[go-tls-read] failed reading conn pointer for pid %llu", pid_tgid >> 32);
200+
log_debug("[go-tls-read] failed reading conn pointer for pid %llu", pid);
236201
return 0;
237202
}
238203
if (read_location(ctx, &od->read_buffer.ptr, sizeof(call_data.b_data), &call_data.b_data)) {
239-
log_debug("[go-tls-read] failed reading buffer pointer for pid %llu", pid_tgid >> 32);
204+
log_debug("[go-tls-read] failed reading buffer pointer for pid %llu", pid);
240205
return 0;
241206
}
242207

243-
bpf_map_update_elem(&go_tls_read_args, &call_key, &call_data, BPF_ANY);
208+
bpf_map_update_with_telemetry(go_tls_read_args, &call_key, &call_data, BPF_ANY);
244209
return 0;
245210
}
246211

247212
// func (c *Conn) Read(b []byte) (int, error)
248213
SEC("uprobe/crypto/tls.(*Conn).Read/return")
249214
int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Read__return) {
250215
u64 pid_tgid = bpf_get_current_pid_tgid();
251-
u64 pid = pid_tgid >> 32;
216+
u64 pid = GET_USER_MODE_PID(pid_tgid);
252217
tls_offsets_data_t* od = get_offsets_data();
253218
if (od == NULL) {
254219
log_debug("[go-tls-read-return] no offsets data in map for pid %llu", pid);
@@ -318,27 +283,27 @@ int BPF_BYPASSABLE_UPROBE(uprobe__crypto_tls_Conn_Close) {
318283
u64 pid_tgid = bpf_get_current_pid_tgid();
319284
tls_offsets_data_t* od = get_offsets_data();
320285
if (od == NULL) {
321-
log_debug("[go-tls-close] no offsets data in map for pid %llu", pid_tgid >> 32);
286+
log_debug("[go-tls-close] no offsets data in map for pid %llu", GET_USER_MODE_PID(pid_tgid));
322287
return 0;
323288
}
324289

325290
// Read the PID and goroutine ID to make the partial call key
326291
go_tls_function_args_key_t call_key = {0};
327-
call_key.pid = pid_tgid >> 32;
292+
call_key.pid = GET_USER_MODE_PID(pid_tgid);
328293
if (read_goroutine_id(ctx, &od->goroutine_id, &call_key.goroutine_id) == 0) {
329294
bpf_map_delete_elem(&go_tls_read_args, &call_key);
330295
bpf_map_delete_elem(&go_tls_write_args, &call_key);
331296
}
332297

333298
void* conn_pointer = NULL;
334299
if (read_location(ctx, &od->close_conn_pointer, sizeof(conn_pointer), &conn_pointer)) {
335-
log_debug("[go-tls-close] failed reading close conn pointer for pid %llu", pid_tgid >> 32);
300+
log_debug("[go-tls-close] failed reading close conn pointer for pid %llu", GET_USER_MODE_PID(pid_tgid));
336301
return 0;
337302
}
338303

339304
conn_tuple_t* t = conn_tup_from_tls_conn(od, conn_pointer, pid_tgid);
340305
if (t == NULL) {
341-
log_debug("[go-tls-close] failed getting conn tup from tls conn for pid %llu", pid_tgid >> 32);
306+
log_debug("[go-tls-close] failed getting conn tup from tls conn for pid %llu", GET_USER_MODE_PID(pid_tgid));
342307
return 0;
343308
}
344309

0 commit comments

Comments
 (0)