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>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
src/bhyve/bhyve_command.c | 10 ++++--
src/bhyve/bhyve_domain.c | 12 ++++++-
.../bhyvexml2argv-slirp-ip.xml | 22 +++++++++++++
.../bhyvexml2argv-slirp-mac-addr.args | 10 ++++++
.../bhyvexml2argv-slirp-mac-addr.ldargs | 4 +++
.../bhyvexml2argv-slirp-mac-addr.xml | 22 +++++++++++++
.../bhyvexml2argv-slirp.args | 10 ++++++
.../bhyvexml2argv-slirp.ldargs | 4 +++
.../bhyvexml2argvdata/bhyvexml2argv-slirp.xml | 21 ++++++++++++
tests/bhyvexml2argvtest.c | 3 ++
.../bhyvexml2xmlout-slirp.xml | 32 +++++++++++++++++++
tests/bhyvexml2xmltest.c | 1 +
12 files changed, 148 insertions(+), 3 deletions(-)
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-ip.xml
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.args
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.ldargs
create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.xml
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..4100bf1c05 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -83,6 +83,8 @@ bhyveBuildNetArgStr(const virDomainDef *def,
if (virDomainActualNetDefValidate(net) < 0)
return -1;
+ virMacAddrFormat(&net->mac, macaddr);
+
switch (actualType) {
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_BRIDGE:
@@ -93,9 +95,13 @@ bhyveBuildNetArgStr(const virDomainDef *def,
goto cleanup;
}
break;
+ case VIR_DOMAIN_NET_TYPE_USER:
+ virCommandAddArg(cmd, "-s");
+ virCommandAddArgFormat(cmd, "%d:0,%s,mac=%s,slirp,open",
+ net->info.addr.pci.slot, nic_model, macaddr);
+ 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:
@@ -144,7 +150,7 @@ bhyveBuildNetArgStr(const virDomainDef *def,
virCommandAddArg(cmd, "-s");
virCommandAddArgFormat(cmd, "%d:0,%s,%s,mac=%s",
net->info.addr.pci.slot, nic_model,
- realifname, virMacAddrFormat(&net->mac, macaddr));
+ realifname, macaddr);
ret = 0;
cleanup:
diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index 4c9ed29333..b9f9761b43 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -325,6 +325,17 @@ 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->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 +348,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.args b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.args
new file mode 100644
index 0000000000..0c766d157b
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.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,mac=00:11:22:33:44:56,slirp,open \
+bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.ldargs
new file mode 100644
index 0000000000..5905f4b3e6
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp-mac-addr.ldargs
@@ -0,0 +1,4 @@
+bhyveload \
+-m 214 \
+-d /tmp/freebsd.img \
+bhyve
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/bhyvexml2argvdata/bhyvexml2argv-slirp.args b/tests/bhyvexml2argvdata/bhyvexml2argv-slirp.args
new file mode 100644
index 0000000000..98666255e1
--- /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,mac=52:54:00:00:00:00,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..b83051d3cd 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -270,6 +270,9 @@ mymain(void)
DO_TEST("sata-rotation-rate");
DO_TEST_FAILURE("disk-virtio-rotation-rate");
DO_TEST_FAILURE("disk-virtio-queue-opts");
+ DO_TEST("slirp");
+ DO_TEST("slirp-mac-addr");
+ DO_TEST_FAILURE("slirp-ip");
/* 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
© 2016 - 2025 Red Hat, Inc.