log.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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!(&ctx, "{}, {}, {}", 69, 420i32, "wao");
  9. let ipv4 = 167772161u32; // 10.0.0.1
  10. let ipv6 = [
  11. 32u8, 1u8, 13u8, 184u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8,
  12. ]; // 2001:db8::1
  13. info!(&ctx, "ipv4: {:i}, ipv6: {:i}", ipv4, ipv6);
  14. let mac = [4u8, 32u8, 6u8, 9u8, 0u8, 64u8];
  15. trace!(&ctx, "mac lc: {:mac}, mac uc: {:MAC}", mac, mac);
  16. let hex = 0x2f;
  17. warn!(&ctx, "hex lc: {:x}, hex uc: {:X}", hex, hex);
  18. let hex = [0xde, 0xad, 0xbe, 0xef].as_slice();
  19. debug!(&ctx, "hex lc: {:x}, hex uc: {:X}", hex, hex);
  20. // Testing compilation only.
  21. if false {
  22. struct NoCopy {}
  23. impl NoCopy {
  24. fn consume(self) -> u64 {
  25. 0xdeadbeef
  26. }
  27. }
  28. let no_copy = NoCopy {};
  29. debug!(&ctx, "{:x}", no_copy.consume());
  30. }
  31. }
  32. #[cfg(not(test))]
  33. #[panic_handler]
  34. fn panic(_info: &core::panic::PanicInfo) -> ! {
  35. loop {}
  36. }