Re: [PATCH net-next 2/6] psp: don't report the main netdevice's ifindex to associated namespaces
From: "Daniel Zahka" <daniel.zahka@gmail.com>
Date: 2026-09-14 12:02:26
Also in:
linux-kselftest
On Sat Sep 12, 2026 at 4:04 PM EDT, Jakub Kicinski wrote:
quoted hunk ↗ jump to hunk
PSP device is visible in a netns if any of the devices (eg. netkit) are associated with that PSP device. In the main netns we show all the associated netdevs + their netns id. In the "container" netns we show only the local devices. But we were listing the main netdev in all cases, even though it's meaningless outside of the main netns. Report ifindex only in the main netdevice's namespace. Absence is already unambiguous, the by-association flag is set exactly in the messages which no longer carry the ifindex. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- Documentation/netlink/specs/psp.yaml | 2 ++ net/psp/psp_nl.c | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-)diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml index e9c2ee7e28e0..f3266763c325 100644 --- a/Documentation/netlink/specs/psp.yaml +++ b/Documentation/netlink/specs/psp.yaml@@ -38,6 +38,8 @@ name: psp doc: | ifindex of the main netdevice linked to the PSP device, or the ifindex to associate with the PSP device. + Only reported to the network namespace the main netdevice + lives in, an ifindex has no meaning outside of it. type: u32 - name: psp-versions-capdiff --git a/net/psp/psp_nl.c b/net/psp/psp_nl.c index f91665748dde..b57366b5e032 100644 --- a/net/psp/psp_nl.c +++ b/net/psp/psp_nl.c@@ -294,13 +294,16 @@ psp_nl_dev_fill(struct psp_dev *psd, struct sk_buff *rsp, return -EMSGSIZE; if (nla_put_u32(rsp, PSP_A_DEV_ID, psd->id) || - nla_put_u32(rsp, PSP_A_DEV_IFINDEX, psd->main_netdev->ifindex) || nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_CAP, psd->caps->versions) || nla_put_u32(rsp, PSP_A_DEV_PSP_VERSIONS_ENA, psd->config.versions)) goto err_cancel_msg; if (cur_net == dev_net(psd->main_netdev)) { - /* Primary device - dump assoc list */ + /* Primary device - report the netdev, dump assoc list. */ + if (nla_put_u32(rsp, PSP_A_DEV_IFINDEX, + psd->main_netdev->ifindex)) + goto err_cancel_msg; + err = psp_nl_fill_assoc_dev_list(psd, rsp, cur_net, NULL); if (err) goto err_cancel_msg;
As an aside, this got me looking at psp_nl_fill_assoc_dev_list() again. The PSP_A_ASSOC_DEV_INFO_NSID handling there looks a bit buggy. Caller sees -1 when the assoc dev is in their namespace, unless they are in the psp_dev's main_netdev's netns. In that case, a self referential nsid is allocated with peernet2id_alloc(). It probably would have made more sense to just only include PSP_A_ASSOC_DEV_INFO_NSID if !net_eq(cur_net, dev_net_ns). I don't suppose it makes any real bugs reachable. Reviewed-by: Daniel Zahka <daniel.zahka@gmail.com>