@@ -280,17 +280,6 @@ static inline void calculate_timestamp(struct dpdk_ts_helper *helper,struct time
280
280
timeradd (& (helper -> start_time ), & cur_time , ts );
281
281
}
282
282
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
-
294
283
static int dpdk_read_with_timeout (pcap_t * p , struct rte_mbuf * * pkts_burst , const uint16_t burst_cnt ){
295
284
struct pcap_dpdk * pd = (struct pcap_dpdk * )(p -> priv );
296
285
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
331
320
// In DPDK, pkt_len is sum of lengths for all segments. And data_len is for one segment
332
321
uint32_t pkt_len = 0 ;
333
322
uint32_t caplen = 0 ;
334
- u_char * bp = NULL ;
323
+ const u_char * bp = NULL ;
335
324
int i = 0 ;
336
325
int pkt_cnt = 0 ;
337
- u_char * large_buffer = NULL ;
338
326
int timeout_ms = p -> opt .timeout ;
339
327
340
328
/*
@@ -394,22 +382,8 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
394
382
// volatile prefetch
395
383
rte_prefetch0 (rte_pktmbuf_mtod (m , void * ));
396
384
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 );
413
387
}
414
388
if (bp ){
415
389
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
420
394
}
421
395
//free all pktmbuf
422
396
rte_pktmbuf_free (m );
423
- if (large_buffer ){
424
- free (large_buffer );
425
- large_buffer = NULL ;
426
- }
427
397
}
428
398
}
429
399
return pkt_cnt ;
0 commit comments