You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Lookup the sockhash map and attach the sk_msg eBPF program to the map
113
+
107
114
```go
108
115
sockMap:= coll.Maps["km_socket"]
109
116
t.Log(sockMap.Type())
@@ -115,7 +122,9 @@ struct {
115
122
Program: prog,
116
123
})
117
124
```
125
+
118
126
#### set up
127
+
119
128
- Establish a network connection, obtain the file descriptor (fd), insert the fd into the map, and sending messages through this fd will trigger the eBPF program
120
129
```go
121
130
localIP:=get_local_ipv4(t)
@@ -164,6 +173,7 @@ struct {
164
173
t.Logf("Update successful for key: %+v, fd: %d", tupleKey, fd32)
165
174
}
166
175
```
176
+
167
177
### test
168
178
169
179
- For the sendmsg program, there are key steps:
@@ -177,15 +187,19 @@ struct {
177
187
- The current plan is to write a test that directly verifies whether TLV is written into the message header.
178
188
- Validation method: Check whether TLV is correctly written into the message header.
179
189
- Validation method
190
+
180
191
```go
181
192
buf:=make([]byte, 64)
182
193
n, _:= ln.Accept().Read(buf)
183
194
t.Logf("Received data: %x", buf[:n])
184
195
```
196
+
185
197
### cgroup_sock.c
186
198
### mount and set up
187
199
#### mount
200
+
188
201
- in workload_test.go
202
+
189
203
```go
190
204
// mount cgroup2
191
205
mount_cgroup2(t, cgroupPath)
@@ -195,21 +209,26 @@ struct {
195
209
defer coll.Close()
196
210
defer lk.Close()
197
211
```
212
+
198
213
#### set up
214
+
199
215
```go
200
216
conn, err:= net.Dial("tcp4", "...")
201
217
if err != nil {
202
218
t.Fatalf("Dial failed: %v", err)
203
219
}
204
220
defer conn.Close()
205
221
```
222
+
206
223
### test
224
+
207
225
- Currently, connect4 and connect6 each have 5 test points.
208
226
- 1
209
227
- handle_kmesh_manage_process(&kmesh_ctx) internally calls bpf_map_update_elem(&map_of_manager, &key, &value, BPF_ANY); or err = bpf_map_delete_elem(&map_of_manager, &key); for verification.
210
228
- When the destination address is CONTROL_CMD_IP: ENABLE_KMESH_PORT, it adds its netns_cookie to the map; when the destination address is CONTROL_CMD_IP: DISABLE_KMESH_PORT, it deletes its netns_cookie from the map.
211
229
- Validation method:
212
230
- Verify the addition when inserting.
231
+
213
232
```go
214
233
kmManageMap:= coll.Maps["km_manage"]
215
234
if kmManageMap == nil {
@@ -236,7 +255,9 @@ defer conn.Close()
236
255
t.Fatalf("Expected 1 entry in km_manage map, but got %d", count)
237
256
}
238
257
```
258
+
239
259
- Validation when deleting
260
+
240
261
```go
241
262
iter = kmManageMap.Iterate()
242
263
count = 0
@@ -251,12 +272,14 @@ defer conn.Close()
251
272
t.Fatalf("Expected 0 entry in km_manage map, but got %d", count)
252
273
}
253
274
```
275
+
254
276
- Notes
255
277
- Here it may be necessary to mock storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); inside workload_cgroup_sock_test.c.
256
278
- 2
257
279
- The function sock_traffic_control(&kmesh_ctx) is critical and internally includes
258
280
- frontend_v = map_lookup_frontend(&frontend_k); Consider how to return frontend_v; this must return a value.
259
281
- By constructing a key-value pair so that the map contains this k-v, it can be found; construct the frontend map.
282
+
260
283
```go
261
284
//frontend map
262
285
type ip_addr struct {
@@ -286,11 +309,13 @@ defer conn.Close()
286
309
log.Fatalf("Update failed: %v", err)
287
310
}
288
311
```
312
+
289
313
- frontend_manager(kmesh_ctx, frontend_v); internally includes
290
314
- kmesh_map_lookup_elem(&map_of_service, key)
291
315
- 2.1: can find:
292
316
- 2.1.1:
293
317
- Test point: waypoint == true in service_value
318
+
294
319
```go
295
320
type service_value struct {
296
321
PrioEndpointCount [7]uint32
@@ -307,18 +332,22 @@ s_val := service_value{
307
332
WaypointPort: 55555, //Build
308
333
}
309
334
```
335
+
310
336
- At this point, you need to monitor the forwarded address so that the forwarded connection will not be rejected
311
337
312
338
### Alternatives
339
+
313
340
```go
314
341
test:=localIp+":"+strconv.Itoa(htons(55555))
315
342
- _, err = net.Listen("tcp4", "10.30.0.124:985")
316
343
```
344
+
317
345
- 2.2.2:
318
346
- 2.2: If not found, perform kmesh_map_lookup_elem(&map_of_backend, key); this must return a value
- Note: The UpstreamID in the constructed value must match the key length used later when populating km_backend or the key length used in km_service. For example:
407
+
373
408
```go
374
409
type backend_key struct {
375
410
BackendUIDuint32
@@ -387,7 +422,9 @@ s_key := service_key{
387
422
ServiceID: 1,
388
423
}
389
424
```
425
+
390
426
- Validation method:
427
+
391
428
```go
392
429
expectedIP:= localIP
393
430
expectedPort:= strconv.Itoa(htons(testPort))
@@ -396,16 +433,18 @@ expectedIP := localIP
396
433
t.Fatalf("Expected redirected to %s:%s, but got %s:%s", expectedIP, expectedPort, host, port)
397
434
}
398
435
```
436
+
399
437
### cgroup_skb.c
438
+
400
439
- It is a type supported by bpf_prog_run and can be tested using the first framework.
401
440
- Since it uses the same __sk_buff parameters as tc triggers, it can be written by following that example.
441
+
402
442
```c
403
443
#include"ut_common.h"
404
444
#include<linux/bpf.h>
405
445
#include<linux/if_ether.h>
406
446
#include<linux/in.h>
407
447
#include<netinet/tcp.h>
408
-
409
448
#include"workload/cgroup_skb.c"
410
449
struct tcp_probe_info mock_info;
411
450
bool mock_ringbuf_called = false;
@@ -504,6 +543,7 @@ int test_ingress_check(struct __sk_buff *ctx)
504
543
test_finish();
505
544
}
506
545
```
546
+
507
547
<!--
508
548
What other approaches did you consider, and why did you rule them out? These do
509
549
not need to be as detailed as the proposal, but should include enough
0 commit comments