Skip to content

Commit 4a19edb

Browse files
dsaherndavem330
authored andcommitted
netlink: Pass extack to dump handlers
Declare extack in netlink_dump and pass to dump handlers via netlink_callback. Add any extack message after the dump_done_errno allowing error messages to be returned. This will be useful when strict checking is done on dump requests, returning why the dump fails EINVAL. Signed-off-by: David Ahern <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 272a661 commit 4a19edb

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/linux/netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ struct netlink_callback {
176176
void *data;
177177
/* the module that dump function belong to */
178178
struct module *module;
179+
struct netlink_ext_ack *extack;
179180
u16 family;
180181
u16 min_dump_alloc;
181182
unsigned int prev_seq, seq;

net/netlink/af_netlink.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,7 @@ EXPORT_SYMBOL(__nlmsg_put);
21712171
static int netlink_dump(struct sock *sk)
21722172
{
21732173
struct netlink_sock *nlk = nlk_sk(sk);
2174+
struct netlink_ext_ack extack = {};
21742175
struct netlink_callback *cb;
21752176
struct sk_buff *skb = NULL;
21762177
struct nlmsghdr *nlh;
@@ -2222,8 +2223,11 @@ static int netlink_dump(struct sock *sk)
22222223
skb_reserve(skb, skb_tailroom(skb) - alloc_size);
22232224
netlink_skb_set_owner_r(skb, sk);
22242225

2225-
if (nlk->dump_done_errno > 0)
2226+
if (nlk->dump_done_errno > 0) {
2227+
cb->extack = &extack;
22262228
nlk->dump_done_errno = cb->dump(skb, cb);
2229+
cb->extack = NULL;
2230+
}
22272231

22282232
if (nlk->dump_done_errno > 0 ||
22292233
skb_tailroom(skb) < nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
@@ -2246,6 +2250,12 @@ static int netlink_dump(struct sock *sk)
22462250
memcpy(nlmsg_data(nlh), &nlk->dump_done_errno,
22472251
sizeof(nlk->dump_done_errno));
22482252

2253+
if (extack._msg && nlk->flags & NETLINK_F_EXT_ACK) {
2254+
nlh->nlmsg_flags |= NLM_F_ACK_TLVS;
2255+
if (!nla_put_string(skb, NLMSGERR_ATTR_MSG, extack._msg))
2256+
nlmsg_end(skb, nlh);
2257+
}
2258+
22492259
if (sk_filter(sk, skb))
22502260
kfree_skb(skb);
22512261
else

0 commit comments

Comments
 (0)