diff --git a/hmp-commands.hx b/hmp-commands.hx index 81723c87cc2959e750a1c0dc6c4a337f769c5ae5..d0ce6a597050dbab6d54802d49776bec9e21273a 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1037,8 +1037,7 @@ ETEXI .args_type = "netdev:O", .params = "[user|tap|socket],id=str[,prop=value][,...]", .help = "add host network device", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_netdev_add, + .mhandler.cmd = hmp_netdev_add, }, STEXI diff --git a/hmp.c b/hmp.c index 42ced2a202b4d8deab6416b5d894aba925e7dfa8..7a4e25f30cb9d6b3865e417f4394b834f32e69f1 100644 --- a/hmp.c +++ b/hmp.c @@ -14,6 +14,8 @@ */ #include "hmp.h" +#include "net.h" +#include "qemu-option.h" #include "qemu-timer.h" #include "qmp-commands.h" @@ -969,3 +971,22 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) &errp); hmp_handle_error(mon, &errp); } + +void hmp_netdev_add(Monitor *mon, const QDict *qdict) +{ + Error *err = NULL; + QemuOpts *opts; + + opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err); + if (error_is_set(&err)) { + goto out; + } + + netdev_add(opts, &err); + if (error_is_set(&err)) { + qemu_opts_del(opts); + } + +out: + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index 5cf3241af010bcf59c4e1a95a3bf35fa9ad25d3a..017df876236ed357172c2defc468c6c1803a012e 100644 --- a/hmp.h +++ b/hmp.h @@ -62,5 +62,6 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict); void hmp_migrate(Monitor *mon, const QDict *qdict); void hmp_device_del(Monitor *mon, const QDict *qdict); void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict); +void hmp_netdev_add(Monitor *mon, const QDict *qdict); #endif diff --git a/net.c b/net.c index 8f7cb40f79900c591375632364c3d415f78762d5..5f0c53cf72b40835a83fbb61cb934123b8f816ff 100644 --- a/net.c +++ b/net.c @@ -1234,27 +1234,39 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict) qemu_del_vlan_client(vc); } -int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) +void netdev_add(QemuOpts *opts, Error **errp) +{ + net_client_init(opts, 1, errp); +} + +int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret) { Error *local_err = NULL; + QemuOptsList *opts_list; QemuOpts *opts; - int res; - opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &local_err); - if (!opts) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + opts_list = qemu_find_opts_err("netdev", &local_err); + if (error_is_set(&local_err)) { + goto exit_err; } - res = net_client_init(opts, 1, &local_err); - if (res < 0) { - qerror_report_err(local_err); - error_free(local_err); + opts = qemu_opts_from_qdict(opts_list, qdict, &local_err); + if (error_is_set(&local_err)) { + goto exit_err; + } + + netdev_add(opts, &local_err); + if (error_is_set(&local_err)) { qemu_opts_del(opts); + goto exit_err; } - return res; + return 0; + +exit_err: + qerror_report_err(local_err); + error_free(local_err); + return -1; } int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data) diff --git a/net.h b/net.h index 7ee97e9fe23d7d9fa8e08b5f472b7ba4f7527409..1eb92800ec281f01368647da488fe397e660cb01 100644 --- a/net.h +++ b/net.h @@ -170,7 +170,8 @@ void net_check_clients(void); void net_cleanup(void); void net_host_device_add(Monitor *mon, const QDict *qdict); void net_host_device_remove(Monitor *mon, const QDict *qdict); -int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data); +void netdev_add(QemuOpts *opts, Error **errp); +int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret); int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data); #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" diff --git a/qapi-schema.json b/qapi-schema.json index dfa0e1f47aa3977bbc35ec3e3200e0ce9c1b41d4..69fcd8e3e658bb88f28391d58268dc5bfd82b21b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -1798,3 +1798,31 @@ { 'command': 'dump-guest-memory', 'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int', '*length': 'int' } } +## +# @netdev_add: +# +# Add a network backend. +# +# @type: the type of network backend. Current valid values are 'user', 'tap', +# 'vde', 'socket', 'dump' and 'bridge' +# +# @id: the name of the new network backend +# +# @props: #optional a list of properties to be passed to the backend in +# the format 'name=value', like 'ifname=tap0,script=no' +# +# Notes: The semantics of @props is not well defined. Future commands will be +# introduced that provide stronger typing for backend creation. +# +# Since: 0.14.0 +# +# Returns: Nothing on success +# If @type is not a valid network backend, DeviceNotFound +# If @id is not a valid identifier, InvalidParameterValue +# if @id already exists, DuplicateId +# If @props contains an invalid parameter for this backend, +# InvalidParameter +## +{ 'command': 'netdev_add', + 'data': {'type': 'str', 'id': 'str', '*props': '**'}, + 'gen': 'no' } diff --git a/qmp-commands.hx b/qmp-commands.hx index 2aa64add359b00b80e53d7b5df7d99c2f0786257..f6550cb9bd9312697be41435a4c7a7df46311589 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -642,10 +642,7 @@ EQMP { .name = "netdev_add", .args_type = "netdev:O", - .params = "[user|tap|socket],id=str[,prop=value][,...]", - .help = "add host network device", - .user_print = monitor_user_noop, - .mhandler.cmd_new = do_netdev_add, + .mhandler.cmd_new = qmp_netdev_add, }, SQMP