system/physmem: use return value of ram_block_discard_require() as errno
[qemu/armbru.git] / net / vmnet-shared.c
blob4726b072536f974e89dab880d8be97af2329a46b
1 /*
2 * vmnet-shared.c
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.
9 */
11 #include "qemu/osdep.h"
12 #include "qapi/qapi-types-net.h"
13 #include "qapi/error.h"
14 #include "vmnet_int.h"
15 #include "clients.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)) {
30 error_setg(errp,
31 "'start-address', 'end-address', 'subnet-mask' "
32 "should be provided together"
34 return false;
37 return true;
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(
46 if_desc,
47 vmnet_operation_mode_key,
48 VMNET_SHARED_MODE
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(
70 if_desc,
71 vmnet_enable_isolation_key,
72 options->isolated
75 return if_desc;
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);
90 xpc_object_t if_desc;
91 int result = -1;
93 if (!validate_options(netdev, errp)) {
94 return result;
97 if_desc = build_if_desc(netdev);
98 result = vmnet_if_create(nc, if_desc, errp);
99 xpc_release(if_desc);
100 return result;