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
Subject: Re: [PATCH net-next v2 13/13] selftests: net: Add a test for port ID in FDB notifications
Date: Tue, 01 Dec 2026 13:10:33 +0000 [thread overview]
Message-ID: <179613063391.3146.12166861393519809084@kernel.org> (raw)
In-Reply-To: <d31f15a3f8e54b84954afad7d57178086d1c9a49.1796041491.git.petrm@nvidia.com>
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
next prev parent reply other threads:[~2026-12-01 13:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:03 [PATCH net-next v2 00/13] net: Report requester's port ID in FDB notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 01/13] net: Introduce struct ndo_fdb_parms Petr Machata
2026-12-01 13:10 ` netdev-bot+sashiko
2026-11-30 13:03 ` [PATCH net-next v2 02/13] net: Pass struct ndo_fdb_parms to ndo_dflt_fdb_{add, del}() Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 03/13] net: Pass portid to ndo_fdb_get through the structure Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 04/13] net: bridge: Pass struct ndo_fdb_parms a bit further Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 05/13] net: bridge: Pass portid through FDB notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 06/13] net: vxlan: " Petr Machata
2026-12-01 13:10 ` netdev-bot+sashiko
2026-11-30 13:03 ` [PATCH net-next v2 07/13] net: rtnetlink: Report port ID in bridge and VXLAN " Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 08/13] net: rtnetlink: Report port ID in bulk FDB delete notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 09/13] net: rtnetlink: Report port ID in fallback FDB notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 10/13] netlink: specs: rt-neigh: Extend the delneigh request attributes Petr Machata
2026-12-01 13:10 ` netdev-bot+sashiko
2026-11-30 13:03 ` [PATCH net-next v2 11/13] tools: ynl: Add NLM_F_BULK Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 12/13] selftests: net: lib: py: Add RtnlNeighFamily Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 13/13] selftests: net: Add a test for port ID in FDB notifications Petr Machata
2026-12-01 13:10 ` netdev-bot+sashiko [this message]
2026-11-30 13:24 ` [PATCH net-next v2 00/13] net: Report requester's " Przemek Kitszel
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=179613063391.3146.12166861393519809084@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=aroulin@nvidia.com \
--cc=bridge@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=razor@blackwall.org \
--cc=shuah@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox