Blame SOURCES/open-lldp-v1.0.1-13-VDP-Changes-in-OUI-infra-for-get-tlv.patch

89f6b3
From 0bc166920c14081ed90d4774a52ca38813fc1739 Mon Sep 17 00:00:00 2001
89f6b3
From: padkrish <padkrish@cisco.com>
89f6b3
Date: Wed, 21 Jan 2015 03:40:52 +0000
89f6b3
Subject: [PATCH] VDP: Changes in OUI infra for get-tlv
89f6b3
89f6b3
Changes made in OUI infra code to support retrieving OUI parameters
89f6b3
during get-tlv
89f6b3
89f6b3
Signed-off-by: padkrish <padkrish@cisco.com>
89f6b3
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
89f6b3
---
89f6b3
 include/qbg_vdp22_oui.h |  7 +++++++
89f6b3
 include/qbg_vdpnl.h     |  1 +
89f6b3
 qbg/vdp22.c             | 32 ++++++++++++++++++++++++++++++++
89f6b3
 qbg/vdp22_cmds.c        |  4 ++++
89f6b3
 qbg/vdp22_oui.c         |  5 +++++
89f6b3
 qbg/vdp_ascii.c         | 37 +++++++++++++++++++++++++++++++++++++
89f6b3
 qbg/vdpnl.c             | 14 ++++++++++++++
89f6b3
 vdptool.c               | 38 ++++++++++++++++++++++++++++++++++----
89f6b3
 8 files changed, 134 insertions(+), 4 deletions(-)
