@@ -303,7 +303,12 @@
{ 'struct': 'ChardevUdp',
'data': { 'remote': 'SocketAddressLegacy',
'*local': 'SocketAddressLegacy' },
- 'base': 'ChardevCommon' }
+ 'base': 'ChardevCommon',
+ 'aliases': [
+ { 'source': ['remote'] },
+ { 'alias': 'localaddr', 'source': ['local', 'host'] },
+ { 'alias': 'localport', 'source': ['local', 'port'] }
+ ]}
##
# @ChardevMux:
@@ -23,9 +23,11 @@
*/
#include "qemu/osdep.h"
+#include "block/qdict.h"
#include "chardev/char.h"
#include "io/channel-socket.h"
#include "qapi/error.h"
+#include "qapi/qmp/qdict.h"
#include "qemu/module.h"
#include "qemu/option.h"
@@ -190,6 +192,36 @@ static void qemu_chr_parse_udp(QemuOpts *opts, ChardevBackend *backend,
}
}
+static void qemu_chr_translate_udp(QDict *args)
+{
+ QDict *remote;
+ QDict *local;
+
+ /*
+ * If "local" or "remote" are given, it's not a legacy command line.
+ * Not translating in this case saves us checking whether an alias is
+ * already given before applying defaults.
+ */
+ if (qdict_haskey(args, "local") || qdict_haskey(args, "remote")) {
+ return;
+ }
+
+ remote = qdict_new();
+ qdict_put_str(remote, "type", "inet");
+ qdict_put(args, "remote", remote);
+
+ qdict_set_default_str(args, "host", "localhost");
+
+ if (qdict_haskey(args, "localaddr") || qdict_haskey(args, "localport")) {
+ local = qdict_new();
+ qdict_put_str(local, "type", "inet");
+ qdict_put(args, "local", local);
+
+ qdict_set_default_str(args, "localaddr", "");
+ qdict_set_default_str(args, "localport", "0");
+ }
+}
+
static void qmp_chardev_open_udp(Chardev *chr,
ChardevBackend *backend,
bool *be_opened,
@@ -225,6 +257,7 @@ static void char_udp_class_init(ObjectClass *oc, void *data)
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->parse = qemu_chr_parse_udp;
+ cc->translate_legacy_options = qemu_chr_translate_udp;
cc->open = qmp_chardev_open_udp;
cc->chr_write = udp_chr_write;
cc->chr_update_read_handler = udp_chr_update_read_handler;
@@ -744,7 +744,6 @@ void qemu_chr_translate_legacy_options(QDict *args)
/*
* TODO:
* All backend types: "mux"
- * udp: defaults for "host"/"localaddr"/"localport"
*/
}
UDP backends have a few differences between CLI and QMP. This adds QAPI aliases and a .translate_legacy_options() implementation that converts CLI inputs to a form that's usable for a QAPIfied --chardev. Signed-off-by: Kevin Wolf <kwolf@redhat.com> --- qapi/char.json | 7 ++++++- chardev/char-udp.c | 33 +++++++++++++++++++++++++++++++++ chardev/char.c | 1 - 3 files changed, 39 insertions(+), 2 deletions(-)