test.rs 929 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #![no_std]
  2. #![no_main]
  3. use aya_ebpf::{
  4. bindings::xdp_action,
  5. macros::{kprobe, kretprobe, tracepoint, uprobe, uretprobe, xdp},
  6. programs::{ProbeContext, RetProbeContext, TracePointContext, XdpContext},
  7. };
  8. #[xdp]
  9. pub fn pass(ctx: XdpContext) -> u32 {
  10. match unsafe { try_pass(ctx) } {
  11. Ok(ret) => ret,
  12. Err(_) => xdp_action::XDP_ABORTED,
  13. }
  14. }
  15. unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> {
  16. Ok(xdp_action::XDP_PASS)
  17. }
  18. #[kprobe]
  19. pub fn test_kprobe(_ctx: ProbeContext) -> u32 {
  20. 0
  21. }
  22. #[kretprobe]
  23. pub fn test_kretprobe(_ctx: RetProbeContext) -> u32 {
  24. 0
  25. }
  26. #[tracepoint]
  27. pub fn test_tracepoint(_ctx: TracePointContext) -> u32 {
  28. 0
  29. }
  30. #[uprobe]
  31. pub fn test_uprobe(_ctx: ProbeContext) -> u32 {
  32. 0
  33. }
  34. #[uretprobe]
  35. pub fn test_uretprobe(_ctx: RetProbeContext) -> u32 {
  36. 0
  37. }
  38. #[cfg(not(test))]
  39. #[panic_handler]
  40. fn panic(_info: &core::panic::PanicInfo) -> ! {
  41. loop {}
  42. }