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

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