13
13
#include <common/trace_common.h>
14
14
15
15
#include <generictracer/maps/http_info_mem.h>
16
+
17
+ #include <generictracer/k_tracer_tailcall.h>
16
18
#include <generictracer/protocol_common.h>
17
19
18
20
#include <maps/accepted_connections.h>
@@ -403,7 +405,100 @@ static __always_inline void handle_http_response(unsigned char *small_buf,
403
405
cleanup_http_request_data (pid_conn , info );
404
406
}
405
407
406
- static __always_inline int __obi_protocol_http (unsigned char * (* tp_loop_fn )(unsigned char * , int )) {
408
+ static __always_inline int __obi_continue2_protocol_http (void * ctx ,
409
+ call_protocol_args_t * args ,
410
+ http_info_t * info ,
411
+ http_connection_metadata_t * meta ) {
412
+ (void )ctx ;
413
+
414
+ if (meta ) {
415
+ u32 type = trace_type_from_meta (meta );
416
+ tp_info_pid_t * tp_p = trace_info_for_connection (& args -> pid_conn .conn , type );
417
+ if (tp_p ) {
418
+ info -> tp = tp_p -> tp ;
419
+ if (args -> self_ref_parent_id ) {
420
+ bpf_dbg_printk ("overwriting parent id from the self referencing client request" );
421
+ __builtin_memcpy (& info -> tp .parent_id , & args -> self_ref_parent_id , sizeof (u64 ));
422
+ }
423
+ } else {
424
+ bpf_dbg_printk ("Can't find trace info, this is a bug!" );
425
+ }
426
+ } else {
427
+ bpf_dbg_printk ("No META!" );
428
+ }
429
+
430
+ // we copy some small part of the buffer to the info trace event, so that we can process an event even with
431
+ // incomplete trace info in user space.
432
+ bpf_probe_read (info -> buf , FULL_BUF_SIZE , (void * )args -> u_buf );
433
+ process_http_request (info , args -> bytes_len , meta , args -> direction , args -> orig_dport );
434
+
435
+ return 0 ;
436
+ }
437
+
438
+ // k_tail_continue2_protocol_http
439
+ SEC ("kprobe/http" )
440
+ int obi_continue2_protocol_http (void * ctx ) {
441
+ call_protocol_args_t * args = protocol_args ();
442
+ if (!args ) {
443
+ return 0 ;
444
+ }
445
+
446
+ http_info_t * info = bpf_map_lookup_elem (& ongoing_http , & args -> pid_conn );
447
+ if (!info ) {
448
+ return 0 ;
449
+ }
450
+
451
+ http_connection_metadata_t * meta =
452
+ connection_meta_by_direction (args -> direction , PACKET_TYPE_REQUEST );
453
+
454
+ return __obi_continue2_protocol_http (ctx , args , info , meta );
455
+ }
456
+
457
+ static __always_inline int
458
+ __obi_continue_protocol_http (void * ctx ,
459
+ call_protocol_args_t * args ,
460
+ http_info_t * info ,
461
+ unsigned char * (* tp_loop_fn )(unsigned char * , int )) {
462
+ http_connection_metadata_t * meta =
463
+ connection_meta_by_direction (args -> direction , PACKET_TYPE_REQUEST );
464
+
465
+ http_get_or_create_trace_info (meta ,
466
+ args -> pid_conn .pid ,
467
+ & args -> pid_conn .conn ,
468
+ (void * )args -> u_buf ,
469
+ args -> bytes_len ,
470
+ capture_header_buffer ,
471
+ args -> ssl ,
472
+ args -> orig_dport ,
473
+ tp_loop_fn );
474
+
475
+ if (tp_loop_fn == bpf_strstr_tp_loop__legacy ) {
476
+ bpf_tail_call (ctx , & jump_table , k_tail_continue2_protocol_http );
477
+ } else {
478
+ return __obi_continue2_protocol_http (ctx , args , info , meta );
479
+ }
480
+
481
+ return 0 ;
482
+ }
483
+
484
+ // k_tail_continue_protocol_http
485
+ SEC ("kprobe/http" )
486
+ int obi_continue_protocol_http (void * ctx ) {
487
+ call_protocol_args_t * args = protocol_args ();
488
+ if (!args ) {
489
+ return 0 ;
490
+ }
491
+
492
+ http_info_t * info = bpf_map_lookup_elem (& ongoing_http , & args -> pid_conn );
493
+ if (!info ) {
494
+ return 0 ;
495
+ }
496
+
497
+ return __obi_continue_protocol_http (ctx , args , info , bpf_strstr_tp_loop__legacy );
498
+ }
499
+
500
+ static __always_inline int __obi_protocol_http (void * ctx ,
501
+ unsigned char * (* tp_loop_fn )(unsigned char * , int )) {
407
502
call_protocol_args_t * args = protocol_args ();
408
503
if (!args ) {
409
504
return 0 ;
@@ -428,7 +523,7 @@ static __always_inline int __obi_protocol_http(unsigned char *(*tp_loop_fn)(unsi
428
523
u64 self_ref_parent_id = 0 ;
429
524
tp_info_t * self_ref_tp = self_referencing_request (& args -> pid_conn , args -> packet_type );
430
525
if (self_ref_tp ) {
431
- __builtin_memcpy (& self_ref_parent_id , & self_ref_tp -> parent_id , sizeof (u64 ));
526
+ __builtin_memcpy (& args -> self_ref_parent_id , & self_ref_tp -> parent_id , sizeof (u64 ));
432
527
}
433
528
434
529
http_info_t * info =
@@ -446,40 +541,12 @@ static __always_inline int __obi_protocol_http(unsigned char *(*tp_loop_fn)(unsi
446
541
447
542
if (args -> packet_type == PACKET_TYPE_REQUEST && (info -> status == 0 ) &&
448
543
(info -> start_monotime_ns == 0 )) {
449
- http_connection_metadata_t * meta =
450
- connection_meta_by_direction (args -> direction , PACKET_TYPE_REQUEST );
451
-
452
- http_get_or_create_trace_info (meta ,
453
- args -> pid_conn .pid ,
454
- & args -> pid_conn .conn ,
455
- (void * )args -> u_buf ,
456
- args -> bytes_len ,
457
- capture_header_buffer ,
458
- args -> ssl ,
459
- args -> orig_dport ,
460
- tp_loop_fn );
461
-
462
- if (meta ) {
463
- u32 type = trace_type_from_meta (meta );
464
- tp_info_pid_t * tp_p = trace_info_for_connection (& args -> pid_conn .conn , type );
465
- if (tp_p ) {
466
- info -> tp = tp_p -> tp ;
467
- if (self_ref_parent_id ) {
468
- bpf_dbg_printk (
469
- "overwriting parent id from the self referencing client request" );
470
- __builtin_memcpy (& info -> tp .parent_id , & self_ref_parent_id , sizeof (u64 ));
471
- }
472
- } else {
473
- bpf_dbg_printk ("Can't find trace info, this is a bug!" );
474
- }
544
+ if (tp_loop_fn == bpf_strstr_tp_loop__legacy ) {
545
+ bpf_tail_call (ctx , & jump_table , k_tail_continue_protocol_http );
546
+ return 0 ;
475
547
} else {
476
- bpf_dbg_printk ( "No META!" );
548
+ return __obi_continue_protocol_http ( ctx , args , info , tp_loop_fn );
477
549
}
478
-
479
- // we copy some small part of the buffer to the info trace event, so that we can process an event even with
480
- // incomplete trace info in user space.
481
- bpf_probe_read (info -> buf , FULL_BUF_SIZE , (void * )args -> u_buf );
482
- process_http_request (info , args -> bytes_len , meta , args -> direction , args -> orig_dport );
483
550
} else if ((args -> packet_type == PACKET_TYPE_RESPONSE ) && (info -> status == 0 )) {
484
551
handle_http_response (
485
552
args -> small_buf , & args -> pid_conn , info , args -> bytes_len , args -> direction , args -> ssl );
@@ -494,13 +561,11 @@ static __always_inline int __obi_protocol_http(unsigned char *(*tp_loop_fn)(unsi
494
561
// k_tail_protocol_http
495
562
SEC ("kprobe/http" )
496
563
int obi_protocol_http (void * ctx ) {
497
- (void )ctx ;
498
- return __obi_protocol_http (bpf_strstr_tp_loop );
564
+ return __obi_protocol_http (ctx , bpf_strstr_tp_loop );
499
565
}
500
566
501
567
// k_tail_protocol_http
502
568
SEC ("kprobe/http" )
503
569
int obi_protocol_http_legacy (void * ctx ) {
504
- (void )ctx ;
505
- return __obi_protocol_http (bpf_strstr_tp_loop__legacy );
570
+ return __obi_protocol_http (ctx , bpf_strstr_tp_loop__legacy );
506
571
}
0 commit comments