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 43A3442DAB; Tue, 4 Jul 2023 23:02:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DA8B540A4B; Tue, 4 Jul 2023 23:02:43 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id A037E406B7 for ; Tue, 4 Jul 2023 23:02:41 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-668711086f4so37021b3a.1 for ; Tue, 04 Jul 2023 14:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1688504560; x=1691096560; 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=xywe4t7PzqLIYDZccvzE9JP7LJXfbFkiqda0OqzkdLU=; b=2O9sqdTXqM+oCfDxLdVruEC80dBlBpGhl4vy0gQS+kH5bjd/EjUyhSWF8xP2hUcTqd oIvq4SR0U8oJ9q7+1h68JTBJedAl/WN3RMXkA69p2rUu3Mh39UT2ln3jOj12l5P09Uom LoiJCZjVbRGFtvVAO2clSz5AMS8i9ThzedicnuUwA3zVlVrnvJ5VQb19Oa8XWI5mKMDh yCtX5OPY5Mw+6mIb39kBA4BDfrW9djapxUURFD7X9BOnc40QYHA8tqLST2LX5W/Znp5N sWxt00kMJiY8qnTgM86KUj0aL2oOhcqmSFUpT9q3Hhu5957T8uK1n+QyukROOM2mpiZL I6RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688504560; x=1691096560; 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=xywe4t7PzqLIYDZccvzE9JP7LJXfbFkiqda0OqzkdLU=; b=dCPAvUfktlG8gxZXP8HRmqy4QywzgpUuFIo06MYof3KYtr5OlyI67e2Cm8Wrg4xGX9 za28qZnw8/CBHv/nd2p5lYFtAWE1qYRO5Ce2g/yqFQA7dsdgUbI4ttqnPB4h31eAAvcI SKKakLlcaGHK2X4Vw7hBTvvZp0oM8DBaluLiPyWwph//Epc1jygxDQKnsevVVqFBCyj7 ckzbSijGOyQPvTLIS7IHXiy+tZi/a6UlxqMbeep2D6OK/Mmrg5nvhIjJmZ2rGVQCteo4 TnYo9DTLiI9HfbwT5aVUSXnHlizpU7/A2oE77T+balC5yewzxKFGyOkVrs1sui6GyI6s 222A== X-Gm-Message-State: ABy/qLY+AzsbiNsjhBQdrQ2cocnM7bNk/IBCH8xXbm+evGbZiRr8EB9P etWx9jbpHNA6sZkE83fHXV/iY/Fk2/fOneK5CPk= X-Google-Smtp-Source: APBJJlHRomngNwZD1BxBqM1J+fB8Z7YbNIuF2GsO1XknFjowsbytuFM3E1S5AbM69rl6hJUuQ97o3g== X-Received: by 2002:a05:6a00:1953:b0:668:98a1:5e9d with SMTP id s19-20020a056a00195300b0066898a15e9dmr455917pfk.6.1688504560203; Tue, 04 Jul 2023 14:02:40 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id k13-20020a63d10d000000b00528da88275bsm7354836pgg.47.2023.07.04.14.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 14:02:39 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Ido Goshen Subject: [PATCH v2] pcap: support MTU set Date: Tue, 4 Jul 2023 14:02:37 -0700 Message-Id: <20230704210237.72933-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 --- v2 - fix FreeBSD part drivers/net/pcap/pcap_ethdev.c | 49 ++++++++++++++++++++++++++- drivers/net/pcap/pcap_osdep.h | 1 + drivers/net/pcap/pcap_osdep_freebsd.c | 23 +++++++++++++ drivers/net/pcap/pcap_osdep_linux.c | 21 ++++++++++++ drivers/net/pcap/pcap_osdep_windows.c | 7 ++++ 5 files changed, 100 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_freebsd.c b/drivers/net/pcap/pcap_osdep_freebsd.c index 20556b3e9215..de6358197391 100644 --- a/drivers/net/pcap/pcap_osdep_freebsd.c +++ b/drivers/net/pcap/pcap_osdep_freebsd.c @@ -6,7 +6,9 @@ #include #include +#include #include +#include #include #include @@ -57,3 +59,24 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac) rte_free(buf); 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; + + strlcpy(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_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