Blame SOURCES/open-lldp-v1.0.1-22-vdp-Fixed-the-memory-leak-for-modify-VSI-support-for.patch

89f6b3
From 73e0c42cc00f537fee1f58e5475cab1f2193e3cc Mon Sep 17 00:00:00 2001
89f6b3
From: padkrish <padkrish@cisco.com>
89f6b3
Date: Fri, 10 Apr 2015 09:03:24 +0000
89f6b3
Subject: [PATCH] vdp: Fixed the memory leak for modify VSI, support for OUI
89f6b3
 modify
89f6b3
89f6b3
This patch has a fix for freeing the memory after a VSI update.
89f6b3
Support for modifying the OUI parameters have been added
89f6b3
to the infra.
89f6b3
Cisco specific handler is also added to support OUI modify.
89f6b3
89f6b3
Signed-off-by: padkrish <padkrish@cisco.com>
89f6b3
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
89f6b3
---
89f6b3
 include/qbg_vdp22.h     |  2 +-
89f6b3
 include/qbg_vdp22_oui.h |  3 +++
89f6b3
 include/vdp_cisco.h     |  2 ++
89f6b3
 qbg/vdp22.c             |  5 +++--
89f6b3
 qbg/vdp22cisco_oui.c    | 44 +++++++++++++++++++++++++++++++++++++++++---
89f6b3
 qbg/vdp22sm.c           | 35 ++++++++++++++++++++++++++++++++---
89f6b3
 6 files changed, 82 insertions(+), 9 deletions(-)
89f6b3
89f6b3
diff --git a/include/qbg_vdp22.h b/include/qbg_vdp22.h
89f6b3
index 6585a10..b1896a5 100644
89f6b3
--- a/include/qbg_vdp22.h
89f6b3
+++ b/include/qbg_vdp22.h
89f6b3
@@ -181,7 +181,7 @@ void vdp22_stop(char *);
89f6b3
 int vdp22_from_ecp22(struct vdp22 *);
89f6b3
 int vdp22_query(const char *);
89f6b3
 struct vdp22 *vdp22_getvdp(const char *);
89f6b3
-int vdp22_addreq(struct vsi22 *, struct vdp22 *);
89f6b3
+int vdp22_addreq(struct vsi22 *, struct vdp22 *, bool *);
89f6b3
 int vdp22_nlback(struct vsi22 *);
89f6b3
 int vdp22_clntback(struct vsi22 *);
89f6b3
 struct vsi22 *vdp22_copy_vsi(struct vsi22 *);
