From patchwork Thu Nov 9 17:31:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 836450 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 3yXqzL5yyRz9t8c for ; Fri, 10 Nov 2017 04:34:22 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C4AD5BD8; Thu, 9 Nov 2017 17:31:50 +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 E54BFBC1 for ; Thu, 9 Nov 2017 17:31:49 +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 816A31CE for ; Thu, 9 Nov 2017 17:31:49 +0000 (UTC) Received: by mail-qk0-f195.google.com with SMTP id v137so8681683qkb.1 for ; Thu, 09 Nov 2017 09:31:49 -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=DJbdvp6g0RUcU+0umgq/G3KBdCVGVstnL5YbrQ7m+nE=; b=Bg5uDkjhSAhByKzlnuOY7xQJcVCo8pEdmYwcMdEutVDJqoBbmOuLNCulzoN3TineE7 WOtvVKTLH8Dn/QoUEX4f9kGIaxjFva88soPi+vw9LEqxCQaCJaskGbphZZWQgAe1myez MGi7nkXYQ3c+wJ9Xx5xrxUL7xsiM7fGellgEnAQRoY4HlIXtqcOWtLY/i/K0H9mIpdSq 2qRU2SlepyPmNDTEQCcH7Y726dLDg6F9Na8oq2rZzJrSk74U29wo5+aPx4LSXCeV4rzY zsBtlGFQCFaJg3XTEBLd5urG65T/1T7EwA/amU7YQmDvMshQx6mlaWASjnw4+8TT3sQb G7BQ== X-Gm-Message-State: AJaThX4PbsEo7punJF0SCvLrCfivaRcuIJ6I31pDfgaKwKJ3a/La0cQj v0R7BEJV8BpDEZIihb9/QWG8JcH+G1g= X-Google-Smtp-Source: AGs4zMYsK8V9D2LOpgWZqa53nDnsZr5VLD3RVOrG3Bt8qTfIIGsdGHhyUPMfltGYzQrBGZAWslJp2g== X-Received: by 10.55.99.214 with SMTP id x205mr2062267qkb.34.1510248708430; Thu, 09 Nov 2017 09:31:48 -0800 (PST) Received: from localhost ([2804:7f4:5087:e653:e8e6:b1:eeb0:fb4]) by smtp.gmail.com with ESMTPSA id y10sm4813633qkl.14.2017.11.09.09.31.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Nov 2017 09:31:47 -0800 (PST) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 9 Nov 2017 15:31:03 -0200 Message-Id: <20171109173107.26256-5-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.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 v2 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 fd181272b..7a6937cc8 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) {