diff --git a/pkg/network/ebpf/c/tracer/events.h b/pkg/network/ebpf/c/tracer/events.h index 5e0650faa862f..3c17a1e1ec683 100644 --- a/pkg/network/ebpf/c/tracer/events.h +++ b/pkg/network/ebpf/c/tracer/events.h @@ -64,7 +64,7 @@ static __always_inline void cleanup_conn(void *ctx, conn_tuple_t *tup, struct so conn.tup.pid = 0; retrans = bpf_map_lookup_elem(&tcp_retransmits, &(conn.tup)); if (retrans) { - conn.tcp_retransmits = *retrans; + conn.tcp_stats.retransmits = *retrans; bpf_map_delete_elem(&tcp_retransmits, &(conn.tup)); } conn.tup.pid = tup->pid; diff --git a/pkg/network/ebpf/c/tracer/tracer.h b/pkg/network/ebpf/c/tracer/tracer.h index f99301993b539..1bdcfaa9774f6 100644 --- a/pkg/network/ebpf/c/tracer/tracer.h +++ b/pkg/network/ebpf/c/tracer/tracer.h @@ -66,6 +66,7 @@ typedef enum { typedef struct { __u32 rtt; __u32 rtt_var; + __u32 retransmits; // Bit mask containing all TCP state transitions tracked by our tracer __u16 state_transitions; @@ -74,9 +75,9 @@ typedef struct { // Full data for a tcp connection typedef struct { conn_tuple_t tup; - conn_stats_ts_t conn_stats; + // move tcp_stats here to align conn_stats on a cacheline boundary tcp_stats_t tcp_stats; - __u32 tcp_retransmits; + conn_stats_ts_t conn_stats; } conn_t; typedef struct { diff --git a/pkg/network/ebpf/kprobe_types_linux.go b/pkg/network/ebpf/kprobe_types_linux.go index 13d63751f2adc..0b56faa4d9b28 100644 --- a/pkg/network/ebpf/kprobe_types_linux.go +++ b/pkg/network/ebpf/kprobe_types_linux.go @@ -17,6 +17,7 @@ type ConnTuple struct { type TCPStats struct { Rtt uint32 Rtt_var uint32 + Retransmits uint32 State_transitions uint16 Pad_cgo_0 [2]byte } @@ -34,10 +35,9 @@ type ConnStats struct { Pad_cgo_0 [6]byte } type Conn struct { - Tup ConnTuple - Conn_stats ConnStats - Tcp_stats TCPStats - Tcp_retransmits uint32 + Tup ConnTuple + Tcp_stats TCPStats + Conn_stats ConnStats } type FailedConn struct { Tup ConnTuple diff --git a/pkg/network/tracer/connection/ebpf_tracer.go b/pkg/network/tracer/connection/ebpf_tracer.go index de5bbf3ccd25a..84f4ccd984fdd 100644 --- a/pkg/network/tracer/connection/ebpf_tracer.go +++ b/pkg/network/tracer/connection/ebpf_tracer.go @@ -427,10 +427,10 @@ func (t *ebpfTracer) GetConnections(buffer *network.ConnectionBuffer, filter fun } if t.getTCPStats(tcp, key) { - updateTCPStats(conn, tcp, 0) + updateTCPStats(conn, tcp) } - if retrans, ok := t.getTCPRetransmits(key, seen); ok { - updateTCPStats(conn, nil, retrans) + if retrans, ok := t.getTCPRetransmits(key, seen); ok && conn.Type == network.TCP { + conn.Monotonic.Retransmits = retrans } *buffer.Next() = *conn @@ -791,13 +791,13 @@ func populateConnStats(stats *network.ConnectionStats, t *netebpf.ConnTuple, s * } } -func updateTCPStats(conn *network.ConnectionStats, tcpStats *netebpf.TCPStats, retransmits uint32) { +func updateTCPStats(conn *network.ConnectionStats, tcpStats *netebpf.TCPStats) { if conn.Type != network.TCP { return } - conn.Monotonic.Retransmits = retransmits if tcpStats != nil { + conn.Monotonic.Retransmits = tcpStats.Retransmits conn.Monotonic.TCPEstablished = tcpStats.State_transitions >> netebpf.Established & 1 conn.Monotonic.TCPClosed = tcpStats.State_transitions >> netebpf.Close & 1 conn.RTT = tcpStats.Rtt diff --git a/pkg/network/tracer/connection/perf_batching.go b/pkg/network/tracer/connection/perf_batching.go index 03d38eaee3af6..9c20044cde3da 100644 --- a/pkg/network/tracer/connection/perf_batching.go +++ b/pkg/network/tracer/connection/perf_batching.go @@ -62,7 +62,7 @@ func (p *perfBatchManager) ExtractBatchInto(buffer *network.ConnectionBuffer, b for rc := p.extractor.NextConnection(b); rc != nil; rc = p.extractor.NextConnection(b) { conn := buffer.Next() populateConnStats(conn, &rc.Tup, &rc.Conn_stats, p.ch) - updateTCPStats(conn, &rc.Tcp_stats, rc.Tcp_retransmits) + updateTCPStats(conn, &rc.Tcp_stats) } } @@ -80,7 +80,7 @@ func (p *perfBatchManager) GetPendingConns(buffer *network.ConnectionBuffer) { for rc := p.extractor.NextConnection(b); rc != nil; rc = p.extractor.NextConnection(b) { c := buffer.Next() populateConnStats(c, &rc.Tup, &rc.Conn_stats, p.ch) - updateTCPStats(c, &rc.Tcp_stats, rc.Tcp_retransmits) + updateTCPStats(c, &rc.Tcp_stats) } } p.extractor.CleanupExpiredState(time.Now()) diff --git a/pkg/network/tracer/connection/tcp_close_consumer.go b/pkg/network/tracer/connection/tcp_close_consumer.go index 3bb67443ee54c..3c9ff45dba9f0 100644 --- a/pkg/network/tracer/connection/tcp_close_consumer.go +++ b/pkg/network/tracer/connection/tcp_close_consumer.go @@ -85,7 +85,7 @@ func (c *tcpCloseConsumer) extractConn(data []byte) { ct := (*netebpf.Conn)(unsafe.Pointer(&data[0])) conn := c.buffer.Next() populateConnStats(conn, &ct.Tup, &ct.Conn_stats, c.ch) - updateTCPStats(conn, &ct.Tcp_stats, ct.Tcp_retransmits) + updateTCPStats(conn, &ct.Tcp_stats) } func (c *tcpCloseConsumer) Start(callback func(*network.ConnectionStats)) {