From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by dpdk.org (Postfix) with ESMTP id 2B99C32A5 for ; Tue, 2 Dec 2014 03:19:39 +0100 (CET) Received: by mail-pa0-f45.google.com with SMTP id lj1so12407611pab.32 for ; Mon, 01 Dec 2014 18:19:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3FygP7r5ZQvmsfTKJDS2IgcyP6e0scrEDWLPhO50XYg=; b=Q6zlZYhxuuZkVrWkIB6TGzBAcZETuWbeTJ6uzbcYvhhTh27SOdX3MLQLX5ezfxmU7g r/d46Yy3ykufKHUXljOhuJGKSjT1xgSk0zkFl1pJFsDynWO3Tu0J/IPu4F7I6I96hbpt 7d7yCZBUuZR5UD4NvWxCRxCkPyN6vifWG2qjl5ewwBcJ2c7FuYj87xZw7JYIo4GWaToU kTUoZfQcWmOekxrrYdvcmMmoXLxuSftxXBATSWFRmMwmqplvOnBwxeTyG/8mzHDUrZKX LqniPwjoqo7s7LvhAJjiyMirFD0zU8WMD5SP8qeGxmVuAT+kzxf1BIDkPYVbjKcG975V ZJlg== X-Gm-Message-State: ALoCoQlR8GlNLyBoDj4oc9Q19ytgdOGyPZwhFGLp0Fpd/x9N/sYsNtk9LblcYbT7tKeczAYu6puB X-Received: by 10.68.230.10 with SMTP id su10mr1156589pbc.129.1417486778325; Mon, 01 Dec 2014 18:19:38 -0800 (PST) Received: from orifice.localdomain ([240b:10:25c0:200:8415:58eb:1815:5947]) by mx.google.com with ESMTPSA id p10sm18733632pds.63.2014.12.01.18.19.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Dec 2014 18:19:37 -0800 (PST) From: Takayuki Usui To: dev@dpdk.org Date: Tue, 2 Dec 2014 11:19:23 +0900 Message-Id: <1417486763-12883-1-git-send-email-takayuki@midokura.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <5476E97D.5040304@6wind.com> References: <5476E97D.5040304@6wind.com> Subject: [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 List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Dec 2014 02:19:39 -0000 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/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)) + return PTR_ERR(net); + dev_net_set(net_dev, net); + put_net(net); + kni = netdev_priv(net_dev); kni->net_dev = net_dev; -- 2.1.3