Skip to content

Commit f2e424a

Browse files
shemmingerferruhy
authored andcommitted
net/pcap: use pcap_next_ex API for unblocking Rx
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: [email protected] Reported-by: Ofer Dagan <[email protected]> Signed-off-by: Stephen Hemminger <[email protected]> Tested-by: Ofer Dagan <[email protected]>
1 parent e71db26 commit f2e424a

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ Noa Ezra <[email protected]>
10921092
Nobuhiro Miki <[email protected]>
10931093
Norbert Ciosek <[email protected]>
10941094
Odi Assli <[email protected]>
1095+
Ofer Dagan <[email protected]>
10951096
Ognjen Joldzic <[email protected]>
10961097
Ola Liljedahl <[email protected]>
10971098
Oleg Polyakov <[email protected]>

drivers/net/pcap/pcap_ethdev.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static uint16_t
274274
eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
275275
{
276276
unsigned int i;
277-
struct pcap_pkthdr header;
277+
struct pcap_pkthdr *header;
278278
struct pmd_process_private *pp;
279279
const u_char *packet;
280280
struct rte_mbuf *mbuf;
@@ -294,43 +294,44 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
294294
*/
295295
for (i = 0; i < nb_pkts; i++) {
296296
/* Get the next PCAP packet */
297-
packet = pcap_next(pcap, &header);
298-
if (unlikely(packet == NULL))
297+
int ret = pcap_next_ex(pcap, &header, &packet);
298+
if (ret != 1) {
299+
if (ret == PCAP_ERROR)
300+
pcap_q->rx_stat.err_pkts++;
301+
299302
break;
303+
}
300304

301305
mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool);
302306
if (unlikely(mbuf == NULL)) {
303307
pcap_q->rx_stat.rx_nombuf++;
304308
break;
305309
}
306310

307-
if (header.caplen <= rte_pktmbuf_tailroom(mbuf)) {
311+
uint32_t len = header->caplen;
312+
if (len <= rte_pktmbuf_tailroom(mbuf)) {
308313
/* pcap packet will fit in the mbuf, can copy it */
309-
rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet,
310-
header.caplen);
311-
mbuf->data_len = (uint16_t)header.caplen;
314+
rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len);
315+
mbuf->data_len = len;
312316
} else {
313317
/* Try read jumbo frame into multi mbufs. */
314318
if (unlikely(eth_pcap_rx_jumbo(pcap_q->mb_pool,
315-
mbuf,
316-
packet,
317-
header.caplen) == -1)) {
319+
mbuf, packet, len) == -1)) {
318320
pcap_q->rx_stat.err_pkts++;
319321
rte_pktmbuf_free(mbuf);
320322
break;
321323
}
322324
}
323325

324-
mbuf->pkt_len = (uint16_t)header.caplen;
325-
*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset,
326-
rte_mbuf_timestamp_t *) =
327-
(uint64_t)header.ts.tv_sec * 1000000 +
328-
header.ts.tv_usec;
326+
mbuf->pkt_len = len;
327+
uint64_t us = (uint64_t)header->ts.tv_sec * US_PER_S + header->ts.tv_usec;
328+
329+
*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us;
329330
mbuf->ol_flags |= timestamp_rx_dynflag;
330331
mbuf->port = pcap_q->port_id;
331332
bufs[num_rx] = mbuf;
332333
num_rx++;
333-
rx_bytes += header.caplen;
334+
rx_bytes += len;
334335
}
335336
pcap_q->rx_stat.pkts += num_rx;
336337
pcap_q->rx_stat.bytes += rx_bytes;

0 commit comments

Comments
 (0)