89f6b3
89f6b3
diff --git a/include/qbg_vdp22_oui.h b/include/qbg_vdp22_oui.h
89f6b3
index 79e1ff5..923e19f 100644
89f6b3
--- a/include/qbg_vdp22_oui.h
89f6b3
+++ b/include/qbg_vdp22_oui.h
89f6b3
@@ -53,6 +53,7 @@ typedef struct vdptool_oui_data_s {
89f6b3
 typedef struct vdptool_oui_hndlr_tbl_s {
89f6b3
 	char *oui_name;
89f6b3
 	bool (*oui_cli_encode_hndlr)(char *dst, char *src, size_t len);
89f6b3
+	void (*oui_print_decode_hndlr)(char *dst);
89f6b3
 } vdptool_oui_hndlr_tbl_t;
89f6b3
 
89f6b3
 struct vdpnl_oui_data_s {
89f6b3
@@ -81,6 +82,11 @@ struct vdp22_oui_handler_s {
89f6b3
 	/* This handler converts the vdpnl structure to vsi22 structure */
89f6b3
 	bool (*vdpnl2vsi22_hndlr)(void *, struct vdpnl_oui_data_s *,
89f6b3
 				   struct vdp22_oui_data_s *);
89f6b3
+	/* This handler converts the vdpnl structure to string */
89f6b3
+	bool (*vdpnl2str_hndlr)(struct vdpnl_oui_data_s *, char *,
89f6b3
+				int *, int);
89f6b3
+	bool (*vsi2vdpnl_hndlr)(void *, struct vdp22_oui_data_s *,
89f6b3
+				struct vdpnl_oui_data_s *);
89f6b3
 	/* This handler creates the OUI fields for Tx */
89f6b3
 	size_t (*vdp_tx_hndlr)(char unsigned *,
89f6b3
 				struct vdp22_oui_data_s *, size_t);
89f6b3
@@ -95,6 +101,7 @@ struct vdp22_oui_handler_s {
89f6b3
 unsigned char vdp22_oui_get_vsi22_fmt(void *);
89f6b3
 unsigned char *vdp22_oui_get_vsi22_len(void *, unsigned char *);
89f6b3
 int oui_vdp_str2uuid(unsigned char *, char *, size_t);
89f6b3
+int oui_vdp_uuid2str(unsigned char *, char *, size_t);
89f6b3
 bool oui_vdp_hndlr_init(struct vdp22_oui_handler_s *);
89f6b3
 int oui_vdp_hexstr2bin(const char *hex, unsigned char *buf, size_t len);
89f6b3
 
89f6b3
diff --git a/include/qbg_vdpnl.h b/include/qbg_vdpnl.h
89f6b3
index bf18e71..cb7efca 100644
89f6b3
--- a/include/qbg_vdpnl.h
89f6b3
+++ b/include/qbg_vdpnl.h
89f6b3
@@ -81,6 +81,7 @@ int vdp_str2vdpnl(char *, struct vdpnl_vsi *, char *);
89f6b3
 int vdp_vdpnl2str(struct vdpnl_vsi *, char *, size_t);
89f6b3
 int vdp22_sendevent(struct vdpnl_vsi *);
89f6b3
 void vdp22_freemaclist(struct vdpnl_vsi *);
89f6b3
+void vsinl_delete_oui(struct vdpnl_vsi *);
89f6b3
 int vdp22_parse_str_vdpnl(struct vdpnl_vsi *, unsigned short *, char *);
89f6b3
 struct vsi22 *vdp22_alloc_vsi_ext(struct vdpnl_vsi *, int *);
89f6b3
 void copy_vsi_external(struct vdpnl_vsi *, struct vsi22 *, int);
89f6b3
diff --git a/qbg/vdp22.c b/qbg/vdp22.c
89f6b3
index ab170ed..10b80a4 100644
89f6b3
--- a/qbg/vdp22.c
89f6b3
+++ b/qbg/vdp22.c
89f6b3
@@ -1010,6 +1010,37 @@ static void copy_fid(struct vdpnl_vsi *vsi, struct vsi22 *p)
89f6b3
 }
89f6b3
 
89f6b3
 /*
89f6b3
+ * This function copies the OUI from VSI22 to vdpnl structure.
89f6b3
+ */
89f6b3
+
89f6b3
+static void copy_oui(struct vdpnl_vsi *vsi, struct vsi22 *p)
89f6b3
+{
89f6b3
+	struct vdp22_oui_handler_s *oui_hndlr;
89f6b3
+	bool ret;
89f6b3
+	int idx;
89f6b3
+
89f6b3
+	vsi->oui_list = calloc(p->no_ouidata, sizeof(*vsi->oui_list));
89f6b3
+	if (!vsi->oui_list)
89f6b3
+		return;
89f6b3
+	vsi->ouisz = p->no_ouidata;
89f6b3
+	for (idx = 0; idx < p->no_ouidata; idx++) {
89f6b3
+		struct vdpnl_oui_data_s *to = &vsi->oui_list[idx];
89f6b3
+		struct vdp22_oui_data_s *from = &p->oui_str_data[idx];
89f6b3
+
89f6b3
+		oui_hndlr = vdp22_get_oui_hndlr(from->oui_name);
89f6b3
+		if (oui_hndlr == NULL) {
89f6b3
+			LLDPAD_ERR("%s: No handler registered for OUI %s\n",
89f6b3
+				   __func__, from->oui_name);
89f6b3
+			continue;
89f6b3
+		}
89f6b3
+		ret = oui_hndlr->vsi2vdpnl_hndlr(p, from, to);
89f6b3
+		if (!ret)
89f6b3
+			LLDPAD_ERR("%s: handler return error for oui %s\n",
89f6b3
+				   __func__, from->oui_name);
89f6b3
+	}
89f6b3
+}
89f6b3
+
89f6b3
+/*
89f6b3
  * Fill the VSI data to return to caller. Currently returned data depends
89f6b3
  * on requestor:
89f6b3
  * 1. Via netlink message from libvirtd and vdptest:
89f6b3
@@ -1033,6 +1064,7 @@ static void copy_vsi(struct vdpnl_vsi *vsi, struct vsi22 *p, int clif)
89f6b3
 	if (clif || (p->flags & VDP22_RETURN_VID)) {
89f6b3
 		copy_fid(vsi, p);
89f6b3
 		p->flags &= ~VDP22_RETURN_VID;
89f6b3
+		copy_oui(vsi, p);
89f6b3
 	}
89f6b3
 }
89f6b3
 
89f6b3
diff --git a/qbg/vdp22_cmds.c b/qbg/vdp22_cmds.c
89f6b3
index 5b5788f..79ea9ca 100644
89f6b3
--- a/qbg/vdp22_cmds.c
89f6b3
+++ b/qbg/vdp22_cmds.c
89f6b3
@@ -434,6 +434,7 @@ static int catvsis(struct vdpnl_vsi *vsi, char *out, size_t out_len)
89f6b3
 	for (i = 1; vdp22_status(i, vsi, 1) > 0; ++i) {
89f6b3
 		if (wanted_req != vsi->request) {
89f6b3
 			vdp22_freemaclist(vsi);
89f6b3
+			vsinl_delete_oui(vsi);
89f6b3
 			continue;
89f6b3
 		}
89f6b3
 		rc = vdp_vdpnl2str(vsi, tmp_buf, out_len - used);
89f6b3
@@ -443,6 +444,7 @@ static int catvsis(struct vdpnl_vsi *vsi, char *out, size_t out_len)
89f6b3
 		if ((c < 0) || ((unsigned)c >= (out_len - used)))
89f6b3
 			return 0;
89f6b3
 		vdp22_freemaclist(vsi);
89f6b3
+		vsinl_delete_oui(vsi);
89f6b3
 		if (rc) {
89f6b3
 			used = strlen(out);
89f6b3
 		} else
89f6b3
@@ -533,6 +535,8 @@ static int get_vsi_partial_arg(UNUSED char *arg, char *orig_argvalue,
89f6b3
 			len = strlen(tmp_buf);
89f6b3
 			c = snprintf(out + used, out_len - used, "%04x%s",
89f6b3
 				     len, tmp_buf);
89f6b3
+			vdp22_freemaclist(vsinl);
89f6b3
+			vsinl_delete_oui(vsinl);
89f6b3
 			if ((c < 0) || ((unsigned)c >= (out_len - used)))
89f6b3
 				goto out_delvsi;
89f6b3
 			if (rc)
89f6b3
diff --git a/qbg/vdp22_oui.c b/qbg/vdp22_oui.c
89f6b3
index 3a2d0cc..4960324 100644
89f6b3
--- a/qbg/vdp22_oui.c
89f6b3
+++ b/qbg/vdp22_oui.c
89f6b3
@@ -57,6 +57,11 @@ int oui_vdp_str2uuid(unsigned char *to, char *buffer, size_t max)
89f6b3
 	return vdp_str2uuid(to, buffer, max);
89f6b3
 }
89f6b3
 
89f6b3
+int oui_vdp_uuid2str(unsigned char *from, char *buffer, size_t max)
89f6b3
+{
89f6b3
+	return vdp_uuid2str(from, buffer, max);
89f6b3
+}
89f6b3
+
89f6b3
 int oui_vdp_hexstr2bin(const char *hex, unsigned char *buf, size_t len)
89f6b3
 {
89f6b3
 	return hexstr2bin(hex, buf, len);
89f6b3
diff --git a/qbg/vdp_ascii.c b/qbg/vdp_ascii.c
89f6b3
index 80a4419..709ffd9 100644
89f6b3
--- a/qbg/vdp_ascii.c
89f6b3
+++ b/qbg/vdp_ascii.c
89f6b3
@@ -244,6 +244,10 @@ static bool oui_str2vdpnl(struct vdpnl_vsi *vsi, char *p, unsigned short idx)
89f6b3
 	oui_hndlr = vdp22_get_oui_hndlr(oui_name);
89f6b3
 	if (!oui_hndlr)
89f6b3
 		return false;
89f6b3
+	if (!vsi->oui_list) {
89f6b3
+		LLDPAD_ERR("%s: Null OUI List\n", __func__);
89f6b3
+		return false;
89f6b3
+	}
89f6b3
 	strncpy(vsi->oui_list[idx].oui_name, oui_name,
89f6b3
 		sizeof(vsi->oui_list[idx].oui_name));
89f6b3
 	if (oui_hndlr->str2vdpnl_hndlr)
89f6b3
@@ -597,11 +601,16 @@ static void mgrid2str(char *to, struct vdpnl_vsi *p, size_t to_len)
89f6b3
 /*
89f6b3
  * Convert a vdpnl_vsi to string.
89f6b3
  */
89f6b3
+
89f6b3
 int vdp_vdpnl2str(struct vdpnl_vsi *p, char *s, size_t length)
89f6b3
 {
89f6b3
 	int c, i;
89f6b3
 	size_t total = 0;
89f6b3
 	char instance[VDP_UUID_STRLEN + 2];
89f6b3
+	struct vdp22_oui_handler_s *oui_hndlr;
89f6b3
+	int oui_total = 0;
89f6b3
+	int ret;
89f6b3
+	int idx;
89f6b3
 
89f6b3
 	mgrid2str(instance, p, sizeof(instance));
89f6b3
 	c = snprintf(s, length, "%02x%s%04x%s%02x%s%04x%s%02x%s%04x%lu%02x%s"
89f6b3
@@ -642,6 +651,34 @@ int vdp_vdpnl2str(struct vdpnl_vsi *p, char *s, size_t length)
89f6b3
 		if (!c)
89f6b3
 			goto out;
89f6b3
 	}
89f6b3
+	for (idx = 0; idx < p->ouisz; idx++) {
89f6b3
+		struct vdpnl_oui_data_s *from = &p->oui_list[idx];
89f6b3
+
89f6b3
+		oui_total = 0;
89f6b3
+		oui_hndlr = vdp22_get_oui_hndlr(from->oui_name);
89f6b3
+		if (oui_hndlr == NULL) {
89f6b3
+			LLDPAD_ERR("%s: Unknown OUI Name %s\n", __func__,
89f6b3
+					from->oui_name);
89f6b3
+		} else {
89f6b3
+			c = snprintf(s, length, "%02x%s",
89f6b3
+				     (unsigned int)strlen(VSI22_ARG_OUI_STR),
89f6b3
+				     VSI22_ARG_OUI_STR);
89f6b3
+			s = check_and_update(&total, &length, s, c);
89f6b3
+			if (!s)
89f6b3
+				goto out;
89f6b3
+			ret = oui_hndlr->vdpnl2str_hndlr(from, s, &oui_total,
89f6b3
+							 length);
89f6b3
+			if (!ret) {
89f6b3
+				LLDPAD_ERR("%s: handler return error for "
89f6b3
+					   "oui %s\n", __func__,
89f6b3
+					   from->oui_name);
89f6b3
+				goto out;
89f6b3
+			}
89f6b3
+			s = check_and_update(&total, &length, s, oui_total);
89f6b3
+			if (!s)
89f6b3
+				goto out;
89f6b3
+		}
89f6b3
+	}
89f6b3
 
89f6b3
 out:
89f6b3
 	return s ? total : 0;
89f6b3
diff --git a/qbg/vdpnl.c b/qbg/vdpnl.c
89f6b3
index 5c0ffd4..9b8fcdd 100644
89f6b3
--- a/qbg/vdpnl.c
89f6b3
+++ b/qbg/vdpnl.c
89f6b3
@@ -365,6 +365,19 @@ static int vdpnl_get(struct vdpnl_vsi *p, struct nlmsghdr *nlh)
89f6b3
 }
89f6b3
 
89f6b3
 /*
89f6b3
+ * Delete the OUI structures of VSI22
89f6b3
+ */
89f6b3
+
89f6b3
+void vsinl_delete_oui(struct vdpnl_vsi *p)
89f6b3
+{
89f6b3
+	if ((p->ouisz == 0) || (p->oui_list == NULL))
89f6b3
+		return;
89f6b3
+	p->ouisz = 0;
89f6b3
+	free(p->oui_list);
89f6b3
+	p->oui_list = NULL;
89f6b3
+}
89f6b3
+
89f6b3
+/*
89f6b3
  * Free an malloc'ed maclist array.
89f6b3
  */
89f6b3
 void vdp22_freemaclist(struct vdpnl_vsi *vsi)
89f6b3
@@ -419,6 +432,7 @@ static int vdpnl_getlink(struct nlmsghdr *nlh, size_t len)
89f6b3
 			nla_nest_end(msg, vf_port);
89f6b3
 		}
89f6b3
 		vdp22_freemaclist(&p);
89f6b3
+		vsinl_delete_oui(&p);
89f6b3
 	} while (rc == 1);
89f6b3
 	nla_nest_end(msg, vf_ports);
89f6b3
 	if (rc < 0) {
89f6b3
diff --git a/vdptool.c b/vdptool.c
89f6b3
index 8edd6ca..b805372 100644
89f6b3
--- a/vdptool.c
89f6b3
+++ b/vdptool.c
89f6b3
@@ -58,8 +58,11 @@
89f6b3
 #include "qbg_vdp22_oui.h"
89f6b3
 
89f6b3
 #define OUI_ENCODE_HNDLR(name) name##_oui_encode_hndlr
89f6b3
+#define OUI_PRNT_DECODE_HNDLR(name) name##_oui_print_decode_hndlr
89f6b3
+
89f6b3
 #define EXTERN_OUI_FN(name) \
89f6b3
-	extern bool name##_oui_encode_hndlr(char *, char *, size_t)
89f6b3
+	extern bool name##_oui_encode_hndlr(char *, char *, size_t); \
89f6b3
+	extern void name##_oui_print_decode_hndlr(char *)
89f6b3
 
89f6b3
 /* The handler declaration  for encoding OUI specific information should be
89f6b3
  * here. The corresponding decoder handler should be in lldpad.
89f6b3
@@ -70,7 +73,7 @@ EXTERN_OUI_FN(cisco);
89f6b3
 /* The OUI specific handlers should be added here */
89f6b3
 
89f6b3
 vdptool_oui_hndlr_tbl_t oui_hndlr_tbl[] = {
89f6b3
-	{"cisco", OUI_ENCODE_HNDLR(cisco)}
89f6b3
+	{"cisco", OUI_ENCODE_HNDLR(cisco), OUI_PRNT_DECODE_HNDLR(cisco)}
89f6b3
 };
89f6b3
 
89f6b3
 
89f6b3
@@ -508,6 +511,29 @@ void print_vsi_err_msg(char *key_val)
89f6b3
 		printf("\tInternal Error : %s\n", VSI22_TX_ERR_STR);
89f6b3
 }
89f6b3
 
89f6b3
+static void print_oui_vals(char *argvals)
89f6b3
+{
89f6b3
+	char oui_name[VDP22_OUI_MAX_NAME];
89f6b3
+	char *temp_argval = argvals;
89f6b3
+	char *oui_val;
89f6b3
+	int tbl_size, cnt;
89f6b3
+	u8 oui_name_len;
89f6b3
+
89f6b3
+	hexstr2bin(argvals, &oui_name_len, sizeof(oui_name_len));
89f6b3
+	if (oui_name_len >= VDP22_OUI_MAX_NAME)
89f6b3
+		return;
89f6b3
+	temp_argval = argvals + 2 * sizeof(oui_name_len);
89f6b3
+	oui_val = temp_argval + oui_name_len;
89f6b3
+	strncpy(oui_name, temp_argval, oui_name_len);
89f6b3
+	oui_name[oui_name_len] = '\0';
89f6b3
+	tbl_size = sizeof(oui_hndlr_tbl) / sizeof(vdptool_oui_hndlr_tbl_t);
89f6b3
+	for (cnt = 0; cnt < tbl_size; cnt++) {
89f6b3
+		if (!strncmp(oui_hndlr_tbl[cnt].oui_name, oui_name,
89f6b3
+			     VDP22_OUI_MAX_NAME))
89f6b3
+			oui_hndlr_tbl[cnt].oui_print_decode_hndlr(oui_val);
89f6b3
+	}
89f6b3
+}
89f6b3
+
89f6b3
 static void print_vsi(char **args, char **argvals, int numargs,
89f6b3
 		      bool err_flag)
89f6b3
 {
89f6b3
@@ -517,8 +543,12 @@ static void print_vsi(char **args, char **argvals, int numargs,
89f6b3
 		if (err_flag && (!strcmp(args[i], VSI22_ARG_HINTS_STR)))
89f6b3
 			print_vsi_err_msg(argvals[i]);
89f6b3
 		else {
89f6b3
-			printf("\t%s", args[i]);
89f6b3
-			printf(" = %s\n", argvals[i]);
89f6b3
+			if (!strcmp(args[i], VSI22_ARG_OUI_STR)) {
89f6b3
+				print_oui_vals(argvals[i]);
89f6b3
+			} else {
89f6b3
+				printf("\t%s", args[i]);
89f6b3
+				printf(" = %s\n", argvals[i]);
89f6b3
+			}
89f6b3
 		}
89f6b3
 	}
89f6b3
 }
89f6b3
-- 
89f6b3
2.1.0
89f6b3