Fix that brconfig <bridge> (addr) can't show a large number of MAC addresses

The command shows only 256 addresses at maximum even if a bridge caches more
addresses.  It occurs because the kernel doesn't return an error if the command
passes a short buffer that can't store all cached addresses; the kernel fills
cached addresses as much as possible and returns it without telling that the
result is truncated.

Fix the issue by telling a required size of a buffer if a buffer passed from the
command is not enough, which lets the command retry with an enough buffer.

Reported by k-goda@IIJ
This commit is contained in:
ozaki-r 2018-11-09 06:44:31 +00:00
parent 33cbd42a21
commit 63f183af76

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_bridge.c,v 1.159 2018/09/19 07:51:23 msaitoh Exp $ */
/* $NetBSD: if_bridge.c,v 1.160 2018/11/09 06:44:31 ozaki-r Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.159 2018/09/19 07:51:23 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.160 2018/11/09 06:44:31 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_bridge_ipf.h"
@ -1060,6 +1060,12 @@ bridge_ioctl_rts(struct bridge_softc *sc, void *arg)
BRIDGE_RT_LOCK(sc);
/* The passed buffer is not enough, tell a required size. */
if (bac->ifbac_len < (sizeof(bareq) * sc->sc_brtcnt)) {
count = sc->sc_brtcnt;
goto out;
}
len = bac->ifbac_len;
BRIDGE_RTLIST_WRITER_FOREACH(brt, sc) {
if (len < sizeof(bareq))