From patchwork Tue Jan 16 05:17:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 861273 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=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sysclose.org header.i=fbl@sysclose.org header.b="bUM7t+Se"; dkim-atps=neutral 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 3zLJQS52f2z9s7g for ; Tue, 16 Jan 2018 16:18:08 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 463AAFF9; Tue, 16 Jan 2018 05:18:05 +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 1D325F13 for ; Tue, 16 Jan 2018 05:18:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sender-of-o51.zoho.com (sender-of-o51.zoho.com [135.84.80.216]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7CD70E6 for ; Tue, 16 Jan 2018 05:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1516079880; s=zoho; d=sysclose.org; i=fbl@sysclose.org; h=From:To:Subject:Date:Message-Id; l=3269; bh=s3rWut0CZ7f7yf81FWSpJ06InjO1A+TuWJTZsFzcdKM=; b=bUM7t+Sems3YNJMaM+VcRIUoNZMx8o6jkePCl3XHeWNXaKYrz+VkO5NkhMYQ25wS HxL6edTEEIndQqGBxLfuyVYKTWoPXnNxYvH4xF0Z1McAN1rr9simhpHQJxBJIQTRac5 K//iQZtt2/10XKxVYWTuo3cpbK3yd6134Y8uiO6Y= Received: from localhost (189.114.247.210 [189.114.247.210]) by mx.zohomail.com with SMTPS id 1516079880753914.7783137919138; Mon, 15 Jan 2018 21:18:00 -0800 (PST) From: Flavio Leitner To: dev@openvswitch.org Date: Tue, 16 Jan 2018 03:17:53 -0200 Message-Id: <20180116051753.9639-1-fbl@sysclose.org> X-Mailer: git-send-email 2.14.3 X-ZohoMailClient: External X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v3] netdev-linux: do not send packets to down tap ifaces. 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 Today OVS pushes packets to the TAP interface ignoring its current state. That works because the kernel will return -EIO when it's not UP and OVS will just ignore that as it is not an OVS issue. However, it causes a huge impact when broadcasts happen when using userspace datapath accelerated with DPDK (e.g.: action NORMAL). This patch improves the situation by checking the TAP's interface state before issueing any syscall. However, there might be use-cases moving interfaces to other networking namespaces and in that case, OVS can't retrieve the iface state (sets it to DOWN). That would stop the traffic breaking the use-case. This patch relies on netlink notifications to find out if the device is local or not. When it's local, the device state is checked otherwise it will behave as before. Signed-off-by: Flavio Leitner Tested-by: Vishal Deep Ajmera --- NEWS | 2 ++ lib/netdev-linux.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) ChangeLog: v3 - mentioned in the NEWS file. v2 - drops are accounted. diff --git a/NEWS b/NEWS index cb020d00d..545c64e63 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,8 @@ Post-v2.8.0 connection tracking entry. * New "ct-set-maxconns", "ct-get-maxconns", and "ct-get-nconns" commands for userspace datapath. + - No longer send packets to the Linux TAP device if it's DOWN unless it is + in another networking namespace. - DPDK: * Add support for DPDK v17.11 * Add support for vHost IOMMU diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 37143b8df..6dae7964a 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -502,6 +502,8 @@ struct netdev_linux { /* For devices of class netdev_tap_class only. */ int tap_fd; + bool present; /* If the device is present in the namespace */ + uint64_t tx_dropped; /* tap device can drop if the iface is down */ }; struct netdev_rxq_linux { @@ -750,8 +752,10 @@ netdev_linux_update(struct netdev_linux *dev, dev->ifindex = change->if_index; dev->cache_valid |= VALID_IFINDEX; dev->get_ifindex_error = 0; + dev->present = true; } else { netdev_linux_changed(dev, change->ifi_flags, 0); + dev->present = false; } } else if (rtnetlink_type_is_rtnlgrp_addr(change->nlmsg_type)) { /* Invalidates in4, in6. */ @@ -1234,6 +1238,17 @@ netdev_linux_tap_batch_send(struct netdev *netdev_, { struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct dp_packet *packet; + + /* The Linux tap driver returns EIO if the device is not up, + * so if the device is not up, don't waste time sending it. + * However, if the device is in another network namespace + * then OVS can't retrieve the state. In that case, send the + * packets anyway. */ + if (netdev->present && !(netdev->ifi_flags & IFF_UP)) { + netdev->tx_dropped += dp_packet_batch_size(batch); + return 0; + } + DP_PACKET_BATCH_FOR_EACH (packet, batch) { size_t size = dp_packet_size(packet); ssize_t retval; @@ -1825,6 +1840,7 @@ netdev_tap_get_stats(const struct netdev *netdev_, struct netdev_stats *stats) stats->multicast += dev_stats.multicast; stats->collisions += dev_stats.collisions; } + stats->tx_dropped += netdev->tx_dropped; ovs_mutex_unlock(&netdev->mutex); return error;