From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B6C8845910; Thu, 5 Sep 2024 18:11:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A2C6B42E5F; Thu, 5 Sep 2024 18:11:41 +0200 (CEST) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mails.dpdk.org (Postfix) with ESMTP id 3659342DFA for ; Thu, 5 Sep 2024 18:11:40 +0200 (CEST) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so874286a12.3 for ; Thu, 05 Sep 2024 09:11:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1725552699; x=1726157499; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1KwCnjEpflv3de0SFjsOdRgKApMebfICAz6HyK2bMiQ=; b=16riBmpylhxvc7QbYqNUC+wDk5BIls1Ps/t+oO3IzB1KO1oh1b4SD6u8ZcZ3i/cetH RfrgHS8XstbU7mFZl++khFZRvyMZgUjeffaS99gDkuGpGKLbOa+ThaFjbh9p5cshyahF bRGJCVOcoqidDfY4xJGTLJAbiMSKZpxoqt0zOl/duFiUEvjYZpIvcIri9LV15gocwWBJ yftJpcVL99fnNUGMdcwuAE4xpxZPhUJQ+6InQA114ttrrFj15r6rkWKZ2keiOaynKnV0 XNYeunxALNZlhaEdYwjWSZx3ViUpPbLIUsg5QbR9+sjiWMaT67rdO+16gHOHr8S2ZOS7 FLVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725552699; x=1726157499; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1KwCnjEpflv3de0SFjsOdRgKApMebfICAz6HyK2bMiQ=; b=QOObYq/4yLZoHYWsR+8praVs+RcmErTfzvRPLUV4L26XhpyybpI/z0f6cr+zzYFTe9 /pCHoTWz9BG843xWerKv6HGy8C3+2d3xNeUw7Z0LpTwCBeQOgsD9ApRUGawQDGwI/1h4 iIqbN45cuj85JuHHsxqWocxzjLvbFs0YOl+uPO9oMhIzirX7FdZo3G0K8TrPi/cWO4in Fjp1R73P1uLxYotWcPwvC+ytKdjWUeG2B1+2OJjjOTjxDAgKk2UirNO7r9sCDDOBsEVM GtidKgihXVV0pHXsx32/X3Zu3m9MIl3cwTlCV31j+lKsh50OAt/DMLUMd7OlKFtwkmKz WqIA== X-Gm-Message-State: AOJu0YwM9H9H+P313xjsX8CoYD6LMuqB+3HRdtAkVbDsu8do6aJgupho qRxkO8oYCKX/eXbkXv3culnP2ppOrWGnDdal5OZsMSlBgTDOrgn1W7byXdLL7sbukDlGk/frR3f zuT8= X-Google-Smtp-Source: AGHT+IH5US9Rr8MbBj7VSNRGaYuZgBf3nylp4mDBTNLtSj8U0a2wfdIEf4RYnMn5w0PV3l3f3r91FA== X-Received: by 2002:a17:902:da91:b0:205:3525:81bd with SMTP id d9443c01a7336-205352585f6mr225233825ad.29.1725552699290; Thu, 05 Sep 2024 09:11:39 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206aea55b77sm30250815ad.205.2024.09.05.09.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 09:11:38 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: "Acked-by : Ferruh Yigit" , Stephen Hemminger , Ofer Dagan Subject: [PATCH] net/pcap: use pcap_next_ex to track errors Date: Thu, 5 Sep 2024 09:10:40 -0700 Message-ID: <20240905161129.73553-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Signed-off-by: Stephen Hemminger --- 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