On 04/08/2018 05:40 PM, Roman Bogorodskiy wrote:
virNetDevTapGetRealDeviceName() is used on FreeBSD because interface
names (such as one sees in output of tools like ifconfig(8)) might not
match their /dev entity names, and for bhyve we need the latter.
Current implementation is not very efficient because in order to find
/dev name, it goes through all /dev/tap* entries and tries to issue
TAPGIFNAME ioctl on it. Not only this is slow, but also there's a bug in
this implementation when more than one NIC is passed to a VM: once we
find the tap interface we're looking for, we set its state to UP because
opening it for issuing ioctl sets it DOWN, even if it was UP before.
When we have more than 1 NIC for a VM, we have only last one UP because
others remain DOWN after unsuccessful attempts to match interface name.
New implementation just uses sysctl(3), so it should be faster and
won't make interfaces go down to get name.
---
src/util/virnetdevtap.c | 71 +++++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 41 deletions(-)
ACK with this squashed in:
diff --git i/src/util/virnetdevtap.c w/src/util/virnetdevtap.c
index afe4f0b3c1..bd0710ad2e 100644
--- i/src/util/virnetdevtap.c
+++ w/src/util/virnetdevtap.c
@@ -40,7 +40,6 @@
#include <string.h>
#include <unistd.h>
#include <regex.h>
-#include <dirent.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <net/if.h>
@@ -129,13 +128,14 @@ virNetDevTapGetRealDeviceName(char *ifname ATTRIBUTE_UNUSED)
return NULL;
}
- ret = malloc(len);
+ if (VIR_ALLOC_N(ret, len) < 0)
+ return NULL;
if (sysctl(name, 6, ret, &len, 0, 0) < 0) {
virReportSystemError(errno,
_("Unable to get driver name for '%s'"),
ifname);
- free(ret);
+ VIR_FREE(ret);
return NULL;
}
Michal