Skip to content

Commit

Permalink
ovn-northd: Fix update of a mac prefix.
Browse files Browse the repository at this point in the history
'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: 39242c1 ("northd: refactor and split some IPAM functions")
Signed-off-by: Ilya Maximets <[email protected]>
Acked-by: Mark D. Gray <[email protected]>
Signed-off-by: Mark Michelson <[email protected]>
  • Loading branch information
igsilya authored and putnopvut committed Sep 13, 2021
1 parent 05edcde commit a302947
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion northd/ovn-northd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions tests/ovn.at
Original file line number Diff line number Diff line change
Expand Up @@ -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::"
Expand Down

0 comments on commit a302947

Please sign in to comment.