From patchwork Wed Mar 18 11:04:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Perin X-Patchwork-Id: 2212596 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (4096-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=k3Smaj0P; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4fbQw875SPz1xy3 for ; Wed, 18 Mar 2026 22:05:12 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DF0C9403B8; Wed, 18 Mar 2026 11:05:10 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id vnhGMuoyIRRg; Wed, 18 Mar 2026 11:05:10 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org E4D6D403BA Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (4096-bit key) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=k3Smaj0P Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id E4D6D403BA; Wed, 18 Mar 2026 11:05:09 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DAB2FC0401; Wed, 18 Mar 2026 11:05:08 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D5298C03FC for ; Wed, 18 Mar 2026 11:05:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D326340399 for ; Wed, 18 Mar 2026 11:05:06 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id QcZ1M3yiCbFX for ; Wed, 18 Mar 2026 11:05:06 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.125.188.123; helo=smtp-relay-internal-1.canonical.com; envelope-from=matteo.perin@canonical.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org A7EB24007D Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=reject dis=none) header.from=canonical.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A7EB24007D Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by smtp2.osuosl.org (Postfix) with ESMTPS id A7EB24007D for ; Wed, 18 Mar 2026 11:05:05 +0000 (UTC) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 063DD3FDC3 for ; Wed, 18 Mar 2026 11:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1773831904; bh=qgzPgYTSJ4xQ0j7J0EHf1XVv22HPgK0artSJ8Pp/xzc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k3Smaj0P30+TSdBrDjZrZWz3x9haVtgGAqzMGGm1UHw+4799yub59DSyraVXXgK2r mvKbNTYvcKHsFV4TGNCccNhb5m8NMv10SYMB2FA2nVtAWGaRIoPkFR8ZVhjzt6HcOO WCHl7InKvOf4t9m0BHJxpdawgm4qgH3aM1ZjbyjsPiwtzIyCupN5+FTtkzq2eI3tda WscLw5xvoB4qxNx5oKU3RahVFq2vbzM9HMx019gV210vBcfP8ZPXHb6Szt/Wq8XHkQ JFqZoGBD4GZK3s4Bo6cIW9RQokewURI8LCMDLiOn64dkLhRNNgGmwz0Lm7ZUKe6pPv B3Rw37qNmqXAoatrculyqOuIpYKuATQAc8m3wprUwcxz+OzPCIQwoyLWJHdZd1U61w yFOXoGHRmxtcYHbh8RjqNBcj7uS1XSAtmzYHnEHzEmJVh2687CSYS6NK0O1p0wnPJ9 EnCYO5qf1ykqfg/NiBwBjoXqQLP347Ynj83QbIygkP+YyX77wlmrHKEO9vte8TSsI5 kZEvpEG7aGh/T/OWFITGYnTo+9L0hGb0L4CL0JpFW/Ctknox98lG1c5nbLtLkgVvYL xfQDfONIwi86l8odHMOD9G3HqH3lB/FBDYZd3qLrs7vxbepdhIm7MXSPFlYWkgchzc BqQUo6VuCnyZ50s5jEtNYQkE= Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4853b00f9f5so70851535e9.2 for ; Wed, 18 Mar 2026 04:05:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773831903; x=1774436703; 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; bh=qgzPgYTSJ4xQ0j7J0EHf1XVv22HPgK0artSJ8Pp/xzc=; b=ekbDlJsimAXUwQ1Ca2ajGTe4wAAcInHkHujTHzUPcujovrLlu+Ze9gTfLrb13WMsUx u/+idwcEFOJpLMHoeL1lIJozgM8sArTFkDZG1PVhpBxj7Z6JhQohV83USZgA47FPsdol v2xrzKv4E9eF2MKIZdB/GthjQ+SAyRuCOUYKrRT5T2fwoNybrE1SD8bfaCbMeLyv1a+3 TclDaZuGNtDgB5VGs8v/xFTcDIkS/4o8Cn1XbBSiVVqSYDSl1GrDdrlD6ADUgn1Mj5zx UwaCYThcS1Z3eC6XHchwTJAY8pX/NqVrgsvaw4VncZjXKcB9fmkTqfmTtjbH9fbtioUv 5OjA== X-Gm-Message-State: AOJu0Yzspk0Mt6ko04mSDRIMf/lCEHLVFhft/UkVSiDn1QHt/wvuhZeY m/XlqyN3VKBj+yjNj09CF5lxxHB5T/Lz5NY3V5WbGQivQNKk0s7oR1G4scsSxlUF/oynvmtiZqc BdlV0ooE2QGLlwgu7XT4PrmAmRprd/1GuDQDX+wv7HDA5ampDdmGOsZlZSvcaeQhk7up2nimba3 iC4iAfXbDGDg== X-Gm-Gg: ATEYQzxx4r0N/jAnLNKE4YCZIpTBlQ9d1tgVVa/yMhXSl4WPdfLuHjixPniAVtHPPh7 3/nAEWApRSmTSbMkdiiRIulTlkLlcdY9KYmvLYXPxdCuJi0ZoBXpz00lnvZr0Mfg/CjLF9pGwP8 5uImLHca8SG+FBVJEW2hlrQkBK55YYMpMy+lGTN6F+hBDvtFUxPoyggZYLKPcmw2CHqbju1ZSbh OTHq4xYVfOhSJnWeAcHFBPswzL1e3g8MsxTY6CkqeC/7p928ig5L1cbVfjjNNIgDILIk3Yfx3QO iZSxBVTny0vF0qCWG3TmDc4E6/jqGFyNsKY4o8VE8Mri0Z22OxTf5k4SHZFGqOsP+XGDhZoHxfs uUOgVKmYIf+RZ+AwAir/7yddQHxZ5Gwvq+H9iTCDdYV8cjLu+BXKTP/MnHORuoiw= X-Received: by 2002:a05:600c:4ed4:b0:485:3c2d:d02b with SMTP id 5b1f17b1804b1-486f4444050mr49341815e9.22.1773831903269; Wed, 18 Mar 2026 04:05:03 -0700 (PDT) X-Received: by 2002:a05:600c:4ed4:b0:485:3c2d:d02b with SMTP id 5b1f17b1804b1-486f4444050mr49341225e9.22.1773831902790; Wed, 18 Mar 2026 04:05:02 -0700 (PDT) Received: from matperin-thinkpad.tail8a424f.ts.net ([151.36.229.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4856ea97af2sm125322895e9.4.2026.03.18.04.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 04:05:02 -0700 (PDT) To: ovs-dev@openvswitch.org Date: Wed, 18 Mar 2026 12:04:39 +0100 Message-ID: <20260318110442.102318-2-matteo.perin@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318110442.102318-1-matteo.perin@canonical.com> References: <20260318110442.102318-1-matteo.perin@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 1/4] netdev-linux: Skip vport nsid lookup for user dpif. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matteo Perin via dev From: Matteo Perin Reply-To: Matteo Perin Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" For ports on non-system (i.e. userspace) datapaths, the dpif_netlink_vport_get() call in netdev_linux_netnsid_update() is meaningless, these ports are not kernel vports. Generalize the tap class check in netdev_linux_netnsid_update() with a dpif_type check: when dpif_type is set and is not "system", assume the device is local without attempting the vport lookup. This change will cover all device types on userspace datapaths (e.g. veth pairs). Signed-off-by: Matteo Perin --- lib/netdev-linux.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 47faea8c6..c694dc1c5 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -614,7 +614,12 @@ static int netdev_linux_netnsid_update(struct netdev_linux *netdev) { if (netnsid_is_unset(netdev->netnsid)) { - if (netdev_get_class(&netdev->up) == &netdev_tap_class) { + const char *dpif_type = netdev_get_dpif_type(&netdev->up); + + if (netdev_get_class(&netdev->up) == &netdev_tap_class + || (dpif_type && strcmp(dpif_type, "system"))) { + /* vport netlink lookup makes no sense for + * non-system dpif types, set nsid to local. */ netnsid_set_local(&netdev->netnsid); } else { return netdev_linux_netnsid_update__(netdev); From patchwork Wed Mar 18 11:04:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Perin X-Patchwork-Id: 2212598 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (4096-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=oCCyuYMF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4fbQwc14pRz1xy3 for ; Wed, 18 Mar 2026 22:05:36 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C3FB683C2E; Wed, 18 Mar 2026 11:05:34 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id dfJ2hUlUwAyF; Wed, 18 Mar 2026 11:05:33 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org BE21281B8A Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (4096-bit key) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=oCCyuYMF Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id BE21281B8A; Wed, 18 Mar 2026 11:05:33 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 99925C03FD; Wed, 18 Mar 2026 11:05:33 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 368ACC03FC for ; Wed, 18 Mar 2026 11:05:32 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 08D0883BC9 for ; Wed, 18 Mar 2026 11:05:15 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id arxEbKmF0353 for ; Wed, 18 Mar 2026 11:05:14 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.125.188.123; helo=smtp-relay-internal-1.canonical.com; envelope-from=matteo.perin@canonical.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org EEF0F81B98 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=reject dis=none) header.from=canonical.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org EEF0F81B98 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by smtp1.osuosl.org (Postfix) with ESMTPS id EEF0F81B98 for ; Wed, 18 Mar 2026 11:05:13 +0000 (UTC) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 3A90C3FB77 for ; Wed, 18 Mar 2026 11:05:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1773831912; bh=S8Wi19BeDxue4SuqOLtmsYaAuzWWFdrosSqXS97lT4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oCCyuYMF4M9i8i79UjV23Ecu720oZOidcsm6GbfCk+rA+Vrq2Q72Zw5XEbOUGHNp0 ZsguTwGZ2qixWY8iSCGZliKG+ri6qzvK5R+7uZy9Sp0Ze+i+8PB1gJGqWtIlxdmKJw W94BEv/D1EGHDlQakNi0dtw8vPyMgX71xmbeTXMXtXHehwHRvkEhqlpthMNKHtxa0k wvppMvQhEZ52+oLSKzQ5dQyZ/YGTca7Drshkw02LrFXK+NIglyFWoLS2YBgr5dOwPc oiQjlCPFy0Seur6I32snJ+5inFjFgPb2OSOTPJgYx5FkBR834DmJx+g0Yzasnjpy8R TpSKsb+SxLTs4PVi53KIhrpPOyKb6hjztd1VXpMfg+RFavQY/7eNWLtoQgS7zmv/Vo Lt26tSw2ECXtrOW0YGuT4UZbyKpq7jmlH+JfDhm4Eqy2hKlH5EbcERtLX3E3Bev4Xb lhHxjs3LYhayMDZHARx6zpmzJb5Zv/U4w3PK0iT+nHXtxfEPrKHWSJyhTq4SfrvROo Pqn1eDtObP/30bvRHP5Ue2aophP0EhZc3kpAPK/lY9Oyt6ZCjLOKKLLS5nrdnyc4R8 yH2CFFkB7PPG+o2mfvG3On2rPyyTj6DibikTcePrAvAjZ10+yYv0PVOMWqT+qMKf8R BMowp362EqI7DwgnaRbHz65s= Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-485355493aeso51602285e9.1 for ; Wed, 18 Mar 2026 04:05:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773831911; x=1774436711; 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; bh=S8Wi19BeDxue4SuqOLtmsYaAuzWWFdrosSqXS97lT4s=; b=RVsHyRg1SeR594CC+nk0oswJY7oq+h69r4AS7z0fXibCE8AErzL33GqZJTJmgmYiEv 4xGK4fnGzajuC7WfU9XqAlsCrZzTGd1x/8S4tblM25t7yNLnWRLCwFtXlHLMeScfGKh6 sgIaWwSLxVvzy8XHwaLjnUE9N2izcqI6cEpHOXy2yGsLRYyPVuXI28ZQrhSueeF5zOXs YIo0XpuULoIj4Ev7ALxqCEd3yi+OIK+S/gFO0Rk3DH7AmFSp6Hk7roF9v0KgWDSjIssm Cv4Cl5wYi/Jy3zz8K20Z6h5UJeADJ6s1bH/cO3+4mOx0qgTfGxkS0QYEH8BCgjYp9ETa X9GA== X-Gm-Message-State: AOJu0YzGTIuzkU1wYRRnLES6wz3APC0sWBQi0MUWhALMnwcqYaCJt69G azaMJzbsv+yMrMZFt7Yr+q14SC5lHdeWiWUOYdLEd3dVQf57ZI1lHkyKo5LplEUkNsWUgHbYfNa 2SEnatkorpHA9nQP7Auf9cxuzdgODFGoJCzV7IRaA8zLyurcRxJ08MyTJOYmexV1HkjZWNrqY5W fc9czTFiuBhw== X-Gm-Gg: ATEYQzyOa1+J4kRMclJCFyULfiHiINP5xm6CfjO/RGgkEaORWHx/OKYwcx11IV93ktr AR0FBHdzBp3dvYNLwaRskPzQ1ocxD68ucAFcMcjSugHkd7BSKLvSYqnbvZQ0qfHfiF40VHpah64 SGiroqpVXh+uRCoEqzjqUbEyXbuJR0DCgvWbZbrDve8tX5AEX7gjzm3z6+uFrGeVPSHAYur1C+f QnfiI24AWIU5FWbUFcNWO8eyaC47V0NDWK+CoPi2paIkkK+n61006kK+C6VbwVUd+PIJGqV5nq+ U5SSbZtIpTbu3kT9nU5FMxDR+oLZGzpnzEGDqiKGt2yEQ3qmk3d5bFVct+UlPcHI1PQgz5llwzD 55NuDFx8hmJJW0tCI+QVgKxNHVrPY32PmZCbcCFBVeG6AtGQa8THJzJiI03lWgcQ= X-Received: by 2002:a05:600c:4fc4:b0:485:3b00:f92e with SMTP id 5b1f17b1804b1-486f441bc46mr46156995e9.2.1773831911187; Wed, 18 Mar 2026 04:05:11 -0700 (PDT) X-Received: by 2002:a05:600c:4fc4:b0:485:3b00:f92e with SMTP id 5b1f17b1804b1-486f441bc46mr46156175e9.2.1773831910522; Wed, 18 Mar 2026 04:05:10 -0700 (PDT) Received: from matperin-thinkpad.tail8a424f.ts.net ([151.36.229.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4856ea97af2sm125322895e9.4.2026.03.18.04.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 04:05:10 -0700 (PDT) To: ovs-dev@openvswitch.org Date: Wed, 18 Mar 2026 12:04:40 +0100 Message-ID: <20260318110442.102318-3-matteo.perin@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318110442.102318-1-matteo.perin@canonical.com> References: <20260318110442.102318-1-matteo.perin@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 2/4] netdev-linux: Handle self nsid mapping in RTM events. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matteo Perin via dev From: Matteo Perin Reply-To: Matteo Perin Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When NETLINK_LISTEN_ALL_NSID is enabled on the RTNL notification socket, the kernel tags every broadcast RTM event with the sender nsid as looked up in the receiver namespace-id table. Normally, events originating in the local namespace carry no nsid cmsg (which OVS interprets as NETNSID_LOCAL). However, some container runtimes cause the kernel to create a self-referential nsid mapping (the root namespace gets a real nsid that points back to itself) as a side-effect of cross namespace link queries (RTM_GETLINK). When this mapping exists, the kernel tags locally-originated events with that nsid instead of omitting the cmsg, causing OVS to silently reject them. Fix this by: - At startup, query the kernel (RTM_GETNSID on /proc/self/ns/net) to discover whether a self-referential nsid mapping already exists. - Subscribe the notification socket to RTNLGRP_NSID so that RTM_NEWNSID events are received whenever the kernel creates a new nsid mapping. On receiving such a notification, immediately re-query the self-nsid. This is race-free: the notification and the first tagged event arrive on the same socket and are processed sequentially, so the self-nsid is updated before any tagged event is evaluated. - In netdev_linux_update(), treat the self-nsid as equivalent to NETNSID_LOCAL for local devices. Remote devices retain strict nsid matching via the vport-queried nsid. Signed-off-by: Matteo Perin --- lib/netdev-linux.c | 150 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 138 insertions(+), 12 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index c694dc1c5..c44aa4093 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -586,6 +586,97 @@ is_tap_netdev(const struct netdev *netdev) return netdev_get_class(netdev) == &netdev_tap_class; } +/* Cached nsid of the local namespace: + * NETNSID_LOCAL if no self-referential mapping has been found (yet). + * Set once by netdev_linux_query_self_nsid() when a local nsid mapping is + * found on a RTNLGRP_NSID notification or at startup. */ +static int netdev_linux_self_nsid = NETNSID_LOCAL; + +/* Queries the kernel for the nsid assigned to the local network namespace + * and updates netdev_linux_self_nsid if a mapping is found. */ +static void +netdev_linux_query_self_nsid(void) +{ +#ifdef HAVE_LINUX_NET_NAMESPACE_H + static const char ns_path[] = "/proc/self/ns/net"; + int fd = open(ns_path, O_RDONLY); + + if (fd >= 0) { + const int rta_offset = NLMSG_ALIGN(sizeof(struct rtgenmsg)); + struct ofpbuf request; + struct ofpbuf *reply = NULL; + int error; + + ofpbuf_init(&request, 0); + nl_msg_put_nlmsghdr(&request, + rta_offset + NL_ATTR_SIZE(sizeof(uint32_t)), + RTM_GETNSID, NLM_F_REQUEST); + ofpbuf_put_zeros(&request, rta_offset); + nl_msg_put_u32(&request, NETNSA_FD, fd); + + error = nl_transact(NETLINK_ROUTE, &request, &reply); + if (!error && reply) { + const struct nlattr *a; + + a = nl_attr_find(reply, NLMSG_HDRLEN + rta_offset, NETNSA_NSID); + if (a) { + netdev_linux_self_nsid = nl_attr_get_u32(a); + VLOG_DBG("local network namespace has nsid %d", + netdev_linux_self_nsid); + } + } + + ofpbuf_uninit(&request); + ofpbuf_delete(reply); + close(fd); + } +#endif +} + +/* Returns the nsid that the kernel assigns to the local network namespace, + * or NETNSID_LOCAL if no such mapping exists. + * + * NETLINK_LISTEN_ALL_NSID workaround: OVS enables this option on its RTNL + * notification socket so that it can receive events from remote namespaces. + * A side-effect of this option is that the kernel tags every broadcast + * (including locally-originated RTM events) with the sender nsid looked up + * in the receiver nsid table. + * + * Some container runtimes create a self-referential nsid mapping as a + * side-effect of cross-namespace link queries: the root namespace ends up + * with a real nsid that points back to itself. + * When that mapping exists, local events arrive with a set nsid instead of + * no cmsg (which OVS interprets as NETNSID_LOCAL=-1), causing the + * events to be silently rejected. + * + * This function discovers the self-nsid so that netdev_linux_update() can + * treat it as equivalent to NETNSID_LOCAL. + * + * If a self-referential mapping is created after OVS has started, the + * initial query returns NETNSID_LOCAL (no mapping found). The notification + * socket is subscribed to RTNLGRP_NSID, so netdev_linux_run() will receive + * RTM_NEWNSID when the kernel creates the mapping and immediately re-query + * the self-nsid. + * + * Once created, a self-referential nsid mapping is permanent: the kernel + * only removes nsid entries when the peer namespace is destroyed. + * + * If NETLINK_LISTEN_ALL_NSID is ever deprecated and superseded by a + * mechanism that does not tag local events with a numeric nsid, this + * workaround (and the check in netdev_linux_update()) can be removed. */ +static int +netdev_linux_get_self_nsid(void) +{ + static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; + + if (ovsthread_once_start(&once)) { + netdev_linux_query_self_nsid(); + ovsthread_once_done(&once); + } + + return netdev_linux_self_nsid; +} + static int netdev_linux_netnsid_update__(struct netdev_linux *netdev) { @@ -629,13 +720,6 @@ netdev_linux_netnsid_update(struct netdev_linux *netdev) return 0; } -static bool -netdev_linux_netnsid_is_eq(struct netdev_linux *netdev, int nsid) -{ - netdev_linux_netnsid_update(netdev); - return netnsid_eq(netdev->netnsid, nsid); -} - static bool netdev_linux_netnsid_is_remote(struct netdev_linux *netdev) { @@ -652,15 +736,19 @@ static void netdev_linux_changed(struct netdev_linux *netdev, OVS_REQUIRES(netdev->mutex); /* Returns a NETLINK_ROUTE socket listening for RTNLGRP_LINK, - * RTNLGRP_IPV4_IFADDR and RTNLGRP_IPV6_IFADDR changes, or NULL - * if no such socket could be created. */ + * RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR, and RTNLGRP_NSID changes, + * or NULL if no such socket could be created. */ static struct nl_sock * netdev_linux_notify_sock(void) { static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; static struct nl_sock *sock; unsigned int mcgroups[] = {RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR, - RTNLGRP_IPV6_IFADDR, RTNLGRP_IPV6_IFINFO}; + RTNLGRP_IPV6_IFADDR, RTNLGRP_IPV6_IFINFO, +#ifdef HAVE_LINUX_NET_NAMESPACE_H + RTNLGRP_NSID, +#endif + }; if (ovsthread_once_start(&once)) { int error; @@ -791,6 +879,21 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) if (!error) { struct rtnetlink_change change; +#ifdef HAVE_LINUX_NET_NAMESPACE_H + /* RTM_NEWNSID: a new namespace id mapping was created. + * Re-query the self-nsid in case the kernel just created + * a self-referential root-namespace mapping. */ + { + const struct nlmsghdr *nlmsg = buf.data; + + if (nlmsg->nlmsg_type == RTM_NEWNSID) { + netdev_linux_query_self_nsid(); + ofpbuf_uninit(&buf); + continue; + } + } +#endif + if (rtnetlink_parse(&buf, &change) && !change.irrelevant) { struct netdev *netdev_ = NULL; char dev_name[IFNAMSIZ]; @@ -936,9 +1039,32 @@ netdev_linux_update(struct netdev_linux *dev, int nsid, const struct rtnetlink_change *change) OVS_REQUIRES(dev->mutex) { - if (netdev_linux_netnsid_is_eq(dev, nsid)) { - netdev_linux_update__(dev, change); + netdev_linux_netnsid_update(dev); + + if (netnsid_is_remote(dev->netnsid)) { + /* Remote device: only accept events with exactly matching nsid. */ + if (!netnsid_eq(dev->netnsid, nsid)) { + return; + } + } else { + /* Local (or unresolved) device: only accept events that actually + * originated in the local namespace. + * + * NETLINK_LISTEN_ALL_NSID workaround: the kernel may tag local + * events with a real nsid instead of omitting the cmsg. The + * self-nsid is queried once at startup and refreshed whenever + * an RTM_NEWNSID notification arrives. + * + * Any other nsid means the event came from a genuinely different + * namespace and must be rejected to avoid cross-namespace name + * collisions. */ + if (!netnsid_is_local(nsid) + && nsid != netdev_linux_get_self_nsid()) { + return; + } } + + netdev_linux_update__(dev, change); } static struct netdev * From patchwork Wed Mar 18 11:04:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Perin X-Patchwork-Id: 2212599 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (4096-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=LNWz4+vy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4fbQwk4sCWz1xy3 for ; Wed, 18 Mar 2026 22:05:42 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 5068C40C9E; Wed, 18 Mar 2026 11:05:41 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id mA6uTObOVlrl; Wed, 18 Mar 2026 11:05:39 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org B0FD940CA4 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (4096-bit key) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=LNWz4+vy Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id B0FD940CA4; Wed, 18 Mar 2026 11:05:38 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9D7A7C03FD; Wed, 18 Mar 2026 11:05:38 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 05B0FC03FC for ; Wed, 18 Mar 2026 11:05:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 039A24039A for ; Wed, 18 Mar 2026 11:05:21 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id lPxMfTwfXt_6 for ; Wed, 18 Mar 2026 11:05:20 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.125.188.122; helo=smtp-relay-internal-0.canonical.com; envelope-from=matteo.perin@canonical.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 3204E403DA Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=reject dis=none) header.from=canonical.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 3204E403DA Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by smtp2.osuosl.org (Postfix) with ESMTPS id 3204E403DA for ; Wed, 18 Mar 2026 11:05:19 +0000 (UTC) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 3C68D3F19A for ; Wed, 18 Mar 2026 11:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1773831918; bh=d0YEA+n/2hd0W6W+LkgBteSqNZoT7bMLKJRIl0UjaT4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LNWz4+vyON2XDAqQ2/BhS1YsH3V/FiDOoWJarV/BrU1IH7l0MOuOq8wjykwBXYj/M RFNABz0LQfQraproDooxg3rj9bcIbmOxinUM6uAu55WHDqpI+kfRlVkKefOiKCZvO0 vCfTF91FcsQnQVWNQCR87uxVxrtdLV1TxQ0dmKONLarVzIHpQEuM3n9MixLuMzAChF kIKgYgIQpP4qX3ghCYe3yoBNOQV1PhnBen5ltudeL3elxn9OsSoLnrSLYfWfW++4dl GdwkE/mjKoJz7ig1M7KKHqLZ+K7jVAgQACobvccC6STEZ8I70OIO3F9jrbnB/lkFxB bKYm1J2Z5pgwAFjWQXbnyjHMIm1nFME33UTeXSE1NnT7ozpt1gpsjZjOptWeVH0oMs gpyKmmZDq0EGfJonN0h2EDMIg2kch9Occt6acDy+4XASCeNovFYv4TLcpCDi8/tgUU 4ZfmkTpHXYDqb0Z/MY6A5G/zJ+eHTGvAlsCGt7cjFTJB+asPU6fEuxnndzy1PH7sPV FLB9oqHns9O0VI+OC2nSwMhupoUPeIzM3nJQhuZbAjLkYvIRvoZWZTPXEowSX8Ee3P xO0IFs34Gc/tlTfBrP7DICSQY5sk1AZ5mAJ2exhooY0TQfXHAa+FEqnCpqhfYpWf1B OorQpl8ITY1YGRBkU4bSdFS8= Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-48534941525so95166695e9.2 for ; Wed, 18 Mar 2026 04:05:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773831917; x=1774436717; 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; bh=d0YEA+n/2hd0W6W+LkgBteSqNZoT7bMLKJRIl0UjaT4=; b=ChMBNgSfJdbs5sUa0ZU1BOT7iuLxc5o93ceh9p/tnGkqGfrXfMYvcZgOF0TMxGdpvD J9DEp1nkpOLC8Z1ljkbwkP73OlgNmY65cnWY9YH9Rfwk/SCVck9qNvqy9d4KHXM/7xCN c/SndNT7CZZImvr5wjQkSYARXrJCcXKx0MfrioTqgdM0GbEAygQobugi/i8F/ZkGY2X0 qK5vI0HOhmori4C3IQHTbxvR7yBFhZnvz+bNx11b0LOJWc13pyTSbSrWUb4F0PdvGyof WbM6eVkN/cMYUkYVw11NVFZUkjdaANz+qPjuQjF+9Fjl6tpAHS+LWueAx0Kb5Sq2bvBY Cx9Q== X-Gm-Message-State: AOJu0YzqP1phry1HM3eKiIM62zyHksdvcqK3J37LDlaSHPt/wzOOu+tf NMGZGH4JIdsUJ+zYPUZD91jrqoxa4hWc6KHfY9SW9qAVExcp2yxRUMVRq9VAebFQ989kw0RvZLl 4zFQG+k49V3AoN4D2won4wKO7nMQ4/ZlmKxyVP2ClJov2NHZ9vE/9xuQ2JZkC0tMAf+lJK50IfO gJyM1yAMCpwg== X-Gm-Gg: ATEYQzwJO2oyk8N7UCw88UKgxOEEdzsAVlgfYfkTCisInEFQbhMIOwyHdkXL6p+WZDt WR0H7iX8ghDQL9RDR2rBWT7VUpwwoy5nV3/GJA7spd2haCd7zACXXGXA8fI58VibIOtLkOkP9nw PUlhL6F1qomyXXckLMSzMigLRYcJBMPmuCb3UspyeApKj/hmcIEYRdvziViU5OF015JMLCng6Aw LsAoU1zfJYj8dF8lgWl7gIHbovK+GOVKMbvZKUIt+QAX7HxqRhNjkfBKQ+QDphWR3JkB9boup43 yjr+iv1sWRgzLQlcSJEqs7d9nqnwuzY2TyegurA8F+bwgGvc2jYUBC2u5xf9uRA68P8qTChmlw7 T6edJfM0Ygo+87Tw+X7m9i+z2t8ENSsRCwzzp9RRAuEuwZtpHjjfOgrAtBQWn+L8= X-Received: by 2002:a05:600c:4712:b0:485:3aa1:a7f0 with SMTP id 5b1f17b1804b1-486f442e6damr47665005e9.4.1773831917360; Wed, 18 Mar 2026 04:05:17 -0700 (PDT) X-Received: by 2002:a05:600c:4712:b0:485:3aa1:a7f0 with SMTP id 5b1f17b1804b1-486f442e6damr47664245e9.4.1773831916893; Wed, 18 Mar 2026 04:05:16 -0700 (PDT) Received: from matperin-thinkpad.tail8a424f.ts.net ([151.36.229.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4856ea97af2sm125322895e9.4.2026.03.18.04.05.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 04:05:15 -0700 (PDT) To: ovs-dev@openvswitch.org Date: Wed, 18 Mar 2026 12:04:41 +0100 Message-ID: <20260318110442.102318-4-matteo.perin@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318110442.102318-1-matteo.perin@canonical.com> References: <20260318110442.102318-1-matteo.perin@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 3/4] netdev-linux: Generalize ethtool stringset query. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matteo Perin via dev From: Matteo Perin Reply-To: Matteo Perin Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Refactor netdev_linux_read_stringset_info() and netdev_linux_read_definitions() to accept a string set type parameter, instead of hardcoding ETH_SS_FEATURES. This allows these functions to query any ethtool string set type, such as ETH_SS_STATS (i.e. device statistics). Signed-off-by: Matteo Perin --- lib/netdev-linux.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index c44aa4093..40d10f66e 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2562,7 +2562,9 @@ netdev_internal_get_stats(const struct netdev *netdev_, } static int -netdev_linux_read_stringset_info(struct netdev_linux *netdev, uint32_t *len) +netdev_linux_read_stringset_info(struct netdev_linux *netdev, + enum ethtool_stringset string_set, + uint32_t *len) { union { struct ethtool_cmd ecmd; @@ -2576,7 +2578,7 @@ netdev_linux_read_stringset_info(struct netdev_linux *netdev, uint32_t *len) sset_info.hdr.cmd = ETHTOOL_GSSET_INFO; sset_info.hdr.reserved = 0; - sset_info.hdr.sset_mask = 1ULL << ETH_SS_FEATURES; + sset_info.hdr.sset_mask = 1ULL << string_set; error = netdev_linux_do_ethtool(netdev_get_name(&netdev->up), (struct ethtool_cmd *) &sset_info, @@ -2584,11 +2586,11 @@ netdev_linux_read_stringset_info(struct netdev_linux *netdev, uint32_t *len) if (error) { return error; } - if (sset_info.hdr.sset_mask & (1ULL << ETH_SS_FEATURES)) { + if (sset_info.hdr.sset_mask & (1ULL << string_set)) { *len = sset_info.sset_len[0]; return 0; } else { - /* ETH_SS_FEATURES is not supported. */ + /* String set is not supported. */ return -EOPNOTSUPP; } } @@ -2596,13 +2598,14 @@ netdev_linux_read_stringset_info(struct netdev_linux *netdev, uint32_t *len) static int netdev_linux_read_definitions(struct netdev_linux *netdev, + enum ethtool_stringset string_set, struct ethtool_gstrings **pstrings) { struct ethtool_gstrings *strings = NULL; uint32_t len = 0; int error = 0; - error = netdev_linux_read_stringset_info(netdev, &len); + error = netdev_linux_read_stringset_info(netdev, string_set, &len); if (error) { return error; } else if (!len) { @@ -2612,7 +2615,7 @@ netdev_linux_read_definitions(struct netdev_linux *netdev, strings = xzalloc(sizeof *strings + len * ETH_GSTRING_LEN); strings->cmd = ETHTOOL_GSTRINGS; - strings->string_set = ETH_SS_FEATURES; + strings->string_set = string_set; strings->len = len; error = netdev_linux_do_ethtool(netdev_get_name(&netdev->up), (struct ethtool_cmd *) strings, @@ -2644,7 +2647,7 @@ netdev_linux_set_ol(struct netdev *netdev_) COVERAGE_INC(netdev_get_ethtool); - error = netdev_linux_read_definitions(netdev, &names); + error = netdev_linux_read_definitions(netdev, ETH_SS_FEATURES, &names); if (error) { return; } From patchwork Wed Mar 18 11:04:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Perin X-Patchwork-Id: 2212600 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (4096-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=kfZUnqaL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4fbQwz6TK1z1xy3 for ; Wed, 18 Mar 2026 22:05:55 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 9032661538; Wed, 18 Mar 2026 11:05:53 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id p-MX3_CskrIR; Wed, 18 Mar 2026 11:05:51 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 7C89760A71 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (4096-bit key) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20251003 header.b=kfZUnqaL Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7C89760A71; Wed, 18 Mar 2026 11:05:51 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 557DFC03FD; Wed, 18 Mar 2026 11:05:51 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 63D00C03FC for ; Wed, 18 Mar 2026 11:05:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id CE33060A50 for ; Wed, 18 Mar 2026 11:05:24 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Dsr4z-EVebzw for ; Wed, 18 Mar 2026 11:05:24 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=185.125.188.123; helo=smtp-relay-internal-1.canonical.com; envelope-from=matteo.perin@canonical.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org BA77360A4C Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=reject dis=none) header.from=canonical.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org BA77360A4C Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by smtp3.osuosl.org (Postfix) with ESMTPS id BA77360A4C for ; Wed, 18 Mar 2026 11:05:23 +0000 (UTC) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 2A6613FB56 for ; Wed, 18 Mar 2026 11:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1773831922; bh=47O0eD5FF5yIPL32bLEhYDihgr0O3/hnRiIkJDdUkeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfZUnqaLlTLwq6cbiGDoI3jzQL4jCLmFYH/3OgBiIzMzlTpH9KYbSafD2RlfWcQwb tqCS7ECDT15we2L7AC2SJ/qthQLJmLAvsr+byS9mnBF2ecRpwpgfsArL1MLS8h0YS7 n9sjdJ++/KG9Nny2cmiYQVIv4af5wB/SN6szSPVwPZcmXeLzU1zl5ZsB8Sc3irtjgC ULwvvb0ya1ny+tlgeQ6QVsc081m3GHMs5rX4gWeu3VNC+gDM6FtB06eG++py+U6+CH fnlZxTcMvX6GiQ76cZCo9rfWDCMWTCtssKwHBBeZKaZokM58TUDvuN+ZjkQCqdPcHs QoZK1mV7+DOtFthzpDKk1MKs7GotDgXaLAePLFb42P38Hp87Fp/0X4vAJcuXxEPU/P wCpwRTs90Ze78leto21KMHB7DFj+U+ty+XiPtXuuhZGd/hhgrgv/XRHE28oWwAQoa4 IHSNOizLIkxh6RFBt3iqxoljx8c56yZHQd7+JrtQYQSFb3WSpU94coipea3vR6QcVI +s+8G3En0H/KcBwI1OPeftwXv/XtnAO4oQbjt5ILPrOhswKVkW2TR7Sv1ntYSDvBAM ZALWtv6OuiAmcSqZDVjGcCX2wxpxVZZV5FiGDBgLnOtQApE18aTw9rDUyiu4geSTlN DCcq8bRHOIfDhEq6Z2tOTgCA= Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48553fdd03dso39272725e9.0 for ; Wed, 18 Mar 2026 04:05:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773831921; x=1774436721; 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; bh=47O0eD5FF5yIPL32bLEhYDihgr0O3/hnRiIkJDdUkeo=; b=NKG/eOts62WyjWIlsmFSBK+FaDNjct91UIMdfHx29GkBSbTHNqxe8hhDb3Txplk1dh N08JOo6mVLY0yYIL4JGmaf0mAMxdViiUyMu6iIirh4zQmD8v7YWErM3Kh6HtMpTUwaKB o/YOMierOGbC0qj7khYPeV14unF8BaiJPSdpUVHVlQLxt1LgB783wQhERtTUl5j+hgM+ S1SsadvJvP+xTkUtnOQoBPXbA9MQvbadbFuUfPqmILiqz8JxfwI3Q3lSut/6ZIwSc+H1 9+K2JeXpkqDhBEMoJR30K1KALZRj9ZUCjYLmpeRxgcR2SWNcyNZJpGR7RwpDKhjvVFPM fIlQ== X-Gm-Message-State: AOJu0YyH3ykaqqZLIP2WUf6jMu8pwUrs3rmoUMIBMD6HNUFeKpm3hRCe RLklqwYt1AeYK4PynFdQ1GtQSNf4ODSZrqPnIhYJYtvyg3Me56n/TF3KJAfLd1FvE/fTalyQLl+ fFPsBod3qm/862HI19GpVyRLdFXkzCWP36+uLHWxyCkup+KxzhAnlmqkCKfWdrzjNkzeKbI3+Yj wi9ajnzjn02Q== X-Gm-Gg: ATEYQzx1uZkPRmAQLiwyUA4yBAmrYiBHK0mmU+qSo15gqccid6g+WCgop8U2fsnIOLu +pJpNCrhiGzBW8jQNjgBdDnc7UPHl9sdRvaAMHvqFOI3ffvizty9dBTUUVqt8UQvfg/l4yxoGZa zj2Q6CMy11RZr6UT5wCEdq2PBe6IysmiC1tOf7H9/VckGsOu/S1IQZPtHEFnfJaKgyBqyxF8fhj DIiknGRbap1MSrGO1GN+/bMx+YQadO5N8g646WCiHYpXRequEroZUr60yVDnBPgbk8+O2qAzwGV I2CNQYuiKQ4DI2YPDz28cDRQRc35WDwoz8z7V7kRqao3wUtMsTTXawjsH/vWQe8jadChv/Q5yzr 15vEHruP3h1MjB3SxCvbAeSZ7UywZtk1syA9JhqV8gUPRglZapmXO+2TcNOkbVgU= X-Received: by 2002:a05:600c:4e8b:b0:471:700:f281 with SMTP id 5b1f17b1804b1-486f45797eamr50132635e9.25.1773831920810; Wed, 18 Mar 2026 04:05:20 -0700 (PDT) X-Received: by 2002:a05:600c:4e8b:b0:471:700:f281 with SMTP id 5b1f17b1804b1-486f45797eamr50131875e9.25.1773831920277; Wed, 18 Mar 2026 04:05:20 -0700 (PDT) Received: from matperin-thinkpad.tail8a424f.ts.net ([151.36.229.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4856ea97af2sm125322895e9.4.2026.03.18.04.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 04:05:19 -0700 (PDT) To: ovs-dev@openvswitch.org Date: Wed, 18 Mar 2026 12:04:42 +0100 Message-ID: <20260318110442.102318-5-matteo.perin@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318110442.102318-1-matteo.perin@canonical.com> References: <20260318110442.102318-1-matteo.perin@canonical.com> MIME-Version: 1.0 Subject: [ovs-dev] [PATCH v5 4/4] netdev-linux: Add peer_ifindex in veth iface status. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Matteo Perin via dev From: Matteo Perin Reply-To: Matteo Perin Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds the peer_ifindex to the interface status column for Linux veth devices, allowing applications like OVN to programmatically discover veth pairs without requiring additional system calls or manual configuration. The implementation leverages the existing ethtool infrastructure: - Uses ETHTOOL_GDRVINFO to identify veth devices and get n_stats - Queries ETH_SS_STATS string set to get statistic names - Dynamically allocates buffer based on n_stats - Uses ETHTOOL_GSTATS to retrieve veth statistics - Finds peer_ifindex by name in the statistics array The ifindex value is cached to avoid scalability issues with a considerable amount of ports. The cached peer_ifindex is then properly invalidated when the corresponding veth device is removed. This ensures that, when veth pairs are deleted and recreated with the same name, the new peer_ifindex is correctly detected and reported. A test that create veth pairs across network namespaces, verifies peer_ifindex reporting, and validates correct detection of ifindex changes when pairs are recreated was added as well. Signed-off-by: Matteo Perin --- lib/netdev-linux-private.h | 1 + lib/netdev-linux.c | 52 ++++++++++++++++++++++++++++++++++++++ tests/system-interface.at | 48 +++++++++++++++++++++++++++++++++++ vswitchd/vswitch.xml | 13 ++++++++++ 4 files changed, 114 insertions(+) diff --git a/lib/netdev-linux-private.h b/lib/netdev-linux-private.h index cf4a021d3..3f3fc04b5 100644 --- a/lib/netdev-linux-private.h +++ b/lib/netdev-linux-private.h @@ -97,6 +97,7 @@ struct netdev_linux { uint8_t current_duplex; /* Cached from ETHTOOL_GSET. */ struct ethtool_drvinfo drvinfo; /* Cached from ETHTOOL_GDRVINFO. */ + uint64_t peer_ifindex; /* Cached from ETHTOOL_GSTATS (veth). */ struct tc *tc; /* For devices of class netdev_tap_class only. */ diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 40d10f66e..ec2d0bc2f 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -3853,6 +3853,51 @@ netdev_linux_get_next_hop(const struct in_addr *host, struct in_addr *next_hop, return ENXIO; } +/* For veth devices, query peer_ifindex via ethtool statistics. */ +static void +netdev_linux_get_peer_ifindex(struct netdev_linux *netdev) +{ + struct ethtool_gstrings *names = NULL; + struct ethtool_stats *stats = NULL; + size_t n_stats = netdev->drvinfo.n_stats; + struct ethtool_cmd *cmd; + int error; + + if (strcmp(netdev->drvinfo.driver, "veth") || !n_stats) { + return; + } + + error = netdev_linux_read_definitions(netdev, ETH_SS_STATS, &names); + if (error) { + return; + } + + stats = xzalloc(sizeof *stats + n_stats * sizeof stats->data[0]); + stats->cmd = ETHTOOL_GSTATS; + stats->n_stats = n_stats; + + cmd = (struct ethtool_cmd *) stats; + error = netdev_linux_do_ethtool(netdev->up.name, cmd, + ETHTOOL_GSTATS, "ETHTOOL_GSTATS"); + if (error) { + free(stats); + free(names); + return; + } + + for (uint32_t i = 0; i < names->len && i < stats->n_stats; i++) { + char *name = (char *) &names->data[i * ETH_GSTRING_LEN]; + + if (!strcmp(name, "peer_ifindex")) { + netdev->peer_ifindex = stats->data[i]; + break; + } + } + + free(stats); + free(names); +} + int netdev_linux_get_status(const struct netdev *netdev_, struct smap *smap) { @@ -3865,11 +3910,13 @@ netdev_linux_get_status(const struct netdev *netdev_, struct smap *smap) COVERAGE_INC(netdev_get_ethtool); memset(&netdev->drvinfo, 0, sizeof netdev->drvinfo); + netdev->peer_ifindex = 0; error = netdev_linux_do_ethtool(netdev->up.name, cmd, ETHTOOL_GDRVINFO, "ETHTOOL_GDRVINFO"); if (!error) { + netdev_linux_get_peer_ifindex(netdev); netdev->cache_valid |= VALID_DRVINFO; } } @@ -3878,6 +3925,11 @@ netdev_linux_get_status(const struct netdev *netdev_, struct smap *smap) smap_add(smap, "driver_name", netdev->drvinfo.driver); smap_add(smap, "driver_version", netdev->drvinfo.version); smap_add(smap, "firmware_version", netdev->drvinfo.fw_version); + + if (netdev->peer_ifindex) { + smap_add_format(smap, "peer_ifindex", + "%"PRIu64, netdev->peer_ifindex); + } } ovs_mutex_unlock(&netdev->mutex); diff --git a/tests/system-interface.at b/tests/system-interface.at index 20a882d1c..89e36809e 100644 --- a/tests/system-interface.at +++ b/tests/system-interface.at @@ -231,3 +231,51 @@ AT_CHECK([grep 'name too long' stderr], [0], [ignore]) OVS_TRAFFIC_VSWITCHD_STOP(["/could not open network device.*name too long/d"]) AT_CLEANUP + +dnl Test that peer_ifindex is correctly reported for veth devices. +AT_SETUP([interface - veth peer_ifindex status]) +AT_SKIP_IF([test $HAVE_ETHTOOL = "no"]) + +OVS_TRAFFIC_VSWITCHD_START() + +ADD_NAMESPACES(testns) + +dnl Create a veth pair: ovs-veth0 (main ns) <-> ovs-veth1 (testns). +AT_CHECK([ip link add ovs-veth0 type veth peer name ovs-veth1]) +on_exit 'ip link del ovs-veth0' +AT_CHECK([ip link set ovs-veth1 netns testns]) + +AT_CHECK([ovs-vsctl add-port br0 ovs-veth0]) + +dnl Get the actual ifindex of ovs-veth1 in testns. +AT_CHECK([ip netns exec testns ip link show ovs-veth1], [0], [stdout]) +peer1_ifindex=$(sed -n 's/^\([[0-9]]*\):.*/\1/p' stdout) + +dnl Verify OVS reports the correct peer_ifindex. +OVS_WAIT_UNTIL_EQUAL([ovs-vsctl get interface ovs-veth0 status:peer_ifindex], + ["\"$peer1_ifindex\""]) + +dnl Recreate veth pair with the same name to test stale ifindex detection. +AT_CHECK([ip link del ovs-veth0]) +AT_CHECK([ip link add ovs-veth0 type veth peer name ovs-veth1]) +AT_CHECK([ip link set ovs-veth1 netns testns]) + +dnl Get the new peer's ifindex. +AT_CHECK([ip netns exec testns ip link show ovs-veth1], [0], [stdout]) +peer2_ifindex=$(sed -n 's/^\([[0-9]]*\):.*/\1/p' stdout) + +dnl Verify OVS detects the change and reports the new peer_ifindex. +OVS_WAIT_UNTIL_EQUAL([ovs-vsctl get interface ovs-veth0 status:peer_ifindex], + ["\"$peer2_ifindex\""]) + +dnl Verify the two peer ifindexes are different. +AT_CHECK([test "$peer1_ifindex" != "$peer2_ifindex"]) + +OVS_TRAFFIC_VSWITCHD_STOP(["dnl +/could not open network device ovs-veth0/d +/cannot get .*STP status on nonexistent port/d +/ethtool command .*on network device ovs-veth0 failed/d +/error receiving .*ovs-veth0/d +/ovs-veth0: removing policing failed/d"]) + +AT_CLEANUP diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml index b7a5afc0a..25f635e82 100644 --- a/vswitchd/vswitch.xml +++ b/vswitchd/vswitch.xml @@ -3746,6 +3746,19 @@ ovs-vsctl add-port br0 p0 -- set Interface p0 type=patch options:peer=p1 \ The version string of the network adapter's firmware, if available. + +

+ For veth devices on Linux, this column contains the interface index + of the peer veth device. This allows applications to + programmatically discover veth pairs without requiring additional + system calls or parsing network interface information. +

+

+ Only present for veth devices (when is "veth"). Not available on non-Linux systems. +

+
+ The source IP address used for an IPv4/IPv6 tunnel end-point, such as gre.