From patchwork Thu Nov 2 19:05:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833514 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 3ySZv86Pwcz9sMN for ; Fri, 3 Nov 2017 06:31:00 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7A2D3E71; Thu, 2 Nov 2017 19:05:57 +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 58630E64 for ; Thu, 2 Nov 2017 19:05:53 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id ECCEF463 for ; Thu, 2 Nov 2017 19:05:52 +0000 (UTC) Received: by mail-qk0-f195.google.com with SMTP id r64so653163qkc.1 for ; Thu, 02 Nov 2017 12:05:52 -0700 (PDT) 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=my0lq0LvlmyBZA7SuT2TFRLiauN5BagkWEuJtgaax0I=; b=dY8yY8bvte19T8OyUFzgSAKAOLr6eLuk8KYodMM1Sp7h87bnZ/D/UDnijHiyX5xWr2 ODG81rgH9MYTPPVZQw6C1JFNUuwt7EbvHVIT3S9Ll/e0CLI5J3Pnw16eJUXqJpZvDLT8 SPisJAZE/rfZPdCBIqkxnDtMOVCj3Udd/lHOqBvSz6s9K1iPhe+HQ6WtB8sIsLrSIWrP vWJ6AffOirmp07544D/3mba79diMZFE3rvQrSOdOU7CKLHPDTGVaxaMoBxC8kAv1wTm+ YPT6wMFnU1V9Le/Teig8eV1PdTtbo+y9S9N+Y7mBJ+VElKsrrRzDkacXyIiFk7Hja1HF UZCg== X-Gm-Message-State: AJaThX4h4d1YyMUqMNE4NCK4JzmQLyhMDG6pbDCojlTdKEuSRuFjWZxW 0BSPLoOYA7GvaTICcBMYM0o9cIU7XU8= X-Google-Smtp-Source: ABhQp+QJM+hnBDha9ODTBfdF7vkZ/DERDs9bMDRGmzhDMr4tDQCu5vuu4dVXlv09D0BNjYJR1/MNSg== X-Received: by 10.55.18.165 with SMTP id 37mr6222520qks.352.1509649551189; Thu, 02 Nov 2017 12:05:51 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id n4sm2615823qkh.8.2017.11.02.12.05.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:50 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:04 -0200 Message-Id: <20171102190509.2688-4-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM 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 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 563eb5638..81c4631f0 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 3c80690f4..8ddaa8b39 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);