From: Vincent Bernat Date: Tue, 13 Aug 2013 19:33:29 +0000 (+0200) Subject: lldpd: make notifications work when a port goes down X-Git-Tag: 0.7.7~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef3707dacfd94a260b43b4e85930a04606166bf7;p=thirdparty%2Flldpd.git lldpd: make notifications work when a port goes down We need to refactor a bit `lldpd_remote_cleanup()` to separate the expiration process (checking each remote port to check if it is still current) and the removal of remote port (which triggers the expire function because we want to be notified when a neighbor disappear this way). --- diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c index 9448290a..5a111022 100644 --- a/src/daemon/lldpd.c +++ b/src/daemon/lldpd.c @@ -335,10 +335,10 @@ lldpd_cleanup(struct lldpd *cfg) hardware_next = TAILQ_NEXT(hardware, h_entries); if (!hardware->h_flags) { TAILQ_REMOVE(&cfg->g_hardware, hardware, h_entries); - lldpd_remote_cleanup(hardware, NULL); + lldpd_remote_cleanup(hardware, notify_clients_deletion, 1); lldpd_hardware_cleanup(cfg, hardware); } else - lldpd_remote_cleanup(hardware, notify_clients_deletion); + lldpd_remote_cleanup(hardware, notify_clients_deletion, 0); } log_debug("localchassis", "cleanup all chassis"); @@ -1061,7 +1061,7 @@ lldpd_exit(struct lldpd *cfg) hardware = hardware_next) { hardware_next = TAILQ_NEXT(hardware, h_entries); log_debug("main", "cleanup interface %s", hardware->h_ifname); - lldpd_remote_cleanup(hardware, NULL); + lldpd_remote_cleanup(hardware, NULL, 1); lldpd_hardware_cleanup(cfg, hardware); } } diff --git a/src/lib/atom-private.c b/src/lib/atom-private.c index de2c7e67..752b8078 100644 --- a/src/lib/atom-private.c +++ b/src/lib/atom-private.c @@ -693,7 +693,7 @@ _lldpctl_atom_free_port(lldpctl_atom_t *atom) add_chassis(&chassis_list, one_port->p_chassis); /* Free hardware port */ - lldpd_remote_cleanup(hardware, NULL); + lldpd_remote_cleanup(hardware, NULL, 1); lldpd_port_cleanup(port->port, 1); free(port->hardware); diff --git a/src/lldpd-structs.c b/src/lldpd-structs.c index a14fe5da..58577f3d 100644 --- a/src/lldpd-structs.c +++ b/src/lldpd-structs.c @@ -103,12 +103,14 @@ lldpd_pi_cleanup(struct lldpd_port *port) } #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. */ +/* 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; @@ -120,22 +122,21 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware, port != NULL; port = port_next) { port_next = TAILQ_NEXT(port, p_entries); - del = (expire == NULL); + del = all; if (expire && (now - port->p_lastupdate >= port->p_chassis->c_ttl)) { hardware->h_ageout_cnt++; hardware->h_delete_cnt++; - expire(hardware, port); del = 1; } if (del) { - if (expire) - TAILQ_REMOVE(&hardware->h_rports, port, p_entries); + expire(hardware, port); + TAILQ_REMOVE(&hardware->h_rports, port, p_entries); 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 diff --git a/src/lldpd-structs.h b/src/lldpd-structs.h index 848fd667..ca34ae26 100644 --- a/src/lldpd-structs.h +++ b/src/lldpd-structs.h @@ -440,7 +440,8 @@ MARSHAL_END(lldpd_neighbor_change); void lldpd_chassis_mgmt_cleanup(struct lldpd_chassis *); void lldpd_chassis_cleanup(struct lldpd_chassis *, int); void lldpd_remote_cleanup(struct lldpd_hardware *, - void(*expire)(struct lldpd_hardware *, struct lldpd_port *)); + void(*expire)(struct lldpd_hardware *, struct lldpd_port *), + int); void lldpd_port_cleanup(struct lldpd_port *, int); void lldpd_config_cleanup(struct lldpd_config *); #ifdef ENABLE_DOT1