@@ -139,6 +139,7 @@ enum event_source {
139139 EVENT_SOURCE_SK = 1 ,
140140 EVENT_SOURCE_IPTABLES = 2 ,
141141 EVENT_SOURCE_TCP = 3 ,
142+ EVENT_SOURCE_PCAP = 4 ,
142143};
143144
144145struct event_t {
@@ -184,16 +185,9 @@ get_event(void) {
184185 return event ;
185186}
186187
187- #define MAX_QUEUE_ENTRIES 10000
188- struct {
189- __uint (type , BPF_MAP_TYPE_QUEUE );
190- __type (value , struct event_t );
191- __uint (max_entries , MAX_QUEUE_ENTRIES );
192- } events SEC (".maps" );
193-
194188struct {
195189 __uint (type , BPF_MAP_TYPE_PERF_EVENT_ARRAY );
196- } pcap_events SEC (".maps" );
190+ } events SEC (".maps" );
197191
198192#define MAX_TRACK_SIZE 1024
199193struct {
@@ -482,7 +476,7 @@ kprobe_skb(struct sk_buff *skb, struct pt_regs *ctx, bool has_get_func_ip,
482476 event -> addr = has_get_func_ip ? bpf_get_func_ip (ctx ) : PT_REGS_IP (ctx );
483477 event -> type = EVENT_TYPE_KPROBE ;
484478 event -> source = EVENT_SOURCE_SKB ;
485- bpf_map_push_elem ( & events , event , BPF_EXIST );
479+ bpf_perf_event_output ( ctx , & events , BPF_F_CURRENT_CPU , event , sizeof ( * event ) );
486480
487481 return BPF_OK ;
488482}
@@ -571,12 +565,11 @@ set_skb_pcap_meta(struct sk_buff *skb, struct pcap_meta *pcap, int action, bool
571565
572566static __always_inline void
573567output_skb_pcap_event (struct sk_buff * skb , struct event_t * event , int action , bool is_fexit ) {
574- u64 flags ;
575-
568+ event -> source = EVENT_SOURCE_PCAP ;
576569 set_skb_pcap_meta (skb , & event -> pcap , action , is_fexit );
577570
578- flags = (((u64 ) event -> pcap .cap_len ) << 32 ) | BPF_F_CURRENT_CPU ;
579- bpf_skb_output (skb , & pcap_events , flags , event , __sizeof_pcap_event );
571+ u64 flags = (((u64 ) event -> pcap .cap_len ) << 32 ) | BPF_F_CURRENT_CPU ;
572+ bpf_skb_output (skb , & events , flags , event , __sizeof_pcap_event );
580573}
581574
582575static __noinline void
@@ -594,7 +587,7 @@ handle_tc_skb(struct sk_buff *skb, void *ctx, int action, bool is_fexit, const b
594587 event -> source = EVENT_SOURCE_SKB ;
595588
596589 if (!cfg -> output_pcap ) {
597- bpf_map_push_elem ( & events , event , BPF_EXIST );
590+ bpf_perf_event_output ( ctx , & events , BPF_F_CURRENT_CPU , event , sizeof ( * event ) );
598591 return ;
599592 }
600593
@@ -731,10 +724,11 @@ set_xdp_pcap_meta(struct xdp_buff *xdp, struct pcap_meta *pcap, u32 len, int act
731724
732725static __always_inline void
733726output_xdp_pcap_event (struct xdp_buff * xdp , struct event_t * event , u32 len , int action , bool is_fexit ) {
727+ event -> source = EVENT_SOURCE_PCAP ;
734728 set_xdp_pcap_meta (xdp , & event -> pcap , len , action , is_fexit );
735729
736730 u64 flags = (((u64 ) event -> pcap .cap_len ) << 32 ) | BPF_F_CURRENT_CPU ;
737- bpf_xdp_output (xdp , & pcap_events , flags , event , __sizeof_pcap_event );
731+ bpf_xdp_output (xdp , & events , flags , event , __sizeof_pcap_event );
738732}
739733
740734static __noinline void
@@ -759,7 +753,7 @@ handle_xdp_buff(struct xdp_buff *xdp, void *ctx, int verdict, bool is_fexit, con
759753 event -> source = EVENT_SOURCE_SKB ;
760754
761755 if (!cfg -> output_pcap ) {
762- bpf_map_push_elem ( & events , event , BPF_EXIST );
756+ bpf_perf_event_output ( ctx , & events , BPF_F_CURRENT_CPU , event , sizeof ( * event ) );
763757 return ;
764758 }
765759
@@ -854,7 +848,7 @@ ipt_do_table_exit(struct pt_regs *ctx, uint verdict) {
854848 event -> addr = PT_REGS_IP (ctx );
855849 event -> type = EVENT_TYPE_KPROBE ;
856850 event -> source = EVENT_SOURCE_IPTABLES ;
857- bpf_map_push_elem ( & events , event , BPF_EXIST );
851+ bpf_perf_event_output ( ctx , & events , BPF_F_CURRENT_CPU , event , sizeof ( * event ) );
858852
859853 return BPF_OK ;
860854}
@@ -1021,7 +1015,7 @@ kprobe_sk(struct sock *sk, struct pt_regs *ctx, const bool has_get_func_ip) {
10211015 event -> addr = has_get_func_ip ? bpf_get_func_ip (ctx ) : PT_REGS_IP (ctx );
10221016 event -> type = EVENT_TYPE_KPROBE ;
10231017 event -> source = EVENT_SOURCE_SK ;
1024- bpf_map_push_elem ( & events , event , BPF_EXIST );
1018+ bpf_perf_event_output ( ctx , & events , BPF_F_CURRENT_CPU , event , sizeof ( * event ) );
10251019
10261020 return BPF_OK ;
10271021}
@@ -1117,7 +1111,7 @@ output_tcp(void *ctx, struct sock *sk, struct event_t *event) {
11171111 event -> skb_addr = (u64 ) sk ;
11181112 event -> type = EVENT_TYPE_KPROBE ;
11191113 event -> source = EVENT_SOURCE_TCP ;
1120- bpf_map_push_elem ( & events , event , BPF_EXIST );
1114+ bpf_perf_event_output ( ctx , & events , BPF_F_CURRENT_CPU , event , sizeof ( * event ) );
11211115}
11221116
11231117SEC ("kprobe/tcp_connect" )
0 commit comments