net/tap: do not send packets larger than MTU

Signed-off-by: Pascal Mazon <pascal.mazon@6wind.com>
Acked-by: Keith Wiles <keith.wiles@intel.com>
This commit is contained in:
Pascal Mazon 2017-03-15 16:09:08 +01:00 committed by Ferruh Yigit
parent 2d5a4b62ff
commit 5025409c04
2 changed files with 7 additions and 0 deletions

View 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;
}

View 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 */
};