@@ -91,7 +91,7 @@ struct pping_config {
91
91
92
92
static volatile int keep_running = 1 ;
93
93
static json_writer_t * json_ctx = NULL ;
94
- static void (* print_event_func )(void * , int , void * , __u32 ) = NULL ;
94
+ static void (* print_event_func )(const union pping_event * ) = NULL ;
95
95
96
96
static const struct option long_options [] = {
97
97
{ "help" , no_argument , NULL , 'h' },
@@ -511,7 +511,7 @@ static bool flow_timeout(void *key_ptr, void *val_ptr, __u64 now)
511
511
fe .flow_event_type = FLOW_EVENT_CLOSING ;
512
512
fe .reason = EVENT_REASON_FLOW_TIMEOUT ;
513
513
fe .source = EVENT_SOURCE_USERSPACE ;
514
- print_event_func (NULL , 0 , & fe , sizeof ( fe ) );
514
+ print_event_func (( union pping_event * ) & fe );
515
515
}
516
516
return true;
517
517
}
@@ -722,11 +722,8 @@ static void print_ns_datetime(FILE *stream, __u64 monotonic_ns)
722
722
fprintf (stream , "%s.%09llu" , timestr , ts % NS_PER_SECOND );
723
723
}
724
724
725
- static void print_event_standard (void * ctx , int cpu , void * data ,
726
- __u32 data_size )
725
+ static void print_event_standard (const union pping_event * e )
727
726
{
728
- const union pping_event * e = data ;
729
-
730
727
if (e -> event_type == EVENT_TYPE_RTT ) {
731
728
print_ns_datetime (stdout , e -> rtt_event .timestamp );
732
729
printf (" %llu.%06llu ms %llu.%06llu ms %s " ,
@@ -748,19 +745,19 @@ static void print_event_standard(void *ctx, int cpu, void *data,
748
745
}
749
746
}
750
747
751
- static void print_event_ppviz (void * ctx , int cpu , void * data , __u32 data_size )
748
+ static void print_event_ppviz (const union pping_event * e )
752
749
{
753
- const struct rtt_event * e = data ;
754
- __u64 time = convert_monotonic_to_realtime (e -> timestamp );
755
-
756
750
// ppviz format does not support flow events
757
751
if (e -> event_type != EVENT_TYPE_RTT )
758
752
return ;
759
753
754
+ const struct rtt_event * re = & e -> rtt_event ;
755
+ __u64 time = convert_monotonic_to_realtime (re -> timestamp );
756
+
760
757
printf ("%llu.%09llu %llu.%09llu %llu.%09llu " , time / NS_PER_SECOND ,
761
- time % NS_PER_SECOND , e -> rtt / NS_PER_SECOND ,
762
- e -> rtt % NS_PER_SECOND , e -> min_rtt / NS_PER_SECOND , e -> min_rtt );
763
- print_flow_ppvizformat (stdout , & e -> flow );
758
+ time % NS_PER_SECOND , re -> rtt / NS_PER_SECOND ,
759
+ re -> rtt % NS_PER_SECOND , re -> min_rtt / NS_PER_SECOND , re -> min_rtt );
760
+ print_flow_ppvizformat (stdout , & re -> flow );
764
761
printf ("\n" );
765
762
}
766
763
@@ -805,10 +802,8 @@ static void print_flowevent_fields_json(json_writer_t *ctx,
805
802
jsonw_string_field (ctx , "triggered_by" , eventsource_to_str (fe -> source ));
806
803
}
807
804
808
- static void print_event_json (void * ctx , int cpu , void * data , __u32 data_size )
805
+ static void print_event_json (const union pping_event * e )
809
806
{
810
- const union pping_event * e = data ;
811
-
812
807
if (e -> event_type != EVENT_TYPE_RTT && e -> event_type != EVENT_TYPE_FLOW )
813
808
return ;
814
809
@@ -826,9 +821,27 @@ static void print_event_json(void *ctx, int cpu, void *data, __u32 data_size)
826
821
jsonw_end_object (json_ctx );
827
822
}
828
823
829
- static void handle_missed_rtt_event (void * ctx , int cpu , __u64 lost_cnt )
824
+ static void handle_event (void * ctx , int cpu , void * data , __u32 data_size )
825
+ {
826
+ const union pping_event * e = data ;
827
+
828
+ if (data_size < sizeof (e -> event_type ))
829
+ return ;
830
+
831
+ switch (e -> event_type ) {
832
+ case EVENT_TYPE_RTT :
833
+ case EVENT_TYPE_FLOW :
834
+ print_event_func (e );
835
+ break ;
836
+ default :
837
+ fprintf (stderr , "Warning: Unknown event type %llu\n" ,
838
+ e -> event_type );
839
+ };
840
+ }
841
+
842
+ static void handle_missed_events (void * ctx , int cpu , __u64 lost_cnt )
830
843
{
831
- fprintf (stderr , "Lost %llu RTT events on CPU %d\n" , lost_cnt , cpu );
844
+ fprintf (stderr , "Lost %llu events on CPU %d\n" , lost_cnt , cpu );
832
845
}
833
846
834
847
/*
@@ -1081,8 +1094,8 @@ int main(int argc, char *argv[])
1081
1094
// Set up perf buffer
1082
1095
pb = perf_buffer__new (bpf_object__find_map_fd_by_name (obj ,
1083
1096
config .event_map ),
1084
- PERF_BUFFER_PAGES , print_event_func ,
1085
- handle_missed_rtt_event , NULL , NULL );
1097
+ PERF_BUFFER_PAGES , handle_event ,
1098
+ handle_missed_events , NULL , NULL );
1086
1099
err = libbpf_get_error (pb );
1087
1100
if (err ) {
1088
1101
fprintf (stderr , "Failed to open perf buffer %s: %s\n" ,
0 commit comments