]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Allow to force a protocol.
authorVincent Bernat <bernat@luffy.cx>
Fri, 12 Mar 2010 13:47:05 +0000 (14:47 +0100)
committerVincent Bernat <bernat@luffy.cx>
Wed, 17 Mar 2010 12:49:37 +0000 (13:49 +0100)
This fixes ticket #34. By using the option to enable a protocol twice,
we are able to speak a protocol even when no peer is detected. In this
case, packets are sent even when another protocol is detected. A new
parameter has been added to get this behaviour for LLDP as well.

CHANGELOG
man/lldpd.8
src/lldpd.c

index 4d7d0f42485463507bde6628d8cb865412de3367..4e860e58c9cd84b79593c5fbba18b1047f1c1478 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,6 +11,8 @@ lldpd (0.5.0)
     + Add "-k" switch to avoid to emit too much information on running
       kernel.
     + Support of ifAlias with kernel >= 2.6.28
+    + Allow to force a protocol even when no peer for this protocol is
+      detected.
     + Lot of portability stuff. lldpd can now be compiled on RHEL
       2.1. Still Linux-only though.
     + Add an option to specify AgentX socket (-X).
index b15ccaefc3042b110bed3ab8537bde166f9cdaa7..a4c5fc35371947238378c84e4086976db6f34026 100644 (file)
@@ -21,7 +21,7 @@
 .Nd LLDP daemon
 .Sh SYNOPSIS
 .Nm
-.Op Fl dvxcseik
+.Op Fl dvxcseikl
 .Op Fl X Ar socket
 .Op Fl m Ar management
 .Op Fl M Ar class
@@ -85,16 +85,25 @@ in a chroot, you need to specify an IP address (not a hostname) when
 using a TCP or UDP socket.
 .It Fl c
 Enable the support of CDP protocol to deal with Cisco routers that do
-not speak LLDP.
+not speak LLDP. If repeated, CDPv1 packets will be sent even when
+there is no CDP peer detected.
 .It Fl f
 Enable the support of FDP protocol to deal with Foundry routers that do
-not speak LLDP.
+not speak LLDP. If repeated, FDP packets will be sent even when there
+is no FDP peer detected.
 .It Fl s
 Enable the support of SONMP protocol to deal with Nortel routers and
-switches that do not speak LLDP.
+switches that do not speak LLDP. If repeated, SONMP packets will be
+sent even when there is no SONMP peer detected.
 .It Fl e
 Enable the support of EDP protocol to deal with Extreme routers and
-switches that do not speak LLDP.
+switches that do not speak LLDP. If repeated, EDP packets will be sent
+even when there is no EDP peer detected.
+.It Fl l
+Force to send LLDP packets even when there is no LLDP peer detected
+but there is a peer speaking another protocol detected. By default,
+LLDP packets are sent when there is a peer speaking LLDP detected or
+when there is no peer at all.
 .It Fl m Ar management
 Specify the management address of this system.
 .Nm
index 7d2722ea2627176cf1adaf9833cf38675a58b6e3..05a840eff1a8b9ef8e9706c6616b71f16314c9d3 100644 (file)
@@ -48,7 +48,7 @@ static void            usage(void);
 
 static struct protocol protos[] =
 {
-       { LLDPD_MODE_LLDP, 1, "LLDP", ' ', lldp_send, lldp_decode, NULL,
+       { LLDPD_MODE_LLDP, 1, "LLDP", 'l', lldp_send, lldp_decode, NULL,
          LLDP_MULTICAST_ADDR },
 #ifdef ENABLE_CDP
        { LLDPD_MODE_CDPV1, 0, "CDPv1", 'c', cdpv1_send, cdp_decode, cdpv1_guess,
@@ -624,13 +624,18 @@ lldpd_send_all(struct lldpd *cfg)
                        if (!cfg->g_protocols[i].enabled)
                                continue;
                        /* We send only if we have at least one remote system
-                        * speaking this protocol */
+                        * speaking this protocol or if the protocol is forced */
+                       if (cfg->g_protocols[i].enabled > 1) {
+                               cfg->g_protocols[i].send(cfg, hardware);
+                               sent++;
+                               continue;
+                       }
                        TAILQ_FOREACH(port, &hardware->h_rports, p_entries) {
                                if (port->p_protocol ==
                                    cfg->g_protocols[i].mode) {
                                        cfg->g_protocols[i].send(cfg,
                                            hardware);
-                                       sent = 1;
+                                       sent++;
                                        break;
                                }
                        }
@@ -835,10 +840,8 @@ lldpd_main(int argc, char *argv[])
         * Get and parse command line options
         */
        popt = strchr(opts, '@');
-       for (i=0; protos[i].mode != 0; i++) {
-               if (protos[i].enabled == 1) continue;
+       for (i=0; protos[i].mode != 0; i++)
                *(popt++) = protos[i].arg;
-       }
        *popt = '\0';
        while ((ch = getopt(argc, argv, opts)) != -1) {
                switch (ch) {
@@ -896,9 +899,13 @@ lldpd_main(int argc, char *argv[])
                default:
                        found = 0;
                        for (i=0; protos[i].mode != 0; i++) {
-                               if (protos[i].enabled) continue;
                                if (ch == protos[i].arg) {
-                                       protos[i].enabled = 1;
+                                       protos[i].enabled++;
+                                       /* When an argument enable
+                                          several protocols, only the
+                                          first one can be forced. */
+                                       if (found && protos[i].enabled > 1)
+                                               protos[i].enabled = 1;
                                        found = 1;
                                }
                        }
@@ -966,9 +973,11 @@ lldpd_main(int argc, char *argv[])
 
        cfg->g_protocols = protos;
        for (i=0; protos[i].mode != 0; i++)
-               if (protos[i].enabled) {
+               if (protos[i].enabled > 1)
+                       LLOG_INFO("protocol %s enabled and forced", protos[i].name);
+               else if (protos[i].enabled)
                        LLOG_INFO("protocol %s enabled", protos[i].name);
-               else
+               else
                        LLOG_INFO("protocol %s disabled", protos[i].name);
 
        TAILQ_INIT(&cfg->g_hardware);