Commit e583f293aa for qemu.org
commit e583f293aa16a92fe5203c0d322a44e79cf8725c
Author: Nariman Sayed <narimansayed28@gmail.com>
Date: Wed Oct 7 08:07:17 2026 +0300
net: add generic get_mtu NetClientInfo callback
Add a get_mtu callback to NetClientInfo, along with a qemu_get_mtu()
wrapper following the existing qemu_has_ufo()-style pattern, so that
device models can query a netdev backend's host MTU generically
without needing to know or check its backend type.
Wire this up for the tap backend via tap_get_mtu(), which is now
static and only referenced through net_tap_info.get_mtu, matching
the existing pattern used by tap_has_ufo() and similar callbacks.
This allows other backends (e.g. vhost-user, vhost-vdpa) to
implement get_mtu in the future without requiring changes to any
code that calls qemu_get_mtu().
Suggested-by: Eugenio Perez Martin <eperezma@redhat.com>
Signed-off-by: Nariman Sayed <narimansayed28@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20261007050718.926-3-narimansayed28@gmail.com>
diff --git a/include/net/net.h b/include/net/net.h
index fdf6a2ddd4..de4f03c301 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -73,6 +73,7 @@ typedef bool (HasVnetHdr)(NetClientState *);
typedef bool (HasVnetHdrLen)(NetClientState *, int);
typedef void (SetOffload)(NetClientState *, const NetOffloads *);
typedef int (GetVnetHdrLen)(NetClientState *);
+typedef int (GetMtu)(NetClientState *);
typedef void (SetVnetHdrLen)(NetClientState *, int);
typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *);
typedef int (SetVnetLE)(NetClientState *, bool);
@@ -113,6 +114,7 @@ typedef struct NetClientInfo {
NetCheckPeerType *check_peer_type;
IsWaitIncoming *is_wait_incoming;
GetVHostNet *get_vhost_net;
+ GetMtu *get_mtu;
} NetClientInfo;
struct NetClientState {
@@ -214,6 +216,7 @@ bool qemu_has_uso(NetClientState *nc);
bool qemu_has_tunnel(NetClientState *nc);
bool qemu_has_vnet_hdr(NetClientState *nc);
bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
+int qemu_get_mtu(NetClientState *nc);
void qemu_set_offload(NetClientState *nc, const NetOffloads *ol);
int qemu_get_vnet_hdr_len(NetClientState *nc);
void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
diff --git a/net/net.c b/net/net.c
index d7fa637ce5..bf7e5d9b12 100644
--- a/net/net.c
+++ b/net/net.c
@@ -514,6 +514,15 @@ bool qemu_has_ufo(NetClientState *nc)
return nc->info->has_ufo(nc);
}
+int qemu_get_mtu(NetClientState *nc)
+{
+ if (!nc || !nc->info->get_mtu) {
+ return -1;
+ }
+
+ return nc->info->get_mtu(nc);
+}
+
bool qemu_has_uso(NetClientState *nc)
{
if (!nc || !nc->info->has_uso) {
diff --git a/net/tap.c b/net/tap.c
index acccabca56..665dee800d 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -446,6 +446,13 @@ int tap_get_fd(NetClientState *nc)
return s->fd;
}
+static int tap_get_mtu(NetClientState *nc)
+{
+ TAPState *s = container_of(nc, TAPState, nc);
+ assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
+ return tap_fd_get_mtu(s->fd);
+}
+
/*
* tap_get_vhost_net() can return NULL if a tap net-device backend is
* created with 'vhost=off' option, 'vhostforce=off' or no vhost or
@@ -607,6 +614,7 @@ static NetClientInfo net_tap_info = {
.set_steering_ebpf = tap_set_steering_ebpf,
.is_wait_incoming = tap_is_wait_incoming,
.get_vhost_net = tap_get_vhost_net,
+ .get_mtu = tap_get_mtu,
};
static TAPState *new_tap(NetClientState *peer,