|
|
@ -194,6 +194,7 @@ pub struct BpfLoader<'a> {
|
|
|
|
globals: HashMap<&'a str, &'a [u8]>,
|
|
|
|
globals: HashMap<&'a str, &'a [u8]>,
|
|
|
|
features: Features,
|
|
|
|
features: Features,
|
|
|
|
extensions: HashSet<&'a str>,
|
|
|
|
extensions: HashSet<&'a str>,
|
|
|
|
|
|
|
|
verifier_log_level: u32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> BpfLoader<'a> {
|
|
|
|
impl<'a> BpfLoader<'a> {
|
|
|
@ -207,6 +208,7 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
globals: HashMap::new(),
|
|
|
|
globals: HashMap::new(),
|
|
|
|
features,
|
|
|
|
features,
|
|
|
|
extensions: HashSet::new(),
|
|
|
|
extensions: HashSet::new(),
|
|
|
|
|
|
|
|
verifier_log_level: 7,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -314,6 +316,24 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
self
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Sets BPF verifier log level.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Example
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```no_run
|
|
|
|
|
|
|
|
/// use aya::BpfLoader;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// let bpf = BpfLoader::new()
|
|
|
|
|
|
|
|
/// .verifier_log_level(3)
|
|
|
|
|
|
|
|
/// .load_file("file.o")?;
|
|
|
|
|
|
|
|
/// # Ok::<(), aya::BpfError>(())
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
pub fn verifier_log_level(&mut self, level: u32) -> &mut BpfLoader<'a> {
|
|
|
|
|
|
|
|
self.verifier_log_level = level;
|
|
|
|
|
|
|
|
self
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Loads eBPF bytecode from a file.
|
|
|
|
/// Loads eBPF bytecode from a file.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
/// # Examples
|
|
|
@ -345,6 +365,7 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
/// # Ok::<(), aya::BpfError>(())
|
|
|
|
/// # Ok::<(), aya::BpfError>(())
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
pub fn load(&mut self, data: &[u8]) -> Result<Bpf, BpfError> {
|
|
|
|
pub fn load(&mut self, data: &[u8]) -> Result<Bpf, BpfError> {
|
|
|
|
|
|
|
|
let verifier_log_level = self.verifier_log_level;
|
|
|
|
let mut obj = Object::parse(data)?;
|
|
|
|
let mut obj = Object::parse(data)?;
|
|
|
|
obj.patch_map_data(self.globals.clone())?;
|
|
|
|
obj.patch_map_data(self.globals.clone())?;
|
|
|
|
|
|
|
|
|
|
|
@ -444,65 +465,65 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
|
|
|
|
|
|
|
|
let program = if self.extensions.contains(name.as_str()) {
|
|
|
|
let program = if self.extensions.contains(name.as_str()) {
|
|
|
|
Program::Extension(Extension {
|
|
|
|
Program::Extension(Extension {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
match §ion {
|
|
|
|
match §ion {
|
|
|
|
ProgramSection::KProbe { .. } => Program::KProbe(KProbe {
|
|
|
|
ProgramSection::KProbe { .. } => Program::KProbe(KProbe {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
kind: ProbeKind::KProbe,
|
|
|
|
kind: ProbeKind::KProbe,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::KRetProbe { .. } => Program::KProbe(KProbe {
|
|
|
|
ProgramSection::KRetProbe { .. } => Program::KProbe(KProbe {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
kind: ProbeKind::KRetProbe,
|
|
|
|
kind: ProbeKind::KRetProbe,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::UProbe { .. } => Program::UProbe(UProbe {
|
|
|
|
ProgramSection::UProbe { .. } => Program::UProbe(UProbe {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
kind: ProbeKind::UProbe,
|
|
|
|
kind: ProbeKind::UProbe,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::URetProbe { .. } => Program::UProbe(UProbe {
|
|
|
|
ProgramSection::URetProbe { .. } => Program::UProbe(UProbe {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
kind: ProbeKind::URetProbe,
|
|
|
|
kind: ProbeKind::URetProbe,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::TracePoint { .. } => Program::TracePoint(TracePoint {
|
|
|
|
ProgramSection::TracePoint { .. } => Program::TracePoint(TracePoint {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::SocketFilter { .. } => {
|
|
|
|
ProgramSection::SocketFilter { .. } => {
|
|
|
|
Program::SocketFilter(SocketFilter {
|
|
|
|
Program::SocketFilter(SocketFilter {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::Xdp { .. } => Program::Xdp(Xdp {
|
|
|
|
ProgramSection::Xdp { .. } => Program::Xdp(Xdp {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::SkMsg { .. } => Program::SkMsg(SkMsg {
|
|
|
|
ProgramSection::SkMsg { .. } => Program::SkMsg(SkMsg {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::CgroupSysctl { .. } => {
|
|
|
|
ProgramSection::CgroupSysctl { .. } => {
|
|
|
|
Program::CgroupSysctl(CgroupSysctl {
|
|
|
|
Program::CgroupSysctl(CgroupSysctl {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::CgroupSockopt { attach_type, .. } => {
|
|
|
|
ProgramSection::CgroupSockopt { attach_type, .. } => {
|
|
|
|
Program::CgroupSockopt(CgroupSockopt {
|
|
|
|
Program::CgroupSockopt(CgroupSockopt {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
attach_type: *attach_type,
|
|
|
|
attach_type: *attach_type,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::SkSkbStreamParser { .. } => Program::SkSkb(SkSkb {
|
|
|
|
ProgramSection::SkSkbStreamParser { .. } => Program::SkSkb(SkSkb {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
kind: SkSkbKind::StreamParser,
|
|
|
|
kind: SkSkbKind::StreamParser,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::SkSkbStreamVerdict { .. } => Program::SkSkb(SkSkb {
|
|
|
|
ProgramSection::SkSkbStreamVerdict { .. } => Program::SkSkb(SkSkb {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
kind: SkSkbKind::StreamVerdict,
|
|
|
|
kind: SkSkbKind::StreamVerdict,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::SockOps { .. } => Program::SockOps(SockOps {
|
|
|
|
ProgramSection::SockOps { .. } => Program::SockOps(SockOps {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::SchedClassifier { .. } => {
|
|
|
|
ProgramSection::SchedClassifier { .. } => {
|
|
|
|
Program::SchedClassifier(SchedClassifier {
|
|
|
|
Program::SchedClassifier(SchedClassifier {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
name: unsafe {
|
|
|
|
name: unsafe {
|
|
|
|
CString::from_vec_unchecked(Vec::from(name.clone()))
|
|
|
|
CString::from_vec_unchecked(Vec::from(name.clone()))
|
|
|
|
.into_boxed_c_str()
|
|
|
|
.into_boxed_c_str()
|
|
|
@ -510,57 +531,57 @@ impl<'a> BpfLoader<'a> {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::CgroupSkb { .. } => Program::CgroupSkb(CgroupSkb {
|
|
|
|
ProgramSection::CgroupSkb { .. } => Program::CgroupSkb(CgroupSkb {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
expected_attach_type: None,
|
|
|
|
expected_attach_type: None,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::CgroupSkbIngress { .. } => Program::CgroupSkb(CgroupSkb {
|
|
|
|
ProgramSection::CgroupSkbIngress { .. } => Program::CgroupSkb(CgroupSkb {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
expected_attach_type: Some(CgroupSkbAttachType::Ingress),
|
|
|
|
expected_attach_type: Some(CgroupSkbAttachType::Ingress),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::CgroupSkbEgress { .. } => Program::CgroupSkb(CgroupSkb {
|
|
|
|
ProgramSection::CgroupSkbEgress { .. } => Program::CgroupSkb(CgroupSkb {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
expected_attach_type: Some(CgroupSkbAttachType::Egress),
|
|
|
|
expected_attach_type: Some(CgroupSkbAttachType::Egress),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::CgroupSockAddr { attach_type, .. } => {
|
|
|
|
ProgramSection::CgroupSockAddr { attach_type, .. } => {
|
|
|
|
Program::CgroupSockAddr(CgroupSockAddr {
|
|
|
|
Program::CgroupSockAddr(CgroupSockAddr {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
attach_type: *attach_type,
|
|
|
|
attach_type: *attach_type,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::LircMode2 { .. } => Program::LircMode2(LircMode2 {
|
|
|
|
ProgramSection::LircMode2 { .. } => Program::LircMode2(LircMode2 {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::PerfEvent { .. } => Program::PerfEvent(PerfEvent {
|
|
|
|
ProgramSection::PerfEvent { .. } => Program::PerfEvent(PerfEvent {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::RawTracePoint { .. } => {
|
|
|
|
ProgramSection::RawTracePoint { .. } => {
|
|
|
|
Program::RawTracePoint(RawTracePoint {
|
|
|
|
Program::RawTracePoint(RawTracePoint {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::Lsm { .. } => Program::Lsm(Lsm {
|
|
|
|
ProgramSection::Lsm { .. } => Program::Lsm(Lsm {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::BtfTracePoint { .. } => {
|
|
|
|
ProgramSection::BtfTracePoint { .. } => {
|
|
|
|
Program::BtfTracePoint(BtfTracePoint {
|
|
|
|
Program::BtfTracePoint(BtfTracePoint {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ProgramSection::FEntry { .. } => Program::FEntry(FEntry {
|
|
|
|
ProgramSection::FEntry { .. } => Program::FEntry(FEntry {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::FExit { .. } => Program::FExit(FExit {
|
|
|
|
ProgramSection::FExit { .. } => Program::FExit(FExit {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::Extension { .. } => Program::Extension(Extension {
|
|
|
|
ProgramSection::Extension { .. } => Program::Extension(Extension {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::SkLookup { .. } => Program::SkLookup(SkLookup {
|
|
|
|
ProgramSection::SkLookup { .. } => Program::SkLookup(SkLookup {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
ProgramSection::CgroupSock { attach_type, .. } => {
|
|
|
|
ProgramSection::CgroupSock { attach_type, .. } => {
|
|
|
|
Program::CgroupSock(CgroupSock {
|
|
|
|
Program::CgroupSock(CgroupSock {
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd),
|
|
|
|
data: ProgramData::new(prog_name, obj, btf_fd, verifier_log_level),
|
|
|
|
attach_type: *attach_type,
|
|
|
|
attach_type: *attach_type,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|