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

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