Skip to content

Commit

Permalink
qapi: net: add stream and dgram netdevs
Browse files Browse the repository at this point in the history
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 (off 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 <[email protected]>
Reviewed-by: Stefano Brivio <[email protected]>
Acked-by: Markus Armbruster <[email protected]>
Acked-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
  • Loading branch information
vivier authored and jasowang committed Oct 28, 2022
1 parent 53b85d9 commit 5166fe0
Show file tree
Hide file tree
Showing 9 changed files with 1,078 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ ERST
{
.name = "netdev_add",
.args_type = "netdev:O",
.params = "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user"
.params = "[user|tap|socket|stream|dgram|vde|bridge|hubport|netmap|vhost-user"
#ifdef CONFIG_VMNET
"|vmnet-host|vmnet-shared|vmnet-bridged"
#endif
Expand Down
6 changes: 6 additions & 0 deletions net/clients.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ int net_init_hubport(const Netdev *netdev, const char *name,
int net_init_socket(const Netdev *netdev, const char *name,
NetClientState *peer, Error **errp);

int net_init_stream(const Netdev *netdev, const char *name,
NetClientState *peer, Error **errp);

int net_init_dgram(const Netdev *netdev, const char *name,
NetClientState *peer, Error **errp);

int net_init_tap(const Netdev *netdev, const char *name,
NetClientState *peer, Error **errp);

Expand Down
Loading

0 comments on commit 5166fe0

Please sign in to comment.