Re: [RFC PATCH v2 3/8] qapi: net: add stream and dgram netdevs

2022-06-20 Thread Laurent Vivier

On 20/06/2022 13:22, Markus Armbruster wrote:

Laurent Vivier  writes:


On 15/06/2022 13:46, Markus Armbruster wrote:

Laurent Vivier  writes:


On 13/05/2022 13:44, Markus Armbruster wrote:

Laurent Vivier  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)

Signed-off-by: Laurent Vivier 
---
hmp-commands.hx |   2 +-
net/clients.h   |   6 +
net/dgram.c | 630 
net/hub.c   |   2 +
net/meson.build |   2 +
net/net.c   |  24 +-
net/stream.c| 425 
qapi/net.json   |  38 ++-
8 files changed, 1125 insertions(+), 4 deletions(-)
create mode 100644 net/dgram.c
create mode 100644 net/stream.c


...

diff --git a/net/net.c b/net/net.c
index 2aab7167316c..fd6b30a10c57 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1015,6 +1015,8 @@ static int (* const 
net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
#endif
[NET_CLIENT_DRIVER_TAP]   = net_init_tap,
[NET_CLIENT_DRIVER_SOCKET]= net_init_socket,
+[NET_CLIENT_DRIVER_STREAM]= net_init_stream,
+[NET_CLIENT_DRIVER_DGRAM] = net_init_dgram,
#ifdef CONFIG_VDE
[NET_CLIENT_DRIVER_VDE]   = net_init_vde,
#endif
@@ -1097,6 +1099,8 @@ void show_netdevs(void)
int idx;
const char *available_netdevs[] = {
"socket",
+"stream",
+"dgram",
"hubport",
"tap",
#ifdef CONFIG_SLIRP
@@ -1606,7 +1610,25 @@ int net_init_clients(Error **errp)
 */
static bool netdev_is_modern(const char *optarg)
{
-return false;
+static QemuOptsList dummy_opts = {
+.name = "netdev",
+.implied_opt_name = "type",
+.head = QTAILQ_HEAD_INITIALIZER(dummy_opts.head),
+.desc = { { } },
+};
+const char *netdev;
+QemuOpts *opts;
+bool is_modern;
+
+opts = qemu_opts_parse(_opts, optarg, true, _fatal);
+netdev = qemu_opt_get(opts, "type");
+
+is_modern = strcmp(netdev, "stream") == 0 ||
+strcmp(netdev, "dgram") == 0;


Crashes when user neglects to pass "type".


I think "type" is always passed because of the '.implied_opt_name = "type"'. Am 
I wrong?


.implied_opt_name = "type" lets you shorten "type=T,..." to "T,...".  It
doesn't make key "type" mandatory.  "-netdev id=foo" is still permitted.
Even "-netdev ''" is.



In fact type is checked before by QAPI definition:

{ 'union': 'Netdev',
'base': { 'id': 'str', 'type': 'NetClientDriver' },
'discriminator': 'type',
...

As it's the discriminator it must be there.

$ qemu-system-x86_64 -netdev id=foo
qemu-system-x86_64: -netdev id=foo: Parameter 'type' is missing


It does crash for me:

 (gdb) bt
 #0  0x74d25dcb in __strcmp_avx2 () at /lib64/libc.so.6
 #1  0x55b4574b in netdev_is_modern (optarg=0x7fffe2ae "id=foo")
 at ../net/net.c:1626
 #2  0x55b457ad in net_client_parse
 (opts_list=0x56563780 , optarg=0x7fffe2ae 
"id=foo") at ../net/net.c:1636
 #3  0x55ad98de in qemu_init (argc=3, argv=0x7fffdf08, envp=0x0)
 at ../softmmu/vl.c:2901
 #4  0x55842c01 in qemu_main (argc=3, argv=0x7fffdf08, envp=0x0)
 at ../softmmu/main.c:35
 #5  0x55842c37 in main (argc=3, argv=0x7fffdf08)
 at ../softmmu/main.c:45
 (gdb) up
 #1  0x55b4574b in netdev_is_modern (optarg=0x7fffe2ae "id=foo")
 at ../net/net.c:1626
 1626   is_modern = strcmp(netdev, "stream") == 0 ||
 (gdb) p netdev
 $1 = 0x0

This is

  https://github.com/patchew-project/qemu 
tags/patchew/20220512080932.735962-1-lviv...@redhat.com

I suspect you tested with your v3, which doesn't crash for me, either.



Yes, thank you. So this is fixed now :)

Laurent




Re: [RFC PATCH v2 3/8] qapi: net: add stream and dgram netdevs

2022-06-20 Thread Markus Armbruster
Laurent Vivier  writes:

> On 15/06/2022 13:46, Markus Armbruster wrote:
>> Laurent Vivier  writes:
>> 
>>> On 13/05/2022 13:44, Markus Armbruster wrote:
 Laurent Vivier  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)
>
> Signed-off-by: Laurent Vivier 
> ---
>hmp-commands.hx |   2 +-
>net/clients.h   |   6 +
>net/dgram.c | 630 
>net/hub.c   |   2 +
>net/meson.build |   2 +
>net/net.c   |  24 +-
>net/stream.c| 425 
>qapi/net.json   |  38 ++-
>8 files changed, 1125 insertions(+), 4 deletions(-)
>create mode 100644 net/dgram.c
>create mode 100644 net/stream.c
>
> ...
> diff --git a/net/net.c b/net/net.c
> index 2aab7167316c..fd6b30a10c57 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -1015,6 +1015,8 @@ static int (* const 
> net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
>#endif
>[NET_CLIENT_DRIVER_TAP]   = net_init_tap,
>[NET_CLIENT_DRIVER_SOCKET]= net_init_socket,
> +[NET_CLIENT_DRIVER_STREAM]= net_init_stream,
> +[NET_CLIENT_DRIVER_DGRAM] = net_init_dgram,
>#ifdef CONFIG_VDE
>[NET_CLIENT_DRIVER_VDE]   = net_init_vde,
>#endif
> @@ -1097,6 +1099,8 @@ void show_netdevs(void)
>int idx;
>const char *available_netdevs[] = {
>"socket",
> +"stream",
> +"dgram",
>"hubport",
>"tap",
>#ifdef CONFIG_SLIRP
> @@ -1606,7 +1610,25 @@ int net_init_clients(Error **errp)
> */
>static bool netdev_is_modern(const char *optarg)
>{
> -return false;
> +static QemuOptsList dummy_opts = {
> +.name = "netdev",
> +.implied_opt_name = "type",
> +.head = QTAILQ_HEAD_INITIALIZER(dummy_opts.head),
> +.desc = { { } },
> +};
> +const char *netdev;
> +QemuOpts *opts;
> +bool is_modern;
> +
> +opts = qemu_opts_parse(_opts, optarg, true, _fatal);
> +netdev = qemu_opt_get(opts, "type");
> +
> +is_modern = strcmp(netdev, "stream") == 0 ||
> +strcmp(netdev, "dgram") == 0;

 Crashes when user neglects to pass "type".
>>>
>>> I think "type" is always passed because of the '.implied_opt_name = 
>>> "type"'. Am I wrong?
>> 
>> .implied_opt_name = "type" lets you shorten "type=T,..." to "T,...".  It
>> doesn't make key "type" mandatory.  "-netdev id=foo" is still permitted.
>> Even "-netdev ''" is.
>
>
> In fact type is checked before by QAPI definition:
>
> { 'union': 'Netdev',
>'base': { 'id': 'str', 'type': 'NetClientDriver' },
>'discriminator': 'type',
> ...
>
> As it's the discriminator it must be there.
>
>$ qemu-system-x86_64 -netdev id=foo
>qemu-system-x86_64: -netdev id=foo: Parameter 'type' is missing

It does crash for me:

(gdb) bt
#0  0x74d25dcb in __strcmp_avx2 () at /lib64/libc.so.6
#1  0x55b4574b in netdev_is_modern (optarg=0x7fffe2ae "id=foo")
at ../net/net.c:1626
#2  0x55b457ad in net_client_parse
(opts_list=0x56563780 , optarg=0x7fffe2ae 
"id=foo") at ../net/net.c:1636
#3  0x55ad98de in qemu_init (argc=3, argv=0x7fffdf08, envp=0x0)
at ../softmmu/vl.c:2901
#4  0x55842c01 in qemu_main (argc=3, argv=0x7fffdf08, envp=0x0)
at ../softmmu/main.c:35
#5  0x55842c37 in main (argc=3, argv=0x7fffdf08)
at ../softmmu/main.c:45
(gdb) up
#1  0x55b4574b in netdev_is_modern (optarg=0x7fffe2ae "id=foo")
at ../net/net.c:1626
1626is_modern = strcmp(netdev, "stream") == 0 ||
(gdb) p netdev
$1 = 0x0

This is

 https://github.com/patchew-project/qemu 
tags/patchew/20220512080932.735962-1-lviv...@redhat.com 

I suspect you tested with your v3, which doesn't crash for me, either.

[...]




Re: [RFC PATCH v2 3/8] qapi: net: add stream and dgram netdevs

2022-06-20 Thread Laurent Vivier

On 15/06/2022 13:46, Markus Armbruster wrote:

Laurent Vivier  writes:


On 13/05/2022 13:44, Markus Armbruster wrote:

Laurent Vivier  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)

Signed-off-by: Laurent Vivier 
---
   hmp-commands.hx |   2 +-
   net/clients.h   |   6 +
   net/dgram.c | 630 
   net/hub.c   |   2 +
   net/meson.build |   2 +
   net/net.c   |  24 +-
   net/stream.c| 425 
   qapi/net.json   |  38 ++-
   8 files changed, 1125 insertions(+), 4 deletions(-)
   create mode 100644 net/dgram.c
   create mode 100644 net/stream.c


...

diff --git a/net/net.c b/net/net.c
index 2aab7167316c..fd6b30a10c57 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1015,6 +1015,8 @@ static int (* const 
net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
   #endif
   [NET_CLIENT_DRIVER_TAP]   = net_init_tap,
   [NET_CLIENT_DRIVER_SOCKET]= net_init_socket,
+[NET_CLIENT_DRIVER_STREAM]= net_init_stream,
+[NET_CLIENT_DRIVER_DGRAM] = net_init_dgram,
   #ifdef CONFIG_VDE
   [NET_CLIENT_DRIVER_VDE]   = net_init_vde,
   #endif
@@ -1097,6 +1099,8 @@ void show_netdevs(void)
   int idx;
   const char *available_netdevs[] = {
   "socket",
+"stream",
+"dgram",
   "hubport",
   "tap",
   #ifdef CONFIG_SLIRP
@@ -1606,7 +1610,25 @@ int net_init_clients(Error **errp)
*/
   static bool netdev_is_modern(const char *optarg)
   {
-return false;
+static QemuOptsList dummy_opts = {
+.name = "netdev",
+.implied_opt_name = "type",
+.head = QTAILQ_HEAD_INITIALIZER(dummy_opts.head),
+.desc = { { } },
+};
+const char *netdev;
+QemuOpts *opts;
+bool is_modern;
+
+opts = qemu_opts_parse(_opts, optarg, true, _fatal);
+netdev = qemu_opt_get(opts, "type");
+
+is_modern = strcmp(netdev, "stream") == 0 ||
+strcmp(netdev, "dgram") == 0;


Crashes when user neglects to pass "type".


I think "type" is always passed because of the '.implied_opt_name = "type"'. Am 
I wrong?


.implied_opt_name = "type" lets you shorten "type=T,..." to "T,...".  It
doesn't make key "type" mandatory.  "-netdev id=foo" is still permitted.
Even "-netdev ''" is.



In fact type is checked before by QAPI definition:

{ 'union': 'Netdev',
  'base': { 'id': 'str', 'type': 'NetClientDriver' },
  'discriminator': 'type',
...

As it's the discriminator it must be there.

  $ qemu-system-x86_64 -netdev id=foo
  qemu-system-x86_64: -netdev id=foo: Parameter 'type' is missing

...

diff --git a/qapi/net.json b/qapi/net.json
index b92f3f5fb444..eef26e1b 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -7,6 +7,7 @@
   ##
   
   { 'include': 'common.json' }

+{ 'include': 'sockets.json' }
   
   ##

   # @set_link:
@@ -452,6 +453,37 @@
   '*vhostdev': 'str',
   '*queues':   'int' } }
   
+##

+# @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)
+#
+# Since: 7.1
+##
+{ 'struct': 'NetdevStreamOptions',
+  'data': {
+'addr':   'SocketAddress',
+'*server': 'bool' } }
+
+##
+# @NetdevDgramOptions:
+#
+# Configuration info for datagram socket netdev.
+#
+# @remote: remote address
+# @local: local address


Defaults?


We can't have a default because for multicast default is remoTe, and for 
unicast default
is local.


Well, the members are optional, so there must be some default behavior,
which may or may not correspond to a single default value.  Regardless,
what happens when a member is absent ought to be documented.


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.
I've updated qemu-options.hx with that syntax.

Thanks,
Laurent




Re: [RFC PATCH v2 3/8] qapi: net: add stream and dgram netdevs

2022-06-15 Thread Markus Armbruster
Laurent Vivier  writes:

> On 13/05/2022 13:44, Markus Armbruster wrote:
>> Laurent Vivier  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)
>>>
>>> Signed-off-by: Laurent Vivier 
>>> ---
>>>   hmp-commands.hx |   2 +-
>>>   net/clients.h   |   6 +
>>>   net/dgram.c | 630 
>>>   net/hub.c   |   2 +
>>>   net/meson.build |   2 +
>>>   net/net.c   |  24 +-
>>>   net/stream.c| 425 
>>>   qapi/net.json   |  38 ++-
>>>   8 files changed, 1125 insertions(+), 4 deletions(-)
>>>   create mode 100644 net/dgram.c
>>>   create mode 100644 net/stream.c
>>>
>>> diff --git a/hmp-commands.hx b/hmp-commands.hx
>>> index 03e6a73d1f55..172dbab1dfed 100644
>>> --- a/hmp-commands.hx
>>> +++ b/hmp-commands.hx
>>> @@ -1269,7 +1269,7 @@ ERST
>>>   {
>>>   .name   = "netdev_add",
>>>   .args_type  = "netdev:O",
>>> -.params = 
>>> "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
>>> +.params = 
>>> "[user|tap|socket|stream|dgram|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
>>>   .help   = "add host network device",
>>>   .cmd= hmp_netdev_add,
>>>   .command_completion = netdev_add_completion,
>> 
>> Does qemu-options.hx need an update, too?
>
> Done
>
>> 
>>> diff --git a/net/clients.h b/net/clients.h
>>> index 92f9b59aedce..c1b51d79b147 100644
>>> --- a/net/clients.h
>>> +++ b/net/clients.h
>>> @@ -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);
>>>   
>>> diff --git a/net/dgram.c b/net/dgram.c
>>> new file mode 100644
>>> index ..aa4240501ed0
>>> --- /dev/null
>>> +++ b/net/dgram.c
>>> @@ -0,0 +1,630 @@
>>> +/*
>>> + * QEMU System Emulator
>>> + *
>>> + * Copyright (c) 2003-2008 Fabrice Bellard
>>> + *
>>> + * Permission is hereby granted, free of charge, to any person obtaining a 
>>> copy
>>> + * of this software and associated documentation files (the "Software"), 
>>> to deal
>>> + * in the Software without restriction, including without limitation the 
>>> rights
>>> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or 
>>> sell
>>> + * copies of the Software, and to permit persons to whom the Software is
>>> + * furnished to do so, subject to the following conditions:
>>> + *
>>> + * The above copyright notice and this permission notice shall be included 
>>> in
>>> + * all copies or substantial portions of the Software.
>>> + *
>>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
>>> OR
>>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
>>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
>>> OTHER
>>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
>>> FROM,
>>> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
>>> IN
>>> + * THE SOFTWARE.
>>> + */
>> 
>> Blank line here, please.
>> 
>> Why not GPLv2+?
>
> I've kept the original text copied from net/socket.c, but I can move this to 
> GPL2+

If the file's contents is derived from net/socket.c, copying the
legalese from there makes sense.

>>> +#include "qemu/osdep.h"
>> 
>> [...]
>> 
>>> diff --git a/net/net.c b/net/net.c
>>> index 2aab7167316c..fd6b30a10c57 100644
>>> --- a/net/net.c
>>> +++ b/net/net.c
>>> @@ -1015,6 +1015,8 @@ static int (* const 
>>> net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
>>>   #endif
>>>   [NET_CLIENT_DRIVER_TAP]   = net_init_tap,
>>>   [NET_CLIENT_DRIVER_SOCKET]= net_init_socket,
>>> +[NET_CLIENT_DRIVER_STREAM]= net_init_stream,
>>> +[NET_CLIENT_DRIVER_DGRAM] = net_init_dgram,
>>>   #ifdef CONFIG_VDE
>>>   [NET_CLIENT_DRIVER_VDE]   = net_init_vde,
>>>   #endif
>>> @@ -1097,6 +1099,8 @@ void show_netdevs(void)
>>>   int idx;
>>>   const char *available_netdevs[] = {
>>>   "socket",
>>> +"stream",

Re: [RFC PATCH v2 3/8] qapi: net: add stream and dgram netdevs

2022-06-14 Thread Laurent Vivier

On 13/05/2022 13:44, Markus Armbruster wrote:

Laurent Vivier  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)

Signed-off-by: Laurent Vivier 
---
  hmp-commands.hx |   2 +-
  net/clients.h   |   6 +
  net/dgram.c | 630 
  net/hub.c   |   2 +
  net/meson.build |   2 +
  net/net.c   |  24 +-
  net/stream.c| 425 
  qapi/net.json   |  38 ++-
  8 files changed, 1125 insertions(+), 4 deletions(-)
  create mode 100644 net/dgram.c
  create mode 100644 net/stream.c

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 03e6a73d1f55..172dbab1dfed 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1269,7 +1269,7 @@ ERST
  {
  .name   = "netdev_add",
  .args_type  = "netdev:O",
-.params = 
"[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
+.params = 
"[user|tap|socket|stream|dgram|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
  .help   = "add host network device",
  .cmd= hmp_netdev_add,
  .command_completion = netdev_add_completion,


Does qemu-options.hx need an update, too?


Done




diff --git a/net/clients.h b/net/clients.h
index 92f9b59aedce..c1b51d79b147 100644
--- a/net/clients.h
+++ b/net/clients.h
@@ -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);
  
diff --git a/net/dgram.c b/net/dgram.c

new file mode 100644
index ..aa4240501ed0
--- /dev/null
+++ b/net/dgram.c
@@ -0,0 +1,630 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */


Blank line here, please.

Why not GPLv2+?


I've kept the original text copied from net/socket.c, but I can move this to 
GPL2+




+#include "qemu/osdep.h"


[...]


diff --git a/net/net.c b/net/net.c
index 2aab7167316c..fd6b30a10c57 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1015,6 +1015,8 @@ static int (* const 
net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
  #endif
  [NET_CLIENT_DRIVER_TAP]   = net_init_tap,
  [NET_CLIENT_DRIVER_SOCKET]= net_init_socket,
+[NET_CLIENT_DRIVER_STREAM]= net_init_stream,
+[NET_CLIENT_DRIVER_DGRAM] = net_init_dgram,
  #ifdef CONFIG_VDE
  [NET_CLIENT_DRIVER_VDE]   = net_init_vde,
  #endif
@@ -1097,6 +1099,8 @@ void show_netdevs(void)
  int idx;
  const char *available_netdevs[] = {
  "socket",
+"stream",
+"dgram",
  "hubport",
  "tap",
  #ifdef CONFIG_SLIRP
@@ -1606,7 +1610,25 @@ int net_init_clients(Error **errp)
   */
  static bool netdev_is_modern(const char *optarg)
  {
-return false;
+static QemuOptsList dummy_opts = {
+.name = "netdev",
+.implied_opt_name = "type",
+.head = QTAILQ_HEAD_INITIALIZER(dummy_opts.head),
+.desc = { { } },
+};
+const char *netdev;
+QemuOpts *opts;
+bool is_modern;
+
+opts = qemu_opts_parse(_opts, optarg, true, _fatal);
+netdev = qemu_opt_get(opts, "type");
+
+is_modern = 

Re: [RFC PATCH v2 3/8] qapi: net: add stream and dgram netdevs

2022-05-13 Thread Markus Armbruster
Laurent Vivier  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)
>
> Signed-off-by: Laurent Vivier 
> ---
>  hmp-commands.hx |   2 +-
>  net/clients.h   |   6 +
>  net/dgram.c | 630 
>  net/hub.c   |   2 +
>  net/meson.build |   2 +
>  net/net.c   |  24 +-
>  net/stream.c| 425 
>  qapi/net.json   |  38 ++-
>  8 files changed, 1125 insertions(+), 4 deletions(-)
>  create mode 100644 net/dgram.c
>  create mode 100644 net/stream.c
>
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index 03e6a73d1f55..172dbab1dfed 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1269,7 +1269,7 @@ ERST
>  {
>  .name   = "netdev_add",
>  .args_type  = "netdev:O",
> -.params = 
> "[user|tap|socket|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
> +.params = 
> "[user|tap|socket|stream|dgram|vde|bridge|hubport|netmap|vhost-user],id=str[,prop=value][,...]",
>  .help   = "add host network device",
>  .cmd= hmp_netdev_add,
>  .command_completion = netdev_add_completion,

Does qemu-options.hx need an update, too?

> diff --git a/net/clients.h b/net/clients.h
> index 92f9b59aedce..c1b51d79b147 100644
> --- a/net/clients.h
> +++ b/net/clients.h
> @@ -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);
>  
> diff --git a/net/dgram.c b/net/dgram.c
> new file mode 100644
> index ..aa4240501ed0
> --- /dev/null
> +++ b/net/dgram.c
> @@ -0,0 +1,630 @@
> +/*
> + * QEMU System Emulator
> + *
> + * Copyright (c) 2003-2008 Fabrice Bellard
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */

Blank line here, please.

Why not GPLv2+?

> +#include "qemu/osdep.h"

[...]

> diff --git a/net/net.c b/net/net.c
> index 2aab7167316c..fd6b30a10c57 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -1015,6 +1015,8 @@ static int (* const 
> net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
>  #endif
>  [NET_CLIENT_DRIVER_TAP]   = net_init_tap,
>  [NET_CLIENT_DRIVER_SOCKET]= net_init_socket,
> +[NET_CLIENT_DRIVER_STREAM]= net_init_stream,
> +[NET_CLIENT_DRIVER_DGRAM] = net_init_dgram,
>  #ifdef CONFIG_VDE
>  [NET_CLIENT_DRIVER_VDE]   = net_init_vde,
>  #endif
> @@ -1097,6 +1099,8 @@ void show_netdevs(void)
>  int idx;
>  const char *available_netdevs[] = {
>  "socket",
> +"stream",
> +"dgram",
>  "hubport",
>  "tap",
>  #ifdef CONFIG_SLIRP
> @@ -1606,7 +1610,25 @@ int net_init_clients(Error **errp)
>   */
>  static bool netdev_is_modern(const char *optarg)
>  {
> -return false;
> +static QemuOptsList dummy_opts = {
> +.name = "netdev",
> +.implied_opt_name = "type",
> +.head = QTAILQ_HEAD_INITIALIZER(dummy_opts.head),
> +.desc = { { } },
> +};
> +const char *netdev;
> +QemuOpts *opts;
> +bool is_modern;
> +
> +opts = qemu_opts_parse(_opts, optarg, true, _fatal);
> +