map_test.ebpf.rs 760 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //! ```cargo
  2. //! [dependencies]
  3. //! aya-bpf = { path = "../../../../bpf/aya-bpf" }
  4. //! ```
  5. #![no_std]
  6. #![no_main]
  7. use aya_bpf::{
  8. bindings::xdp_action,
  9. macros::{map, xdp},
  10. programs::XdpContext,
  11. maps::Array,
  12. };
  13. #[map]
  14. static mut FOO: Array<u32> = Array::<u32>::with_max_entries(10, 0);
  15. #[map(name = "BAR")]
  16. static mut BAZ: Array<u32> = Array::<u32>::with_max_entries(10, 0);
  17. #[xdp]
  18. pub fn pass(ctx: XdpContext) -> u32 {
  19. match unsafe { try_pass(ctx) } {
  20. Ok(ret) => ret,
  21. Err(_) => xdp_action::XDP_ABORTED,
  22. }
  23. }
  24. unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> {
  25. Ok(xdp_action::XDP_PASS)
  26. }
  27. #[panic_handler]
  28. fn panic(_info: &core::panic::PanicInfo) -> ! {
  29. unsafe { core::hint::unreachable_unchecked() }
  30. }