]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - src/lldpd.c
Allow to force a protocol.
[thirdparty/lldpd.git] / src / lldpd.c
index ae85a5bdc19500ccefe6ce30bf7ee6ba9f18701c..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,
@@ -107,24 +107,38 @@ usage(void)
        fprintf(stderr, "-i       Disable LLDP-MED inventory TLV transmission.\n");
        fprintf(stderr, "-k       Disable advertising of kernel release, version, machine.\n");
        fprintf(stderr, "-m IP    Specify the management address of this system.\n");
+#ifdef ENABLE_LLDPMED
        fprintf(stderr, "-M class Enable emission of LLDP-MED frame. 'class' should be one of:\n");
        fprintf(stderr, "             1 Generic Endpoint (Class I)\n");
        fprintf(stderr, "             2 Media Endpoint (Class II)\n");
        fprintf(stderr, "             3 Communication Device Endpoints (Class III)\n");
        fprintf(stderr, "             4 Network Connectivity Device\n");
+#endif
+#ifdef USE_SNMP
        fprintf(stderr, "-x       Enable SNMP subagent.\n");
+#endif
 #ifdef ENABLE_LISTENVLAN
        fprintf(stderr, "-v       Listen on VLAN as well.\n");
 #endif
        fprintf(stderr, "\n");
 
-       fprintf(stderr, "Protocol support. (Disabled by default)\n");
+#if defined ENABLE_CDP || defined ENABLE_EDP || defined ENABLE_FDP || defined ENABLE_SONMP
+       fprintf(stderr, "Additional protocol support.\n");
+#ifdef ENABLE_CDP
        fprintf(stderr, "-c       Enable the support of CDP protocol. (Cisco)\n");
+#endif
+#ifdef ENABLE_EDP
        fprintf(stderr, "-e       Enable the support of EDP protocol. (Extreme)\n");
+#endif
+#ifdef ENABLE_FDP
        fprintf(stderr, "-f       Enable the support of FDP protocol. (Foundry)\n");
+#endif
+#ifdef ENABLE_SONMP
        fprintf(stderr, "-s       Enable the support of SONMP protocol. (Nortel)\n");
+#endif
 
        fprintf(stderr, "\n");
+#endif
 
        fprintf(stderr, "see manual page lldpd(8) for more information\n");
        exit(1);
@@ -610,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;
                                }
                        }
@@ -806,7 +825,7 @@ lldpd_main(int argc, char *argv[])
 #ifdef ENABLE_LISTENVLAN
                "v"
 #endif
-               "kdxX:m:p:M:i@                    ";
+               "hkdxX:m:p:M:i@                    ";
        int i, found, advertise_version = 1;
 #ifdef ENABLE_LISTENVLAN
        int vlan = 0;
@@ -821,13 +840,14 @@ 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) {
+               case 'h':
+                       usage();
+                       break;
 #ifdef ENABLE_LISTENVLAN
                case 'v':
                        vlan = 1;
@@ -879,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;
                                }
                        }
@@ -949,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);