Skip to content

Commit ac2ff9b

Browse files
akihikodakijasowang
authored andcommitted
tap-linux: Open ipvtap and macvtap
ipvtap and macvtap create a file for each interface unlike tuntap, which creates one file shared by all interfaces. Try to open a file dedicated to the interface first for ipvtap and macvtap. Signed-off-by: Akihiko Odaki <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 2938c36 commit ac2ff9b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

net/tap-linux.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,21 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
4545
int len = sizeof(struct virtio_net_hdr);
4646
unsigned int features;
4747

48-
fd = RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR));
48+
49+
ret = if_nametoindex(ifname);
50+
if (ret) {
51+
g_autofree char *file = g_strdup_printf("/dev/tap%d", ret);
52+
fd = open(file, O_RDWR);
53+
} else {
54+
fd = -1;
55+
}
56+
4957
if (fd < 0) {
50-
error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN);
51-
return -1;
58+
fd = RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR));
59+
if (fd < 0) {
60+
error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN);
61+
return -1;
62+
}
5263
}
5364
memset(&ifr, 0, sizeof(ifr));
5465
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;

0 commit comments

Comments
 (0)