[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v7 05/14] qapi: net: add stream and dgram netdevs
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v7 05/14] qapi: net: add stream and dgram netdevs |
Date: |
Tue, 02 Aug 2022 10:37:23 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
Laurent Vivier <lvivier@redhat.com> writes:
> Copied from socket netdev file and modified to use SocketAddress
> to be able to introduce new features like unix socket.
>
> "udp" and "mcast" are squashed into dgram netdev, multicast is detected
> according to the IP address type.
> "listen" and "connect" modes are managed by stream netdev. An optional
> parameter "server" defines the mode (server by default)
>
> The two new types need to be parsed the modern way with -netdev, because
> with the traditional way, the "type" field of netdev structure collides with
> the "type" field of SocketAddress and prevents the correct evaluation of the
> command line option. Moreover the traditional way doesn't allow to use
> the same type (SocketAddress) several times with the -netdev option
> (needed to specify "local" and "remote" addresses).
>
> The previous commit paved the way for parsing the modern way, but
> omitted one detail: how to pick modern vs. traditional, in
> netdev_is_modern().
>
> We want to pick based on the value of parameter "type". But how to
> extract it from the option argument?
>
> Parsing the option argument, either the modern or the traditional way,
> extracts it for us, but only if parsing succeeds.
>
> If parsing fails, there is no good option. No matter which parser we
> pick, it'll be the wrong one for some arguments, and the error
> reporting will be confusing.
>
> Fortunately, the traditional parser accepts *anything* when called in
> a certain way. This maximizes our chance to extract the value of
> "type", and in turn minimizes the risk of confusing error reporting.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
[...]
> diff --git a/qapi/net.json b/qapi/net.json
> index 75ba2cb98901..a7506a40ff12 100644
> --- a/qapi/net.json
> +++ b/qapi/net.json
> @@ -7,6 +7,7 @@
> ##
>
> { 'include': 'common.json' }
> +{ 'include': 'sockets.json' }
>
> ##
> # @set_link:
> @@ -573,6 +574,61 @@
> '*isolated': 'bool' },
> 'if': 'CONFIG_VMNET' }
>
> +##
> +# @NetdevStreamOptions:
> +#
> +# Configuration info for stream socket netdev
> +#
> +# @addr: socket address to listen on (server=true)
> +# or connect to (server=false)
> +# @server: create server socket (default: true)
> +#
> +# Only SocketAddress types 'inet' and 'fd' are supported.
> +#
> +# Since: 7.1
> +##
> +{ 'struct': 'NetdevStreamOptions',
> + 'data': {
> + 'addr': 'SocketAddress',
> + '*server': 'bool' } }
> +
> +##
> +# @NetdevDgramOptions:
> +#
> +# Configuration info for datagram socket netdev.
> +#
> +# @remote: remote address
> +# @local: local address
> +#
> +# Only SocketAddress types 'inet' and 'fd' are supported.
> +#
> +# The code checks there is at least one of these options and reports an error
> +# if not. If remote address is present and it's a multicast address, local
> +# address is optional. Otherwise local address is required and remote address
> +# is optional.
> +#
> +# .. table:: Valid parameters combination table
> +# :widths: auto
> +#
> +# ============= ======== =====
> +# remote local okay?
> +# ============= ======== =====
> +# absent absent no
> +# absent not fd no
> +# absent fd yes
> +# multicast absent yes
> +# multicast present yes
> +# not multicast absent no
> +# not multicast present yes
> +# ============= ======== =====
Looks good now.
> +#
> +# Since: 7.1
> +##
> +{ 'struct': 'NetdevDgramOptions',
> + 'data': {
> + '*local': 'SocketAddress',
> + '*remote': 'SocketAddress' } }
> +
> ##
> # @NetClientDriver:
> #
> @@ -586,8 +642,9 @@
> # @vmnet-bridged since 7.1
> ##
> { 'enum': 'NetClientDriver',
> - 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde',
> - 'bridge', 'hubport', 'netmap', 'vhost-user', 'vhost-vdpa',
> + 'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'stream',
> + 'dgram', 'vde', 'bridge', 'hubport', 'netmap', 'vhost-user',
> + 'vhost-vdpa',
> { 'name': 'vmnet-host', 'if': 'CONFIG_VMNET' },
> { 'name': 'vmnet-shared', 'if': 'CONFIG_VMNET' },
> { 'name': 'vmnet-bridged', 'if': 'CONFIG_VMNET' }] }
> @@ -617,6 +674,8 @@
> 'tap': 'NetdevTapOptions',
> 'l2tpv3': 'NetdevL2TPv3Options',
> 'socket': 'NetdevSocketOptions',
> + 'stream': 'NetdevStreamOptions',
> + 'dgram': 'NetdevDgramOptions',
> 'vde': 'NetdevVdeOptions',
> 'bridge': 'NetdevBridgeOptions',
> 'hubport': 'NetdevHubPortOptions',
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 79e00916a11f..170117e1adf0 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2726,6 +2726,18 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev,
> "-netdev socket,id=str[,fd=h][,udp=host:port][,localaddr=host:port]\n"
> " configure a network backend to connect to another
> network\n"
> " using an UDP tunnel\n"
> + "-netdev
> stream,id=str[,server=on|off],addr.type=inet,addr.host=host,addr.port=port\n"
> + "-netdev stream,id=str[,server=on|off],addr.type=fd,addr.str=h\n"
> + " configure a network backend to connect to another
> network\n"
> + " using a socket connection in stream mode.\n"
> + "-netdev
> dgram,id=str,remote.type=inet,remote.host=maddr,remote.port=port[,local.type=inet,local.host=addr]\n"
> + "-netdev
> dgram,id=str,remote.type=inet,remote.host=maddr,remote.port=port[,local.type=fd,local.str=h]\n"
> + " configure a network backend to connect to a multicast
> maddr and port\n"
> + " use ``local.host=addr`` to specify the host address to
> send packets from\n"
> + "-netdev
> dgram,id=str,local.type=inet,local.host=addr,local.port=port[,remote.type=inet,remote.host=addr,remote.port=port]\n"
> + "-netdev dgram,id=str,local.type=fd,local.str=h\n"
> + " configure a network backend to connect to another
> network\n"
> + " using an UDP tunnel\n"
> #ifdef CONFIG_VDE
> "-netdev
> vde,id=str[,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
> " configure a network backend to connect to port 'n' of a
> vde switch\n"
I had a few questions on this part in review of v6. Care to reply
there?
- Re: [PATCH v7 05/14] qapi: net: add stream and dgram netdevs,
Markus Armbruster <=