@@ -280,17 +280,6 @@ static inline void calculate_timestamp(struct dpdk_ts_helper *helper,struct time
280280	timeradd (& (helper -> start_time ), & cur_time , ts );
281281}
282282
283- static  void  dpdk_gather_data (unsigned char   * data , uint32_t  len , struct  rte_mbuf  * mbuf )
284- {
285- 	uint32_t  total_len  =  0 ;
286- 	while  (mbuf  &&  (total_len + mbuf -> data_len ) <  len  ){
287- 		rte_memcpy (data + total_len , rte_pktmbuf_mtod (mbuf ,void  * ),mbuf -> data_len );
288- 		total_len += mbuf -> data_len ;
289- 		mbuf = mbuf -> next ;
290- 	}
291- }
292- 
293- 
294283static  int  dpdk_read_with_timeout (pcap_t  * p , struct  rte_mbuf  * * pkts_burst , const  uint16_t  burst_cnt ){
295284	struct  pcap_dpdk  * pd  =  (struct  pcap_dpdk * )(p -> priv );
296285	int  nb_rx  =  0 ;
@@ -331,10 +320,9 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
331320	// In DPDK, pkt_len is sum of lengths for all segments. And data_len is for one segment 
332321	uint32_t  pkt_len  =  0 ;
333322	uint32_t  caplen  =  0 ;
334- 	u_char  * bp  =  NULL ;
323+ 	const   u_char  * bp  =  NULL ;
335324	int  i = 0 ;
336325	int  pkt_cnt  =  0 ;
337- 	u_char  * large_buffer = NULL ;
338326	int  timeout_ms  =  p -> opt .timeout ;
339327
340328	/* 
@@ -394,22 +382,8 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
394382			// volatile prefetch 
395383			rte_prefetch0 (rte_pktmbuf_mtod (m , void  * ));
396384			bp  =  NULL ;
397- 			if  (m -> nb_segs  ==  1 )
398- 			{
399- 				bp  =  rte_pktmbuf_mtod (m , u_char  * );
400- 			}else {
401- 				// use fast buffer pcap_tmp_buf if pkt_len is small, no need to call malloc and free 
402- 				if  ( pkt_len  <= RTE_ETH_PCAP_SNAPLEN )
403- 				{
404- 					dpdk_gather_data (pd -> pcap_tmp_buf , RTE_ETH_PCAP_SNAPLEN , m );
405- 					bp  =  pd -> pcap_tmp_buf ;
406- 				}else {
407- 					// need call free later 
408- 					large_buffer  =  (u_char  * )malloc (caplen * sizeof (u_char ));
409- 					dpdk_gather_data (large_buffer , caplen , m );
410- 					bp  =  large_buffer ;
411- 				}
412- 
385+ 			if  (caplen  <  sizeof (pd -> pcap_tmp_buf )) {
386+ 				bp  =  rte_pktmbuf_read (m , 0 , caplen , pd -> pcap_tmp_buf );
413387			}
414388			if  (bp ){
415389				if  (p -> fcode .bf_insns == NULL  ||  pcapint_filter (p -> fcode .bf_insns , bp , pcap_header .len , pcap_header .caplen )){
@@ -420,10 +394,6 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
420394			}
421395			//free all pktmbuf 
422396			rte_pktmbuf_free (m );
423- 			if  (large_buffer ){
424- 				free (large_buffer );
425- 				large_buffer = NULL ;
426- 			}
427397		}
428398	}
429399	return  pkt_cnt ;
0 commit comments