[PATCH v5 04/11] net/pcap: support setting MTU

Stephen Hemminger
2026-01-18T17:00:11Z

If PCAP PMD is used in single interface mode, it can pass
the MTU setup to the device. Only implemented on
Linux and FreeBSD.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
doc/guides/nics/features/pcap.ini | 1 +
drivers/net/pcap/pcap_ethdev.c | 14 ++++++++++++++
drivers/net/pcap/pcap_osdep.h | 1 +
drivers/net/pcap/pcap_osdep_freebsd.c | 26 ++++++++++++++++++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 21 +++++++++++++++++++++
drivers/net/pcap/pcap_osdep_windows.c | 6 ++++++
6 files changed, 69 insertions(+)

diff --git a/doc/guides/nics/features/pcap.ini b/doc/guides/nics/features/pcap.ini
index b0dac3cca7..d2f5ee6039 100644
--- a/doc/guides/nics/features/pcap.ini
+++ b/doc/guides/nics/features/pcap.ini
@@ -19,3 +19,4 @@ Power8 = Y
x86-32 = Y
x86-64 = Y
Usage doc = Y
+MTU update = Y
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index e86aaf8bbc..5683c44892 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -749,6 +749,8 @@ eth_dev_info(struct rte_eth_dev *dev,
dev_info->max_rx_queues = dev->data->nb_rx_queues;
dev_info->max_tx_queues = dev->data->nb_tx_queues;
dev_info->min_rx_bufsize = 0;
+ dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN - RTE_ETHER_CRC_LEN;
+ dev_info->max_mtu = RTE_ETH_PCAP_SNAPLEN;
dev_info->tx_offload_capa = RTE_ETH_TX_OFFLOAD_MULTI_SEGS;

return 0;
@@ -1007,6 +1009,17 @@ eth_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
return 0;
}

+static int
+eth_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+ struct pmd_internals *internals = dev->data->dev_private;
+
+ if (internals->single_iface)
+ return osdep_iface_mtu_set(internals->if_index, mtu);
+
+ return 0;
+}
+
static const struct eth_dev_ops ops = {
.dev_start = eth_dev_start,
.dev_stop = eth_dev_stop,
@@ -1020,6 +1033,7 @@ static const struct eth_dev_ops ops = {
.rx_queue_stop = eth_rx_queue_stop,
.tx_queue_stop = eth_tx_queue_stop,
.link_update = eth_link_update,
+ .mtu_set = eth_mtu_set,
.stats_get = eth_stats_get,
.stats_reset = eth_stats_reset,
};
diff --git a/drivers/net/pcap/pcap_osdep.h b/drivers/net/pcap/pcap_osdep.h
index 2aa13f3629..3c8b7ff27b 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(int index, uint16_t mtu);

#endif
diff --git a/drivers/net/pcap/pcap_osdep_freebsd.c b/drivers/net/pcap/pcap_osdep_freebsd.c
index 32e4a2bee7..697b7029dd 100644
--- a/drivers/net/pcap/pcap_osdep_freebsd.c
+++ b/drivers/net/pcap/pcap_osdep_freebsd.c
@@ -4,9 +4,12 @@
* All rights reserved.
*/

+#include <unistd.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <sys/sysctl.h>
+#include <sys/ioctl.h>
+#include <sys/sockio.h>

#include "pcap_osdep.h"

@@ -54,3 +57,26 @@ osdep_iface_mac_get(const char *if_name, struct rte_ether_addr *mac)
free(buf);
return 0;
}
+
+int
+osdep_iface_mtu_set(int ifindex, uint16_t mtu)
+{
+ struct ifreq ifr = { 0 };
+ char ifname[IFNAMSIZ];
+ int s, ret;
+
+ if (if_indextoname(ifindex, ifname) == NULL)
+ return -errno;
+
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -errno;
+
+ strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ ifr.ifr_mtu = mtu;
+
+ ret = ioctl(s, SIOCSIFMTU, &ifr);
+ close(s);
+
+ return (ret < 0) ? -errno : 0;
+}
diff --git a/drivers/net/pcap/pcap_osdep_linux.c b/drivers/net/pcap/pcap_osdep_linux.c
index 97033f57c5..d180e9b4b4 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(int ifindex, uint16_t mtu)
+{
+ char ifname[IFNAMSIZ];
+
+ if (if_indextoname(ifindex, ifname) == NULL)
+ return -errno;
+
+ int s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -errno;
+
+ struct ifreq ifr = { .ifr_mtu = mtu };
+ strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+
+ int ret = ioctl(s, SIOCSIFMTU, &ifr);
+ close(s);
+
+ return (ret < 0) ? -errno : 0;
+}
diff --git a/drivers/net/pcap/pcap_osdep_windows.c b/drivers/net/pcap/pcap_osdep_windows.c
index 1d398dc7ed..00df67b8fc 100644
--- a/drivers/net/pcap/pcap_osdep_windows.c
+++ b/drivers/net/pcap/pcap_osdep_windows.c
@@ -116,3 +116,9 @@ osdep_iface_mac_get(const char *device_name, struct rte_ether_addr *mac)
free(info);
return ret;
}
+
+int
+osdep_iface_mtu_set(int index __rte_unused, uint16_t mtu __rte_unused)
+{
+ return -ENOTSUP;
+}
--
2.51.0