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

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