Blame SOURCES/open-lldp-v1.0.1-14-VDP-Changes-in-Cisco-OUI-handlers-to-support-get-tlv.patch

436175
From ead7bc6267c87e0816ba2367b9036d8a647f3099 Mon Sep 17 00:00:00 2001
436175
From: padkrish <padkrish@cisco.com>
436175
Date: Wed, 21 Jan 2015 03:41:14 +0000
436175
Subject: [PATCH] VDP: Changes in Cisco OUI handlers to support 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/vdp_cisco.h  |  22 ++++++++++
436175
 qbg/vdp22cisco_oui.c | 120 ++++++++++++++++++++++++++++++++++++++++++---------
436175
 vdptool_cisco_oui.c  |  54 +++++++++++++++++++++++
436175
 3 files changed, 175 insertions(+), 21 deletions(-)
436175
436175
diff --git a/include/vdp_cisco.h b/include/vdp_cisco.h
436175
index 339d479..821db68 100644
436175
--- a/include/vdp_cisco.h
436175
+++ b/include/vdp_cisco.h
436175
@@ -96,6 +96,7 @@ typedef union l3_addrtype_ {
436175
 typedef struct vdp_cisco_oui_s {
436175
 	char key[KEYLEN];       /* Profile name */
436175
 	u8 uuid[PORT_UUID_MAX]; /* Instance ID */
436175
+	bool uuid_set;
436175
 	size_t vm_name_len;
436175
 	char vm_name[MAX_VM_NAME];
436175
 	u16 afi;
436175
@@ -103,10 +104,18 @@ typedef struct vdp_cisco_oui_s {
436175
 	l3_addr_t l3_addr;
436175
 } vdp_cisco_oui_t;
436175
 
436175
+struct oui_keyword_handler oui_key_handle[] = {
436175
+	{CISCO_OUI_NAME_ARG_STR, CISCO_OUI_NAME_ARG},
436175
+	{CISCO_OUI_NAME_UUID_ARG_STR, CISCO_OUI_NAME_UUID_ARG},
436175
+	{CISCO_OUI_L3V4ADDR_ARG_STR, CISCO_OUI_L3V4ADDR_ARG} };
436175
+
436175
 bool cisco_str2vdpnl_hndlr(struct vdpnl_oui_data_s *, char *);
436175
 bool cisco_vdp_free_oui(struct vdp22_oui_data_s *);
436175
 bool cisco_vdpnl2vsi22_hndlr(void *, struct vdpnl_oui_data_s *,
436175
 			     struct vdp22_oui_data_s *);
436175
+bool cisco_vdpnl2str_hndlr(struct vdpnl_oui_data_s *, char *, int *, int);
436175
+bool cisco_vsi2vdpnl_hndlr(void *, struct vdp22_oui_data_s *,
436175
+			   struct vdpnl_oui_data_s *);
436175
 size_t cisco_vdp_tx_hndlr(char unsigned *, struct vdp22_oui_data_s *, size_t);
436175
 bool cisco_vdp_rx_hndlr();
436175
 unsigned long cisco_vdp_oui_ptlvsize(void *);
436175
@@ -118,4 +127,17 @@ static inline void fill_cisco_oui_type(unsigned char *oui_type)
436175
 	oui_type[2] = 0x0c;
436175
 }
436175
 
436175
+enum oui_key_arg get_oui_key(char *token, u8 key_len)
436175
+{
436175
+	int count, key_str_size;
436175
+
436175
+	key_str_size = sizeof(oui_key_handle) / sizeof(oui_key_handle[0]);
436175
+	for (count = 0; count < key_str_size; count++) {
436175
+		if ((key_len <= strlen(token)) &&
436175
+		    (!strncmp(token, oui_key_handle[count].keyword, key_len)))
436175
+			return oui_key_handle[count].val;
436175
+	}
436175
+	return CISCO_OUI_INVALID_ARG;
436175
+}
436175
+
436175
 #endif /* __VDP22_VISCO_H__ */
436175
diff --git a/qbg/vdp22cisco_oui.c b/qbg/vdp22cisco_oui.c
436175
index ef6c307..e8a824c 100644
436175
--- a/qbg/vdp22cisco_oui.c
436175
+++ b/qbg/vdp22cisco_oui.c
436175
@@ -29,31 +29,14 @@
436175
 #include <ctype.h>
436175
 #include "messages.h"
436175
 #include "qbg_vdp22def.h"
436175
+#include "qbg_utils.h"
436175
 #include "vdp_cisco.h"
436175
 
436175
 struct vdp22_oui_handler_s cisco_oui_hndlr = {
436175
 		{0x00, 0x00, 0x0c}, "cisco", cisco_str2vdpnl_hndlr,
436175
-		cisco_vdpnl2vsi22_hndlr,
436175
-		cisco_vdp_tx_hndlr, cisco_vdp_rx_hndlr, cisco_vdp_free_oui,
436175
-		cisco_vdp_oui_ptlvsize};
436175
-
436175
-struct oui_keyword_handler oui_key_handle[] = {
436175
-	{CISCO_OUI_NAME_ARG_STR, CISCO_OUI_NAME_ARG},
436175
-	{CISCO_OUI_NAME_UUID_ARG_STR, CISCO_OUI_NAME_UUID_ARG},
436175
-	{CISCO_OUI_L3V4ADDR_ARG_STR, CISCO_OUI_L3V4ADDR_ARG} };
436175
-
436175
-enum oui_key_arg get_oui_key(char *token, u8 key_len)
436175
-{
436175
-	int count, key_str_size;
436175
-
436175
-	key_str_size = sizeof(oui_key_handle) / sizeof(oui_key_handle[0]);
436175
-	for (count = 0; count < key_str_size; count++) {
436175
-		if ((key_len <= strlen(token)) &&
436175
-		     (!strncmp(token, oui_key_handle[count].keyword, key_len)))
436175
-			return oui_key_handle[count].val;
436175
-	}
436175
-	return CISCO_OUI_INVALID_ARG;
436175
-}
436175
+		cisco_vdpnl2vsi22_hndlr, cisco_vdpnl2str_hndlr,
436175
+		cisco_vsi2vdpnl_hndlr, cisco_vdp_tx_hndlr, cisco_vdp_rx_hndlr,
436175
+		cisco_vdp_free_oui, cisco_vdp_oui_ptlvsize};
436175
 
