]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - src/lldpd-structs.c
debian: no need to BD on lsb-release anymore
[thirdparty/lldpd.git] / src / lldpd-structs.c
index 094325d7e9806c85cd0c07b584a40510e9df0217..95cef9f11a1169f6310e7fc1f9cba7fdfd9beb11 100644 (file)
@@ -103,6 +103,56 @@ lldpd_pi_cleanup(struct lldpd_port *port)
 }
 #endif
 
+#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.
@@ -124,9 +174,8 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware,
                port_next = TAILQ_NEXT(port, p_entries);
                del = all;
                if (!all && expire &&
-                   (now >= port->p_lastupdate + port->p_chassis->c_ttl)) {
-                       hardware->h_ageout_cnt++;
-                       hardware->h_delete_cnt++;
+                   (now >= port->p_lastupdate + port->p_ttl)) {
+                       if (port->p_ttl > 0) hardware->h_ageout_cnt++;
                        del = 1;
                }
                if (del) {
@@ -136,6 +185,10 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware,
                         * 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);
                }
@@ -161,16 +214,19 @@ lldpd_port_cleanup(struct lldpd_port *port, int all)
 #endif
        /* will set these to NULL so we don't free wrong memory */
 
-       free(port->p_id);
-       port->p_id = NULL;
-       free(port->p_descr);
-       port->p_descr = NULL;
        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
        }
 }
 
@@ -180,7 +236,9 @@ lldpd_config_cleanup(struct lldpd_config *config)
        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);