[PATCH 1/3] bhyve: implement SLIRP networking
Bhyve supports SLIRP networking using the following syntax: -s 12:0,e1000,slirp,open Where "e1000" is a NIC model, "slirp" is the SLIRP backend and "open" specifies open mode where external network is available to the guest. The "open" mode is a recent addition in FreeBSD -CURRENT. Unfortunately, bhyve does not provide a way to probe whether the open mode is supported, so users will have to make sure it's supported on their own. For the reference, without the "open" mode, the guest will have no outside network connectivity. To make this mode useful, it is possible to configure forwarding from the host to the guest, but it is not covered by this patch. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_command.c | 6 +++- .../bhyvexml2argv-slirp.args | 10 ++++++ .../bhyvexml2argv-slirp.ldargs | 4 +++ .../bhyvexml2argvdata/bhyvexml2argv-slirp.xml | 21 ++++++++++++ tests/bhyvexml2argvtest.c | 1 + .../bhyvexml2xmlout-slirp.xml | 32 +++++++++++++++++++ tests/bhyvexml2xmltest.c | 1 + 7 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp.ldargs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp.xml create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-slirp.xml diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index e42e7b1ecc..b7e47084e6 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -93,9 +93,13 @@ bhyveBuildNetArgStr(const virDomainDef *def, goto cleanup; } break; + case VIR_DOMAIN_NET_TYPE_USER: + virCommandAddArg(cmd, "-s"); + virCommandAddArgFormat(cmd, "%d:0,%s,slirp,open", + net->info.addr.pci.slot, nic_model); + return 0; case VIR_DOMAIN_NET_TYPE_ETHERNET: case VIR_DOMAIN_NET_TYPE_DIRECT: - case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.args b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.args new file mode 100644 index 0000000000..ff9a90ebc9 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.args @@ -0,0 +1,10 @@ +bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,ahci,hd:/tmp/freebsd.img \ +-s 3:0,e1000,slirp,open \ +bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.ldargs new file mode 100644 index 0000000000..5905f4b3e6 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.ldargs @@ -0,0 +1,4 @@ +bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.xml new file mode 100644 index 0000000000..5cf13d2a20 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.xml @@ -0,0 +1,21 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid> + <memory>219136</memory> + <vcpu>1</vcpu> + <os> + <type>hvm</type> + </os> + <devices> + <disk type='file'> + <driver name='file' type='raw'/> + <source file='/tmp/freebsd.img'/> + <target dev='hda' bus='sata'/> + <address type='drive' controller='0' bus='0' target='2' unit='0'/> + </disk> + <interface type='user'> + <model type='e1000'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </interface> + </devices> +</domain> diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index 650313c2da..ee3d677947 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -270,6 +270,7 @@ mymain(void) DO_TEST("sata-rotation-rate"); DO_TEST_FAILURE("disk-virtio-rotation-rate"); DO_TEST_FAILURE("disk-virtio-queue-opts"); + DO_TEST("slirp"); /* Address allocation tests */ DO_TEST("addr-single-sata-disk"); diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-slirp.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-slirp.xml new file mode 100644 index 0000000000..44d2616f6c --- /dev/null +++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-slirp.xml @@ -0,0 +1,32 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <disk type='file' device='disk'> + <driver name='file' type='raw'/> + <source file='/tmp/freebsd.img'/> + <target dev='hda' bus='sata'/> + <address type='drive' controller='0' bus='0' target='2' unit='0'/> + </disk> + <controller type='pci' index='0' model='pci-root'/> + <controller type='sata' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </controller> + <interface type='user'> + <mac address='52:54:00:00:00:00'/> + <model type='e1000'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </interface> + </devices> +</domain> diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index c2458b9fc4..0abc50b0de 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -122,6 +122,7 @@ mymain(void) DO_TEST_DIFFERENT("nvme"); DO_TEST_DIFFERENT("2-nvme-2-controllers"); DO_TEST_DIFFERENT("passthru-multiple-devs"); + DO_TEST_DIFFERENT("slirp"); /* Address allocation tests */ DO_TEST_DIFFERENT("addr-single-sata-disk"); -- 2.51.2
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev, break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1; + } + if (net->guestIP.nips) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting IP addresses for SLIRP networking is not supported")); + return -1; + } + } + } case VIR_DOMAIN_DEVICE_AUDIO: case VIR_DOMAIN_DEVICE_CRYPTO: case VIR_DOMAIN_DEVICE_FS: @@ -337,7 +353,6 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev, case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_MEMORY: - case VIR_DOMAIN_DEVICE_NET: case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_PANIC: diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml new file mode 100644 index 0000000000..0152066b4f --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml @@ -0,0 +1,22 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid> + <memory>219136</memory> + <vcpu>1</vcpu> + <os> + <type>hvm</type> + </os> + <devices> + <disk type='file'> + <driver name='file' type='raw'/> + <source file='/tmp/freebsd.img'/> + <target dev='hda' bus='sata'/> + <address type='drive' controller='0' bus='0' target='2' unit='0'/> + </disk> + <interface type='user'> + <model type='e1000'/> + <ip family='ipv4' address='172.17.1.1' prefix='16'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </interface> + </devices> +</domain> diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml new file mode 100644 index 0000000000..b573d725d4 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml @@ -0,0 +1,22 @@ +<domain type='bhyve'> + <name>bhyve</name> + <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid> + <memory>219136</memory> + <vcpu>1</vcpu> + <os> + <type>hvm</type> + </os> + <devices> + <disk type='file'> + <driver name='file' type='raw'/> + <source file='/tmp/freebsd.img'/> + <target dev='hda' bus='sata'/> + <address type='drive' controller='0' bus='0' target='2' unit='0'/> + </disk> + <interface type='user'> + <model type='e1000'/> + <mac address="00:11:22:33:44:56"/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </interface> + </devices> +</domain> diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index ee3d677947..645bcb876c 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -271,6 +271,8 @@ mymain(void) DO_TEST_FAILURE("disk-virtio-rotation-rate"); DO_TEST_FAILURE("disk-virtio-queue-opts"); DO_TEST("slirp"); + DO_TEST_FAILURE("slirp-mac-addr"); + DO_TEST_FAILURE("slirp-ip"); /* Address allocation tests */ DO_TEST("addr-single-sata-disk"); -- 2.51.2
On 11/26/25 18:03, Roman Bogorodskiy wrote:
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev,
break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1;
This is a bit unfortunate as many of our public APIs (e.g. virDomainDetachDevice()) try to match <interface/> using its MAC address first. OTOH, they can find a match using other values specific to individual device and we specifically document that device XML should be passed full.
+ } + if (net->guestIP.nips) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting IP addresses for SLIRP networking is not supported")); + return -1; + } + } + }
Michal
Michal Prívozník wrote:
On 11/26/25 18:03, Roman Bogorodskiy wrote:
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev,
break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1;
This is a bit unfortunate as many of our public APIs (e.g. virDomainDetachDevice()) try to match <interface/> using its MAC address first. OTOH, they can find a match using other values specific to individual device and we specifically document that device XML should be passed full.
Thanks for taking time to point that out. I looked to check how hard would that be to support that, but apparently, it's already there, just not mentioned in the manual page [1]. I'll push the series with this chunk removed after one more round of testing. 1: https://reviews.freebsd.org/D54133
+ } + if (net->guestIP.nips) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting IP addresses for SLIRP networking is not supported")); + return -1; + } + } + }
Michal
On 12/8/25 1:02 PM, Roman Bogorodskiy wrote:
Michal Prívozník wrote:
On 11/26/25 18:03, Roman Bogorodskiy wrote:
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev,
break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1;
This is a bit unfortunate as many of our public APIs (e.g. virDomainDetachDevice()) try to match <interface/> using its MAC address first. OTOH, they can find a match using other values specific to individual device and we specifically document that device XML should be passed full.
Thanks for taking time to point that out. I looked to check how hard would that be to support that, but apparently, it's already there, just not mentioned in the manual page [1].
I'll push the series with this chunk removed after one more round of testing.
(just now noticed this - I haven't been paying attention :-/) Whether or not the user provides a MAC address, the config that's stored on disk will contain one (either user-supplied or auto-generated), and that MAC address won't be honored, which could be confusing to users. When a MAC address isn't specified for <interface> we will always generate one prior to saving the config, so that the same MAC setting will persist across restarts of the guest; doing otherwise wreaks havoc in the guest OS - any time the MAC address changes, it will think there is a new network device and want to configure it (MS Windows does this even if the MAC address of the default router changes). (Of course I'm assuming that bhyve makes the guest NIC appear with a random MAC; does it instead always use the same hard-coded MAC address? What if someone puts two slirp-backed interfaces in the config?)
Laine Stump wrote:
On 12/8/25 1:02 PM, Roman Bogorodskiy wrote:
Michal Prívozník wrote:
On 11/26/25 18:03, Roman Bogorodskiy wrote:
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev, break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1;
This is a bit unfortunate as many of our public APIs (e.g. virDomainDetachDevice()) try to match <interface/> using its MAC address first. OTOH, they can find a match using other values specific to individual device and we specifically document that device XML should be passed full.
Thanks for taking time to point that out. I looked to check how hard would that be to support that, but apparently, it's already there, just not mentioned in the manual page [1].
I'll push the series with this chunk removed after one more round of testing.
(just now noticed this - I haven't been paying attention :-/)
Whether or not the user provides a MAC address, the config that's stored on disk will contain one (either user-supplied or auto-generated), and that MAC address won't be honored, which could be confusing to users.
When a MAC address isn't specified for <interface> we will always generate one prior to saving the config, so that the same MAC setting will persist across restarts of the guest; doing otherwise wreaks havoc in the guest OS - any time the MAC address changes, it will think there is a new network device and want to configure it (MS Windows does this even if the MAC address of the default router changes). (Of course I'm assuming that bhyve makes the guest NIC appear with a random MAC; does it instead always use the same hard-coded MAC address? What if someone puts two slirp-backed interfaces in the config?)
Could you please take a look at the v2 version of this series? I think it has these issues addressed. Roman
On 12/15/25 12:00 PM, Roman Bogorodskiy wrote:
Laine Stump wrote:
On 12/8/25 1:02 PM, Roman Bogorodskiy wrote:
Michal Prívozník wrote:
On 11/26/25 18:03, Roman Bogorodskiy wrote:
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev, break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1;
This is a bit unfortunate as many of our public APIs (e.g. virDomainDetachDevice()) try to match <interface/> using its MAC address first. OTOH, they can find a match using other values specific to individual device and we specifically document that device XML should be passed full.
Thanks for taking time to point that out. I looked to check how hard would that be to support that, but apparently, it's already there, just not mentioned in the manual page [1].
I'll push the series with this chunk removed after one more round of testing.
(just now noticed this - I haven't been paying attention :-/)
Whether or not the user provides a MAC address, the config that's stored on disk will contain one (either user-supplied or auto-generated), and that MAC address won't be honored, which could be confusing to users.
When a MAC address isn't specified for <interface> we will always generate one prior to saving the config, so that the same MAC setting will persist across restarts of the guest; doing otherwise wreaks havoc in the guest OS - any time the MAC address changes, it will think there is a new network device and want to configure it (MS Windows does this even if the MAC address of the default router changes). (Of course I'm assuming that bhyve makes the guest NIC appear with a random MAC; does it instead always use the same hard-coded MAC address? What if someone puts two slirp-backed interfaces in the config?)
Could you please take a look at the v2 version of this series? I think it has these issues addressed.
Ah, sorry - I hadn't gotten that far yet :-). So did you just add the mac address option to bhyve, or was it always there and you just weren't using it before? (I just added my r-b to the revised patch, with a note that the bhyve commandline example should have "mac=blah" added).
Laine Stump wrote:
On 12/15/25 12:00 PM, Roman Bogorodskiy wrote:
Laine Stump wrote:
On 12/8/25 1:02 PM, Roman Bogorodskiy wrote:
Michal Prívozník wrote:
On 11/26/25 18:03, Roman Bogorodskiy wrote:
SLIRP networking in bhyve doesn't support MAC and IP addresses configuration, so update the validation code to check that these options are not specified.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/bhyve/bhyve_domain.c | 17 +++++++++++++- .../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++++++++ .../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++++++++ tests/bhyvexml2argvtest.c | 2 ++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index 4c9ed29333..5c1ed86df6 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -325,6 +325,22 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev, break; } + case VIR_DOMAIN_DEVICE_NET: { + virDomainNetDef *net = dev->data.net; + + if (net->type == VIR_DOMAIN_NET_TYPE_USER) { + if (!net->mac_generated) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("setting MAC address for SLIRP networking is not supported")); + return -1;
This is a bit unfortunate as many of our public APIs (e.g. virDomainDetachDevice()) try to match <interface/> using its MAC address first. OTOH, they can find a match using other values specific to individual device and we specifically document that device XML should be passed full.
Thanks for taking time to point that out. I looked to check how hard would that be to support that, but apparently, it's already there, just not mentioned in the manual page [1].
I'll push the series with this chunk removed after one more round of testing.
(just now noticed this - I haven't been paying attention :-/)
Whether or not the user provides a MAC address, the config that's stored on disk will contain one (either user-supplied or auto-generated), and that MAC address won't be honored, which could be confusing to users.
When a MAC address isn't specified for <interface> we will always generate one prior to saving the config, so that the same MAC setting will persist across restarts of the guest; doing otherwise wreaks havoc in the guest OS - any time the MAC address changes, it will think there is a new network device and want to configure it (MS Windows does this even if the MAC address of the default router changes). (Of course I'm assuming that bhyve makes the guest NIC appear with a random MAC; does it instead always use the same hard-coded MAC address? What if someone puts two slirp-backed interfaces in the config?)
Could you please take a look at the v2 version of this series? I think it has these issues addressed.
Ah, sorry - I hadn't gotten that far yet :-). So did you just add the mac address option to bhyve, or was it always there and you just weren't using it before? (I just added my r-b to the revised patch, with a note that the bhyve commandline example should have "mac=blah" added).
The option for mac was already there, but not documented. What's needed on bhyve side now is to document that and to allow MTU configuration, which is not directly related to this series, I believe. Thanks, Roman
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- docs/drvbhyve.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/drvbhyve.rst b/docs/drvbhyve.rst index c0f4cd8a1f..7cf5fc9efb 100644 --- a/docs/drvbhyve.rst +++ b/docs/drvbhyve.rst @@ -694,6 +694,30 @@ Users must configure the device for passthrough manually either by using ``devctl(8)`` or by setting ``pptdevs`` in ``loader.conf(5)``. Please refer to the ``vmm(4)`` manual page for more details. +SLIRP networking +~~~~~~~~~~~~~~~~ +:since:`Since 11.11.0`, it is possible to use SLIRP networking. + +Example: + +:: + + ... + <interface type='user'> + <model type='e1000'/> + </interface> + ... + +Then the guest will have external network connectivity without +any configuration on the host. + +.. note:: + This configuration requires SLIRP open mode support by ``bhyve``. + It was introduced in FreeBSD -CURRENT in this commit: + https://cgit.FreeBSD.org/src/commit/?id=0e62ebd20172f67283bac9526c2aaeaffeb4.... + Unfortunately, there is no (easy) way to probe its support in libvirt, + so please consult the ``bhyve(8)`` manual page to make sure it is available. + Guest-specific considerations ----------------------------- -- 2.51.2
On 11/26/25 18:03, Roman Bogorodskiy wrote:
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- docs/drvbhyve.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
diff --git a/docs/drvbhyve.rst b/docs/drvbhyve.rst index c0f4cd8a1f..7cf5fc9efb 100644 --- a/docs/drvbhyve.rst +++ b/docs/drvbhyve.rst @@ -694,6 +694,30 @@ Users must configure the device for passthrough manually either by using ``devctl(8)`` or by setting ``pptdevs`` in ``loader.conf(5)``. Please refer to the ``vmm(4)`` manual page for more details.
+SLIRP networking +~~~~~~~~~~~~~~~~ +:since:`Since 11.11.0`, it is possible to use SLIRP networking. + +Example: + +:: + + ... + <interface type='user'> + <model type='e1000'/> + </interface> + ... + +Then the guest will have external network connectivity without +any configuration on the host. + +.. note:: + This configuration requires SLIRP open mode support by ``bhyve``. + It was introduced in FreeBSD -CURRENT in this commit: + https://cgit.FreeBSD.org/src/commit/?id=0e62ebd20172f67283bac9526c2aaeaffeb4.... + Unfortunately, there is no (easy) way to probe its support in libvirt, + so please consult the ``bhyve(8)`` manual page to make sure it is available. + Guest-specific considerations -----------------------------
To all three patches: Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (3)
-
Laine Stump -
Michal Prívozník -
Roman Bogorodskiy