github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/socketenricher/bpf/socket-enricher-helpers.h (about)

     1  /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR Apache-2.0 */
     2  
     3  #ifndef SOCKET_ENRICHER_HELPERS_H
     4  #define SOCKET_ENRICHER_HELPERS_H
     5  
     6  #include <vmlinux.h>
     7  #include <bpf/bpf_helpers.h>
     8  #include <bpf/bpf_core_read.h>
     9  #include <bpf/bpf_tracing.h>
    10  
    11  static __always_inline void prepare_socket_key(struct sockets_key *socket_key,
    12  					       struct sock *sock)
    13  {
    14  	struct inet_sock *inet_sock = (struct inet_sock *)sock;
    15  	BPF_CORE_READ_INTO(&socket_key->netns, sock, __sk_common.skc_net.net,
    16  			   ns.inum);
    17  	BPF_CORE_READ_INTO(&socket_key->family, sock, __sk_common.skc_family);
    18  	socket_key->proto = BPF_CORE_READ_BITFIELD_PROBED(sock, sk_protocol);
    19  	socket_key->port = bpf_ntohs(BPF_CORE_READ(inet_sock, inet_sport));
    20  }
    21  
    22  #endif