89f6b3
diff --git a/include/qbg_vdp22_oui.h b/include/qbg_vdp22_oui.h
89f6b3
index 923e19f..d60075d 100644
89f6b3
--- a/include/qbg_vdp22_oui.h
89f6b3
+++ b/include/qbg_vdp22_oui.h
89f6b3
@@ -82,6 +82,9 @@ struct vdp22_oui_handler_s {
89f6b3
 	/* This handler converts the vdpnl structure to vsi22 structure */
89f6b3
 	bool (*vdpnl2vsi22_hndlr)(void *, struct vdpnl_oui_data_s *,
89f6b3
 				   struct vdp22_oui_data_s *);
89f6b3
+	/* This handler modifies the existing OUI parameters */
89f6b3
+	bool (*vsi22_mod_hndlr)(void *, struct vdp22_oui_data_s *,
89f6b3
+				struct vdp22_oui_data_s *);
89f6b3
 	/* This handler converts the vdpnl structure to string */
89f6b3
 	bool (*vdpnl2str_hndlr)(struct vdpnl_oui_data_s *, char *,
89f6b3
 				int *, int);
89f6b3
diff --git a/include/vdp_cisco.h b/include/vdp_cisco.h
89f6b3
index 821db68..4abe802 100644
89f6b3
--- a/include/vdp_cisco.h
89f6b3
+++ b/include/vdp_cisco.h
89f6b3
@@ -113,6 +113,8 @@ 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_vsi22_mod_hndlr(void *, struct vdp22_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
diff --git a/qbg/vdp22.c b/qbg/vdp22.c
89f6b3
index 10b80a4..8f14fdd 100644
89f6b3
--- a/qbg/vdp22.c
89f6b3
+++ b/qbg/vdp22.c
89f6b3
@@ -900,6 +900,7 @@ int vdp22_request(struct vdpnl_vsi *vsi, int clif)
89f6b3
 	int rc;
89f6b3
 	struct vsi22 *p;
89f6b3
 	struct vdp22 *vdp;
89f6b3
+	bool modf_vsi = false;
89f6b3
 
89f6b3
 	LLDPAD_DBG("%s:%s clif:%d\n", __func__, vsi->ifname, clif);
89f6b3
 	vdp = vdp22_findif(vsi->ifname, NULL);
89f6b3
@@ -917,8 +918,8 @@ int vdp22_request(struct vdpnl_vsi *vsi, int clif)
89f6b3
 			vsi->request += 1;
89f6b3
 		p = vdp22_alloc_vsi_int(vsi, vdp, &rc, true);
89f6b3
 		if (p) {
89f6b3
-			rc = vdp22_addreq(p, vdp);
89f6b3
-			if (rc)
89f6b3
+			rc = vdp22_addreq(p, vdp, &modf_vsi);
89f6b3
+			if (rc || modf_vsi)
89f6b3
 				vdp22_delete_vsi(p);
89f6b3
 		}
89f6b3
 	} else
89f6b3
diff --git a/qbg/vdp22cisco_oui.c b/qbg/vdp22cisco_oui.c
89f6b3
index 272d480..da6ce24 100644
89f6b3
--- a/qbg/vdp22cisco_oui.c
89f6b3
+++ b/qbg/vdp22cisco_oui.c
89f6b3
@@ -34,8 +34,9 @@
89f6b3
 
89f6b3
 struct vdp22_oui_handler_s cisco_oui_hndlr = {
89f6b3
 		{0x00, 0x00, 0x0c}, "cisco", cisco_str2vdpnl_hndlr,
89f6b3
-		cisco_vdpnl2vsi22_hndlr, cisco_vdpnl2str_hndlr,
89f6b3
-		cisco_vsi2vdpnl_hndlr, cisco_vdp_tx_hndlr, cisco_vdp_rx_hndlr,
89f6b3
+		cisco_vdpnl2vsi22_hndlr, cisco_vsi22_mod_hndlr,
89f6b3
+		cisco_vdpnl2str_hndlr, cisco_vsi2vdpnl_hndlr,
89f6b3
+		cisco_vdp_tx_hndlr, cisco_vdp_rx_hndlr,
89f6b3
 		cisco_vdp_free_oui, cisco_vdp_oui_ptlvsize};
89f6b3
 
89f6b3
 /*
89f6b3
@@ -104,9 +105,11 @@ bool cisco_str2vdpnl_hndlr(struct vdpnl_oui_data_s *vdp_oui_p, char *token)
89f6b3
 			}
89f6b3
 			strncpy(uuid, token, data_len);
89f6b3
 			if (oui_vdp_str2uuid(vdp_cisco_oui_p->uuid, uuid,
89f6b3
-					     sizeof(vdp_cisco_oui_p->uuid)))
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 = false;
89f6b3
+			} else
89f6b3
 				vdp_cisco_oui_p->uuid_set = true;
89f6b3
 			free(uuid);
89f6b3
 			break;
89f6b3
@@ -177,6 +180,41 @@ bool cisco_vdpnl2vsi22_hndlr(void *vsi_data, struct vdpnl_oui_data_s *from,
89f6b3
 }
89f6b3
 
89f6b3
 /*
89f6b3
+ * This converts modifies the existing OUI parameters
89f6b3
+ */
89f6b3
+
89f6b3
+bool cisco_vsi22_mod_hndlr(UNUSED void *vsi_data, struct vdp22_oui_data_s *from,
89f6b3
+			   struct vdp22_oui_data_s *to)
89f6b3
+{
89f6b3
+	vdp_cisco_oui_t *from_oui;
89f6b3
+	vdp_cisco_oui_t *to_oui;
89f6b3
+
89f6b3
+	from_oui = (vdp_cisco_oui_t *)from->data;
89f6b3
+	to_oui = (vdp_cisco_oui_t *)to->data;
89f6b3
+	if ((!from_oui) || (!to_oui)) {
89f6b3
+		LLDPAD_DBG("%s: NULL OUI data\n", __func__);
89f6b3
+		return false;
89f6b3
+	}
89f6b3
+	if (from_oui->vm_name_len != 0) {
89f6b3
+		to_oui->vm_name_len = from_oui->vm_name_len;
89f6b3
+		strncpy(to_oui->vm_name, from_oui->vm_name,
89f6b3
+			to_oui->vm_name_len);
89f6b3
+	}
89f6b3
+	/* UUID can be modified only if not set */
89f6b3
+	if (!to_oui->uuid_set) {
89f6b3
+		memcpy(to_oui->uuid, from_oui->uuid, sizeof(to_oui->uuid));
89f6b3
+		to_oui->uuid_set = true;
89f6b3
+	}
89f6b3
+	if (from_oui->vm_addr_len != 0) {
89f6b3
+		to_oui->vm_addr_len = from_oui->vm_addr_len;
89f6b3
+		to_oui->afi = from_oui->afi;
89f6b3
+		memcpy(&(to_oui->l3_addr), &(from_oui->l3_addr),
89f6b3
+			sizeof(to_oui->l3_addr));
89f6b3
+	}
89f6b3
+	return true;
89f6b3
+}
89f6b3
+
89f6b3
+/*
89f6b3
  * This function converts the OUI information from vdpnl struct to string
89f6b3
  */
89f6b3
 
89f6b3
diff --git a/qbg/vdp22sm.c b/qbg/vdp22sm.c
89f6b3
index 14356ac..be838a9 100644
89f6b3
--- a/qbg/vdp22sm.c
89f6b3
+++ b/qbg/vdp22sm.c
89f6b3
@@ -184,10 +184,36 @@ static inline size_t vsi22_ptlv_sz(struct vsi22 *vp)
89f6b3
 }
