test_btf_haskv.c 815 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. struct bpf_map_def SEC("maps") btf_map = {
  11. .type = BPF_MAP_TYPE_ARRAY,
  12. .key_size = sizeof(int),
  13. .value_size = sizeof(struct ipv_counts),
  14. .max_entries = 4,
  15. };
  16. BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
  17. struct dummy_tracepoint_args {
  18. unsigned long long pad;
  19. struct sock *sock;
  20. };
  21. SEC("dummy_tracepoint")
  22. int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
  23. {
  24. struct ipv_counts *counts;
  25. int key = 0;
  26. if (!arg->sock)
  27. return 0;
  28. counts = bpf_map_lookup_elem(&btf_map, &key);
  29. if (!counts)
  30. return 0;
  31. counts->v6++;
  32. return 0;
  33. }
  34. char _license[] SEC("license") = "GPL";