Skip to content

Commit

Permalink
netdev-genl: Set extack and fix error on napi-get
Browse files Browse the repository at this point in the history
In commit 27f91aa ("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>
  • Loading branch information
Joe Damato authored and Jakub Kicinski committed Sep 3, 2024
1 parent 55ddb6c commit 4e3a024
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/core/netdev-genl.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info)
rtnl_lock();

napi = napi_by_id(napi_id);
if (napi)
if (napi) {
err = netdev_nl_napi_fill_one(rsp, napi, info);
else
err = -EINVAL;
} else {
NL_SET_BAD_ATTR(info->extack, info->attrs[NETDEV_A_NAPI_ID]);
err = -ENOENT;
}

rtnl_unlock();

Expand Down

0 comments on commit 4e3a024

Please sign in to comment.