Skip to content

Commit

Permalink
ovn-nbctl: Avoid uninitialized value for mirror index.
Browse files Browse the repository at this point in the history
The local mirror doesn't have an index, avoid storing
uninitialized value in that case. Also prevent from index
printing for local mirrors.

Signed-off-by: Ales Musil <[email protected]>
Signed-off-by: Numan Siddique <[email protected]>
  • Loading branch information
almusil authored and numansiddique committed Jul 4, 2024
1 parent 0a80f9d commit 908a7e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions tests/ovn-nbctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ OVN_NBCTL_TEST([ovn_nbctl_mirrors], [mirrors], [
check ovn-nbctl mirror-add mirror1 gre 0 from-lport 10.10.10.1
check ovn-nbctl mirror-add mirror2 erspan 1 to-lport 10.10.10.2
check ovn-nbctl mirror-add mirror3 gre 2 to-lport 10.10.10.3
check ovn-nbctl mirror-add mirror-local local both 10.10.10.3
check ovn-nbctl ls-add sw0
check ovn-nbctl lsp-add sw0 sw0-port1
check ovn-nbctl lsp-add sw0 sw0-port2
Expand Down Expand Up @@ -480,6 +481,11 @@ check_column "$mirror3uuid" nb:Logical_Switch_Port mirror_rules name=sw0-port3

dnl Verify if multiple ports are attached to the same mirror properly
AT_CHECK([ovn-nbctl mirror-list], [0], [dnl
mirror-local:
Type : local
Sink : 10.10.10.3
Filter : both

mirror1:
Type : gre
Sink : 10.10.10.1
Expand All @@ -500,6 +506,9 @@ mirror3:

])

dnl Remove the local mirror
check ovn-nbctl mirror-del mirror-local

dnl Detach one source port from mirror
check ovn-nbctl lsp-detach-mirror sw0-port3 mirror3

Expand Down
8 changes: 5 additions & 3 deletions utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -7691,7 +7691,7 @@ nbctl_mirror_add(struct ctl_context *ctx)
const char *sink = NULL;
const char *type = NULL;
const char *name = NULL;
int64_t index;
int64_t index = -1;
char *error = NULL;
const struct nbrec_mirror *mirror_check = NULL;
int pos = 1;
Expand Down Expand Up @@ -7824,8 +7824,10 @@ nbctl_mirror_list(struct ctl_context *ctx)
ds_put_format(&ctx->output, " Type : %s\n", mirror->type);
ds_put_format(&ctx->output, " Sink : %s\n", mirror->sink);
ds_put_format(&ctx->output, " Filter : %s\n", mirror->filter);
ds_put_format(&ctx->output, " Index/Key: %ld\n",
(long int) mirror->index);
if (strcmp(mirror->type, "local")) {
ds_put_format(&ctx->output, " Index/Key: %"PRId64"\n",
mirror->index);
}
ds_put_cstr(&ctx->output, "\n");
}

Expand Down

0 comments on commit 908a7e7

Please sign in to comment.