From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796130636; b=erlLQ2TScav3sfZzbvTD/7mRiRfBUJ8R5/f5t3PfxdpSgm+Iyz0R6Ik1cz2YvKGgLkiH E9XtdJ2ToitiJAO+Ad/uAezoI9ifOZ6Yew5Do/KfQKgfGZAb4jCdXgoHw5523sGUJ6Bpn gM1OIb1Igwvy3L2VcZfHneTGHrrodUtF2r49656WtDJKltMdjP86JW32bNUzb+UbH3EsX LIPLriWqcI6UtpAbulneLPwWjB1ZtPVjoIMZY2kupV74keAZtT/B11VuOHanT463/XVuc kPZesNT6ho6w2NM+RsEvILsFH0hulUbeDz0fdIA2tlSAd+pJvFIIMqIrSYmEMXg/x7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796130636; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=AIiu572Enfb/pkPnXvEjhpPEnyGmLhlDYq4S7iF5Wjw=; b=TpkRK3XETaI+0n54Cs0j5xdV+NFLtURUrpXGENzH7knT85r/r5v8oVC6YE50gx8APcKE 8srxG/MzmadkwRoX6tHkdaaagEv3AwvBmy5VV/qEuCouPSxWk8i3l6OkjdWop9GmfczNN OXae/M2MtYrg6zJzDaC6UuYb72tMi1iOBwpilknTRwRWJnO+58QNIKt2IUwPIr6zWs918 4AisJD40B9w9RpTC7e9iQHXS4Sj+S4ZGlAZUgqwzqjUu7ZTIdrWv9VOlOosh8ncwBKc2Q k2j0rjwVwUnOx+bYYHP7cAusKyp9r65soB3B+I65y64UAIAUZluXSFm1j9IUDAMkiRA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aok55EIV; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF52D606A337; Tue, 1 Dec 2026 13:10:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aok55EIV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 616041F00930; Tue, 1 Dec 2026 13:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796130635; bh=AIiu572Enfb/pkPnXvEjhpPEnyGmLhlDYq4S7iF5Wjw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=aok55EIVEGpWLuTt3wZ735HNo/O2z07F8pfEXSvh2DY+GqPXrBGhzyXgtHGS2bGGt bxp3Na4s8omclA0jXvBHysd5lwE6BBUdNDC/E9hu1HPWg2vSa884Z0M/62lVqDV25L Bc4UMytJBZRDeVfWbC8pI4IK7ITYblmOT0zjvcMbd5R2Ly4EBNQwLuYgL9lApwFbq7 lrwA1HNQ1UC2Sx5OkAN2E1N/bvX+eTk8hwA3P8E3WHqVWDL5u38i9tBJheZA+mKyXx AEhgsaoOdH8Ii+RDK8iQ56+OkNrLw1H+bpB3CqOvrS1xp0L6QhM/BdHF5m0NboR8CX zkZRcpwWpIFBg== Subject: Re: [PATCH net-next v2 13/13] selftests: net: Add a test for port ID in FDB notifications From: netdev-bot+sashiko@kernel.org To: petrm@nvidia.com Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org, andrew+netdev@lunn.ch, razor@blackwall.org, bridge@lists.linux.dev, idosch@nvidia.com, aroulin@nvidia.com, mlxsw@nvidia.com, shuah@kernel.org, linux-kselftest@vger.kernel.org Date: Tue, 01 Dec 2026 13:10:33 +0000 Message-ID: <179613063391.3146.12166861393519809084@kernel.org> In-Reply-To: References: X-sashiko-severity: Low Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: bridge@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] selftests: net: unclosed AF_PACKET socket in test_bridge_learned() - [Low] selftests: net: unclosed RtnlNeighFamily sockets in Env._socket() -- > diff --git a/tools/testing/selftests/net/fdb_notify_portid.py b/tools/testing/selftests/net/fdb_notify_portid.py > --- /dev/null > +++ b/tools/testing/selftests/net/fdb_notify_portid.py > @@ -0,0 +1,297 @@ > +#!/usr/bin/env python3 > +# SPDX-License-Identifier: GPL-2.0 > + > +""" > +Check that FDB notifications carry the netlink port ID of the requester in > +nlmsg_pid. A listener socket subscribed to the neighbour group receives the > +notifications, while separate requester sockets make the changes. The port ID > +the listener sees is expected to match that of the requester socket. > +""" > + > +import socket > +import struct > +from collections import namedtuple > + > +from lib.py import ksft_run, ksft_exit, ksft_eq, ksft_ne, ksft_true > +from lib.py import ksft_busy_wait > +from lib.py import ip, tool > +from lib.py import NetNS, NetNSEnter > +from lib.py import Netlink, RtnlNeighFamily > + > +RTM_NEWNEIGH = 28 > +RTM_DELNEIGH = 29 > + > +NTF_SELF = 0x02 > +NTF_MASTER = 0x04 > + > +NUD_NOARP = 0x40 > +NUD_PERMANENT = 0x80 > + > +ETH_P_EXP1 = 0x88b5 # Local Experimental EtherType 1 > + > +Ntf = namedtuple("Ntf", "type portid addr") > + > + > +class Env: > + """The listener socket, the two requester sockets A and B, and the > + netlink port IDs of the latter. All sockets live in the given netns.""" > + > + @staticmethod > + def _socket(ns): > + with NetNSEnter(ns): > + rtnl = RtnlNeighFamily() [Severity: Low] Env creates three RtnlNeighFamily instances per test case (listener, a and b), and nothing ever closes their netlink sockets. As far as I can tell, YnlFamily ends up in reference cycles with itself, through the per-op partials it attaches in __init__ and the family back-pointer. So refcounting does not free these objects when env goes out of scope. They hang around until the cyclic GC runs or the process exits. Across the seven test cases that is up to 21 netlink sockets. Each one pins the namespace it was created in, even after NetNS has deleted that namespace. Could Env grow a close() method, or become a context manager, that closes listener.sock, a.sock and b.sock? Alternatively, _socket() could register the close with defer(). Whichever matches how other lib.py users manage YNL sockets is fine with me. > + return rtnl > + > + def __init__(self, ns): > + self.ns = str(ns) > + > + self.listener = self._socket(ns) > + self.listener.include_raw = True > + self.listener.ntf_subscribe("rtnlgrp-neigh") > + > + self.a = self._socket(ns) > + self.a.sock.bind((0, 0)) > + > + self.b = self._socket(ns) > + self.b.sock.bind((0, 0)) > + > + self.portids = {self.a: self.a.sock.getsockname()[0], > + self.b: self.b.sock.getsockname()[0]} > + > + ksft_ne(self.portids[self.a], self.portids[self.b]) > + ksft_ne(self.portids[self.a], 0) > + > + def ifindex(self, name): > + """Look up the ifindex of a device in the test netns.""" > + with NetNSEnter(self.ns): > + return socket.if_nametoindex(name) > + > + def ntfs(self): > + """Return the bridge-family notifications received by the listener.""" > + self.listener.check_ntf() > + ntfs = [] > + while self.listener.async_msg_queue.qsize() > 0: > + msg = self.listener.async_msg_queue.get() > + if msg['msg']['ndm-family'] == socket.AF_BRIDGE: > + ntfs.append(Ntf(msg['raw'].nl_type, msg['raw'].nl_portid, > + msg['msg']['lladdr'])) > + return ntfs > + > + def check_ntfs(self, nl_type, addr, requester, count=1): > + """Expect count notifications for addr, all from the requester.""" > + portids = [n.portid for n in self.ntfs() > + if n.type == nl_type and n.addr == addr] > + ksft_eq(portids, [self.portids[requester]] * count, > + f"nlmsg_pid of {addr} notifications") > + > + > +def fdb_req(ifindex, ndm_flags, attrs): > + """Build an AF_BRIDGE neighbour request with the given attributes.""" > + return {'ndm-family': socket.AF_BRIDGE, 'ndm-ifindex': ifindex, > + 'ndm-flags': ndm_flags, **attrs} > + > + > +def test_msg(env, sock, message, message_type, > + ifindex, addr, ndm_flags, flags, count, attrs): > + """Send one request through SOCK, and expect COUNT notifications of > + MESSAGE_TYPE about ADDR carrying the port ID of SOCK.""" > + # pylint: disable=too-many-arguments,too-many-positional-arguments > + req = fdb_req(ifindex, ndm_flags, attrs | {"lladdr": addr}) > + sock.do(message, req, flags) > + env.check_ntfs(message_type, addr, sock, count) > + > + > +def add_replace_del(env, ifname, addr, ndm_flags, *, add, rep, dlt, count=1): > + """Add an entry through socket A, replace it through B, delete through A. > + ADD, REP and DLT are the attributes of the respective requests. If REP is > + None, the replace step is skipped.""" > + # pylint: disable=too-many-arguments > + ifindex = env.ifindex(ifname) > + > + test_msg(env, env.a, 'newneigh', RTM_NEWNEIGH, ifindex, addr, ndm_flags, > + flags=[Netlink.NLM_F_CREATE | Netlink.NLM_F_EXCL], > + count=count, attrs=add) > + > + if rep is not None: > + test_msg(env, env.b, 'newneigh', RTM_NEWNEIGH, ifindex, addr, ndm_flags, > + flags=[Netlink.NLM_F_CREATE | Netlink.NLM_F_REPLACE], > + count=count, attrs=rep) > + > + test_msg(env, env.a, 'delneigh', RTM_DELNEIGH, ifindex, addr, ndm_flags, > + flags=[], > + count=count, attrs=dlt) > + > + > +def flush(env, ifname, addrs, add, dlt): > + """Flush all permanent entries through socket A, and check that all the > + notifications carry the port ID.""" > + > + ifindex = env.ifindex(ifname) > + > + for addr in addrs: > + attrs = add | {"ndm-state": NUD_PERMANENT, > + "lladdr": addr} > + env.a.do('newneigh', fdb_req(ifindex, NTF_SELF, attrs), > + flags=[Netlink.NLM_F_CREATE | Netlink.NLM_F_EXCL]) > + > + env.ntfs() > + > + attrs = dlt | {'ndm-state': NUD_PERMANENT, > + 'ndm-state-mask': NUD_PERMANENT} > + env.a.do('delneigh', fdb_req(ifindex, NTF_SELF, attrs), > + flags=[Netlink.NLM_F_BULK]) > + > + ntfs = [n for n in env.ntfs() if n.type == RTM_DELNEIGH] > + > + ksft_true({n.addr for n in ntfs} >= set(addrs), > + "Flush did not notify about all the entries") > + ksft_eq({n.portid for n in ntfs}, {env.portids[env.a]}, > + "nlmsg_pid of flush notifications") > + > + > +def test_bridge() -> None: > + """Bridge port and bridge device entries: add, replace, delete.""" > + with NetNS() as ns: > + env = Env(ns) > + > + ip("link add br0 up type bridge vlan_default_pvid 0", ns=ns) > + ip("link add d0 up type dummy", ns=ns) > + ip("link set dev d0 master br0", ns=ns) > + > + add_replace_del(env, "d0", "00:11:22:33:44:01", NTF_MASTER, > + add={"ndm-state": NUD_PERMANENT}, > + rep={"ndm-state": NUD_NOARP}, > + dlt={}) > + > + add_replace_del(env, "br0", "00:11:22:33:44:02", NTF_SELF, > + add={"ndm-state": NUD_PERMANENT}, > + rep=None, > + dlt={}) > + > + > +def test_bridge_vlan() -> None: > + """Without a VID given, an entry is added and deleted in every VLAN.""" > + with NetNS() as ns: > + env = Env(ns) > + > + ip("link add br0 up type bridge vlan_filtering 1 vlan_default_pvid 0", > + ns=ns) > + ip("link add d0 up type dummy", ns=ns) > + ip("link set dev d0 master br0", ns=ns) > + > + tool("bridge", "vlan add dev d0 vid 10", ns=ns) > + tool("bridge", "vlan add dev d0 vid 20", ns=ns) > + > + # Three notifications: for VID 10 and 20, and for the entry > + # without VLAN. > + add_replace_del(env, "d0", "00:11:22:33:44:03", NTF_MASTER, count=3, > + add={"ndm-state": NUD_PERMANENT}, > + rep=None, > + dlt={}) > + > + > +def test_bridge_flush() -> None: > + """Bulk delete of bridge entries.""" > + with NetNS() as ns: > + env = Env(ns) > + ip("link add br0 up type bridge vlan_default_pvid 0", ns=ns) > + ip("link add d0 up type dummy", ns=ns) > + ip("link set dev d0 master br0", ns=ns) > + > + flush(env, "br0", ["00:11:22:33:44:10", > + "00:11:22:33:44:11", > + "00:11:22:33:44:12"], > + add={}, > + dlt={}) > + > + > +def test_bridge_learned() -> None: > + """Entries that are not a result of a request carry port ID of zero.""" > + with NetNS() as ns: > + env = Env(ns) > + ip("link add br0 up type bridge", ns=ns) > + ip("link add v0 up type veth peer name v1", ns=ns) > + ip("link set dev v0 master br0", ns=ns) > + ip("link set dev v1 up", ns=ns) > + > + addr = "00:11:22:33:44:31" > + frame = (b"\xff" * 6 + bytes.fromhex(addr.replace(":", "")) + > + struct.pack("!H", ETH_P_EXP1) + b"\0" * 46) > + with NetNSEnter(env.ns): > + tx = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) > + tx.bind(("v1", 0)) > + > + portids = [] > + > + def learned(): > + nonlocal portids > + tx.send(frame) > + portids = [n.portid for n in env.ntfs() > + if n.type == RTM_NEWNEIGH and n.addr == addr] > + return portids != [] > + > + # Keep sending until the entry is learned: a frame that > + # arrives while the bridge port is not yet up is dropped > + # without triggering learning. Once the entry exists, repeated > + # frames only refresh it and do not generate notifications. > + ksft_busy_wait(learned, deadline=2) > + > + ksft_eq(portids, [0], "nlmsg_pid of learned entry") > + > + > +def test_vxlan() -> None: > + """VXLAN entries: add, replace the remote, delete.""" > + with NetNS() as ns: > + env = Env(ns) > + ip("link add vx0 up type vxlan id 2000 dstport 4789", ns=ns) > + > + add_replace_del(env, "vx0", "00:11:22:33:44:41", NTF_SELF, > + add={"dst": "192.0.2.1", "ndm-state": NUD_PERMANENT}, > + rep={"dst": "192.0.2.2", "ndm-state": NUD_PERMANENT}, > + dlt={"dst": "192.0.2.2"}) > + > + > +def test_vxlan_flush() -> None: > + """Bulk delete of VXLAN entries.""" > + with NetNS() as ns: > + env = Env(ns) > + ip("link add vx0 up type vxlan id 2000 dstport 4789", ns=ns) > + > + flush(env, "vx0", ["00:11:22:33:44:50", > + "00:11:22:33:44:51", > + "00:11:22:33:44:52"], > + add={"dst": "192.0.2.1"}, > + dlt={"dst": "192.0.2.1"}) > + > + > +def test_macvlan() -> None: > + """The notifications for macvlan, which does not notify by itself, are > + sent by the generic code in rtnetlink.""" > + with NetNS() as ns: > + env = Env(ns) > + ip("link add dd up type dummy", ns=ns) > + ip("link add mv0 up link dd type macvlan mode passthru", ns=ns) > + > + # macvlan does not support replace. > + add_replace_del(env, "mv0", "00:11:22:33:44:61", NTF_SELF, > + add={"ndm-state": NUD_PERMANENT}, > + rep=None, > + dlt={}) > + > + > +def main() -> None: > + """Run all the tests.""" > + ksft_run([ > + test_bridge, > + test_bridge_vlan, > + test_bridge_flush, > + test_bridge_learned, > + test_vxlan, > + test_vxlan_flush, > + test_macvlan, > + ]) > + ksft_exit() > + > + > +if __name__ == "__main__": > + main() [Severity: Low] The raw AF_PACKET socket opened here is never closed. tx is still referenced by the learned() closure, so it stays open and bound to v1 until test_bridge_learned() returns. That means it is still alive while NetNS.__exit__() tears the namespace down. It also leaks if ksft_busy_wait() or ksft_eq() raises. An open socket keeps its network namespace alive, so the namespace outlives its deletion for no good reason. It is a minor thing for a single test, but it is easy to avoid. You could wrap the busy wait in a with block on tx, or register defer(tx.close) right after the socket is created. -- Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796041491.git.petrm%40nvidia.com