]> git.droids-corp.org - dpdk.git/commitdiff
kni: create interface in current network namespace
authorTakayuki Usui <takayuki@midokura.com>
Wed, 3 Dec 2014 01:37:26 +0000 (10:37 +0900)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 3 Dec 2014 19:45:19 +0000 (20:45 +0100)
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>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
lib/librte_eal/linuxapp/kni/kni_misc.c

index ba77776ddee9242c6772f314fa479c276057a153..868b32541ed21588f6a3d29c074f5f28cf77dd65 100644 (file)
@@ -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,14 @@ 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)) {
+               free_netdev(net_dev);
+               return PTR_ERR(net);
+       }
+       dev_net_set(net_dev, net);
+       put_net(net);
+
        kni = netdev_priv(net_dev);
 
        kni->net_dev = net_dev;