[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8fa3ba08-e488-13c8-7a2b-8227c5fd77df@gmail.com>
Date: Wed, 21 Nov 2018 11:05:11 -0700
From: David Ahern <dsahern@...il.com>
To: Nicolas Dichtel <nicolas.dichtel@...nd.com>, davem@...emloft.net
Cc: netdev@...r.kernel.org
Subject: Re: [PATCH net-next 2/4] netns: add support of NETNSA_TARGET_NSID
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)
>
Powered by blists - more mailing lists