Merge pull request #68 from dmitris/fix-clippy

include and use clap only if needed
pull/74/head
Michal Rostecki 2 years ago committed by GitHub
commit fa404ffb26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -73,3 +73,6 @@ regex = "^[a-z_]+$"
type = "string" type = "string"
prompt = "Which lsm hook? (e.g file_open, task_alloc) You can find a list of hooks in include/linux/lsm_hooks.h in the kernel source tree." prompt = "Which lsm hook? (e.g file_open, task_alloc) You can find a list of hooks in include/linux/lsm_hooks.h in the kernel source tree."
regex = "^[a-z_]+$" regex = "^[a-z_]+$"
[hooks]
pre = ["pre-script.rhai"]

@ -0,0 +1,2 @@
let program_types_with_opts = ["classifier", "cgroup_skb", "cgroup_sockopt", "cgroup_sysctl", "sock_ops", "uprobe", "uretprobe", "xdp"];
variable::set("program_types_with_opts", program_types_with_opts);

@ -12,4 +12,4 @@ pub struct SockKey {
#[cfg(feature = "user")] #[cfg(feature = "user")]
unsafe impl aya::Pod for SockKey {} unsafe impl aya::Pod for SockKey {}
{%- endif -%} {%- endif %}

@ -6,10 +6,12 @@ publish = false
[dependencies] [dependencies]
aya = { version = ">=0.11", features=["async_tokio"] } aya = { version = ">=0.11", features=["async_tokio"] }
{% if program_types_with_opts contains program_type -%}
clap = { version = "4.0", features = ["derive"] }
{% endif -%}
aya-log = "0.1" aya-log = "0.1"
{{project-name}}-common = { path = "../{{project-name}}-common", features=["user"] } {{project-name}}-common = { path = "../{{project-name}}-common", features=["user"] }
anyhow = "1.0.42" anyhow = "1.0.42"
clap = { version = "4.0", features = ["derive"] }
env_logger = "0.10" env_logger = "0.10"
{%- if program_type == "uprobe" %} {%- if program_type == "uprobe" %}
libc = "0.2" libc = "0.2"

@ -1,4 +1,3 @@
use aya::{include_bytes_aligned, Bpf};
{% case program_type -%} {% case program_type -%}
{%- when "kprobe", "kretprobe" -%} {%- when "kprobe", "kretprobe" -%}
use aya::programs::KProbe; use aya::programs::KProbe;
@ -41,38 +40,35 @@ use aya::programs::SocketFilter;
{%- when "raw_tracepoint" -%} {%- when "raw_tracepoint" -%}
use aya::programs::RawTracePoint; use aya::programs::RawTracePoint;
{%- endcase %} {%- endcase %}
use aya::{include_bytes_aligned, Bpf};
use aya_log::BpfLogger; use aya_log::BpfLogger;
{% if program_types_with_opts contains program_type -%}
use clap::Parser; use clap::Parser;
{% endif -%}
use log::{info, warn}; use log::{info, warn};
use tokio::signal; use tokio::signal;
{% case program_type %} {% if program_types_with_opts contains program_type -%}
{%- when
"xdp", "classifier", "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt", "uprobe", "uretprobe" -%}
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct Opt { struct Opt {
{% if program_type == "xdp" or program_type == "classifier" -%} {%- if program_type == "xdp" or program_type == "classifier" %}
#[clap(short, long, default_value = "eth0")] #[clap(short, long, default_value = "eth0")]
iface: String, iface: String,
{%- elsif program_type == "sock_ops" or program_type == "cgroup_skb" or program_type == "cgroup_sysctl" or program_type == "cgroup_sockopt" -%} {% elsif program_type == "sock_ops" or program_type == "cgroup_skb" or program_type == "cgroup_sysctl" or program_type == "cgroup_sockopt" %}
#[clap(short, long, default_value = "/sys/fs/cgroup/unified")] #[clap(short, long, default_value = "/sys/fs/cgroup/unified")]
cgroup_path: String, cgroup_path: String,
{%- elsif program_type == "uprobe" or program_type == "uretprobe" -%} {% elsif program_type == "uprobe" or program_type == "uretprobe" %}
#[clap(short, long)] #[clap(short, long)]
pid: Option<i32> pid: Option<i32>
{%- endif %} {% endif -%}
} }
{%- endcase %}
{% endif -%}
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), anyhow::Error> { async fn main() -> Result<(), anyhow::Error> {
{% case program_type %} {%- if program_types_with_opts contains program_type %}
{%- when
"xdp", "classifier", "sock_ops", "cgroup_skb", "cgroup_sysctl", "cgroup_sockopt", "uprobe", "uretprobe" -%}
let opt = Opt::parse(); let opt = Opt::parse();
{% endif %}
{%- endcase %}
env_logger::init(); env_logger::init();
// This will include your eBPF object file as raw bytes at compile-time and load it at // This will include your eBPF object file as raw bytes at compile-time and load it at

Loading…
Cancel
Save