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

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