Skip to content

Commit

Permalink
ovn-nbctl: Help catch lport-set-addresses mistakes.
Browse files Browse the repository at this point in the history
While debugging a broken OVN environment yesterday, the problem turned
out to be invalid entries in the logical port addresses column.  In
particular, the following command had been used:

  $ ovn-nbctl lport-set-addresses lp0 MAC IP

instead of:

  $ ovn-nbctl lport-set-addresses lp0 "MAC IP"

This is really easy to mess up, so add some simple validation to the
lport-set-addresses command.  If the beginning of an argument is ever
an IP address, it's wrong.

In passing, also add a note to the ovn-nb db documentation to note that
the order of "MAC IP" is required, as "IP MAC" is not valid.

Signed-off-by: Russell Bryant <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
russellb committed Jan 21, 2016
1 parent 9fd5239 commit 5761980
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ovn/ovn-nb.xml
Expand Up @@ -285,6 +285,11 @@
if any, uses this information to avoid issuing ARP requests for
logical switch ports.
</p>

<p>
Note that the order here is important. The Ethernet address must
be listed before the IP address.
</p>
</dd>

<dt><code>unknown</code></dt>
Expand Down
16 changes: 16 additions & 0 deletions ovn/utilities/ovn-nbctl.c
Expand Up @@ -25,6 +25,7 @@
#include "fatal-signal.h"
#include "json.h"
#include "ovn/lib/ovn-nb-idl.h"
#include "packets.h"
#include "poll-loop.h"
#include "process.h"
#include "smap.h"
Expand Down Expand Up @@ -663,6 +664,21 @@ nbctl_lport_set_addresses(struct ctl_context *ctx)
return;
}

int i;
for (i = 2; i < ctx->argc; i++) {
struct eth_addr ea;

if (strcmp(ctx->argv[i], "unknown")
&& !ovs_scan(ctx->argv[i], ETH_ADDR_SCAN_FMT,
ETH_ADDR_SCAN_ARGS(ea))) {
VLOG_ERR("Invalid address format (%s). See ovn-nb(5). "
"Hint: An Ethernet address must be "
"listed before an IP address, together as a single "
"argument.", ctx->argv[i]);
return;
}
}

nbrec_logical_port_set_addresses(lport,
(const char **) ctx->argv + 2, ctx->argc - 2);
}
Expand Down

0 comments on commit 5761980

Please sign in to comment.