From nobody Fri Aug 28 00:11:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786881022; cv=none; d=zohomail.com; s=zohoarc; b=aWIBA6n7+qWUSCgp50cRDaPeyayQWVdWcEBJDuW6vzn8k1pri+dgAcOYIewmb47E0pzHjvutyFsPKUXVf+ArzeOtR/uRFoh52Y1KN96bBZdyaQelbhfYcSCh/TQQ9NbJ0aeUiHu9yp2JjGSzRaXac42CeQ99FyJ2vZYlDUI1QJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786881022; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5Ltu2h4mQNH63wNh6b4t2KW06UJSusNDf0EeH5Va9VI=; b=jS3QM/R08X9x0qnSgxl6753ZHoOdb2/3n1+Srng9FuMMpDH2FuHmckNzigaoUQVM0NdLtC5qk+sAa9LRZYVLvXQkZVPkCD9JDhLakglyYBVckIrlEPX2FUzaZAUa+NLVs0COY3eGb9r0/cd5INkAY0HMWDpr3KRlXkBhI7qQyLQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786881022289715.7066306915965; Sun, 16 Aug 2026 04:50:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvZMo-0001ig-1M; Sun, 16 Aug 2026 07:49:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wvSav-0000ko-I8 for qemu-devel@nongnu.org; Sun, 16 Aug 2026 00:35:37 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvSat-0003FT-Qg for qemu-devel@nongnu.org; Sun, 16 Aug 2026 00:35:37 -0400 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4954a32cf1eso11711115e9.3 for ; Sat, 15 Aug 2026 21:35:35 -0700 (PDT) Received: from DESKTOP-2SK3BJA.localdomain ([197.49.67.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4815f2b27bfsm22971471f8f.23.2026.08.15.21.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Aug 2026 21:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786854934; x=1787459734; darn=nongnu.org; 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:content-type; bh=5Ltu2h4mQNH63wNh6b4t2KW06UJSusNDf0EeH5Va9VI=; b=aUGjGWRdMxG/cXb8oqVt6jzbf/otpKMJqjiltTL4/w2mF9AqD7qCg0cyV7fYiwkmGj /kWO1iehE/7tww44HokCG07HoTl9cuKliHWNP9jC9r+DclfKuq0Sqc7fOfW7tndM0hBX uRN/MNQJS2Z2ZcQlQ9RBEwYDPtvPWcMdlRR5FloEcnNtMcy0Y7QFfAXD4TjB5nUlqvXB A7Bo4Xw8re0WfKx2rls/11DIoYE9lJHVeKYwyBKfoLyHDjhSf175MZAoixiP/KS16+dz YKGTcpm5JjwpeXxR8lOLo+fJ5h2ABGe3vNtJgrWewQOPFmtqKcQ3Mdl9Nm9v/64Oi2FW j0Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786854934; x=1787459734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=5Ltu2h4mQNH63wNh6b4t2KW06UJSusNDf0EeH5Va9VI=; b=pA/fQsqJw6zJG07EzeJbbMs5E6nQabXcGJUmiKw9u5hekG5EB7TYLY5LesBRb3GNQC +mj1mbIqAnfKFpDtTrn4jn79AFHLkov9iNFUttjSMTM93iGChOcfHg3/yulBYSEoV7yJ opcdhp1FA3NClpXTohuvT3aE4ymYfUlLpISHgoQrlmr/EF38UkCa322og25EErJoB4PT UDXARucCEpnFhB64TJlhvwODFYpiKat8DkgHEgbALV4j5vYxaKfANTh6vYn9KfXXZ+3N Bqc/HNZcFdVhKTLhKTxOfTvuZTxQkVZQa1EGgWJoUgkgcHM4Mgj4wBPSof9SQcAe3sQq w1cw== X-Gm-Message-State: AOJu0YwEwZM9ZRwC/XchJ1vW60SXX81Gpls3pRNgVejUDEOy+Onx/QNT N0rW1NfaLja4tLmeP3NIPpAFmCeXgnz0xE+L1zzew5viDBJvcedLtTMBkcmsPgNA X-Gm-Gg: AR+sD13MAxxflPLnufkYlpQrr+275MczYaPj1heKWEVoOFA3eeX8cq0JwFxoVWleadt YxYzaQJPwGq0Py5GfgYOh5ijgAwxkOMSFvZR+kl9uMF+Act5RAeh7mPzDpG5sJP3qFtF93/UzZF +ZChFYV+a0Gw8wT+GawCRy5NvM09Usy9XGUX706XWKe2p+Inn3gNi34FF8C4tMAQnPPQxH+oa6H UPVIUUBgRVF1L5X7x1Oup7w+qOuFKiAB5Fri/IIwzDb3xc/JB336TgSHPiaRfw5N5lqYGnZ30eI 5lg1T1YX/Woz4mqybs85DTpVRMRKF1RFc+m5wk8nXR3YnlX1y9UxuomwUahqcbZfr2zUm3AqdTy Umy7mP586J14jk/UF1pjW0Q7fQwlqvSxv05Qt1jqnjMFsEpmYydap3DI16ZyoHa44Y7VLOBakOn b/eVcHnTjhvEeMmeMBirCGExmsimqQY/niHi9ltZ7ndvgQC/4S7aeqfKtnshUjP8vyysQyDe99U A9WkTn29ST80A== X-Received: by 2002:adf:f791:0:b0:460:70ae:f1af with SMTP id ffacd0b85a97d-481607630f2mr18681836f8f.27.1786854933574; Sat, 15 Aug 2026 21:35:33 -0700 (PDT) From: Nariman Sayed To: qemu-devel@nongnu.org Cc: Nariman Sayed Subject: [PATCH 1/3] net/tap: add tap_fd_get_mtu() to query host tap MTU Date: Sun, 16 Aug 2026 07:34:49 +0300 Message-Id: <20260816043451.2547-2-narimansayed28@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260816043451.2547-1-narimansayed28@gmail.com> References: <20260816043451.2547-1-narimansayed28@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=narimansayed28@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FORGED_GMAIL_RCVD=1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 16 Aug 2026 07:49:20 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1786881023334158500 Content-Type: text/plain; charset="utf-8" Add a helper function to read the host tap device's configured MTU via SIOCGIFMTU. Since this ioctl requires a socket rather than the tap character device fd itself, a separate control socket is opened to perform the query, following the same pattern used by net/can/can_socketcan.c. This is implemented for Linux only, with stub implementations returning -1 for BSD, Solaris, and the tap-stub backend, matching the existing pattern used by tap_fd_get_ifname() and tap_fd_set_steering_ebpf() in those files. This is a preparatory patch; the function is not yet called from anywhere. Signed-off-by: Nariman Sayed Tested-by: Aniket Sahu --- net/tap-bsd.c | 5 +++++ net/tap-linux.c | 30 ++++++++++++++++++++++++++++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap_int.h | 1 + 5 files changed, 46 insertions(+) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index c39daf9385..17cedccf9e 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -264,6 +264,11 @@ int tap_fd_get_ifname(int fd, char *ifname) return -1; } =20 +int tap_fd_get_mtu(int fd) +{ + return -1; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { return -1; diff --git a/net/tap-linux.c b/net/tap-linux.c index 3cd7d26710..23a10151c1 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/cutils.h" +#include "qemu/sockets.h" =20 #define PATH_NET_TUN "/dev/net/tun" =20 @@ -346,6 +347,35 @@ int tap_fd_get_ifname(int fd, char *ifname) return 0; } =20 +int tap_fd_get_mtu(int fd) +{ + struct ifreq ifr; + int s, ret, mtu; + + memset(&ifr, 0, sizeof(ifr)); + if (tap_fd_get_ifname(fd, ifr.ifr_name) !=3D 0) { + return -1; + } + + s =3D qemu_socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + error_report("could not create control socket: %s", + strerror(errno)); + return -1; + } + + ret =3D ioctl(s, SIOCGIFMTU, &ifr); + if (ret !=3D 0) { + error_report("SIOCGIFMTU ioctl() failed: %s", strerror(errno)); + close(s); + return -1; + } + + mtu =3D ifr.ifr_mtu; + close(s); + return mtu; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { if (ioctl(fd, TUNSETSTEERINGEBPF, (void *) &prog_fd) !=3D 0) { diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 8704b1084b..d3bd6e6b48 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -266,6 +266,11 @@ int tap_fd_get_ifname(int fd, char *ifname) return -1; } =20 +int tap_fd_get_mtu(int fd) +{ + return -1; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { return -1; diff --git a/net/tap-stub.c b/net/tap-stub.c index 6aa60d96ad..756ce882a7 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -91,6 +91,11 @@ int tap_fd_get_ifname(int fd, char *ifname) return -1; } =20 +int tap_fd_get_mtu(int fd) +{ + return -1; +} + int tap_fd_set_steering_ebpf(int fd, int prog_fd) { return -1; diff --git a/net/tap_int.h b/net/tap_int.h index dc4f484006..360d61c889 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -45,6 +45,7 @@ int tap_fd_set_vnet_be(int fd, int vnet_is_be); int tap_fd_enable(int fd); int tap_fd_disable(int fd); int tap_fd_get_ifname(int fd, char *ifname); +int tap_fd_get_mtu(int fd); int tap_fd_set_steering_ebpf(int fd, int prog_fd); =20 #endif /* NET_TAP_INT_H */ --=20 2.34.1 From nobody Fri Aug 28 00:11:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786881014; cv=none; d=zohomail.com; s=zohoarc; b=AYEEYckD51KJo1WB4ugs9t2/UmywjqM99nodiRzQGKGsH0CosgpFFTEO95C6H0YhIGMeB/txHmialA7mSllc6qhO8XDZDMK5uni9PCgz1i2oSfySxbzzexAKXahCCLVoMhq34pvvXv3KxUOayuPpufPMEUpvXpb92zSU2gDBYRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786881014; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vt0hlKCIgUUpRy6BPbyzZxYr4+CSZL2N8xdEVEJEljM=; b=Hvew6etNS+cg3BZWmP7OvpM3rbRjSzn2MB6VMjfuh25XjAnQztCwG6PMrrBFqPVaQmE2kGu6C1mfPLBhYkmkVU554xxep3PPCYrYmmq4uRlhMx9BqC5RZvZhPrOI0Un2ZZY1CD8EMcYY15rsWV4l0uKFrk1XnDR/MN8FXznmJBk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786881014466173.0932845956272; Sun, 16 Aug 2026 04:50:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvZMp-0001lF-9W; Sun, 16 Aug 2026 07:49:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wvSay-0000lD-Pc for qemu-devel@nongnu.org; Sun, 16 Aug 2026 00:35:40 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvSax-0003G2-Cm for qemu-devel@nongnu.org; Sun, 16 Aug 2026 00:35:40 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-482938466a7so1183792f8f.1 for ; Sat, 15 Aug 2026 21:35:38 -0700 (PDT) Received: from DESKTOP-2SK3BJA.localdomain ([197.49.67.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4815f2b27bfsm22971471f8f.23.2026.08.15.21.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Aug 2026 21:35:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786854938; x=1787459738; darn=nongnu.org; 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:content-type; bh=vt0hlKCIgUUpRy6BPbyzZxYr4+CSZL2N8xdEVEJEljM=; b=VvuNukKPTgOy0iT34vQQTArvPVWuOeG7tMjwX3hdcWM6OVH36shMUUUaQY0B+pdldy 9+xca+SDDkHGARV+YD8FB6p6UgOL83VDJHz/msgHo7nfOeRrEdxs6fVfsE+YFz5fcPfb Peqt5GlsUm91A0Py3yxKdzQPR6h+fSAfZKoP4zmTmp2fr90QYQkzQsxYyK0SyHhm+4OV w+S8pGIeLyuk/IKqe9fjUO0WBRRtBjX4jwtJweovicz+gjVMYBm0Lci2EPIJImBqVNOA KDaH5ymTSBleqFD0M2azMuI2kKanGrt00lE/eas6YhKLqFCG9R0nD8ZmQQTF747txIgv 1tdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786854938; x=1787459738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=vt0hlKCIgUUpRy6BPbyzZxYr4+CSZL2N8xdEVEJEljM=; b=G2Ui+lyUWB5xZa/jQzaODGyMrk3N3Klk8oeOu4N+U/UD4LS7kW7TlMrwFxnDp8UHP7 YDx1HCFk/aOrRsw7WjJDB14690EXqKix+2QG8wG+BhMnZIfHqztvOgyC159V6amDIeMM AuwX8xReHpV0gOFiqVBiR99xodk9FaI7/agR/FbpAwlx/oVikMjih4ZBJvAwthfoCtiK 0nLWv0LZBs7mgUrfDgW4m2BCMcYDwIgC/irKlaKkw6LCgdKM9OhjkcsOG4qSx7Oga+Wn pUi3jyt0KPmINbjIZS0IczL189F5wXTW0sJR9yYUM0OFRxNoo4lwr7TQB5KGnzG0iMfX BVGQ== X-Gm-Message-State: AOJu0Yza3vkN7qS7EbwNFW8HqIEdYfkPZwgKhV4jruvgRKMuq3K61RM3 AEt6FOtA5b/6/wqYOAPE87elqFCL0l7Meh6KqUhgTK7ZYQNHSQfNVGDkWf2I0eYC X-Gm-Gg: AR+sD101DTcLf0v0iP7H3az04Fi7ZGb5nDXDW2r5+WYtbvLdEcHsfB93O33+bPaXvTY Z/SYlqLIfGnjrn/k7U7Hjnb2nyYbhwbBAeU1ELV3TvgOeEIVgZ0BkwSq09gpXmynliR7VGUj97/ aFsk5P63Qyub9AL0oxEwfz1i6JZX+0wdO8Ib71hDEwEq+2ASilGRJyjvPP438BF/lp9nnYnK98K nAoTC+JIwPt4LrZA4uER1cbONANiaYMqyMthIrNIFJKo8F4vZ5L/Qo0cCOmaEHhzoerUtJ4bIQy 3o/l22wzp8Nv1McfzslROyMtk8nrKCepKKpW2pWFBGK1CKHmvO8sqXjsIdevaiysXb6qcc3CnEM dm2X9BjQL/2Qls1qNhUzQkFgNsuH52Cl7UA58z8EtTGskirwdu7b2QZwScyxnyTwrsQvsBFAOXM Krw+TOAcfrt/2IdAbagmq8CucmP0XCSK8sG/SEZmry3rlbHkbESdquNUea7OeWfEGzxbSXlCbH6 GhzzgJzBSRCCYCrZovKvewQ X-Received: by 2002:adf:ea42:0:b0:47d:dfc6:b28b with SMTP id ffacd0b85a97d-4816079d262mr17605360f8f.30.1786854937794; Sat, 15 Aug 2026 21:35:37 -0700 (PDT) From: Nariman Sayed To: qemu-devel@nongnu.org Cc: Nariman Sayed Subject: [PATCH 2/3] net/tap: expose tap_get_mtu() via NetClientState Date: Sun, 16 Aug 2026 07:34:50 +0300 Message-Id: <20260816043451.2547-3-narimansayed28@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260816043451.2547-1-narimansayed28@gmail.com> References: <20260816043451.2547-1-narimansayed28@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=narimansayed28@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FORGED_GMAIL_RCVD=1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 16 Aug 2026 07:49:20 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1786881015356158500 Content-Type: text/plain; charset="utf-8" Add a public tap_get_mtu() function, following the same pattern as the existing tap_get_fd(), to allow other subsystems (such as virtio-net) to query a tap netdev's host MTU via its NetClientState without depending on tap-internal headers. This is a preparatory patch; the function is not yet called from anywhere. Signed-off-by: Nariman Sayed --- include/net/tap.h | 1 + net/tap.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/net/tap.h b/include/net/tap.h index 6f34f13eae..6b478acbfb 100644 --- a/include/net/tap.h +++ b/include/net/tap.h @@ -32,5 +32,6 @@ int tap_enable(NetClientState *nc); int tap_disable(NetClientState *nc); =20 int tap_get_fd(NetClientState *nc); +int tap_get_mtu(NetClientState *nc); =20 #endif /* QEMU_NET_TAP_H */ diff --git a/net/tap.c b/net/tap.c index 57ffb09885..122319d5f3 100644 --- a/net/tap.c +++ b/net/tap.c @@ -379,6 +379,13 @@ int tap_get_fd(NetClientState *nc) return s->fd; } =20 +int tap_get_mtu(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + assert(nc->info->type =3D=3D 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=3Doff' option, 'vhostforce=3Doff' or no vhost or --=20 2.34.1 From nobody Fri Aug 28 00:11:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1786881007; cv=none; d=zohomail.com; s=zohoarc; b=Cxlp65yRwGtTEofS1AaKzBN8pyVYKx0mJgk3aAxfcELxoGuA6kDRGL3Z8vdnOUqvCKU30CDIMMzZk9/yIJrKRaV3XMtEf8vwt2Tog27db7sU6+gKz+Nn3HPI6aTPT7i2X+VmbdKzR+t5E4xC4xcVUbBx9QrV/jzIArWYaJhOkZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786881007; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=O1q1TMFyF//zhxzhHPJ+eLgFtmqB4YMCiYqMQiDtR3E=; b=JOAfZVFYGq5UYnh1rRsJEEkRWKBu0DvafN2R7lS5npqKow5RoVsjmRfYX4KKAkRJsxC4JVE3KZ3zljJSjp7qGEDnvbnww1zvjaz5nUne7B4dpH+0uEaAL4KC0/P96VP7eP2NYRJXCJCpBqD+y9Dixc0YVp50LIyHh74IIM9/tE8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786881007602296.2507223606726; Sun, 16 Aug 2026 04:50:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wvZMt-0001oM-OP; Sun, 16 Aug 2026 07:49:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wvSb1-0000le-Us for qemu-devel@nongnu.org; Sun, 16 Aug 2026 00:35:44 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wvSb0-0003Gk-Bz for qemu-devel@nongnu.org; Sun, 16 Aug 2026 00:35:43 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4996f1ee4a4so18817515e9.2 for ; Sat, 15 Aug 2026 21:35:42 -0700 (PDT) Received: from DESKTOP-2SK3BJA.localdomain ([197.49.67.128]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4815f2b27bfsm22971471f8f.23.2026.08.15.21.35.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Aug 2026 21:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786854941; x=1787459741; darn=nongnu.org; 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:content-type; bh=O1q1TMFyF//zhxzhHPJ+eLgFtmqB4YMCiYqMQiDtR3E=; b=NKGZqC90VyFgnh7EXIO3j3SYximp6X90EjLx6wizHRzut1hCIv0FenW8hLup5FeeM5 MJPX4jPfjUdH8OaY3KDb722XgUcL/c81v9fohE/oLKfmnoUtsWoTYzhjXoxyqwOKid63 rbXJYFRGZxclCDkOCb4omsYWRe9zRQWLnxyrajLesEsCPBdcx6CBx2SycdIJAkqutbuK XEyeomnD6FWWwXPD5yBF+XQtPXcuf3DokemLOCamEz+6Goqmwz86FrH9Ps9zueEDHmt4 hrzbfN/IBgbd0uNHX9uFxWt0DpFSIWMmsuvI/Vu/Ry2DvQ0VqsL9ehOAxHWUx5PVzN+b BItA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786854941; x=1787459741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=O1q1TMFyF//zhxzhHPJ+eLgFtmqB4YMCiYqMQiDtR3E=; b=jSraKsNNMX3GeIazD47oX2JW6s1BmTZxKoqsJNlrUCeuYdFUECed2/e2n1pMH/HQdx pqLq96E7K8KyND8jHRC/BDfKgCBIrtS7fbsCQp26yDodiSyaKIW24kpJR9aCz83vqv3l QnSPW0EmpcSRU2OUwXr6I7cEnIfNBUv3FDbFuGVf+0afMgmEILeiLknvUD5loRVpQ3Rc HCyJd9j47F+9U4kg+hwF3jJxGGYOjba52xTo2Y2zCefhR8gyGzWYLy6rVgUEvo37fzYz kWm3uontSnSIvmh3l2mFw12IjXAnkzb3OUqaxuC9wFIFtwvUaz5PYeQtgC4Oqmnz6Iub y0Tw== X-Gm-Message-State: AOJu0YwQs45tUH43v4ItctV+FSZmje0vhsX9UPWvqx9+eAicN+ucFEwL d52MLeue7SFT4Q4DaAGQdQm0MsyBM88kK+9Ia2sJq0OEOQXtZHUPUtqiaIQ3lFwE X-Gm-Gg: AR+sD10MJlG9ZNeJBnbc4J7GByjT/n9oWxBEdlWrQTRkKsKzCx3zusMEAodfC1HT5aS lHZMkUG+6MdnawxbZEXILiiER4KizKkwzgzyQNPo28X8xTIl1mk6db/ESCxHAqZYQiK/WTnhCeI T8Em8AXyQaHvxVW6aJm4bhebtyttrVcHELnc172Kt4Bz+qGODPSbRxvYwIyMBJXWsZ/b6gGfGAC PkIXP4kUJll+MRUAwkmNlWoHgbIK50Y3koquob4cPMgSa0v1P8l9yzwBo+h+mSc4psuBlvo8FH2 5Qc0Jh52jtW/9FndG7rX+Ego01e49GmJLI7uXp2Ne4RVTatPt/mv7gEO7s0DztvneIaoN/sHotW a3ETthBEl5R/CDoEbRthj0Mi8s0230MBEdN3AaKyRiZ7U6PgzBBg6AwHLoigSwZC9Fp0rCGYUMf UxcSGQRshwlVfmi4Fjnpbt7+TUDKJEE72hRyXsly6wcbljG8zoG/guVMwYU+BYgCYzLD2V2TxQO Xrn/Zs+4KEpmQ== X-Received: by 2002:a05:600c:620a:b0:495:6bc9:62b0 with SMTP id 5b1f17b1804b1-499879b9c2fmr269157485e9.17.1786854940704; Sat, 15 Aug 2026 21:35:40 -0700 (PDT) From: Nariman Sayed To: qemu-devel@nongnu.org Cc: Nariman Sayed Subject: [PATCH 3/3] virtio-net: add mtu-from-tap property for automatic MTU detection Date: Sun, 16 Aug 2026 07:34:51 +0300 Message-Id: <20260816043451.2547-4-narimansayed28@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260816043451.2547-1-narimansayed28@gmail.com> References: <20260816043451.2547-1-narimansayed28@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=narimansayed28@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sun, 16 Aug 2026 07:49:20 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1786881009661158500 Content-Type: text/plain; charset="utf-8" Currently, exposing the host tap device's MTU to the guest via VIRTIO_NET_F_MTU requires manually specifying host_mtu=3D on the virtio-net-pci device, duplicating the MTU already configured on the host's tap interface. Add a new mtu-from-tap boolean property (default off, preserving existing behavior). When enabled and the device's netdev peer is a tap client, the host tap's MTU is queried via tap_get_mtu() and used to set net_conf.mtu and enable VIRTIO_NET_F_MTU. This detection must happen in virtio_net_device_realize(), before virtio_net_set_config_size() computes the virtio config space size from host_features. Performing the detection later (e.g. in the get_features_ex() callback, which runs after the NIC and its config space are already sized) results in the mtu config field falling outside the sized config space, and the guest reading back an unmapped garbage value (0xffff) instead of the intended MTU. Since qemu_new_nic() has not yet been called at this point in realize(), the tap peer is accessed via n->nic_conf.peers.ncs[0] (populated during property parsing, before realize() runs, via the netdev=3D property) rather than through n->nic. Signed-off-by: Nariman Sayed --- hw/net/virtio-net.c | 12 ++++++++++++ include/hw/virtio/virtio-net.h | 1 + 2 files changed, 13 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 814b99a43d..6faeca87d4 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3901,6 +3901,17 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); } =20 + if (n->net_conf.mtu_from_tap) { + NetClientState *tap_peer =3D n->nic_conf.peers.ncs[0]; + if (tap_peer && tap_peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP)= { + int mtu =3D tap_get_mtu(tap_peer); + if (mtu > 0) { + n->net_conf.mtu =3D mtu; + n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); + } + } + } + if (n->net_conf.duplex_str) { if (strncmp(n->net_conf.duplex_str, "half", 5) =3D=3D 0) { n->net_conf.duplex =3D DUPLEX_HALF; @@ -4275,6 +4286,7 @@ static const Property virtio_net_properties[] =3D { DEFINE_PROP_UINT16("tx_queue_size", VirtIONet, net_conf.tx_queue_size, VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE), DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0), + DEFINE_PROP_BOOL("mtu-from-tap", VirtIONet, net_conf.mtu_from_tap, fal= se), DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), DEFINE_PROP_BOOL("failover", VirtIONet, failover, false), diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 371e376428..11044b6d27 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -52,6 +52,7 @@ typedef struct virtio_net_conf uint16_t rx_queue_size; uint16_t tx_queue_size; uint16_t mtu; + bool mtu_from_tap; int32_t speed; char *duplex_str; uint8_t duplex; --=20 2.34.1