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 24EC1A0093; Thu, 17 Mar 2022 18:44:04 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A3C9140E28; Thu, 17 Mar 2022 18:44:03 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80119.outbound.protection.outlook.com [40.107.8.119]) by mails.dpdk.org (Postfix) with ESMTP id 98002407FF for ; Thu, 17 Mar 2022 18:44:01 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gIN1sjlUTRsJ8bIQIX2oMg2Kz7bMmslzm8dzn6UJVVypFSVPom35QhRwSlPOoXN7CwC2PN8yDqjPnDUkJTQqpLXD2ElvyB/IX57vX8c9FCjpUhd0+WmtVTPlzWSWouZEq1Hzi9LoIQXN+zl4aJ+CDfs+izacgtdXvNGigdhbEivKKllHofsdiul/4UrIUPZADREegyFzh8TR4a9v61Kz4Yv3ptiD3i++LX+5GBMYad95guJTkNMVMmy0NLGTh2LZznp+OI+K8e5BC76g+gezUdS2YwWfBjgAi0xBJMO3aqrO6ypLswOGDo0FJE+f6Ytp2NmsANAnHsy9inS//PSzMw== 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=/RnTmj4kwli1yrzyHE5FlnWMpOgmULkEdANAhiJfT1Q=; b=HJe6wGnFL53BcPwMClskFgdDGIiFJ39NYLdEVNdw/QJ0lBCELCxJtsS8WYQTb3gJTzkbqeSQzTGGyJNqTxVDVC+/tZMKEAhbxt7I4msZXQ85rSnWBXmc7hiYXUcH2EOYvKg51g89LZU1BuyY8hzzsNL7tsUu5kQvnUeRJbgFHAkwVa3dkthNVNVYR82noUAJjn2QV/iUNsMQnI+WCI081iKyiCLwKmDVNzOHsmIdI6MVkoAlLYs2/y1gXApzg+kA6CMwZ7s1Hjsjk1kHf67RJF/kOcxpIyE/gJ2C4AmA0pFup/DF5OAPcqCcG9UgvFgJ+VR+zajG+ifWpfmLItEylQ== 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=/RnTmj4kwli1yrzyHE5FlnWMpOgmULkEdANAhiJfT1Q=; b=WyUbvW0YM6AKNkyZdrzwy4nctSl0Ad/VrtVYftq+ISph6QtRb3DizQMiN2rmSSVDrI4nia2BOh/0CgL65dEA/dP4HqC9V3XgJwZLKss0rViViGK1OBx4A9gJJBcKig38J0ICzKVBaU27he5lUkwlIlEwJ2OY2X0GRI7gOQjmegY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=cgstowernetworks.com; Received: from AS4PR09MB5525.eurprd09.prod.outlook.com (2603:10a6:20b:4c0::18) by AM0PR09MB4290.eurprd09.prod.outlook.com (2603:10a6:20b:167::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.16; Thu, 17 Mar 2022 17:44:00 +0000 Received: from AS4PR09MB5525.eurprd09.prod.outlook.com ([fe80::b069:f286:651f:ce78]) by AS4PR09MB5525.eurprd09.prod.outlook.com ([fe80::b069:f286:651f:ce78%9]) with mapi id 15.20.5081.017; Thu, 17 Mar 2022 17:44:00 +0000 From: ido g To: Ferruh Yigit Cc: dev@dpdk.org, ido g Subject: [PATCH] net/pcap: support MTU set Date: Thu, 17 Mar 2022 19:43:47 +0200 Message-Id: <20220317174347.110909-1-ido@cgstowernetworks.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: VE1PR03CA0017.eurprd03.prod.outlook.com (2603:10a6:802:a0::29) To AS4PR09MB5525.eurprd09.prod.outlook.com (2603:10a6:20b:4c0::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f377e0f0-cffb-451b-1a5d-08da083db83e X-MS-TrafficTypeDiagnostic: AM0PR09MB4290: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: P45l/Vt8TEnKoT2GDhmY7gwhxAH2PlLAyi/MMHLr17NCyIQfj1P57VEkxtD2MZfYIAWSII9uQk7EvF6Gx4Qcronp2Hj9I4H091xR9uXWNCxQMLAM1EdiPXXzMRRbeH9aEs7wBLz9EkypCdBxoriJDhIG3GPBLbqVEthKGTd+jdfMw2YCPyzm7sbdXcnZQrWM6zWy+z1CwiK92AiZcOxm61UWMqX+m2/1gwED+U5Jfo9lgFDU9UO7Yj6XTjyyPX7PIvLuAPFT/XhJwLQrFUFnsDt8ylmyWxv2LswXGKWbLwSzQ6eH6K7qqdR+pQEUYjZ/6a2pH8dQdMZ605/QgCvqAPQ3uwsyfhUy1EJ8R2MavERkh19L2drOAabOxW5U6Es7XLP6IY1RuuhfUurnT8Lx/cx0UXF3CE7bNAc/gI7UA6XTgeWak016HumTAv7QzU2VDU/B6eRGw8rU67oi3PKmcqVgvMLiA63QQo7jztGV5usEWasaFBM8PxNDnYHB3wn2f4Yt1Gwuw9Jo9eSqvddrosApBjeU2pgWd8/0cWreC/pfiS/8DE3pKsLfGbJU9u1ckwxgaRGHs+mLRrhQlC4rlYGZ2wTmZXnLi51IKXKrDKQKkjzITQt8kVGIf7GrbjOGiNo9rp397Trgufd1uT/BS6nJ/Rf78M+hfx/BxKyRs9knXqJP9Yemn+EbQm1ocXZyq32CVavr4rIwYog3bNE2kZoH2QaQXTn9/y/L8jUZ1TqZnSOIiM6Q76Thj5Lq1bpZfU3C4e1v4dzK8dG2hQOF9erwcKnLcjM8mcqLt0fC314= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS4PR09MB5525.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(39830400003)(366004)(136003)(396003)(346002)(376002)(107886003)(83380400001)(186003)(1076003)(26005)(4326008)(38350700002)(38100700002)(8936002)(5660300002)(8676002)(66556008)(66476007)(66946007)(2906002)(6666004)(508600001)(2616005)(52116002)(6512007)(316002)(966005)(6486002)(6916009)(86362001)(6506007)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?iyLN+ixwA9VXMvKi7JWEOK6SxA1aW9TwLfaQKPxFwHKDHCgt4fuT1hd9pkFJ?= =?us-ascii?Q?1udAWpiCeEIkzgbnWoQ8IUeo7AkTWw6jCHuJqISru2TXvjB/epLHLy4BzUe5?= =?us-ascii?Q?ozryRqS+2M2DXRm303ipyKw3lzHsXEyBMovcUq+N9uher2aBZ+Msax7SEv8e?= =?us-ascii?Q?3/67oeLvDWCKNKp8yap9WfFSDwnMu2CloXEhO68tOV7AjLBmfkmsgq4SIxLu?= =?us-ascii?Q?kq5aCuAuptY6/ZCyh5RTfrGHiZwgOsIbAFoOTv/qFzRPza2QlzWJmestECKJ?= =?us-ascii?Q?kJaoJy+ZIcb5bJ4iRd2cZsE+lfM8Eafs1urhdvft1M6Wt7gvQtjOVu6Iu+Hz?= =?us-ascii?Q?OcdWqgndtvr0e9olUAEBiLfNnk/5HU4z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ZiVPvC8FmoWlB2+Rmet3XLVgaR/FG8h2f23txrG4kWFB7V+vmwFqp6oAEtXj?= =?us-ascii?Q?56QjvPiTWxQ7lEcDxx5W66tCYjuWsqhMjECw60RGELwJ9hWLHZ2RSZu8mBVb?= =?us-ascii?Q?FYtMCrBvyXyF3mB5Eq5uFzLcY0JkJwJ+9XB39k7OmCLaas/jBZkl2ujiKbub?= =?us-ascii?Q?fBzuhIVA/b6HK4o0BBvjYjCiyQ9tY8LSWPNom6vsnNBmsp0W503wAA=3D=3D?= X-OriginatorOrg: cgstowernetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: f377e0f0-cffb-451b-1a5d-08da083db83e X-MS-Exchange-CrossTenant-AuthSource: AS4PR09MB5525.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2022 17:44:00.4701 (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: gFWBObTYSH2AMRQP+ZHzuITQ9MijQ1XnfHgIPwQk1LoEOlQ+53GFDxrGfg4Ek47EJvTW5EQ/eS7a2moNi92dHXHzl71gdY3Qm50ipdktt2A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR09MB4290 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 For more details see https://bugs.dpdk.org/show_bug.cgi?id=961 Signed-off-by: ido g --- drivers/net/pcap/pcap_ethdev.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index ec29fd6bc5..476d03c6b1 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, @@ -807,6 +828,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 +1031,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 -- 2.17.1