89f6b3
 
89f6b3
 /*
89f6b3
+ * This function modifies the existing OUI parameters in a VSI.
89f6b3
+ */
89f6b3
+static void vdp22_modoui(struct vsi22 *p, struct vsi22 *vsip)
89f6b3
+{
89f6b3
+	struct vdp22_oui_handler_s *oui_hndlr;
89f6b3
+	int idx, inn_idx, ret;
89f6b3
+
89f6b3
+	for (idx = 0; idx < vsip->no_ouidata; idx++) {
89f6b3
+		struct vdp22_oui_data_s *from = &vsip->oui_str_data[idx];
89f6b3
+
89f6b3
+		for (inn_idx = 0; inn_idx < p->no_ouidata; inn_idx++) {
89f6b3
+			struct vdp22_oui_data_s *to = &p->oui_str_data[inn_idx];
89f6b3
+
89f6b3
+			if (!strncmp(to->oui_name, from->oui_name,
89f6b3
+				     sizeof(to->oui_name))) {
89f6b3
+				oui_hndlr = vdp22_get_oui_hndlr(to->oui_name);
89f6b3
+				ret = oui_hndlr->vsi22_mod_hndlr(p, from, to);
89f6b3
+				if (!ret)
89f6b3
+					LLDPAD_ERR("%s: handler return error for oui %s\n",
89f6b3
+						   __func__, from->oui_name);
89f6b3
+				return;
89f6b3
+			}
89f6b3
+		}
89f6b3
+	}
89f6b3
+}
89f6b3
+
89f6b3
+/*
89f6b3
  * This function calls the registered OUI handlers that returns the size of
89f6b3
  * the OUI data.
89f6b3
  */
89f6b3
-
89f6b3
 static inline size_t oui22_ptlv_sz(struct vsi22 *vp)
89f6b3
 {
89f6b3
 	struct vdp22_oui_handler_s *oui_hndlr;
89f6b3
@@ -1054,7 +1080,7 @@ bool vdp22_cmp_fdata(struct vsi22 *p, struct vsi22 *vsip)
89f6b3
 /*
89f6b3
  * Handle a new request.
89f6b3
  */
89f6b3
-int vdp22_addreq(struct vsi22 *vsip, struct vdp22 *vdp)
89f6b3
+int vdp22_addreq(struct vsi22 *vsip, struct vdp22 *vdp, bool *modf_vsi)
89f6b3
 {
89f6b3
 	int rc = 0;
89f6b3
 	struct vsi22 *p;
89f6b3
@@ -1094,8 +1120,11 @@ int vdp22_addreq(struct vsi22 *vsip, struct vdp22 *vdp)
89f6b3
 			LLDPAD_DBG("%s:%s TODO mismatch filter data [%02x]\n",
89f6b3
 				   __func__, vsip->vdp->ifname, vsip->vsi[0]);
89f6b3
 			rc = -EINVAL;
89f6b3
-		} else
89f6b3
+		} else {
89f6b3
+			vdp22_modoui(p, vsip);
89f6b3
 			rc = vdp22_modvsi(p, vsip->vsi_mode);
89f6b3
+			*modf_vsi = true;
89f6b3
+		}
89f6b3
 	}
89f6b3
 out:
89f6b3
 	LLDPAD_DBG("%s:%s rc:%d\n", __func__, vsip->vdp->ifname, rc);
89f6b3
-- 
89f6b3
2.1.0
89f6b3