@@ -70,11 +70,11 @@ struct bpf_map_def SEC("maps") sock_cork_bytes = {
7070 .max_entries = 1
7171};
7272
73- struct bpf_map_def SEC ("maps" ) sock_pull_bytes = {
73+ struct bpf_map_def SEC ("maps" ) sock_bytes = {
7474 .type = BPF_MAP_TYPE_ARRAY ,
7575 .key_size = sizeof (int ),
7676 .value_size = sizeof (int ),
77- .max_entries = 2
77+ .max_entries = 4
7878};
7979
8080struct bpf_map_def SEC ("maps" ) sock_redir_flags = {
@@ -181,27 +181,33 @@ int bpf_sockmap(struct bpf_sock_ops *skops)
181181SEC ("sk_msg1" )
182182int bpf_prog4 (struct sk_msg_md * msg )
183183{
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 ;
186186
187187 bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
188188 if (bytes )
189189 bpf_msg_apply_bytes (msg , * bytes );
190190 bytes = bpf_map_lookup_elem (& sock_cork_bytes , & zero );
191191 if (bytes )
192192 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 );
195195 if (start && end )
196196 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 );
197201 return SK_PASS ;
198202}
199203
200204SEC ("sk_msg2" )
201205int bpf_prog5 (struct sk_msg_md * msg )
202206{
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 ;
205211
206212 bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
207213 if (bytes )
@@ -210,8 +216,8 @@ int bpf_prog5(struct sk_msg_md *msg)
210216 if (bytes )
211217 err2 = bpf_msg_cork_bytes (msg , * bytes );
212218 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 );
215221 if (start && end ) {
216222 int err ;
217223
@@ -225,6 +231,23 @@ int bpf_prog5(struct sk_msg_md *msg)
225231 bpf_printk ("sk_msg2: length update %i->%i\n" ,
226232 len1 , len2 );
227233 }
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+
228251 bpf_printk ("sk_msg2: data length %i err1 %i err2 %i\n" ,
229252 len1 , err1 , err2 );
230253 return SK_PASS ;
@@ -233,8 +256,8 @@ int bpf_prog5(struct sk_msg_md *msg)
233256SEC ("sk_msg3" )
234257int bpf_prog6 (struct sk_msg_md * msg )
235258{
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 ;
238261 __u64 flags = 0 ;
239262
240263 bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
@@ -243,10 +266,17 @@ int bpf_prog6(struct sk_msg_md *msg)
243266 bytes = bpf_map_lookup_elem (& sock_cork_bytes , & zero );
244267 if (bytes )
245268 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 );
248272 if (start && end )
249273 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+
250280 f = bpf_map_lookup_elem (& sock_redir_flags , & zero );
251281 if (f && * f ) {
252282 key = 2 ;
@@ -262,8 +292,9 @@ int bpf_prog6(struct sk_msg_md *msg)
262292SEC ("sk_msg4" )
263293int bpf_prog7 (struct sk_msg_md * msg )
264294{
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 ;
267298 __u64 flags = 0 ;
268299
269300 int err ;
@@ -274,10 +305,10 @@ int bpf_prog7(struct sk_msg_md *msg)
274305 if (bytes )
275306 err2 = bpf_msg_cork_bytes (msg , * bytes );
276307 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 ) {
280308
309+ start = bpf_map_lookup_elem (& sock_bytes , & zero );
310+ end = bpf_map_lookup_elem (& sock_bytes , & one );
311+ if (start && end ) {
281312 bpf_printk ("sk_msg2: pull(%i:%i)\n" ,
282313 start ? * start : 0 , end ? * end : 0 );
283314 err = bpf_msg_pull_data (msg , * start , * end , 0 );
@@ -288,6 +319,22 @@ int bpf_prog7(struct sk_msg_md *msg)
288319 bpf_printk ("sk_msg2: length update %i->%i\n" ,
289320 len1 , len2 );
290321 }
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+
291338 f = bpf_map_lookup_elem (& sock_redir_flags , & zero );
292339 if (f && * f ) {
293340 key = 2 ;
@@ -342,19 +389,23 @@ int bpf_prog9(struct sk_msg_md *msg)
342389SEC ("sk_msg7" )
343390int bpf_prog10 (struct sk_msg_md * msg )
344391{
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 ;
347394
348395 bytes = bpf_map_lookup_elem (& sock_apply_bytes , & zero );
349396 if (bytes )
350397 bpf_msg_apply_bytes (msg , * bytes );
351398 bytes = bpf_map_lookup_elem (& sock_cork_bytes , & zero );
352399 if (bytes )
353400 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 );
356403 if (start && end )
357404 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 );
358409
359410 return SK_DROP ;
360411}
0 commit comments