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

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