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

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