aya: Use AsFd when attaching fds to programs

This is a breaking change but adds another level of safety to ensure
the file descriptor we receive is valid. Additionally, this allows
aya to internally easily duplicate this file descriptor using std
library methods instead of manually calling `dup` which doesn't
duplicate with the CLOSE_ON_EXEC flag that is standard pratice to
avoid leaking the file descriptor when exec'ing.
pull/723/head
Andrés Medina 1 year ago committed by Tamir Duberstein
parent d2e74e562d
commit 6895b1e2ed
No known key found for this signature in database

@ -5,14 +5,17 @@ mod sock_map;
pub use sock_hash::SockHash; pub use sock_hash::SockHash;
pub use sock_map::SockMap; pub use sock_map::SockMap;
use std::os::fd::{AsRawFd, RawFd}; use std::os::fd::{AsFd, BorrowedFd, RawFd};
/// A socket map file descriptor. /// A socket map file descriptor.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct SockMapFd(RawFd); pub struct SockMapFd(RawFd);
impl AsRawFd for SockMapFd { impl AsFd for SockMapFd {
fn as_raw_fd(&self) -> RawFd { fn as_fd(&self) -> BorrowedFd<'_> {
self.0 // SAFETY: This isn't necessarily safe, we need to find ways
// to enforce that the file descriptor is still
// valid. TODO(#612)
unsafe { BorrowedFd::borrow_raw(self.0) }
} }
} }

@ -1,14 +1,14 @@
//! Cgroup device programs. //! Cgroup device programs.
use crate::util::KernelVersion; use std::os::fd::AsFd;
use std::os::fd::{AsFd as _, AsRawFd};
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_CGROUP_DEVICE, bpf_prog_type::BPF_PROG_TYPE_CGROUP_DEVICE}, generated::{bpf_attach_type::BPF_CGROUP_DEVICE, bpf_prog_type::BPF_PROG_TYPE_CGROUP_DEVICE},
programs::{ programs::{
define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError, define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
util::KernelVersion,
}; };
/// A program used to watch or prevent device interaction from a cgroup. /// A program used to watch or prevent device interaction from a cgroup.
@ -60,34 +60,35 @@ impl CgroupDevice {
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [CgroupDevice::detach] /// The returned value can be used to detach, see [CgroupDevice::detach]
pub fn attach<T: AsRawFd>(&mut self, cgroup: T) -> Result<CgroupDeviceLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, cgroup: T) -> Result<CgroupDeviceLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd(); let cgroup_fd = cgroup.as_fd();
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) {
let link_fd = bpf_link_create(prog_fd, cgroup_fd, BPF_CGROUP_DEVICE, None, 0).map_err( let link_fd = bpf_link_create(
|(_, io_error)| SyscallError { prog_fd,
LinkTarget::Fd(cgroup_fd),
BPF_CGROUP_DEVICE,
None,
0,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(CgroupDeviceLink::new(CgroupDeviceLinkInner::Fd( .insert(CgroupDeviceLink::new(CgroupDeviceLinkInner::Fd(
FdLink::new(link_fd), FdLink::new(link_fd),
))) )))
} else { } else {
bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_DEVICE).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd, cgroup_fd, BPF_CGROUP_DEVICE)?;
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data self.data
.links .links
.insert(CgroupDeviceLink::new(CgroupDeviceLinkInner::ProgAttach( .insert(CgroupDeviceLink::new(CgroupDeviceLinkInner::ProgAttach(
ProgAttachLink::new(prog_fd, cgroup_fd, BPF_CGROUP_DEVICE), link,
))) )))
} }
} }

@ -1,11 +1,6 @@
//! Cgroup skb programs. //! Cgroup skb programs.
use crate::util::KernelVersion; use std::{hash::Hash, os::fd::AsFd, path::Path};
use std::{
hash::Hash,
os::fd::{AsFd as _, AsRawFd},
path::Path,
};
use crate::{ use crate::{
generated::{ generated::{
@ -15,7 +10,8 @@ use crate::{
programs::{ programs::{
define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError, define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
util::KernelVersion,
VerifierLogLevel, VerifierLogLevel,
}; };
@ -87,44 +83,36 @@ impl CgroupSkb {
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [CgroupSkb::detach]. /// The returned value can be used to detach, see [CgroupSkb::detach].
pub fn attach<T: AsRawFd>( pub fn attach<T: AsFd>(
&mut self, &mut self,
cgroup: T, cgroup: T,
attach_type: CgroupSkbAttachType, attach_type: CgroupSkbAttachType,
) -> Result<CgroupSkbLinkId, ProgramError> { ) -> Result<CgroupSkbLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd(); let cgroup_fd = cgroup.as_fd();
let attach_type = match attach_type { let attach_type = match attach_type {
CgroupSkbAttachType::Ingress => BPF_CGROUP_INET_INGRESS, CgroupSkbAttachType::Ingress => BPF_CGROUP_INET_INGRESS,
CgroupSkbAttachType::Egress => BPF_CGROUP_INET_EGRESS, CgroupSkbAttachType::Egress => BPF_CGROUP_INET_EGRESS,
}; };
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) {
let link_fd = bpf_link_create(prog_fd, cgroup_fd, attach_type, None, 0).map_err( let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(cgroup_fd), attach_type, None, 0)
|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(CgroupSkbLink::new(CgroupSkbLinkInner::Fd(FdLink::new( .insert(CgroupSkbLink::new(CgroupSkbLinkInner::Fd(FdLink::new(
link_fd, link_fd,
)))) ))))
} else { } else {
bpf_prog_attach(prog_fd, cgroup_fd, attach_type).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd, cgroup_fd, attach_type)?;
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data self.data
.links .links
.insert(CgroupSkbLink::new(CgroupSkbLinkInner::ProgAttach( .insert(CgroupSkbLink::new(CgroupSkbLinkInner::ProgAttach(link)))
ProgAttachLink::new(prog_fd, cgroup_fd, attach_type),
)))
} }
} }

@ -2,19 +2,15 @@
pub use aya_obj::programs::CgroupSockAttachType; pub use aya_obj::programs::CgroupSockAttachType;
use crate::util::KernelVersion; use std::{hash::Hash, os::fd::AsFd, path::Path};
use std::{
hash::Hash,
os::fd::{AsFd as _, AsRawFd},
path::Path,
};
use crate::{ use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK, generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK,
programs::{ programs::{
define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError, define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
util::KernelVersion,
VerifierLogLevel, VerifierLogLevel,
}; };
@ -70,36 +66,28 @@ impl CgroupSock {
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [CgroupSock::detach]. /// The returned value can be used to detach, see [CgroupSock::detach].
pub fn attach<T: AsRawFd>(&mut self, cgroup: T) -> Result<CgroupSockLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, cgroup: T) -> Result<CgroupSockLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd(); let cgroup_fd = cgroup.as_fd();
let attach_type = self.data.expected_attach_type.unwrap(); let attach_type = self.data.expected_attach_type.unwrap();
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) {
let link_fd = bpf_link_create(prog_fd, cgroup_fd, attach_type, None, 0).map_err( let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(cgroup_fd), attach_type, None, 0)
|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(CgroupSockLink::new(CgroupSockLinkInner::Fd(FdLink::new( .insert(CgroupSockLink::new(CgroupSockLinkInner::Fd(FdLink::new(
link_fd, link_fd,
)))) ))))
} else { } else {
bpf_prog_attach(prog_fd, cgroup_fd, attach_type).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd, cgroup_fd, attach_type)?;
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data self.data
.links .links
.insert(CgroupSockLink::new(CgroupSockLinkInner::ProgAttach( .insert(CgroupSockLink::new(CgroupSockLinkInner::ProgAttach(link)))
ProgAttachLink::new(prog_fd, cgroup_fd, attach_type),
)))
} }
} }

