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 <[email protected]>
---
 ovn/utilities/ovn-sbctl.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

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 *
-- 
2.1.0

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to