pass.rs 651 B

1234567891011121314151617181920212223
  1. #![no_std]
  2. #![no_main]
  3. use aya_bpf::{bindings::xdp_action, macros::xdp, programs::XdpContext};
  4. // Note: the `frags` attribute causes this probe to be incompatible with kernel versions < 5.18.0.
  5. // See https://github.com/torvalds/linux/commit/c2f2cdb.
  6. #[xdp(name = "pass", frags = "true")]
  7. pub fn pass(ctx: XdpContext) -> u32 {
  8. match unsafe { try_pass(ctx) } {
  9. Ok(ret) => ret,
  10. Err(_) => xdp_action::XDP_ABORTED,
  11. }
  12. }
  13. unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> {
  14. Ok(xdp_action::XDP_PASS)
  15. }
  16. #[panic_handler]
  17. fn panic(_info: &core::panic::PanicInfo) -> ! {
  18. unsafe { core::hint::unreachable_unchecked() }
  19. }