Some options require macOS 11 or newer APIs. Instead of crashing (target
version not set) or failing to compile (target version set), we will just
return an error when the user tries to use the option.
Signed-off-by: Joelle van Dyne <j@getutm.app>
---
net/vmnet-host.c | 48 +++++++++++++++++++++++++++++++--------------
net/vmnet-shared.c | 23 +++++++++++++++++-----
net/vmnet-bridged.m | 18 ++++++++++++++---
3 files changed, 66 insertions(+), 23 deletions(-)
diff --git a/net/vmnet-host.c b/net/vmnet-host.c
index 49fb25c224..f3f0ac89e4 100644
--- a/net/vmnet-host.c
+++ b/net/vmnet-host.c
@@ -21,12 +21,28 @@
static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetHostOptions *options = &(netdev->u.vmnet_host);
- QemuUUID net_uuid;
- if (options->net_uuid &&
- qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
- error_setg(errp, "Invalid UUID provided in 'net-uuid'");
- return false;
+ if (__builtin_available(macOS 11, *)) {
+ QemuUUID net_uuid;
+ if (options->net_uuid &&
+ qemu_uuid_parse(options->net_uuid, &net_uuid) < 0) {
+ error_setg(errp, "Invalid UUID provided in 'net-uuid'");
+ return false;
+ }
+ } else {
+ if (options->has_isolated) {
+ error_setg(errp,
+ "vmnet-host.isolated feature is "
+ "unavailable: outdated vmnet.framework API");
+ return false;
+ }
+
+ if (options->net_uuid) {
+ error_setg(errp,
+ "vmnet-host.net-uuid feature is "
+ "unavailable: outdated vmnet.framework API");
+ return false;
+ }
}
if ((options->start_address ||
@@ -53,16 +69,18 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_operation_mode_key,
VMNET_HOST_MODE);
- xpc_dictionary_set_bool(if_desc,
- vmnet_enable_isolation_key,
- options->isolated);
-
- QemuUUID net_uuid;
- if (options->net_uuid) {
- qemu_uuid_parse(options->net_uuid, &net_uuid);
- xpc_dictionary_set_uuid(if_desc,
- vmnet_network_identifier_key,
- net_uuid.data);
+ if (__builtin_available(macOS 11, *)) {
+ xpc_dictionary_set_bool(if_desc,
+ vmnet_enable_isolation_key,
+ options->isolated);
+
+ QemuUUID net_uuid;
+ if (options->net_uuid) {
+ qemu_uuid_parse(options->net_uuid, &net_uuid);
+ xpc_dictionary_set_uuid(if_desc,
+ vmnet_network_identifier_key,
+ net_uuid.data);
+ }
}
if (options->start_address) {
diff --git a/net/vmnet-shared.c b/net/vmnet-shared.c
index 4726b07253..e6c65f3417 100644
--- a/net/vmnet-shared.c
+++ b/net/vmnet-shared.c
@@ -21,6 +21,17 @@ static bool validate_options(const Netdev *netdev, Error **errp)
{
const NetdevVmnetSharedOptions *options = &(netdev->u.vmnet_shared);
+ if (__builtin_available(macOS 11, *)) {
+ /* clang requires a true branch */
+ } else {
+ if (options->has_isolated) {
+ error_setg(errp,
+ "vmnet-shared.isolated feature is "
+ "unavailable: outdated vmnet.framework API");
+ return false;
+ }
+ }
+
if ((options->start_address ||
options->end_address ||
options->subnet_mask) &&
@@ -66,11 +77,13 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
options->subnet_mask);
}
- xpc_dictionary_set_bool(
- if_desc,
- vmnet_enable_isolation_key,
- options->isolated
- );
+ if (__builtin_available(macOS 11, *)) {
+ xpc_dictionary_set_bool(
+ if_desc,
+ vmnet_enable_isolation_key,
+ options->isolated
+ );
+ }
return if_desc;
}
diff --git a/net/vmnet-bridged.m b/net/vmnet-bridged.m
index a04a14fa11..13fa2d16b6 100644
--- a/net/vmnet-bridged.m
+++ b/net/vmnet-bridged.m
@@ -88,6 +88,16 @@ static bool validate_options(const Netdev *netdev, Error **errp)
return false;
}
+ if (__builtin_available(macOS 11, *)) {
+ /* clang requires a true branch */
+ } else {
+ if (options->has_isolated) {
+ error_setg(errp,
+ "vmnet-bridged.isolated feature is "
+ "unavailable: outdated vmnet.framework API");
+ return false;
+ }
+ }
return true;
}
@@ -106,9 +116,11 @@ static xpc_object_t build_if_desc(const Netdev *netdev)
vmnet_shared_interface_name_key,
options->ifname);
- xpc_dictionary_set_bool(if_desc,
- vmnet_enable_isolation_key,
- options->isolated);
+ if (__builtin_available(macOS 11, *)) {
+ xpc_dictionary_set_bool(if_desc,
+ vmnet_enable_isolation_key,
+ options->isolated);
+ }
return if_desc;
}
--
2.41.0
© 2016 - 2024 Red Hat, Inc.