-
Notifications
You must be signed in to change notification settings - Fork 26
/
bpf_bpfel.go
279 lines (254 loc) · 8.01 KB
/
bpf_bpfel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Code generated by bpf2go; DO NOT EDIT.
//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mips64le || mips64p32le || mipsle || ppc64le || riscv64
package l7_req
import (
"bytes"
_ "embed"
"fmt"
"io"
"github.com/cilium/ebpf"
)
type bpfCallEvent struct {
Pid uint32
Tid uint32
Tx uint64
Type uint8
_ [3]byte
Seq uint32
}
type bpfGoReadKey struct {
Pid uint32
_ [4]byte
Goid uint64
}
type bpfGoReqKey struct {
Pid uint32
_ [4]byte
Fd uint64
}
type bpfL7Event struct {
Fd uint64
WriteTimeNs uint64
Pid uint32
Status uint32
Duration uint64
Protocol uint8
Method uint8
Padding uint16
Payload [1024]uint8
PayloadSize uint32
PayloadReadComplete uint8
Failed uint8
IsTls uint8
_ [1]byte
Seq uint32
Tid uint32
_ [4]byte
}
type bpfL7Request struct {
WriteTimeNs uint64
Protocol uint8
Method uint8
Payload [1024]uint8
_ [2]byte
PayloadSize uint32
PayloadReadComplete uint8
RequestType uint8
_ [2]byte
Seq uint32
Tid uint32
_ [4]byte
}
type bpfLogMessage struct {
Level uint32
LogMsg [100]uint8
FuncName [100]uint8
Pid uint32
Arg1 uint64
Arg2 uint64
Arg3 uint64
}
type bpfSocketKey struct {
Fd uint64
Pid uint32
IsTls uint8
_ [3]byte
}
// loadBpf returns the embedded CollectionSpec for bpf.
func loadBpf() (*ebpf.CollectionSpec, error) {
reader := bytes.NewReader(_BpfBytes)
spec, err := ebpf.LoadCollectionSpecFromReader(reader)
if err != nil {
return nil, fmt.Errorf("can't load bpf: %w", err)
}
return spec, err
}
// loadBpfObjects loads bpf and converts it into a struct.
//
// The following types are suitable as obj argument:
//
// *bpfObjects
// *bpfPrograms
// *bpfMaps
//
// See ebpf.CollectionSpec.LoadAndAssign documentation for details.
func loadBpfObjects(obj interface{}, opts *ebpf.CollectionOptions) error {
spec, err := loadBpf()
if err != nil {
return err
}
return spec.LoadAndAssign(obj, opts)
}
// bpfSpecs contains maps and programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfSpecs struct {
bpfProgramSpecs
bpfMapSpecs
}
// bpfSpecs contains programs before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfProgramSpecs struct {
GoTlsConnReadEnter *ebpf.ProgramSpec `ebpf:"go_tls_conn_read_enter"`
GoTlsConnReadExit *ebpf.ProgramSpec `ebpf:"go_tls_conn_read_exit"`
GoTlsConnWriteEnter *ebpf.ProgramSpec `ebpf:"go_tls_conn_write_enter"`
SslReadEnterV102 *ebpf.ProgramSpec `ebpf:"ssl_read_enter_v1_0_2"`
SslReadEnterV111 *ebpf.ProgramSpec `ebpf:"ssl_read_enter_v1_1_1"`
SslReadEnterV3 *ebpf.ProgramSpec `ebpf:"ssl_read_enter_v3"`
SslRetRead *ebpf.ProgramSpec `ebpf:"ssl_ret_read"`
SslWriteV102 *ebpf.ProgramSpec `ebpf:"ssl_write_v1_0_2"`
SslWriteV111 *ebpf.ProgramSpec `ebpf:"ssl_write_v1_1_1"`
SslWriteV3 *ebpf.ProgramSpec `ebpf:"ssl_write_v3"`
SysEnterRead *ebpf.ProgramSpec `ebpf:"sys_enter_read"`
SysEnterRecvfrom *ebpf.ProgramSpec `ebpf:"sys_enter_recvfrom"`
SysEnterSendto *ebpf.ProgramSpec `ebpf:"sys_enter_sendto"`
SysEnterWrite *ebpf.ProgramSpec `ebpf:"sys_enter_write"`
SysExitRead *ebpf.ProgramSpec `ebpf:"sys_exit_read"`
SysExitRecvfrom *ebpf.ProgramSpec `ebpf:"sys_exit_recvfrom"`
SysExitSendto *ebpf.ProgramSpec `ebpf:"sys_exit_sendto"`
SysExitWrite *ebpf.ProgramSpec `ebpf:"sys_exit_write"`
}
// bpfMapSpecs contains maps before they are loaded into the kernel.
//
// It can be passed ebpf.CollectionSpec.Assign.
type bpfMapSpecs struct {
ActiveL7Requests *ebpf.MapSpec `ebpf:"active_l7_requests"`
ActiveReads *ebpf.MapSpec `ebpf:"active_reads"`
ActiveWrites *ebpf.MapSpec `ebpf:"active_writes"`
GoActiveL7Requests *ebpf.MapSpec `ebpf:"go_active_l7_requests"`
GoActiveReads *ebpf.MapSpec `ebpf:"go_active_reads"`
GoL7RequestHeap *ebpf.MapSpec `ebpf:"go_l7_request_heap"`
IngressEgressCalls *ebpf.MapSpec `ebpf:"ingress_egress_calls"`
IngressEgressHeap *ebpf.MapSpec `ebpf:"ingress_egress_heap"`
L7EventHeap *ebpf.MapSpec `ebpf:"l7_event_heap"`
L7Events *ebpf.MapSpec `ebpf:"l7_events"`
L7RequestHeap *ebpf.MapSpec `ebpf:"l7_request_heap"`
LogHeap *ebpf.MapSpec `ebpf:"log_heap"`
LogMap *ebpf.MapSpec `ebpf:"log_map"`
}
// bpfObjects contains all objects after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfObjects struct {
bpfPrograms
bpfMaps
}
func (o *bpfObjects) Close() error {
return _BpfClose(
&o.bpfPrograms,
&o.bpfMaps,
)
}
// bpfMaps contains all maps after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfMaps struct {
ActiveL7Requests *ebpf.Map `ebpf:"active_l7_requests"`
ActiveReads *ebpf.Map `ebpf:"active_reads"`
ActiveWrites *ebpf.Map `ebpf:"active_writes"`
GoActiveL7Requests *ebpf.Map `ebpf:"go_active_l7_requests"`
GoActiveReads *ebpf.Map `ebpf:"go_active_reads"`
GoL7RequestHeap *ebpf.Map `ebpf:"go_l7_request_heap"`
IngressEgressCalls *ebpf.Map `ebpf:"ingress_egress_calls"`
IngressEgressHeap *ebpf.Map `ebpf:"ingress_egress_heap"`
L7EventHeap *ebpf.Map `ebpf:"l7_event_heap"`
L7Events *ebpf.Map `ebpf:"l7_events"`
L7RequestHeap *ebpf.Map `ebpf:"l7_request_heap"`
LogHeap *ebpf.Map `ebpf:"log_heap"`
LogMap *ebpf.Map `ebpf:"log_map"`
}
func (m *bpfMaps) Close() error {
return _BpfClose(
m.ActiveL7Requests,
m.ActiveReads,
m.ActiveWrites,
m.GoActiveL7Requests,
m.GoActiveReads,
m.GoL7RequestHeap,
m.IngressEgressCalls,
m.IngressEgressHeap,
m.L7EventHeap,
m.L7Events,
m.L7RequestHeap,
m.LogHeap,
m.LogMap,
)
}
// bpfPrograms contains all programs after they have been loaded into the kernel.
//
// It can be passed to loadBpfObjects or ebpf.CollectionSpec.LoadAndAssign.
type bpfPrograms struct {
GoTlsConnReadEnter *ebpf.Program `ebpf:"go_tls_conn_read_enter"`
GoTlsConnReadExit *ebpf.Program `ebpf:"go_tls_conn_read_exit"`
GoTlsConnWriteEnter *ebpf.Program `ebpf:"go_tls_conn_write_enter"`
SslReadEnterV102 *ebpf.Program `ebpf:"ssl_read_enter_v1_0_2"`
SslReadEnterV111 *ebpf.Program `ebpf:"ssl_read_enter_v1_1_1"`
SslReadEnterV3 *ebpf.Program `ebpf:"ssl_read_enter_v3"`
SslRetRead *ebpf.Program `ebpf:"ssl_ret_read"`
SslWriteV102 *ebpf.Program `ebpf:"ssl_write_v1_0_2"`
SslWriteV111 *ebpf.Program `ebpf:"ssl_write_v1_1_1"`
SslWriteV3 *ebpf.Program `ebpf:"ssl_write_v3"`
SysEnterRead *ebpf.Program `ebpf:"sys_enter_read"`
SysEnterRecvfrom *ebpf.Program `ebpf:"sys_enter_recvfrom"`
SysEnterSendto *ebpf.Program `ebpf:"sys_enter_sendto"`
SysEnterWrite *ebpf.Program `ebpf:"sys_enter_write"`
SysExitRead *ebpf.Program `ebpf:"sys_exit_read"`
SysExitRecvfrom *ebpf.Program `ebpf:"sys_exit_recvfrom"`
SysExitSendto *ebpf.Program `ebpf:"sys_exit_sendto"`
SysExitWrite *ebpf.Program `ebpf:"sys_exit_write"`
}
func (p *bpfPrograms) Close() error {
return _BpfClose(
p.GoTlsConnReadEnter,
p.GoTlsConnReadExit,
p.GoTlsConnWriteEnter,
p.SslReadEnterV102,
p.SslReadEnterV111,
p.SslReadEnterV3,
p.SslRetRead,
p.SslWriteV102,
p.SslWriteV111,
p.SslWriteV3,
p.SysEnterRead,
p.SysEnterRecvfrom,
p.SysEnterSendto,
p.SysEnterWrite,
p.SysExitRead,
p.SysExitRecvfrom,
p.SysExitSendto,
p.SysExitWrite,
)
}
func _BpfClose(closers ...io.Closer) error {
for _, closer := range closers {
if err := closer.Close(); err != nil {
return err
}
}
return nil
}
// Do not access this directly.
//
//go:embed bpf_bpfel.o
var _BpfBytes []byte