aya: xdp: fix detaching on kernels older than 5.7

XDP_FLAGS_REPLACE was added in 5.7. Now for kernels >= 5.7 whenever we
detach an XDP program we pass along the program fd we expect to be
detaching. For older kernels, we just detach whatever is attached, which
is not great but it's the way the API worked pre XDP_FLAGS_REPLACE.
pull/1/head
Alessandro Decina 4 years ago
parent 607cf68a69
commit 30d2b25f11

@ -110,6 +110,7 @@ impl Xdp {
Ok(self.data.link(XdpLink::NlLink(NlLink {
if_index,
prog_fd: Some(prog_fd),
flags,
})))
}
}
@ -119,12 +120,19 @@ impl Xdp {
struct NlLink {
if_index: i32,
prog_fd: Option<RawFd>,
flags: XdpFlags,
}
impl Link for NlLink {
fn detach(&mut self) -> Result<(), ProgramError> {
if let Some(fd) = self.prog_fd.take() {
let _ = unsafe { netlink_set_xdp_fd(self.if_index, -1, Some(fd), XDP_FLAGS_REPLACE) };
let k_ver = kernel_version().unwrap();
let flags = if k_ver >= (5, 7, 0) {
self.flags.bits | XDP_FLAGS_REPLACE
} else {
self.flags.bits
};
let _ = unsafe { netlink_set_xdp_fd(self.if_index, -1, Some(fd), flags) };
Ok(())
} else {
Err(ProgramError::AlreadyDetached)

Loading…
Cancel
Save