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.