Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: auto-attach tracepoints based on SEC() data #1057

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions aya-obj/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ pub enum ProgramSection {
URetProbe {
sleepable: bool,
},
TracePoint,
TracePoint {
category: Option<String>,
name: Option<String>,
},
SocketFilter,
Xdp {
frags: bool,
Expand All @@ -275,7 +278,9 @@ pub enum ProgramSection {
Lsm {
sleepable: bool,
},
BtfTracePoint,
BtfTracePoint {
trace_point: Option<String>,
},
FEntry {
sleepable: bool,
},
Expand Down Expand Up @@ -331,8 +336,14 @@ impl FromStr for ProgramSection {
}
},
},
"tp_btf" => BtfTracePoint,
"tracepoint" | "tp" => TracePoint,
"tp_btf" => BtfTracePoint {
trace_point: pieces.next().map(|s| s.to_string()),
},
"tracepoint" | "tp" => {
let category = pieces.next().map(|s| s.to_string());
let name = pieces.next().map(|s| s.to_string());
TracePoint { category, name }
}
"socket" => SocketFilter,
"sk_msg" => SkMsg,
"sk_skb" => {
Expand Down Expand Up @@ -2029,7 +2040,7 @@ mod tests {
assert_matches!(
obj.parse_section(fake_section(
EbpfSectionKind::Program,
"tracepoint/foo",
"tracepoint/cat/name",
bytes_of(&fake_ins()),
None
)),
Expand Down
48 changes: 36 additions & 12 deletions aya/src/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ use crate::{
Object, ParseError, ProgramSection,
},
programs::{
BtfTracePoint, CgroupDevice, CgroupSkb, CgroupSkbAttachType, CgroupSock, CgroupSockAddr,
CgroupSockopt, CgroupSysctl, Extension, FEntry, FExit, Iter, KProbe, LircMode2, Lsm,
PerfEvent, ProbeKind, Program, ProgramData, ProgramError, RawTracePoint, SchedClassifier,
SkLookup, SkMsg, SkSkb, SkSkbKind, SockOps, SocketFilter, TracePoint, UProbe, Xdp,
trace_point::TracePointAttachInfo, BtfTracePoint, CgroupDevice, CgroupSkb,
CgroupSkbAttachType, CgroupSock, CgroupSockAddr, CgroupSockopt, CgroupSysctl, Extension,
FEntry, FExit, Iter, KProbe, LircMode2, Lsm, PerfEvent, ProbeKind, Program, ProgramData,
ProgramError, RawTracePoint, SchedClassifier, SkLookup, SkMsg, SkSkb, SkSkbKind, SockOps,
SocketFilter, TracePoint, UProbe, Xdp,
},
sys::{
bpf_load_btf, is_bpf_cookie_supported, is_bpf_global_data_supported,
Expand Down Expand Up @@ -412,15 +413,18 @@ impl<'a> EbpfLoader<'a> {
| ProgramSection::FEntry { sleepable: _ }
| ProgramSection::FExit { sleepable: _ }
| ProgramSection::Lsm { sleepable: _ }
| ProgramSection::BtfTracePoint
| ProgramSection::BtfTracePoint { trace_point: _ }
| ProgramSection::Iter { sleepable: _ } => {
return Err(EbpfError::BtfError(err))
}
ProgramSection::KRetProbe
| ProgramSection::KProbe
| ProgramSection::UProbe { sleepable: _ }
| ProgramSection::URetProbe { sleepable: _ }
| ProgramSection::TracePoint
| ProgramSection::TracePoint {
category: _,
name: _,
}
| ProgramSection::SocketFilter
| ProgramSection::Xdp {
frags: _,
Expand Down Expand Up @@ -575,9 +579,19 @@ impl<'a> EbpfLoader<'a> {
kind: ProbeKind::URetProbe,
})
}
ProgramSection::TracePoint => Program::TracePoint(TracePoint {
data: ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level),
}),
ProgramSection::TracePoint { category, name } => {
let expected_attach_info = match (category, name) {
(Some(category), Some(name)) => Some(TracePointAttachInfo {
category: category.clone(),
name: name.clone(),
}),
_ => None,
};
Program::TracePoint(TracePoint {
data: ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level),
expected_attach_info,
})
}
ProgramSection::SocketFilter => Program::SocketFilter(SocketFilter {
data: ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level),
}),
Expand Down Expand Up @@ -657,9 +671,11 @@ impl<'a> EbpfLoader<'a> {
}
Program::Lsm(Lsm { data })
}
ProgramSection::BtfTracePoint => Program::BtfTracePoint(BtfTracePoint {
data: ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level),
}),
ProgramSection::BtfTracePoint { trace_point: _ } => {
Program::BtfTracePoint(BtfTracePoint {
data: ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level),
})
}
ProgramSection::FEntry { sleepable } => {
let mut data =
ProgramData::new(prog_name, obj, btf_fd, *verifier_log_level);
Expand Down Expand Up @@ -1081,6 +1097,14 @@ impl Ebpf {
pub fn programs_mut(&mut self) -> impl Iterator<Item = (&str, &mut Program)> {
self.programs.iter_mut().map(|(s, p)| (s.as_str(), p))
}

/// TODO
pub fn auto_attach(&mut self) {
for (_, program) in self.programs_mut() {
let btf = Btf::from_sys_fs().expect("unable to get btf info");
program.auto_attach(Some(&btf)).unwrap();
}
}
}

/// The error type returned by [`Ebpf::load_file`] and [`Ebpf::load`].
Expand Down
2 changes: 1 addition & 1 deletion aya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
meta_variable_misuse,
missing_abi,
//missing_copy_implementations,
missing_docs,
// missing_docs,
non_ascii_idents,
noop_method_call,
rust_2021_incompatible_closure_captures,
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/cgroup_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ impl CgroupDevice {
)))
}
}

