aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/linux
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2023-07-28 20:06:09 +0200
committerFlorin Coras <florin.coras@gmail.com>2023-08-02 16:07:06 +0000
commit3706636ca05982996b16610233df3e303845238e (patch)
tree0be54c3b87adc3e15d7ad0abe08312ae10d7d8e6 /src/vlib/linux
parentf566524a210dcf55a667e54bdaae2a833a9b13a5 (diff)
vlib: remove dependency on libuuid
Type: improvement Change-Id: I4e2b2e4f227dfcb3df36166db13c8aa5c0b603f5 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/linux')
-rw-r--r--src/vlib/linux/vmbus.c65
1 files changed, 53 insertions, 12 deletions
diff --git a/src/vlib/linux/vmbus.c b/src/vlib/linux/vmbus.c
index 12813651d4c..aae11a1fefb 100644
--- a/src/vlib/linux/vmbus.c
+++ b/src/vlib/linux/vmbus.c
@@ -31,8 +31,6 @@
#include <linux/ethtool.h>
#include <linux/sockios.h>
-#include <uuid/uuid.h>
-
static const char sysfs_vmbus_dev_path[] = "/sys/bus/vmbus/devices";
static const char sysfs_vmbus_drv_path[] = "/sys/bus/vmbus/drivers";
static const char sysfs_class_net_path[] = "/sys/class/net";
@@ -123,16 +121,39 @@ unformat_vlib_vmbus_addr (unformat_input_t *input, va_list *args)
{
vlib_vmbus_addr_t *addr = va_arg (*args, vlib_vmbus_addr_t *);
uword ret = 0;
- u8 *s;
+ u8 *s = 0;
- if (!unformat (input, "%s", &s))
+ if (!unformat (input, "%U", unformat_token, "a-zA-Z0-9-", &s))
return 0;
- if (uuid_parse ((char *) s, addr->guid) == 0)
- ret = 1;
+ if (vec_len (s) != 36)
+ goto fail;
- vec_free (s);
+ if (s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-')
+ goto fail;
+
+ clib_memmove (s + 8, s + 9, 4);
+ clib_memmove (s + 12, s + 14, 4);
+ clib_memmove (s + 16, s + 19, 4);
+ clib_memmove (s + 20, s + 24, 12);
+
+ for (int i = 0; i < 32; i++)
+ if (s[i] >= '0' && s[i] <= '9')
+ s[i] -= '0';
+ else if (s[i] >= 'A' && s[i] <= 'F')
+ s[i] -= 'A' - 10;
+ else if (s[i] >= 'a' && s[i] <= 'f')
+ s[i] -= 'a' - 10;
+ else
+ goto fail;
+
+ for (int i = 0; i < 16; i++)
+ addr->guid[i] = s[2 * i] * 16 + s[2 * i + 1];
+ ret = 1;
+
+fail:
+ vec_free (s);
return ret;
}
@@ -141,10 +162,24 @@ u8 *
format_vlib_vmbus_addr (u8 *s, va_list *va)
{
vlib_vmbus_addr_t *addr = va_arg (*va, vlib_vmbus_addr_t *);
- char tmp[40];
-
- uuid_unparse (addr->guid, tmp);
- return format (s, "%s", tmp);
+ u8 *bytes = addr->guid;
+
+ for (int i = 0; i < 4; i++)
+ s = format (s, "%02X", bytes++[0]);
+ vec_add1 (s, '-');
+ for (int i = 0; i < 2; i++)
+ s = format (s, "%02X", bytes++[0]);
+ vec_add1 (s, '-');
+ for (int i = 0; i < 2; i++)
+ s = format (s, "%02X", bytes++[0]);
+ vec_add1 (s, '-');
+ for (int i = 0; i < 2; i++)
+ s = format (s, "%02X", bytes++[0]);
+ vec_add1 (s, '-');
+ for (int i = 0; i < 6; i++)
+ s = format (s, "%02X", bytes++[0]);
+
+ return s;
}
/* workaround for mlx bug, bring lower device up before unbind */
@@ -383,7 +418,13 @@ vmbus_addr_cmp (void *v1, void *v2)
vlib_vmbus_addr_t *a1 = v1;
vlib_vmbus_addr_t *a2 = v2;
- return uuid_compare (a1->guid, a2->guid);
+ for (int i = 0; i < ARRAY_LEN (a1->guid); i++)
+ if (a1->guid[i] > a2->guid[i])
+ return 1;
+ else if (a1->guid[i] < a2->guid[i])
+ return -1;
+
+ return 0;
}
vlib_vmbus_addr_t *