From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Dichtel Subject: Re: [PATCH v2] kni: create KNI interface in current network namespace Date: Tue, 02 Dec 2014 10:04:30 +0100 Message-ID: <547D809E.8020607@6wind.com> References: <5476E97D.5040304@6wind.com> <1417486763-12883-1-git-send-email-takayuki@midokura.com> Reply-To: nicolas.dichtel-pdR9zngts4EAvxtiuMwx3w@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable To: Takayuki Usui , dev-VfR2kkLFssw@public.gmane.org Return-path: In-Reply-To: <1417486763-12883-1-git-send-email-takayuki-SN072n759w5Wk0Htik3J/w@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" Le 02/12/2014 03:19, Takayuki Usui a =C3=A9crit : > 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 > --- > 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/li= nuxapp/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 l= ong ioctl_param) > struct net_device *net_dev =3D NULL; > struct net_device *lad_dev =3D 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 =3D 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 =3D netdev_priv(net_dev); > > kni->net_dev =3D net_dev; >