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

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