@ -2,19 +2,15 @@
pub use aya_obj::programs::CgroupSockAddrAttachType; pub use aya_obj::programs::CgroupSockAddrAttachType;
use crate::util::KernelVersion; use std::{hash::Hash, os::fd::AsFd, path::Path};
use std::{
hash::Hash,
os::fd::{AsFd as _, AsRawFd},
path::Path,
};
use crate::{ use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK_ADDR, generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
programs::{ programs::{
define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError, define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
util::KernelVersion,
VerifierLogLevel, VerifierLogLevel,
}; };
@ -71,37 +67,27 @@ impl CgroupSockAddr {
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [CgroupSockAddr::detach]. /// The returned value can be used to detach, see [CgroupSockAddr::detach].
pub fn attach<T: AsRawFd>(&mut self, cgroup: T) -> Result<CgroupSockAddrLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, cgroup: T) -> Result<CgroupSockAddrLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd(); let cgroup_fd = cgroup.as_fd();
let attach_type = self.data.expected_attach_type.unwrap(); let attach_type = self.data.expected_attach_type.unwrap();
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) {
let link_fd = bpf_link_create(prog_fd, cgroup_fd, attach_type, None, 0).map_err( let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(cgroup_fd), attach_type, None, 0)
|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(CgroupSockAddrLink::new(CgroupSockAddrLinkInner::Fd( .insert(CgroupSockAddrLink::new(CgroupSockAddrLinkInner::Fd(
FdLink::new(link_fd), FdLink::new(link_fd),
))) )))
} else { } else {
bpf_prog_attach(prog_fd, cgroup_fd, attach_type).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd, cgroup_fd, attach_type)?;
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data.links.insert(CgroupSockAddrLink::new( self.data.links.insert(CgroupSockAddrLink::new(
CgroupSockAddrLinkInner::ProgAttach(ProgAttachLink::new( CgroupSockAddrLinkInner::ProgAttach(link),
prog_fd,
cgroup_fd,
attach_type,
)),
)) ))
} }
} }

@ -2,19 +2,15 @@
pub use aya_obj::programs::CgroupSockoptAttachType; pub use aya_obj::programs::CgroupSockoptAttachType;
use crate::util::KernelVersion; use std::{hash::Hash, os::fd::AsFd, path::Path};
use std::{
hash::Hash,
os::fd::{AsFd as _, AsRawFd},
path::Path,
};
use crate::{ use crate::{
generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCKOPT, generated::bpf_prog_type::BPF_PROG_TYPE_CGROUP_SOCKOPT,
programs::{ programs::{
define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError, define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
util::KernelVersion,
VerifierLogLevel, VerifierLogLevel,
}; };
@ -68,35 +64,29 @@ impl CgroupSockopt {
/// Attaches the program to the given cgroup. /// Attaches the program to the given cgroup.
/// ///
/// The returned value can be used to detach, see [CgroupSockopt::detach]. /// The returned value can be used to detach, see [CgroupSockopt::detach].
pub fn attach<T: AsRawFd>(&mut self, cgroup: T) -> Result<CgroupSockoptLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, cgroup: T) -> Result<CgroupSockoptLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd(); let cgroup_fd = cgroup.as_fd();
let attach_type = self.data.expected_attach_type.unwrap(); let attach_type = self.data.expected_attach_type.unwrap();
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) {
let link_fd = bpf_link_create(prog_fd, cgroup_fd, attach_type, None, 0).map_err( let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(cgroup_fd), attach_type, None, 0)
|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(CgroupSockoptLink::new(CgroupSockoptLinkInner::Fd( .insert(CgroupSockoptLink::new(CgroupSockoptLinkInner::Fd(
FdLink::new(link_fd), FdLink::new(link_fd),
))) )))
} else { } else {
bpf_prog_attach(prog_fd, cgroup_fd, attach_type).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd, cgroup_fd, attach_type)?;
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data self.data
.links .links
.insert(CgroupSockoptLink::new(CgroupSockoptLinkInner::ProgAttach( .insert(CgroupSockoptLink::new(CgroupSockoptLinkInner::ProgAttach(
ProgAttachLink::new(prog_fd, cgroup_fd, attach_type), link,
))) )))
} }
} }

@ -1,17 +1,14 @@
//! Cgroup sysctl programs. //! Cgroup sysctl programs.
use crate::util::KernelVersion; use std::{hash::Hash, os::fd::AsFd};
use std::{
hash::Hash,
os::fd::{AsFd as _, AsRawFd},
};
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, FdLink, Link, ProgAttachLink, ProgramData, ProgramError, define_link_wrapper, load_program, FdLink, Link, ProgAttachLink, ProgramData, ProgramError,
}, },
sys::{bpf_link_create, bpf_prog_attach, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
util::KernelVersion,
}; };
/// A program used to watch for sysctl changes. /// A program used to watch for sysctl changes.
@ -62,35 +59,35 @@ impl CgroupSysctl {
/// 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].
pub fn attach<T: AsRawFd>(&mut self, cgroup: T) -> Result<CgroupSysctlLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, cgroup: T) -> Result<CgroupSysctlLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd(); let cgroup_fd = cgroup.as_fd();
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 7, 0) {
let link_fd = bpf_link_create(prog_fd, cgroup_fd, BPF_CGROUP_SYSCTL, None, 0).map_err( let link_fd = bpf_link_create(
|(_, io_error)| SyscallError { prog_fd,
LinkTarget::Fd(cgroup_fd),
BPF_CGROUP_SYSCTL,
None,
0,
)
.map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(CgroupSysctlLink::new(CgroupSysctlLinkInner::Fd( .insert(CgroupSysctlLink::new(CgroupSysctlLinkInner::Fd(
FdLink::new(link_fd), FdLink::new(link_fd),
))) )))
} else { } else {
bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SYSCTL).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd, cgroup_fd, BPF_CGROUP_SYSCTL)?;
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data self.data
.links .links
.insert(CgroupSysctlLink::new(CgroupSysctlLinkInner::ProgAttach( .insert(CgroupSysctlLink::new(CgroupSysctlLinkInner::ProgAttach(
ProgAttachLink::new(prog_fd, cgroup_fd, BPF_CGROUP_SYSCTL), link,
))) )))
} }
} }

