]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Add a way to specify which interfaces lldpd should listen to.
authorVincent Bernat <bernat@luffy.cx>
Sat, 2 Jul 2011 18:05:21 +0000 (20:05 +0200)
committerVincent Bernat <bernat@luffy.cx>
Sat, 2 Jul 2011 18:05:21 +0000 (20:05 +0200)
CHANGELOG
man/lldpd.8
src/interfaces.c
src/lldpd.c
src/lldpd.h

index b62ae9dd54eeae75b54b187cff44efea6a8f2741..be39c176123976ebbfeac426f84e9bdc8fbee592 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,7 @@ lldpd (0.5.4)
   * Features:
     + Get OS information from /etc/os-release if available. Patch from
       Michael Tremer.
+    + Add a flag to specify which interfaces lldpd should listen to.
 
 lldpd (0.5.3)
   * Fixes:
index 6d5fcbce9513a4c7a83038febf7d9933ee5438b7..0f97c57c5a53e7776807d90c12ebf0ec9ea0875c 100644 (file)
@@ -25,6 +25,7 @@
 .Op Fl S Ar description
 .Op Fl X Ar socket
 .Op Fl m Ar management
+.Op Fl I Ar interfaces
 .Op Fl M Ar class
 .Op Fl H Ar hide
 .Sh DESCRIPTION
@@ -116,6 +117,11 @@ Specify the management address of this system.
 only sends one management address. It will use the first one that it
 finds or the one that you specify with this option. This option can
 use wildcards.
+.It Fl I Ar interfaces
+Specify which interface to listen to. Without this option,
+.Nm
+will listen on all available interfaces. This option can use
+wildcards. Several interfaces can be specified separated by commas.
 .It Fl M Ar class
 Enable emission of LLDP-MED frame. The class should be one of the
 following value:
index 512c7c204d2a2c9b5551a1298686991d392d51ce..8ecc7f6e1d5a0c36c4cd54bc2eab69cb2b086141 100644 (file)
@@ -735,6 +735,41 @@ lldpd_ifh_eth(struct lldpd *cfg, struct ifaddrs *ifap)
        }
 }
 
+void
+lldpd_ifh_whitelist(struct lldpd *cfg, struct ifaddrs *ifap)
+{
+       struct ifaddrs *ifa;
+       char *interfaces = NULL;
+       char *pattern;
+
+       if (!cfg->g_interfaces)
+               return;
+       if ((interfaces = strdup(cfg->g_interfaces)) == NULL) {
+               LLOG_WARNX("unable to allocate memory");
+               return;
+       }
+
+       for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
+               if (ifa->ifa_flags == 0) continue; /* Already handled by someone else */
+               strcpy(interfaces, cfg->g_interfaces); /* Restore our list of interfaces */
+               pattern = strtok(interfaces, ",");
+               while (pattern != NULL) {
+                       if (fnmatch(pattern, ifa->ifa_name, 0) == 0) {
+                               /* This interface is whitelisted */
+                               break;
+                       }
+                       pattern = strtok(NULL, ",");
+               }
+               if (pattern == NULL) {
+                       /* This interface was not found. We flag it. */
+                       LLOG_DEBUG("blacklist %s", ifa->ifa_name);
+                       ifa->ifa_flags = 0;
+               }
+       }
+
+       free(interfaces);
+}
+
 static int
 iface_bond_init(struct lldpd *cfg, struct lldpd_hardware *hardware)
 {
index 8253d7e02fb8e167c9bd0960b35e32ba765b07b6..e51a6940b6346491b31f46f773055deca03da745 100644 (file)
@@ -980,6 +980,7 @@ lldpd_update_localports(struct lldpd *cfg)
        struct ifaddrs *ifap;
        struct lldpd_hardware *hardware;
        lldpd_ifhandlers ifhs[] = {
+               lldpd_ifh_whitelist, /* Is the interface whitelisted? */
                lldpd_ifh_bond, /* Handle bond */
                lldpd_ifh_eth,  /* Handle classic ethernet interfaces */
 #ifdef ENABLE_DOT1
@@ -1108,8 +1109,9 @@ lldpd_main(int argc, char *argv[])
        char *agentx = NULL;    /* AgentX socket */
 #endif
        char *mgmtp = NULL;
+       char *interfaces = NULL;
        char *popt, opts[] = 
-               "H:hkrdxX:m:p:M:S:i@                    ";
+               "H:hkrdxX:m:I:p:M:S:i@                    ";
        int i, found, advertise_version = 1;
 #ifdef ENABLE_LLDPMED
        int lldpmed = 0, noinventory = 0;
@@ -1142,6 +1144,9 @@ lldpd_main(int argc, char *argv[])
                case 'm':
                        mgmtp = optarg;
                        break;
+               case 'I':
+                       interfaces = optarg;
+                       break;
                case 'k':
                        advertise_version = 0;
                        break;
@@ -1244,6 +1249,7 @@ lldpd_main(int argc, char *argv[])
                fatal(NULL);
 
        cfg->g_mgmt_pattern = mgmtp;
+       cfg->g_interfaces = interfaces;
        cfg->g_smart = smart;
        cfg->g_receiveonly = receiveonly;
 
index 9543d73e5db673b80bf7224a34c0f8d50c8d3596..b11df407dfec1264cb0d1e4e4fa1283ca6991cc8 100644 (file)
@@ -345,6 +345,7 @@ struct lldpd {
        TAILQ_HEAD(, lldpd_callback) g_callbacks;
 
        char                    *g_mgmt_pattern;
+       char                    *g_interfaces;
 
         char                    *g_descr_override;
        char                    *g_lsb_release;
@@ -447,6 +448,7 @@ int  ctl_msg_pack_structure(char *, void *, unsigned int, struct hmsg *, void **
 int     ctl_msg_unpack_structure(char *, void *, unsigned int, struct hmsg *, void **);
 
 /* interfaces.c */
+void    lldpd_ifh_whitelist(struct lldpd *, struct ifaddrs *);
 void    lldpd_ifh_bond(struct lldpd *, struct ifaddrs *);
 void    lldpd_ifh_eth(struct lldpd *, struct ifaddrs *);
 #ifdef ENABLE_DOT1