DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/pcap: use pcap_next_ex to track errors
@ 2024-09-05 16:10 Stephen Hemminger
  2024-10-10  2:14 ` Ferruh Yigit
  2024-10-13 15:47 ` Ferruh Yigit
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Hemminger @ 2024-09-05 16:10 UTC (permalink / raw)
  To: dev; +Cc: Acked-by : Ferruh Yigit, Stephen Hemminger, Ofer Dagan

Use pcap_next_ex rather than just pcap_next because pcap_next
always blocks if there is no packets to receive.

Bugzilla ID: 1526
Reported-by: Ofer Dagan <ofer.d@claroty.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/pcap/pcap_ethdev.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index bfec085045..261997be5c 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -274,7 +274,7 @@ static uint16_t
 eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
 	unsigned int i;
-	struct pcap_pkthdr header;
+	struct pcap_pkthdr *header;
 	struct pmd_process_private *pp;
 	const u_char *packet;
 	struct rte_mbuf *mbuf;
@@ -294,9 +294,13 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	 */
 	for (i = 0; i < nb_pkts; i++) {
 		/* Get the next PCAP packet */
-		packet = pcap_next(pcap, &header);
-		if (unlikely(packet == NULL))
+		int ret = pcap_next_ex(pcap, &header, &packet);
+		if (ret != 1) {
+			if (ret == PCAP_ERROR)
+				pcap_q->rx_stat.err_pkts++;
+
 			break;
+		}
 
 		mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool);
 		if (unlikely(mbuf == NULL)) {
@@ -304,33 +308,30 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 			break;
 		}
 
-		if (header.caplen <= rte_pktmbuf_tailroom(mbuf)) {
+		uint32_t len = header->caplen;
+		if (len <= rte_pktmbuf_tailroom(mbuf)) {
 			/* pcap packet will fit in the mbuf, can copy it */
-			rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet,
-					header.caplen);
-			mbuf->data_len = (uint16_t)header.caplen;
+			rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len);
+			mbuf->data_len = len;
 		} else {
 			/* Try read jumbo frame into multi mbufs. */
 			if (unlikely(eth_pcap_rx_jumbo(pcap_q->mb_pool,
-						       mbuf,
-						       packet,
-						       header.caplen) == -1)) {
+						       mbuf, packet, len) == -1)) {
 				pcap_q->rx_stat.err_pkts++;
 				rte_pktmbuf_free(mbuf);
 				break;
 			}
 		}
 
-		mbuf->pkt_len = (uint16_t)header.caplen;
-		*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset,
-			rte_mbuf_timestamp_t *) =
-				(uint64_t)header.ts.tv_sec * 1000000 +
-				header.ts.tv_usec;
+		mbuf->pkt_len = len;
+		uint64_t us = (uint64_t)header->ts.tv_sec * US_PER_S + header->ts.tv_usec;
+
+		*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us;
 		mbuf->ol_flags |= timestamp_rx_dynflag;
 		mbuf->port = pcap_q->port_id;
 		bufs[num_rx] = mbuf;
 		num_rx++;
-		rx_bytes += header.caplen;
+		rx_bytes += len;
 	}
 	pcap_q->rx_stat.pkts += num_rx;
 	pcap_q->rx_stat.bytes += rx_bytes;
-- 
2.45.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net/pcap: use pcap_next_ex to track errors
  2024-09-05 16:10 [PATCH] net/pcap: use pcap_next_ex to track errors Stephen Hemminger
