From patchwork Thu Nov 9 17:31:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 836449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yXqzH1R1sz9t8Z for ; Fri, 10 Nov 2017 04:33:50 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D2E9EBC2; Thu, 9 Nov 2017 17:31:45 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 5F97DB0B for ; Thu, 9 Nov 2017 17:31:45 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 0AB758A for ; Thu, 9 Nov 2017 17:31:44 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id q33so4171408qta.2 for ; Thu, 09 Nov 2017 09:31:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5LeFrR9/3shDLvv44C6djmggr2l1sMAE/6u8E9VFHsI=; b=i3Qa189iVbgDj6vGri91tDiJ4GXqqIa9T4SkHmjBzhpGBbAGLeQ5XH4kPg7679CEmR yYGj00twufC39LDRyiMeMy3fn7cg3o2iuYaCLPxEo3/s2KMKUS0vN4VKNfpbg1GLFR9L +oroWNmKUHmioNbIGQYC7SLlHiduhVUby6scVyVStDPMEfEEm3fM4Yi0nxlp9rPY2CUj EjpCKlElGiwJhXGGsMpRuPJaEeYaYjzq+w2UvE0vg+dmHGxcPSZTZE0Gcal7ai+mgZMC D9W8cfpBIi1sI7d4Lbf+K9YMQILtPUdHnAJ2RU5OtXVP5ySX0yOamvTMM/i1dFd8xwi2 O4mg== X-Gm-Message-State: AJaThX7pIUtC5vZk5KFxj9JRGbor4PFZMZ/O3bP7NmTNQyLbic+kKKNT U6uuu8SHzeVESAw1a9RvUfuzJmcyj/Q= X-Google-Smtp-Source: AGs4zMaKRJ8vCbbBTf0hS1k8CKZFtK5j6TBSw7lxJJ2OHKv3vNsFFiwvMq78LZqyBcX4+QA+fF8D4A== X-Received: by 10.200.39.20 with SMTP id g20mr1916548qtg.125.1510248704056; Thu, 09 Nov 2017 09:31:44 -0800 (PST) Received: from localhost ([2804:7f4:5087:e653:e8e6:b1:eeb0:fb4]) by smtp.gmail.com with ESMTPSA id g47sm5017627qtc.1.2017.11.09.09.31.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2017 09:31:43 -0800 (PST) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 9 Nov 2017 15:31:02 -0200 Message-Id: <20171109173107.26256-4-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171109173107.26256-1-fbl@redhat.com> References: <20171109173107.26256-1-fbl@redhat.com> X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH v2 3/8] vport: retrieve the netnsid if available. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Recent kernels provide the network namespace ID of a port, so use that to discover where the port currently is. Signed-off-by: Flavio Leitner --- datapath/linux/compat/include/linux/openvswitch.h | 2 ++ lib/dpif-netlink.c | 6 ++++++ lib/dpif-netlink.h | 2 ++ lib/netdev-linux.c | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h index bc6c94b8d..d2712d05f 100644 --- a/datapath/linux/compat/include/linux/openvswitch.h +++ b/datapath/linux/compat/include/linux/openvswitch.h @@ -283,6 +283,8 @@ enum ovs_vport_attr { /* receiving upcalls */ OVS_VPORT_ATTR_STATS, /* struct ovs_vport_stats */ OVS_VPORT_ATTR_PAD, + OVS_VPORT_ATTR_IFINDEX, + OVS_VPORT_ATTR_NETNSID, __OVS_VPORT_ATTR_MAX }; diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index fd333094d..b85e74c50 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -3065,6 +3065,7 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, [OVS_VPORT_ATTR_STATS] = { NL_POLICY_FOR(struct ovs_vport_stats), .optional = true }, [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = true }, + [OVS_VPORT_ATTR_NETNSID] = { .type = NL_A_U32, .optional = true }, }; dpif_netlink_vport_init(vport); @@ -3100,6 +3101,11 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, vport->options = nl_attr_get(a[OVS_VPORT_ATTR_OPTIONS]); vport->options_len = nl_attr_get_size(a[OVS_VPORT_ATTR_OPTIONS]); } + if (a[OVS_VPORT_ATTR_NETNSID]) { + netns_set_id(&vport->netns, nl_attr_get_u32(a[OVS_VPORT_ATTR_NETNSID])); + } else { + netns_set_local(&vport->netns); + } return 0; } diff --git a/lib/dpif-netlink.h b/lib/dpif-netlink.h index 568b81441..680a74c2f 100644 --- a/lib/dpif-netlink.h +++ b/lib/dpif-netlink.h @@ -21,6 +21,7 @@ #include #include #include "odp-netlink.h" +#include "netns.h" #include "flow.h" @@ -32,6 +33,7 @@ struct dpif_netlink_vport { /* ovs_vport header. */ int dp_ifindex; + struct netns netns; odp_port_t port_no; /* ODPP_NONE if unknown. */ enum ovs_vport_type type; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index c31334ce1..fd181272b 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -476,6 +476,7 @@ struct netdev_linux { long long int miimon_interval; /* Miimon Poll rate. Disabled if <= 0. */ struct timer miimon_timer; + struct netns netns; /* network namespace. */ /* The following are figured out "on demand" only. They are only valid * when the corresponding VALID_* bit in 'cache_valid' is set. */ int ifindex; @@ -571,6 +572,25 @@ netdev_rxq_linux_cast(const struct netdev_rxq *rx) return CONTAINER_OF(rx, struct netdev_rxq_linux, up); } +static int +netdev_linux_netns_update(struct netdev_linux *netdev) +{ + struct netns *dev_netns = &netdev->netns; + struct dpif_netlink_vport reply; + struct ofpbuf *buf; + int error; + + error = dpif_netlink_vport_get(netdev_get_name(&netdev->up), &reply, &buf); + if (error) { + netns_set_invalid(dev_netns); + return error; + } + + netns_copy(dev_netns, &reply.netns); + ofpbuf_delete(buf); + return 0; +} + static void netdev_linux_update(struct netdev_linux *netdev, const struct rtnetlink_change *) OVS_REQUIRES(netdev->mutex);