]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
interfaces: management address is set to pattern on exact match
authorVincent Bernat <vincent@bernat.im>
Sat, 28 Mar 2015 08:57:43 +0000 (09:57 +0100)
committerVincent Bernat <vincent@bernat.im>
Sun, 29 Mar 2015 08:57:43 +0000 (10:57 +0200)
When the management pattern is an exact IP address, use it as is instead
of trying to match an interface. When a user doesn't want this
behavior (keeping the check), they should use something like
`192.168.1.15,0` or `!*,!!192.168.1.15` instead of the exact IP address.

This feature allows a user to advertise an out-of-band management IP
address.

Closes #103

NEWS
src/client/lldpcli.8.in
src/daemon/interfaces.c
src/daemon/lldpd.8.in

diff --git a/NEWS b/NEWS
index 9f74acef137d69cd16b6d3e9ab9dbec96080cada..a2d629515d440f7463ef29650c30346fd9edbea6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 lldpd (0.7.14)
   * Features:
     + Shutdown LLPDU are sent on MSAP change and when lldpd exits.
+    + When an exact IP is provided as a management pattern, use it
+      unconditionally.
   * Fix:
     + Incorrect boundary check when decoding management address and
       protocol identity may lead to lldpd crash when processing
index a47784a96f6c07e2a5770bfd5e0d6bec0945e2a5..5e1d70452acecb157979a227a82f76ed14baa4b0 100644 (file)
@@ -301,10 +301,11 @@ not disable promiscuous mode on interfaces already using this mode.
 .Bd -ragged -offset XXXXXX
 Specify the management addresses of this system. As for interfaces
 (described above), this option can use wildcards and inversions.
-Without this option, the first IPv4 and the first IPv6 are used. If
-only negative patterns are provided, only one IPv4 and one IPv6
-addresses are chosen. Otherwise, many of them can be selected. If you
-want to blacklist IPv6 addresses, you can use
+Without this option, the first IPv4 and the first IPv6 are used. If an
+exact IP address is provided, it is used as a management address
+without any check. If only negative patterns are provided, only one
+IPv4 and one IPv6 addresses are chosen. Otherwise, many of them can be
+selected. If you want to blacklist IPv6 addresses, you can use
 .Em !*:* .
 .Ed
 
index 849ed285b7291e193dc3c7f05faf512b61dbf08d..3b7a7bba89cd4eb504f237d9306a9c91c94e741c 100644 (file)
@@ -436,15 +436,47 @@ interfaces_helper_mgmt(struct lldpd *cfg,
 {
        int allnegative = 0;
        int af;
+       const char *pattern = cfg->g_config.c_mgmt_pattern;
 
        lldpd_chassis_mgmt_cleanup(LOCAL_CHASSIS(cfg));
 
+       /* Is the pattern provided an actual IP address? */
+       if (pattern && strpbrk(pattern, "!,*?") == NULL) {
+               struct in6_addr addr;
+               size_t addr_size;
+               for (af = LLDPD_AF_UNSPEC + 1;
+                    af != LLDPD_AF_LAST; af++) {
+                       switch (af) {
+                       case LLDPD_AF_IPV4: addr_size = sizeof(struct in_addr); break;
+                       case LLDPD_AF_IPV6: addr_size = sizeof(struct in6_addr); break;
+                       default: assert(0);
+                       }
+                       if (inet_pton(lldpd_af(af), pattern, &addr) == 1)
+                               break;
+               }
+               if (af == LLDPD_AF_LAST) {
+                       log_debug("interfaces",
+                           "interface management pattern is an incorrect IP");
+               } else {
+                       struct lldpd_mgmt *mgmt;
+                       mgmt = lldpd_alloc_mgmt(af, &addr, addr_size, 0);
+                       if (mgmt == NULL) {
+                               log_warn("interfaces", "out of memory error");
+                               return;
+                       }
+                       log_debug("interfaces", "add exact management address %s",
+                               pattern);
+                       TAILQ_INSERT_TAIL(&LOCAL_CHASSIS(cfg)->c_mgmt, mgmt, m_entries);
+               }
+               return;
+       }
+
        /* Is the pattern provided all negative? */
-       if (cfg->g_config.c_mgmt_pattern == NULL) allnegative = 1;
-       else if (cfg->g_config.c_mgmt_pattern[0] == '!') {
+       if (pattern == NULL) allnegative = 1;
+       else if (pattern[0] == '!') {
                /* If each comma is followed by '!', its an all
                   negative pattern */
-               char *sep = cfg->g_config.c_mgmt_pattern;
+               const char *sep = pattern;
                while ((sep = strchr(sep, ',')) &&
                       (*(++sep) == '!'));
                if (sep == NULL) allnegative = 1;
index 695aaa9429db161d829b29ae9f819b176553d839..4c17b83cf11783d975bc6f17a4bd71d1a51e938b 100644 (file)
@@ -186,10 +186,11 @@ will not send any frame. It will only listen to neighbors.
 .It Fl m Ar management
 Specify the management addresses of this system. As for interfaces
 (described below), this option can use wildcards and inversions.
-Without this option, the first IPv4 and the first IPv6 are used. If
-only negative patterns are provided, only one IPv4 and one IPv6
-addresses are chosen. Otherwise, many of them can be selected. If you
-want to blacklist IPv6 addresses, you can use
+Without this option, the first IPv4 and the first IPv6 are used. If an
+exact IP address is provided, it is used as a management address
+without any check. If only negative patterns are provided, only one
+IPv4 and one IPv6 addresses are chosen. Otherwise, many of them can be
+selected. If you want to blacklist IPv6 addresses, you can use
 .Em !*:* .
 .It Fl u Ar file
 Specify the Unix-domain socket used for communication with