tap-linux: Open ipvtap and macvtap
PATCH 1/1 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.
--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
net/tap-linux.c +14 -3
@@ -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 ;
---
base-commit: 31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20241008-macvtap-b152e5abb457
Best regards,
Signature · 1 line
Akihiko Odaki <[email protected]>
Quoted 5 lines · Akihiko Odaki
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.
Management layers usually pass these fds via SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).
Quoted 17 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +3
-1@@ -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) {
net/tap-linux.c int tap_open(char *ifname, int ifname_size, int *vnet_hdr, · line 58
Quoted 10 lines
net/tap-linux.c +7
-2+ 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 ));
Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 12 lines
net/tap-linux.c +4
-1+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 ; ---base-commit:
31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20241008-macvtap-b152e5abb457
Quoted 3 lines
Best regards,
--
Akihiko Odaki <[email protected]>
Thanks
Quoted 1 line
Quoted 10 lines · Jason Wang
Quoted 5 lines · Akihiko Odaki
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.
Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).
I used this for testing.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +0
-0@@ -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;
Quoted 16 lines
Quoted 4 lines
net/tap-linux.c +3
-1- fd =RETRY_ON_EINTR (open (PATH_NET_TUN ,O_RDWR )); + + ret =if_nametoindex (ifname); +if (ret) {net/tap-linux.c int tap_open(char *ifname, int ifname_size, int *vnet_hdr, · line 58
Quoted 10 lines
net/tap-linux.c +7
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
This is also consistent with libvirt. libvirt first checks if g_strdup_printf("/dev/tap%d", ifindex) exists, and falls back to tuntap otherwise.
Regards,
Akihiko Odaki
Quoted 21 lines
Quoted 13 lines
net/tap-linux.c +4
-1+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 ; ---base-commit:
31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20241008-macvtap-b152e5abb457Quoted 3 lines
Best regards,
--
Akihiko Odaki <[email protected]>Thanks
Quoted 1 line
Quoted 9 lines · Akihiko Odaki
Quoted 7 lines · Jason Wang
Quoted 5 lines · Akihiko Odaki
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.
Quoted 5 lines
Quoted 3 lines
Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
Quoted 32 lines
Quoted 15 lines
Quoted 15 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +0
-0@@ -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;Quoted 16 lines
Quoted 4 lines
net/tap-linux.c +3
-1- fd =RETRY_ON_EINTR (open (PATH_NET_TUN ,O_RDWR )); + + ret =if_nametoindex (ifname); +if (ret) {net/tap-linux.c int tap_open(char *ifname, int ifname_size, int *vnet_hdr, · line 58
Quoted 10 lines
net/tap-linux.c +7
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of open() not TUNSETIFF?
Quoted 4 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.
This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
Thanks
Quoted 26 lines
Regards,
Akihiko OdakiQuoted 21 lines
Quoted 13 lines
net/tap-linux.c +4
-1+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 ; ---base-commit:
31669121a01a14732f57c49400bc239cf9fd505f
change-id: 20241008-macvtap-b152e5abb457Quoted 3 lines
Best regards,
--
Akihiko Odaki <[email protected]>Thanks
Quoted 1 line
Quoted 14 lines · Jason Wang
Quoted 13 lines · Akihiko Odaki
Quoted 10 lines · Jason Wang
Quoted 5 lines · Akihiko Odaki
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.
Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).
Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 20 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +3
-1@@ -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) {net/tap-linux.c int tap_open(char *ifname, int ifname_size, int *vnet_hdr, · line 58
Quoted 10 lines
net/tap-linux.c +7
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?
We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses /dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.
Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki
Hi Jason,
Can you check this patch again?
Regards,
Akihiko Odaki
Quoted 80 lines · Akihiko Odaki
Quoted 14 lines · Jason Wang
Quoted 13 lines · Akihiko Odaki
Quoted 10 lines · Jason Wang
Quoted 5 lines · Akihiko Odaki
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.
Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
Signed-off-by Akihiko Odaki <[email protected]>---
net/tap-linux.c| 17 ++++++++++++++---1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +4
-1@@ -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);net/tap-linux.c int tap_open(char *ifname, int ifname_size, int · line 60
Quoted 10 lines
net/tap-linux.c +6
-2+ 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));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses
/dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki
Quoted 4 lines · Akihiko Odaki
Hi Jason,
Can you check this patch again?
I would like to have this if
1) it would be used by libvirt.
or
2) there's no other way to do this
Thanks
Quoted 95 lines
Regards,
Akihiko OdakiQuoted 89 lines · Akihiko Odaki
Quoted 18 lines · Jason Wang
Quoted 16 lines · Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 7 lines · Akihiko Odaki
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.Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +4
-1@@ -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);net/tap-linux.c int tap_open(char *ifname, int ifname_size, int · line 60
Quoted 10 lines
net/tap-linux.c +6
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses
/dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki
Quoted 6 lines · Jason Wang
Quoted 4 lines · Akihiko Odaki
Hi Jason,
Can you check this patch again?
Quoted 7 lines
I would like to have this if
1) it would be used by libvirt.
or
2) there's no other way to do this
I need this to make QEMU work with macvtap on mkosi, and this patch is an effective way to accomplish the goal.
Requiring to pass a file descriptor is simply less convenient. Most (if not all) aspects of QEMU can be configured without file descriptors; I don't think there is a reason to make tap exceptional.
Regards,
Akihiko Odaki
Quoted 99 lines
Thanks
Quoted 95 lines
Regards,
Akihiko OdakiQuoted 89 lines · Akihiko Odaki
Quoted 18 lines · Jason Wang
Quoted 16 lines · Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 7 lines · Akihiko Odaki
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.Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +4
-1@@ -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);net/tap-linux.c int tap_open(char *ifname, int ifname_size, int · line 60
Quoted 10 lines
net/tap-linux.c +6
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses
/dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki
Quoted 10 lines · Akihiko Odaki
Quoted 8 lines · Jason Wang
Quoted 4 lines · Akihiko Odaki
Hi Jason,
Can you check this patch again?
I would like to have this if
Quoted 8 lines
Quoted 5 lines
1) it would be used by libvirt.
or
2) there's no other way to do this
I need this to make QEMU work with macvtap on mkosi, and this patch is an effective way to accomplish the goal.
I'm not sure how to define "effective" here.
Quoted 4 lines
Requiring to pass a file descriptor is simply less convenient. Most (if not all) aspects of QEMU can be configured without file descriptors; I don't think there is a reason to make tap exceptional.
TUNSETIFF requires CAP_NET_ADMIN and qemu doesn't want to run with privilege, so fd is prefered in the case of tuntap.
For macvtap,ipvtap, though open, doesn't require any privilege. Passing fd via SCM_RIGHTS is still preferable as it eases the interaction with security facilities (for example, you may want to whitelist /dev/tapX for Qemu to access etc).
Thanks
Quoted 104 lines
Regards,
Akihiko OdakiQuoted 99 lines
Thanks
Quoted 95 lines
Regards,
Akihiko OdakiQuoted 89 lines · Akihiko Odaki
Quoted 18 lines · Jason Wang
Quoted 16 lines · Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 7 lines · Akihiko Odaki
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.Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +4
-1@@ -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);net/tap-linux.c int tap_open(char *ifname, int ifname_size, int · line 60
Quoted 10 lines
net/tap-linux.c +6
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses
/dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 12 lines · Akihiko Odaki
Quoted 10 lines · Jason Wang
Quoted 4 lines · Akihiko Odaki
Hi Jason,
Can you check this patch again?
I would like to have this if
1) it would be used by libvirt.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
or
2) there's no other way to do this
I need this to make QEMU work with macvtap on mkosi, and this patch is an effective way to accomplish the goal.
I'm not sure how to define "effective" here.
I just meant it requires me writing less code.
Quoted 6 lines
Quoted 5 lines
Requiring to pass a file descriptor is simply less convenient. Most (if not all) aspects of QEMU can be configured without file descriptors; I don't think there is a reason to make tap exceptional.
Quoted 7 lines
TUNSETIFF requires
CAP_NET_ADMINand qemu doesn't want to run with privilege, so fd is prefered in the case of tuntap.For macvtap,ipvtap, though open, doesn't require any privilege. Passing fd via
SCM_RIGHTSis still preferable as it eases the interaction with security facilities (for example, you may want to whitelist/dev/tapXfor Qemu to access etc).
That is true for almost any kind of files, and QEMU provides options to specify files with file descriptor for this reason. However, it also provides alternative options to specify files with e.g., path for convenience.
This patch does not add a entirely-new complex, high-level feature. It only pushes the macvtap/ipvtap support to the same level with tuntap and other features interacting with files.
Regards,
Akihiko Odaki
Quoted 108 lines
Thanks
Quoted 104 lines
Regards,
Akihiko OdakiQuoted 99 lines
Thanks
Quoted 95 lines
Regards,
Akihiko OdakiQuoted 89 lines · Akihiko Odaki
Quoted 18 lines · Jason Wang
Quoted 16 lines · Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 7 lines · Akihiko Odaki
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.Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +4
-1@@ -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);net/tap-linux.c int tap_open(char *ifname, int ifname_size, int · line 60
Quoted 10 lines
net/tap-linux.c +6
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses
/dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki
Quoted 40 lines · Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 12 lines · Akihiko Odaki
Quoted 10 lines · Jason Wang
Quoted 4 lines · Akihiko Odaki
Hi Jason,
Can you check this patch again?
I would like to have this if
1) it would be used by libvirt.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
or
2) there's no other way to do this
I need this to make QEMU work with macvtap on mkosi, and this patch is an effective way to accomplish the goal.
I'm not sure how to define "effective" here.
I just meant it requires me writing less code.
Quoted 6 lines
Quoted 5 lines
Requiring to pass a file descriptor is simply less convenient. Most (if not all) aspects of QEMU can be configured without file descriptors; I don't think there is a reason to make tap exceptional.
Quoted 7 lines
TUNSETIFF requires
CAP_NET_ADMINand qemu doesn't want to run with privilege, so fd is prefered in the case of tuntap.For macvtap,ipvtap, though open, doesn't require any privilege. Passing fd via
SCM_RIGHTSis still preferable as it eases the interaction with security facilities (for example, you may want to whitelist/dev/tapXfor Qemu to access etc).
Quoted 8 lines
That is true for almost any kind of files, and QEMU provides options to specify files with file descriptor for this reason. However, it also provides alternative options to specify files with e.g., path for convenience.
This patch does not add a entirely-new complex, high-level feature. It only pushes the macvtap/ipvtap support to the same level with tuntap and other features interacting with files.
Fair enough. I've queued this.
Thanks
Quoted 113 lines
Regards,
Akihiko OdakiQuoted 108 lines
Thanks
Quoted 104 lines
Regards,
Akihiko OdakiQuoted 99 lines
Thanks
Quoted 95 lines
Regards,
Akihiko OdakiQuoted 89 lines · Akihiko Odaki
Quoted 18 lines · Jason Wang
Quoted 16 lines · Akihiko Odaki
Quoted 13 lines · Jason Wang
Quoted 7 lines · Akihiko Odaki
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.Management layers usually pass these fds via
SCM_RIGHTS. Is this for testing purposes? (Note that we can use something like -netdev tap,fd=10 10<>/dev/tap0).Quoted 5 lines
Quoted 1 line
I used this for testing.
Anything that prevents you from using fd redirection? If not management interest and we had already had a way for testing, I tend to not introduce new code as it may bring bugs.
I don't know what ifindex the macvtap device has so it's easier to use if QEMU can automatically figure out the it.
Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 22 lines
Signed-off-by Akihiko Odaki <[email protected]>--- net/tap-linux.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)net/tap-linux.c +4
-1@@ -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);net/tap-linux.c int tap_open(char *ifname, int ifname_size, int · line 60
Quoted 10 lines
net/tap-linux.c +6
-2+ 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 ));Any reason tuntap were tried after the macvtap/ipvtap?
Quoted 6 lines
Quoted 4 lines
If we try tuntap first, we will know that it is not tuntap when calling TUNSETIFF. We will need to call TUNGETFEATURES and TUNSETVNETHDRSZ again in such a case because they precede TUNSETIFF. Calling them twice is troublesome.
I may miss something, we are only at the phase of
open()not TUNSETIFF?We can tell if it is macvtap/ipvtap just by trying opening the device file. That is not possible with tuntap because tuntap uses
/dev/net/tun, a device file common for all tuntap interfaces and its presence does not tell if the interface is tuntap.Quoted 8 lines
Quoted 5 lines
This is also consistent with libvirt. libvirt first checks if
g_strdup_printf("/dev/tap%d", ifindex)exists, and falls back to tuntap otherwise.This is not what I understand from how layered products work. Libvirt should align with Qemu for low level things like TAP, not the reverse.
This change is intended for the use case where libvirt is not in use. In particular, I use mkosi, which is not a full fledged layering mechanism.
Regards,
Akihiko Odaki