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 A75D6A0542; Mon, 6 Jun 2022 18:22:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 97983406B4; Mon, 6 Jun 2022 18:22:19 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80117.outbound.protection.outlook.com [40.107.8.117]) by mails.dpdk.org (Postfix) with ESMTP id EA4E34069C for ; Mon, 6 Jun 2022 18:22:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XIDY8P6R/PZsfjFsp5DMFYSR1zKPPKvL53BNQe8qVoIIGvvR8uM0o4wUhyW40vMyh9QaXHF/aNl6L0UQArKmcA7/FyyHnFSRzLJ2nvBfTRxclWLqlYFcQmxFen2zTdHPHSHlH3Wy73ffovRvkt/z1LO8kFHCpQ4A1E+LMInVy7jNF1FT63/AxfH8oEQrMcC6uZHFRwmEgQocc95mZNcetwE1p48b0YuWwRfuw+NR1GVK9ky/UhilulXQimRPN3mtsDCCzlwuHb7AxvegHbSDUZfxn0HoBYOkSdfVp+jrXeea6VK+akn6RyQhMv0BZGmHHElPnwEuSMoCwpzuPu6zpg== 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=yhL2/tTWSxeMJ8DbK3U1Joyx9xt1maRRcSOE27Tt7FU=; b=XIhnHfjxENXQlRN3YGLniZRRsXNsuZtf1HCrNT12BpXfi+A5++5QZCjiaQ760nal++NNQTZL7UD0D6ZxOsYy6ZAKEnr8hNbUZRMJnD8iN6vBsZu+hKiCGi51lcE9FNj9P044PMD36DepCzDJQs0B77lzWqT0m3coRgRnX/0ipd5JUvsip4df9Lh7HNozsCO2+3hZH647lRNVYn9MfunGXgE6dO4hkfpRibG/cH1nfvnX7mT/zcdoJWzP7OCS0wo6uEYVyxivzr/j+C/t8qxK1UDjLiRTBPJrBuxbHbNF2/041UC3YZjAQhKo3gYofJx6POlKwHg+b0divSl/Qb+Lhw== 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=yhL2/tTWSxeMJ8DbK3U1Joyx9xt1maRRcSOE27Tt7FU=; b=oHen2kPSJqUtQqHS2k01okGBZOhJSEXExCqn/5rL55wgZL/V7KcfqR/yl9J6gpy44eAWJ/zH+CY4BACR7kMDxK350Q5D0HuNU1TN1Ck06hWBwbPW5fYeFrr7AOiWNSufx/OX3soql0OCQ3jyZ6sM8v5s3bq35K+2hMUVElpmp9E= 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 AM9PR09MB4961.eurprd09.prod.outlook.com (2603:10a6:20b:301::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.13; Mon, 6 Jun 2022 16:22:16 +0000 Received: from AM0PR09MB3972.eurprd09.prod.outlook.com ([fe80::d0d6:ba99:48ac:5e72]) by AM0PR09MB3972.eurprd09.prod.outlook.com ([fe80::d0d6:ba99:48ac:5e72%6]) with mapi id 15.20.5314.019; Mon, 6 Jun 2022 16:22:15 +0000 From: Ido Goshen To: ferruh.yigit@xilinx.com, stephen@networkplumber.org Cc: dev@dpdk.org, Ido Goshen Subject: [PATCH v4] pcap: support MTU set Date: Mon, 6 Jun 2022 19:21:47 +0300 Message-Id: <20220606162147.57218-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: VI1P195CA0080.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:59::33) 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: 97b28104-3bce-4b2b-4189-08da47d8b839 X-MS-TrafficTypeDiagnostic: AM9PR09MB4961: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: c2314Eqac70d9RSoebIDFQanVZeoIAxV9P1gA0QPPpYBNoLlIm+5ztvBIBv2or9gLh4LXd9qO4iugKmi7IE5Hll6fWLmcNgHc0/7Y4IbbIrYLbtDjPIVi2lCgssyDsVZLWZtjc86R1wqboswQAO0kpergg0hWvxwyRqE2rWrQR12FbwO9lhorub9MeXCbN9JpVxggOUZr3ToTuxa5N/fg9OfbojcpNw+5XBFrvIMkjQ0Jp8XRqb9+LGPhkNZKKo5zDosKcLiVNBzWbxR4z1xOipNZiNQ9Mxqr6HO9wJ7u8o40orbZBnpZKtdybdzfI0v28L6gdEv/Ha4RuLQto+pX+V7yxeVxturAxzmaPUsFpoC12rOOACVRuBTAuPQkjog/RLIzeMVhFZuN6Vbsc77+EGfz/tYdpdhnMb5Dd/d1vy8HSJz+ysy5zL+/NUGFUaXMeuqlzhhI61R/Fq0X1OVZLoi3+qfQxWGqvTHLjl4w9RDP5H+ZJMH12eHTdrb1/Bo8wa9v6gO2A8jRp0I/8BFjEp39pUk/4mkR7c04cMaOWAtQ6IKOhAxfow+EKaIGjBbEhgqJm2NQMKulqnBXSvPnWFSvtKIb8xUI9gqcTsrFRhZqps1s8qiM4Jvpj+LrKFw+mwSG3PDZB9/afkyruNTTa4C6+tgXp6N2nhyWM+POquNLD66dYUXPZTJpy72z+kz2sl8hspDcFVrDE/JOonNow== 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)(396003)(376002)(346002)(366004)(136003)(1076003)(2616005)(41300700001)(107886003)(6512007)(26005)(186003)(38350700002)(38100700002)(86362001)(83380400001)(66556008)(66946007)(4326008)(8676002)(66476007)(2906002)(5660300002)(8936002)(508600001)(52116002)(6506007)(6486002)(36756003)(6666004)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4zP2ZYyOnJDIVLsVWaPpmiKseu3U4QUMCIcubITpt1285gVyeOwGhHwAeFmv?= =?us-ascii?Q?aVxI9Hoep5GVUnMF/K3WeCGCdfl8bJOFvw21a4nYfQZWD1PZmqajTfXi4smG?= =?us-ascii?Q?u2oXNpJicix7X3yNNTvLXVzY5qOYpKSR+Eo+iaCEo001uUpPCer/2PV6IIhs?= =?us-ascii?Q?+wENhuGF2L+8HV/ZdxrN4gTFgcvQ/hlhtl/9kgVtzFt0+hDcwJtZSRvLVAPA?= =?us-ascii?Q?+u/ogWeI3ufzBNToJQlj6/FhD+N0u5baRFRvZa5C3lDHeZaUsT6jRw7b6u6k?= =?us-ascii?Q?BN9z39AF669Rl886oolgpVQJQoOZOk6ZK5AnDXftjh9XtcAY7dODw1RdYWut?= =?us-ascii?Q?faZ9vCPR6pW2InPOuko1igg7fBaW8Ok+6LPc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7JP4VKkE2ijXAi5We5VIRTPqagZi31UcIYnvzPdFzrJH0CW?= =?us-ascii?Q?7XxMY98k0eZ3lVGVvNWic5fJ99/QWFasvvYqZuFXfia/kbe3o0Jg2d9G+2Mr?= =?us-ascii?Q?RMvCWIjN1BZSJY2sdK9zprZOvkp7Zta+WWeI1OKNOwXJ7EDu5oOI0GFAxsQ/?= =?us-ascii?Q?nb7h72tciqXgbGVdWzPoYHq8xSBJ+/Fzy87kFWtT+tOg+jGr+ScggKaQD4UC?= =?us-ascii?Q?oid2EkpLDt0U4Zh+guJYy9mleg8/cXsn8KppHlSKXs11LakehlwKjky9T7lE?= =?us-ascii?Q?6mGEBfB5XbqHdcldM8lokdNrPusC267cnrKz5KkBkLWW78fcOkzW9ToJtnFp?= =?us-ascii?Q?oVpU3GOCzMfABtfIdv2vxqelUB14MxUBUHRu//wWKTy+hEKnuzkGXy5w0VwH?= =?us-ascii?Q?1pX8jPkQqgAnjM9ThgfV/Rj63bMQJGeo5e9T1H+PvvqF7Hqulpj5ZHcAAmKt?= =?us-ascii?Q?l0QShbJgu5EEJ71rlB0mNa5rmplKZHk=3D?= X-OriginatorOrg: cgstowernetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97b28104-3bce-4b2b-4189-08da47d8b839 X-MS-Exchange-CrossTenant-AuthSource: AM0PR09MB3972.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2022 16:22:15.8426 (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: si7c+JDZGSpbcYgytPKvnzkkPkAnjV7ozKujPOdLbVeUWcoUJLPLNKRalgfqu3sY8e7y84GYnLbLXxCX4aHRA/IOudk8baEKIlp+mshMY7s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR09MB4961 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 --- v4: 1. Add release notes comment 2. Access pmd internals via queue struct 3. eth_mtu_set code convention fixes 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. --- doc/guides/rel_notes/release_22_07.rst | 3 ++ drivers/net/pcap/pcap_ethdev.c | 38 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst index 0ed4f92820..717191d498 100644 --- a/doc/guides/rel_notes/release_22_07.rst +++ b/doc/guides/rel_notes/release_22_07.rst @@ -95,6 +95,9 @@ New Features * Added AH mode support in lookaside protocol (IPsec) for CN9K & CN10K. * Added AES-GMAC support in lookaside protocol (IPsec) for CN9K & CN10K. +* **Updated pcap driver.** + + * Added support for MTU via ``rte_eth_dev_set_mtu`` Removed Items ------------- diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index ec29fd6bc5..db1958f20f 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -74,6 +74,7 @@ struct pcap_rx_queue { /* Contains pre-generated packets to be looped through */ struct rte_ring *pkts; + struct pmd_internals *internals; }; struct pcap_tx_queue { @@ -82,6 +83,7 @@ struct pcap_tx_queue { struct queue_stat tx_stat; char name[PATH_MAX]; char type[ETH_PCAP_ARG_MAXLEN]; + struct pmd_internals *internals; }; struct pmd_internals { @@ -93,6 +95,7 @@ struct pmd_internals { int single_iface; int phy_mac; unsigned int infinite_rx; + uint16_t mtu; }; struct pmd_process_private { @@ -278,6 +281,7 @@ 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 pmd_internals *internals = pcap_q->internals; uint16_t num_rx = 0; uint32_t rx_bytes = 0; pcap_t *pcap; @@ -303,6 +307,12 @@ eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) break; } + if (unlikely(header.caplen > internals->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 +388,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 pmd_internals *internals = dumper_q->internals; uint16_t num_tx = 0; uint32_t tx_bytes = 0; struct pcap_pkthdr header; @@ -396,6 +407,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 > internals->mtu)) { + rte_pktmbuf_free(mbuf); + continue; + } + if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > sizeof(temp_data))) { caplen = sizeof(temp_data); @@ -464,6 +481,7 @@ 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 pmd_internals *internals = tx_queue->internals; uint16_t num_tx = 0; uint32_t tx_bytes = 0; pcap_t *pcap; @@ -479,6 +497,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 > internals->mtu)) { + rte_pktmbuf_free(mbuf); + continue; + } + if (unlikely(!rte_pktmbuf_is_contiguous(mbuf) && len > sizeof(temp_data))) { PMD_LOG(ERR, @@ -807,6 +831,16 @@ eth_stats_reset(struct rte_eth_dev *dev) return 0; } +static int +eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) +{ + struct pmd_internals *internals = dev->data->dev_private; + + PMD_LOG(INFO, "MTU set %s %u\n", dev->device->name, mtu); + internals->mtu = mtu; + return 0; +} + static inline void infinite_rx_ring_free(struct rte_ring *pkts) { @@ -878,6 +912,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, pcap_q->mb_pool = mb_pool; pcap_q->port_id = dev->data->port_id; pcap_q->queue_id = rx_queue_id; + pcap_q->internals = internals; dev->data->rx_queues[rx_queue_id] = pcap_q; if (internals->infinite_rx) { @@ -952,6 +987,7 @@ eth_tx_queue_setup(struct rte_eth_dev *dev, pcap_q->port_id = dev->data->port_id; pcap_q->queue_id = tx_queue_id; + pcap_q->internals = internals; dev->data->tx_queues[tx_queue_id] = pcap_q; return 0; @@ -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)->mtu = RTE_ETH_PCAP_SNAPLEN; 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