|
|
@ -1,6 +1,4 @@
|
|
|
|
use std::{
|
|
|
|
use std::{ffi::CStr, mem::MaybeUninit, net::UdpSocket, num::NonZeroU32, time::Duration};
|
|
|
|
ffi::CStr, mem::MaybeUninit, net::UdpSocket, num::NonZeroU32, ptr::NonNull, time::Duration,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use aya::{
|
|
|
|
use aya::{
|
|
|
|
maps::{Array, CpuMap, XskMap},
|
|
|
|
maps::{Array, CpuMap, XskMap},
|
|
|
@ -33,9 +31,14 @@ fn af_xdp() {
|
|
|
|
#[repr(align(16384))]
|
|
|
|
#[repr(align(16384))]
|
|
|
|
struct PacketMap(MaybeUninit<[u8; 4096]>);
|
|
|
|
struct PacketMap(MaybeUninit<[u8; 4096]>);
|
|
|
|
|
|
|
|
|
|
|
|
let mem = Box::new(PacketMap(MaybeUninit::uninit()));
|
|
|
|
// Safety: don't access alloc down the line.
|
|
|
|
let mem = NonNull::new(Box::leak(mem).0.as_mut_ptr()).unwrap();
|
|
|
|
let mut alloc = Box::new(PacketMap(MaybeUninit::uninit()));
|
|
|
|
let umem = unsafe { Umem::new(UmemConfig::default(), mem).unwrap() };
|
|
|
|
let umem = {
|
|
|
|
|
|
|
|
// Safety: this is a shared buffer between the kernel and us, uninitialized memory is valid.
|
|
|
|
|
|
|
|
let mem = unsafe { alloc.0.assume_init_mut() }.as_mut().into();
|
|
|
|
|
|
|
|
// Safety: we cannot access `mem` further down the line because it falls out of scope.
|
|
|
|
|
|
|
|
unsafe { Umem::new(UmemConfig::default(), mem).unwrap() }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut iface = IfInfo::invalid();
|
|
|
|
let mut iface = IfInfo::invalid();
|
|
|
|
iface
|
|
|
|
iface
|
|
|
|