struct lldpd_mgmt *mgmt, *mgmt_next;
log_debug("alloc", "cleanup management addresses for chassis %s",
- chassis->c_name ? chassis->c_name : "(unknwon)");
+ chassis->c_name ? chassis->c_name : "(unknown)");
for (mgmt = TAILQ_FIRST(&chassis->c_mgmt);
mgmt != NULL;
{
lldpd_chassis_mgmt_cleanup(chassis);
log_debug("alloc", "cleanup chassis %s",
- chassis->c_name ? chassis->c_name : "(unknwon)");
+ chassis->c_name ? chassis->c_name : "(unknown)");
#ifdef ENABLE_LLDPMED
free(chassis->c_med_hw);
free(chassis->c_med_sw);
}
#endif
-/* Cleanup a remote port. The last argument, `expire` is a function that should
- * be called when expiration happens. If it is NULL, all remote ports are
- * removed. */
+#ifdef ENABLE_CUSTOM
+void
+lldpd_custom_tlv_add(struct lldpd_port *port, struct lldpd_custom *curr)
+{
+ struct lldpd_custom *custom;
+
+ if ((custom = malloc(sizeof(struct lldpd_custom)))) {
+ memcpy(custom, curr, sizeof(struct lldpd_custom));
+ if ((custom->oui_info = malloc(custom->oui_info_len))) {
+ memcpy(custom->oui_info, curr->oui_info, custom->oui_info_len);
+ TAILQ_INSERT_TAIL(&port->p_custom_list, custom, next);
+ } else {
+ free(custom);
+ log_warn("rpc", "could not allocate memory for custom TLV info");
+ }
+ }
+}
+
+void
+lldpd_custom_tlv_cleanup(struct lldpd_port *port, struct lldpd_custom *curr)
+{
+ struct lldpd_custom *custom, *custom_next;
+ for (custom = TAILQ_FIRST(&port->p_custom_list);
+ custom != NULL;
+ custom = custom_next) {
+ custom_next = TAILQ_NEXT(custom, next);
+ if (!memcmp(curr->oui, custom->oui, sizeof(curr->oui)) &&
+ curr->subtype == custom->subtype) {
+ TAILQ_REMOVE(&port->p_custom_list, custom, next);
+ free(custom->oui_info);
+ free(custom);
+ }
+ }
+}
+
+void
+lldpd_custom_list_cleanup(struct lldpd_port *port)
+{
+ struct lldpd_custom *custom, *custom_next;
+ for (custom = TAILQ_FIRST(&port->p_custom_list);
+ custom != NULL;
+ custom = custom_next) {
+ custom_next = TAILQ_NEXT(custom, next);
+ free(custom->oui_info);
+ free(custom);
+ }
+ TAILQ_INIT(&port->p_custom_list);
+}
+#endif
+
+/* Cleanup a remote port. The before last argument, `expire` is a function that
+ * should be called when a remote port is removed. If the last argument is 1,
+ * all remote ports are removed.
+ */
void
lldpd_remote_cleanup(struct lldpd_hardware *hardware,
- void(*expire)(struct lldpd_hardware *, struct lldpd_port *))
+ void(*expire)(struct lldpd_hardware *, struct lldpd_port *),
+ int all)
{
struct lldpd_port *port, *port_next;
int del;
port != NULL;
port = port_next) {
port_next = TAILQ_NEXT(port, p_entries);
- del = (expire == NULL);
- if (expire &&
- (now - port->p_lastupdate >= port->p_chassis->c_ttl)) {
- hardware->h_ageout_cnt++;
- hardware->h_delete_cnt++;
- expire(hardware, port);
+ del = all;
+ if (!all && expire &&
+ (now >= port->p_lastupdate + port->p_ttl)) {
+ if (port->p_ttl > 0) hardware->h_ageout_cnt++;
del = 1;
}
if (del) {
- if (expire)
- TAILQ_REMOVE(&hardware->h_rports, port, p_entries);
+ if (expire) expire(hardware, port);
+ /* This TAILQ_REMOVE is dangerous. It should not be
+ * called while in liblldpctl because we don't have a
+ * real list. It is only needed to be called when we
+ * don't delete the entire list. */
+ if (!all) TAILQ_REMOVE(&hardware->h_rports, port, p_entries);
+
+ hardware->h_delete_cnt++;
+ /* Register last removal to be able to report lldpStatsRemTablesLastChangeTime */
+ hardware->h_lport.p_lastremove = time(NULL);
lldpd_port_cleanup(port, 1);
free(port);
}
}
- if (!expire) TAILQ_INIT(&hardware->h_rports);
+ if (all) TAILQ_INIT(&hardware->h_rports);
}
/* If `all' is true, clear all information, including information that
lldpd_ppvid_cleanup(port);
lldpd_pi_cleanup(port);
#endif
- free(port->p_id);
- free(port->p_descr);
+ /* will set these to NULL so we don't free wrong memory */
+
if (all) {
+ free(port->p_id);
+ port->p_id = NULL;
+ free(port->p_descr);
+ port->p_descr = NULL;
free(port->p_lastframe);
if (port->p_chassis) { /* chassis may not have been attributed, yet */
port->p_chassis->c_refcount--;
port->p_chassis = NULL;
}
+#ifdef ENABLE_CUSTOM
+ lldpd_custom_list_cleanup(port);
+#endif
}
}
log_debug("alloc", "general configuration cleanup");
free(config->c_mgmt_pattern);
free(config->c_cid_pattern);
+ free(config->c_cid_string);
free(config->c_iface_pattern);
+ free(config->c_perm_ifaces);
+ free(config->c_hostname);
free(config->c_platform);
free(config->c_description);
}