Skip to content

Commit

Permalink
net/pcap: use pcap_next_ex API for unblocking Rx
Browse files Browse the repository at this point in the history
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: 4c17330 ("pcap: add new driver")
Cc: stable@dpdk.org

Reported-by: Ofer Dagan <ofer.d@claroty.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Tested-by: Ofer Dagan <ofer.d@claroty.com>
  • Loading branch information
shemminger authored and ferruhy committed Oct 13, 2024
1 parent e71db26 commit f2e424a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ Noa Ezra <noae@mellanox.com>
Nobuhiro Miki <nmiki@yahoo-corp.jp>
Norbert Ciosek <norbertx.ciosek@intel.com>
Odi Assli <odia@nvidia.com>
Ofer Dagan <ofer.d@claroty.com>
Ognjen Joldzic <ognjen.joldzic@gmail.com>
Ola Liljedahl <ola.liljedahl@arm.com>
Oleg Polyakov <olegp123@walla.co.il>
Expand Down
33 changes: 17 additions & 16 deletions drivers/net/pcap/pcap_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -294,43 +294,44 @@ 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)) {
pcap_q->rx_stat.rx_nombuf++;
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;
Expand Down

0 comments on commit f2e424a

Please sign in to comment.