Bug 241737

Summary: cannot use the tap interface name to build a VM
Product: Base System Reporter: Fabien Costard <fabien.costard>
Component: bhyveAssignee: freebsd-virtualization (Nobody) <virtualization>
Status: Closed FIXED    
Severity: Affects Only Me CC: kevans
Priority: --- Keywords: patch
Version: 12.0-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
modification on pci_virtio_net.c
none
update_code on pci_virtio_net.c none

Description Fabien Costard 2019-11-05 16:43:31 UTC
Created attachment 208881 [details]
modification on pci_virtio_net.c

Hi,
If a tap interface is created with a name, it is not possible to start a VM with bhyve using this name. We must use the device name.

For example, I create this interface (sysctl is correctly configured to use tap):
ifconfig tap create name port1

when I launch the VM (after loaded it for sure)
bhyve -c 1 -m 256 -A -H -P -s 0:0,hostbridge -s 1,virtio-net,port1 -s 2:0 virtio-blk,/root/rFreeBSD.img -s 31,lpc -l com1,/dev/nmdm0A rFreeBSD

The network will not work because the command is only develop to check device in /dev/.

I add some code to check if the name matches with a interface and replace it to create the virtual interface

I hope I was enough clear and my code not too ugly
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2019-11-07 13:54:15 UTC
(In reply to Fabien Costard from comment #0)

Hmm... unfortunately, this should work fine in -CURRENT and stable/12, but the patch will not go to stable/11 and did not make it into 12.1. The merged tuntap(4) will create a dev alias for the different name:

root@viper:/usr/src# ifconfig tap create name port1
port1
root@viper:/usr/src# ls -l /dev | grep tap
lrwxr-xr-x  1 root  wheel        4 Nov  7 07:52 port1 -> tap0
crw-------  1 uucp  dialer    0x60 Nov  7 07:52 tap0

I do not have any insight into how -virtualization would prefer to proceed, but this is news from the tun/tap side. =-)
Comment 2 Fabien Costard 2019-11-11 21:35:48 UTC
(In reply to Kyle Evans from comment #1)
Hi,

That is a good with the link. As advice me a friend, I am also trying to find another way (to myself, this is a good way to learn) to find the source device file instead of checking the /dev folder. I hope it will be more generic
Comment 3 Fabien Costard 2019-11-27 15:33:26 UTC
Created attachment 209488 [details]
update_code on pci_virtio_net.c

Hello,

My code was very ugly and bad.. It does not work well. I find I have an issue when I used more that 8 tap interfaces.

After I worked on memory allocation & co... I send you for memories an upgrade of the code.

I know about the previous comments, but I do not want to let a wrong code :-)

Regards,
Fabien
Comment 4 Fabien Costard 2021-08-20 07:18:48 UTC
Ok with the link :-)

Thanks !