qemu-options: Fix CXL Fixed Memory Window interleave-granularity typo
[qemu/kevin.git] / net / net-hmp-cmds.c
blob41d326bf5f135fc49450ffb286b223424ebbcd16
1 /*
2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu/osdep.h"
17 #include "migration/misc.h"
18 #include "monitor/hmp.h"
19 #include "monitor/monitor.h"
20 #include "net/net.h"
21 #include "net/hub.h"
22 #include "qapi/clone-visitor.h"
23 #include "qapi/qapi-commands-net.h"
24 #include "qapi/qapi-visit-net.h"
25 #include "qapi/qmp/qdict.h"
26 #include "qemu/config-file.h"
27 #include "qemu/help_option.h"
28 #include "qemu/option.h"
30 void hmp_info_network(Monitor *mon, const QDict *qdict)
32 NetClientState *nc, *peer;
33 NetClientDriver type;
35 net_hub_info(mon);
37 QTAILQ_FOREACH(nc, &net_clients, next) {
38 peer = nc->peer;
39 type = nc->info->type;
41 /* Skip if already printed in hub info */
42 if (net_hub_id_for_client(nc, NULL) == 0) {
43 continue;
46 if (!peer || type == NET_CLIENT_DRIVER_NIC) {
47 print_net_client(mon, nc);
48 } /* else it's a netdev connected to a NIC, printed with the NIC */
49 if (peer && type == NET_CLIENT_DRIVER_NIC) {
50 monitor_printf(mon, " \\ ");
51 print_net_client(mon, peer);
56 void hmp_set_link(Monitor *mon, const QDict *qdict)
58 const char *name = qdict_get_str(qdict, "name");
59 bool up = qdict_get_bool(qdict, "up");
60 Error *err = NULL;
62 qmp_set_link(name, up, &err);
63 hmp_handle_error(mon, err);
67 void hmp_announce_self(Monitor *mon, const QDict *qdict)
69 const char *interfaces_str = qdict_get_try_str(qdict, "interfaces");
70 const char *id = qdict_get_try_str(qdict, "id");
71 AnnounceParameters *params = QAPI_CLONE(AnnounceParameters,
72 migrate_announce_params());
74 qapi_free_strList(params->interfaces);
75 params->interfaces = hmp_split_at_comma(interfaces_str);
76 params->has_interfaces = params->interfaces != NULL;
77 params->id = g_strdup(id);
78 qmp_announce_self(params, NULL);
79 qapi_free_AnnounceParameters(params);
82 void hmp_netdev_add(Monitor *mon, const QDict *qdict)
84 Error *err = NULL;
85 QemuOpts *opts;
86 const char *type = qdict_get_try_str(qdict, "type");
88 if (type && is_help_option(type)) {
89 show_netdevs();
90 return;
92 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
93 if (err) {
94 goto out;
97 netdev_add(opts, &err);
98 if (err) {
99 qemu_opts_del(opts);
102 out:
103 hmp_handle_error(mon, err);
106 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
108 const char *id = qdict_get_str(qdict, "id");
109 Error *err = NULL;
111 qmp_netdev_del(id, &err);
112 hmp_handle_error(mon, err);
116 void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
118 size_t len;
119 int i;
121 if (nb_args != 2) {
122 return;
124 len = strlen(str);
125 readline_set_completion_index(rs, len);
126 for (i = 0; i < NET_CLIENT_DRIVER__MAX; i++) {
127 readline_add_completion_of(rs, str, NetClientDriver_str(i));
131 void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
133 size_t len;
135 len = strlen(str);
136 readline_set_completion_index(rs, len);
137 if (nb_args == 2) {
138 NetClientState *ncs[MAX_QUEUE_NUM];
139 int count, i;
140 count = qemu_find_net_clients_except(NULL, ncs,
141 NET_CLIENT_DRIVER_NONE,
142 MAX_QUEUE_NUM);
143 for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
144 readline_add_completion_of(rs, str, ncs[i]->name);
146 } else if (nb_args == 3) {
147 readline_add_completion_of(rs, str, "on");
148 readline_add_completion_of(rs, str, "off");
152 void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
154 int len, count, i;
155 NetClientState *ncs[MAX_QUEUE_NUM];
157 if (nb_args != 2) {
158 return;
161 len = strlen(str);
162 readline_set_completion_index(rs, len);
163 count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_DRIVER_NIC,
164 MAX_QUEUE_NUM);
165 for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
166 if (ncs[i]->is_netdev) {
167 readline_add_completion_of(rs, str, ncs[i]->name);