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 5FC7342DAE; Tue, 4 Jul 2023 19:44:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4FBF540A4B; Tue, 4 Jul 2023 19:44:02 +0200 (CEST) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mails.dpdk.org (Postfix) with ESMTP id 106C840042 for ; Tue, 4 Jul 2023 19:44:00 +0200 (CEST) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1b8ad356f03so858865ad.1 for ; Tue, 04 Jul 2023 10:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688492640; x=1691084640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qnf/fpwRqh05DrdIVjEDlwz2ZoISIjRS89AAJxRFNUQ=; b=bAKcMa/Lr5nwXW/CX++ldzhb8GtqklyXnr5usxOtn2NK63TzuGDJz8O6Q+lyoKclVG FEjCE9e4TMBkNEqtA1Pgp/GLR3ueB+72bIiNYLiFeig3bcIU5GttU1EFlT5o8it6h3J0 oV5VRmj/QPoWiTOD6bstI+c50w8jzvkmS4nhB0MtYOfFKTZdn/F9jXkAu1denJg2H0zJ l/a2ClzDBHRrw2PKmaAcITGZDLCoqLpPQHPOOljH7HgNr7hLRbD1aDgTOuK7fLinYCaE 34v86/fk4N0u/QAJff4ei8Rw0eObFr7yQVcMQvwgGmLid9dnzd9ZATt0WYIaVglebYUr H5oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688492640; x=1691084640; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qnf/fpwRqh05DrdIVjEDlwz2ZoISIjRS89AAJxRFNUQ=; b=b5Cc1+L0NO1mK0H62N8YveRfGYGWPxW2YmAcWAc5vwrLjOVlk/oxVBIYF9CZQKAXEh LisEJwE20jgwizeav5+YRqWnjExPe7Fs8LONOAxzbeBD1X0khV6nFWWg3e8eF5Ba85z+ puHvdU3bJ4GMUttkOCk518I50P6aCx5N9G+ZXm/Fqu6zeVy1rSTYPRH8P1q/dQmhDHEa e4WB0KCm1Xmq6t/1CLCf23EnQaK+0pIGCWr4LZqICjidK0iEm3ajChCuXM6uaEg6TLhs vseU98wwVJkl3Ot+YgfwnULkJuAU9iCrZxkmIpv07XokXS142kDz3Dn0eljCZ6rzG3rh uK7g== X-Gm-Message-State: ABy/qLbgBiTDLOq/UyboFSd9FNfeU5vtnsu+5O2sq8xhYw+xAy7kDYJA 0HhN1JQgIIIqHVphyEICRJ7kDXyhcM9msVubeqI= X-Google-Smtp-Source: APBJJlFCtRKLrqbIOAYuuk1+M4wlwbU8HpA8YYN2MZsXcy4fdJb8LJrdvWU4oManUwYzmBCTfZTvgg== X-Received: by 2002:a17:902:d2c1:b0:1b7:d0b3:1678 with SMTP id n1-20020a170902d2c100b001b7d0b31678mr8928514plc.17.1688492639860; Tue, 04 Jul 2023 10:43:59 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id jj1-20020a170903048100b001b891259eddsm4668349plb.197.2023.07.04.10.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 10:43:59 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Ido Goshen Subject: [PATCH] pcap: support MTU set Date: Tue, 4 Jul 2023 10:43:57 -0700 Message-Id: <20230704174357.68674-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20220317174347.110909-1-ido@cgstowernetworks.com> References: <20220317174347.110909-1-ido@cgstowernetworks.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 for pcap driver when the pcap device is convigured to point to a network interface. This is rebased an consolidated from earlier version. Added support for FreeBSD. Signed-off-by: Ido Goshen Signed-off-by: Stephen Hemminger --- drivers/net/pcap/pcap_ethdev.c | 49 ++++++++++++++++++++++++++- drivers/net/pcap/pcap_osdep.h | 1 + drivers/net/pcap/pcap_osdep_linux.c | 21 ++++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 7 ++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index bfec0850456f..672f42d30d8e 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -5,6 +5,7 @@ */ #include +#include #include #include @@ -495,8 +496,13 @@ eth_pcap_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) */ ret = pcap_sendpacket(pcap, rte_pktmbuf_read(mbuf, 0, len, temp_data), len); - if (unlikely(ret != 0)) + if (unlikely(ret != 0)) { + /* Oversize packet dropped due to MTU */ + if (errno == EMSGSIZE) + continue; break; + } + num_tx++; tx_bytes += len; rte_pktmbuf_free(mbuf); @@ -808,6 +814,46 @@ 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; + unsigned int i; + bool is_supported = false; + int ret; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + struct pcap_rx_queue *queue = &internals->rx_queue[i]; + + if ((strcmp(queue->type, ETH_PCAP_IFACE_ARG) == 0) || + (strcmp(queue->type, ETH_PCAP_RX_IFACE_ARG) == 0) || + (strcmp(queue->type, ETH_PCAP_RX_IFACE_IN_ARG) == 0)) { + ret = osdep_iface_mtu_set(queue->name, mtu); + if (ret < 0) + return ret; + is_supported = true; + } + } + + for (i = 0; i < dev->data->nb_tx_queues; i++) { + struct pcap_tx_queue *queue = &internals->tx_queue[i]; + + if ((strcmp(queue->type, ETH_PCAP_IFACE_ARG) == 0) || + (strcmp(queue->type, ETH_PCAP_TX_IFACE_ARG) == 0)) { + ret = osdep_iface_mtu_set(queue->name, mtu); + if (ret < 0) + return ret; + is_supported = true; + } + } + + if (!is_supported) + return -ENOTSUP; + + 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) { @@ -1005,6 +1051,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/drivers/net/pcap/pcap_osdep.h b/drivers/net/pcap/pcap_osdep.h index bf41cba982ec..043677ec777d 100644 --- a/drivers/net/pcap/pcap_osdep.h +++ b/drivers/net/pcap/pcap_osdep.h @@ -14,5 +14,6 @@ extern int eth_pcap_logtype; int osdep_iface_index_get(const char *name); int osdep_iface_mac_get(const char *name, struct rte_ether_addr *mac); +int osdep_iface_mtu_set(const char *name, uint16_t mtu); #endif diff --git a/drivers/net/pcap/pcap_osdep_linux.c b/drivers/net/pcap/pcap_osdep_linux.c index 97033f57c5d9..845296595f86 100644 --- a/drivers/net/pcap/pcap_osdep_linux.c +++ b/drivers/net/pcap/pcap_osdep_linux.c @@ -40,3 +40,24 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac) close(if_fd); return 0; } + +int +osdep_iface_mtu_set(const char *if_name, uint16_t mtu) +{ + struct ifreq ifr; + int if_fd = socket(AF_INET, SOCK_DGRAM, 0); + + if (if_fd == -1) + return -errno; + + rte_strscpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name)); + ifr.ifr_mtu = mtu; + if (ioctl(if_fd, SIOCSIFMTU, &ifr)) { + PMD_LOG(ERR, "%s mtu set to %d failed\n", if_name, mtu); + close(if_fd); + return -errno; + } + + close(if_fd); + return 0; +} diff --git a/drivers/net/pcap/pcap_osdep_windows.c b/drivers/net/pcap/pcap_osdep_windows.c index 1d398dc7ed9f..db34fc49e22e 100644 --- a/drivers/net/pcap/pcap_osdep_windows.c +++ b/drivers/net/pcap/pcap_osdep_windows.c @@ -116,3 +116,10 @@ osdep_iface_mac_get(const char *device_name, struct rte_ether_addr *mac) free(info); return ret; } + +int +osdep_iface_mtu_set(__rte_unused const char *device_name, __rte_unused uint16_t mtu) +{ + PMD_LOG(ERR, "mtu set not supported on Windows\n"); + return -ENOTSUP; +} -- 2.39.2