aya-obj: conversion from u32 & impl display for link type

Adds conversion from u32 to link type enum. Also implements display for
condensed metadata output.

So far, this is still WIP since this commit/PR also plans to add better
access to `bpf_link_info__bindgen_ty_1` metadata.
pull/979/head
tyrone-wu 10 months ago
parent 1e972cb7a5
commit a35a513802
No known key found for this signature in database
GPG Key ID: 978B1A1B79210AD6

@ -87,6 +87,7 @@ mod std {
pub mod btf;
pub mod generated;
pub mod links;
pub mod maps;
pub mod obj;
pub mod programs;

@ -0,0 +1,53 @@
//! Link struct and type bindings.
use core::fmt::Display;
use crate::generated::bpf_link_type::{self, *};
impl From<u32> for bpf_link_type {
fn from(link_type: u32) -> Self {
match link_type {
x if x == BPF_LINK_TYPE_UNSPEC as u32 => BPF_LINK_TYPE_UNSPEC,
x if x == BPF_LINK_TYPE_RAW_TRACEPOINT as u32 => BPF_LINK_TYPE_RAW_TRACEPOINT,
x if x == BPF_LINK_TYPE_TRACING as u32 => BPF_LINK_TYPE_TRACING,
x if x == BPF_LINK_TYPE_CGROUP as u32 => BPF_LINK_TYPE_CGROUP,
x if x == BPF_LINK_TYPE_ITER as u32 => BPF_LINK_TYPE_ITER,
x if x == BPF_LINK_TYPE_NETNS as u32 => BPF_LINK_TYPE_NETNS,
x if x == BPF_LINK_TYPE_XDP as u32 => BPF_LINK_TYPE_XDP,
x if x == BPF_LINK_TYPE_PERF_EVENT as u32 => BPF_LINK_TYPE_PERF_EVENT,
x if x == BPF_LINK_TYPE_KPROBE_MULTI as u32 => BPF_LINK_TYPE_KPROBE_MULTI,
x if x == BPF_LINK_TYPE_STRUCT_OPS as u32 => BPF_LINK_TYPE_STRUCT_OPS,
x if x == BPF_LINK_TYPE_NETFILTER as u32 => BPF_LINK_TYPE_NETFILTER,
x if x == BPF_LINK_TYPE_TCX as u32 => BPF_LINK_TYPE_TCX,
x if x == BPF_LINK_TYPE_UPROBE_MULTI as u32 => BPF_LINK_TYPE_UPROBE_MULTI,
x if x == BPF_LINK_TYPE_NETKIT as u32 => BPF_LINK_TYPE_NETKIT,
_ => __MAX_BPF_LINK_TYPE,
}
}
}
impl Display for bpf_link_type {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"{}",
match self {
BPF_LINK_TYPE_UNSPEC => "Unspec",
BPF_LINK_TYPE_RAW_TRACEPOINT => "RawTracePoint",
BPF_LINK_TYPE_TRACING => "Tracing",
BPF_LINK_TYPE_CGROUP => "Cgroup",
BPF_LINK_TYPE_ITER => "Iter",
BPF_LINK_TYPE_NETNS => "NetNs",
BPF_LINK_TYPE_XDP => "Xdp",
BPF_LINK_TYPE_PERF_EVENT => "PerfEvent",
BPF_LINK_TYPE_KPROBE_MULTI => "KProbeMulti",
BPF_LINK_TYPE_STRUCT_OPS => "StructOps",
BPF_LINK_TYPE_NETFILTER => "Netfilter",
BPF_LINK_TYPE_TCX => "Tcx",
BPF_LINK_TYPE_UPROBE_MULTI => "UProbeMulti",
BPF_LINK_TYPE_NETKIT => "NetKit",
__MAX_BPF_LINK_TYPE => "MaxLinkType",
}
)
}
}

