]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldp: send a shutdown LLDPDU on exit
authorVincent Bernat <vincent@bernat.im>
Sun, 4 Jan 2015 17:24:29 +0000 (18:24 +0100)
committerVincent Bernat <vincent@bernat.im>
Sun, 4 Jan 2015 17:24:29 +0000 (18:24 +0100)
With the previous commit, it is now easy to send a shutdown LLPDU when
exiting lldpd. Let's do that.

src/daemon/lldp.c
src/daemon/lldpd.c
src/daemon/lldpd.h

index 0e6220e22f609de1e711cf26995ece2af5fa383d..5b0e4771feb1d499f892e7f9c87ca7be7f7df8cb 100644 (file)
@@ -469,12 +469,14 @@ toobig:
        return E2BIG;
 }
 
-/* Send a shutdown LLDPDU. Should be called only if we have a previously sent
- * LLDPDU. */
-static int
+/* Send a shutdown LLDPDU. */
+int
 lldp_send_shutdown(struct lldpd *global,
     struct lldpd_hardware *hardware)
 {
+       if (hardware->h_lchassis_previous_id == NULL ||
+           hardware->h_lport_previous_id == NULL)
+               return 0;
        return _lldp_send(global, hardware,
            hardware->h_lchassis_previous_id_subtype,
            hardware->h_lchassis_previous_id,
index 8e97fe86b204dd78badd3f63a1865e71d90b3b36..153514bed4bc155d3347fdf14fa47b62d5738351 100644 (file)
@@ -906,6 +906,21 @@ lldpd_recv(struct lldpd *cfg, struct lldpd_hardware *hardware, int fd)
        free(buffer);
 }
 
+static void
+lldpd_send_shutdown(struct lldpd_hardware *hardware)
+{
+       struct lldpd *cfg = hardware->h_cfg;
+       if (cfg->g_config.c_receiveonly || cfg->g_config.c_paused) return;
+       if ((hardware->h_flags & IFF_RUNNING) == 0)
+               return;
+
+       /* It's safe to call `lldp_send_shutdown()` because shutdown LLDPU will
+        * only be emitted if LLDP was sent on that port. */
+       if (lldp_send_shutdown(hardware->h_cfg, hardware) != 0)
+               log_warnx("send", "unable to send shutdown LLDPDU on %s",
+                   hardware->h_ifname);
+}
+
 void
 lldpd_send(struct lldpd_hardware *hardware)
 {
@@ -1120,6 +1135,10 @@ lldpd_exit(struct lldpd *cfg)
 {
        struct lldpd_hardware *hardware, *hardware_next;
        log_debug("main", "exit lldpd");
+
+       TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries)
+               lldpd_send_shutdown(hardware);
+
        close(cfg->g_ctl);
        priv_ctl_cleanup(cfg->g_ctlname);
        log_debug("main", "cleanup hardware information");
index f581067629341d53f3807db4e3830bcccb3f3e04..9f986f3171e3eb210725702c04cc9b26c097f867 100644 (file)
@@ -160,6 +160,7 @@ void         levent_schedule_cleanup(struct lldpd *);
 int     levent_make_socket_nonblocking(int);
 
 /* lldp.c */
+int     lldp_send_shutdown(PROTO_SEND_SIG);
 int     lldp_send(PROTO_SEND_SIG);
 int     lldp_decode(PROTO_DECODE_SIG);