psp: don't report the main netdevice's ifindex to associated namespaces

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.

Reviewed-by: Daniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20260912200426.121025-3-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jakub Kicinski 2026-09-12 13:04:22 -07:00
parent fbcd35eb18
commit cf3302111b
2 changed files with 7 additions and 2 deletions

View File

@ -38,6 +38,8 @@ attribute-sets:
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-cap

View File

@ -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;