@ -1523,8 +1523,12 @@ pub fn aya_obj::generated::bpf_link_type::clone(&self) -> aya_obj::generated::bp
impl core::cmp::Eq for aya_obj::generated::bpf_link_type
impl core::cmp::PartialEq for aya_obj::generated::bpf_link_type
pub fn aya_obj::generated::bpf_link_type::eq(&self, other: &aya_obj::generated::bpf_link_type) -> bool
impl core::convert::From<u32> for aya_obj::generated::bpf_link_type
pub fn aya_obj::generated::bpf_link_type::from(link_type: u32) -> Self
impl core::fmt::Debug for aya_obj::generated::bpf_link_type
pub fn aya_obj::generated::bpf_link_type::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::fmt::Display for aya_obj::generated::bpf_link_type
pub fn aya_obj::generated::bpf_link_type::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::hash::Hash for aya_obj::generated::bpf_link_type
pub fn aya_obj::generated::bpf_link_type::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
impl core::marker::Copy for aya_obj::generated::bpf_link_type
@ -1547,6 +1551,8 @@ impl<T> alloc::borrow::ToOwned for aya_obj::generated::bpf_link_type where T: co
pub type aya_obj::generated::bpf_link_type::Owned = T
pub fn aya_obj::generated::bpf_link_type::clone_into(&self, target: &mut T)
pub fn aya_obj::generated::bpf_link_type::to_owned(&self) -> T
impl<T> alloc::string::ToString for aya_obj::generated::bpf_link_type where T: core::fmt::Display + core::marker::Sized
pub fn aya_obj::generated::bpf_link_type::to_string(&self) -> alloc::string::String
impl<T> core::any::Any for aya_obj::generated::bpf_link_type where T: 'static + core::marker::Sized
pub fn aya_obj::generated::bpf_link_type::type_id(&self) -> core::any::TypeId
impl<T> core::borrow::Borrow<T> for aya_obj::generated::bpf_link_type where T: core::marker::Sized
@ -1605,6 +1611,8 @@ pub type aya_obj::generated::bpf_map_type::Error = aya_obj::maps::InvalidMapType
pub fn aya_obj::generated::bpf_map_type::try_from(map_type: u32) -> core::result::Result<Self, Self::Error>
impl core::fmt::Debug for aya_obj::generated::bpf_map_type
pub fn aya_obj::generated::bpf_map_type::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::fmt::Display for aya_obj::generated::bpf_map_type
pub fn aya_obj::generated::bpf_map_type::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl core::hash::Hash for aya_obj::generated::bpf_map_type
pub fn aya_obj::generated::bpf_map_type::hash<__H: core::hash::Hasher>(&self, state: &mut __H)
impl core::marker::Copy for aya_obj::generated::bpf_map_type
@ -1627,6 +1635,8 @@ impl<T> alloc::borrow::ToOwned for aya_obj::generated::bpf_map_type where T: cor
pub type aya_obj::generated::bpf_map_type::Owned = T
pub fn aya_obj::generated::bpf_map_type::clone_into(&self, target: &mut T)
pub fn aya_obj::generated::bpf_map_type::to_owned(&self) -> T
impl<T> alloc::string::ToString for aya_obj::generated::bpf_map_type where T: core::fmt::Display + core::marker::Sized
pub fn aya_obj::generated::bpf_map_type::to_string(&self) -> alloc::string::String
impl<T> core::any::Any for aya_obj::generated::bpf_map_type where T: 'static + core::marker::Sized
pub fn aya_obj::generated::bpf_map_type::type_id(&self) -> core::any::TypeId
impl<T> core::borrow::Borrow<T> for aya_obj::generated::bpf_map_type where T: core::marker::Sized
@ -6270,6 +6280,7 @@ pub type aya_obj::generated::_bindgen_ty_7 = core::ffi::c_uint
pub type aya_obj::generated::_bindgen_ty_8 = core::ffi::c_uint
pub type aya_obj::generated::_bindgen_ty_9 = core::ffi::c_uint
pub type aya_obj::generated::_bindgen_ty_92 = core::ffi::c_uint
pub mod aya_obj::links
pub mod aya_obj::maps
pub enum aya_obj::maps::Map
pub aya_obj::maps::Map::Btf(aya_obj::maps::BtfMap)

Loading…
Cancel
Save