4
0

mod.rs 1016 B

123456789101112131415161718192021222324252627282930313233
  1. mod cpu_map;
  2. mod dev_map;
  3. mod dev_map_hash;
  4. mod xsk_map;
  5. use core::cell::UnsafeCell;
  6. use aya_bpf_bindings::{
  7. bindings::{bpf_map_def, xdp_action::XDP_REDIRECT},
  8. helpers::bpf_redirect_map,
  9. };
  10. pub use cpu_map::CpuMap;
  11. pub use dev_map::DevMap;
  12. pub use dev_map_hash::DevMapHash;
  13. pub use xsk_map::XskMap;
  14. /// Wrapper aroung the `bpf_redirect_map` function.
  15. ///
  16. /// # Return value
  17. ///
  18. /// - `Ok(XDP_REDIRECT)` on success.
  19. /// - `Err(_)` of the lowest two bits of `flags` on failure.
  20. #[inline(always)]
  21. fn try_redirect_map(def: &UnsafeCell<bpf_map_def>, key: u32, flags: u64) -> Result<u32, u32> {
  22. // Return XDP_REDIRECT on success, or the value of the two lower bits of the flags argument on
  23. // error. Thus I have no idea why it returns a long (i64) instead of something saner, hence the
  24. // unsigned_abs.
  25. let ret = unsafe { bpf_redirect_map(def.get() as *mut _, key.into(), flags) };
  26. match ret.unsigned_abs() as u32 {
  27. XDP_REDIRECT => Ok(XDP_REDIRECT),
  28. ret => Err(ret),
  29. }
  30. }