436175
 /*
436175
  * This function fills the vdpnl structure of OUI from the command separated
436175
@@ -124,6 +107,7 @@ bool cisco_str2vdpnl_hndlr(struct vdpnl_oui_data_s *vdp_oui_p, char *token)
436175
 					     sizeof(vdp_cisco_oui_p->uuid)))
436175
 				memset(vdp_cisco_oui_p->uuid, 0,
436175
 					sizeof(vdp_cisco_oui_p->uuid));
436175
+				vdp_cisco_oui_p->uuid_set = true;
436175
 			free(uuid);
436175
 			break;
436175
 		case CISCO_OUI_L3V4ADDR_ARG:
436175
@@ -193,6 +177,100 @@ bool cisco_vdpnl2vsi22_hndlr(void *vsi_data, struct vdpnl_oui_data_s *from,
436175
 }
436175
 
436175
 /*
436175
+ * This function converts the OUI information from vdpnl struct to string
436175
+ */
436175
+
436175
+bool cisco_vdpnl2str_hndlr(struct vdpnl_oui_data_s *from, char *out_buf,
436175
+			   int *total, int rem_len)
436175
+{
436175
+	char tmp_out_buf[MAX_OUI_DATA_LEN];
436175
+	char uuid_str[VDP_UUID_STRLEN + 2];
436175
+	char *tmp_oui_buf;
436175
+	vdp_cisco_oui_t *vdp_cisco_oui_p;
436175
+	int c = 0, num_str_bytes;
436175
+	int tmp_buf_len = sizeof(tmp_out_buf);
436175
+
436175
+	tmp_oui_buf = tmp_out_buf;
436175
+	if ((from == NULL) || (out_buf == NULL)) {
436175
+		LLDPAD_ERR("%s: NULL arg\n", __func__);
436175
+		return false;
436175
+	}
436175
+	vdp_cisco_oui_p = (vdp_cisco_oui_t *)from->data;
436175
+	c = snprintf(tmp_oui_buf, tmp_buf_len, "%02x%s",
436175
+		     (unsigned int)strlen("cisco"), "cisco");
436175
+	tmp_buf_len -= c;
436175
+	tmp_oui_buf += c;
436175
+	if (vdp_cisco_oui_p->vm_name_len != 0) {
436175
+		c = snprintf(tmp_oui_buf, tmp_buf_len,
436175
+			     "%02x%s%04x%s",
436175
+			     (unsigned int)strlen(CISCO_OUI_NAME_ARG_STR),
436175
+			     CISCO_OUI_NAME_ARG_STR,
436175
+			     (unsigned int)vdp_cisco_oui_p->vm_name_len,
436175
+			     vdp_cisco_oui_p->vm_name);
436175
+		if ((c < 0) || (c >= tmp_buf_len))
436175
+			return false;
436175
+		tmp_buf_len -= c;
436175
+		tmp_oui_buf += c;
436175
+	}
436175
+	if (vdp_cisco_oui_p->uuid_set) {
436175
+		oui_vdp_uuid2str(vdp_cisco_oui_p->uuid, uuid_str,
436175
+				 sizeof(uuid_str));
436175
+		c = snprintf(tmp_oui_buf, tmp_buf_len,
436175
+			     "%02x%s%04x%s",
436175
+			     (unsigned int)strlen(CISCO_OUI_NAME_UUID_ARG_STR),
436175
+			     CISCO_OUI_NAME_UUID_ARG_STR,
436175
+			     (unsigned int)strlen(uuid_str), uuid_str);
436175
+		if ((c < 0) || (c >= tmp_buf_len))
436175
+			return false;
436175
+		tmp_buf_len -= c;
436175
+		tmp_oui_buf += c;
436175
+	}
436175
+	if (vdp_cisco_oui_p->vm_addr_len != 0) {
436175
+		num_str_bytes = snprintf(NULL, 0, "%ul",
436175
+					 vdp_cisco_oui_p->l3_addr.
436175
+					 ipv4_address.s_addr);
436175
+		c = snprintf(tmp_oui_buf, tmp_buf_len, "%02x%s%04x%ul",
436175
+			     (unsigned int)strlen(CISCO_OUI_L3V4ADDR_ARG_STR),
436175
+			     CISCO_OUI_L3V4ADDR_ARG_STR, num_str_bytes,
436175
+			     vdp_cisco_oui_p->l3_addr.ipv4_address.s_addr);
436175
+		if ((c < 0) || (c >= tmp_buf_len))
436175
+			return false;
436175
+		tmp_buf_len -= c;
436175
+		tmp_oui_buf += c;
436175
+	}
436175
+	c = snprintf(out_buf, rem_len, "%04x%s",
436175
+		     (unsigned int)strlen(tmp_out_buf),
436175
+		     tmp_out_buf);
436175
+	if ((c < 0) || (c >= rem_len))
436175
+		return false;
436175
+	rem_len -= c;
436175
+	out_buf += c;
436175
+	*total += c;
436175
+	return true;
436175
+}
436175
+
436175
+/*
436175
+ * This function converts the OUI information from vsi22 struct to vdpnl struct
436175
+ * vsi is not used here, but can be used for storing the pointer to the parent
436175
+ * struct
436175
+ */
436175
+
436175
+bool cisco_vsi2vdpnl_hndlr(UNUSED void *vsi_data, struct vdp22_oui_data_s *from,
436175
+			   struct vdpnl_oui_data_s *to)
436175
+{
436175
+	if ((from == NULL) || (to == NULL)) {
436175
+		LLDPAD_ERR("%s: NULL arg\n", __func__);
436175
+		return false;
436175
+	}
436175
+	memcpy(to->oui_type, from->oui_type, sizeof(to->oui_type));
436175
+	strncpy(to->oui_name, from->oui_name, sizeof(to->oui_name));
436175
+	to->len = from->len;
436175
+	memcpy(to->data, from->data, to->len);
436175
+	return true;
436175
+}
436175
+
436175
+
436175
+/*
436175
  * This function deletes the OUI information associated with a VSI
436175
  */
