diff mbox

[dpdk-dev] kni: create KNI interface in current network namespace

Message ID 1416539426-20684-1-git-send-email-takayuki@midokura.com (mailing list archive)
State Changes Requested, archived
Headers show

Commit Message

Takayuki Usui Nov. 21, 2014, 3:10 a.m. UTC
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.

Signed-off-by: Takayuki Usui <takayuki@midokura.com>
---
 lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Thomas Monjalon Nov. 26, 2014, 9:26 p.m. UTC | #1
Anyone to review this KNI patch?

2014-11-21 12:10, Takayuki Usui:
> 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.
> 
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> ---
>  lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index ba77776..f4a9965 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>  		return -EBUSY;
>  	}
>  
> +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
> +
>  	kni = netdev_priv(net_dev);
>  
>  	kni->net_dev = net_dev;
Nicolas Dichtel Nov. 27, 2014, 9:06 a.m. UTC | #2
Le 21/11/2014 04:10, 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.
>
> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> ---
>   lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
> index ba77776..f4a9965 100644
> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
>   		return -EBUSY;
>   	}
>
> +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
You should test the returned value and release the refcnt.
net = get_net_ns_by_pid(current->pid)
if (IS_ERR(net))
...
put_net(net);

> +
>   	kni = netdev_priv(net_dev);
>
>   	kni->net_dev = net_dev;
>
Hemant Agrawal Dec. 1, 2014, 5:45 a.m. UTC | #3
> 2014-11-21 12:10, Takayuki Usui:
> > 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.
> >
> > Signed-off-by: Takayuki Usui <takayuki@midokura.com>
> > ---
> >  lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c
> > b/lib/librte_eal/linuxapp/kni/kni_misc.c
> > index ba77776..f4a9965 100644
> > --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
> > +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
> > @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned
> long ioctl_param)
> >  		return -EBUSY;
> >  	}
> >
> > +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
> > +

Another way to get it done is by the following. It will be init_net for the root container.

#ifdef CONFIG_NET_NS
	net_dev->nd_net = current->nsproxy->net_ns; 
#endif
> >  	kni = netdev_priv(net_dev);
> >
> >  	kni->net_dev = net_dev;
Nicolas Dichtel Dec. 1, 2014, 10:42 a.m. UTC | #4
Le 01/12/2014 06:45, Hemant@freescale.com a écrit :
>> 2014-11-21 12:10, Takayuki Usui:
>>> 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.
>>>
>>> Signed-off-by: Takayuki Usui <takayuki@midokura.com>
>>> ---
>>>   lib/librte_eal/linuxapp/kni/kni_misc.c | 2 ++
>>>   1 file changed, 2 insertions(+)
>>>
>>> diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> b/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> index ba77776..f4a9965 100644
>>> --- a/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
>>> @@ -354,6 +354,8 @@ kni_ioctl_create(unsigned int ioctl_num, unsigned
>> long ioctl_param)
>>>   		return -EBUSY;
>>>   	}
>>>
>>> +	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
>>> +
>
> Another way to get it done is by the following. It will be init_net for the root container.
>
> #ifdef CONFIG_NET_NS
> 	net_dev->nd_net = current->nsproxy->net_ns;
> #endif
No. It's always better to use existing helpers, it hides this kind of ifdef and
more importantly, it do the right things (call release_net()/hold_net())!
Reimplemented helpers is error prone.
diff mbox

Patch

diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index ba77776..f4a9965 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -354,6 +354,8 @@  kni_ioctl_create(unsigned int ioctl_num, unsigned long ioctl_param)
 		return -EBUSY;
 	}
 
+	dev_net_set(net_dev, get_net_ns_by_pid(current->pid));
+
 	kni = netdev_priv(net_dev);
 
 	kni->net_dev = net_dev;