programs: xdp: support detaching with FdLink

pull/1/head
Alessandro Decina 4 years ago
parent 0f0bc795e3
commit 561b0015bb

@ -1,11 +1,11 @@
use std::ffi::CString; use std::{cell::RefCell, ffi::CString, rc::Rc};
use libc::if_nametoindex; use libc::if_nametoindex;
use crate::RawFd; use crate::RawFd;
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_XDP, bpf_prog_type::BPF_PROG_TYPE_XDP}, generated::{bpf_attach_type::BPF_XDP, bpf_prog_type::BPF_PROG_TYPE_XDP},
programs::{load_program, ProgramData, ProgramError}, programs::{load_program, FdLink, Link, LinkRef, ProgramData, ProgramError},
syscalls::bpf_link_create, syscalls::bpf_link_create,
}; };
@ -23,7 +23,7 @@ impl Xdp {
self.data.name.to_string() self.data.name.to_string()
} }
pub fn attach(&self, interface: &str) -> Result<(), ProgramError> { pub fn attach(&mut self, interface: &str) -> Result<impl Link, ProgramError> {
let prog_fd = self.data.fd_or_err()?; let prog_fd = self.data.fd_or_err()?;
let c_interface = CString::new(interface).unwrap(); let c_interface = CString::new(interface).unwrap();
@ -39,8 +39,10 @@ impl Xdp {
program: self.name(), program: self.name(),
io_error, io_error,
} }
})?; })? as RawFd;
let link = Rc::new(RefCell::new(FdLink { fd: Some(link_fd) }));
self.data.links.push(link.clone());
Ok(()) Ok(LinkRef::new(&link))
} }
} }

Loading…
Cancel
Save