[lldp-devel] [PATCH] lldpad: Stop port list damage in remove_port

Mark Rustad mark.d.rustad at intel.com
Thu Mar 21 20:17:26 UTC 2013


Commit 384ba242 changed this function to use the standard
port_find_by_name function, which would be good, except
that it missed the setting of the parent pointer, which
is used to remove the port. Consequently, remove_port
calls were damaging the port list. Fix that by restoring
the custom loop.

Signed-off-by: Mark Rustad <mark.d.rustad at intel.com>
Tested-by: Jack Morgan <jack.morgan at intel.com>
---

 lldp/ports.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lldp/ports.c b/lldp/ports.c
index fa95389..0652ce8 100644
--- a/lldp/ports.c
+++ b/lldp/ports.c
@@ -328,18 +328,24 @@ fail:
 
 int remove_port(char *ifname)
 {
-	struct port *port = NULL;    /* Pointer to port to remove */
+	struct port *port;    /* Pointer to port to remove */
 	struct port *parent = NULL;  /* Pointer to previous on port stack */
-	struct lldp_agent *agent = NULL;
-
-	port = port_find_by_name(ifname);
+	struct lldp_agent *agent;
 
-	if (port == NULL) {
-		LLDPAD_DBG("remove_port: port not present\n");
+	for (port = porthead; port; port = port->next) {
+		if (!strncmp(ifname, port->ifname, IFNAMSIZ)) {
+			LLDPAD_DBG("In %s: Found port %s\n", __func__,
+				   port->ifname);
+			break;
+		}
+		parent = port;
+	}
+	if (!port) {
+		LLDPAD_DBG("%s: port not present\n", __func__);
 		return -1;
 	}
 
-	LLDPAD_DBG("In remove_port: Found port %s\n", port->ifname);
+	LLDPAD_DBG("In %s: Found port %s\n", __func__, port->ifname);
 
 	/* Set linkmode to off */
 	set_linkmode(ifname, 0);
@@ -378,7 +384,6 @@ int remove_port(char *ifname)
 
 		LIST_REMOVE(agent, entry);
 		free(agent);
-
 	}
 
 	/* Take this port out of the chain */



More information about the lldp-devel mailing list