The command "ovn-nbctl lrp-add" should not set the MAC address which length is invalid to logical router port. This patch also updates the ovn-nbctl tests.
Signed-off-by: nickcooper-zhangtonghao <nickcooper-zhangtong...@opencloud.tech> --- ovn/utilities/ovn-nbctl.c | 7 ++++++- tests/ovn-nbctl.at | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 2148665..563c6ec 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -1836,7 +1836,12 @@ nbctl_lrp_add(struct ctl_context *ctx) } struct eth_addr ea; - if (!ovs_scan(mac, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(ea))) { + int n = 0; + if (!ovs_scan_len(mac, &n, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(ea))) { + ctl_fatal("%s: invalid mac address %s", lrp_name, mac); + } + + if (mac[n]) { ctl_fatal("%s: invalid mac address %s", lrp_name, mac); } diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 241e6d3..3f459a8 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -301,6 +301,13 @@ AT_SETUP([ovn-nbctl - basic logical router port commands]) OVN_NBCTL_TEST_START AT_CHECK([ovn-nbctl lr-add lr0]) +AT_CHECK([ovn-nbctl lrp-add lr0 lrp0 00:00:00:01:02 192.168.1.1/24], [1], [], + [ovn-nbctl: lrp0: invalid mac address 00:00:00:01:02 +]) +AT_CHECK([ovn-nbctl lrp-add lr0 lrp0 00:00:00:01:02:03:04 192.168.1.1/24], [1], [], + [ovn-nbctl: lrp0: invalid mac address 00:00:00:01:02:03:04 +]) + AT_CHECK([ovn-nbctl lrp-add lr0 lrp0 00:00:00:01:02:03 192.168.1.1/24]) AT_CHECK([ovn-nbctl show lr0 | ${PERL} $srcdir/uuidfilt.pl], [0], [dnl -- 1.8.3.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev