qemu-patch-raspberry4/net
Eric Blake db2a380c84 net: Complete qapi-fication of netdev_add
We've had all the required pieces for doing a type-safe representation
of netdev_add as a flat union for quite some time now (since
0e55c381f6 in v2.7.0, released in 2016), but did not make the final
switch to using it because of concern about whether a command-line
regression in accepting "1" in place of 1 for integer arguments would
be problematic.  Back then, we did not have the deprecation cycle to
allow us to make progress.  But now that we have waited so long, other
problems have crept in: for example, our desire to add
qemu-storage-daemon is hampered by the inability to express net
objects, and we are unable to introspect what we actually accept.
Additionally, our round-trip through QemuOpts silently eats any
argument that expands to an array, rendering dnssearch, hostfwd, and
guestfwd useless through QMP:

{"execute": "netdev_add", "arguments": { "id": "netdev0",
  "type": "user", "dnssearch": [
    { "str": "8.8.8.8" }, { "str": "8.8.4.4" }
  ]}}

So without further ado, let's turn on proper QAPI.  netdev_add() was a
trivial wrapper around net_client_init(), which did a few steps prior
to calling net_client_init1(); with this patch, we now skip directly
to net_client_init1().  In addition to fixing array parameters, the
following additional differences occur:

-  {"execute": "netdev_add", "arguments": {"type": "help"}}
no longer attempts to print help to stdout and exit.  Bug fix, broken
in 547203ead4 'net: List available netdevs with "-netdev help"',
v2.12.0.

-  {"execute": "netdev_add", "arguments': {... "ipv6-net": "..." }}
no longer attempts to desugar the undocumented ipv6-net magic string
into the proper "ipv6-prefix" and "ipv6-prefixlen".  Undocumented
misfeature, introduced in commit 7aac531ef2 "qapi-schema, qemu-options
& slirp: Adding Qemu options for IPv6 addresses", v2.6.0.

-  {'execute':'netdev_add',
     'arguments':{'id':'net2', 'type':'hubport', 'hubid':"2"}}
   {"error": {"class": "GenericError", "desc": "Invalid parameter type for 'hubid', expected: integer"}}
Used to succeed: since our command line treats everything as strings,
our not-so-round-trip conversion from QAPI -> QemuOpts -> QAPI lost
the original typing and turned everything into a string; now that we
skip the QemuOpts, the JSON input has to match the exact QAPI type.
But this stricter QMP is desirable, and introspection is sufficient
for any affected applications to make sure they use it correctly.

In qmp_netdev_add(), we still have to create a QemuOpts object so that
qmp_netdev_del() will be able to remove a hotplugged network device;
but the opts->head remains empty since we now manage all parsing
through the QAPI object rather than QemuOpts; a separate patch will
address the abuse of QemuOpts as a witness for whether a
NetClientState is a netdev.  In the meantime, our argument that we are
okay requires auditing all uses of option group "netdev":

- qemu_netdev_opts: option group definition, empty .desc[]
- CLI (CLI netdev parsing ends before monitors start, so while
  monitors can mess with CLI netdevs, CLI cannot mess with
  monitor netdevs):
  - main() case QEMU_OPTION_netdev: store CLI definition
  - main() case QEMU_OPTION_readconfig, case QEMU_OPTION_writeconfig:
  similar, dealing only with CLI
  - net_init_clients(): Pass CLI to net_client_init()
- Monitor:
  - hmp_netdev_add(): straightforward parse into net_client_init()
  - qmp_netdev_add(): subject of this patch, used to add full
  object to option group, now just adds bare-bones id
  - qmp_netdev_del(), netdev_del_completion(): check the option group
  solely for id, as a 'is this a netdev' predicate

Reported-by: Alex Kirillov <lekiravi@yandex-team.ru>
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200317201711.322764-2-eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Commit message typo fixed]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2020-03-17 21:50:14 +01:00
..
can qemu_log_lock/unlock now preserves the qemu_logfile handle. 2019-12-18 20:18:02 +00:00
announce.c net/announce: Add optional ID 2019-07-02 10:21:06 +08:00
checksum.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
clients.h Drop superfluous includes of qapi-types.h and test-qapi-types.h 2018-02-09 05:05:11 +01:00
colo-compare.c COLO-compare: Fix incorrect if logic 2019-10-29 10:28:07 +08:00
colo-compare.h colo-compare: use notifier to notify packets comparing result 2018-10-19 11:15:03 +08:00
colo.c net: do not depend on slirp internals 2019-01-14 00:44:29 +01:00
colo.h Clean up header guards that don't match their file name 2019-05-13 08:58:55 +02:00
dump.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
eth.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
filter-buffer.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
filter-mirror.c chardev: Use QEMUChrEvent enum in IOEventHandler typedef 2020-01-08 11:15:35 +01:00
filter-replay.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
filter-rewriter.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
filter.c net/filter.c: Add Options to insert filters anywhere in the filter list 2020-03-03 18:04:47 +08:00
hub.c net: Remove deprecated [hub_id name] tuple of 'hostfwd_add' / 'hostfwd_remove' 2020-03-09 18:44:04 +00:00
hub.h net: Remove deprecated [hub_id name] tuple of 'hostfwd_add' / 'hostfwd_remove' 2020-03-09 18:44:04 +00:00
l2tpv3.c Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
Makefile.objs build-sys: link with slirp as an external project 2019-03-07 12:46:31 +01:00
net.c net: Complete qapi-fication of netdev_add 2020-03-17 21:50:14 +01:00
netmap.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
queue.c qemu/queue.h: leave head structs anonymous unless necessary 2019-01-11 15:46:55 +01:00
slirp.c net: Remove deprecated [hub_id name] tuple of 'hostfwd_add' / 'hostfwd_remove' 2020-03-09 18:44:04 +00:00
socket.c net/socket: learn to talk with a unix dgram socket 2019-03-29 15:22:18 +08:00
tap-bsd.c Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
tap-linux.c Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
tap-linux.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
tap-solaris.c Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
tap-stub.c net/tap: Replace tap-haiku.c and tap-aix.c by a generic tap-stub.c 2017-05-23 10:10:38 +08:00
tap-win32.c Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
tap.c Include qemu/main-loop.h less 2019-08-16 13:31:52 +02:00
tap_int.h Include qemu-common.h exactly where needed 2019-06-12 13:20:20 +02:00
trace-events trace: Remove trailing newline in events 2019-09-18 10:19:47 +01:00
util.c net: Clean up includes 2016-02-04 17:41:30 +00:00
util.h net: do not depend on slirp internals 2019-01-14 00:44:29 +01:00
vde.c net/vde: print error on vde_open() failure 2018-03-26 14:52:43 +08:00
vhost-user-stub.c vhost-net-user: add stubs for when no virtio-net device is present 2019-02-21 12:28:01 -05:00
vhost-user.c chardev: Use QEMUChrEvent enum in IOEventHandler typedef 2020-01-08 11:15:35 +01:00