From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6B4FEA00C2; Mon, 23 May 2022 16:28:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 526FE4014F; Mon, 23 May 2022 16:28:02 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70111.outbound.protection.outlook.com [40.107.7.111]) by mails.dpdk.org (Postfix) with ESMTP id B362540141 for ; Mon, 23 May 2022 16:28:00 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FR+q1q9Gn2tZq+tVMF7+IGw9HB1niqXlmEIiogdQP9GIz53Ui1MzJARR0M4ckoJLx6aVxWB9oZqB/ui62f1p9CID+6bbeNlLe6RyKtDZVYhujNGXVPGjuwjQ5hRILxihVg2fg9bxvr6McgWVEHDWZ11oyvXN2OyYp584aX8cHnr4syiWWQf//lEDDG94PtpqD5szwfqt7AyWV+mmymtBCMhI1bUsJo9w+3V5e5vnjYk2gxUBRUKVrX7wsSy+hXWV3pxpH4drlFi5GiHyR0w+qFlNxlR7wbzODbts/RrL+VGIp/kF86FP8P8hTwKdnYrvo8nyGEkKfmYxaE/g5ZJ0yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pcIBjbs0VMLwdqnI5VJK8gKo1WarFBX6Fe7whAOplaI=; b=gsJJih8xA5gO5+Nh7Q5SdvMRLBbQviF5aARPJo2OvY1M3iLpgPsbgv0VMSWTTFg7ZSjYWynhrKWgiO9cvlQxD35z6fb/ReI4BtISn2dhTrz/Zam7CBhda0cub767vFa2Kf1KMjFgRcaMVw6mW3QumBkxaugN8FA2p6GjV8tQ4sBhmMerM3PfzOpWODYnhcFamE3e1J0TDTw+QrHlHbJlHYLoVjVHa9fW3xXwBAX+IIcFgpAINvFX/ziwD/DMerVuVntBEIAH4gTNnXVzXywP+1YGTRPwgQs7rmqt4OGj/Yh0ar7LtXSpysXAqa22CsxSwxKgcllGyLAp4qKmRQ6Yxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=cgstowernetworks.com; dmarc=pass action=none header.from=cgstowernetworks.com; dkim=pass header.d=cgstowernetworks.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cgstowernetworks.onmicrosoft.com; s=selector2-cgstowernetworks-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pcIBjbs0VMLwdqnI5VJK8gKo1WarFBX6Fe7whAOplaI=; b=dupoVPV3YXujqBQVkE8yl9/lUpEjUAAJQVCm2BOyFAikK4UWFrTcwJ4brNztJmwkUbbUpuxeTP9El1ucBfRDSiTK2cYRvID5AQtybIsTK1R3EcpZEwUl/1ynohF4gy/PyLmswbc/dIp08FgzOYk+/VyUJQEz2k99JtgaAU+/vvQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cgstowernetworks.com; Received: from AM0PR09MB3972.eurprd09.prod.outlook.com (2603:10a6:208:195::21) by AM0PR09MB2324.eurprd09.prod.outlook.com (2603:10a6:208:d9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.13; Mon, 23 May 2022 14:27:58 +0000 Received: from AM0PR09MB3972.eurprd09.prod.outlook.com ([fe80::4aa:657d:93c5:c2c1]) by AM0PR09MB3972.eurprd09.prod.outlook.com ([fe80::4aa:657d:93c5:c2c1%7]) with mapi id 15.20.5273.023; Mon, 23 May 2022 14:27:58 +0000 From: Ido Goshen To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org, Ido Goshen Subject: [PATCH v2] pcap: support MTU set Date: Mon, 23 May 2022 17:27:05 +0300 Message-Id: <20220523142705.60326-1-ido@cgstowernetworks.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: VI1PR0502CA0021.eurprd05.prod.outlook.com (2603:10a6:803:1::34) To AM0PR09MB3972.eurprd09.prod.outlook.com (2603:10a6:208:195::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e448c7f0-b9c9-402d-5529-08da3cc86f6a X-MS-TrafficTypeDiagnostic: AM0PR09MB2324:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jycXPU4GEw4zEYaztTQ/jpHyKVepqCZY0l4FvkC5zH8Q7OPVQk+jIs/fTTO+fG66vMVlFthH3B+cBw5ZMhp4Dm0JFERFSCMIKjGgs8RApSYB9UPrJ24mZSkmSCe/yyohwj64HsIgaIeOJcRrx5oiJupVwMnlqH7QejN/ezfdyt7A+6FdVCYLeAsxFRz7zE0uWWi6ERfX1MWu7/+QPdwQ9PHiA6FFlvCtkHVnKWw49lJshyhgpdw2dqjL4852M44M9acRkebro02ZwbM3m/PUM05g1wMj8MARBcXnvkEmHLDelHzlZSmznsCo4UIfTjpCmDbrsYcnh16guEn/PVU0e5gLeqgf5ipngI5NgEqmnF3tdBHmoJng+QV+CjHxTFjDaaak9c61AcFwcofINCEe/6xKstd+oQ2cVSTFO4sEF+xvUzM56kkEZiA2HVWlfRrn8XgmJTcmzYlMu26ygDGUtphSt7jAukfIHL4ygJxaHdkClgKPCUVk7LYu18XROdCJ5C8GAw34aSvdo/J66lY7aWUSg2RyOm6toXHBcnHrcOUlUR3Ax02UtrRU9e2mIsNR4W6GKe92T604bN4sk5SrRZSPkDlUgym+yh5CmyCejo1U/skis/HlLbpCb9CfAWp71qJdMJAE7eebem0Soa2ClJBxJsOnhvh921MNnDOUgJHSDaZx/1dBMiNPXg4uvdlaJZU8eIVSf63WTVXj7jOXGg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR09MB3972.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(136003)(346002)(366004)(396003)(376002)(39830400003)(8936002)(110136005)(6506007)(26005)(6512007)(508600001)(36756003)(5660300002)(6666004)(52116002)(6486002)(316002)(38350700002)(86362001)(66476007)(66556008)(66946007)(83380400001)(4326008)(38100700002)(1076003)(107886003)(186003)(41300700001)(2616005)(2906002)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?78aTqWuZvXKEo8U0t05weKrJRxDqZ3H/8G45c3/dM+Z69ODGnmmM4mBzN8lz?= =?us-ascii?Q?5NZLKCw6U5pbaIv8RAWHzOGroBOzY29DNwU7em7YA6c9ww0tJQgPi7s5L/2S?= =?us-ascii?Q?md3xluYr8uZhn2hZG6XF+omE039lmO2ARTpQRobpBL9C93BnWemVpbdJn6cL?= =?us-ascii?Q?b1NQBma+nb6lrW3I60RpX16r36KF/BfXGMPF1SpmCvUu/amyTJ8FHRdsfW5X?= =?us-ascii?Q?QYZRiPaXRKiUAd+kc6+oyapoqGN0GjbiDRNfl4SKIzHiOphUXljx0MPErXST?= =?us-ascii?Q?+21KuTRn3usGWjulHpZmAZEGt+dMxpg2IKjS2ZuSD+ZMuZF7ptTL+vWolJIj?= =?us-ascii?Q?b23ydTt57bm8b9VhJJhGFNbkhP4eks/Y9R2FkfCAxqVEnYV9H58STvtF5n52?= =?us-ascii?Q?GYcCsL/++3kCqRfTBELusQUTUiuT+C98c/y9h5OnuStbOEOTeG4xiQ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QduW0keWxFmJALLAbcw6+fe2v?= =?us-ascii?Q?QIPlsYt5jwKs8BpaICIvT645uOPo2euCsqLmf9pxKYAre44NPebt4DoOmaBe?= =?us-ascii?Q?Ykr2fgCxThXOMGPSLJotXQ6mvrQEAi8kbLSqke6E/3g9RY5Sg9QjJmB45tpe?= =?us-ascii?Q?Xds3BjURBRrqQJJmQD3Kg7RAiy0/UK5925VgPFUaFY+YctbrEy6PVwi1Jpz4?= =?us-ascii?Q?ITqaC5all/4MuU5IabqBQf2UWOB/O9WgInLHZ0R5SptQk8oU3MZ2MyKZALAF?= =?us-ascii?Q?Pj1PGOEBUI16+is7CtVnDSZJBROBbBxlHNoxXmNd5cZiGxoq5NetLgN6bfVU?= =?us-ascii?Q?kcaXtsCfSLi8lVhw/t/hdhh/NRiKuPNcuPAb+kiZSZbc8YbEzDVRV5WcV07K?= =?us-ascii?Q?P5H7Y0bqVG3HZLJIfx8OFPYteuEfKw4=3D?= X-OriginatorOrg: cgstowernetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: e448c7f0-b9c9-402d-5529-08da3cc86f6a X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB3972.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2022 14:27:58.8118 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fc9e9498-07e8-4b82-b4cf-365bba23cbbf X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tcLlp6sKLvFrAtIiaEDG5eXPELNbyWS7t0t3m08xgrZVyYy2h/BNAnOPzb0NCXYAy0yGZ4XkUdv3U531k0+4tQjLJ5T1+WG11hiZ1L1mW/o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR09MB2324 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Support rte_eth_dev_set_mtu by pcap vdevs Enforce mtu on rx/tx Bugzilla ID: 961 Signed-off-by: Ido Goshen --- v2: preserve pcap behavior to support max size packets by default --- drivers/net/pcap/pcap_ethdev.c | 35 +++++++++++++++++++++++++++++++--- lib/ethdev/rte_ethdev.c | 3 ++- lib/ethdev/rte_ethdev.h | 1 + 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index ec29fd6bc5..7c5fd6dd98 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -278,11 +278,12 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) const u_char *packet; struct rte_mbuf *mbuf; struct pcap_rx_queue *pcap_q = queue; + struct rte_eth_dev *dev = &rte_eth_devices[pcap_q->port_id]; uint16_t num_rx = 0; uint32_t rx_bytes = 0; pcap_t *pcap; - pp = rte_eth_devices[pcap_q->port_id].process_private; + pp = dev->process_private; pcap = pp->rx_pcap[pcap_q->queue_id]; if (unlikely(pcap == NULL || nb_pkts == 0)) @@ -303,6 +304,12 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) break; } + if (unlikely(header.caplen > dev->data->mtu)) { + pcap_q->rx_stat.err_pkts++; + rte_pktmbuf_free(mbuf); + break; + } + 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, @@ -378,6 +385,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *mbuf; struct pmd_process_private *pp; struct pcap_tx_queue *dumper_q = queue; + struct rte_eth_dev *dev = &rte_eth_devices[dumper_q->port_id]; uint16_t num_tx = 0; uint32_t tx_bytes = 0; struct pcap_pkthdr header; @@ -385,7 +393,7 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN]; size_t len, caplen; - pp = rte_eth_devices[dumper_q->port_id].process_private; + pp = dev->process_private; dumper = pp->tx_dumper[dumper_q->queue_id]; if (dumper == NULL || nb_pkts == 0) @@ -396,6 +404,12 @@ eth_pcap_tx_dumper(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) for (i = 0; i < nb_pkts; i++) { mbuf = bufs[i]; len = caplen = rte_pktmbuf_pkt_len(mbuf); + + if (unlikely(len > dev->data->mtu)) { + rte_pktmbuf_free(mbuf); + continue; + } + if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > sizeof(temp_data))) { caplen = sizeof(temp_data); @@ -464,13 +478,14 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_mbuf *mbuf; struct pmd_process_private *pp; struct pcap_tx_queue *tx_queue = queue; + struct rte_eth_dev *dev = &rte_eth_devices[tx_queue->port_id]; uint16_t num_tx = 0; uint32_t tx_bytes = 0; pcap_t *pcap; unsigned char temp_data[RTE_ETH_PCAP_SNAPLEN]; size_t len; - pp = rte_eth_devices[tx_queue->port_id].process_private; + pp = dev->process_private; pcap = pp->tx_pcap[tx_queue->queue_id]; if (unlikely(nb_pkts == 0 || pcap == NULL)) @@ -479,6 +494,12 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) for (i = 0; i < nb_pkts; i++) { mbuf = bufs[i]; len = rte_pktmbuf_pkt_len(mbuf); + + if (unlikely(len > dev->data->mtu)) { + rte_pktmbuf_free(mbuf); + continue; + } + if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > sizeof(temp_data))) { PMD_LOG(ERR, @@ -737,6 +758,7 @@ eth_dev_info(struct rte_eth_dev *dev, dev_info->max_rx_queues = dev->data->nb_rx_queues; dev_info->max_tx_queues = dev->data->nb_tx_queues; dev_info->min_rx_bufsize = 0; + dev_info->default_mtu = dev_info->max_mtu; return 0; } @@ -807,6 +829,12 @@ eth_stats_reset(struct rte_eth_dev *dev) return 0; } +static int eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) +{ + PMD_LOG(INFO, "mtu set %s %u\n", dev->device->name, mtu); + return 0; +} + static inline void infinite_rx_ring_free(struct rte_ring *pkts) { @@ -1004,6 +1032,7 @@ static const struct eth_dev_ops ops = { .link_update = eth_link_update, .stats_get = eth_stats_get, .stats_reset = eth_stats_reset, + .mtu_set = eth_mtu_set, }; static int diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 29a3d80466..75cb38a4b2 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -1186,7 +1186,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, } if (dev_conf->rxmode.mtu == 0) - dev->data->dev_conf.rxmode.mtu = RTE_ETHER_MTU; + dev->data->dev_conf.rxmode.mtu = dev_info.default_mtu; ret = eth_dev_validate_mtu(port_id, &dev_info, dev->data->dev_conf.rxmode.mtu); @@ -3126,6 +3126,7 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info) dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN; dev_info->max_mtu = UINT16_MAX; + dev_info->default_mtu = RTE_ETHER_MTU; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info); diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 04cff8ee10..8a2fd2f4ff 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -1861,6 +1861,7 @@ struct rte_eth_dev_info { Use if_indextoname() to translate into an interface name. */ uint16_t min_mtu; /**< Minimum MTU allowed */ uint16_t max_mtu; /**< Maximum MTU allowed */ + uint16_t default_mtu; const uint32_t *dev_flags; /**< Device flags */ uint32_t min_rx_bufsize; /**< Minimum size of Rx buffer. */ uint32_t max_rx_pktlen; /**< Maximum configurable length of Rx pkt. */ -- 2.17.1