summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki@daynix.com>2024-10-08 15:52:06 +0900
committerJason Wang <jasowang@redhat.com>2025-03-10 17:07:16 +0800
commitac2ff9b840ce82cc7d5fd9ce4fd3019a434d7dc9 (patch)
tree0d8cf020ecf79b3d34f0dbfe419138fb7410451c
parent2938c36937559554a2408b008470c9a76cb9271a (diff)
downloadfocaccia-qemu-ac2ff9b840ce82cc7d5fd9ce4fd3019a434d7dc9.tar.gz
focaccia-qemu-ac2ff9b840ce82cc7d5fd9ce4fd3019a434d7dc9.zip
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 <akihiko.odaki@daynix.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
-rw-r--r--net/tap-linux.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 1226d5fda2..22ec2f45d2 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -45,10 +45,21 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
     int len = sizeof(struct virtio_net_hdr);
     unsigned int features;
 
-    fd = RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR));
+
+    ret = if_nametoindex(ifname);
+    if (ret) {
+        g_autofree char *file = g_strdup_printf("/dev/tap%d", ret);
+        fd = open(file, O_RDWR);
+    } else {
+        fd = -1;
+    }
+
     if (fd < 0) {
-        error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN);
-        return -1;
+        fd = RETRY_ON_EINTR(open(PATH_NET_TUN, O_RDWR));
+        if (fd < 0) {
+            error_setg_errno(errp, errno, "could not open %s", PATH_NET_TUN);
+            return -1;
+        }
     }
     memset(&ifr, 0, sizeof(ifr));
     ifr.ifr_flags = IFF_TAP | IFF_NO_PI;