log.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #![no_std]
  2. #![no_main]
  3. use aya_bpf::{macros::uprobe, programs::ProbeContext};
  4. use aya_log_ebpf::{debug, error, info, trace, warn};
  5. #[uprobe]
  6. pub fn test_log(ctx: ProbeContext) {
  7. debug!(&ctx, "Hello from eBPF!");
  8. error!(
  9. &ctx,
  10. "{}, {}, {}, {:x}",
  11. 69,
  12. 420i32,
  13. "wao",
  14. "wao".as_bytes()
  15. );
  16. let ipv4 = 167772161u32; // 10.0.0.1
  17. let ipv6 = [
  18. 32u8, 1u8, 13u8, 184u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8,
  19. ]; // 2001:db8::1
  20. info!(&ctx, "ipv4: {:i}, ipv6: {:i}", ipv4, ipv6);
  21. let mac = [4u8, 32u8, 6u8, 9u8, 0u8, 64u8];
  22. trace!(&ctx, "mac lc: {:mac}, mac uc: {:MAC}", mac, mac);
  23. let hex = 0x2f;
  24. warn!(&ctx, "hex lc: {:x}, hex uc: {:X}", hex, hex);
  25. let hex = [0xde, 0xad, 0xbe, 0xef].as_slice();
  26. debug!(&ctx, "hex lc: {:x}, hex uc: {:X}", hex, hex);
  27. let len = 42;
  28. let size = 43;
  29. let slice = 44;
  30. let record = 45;
  31. debug!(&ctx, "{} {} {} {}", len, size, slice, record);
  32. // Testing compilation only.
  33. if false {
  34. struct NoCopy {}
  35. impl NoCopy {
  36. fn consume(self) -> u64 {
  37. 0xdeadbeef
  38. }
  39. }
  40. let no_copy = NoCopy {};
  41. debug!(&ctx, "{:x}", no_copy.consume());
  42. }
  43. }
  44. #[cfg(not(test))]
  45. #[panic_handler]
  46. fn panic(_info: &core::panic::PanicInfo) -> ! {
  47. loop {}
  48. }