pub fn auto_attach(&self) -> Result<CgroupDeviceLinkId, ProgramError> {
todo!();
}

/// Queries the cgroup for attached programs.
pub fn query<T: AsFd>(target_fd: T) -> Result<Vec<CgroupDeviceLink>, ProgramError> {
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/cgroup_skb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ impl CgroupSkb {
.insert(CgroupSkbLink::new(CgroupSkbLinkInner::ProgAttach(link)))
}
}

pub fn auto_attach(&self) -> Result<CgroupSkbLinkId, ProgramError> {
todo!();
}

/// Creates a program from a pinned entry on a bpffs.
///
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/cgroup_sock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl CgroupSock {
.insert(CgroupSockLink::new(CgroupSockLinkInner::ProgAttach(link)))
}
}

pub fn auto_attach(&self) -> Result<CgroupSockLinkId, ProgramError>{
todo!();
}

/// Creates a program from a pinned entry on a bpffs.
///
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/cgroup_sock_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ impl CgroupSockAddr {
))
}
}

pub fn auto_attach(&self)-> Result<CgroupSockAddrLinkId, ProgramError> {
todo!();
}

/// Creates a program from a pinned entry on a bpffs.
///
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/cgroup_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ impl CgroupSockopt {
)))
}
}

pub fn auto_attach(&self)-> Result<CgroupSockoptLinkId, ProgramError> {
todo!();
}

/// Creates a program from a pinned entry on a bpffs.
///
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/cgroup_sysctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ impl CgroupSysctl {
)))
}
}

pub fn auto_attach(&self) -> Result<CgroupSysctlLinkId, ProgramError>{
todo!();
}
}

#[derive(Debug, Hash, Eq, PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ impl Extension {
.links
.insert(ExtensionLink::new(FdLink::new(link_fd)))
}

pub fn auto_attach(&self) -> Result<ExtensionLinkId, ProgramError>{
todo!();
}

/// Attaches the extension to another program.
///
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/fentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl FEntry {
pub fn attach(&mut self) -> Result<FEntryLinkId, ProgramError> {
attach_raw_tracepoint(&mut self.data, None)
}

pub fn auto_attach(&self) -> Result<FEntryLinkId, ProgramError>{
todo!();
}
}

define_link_wrapper!(
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/fexit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ impl FExit {
pub fn attach(&mut self) -> Result<FExitLinkId, ProgramError> {
attach_raw_tracepoint(&mut self.data, None)
}

pub fn auto_attach(&self)-> Result<FExitLinkId, ProgramError> {
todo!();
}
}

define_link_wrapper!(
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl Iter {
.links
.insert(IterLink::new(PerfLinkInner::FdLink(FdLink::new(link_fd))))
}

pub fn auto_attach(&self) -> Result<IterLinkId, ProgramError>{
todo!();
}
}

/// An iterator descriptor.
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/kprobe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ impl KProbe {
)
}

pub fn auto_attach(&mut self) -> Result<KProbeLinkId, ProgramError> {
todo!();
}

/// Creates a program from a pinned entry on a bpffs.
///
/// Existing links will not be populated. To work with existing links you should use [`crate::programs::links::PinnedLink`].
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/lirc_mode2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl LircMode2 {

self.data.links.insert(LircLink::new(prog_fd, lircdev_fd))
}

pub fn auto_attach(&self) -> Result<LircLinkId, ProgramError> {
todo!();
}

/// Detaches the program.
///
Expand Down
4 changes: 4 additions & 0 deletions aya/src/programs/lsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl Lsm {
pub fn attach(&mut self) -> Result<LsmLinkId, ProgramError> {
attach_raw_tracepoint(&mut self.data, None)
}

pub fn auto_attach(&self)-> Result<LsmLinkId, ProgramError> {
todo!();
}
}

define_link_wrapper!(
Expand Down
Loading