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

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