1use super::syscalls::bpf;
2use crate::error::Error;
3
4use std::mem::size_of;
5
6#[allow(dead_code)]
7#[derive(Copy, Clone)]
8pub enum AttachType {
9 CgroupInetIngress,
10 CgroupInetEgress,
11 CgroupInetSockCreate,
12 CgroupSockOps,
13 SkSkbStreamParser,
14 SkSkbStreamVerdict,
15 CgroupDevice,
16 SkMsgVerdict,
17 CgroupInet4Bind,
18 CgroupInet6Bind,
19 CgroupInet4Connect,
20 CgroupInet6Connect,
21 CgroupInet4PostBind,
22 CgroupInet6PostBind,
23 CgroupUdp4Sendmsg,
24 CgroupUdp6Sendmsg,
25 LircMode2,
26 FlowDissector,
27 CgroupSysctl,
28 CgroupUdp4Recvmsg,
29 CgroupUdp6Recvmsg,
30 CgroupGetsockopt,
31 CgroupSetsockopt,
32 TraceRawTp,
33 TraceFentry,
34 TraceFexit,
35 ModifyReturn,
36 LsmMac,
37 TraceIter,
38 CgroupInet4Getpeername,
39 CgroupInet6Getpeername,
40 CgroupInet4Getsockname,
41 CgroupInet6Getsockname,
42 XdpDevmap,
43 CgroupInetSockRelease,
44 XdpCpumap,
45 SkLookup,
46 Xdp,
47 SkSkbVerdict,
48 SkReuseportSelect,
49 SkReuseportSelectOrMigrate,
50 PerfEvent,
51 TraceKprobeMulti,
52}
53
54#[allow(dead_code)]
55#[derive(Copy, Clone, Debug)]
56pub enum Command {
57 MapCreate = 0,
58 MapLookupElem,
59 MapUpdateElem,
60 MapDeleteElem,
61 MapGetNextKey,
62 ProgLoad,
63 ObjPin,
64 ObjGet,
65 ProgAttach,
66 ProgDetach,
67 ProgTestRun,
68 ProgGetNextId,
69 MapGetNextId,
70 ProgGetFdById,
71 MapGetFdById,
72 ObjGetInfoByFd,
73 ProgQuery,
74 RawTracepointOpen,
75 BtfLoad,
76 BtfGetFdById,
77 TaskFdQuery,
78 MapLookupAndDeleteElem,
79 MapFreeze,
80 GetNextId,
81 MapLookupBatch,
82 MapLookupAndDeleteBatch,
83 MapUpdateBatch,
84 MapDeleteBatch,
85 LinkCreate,
86 LinkUpdate,
87 LinkGetFdById,
88 LinkGetNextId,
89 EnableStats,
90 IterCreate,
91 LinkDetach,
92 ProgBindMap,
93}
94
95pub trait CallBpf {
96 fn call_bpf(&self, cmd: Command) -> Result<u32, Error>
97 where
98 Self: Sized,
99 {
100 let r = bpf(
101 cmd as u32,
102 self as *const Self as *const u8,
103 size_of::<Self>(),
104 );
105 if r < 0 {
106 Err(Error::SystemError(r))
107 } else {
108 Ok(r as u32)
109 }
110 }
111}