[PATCH v6 07/13] net/pcap: support MTU configuration in single interface mode
Stephen Hemminger
stephen at networkplumber.org
Sun Jan 25 20:20:05 CET 2026
Implement the mtu_set dev_op to allow MTU changes when the pcap PMD is
attached to a real network interface (single interface mode).
The MTU change is passed through to the underlying device via ioctl.
This is supported on Linux and FreeBSD. On Windows, the operation
returns -ENOTSUP (for now).
Also report min_mtu and max_mtu in device info.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
doc/guides/nics/features/pcap.ini | 1 +
doc/guides/rel_notes/release_26_03.rst | 1 +
drivers/net/pcap/pcap_ethdev.c | 14 ++++++++++++++
drivers/net/pcap/pcap_osdep.h | 1 +
drivers/net/pcap/pcap_osdep_freebsd.c | 24 ++++++++++++++++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 22 ++++++++++++++++++++++
drivers/net/pcap/pcap_osdep_windows.c | 6 ++++++
7 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/doc/guides/rel_notes/release_26_03.rst b/doc/guides/rel_notes/release_26_03.rst
index 76d81ac524..41f96ad1af 100644
--- a/doc/guides/rel_notes/release_26_03.rst
+++ b/doc/guides/rel_notes/release_26_03.rst
@@ -57,6 +57,7 @@ New Features
* **Updated PCAP ethernet driver.**
+ * Added support for setting MTU in single interface mode.
* Changed transmit burst to always return the number of packets requested.
Failed sends are counted as transmit errors.
diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c
index 537d66ed30..54f71fa17f 100644
--- a/drivers/net/pcap/pcap_ethdev.c
+++ b/drivers/net/pcap/pcap_ethdev.c
@@ -748,6 +748,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;
@@ -1006,6 +1008,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,
@@ -1019,6 +1032,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 a0e2b5ace9..7eacfce24f 100644
--- a/drivers/net/pcap/pcap_osdep.h
+++ b/drivers/net/pcap/pcap_osdep.h
@@ -15,5 +15,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 0185665f0b..40244c51fb 100644
--- a/drivers/net/pcap/pcap_osdep_freebsd.c
+++ b/drivers/net/pcap/pcap_osdep_freebsd.c
@@ -8,6 +8,8 @@
#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"
@@ -55,3 +57,25 @@ 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 = { .ifr_mtu = mtu };
+ char ifname[IFNAMSIZ];
+ int s, ret;
+
+ if (if_indextoname(ifindex, ifname) == NULL)
+ return -errno;
+
+ s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -errno;
+
+ strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+
+ 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 df976417cb..567ab89bd6 100644
--- a/drivers/net/pcap/pcap_osdep_linux.c
+++ b/drivers/net/pcap/pcap_osdep_linux.c
@@ -40,3 +40,25 @@ 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)
+{
+ struct ifreq ifr = { .ifr_mtu = mtu };
+ char if_name[IFNAMSIZ];
+ int s, ret;
+
+ if (if_indextoname(ifindex, if_name) == NULL)
+ return -errno;
+
+ rte_strscpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
+
+ s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ return -errno;
+
+ 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
More information about the dev
mailing list