436175
 
436175
diff --git a/vdptool_cisco_oui.c b/vdptool_cisco_oui.c
436175
index 4a846ad..7003521 100644
436175
--- a/vdptool_cisco_oui.c
436175
+++ b/vdptool_cisco_oui.c
436175
@@ -25,6 +25,7 @@
436175
 #include <stdio.h>
436175
 #include <stdlib.h>
436175
 #include <string.h>
436175
+#include "lldp_util.h"
436175
 #include "vdp_cisco.h"
436175
 
436175
 bool cisco_oui_encode_hndlr(char *dst, char *src, int len)
436175
@@ -56,3 +57,56 @@ bool cisco_oui_encode_hndlr(char *dst, char *src, int len)
436175
 	return flag;
436175
 }
436175
 
436175
+void cisco_oui_print_decode_hndlr(char *token)
436175
+{
436175
+	struct in_addr vm_inet;
436175
+	char *v4_addr_str;
436175
+	unsigned long vm_ip_addr;
436175
+	int offset = 0, len;
436175
+	u16 data_len;
436175
+	u8 key_len;
436175
+	enum oui_key_arg oui_argtype;
436175
+
436175
+	if (token == NULL)
436175
+		return;
436175
+	len = strlen(token);
436175
+	while (offset < len) {
436175
+		hexstr2bin(token, &key_len, sizeof(key_len));
436175
+		token += 2;
436175
+		offset += 2;
436175
+		oui_argtype = get_oui_key(token, key_len);
436175
+		token += key_len;
436175
+		offset += key_len;
436175
+		hexstr2bin(token, (u8 *)&data_len, sizeof(data_len));
436175
+		data_len = htons(data_len);
436175
+		token += 4;
436175
+		offset += 4;
436175
+		if ((offset + data_len) > len)
436175
+			return;
436175
+		switch (oui_argtype) {
436175
+		case CISCO_OUI_NAME_ARG:
436175
+			printf("\t%s", "VM Name");
436175
+			printf(" = %.*s\n", data_len, token);
436175
+			break;
436175
+		case CISCO_OUI_NAME_UUID_ARG:
436175
+			printf("\t%s", "VM UUID");
436175
+			printf(" = %.*s\n", data_len, token);
436175
+			break;
436175
+		case CISCO_OUI_L3V4ADDR_ARG:
436175
+			v4_addr_str = calloc(data_len, sizeof(char));
436175
+			if (!v4_addr_str)
436175
+				return;
436175
+			strncpy(v4_addr_str, token, data_len);
436175
+			vm_ip_addr = strtoul(v4_addr_str, NULL, 10);
436175
+			vm_inet.s_addr = vm_ip_addr;
436175
+			printf("\t%s", "VM IP Address");
436175
+			printf(" = %s\n", inet_ntoa(vm_inet));
436175
+			free(v4_addr_str);
436175
+			break;
436175
+		default:
436175
+			break;
436175
+		}
436175
+		token += data_len;
436175
+		offset += data_len;
436175
+	}
436175
+}
436175
-- 
436175
2.1.0
436175