test.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #![no_std]
  2. #![no_main]
  3. use aya_ebpf::{
  4. bindings::{bpf_ret_code, xdp_action},
  5. macros::{flow_dissector, kprobe, kretprobe, tracepoint, uprobe, uretprobe, xdp},
  6. programs::{
  7. FlowDissectorContext, ProbeContext, RetProbeContext, TracePointContext, XdpContext,
  8. },
  9. };
  10. #[cfg(not(test))]
  11. extern crate ebpf_panic;
  12. #[xdp]
  13. pub fn pass(ctx: XdpContext) -> u32 {
  14. match unsafe { try_pass(ctx) } {
  15. Ok(ret) => ret,
  16. Err(_) => xdp_action::XDP_ABORTED,
  17. }
  18. }
  19. unsafe fn try_pass(_ctx: XdpContext) -> Result<u32, u32> {
  20. Ok(xdp_action::XDP_PASS)
  21. }
  22. #[kprobe]
  23. pub fn test_kprobe(_ctx: ProbeContext) -> u32 {
  24. 0
  25. }
  26. #[kretprobe]
  27. pub fn test_kretprobe(_ctx: RetProbeContext) -> u32 {
  28. 0
  29. }
  30. #[tracepoint]
  31. pub fn test_tracepoint(_ctx: TracePointContext) -> u32 {
  32. 0
  33. }
  34. #[uprobe]
  35. pub fn test_uprobe(_ctx: ProbeContext) -> u32 {
  36. 0
  37. }
  38. #[uretprobe]
  39. pub fn test_uretprobe(_ctx: RetProbeContext) -> u32 {
  40. 0
  41. }
  42. #[flow_dissector]
  43. pub fn test_flow(_ctx: FlowDissectorContext) -> u32 {
  44. // TODO: write an actual flow dissector. See tools/testing/selftests/bpf/progs/bpf_flow.c in the
  45. // Linux kernel for inspiration.
  46. bpf_ret_code::BPF_FLOW_DISSECTOR_CONTINUE
  47. }