1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2015 Nicira, Inc.
4 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "lldpd-structs.h"
26 VLOG_DEFINE_THIS_MODULE(lldpd_structs);
29 lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *chassis)
31 struct lldpd_mgmt *mgmt;
33 VLOG_DBG("cleanup management addresses for chassis %s",
34 chassis->c_name ? chassis->c_name : "(unknown)");
36 LIST_FOR_EACH_POP (mgmt, m_entries, &chassis->c_mgmt) {
40 list_init(&chassis->c_mgmt);
44 lldpd_chassis_cleanup(struct lldpd_chassis *chassis, bool all)
46 lldpd_chassis_mgmt_cleanup(chassis);
47 VLOG_DBG("cleanup chassis %s",
48 chassis->c_name ? chassis->c_name : "(unknown)");
50 free(chassis->c_name);
51 free(chassis->c_descr);
57 /* Cleanup a remote port. The before last argument, `expire` is a function that
58 * should be called when a remote port is removed. If the last argument is
59 * true, all remote ports are removed.
62 lldpd_remote_cleanup(struct lldpd_hardware *hw,
63 void(*expire)(struct lldpd_hardware *,
67 struct lldpd_port *port, *port_next;
68 time_t now = time_now();
70 VLOG_DBG("cleanup remote port on %s", hw->h_ifname);
71 LIST_FOR_EACH_SAFE (port, port_next, p_entries, &hw->h_rports) {
74 (now >= port->p_lastupdate + port->p_chassis->c_ttl)) {
85 list_remove(&port->p_entries);
87 lldpd_port_cleanup(port, true);
92 list_init(&hw->h_rports);
96 /* Cleanup the auto-attach mappings attached to port.
99 lldpd_aa_maps_cleanup(struct lldpd_port *port)
101 struct lldpd_aa_isid_vlan_maps_tlv *isid_vlan_map = NULL;
102 struct lldpd_aa_isid_vlan_maps_tlv *isid_vlan_map_next = NULL;
104 if (!list_is_empty(&port->p_isid_vlan_maps)) {
106 LIST_FOR_EACH_SAFE (isid_vlan_map, isid_vlan_map_next, m_entries,
107 &port->p_isid_vlan_maps) {
109 list_remove(&isid_vlan_map->m_entries);
113 list_init(&port->p_isid_vlan_maps);
117 /* If `all' is true, clear all information, including information that
118 are not refreshed periodically. Port should be freed manually. */
120 lldpd_port_cleanup(struct lldpd_port *port, bool all)
122 /* We set these to NULL so we don't free wrong memory */
126 port->p_descr = NULL;
128 /* Cleanup auto-attach mappings */
129 lldpd_aa_maps_cleanup(port);
132 free(port->p_lastframe);
133 /* Chassis may not have been attributed, yet.*/
134 if (port->p_chassis) {
135 port->p_chassis->c_refcount--;
136 port->p_chassis = NULL;
142 lldpd_config_cleanup(struct lldpd_config *config)
144 VLOG_DBG("general configuration cleanup");
145 free(config->c_mgmt_pattern);
146 free(config->c_cid_pattern);
147 free(config->c_iface_pattern);
148 free(config->c_platform);
149 free(config->c_description);