From: Nariman Sayed <narimansayed28@gmail.com>
To: qemu-devel@nongnu.org
Cc: Jason Wang <jasowangio@gmail.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Nariman Sayed <narimansayed28@gmail.com>,
Eugenio Perez Martin <eperezma@redhat.com>
Subject: [PATCH v2 2/3] net: add generic get_mtu NetClientInfo callback
Date: Wed, 7 Oct 2026 08:07:17 +0300 [thread overview]
Message-ID: <20261007050718.926-3-narimansayed28@gmail.com> (raw)
In-Reply-To: <20261007050718.926-1-narimansayed28@gmail.com>
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>
---
include/net/net.h | 3 +++
net/net.c | 9 +++++++++
net/tap.c | 8 ++++++++
3 files changed, 20 insertions(+)
diff --git a/include/net/net.h b/include/net/net.h
index 9edfacf827..ed06814644 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -72,6 +72,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);
@@ -110,6 +111,7 @@ typedef struct NetClientInfo {
SetSteeringEBPF *set_steering_ebpf;
NetCheckPeerType *check_peer_type;
GetVHostNet *get_vhost_net;
+ GetMtu *get_mtu;
} NetClientInfo;
struct NetClientState {
@@ -204,6 +206,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 0a30579ca4..9fb70e412a 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 57ffb09885..89cec2accd 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -379,6 +379,13 @@ int tap_get_fd(NetClientState *nc)
return s->fd;
}
+static int tap_get_mtu(NetClientState *nc)
+{
+ TAPState *s = DO_UPCAST(TAPState, nc, 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
@@ -411,6 +418,7 @@ static NetClientInfo net_tap_info = {
.set_vnet_be = tap_set_vnet_be,
.set_steering_ebpf = tap_set_steering_ebpf,
.get_vhost_net = tap_get_vhost_net,
+ .get_mtu = tap_get_mtu,
};
static TAPState *net_tap_fd_init(NetClientState *peer,
--
2.34.1
next prev parent reply other threads:[~2026-10-07 9:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 4:34 [PATCH 0/3] net/tap, virtio-net: auto-detect MTU from host tap device Nariman Sayed
2026-08-16 4:34 ` [PATCH 1/3] net/tap: add tap_fd_get_mtu() to query host tap MTU Nariman Sayed
2026-08-26 17:17 ` Aniket Sahu
2026-09-17 10:28 ` Eugenio Pérez
2026-09-17 10:28 ` Eugenio Pérez
2026-08-16 4:34 ` [PATCH 2/3] net/tap: expose tap_get_mtu() via NetClientState Nariman Sayed
2026-08-16 4:34 ` [PATCH 3/3] virtio-net: add mtu-from-tap property for automatic MTU detection Nariman Sayed
2026-08-24 13:40 ` [PATCH 0/3] net/tap, virtio-net: auto-detect MTU from host tap device Stefan Hajnoczi
2026-10-07 5:07 ` [PATCH v2 " Nariman Sayed
2026-10-07 5:07 ` [PATCH v2 1/3] net/tap: add tap_fd_get_mtu() to query host tap MTU Nariman Sayed
2026-10-07 5:07 ` Nariman Sayed [this message]
2026-10-07 5:07 ` [PATCH v2 3/3] virtio-net: add mtu-from-tap property for automatic MTU detection Nariman Sayed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261007050718.926-3-narimansayed28@gmail.com \
--to=narimansayed28@gmail.com \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.