Skip to content

Commit

Permalink
net/pcap: fix Rx with small buffers
Browse files Browse the repository at this point in the history
[ upstream commit 6653d81 ]

If the pkt pool contains only buffers smaller than the default headroom,
then the driver will compute an invalid buffer size (negative value cast
to an uint16_t).
Rely on the mbuf api to check how much space is available in the mbuf.

Fixes: 6eb0ae2 ("pcap: fix mbuf allocation")

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
  • Loading branch information
david-marchand authored and kevintraynor committed Sep 4, 2019
1 parent 01e9822 commit 11ab8dd
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions drivers/net/pcap/rte_eth_pcap.c
Expand Up @@ -188,7 +188,6 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
struct rte_mbuf *mbuf;
struct pcap_rx_queue *pcap_q = queue;
uint16_t num_rx = 0;
uint16_t buf_size;
uint32_t rx_bytes = 0;
pcap_t *pcap;

Expand All @@ -211,11 +210,7 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
if (unlikely(mbuf == NULL))
break;

/* Now get the space available for data in the mbuf */
buf_size = rte_pktmbuf_data_room_size(pcap_q->mb_pool) -
RTE_PKTMBUF_HEADROOM;

if (header.caplen <= buf_size) {
if (header.caplen <= rte_pktmbuf_tailroom(mbuf)) {
/* pcap packet will fit in the mbuf, can copy it */
rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet,
header.caplen);
Expand Down

0 comments on commit 11ab8dd

Please sign in to comment.