@ -1,8 +1,9 @@
//! Extension programs. //! Extension programs.
use std::os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, OwnedFd};
use thiserror::Error; use std::os::fd::{AsFd as _, BorrowedFd, OwnedFd};
use object::Endianness; use object::Endianness;
use thiserror::Error;
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_CGROUP_INET_INGRESS, bpf_prog_type::BPF_PROG_TYPE_EXT}, generated::{bpf_attach_type::BPF_CGROUP_INET_INGRESS, bpf_prog_type::BPF_PROG_TYPE_EXT},
@ -10,7 +11,7 @@ use crate::{
programs::{ programs::{
define_link_wrapper, load_program, FdLink, FdLinkId, ProgramData, ProgramError, ProgramFd, define_link_wrapper, load_program, FdLink, FdLinkId, ProgramData, ProgramError, ProgramFd,
}, },
sys::{self, bpf_link_create, SyscallError}, sys::{self, bpf_link_create, LinkTarget, SyscallError},
Btf, Btf,
}; };
@ -94,10 +95,15 @@ impl Extension {
.as_ref() .as_ref()
.ok_or(ProgramError::NotLoaded)?; .ok_or(ProgramError::NotLoaded)?;
let target_fd = target_fd.as_fd(); let target_fd = target_fd.as_fd();
let target_fd = target_fd.as_raw_fd();
let btf_id = self.data.attach_btf_id.ok_or(ProgramError::NotLoaded)?; let btf_id = self.data.attach_btf_id.ok_or(ProgramError::NotLoaded)?;
// the attach type must be set as 0, which is bpf_attach_type::BPF_CGROUP_INET_INGRESS // the attach type must be set as 0, which is bpf_attach_type::BPF_CGROUP_INET_INGRESS
let link_fd = bpf_link_create(prog_fd, target_fd, BPF_CGROUP_INET_INGRESS, Some(btf_id), 0) let link_fd = bpf_link_create(
prog_fd,
LinkTarget::Fd(target_fd),
BPF_CGROUP_INET_INGRESS,
Some(btf_id),
0,
)
.map_err(|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
@ -130,7 +136,7 @@ impl Extension {
// the attach type must be set as 0, which is bpf_attach_type::BPF_CGROUP_INET_INGRESS // the attach type must be set as 0, which is bpf_attach_type::BPF_CGROUP_INET_INGRESS
let link_fd = bpf_link_create( let link_fd = bpf_link_create(
prog_fd, prog_fd,
target_fd.as_raw_fd(), LinkTarget::Fd(target_fd),
BPF_CGROUP_INET_INGRESS, BPF_CGROUP_INET_INGRESS,
Some(btf_id), Some(btf_id),
0, 0,

@ -1,12 +1,11 @@
//! Program links. //! Program links.
use libc::{close, dup};
use thiserror::Error; use thiserror::Error;
use std::{ use std::{
collections::{hash_map::Entry, HashMap}, collections::{hash_map::Entry, HashMap},
ffi::CString, ffi::CString,
io, io,
os::fd::{AsRawFd as _, BorrowedFd, OwnedFd, RawFd}, os::fd::{AsFd as _, AsRawFd as _, BorrowedFd, OwnedFd, RawFd},
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
@ -14,7 +13,9 @@ use crate::{
generated::bpf_attach_type, generated::bpf_attach_type,
pin::PinError, pin::PinError,
programs::ProgramError, programs::ProgramError,
sys::{bpf_get_object, bpf_pin_object, bpf_prog_detach, SyscallError}, sys::{
bpf_get_object, bpf_pin_object, bpf_prog_attach, bpf_prog_detach, SysResult, SyscallError,
},
}; };
/// A Link. /// A Link.
@ -234,22 +235,34 @@ pub struct ProgAttachLinkId(RawFd, RawFd, bpf_attach_type);
#[derive(Debug)] #[derive(Debug)]
pub struct ProgAttachLink { pub struct ProgAttachLink {
prog_fd: RawFd, prog_fd: RawFd,
target_fd: RawFd, target_fd: OwnedFd,
attach_type: bpf_attach_type, attach_type: bpf_attach_type,
} }
impl ProgAttachLink { impl ProgAttachLink {
pub(crate) fn new( pub(crate) fn attach(
prog_fd: BorrowedFd<'_>, prog_fd: BorrowedFd<'_>,
target_fd: RawFd, target_fd: BorrowedFd<'_>,
attach_type: bpf_attach_type, attach_type: bpf_attach_type,
) -> Self { ) -> Result<Self, ProgramError> {
// The link is going to own this new file descriptor so we are
// going to need a duplicate whose lifetime we manage. Let's
// duplicate it prior to attaching it so the new file
// descriptor is closed at drop in case it fails to attach.
let target_fd = target_fd.try_clone_to_owned()?;
bpf_prog_attach(prog_fd, target_fd.as_fd(), attach_type).map_err(|(_, io_error)| {
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
let prog_fd = prog_fd.as_raw_fd(); let prog_fd = prog_fd.as_raw_fd();
Self { Ok(Self {
prog_fd, prog_fd,
target_fd: unsafe { dup(target_fd) }, target_fd,
attach_type, attach_type,
} })
} }
} }
@ -257,12 +270,12 @@ impl Link for ProgAttachLink {
type Id = ProgAttachLinkId; type Id = ProgAttachLinkId;
fn id(&self) -> Self::Id { fn id(&self) -> Self::Id {
ProgAttachLinkId(self.prog_fd, self.target_fd, self.attach_type) ProgAttachLinkId(self.prog_fd, self.target_fd.as_raw_fd(), self.attach_type)
} }
fn detach(self) -> Result<(), ProgramError> { fn detach(self) -> Result<(), ProgramError> {
let _ = bpf_prog_detach(self.prog_fd, self.target_fd, self.attach_type); let _: SysResult<_> =
unsafe { close(self.target_fd) }; bpf_prog_detach(self.prog_fd, self.target_fd.as_fd(), self.attach_type);
Ok(()) Ok(())
} }
} }

@ -1,14 +1,12 @@
//! Lirc programs. //! Lirc programs.
use std::os::fd::{AsFd as _, AsRawFd, BorrowedFd, IntoRawFd as _, RawFd}; use std::os::fd::{AsFd, AsRawFd, BorrowedFd, IntoRawFd as _, OwnedFd, 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::{load_program, query, Link, ProgramData, ProgramError, ProgramInfo}, programs::{load_program, query, Link, ProgramData, ProgramError, ProgramInfo},
sys::{bpf_prog_attach, bpf_prog_detach, bpf_prog_get_fd_by_id, SyscallError}, sys::{bpf_prog_attach, bpf_prog_detach, bpf_prog_get_fd_by_id, SysResult, SyscallError},
}; };
use libc::{close, dup};
/// A program used to decode IR into key events for a lirc device. /// A program used to decode IR into key events for a lirc device.
/// ///
/// [`LircMode2`] programs can be used to inspect infrared pulses, spaces, /// [`LircMode2`] programs can be used to inspect infrared pulses, spaces,
@ -60,12 +58,17 @@ impl LircMode2 {
/// 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].
pub fn attach<T: AsRawFd>(&mut self, lircdev: T) -> Result<LircLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, lircdev: T) -> Result<LircLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let lircdev_fd = lircdev.as_raw_fd();
bpf_prog_attach(prog_fd, lircdev_fd, BPF_LIRC_MODE2).map_err(|(_, io_error)| { // The link is going to own this new file descriptor so we are
// going to need a duplicate whose lifetime we manage. Let's
// duplicate it prior to attaching it so the new file
// descriptor is closed at drop in case it fails to attach.
let lircdev_fd = lircdev.as_fd().try_clone_to_owned()?;
bpf_prog_attach(prog_fd, lircdev_fd.as_fd(), BPF_LIRC_MODE2).map_err(|(_, io_error)| {
SyscallError { SyscallError {
call: "bpf_prog_attach", call: "bpf_prog_attach",
io_error, io_error,
@ -91,31 +94,25 @@ impl LircMode2 {
} }
/// Queries the lirc device for attached programs. /// Queries the lirc device for attached programs.
pub fn query<T: AsRawFd>(target_fd: T) -> Result<Vec<LircLink>, ProgramError> { pub fn query<T: AsFd>(target_fd: T) -> Result<Vec<LircLink>, ProgramError> {
let prog_ids = query(target_fd.as_raw_fd(), BPF_LIRC_MODE2, 0, &mut None)?; let target_fd = target_fd.as_fd();
let prog_ids = query(target_fd, BPF_LIRC_MODE2, 0, &mut None)?;
let mut prog_fds = Vec::with_capacity(prog_ids.len());
for id in prog_ids { prog_ids
let fd = bpf_prog_get_fd_by_id(id)?;
prog_fds.push(fd);
}
Ok(prog_fds
.into_iter() .into_iter()
.map(|prog_fd| { .map(|prog_id| {
LircLink::new( let prog_fd = bpf_prog_get_fd_by_id(prog_id)?;
let target_fd = target_fd.try_clone_to_owned()?;
// SAFETY: The file descriptor will stay valid because // SAFETY: The file descriptor will stay valid because
// we are leaking it. We cannot use `OwnedFd` in here // we are leaking it. We cannot use `OwnedFd` in here
// because LircMode2::attach also uses LircLink::new // because LircMode2::attach also uses LircLink::new
// but with a borrowed file descriptor (of the loaded // but with a borrowed file descriptor (of the loaded
// program) without duplicating. TODO(#612): Fix API // program) without duplicating. TODO(#612): Fix API
// or internals so this file descriptor isn't leaked // or internals so this file descriptor isn't leaked
unsafe { BorrowedFd::borrow_raw(prog_fd.into_raw_fd()) }, let prog_fd = unsafe { BorrowedFd::borrow_raw(prog_fd.into_raw_fd()) };
target_fd.as_raw_fd(), Ok(LircLink::new(prog_fd, target_fd))
)
}) })
.collect()) .collect()
} }
} }
@ -127,16 +124,13 @@ pub struct LircLinkId(RawFd, RawFd);
/// An LircMode2 Link /// An LircMode2 Link
pub struct LircLink { pub struct LircLink {
prog_fd: RawFd, prog_fd: RawFd,
target_fd: RawFd, target_fd: OwnedFd,
} }
impl LircLink { impl LircLink {
pub(crate) fn new(prog_fd: BorrowedFd<'_>, target_fd: RawFd) -> Self { pub(crate) fn new(prog_fd: BorrowedFd<'_>, target_fd: OwnedFd) -> Self {
let prog_fd = prog_fd.as_raw_fd(); let prog_fd = prog_fd.as_raw_fd();
Self { Self { prog_fd, target_fd }
prog_fd,
target_fd: unsafe { dup(target_fd) },
}
} }
/// Get ProgramInfo from this link /// Get ProgramInfo from this link
@ -151,12 +145,11 @@ impl Link for LircLink {
type Id = LircLinkId; type Id = LircLinkId;
fn id(&self) -> Self::Id { fn id(&self) -> Self::Id {
LircLinkId(self.prog_fd, self.target_fd) LircLinkId(self.prog_fd, self.target_fd.as_raw_fd())
} }
fn detach(self) -> Result<(), ProgramError> { fn detach(self) -> Result<(), ProgramError> {
let _ = bpf_prog_detach(self.prog_fd, self.target_fd, BPF_LIRC_MODE2); let _: SysResult<_> = bpf_prog_detach(self.prog_fd, self.target_fd.as_fd(), BPF_LIRC_MODE2);
unsafe { close(self.target_fd) };
Ok(()) Ok(())
} }
} }

@ -640,8 +640,8 @@ fn load_program<T: Link>(
} }
} }
pub(crate) fn query<T: AsRawFd>( pub(crate) fn query(
target_fd: T, target_fd: BorrowedFd<'_>,
attach_type: bpf_attach_type, attach_type: bpf_attach_type,
query_flags: u32, query_flags: u32,
attach_flags: &mut Option<u32>, attach_flags: &mut Option<u32>,
@ -653,7 +653,7 @@ pub(crate) fn query<T: AsRawFd>(
loop { loop {
match bpf_prog_query( match bpf_prog_query(
target_fd.as_raw_fd(), target_fd.as_fd().as_raw_fd(),
attach_type, attach_type,
query_flags, query_flags,
attach_flags.as_mut(), attach_flags.as_mut(),

@ -7,7 +7,7 @@ use crate::{
probe::{detach_debug_fs, ProbeEvent}, probe::{detach_debug_fs, ProbeEvent},
FdLink, Link, ProgramError, FdLink, Link, ProgramError,
}, },
sys::{bpf_link_create, perf_event_ioctl, SysResult, SyscallError}, sys::{bpf_link_create, perf_event_ioctl, LinkTarget, SysResult, SyscallError},
FEATURES, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF, FEATURES, PERF_EVENT_IOC_DISABLE, PERF_EVENT_IOC_ENABLE, PERF_EVENT_IOC_SET_BPF,
}; };
@ -75,12 +75,11 @@ pub(crate) fn perf_attach(
fd: OwnedFd, fd: OwnedFd,
) -> Result<PerfLinkInner, ProgramError> { ) -> Result<PerfLinkInner, ProgramError> {
if FEATURES.bpf_perf_link() { if FEATURES.bpf_perf_link() {
let link_fd = bpf_link_create(prog_fd, fd.as_raw_fd(), BPF_PERF_EVENT, None, 0).map_err( let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(fd.as_fd()), BPF_PERF_EVENT, None, 0)
|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
Ok(PerfLinkInner::FdLink(FdLink::new(link_fd))) Ok(PerfLinkInner::FdLink(FdLink::new(link_fd)))
} else { } else {
perf_attach_either(prog_fd, fd, None) perf_attach_either(prog_fd, fd, None)

@ -1,9 +1,9 @@
use std::os::fd::{AsFd as _, AsRawFd}; use std::os::fd::AsFd;
use crate::{ use crate::{
generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP}, generated::{bpf_attach_type::BPF_SK_LOOKUP, bpf_prog_type::BPF_PROG_TYPE_SK_LOOKUP},
programs::{define_link_wrapper, load_program, FdLinkId, ProgramData, ProgramError}, programs::{define_link_wrapper, load_program, FdLinkId, ProgramData, ProgramError},
sys::{bpf_link_create, SyscallError}, sys::{bpf_link_create, LinkTarget, SyscallError},
}; };
use super::links::FdLink; use super::links::FdLink;
@ -60,17 +60,16 @@ impl SkLookup {
/// Attaches the program to the given network namespace. /// Attaches the program to the given network namespace.
/// ///
/// The returned value can be used to detach, see [SkLookup::detach]. /// The returned value can be used to detach, see [SkLookup::detach].
pub fn attach<T: AsRawFd>(&mut self, netns: T) -> Result<SkLookupLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, netns: T) -> Result<SkLookupLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let netns_fd = netns.as_raw_fd(); let netns_fd = netns.as_fd();
let link_fd = bpf_link_create(prog_fd, netns_fd, BPF_SK_LOOKUP, None, 0).map_err( let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(netns_fd), BPF_SK_LOOKUP, None, 0)
|(_, io_error)| SyscallError { .map_err(|(_, io_error)| SyscallError {
call: "bpf_link_create", call: "bpf_link_create",
io_error, io_error,
}, })?;
)?;
self.data self.data
.links .links
.insert(SkLookupLink::new(FdLink::new(link_fd))) .insert(SkLookupLink::new(FdLink::new(link_fd)))

@ -1,6 +1,6 @@
//! Skmsg programs. //! Skmsg programs.
use std::os::fd::{AsFd as _, AsRawFd as _}; use std::os::fd::AsFd as _;
use crate::{ 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},
@ -9,7 +9,6 @@ use crate::{
define_link_wrapper, load_program, ProgAttachLink, ProgAttachLinkId, ProgramData, define_link_wrapper, load_program, ProgAttachLink, ProgAttachLinkId, ProgramData,
ProgramError, ProgramError,
}, },
sys::{bpf_prog_attach, SyscallError},
}; };
/// A program used to intercept messages sent with `sendmsg()`/`sendfile()`. /// A program used to intercept messages sent with `sendmsg()`/`sendfile()`.
@ -81,19 +80,9 @@ impl SkMsg {
pub fn attach(&mut self, map: SockMapFd) -> Result<SkMsgLinkId, ProgramError> { pub fn attach(&mut self, map: SockMapFd) -> Result<SkMsgLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let map_fd = map.as_raw_fd(); let link = ProgAttachLink::attach(prog_fd, map.as_fd(), BPF_SK_MSG_VERDICT)?;
bpf_prog_attach(prog_fd, map_fd, BPF_SK_MSG_VERDICT).map_err(|(_, io_error)| { self.data.links.insert(SkMsgLink::new(link))
SyscallError {
call: "bpf_prog_attach",
io_error,
}
})?;
self.data.links.insert(SkMsgLink::new(ProgAttachLink::new(
prog_fd,
map_fd,
BPF_SK_MSG_VERDICT,
)))
} }
/// Detaches the program from a sockmap. /// Detaches the program from a sockmap.

@ -1,9 +1,6 @@
//! Skskb programs. //! Skskb programs.
use std::{ use std::{os::fd::AsFd as _, path::Path};
os::fd::{AsFd as _, AsRawFd as _},
path::Path,
};
use crate::{ use crate::{
generated::{ generated::{
@ -15,7 +12,6 @@ use crate::{
define_link_wrapper, load_program, ProgAttachLink, ProgAttachLinkId, ProgramData, define_link_wrapper, load_program, ProgAttachLink, ProgAttachLinkId, ProgramData,
ProgramError, ProgramError,
}, },
sys::{bpf_prog_attach, SyscallError},
VerifierLogLevel, VerifierLogLevel,
}; };
@ -77,21 +73,15 @@ impl SkSkb {
pub fn attach(&mut self, map: SockMapFd) -> Result<SkSkbLinkId, ProgramError> { pub fn attach(&mut self, map: SockMapFd) -> Result<SkSkbLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let map_fd = map.as_raw_fd();
let attach_type = match self.kind { let attach_type = match self.kind {
SkSkbKind::StreamParser => BPF_SK_SKB_STREAM_PARSER, SkSkbKind::StreamParser => BPF_SK_SKB_STREAM_PARSER,
SkSkbKind::StreamVerdict => BPF_SK_SKB_STREAM_VERDICT, SkSkbKind::StreamVerdict => BPF_SK_SKB_STREAM_VERDICT,
}; };
bpf_prog_attach(prog_fd, map_fd, attach_type).map_err(|(_, io_error)| SyscallError {
call: "bpf_prog_attach", let link = ProgAttachLink::attach(prog_fd, map.as_fd(), attach_type)?;
io_error,
})?; self.data.links.insert(SkSkbLink::new(link))
self.data.links.insert(SkSkbLink::new(ProgAttachLink::new(
prog_fd,
map_fd,
attach_type,
)))
} }
/// Detaches the program. /// Detaches the program.

@ -1,5 +1,5 @@
//! Socket option programs. //! Socket option programs.
use std::os::fd::{AsFd as _, AsRawFd}; use std::os::fd::AsFd;
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},
@ -7,7 +7,6 @@ use crate::{
define_link_wrapper, load_program, ProgAttachLink, ProgAttachLinkId, ProgramData, define_link_wrapper, load_program, ProgAttachLink, ProgAttachLinkId, ProgramData,
ProgramError, ProgramError,
}, },
sys::{bpf_prog_attach, SyscallError},
}; };
/// A program used to work with sockets. /// A program used to work with sockets.
@ -58,22 +57,11 @@ impl SockOps {
/// 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].
pub fn attach<T: AsRawFd>(&mut self, cgroup: T) -> Result<SockOpsLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, cgroup: T) -> Result<SockOpsLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd();
let cgroup_fd = cgroup.as_raw_fd();
bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS).map_err(|(_, io_error)| { let link = ProgAttachLink::attach(prog_fd.as_fd(), cgroup.as_fd(), BPF_CGROUP_SOCK_OPS)?;
SyscallError { self.data.links.insert(SockOpsLink::new(link))
call: "bpf_prog_attach",
io_error,
}
})?;
self.data.links.insert(SockOpsLink::new(ProgAttachLink::new(
prog_fd,
cgroup_fd,
BPF_CGROUP_SOCK_OPS,
)))
} }
/// Detaches the program. /// Detaches the program.

@ -2,7 +2,7 @@
use libc::{setsockopt, SOL_SOCKET}; use libc::{setsockopt, SOL_SOCKET};
use std::{ use std::{
io, mem, io, mem,
os::fd::{AsFd as _, AsRawFd, RawFd}, os::fd::{AsFd, AsRawFd, RawFd},
}; };
use thiserror::Error; use thiserror::Error;
@ -48,13 +48,12 @@ pub enum SocketFilterError {
/// # } /// # }
/// # let mut bpf = aya::Bpf::load(&[])?; /// # let mut bpf = aya::Bpf::load(&[])?;
/// use std::net::TcpStream; /// use std::net::TcpStream;
/// use std::os::fd::AsRawFd;
/// use aya::programs::SocketFilter; /// use aya::programs::SocketFilter;
/// ///
/// let mut client = TcpStream::connect("127.0.0.1:1234")?; /// let mut client = TcpStream::connect("127.0.0.1:1234")?;
/// let prog: &mut SocketFilter = bpf.program_mut("filter_packets").unwrap().try_into()?; /// let prog: &mut SocketFilter = bpf.program_mut("filter_packets").unwrap().try_into()?;
/// prog.load()?; /// prog.load()?;
/// prog.attach(client.as_raw_fd())?; /// prog.attach(&client)?;
/// # Ok::<(), Error>(()) /// # Ok::<(), Error>(())
/// ``` /// ```
#[derive(Debug)] #[derive(Debug)]
@ -72,10 +71,11 @@ impl SocketFilter {
/// 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].
pub fn attach<T: AsRawFd>(&mut self, socket: T) -> Result<SocketFilterLinkId, ProgramError> { pub fn attach<T: AsFd>(&mut self, socket: T) -> Result<SocketFilterLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let prog_fd = prog_fd.as_raw_fd(); let prog_fd = prog_fd.as_raw_fd();
let socket = socket.as_fd();
let socket = socket.as_raw_fd(); let socket = socket.as_raw_fd();
let ret = unsafe { let ret = unsafe {

@ -1,6 +1,9 @@
//! eXpress Data Path (XDP) programs. //! eXpress Data Path (XDP) programs.
use crate::{sys::SyscallError, util::KernelVersion}; use crate::{
sys::{LinkTarget, SyscallError},
util::KernelVersion,
};
use bitflags; use bitflags;
use libc::if_nametoindex; use libc::if_nametoindex;
use std::{ use std::{
@ -128,12 +131,11 @@ impl Xdp {
) -> Result<XdpLinkId, ProgramError> { ) -> Result<XdpLinkId, ProgramError> {
let prog_fd = self.fd()?; let prog_fd = self.fd()?;
let prog_fd = prog_fd.as_fd(); let prog_fd = prog_fd.as_fd();
let if_index = if_index as RawFd;
if KernelVersion::current().unwrap() >= KernelVersion::new(5, 9, 0) { if KernelVersion::current().unwrap() >= KernelVersion::new(5, 9, 0) {
let link_fd = bpf_link_create( let link_fd = bpf_link_create(
prog_fd, prog_fd,
if_index, LinkTarget::IfIndex(if_index),
bpf_attach_type::BPF_XDP, bpf_attach_type::BPF_XDP,
None, None,
flags.bits(), flags.bits(),
@ -146,6 +148,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 {
let if_index = if_index as i32;
unsafe { netlink_set_xdp_fd(if_index, Some(prog_fd), None, flags.bits()) } unsafe { netlink_set_xdp_fd(if_index, Some(prog_fd), None, flags.bits()) }
.map_err(|io_error| XdpError::NetlinkError { io_error })?; .map_err(|io_error| XdpError::NetlinkError { io_error })?;

@ -365,10 +365,15 @@ pub(crate) fn bpf_map_freeze(fd: RawFd) -> SysResult<c_long> {
sys_bpf(bpf_cmd::BPF_MAP_FREEZE, &mut attr) sys_bpf(bpf_cmd::BPF_MAP_FREEZE, &mut attr)
} }
pub(crate) enum LinkTarget<'f> {
Fd(BorrowedFd<'f>),
IfIndex(u32),
}
// since kernel 5.7 // since kernel 5.7
pub(crate) fn bpf_link_create( pub(crate) fn bpf_link_create(
prog_fd: BorrowedFd<'_>, prog_fd: BorrowedFd<'_>,
target_fd: RawFd, target: LinkTarget<'_>,
attach_type: bpf_attach_type, attach_type: bpf_attach_type,
btf_id: Option<u32>, btf_id: Option<u32>,
flags: u32, flags: u32,
@ -376,7 +381,15 @@ pub(crate) fn bpf_link_create(
let mut attr = unsafe { mem::zeroed::<bpf_attr>() }; let mut attr = unsafe { mem::zeroed::<bpf_attr>() };
attr.link_create.__bindgen_anon_1.prog_fd = prog_fd.as_raw_fd() as u32; attr.link_create.__bindgen_anon_1.prog_fd = prog_fd.as_raw_fd() as u32;
attr.link_create.__bindgen_anon_2.target_fd = target_fd as u32;
match target {
LinkTarget::Fd(fd) => {
attr.link_create.__bindgen_anon_2.target_fd = fd.as_raw_fd() as u32;
}
LinkTarget::IfIndex(ifindex) => {
attr.link_create.__bindgen_anon_2.target_ifindex = ifindex;
}
};
attr.link_create.attach_type = attach_type as u32; attr.link_create.attach_type = attach_type as u32;
attr.link_create.flags = flags; attr.link_create.flags = flags;
if let Some(btf_id) = btf_id { if let Some(btf_id) = btf_id {
@ -410,13 +423,13 @@ pub(crate) fn bpf_link_update(
pub(crate) fn bpf_prog_attach( pub(crate) fn bpf_prog_attach(
prog_fd: BorrowedFd<'_>, prog_fd: BorrowedFd<'_>,
target_fd: RawFd, target_fd: BorrowedFd<'_>,
attach_type: bpf_attach_type, attach_type: bpf_attach_type,
) -> SysResult<c_long> { ) -> SysResult<c_long> {
let mut attr = unsafe { mem::zeroed::<bpf_attr>() }; let mut attr = unsafe { mem::zeroed::<bpf_attr>() };
attr.__bindgen_anon_5.attach_bpf_fd = prog_fd.as_raw_fd() as u32; attr.__bindgen_anon_5.attach_bpf_fd = prog_fd.as_raw_fd() as u32;
attr.__bindgen_anon_5.target_fd = target_fd as u32; attr.__bindgen_anon_5.target_fd = target_fd.as_raw_fd() as u32;
attr.__bindgen_anon_5.attach_type = attach_type as u32; attr.__bindgen_anon_5.attach_type = attach_type as u32;
sys_bpf(bpf_cmd::BPF_PROG_ATTACH, &mut attr) sys_bpf(bpf_cmd::BPF_PROG_ATTACH, &mut attr)
@ -424,13 +437,13 @@ pub(crate) fn bpf_prog_attach(
pub(crate) fn bpf_prog_detach( pub(crate) fn bpf_prog_detach(
prog_fd: RawFd, prog_fd: RawFd,
map_fd: RawFd, target_fd: BorrowedFd<'_>,
attach_type: bpf_attach_type, attach_type: bpf_attach_type,
) -> SysResult<c_long> { ) -> SysResult<c_long> {
let mut attr = unsafe { mem::zeroed::<bpf_attr>() }; let mut attr = unsafe { mem::zeroed::<bpf_attr>() };
attr.__bindgen_anon_5.attach_bpf_fd = prog_fd as u32; attr.__bindgen_anon_5.attach_bpf_fd = prog_fd as u32;
attr.__bindgen_anon_5.target_fd = map_fd as u32; attr.__bindgen_anon_5.target_fd = target_fd.as_raw_fd() as u32;
attr.__bindgen_anon_5.attach_type = attach_type as u32; attr.__bindgen_anon_5.attach_type = attach_type as u32;
sys_bpf(bpf_cmd::BPF_PROG_DETACH, &mut attr) sys_bpf(bpf_cmd::BPF_PROG_DETACH, &mut attr)
@ -683,7 +696,7 @@ pub(crate) fn is_perf_link_supported() -> bool {
let fd = fd.as_fd(); let fd = fd.as_fd();
matches!( matches!(
// Uses an invalid target FD so we get EBADF if supported. // Uses an invalid target FD so we get EBADF if supported.
bpf_link_create(fd, -1, bpf_attach_type::BPF_PERF_EVENT, None, 0), bpf_link_create(fd, LinkTarget::IfIndex(u32::MAX), bpf_attach_type::BPF_PERF_EVENT, None, 0),
// Returns EINVAL if unsupported. EBADF if supported. // Returns EINVAL if unsupported. EBADF if supported.
Err((_, e)) if e.raw_os_error() == Some(libc::EBADF), Err((_, e)) if e.raw_os_error() == Some(libc::EBADF),
) )

@ -637,8 +637,8 @@ pub fn aya::maps::SockMap<T>::borrow_mut(&mut self) -> &mut T
impl<T> core::convert::From<T> for aya::maps::SockMap<T> impl<T> core::convert::From<T> for aya::maps::SockMap<T>
pub fn aya::maps::SockMap<T>::from(t: T) -> T pub fn aya::maps::SockMap<T>::from(t: T) -> T
pub struct aya::maps::sock::SockMapFd(_) pub struct aya::maps::sock::SockMapFd(_)
impl std::os::fd::raw::AsRawFd for aya::maps::sock::SockMapFd impl std::os::fd::owned::AsFd for aya::maps::sock::SockMapFd
pub fn aya::maps::sock::SockMapFd::as_raw_fd(&self) -> std::os::fd::raw::RawFd pub fn aya::maps::sock::SockMapFd::as_fd(&self) -> std::os::fd::owned::BorrowedFd<'_>
impl core::clone::Clone for aya::maps::sock::SockMapFd impl core::clone::Clone for aya::maps::sock::SockMapFd
pub fn aya::maps::sock::SockMapFd::clone(&self) -> aya::maps::sock::SockMapFd pub fn aya::maps::sock::SockMapFd::clone(&self) -> aya::maps::sock::SockMapFd
impl core::marker::Copy for aya::maps::sock::SockMapFd impl core::marker::Copy for aya::maps::sock::SockMapFd
@ -1793,7 +1793,7 @@ pub use aya::programs::CgroupSockoptAttachType
pub mod aya::programs::cgroup_device pub mod aya::programs::cgroup_device
pub struct aya::programs::cgroup_device::CgroupDevice pub struct aya::programs::cgroup_device::CgroupDevice
impl aya::programs::cgroup_device::CgroupDevice impl aya::programs::cgroup_device::CgroupDevice
pub fn aya::programs::cgroup_device::CgroupDevice::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_device::CgroupDevice::detach(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::detach(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_device::CgroupDevice::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_device::CgroupDevice::take_link(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLink, aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::take_link(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLink, aya::programs::ProgramError>
@ -1936,7 +1936,7 @@ impl<T> core::convert::From<T> for aya::programs::cgroup_skb::CgroupSkbAttachTyp
pub fn aya::programs::cgroup_skb::CgroupSkbAttachType::from(t: T) -> T pub fn aya::programs::cgroup_skb::CgroupSkbAttachType::from(t: T) -> T
pub struct aya::programs::cgroup_skb::CgroupSkb pub struct aya::programs::cgroup_skb::CgroupSkb
impl aya::programs::cgroup_skb::CgroupSkb impl aya::programs::cgroup_skb::CgroupSkb
pub fn aya::programs::cgroup_skb::CgroupSkb::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T, attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<aya::programs::cgroup_skb::CgroupSkbLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_skb::CgroupSkb::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T, attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<aya::programs::cgroup_skb::CgroupSkbLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_skb::CgroupSkb::detach(&mut self, link_id: aya::programs::cgroup_skb::CgroupSkbLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_skb::CgroupSkb::detach(&mut self, link_id: aya::programs::cgroup_skb::CgroupSkbLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_skb::CgroupSkb::expected_attach_type(&self) -> &core::option::Option<aya::programs::cgroup_skb::CgroupSkbAttachType> pub fn aya::programs::cgroup_skb::CgroupSkb::expected_attach_type(&self) -> &core::option::Option<aya::programs::cgroup_skb::CgroupSkbAttachType>
pub fn aya::programs::cgroup_skb::CgroupSkb::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, expected_attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_skb::CgroupSkb::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, expected_attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
@ -2047,7 +2047,7 @@ pub mod aya::programs::cgroup_sock
pub use aya::programs::cgroup_sock::CgroupSockAttachType pub use aya::programs::cgroup_sock::CgroupSockAttachType
pub struct aya::programs::cgroup_sock::CgroupSock pub struct aya::programs::cgroup_sock::CgroupSock
impl aya::programs::cgroup_sock::CgroupSock impl aya::programs::cgroup_sock::CgroupSock
pub fn aya::programs::cgroup_sock::CgroupSock::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock::CgroupSockLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock::CgroupSockLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock::CgroupSock::detach(&mut self, link_id: aya::programs::cgroup_sock::CgroupSockLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::detach(&mut self, link_id: aya::programs::cgroup_sock::CgroupSockLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock::CgroupSock::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock::CgroupSockAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock::CgroupSockAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock::CgroupSock::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
@ -2157,7 +2157,7 @@ pub mod aya::programs::cgroup_sock_addr
pub use aya::programs::cgroup_sock_addr::CgroupSockAddrAttachType pub use aya::programs::cgroup_sock_addr::CgroupSockAddrAttachType
pub struct aya::programs::cgroup_sock_addr::CgroupSockAddr pub struct aya::programs::cgroup_sock_addr::CgroupSockAddr
impl aya::programs::cgroup_sock_addr::CgroupSockAddr impl aya::programs::cgroup_sock_addr::CgroupSockAddr
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::detach(&mut self, link_id: aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::detach(&mut self, link_id: aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock_addr::CgroupSockAddrAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock_addr::CgroupSockAddrAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
@ -2267,7 +2267,7 @@ pub mod aya::programs::cgroup_sockopt
pub use aya::programs::cgroup_sockopt::CgroupSockoptAttachType pub use aya::programs::cgroup_sockopt::CgroupSockoptAttachType
pub struct aya::programs::cgroup_sockopt::CgroupSockopt pub struct aya::programs::cgroup_sockopt::CgroupSockopt
impl aya::programs::cgroup_sockopt::CgroupSockopt impl aya::programs::cgroup_sockopt::CgroupSockopt
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sockopt::CgroupSockoptLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sockopt::CgroupSockoptLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::detach(&mut self, link_id: aya::programs::cgroup_sockopt::CgroupSockoptLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::detach(&mut self, link_id: aya::programs::cgroup_sockopt::CgroupSockoptLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sockopt::CgroupSockoptAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sockopt::CgroupSockoptAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
@ -2376,7 +2376,7 @@ pub fn aya::programs::cgroup_sockopt::CgroupSockoptLinkId::from(t: T) -> T
pub mod aya::programs::cgroup_sysctl pub mod aya::programs::cgroup_sysctl
pub struct aya::programs::cgroup_sysctl::CgroupSysctl pub struct aya::programs::cgroup_sysctl::CgroupSysctl
impl aya::programs::cgroup_sysctl::CgroupSysctl impl aya::programs::cgroup_sysctl::CgroupSysctl
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::detach(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::detach(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::take_link(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLink, aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::take_link(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLink, aya::programs::ProgramError>
@ -3395,10 +3395,10 @@ impl<T> core::convert::From<T> for aya::programs::lirc_mode2::LircLinkId
pub fn aya::programs::lirc_mode2::LircLinkId::from(t: T) -> T pub fn aya::programs::lirc_mode2::LircLinkId::from(t: T) -> T
pub struct aya::programs::lirc_mode2::LircMode2 pub struct aya::programs::lirc_mode2::LircMode2
impl aya::programs::lirc_mode2::LircMode2 impl aya::programs::lirc_mode2::LircMode2
pub fn aya::programs::lirc_mode2::LircMode2::attach<T: std::os::fd::raw::AsRawFd>(&mut self, lircdev: T) -> core::result::Result<aya::programs::lirc_mode2::LircLinkId, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::attach<T: std::os::fd::owned::AsFd>(&mut self, lircdev: T) -> core::result::Result<aya::programs::lirc_mode2::LircLinkId, aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::detach(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::detach(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::query<T: std::os::fd::raw::AsRawFd>(target_fd: T) -> core::result::Result<alloc::vec::Vec<aya::programs::lirc_mode2::LircLink>, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::query<T: std::os::fd::owned::AsFd>(target_fd: T) -> core::result::Result<alloc::vec::Vec<aya::programs::lirc_mode2::LircLink>, aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::take_link(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<aya::programs::lirc_mode2::LircLink, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::take_link(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<aya::programs::lirc_mode2::LircLink, aya::programs::ProgramError>
impl aya::programs::lirc_mode2::LircMode2 impl aya::programs::lirc_mode2::LircMode2
pub fn aya::programs::lirc_mode2::LircMode2::fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>
@ -5567,7 +5567,7 @@ impl<T> core::convert::From<T> for aya::programs::tp_btf::BtfTracePoint
pub fn aya::programs::tp_btf::BtfTracePoint::from(t: T) -> T pub fn aya::programs::tp_btf::BtfTracePoint::from(t: T) -> T
pub struct aya::programs::CgroupDevice pub struct aya::programs::CgroupDevice
impl aya::programs::cgroup_device::CgroupDevice impl aya::programs::cgroup_device::CgroupDevice
pub fn aya::programs::cgroup_device::CgroupDevice::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_device::CgroupDevice::detach(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::detach(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_device::CgroupDevice::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_device::CgroupDevice::take_link(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLink, aya::programs::ProgramError> pub fn aya::programs::cgroup_device::CgroupDevice::take_link(&mut self, link_id: aya::programs::cgroup_device::CgroupDeviceLinkId) -> core::result::Result<aya::programs::cgroup_device::CgroupDeviceLink, aya::programs::ProgramError>
@ -5615,7 +5615,7 @@ impl<T> core::convert::From<T> for aya::programs::cgroup_device::CgroupDevice
pub fn aya::programs::cgroup_device::CgroupDevice::from(t: T) -> T pub fn aya::programs::cgroup_device::CgroupDevice::from(t: T) -> T
pub struct aya::programs::CgroupSkb pub struct aya::programs::CgroupSkb
impl aya::programs::cgroup_skb::CgroupSkb impl aya::programs::cgroup_skb::CgroupSkb
pub fn aya::programs::cgroup_skb::CgroupSkb::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T, attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<aya::programs::cgroup_skb::CgroupSkbLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_skb::CgroupSkb::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T, attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<aya::programs::cgroup_skb::CgroupSkbLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_skb::CgroupSkb::detach(&mut self, link_id: aya::programs::cgroup_skb::CgroupSkbLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_skb::CgroupSkb::detach(&mut self, link_id: aya::programs::cgroup_skb::CgroupSkbLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_skb::CgroupSkb::expected_attach_type(&self) -> &core::option::Option<aya::programs::cgroup_skb::CgroupSkbAttachType> pub fn aya::programs::cgroup_skb::CgroupSkb::expected_attach_type(&self) -> &core::option::Option<aya::programs::cgroup_skb::CgroupSkbAttachType>
pub fn aya::programs::cgroup_skb::CgroupSkb::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, expected_attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_skb::CgroupSkb::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, expected_attach_type: aya::programs::cgroup_skb::CgroupSkbAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
@ -5663,7 +5663,7 @@ impl<T> core::convert::From<T> for aya::programs::cgroup_skb::CgroupSkb
pub fn aya::programs::cgroup_skb::CgroupSkb::from(t: T) -> T pub fn aya::programs::cgroup_skb::CgroupSkb::from(t: T) -> T
pub struct aya::programs::CgroupSock pub struct aya::programs::CgroupSock
impl aya::programs::cgroup_sock::CgroupSock impl aya::programs::cgroup_sock::CgroupSock
pub fn aya::programs::cgroup_sock::CgroupSock::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock::CgroupSockLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock::CgroupSockLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock::CgroupSock::detach(&mut self, link_id: aya::programs::cgroup_sock::CgroupSockLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::detach(&mut self, link_id: aya::programs::cgroup_sock::CgroupSockLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock::CgroupSock::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock::CgroupSockAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock::CgroupSockAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock::CgroupSock::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock::CgroupSock::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
@ -5710,7 +5710,7 @@ impl<T> core::convert::From<T> for aya::programs::cgroup_sock::CgroupSock
pub fn aya::programs::cgroup_sock::CgroupSock::from(t: T) -> T pub fn aya::programs::cgroup_sock::CgroupSock::from(t: T) -> T
pub struct aya::programs::CgroupSockAddr pub struct aya::programs::CgroupSockAddr
impl aya::programs::cgroup_sock_addr::CgroupSockAddr impl aya::programs::cgroup_sock_addr::CgroupSockAddr
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::detach(&mut self, link_id: aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::detach(&mut self, link_id: aya::programs::cgroup_sock_addr::CgroupSockAddrLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock_addr::CgroupSockAddrAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sock_addr::CgroupSockAddrAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
@ -5757,7 +5757,7 @@ impl<T> core::convert::From<T> for aya::programs::cgroup_sock_addr::CgroupSockAd
pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::from(t: T) -> T pub fn aya::programs::cgroup_sock_addr::CgroupSockAddr::from(t: T) -> T
pub struct aya::programs::CgroupSockopt pub struct aya::programs::CgroupSockopt
impl aya::programs::cgroup_sockopt::CgroupSockopt impl aya::programs::cgroup_sockopt::CgroupSockopt
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sockopt::CgroupSockoptLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sockopt::CgroupSockoptLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::detach(&mut self, link_id: aya::programs::cgroup_sockopt::CgroupSockoptLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::detach(&mut self, link_id: aya::programs::cgroup_sockopt::CgroupSockoptLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sockopt::CgroupSockoptAttachType) -> core::result::Result<Self, aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::from_pin<P: core::convert::AsRef<std::path::Path>>(path: P, attach_type: aya_obj::programs::cgroup_sockopt::CgroupSockoptAttachType) -> core::result::Result<Self, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sockopt::CgroupSockopt::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
@ -5804,7 +5804,7 @@ impl<T> core::convert::From<T> for aya::programs::cgroup_sockopt::CgroupSockopt
pub fn aya::programs::cgroup_sockopt::CgroupSockopt::from(t: T) -> T pub fn aya::programs::cgroup_sockopt::CgroupSockopt::from(t: T) -> T
pub struct aya::programs::CgroupSysctl pub struct aya::programs::CgroupSysctl
impl aya::programs::cgroup_sysctl::CgroupSysctl impl aya::programs::cgroup_sysctl::CgroupSysctl
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLinkId, aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLinkId, aya::programs::ProgramError>
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::detach(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::detach(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::cgroup_sysctl::CgroupSysctl::take_link(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLink, aya::programs::ProgramError> pub fn aya::programs::cgroup_sysctl::CgroupSysctl::take_link(&mut self, link_id: aya::programs::cgroup_sysctl::CgroupSysctlLinkId) -> core::result::Result<aya::programs::cgroup_sysctl::CgroupSysctlLink, aya::programs::ProgramError>
@ -6045,10 +6045,10 @@ impl<T> core::convert::From<T> for aya::programs::kprobe::KProbe
pub fn aya::programs::kprobe::KProbe::from(t: T) -> T pub fn aya::programs::kprobe::KProbe::from(t: T) -> T
pub struct aya::programs::LircMode2 pub struct aya::programs::LircMode2
impl aya::programs::lirc_mode2::LircMode2 impl aya::programs::lirc_mode2::LircMode2
pub fn aya::programs::lirc_mode2::LircMode2::attach<T: std::os::fd::raw::AsRawFd>(&mut self, lircdev: T) -> core::result::Result<aya::programs::lirc_mode2::LircLinkId, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::attach<T: std::os::fd::owned::AsFd>(&mut self, lircdev: T) -> core::result::Result<aya::programs::lirc_mode2::LircLinkId, aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::detach(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::detach(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::query<T: std::os::fd::raw::AsRawFd>(target_fd: T) -> core::result::Result<alloc::vec::Vec<aya::programs::lirc_mode2::LircLink>, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::query<T: std::os::fd::owned::AsFd>(target_fd: T) -> core::result::Result<alloc::vec::Vec<aya::programs::lirc_mode2::LircLink>, aya::programs::ProgramError>
pub fn aya::programs::lirc_mode2::LircMode2::take_link(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<aya::programs::lirc_mode2::LircLink, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::take_link(&mut self, link_id: aya::programs::lirc_mode2::LircLinkId) -> core::result::Result<aya::programs::lirc_mode2::LircLink, aya::programs::ProgramError>
impl aya::programs::lirc_mode2::LircMode2 impl aya::programs::lirc_mode2::LircMode2
pub fn aya::programs::lirc_mode2::LircMode2::fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError> pub fn aya::programs::lirc_mode2::LircMode2::fd(&self) -> core::result::Result<&aya::programs::ProgramFd, aya::programs::ProgramError>
@ -6354,7 +6354,7 @@ impl<T> core::convert::From<T> for aya::programs::tc::SchedClassifier
pub fn aya::programs::tc::SchedClassifier::from(t: T) -> T pub fn aya::programs::tc::SchedClassifier::from(t: T) -> T
pub struct aya::programs::SkLookup pub struct aya::programs::SkLookup
impl aya::programs::SkLookup impl aya::programs::SkLookup
pub fn aya::programs::SkLookup::attach<T: std::os::fd::raw::AsRawFd>(&mut self, netns: T) -> core::result::Result<SkLookupLinkId, aya::programs::ProgramError> pub fn aya::programs::SkLookup::attach<T: std::os::fd::owned::AsFd>(&mut self, netns: T) -> core::result::Result<SkLookupLinkId, aya::programs::ProgramError>
pub fn aya::programs::SkLookup::detach(&mut self, link_id: SkLookupLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::SkLookup::detach(&mut self, link_id: SkLookupLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::SkLookup::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::SkLookup::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::SkLookup::take_link(&mut self, link_id: SkLookupLinkId) -> core::result::Result<SkLookupLink, aya::programs::ProgramError> pub fn aya::programs::SkLookup::take_link(&mut self, link_id: SkLookupLinkId) -> core::result::Result<SkLookupLink, aya::programs::ProgramError>
@ -6497,7 +6497,7 @@ impl<T> core::convert::From<T> for aya::programs::SkSkb
pub fn aya::programs::SkSkb::from(t: T) -> T pub fn aya::programs::SkSkb::from(t: T) -> T
pub struct aya::programs::SockOps pub struct aya::programs::SockOps
impl aya::programs::SockOps impl aya::programs::SockOps
pub fn aya::programs::SockOps::attach<T: std::os::fd::raw::AsRawFd>(&mut self, cgroup: T) -> core::result::Result<SockOpsLinkId, aya::programs::ProgramError> pub fn aya::programs::SockOps::attach<T: std::os::fd::owned::AsFd>(&mut self, cgroup: T) -> core::result::Result<SockOpsLinkId, aya::programs::ProgramError>
pub fn aya::programs::SockOps::detach(&mut self, link_id: SockOpsLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::SockOps::detach(&mut self, link_id: SockOpsLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::SockOps::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::SockOps::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::SockOps::take_link(&mut self, link_id: SockOpsLinkId) -> core::result::Result<SockOpsLink, aya::programs::ProgramError> pub fn aya::programs::SockOps::take_link(&mut self, link_id: SockOpsLinkId) -> core::result::Result<SockOpsLink, aya::programs::ProgramError>
@ -6545,7 +6545,7 @@ impl<T> core::convert::From<T> for aya::programs::SockOps
pub fn aya::programs::SockOps::from(t: T) -> T pub fn aya::programs::SockOps::from(t: T) -> T
pub struct aya::programs::SocketFilter pub struct aya::programs::SocketFilter
impl aya::programs::SocketFilter impl aya::programs::SocketFilter
pub fn aya::programs::SocketFilter::attach<T: std::os::fd::raw::AsRawFd>(&mut self, socket: T) -> core::result::Result<SocketFilterLinkId, aya::programs::ProgramError> pub fn aya::programs::SocketFilter::attach<T: std::os::fd::owned::AsFd>(&mut self, socket: T) -> core::result::Result<SocketFilterLinkId, aya::programs::ProgramError>
pub fn aya::programs::SocketFilter::detach(&mut self, link_id: SocketFilterLinkId) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::SocketFilter::detach(&mut self, link_id: SocketFilterLinkId) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::SocketFilter::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError> pub fn aya::programs::SocketFilter::load(&mut self) -> core::result::Result<(), aya::programs::ProgramError>
pub fn aya::programs::SocketFilter::take_link(&mut self, link_id: SocketFilterLinkId) -> core::result::Result<SocketFilterLink, aya::programs::ProgramError> pub fn aya::programs::SocketFilter::take_link(&mut self, link_id: SocketFilterLinkId) -> core::result::Result<SocketFilterLink, aya::programs::ProgramError>

Loading…
Cancel
Save