@ -4,6 +4,7 @@ use std::{hash::Hash, os::fd::AsFd, path::Path};
use aya_obj ::generated ::bpf_prog_type ::BPF_PROG_TYPE_CGROUP_SOCK_ADDR ;
pub use aya_obj ::programs ::CgroupSockAddrAttachType ;
use log ::warn ;
use crate ::{
VerifierLogLevel ,
@ -71,6 +72,11 @@ impl CgroupSockAddr {
/// Attaches the program to the given cgroup.
///
/// The returned value can be used to detach, see [CgroupSockAddr::detach].
///
/// # Warning
///
/// On kernels 5.7.0 and later, attach modes other than `CgroupAttachMode::default()` are not passed to `bpf_link_create`.
/// On older kernels (using `bpf_prog_attach`), the attach mode is honored.
pub fn attach < T : AsFd > (
& mut self ,
cgroup : T ,
@ -81,17 +87,17 @@ impl CgroupSockAddr {
let cgroup_fd = cgroup . as_fd ( ) ;
let attach_type = self . data . expected_attach_type . unwrap ( ) ;
if KernelVersion ::at_least ( 5 , 7 , 0 ) {
let link_fd = bpf_link_create (
prog_fd,
LinkTarget ::Fd ( cgroup_fd ) ,
attach_type ,
mode . into ( ) ,
None ,
)
. map_err ( | io_error | SyscallError {
call : "bpf_link_create" ,
io_error ,
} ) ? ;
if mode ! = CgroupAttachMode ::default ( ) {
warn! (
"CgroupAttachMode {:?} will not be passed on to bpf_link_create" ,
mode
) ;
}
let link_fd = bpf_link_create ( prog_fd , LinkTarget ::Fd ( cgroup_fd ) , attach_type , 0 , None )
. map_err ( | io_error | SyscallError {
call : "bpf_link_create" ,
io_error ,
} ) ? ;
self . data
. links
. insert ( CgroupSockAddrLink ::new ( CgroupSockAddrLinkInner ::Fd (