[lldp-devel] [PATCH 1/2] vdp rename function instance2str to vp_uuid2str

Thomas Richter tmricht at linux.vnet.ibm.com
Mon Mar 11 15:51:43 UTC 2013


Rename function instance2str() to vp_uuid2str() and
the corresponding define for the minimum string length
from INSTANCE_STRLEN to VDP_UUID_STRLEN.
Also move the function to file lldp_qbg_utils.c

Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
---
 include/lldp_qbg_utils.h |    8 ++++++++
 include/lldp_vdp.h       |    2 --
 lldp_qbg_utils.c         |   12 ++++++++++++
 lldp_vdp.c               |    5 +++--
 lldp_vdp_cmds.c          |   20 +++-----------------
 qbg/lldp_vdpnl.c         |   13 +++++++------
 6 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/include/lldp_qbg_utils.h b/include/lldp_qbg_utils.h
index 744e523..9f465c4 100644
--- a/include/lldp_qbg_utils.h
+++ b/include/lldp_qbg_utils.h
@@ -32,4 +32,12 @@
 
 void hexdump_frame(const char *, char *, const unsigned char *, size_t);
 int modules_notify(int, int, char *, void *);
+
+/*
+ * Required buffer space to display a UUID.
+ * VDP_UUID_STRLEN = strlen("fa9b7fff-b0a0-4893-abcd-beef4ff18f8f")
+ */
+#define VDP_UUID_STRLEN 36
+
+int vdp_uuid2str(const u8 *, char *, size_t);
 #endif
diff --git a/include/lldp_vdp.h b/include/lldp_vdp.h
index 1ad5365..1e2908b 100644
--- a/include/lldp_vdp.h
+++ b/include/lldp_vdp.h
@@ -161,12 +161,10 @@ int vdp_vsis_pending(struct vdp_data *);
 int vdp_vsis(char *);
 const char *vdp_response2str(int);
 void vdp_trace_profile(struct vsi_profile *);
-int instance2str(const u8 *, char *, size_t);
 struct vsi_profile *vdp_alloc_profile(void);
 void vdp_delete_profile(struct vsi_profile *);
 struct vsi_profile *vdp_find_profile(struct vdp_data *, struct vsi_profile *);
 
 #define MAC_ADDR_STRLEN		18
-#define INSTANCE_STRLEN		36
 
 #endif /* _LLDP_VDP_H */
diff --git a/lldp_qbg_utils.c b/lldp_qbg_utils.c
index ffac80b..04491de 100644
--- a/lldp_qbg_utils.c
+++ b/lldp_qbg_utils.c
@@ -81,3 +81,15 @@ int modules_notify(int id, int sender_id, char *ifname, void *data)
 	LLDPAD_DBG("%s:%s target-id:%#x rc:%d\n", __func__, ifname, id, rc);
 	return rc;
 }
