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

     1  /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
     2  /* Copyright Authors of Cilium */
     3  #pragma once
     4  
     5  #ifndef BPF_TEST
     6  #define __MAGIC_FILE__ (__u8)__id_for_file(__FILE_NAME__)
     7  #define __MAGIC_LINE__ __LINE__
     8  #else
     9  /* bpf tests assert that metrics get updated by performing a map lookup.
    10   * This cannot work if the metrics key has dynamic components like line/file
    11   * info, so disable this during tests.
    12   */
    13  #define __MAGIC_FILE__ 0
    14  #define __MAGIC_LINE__ 0
    15  #endif
    16  
    17  #define _strcase_(id, known_name) do {			\
    18  	if (!__builtin_strcmp(header_name, known_name))	\
    19  		return id;				\
    20  	} while (0)
    21  
    22  /*
    23   * __id_for_file is used by __MAGIC_FILE__ to encode source file information in
    24   * drop notifications and forward/drop metrics. It must be inlined, otherwise
    25   * clang won't translate this to a constexpr.
    26   *
    27   * The following list of files is static, but it is validated during build with
    28   * the pkg/datapath/loader/check-sources.sh tool.
    29   */
    30  static __always_inline int
    31  __id_for_file(const char *const header_name)
    32  {
    33  	/* @@ source files list begin */
    34  
    35  	/* source files from bpf/ */
    36  	_strcase_(1, "bpf_host.c");
    37  	_strcase_(2, "bpf_lxc.c");
    38  	_strcase_(3, "bpf_overlay.c");
    39  	_strcase_(4, "bpf_xdp.c");
    40  	_strcase_(5, "bpf_sock.c");
    41  	_strcase_(6, "bpf_network.c");
    42  	_strcase_(7, "bpf_wireguard.c");
    43  
    44  	/* header files from bpf/lib/ */
    45  	_strcase_(101, "arp.h");
    46  	_strcase_(102, "drop.h");
    47  	_strcase_(103, "srv6.h");
    48  	_strcase_(104, "icmp6.h");
    49  	_strcase_(105, "nodeport.h");
    50  	_strcase_(106, "lb.h");
    51  	_strcase_(107, "mcast.h");
    52  	_strcase_(108, "ipv4.h");
    53  	_strcase_(109, "conntrack.h");
    54  	_strcase_(110, "l3.h");
    55  	_strcase_(111, "trace.h");
    56  	_strcase_(112, "encap.h");
    57  	_strcase_(113, "encrypt.h");
    58  
    59  	/* @@ source files list end */
    60  
    61  	return 0;
    62  }
    63  
    64  #undef _strcase_