8000 Fix wrong SSL port by rafaelroquetto · Pull Request #1920 · grafana/beyla · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix wrong SSL port #1920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions bpf/common/ssl_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
#include <maps/active_ssl_write_args.h>
#include <maps/ssl_to_conn.h>

static __always_inline void set_active_ssl_connection(pid_connection_info_t *conn, void *ssl) {
static __always_inline void set_active_ssl_connection(ssl_pid_connection_info_t *ssl_conn,
void *ssl) {
bpf_dbg_printk("Correlating SSL %llx to connection", ssl);
dbg_print_http_connection_info(&conn->conn);
dbg_print_http_connection_info(&ssl_conn->p_conn.conn);

bpf_map_update_elem(&active_ssl_connections, conn, &ssl, BPF_ANY);
bpf_map_update_elem(&ssl_to_conn, &ssl, conn, BPF_ANY);
bpf_map_update_elem(&active_ssl_connections, &ssl_conn->p_conn, &ssl, BPF_ANY);
bpf_map_update_elem(&ssl_to_conn, &ssl, ssl_conn, BPF_ANY);
}

static __always_inline void *unconnected_ssl_from_args(u64 id, u8 direction) {
Expand Down Expand Up @@ -47,22 +48,26 @@ static __always_inline void connect_ssl_to_sock(u64 id, struct sock *sock, u8 di
if (!ssl) {
return;
}
pid_connection_info_t p_conn = {0};
p_conn.pid = pid_from_pid_tgid(id);
bool success = parse_sock_info(sock, &p_conn.conn);
ssl_pid_connection_info_t ssl_conn = {0};
ssl_conn.p_conn.pid = pid_from_pid_tgid(id);
bool success = parse_sock_info(sock, &ssl_conn.p_conn.conn);
if (success) {
sort_connection_info(&p_conn.conn);
set_active_ssl_connection(&p_conn, ssl);
ssl_conn.orig_dport = ssl_conn.p_conn.conn.d_port;
sort_connection_info(&ssl_conn.p_conn.conn);
set_active_ssl_connection(&ssl_conn, ssl);
}
}

static __always_inline void
connect_ssl_to_connection(u64 id, pid_connection_info_t *conn, u8 direction) {
connect_ssl_to_connection(u64 id, pid_connection_info_t *conn, u8 direction, u16 orig_dport) {
void *ssl = unconnected_ssl_from_args(id, direction);
if (!ssl) {
return;
}
set_active_ssl_connection(conn, ssl);
ssl_pid_connection_info_t ssl_conn = {0};
ssl_conn.orig_dport = orig_dport;
ssl_conn.p_conn = *conn;
set_active_ssl_connection(&ssl_conn, ssl);
}

static __always_inline void *is_ssl_connection(pid_connection_info_t *conn) {
Expand Down
4 changes: 2 additions & 2 deletions bpf/generictracer/k_tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ int BPF_KPROBE(beyla_kprobe_tcp_sendmsg, struct sock *sk, struct msghdr *msg, si
s_args.p_conn.pid = pid_from_pid_tgid(id);
s_args.orig_dport = orig_dport;

connect_ssl_to_connection(id, &s_args.p_conn, TCP_SEND);
connect_ssl_to_connection(id, &s_args.p_conn, TCP_SEND, orig_dport);

void *ssl = is_ssl_connection(&s_args.p_conn);
if (size > 0) {
Expand Down Expand Up @@ -418,7 +418,7 @@ int BPF_KPROBE(beyla_kprobe_tcp_rate_check_app_limited, struct sock *sk) {
}
}

connect_ssl_to_connection(id, &s_args.p_conn, TCP_SEND);
connect_ssl_to_connection(id, &s_args.p_conn, TCP_SEND, orig_dport);

void *ssl = is_ssl_connection(&s_args.p_conn);
if (ssl) {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,24 @@ func testNestedHTTPSTracesKProbes(t *testing.T) {
jaeger.Tag{Key: "span.kind", Type: "string", Value: "server"},
)
assert.Empty(t, sd, sd.String())

// check client call (and ensure server port is correct/not swapped)
res = trace.FindByOperationName("GET /users", "client")
require.Len(t, res, 1)
parent = res[0]
require.NotEmpty(t, parent.TraceID)
require.Equal(t, traceID, parent.TraceID)
require.NotEmpty(t, parent.SpanID)
// check duration is at least 2us
assert.Less(t, (2 * time.Microsecond).Microseconds(), parent.Duration)
// check span attributes
sd = parent.Diff(
jaeger.Tag{Key: "http.request.method", Type: "string", Value: "GET"},
jaeger.Tag{Key: "http.response.status_code", Type: "int64", Value: float64(403)},
jaeger.Tag{Key: "server.port", Type: "int64", Value: float64(3043)},
jaeger.Tag{Key: "span.kind", Type: "string", Value: "client"},
)
assert.Empty(t, sd, sd.String())
}

func testHTTPTracesNestedSelfCalls(t *testing.T) {
Expand Down
Loading
0