[dpdk-dev] net/tap: do not send packets larger than MTU

Message ID f226901ceb3bae7a52b8fd896544b73ebb51301d.1489590540.git.pascal.mazon@6wind.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Pascal Mazon March 15, 2017, 3:09 p.m. UTC
  Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
---
 drivers/net/tap/rte_eth_tap.c | 6 ++++++
 drivers/net/tap/rte_eth_tap.h | 1 +
 2 files changed, 7 insertions(+)
  

Comments

Wiles, Keith March 15, 2017, 9:48 p.m. UTC | #1
> On Mar 15, 2017, at 11:09 PM, Pascal Mazon <pascal.mazon@6wind.com> wrote:
> 
> Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>

Acked-by: Keith Wiles <keith.wiles#intel.com>
> ---
> drivers/net/tap/rte_eth_tap.c | 6 ++++++
> drivers/net/tap/rte_eth_tap.h | 1 +
> 2 files changed, 7 insertions(+)

Regards,
Keith
  
Ferruh Yigit March 24, 2017, 3:29 p.m. UTC | #2
On 3/15/2017 9:48 PM, Wiles, Keith wrote:
> 
>> On Mar 15, 2017, at 11:09 PM, Pascal Mazon <pascal.mazon@6wind.com> wrote:
>>
>> Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
> 
> Acked-by: Keith Wiles <keith.wiles#intel.com>

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

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 69fa282ca176..17496501e6ba 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -340,14 +340,19 @@  pmd_tx_burst(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 	struct tx_queue *txq = queue;
 	uint16_t num_tx = 0;
 	unsigned long num_tx_bytes = 0;
+	uint32_t max_size;
 	int i, n;
 
 	if (unlikely(nb_pkts == 0))
 		return 0;
 
+	max_size = *txq->mtu + (ETHER_HDR_LEN + ETHER_CRC_LEN + 4);
 	for (i = 0; i < nb_pkts; i++) {
 		/* copy the tx frame data */
 		mbuf = bufs[num_tx];
+		/* stats.errs will be incremented */
+		if (rte_pktmbuf_pkt_len(mbuf) > max_size)
+			break;
 		n = write(txq->fd,
 			  rte_pktmbuf_mtod(mbuf, void *),
 			  rte_pktmbuf_pkt_len(mbuf));
@@ -707,6 +712,7 @@  tap_setup_queue(struct rte_eth_dev *dev,
 
 	rx->fd = fd;
 	tx->fd = fd;
+	tx->mtu = &dev->data->mtu;
 
 	return fd;
 }
diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h
index 1ad6ad88796a..9546411bd790 100644
--- a/drivers/net/tap/rte_eth_tap.h
+++ b/drivers/net/tap/rte_eth_tap.h
@@ -60,6 +60,7 @@  struct rx_queue {
 
 struct tx_queue {
 	int fd;
+	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
 	struct pkt_stats stats;         /* Stats for this TX queue */
 };