]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: make notifications work when a port goes down
authorVincent Bernat <bernat@luffy.cx>
Tue, 13 Aug 2013 19:33:29 +0000 (21:33 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 13 Aug 2013 19:33:29 +0000 (21:33 +0200)
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).

src/daemon/lldpd.c
src/lib/atom-private.c
src/lldpd-structs.c
src/lldpd-structs.h

index 9448290a7455a1866734c1bea1e1274042a9204e..5a11102265ad609ecb128432110b0efe7c652fbe 100644 (file)
@@ -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);
        }
 }
index de2c7e6799ed56025a7d110aa04c5785d78c6db8..752b807883dd6bfc27fabba51d7d4d0862a9ff41 100644 (file)
@@ -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);
 
index a14fe5da3e6d72214933901c5d8dca4037bc8139..58577f3d7142a650e5dea15de47f20ec52f2a73d 100644 (file)
@@ -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
index 848fd667fad56e866c2597f60d1efcbce79deaaf..ca34ae26cd49a508c968e660f15aa7736e5b90da 100644 (file)
@@ -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