From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [PATCH net-next 2/4] netns: add support of NETNSA_TARGET_NSID Date: Wed, 21 Nov 2018 11:05:11 -0700 Message-ID: <8fa3ba08-e488-13c8-7a2b-8227c5fd77df@gmail.com> References: <20181121110124.5501-1-nicolas.dichtel@6wind.com> <20181121110124.5501-3-nicolas.dichtel@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org To: Nicolas Dichtel , davem@davemloft.net Return-path: Received: from mail-pl1-f196.google.com ([209.85.214.196]:36909 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729828AbeKVEki (ORCPT ); Wed, 21 Nov 2018 23:40:38 -0500 Received: by mail-pl1-f196.google.com with SMTP id b5so6592824plr.4 for ; Wed, 21 Nov 2018 10:05:15 -0800 (PST) In-Reply-To: <20181121110124.5501-3-nicolas.dichtel@6wind.com> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: On 11/21/18 4:01 AM, Nicolas Dichtel wrote: > static int rtnl_net_dumpid(struct sk_buff *skb, struct netlink_callback *cb) > { > - struct net *net = sock_net(skb->sk); > struct rtnl_net_dump_cb net_cb = { > - .net = net, > + .tgt_net = sock_net(skb->sk), > .skb = skb, > .cb = cb, > .idx = 0, > .s_idx = cb->args[0], > }; > + int err = 0; > > - if (cb->strict_check && > - nlmsg_attrlen(cb->nlh, sizeof(struct rtgenmsg))) { > - NL_SET_ERR_MSG(cb->extack, "Unknown data in network namespace id dump request"); > - return -EINVAL; > + if (cb->strict_check) { > + err = rtnl_valid_dump_net_req(cb->nlh, skb->sk, &net_cb, cb); > + if (err < 0) > + goto end; > } > > - spin_lock_bh(&net->nsid_lock); > - idr_for_each(&net->netns_ids, rtnl_net_dumpid_one, &net_cb); > - spin_unlock_bh(&net->nsid_lock); > + spin_lock_bh(&net_cb.tgt_net->nsid_lock); > + idr_for_each(&net_cb.tgt_net->netns_ids, rtnl_net_dumpid_one, &net_cb); > + spin_unlock_bh(&net_cb.tgt_net->nsid_lock); > > cb->args[0] = net_cb.idx; > - return skb->len; > +end: > + if (net_cb.ref_net) > + put_net(net_cb.tgt_net); That is going to lead to confusion -- you check that ref_net is set put do a put on tgt_net. Other places using a target namespace use the nsid as the key to whether a put_net is needed. > + return err < 0 ? err : skb->len; > } > > static void rtnl_net_notifyid(struct net *net, int cmd, int id) >