]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
interfaces: on NetBSD, ifbic_req can use more than 64 bytes
authorVincent Bernat <vincent@bernat.ch>
Wed, 1 Dec 2021 18:29:28 +0000 (19:29 +0100)
committerVincent Bernat <vincent@bernat.ch>
Wed, 1 Dec 2021 18:29:52 +0000 (19:29 +0100)
Therefore, allocate it dynamically. Fix #489.

src/daemon/interfaces-bsd.c

index c8e466b0bf9b6b3468f68a32109ef683dc9fa730..d7d9c6c0aad42e58ad7892f26c60f41424d90f6d 100644 (file)
@@ -72,11 +72,19 @@ ifbsd_check_bridge(struct lldpd *cfg,
     struct interfaces_device_list *interfaces,
     struct interfaces_device *master)
 {
-       struct ifbreq req[64];
-       struct ifbifconf bifc = {
-               .ifbic_len = sizeof(req),
-               .ifbic_req = req
-       };
+       static size_t ifbic_len = 64;
+       struct ifbreq *req = NULL;
+       struct ifbifconf bifc = {};
+
+ retry_alloc:
+       if ((req = realloc(req, ifbic_len)) == NULL) {
+               log_warn("interfaces", "unable to allocate memory to query bridge %s",
+                   master->name);
+               free(bifc.ifbic_req);
+               return;
+       }
+       bifc.ifbic_len = ifbic_len;
+       bifc.ifbic_req = req;
 
 #if defined HOST_OS_FREEBSD || defined HOST_OS_NETBSD || defined HOST_OS_OSX || defined HOST_OS_DRAGONFLY
        struct ifdrv ifd = {
@@ -101,11 +109,9 @@ ifbsd_check_bridge(struct lldpd *cfg,
 #else
 # error Unsupported OS
 #endif
-       if (bifc.ifbic_len >= sizeof(req)) {
-               log_warnx("interfaces",
-                   "%s is a bridge too big. Please, report the problem",
-                   master->name);
-               return;
+       if (bifc.ifbic_len >= ifbic_len) {
+               ifbic_len = bifc.ifbic_len + 1;
+               goto retry_alloc;
        }
        for (int i = 0; i < bifc.ifbic_len / sizeof(*req); i++) {
                struct interfaces_device *slave =