From patchwork Thu Dec 27 21:41:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1019009 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; dmarc=none (p=none dis=none) header.from=ovn.org 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 43Qjwc6k3Vz9s55 for ; Fri, 28 Dec 2018 08:42:08 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 168B7E95; Thu, 27 Dec 2018 21:42:06 +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 3842CD26 for ; Thu, 27 Dec 2018 21:42:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id CB514189 for ; Thu, 27 Dec 2018 21:42:03 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 8B553FF802; Thu, 27 Dec 2018 21:41:59 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Thu, 27 Dec 2018 13:41:55 -0800 Message-Id: <20181227214155.24265-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Shweta Seth , Ben Pfaff Subject: [ovs-dev] [PATCH] ofproto-dpif-xlate: Account mirrored packets only if the VLAN 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 Until now, OVS has accounted packets to mirrors even if the VLAN selection criteria did not match. This fixes the problem. Reported-by: Shweta Seth Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2018-December/047931.html Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- ofproto/ofproto-dpif-xlate.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 839fddd99fbe..8d17151a057e 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -2058,21 +2058,9 @@ mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle, return; } - if (ctx->xin->resubmit_stats) { - mirror_update_stats(xbridge->mbridge, mirrors, - ctx->xin->resubmit_stats->n_packets, - ctx->xin->resubmit_stats->n_bytes); - } - if (ctx->xin->xcache) { - struct xc_entry *entry; - - entry = xlate_cache_add_entry(ctx->xin->xcache, XC_MIRROR); - entry->mirror.mbridge = mbridge_ref(xbridge->mbridge); - entry->mirror.mirrors = mirrors; - } - /* 'mirrors' is a bit-mask of candidates for mirroring. Iterate as long as * some candidates remain. */ + mirror_mask_t used_mirrors = 0; while (mirrors) { const unsigned long *vlans; mirror_mask_t dup_mirrors; @@ -2096,6 +2084,9 @@ mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle, continue; } + /* We sent a packet to this mirror. */ + used_mirrors |= rightmost_1bit(mirrors); + /* Record the mirror, and the mirrors that output to the same * destination, so that we don't mirror to them again. This must be * done now to ensure that output_normal(), below, doesn't recursively @@ -2129,6 +2120,21 @@ mirror_packet(struct xlate_ctx *ctx, struct xbundle *xbundle, mirrors &= ~ctx->mirrors; ctx->mirror_snaplen = 0; } + + if (used_mirrors) { + if (ctx->xin->resubmit_stats) { + mirror_update_stats(xbridge->mbridge, used_mirrors, + ctx->xin->resubmit_stats->n_packets, + ctx->xin->resubmit_stats->n_bytes); + } + if (ctx->xin->xcache) { + struct xc_entry *entry; + + entry = xlate_cache_add_entry(ctx->xin->xcache, XC_MIRROR); + entry->mirror.mbridge = mbridge_ref(xbridge->mbridge); + entry->mirror.mirrors = used_mirrors; + } + } } static void