|
|
@ -35,7 +35,7 @@ pub enum XdpError {
|
|
|
|
|
|
|
|
|
|
|
|
bitflags! {
|
|
|
|
bitflags! {
|
|
|
|
/// Flags passed to [`Xdp::attach()`].
|
|
|
|
/// Flags passed to [`Xdp::attach()`].
|
|
|
|
#[derive(Default)]
|
|
|
|
#[derive(Clone, Copy, Debug, Default)]
|
|
|
|
pub struct XdpFlags: u32 {
|
|
|
|
pub struct XdpFlags: u32 {
|
|
|
|
/// Skb mode.
|
|
|
|
/// Skb mode.
|
|
|
|
const SKB_MODE = XDP_FLAGS_SKB_MODE;
|
|
|
|
const SKB_MODE = XDP_FLAGS_SKB_MODE;
|
|
|
@ -128,7 +128,7 @@ impl Xdp {
|
|
|
|
|
|
|
|
|
|
|
|
let k_ver = kernel_version().unwrap();
|
|
|
|
let k_ver = kernel_version().unwrap();
|
|
|
|
if k_ver >= (5, 9, 0) {
|
|
|
|
if k_ver >= (5, 9, 0) {
|
|
|
|
let link_fd = bpf_link_create(prog_fd, if_index, BPF_XDP, None, flags.bits).map_err(
|
|
|
|
let link_fd = bpf_link_create(prog_fd, if_index, BPF_XDP, None, flags.bits()).map_err(
|
|
|
|
|(_, io_error)| ProgramError::SyscallError {
|
|
|
|
|(_, io_error)| ProgramError::SyscallError {
|
|
|
|
call: "bpf_link_create".to_owned(),
|
|
|
|
call: "bpf_link_create".to_owned(),
|
|
|
|
io_error,
|
|
|
|
io_error,
|
|
|
@ -138,7 +138,7 @@ impl Xdp {
|
|
|
|
.links
|
|
|
|
.links
|
|
|
|
.insert(XdpLink::new(XdpLinkInner::FdLink(FdLink::new(link_fd))))
|
|
|
|
.insert(XdpLink::new(XdpLinkInner::FdLink(FdLink::new(link_fd))))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
unsafe { netlink_set_xdp_fd(if_index, prog_fd, None, flags.bits) }
|
|
|
|
unsafe { netlink_set_xdp_fd(if_index, prog_fd, None, flags.bits()) }
|
|
|
|
.map_err(|io_error| XdpError::NetlinkError { io_error })?;
|
|
|
|
.map_err(|io_error| XdpError::NetlinkError { io_error })?;
|
|
|
|
|
|
|
|
|
|
|
|
self.data
|
|
|
|
self.data
|
|
|
@ -226,9 +226,9 @@ impl Link for NlLink {
|
|
|
|
fn detach(self) -> Result<(), ProgramError> {
|
|
|
|
fn detach(self) -> Result<(), ProgramError> {
|
|
|
|
let k_ver = kernel_version().unwrap();
|
|
|
|
let k_ver = kernel_version().unwrap();
|
|
|
|
let flags = if k_ver >= (5, 7, 0) {
|
|
|
|
let flags = if k_ver >= (5, 7, 0) {
|
|
|
|
self.flags.bits | XDP_FLAGS_REPLACE
|
|
|
|
self.flags.bits() | XDP_FLAGS_REPLACE
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self.flags.bits
|
|
|
|
self.flags.bits()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let _ = unsafe { netlink_set_xdp_fd(self.if_index, -1, Some(self.prog_fd), flags) };
|
|
|
|
let _ = unsafe { netlink_set_xdp_fd(self.if_index, -1, Some(self.prog_fd), flags) };
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|