diff options
author | Lorenzo Bianconi <lorenzo.bianconi@redhat.com> | 2018-10-26 18:20:44 +0200 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2018-11-06 07:35:47 -0800 |
commit | 282e53576530faab217c61b6eb7e0f5a49da0ce2 (patch) | |
tree | 590f0f8882a2f76415dac120d22445462a0446c0 /ovn | |
parent | 2345de01f848e13c67edc6dad0b05cb1b83164ec (diff) | |
download | openvswitch-282e53576530faab217c61b6eb7e0f5a49da0ce2.tar.gz |
OVN: introduce mac_prefix support to IPAM
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=<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 <mmichels@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.c | 37 | ||||
-rw-r--r-- | ovn/ovn-nb.xml | 5 |
2 files changed, 39 insertions, 3 deletions
diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index d5a3bc9a9..2f1f616fa 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 @@ -931,10 +932,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; } @@ -1045,7 +1053,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; @@ -1116,7 +1128,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; @@ -7156,6 +7176,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. </column> </group> + + <column name="options" key="mac_prefix"> + Configure a given OUI to be used as prefix when L2 address is + dynamically assigned, e.g. <code>00:11:22</code> + </column> </group> <group title="Connection Options"> |