Message ID | 1491003982-44081-1-git-send-email-zhouhan@gmail.com |
---|---|
State | Accepted |
Headers | show |
On Fri, Mar 31, 2017 at 04:46:22PM -0700, Han Zhou wrote: > When uuid starts with 0s, lflow-list will fail if leading 0s are > not included in command argument. This leads to unexpected results > considering that leading 0s are usually not shown up in cookies > of OpenFlow outputs of tools such as ovs-ofctl dump-flows > and ovs-appctl ofproto/trace. E.g. > > lflow uuid: 0c16ceb4-0409-484b-8297-a6e7f264ac2d > $ ovn-nbctl lflow-list 0c16ceb4 # works fine > $ ovn-nbctl lflow-list c16ceb4 # doesn't work > > This patch fixes the problem. > > Signed-off-by: Han Zhou <zhouhan@gmail.com> Wow, that's subtle. Good catch! I applied this to master and branch-2.7. I couldn't resist changing strip_leading_zero() to just static const char * strip_leading_zero(const char *s) { return s + strspn(s, "0"); } though. (By the way, this is going to result in "ovn-nbctl lflow-list 00000" listing all the flows, but I guess that's not a big deal.) Thanks, Ben.
diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index 4e3cbad..612456a 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -714,13 +714,24 @@ parse_partial_uuid(char *s) return NULL; } +static const char * +strip_leading_zero(const char *s) +{ + size_t i = 0; + while (s[i++] == '0'); + return s + i; +} + static bool is_partial_uuid_match(const struct uuid *uuid, const char *match) { char uuid_s[UUID_LEN + 1]; snprintf(uuid_s, sizeof uuid_s, UUID_FMT, UUID_ARGS(uuid)); - return !strncmp(uuid_s, match, strlen(match)); + const char *s1 = strip_leading_zero(uuid_s); + const char *s2 = strip_leading_zero(match); + + return !strncmp(s1, s2, strlen(s2)); } static const struct sbrec_datapath_binding *
When uuid starts with 0s, lflow-list will fail if leading 0s are not included in command argument. This leads to unexpected results considering that leading 0s are usually not shown up in cookies of OpenFlow outputs of tools such as ovs-ofctl dump-flows and ovs-appctl ofproto/trace. E.g. lflow uuid: 0c16ceb4-0409-484b-8297-a6e7f264ac2d $ ovn-nbctl lflow-list 0c16ceb4 # works fine $ ovn-nbctl lflow-list c16ceb4 # doesn't work This patch fixes the problem. Signed-off-by: Han Zhou <zhouhan@gmail.com> --- ovn/utilities/ovn-sbctl.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)