Merge pull request #46 from nak3/add-cgroup-sysctl

Add cgroup_sysctl template for BPF_PROG_TYPE_CGROUP_SYSCTL
pull/49/head
Alessandro Decina 3 years ago committed by GitHub
commit c6b6f1ed3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,6 +31,7 @@ jobs:
- xdp
- classifier
- cgroup_skb
- cgroup_sysctl
- tracepoint
- lsm
- tp_btf

@ -18,6 +18,7 @@ choices = [
"xdp",
"classifier",
"cgroup_skb",
"cgroup_sysctl",
"tracepoint",
"lsm",
"tp_btf"

@ -284,6 +284,25 @@ use aya_bpf::{
pub fn {{crate_name}}(_ctx: SkBuffContext) -> i64 {
return 0
}
{%- when "cgroup_sysctl" %}
use aya_bpf::{
macros::cgroup_sysctl,
programs::SysctlContext,
};
use aya_log_ebpf::info;
#[cgroup_sysctl(name="{{crate_name}}")]
pub fn {{crate_name}}(ctx: SysctlContext) -> i32 {
match unsafe { try_{{crate_name}}(ctx) } {
Ok(ret) => ret,
Err(ret) => ret,
}
}
unsafe fn try_{{crate_name}}(ctx: SysctlContext) -> Result<i32, i32> {
info!(&ctx, "sysctl operation called");
Ok(0)
}
{%- endcase %}
#[panic_handler]

@ -21,6 +21,8 @@ use aya::programs::{Xdp, XdpFlags};
use aya::programs::{tc, SchedClassifier, TcAttachType};
{%- when "cgroup_skb" -%}
use aya::programs::{CgroupSkb, CgroupSkbAttachType};
{%- when "cgroup_sysctl" -%}
use aya::programs::{CgroupSysctl};
{%- when "tracepoint" -%}
use aya::programs::TracePoint;
{%- when "lsm" -%}
@ -43,7 +45,7 @@ struct Opt {
{% if program_type == "xdp" or program_type == "classifier" -%}
#[clap(short, long, default_value = "eth0")]
iface: String,
{%- elsif program_type == "sock_ops" or program_type == "cgroup_skb" -%}
{%- elsif program_type == "sock_ops" or program_type == "cgroup_skb" or program_type == "cgroup_sysctl" -%}
#[clap(short, long, default_value = "/sys/fs/cgroup/unified")]
cgroup_path: String,
{%- elsif program_type == "uprobe" or program_type == "uretprobe" -%}
@ -145,6 +147,11 @@ async fn main() -> Result<(), anyhow::Error> {
let prog: &mut SocketFilter = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
prog.load()?;
prog.attach(client.as_raw_fd())?;
{%- when "cgroup_sysctl" -%}
let program: &mut CgroupSysctl = bpf.program_mut("{{crate_name}}").unwrap().try_into()?;
let cgroup = std::fs::File::open(opt.cgroup_path)?;
program.load()?;
program.attach(cgroup)?;
{%- endcase %}
info!("Waiting for Ctrl-C...");

Loading…
Cancel
Save