2 * Human Monitor Interface commands
4 * Copyright IBM, Corp. 2011
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"
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
;
37 QTAILQ_FOREACH(nc
, &net_clients
, next
) {
39 type
= nc
->info
->type
;
41 /* Skip if already printed in hub info */
42 if (net_hub_id_for_client(nc
, NULL
) == 0) {
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");
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
)
86 const char *type
= qdict_get_try_str(qdict
, "type");
88 if (type
&& is_help_option(type
)) {
92 opts
= qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict
, &err
);
97 netdev_add(opts
, &err
);
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");
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
)
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
)
136 readline_set_completion_index(rs
, len
);
138 NetClientState
*ncs
[MAX_QUEUE_NUM
];
140 count
= qemu_find_net_clients_except(NULL
, ncs
,
141 NET_CLIENT_DRIVER_NONE
,
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
)
155 NetClientState
*ncs
[MAX_QUEUE_NUM
];
162 readline_set_completion_index(rs
, len
);
163 count
= qemu_find_net_clients_except(NULL
, ncs
, NET_CLIENT_DRIVER_NIC
,
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
);