@ 2024-10-10  2:14 ` Ferruh Yigit
  2024-10-10  2:21   ` Stephen Hemminger
  2024-10-13 15:47 ` Ferruh Yigit
  1 sibling, 1 reply; 6+ messages in thread
From: Ferruh Yigit @ 2024-10-10  2:14 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Ofer Dagan, Tyler Retzlaff

On 9/5/2024 5:10 PM, Stephen Hemminger wrote:
> Use pcap_next_ex rather than just pcap_next because pcap_next
> always blocks if there is no packets to receive.
> 

Hi Stephen,

Do you know if using 'pcap_next_ex()' (instead of 'pcap_next()') has any
dependency impact?
Like can we rely that all libraries that support 'pcap_next()', also
supports 'pcap_next_ex()'?


> Bugzilla ID: 1526
> Reported-by: Ofer Dagan <ofer.d@claroty.com>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>

Hi Ofer, Can you please verify this fix?


> ---
>  drivers/net/pcap/pcap_ethdev.c | 33 +++++++++++++++++----------------
>  1 file changed, 17 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
> index bfec085045..261997be5c 100644
> --- a/drivers/net/pcap/pcap_ethdev.c
> +++ b/drivers/net/pcap/pcap_ethdev.c
> @@ -274,7 +274,7 @@ static uint16_t
>  eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
>  {
>  	unsigned int i;
> -	struct pcap_pkthdr header;
> +	struct pcap_pkthdr *header;
>  	struct pmd_process_private *pp;
>  	const u_char *packet;
>  	struct rte_mbuf *mbuf;
> @@ -294,9 +294,13 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
>  	 */
>  	for (i = 0; i < nb_pkts; i++) {
>  		/* Get the next PCAP packet */
> -		packet = pcap_next(pcap, &header);
> -		if (unlikely(packet == NULL))
> +		int ret = pcap_next_ex(pcap, &header, &packet);
> +		if (ret != 1) {
> +			if (ret == PCAP_ERROR)
> +				pcap_q->rx_stat.err_pkts++;
> +
>  			break;
> +		}
>  
>  		mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool);
>  		if (unlikely(mbuf == NULL)) {
> @@ -304,33 +308,30 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
>  			break;
>  		}
>  
> -		if (header.caplen <= rte_pktmbuf_tailroom(mbuf)) {
> +		uint32_t len = header->caplen;
> +		if (len <= rte_pktmbuf_tailroom(mbuf)) {
>  			/* pcap packet will fit in the mbuf, can copy it */
> -			rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet,
> -					header.caplen);
> -			mbuf->data_len = (uint16_t)header.caplen;
> +			rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len);
> +			mbuf->data_len = len;
>  		} else {
>  			/* Try read jumbo frame into multi mbufs. */
>  			if (unlikely(eth_pcap_rx_jumbo(pcap_q->mb_pool,
> -						       mbuf,
> -						       packet,
> -						       header.caplen) == -1)) {
> +						       mbuf, packet, len) == -1)) {
>  				pcap_q->rx_stat.err_pkts++;
>  				rte_pktmbuf_free(mbuf);
>  				break;
>  			}
>  		}
>  
> -		mbuf->pkt_len = (uint16_t)header.caplen;
> -		*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset,
> -			rte_mbuf_timestamp_t *) =
> -				(uint64_t)header.ts.tv_sec * 1000000 +
> -				header.ts.tv_usec;
> +		mbuf->pkt_len = len;
> +		uint64_t us = (uint64_t)header->ts.tv_sec * US_PER_S + header->ts.tv_usec;
> +
> +		*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us;
>  		mbuf->ol_flags |= timestamp_rx_dynflag;
>  		mbuf->port = pcap_q->port_id;
>  		bufs[num_rx] = mbuf;
>  		num_rx++;
> -		rx_bytes += header.caplen;
> +		rx_bytes += len;
>  	}
>  	pcap_q->rx_stat.pkts += num_rx;
>  	pcap_q->rx_stat.bytes += rx_bytes;


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net/pcap: use pcap_next_ex to track errors
  2024-10-10  2:14 ` Ferruh Yigit
@ 2024-10-10  2:21   ` Stephen Hemminger
  2024-10-10  2:24     ` Ferruh Yigit
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2024-10-10  2:21 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Ofer Dagan, Tyler Retzlaff

On Thu, 10 Oct 2024 03:14:48 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> On 9/5/2024 5:10 PM, Stephen Hemminger wrote:
> > Use pcap_next_ex rather than just pcap_next because pcap_next
> > always blocks if there is no packets to receive.
> >   
> 
> Hi Stephen,
> 
> Do you know if using 'pcap_next_ex()' (instead of 'pcap_next()') has any
> dependency impact?
> Like can we rely that all libraries that support 'pcap_next()', also
> supports 'pcap_next_ex()'?

