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

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