test_btf_nokv.c 759 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. struct dummy_tracepoint_args {
  17. unsigned long long pad;
  18. struct sock *sock;
  19. };
  20. SEC("dummy_tracepoint")
  21. int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
  22. {
  23. struct ipv_counts *counts;
  24. int key = 0;
  25. if (!arg->sock)
  26. return 0;
  27. counts = bpf_map_lookup_elem(&btf_map, &key);
  28. if (!counts)
  29. return 0;
  30. counts->v6++;
  31. return 0;
  32. }
  33. char _license[] SEC("license") = "GPL";