]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
interfaces: limit the maximum search depth when applying a VLAN
authorVincent Bernat <vincent@bernat.im>
Sun, 13 Mar 2016 11:04:06 +0000 (12:04 +0100)
committerVincent Bernat <vincent@bernat.im>
Sun, 13 Mar 2016 11:04:06 +0000 (12:04 +0100)
It's now quite easy to hit a bug where we loop over interfaces when
trying to find the physical interface associated to a VLAN. Put a
maximum depth of 5.

NEWS
src/daemon/interfaces.c

diff --git a/NEWS b/NEWS
index 058a07e67aac7598bbd5daf32c3ac20b2e6178c0..3022f7e37c126bbe28ca09e8bf485222141e93da 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ lldpd (0.9.2)
   * Change:
     + Ability to add/remove/replace custom TLV from lldpcli.
     + LLDP-MED capabilities are displayed differently in lldpcli.
+    + Limit the maximum depth (5) when trying to apply a VLAN.
   * Fix:
     + LLDP-MED POE TLV are now displayed in lldpcli.
     + Ignore lower link when it is in another namespace.
index b3f99346cd5fdfbf19f4bdcfb9ca36ec7a2117b9..8c18be0974cae70bacbaf425c5de7031046ef16f 100644 (file)
@@ -223,6 +223,7 @@ iface_append_vlan(struct lldpd *cfg,
  *
  * @param vlan  The VLAN interface (used to get VLAN ID).
  * @param upper The upper interface we are currently examining.
+ * @param depth Depth of the stack (avoid infinite recursion)
  *
  * Initially, upper == vlan. This function will be called recursively.
  */
@@ -230,8 +231,16 @@ static void
 iface_append_vlan_to_lower(struct lldpd *cfg,
     struct interfaces_device_list *interfaces,
     struct interfaces_device *vlan,
-    struct interfaces_device *upper)
+    struct interfaces_device *upper,
+    int depth)
 {
+       if (depth > 5) {
+               log_debug("interfaces",
+                   "maximum depth reached when applying VLAN %s (loop?)",
+                   vlan->name);
+               return;
+       }
+       depth++;
        struct interfaces_device *lower;
        log_debug("interfaces",
            "looking to apply VLAN %s to physical interface behind %s",
@@ -243,7 +252,8 @@ iface_append_vlan_to_lower(struct lldpd *cfg,
                    vlan->name, upper->name);
                iface_append_vlan_to_lower(cfg,
                    interfaces, vlan,
-                   upper->lower);
+                   upper->lower,
+                   depth);
                return;
        }
 
@@ -262,7 +272,7 @@ iface_append_vlan_to_lower(struct lldpd *cfg,
                log_debug("interfaces", "VLAN %s on lower interface %s",
                    vlan->name, upper->name);
                iface_append_vlan_to_lower(cfg,
-                   interfaces, vlan, lower);
+                   interfaces, vlan, lower, depth);
        }
 }
 
@@ -283,7 +293,7 @@ interfaces_helper_vlan(struct lldpd *cfg,
                log_debug("interfaces", "search physical interface for VLAN interface %s",
                    iface->name);
                iface_append_vlan_to_lower(cfg, interfaces,
-                   iface, iface);
+                   iface, iface, 0);
        }
 }
 #endif