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

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