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

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