From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Brauner Subject: Re: [PATCH net-next 01/20] netlink: Pass extack to dump handlers Date: Fri, 5 Oct 2018 19:41:05 +0200 Message-ID: <20181005174104.fdf5rxkqgyum5niu@brauner.io> References: <20181004213355.14899-1-dsahern@kernel.org> <20181004213355.14899-2-dsahern@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: netdev@vger.kernel.org, davem@davemloft.net, jbenc@redhat.com, stephen@networkplumber.org, David Ahern To: David Ahern Return-path: Received: from mail-wr1-f66.google.com ([209.85.221.66]:45199 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbeJFAk5 (ORCPT ); Fri, 5 Oct 2018 20:40:57 -0400 Received: by mail-wr1-f66.google.com with SMTP id q5-v6so14353066wrw.12 for ; Fri, 05 Oct 2018 10:41:12 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20181004213355.14899-2-dsahern@kernel.org> Sender: netdev-owner@vger.kernel.org List-ID: On Thu, Oct 04, 2018 at 02:33:36PM -0700, David Ahern wrote: > From: David Ahern > > 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 Acked-by: Christian Brauner > --- > include/linux/netlink.h | 1 + > net/netlink/af_netlink.c | 12 +++++++++++- > 2 files changed, 12 insertions(+), 1 deletion(-) > > diff --git a/include/linux/netlink.h b/include/linux/netlink.h > index 71f121b66ca8..88c8a2d83eb3 100644 > --- a/include/linux/netlink.h > +++ b/include/linux/netlink.h > @@ -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; > diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c > index e3a0538ec0be..7ac585f33a9e 100644 > --- a/net/netlink/af_netlink.c > +++ b/net/netlink/af_netlink.c > @@ -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 > -- > 2.11.0 >