+
+int vdp_uuid2str(const u8 *p, char *dst, size_t size)
+{
+	if (dst && size > VDP_UUID_STRLEN) {
+		snprintf(dst, size, "%02x%02x%02x%02x-%02x%02x-%02x%02x"
+			 "-%02x%02x-%02x%02x%02x%02x%02x%02x",
+			 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
+			 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
+		return 0;
+	}
+	return -1;
+}
diff --git a/lldp_vdp.c b/lldp_vdp.c
index 66a0871..72cf092 100644
--- a/lldp_vdp.c
+++ b/lldp_vdp.c
@@ -45,6 +45,7 @@
 #include "lldp_tlv.h"
 #include "lldp_vdp_cmds.h"
 #include "lldp_vdp_clif.h"
+#include "lldp_qbg_utils.h"
 #include "lldp_mand_clif.h"
 
 static const char * const vsi_responses[] = {
@@ -75,10 +76,10 @@ int vdp_trigger(struct vsi_profile *profile);
 
 void vdp_trace_profile(struct vsi_profile *p)
 {
-	char instance[INSTANCE_STRLEN + 2];
+	char instance[VDP_UUID_STRLEN + 2];
 	struct mac_vlan *mac_vlan;
 
-	instance2str(p->instance, instance, sizeof(instance));
+	vdp_uuid2str(p->instance, instance, sizeof(instance));
 
 	LLDPAD_DBG("profile:%p mode:%d response:%d state:%d (%s) no_nlmsg:%d"
 		   " txmit:%i"
diff --git a/lldp_vdp_cmds.c b/lldp_vdp_cmds.c
index 14bf627..4785841 100644
--- a/lldp_vdp_cmds.c
+++ b/lldp_vdp_cmds.c
@@ -37,6 +37,7 @@
 #include "lldp_mand_clif.h"
 #include "lldp_vdp_clif.h"
 #include "lldp_vdp_cmds.h"
+#include "lldp_qbg_utils.h"
 #include "lldp/ports.h"
 #include "messages.h"
 #include "libconfig.h"
@@ -104,9 +105,9 @@ char *print_profile(char *s, size_t length, struct vsi_profile *p)
 		return r;
 
 	{
-		char instance[INSTANCE_STRLEN + 2];
+		char instance[VDP_UUID_STRLEN + 2];
 
-		instance2str(p->instance, instance, sizeof(instance));
+		vdp_uuid2str(p->instance, instance, sizeof(instance));
 		c = snprintf(s, length, "instance: %s\n", &instance[0]);
 	}
 	s = check_and_update(&total, &length, s, c);
@@ -304,21 +305,6 @@ static void str2instance(struct vsi_profile *profile, char *buffer)
 	}
 }
 
-/* INSTANCE_STRLEN = strlen("fa9b7fff-b0a0-4893-abcd-beef4ff18f8f") */
-#define INSTANCE_STRLEN 36
-
-int instance2str(const u8 *p, char *dst, size_t size)
-{
-	if (dst && size > INSTANCE_STRLEN) {
-		snprintf(dst, size, "%02x%02x%02x%02x-%02x%02x-%02x%02x"
-			 "-%02x%02x-%02x%02x%02x%02x%02x%02x",
-			 p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
-			 p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
-		return 0;
-	}
-	return -1;
-}
-
 static void vdp_fill_profile(struct vsi_profile *profile, char *buffer,
 			     int field)
 {
diff --git a/qbg/lldp_vdpnl.c b/qbg/lldp_vdpnl.c
index 26d2cb8..cd3f32a 100644
--- a/qbg/lldp_vdpnl.c
+++ b/qbg/lldp_vdpnl.c
@@ -41,6 +41,7 @@
 #include "messages.h"
 #include "lldp_vdp.h"
 #include "lldp_vdpnl.h"
+#include "lldp_qbg_utils.h"
 #include "lldp_rtnl.h"
 
 static struct nla_policy ifla_vf_policy[IFLA_VF_MAX + 1] = {
@@ -96,7 +97,7 @@ static int vdpnl_get(struct nlmsghdr *nlh, struct vdpnl_vsi *p)
 
 static void vdpnl_show(struct vdpnl_vsi *vsi)
 {
-	char instance[INSTANCE_STRLEN + 2];
+	char instance[VDP_UUID_STRLEN + 2];
 	struct vdpnl_mac *mac;
 	int i;
 
@@ -112,7 +113,7 @@ static void vdpnl_show(struct vdpnl_vsi *vsi)
 		   "typeid_version:%d\n",
 		   __func__, vsi->vsi_mgrid, vsi->vsi_typeid,
 		   vsi->vsi_typeversion);
-	instance2str(vsi->vsi_uuid, instance, sizeof(instance));
+	vdp_uuid2str(vsi->vsi_uuid, instance, sizeof(instance));
 	LLDPAD_DBG("%s: IFLA_PORT_INSTANCE_UUID=%s\n", __func__, instance);
 	LLDPAD_DBG("%s: IFLA_PORT_REQUEST=%d\n", __func__, vsi->request);
 	LLDPAD_DBG("%s: IFLA_PORT_RESPONSE=%d\n", __func__, vsi->response);
@@ -124,7 +125,7 @@ static void vdpnl_show(struct vdpnl_vsi *vsi)
  */
 static int vdpnl_vfports(struct nlattr *vfports, struct vdpnl_vsi *vsi)
 {
-	char instance[INSTANCE_STRLEN + 2];
+	char instance[VDP_UUID_STRLEN + 2];
 	struct nlattr *tb_vf_ports, *tb3[IFLA_PORT_MAX + 1];
 	int rem;
 
@@ -156,7 +157,7 @@ static int vdpnl_vfports(struct nlattr *vfports, struct vdpnl_vsi *vsi)
 
 			uuid = (unsigned char *)
 				RTA_DATA(tb3[IFLA_PORT_HOST_UUID]);
-			instance2str(uuid, instance, sizeof(instance));
+			vdp_uuid2str(uuid, instance, sizeof(instance));
 			LLDPAD_DBG("%s: IFLA_PORT_HOST_UUID=%s\n", __func__,
 				   instance);
 		}
@@ -315,11 +316,11 @@ static void vdpnl_reply1(struct vdpnl_vsi *p, struct nlmsghdr *nlh, size_t len)
  */
 static void vdpnl_reply2(struct vdpnl_vsi *p, struct nlmsghdr *nlh)
 {
-	char instance[INSTANCE_STRLEN + 2];
+	char instance[VDP_UUID_STRLEN + 2];
 
 	mynla_put(nlh, IFLA_PORT_INSTANCE_UUID, sizeof p->vsi_uuid,
 		  p->vsi_uuid);
-	instance2str(p->vsi_uuid, instance, sizeof instance);
+	vdp_uuid2str(p->vsi_uuid, instance, sizeof instance);
 	LLDPAD_DBG("%s: IFLA_PORT_INSTANCE_UUID=%s\n", __func__, instance);
 	mynla_put_u32(nlh, IFLA_PORT_VF, PORT_SELF_VF);
 	LLDPAD_DBG("%s: IFLA_PORT_VF=%d\n", __func__,  PORT_SELF_VF);
-- 
1.7.1



More information about the lldp-devel mailing list