net/tap: do not send packets larger than MTU
authorPascal Mazon <pascal.mazon@6wind.com>
Wed, 15 Mar 2017 15:09:08 +0000 (16:09 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 4 Apr 2017 16:59:47 +0000 (18:59 +0200)
Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
Acked-by: Keith Wiles <keith.wiles@intel.com>
drivers/net/tap/rte_eth_tap.c
drivers/net/tap/rte_eth_tap.h

index c711b36..3345c1a 100644 (file)
@@ -305,14 +305,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));
@@ -646,6 +651,7 @@ tap_setup_queue(struct rte_eth_dev *dev,
 
        rx->fd = fd;
        tx->fd = fd;
+       tx->mtu = &dev->data->mtu;
 
        return fd;
 }
index 741ec53..deb594c 100644 (file)
@@ -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 */
 };