From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <nicolas.dichtel@6wind.com>
Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com
 [209.85.212.179]) by dpdk.org (Postfix) with ESMTP id 5798F2A9
 for <dev@dpdk.org>; Tue,  2 Dec 2014 10:04:33 +0100 (CET)
Received: by mail-wi0-f179.google.com with SMTP id ex7so20191316wid.12
 for <dev@dpdk.org>; Tue, 02 Dec 2014 01:04:33 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:message-id:date:from:reply-to:organization
 :user-agent:mime-version:to:cc:subject:references:in-reply-to
 :content-type:content-transfer-encoding;
 bh=Cg0SiT4W+ZmXj4/8djiaarxHAyC5uJI4iEmCnhLnOQs=;
 b=nGMc3b4jXs4cfQybb1LtkuuPTXhRykVBxsI91UXy0bzXJEvwrOUqdirSnlKuxA4TSb
 tchzbLzO7UZdQOF82Dbsa1Cb2h1n636NkLH7USPNsAryalpi/0KL+vzUqPsCQlrYhVSj
 t7mVCHEfg9VIzbRap52ofTbXdn6PxzSAofSh8tt9vXe1GqbD16D5UYYf0pFhWwSPHWeT
 50D8nAU3bbJTz5dnKfUQCdKJpMMEk9l35y3e5I0KiTbiEMbuHDRM48s6kgvFKK4h20Jl
 36Qokc22RCq+Rg+FJjAnDibFABlPs1IMyGidAjAgAsaYa7mFtlkaKJxK3KsC9UlnXt8h
 sfcw==
X-Gm-Message-State: ALoCoQmlB35eJzFXwgo8goCczhJINWS9g11FHWKCxfAQH8woZ2nqCcxklwjecoPQznkEBmR9dE3z
X-Received: by 10.180.73.7 with SMTP id h7mr90978848wiv.83.1417511073153;
 Tue, 02 Dec 2014 01:04:33 -0800 (PST)
Received: from ?IPv6:2a01:e35:8b63:dc30:209f:d612:54c8:4fbd?
 ([2a01:e35:8b63:dc30:209f:d612:54c8:4fbd])
 by mx.google.com with ESMTPSA id p14sm3041455wie.1.2014.12.02.01.04.31
 for <multiple recipients>
 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Tue, 02 Dec 2014 01:04:32 -0800 (PST)
Message-ID: <547D809E.8020607@6wind.com>
Date: Tue, 02 Dec 2014 10:04:30 +0100
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Organization: 6WIND
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:31.0) Gecko/20100101 Thunderbird/31.2.0
MIME-Version: 1.0
To: Takayuki Usui <takayuki@midokura.com>, dev@dpdk.org
References: <5476E97D.5040304@6wind.com>
 <1417486763-12883-1-git-send-email-takayuki@midokura.com>
In-Reply-To: <1417486763-12883-1-git-send-email-takayuki@midokura.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Subject: Re: [dpdk-dev] [PATCH v2] kni: create KNI interface in current
	network namespace
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
Reply-To: nicolas.dichtel@6wind.com
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 02 Dec 2014 09:04:33 -0000

Le 02/12/2014 03:19, Takayuki Usui a écrit :
> With this patch, KNI interface (e.g. vEth0) is created in the
> network namespace where the DPDK application is running.
> Otherwise, all interfaces are created in the default namespace
> in the host.
>
> put_net() is required, since get_net_ns_by_pid() increments
> the reference counter of the network namespace with get_net().
>
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> ---
>   lib/librte_eal/linuxapp/kni/kni_misc.c | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index ba77776..33c7a48 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -311,6 +311,7 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>   	struct net_device *net_dev = NULL;
>   	struct net_device *lad_dev = NULL;
>   	struct kni_dev *kni, *dev, *n;
> +	struct net *net;
>
>   	printk(KERN_INFO "KNI: Creating kni...\n");
>   	/* Check the buffer size, to avoid warning */
> @@ -354,6 +355,12 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>   		return -EBUSY;
>   	}
>
> +	net = get_net_ns_by_pid(current->pid);
> +	if (IS_ERR(net))
In case of error, you should call free_netdev(net_dev) to avoid a memory leak.

> +		return PTR_ERR(net);
> +	dev_net_set(net_dev, net);
> +	put_net(net);
> +
>   	kni = netdev_priv(net_dev);
>
>   	kni->net_dev = net_dev;
>