Use a macro for program unload api

pull/264/head
Davide Bertola 3 years ago
parent 08d5697948
commit 4abaad6a46

@ -10,8 +10,8 @@ use crate::{
bpf_prog_type::BPF_PROG_TYPE_CGROUP_SKB, bpf_prog_type::BPF_PROG_TYPE_CGROUP_SKB,
}, },
programs::{ programs::{
define_link_wrapper, load_program, unload_program, FdLink, Link, OwnedLink, ProgAttachLink, define_link_wrapper, load_program, FdLink, Link, OwnedLink, ProgAttachLink, ProgramData,
ProgramData, ProgramError, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, kernel_version}, sys::{bpf_link_create, bpf_prog_attach, kernel_version},
}; };
@ -72,14 +72,6 @@ impl CgroupSkb {
load_program(BPF_PROG_TYPE_CGROUP_SKB, &mut self.data) load_program(BPF_PROG_TYPE_CGROUP_SKB, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Returns the expected attach type of the program. /// Returns the expected attach type of the program.
/// ///
/// [`CgroupSkb`] programs can specify the expected attach type in their ELF /// [`CgroupSkb`] programs can specify the expected attach type in their ELF

@ -7,8 +7,8 @@ use std::{
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_CGROUP_SYSCTL, bpf_prog_type::BPF_PROG_TYPE_CGROUP_SYSCTL}, generated::{bpf_attach_type::BPF_CGROUP_SYSCTL, bpf_prog_type::BPF_PROG_TYPE_CGROUP_SYSCTL},
programs::{ programs::{
define_link_wrapper, load_program, unload_program, FdLink, Link, OwnedLink, ProgAttachLink, define_link_wrapper, load_program, FdLink, Link, OwnedLink, ProgAttachLink, ProgramData,
ProgramData, ProgramError, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, kernel_version}, sys::{bpf_link_create, bpf_prog_attach, kernel_version},
}; };
@ -59,14 +59,6 @@ impl CgroupSysctl {
load_program(BPF_PROG_TYPE_CGROUP_SYSCTL, &mut self.data) load_program(BPF_PROG_TYPE_CGROUP_SYSCTL, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [CgroupSysctl::detach]. /// The returned value can be used to detach, see [CgroupSysctl::detach].

@ -4,8 +4,8 @@ use crate::{
generated::{bpf_attach_type::BPF_TRACE_FENTRY, bpf_prog_type::BPF_PROG_TYPE_TRACING}, generated::{bpf_attach_type::BPF_TRACE_FENTRY, bpf_prog_type::BPF_PROG_TYPE_TRACING},
obj::btf::{Btf, BtfKind}, obj::btf::{Btf, BtfKind},
programs::{ programs::{
define_link_wrapper, load_program, unload_program, utils::attach_raw_tracepoint, FdLink, define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
FdLinkId, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
}; };
@ -62,14 +62,6 @@ impl FEntry {
load_program(BPF_PROG_TYPE_TRACING, &mut self.data) load_program(BPF_PROG_TYPE_TRACING, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program. /// Attaches the program.
/// ///
/// The returned value can be used to detach, see [FEntry::detach]. /// The returned value can be used to detach, see [FEntry::detach].

@ -4,8 +4,8 @@ use crate::{
generated::{bpf_attach_type::BPF_TRACE_FEXIT, bpf_prog_type::BPF_PROG_TYPE_TRACING}, generated::{bpf_attach_type::BPF_TRACE_FEXIT, bpf_prog_type::BPF_PROG_TYPE_TRACING},
obj::btf::{Btf, BtfKind}, obj::btf::{Btf, BtfKind},
programs::{ programs::{
define_link_wrapper, load_program, unload_program, utils::attach_raw_tracepoint, FdLink, define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
FdLinkId, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
}; };
@ -62,14 +62,6 @@ impl FExit {
load_program(BPF_PROG_TYPE_TRACING, &mut self.data) load_program(BPF_PROG_TYPE_TRACING, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program. /// Attaches the program.
/// ///
/// The returned value can be used to detach, see [FExit::detach]. /// The returned value can be used to detach, see [FExit::detach].

@ -12,8 +12,6 @@ use crate::{
}, },
}; };
use super::unload_program;
/// A kernel probe. /// A kernel probe.
/// ///
/// Kernel probes are eBPF programs that can be attached to almost any function inside /// Kernel probes are eBPF programs that can be attached to almost any function inside
@ -51,14 +49,6 @@ impl KProbe {
load_program(BPF_PROG_TYPE_KPROBE, &mut self.data) load_program(BPF_PROG_TYPE_KPROBE, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Returns `KProbe` if the program is a `kprobe`, or `KRetProbe` if the /// Returns `KProbe` if the program is a `kprobe`, or `KRetProbe` if the
/// program is a `kretprobe`. /// program is a `kretprobe`.
pub fn kind(&self) -> ProbeKind { pub fn kind(&self) -> ProbeKind {

@ -3,10 +3,7 @@ use std::os::unix::prelude::{AsRawFd, RawFd};
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_LIRC_MODE2, bpf_prog_type::BPF_PROG_TYPE_LIRC_MODE2}, generated::{bpf_attach_type::BPF_LIRC_MODE2, bpf_prog_type::BPF_PROG_TYPE_LIRC_MODE2},
programs::{ programs::{load_program, query, Link, OwnedLink, ProgramData, ProgramError, ProgramInfo},
load_program, query, unload_program, Link, OwnedLink, ProgramData, ProgramError,
ProgramInfo,
},
sys::{bpf_obj_get_info_by_fd, bpf_prog_attach, bpf_prog_detach, bpf_prog_get_fd_by_id}, sys::{bpf_obj_get_info_by_fd, bpf_prog_attach, bpf_prog_detach, bpf_prog_get_fd_by_id},
}; };
@ -61,14 +58,6 @@ impl LircMode2 {
load_program(BPF_PROG_TYPE_LIRC_MODE2, &mut self.data) load_program(BPF_PROG_TYPE_LIRC_MODE2, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given lirc device. /// Attaches the program to the given lirc device.
/// ///
/// The returned value can be used to detach, see [LircMode2::detach]. /// The returned value can be used to detach, see [LircMode2::detach].

@ -3,8 +3,8 @@ use crate::{
generated::{bpf_attach_type::BPF_LSM_MAC, bpf_prog_type::BPF_PROG_TYPE_LSM}, generated::{bpf_attach_type::BPF_LSM_MAC, bpf_prog_type::BPF_PROG_TYPE_LSM},
obj::btf::{Btf, BtfKind}, obj::btf::{Btf, BtfKind},
programs::{ programs::{
define_link_wrapper, load_program, unload_program, utils::attach_raw_tracepoint, FdLink, define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
FdLinkId, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
}; };
@ -67,14 +67,6 @@ impl Lsm {
load_program(BPF_PROG_TYPE_LSM, &mut self.data) load_program(BPF_PROG_TYPE_LSM, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program. /// Attaches the program.
/// ///
/// The returned value can be used to detach, see [Lsm::detach]. /// The returned value can be used to detach, see [Lsm::detach].

@ -552,6 +552,47 @@ impl<'a, P: ProgramFd> ProgramFd for &'a P {
} }
} }
macro_rules! impl_program_unload {
($($struct_name:ident),+ $(,)?) => {
$(
impl $struct_name {
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
}
)+
}
}
impl_program_unload!(
KProbe,
UProbe,
TracePoint,
SocketFilter,
Xdp,
SkMsg,
SkSkb,
SchedClassifier,
CgroupSkb,
CgroupSysctl,
CgroupSockopt,
LircMode2,
PerfEvent,
Lsm,
RawTracePoint,
BtfTracePoint,
FEntry,
FExit,
Extension,
CgroupSockAddr,
SkLookup,
SockOps
);
macro_rules! impl_program_fd { macro_rules! impl_program_fd {
($($struct_name:ident),+ $(,)?) => { ($($struct_name:ident),+ $(,)?) => {
$( $(

@ -14,7 +14,7 @@ use crate::{
programs::{ programs::{
load_program, perf_attach, load_program, perf_attach,
perf_attach::{PerfLink, PerfLinkId}, perf_attach::{PerfLink, PerfLinkId},
unload_program, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
sys::perf_event_open, sys::perf_event_open,
}; };
@ -128,14 +128,6 @@ impl PerfEvent {
load_program(BPF_PROG_TYPE_PERF_EVENT, &mut self.data) load_program(BPF_PROG_TYPE_PERF_EVENT, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches to the given perf event. /// Attaches to the given perf event.
/// ///
/// The possible values and encoding of the `config` argument depends on the /// The possible values and encoding of the `config` argument depends on the

@ -4,8 +4,8 @@ use std::ffi::CString;
use crate::{ use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_RAW_TRACEPOINT, generated::bpf_prog_type::BPF_PROG_TYPE_RAW_TRACEPOINT,
programs::{ programs::{
define_link_wrapper, load_program, unload_program, utils::attach_raw_tracepoint, FdLink, define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
FdLinkId, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
}; };
@ -45,14 +45,6 @@ impl RawTracePoint {
load_program(BPF_PROG_TYPE_RAW_TRACEPOINT, &mut self.data) load_program(BPF_PROG_TYPE_RAW_TRACEPOINT, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given tracepoint. /// Attaches the program to the given tracepoint.
/// ///
/// The returned value can be used to detach, see [RawTracePoint::detach]. /// The returned value can be used to detach, see [RawTracePoint::detach].

@ -3,8 +3,8 @@ use crate::{
generated::{bpf_attach_type::BPF_SK_MSG_VERDICT, bpf_prog_type::BPF_PROG_TYPE_SK_MSG}, generated::{bpf_attach_type::BPF_SK_MSG_VERDICT, bpf_prog_type::BPF_PROG_TYPE_SK_MSG},
maps::sock::SocketMap, maps::sock::SocketMap,
programs::{ programs::{
define_link_wrapper, load_program, unload_program, OwnedLink, ProgAttachLink, define_link_wrapper, load_program, OwnedLink, ProgAttachLink, ProgAttachLinkId,
ProgAttachLinkId, ProgramData, ProgramError, ProgramData, ProgramError,
}, },
sys::bpf_prog_attach, sys::bpf_prog_attach,
}; };
@ -69,14 +69,6 @@ impl SkMsg {
load_program(BPF_PROG_TYPE_SK_MSG, &mut self.data) load_program(BPF_PROG_TYPE_SK_MSG, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given sockmap. /// Attaches the program to the given sockmap.
/// ///
/// The returned value can be used to detach, see [SkMsg::detach]. /// The returned value can be used to detach, see [SkMsg::detach].

@ -6,8 +6,8 @@ use crate::{
}, },
maps::sock::SocketMap, maps::sock::SocketMap,
programs::{ programs::{
define_link_wrapper, load_program, unload_program, OwnedLink, ProgAttachLink, define_link_wrapper, load_program, OwnedLink, ProgAttachLink, ProgAttachLinkId,
ProgAttachLinkId, ProgramData, ProgramError, ProgramData, ProgramError,
}, },
sys::bpf_prog_attach, sys::bpf_prog_attach,
}; };
@ -62,14 +62,6 @@ impl SkSkb {
load_program(BPF_PROG_TYPE_SK_SKB, &mut self.data) load_program(BPF_PROG_TYPE_SK_SKB, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given socket map. /// Attaches the program to the given socket map.
/// ///
/// The returned value can be used to detach, see [SkSkb::detach]. /// The returned value can be used to detach, see [SkSkb::detach].

@ -4,8 +4,8 @@ use std::os::unix::io::AsRawFd;
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_CGROUP_SOCK_OPS, bpf_prog_type::BPF_PROG_TYPE_SOCK_OPS}, generated::{bpf_attach_type::BPF_CGROUP_SOCK_OPS, bpf_prog_type::BPF_PROG_TYPE_SOCK_OPS},
programs::{ programs::{
define_link_wrapper, load_program, unload_program, OwnedLink, ProgAttachLink, define_link_wrapper, load_program, OwnedLink, ProgAttachLink, ProgAttachLinkId,
ProgAttachLinkId, ProgramData, ProgramError, ProgramData, ProgramError,
}, },
sys::bpf_prog_attach, sys::bpf_prog_attach,
}; };
@ -56,14 +56,6 @@ impl SockOps {
load_program(BPF_PROG_TYPE_SOCK_OPS, &mut self.data) load_program(BPF_PROG_TYPE_SOCK_OPS, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [SockOps::detach]. /// The returned value can be used to detach, see [SockOps::detach].

@ -8,7 +8,7 @@ use thiserror::Error;
use crate::{ use crate::{
generated::{bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER, SO_ATTACH_BPF, SO_DETACH_BPF}, generated::{bpf_prog_type::BPF_PROG_TYPE_SOCKET_FILTER, SO_ATTACH_BPF, SO_DETACH_BPF},
programs::{load_program, unload_program, Link, OwnedLink, ProgramData, ProgramError}, programs::{load_program, Link, OwnedLink, ProgramData, ProgramError},
}; };
/// The type returned when attaching a [`SocketFilter`] fails. /// The type returned when attaching a [`SocketFilter`] fails.
@ -70,14 +70,6 @@ impl SocketFilter {
load_program(BPF_PROG_TYPE_SOCKET_FILTER, &mut self.data) load_program(BPF_PROG_TYPE_SOCKET_FILTER, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the filter on the given socket. /// Attaches the filter on the given socket.
/// ///
/// The returned value can be used to detach from the socket, see [SocketFilter::detach]. /// The returned value can be used to detach from the socket, see [SocketFilter::detach].

@ -10,10 +10,7 @@ use crate::{
generated::{ generated::{
bpf_prog_type::BPF_PROG_TYPE_SCHED_CLS, TC_H_CLSACT, TC_H_MIN_EGRESS, TC_H_MIN_INGRESS, bpf_prog_type::BPF_PROG_TYPE_SCHED_CLS, TC_H_CLSACT, TC_H_MIN_EGRESS, TC_H_MIN_INGRESS,
}, },
programs::{ programs::{define_link_wrapper, load_program, Link, OwnedLink, ProgramData, ProgramError},
define_link_wrapper, load_program, unload_program, Link, OwnedLink, ProgramData,
ProgramError,
},
sys::{ sys::{
netlink_find_filter_with_name, netlink_qdisc_add_clsact, netlink_qdisc_attach, netlink_find_filter_with_name, netlink_qdisc_add_clsact, netlink_qdisc_attach,
netlink_qdisc_detach, netlink_qdisc_detach,
@ -109,14 +106,6 @@ impl SchedClassifier {
load_program(BPF_PROG_TYPE_SCHED_CLS, &mut self.data) load_program(BPF_PROG_TYPE_SCHED_CLS, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given `interface`. /// Attaches the program to the given `interface`.
/// ///
/// The returned value can be used to detach, see [SchedClassifier::detach]. /// The returned value can be used to detach, see [SchedClassifier::detach].

@ -3,8 +3,8 @@ use crate::{
generated::{bpf_attach_type::BPF_TRACE_RAW_TP, bpf_prog_type::BPF_PROG_TYPE_TRACING}, generated::{bpf_attach_type::BPF_TRACE_RAW_TP, bpf_prog_type::BPF_PROG_TYPE_TRACING},
obj::btf::{Btf, BtfKind}, obj::btf::{Btf, BtfKind},
programs::{ programs::{
define_link_wrapper, load_program, unload_program, utils::attach_raw_tracepoint, FdLink, define_link_wrapper, load_program, utils::attach_raw_tracepoint, FdLink, FdLinkId,
FdLinkId, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
}; };
@ -65,14 +65,6 @@ impl BtfTracePoint {
load_program(BPF_PROG_TYPE_TRACING, &mut self.data) load_program(BPF_PROG_TYPE_TRACING, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program. /// Attaches the program.
/// ///
/// The returned value can be used to detach, see [BtfTracePoint::detach]. /// The returned value can be used to detach, see [BtfTracePoint::detach].

@ -12,8 +12,6 @@ use crate::{
sys::perf_event_open_trace_point, sys::perf_event_open_trace_point,
}; };
use super::unload_program;
/// The type returned when attaching a [`TracePoint`] fails. /// The type returned when attaching a [`TracePoint`] fails.
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum TracePointError { pub enum TracePointError {
@ -73,14 +71,6 @@ impl TracePoint {
load_program(BPF_PROG_TYPE_TRACEPOINT, &mut self.data) load_program(BPF_PROG_TYPE_TRACEPOINT, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches to a given trace point. /// Attaches to a given trace point.
/// ///
/// For a list of the available event categories and names, see /// For a list of the available event categories and names, see

@ -19,7 +19,7 @@ use crate::{
define_link_wrapper, load_program, define_link_wrapper, load_program,
perf_attach::{PerfLink, PerfLinkId}, perf_attach::{PerfLink, PerfLinkId},
probe::{attach, ProbeKind}, probe::{attach, ProbeKind},
unload_program, OwnedLink, ProgramData, ProgramError, OwnedLink, ProgramData, ProgramError,
}, },
}; };
@ -51,14 +51,6 @@ impl UProbe {
load_program(BPF_PROG_TYPE_KPROBE, &mut self.data) load_program(BPF_PROG_TYPE_KPROBE, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Returns `UProbe` if the program is a `uprobe`, or `URetProbe` if the /// Returns `UProbe` if the program is a `uprobe`, or `URetProbe` if the
/// program is a `uretprobe`. /// program is a `uretprobe`.
pub fn kind(&self) -> ProbeKind { pub fn kind(&self) -> ProbeKind {

@ -12,8 +12,7 @@ use crate::{
XDP_FLAGS_UPDATE_IF_NOEXIST, XDP_FLAGS_UPDATE_IF_NOEXIST,
}, },
programs::{ programs::{
define_link_wrapper, load_program, unload_program, FdLink, Link, OwnedLink, ProgramData, define_link_wrapper, load_program, FdLink, Link, OwnedLink, ProgramData, ProgramError,
ProgramError,
}, },
sys::{bpf_link_create, kernel_version, netlink_set_xdp_fd}, sys::{bpf_link_create, kernel_version, netlink_set_xdp_fd},
}; };
@ -82,14 +81,6 @@ impl Xdp {
load_program(BPF_PROG_TYPE_XDP, &mut self.data) load_program(BPF_PROG_TYPE_XDP, &mut self.data)
} }
/// Unloads the program from the kernel.
///
/// If `detach` is true, links will be detached before unloading the program.
/// Note that OwnedLinks you obtained using [KProbe::forget_link] will not be detached.
pub fn unload(&mut self, detach: bool) -> Result<(), ProgramError> {
unload_program(&mut self.data, detach)
}
/// Attaches the program to the given `interface`. /// Attaches the program to the given `interface`.
/// ///
/// The returned value can be used to detach, see [Xdp::detach]. /// The returned value can be used to detach, see [Xdp::detach].

Loading…
Cancel
Save