@ -108,7 +108,7 @@ pub use xdp::{Xdp, XdpError, XdpFlags};
use crate ::{
use crate ::{
generated ::{ bpf_attach_type , bpf_link_info , bpf_prog_info , bpf_prog_type } ,
generated ::{ bpf_attach_type , bpf_link_info , bpf_prog_info , bpf_prog_type } ,
maps ::MapError ,
maps ::MapError ,
obj ::{ self , btf ::BtfError , Function, VerifierLog} ,
obj ::{ self , btf ::BtfError , VerifierLog} ,
pin ::PinError ,
pin ::PinError ,
programs ::utils ::{ boot_time , get_fdinfo } ,
programs ::utils ::{ boot_time , get_fdinfo } ,
sys ::{
sys ::{
@ -292,90 +292,90 @@ impl Program {
pub fn prog_type ( & self ) -> bpf_prog_type {
pub fn prog_type ( & self ) -> bpf_prog_type {
use crate ::generated ::bpf_prog_type ::* ;
use crate ::generated ::bpf_prog_type ::* ;
match self {
match self {
Program ::KProbe ( _ ) = > BPF_PROG_TYPE_KPROBE ,
Self ::KProbe ( _ ) = > BPF_PROG_TYPE_KPROBE ,
Program ::UProbe ( _ ) = > BPF_PROG_TYPE_KPROBE ,
Self ::UProbe ( _ ) = > BPF_PROG_TYPE_KPROBE ,
Program ::TracePoint ( _ ) = > BPF_PROG_TYPE_TRACEPOINT ,
Self ::TracePoint ( _ ) = > BPF_PROG_TYPE_TRACEPOINT ,
Program ::SocketFilter ( _ ) = > BPF_PROG_TYPE_SOCKET_FILTER ,
Self ::SocketFilter ( _ ) = > BPF_PROG_TYPE_SOCKET_FILTER ,
Program ::Xdp ( _ ) = > BPF_PROG_TYPE_XDP ,
Self ::Xdp ( _ ) = > BPF_PROG_TYPE_XDP ,
Program ::SkMsg ( _ ) = > BPF_PROG_TYPE_SK_MSG ,
Self ::SkMsg ( _ ) = > BPF_PROG_TYPE_SK_MSG ,
Program ::SkSkb ( _ ) = > BPF_PROG_TYPE_SK_SKB ,
Self ::SkSkb ( _ ) = > BPF_PROG_TYPE_SK_SKB ,
Program ::SockOps ( _ ) = > BPF_PROG_TYPE_SOCK_OPS ,
Self ::SockOps ( _ ) = > BPF_PROG_TYPE_SOCK_OPS ,
Program ::SchedClassifier ( _ ) = > BPF_PROG_TYPE_SCHED_CLS ,
Self ::SchedClassifier ( _ ) = > BPF_PROG_TYPE_SCHED_CLS ,
Program ::CgroupSkb ( _ ) = > BPF_PROG_TYPE_CGROUP_SKB ,
Self ::CgroupSkb ( _ ) = > BPF_PROG_TYPE_CGROUP_SKB ,
Program ::CgroupSysctl ( _ ) = > BPF_PROG_TYPE_CGROUP_SYSCTL ,
Self ::CgroupSysctl ( _ ) = > BPF_PROG_TYPE_CGROUP_SYSCTL ,
Program ::CgroupSockopt ( _ ) = > BPF_PROG_TYPE_CGROUP_SOCKOPT ,
Self ::CgroupSockopt ( _ ) = > BPF_PROG_TYPE_CGROUP_SOCKOPT ,
Program ::LircMode2 ( _ ) = > BPF_PROG_TYPE_LIRC_MODE2 ,
Self ::LircMode2 ( _ ) = > BPF_PROG_TYPE_LIRC_MODE2 ,
Program ::PerfEvent ( _ ) = > BPF_PROG_TYPE_PERF_EVENT ,
Self ::PerfEvent ( _ ) = > BPF_PROG_TYPE_PERF_EVENT ,
Program ::RawTracePoint ( _ ) = > BPF_PROG_TYPE_RAW_TRACEPOINT ,
Self ::RawTracePoint ( _ ) = > BPF_PROG_TYPE_RAW_TRACEPOINT ,
Program ::Lsm ( _ ) = > BPF_PROG_TYPE_LSM ,
Self ::Lsm ( _ ) = > BPF_PROG_TYPE_LSM ,
Program ::BtfTracePoint ( _ ) = > BPF_PROG_TYPE_TRACING ,
Self ::BtfTracePoint ( _ ) = > BPF_PROG_TYPE_TRACING ,
Program ::FEntry ( _ ) = > BPF_PROG_TYPE_TRACING ,
Self ::FEntry ( _ ) = > BPF_PROG_TYPE_TRACING ,
Program ::FExit ( _ ) = > BPF_PROG_TYPE_TRACING ,
Self ::FExit ( _ ) = > BPF_PROG_TYPE_TRACING ,
Program ::Extension ( _ ) = > BPF_PROG_TYPE_EXT ,
Self ::Extension ( _ ) = > BPF_PROG_TYPE_EXT ,
Program ::CgroupSockAddr ( _ ) = > BPF_PROG_TYPE_CGROUP_SOCK_ADDR ,
Self ::CgroupSockAddr ( _ ) = > BPF_PROG_TYPE_CGROUP_SOCK_ADDR ,
Program ::SkLookup ( _ ) = > BPF_PROG_TYPE_SK_LOOKUP ,
Self ::SkLookup ( _ ) = > BPF_PROG_TYPE_SK_LOOKUP ,
Program ::CgroupSock ( _ ) = > BPF_PROG_TYPE_CGROUP_SOCK ,
Self ::CgroupSock ( _ ) = > BPF_PROG_TYPE_CGROUP_SOCK ,
Program ::CgroupDevice ( _ ) = > BPF_PROG_TYPE_CGROUP_DEVICE ,
Self ::CgroupDevice ( _ ) = > BPF_PROG_TYPE_CGROUP_DEVICE ,
}
}
}
}
/// Pin the program to the provided path
/// Pin the program to the provided path
pub fn pin < P : AsRef < Path > > ( & mut self , path : P ) -> Result < ( ) , PinError > {
pub fn pin < P : AsRef < Path > > ( & mut self , path : P ) -> Result < ( ) , PinError > {
match self {
match self {
Program ::KProbe ( p ) = > p . pin ( path ) ,
Self ::KProbe ( p ) = > p . pin ( path ) ,
Program ::UProbe ( p ) = > p . pin ( path ) ,
Self ::UProbe ( p ) = > p . pin ( path ) ,
Program ::TracePoint ( p ) = > p . pin ( path ) ,
Self ::TracePoint ( p ) = > p . pin ( path ) ,
Program ::SocketFilter ( p ) = > p . pin ( path ) ,
Self ::SocketFilter ( p ) = > p . pin ( path ) ,
Program ::Xdp ( p ) = > p . pin ( path ) ,
Self ::Xdp ( p ) = > p . pin ( path ) ,
Program ::SkMsg ( p ) = > p . pin ( path ) ,
Self ::SkMsg ( p ) = > p . pin ( path ) ,
Program ::SkSkb ( p ) = > p . pin ( path ) ,
Self ::SkSkb ( p ) = > p . pin ( path ) ,
Program ::SockOps ( p ) = > p . pin ( path ) ,
Self ::SockOps ( p ) = > p . pin ( path ) ,
Program ::SchedClassifier ( p ) = > p . pin ( path ) ,
Self ::SchedClassifier ( p ) = > p . pin ( path ) ,
Program ::CgroupSkb ( p ) = > p . pin ( path ) ,
Self ::CgroupSkb ( p ) = > p . pin ( path ) ,
Program ::CgroupSysctl ( p ) = > p . pin ( path ) ,
Self ::CgroupSysctl ( p ) = > p . pin ( path ) ,
Program ::CgroupSockopt ( p ) = > p . pin ( path ) ,
Self ::CgroupSockopt ( p ) = > p . pin ( path ) ,
Program ::LircMode2 ( p ) = > p . pin ( path ) ,
Self ::LircMode2 ( p ) = > p . pin ( path ) ,
Program ::PerfEvent ( p ) = > p . pin ( path ) ,
Self ::PerfEvent ( p ) = > p . pin ( path ) ,
Program ::RawTracePoint ( p ) = > p . pin ( path ) ,
Self ::RawTracePoint ( p ) = > p . pin ( path ) ,
Program ::Lsm ( p ) = > p . pin ( path ) ,
Self ::Lsm ( p ) = > p . pin ( path ) ,
Program ::BtfTracePoint ( p ) = > p . pin ( path ) ,
Self ::BtfTracePoint ( p ) = > p . pin ( path ) ,
Program ::FEntry ( p ) = > p . pin ( path ) ,
Self ::FEntry ( p ) = > p . pin ( path ) ,
Program ::FExit ( p ) = > p . pin ( path ) ,
Self ::FExit ( p ) = > p . pin ( path ) ,
Program ::Extension ( p ) = > p . pin ( path ) ,
Self ::Extension ( p ) = > p . pin ( path ) ,
Program ::CgroupSockAddr ( p ) = > p . pin ( path ) ,
Self ::CgroupSockAddr ( p ) = > p . pin ( path ) ,
Program ::SkLookup ( p ) = > p . pin ( path ) ,
Self ::SkLookup ( p ) = > p . pin ( path ) ,
Program ::CgroupSock ( p ) = > p . pin ( path ) ,
Self ::CgroupSock ( p ) = > p . pin ( path ) ,
Program ::CgroupDevice ( p ) = > p . pin ( path ) ,
Self ::CgroupDevice ( p ) = > p . pin ( path ) ,
}
}
}
}
/// Unloads the program from the kernel.
/// Unloads the program from the kernel.
pub fn unload ( self ) -> Result < ( ) , ProgramError > {
pub fn unload ( self ) -> Result < ( ) , ProgramError > {
match self {
match self {
Program ::KProbe ( mut p ) = > p . unload ( ) ,
Self ::KProbe ( mut p ) = > p . unload ( ) ,
Program ::UProbe ( mut p ) = > p . unload ( ) ,
Self ::UProbe ( mut p ) = > p . unload ( ) ,
Program ::TracePoint ( mut p ) = > p . unload ( ) ,
Self ::TracePoint ( mut p ) = > p . unload ( ) ,
Program ::SocketFilter ( mut p ) = > p . unload ( ) ,
Self ::SocketFilter ( mut p ) = > p . unload ( ) ,
Program ::Xdp ( mut p ) = > p . unload ( ) ,
Self ::Xdp ( mut p ) = > p . unload ( ) ,
Program ::SkMsg ( mut p ) = > p . unload ( ) ,
Self ::SkMsg ( mut p ) = > p . unload ( ) ,
Program ::SkSkb ( mut p ) = > p . unload ( ) ,
Self ::SkSkb ( mut p ) = > p . unload ( ) ,
Program ::SockOps ( mut p ) = > p . unload ( ) ,
Self ::SockOps ( mut p ) = > p . unload ( ) ,
Program ::SchedClassifier ( mut p ) = > p . unload ( ) ,
Self ::SchedClassifier ( mut p ) = > p . unload ( ) ,
Program ::CgroupSkb ( mut p ) = > p . unload ( ) ,
Self ::CgroupSkb ( mut p ) = > p . unload ( ) ,
Program ::CgroupSysctl ( mut p ) = > p . unload ( ) ,
Self ::CgroupSysctl ( mut p ) = > p . unload ( ) ,
Program ::CgroupSockopt ( mut p ) = > p . unload ( ) ,
Self ::CgroupSockopt ( mut p ) = > p . unload ( ) ,
Program ::LircMode2 ( mut p ) = > p . unload ( ) ,
Self ::LircMode2 ( mut p ) = > p . unload ( ) ,
Program ::PerfEvent ( mut p ) = > p . unload ( ) ,
Self ::PerfEvent ( mut p ) = > p . unload ( ) ,
Program ::RawTracePoint ( mut p ) = > p . unload ( ) ,
Self ::RawTracePoint ( mut p ) = > p . unload ( ) ,
Program ::Lsm ( mut p ) = > p . unload ( ) ,
Self ::Lsm ( mut p ) = > p . unload ( ) ,
Program ::BtfTracePoint ( mut p ) = > p . unload ( ) ,
Self ::BtfTracePoint ( mut p ) = > p . unload ( ) ,
Program ::FEntry ( mut p ) = > p . unload ( ) ,
Self ::FEntry ( mut p ) = > p . unload ( ) ,
Program ::FExit ( mut p ) = > p . unload ( ) ,
Self ::FExit ( mut p ) = > p . unload ( ) ,
Program ::Extension ( mut p ) = > p . unload ( ) ,
Self ::Extension ( mut p ) = > p . unload ( ) ,
Program ::CgroupSockAddr ( mut p ) = > p . unload ( ) ,
Self ::CgroupSockAddr ( mut p ) = > p . unload ( ) ,
Program ::SkLookup ( mut p ) = > p . unload ( ) ,
Self ::SkLookup ( mut p ) = > p . unload ( ) ,
Program ::CgroupSock ( mut p ) = > p . unload ( ) ,
Self ::CgroupSock ( mut p ) = > p . unload ( ) ,
Program ::CgroupDevice ( mut p ) = > p . unload ( ) ,
Self ::CgroupDevice ( mut p ) = > p . unload ( ) ,
}
}
}
}
@ -384,30 +384,30 @@ impl Program {
/// Can be used to add a program to a [`crate::maps::ProgramArray`] or attach an [`Extension`] program.
/// Can be used to add a program to a [`crate::maps::ProgramArray`] or attach an [`Extension`] program.
pub fn fd ( & self ) -> Result < & ProgramFd , ProgramError > {
pub fn fd ( & self ) -> Result < & ProgramFd , ProgramError > {
match self {
match self {
Program ::KProbe ( p ) = > p . fd ( ) ,
Self ::KProbe ( p ) = > p . fd ( ) ,
Program ::UProbe ( p ) = > p . fd ( ) ,
Self ::UProbe ( p ) = > p . fd ( ) ,
Program ::TracePoint ( p ) = > p . fd ( ) ,
Self ::TracePoint ( p ) = > p . fd ( ) ,
Program ::SocketFilter ( p ) = > p . fd ( ) ,
Self ::SocketFilter ( p ) = > p . fd ( ) ,
Program ::Xdp ( p ) = > p . fd ( ) ,
Self ::Xdp ( p ) = > p . fd ( ) ,
Program ::SkMsg ( p ) = > p . fd ( ) ,
Self ::SkMsg ( p ) = > p . fd ( ) ,
Program ::SkSkb ( p ) = > p . fd ( ) ,
Self ::SkSkb ( p ) = > p . fd ( ) ,
Program ::SockOps ( p ) = > p . fd ( ) ,
Self ::SockOps ( p ) = > p . fd ( ) ,
Program ::SchedClassifier ( p ) = > p . fd ( ) ,
Self ::SchedClassifier ( p ) = > p . fd ( ) ,
Program ::CgroupSkb ( p ) = > p . fd ( ) ,
Self ::CgroupSkb ( p ) = > p . fd ( ) ,
Program ::CgroupSysctl ( p ) = > p . fd ( ) ,
Self ::CgroupSysctl ( p ) = > p . fd ( ) ,
Program ::CgroupSockopt ( p ) = > p . fd ( ) ,
Self ::CgroupSockopt ( p ) = > p . fd ( ) ,
Program ::LircMode2 ( p ) = > p . fd ( ) ,
Self ::LircMode2 ( p ) = > p . fd ( ) ,
Program ::PerfEvent ( p ) = > p . fd ( ) ,
Self ::PerfEvent ( p ) = > p . fd ( ) ,
Program ::RawTracePoint ( p ) = > p . fd ( ) ,
Self ::RawTracePoint ( p ) = > p . fd ( ) ,
Program ::Lsm ( p ) = > p . fd ( ) ,
Self ::Lsm ( p ) = > p . fd ( ) ,
Program ::BtfTracePoint ( p ) = > p . fd ( ) ,
Self ::BtfTracePoint ( p ) = > p . fd ( ) ,
Program ::FEntry ( p ) = > p . fd ( ) ,
Self ::FEntry ( p ) = > p . fd ( ) ,
Program ::FExit ( p ) = > p . fd ( ) ,
Self ::FExit ( p ) = > p . fd ( ) ,
Program ::Extension ( p ) = > p . fd ( ) ,
Self ::Extension ( p ) = > p . fd ( ) ,
Program ::CgroupSockAddr ( p ) = > p . fd ( ) ,
Self ::CgroupSockAddr ( p ) = > p . fd ( ) ,
Program ::SkLookup ( p ) = > p . fd ( ) ,
Self ::SkLookup ( p ) = > p . fd ( ) ,
Program ::CgroupSock ( p ) = > p . fd ( ) ,
Self ::CgroupSock ( p ) = > p . fd ( ) ,
Program ::CgroupDevice ( p ) = > p . fd ( ) ,
Self ::CgroupDevice ( p ) = > p . fd ( ) ,
}
}
}
}
}
}
@ -434,8 +434,8 @@ impl<T: Link> ProgramData<T> {
obj : ( obj ::Program , obj ::Function ) ,
obj : ( obj ::Program , obj ::Function ) ,
btf_fd : Option < Arc < OwnedFd > > ,
btf_fd : Option < Arc < OwnedFd > > ,
verifier_log_level : VerifierLogLevel ,
verifier_log_level : VerifierLogLevel ,
) -> ProgramData< T > {
) -> Self {
ProgramData {
Self {
name ,
name ,
obj : Some ( obj ) ,
obj : Some ( obj ) ,
fd : None ,
fd : None ,
@ -457,7 +457,7 @@ impl<T: Link> ProgramData<T> {
path : & Path ,
path : & Path ,
info : bpf_prog_info ,
info : bpf_prog_info ,
verifier_log_level : VerifierLogLevel ,
verifier_log_level : VerifierLogLevel ,
) -> Result < ProgramData < T > , ProgramError > {
) -> Result < Self , ProgramError > {
let attach_btf_id = if info . attach_btf_id > 0 {
let attach_btf_id = if info . attach_btf_id > 0 {
Some ( info . attach_btf_id )
Some ( info . attach_btf_id )
} else {
} else {
@ -467,7 +467,7 @@ impl<T: Link> ProgramData<T> {
. then ( | | bpf_btf_get_fd_by_id ( info . attach_btf_obj_id ) )
. then ( | | bpf_btf_get_fd_by_id ( info . attach_btf_obj_id ) )
. transpose ( ) ? ;
. transpose ( ) ? ;
Ok ( ProgramData {
Ok ( Self {
name ,
name ,
obj : None ,
obj : None ,
fd : Some ( ProgramFd ( fd ) ) ,
fd : Some ( ProgramFd ( fd ) ) ,
@ -486,7 +486,7 @@ impl<T: Link> ProgramData<T> {
pub ( crate ) fn from_pinned_path < P : AsRef < Path > > (
pub ( crate ) fn from_pinned_path < P : AsRef < Path > > (
path : P ,
path : P ,
verifier_log_level : VerifierLogLevel ,
verifier_log_level : VerifierLogLevel ,
) -> Result < ProgramData < T > , ProgramError > {
) -> Result < Self , ProgramError > {
let path_string =
let path_string =
CString ::new ( path . as_ref ( ) . as_os_str ( ) . to_string_lossy ( ) . as_bytes ( ) ) . unwrap ( ) ;
CString ::new ( path . as_ref ( ) . as_os_str ( ) . to_string_lossy ( ) . as_bytes ( ) ) . unwrap ( ) ;
@ -497,7 +497,7 @@ impl<T: Link> ProgramData<T> {
let info = ProgramInfo ::new_from_fd ( fd . as_fd ( ) ) ? ;
let info = ProgramInfo ::new_from_fd ( fd . as_fd ( ) ) ? ;
let name = info . name_as_str ( ) . map ( | s | s . to_string ( ) ) ;
let name = info . name_as_str ( ) . map ( | s | s . to_string ( ) ) ;
ProgramData ::from_bpf_prog_info ( name , fd , path . as_ref ( ) , info . 0 , verifier_log_level )
Self ::from_bpf_prog_info ( name , fd , path . as_ref ( ) , info . 0 , verifier_log_level )
}
}
}
}
@ -571,7 +571,7 @@ fn load_program<T: Link>(
kernel_version ,
kernel_version ,
..
..
} ,
} ,
Function {
obj:: Function {
instructions ,
instructions ,
func_info ,
func_info ,
line_info ,
line_info ,
@ -1072,7 +1072,7 @@ impl ProgramInfo {
}
}
/// Loads a program from a pinned path in bpffs.
/// Loads a program from a pinned path in bpffs.
pub fn from_pin < P : AsRef < Path > > ( path : P ) -> Result < ProgramInfo , ProgramError > {
pub fn from_pin < P : AsRef < Path > > ( path : P ) -> Result < Self , ProgramError > {
let path_string = CString ::new ( path . as_ref ( ) . to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
let path_string = CString ::new ( path . as_ref ( ) . to_str ( ) . unwrap ( ) ) . unwrap ( ) ;
let fd = bpf_get_object ( & path_string ) . map_err ( | ( _ , io_error ) | SyscallError {
let fd = bpf_get_object ( & path_string ) . map_err ( | ( _ , io_error ) | SyscallError {
call : "BPF_OBJ_GET" ,
call : "BPF_OBJ_GET" ,
@ -1080,7 +1080,7 @@ impl ProgramInfo {
} ) ? ;
} ) ? ;
let info = bpf_prog_get_info_by_fd ( fd . as_fd ( ) , & mut [ ] ) ? ;
let info = bpf_prog_get_info_by_fd ( fd . as_fd ( ) , & mut [ ] ) ? ;
Ok ( ProgramInfo ( info ) )
Ok ( Self ( info ) )
}
}
}
}