From patchwork Fri Oct 26 16:20:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 989658 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=fail (p=none dis=none) header.from=redhat.com 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 42hTl41RNQz9sMl for ; Sat, 27 Oct 2018 03:21:19 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A3582277D; Fri, 26 Oct 2018 16:21:15 +0000 (UTC) X-Original-To: ovs-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 9B79526CF for ; Fri, 26 Oct 2018 16:21:01 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id A55157F8 for ; Fri, 26 Oct 2018 16:21:00 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id g9-v6so1959103wrq.4 for ; Fri, 26 Oct 2018 09:21:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nBc5HZTrWPXeRK9Zz8hxcGNPnYTeVwspGVZgmN/W93E=; b=pH9jBugTDgcf2f3G1umuJBeChZRx7fuojqSSsdjpMlpX4RbWYIM32AseCslYOBYtpi EM3K50h6PHTfi9ZW9HEYcf3rnE0k3H9yvgr8THOqYmh6XyhumbegZzNx4epO97bu/evI YOT9x5YzX+/72V9L2c+9UZCzBKOVOoFvDkLtk53xCMT5q/EqNyfYrOyq+U6YWgdDAbSx 4jhWm0y94MptUkNyCmN+JbxEHlQENc6mYHo+d0RJ8CeiL2Udb1WE5dpXlYGnykJXrZRO duS8DNK3shzzRzexJfj7i+YiARD0NZ06lymGAGP9A1MqJERnO57FJ4941o2kBHx/E4EJ 7RVw== X-Gm-Message-State: AGRZ1gLN9Yj/O4UZIpAaXjBqBvdNOX6TpXL3octNvw9dbHfxOPT5Gdlx 4TDJyMH5IuLdjniirrLJBJ4qptbRpgE= X-Google-Smtp-Source: AJdET5fXU3vvXWXd2VB3hglZc20LwoJr69w1jiqsvUquXELD+8KpzyHBnHbzDVqSJyacfmmuVR2D8A== X-Received: by 2002:adf:9f0f:: with SMTP id l15-v6mr6369178wrf.206.1540570858636; Fri, 26 Oct 2018 09:20:58 -0700 (PDT) Received: from localhost.localdomain.com ([151.66.52.234]) by smtp.gmail.com with ESMTPSA id m16sm9244939wrx.75.2018.10.26.09.20.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Oct 2018 09:20:57 -0700 (PDT) From: Lorenzo Bianconi To: ovs-dev@openvswitch.org Date: Fri, 26 Oct 2018 18:20:44 +0200 Message-Id: <635353f3a63d4e1fc776ed9dea1f1403caab426d.1540570685.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: References: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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 v2] OVN: introduce mac_prefix support to IPAM 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 Add the possibility to specify a given mac address prefix for dynamically generated mac address. Mac address prefix can be specified in nbdb NB_Global table, options:mac_prefix= This patch fix a possible issue of L2 address duplication if multiple OVN deployments share a single broadcast domain Acked-by: Mark Michelson Signed-off-by: Lorenzo Bianconi Acked-by: Mark Michelson --- Changes since v1: - use a global definition for mac_prefix --- ovn/northd/ovn-northd.c | 37 ++++++++++++++++++++++++++++++++++--- ovn/ovn-nb.xml | 5 +++++ tests/ovn.at | 17 +++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index 439651f80..816c72311 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -68,6 +68,7 @@ static const char *unixctl_path; /* MAC address management (macam) table of "struct eth_addr"s, that holds the * MAC addresses allocated by the OVN ipam module. */ static struct hmap macam = HMAP_INITIALIZER(&macam); +static struct eth_addr mac_prefix; #define MAX_OVN_TAGS 4096 @@ -922,10 +923,17 @@ ipam_insert_mac(struct eth_addr *ea, bool check) } uint64_t mac64 = eth_addr_to_uint64(*ea); + uint64_t prefix; + + if (!eth_addr_is_zero(mac_prefix)) { + prefix = eth_addr_to_uint64(mac_prefix); + } else { + prefix = MAC_ADDR_PREFIX; + } /* If the new MAC was not assigned by this address management system or * check is true and the new MAC is a duplicate, do not insert it into the * macam hmap. */ - if (((mac64 ^ MAC_ADDR_PREFIX) >> 24) + if (((mac64 ^ prefix) >> 24) || (check && ipam_is_duplicate_mac(ea, mac64, true))) { return; } @@ -1036,7 +1044,11 @@ ipam_get_unused_mac(void) for (i = 0; i < MAC_ADDR_SPACE - 1; i++) { /* The tentative MAC's suffix will be in the interval (1, 0xfffffe). */ mac_addr_suffix = ((last_mac + i) % (MAC_ADDR_SPACE - 1)) + 1; - mac64 = MAC_ADDR_PREFIX | mac_addr_suffix; + if (!eth_addr_is_zero(mac_prefix)) { + mac64 = eth_addr_to_uint64(mac_prefix) | mac_addr_suffix; + } else { + mac64 = MAC_ADDR_PREFIX | mac_addr_suffix; + } eth_addr_from_uint64(mac64, &mac); if (!ipam_is_duplicate_mac(&mac, mac64, false)) { last_mac = mac_addr_suffix; @@ -1107,7 +1119,15 @@ dynamic_mac_changed(const char *lsp_addresses, } uint64_t mac64 = eth_addr_to_uint64(update->current_addresses.ea); - if ((mac64 ^ MAC_ADDR_PREFIX) >> 24) { + uint64_t prefix; + + if (!eth_addr_is_zero(mac_prefix)) { + prefix = eth_addr_to_uint64(mac_prefix); + } else { + prefix = MAC_ADDR_PREFIX; + } + + if ((mac64 ^ prefix) >> 24) { return DYNAMIC; } else { return NONE; @@ -7141,6 +7161,17 @@ ovnnb_db_run(struct northd_context *ctx, sbrec_sb_global_set_options(sb, &nb->options); sb_loop->next_cfg = nb->nb_cfg; + const char *mac_addr_prefix = smap_get(&nb->options, "mac_prefix"); + if (mac_addr_prefix) { + struct eth_addr addr; + + memset(&addr, 0, sizeof addr); + if (ovs_scan(mac_addr_prefix, "%"SCNx8":%"SCNx8":%"SCNx8, + &addr.ea[0], &addr.ea[1], &addr.ea[2])) { + mac_prefix = addr; + } + } + cleanup_macam(&macam); } diff --git a/ovn/ovn-nb.xml b/ovn/ovn-nb.xml index c0739fe57..f309b3b86 100644 --- a/ovn/ovn-nb.xml +++ b/ovn/ovn-nb.xml @@ -102,6 +102,11 @@ tunnel interfaces. + + + Configure a given OUI to be used as prefix when L2 address is + dynamically assigned, e.g. 00:11:22 + diff --git a/tests/ovn.at b/tests/ovn.at index 8825beca3..e512f94aa 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -5616,6 +5616,23 @@ AT_CHECK([ovn-nbctl get Logical-Switch-Port p41 dynamic_addresses], [0], ["f0:00:00:00:10:2b 192.168.1.3" ]) +# define a mac address prefix +ovn-nbctl ls-add sw6 +ovn-nbctl --wait=hv set NB_Global . options:mac_prefix="00:11:22:33:44:55" +ovn-nbctl --wait=sb set Logical-Switch sw6 other_config:subnet=192.168.100.0/24 +for n in $(seq 1 3); do + ovn-nbctl --wait=sb lsp-add sw6 "p5$n" -- lsp-set-addresses "p5$n" dynamic +done +AT_CHECK([ovn-nbctl get Logical-Switch-Port p51 dynamic_addresses], [0], + ["00:11:22:00:00:4d 192.168.100.2" +]) +AT_CHECK([ovn-nbctl get Logical-Switch-Port p52 dynamic_addresses], [0], + ["00:11:22:00:00:4e 192.168.100.3" +]) +AT_CHECK([ovn-nbctl get Logical-Switch-Port p53 dynamic_addresses], [0], + ["00:11:22:00:00:4f 192.168.100.4" +]) + as ovn-sb OVS_APP_EXIT_AND_WAIT([ovsdb-server])