From patchwork Thu Nov 2 19:05:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833515 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 3ySZwH2ThMz9sMN for ; Fri, 3 Nov 2017 06:31:59 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D5F35E7C; Thu, 2 Nov 2017 19:05:58 +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 68D32E6C for ; Thu, 2 Nov 2017 19:05:55 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 0FB1F4FA for ; Thu, 2 Nov 2017 19:05:54 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id 1so671547qtn.3 for ; Thu, 02 Nov 2017 12:05:54 -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=SWQbWfBZvWJ95KA7f4H2WlUWoPiJwzpdEH5ewTIL6EE=; b=Ss5KA7K+nUp+OZzDbLWumGqyaOYBwqTEVKc7gvx0Pr1MXp76XYHRwgA3FNLITrCaUd +TzqMkIO6g688jNp+KBsOVZqG5lvyjVNgsOqvohsSkyc6gY+Sgib0q0sjVtCgy0Il+uj AmtwUFvBQeOjWFAt3ZG1Hq/B8WT3v0GlQvteo3gr+/b2lDSzcjoSTw9yOSaOquzo/Kdd EGEJj2VzY8M+WXPjut9RnqGsxUerz7IkejihxSdn3ra10RpTr0C9H1EqNCRapdNQCY3+ FVVpmQiimCeuowgd5G8yYHAEBTVNT8zcXlMMY5wKe+bhIFWt7cY0Zv0lrfaavJftGMQ9 SvOg== X-Gm-Message-State: AMCzsaURgOtLBvFqjPcoT9X1XsuPkfS8Lhc5W+7vWM2+D5Lv0caqY0Cn nVsXfoPRl2CdCwuqPScAJP1jdFwLbXA= X-Google-Smtp-Source: ABhQp+RTldw776kgKtgKpyKah8eB+86gZNq9tDuVbGX19jodUVz/Jw1veBvGXe4xmXiUe9xId+bifA== X-Received: by 10.200.48.199 with SMTP id w7mr7010907qta.54.1509649554028; Thu, 02 Nov 2017 12:05:54 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id y192sm2641167qky.62.2017.11.02.12.05.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:53 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:05 -0200 Message-Id: <20171102190509.2688-5-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 4/8] netdev: update device info only if netns matches. 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 A network device in another network namespace could have the same name, so once the socket starts listening to other network namespaces, it is necessary to confirm the netns id. Signed-off-by: Flavio Leitner --- lib/netdev-linux.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 8ddaa8b39..7f9387c0e 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -573,7 +573,7 @@ netdev_rxq_linux_cast(const struct netdev_rxq *rx) } static int -netdev_linux_netns_update(struct netdev_linux *netdev) +netdev_linux_netns_update__(struct netdev_linux *netdev) { struct netns *dev_netns = &netdev->netns; struct dpif_netlink_vport reply; @@ -591,7 +591,31 @@ netdev_linux_netns_update(struct netdev_linux *netdev) return 0; } -static void netdev_linux_update(struct netdev_linux *netdev, +static int +netdev_linux_netns_update(struct netdev_linux *netdev) +{ + if (netns_is_invalid(&netdev->netns)) { + return netdev_linux_netns_update__(netdev); + } + + return 0; +} + +static bool +netdev_linux_netns_is_remote(struct netdev_linux *netdev) +{ + netdev_linux_netns_update(netdev); + return netns_is_remote(&netdev->netns); +} + +static bool +netdev_linux_netns_is_eq(struct netdev_linux *netdev, struct netns *ns) +{ + netdev_linux_netns_update(netdev); + return netns_eq(&netdev->netns, ns); +} + +static void netdev_linux_update(struct netdev_linux *netdev, struct netns *, const struct rtnetlink_change *) OVS_REQUIRES(netdev->mutex); static void netdev_linux_changed(struct netdev_linux *netdev, @@ -655,10 +679,11 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) do { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); uint64_t buf_stub[4096 / 8]; + struct netns ns; struct ofpbuf buf; ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); - error = nl_sock_recv(sock, &buf, NULL, false); + error = nl_sock_recv(sock, &buf, &ns, false); if (!error) { struct rtnetlink_change change; @@ -677,7 +702,7 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) struct netdev_linux *netdev = netdev_linux_cast(netdev_); ovs_mutex_lock(&netdev->mutex); - netdev_linux_update(netdev, &change); + netdev_linux_update(netdev, &ns, &change); ovs_mutex_unlock(&netdev->mutex); } netdev_close(netdev_); @@ -744,11 +769,11 @@ netdev_linux_changed(struct netdev_linux *dev, } static void -netdev_linux_update(struct netdev_linux *dev, - const struct rtnetlink_change *change) +netdev_linux_update__(struct netdev_linux *dev, + const struct rtnetlink_change *change) OVS_REQUIRES(dev->mutex) { - if (rtnetlink_type_is_rtnlgrp_link(change->nlmsg_type)){ + if (rtnetlink_type_is_rtnlgrp_link(change->nlmsg_type)) { if (change->nlmsg_type == RTM_NEWLINK) { /* Keep drv-info, and ip addresses. */ netdev_linux_changed(dev, change->ifi_flags, @@ -772,6 +797,7 @@ netdev_linux_update(struct netdev_linux *dev, dev->get_ifindex_error = 0; } else { netdev_linux_changed(dev, change->ifi_flags, 0); + netns_set_invalid(&dev->netns); } } else if (rtnetlink_type_is_rtnlgrp_addr(change->nlmsg_type)) { /* Invalidates in4, in6. */ @@ -781,6 +807,16 @@ netdev_linux_update(struct netdev_linux *dev, } } +static void +netdev_linux_update(struct netdev_linux *dev, struct netns *ns, + const struct rtnetlink_change *change) + OVS_REQUIRES(dev->mutex) +{ + if (netdev_linux_netns_is_eq(dev, ns)) { + netdev_linux_update__(dev, change); + } +} + static struct netdev * netdev_linux_alloc(void) {