From patchwork Mon Aug 17 01:27:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang_y_yi X-Patchwork-Id: 1345550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=pnfHuqE2; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BVGdg3S9mz9sTM for ; Mon, 17 Aug 2020 11:28:23 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 696F786888; Mon, 17 Aug 2020 01:28:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xcOYgU0_hMio; Mon, 17 Aug 2020 01:28:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id B3CCD864D6; Mon, 17 Aug 2020 01:28:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 78BB4C0890; Mon, 17 Aug 2020 01:28:13 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6590FC088B for ; Mon, 17 Aug 2020 01:28:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 48C4D204E0 for ; Mon, 17 Aug 2020 01:28:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2D4hoFEMQCjM for ; Mon, 17 Aug 2020 01:28:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-m973.mail.163.com (mail-m973.mail.163.com [123.126.97.3]) by silver.osuosl.org (Postfix) with ESMTPS id 692BD20000 for ; Mon, 17 Aug 2020 01:28:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=KAjQc P145PWzoRDNXdLcmujKsc5S9UmXisFYyUIgA6I=; b=pnfHuqE2DSQre5xZEmVFA Tiz2jOKpbPK7C/r/W3q81rIJ/Hm23oHgvH7Yi/p9Jg+ujuSKlm5Mk5MTkDvv5b66 DOfPcpYOBeFpHsGnnU2H9480yAUECW9ZXnyjd8g2Ukqunmnv5Vua1JHxhTJRnXJO XzQlGhuNfGMv664OPYxWf8= Received: from yangyi0100.home.langchao.com (unknown [111.207.123.58]) by smtp3 (Coremail) with SMTP id G9xpCgB326QR3Tlf2LT2AA--.27S4; Mon, 17 Aug 2020 09:27:48 +0800 (CST) From: yang_y_yi@163.com To: ovs-dev@openvswitch.org Date: Mon, 17 Aug 2020 09:27:43 +0800 Message-Id: <20200817012745.160200-3-yang_y_yi@163.com> X-Mailer: git-send-email 2.19.2.windows.1 In-Reply-To: <20200817012745.160200-1-yang_y_yi@163.com> References: <20200817012745.160200-1-yang_y_yi@163.com> MIME-Version: 1.0 X-CM-TRANSID: G9xpCgB326QR3Tlf2LT2AA--.27S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFW3Cw43uFWfGr4DGw1fCrg_yoW5AFWxpa yUJF15Jr1rJFW3Jrn3J3s8Wr15Wr1kGr47C34fAa43Xryqv348W3Wvgry7Cr9xC3y5AFn5 Aw4j9FW0k34xZaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UpyIUUUUUU= X-Originating-IP: [111.207.123.58] X-CM-SenderInfo: 51dqwsp1b1xqqrwthudrp/xtbB0hSDi1UMYVVWhwAAsy Cc: i.maximets@ovn.org, yang_y_yi@163.com, fbl@sysclose.org Subject: [ovs-dev] [PATCH V1 2/4] Add netns option for tap interface in userspace datapath X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Yi Yang In userspace datapath, "ovs-vsctl list interface" can't get interface statistics and there are many WARN log, we can enable it work normally if it has correct network namespace. This patch enabled netns option for tap interface , it is the prerequisite interface statistics and other ioctl can work normally. Signed-off-by: Yi Yang --- lib/netdev-linux-private.h | 1 + lib/netdev-linux.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/netdev-linux-private.h b/lib/netdev-linux-private.h index c7c515f..fbedfd9 100644 --- a/lib/netdev-linux-private.h +++ b/lib/netdev-linux-private.h @@ -68,6 +68,7 @@ struct netdev_linux { struct timer miimon_timer; int netnsid; /* Network namespace ID. */ + char *netns; /* Network namespace name. */ /* The following are figured out "on demand" only. They are only valid * when the corresponding VALID_* bit in 'cache_valid' is set. */ int ifindex; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 8d64003..bb3aa9b 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -1054,6 +1054,9 @@ netdev_linux_destruct(struct netdev *netdev_) { ioctl(netdev->tap_fd, TUNSETPERSIST, 0); close(netdev->tap_fd); + if (netdev->netns != NULL) { + free(netdev->netns); + } } if (netdev->miimon_interval > 0) { @@ -3509,6 +3512,48 @@ exit: return error; } +static int +netdev_tap_set_config(struct netdev *netdev, const struct smap *args, + char **errp OVS_UNUSED) +{ + struct netdev_linux *dev = netdev_linux_cast(netdev); + const char *netns; + + ovs_mutex_lock(&dev->mutex); + netns = smap_get(args, "netns"); + if (netns != NULL) { + char nspath[128]; + int nsfd; + + sprintf(nspath, "/var/run/netns/%s", netns); + nsfd = open(nspath, O_RDONLY); + if (nsfd < 0) { + ovs_mutex_unlock(&dev->mutex); + VLOG_ERR("%s: netns %s doesn't exist.", + netdev_get_name(netdev), netns); + return EINVAL; + } + close(nsfd); + } + + if (netns != NULL) { + dev->netns = xstrdup(netns); + } + ovs_mutex_unlock(&dev->mutex); + return 0; +} + +static int +netdev_tap_get_config(const struct netdev *netdev, struct smap *args) +{ + struct netdev_linux *dev = netdev_linux_cast(netdev); + + ovs_mutex_lock(&dev->mutex); + smap_add_format(args, "netns", "%s", dev->netns); + ovs_mutex_unlock(&dev->mutex); + return 0; +} + #define NETDEV_LINUX_CLASS_COMMON \ .run = netdev_linux_run, \ .wait = netdev_linux_wait, \ @@ -3573,6 +3618,8 @@ const struct netdev_class netdev_tap_class = { .get_stats = netdev_tap_get_stats, .get_features = netdev_linux_get_features, .get_status = netdev_linux_get_status, + .set_config = netdev_tap_set_config, + .get_config = netdev_tap_get_config, .send = netdev_linux_send, .rxq_construct = netdev_linux_rxq_construct, .rxq_destruct = netdev_linux_rxq_destruct,