Skip to content

Commit

Permalink
interfaces: on NetBSD, ifbic_req can use more than 64 bytes
Browse files Browse the repository at this point in the history
Therefore, allocate it dynamically. Fix #489.
  • Loading branch information
vincentbernat committed Dec 1, 2021
1 parent 13b8730 commit 690e447
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/daemon/interfaces-bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 =
Expand Down

0 comments on commit 690e447

Please sign in to comment.