Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

netdev-genl: Set extack and fix error on napi-get

In commit 27f91aaf49b3 ("netdev-genl: Add netlink framework functions
for napi"), when an invalid NAPI ID is specified the return value
-EINVAL is used and no extack is set.

Change the return value to -ENOENT and set the extack.

Before this commit:

$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--do napi-get --json='{"id": 451}'
Netlink error: Invalid argument
nl_len = 36 (20) nl_flags = 0x100 nl_type = 2
error: -22

After this commit:

$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml \
--do napi-get --json='{"id": 451}'
Netlink error: No such file or directory
nl_len = 44 (28) nl_flags = 0x300 nl_type = 2
error: -2
extack: {'bad-attr': '.id'}

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Joe Damato <jdamato@fastly.com>
Link: https://patch.msgid.link/20240831121707.17562-1-jdamato@fastly.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Joe Damato and committed by
Jakub Kicinski
4e3a024b 55ddb6c5

+5 -3
+5 -3
net/core/netdev-genl.c
··· 216 216 rtnl_lock(); 217 217 218 218 napi = napi_by_id(napi_id); 219 - if (napi) 219 + if (napi) { 220 220 err = netdev_nl_napi_fill_one(rsp, napi, info); 221 - else 222 - err = -EINVAL; 221 + } else { 222 + NL_SET_BAD_ATTR(info->extack, info->attrs[NETDEV_A_NAPI_ID]); 223 + err = -ENOENT; 224 + } 223 225 224 226 rtnl_unlock(); 225 227