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 ((options
->start_address
||
25 options
->end_address
||
26 options
->subnet_mask
) &&
27 !(options
->start_address
&&
28 options
->end_address
&&
29 options
->subnet_mask
)) {
31 "'start-address', 'end-address', 'subnet-mask' "
32 "should be provided together"
40 static xpc_object_t
build_if_desc(const Netdev
*netdev
)
42 const NetdevVmnetSharedOptions
*options
= &(netdev
->u
.vmnet_shared
);
43 xpc_object_t if_desc
= xpc_dictionary_create(NULL
, NULL
, 0);
45 xpc_dictionary_set_uint64(
47 vmnet_operation_mode_key
,
51 if (options
->nat66_prefix
) {
52 xpc_dictionary_set_string(if_desc
,
53 vmnet_nat66_prefix_key
,
54 options
->nat66_prefix
);
57 if (options
->start_address
) {
58 xpc_dictionary_set_string(if_desc
,
59 vmnet_start_address_key
,
60 options
->start_address
);
61 xpc_dictionary_set_string(if_desc
,
62 vmnet_end_address_key
,
63 options
->end_address
);
64 xpc_dictionary_set_string(if_desc
,
65 vmnet_subnet_mask_key
,
66 options
->subnet_mask
);
69 xpc_dictionary_set_bool(
71 vmnet_enable_isolation_key
,
78 static NetClientInfo net_vmnet_shared_info
= {
79 .type
= NET_CLIENT_DRIVER_VMNET_SHARED
,
80 .size
= sizeof(VmnetState
),
81 .receive
= vmnet_receive_common
,
82 .cleanup
= vmnet_cleanup_common
,
85 int net_init_vmnet_shared(const Netdev
*netdev
, const char *name
,
86 NetClientState
*peer
, Error
**errp
)
88 NetClientState
*nc
= qemu_new_net_client(&net_vmnet_shared_info
,
89 peer
, "vmnet-shared", name
);
93 if (!validate_options(netdev
, errp
)) {
97 if_desc
= build_if_desc(netdev
);
98 result
= vmnet_if_create(nc
, if_desc
, errp
);