diff --git a/pkg/network/ebpf/c/protocols/http2/decoding.h b/pkg/network/ebpf/c/protocols/http2/decoding.h index 81d1f36af3d9c..d214b46a1b503 100644 --- a/pkg/network/ebpf/c/protocols/http2/decoding.h +++ b/pkg/network/ebpf/c/protocols/http2/decoding.h @@ -101,16 +101,17 @@ static __always_inline void pktbuf_skip_preface(pktbuf_t pkt) { // Returns the telemetry pointer from the relevant map. static __always_inline void* get_telemetry(pktbuf_t pkt) { - const __u32 zero = 0; + const __u32 plaintext_ey = 0; + const __u32 tls_key = 1; pktbuf_map_lookup_option_t map_lookup_telemetry_array[] = { [PKTBUF_SKB] = { .map = &http2_telemetry, - .key = (void*)&zero, + .key = (void*)&plaintext_ey, }, [PKTBUF_TLS] = { - .map = &tls_http2_telemetry, - .key = (void*)&zero, + .map = &http2_telemetry, + .key = (void*)&tls_key, }, }; return pktbuf_map_lookup(pkt, map_lookup_telemetry_array); diff --git a/pkg/network/ebpf/c/protocols/http2/maps-defs.h b/pkg/network/ebpf/c/protocols/http2/maps-defs.h index ddeff6742c6e5..d8c0ac37820e1 100644 --- a/pkg/network/ebpf/c/protocols/http2/maps-defs.h +++ b/pkg/network/ebpf/c/protocols/http2/maps-defs.h @@ -47,7 +47,6 @@ BPF_PERCPU_ARRAY_MAP(http2_ctx_heap, http2_ctx_t, 1) * only key 0 is used * value is a http2 telemetry object */ -BPF_ARRAY_MAP(http2_telemetry, http2_telemetry_t, 1) -BPF_ARRAY_MAP(tls_http2_telemetry, http2_telemetry_t, 1) +BPF_ARRAY_MAP(http2_telemetry, http2_telemetry_t, 2) #endif diff --git a/pkg/network/protocols/http2/protocol.go b/pkg/network/protocols/http2/protocol.go index 3553b461b983d..5690b2cb5108b 100644 --- a/pkg/network/protocols/http2/protocol.go +++ b/pkg/network/protocols/http2/protocol.go @@ -61,8 +61,6 @@ const ( // TelemetryMap is the name of the map used to retrieve plaintext metrics from the kernel TelemetryMap = "http2_telemetry" - // TLSTelemetryMap is the name of the map used to retrieve metrics from the eBPF probes for TLS - TLSTelemetryMap = "tls_http2_telemetry" tlsFirstFrameTailCall = "uprobe__http2_tls_handle_first_frame" tlsFilterTailCall = "uprobe__http2_tls_filter" @@ -316,13 +314,8 @@ func (p *Protocol) updateKernelTelemetry(mgr *manager.Manager) { return } - tlsMap, err := protocols.GetMap(mgr, TLSTelemetryMap) - if err != nil { - log.Warn(err) - return - } - - var zero uint32 + plaintextKey := uint32(0) + tlsKey := uint32(1) http2Telemetry := &HTTP2Telemetry{} ticker := time.NewTicker(30 * time.Second) @@ -332,14 +325,14 @@ func (p *Protocol) updateKernelTelemetry(mgr *manager.Manager) { for { select { case <-ticker.C: - if err := mp.Lookup(unsafe.Pointer(&zero), unsafe.Pointer(http2Telemetry)); err != nil { + if err := mp.Lookup(unsafe.Pointer(&plaintextKey), unsafe.Pointer(http2Telemetry)); err != nil { log.Errorf("unable to lookup %q map: %s", TelemetryMap, err) return } p.http2Telemetry.update(http2Telemetry, false) - if err := tlsMap.Lookup(unsafe.Pointer(&zero), unsafe.Pointer(http2Telemetry)); err != nil { - log.Errorf("unable to lookup %q map: %s", TLSTelemetryMap, err) + if err := mp.Lookup(unsafe.Pointer(&tlsKey), unsafe.Pointer(http2Telemetry)); err != nil { + log.Errorf("unable to lookup %q map: %s", TelemetryMap, err) return } p.http2Telemetry.update(http2Telemetry, true) diff --git a/pkg/network/usm/usm_http2_monitor_test.go b/pkg/network/usm/usm_http2_monitor_test.go index 4a3fba2c48c99..8503e1e96cf0e 100644 --- a/pkg/network/usm/usm_http2_monitor_test.go +++ b/pkg/network/usm/usm_http2_monitor_test.go @@ -1924,11 +1924,11 @@ func dialHTTP2Server(t *testing.T) net.Conn { // getHTTP2KernelTelemetry returns the HTTP2 kernel telemetry func getHTTP2KernelTelemetry(monitor *Monitor, isTLS bool) (*usmhttp2.HTTP2Telemetry, error) { http2Telemetry := &usmhttp2.HTTP2Telemetry{} - var zero uint32 mapName := usmhttp2.TelemetryMap + key := uint32(0) if isTLS { - mapName = usmhttp2.TLSTelemetryMap + key = uint32(1) } mp, _, err := monitor.ebpfProgram.GetMap(mapName) @@ -1936,7 +1936,7 @@ func getHTTP2KernelTelemetry(monitor *Monitor, isTLS bool) (*usmhttp2.HTTP2Telem return nil, fmt.Errorf("unable to get %q map: %s", mapName, err) } - if err := mp.Lookup(unsafe.Pointer(&zero), unsafe.Pointer(http2Telemetry)); err != nil { + if err := mp.Lookup(unsafe.Pointer(&key), unsafe.Pointer(http2Telemetry)); err != nil { return nil, fmt.Errorf("unable to lookup %q map: %s", mapName, err) } return http2Telemetry, nil