From: Vincent Bernat Date: Fri, 12 Mar 2010 13:47:05 +0000 (+0100) Subject: Allow to force a protocol. X-Git-Tag: 0.5.1~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c877af0a363614c1f3a1c8760ac2a1f6570e6f5;p=thirdparty%2Flldpd.git Allow to force a protocol. 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. --- diff --git a/CHANGELOG b/CHANGELOG index 4d7d0f42..4e860e58 100644 --- 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). diff --git a/man/lldpd.8 b/man/lldpd.8 index b15ccaef..a4c5fc35 100644 --- a/man/lldpd.8 +++ b/man/lldpd.8 @@ -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 diff --git a/src/lldpd.c b/src/lldpd.c index 7d2722ea..05a840ef 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -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);