|
|
|
@ -1,11 +1,11 @@
|
|
|
|
//! Cgroup skb programs.
|
|
|
|
//! Cgroup skb programs.
|
|
|
|
|
|
|
|
|
|
|
|
use std::{hash::Hash, os::fd::AsFd, path::Path};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use aya_obj::generated::{
|
|
|
|
use aya_obj::generated::{
|
|
|
|
bpf_attach_type::{BPF_CGROUP_INET_EGRESS, BPF_CGROUP_INET_INGRESS},
|
|
|
|
bpf_attach_type::{BPF_CGROUP_INET_EGRESS, BPF_CGROUP_INET_INGRESS},
|
|
|
|
bpf_prog_type::BPF_PROG_TYPE_CGROUP_SKB,
|
|
|
|
bpf_prog_type::BPF_PROG_TYPE_CGROUP_SKB,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
use log::warn;
|
|
|
|
|
|
|
|
use std::{hash::Hash, os::fd::AsFd, path::Path};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
VerifierLogLevel,
|
|
|
|
VerifierLogLevel,
|
|
|
|
@ -86,6 +86,10 @@ 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].
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Warning
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// attach modes other than CgroupAttachMode::default() may not be passed on to kernel BPF APIs
|
|
|
|
pub fn attach<T: AsFd>(
|
|
|
|
pub fn attach<T: AsFd>(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
cgroup: T,
|
|
|
|
cgroup: T,
|
|
|
|
@ -101,13 +105,13 @@ impl CgroupSkb {
|
|
|
|
CgroupSkbAttachType::Egress => BPF_CGROUP_INET_EGRESS,
|
|
|
|
CgroupSkbAttachType::Egress => BPF_CGROUP_INET_EGRESS,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if KernelVersion::at_least(5, 7, 0) {
|
|
|
|
if KernelVersion::at_least(5, 7, 0) {
|
|
|
|
let link_fd = bpf_link_create(
|
|
|
|
if mode != CgroupAttachMode::default() {
|
|
|
|
prog_fd,
|
|
|
|
warn!(
|
|
|
|
LinkTarget::Fd(cgroup_fd),
|
|
|
|
"CgroupAttachMode {:?} will not be passed on to bpf_link_create",
|
|
|
|
attach_type,
|
|
|
|
mode
|
|
|
|
mode.into(),
|
|
|
|
);
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
let link_fd = bpf_link_create(prog_fd, LinkTarget::Fd(cgroup_fd), attach_type, 0, None)
|
|
|
|
.map_err(|io_error| SyscallError {
|
|
|
|
.map_err(|io_error| SyscallError {
|
|
|
|
call: "bpf_link_create",
|
|
|
|
call: "bpf_link_create",
|
|
|
|
io_error,
|
|
|
|
io_error,
|
|
|
|
|