test_btf_haskv.c 875 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2018 Facebook */
  3. #include <linux/bpf.h>
  4. #include "bpf_helpers.h"
  5. int _version SEC("version") = 1;
  6. struct ipv_counts {
  7. unsigned int v4;
  8. unsigned int v6;
  9. };
  10. typedef int btf_map_key;
  11. typedef struct ipv_counts btf_map_value;
  12. btf_map_key dumm_key;
  13. btf_map_value dummy_value;
  14. struct bpf_map_def SEC("maps") btf_map = {
  15. .type = BPF_MAP_TYPE_ARRAY,
  16. .key_size = sizeof(int),
  17. .value_size = sizeof(struct ipv_counts),
  18. .max_entries = 4,
  19. };
  20. struct dummy_tracepoint_args {
  21. unsigned long long pad;
  22. struct sock *sock;
  23. };
  24. SEC("dummy_tracepoint")
  25. int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
  26. {
  27. struct ipv_counts *counts;
  28. int key = 0;
  29. if (!arg->sock)
  30. return 0;
  31. counts = bpf_map_lookup_elem(&btf_map, &key);
  32. if (!counts)
  33. return 0;
  34. counts->v6++;
  35. return 0;
  36. }
  37. char _license[] SEC("license") = "GPL";