From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Dichtel Subject: Re: [PATCH net-next 2/4] netns: add support of NETNSA_TARGET_NSID Date: Wed, 21 Nov 2018 21:58:42 +0100 Message-ID: References: <20181121110124.5501-1-nicolas.dichtel@6wind.com> <20181121110124.5501-3-nicolas.dichtel@6wind.com> <8fa3ba08-e488-13c8-7a2b-8227c5fd77df@gmail.com> Reply-To: nicolas.dichtel@6wind.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Cc: netdev@vger.kernel.org To: David Ahern , davem@davemloft.net Return-path: Received: from mail-wm1-f68.google.com ([209.85.128.68]:40393 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbeKVHen (ORCPT ); Thu, 22 Nov 2018 02:34:43 -0500 Received: by mail-wm1-f68.google.com with SMTP id q26so7075586wmf.5 for ; Wed, 21 Nov 2018 12:58:45 -0800 (PST) In-Reply-To: <8fa3ba08-e488-13c8-7a2b-8227c5fd77df@gmail.com> Content-Language: fr Sender: netdev-owner@vger.kernel.org List-ID: Le 21/11/2018 à 19:05, David Ahern a écrit : > 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. The target-nsid is not stored in net_cb (not needed). ref_net is set only if tgt_net comes from TARGET_NSID. I can add a comment.