The code depends on libpcap, and that API has been in pcap since the
early days. See it in a version from 2003!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net/pcap: use pcap_next_ex to track errors
  2024-10-10  2:21   ` Stephen Hemminger
@ 2024-10-10  2:24     ` Ferruh Yigit
  2024-10-10  2:34       ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Ferruh Yigit @ 2024-10-10  2:24 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, Ofer Dagan, Tyler Retzlaff

On 10/10/2024 3:21 AM, Stephen Hemminger wrote:
> On Thu, 10 Oct 2024 03:14:48 +0100
> Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> 
>> On 9/5/2024 5:10 PM, Stephen Hemminger wrote:
>>> Use pcap_next_ex rather than just pcap_next because pcap_next
>>> always blocks if there is no packets to receive.
>>>   
>>
>> Hi Stephen,
>>
>> Do you know if using 'pcap_next_ex()' (instead of 'pcap_next()') has any
>> dependency impact?
>> Like can we rely that all libraries that support 'pcap_next()', also
>> supports 'pcap_next_ex()'?
> 
> The code depends on libpcap, and that API has been in pcap since the
> early days. See it in a version from 2003!
> 

Thanks for confirming. I assume it is same with the 'iphlpapi' that
windows uses.

Let wait a little more, it would be good if we get a test result from
Ofer first.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net/pcap: use pcap_next_ex to track errors
  2024-10-10  2:24     ` Ferruh Yigit
@ 2024-10-10  2:34       ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2024-10-10  2:34 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Ofer Dagan, Tyler Retzlaff

On Thu, 10 Oct 2024 03:24:42 +0100
Ferruh Yigit <ferruh.yigit@amd.com> wrote:

> On 10/10/2024 3:21 AM, Stephen Hemminger wrote:
> > On Thu, 10 Oct 2024 03:14:48 +0100
> > Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> >   
> >> On 9/5/2024 5:10 PM, Stephen Hemminger wrote:  
> >>> Use pcap_next_ex rather than just pcap_next because pcap_next
> >>> always blocks if there is no packets to receive.
> >>>     
> >>
> >> Hi Stephen,
> >>
> >> Do you know if using 'pcap_next_ex()' (instead of 'pcap_next()') has any
> >> dependency impact?
> >> Like can we rely that all libraries that support 'pcap_next()', also
> >> supports 'pcap_next_ex()'?  
> > 
> > The code depends on libpcap, and that API has been in pcap since the
> > early days. See it in a version from 2003!
> >   
> 
> Thanks for confirming. I assume it is same with the 'iphlpapi' that
> windows uses.
> 
> Let wait a little more, it would be good if we get a test result from
> Ofer first.
> 

I think the Windows build would have caught any issue.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] net/pcap: use pcap_next_ex to track errors
  2024-09-05 16:10 [PATCH] net/pcap: use pcap_next_ex to track errors Stephen Hemminger
  2024-10-10  2:14 ` Ferruh Yigit
@ 2024-10-13 15:47 ` Ferruh Yigit
  1 sibling, 0 replies; 6+ messages in thread
From: Ferruh Yigit @ 2024-10-13 15:47 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Ofer Dagan

On 9/5/2024 5:10 PM, Stephen Hemminger wrote:
> Use pcap_next_ex rather than just pcap_next because pcap_next
> always blocks if there is no packets to receive.
> 
> Bugzilla ID: 1526
> Fixes: 4c173302c307 ("pcap: add new driver")
> Cc: stable@dpdk.org
>
> Reported-by: Ofer Dagan <ofer.d@claroty.com>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
>

According Bugzilla comment:
Tested-by: Ofer Dagan <ofer.d@claroty.com>

Applied to dpdk-next-net/main, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-13 15:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-05 16:10 [PATCH] net/pcap: use pcap_next_ex to track errors Stephen Hemminger
2024-10-10  2:14 ` Ferruh Yigit
2024-10-10  2:21   ` Stephen Hemminger
2024-10-10  2:24     ` Ferruh Yigit
2024-10-10  2:34       ` Stephen Hemminger
2024-10-13 15:47 ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).