github.com/cilium/cilium@v1.16.2/bpf/lib/signal.h (about)

     1  /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
     2  /* Copyright Authors of Cilium */
     3  
     4  #pragma once
     5  
     6  #include <bpf/api.h>
     7  #include <lib/common.h>
     8  
     9  struct {
    10  	__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
    11  	__uint(key_size, sizeof(__u32));
    12  	__uint(value_size, sizeof(__u32));
    13  	__uint(pinning, LIBBPF_PIN_BY_NAME);
    14  	__uint(max_entries, __NR_CPUS__);
    15  } SIGNAL_MAP __section_maps_btf;
    16  
    17  enum {
    18  	SIGNAL_NAT_FILL_UP = 0,
    19  	SIGNAL_CT_FILL_UP,
    20  	SIGNAL_AUTH_REQUIRED,
    21  };
    22  
    23  enum {
    24  	SIGNAL_PROTO_V4 = 0,
    25  	SIGNAL_PROTO_V6,
    26  };
    27  
    28  struct signal_msg {
    29  	__u32 signal_nr;
    30  	union {
    31  		struct {
    32  			__u32 proto;
    33  		};
    34  		struct auth_key auth;
    35  	};
    36  };
    37  
    38  /**
    39   * SEND_SIGNAL sets a single union MEMBER to VALUE and only includes that
    40   * member (and signal_nr) in message size. Used to avoid referencing
    41   * uninitialized memory if trying to send the whole msg.
    42   */
    43  #define SEND_SIGNAL(CTX, SIGNAL, MEMBER, VALUE)				\
    44    {									\
    45  	struct signal_msg msg = {					\
    46  		.signal_nr	= (SIGNAL),				\
    47  		.MEMBER		= (VALUE),				\
    48  	};								\
    49  	ctx_event_output((CTX), &SIGNAL_MAP, BPF_F_CURRENT_CPU, &msg,	\
    50  			 sizeof(msg.signal_nr) + sizeof(msg.MEMBER));	\
    51    }
    52  
    53  static __always_inline void send_signal_nat_fill_up(struct __ctx_buff *ctx,
    54  						    __u32 proto)
    55  {
    56  	SEND_SIGNAL(ctx, SIGNAL_NAT_FILL_UP, proto, proto);
    57  }
    58  
    59  static __always_inline void send_signal_ct_fill_up(struct __ctx_buff *ctx,
    60  						   __u32 proto)
    61  {
    62  	SEND_SIGNAL(ctx, SIGNAL_CT_FILL_UP, proto, proto);
    63  }
    64  
    65  static __always_inline void send_signal_auth_required(struct __ctx_buff *ctx,
    66  						      const struct auth_key *auth)
    67  {
    68  	SEND_SIGNAL(ctx, SIGNAL_AUTH_REQUIRED, auth, *auth);
    69  }