github.phpd.cn/cilium/cilium@v1.6.12/bpf/bpf_alignchecker.c (about)

     1  /*
     2   *  Copyright (C) 2018-2019 Authors of Cilium
     3   *
     4   *  This program is free software; you can redistribute it and/or modify
     5   *  it under the terms of the GNU General Public License as published by
     6   *  the Free Software Foundation; either version 2 of the License, or
     7   *  (at your option) any later version.
     8   *
     9   *  This program is distributed in the hope that it will be useful,
    10   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   *  GNU General Public License for more details.
    13   *
    14   *  You should have received a copy of the GNU General Public License
    15   *  along with this program; if not, write to the Free Software
    16   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    17   */
    18  #include <stdio.h>
    19  #include <linux/byteorder.h>
    20  #include "node_config.h"
    21  #include "lib/conntrack.h"
    22  #include "lib/maps.h"
    23  #include "lib/nat.h"
    24  #include "sockops/bpf_sockops.h"
    25  
    26  // DECLARE_STRUCT declares a unique usage of the struct 'x' on the stack.
    27  //
    28  // To prevent compiler from optimizing away the var, we pass a reference
    29  // to the var to a BPF helper function which accepts a reference as
    30  // an argument.
    31  #define DECLARE_STRUCT(x, iter)			\
    32  {						\
    33  	struct x s ## iter = {};		\
    34  	trace_printk("%p", 1, &s ## iter);	\
    35  	iter++;					\
    36  }
    37  
    38  // This function is a placeholder for C struct definitions shared with Go, and
    39  // it's never being executed.
    40  int main() {
    41      int iter = 0;
    42  
    43      DECLARE_STRUCT(ipv4_ct_tuple, iter);
    44      DECLARE_STRUCT(ipv6_ct_tuple, iter);
    45      DECLARE_STRUCT(ct_entry, iter);
    46      DECLARE_STRUCT(ipcache_key, iter);
    47      DECLARE_STRUCT(remote_endpoint_info, iter);
    48      DECLARE_STRUCT(lb4_key_v2, iter);
    49      DECLARE_STRUCT(lb4_service_v2, iter);
    50      DECLARE_STRUCT(lb4_backend, iter);
    51      DECLARE_STRUCT(lb6_key, iter);
    52      DECLARE_STRUCT(lb6_service, iter);
    53      DECLARE_STRUCT(lb6_key_v2, iter);
    54      DECLARE_STRUCT(lb6_service_v2, iter);
    55      DECLARE_STRUCT(lb6_backend, iter);
    56      DECLARE_STRUCT(endpoint_key, iter);
    57      DECLARE_STRUCT(endpoint_info, iter);
    58      DECLARE_STRUCT(metrics_key, iter);
    59      DECLARE_STRUCT(metrics_value, iter);
    60      DECLARE_STRUCT(sock_key, iter);
    61      DECLARE_STRUCT(ep_config, iter);
    62      DECLARE_STRUCT(policy_key, iter);
    63      DECLARE_STRUCT(policy_entry, iter);
    64      DECLARE_STRUCT(ipv4_nat_entry, iter);
    65      DECLARE_STRUCT(ipv6_nat_entry, iter);
    66  
    67      return 0;
    68  }