From patchwork Mon Oct 26 18:16:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1387965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.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 fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CKjhl41Z1z9sSW for ; Tue, 27 Oct 2020 05:16:39 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 25F10855DF; Mon, 26 Oct 2020 18:16:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aeXWcFjmyQmj; Mon, 26 Oct 2020 18:16:37 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 8E8E1852E9; Mon, 26 Oct 2020 18:16:37 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 70B5AC0859; Mon, 26 Oct 2020 18:16:37 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 14FFCC0051 for ; Mon, 26 Oct 2020 18:16:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id F17D78700C for ; Mon, 26 Oct 2020 18:16:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WJWmgWnbICuO for ; Mon, 26 Oct 2020 18:16:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by hemlock.osuosl.org (Postfix) with ESMTPS id 046A58700B for ; Mon, 26 Oct 2020 18:16:35 +0000 (UTC) Received: from sigfpe.attlocal.net (75-54-222-30.lightspeed.rdcyca.sbcglobal.net [75.54.222.30]) (Authenticated sender: blp@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id AE15D100008; Mon, 26 Oct 2020 18:16:31 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Mon, 26 Oct 2020 11:16:20 -0700 Message-Id: <20201026181626.1827014-1-blp@ovn.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH ovn 1/7] northd: Count mask length and priority correctly for IPv6 addresses. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Before this commit, the IPv4 calculation was used even for IPv6 addresses, which was wrong. Signed-off-by: Ben Pfaff Acked-by: Numan Siddique --- northd/ovn-northd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index 59b7b3d2ee3a..d677f357f5d0 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -9303,10 +9303,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, /* Check the validity of nat->logical_ip. 'logical_ip' can * be a subnet when the type is "snat". */ + int cidr_bits; if (is_v6) { error = ipv6_parse_masked(nat->logical_ip, &ipv6, &mask_v6); + cidr_bits = ipv6_count_cidr_bits(&mask_v6); } else { error = ip_parse_masked(nat->logical_ip, &ip, &mask); + cidr_bits = ip_count_cidr_bits(mask); } if (!strcmp(nat->type, "snat")) { if (error) { @@ -9612,11 +9615,11 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports, * nat->logical_ip with the longest mask gets a higher * priority. */ ovn_lflow_add_with_hint(lflows, od, S_ROUTER_OUT_SNAT, - count_1bits(ntohl(mask)) + 1, + cidr_bits + 1, ds_cstr(&match), ds_cstr(&actions), &nat->header_); } else { - uint16_t priority = count_1bits(ntohl(mask)) + 1; + uint16_t priority = cidr_bits + 1; /* Distributed router. */ ds_clear(&match);