@@ -70,11 +70,11 @@ struct bpf_map_def SEC("maps") sock_cork_bytes = {
70
70
.max_entries = 1
71
71
};
72
72
73
- struct bpf_map_def SEC ("maps" ) sock_pull_bytes = {
73
+ struct bpf_map_def SEC ("maps" ) sock_bytes = {
74
74
.type = BPF_MAP_TYPE_ARRAY ,
75
75
.key_size = sizeof (int ),
76
76
.value_size = sizeof (int ),
77
- .max_entries = 2
77
+ .max_entries = 4
78
78
};
79
79
80
80
struct bpf_map_def SEC ("maps" ) sock_redir_flags = {
@@ -181,27 +181,33 @@ int bpf_sockmap(struct bpf_sock_ops *skops)
181
181
SEC ("sk_msg1" )
182
182
int bpf_prog4 (struct sk_msg_md * msg )
183
183
{
184
- int * bytes , zero = 0 , one = 1 ;
185
- int * start , * end ;
184
+ int * bytes , zero = 0 , one = 1 , two = 2 , three = 3 ;
185
+ int * start , * end , * start_push , * end_push ;
186
186
187
187
bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
188
188
if (bytes )
189
189
bpf_msg_apply_bytes (msg , * bytes );
190
190
bytes = bpf_map_lookup_elem (& sock_cork_bytes , & zero );
191
191
if (bytes )
192
192
bpf_msg_cork_bytes (msg , * bytes );
193
- start = bpf_map_lookup_elem (& sock_pull_bytes , & zero );
194
- end = bpf_map_lookup_elem (& sock_pull_bytes , & one );
193
+ start = bpf_map_lookup_elem (& sock_bytes , & zero );
194
+ end = bpf_map_lookup_elem (& sock_bytes , & one );
195
195
if (start && end )
196
196
bpf_msg_pull_data (msg , * start , * end , 0 );
197
+ start_push = bpf_map_lookup_elem (& sock_bytes , & two );
198
+ end_push = bpf_map_lookup_elem (& sock_bytes , & three );
199
+ if (start_push && end_push )
200
+ bpf_msg_push_data (msg , * start_push , * end_push , 0 );
197
201
return SK_PASS ;
198
202
}
199
203
200
204
SEC ("sk_msg2" )
201
205
int bpf_prog5 (struct sk_msg_md * msg )
202
206
{
203
- int err1 = -1 , err2 = -1 , zero = 0 , one = 1 ;
204
- int * bytes , * start , * end , len1 , len2 ;
207
+ int zero = 0 , one = 1 , two = 2 , three = 3 ;
208
+ int * start , * end , * start_push , * end_push ;
209
+ int * bytes , len1 , len2 = 0 , len3 ;
210
+ int err1 = -1 , err2 = -1 ;
205
211
206
212
bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
207
213
if (bytes )
@@ -210,8 +216,8 @@ int bpf_prog5(struct sk_msg_md *msg)
210
216
if (bytes )
211
217
err2 = bpf_msg_cork_bytes (msg , * bytes );
212
218
len1 = (__u64 )msg -> data_end - (__u64 )msg -> data ;
213
- start = bpf_map_lookup_elem (& sock_pull_bytes , & zero );
214
- end = bpf_map_lookup_elem (& sock_pull_bytes , & one );
219
+ start = bpf_map_lookup_elem (& sock_bytes , & zero );
220
+ end = bpf_map_lookup_elem (& sock_bytes , & one );
215
221
if (start && end ) {
216
222
int err ;
217
223
@@ -225,6 +231,23 @@ int bpf_prog5(struct sk_msg_md *msg)
225
231
bpf_printk ("sk_msg2: length update %i->%i\n" ,
226
232
len1 , len2 );
227
233
}
234
+
235
+ start_push = bpf_map_lookup_elem (& sock_bytes , & two );
236
+ end_push = bpf_map_lookup_elem (& sock_bytes , & three );
237
+ if (start_push && end_push ) {
238
+ int err ;
239
+
240
+ bpf_printk ("sk_msg2: push(%i:%i)\n" ,
241
+ start_push ? * start_push : 0 ,
242
+ end_push ? * end_push : 0 );
243
+ err = bpf_msg_push_data (msg , * start_push , * end_push , 0 );
244
+ if (err )
245
+ bpf_printk ("sk_msg2: push_data err %i\n" , err );
246
+ len3 = (__u64 )msg -> data_end - (__u64 )msg -> data ;
247
+ bpf_printk ("sk_msg2: length push_update %i->%i\n" ,
248
+ len2 ? len2 : len1 , len3 );
249
+ }
250
+
228
251
bpf_printk ("sk_msg2: data length %i err1 %i err2 %i\n" ,
229
252
len1 , err1 , err2 );
230
253
return SK_PASS ;
@@ -233,8 +256,8 @@ int bpf_prog5(struct sk_msg_md *msg)
233
256
SEC ("sk_msg3" )
234
257
int bpf_prog6 (struct sk_msg_md * msg )
235
258
{
236
- int * bytes , zero = 0 , one = 1 , key = 0 ;
237
- int * start , * end , * f ;
259
+ int * bytes , * start , * end , * start_push , * end_push , * f ;
260
+ int zero = 0 , one = 1 , two = 2 , three = 3 , key = 0 ;
238
261
__u64 flags = 0 ;
239
262
240
263
bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
@@ -243,10 +266,17 @@ int bpf_prog6(struct sk_msg_md *msg)
243
266
bytes = bpf_map_lookup_elem (& sock_cork_bytes , & zero );
244
267
if (bytes )
245
268
bpf_msg_cork_bytes (msg , * bytes );
246
- start = bpf_map_lookup_elem (& sock_pull_bytes , & zero );
247
- end = bpf_map_lookup_elem (& sock_pull_bytes , & one );
269
+
270
+ start = bpf_map_lookup_elem (& sock_bytes , & zero );
271
+ end = bpf_map_lookup_elem (& sock_bytes , & one );
248
272
if (start && end )
249
273
bpf_msg_pull_data (msg , * start , * end , 0 );
274
+
275
+ start_push = bpf_map_lookup_elem (& sock_bytes , & two );
276
+ end_push = bpf_map_lookup_elem (& sock_bytes , & three );
277
+ if (start_push && end_push )
278
+ bpf_msg_push_data (msg , * start_push , * end_push , 0 );
279
+
250
280
f = bpf_map_lookup_elem (& sock_redir_flags , & zero );
251
281
if (f && * f ) {
252
282
key = 2 ;
@@ -262,8 +292,9 @@ int bpf_prog6(struct sk_msg_md *msg)
262
292
SEC ("sk_msg4" )
263
293
int bpf_prog7 (struct sk_msg_md * msg )
264
294
{
265
- int err1 = 0 , err2 = 0 , zero = 0 , one = 1 , key = 0 ;
266
- int * f , * bytes , * start , * end , len1 , len2 ;
295
+ int zero = 0 , one = 1 , two = 2 , three = 3 , len1 , len2 = 0 , len3 ;
296
+ int * bytes , * start , * end , * start_push , * end_push , * f ;
297
+ int err1 = 0 , err2 = 0 , key = 0 ;
267
298
__u64 flags = 0 ;
268
299
269
300
int err ;
@@ -274,10 +305,10 @@ int bpf_prog7(struct sk_msg_md *msg)
274
305
if (bytes )
275
306
err2 = bpf_msg_cork_bytes (msg , * bytes );
276
307
len1 = (__u64 )msg -> data_end - (__u64 )msg -> data ;
277
- start = bpf_map_lookup_elem (& sock_pull_bytes , & zero );
278
- end = bpf_map_lookup_elem (& sock_pull_bytes , & one );
279
- if (start && end ) {
280
308
309
+ start = bpf_map_lookup_elem (& sock_bytes , & zero );
310
+ end = bpf_map_lookup_elem (& sock_bytes , & one );
311
+ if (start && end ) {
281
312
bpf_printk ("sk_msg2: pull(%i:%i)\n" ,
282
313
start ? * start : 0 , end ? * end : 0 );
283
314
err = bpf_msg_pull_data (msg , * start , * end , 0 );
@@ -288,6 +319,22 @@ int bpf_prog7(struct sk_msg_md *msg)
288
319
bpf_printk ("sk_msg2: length update %i->%i\n" ,
289
320
len1 , len2 );
290
321
}
322
+
323
+ start_push = bpf_map_lookup_elem (& sock_bytes , & two );
324
+ end_push = bpf_map_lookup_elem (& sock_bytes , & three );
325
+ if (start_push && end_push ) {
326
+ bpf_printk ("sk_msg4: push(%i:%i)\n" ,
327
+ start_push ? * start_push : 0 ,
328
+ end_push ? * end_push : 0 );
329
+ err = bpf_msg_push_data (msg , * start_push , * end_push , 0 );
330
+ if (err )
331
+ bpf_printk ("sk_msg4: push_data err %i\n" ,
332
+ err );
333
+ len3 = (__u64 )msg -> data_end - (__u64 )msg -> data ;
334
+ bpf_printk ("sk_msg4: length push_update %i->%i\n" ,
335
+ len2 ? len2 : len1 , len3 );
336
+ }
337
+
291
338
f = bpf_map_lookup_elem (& sock_redir_flags , & zero );
292
339
if (f && * f ) {
293
340
key = 2 ;
@@ -342,19 +389,23 @@ int bpf_prog9(struct sk_msg_md *msg)
342
389
SEC ("sk_msg7" )
343
390
int bpf_prog10 (struct sk_msg_md * msg )
344
391
{
345
- int * bytes , zero = 0 , one = 1 ;
346
- int * start , * end ;
392
+ int * bytes , * start , * end , * start_push , * end_push ;
393
+ int zero = 0 , one = 1 , two = 2 , three = 3 ;
347
394
348
395
bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
349
396
if (bytes )
350
397
bpf_msg_apply_bytes (msg , * bytes );
351
398
bytes = bpf_map_lookup_elem (& sock_cork_bytes , & zero );
352
399
if (bytes )
353
400
bpf_msg_cork_bytes (msg , * bytes );
354
- start = bpf_map_lookup_elem (& sock_pull_bytes , & zero );
355
- end = bpf_map_lookup_elem (& sock_pull_bytes , & one );
401
+ start = bpf_map_lookup_elem (& sock_bytes , & zero );
402
+ end = bpf_map_lookup_elem (& sock_bytes , & one );
356
403
if (start && end )
357
404
bpf_msg_pull_data (msg , * start , * end , 0 );
405
+ start_push = bpf_map_lookup_elem (& sock_bytes , & two );
406
+ end_push = bpf_map_lookup_elem (& sock_bytes , & three );
407
+ if (start_push && end_push )
408
+ bpf_msg_push_data (msg , * start_push , * end_push , 0 );
358
409
359
410
return SK_DROP ;
360
411
}
0 commit comments