summaryrefslogtreecommitdiff
path: root/ovn
diff options
context:
space:
mode:
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>2019-03-05 14:22:50 +0100
committerBen Pfaff <blp@ovn.org>2019-03-05 15:44:59 -0800
commitf1301a259a92e526672b2f3119a9b234a5013387 (patch)
tree334f9e743dcda4ca74430f4229abcdd4561ce6f1 /ovn
parent2257757aa15f25bf64b96d918c79f4606d0cad2c (diff)
downloadopenvswitch-f1301a259a92e526672b2f3119a9b234a5013387.tar.gz
OVN: select a random mac_prefix if not provided
Select a random IPAM mac_prefix if it has not been provided by the user. With this patch the admin can avoid to configure mac_prefix in order to avoid L2 address collisions if multiple OVN deployments share the same broadcast domain. Remove MAC_ADDR_PREFIX definitions/occurrences since now mac_prefix is always provided to ovn-northd Acked-by: Numan Siddique <nusiddiq@redhat.com> Tested-by: Miguel Duarte de Mora Barroso <mdbarroso@redhat.com> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ovn')
-rw-r--r--ovn/northd/ovn-northd.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c
index 3569ea2be..3661681dc 100644
--- a/ovn/northd/ovn-northd.c
+++ b/ovn/northd/ovn-northd.c
@@ -62,7 +62,6 @@ static const char *ovnnb_db;
static const char *ovnsb_db;
static const char *unixctl_path;
-#define MAC_ADDR_PREFIX 0x0A0000000000ULL
#define MAC_ADDR_SPACE 0xffffff
/* MAC address management (macam) table of "struct eth_addr"s, that holds the
@@ -937,13 +936,8 @@ ipam_insert_mac(struct eth_addr *ea, bool check)
}
uint64_t mac64 = eth_addr_to_uint64(*ea);
- uint64_t prefix;
+ uint64_t prefix = eth_addr_to_uint64(mac_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. */
@@ -1056,11 +1050,7 @@ ipam_get_unused_mac(ovs_be32 ip)
for (i = 0; i < MAC_ADDR_SPACE - 1; i++) {
/* The tentative MAC's suffix will be in the interval (1, 0xfffffe). */
mac_addr_suffix = ((base_addr + i) % (MAC_ADDR_SPACE - 1)) + 1;
- 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;
- }
+ mac64 = eth_addr_to_uint64(mac_prefix) | mac_addr_suffix;
eth_addr_from_uint64(mac64, &mac);
if (!ipam_is_duplicate_mac(&mac, mac64, true)) {
break;
@@ -1132,13 +1122,7 @@ dynamic_mac_changed(const char *lsp_addresses,
}
uint64_t mac64 = eth_addr_to_uint64(update->current_addresses.ea);
- uint64_t prefix;
-
- if (!eth_addr_is_zero(mac_prefix)) {
- prefix = eth_addr_to_uint64(mac_prefix);
- } else {
- prefix = MAC_ADDR_PREFIX;
- }
+ uint64_t prefix = eth_addr_to_uint64(mac_prefix);
if ((mac64 ^ prefix) >> 24) {
return DYNAMIC;
@@ -7300,6 +7284,20 @@ ovnnb_db_run(struct northd_context *ctx,
&addr.ea[0], &addr.ea[1], &addr.ea[2])) {
mac_prefix = addr;
}
+ } else {
+ struct smap options;
+
+ smap_clone(&options, &nb->options);
+ eth_addr_random(&mac_prefix);
+ memset(&mac_prefix.ea[3], 0, 3);
+
+ smap_add_format(&options, "mac_prefix",
+ "%02"PRIx8":%02"PRIx8":%02"PRIx8,
+ mac_prefix.ea[0], mac_prefix.ea[1], mac_prefix.ea[2]);
+ nbrec_nb_global_verify_options(nb);
+ nbrec_nb_global_set_options(nb, &options);
+
+ smap_destroy(&options);
}
cleanup_macam(&macam);