]> git.baikalelectronics.ru Git - kernel.git/commitdiff
netlink: Pass extack to dump handlers
authorDavid Ahern <dsahern@gmail.com>
Mon, 8 Oct 2018 03:16:22 +0000 (20:16 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 Oct 2018 17:39:03 +0000 (10:39 -0700)
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 <dsahern@gmail.com>
Acked-by: Christian Brauner <christian@brauner.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netlink.h
net/netlink/af_netlink.c

index 71f121b66ca896a455d4ebf310c94d4a0472eaff..88c8a2d83eb3c78bed8edb635ed9c41d03e1155f 100644 (file)
@@ -176,6 +176,7 @@ struct netlink_callback {
        void                    *data;
        /* the module that dump function belong to */
        struct module           *module;
+       struct netlink_ext_ack  *extack;
        u16                     family;
        u16                     min_dump_alloc;
        unsigned int            prev_seq, seq;
index e3a0538ec0bed789a245a1f50e121f9fb2f2a836..7ac585f33a9e6f78b16482509d807169e3d730a2 100644 (file)
@@ -2171,6 +2171,7 @@ EXPORT_SYMBOL(__nlmsg_put);
 static int netlink_dump(struct sock *sk)
 {
        struct netlink_sock *nlk = nlk_sk(sk);
+       struct netlink_ext_ack extack = {};
        struct netlink_callback *cb;
        struct sk_buff *skb = NULL;
        struct nlmsghdr *nlh;
@@ -2222,8 +2223,11 @@ static int netlink_dump(struct sock *sk)
        skb_reserve(skb, skb_tailroom(skb) - alloc_size);
        netlink_skb_set_owner_r(skb, sk);
 
-       if (nlk->dump_done_errno > 0)
+       if (nlk->dump_done_errno > 0) {
+               cb->extack = &extack;
                nlk->dump_done_errno = cb->dump(skb, cb);
+               cb->extack = NULL;
+       }
 
        if (nlk->dump_done_errno > 0 ||
            skb_tailroom(skb) < nlmsg_total_size(sizeof(nlk->dump_done_errno))) {
@@ -2246,6 +2250,12 @@ static int netlink_dump(struct sock *sk)
        memcpy(nlmsg_data(nlh), &nlk->dump_done_errno,
               sizeof(nlk->dump_done_errno));
 
+       if (extack._msg && nlk->flags & NETLINK_F_EXT_ACK) {
+               nlh->nlmsg_flags |= NLM_F_ACK_TLVS;
+               if (!nla_put_string(skb, NLMSGERR_ATTR_MSG, extack._msg))
+                       nlmsg_end(skb, nlh);
+       }
+
        if (sk_filter(sk, skb))
                kfree_skb(skb);
        else