DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pascal Mazon <pascal.mazon@6wind.com>
To: keith.wiles@intel.com
Cc: dev@dpdk.org, Pascal Mazon <pascal.mazon@6wind.com>
Subject: [dpdk-dev] [PATCH] net/tap: do not send packets larger than MTU
Date: Wed, 15 Mar 2017 16:09:08 +0100	[thread overview]
Message-ID: <f226901ceb3bae7a52b8fd896544b73ebb51301d.1489590540.git.pascal.mazon@6wind.com> (raw)

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(+)

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 */
 };
 
-- 
2.8.0.rc0

             reply	other threads:[~2017-03-15 15:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 15:09 Pascal Mazon [this message]
2017-03-15 21:48 ` Wiles, Keith
2017-03-24 15:29   ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f226901ceb3bae7a52b8fd896544b73ebb51301d.1489590540.git.pascal.mazon@6wind.com \
    --to=pascal.mazon@6wind.com \
    --cc=dev@dpdk.org \
    --cc=keith.wiles@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).