From patchwork Wed Sep 8 12:16:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1525830 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=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H4LjM4v8Pz9tjx for ; Wed, 8 Sep 2021 22:16:53 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5A46C40722; Wed, 8 Sep 2021 12:16:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Cb8cYLfmYw7w; Wed, 8 Sep 2021 12:16:49 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id B7EE640718; Wed, 8 Sep 2021 12:16:48 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 87359C000F; Wed, 8 Sep 2021 12:16:48 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0C410C000D for ; Wed, 8 Sep 2021 12:16:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E906740204 for ; Wed, 8 Sep 2021 12:16:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q7fm8yvl7oUe for ; Wed, 8 Sep 2021 12:16:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp2.osuosl.org (Postfix) with ESMTPS id C213140184 for ; Wed, 8 Sep 2021 12:16:45 +0000 (UTC) Received: (Authenticated sender: i.maximets@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 182E320016; Wed, 8 Sep 2021 12:16:41 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Wed, 8 Sep 2021 14:16:40 +0200 Message-Id: <20210908121640.3921795-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Cc: Dumitru Ceara , Ilya Maximets Subject: [ovs-dev] [PATCH ovn] ovn-northd: Fix update of a mac prefix. 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" 'smap_add' doesn't check for duplicates. This leads to having more than one entry with a 'mac_prefix' key in the 'options' smap. 'ovsdb_datum_sort_unique' removes duplicates before sending the transaction. It does that by sorting values and keeping the first one per key. In normal case 'mac_prefix' transitions from nothing to random and it works fine. However, northd also tries to change all-zero prefix to random one and this fails, because all-zero prefix goes first in a sorted map and a new random value gets dropped from the transaction. This makes northd to update macs of all ports on every iteration with a new random mac prefix. Fix that by replacing smap value and not relying on IDL for removing duplicates. Fixes: 39242c106eff ("northd: refactor and split some IPAM functions") Signed-off-by: Ilya Maximets Acked-by: Mark D. Gray --- northd/ovn-northd.c | 2 +- tests/ovn.at | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c index ee761cef0..eef752542 100644 --- a/northd/ovn-northd.c +++ b/northd/ovn-northd.c @@ -14212,7 +14212,7 @@ ovnnb_db_run(struct northd_context *ctx, struct smap options; smap_clone(&options, &nb->options); - smap_add(&options, "mac_prefix", mac_addr_prefix); + smap_replace(&options, "mac_prefix", mac_addr_prefix); if (!monitor_mac) { eth_addr_random(&svc_monitor_mac_ea); diff --git a/tests/ovn.at b/tests/ovn.at index 5104a6895..30625ec37 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -8030,6 +8030,19 @@ mac_prefix=$(ovn-nbctl --wait=sb get NB_Global . options:mac_prefix | tr -d \") port_addr=$(ovn-nbctl get Logical-Switch-Port p91 dynamic_addresses | tr -d \") AT_CHECK([test "$port_addr" = "${mac_prefix}:00:00:09"], [0], []) +# set mac_prefix to all-zeroes and check it is allocated in a random manner +ovn-nbctl --wait=hv set NB_Global . options:mac_prefix="00:00:00:00:00:00" +ovn-nbctl ls-add sw14 +ovn-nbctl --wait=sb set Logical-Switch sw14 other_config:mac_only=true +ovn-nbctl --wait=sb lsp-add sw14 p141 -- lsp-set-addresses p141 dynamic + +mac_prefix=$(ovn-nbctl --wait=sb get NB_Global . options:mac_prefix | tr -d \") +port_addr=$(ovn-nbctl get Logical-Switch-Port p141 dynamic_addresses | tr -d \") +AT_CHECK([test "$mac_prefix" != "00:00:00:00:00:00"], [0], []) +AT_CHECK([test "$port_addr" = "${mac_prefix}:00:00:0a"], [0], []) +ovn-nbctl --wait=sb lsp-del sw14 p141 +ovn-nbctl --wait=sb ls-del sw14 + ovn-nbctl --wait=hv set NB_Global . options:mac_prefix="00:11:22" ovn-nbctl ls-add sw10 ovn-nbctl --wait=sb set Logical-Switch sw10 other_config:ipv6_prefix="ae01::"