sample_map_ret0.bpf.c 677 B

12345678910111213141516171819202122232425262728293031323334
  1. /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
  2. #include <linux/bpf.h>
  3. #include <bpf/bpf_helpers.h>
  4. struct {
  5. __uint(type, BPF_MAP_TYPE_HASH);
  6. __type(key, __u32);
  7. __type(value, long);
  8. __uint(max_entries, 2);
  9. } htab SEC(".maps");
  10. struct {
  11. __uint(type, BPF_MAP_TYPE_ARRAY);
  12. __type(key, __u32);
  13. __type(value, long);
  14. __uint(max_entries, 2);
  15. } array SEC(".maps");
  16. /* Sample program which should always load for testing control paths. */
  17. SEC("xdp") int func()
  18. {
  19. __u64 key64 = 0;
  20. __u32 key = 0;
  21. long *value;
  22. value = bpf_map_lookup_elem(&htab, &key);
  23. if (!value)
  24. return 1;
  25. value = bpf_map_lookup_elem(&array, &key64);
  26. if (!value)
  27. return 1;
  28. return 0;
  29. }