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 82838A04FD; Mon, 30 May 2022 12:37:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7195A42B75; Mon, 30 May 2022 12:37:36 +0200 (CEST) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70120.outbound.protection.outlook.com [40.107.7.120]) by mails.dpdk.org (Postfix) with ESMTP id 2DEA0400D6 for ; Mon, 30 May 2022 12:37:35 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DePrKbWWFgVByGjVwrZ7xicZ39F6404mmKKDbukaUUqBjxaYE0mdFYoy5Syo+S1lohX/lVRp7bvbprwZflXSDlQLtU2VS+nivB8Ex7E5cdJZEWMCGoivx5MbpS86sV72BAabYFnJnQ6+qiShhFOk9IQSNcru69IbEjAsLx+2LIMFvbxThngt7HcWep9gF3faNs+1F2UVctdunSt/HHRSkjFx/KANJYXLRklYtL8c6NhfnbDRGUpUuSsXkz0TVb8tdJe24MIVlyHWC9U/3T4hqkoq/wmPwhpXM8WShjsvof79BLOvT4Polgf8Qo/fM0Ca90hu7AA6NuMzPVXxCgRJBg== 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=Pl4+f+z5yh//vsQiOIREeTtw0rmQ4XMUjxLuMGaVzDc=; b=Uxj0vbxlSQi5WiPkT2eqE8rxBTZAt5wfF5T0SZgwIHmItPebRcn44RByaj/MPZJxnY9a0TFKTPraosnNQZvH2DxgejjMgNWGqXMPvyJ4Mmkj0wFVF/zzad2x7sdg/sSe2pIAw3QylDsYGxSz3ViyhqVdpciaHrUIsklMzGKWLgMJsg770HAAzM1PxbtCnaEyFlVZQpg01bAfQxDOx1MlKm3ZXVqBhSWPIV+UofYk3W9E7qrgbKaauXKQxZnwwFcCFIeh/NKUBtXkMrs+UCeOxymfyG0gx2HIDfNXvEEB8PUhT/gggPKiwNbBIMrqbOa1HaqIAbsGvkwG+1aZXZiFFg== 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=Pl4+f+z5yh//vsQiOIREeTtw0rmQ4XMUjxLuMGaVzDc=; b=gLZg9sohORv0jPQkmuN6BkuaqqR2NT1pAgUdsNs1oMbQoobiktOGjoNocqc/Pm9aRssjXIIgd3kskute0BWUaBoPcTddpFg9RJGt/x4vepuH3/W2bTVwf40gIi73smKiVL6FfUmH71sTRZL0hUYbMPZYVzF0uQbwLF0eVvqX48M= 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 VE1PR09MB3344.eurprd09.prod.outlook.com (2603:10a6:803:12a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13; Mon, 30 May 2022 10:37:33 +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.5293.019; Mon, 30 May 2022 10:37:33 +0000 From: Ido Goshen To: ferruh.yigit@xilinx.com, stephen@networkplumber.org Cc: dev@dpdk.org, Ido Goshen Subject: [PATCH v3] pcap: support MTU set Date: Mon, 30 May 2022 13:36:47 +0300 Message-Id: <20220530103647.35626-1-ido@cgstowernetworks.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220317174347.110909-1-ido@cgstowernetworks.com> References: <20220317174347.110909-1-ido@cgstowernetworks.com> Content-Type: text/plain X-ClientProxiedBy: MRXP264CA0034.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:14::22) 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: a21456c6-62ce-4b93-bc30-08da4228677f X-MS-TrafficTypeDiagnostic: VE1PR09MB3344: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: qQ2d965pYGFOHClREb7bTdfgTM5cd23TBafQEQYegZcUYZ1Rsh9+Q18vFqK0JVZmh2CKCZt0gv7jc1PpIussWd35K7qYi/Nwhs0qJAteTh+CRbHNol1Pz/hDr2cAVEKTnuH2T64hRpOwjIUQVUSUm6GNy6/ZRJAK5y4NUrrWZqiTe+HMYVv+LXoUN+M+YQGYu8GZXo/+RZshamgarf2aAZqPgcTrF/pLyaYtUeo//2E2J/F+V8VZHDgl2xStSATjvrCgUP1VlDsND0zw7ojYo+bcJ8QbdK60/8QbRtaPXEE+lszPT1dMcBLpIhINeYTQQlqNIvKionoDE7aCe3P9JVMzBglSMnwvYLnErPUGMpX8fzxiwzZWX1x7/isPF2CLRPQ2OQ7CcBI15+n0wC7BdjJckERRFLB9OPB1bTVPqnyV5xhDMlU51fXJT1n9Fo1OF8c+6mwaV3pAdvdN4J2K0nVlok6O8HjK0Uj64smy+9oheeI+V8GkuPYPJLo2C5g7HQ8hq/MgJbAFGeyGLC0G+g4/ASgMzZQbLuHYgyYCEjlB+xiqx0NRG2mpq+JsMVGAHufudt+VaePo6LbNWN1RLhE4m20w8wMFPpRApsBd/HRkIOap7v0JC94QupOBmS6hvVrRcOm+yiafixleRttH9oYPpBKwTXwzKaZ5+plV3Cv/SmKgFatubdlDZxHyZXBkvd9JV25X3RyOJElZfeH0vw== 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)(39830400003)(376002)(136003)(396003)(366004)(346002)(1076003)(6506007)(6512007)(26005)(5660300002)(316002)(6666004)(8676002)(6486002)(8936002)(52116002)(66946007)(66476007)(186003)(36756003)(41300700001)(66556008)(508600001)(2906002)(38100700002)(107886003)(2616005)(86362001)(38350700002)(83380400001)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?+poiDcT5uHjWMNrACNTcmUMVh8O0QKM/8WqKsXDs7ZNKGPgCyFNeyysk52YJ?= =?us-ascii?Q?xmGWIh/RH24SttqYAA+M8Yz0lMMNDufof9DzCozM8gaQVhV/8/MoLp4uyzeG?= =?us-ascii?Q?u1llvuzhft50rYnfuzHI9h14lE33unmTRgFVYViETCmnett6J534SKzdzYnd?= =?us-ascii?Q?xGIyMta2FyZJvj3gP7s55wCHl4aFilpyhkgmMbws7SSqlX0aCUlx52xpcEGM?= =?us-ascii?Q?N7Ear1zePH1aU0y2AFlQI0Wezuib4N5BrV43W1NFz7nlMcZrwv9CjsD4Yn+/?= =?us-ascii?Q?1SPx+y6UXiWVOtxTj0UnqvNyTwyvRY35W3h6xFUPLUtnuD6DrWqDxF0agcIr?= =?us-ascii?Q?sFh4sOEdnNtmLVLPLaeNN2uD0z+HE7qUB8bMSzHO3AmP1RSeBjsa8V4+2rO2?= =?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ab3vBMs6Jr34P+tmqfQjlSZ0Km1vUjWkOx?= =?us-ascii?Q?TWIeE+ntaM0MiTGytyhM7C08fH5hid8JfEhxuW6Zr6EeGnOnT4nqyoKkO30o?= =?us-ascii?Q?iiTGAv+RGH8sbubEBjEVVY1CcPJdLrOVAx5Pipd4o3Ciak9Pk6aTxdSqiA15?= =?us-ascii?Q?yjYHand7KnZYZGnVnmPlBpx5IeekwsXCqzwnWpUySD+7CKUhO6moe4IazMsB?= =?us-ascii?Q?+kw9rwiVc/FXO+jLsn/wHT31JmIpdjPxzoQ+/8BV/Mxi3K+mPlAjHn1MKPFn?= =?us-ascii?Q?rBbMx3jaQ1xWdXow0p0ztaXfMDw9BfG8s7NDvFocwQ05icSOxCvrVZx8dhcN?= =?us-ascii?Q?XGTrKVPs6GWrDkYIt+drsLHIhAsIE/A6wPUq4hteGzKa5SibDoPZ0n3erbP3?= =?us-ascii?Q?36abAu0bcnslvE6AxL9tnDbPpHzU/LJjPC3XOj6CYYNA23Rp1cEJz6fMhsAx?= =?us-ascii?Q?dMKp39hxw3dTz4waWy/DGKmoqpZYfOg=3D?= X-OriginatorOrg: cgstowernetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: a21456c6-62ce-4b93-bc30-08da4228677f X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB3972.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2022 10:37:33.5144 (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: tSAFCYsZtVpt4XVPdMMkUc0f7RJa8r3nvvnmx131oqevGEIQSvDrGV5GvGz8YRz2B23zBKjNZ3fmUvLbntZBFlTgwDG/IOgs0JK5wPs/qCs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR09MB3344 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 --- v3: Preserve pcap behavior to support max size packets by default alternative to v2 in order to limit the code change to pcap only and avoid abi change. Enforce mtu only in case rte_eth_dev_set_mtu was explicitly called. v2: Preserve pcap behavior to support max size packets by default. --- drivers/net/pcap/pcap_ethdev.c | 44 +++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index ec29fd6bc5..2e7fff9579 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -93,6 +93,7 @@ struct pmd_internals { int single_iface; int phy_mac; unsigned int infinite_rx; + int is_mtu_set; }; struct pmd_process_private { @@ -278,11 +279,13 @@ 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]; + struct pmd_internals *internals = dev->data->dev_private; 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 +306,13 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) break; } + if (unlikely(header.caplen > dev->data->mtu) && + internals->is_mtu_set) { + 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 +388,8 @@ 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]; + struct pmd_internals *internals = dev->data->dev_private; uint16_t num_tx = 0; uint32_t tx_bytes = 0; struct pcap_pkthdr header; @@ -385,7 +397,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 +408,13 @@ 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) && + internals->is_mtu_set) { + rte_pktmbuf_free(mbuf); + continue; + } + if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > sizeof(temp_data))) { caplen = sizeof(temp_data); @@ -464,13 +483,15 @@ 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]; + struct pmd_internals *internals = dev->data->dev_private; 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 +500,13 @@ 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) && + internals->is_mtu_set) { + rte_pktmbuf_free(mbuf); + continue; + } + if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > sizeof(temp_data))) { PMD_LOG(ERR, @@ -807,6 +835,14 @@ 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); + struct pmd_internals *internals = dev->data->dev_private; + internals->is_mtu_set = 1; + return 0; +} + static inline void infinite_rx_ring_free(struct rte_ring *pkts) { @@ -1004,6 +1040,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 @@ -1233,6 +1270,7 @@ pmd_init_internals(struct rte_vdev_device *vdev, .addr_bytes = { 0x02, 0x70, 0x63, 0x61, 0x70, iface_idx++ } }; (*internals)->phy_mac = 0; + (*internals)->is_mtu_set = 0; data = (*eth_dev)->data; data->nb_rx_queues = (uint16_t)nb_rx_queues; data->nb_tx_queues = (uint16_t)nb_tx_queues; -- 2.17.1