4 * Copyright(c) 2022 Vladislav Yaroshchuk <vladislav.yaroshchuk@jetbrains.com>
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
11 #include "qemu/osdep.h"
12 #include "qapi/qapi-types-net.h"
13 #include "qapi/error.h"
14 #include "vmnet_int.h"
17 #include <vmnet/vmnet.h>
20 static bool validate_options(const Netdev
*netdev
, Error
**errp
)
22 const NetdevVmnetSharedOptions
*options
= &(netdev
->u
.vmnet_shared
);
24 #if !defined(MAC_OS_VERSION_11_0) || \
25 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
26 if (options
->has_isolated
) {
28 "vmnet-shared.isolated feature is "
29 "unavailable: outdated vmnet.framework API");
34 if ((options
->start_address
||
35 options
->end_address
||
36 options
->subnet_mask
) &&
37 !(options
->start_address
&&
38 options
->end_address
&&
39 options
->subnet_mask
)) {
41 "'start-address', 'end-address', 'subnet-mask' "
42 "should be provided together"
50 static xpc_object_t
build_if_desc(const Netdev
*netdev
)
52 const NetdevVmnetSharedOptions
*options
= &(netdev
->u
.vmnet_shared
);
53 xpc_object_t if_desc
= xpc_dictionary_create(NULL
, NULL
, 0);
55 xpc_dictionary_set_uint64(
57 vmnet_operation_mode_key
,
61 if (options
->nat66_prefix
) {
62 xpc_dictionary_set_string(if_desc
,
63 vmnet_nat66_prefix_key
,
64 options
->nat66_prefix
);
67 if (options
->start_address
) {
68 xpc_dictionary_set_string(if_desc
,
69 vmnet_start_address_key
,
70 options
->start_address
);
71 xpc_dictionary_set_string(if_desc
,
72 vmnet_end_address_key
,
73 options
->end_address
);
74 xpc_dictionary_set_string(if_desc
,
75 vmnet_subnet_mask_key
,
76 options
->subnet_mask
);
79 #if defined(MAC_OS_VERSION_11_0) && \
80 MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
81 xpc_dictionary_set_bool(
83 vmnet_enable_isolation_key
,
91 static NetClientInfo net_vmnet_shared_info
= {
92 .type
= NET_CLIENT_DRIVER_VMNET_SHARED
,
93 .size
= sizeof(VmnetState
),
94 .receive
= vmnet_receive_common
,
95 .cleanup
= vmnet_cleanup_common
,
98 int net_init_vmnet_shared(const Netdev
*netdev
, const char *name
,
99 NetClientState
*peer
, Error
**errp
)
101 NetClientState
*nc
= qemu_new_net_client(&net_vmnet_shared_info
,
102 peer
, "vmnet-shared", name
);
103 xpc_object_t if_desc
;
106 if (!validate_options(netdev
, errp
)) {
110 if_desc
= build_if_desc(netdev
);
111 result
= vmnet_if_create(nc
, if_desc
, errp
);
112 xpc_release(if_desc
);