1
The following changes since commit aa90f1161bb17a4863e16ec2f75104cff0752d4e:
1
The following changes since commit 6157b0e19721aadb4c7fdcfe57b2924af6144b14:
2
2
3
Merge tag 'migration-20250314-pull-request' of https://gitlab.com/farosas/qemu into staging (2025-03-16 02:45:22 -0400)
3
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-6.0-pull-request' into staging (2021-03-14 17:47:49 +0000)
4
4
5
are available in the Git repository at:
5
are available in the git repository at:
6
6
7
https://github.com/jasowang/qemu.git tags/net-pull-request
7
https://github.com/jasowang/qemu.git tags/net-pull-request
8
8
9
for you to fetch changes up to b027f55a994af885a7a498a40373a2dcc2d8b15e:
9
for you to fetch changes up to f2e8319d456724c3d8514d943dc4607e2f08e88a:
10
10
11
vdpa: Allow vDPA to work on big-endian machine (2025-03-17 13:46:28 +0800)
11
net: Do not fill legacy info_str for backends (2021-03-15 16:41:22 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
-----BEGIN PGP SIGNATURE-----
15
14
16
iQEzBAABCAAdFiEEIV1G9IJGaJ7HfzVi7wSWWzmNYhEFAmfX5/cACgkQ7wSWWzmN
15
Changes since V1:
17
YhFRHQgArp4daHmnfc4r8TNel7fBjeSTpfDGwQcUJbcljKK2ABtylcESAEg6tsAw
16
- drop the workaound of "-nic" id and fix the merge
18
aBzaZ2PwoTQfDV2s//g/d2uzd3BWH0Iu3qimsyBtx7Um7D4h7NsGB+gTB/7IhcK8
17
- add the series of query-netdev
19
1LjMHqDnaeS6fzJ93/umTXuyQLzA3tIFkJBzvxVseLrmv6uBPmAy+PDNe/uZ2jeF
20
2H20jNt/HMc1Yf7sE7NKTBkX+OxuIFkpOGcBtVxiPK1//Wmhw+v+zlQOFjUC+6CD
21
LxiBB0Q0tD7ekfbuF6x2SOnuzLDHgpMzgoGqLIYzeQhBX9TdHLM0LtEHHaMyW1pj
22
7mGPSY4avVSM1sePgtmNJ5Y5r/xTRA==
23
=e7Sc
24
-----END PGP SIGNATURE-----
25
18
26
----------------------------------------------------------------
19
----------------------------------------------------------------
27
Konstantin Shkolnyy (1):
20
Alexander Bulekov (4):
28
vdpa: Allow vDPA to work on big-endian machine
21
rtl8139: switch to use qemu_receive_packet() for loopback
22
pcnet: switch to use qemu_receive_packet() for loopback
23
cadence_gem: switch to use qemu_receive_packet() for loopback
24
lan9118: switch to use qemu_receive_packet() for loopback
29
25
30
net/vhost-vdpa.c | 13 +++++++++++++
26
Alexey Kirillov (5):
31
1 file changed, 13 insertions(+)
27
qapi: net: Add query-netdev command
28
tests: Add tests for query-netdev command
29
net: Move NetClientState.info_str to dynamic allocations
30
hmp: Use QAPI NetdevInfo in hmp_info_network
31
net: Do not fill legacy info_str for backends
32
33
Bin Meng (1):
34
net: Fix build error when DEBUG_NET is on
35
36
Cornelia Huck (1):
37
pvrdma: wean code off pvrdma_ring.h kernel header
38
39
Jason Wang (8):
40
virtio-net: calculating proper msix vectors on init
41
e1000: fail early for evil descriptor
42
net: introduce qemu_receive_packet()
43
e1000: switch to use qemu_receive_packet() for loopback
44
dp8393x: switch to use qemu_receive_packet() for loopback packet
45
msf2-mac: switch to use qemu_receive_packet() for loopback
46
sungem: switch to use qemu_receive_packet() for loopback
47
tx_pkt: switch to use qemu_receive_packet_iov() for loopback
48
49
Paolo Bonzini (1):
50
net: validate that ids are well formed
51
52
hw/core/machine.c | 1 +
53
hw/net/cadence_gem.c | 4 +-
54
hw/net/dp8393x.c | 2 +-
55
hw/net/e1000.c | 6 +-
56
hw/net/lan9118.c | 2 +-
57
hw/net/msf2-emac.c | 2 +-
58
hw/net/net_tx_pkt.c | 2 +-
59
hw/net/pcnet.c | 2 +-
60
hw/net/rtl8139.c | 2 +-
61
hw/net/sungem.c | 2 +-
62
hw/net/xen_nic.c | 5 +-
63
hw/rdma/vmw/pvrdma.h | 5 +-
64
hw/rdma/vmw/pvrdma_cmd.c | 6 +-
65
hw/rdma/vmw/pvrdma_dev_ring.c | 41 +++--
66
hw/rdma/vmw/pvrdma_dev_ring.h | 9 +-
67
hw/rdma/vmw/pvrdma_main.c | 4 +-
68
hw/virtio/virtio-net-pci.c | 10 +-
69
include/net/net.h | 10 +-
70
include/net/queue.h | 8 +
71
include/qapi/hmp-output-visitor.h | 30 ++++
72
.../drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h | 114 ------------
73
net/l2tpv3.c | 8 +-
74
net/net.c | 117 +++++++++++--
75
net/netmap.c | 7 +
76
net/queue.c | 22 +++
77
net/slirp.c | 124 ++++++++++++-
78
net/socket.c | 92 +++++++---
79
net/tap-win32.c | 10 +-
80
net/tap.c | 107 ++++++++++--
81
net/vde.c | 25 ++-
82
net/vhost-user.c | 20 ++-
83
net/vhost-vdpa.c | 15 +-
84
qapi/hmp-output-visitor.c | 193 +++++++++++++++++++++
85
qapi/meson.build | 1 +
86
qapi/net.json | 80 +++++++++
87
scripts/update-linux-headers.sh | 3 +-
88
tests/qtest/meson.build | 3 +
89
tests/qtest/test-query-netdev.c | 120 +++++++++++++
90
38 files changed, 990 insertions(+), 224 deletions(-)
91
create mode 100644 include/qapi/hmp-output-visitor.h
92
delete mode 100644 include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h
93
create mode 100644 qapi/hmp-output-visitor.c
94
create mode 100644 tests/qtest/test-query-netdev.c
95
96
97
diff view generated by jsdifflib
New patch
1
Currently, the default msix vectors for virtio-net-pci is 3 which is
2
obvious not suitable for multiqueue guest, so we depends on the user
3
or management tools to pass a correct vectors parameter. In fact, we
4
can simplifying this by calculating the number of vectors on realize.
1
5
6
Consider we have N queues, the number of vectors needed is 2*N + 2
7
(#queue pairs + plus one config interrupt and control vq). We didn't
8
check whether or not host support control vq because it was added
9
unconditionally by qemu to avoid breaking legacy guests such as Minix.
10
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com
12
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
13
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Signed-off-by: Jason Wang <jasowang@redhat.com>
15
---
16
hw/core/machine.c | 1 +
17
hw/virtio/virtio-net-pci.c | 10 +++++++++-
18
2 files changed, 10 insertions(+), 1 deletion(-)
19
20
diff --git a/hw/core/machine.c b/hw/core/machine.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/core/machine.c
23
+++ b/hw/core/machine.c
24
@@ -XXX,XX +XXX,XX @@
25
GlobalProperty hw_compat_5_2[] = {
26
{ "ICH9-LPC", "smm-compat", "on"},
27
{ "PIIX4_PM", "smm-compat", "on"},
28
+ { "virtio-net-pci", "vectors", "3"},
29
};
30
const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2);
31
32
diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/virtio/virtio-net-pci.c
35
+++ b/hw/virtio/virtio-net-pci.c
36
@@ -XXX,XX +XXX,XX @@ struct VirtIONetPCI {
37
static Property virtio_net_properties[] = {
38
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
39
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
40
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
41
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
42
+ DEV_NVECTORS_UNSPECIFIED),
43
DEFINE_PROP_END_OF_LIST(),
44
};
45
46
@@ -XXX,XX +XXX,XX @@ static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
47
DeviceState *qdev = DEVICE(vpci_dev);
48
VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
49
DeviceState *vdev = DEVICE(&dev->vdev);
50
+ VirtIONet *net = VIRTIO_NET(vdev);
51
+
52
+ if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
53
+ vpci_dev->nvectors = 2 * MAX(net->nic_conf.peers.queues, 1)
54
+ + 1 /* Config interrupt */
55
+ + 1 /* Control vq */;
56
+ }
57
58
virtio_net_set_netclient_name(&dev->vdev, qdev->id,
59
object_get_typename(OBJECT(qdev)));
60
--
61
2.7.4
62
63
diff view generated by jsdifflib
New patch
1
From: Bin Meng <bin.meng@windriver.com>
1
2
3
"qemu-common.h" should be included to provide the forward declaration
4
of qemu_hexdump() when DEBUG_NET is on.
5
6
Signed-off-by: Bin Meng <bin.meng@windriver.com>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
---
10
net/net.c | 1 +
11
1 file changed, 1 insertion(+)
12
13
diff --git a/net/net.c b/net/net.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/net/net.c
16
+++ b/net/net.c
17
@@ -XXX,XX +XXX,XX @@
18
*/
19
20
#include "qemu/osdep.h"
21
+#include "qemu-common.h"
22
23
#include "net/net.h"
24
#include "clients.h"
25
--
26
2.7.4
27
28
diff view generated by jsdifflib
New patch
1
From: Paolo Bonzini <pbonzini@redhat.com>
1
2
3
When a network or network device is created from the command line or HMP,
4
QemuOpts ensures that the id passes the id_wellformed check. However,
5
QMP skips this:
6
7
$ qemu-system-x86_64 -qmp stdio -S -nic user,id=123/456
8
qemu-system-x86_64: -nic user,id=123/456: Parameter id expects an identifier
9
Identifiers consist of letters, digits, -, ., _, starting with a letter.
10
11
$ qemu-system-x86_64 -qmp stdio -S
12
{"execute":"qmp_capabilities"}
13
{"return": {}}
14
{"execute":"netdev_add", "arguments": {"type": "user", "id": "123/456"}}
15
{"return": {}}
16
17
After:
18
19
$ qemu-system-x86_64 -qmp stdio -S
20
{"execute":"qmp_capabilities"}
21
{"return": {}}
22
{"execute":"netdev_add", "arguments": {"type": "user", "id": "123/456"}}
23
{"error": {"class": "GenericError", "desc": "Parameter "id" expects an identifier"}}
24
25
Validity checks should be performed always at the bottom of the call chain,
26
because QMP skips all the steps above. At the same time we know that every
27
call chain should go through either QMP or (for legacy) through QemuOpts.
28
Because the id for -net and -nic is automatically generated and not
29
well-formed by design, just add the check to QMP.
30
31
Cc: Jason Wang <jasowang@redhat.com>
32
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
33
Signed-off-by: Jason Wang <jasowang@redhat.com>
34
---
35
net/net.c | 5 +++++
36
1 file changed, 5 insertions(+)
37
38
diff --git a/net/net.c b/net/net.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/net/net.c
41
+++ b/net/net.c
42
@@ -XXX,XX +XXX,XX @@ void netdev_add(QemuOpts *opts, Error **errp)
43
44
void qmp_netdev_add(Netdev *netdev, Error **errp)
45
{
46
+ if (!id_wellformed(netdev->id)) {
47
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id", "an identifier");
48
+ return;
49
+ }
50
+
51
net_client_init1(netdev, true, errp);
52
}
53
54
--
55
2.7.4
56
57
diff view generated by jsdifflib
New patch
1
During procss_tx_desc(), driver can try to chain data descriptor with
2
legacy descriptor, when will lead underflow for the following
3
calculation in process_tx_desc() for bytes:
1
4
5
if (tp->size + bytes > msh)
6
bytes = msh - tp->size;
7
8
This will lead a infinite loop. So check and fail early if tp->size if
9
greater or equal to msh.
10
11
Reported-by: Alexander Bulekov <alxndr@bu.edu>
12
Reported-by: Cheolwoo Myung <cwmyung@snu.ac.kr>
13
Reported-by: Ruhr-University Bochum <bugs-syssec@rub.de>
14
Cc: Prasad J Pandit <ppandit@redhat.com>
15
Cc: qemu-stable@nongnu.org
16
Signed-off-by: Jason Wang <jasowang@redhat.com>
17
---
18
hw/net/e1000.c | 4 ++++
19
1 file changed, 4 insertions(+)
20
21
diff --git a/hw/net/e1000.c b/hw/net/e1000.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/net/e1000.c
24
+++ b/hw/net/e1000.c
25
@@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
26
msh = tp->tso_props.hdr_len + tp->tso_props.mss;
27
do {
28
bytes = split_size;
29
+ if (tp->size >= msh) {
30
+ goto eop;
31
+ }
32
if (tp->size + bytes > msh)
33
bytes = msh - tp->size;
34
35
@@ -XXX,XX +XXX,XX @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp)
36
tp->size += split_size;
37
}
38
39
+eop:
40
if (!(txd_lower & E1000_TXD_CMD_EOP))
41
return;
42
if (!(tp->cptse && tp->size < tp->tso_props.hdr_len)) {
43
--
44
2.7.4
45
46
diff view generated by jsdifflib
New patch
1
Some NIC supports loopback mode and this is done by calling
2
nc->info->receive() directly which in fact suppresses the effort of
3
reentrancy check that is done in qemu_net_queue_send().
1
4
5
Unfortunately we can't use qemu_net_queue_send() here since for
6
loopback there's no sender as peer, so this patch introduce a
7
qemu_receive_packet() which is used for implementing loopback mode
8
for a NIC with this check.
9
10
NIC that supports loopback mode will be converted to this helper.
11
12
This is intended to address CVE-2021-3416.
13
14
Cc: Prasad J Pandit <ppandit@redhat.com>
15
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
16
Cc: qemu-stable@nongnu.org
17
Signed-off-by: Jason Wang <jasowang@redhat.com>
18
---
19
include/net/net.h | 5 +++++
20
include/net/queue.h | 8 ++++++++
21
net/net.c | 38 +++++++++++++++++++++++++++++++-------
22
net/queue.c | 22 ++++++++++++++++++++++
23
4 files changed, 66 insertions(+), 7 deletions(-)
24
25
diff --git a/include/net/net.h b/include/net/net.h
26
index XXXXXXX..XXXXXXX 100644
27
--- a/include/net/net.h
28
+++ b/include/net/net.h
29
@@ -XXX,XX +XXX,XX @@ void *qemu_get_nic_opaque(NetClientState *nc);
30
void qemu_del_net_client(NetClientState *nc);
31
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
32
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
33
+int qemu_can_receive_packet(NetClientState *nc);
34
int qemu_can_send_packet(NetClientState *nc);
35
ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
36
int iovcnt);
37
ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
38
int iovcnt, NetPacketSent *sent_cb);
39
ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
40
+ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size);
41
+ssize_t qemu_receive_packet_iov(NetClientState *nc,
42
+ const struct iovec *iov,
43
+ int iovcnt);
44
ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size);
45
ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
46
int size, NetPacketSent *sent_cb);
47
diff --git a/include/net/queue.h b/include/net/queue.h
48
index XXXXXXX..XXXXXXX 100644
49
--- a/include/net/queue.h
50
+++ b/include/net/queue.h
51
@@ -XXX,XX +XXX,XX @@ void qemu_net_queue_append_iov(NetQueue *queue,
52
53
void qemu_del_net_queue(NetQueue *queue);
54
55
+ssize_t qemu_net_queue_receive(NetQueue *queue,
56
+ const uint8_t *data,
57
+ size_t size);
58
+
59
+ssize_t qemu_net_queue_receive_iov(NetQueue *queue,
60
+ const struct iovec *iov,
61
+ int iovcnt);
62
+
63
ssize_t qemu_net_queue_send(NetQueue *queue,
64
NetClientState *sender,
65
unsigned flags,
66
diff --git a/net/net.c b/net/net.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/net/net.c
69
+++ b/net/net.c
70
@@ -XXX,XX +XXX,XX @@ int qemu_set_vnet_be(NetClientState *nc, bool is_be)
71
#endif
72
}
73
74
+int qemu_can_receive_packet(NetClientState *nc)
75
+{
76
+ if (nc->receive_disabled) {
77
+ return 0;
78
+ } else if (nc->info->can_receive &&
79
+ !nc->info->can_receive(nc)) {
80
+ return 0;
81
+ }
82
+ return 1;
83
+}
84
+
85
int qemu_can_send_packet(NetClientState *sender)
86
{
87
int vm_running = runstate_is_running();
88
@@ -XXX,XX +XXX,XX @@ int qemu_can_send_packet(NetClientState *sender)
89
return 1;
90
}
91
92
- if (sender->peer->receive_disabled) {
93
- return 0;
94
- } else if (sender->peer->info->can_receive &&
95
- !sender->peer->info->can_receive(sender->peer)) {
96
- return 0;
97
- }
98
- return 1;
99
+ return qemu_can_receive_packet(sender->peer);
100
}
101
102
static ssize_t filter_receive_iov(NetClientState *nc,
103
@@ -XXX,XX +XXX,XX @@ ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size)
104
return qemu_send_packet_async(nc, buf, size, NULL);
105
}
106
107
+ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size)
108
+{
109
+ if (!qemu_can_receive_packet(nc)) {
110
+ return 0;
111
+ }
112
+
113
+ return qemu_net_queue_receive(nc->incoming_queue, buf, size);
114
+}
115
+
116
+ssize_t qemu_receive_packet_iov(NetClientState *nc, const struct iovec *iov,
117
+ int iovcnt)
118
+{
119
+ if (!qemu_can_receive_packet(nc)) {
120
+ return 0;
121
+ }
122
+
123
+ return qemu_net_queue_receive_iov(nc->incoming_queue, iov, iovcnt);
124
+}
125
+
126
ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size)
127
{
128
return qemu_send_packet_async_with_flags(nc, QEMU_NET_PACKET_FLAG_RAW,
129
diff --git a/net/queue.c b/net/queue.c
130
index XXXXXXX..XXXXXXX 100644
131
--- a/net/queue.c
132
+++ b/net/queue.c
133
@@ -XXX,XX +XXX,XX @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue,
134
return ret;
135
}
136
137
+ssize_t qemu_net_queue_receive(NetQueue *queue,
138
+ const uint8_t *data,
139
+ size_t size)
140
+{
141
+ if (queue->delivering) {
142
+ return 0;
143
+ }
144
+
145
+ return qemu_net_queue_deliver(queue, NULL, 0, data, size);
146
+}
147
+
148
+ssize_t qemu_net_queue_receive_iov(NetQueue *queue,
149
+ const struct iovec *iov,
150
+ int iovcnt)
151
+{
152
+ if (queue->delivering) {
153
+ return 0;
154
+ }
155
+
156
+ return qemu_net_queue_deliver_iov(queue, NULL, 0, iov, iovcnt);
157
+}
158
+
159
ssize_t qemu_net_queue_send(NetQueue *queue,
160
NetClientState *sender,
161
unsigned flags,
162
--
163
2.7.4
164
165
diff view generated by jsdifflib
New patch
1
This patch switches to use qemu_receive_packet() which can detect
2
reentrancy and return early.
1
3
4
This is intended to address CVE-2021-3416.
5
6
Cc: Prasad J Pandit <ppandit@redhat.com>
7
Cc: qemu-stable@nongnu.org
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
11
hw/net/e1000.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
diff --git a/hw/net/e1000.c b/hw/net/e1000.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/net/e1000.c
17
+++ b/hw/net/e1000.c
18
@@ -XXX,XX +XXX,XX @@ e1000_send_packet(E1000State *s, const uint8_t *buf, int size)
19
20
NetClientState *nc = qemu_get_queue(s->nic);
21
if (s->phy_reg[PHY_CTRL] & MII_CR_LOOPBACK) {
22
- nc->info->receive(nc, buf, size);
23
+ qemu_receive_packet(nc, buf, size);
24
} else {
25
qemu_send_packet(nc, buf, size);
26
}
27
--
28
2.7.4
29
30
diff view generated by jsdifflib
New patch
1
This patch switches to use qemu_receive_packet() which can detect
2
reentrancy and return early.
1
3
4
This is intended to address CVE-2021-3416.
5
6
Cc: Prasad J Pandit <ppandit@redhat.com>
7
Cc: qemu-stable@nongnu.org
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
11
hw/net/dp8393x.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
diff --git a/hw/net/dp8393x.c b/hw/net/dp8393x.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/net/dp8393x.c
17
+++ b/hw/net/dp8393x.c
18
@@ -XXX,XX +XXX,XX @@ static void dp8393x_do_transmit_packets(dp8393xState *s)
19
s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
20
if (nc->info->can_receive(nc)) {
21
s->loopback_packet = 1;
22
- nc->info->receive(nc, s->tx_buffer, tx_len);
23
+ qemu_receive_packet(nc, s->tx_buffer, tx_len);
24
}
25
} else {
26
/* Transmit packet */
27
--
28
2.7.4
29
30
diff view generated by jsdifflib
New patch
1
This patch switches to use qemu_receive_packet() which can detect
2
reentrancy and return early.
1
3
4
This is intended to address CVE-2021-3416.
5
6
Cc: Prasad J Pandit <ppandit@redhat.com>
7
Cc: qemu-stable@nongnu.org
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
11
hw/net/msf2-emac.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/net/msf2-emac.c
17
+++ b/hw/net/msf2-emac.c
18
@@ -XXX,XX +XXX,XX @@ static void msf2_dma_tx(MSF2EmacState *s)
19
* R_CFG1 bit 0 is set.
20
*/
21
if (s->regs[R_CFG1] & R_CFG1_LB_EN_MASK) {
22
- nc->info->receive(nc, buf, size);
23
+ qemu_receive_packet(nc, buf, size);
24
} else {
25
qemu_send_packet(nc, buf, size);
26
}
27
--
28
2.7.4
29
30
diff view generated by jsdifflib
New patch
1
This patch switches to use qemu_receive_packet() which can detect
2
reentrancy and return early.
1
3
4
This is intended to address CVE-2021-3416.
5
6
Cc: Prasad J Pandit <ppandit@redhat.com>
7
Cc: qemu-stable@nongnu.org
8
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
13
hw/net/sungem.c | 2 +-
14
1 file changed, 1 insertion(+), 1 deletion(-)
15
16
diff --git a/hw/net/sungem.c b/hw/net/sungem.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/net/sungem.c
19
+++ b/hw/net/sungem.c
20
@@ -XXX,XX +XXX,XX @@ static void sungem_send_packet(SunGEMState *s, const uint8_t *buf,
21
NetClientState *nc = qemu_get_queue(s->nic);
22
23
if (s->macregs[MAC_XIFCFG >> 2] & MAC_XIFCFG_LBCK) {
24
- nc->info->receive(nc, buf, size);
25
+ qemu_receive_packet(nc, buf, size);
26
} else {
27
qemu_send_packet(nc, buf, size);
28
}
29
--
30
2.7.4
31
32
diff view generated by jsdifflib
New patch
1
This patch switches to use qemu_receive_receive_iov() which can detect
2
reentrancy and return early.
1
3
4
This is intended to address CVE-2021-3416.
5
6
Cc: Prasad J Pandit <ppandit@redhat.com>
7
Cc: qemu-stable@nongnu.org
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
11
hw/net/net_tx_pkt.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/net/net_tx_pkt.c
17
+++ b/hw/net/net_tx_pkt.c
18
@@ -XXX,XX +XXX,XX @@ static inline void net_tx_pkt_sendv(struct NetTxPkt *pkt,
19
NetClientState *nc, const struct iovec *iov, int iov_cnt)
20
{
21
if (pkt->is_loopback) {
22
- nc->info->receive_iov(nc, iov, iov_cnt);
23
+ qemu_receive_packet_iov(nc, iov, iov_cnt);
24
} else {
25
qemu_sendv_packet(nc, iov, iov_cnt);
26
}
27
--
28
2.7.4
29
30
diff view generated by jsdifflib
New patch
1
From: Alexander Bulekov <alxndr@bu.edu>
1
2
3
This patch switches to use qemu_receive_packet() which can detect
4
reentrancy and return early.
5
6
This is intended to address CVE-2021-3416.
7
8
Cc: Prasad J Pandit <ppandit@redhat.com>
9
Cc: qemu-stable@nongnu.org
10
Buglink: https://bugs.launchpad.net/qemu/+bug/1910826
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com
12
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
15
hw/net/rtl8139.c | 2 +-
16
1 file changed, 1 insertion(+), 1 deletion(-)
17
18
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/net/rtl8139.c
21
+++ b/hw/net/rtl8139.c
22
@@ -XXX,XX +XXX,XX @@ static void rtl8139_transfer_frame(RTL8139State *s, uint8_t *buf, int size,
23
}
24
25
DPRINTF("+++ transmit loopback mode\n");
26
- rtl8139_do_receive(qemu_get_queue(s->nic), buf, size, do_interrupt);
27
+ qemu_receive_packet(qemu_get_queue(s->nic), buf, size);
28
29
if (iov) {
30
g_free(buf2);
31
--
32
2.7.4
33
34
diff view generated by jsdifflib
New patch
1
From: Alexander Bulekov <alxndr@bu.edu>
1
2
3
This patch switches to use qemu_receive_packet() which can detect
4
reentrancy and return early.
5
6
This is intended to address CVE-2021-3416.
7
8
Cc: Prasad J Pandit <ppandit@redhat.com>
9
Cc: qemu-stable@nongnu.org
10
Buglink: https://bugs.launchpad.net/qemu/+bug/1917085
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com
12
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
15
hw/net/pcnet.c | 2 +-
16
1 file changed, 1 insertion(+), 1 deletion(-)
17
18
diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/net/pcnet.c
21
+++ b/hw/net/pcnet.c
22
@@ -XXX,XX +XXX,XX @@ txagain:
23
if (BCR_SWSTYLE(s) == 1)
24
add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS);
25
s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC;
26
- pcnet_receive(qemu_get_queue(s->nic), s->buffer, s->xmit_pos);
27
+ qemu_receive_packet(qemu_get_queue(s->nic), s->buffer, s->xmit_pos);
28
s->looptest = 0;
29
} else {
30
if (s->nic) {
31
--
32
2.7.4
33
34
diff view generated by jsdifflib
New patch
1
From: Alexander Bulekov <alxndr@bu.edu>
1
2
3
This patch switches to use qemu_receive_packet() which can detect
4
reentrancy and return early.
5
6
This is intended to address CVE-2021-3416.
7
8
Cc: Prasad J Pandit <ppandit@redhat.com>
9
Cc: qemu-stable@nongnu.org
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
12
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
---
14
hw/net/cadence_gem.c | 4 ++--
15
1 file changed, 2 insertions(+), 2 deletions(-)
16
17
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/net/cadence_gem.c
20
+++ b/hw/net/cadence_gem.c
21
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
22
/* Send the packet somewhere */
23
if (s->phy_loop || (s->regs[GEM_NWCTRL] &
24
GEM_NWCTRL_LOCALLOOP)) {
25
- gem_receive(qemu_get_queue(s->nic), s->tx_packet,
26
- total_bytes);
27
+ qemu_receive_packet(qemu_get_queue(s->nic), s->tx_packet,
28
+ total_bytes);
29
} else {
30
qemu_send_packet(qemu_get_queue(s->nic), s->tx_packet,
31
total_bytes);
32
--
33
2.7.4
34
35
diff view generated by jsdifflib
New patch
1
From: Alexander Bulekov <alxndr@bu.edu>
1
2
3
This patch switches to use qemu_receive_packet() which can detect
4
reentrancy and return early.
5
6
This is intended to address CVE-2021-3416.
7
8
Cc: Prasad J Pandit <ppandit@redhat.com>
9
Cc: qemu-stable@nongnu.org
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com
11
Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
12
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
---
14
hw/net/lan9118.c | 2 +-
15
1 file changed, 1 insertion(+), 1 deletion(-)
16
17
diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/net/lan9118.c
20
+++ b/hw/net/lan9118.c
21
@@ -XXX,XX +XXX,XX @@ static void do_tx_packet(lan9118_state *s)
22
/* FIXME: Honor TX disable, and allow queueing of packets. */
23
if (s->phy_control & 0x4000) {
24
/* This assumes the receive routine doesn't touch the VLANClient. */
25
- lan9118_receive(qemu_get_queue(s->nic), s->txp->data, s->txp->len);
26
+ qemu_receive_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len);
27
} else {
28
qemu_send_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len);
29
}
30
--
31
2.7.4
32
33
diff view generated by jsdifflib
New patch
1
1
From: Cornelia Huck <cohuck@redhat.com>
2
3
The pvrdma code relies on the pvrdma_ring.h kernel header for some
4
basic ring buffer handling. The content of that header isn't very
5
exciting, but contains some (q)atomic_*() invocations that (a)
6
cause manual massaging when doing a headers update, and (b) are
7
an indication that we probably should not be importing that header
8
at all.
9
10
Let's reimplement the ring buffer handling directly in the pvrdma
11
code instead. This arguably also improves readability of the code.
12
13
Importing the header can now be dropped.
14
15
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
16
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
17
Reviewed-by: Yuval Shaia <yuval.shaia.ml@gmail.com>
18
Tested-by: Yuval Shaia <yuval.shaia.ml@gmail.com>
19
Signed-off-by: Jason Wang <jasowang@redhat.com>
20
---
21
hw/rdma/vmw/pvrdma.h | 5 +-
22
hw/rdma/vmw/pvrdma_cmd.c | 6 +-
23
hw/rdma/vmw/pvrdma_dev_ring.c | 41 ++++----
24
hw/rdma/vmw/pvrdma_dev_ring.h | 9 +-
25
hw/rdma/vmw/pvrdma_main.c | 4 +-
26
.../drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h | 114 ---------------------
27
scripts/update-linux-headers.sh | 3 +-
28
7 files changed, 38 insertions(+), 144 deletions(-)
29
delete mode 100644 include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h
30
31
diff --git a/hw/rdma/vmw/pvrdma.h b/hw/rdma/vmw/pvrdma.h
32
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/rdma/vmw/pvrdma.h
34
+++ b/hw/rdma/vmw/pvrdma.h
35
@@ -XXX,XX +XXX,XX @@
36
#include "../rdma_backend_defs.h"
37
#include "../rdma_rm_defs.h"
38
39
-#include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h"
40
#include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h"
41
#include "pvrdma_dev_ring.h"
42
#include "qom/object.h"
43
@@ -XXX,XX +XXX,XX @@ typedef struct DSRInfo {
44
union pvrdma_cmd_req *req;
45
union pvrdma_cmd_resp *rsp;
46
47
- struct pvrdma_ring *async_ring_state;
48
+ PvrdmaRingState *async_ring_state;
49
PvrdmaRing async;
50
51
- struct pvrdma_ring *cq_ring_state;
52
+ PvrdmaRingState *cq_ring_state;
53
PvrdmaRing cq;
54
} DSRInfo;
55
56
diff --git a/hw/rdma/vmw/pvrdma_cmd.c b/hw/rdma/vmw/pvrdma_cmd.c
57
index XXXXXXX..XXXXXXX 100644
58
--- a/hw/rdma/vmw/pvrdma_cmd.c
59
+++ b/hw/rdma/vmw/pvrdma_cmd.c
60
@@ -XXX,XX +XXX,XX @@ static int create_cq_ring(PCIDevice *pci_dev , PvrdmaRing **ring,
61
r = g_malloc(sizeof(*r));
62
*ring = r;
63
64
- r->ring_state = (struct pvrdma_ring *)
65
+ r->ring_state = (PvrdmaRingState *)
66
rdma_pci_dma_map(pci_dev, tbl[0], TARGET_PAGE_SIZE);
67
68
if (!r->ring_state) {
69
@@ -XXX,XX +XXX,XX @@ static int create_qp_rings(PCIDevice *pci_dev, uint64_t pdir_dma,
70
*rings = sr;
71
72
/* Create send ring */
73
- sr->ring_state = (struct pvrdma_ring *)
74
+ sr->ring_state = (PvrdmaRingState *)
75
rdma_pci_dma_map(pci_dev, tbl[0], TARGET_PAGE_SIZE);
76
if (!sr->ring_state) {
77
rdma_error_report("Failed to map to QP ring state");
78
@@ -XXX,XX +XXX,XX @@ static int create_srq_ring(PCIDevice *pci_dev, PvrdmaRing **ring,
79
r = g_malloc(sizeof(*r));
80
*ring = r;
81
82
- r->ring_state = (struct pvrdma_ring *)
83
+ r->ring_state = (PvrdmaRingState *)
84
rdma_pci_dma_map(pci_dev, tbl[0], TARGET_PAGE_SIZE);
85
if (!r->ring_state) {
86
rdma_error_report("Failed to map tp SRQ ring state");
87
diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c
88
index XXXXXXX..XXXXXXX 100644
89
--- a/hw/rdma/vmw/pvrdma_dev_ring.c
90
+++ b/hw/rdma/vmw/pvrdma_dev_ring.c
91
@@ -XXX,XX +XXX,XX @@
92
#include "trace.h"
93
94
#include "../rdma_utils.h"
95
-#include "standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h"
96
#include "pvrdma_dev_ring.h"
97
98
int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
99
- struct pvrdma_ring *ring_state, uint32_t max_elems,
100
+ PvrdmaRingState *ring_state, uint32_t max_elems,
101
size_t elem_sz, dma_addr_t *tbl, uint32_t npages)
102
{
103
int i;
104
@@ -XXX,XX +XXX,XX @@ out:
105
106
void *pvrdma_ring_next_elem_read(PvrdmaRing *ring)
107
{
108
- int e;
109
- unsigned int idx = 0, offset;
110
+ unsigned int idx, offset;
111
+ const uint32_t tail = qatomic_read(&ring->ring_state->prod_tail);
112
+ const uint32_t head = qatomic_read(&ring->ring_state->cons_head);
113
114
- e = pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &idx);
115
- if (e <= 0) {
116
+ if (tail & ~((ring->max_elems << 1) - 1) ||
117
+ head & ~((ring->max_elems << 1) - 1) ||
118
+ tail == head) {
119
trace_pvrdma_ring_next_elem_read_no_data(ring->name);
120
return NULL;
121
}
122
123
+ idx = head & (ring->max_elems - 1);
124
offset = idx * ring->elem_sz;
125
return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_SIZE);
126
}
127
128
void pvrdma_ring_read_inc(PvrdmaRing *ring)
129
{
130
- pvrdma_idx_ring_inc(&ring->ring_state->cons_head, ring->max_elems);
131
+ uint32_t idx = qatomic_read(&ring->ring_state->cons_head);
132
+
133
+ idx = (idx + 1) & ((ring->max_elems << 1) - 1);
134
+ qatomic_set(&ring->ring_state->cons_head, idx);
135
}
136
137
void *pvrdma_ring_next_elem_write(PvrdmaRing *ring)
138
{
139
- int idx;
140
- unsigned int offset, tail;
141
+ unsigned int idx, offset;
142
+ const uint32_t tail = qatomic_read(&ring->ring_state->prod_tail);
143
+ const uint32_t head = qatomic_read(&ring->ring_state->cons_head);
144
145
- idx = pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &tail);
146
- if (idx <= 0) {
147
+ if (tail & ~((ring->max_elems << 1) - 1) ||
148
+ head & ~((ring->max_elems << 1) - 1) ||
149
+ tail == (head ^ ring->max_elems)) {
150
rdma_error_report("CQ is full");
151
return NULL;
152
}
153
154
- idx = pvrdma_idx(&ring->ring_state->prod_tail, ring->max_elems);
155
- if (idx < 0 || tail != idx) {
156
- rdma_error_report("Invalid idx %d", idx);
157
- return NULL;
158
- }
159
-
160
+ idx = tail & (ring->max_elems - 1);
161
offset = idx * ring->elem_sz;
162
return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_SIZE);
163
}
164
165
void pvrdma_ring_write_inc(PvrdmaRing *ring)
166
{
167
- pvrdma_idx_ring_inc(&ring->ring_state->prod_tail, ring->max_elems);
168
+ uint32_t idx = qatomic_read(&ring->ring_state->prod_tail);
169
+
170
+ idx = (idx + 1) & ((ring->max_elems << 1) - 1);
171
+ qatomic_set(&ring->ring_state->prod_tail, idx);
172
}
173
174
void pvrdma_ring_free(PvrdmaRing *ring)
175
diff --git a/hw/rdma/vmw/pvrdma_dev_ring.h b/hw/rdma/vmw/pvrdma_dev_ring.h
176
index XXXXXXX..XXXXXXX 100644
177
--- a/hw/rdma/vmw/pvrdma_dev_ring.h
178
+++ b/hw/rdma/vmw/pvrdma_dev_ring.h
179
@@ -XXX,XX +XXX,XX @@
180
181
#define MAX_RING_NAME_SZ 32
182
183
+typedef struct PvrdmaRingState {
184
+ int prod_tail; /* producer tail */
185
+ int cons_head; /* consumer head */
186
+} PvrdmaRingState;
187
+
188
typedef struct PvrdmaRing {
189
char name[MAX_RING_NAME_SZ];
190
PCIDevice *dev;
191
uint32_t max_elems;
192
size_t elem_sz;
193
- struct pvrdma_ring *ring_state; /* used only for unmap */
194
+ PvrdmaRingState *ring_state; /* used only for unmap */
195
int npages;
196
void **pages;
197
} PvrdmaRing;
198
199
int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
200
- struct pvrdma_ring *ring_state, uint32_t max_elems,
201
+ PvrdmaRingState *ring_state, uint32_t max_elems,
202
size_t elem_sz, dma_addr_t *tbl, uint32_t npages);
203
void *pvrdma_ring_next_elem_read(PvrdmaRing *ring);
204
void pvrdma_ring_read_inc(PvrdmaRing *ring);
205
diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
206
index XXXXXXX..XXXXXXX 100644
207
--- a/hw/rdma/vmw/pvrdma_main.c
208
+++ b/hw/rdma/vmw/pvrdma_main.c
209
@@ -XXX,XX +XXX,XX @@ static void free_dev_ring(PCIDevice *pci_dev, PvrdmaRing *ring,
210
rdma_pci_dma_unmap(pci_dev, ring_state, TARGET_PAGE_SIZE);
211
}
212
213
-static int init_dev_ring(PvrdmaRing *ring, struct pvrdma_ring **ring_state,
214
+static int init_dev_ring(PvrdmaRing *ring, PvrdmaRingState **ring_state,
215
const char *name, PCIDevice *pci_dev,
216
dma_addr_t dir_addr, uint32_t num_pages)
217
{
218
@@ -XXX,XX +XXX,XX @@ static int init_dev_ring(PvrdmaRing *ring, struct pvrdma_ring **ring_state,
219
/* RX ring is the second */
220
(*ring_state)++;
221
rc = pvrdma_ring_init(ring, name, pci_dev,
222
- (struct pvrdma_ring *)*ring_state,
223
+ (PvrdmaRingState *)*ring_state,
224
(num_pages - 1) * TARGET_PAGE_SIZE /
225
sizeof(struct pvrdma_cqne),
226
sizeof(struct pvrdma_cqne),
227
diff --git a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h b/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h
228
deleted file mode 100644
229
index XXXXXXX..XXXXXXX
230
--- a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h
231
+++ /dev/null
232
@@ -XXX,XX +XXX,XX @@
233
-/*
234
- * Copyright (c) 2012-2016 VMware, Inc. All rights reserved.
235
- *
236
- * This program is free software; you can redistribute it and/or
237
- * modify it under the terms of EITHER the GNU General Public License
238
- * version 2 as published by the Free Software Foundation or the BSD
239
- * 2-Clause License. This program is distributed in the hope that it
240
- * will be useful, but WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED
241
- * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
242
- * See the GNU General Public License version 2 for more details at
243
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html.
244
- *
245
- * You should have received a copy of the GNU General Public License
246
- * along with this program available in the file COPYING in the main
247
- * directory of this source tree.
248
- *
249
- * The BSD 2-Clause License
250
- *
251
- * Redistribution and use in source and binary forms, with or
252
- * without modification, are permitted provided that the following
253
- * conditions are met:
254
- *
255
- * - Redistributions of source code must retain the above
256
- * copyright notice, this list of conditions and the following
257
- * disclaimer.
258
- *
259
- * - Redistributions in binary form must reproduce the above
260
- * copyright notice, this list of conditions and the following
261
- * disclaimer in the documentation and/or other materials
262
- * provided with the distribution.
263
- *
264
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
265
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
266
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
267
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
268
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
269
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
270
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
271
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
273
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
274
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
275
- * OF THE POSSIBILITY OF SUCH DAMAGE.
276
- */
277
-
278
-#ifndef __PVRDMA_RING_H__
279
-#define __PVRDMA_RING_H__
280
-
281
-#include "standard-headers/linux/types.h"
282
-
283
-#define PVRDMA_INVALID_IDX    -1    /* Invalid index. */
284
-
285
-struct pvrdma_ring {
286
-    int prod_tail;    /* Producer tail. */
287
-    int cons_head;    /* Consumer head. */
288
-};
289
-
290
-struct pvrdma_ring_state {
291
-    struct pvrdma_ring tx;    /* Tx ring. */
292
-    struct pvrdma_ring rx;    /* Rx ring. */
293
-};
294
-
295
-static inline int pvrdma_idx_valid(uint32_t idx, uint32_t max_elems)
296
-{
297
-    /* Generates fewer instructions than a less-than. */
298
-    return (idx & ~((max_elems << 1) - 1)) == 0;
299
-}
300
-
301
-static inline int32_t pvrdma_idx(int *var, uint32_t max_elems)
302
-{
303
-    const unsigned int idx = qatomic_read(var);
304
-
305
-    if (pvrdma_idx_valid(idx, max_elems))
306
-        return idx & (max_elems - 1);
307
-    return PVRDMA_INVALID_IDX;
308
-}
309
-
310
-static inline void pvrdma_idx_ring_inc(int *var, uint32_t max_elems)
311
-{
312
-    uint32_t idx = qatomic_read(var) + 1;    /* Increment. */
313
-
314
-    idx &= (max_elems << 1) - 1;        /* Modulo size, flip gen. */
315
-    qatomic_set(var, idx);
316
-}
317
-
318
-static inline int32_t pvrdma_idx_ring_has_space(const struct pvrdma_ring *r,
319
-                     uint32_t max_elems, uint32_t *out_tail)
320
-{
321
-    const uint32_t tail = qatomic_read(&r->prod_tail);
322
-    const uint32_t head = qatomic_read(&r->cons_head);
323
-
324
-    if (pvrdma_idx_valid(tail, max_elems) &&
325
-     pvrdma_idx_valid(head, max_elems)) {
326
-        *out_tail = tail & (max_elems - 1);
327
-        return tail != (head ^ max_elems);
328
-    }
329
-    return PVRDMA_INVALID_IDX;
330
-}
331
-
332
-static inline int32_t pvrdma_idx_ring_has_data(const struct pvrdma_ring *r,
333
-                     uint32_t max_elems, uint32_t *out_head)
334
-{
335
-    const uint32_t tail = qatomic_read(&r->prod_tail);
336
-    const uint32_t head = qatomic_read(&r->cons_head);
337
-
338
-    if (pvrdma_idx_valid(tail, max_elems) &&
339
-     pvrdma_idx_valid(head, max_elems)) {
340
-        *out_head = head & (max_elems - 1);
341
-        return tail != head;
342
-    }
343
-    return PVRDMA_INVALID_IDX;
344
-}
345
-
346
-#endif /* __PVRDMA_RING_H__ */
347
diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
348
index XXXXXXX..XXXXXXX 100755
349
--- a/scripts/update-linux-headers.sh
350
+++ b/scripts/update-linux-headers.sh
351
@@ -XXX,XX +XXX,XX @@ sed -e '1h;2,$H;$!d;g' -e 's/[^};]*pvrdma[^(| ]*([^)]*);//g' \
352
"$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h" > \
353
"$tmp_pvrdma_verbs";
354
355
-for i in "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h" \
356
- "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h" \
357
+for i in "$linux/drivers/infiniband/hw/vmw_pvrdma/pvrdma_dev_api.h" \
358
"$tmp_pvrdma_verbs"; do \
359
cp_portable "$i" \
360
"$output/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/"
361
--
362
2.7.4
363
364
diff view generated by jsdifflib
1
From: Konstantin Shkolnyy <kshk@linux.ibm.com>
1
From: Alexey Kirillov <lekiravi@yandex-team.ru>
2
2
3
Add .set_vnet_le() function that always returns success, assuming that
3
The query-netdev command is used to get the configuration of the current
4
vDPA h/w always implements LE data format. Otherwise, QEMU disables vDPA and
4
network device backends (netdevs).
5
outputs the message:
5
This is the QMP analog of the HMP command "info network" but only for
6
"backend does not support LE vnet headers; falling back on userspace virtio"
6
netdevs (i.e. excluding NIC and hubports).
7
7
8
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
8
The query-netdev command returns an array of objects of the NetdevInfo
9
Acked-by: Eugenio Pérez <eperezma@redhat.com>
9
type, which are an extension of Netdev type. It means that response can
10
Signed-off-by: Konstantin Shkolnyy <kshk@linux.ibm.com>
10
be used for netdev-add after small modification. This can be useful for
11
recreate the same netdev configuration.
12
13
Information about the network device is filled in when it is created or
14
modified and is available through the NetClientState->stored_config.
15
16
Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru>
17
Acked-by: Markus Armbruster <armbru@redhat.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
18
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
19
---
13
net/vhost-vdpa.c | 13 +++++++++++++
20
include/net/net.h | 3 ++
14
1 file changed, 13 insertions(+)
21
net/l2tpv3.c | 7 ++++
22
net/net.c | 30 +++++++++++++-
23
net/netmap.c | 7 ++++
24
net/slirp.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
25
net/socket.c | 71 +++++++++++++++++++++++++++++++
26
net/tap-win32.c | 9 ++++
27
net/tap.c | 103 ++++++++++++++++++++++++++++++++++++++++++---
28
net/vde.c | 22 ++++++++++
29
net/vhost-user.c | 18 ++++++--
30
net/vhost-vdpa.c | 14 +++++++
31
qapi/net.json | 80 +++++++++++++++++++++++++++++++++++
32
12 files changed, 477 insertions(+), 9 deletions(-)
15
33
34
diff --git a/include/net/net.h b/include/net/net.h
35
index XXXXXXX..XXXXXXX 100644
36
--- a/include/net/net.h
37
+++ b/include/net/net.h
38
@@ -XXX,XX +XXX,XX @@
39
#include "qapi/qapi-types-net.h"
40
#include "net/queue.h"
41
#include "hw/qdev-properties-system.h"
42
+#include "qapi/clone-visitor.h"
43
+#include "qapi/qapi-visit-net.h"
44
45
#define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
46
#define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
47
@@ -XXX,XX +XXX,XX @@ struct NetClientState {
48
char *model;
49
char *name;
50
char info_str[256];
51
+ NetdevInfo *stored_config;
52
unsigned receive_disabled : 1;
53
NetClientDestructor *destructor;
54
unsigned int queue_index;
55
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/net/l2tpv3.c
58
+++ b/net/l2tpv3.c
59
@@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev,
60
61
l2tpv3_read_poll(s, true);
62
63
+ /* Store startup parameters */
64
+ nc->stored_config = g_new0(NetdevInfo, 1);
65
+ nc->stored_config->type = NET_BACKEND_L2TPV3;
66
+
67
+ QAPI_CLONE_MEMBERS(NetdevL2TPv3Options,
68
+ &nc->stored_config->u.l2tpv3, l2tpv3);
69
+
70
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
71
"l2tpv3: connected");
72
return 0;
73
diff --git a/net/net.c b/net/net.c
74
index XXXXXXX..XXXXXXX 100644
75
--- a/net/net.c
76
+++ b/net/net.c
77
@@ -XXX,XX +XXX,XX @@
78
#include "monitor/monitor.h"
79
#include "qemu/help_option.h"
80
#include "qapi/qapi-commands-net.h"
81
-#include "qapi/qapi-visit-net.h"
82
#include "qapi/qmp/qdict.h"
83
#include "qapi/qmp/qerror.h"
84
#include "qemu/error-report.h"
85
@@ -XXX,XX +XXX,XX @@ static void qemu_free_net_client(NetClientState *nc)
86
}
87
g_free(nc->name);
88
g_free(nc->model);
89
+ qapi_free_NetdevInfo(nc->stored_config);
90
if (nc->destructor) {
91
nc->destructor(nc);
92
}
93
@@ -XXX,XX +XXX,XX @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
94
return filter_list;
95
}
96
97
+NetdevInfoList *qmp_query_netdev(Error **errp)
98
+{
99
+ NetdevInfoList *list = NULL;
100
+ NetClientState *nc;
101
+
102
+ QTAILQ_FOREACH(nc, &net_clients, next) {
103
+ /*
104
+ * Only look at netdevs (backend network devices), not for each queue
105
+ * or NIC / hubport
106
+ */
107
+ if (nc->stored_config) {
108
+ NetdevInfo *element = QAPI_CLONE(NetdevInfo, nc->stored_config);
109
+
110
+ g_free(element->id); /* Need to dealloc empty id after clone */
111
+ element->id = g_strdup(nc->name);
112
+
113
+ element->has_peer_id = nc->peer != NULL;
114
+ if (element->has_peer_id) {
115
+ element->peer_id = g_strdup(nc->peer->name);
116
+ }
117
+
118
+ QAPI_LIST_PREPEND(list, element);
119
+ }
120
+ }
121
+
122
+ return list;
123
+}
124
+
125
void hmp_info_network(Monitor *mon, const QDict *qdict)
126
{
127
NetClientState *nc, *peer;
128
diff --git a/net/netmap.c b/net/netmap.c
129
index XXXXXXX..XXXXXXX 100644
130
--- a/net/netmap.c
131
+++ b/net/netmap.c
132
@@ -XXX,XX +XXX,XX @@ int net_init_netmap(const Netdev *netdev,
133
pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname);
134
netmap_read_poll(s, true); /* Initially only poll for reads. */
135
136
+ /* Store startup parameters */
137
+ nc->stored_config = g_new0(NetdevInfo, 1);
138
+ nc->stored_config->type = NET_BACKEND_NETMAP;
139
+
140
+ QAPI_CLONE_MEMBERS(NetdevNetmapOptions,
141
+ &nc->stored_config->u.netmap, netmap_opts);
142
+
143
return 0;
144
}
145
146
diff --git a/net/slirp.c b/net/slirp.c
147
index XXXXXXX..XXXXXXX 100644
148
--- a/net/slirp.c
149
+++ b/net/slirp.c
150
@@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model,
151
int shift;
152
char *end;
153
struct slirp_config_str *config;
154
+ NetdevUserOptions *stored;
155
+ StringList **stored_hostfwd;
156
+ StringList **stored_guestfwd;
157
158
if (!ipv4 && (vnetwork || vhost || vnameserver)) {
159
error_setg(errp, "IPv4 disabled but netmask/host/dns provided");
160
@@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model,
161
162
nc = qemu_new_net_client(&net_slirp_info, peer, model, name);
163
164
+ /* Store startup parameters */
165
+ nc->stored_config = g_new0(NetdevInfo, 1);
166
+ nc->stored_config->type = NET_BACKEND_USER;
167
+ stored = &nc->stored_config->u.user;
168
+
169
+ if (vhostname) {
170
+ stored->has_hostname = true;
171
+ stored->hostname = g_strdup(vhostname);
172
+ }
173
+
174
+ stored->has_q_restrict = true;
175
+ stored->q_restrict = restricted;
176
+
177
+ stored->has_ipv4 = true;
178
+ stored->ipv4 = ipv4;
179
+
180
+ stored->has_ipv6 = true;
181
+ stored->ipv6 = ipv6;
182
+
183
+ if (ipv4) {
184
+ uint8_t *net_bytes = (uint8_t *)&net;
185
+ uint8_t *mask_bytes = (uint8_t *)&mask;
186
+
187
+ stored->has_net = true;
188
+ stored->net = g_strdup_printf("%d.%d.%d.%d/%d.%d.%d.%d",
189
+ net_bytes[0], net_bytes[1],
190
+ net_bytes[2], net_bytes[3],
191
+ mask_bytes[0], mask_bytes[1],
192
+ mask_bytes[2], mask_bytes[3]);
193
+
194
+ stored->has_host = true;
195
+ stored->host = g_strdup(inet_ntoa(host));
196
+ }
197
+
198
+ if (tftp_export) {
199
+ stored->has_tftp = true;
200
+ stored->tftp = g_strdup(tftp_export);
201
+ }
202
+
203
+ if (bootfile) {
204
+ stored->has_bootfile = true;
205
+ stored->bootfile = g_strdup(bootfile);
206
+ }
207
+
208
+ if (vdhcp_start) {
209
+ stored->has_dhcpstart = true;
210
+ stored->dhcpstart = g_strdup(vdhcp_start);
211
+ }
212
+
213
+ if (ipv4) {
214
+ stored->has_dns = true;
215
+ stored->dns = g_strdup(inet_ntoa(dns));
216
+ }
217
+
218
+ if (dnssearch) {
219
+ stored->has_dnssearch = true;
220
+ StringList **stored_list = &stored->dnssearch;
221
+
222
+ for (int i = 0; dnssearch[i]; i++) {
223
+ String *element = g_new0(String, 1);
224
+
225
+ element->str = g_strdup(dnssearch[i]);
226
+ QAPI_LIST_APPEND(stored_list, element);
227
+ }
228
+ }
229
+
230
+ if (vdomainname) {
231
+ stored->has_domainname = true;
232
+ stored->domainname = g_strdup(vdomainname);
233
+ }
234
+
235
+ if (ipv6) {
236
+ char addrstr[INET6_ADDRSTRLEN];
237
+ const char *res;
238
+
239
+ stored->has_ipv6_prefix = true;
240
+ stored->ipv6_prefix = g_strdup(vprefix6);
241
+
242
+ stored->has_ipv6_prefixlen = true;
243
+ stored->ipv6_prefixlen = vprefix6_len;
244
+
245
+ res = inet_ntop(AF_INET6, &ip6_host,
246
+ addrstr, sizeof(addrstr));
247
+
248
+ stored->has_ipv6_host = true;
249
+ stored->ipv6_host = g_strdup(res);
250
+
251
+ res = inet_ntop(AF_INET6, &ip6_dns,
252
+ addrstr, sizeof(addrstr));
253
+
254
+ stored->has_ipv6_dns = true;
255
+ stored->ipv6_dns = g_strdup(res);
256
+ }
257
+
258
+ if (smb_export) {
259
+ stored->has_smb = true;
260
+ stored->smb = g_strdup(smb_export);
261
+ }
262
+
263
+ if (vsmbserver) {
264
+ stored->has_smbserver = true;
265
+ stored->smbserver = g_strdup(vsmbserver);
266
+ }
267
+
268
+ if (tftp_server_name) {
269
+ stored->has_tftp_server_name = true;
270
+ stored->tftp_server_name = g_strdup(tftp_server_name);
271
+ }
272
+
273
snprintf(nc->info_str, sizeof(nc->info_str),
274
"net=%s,restrict=%s", inet_ntoa(net),
275
restricted ? "on" : "off");
276
@@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model,
277
s->poll_notifier.notify = net_slirp_poll_notify;
278
main_loop_poll_add_notifier(&s->poll_notifier);
279
280
+ stored_hostfwd = &stored->hostfwd;
281
+ stored_guestfwd = &stored->guestfwd;
282
+
283
for (config = slirp_configs; config; config = config->next) {
284
+ String *element = g_new0(String, 1);
285
+
286
+ element->str = g_strdup(config->str);
287
if (config->flags & SLIRP_CFG_HOSTFWD) {
288
if (slirp_hostfwd(s, config->str, errp) < 0) {
289
goto error;
290
}
291
+ stored->has_hostfwd = true;
292
+ QAPI_LIST_APPEND(stored_hostfwd, element);
293
} else {
294
if (slirp_guestfwd(s, config->str, errp) < 0) {
295
goto error;
296
}
297
+ stored->has_guestfwd = true;
298
+ QAPI_LIST_APPEND(stored_guestfwd, element);
299
}
300
}
301
#ifndef _WIN32
302
diff --git a/net/socket.c b/net/socket.c
303
index XXXXXXX..XXXXXXX 100644
304
--- a/net/socket.c
305
+++ b/net/socket.c
306
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
307
NetSocketState *s;
308
SocketAddress *sa;
309
SocketAddressType sa_type;
310
+ NetdevSocketOptions *stored;
311
312
sa = socket_local_address(fd, errp);
313
if (!sa) {
314
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
315
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
316
net_socket_read_poll(s, true);
317
318
+ /* Store startup parameters */
319
+ nc->stored_config = g_new0(NetdevInfo, 1);
320
+ nc->stored_config->type = NET_BACKEND_SOCKET;
321
+ stored = &nc->stored_config->u.socket;
322
+
323
+ stored->has_fd = true;
324
+ stored->fd = g_strdup_printf("%d", fd);
325
+
326
/* mcast: save bound address as dst */
327
if (is_connected && mcast != NULL) {
328
+ stored->has_mcast = true;
329
+ stored->mcast = g_strdup(mcast);
330
+
331
s->dgram_dst = saddr;
332
snprintf(nc->info_str, sizeof(nc->info_str),
333
"socket: fd=%d (cloned mcast=%s:%d)",
334
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
335
{
336
NetClientState *nc;
337
NetSocketState *s;
338
+ NetdevSocketOptions *stored;
339
340
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
341
342
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
343
} else {
344
qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s);
345
}
346
+
347
+ /* Store startup parameters */
348
+ nc->stored_config = g_new0(NetdevInfo, 1);
349
+ nc->stored_config->type = NET_BACKEND_SOCKET;
350
+ stored = &nc->stored_config->u.socket;
351
+
352
+ stored->has_fd = true;
353
+ stored->fd = g_strdup_printf("%d", fd);
354
+
355
return s;
356
}
357
358
@@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque)
359
struct sockaddr_in saddr;
360
socklen_t len;
361
int fd;
362
+ NetdevSocketOptions *stored;
363
364
for(;;) {
365
len = sizeof(saddr);
366
@@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque)
367
s->fd = fd;
368
s->nc.link_down = false;
369
net_socket_connect(s);
370
+
371
+ /* Store additional startup parameters (extend net_socket_listen_init) */
372
+ stored = &s->nc.stored_config->u.socket;
373
+
374
+ stored->has_fd = true;
375
+ stored->fd = g_strdup_printf("%d", fd);
376
+
377
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
378
"socket: connection from %s:%d",
379
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
380
@@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer,
381
NetSocketState *s;
382
struct sockaddr_in saddr;
383
int fd, ret;
384
+ NetdevSocketOptions *stored;
385
386
if (parse_host_port(&saddr, host_str, errp) < 0) {
387
return -1;
388
@@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer,
389
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
390
391
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
392
+
393
+ /* Store startup parameters */
394
+ nc->stored_config = g_new0(NetdevInfo, 1);
395
+ nc->stored_config->type = NET_BACKEND_SOCKET;
396
+ stored = &nc->stored_config->u.socket;
397
+
398
+ stored->has_listen = true;
399
+ stored->listen = g_strdup(host_str);
400
+
401
return 0;
402
}
403
404
@@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer,
405
NetSocketState *s;
406
int fd, connected, ret;
407
struct sockaddr_in saddr;
408
+ NetdevSocketOptions *stored;
409
410
if (parse_host_port(&saddr, host_str, errp) < 0) {
411
return -1;
412
@@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer,
413
return -1;
414
}
415
416
+ /* Store additional startup parameters (extend net_socket_fd_init) */
417
+ stored = &s->nc.stored_config->u.socket;
418
+
419
+ stored->has_connect = true;
420
+ stored->connect = g_strdup(host_str);
421
+
422
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
423
"socket: connect to %s:%d",
424
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
425
@@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer,
426
int fd;
427
struct sockaddr_in saddr;
428
struct in_addr localaddr, *param_localaddr;
429
+ NetdevSocketOptions *stored;
430
431
if (parse_host_port(&saddr, host_str, errp) < 0) {
432
return -1;
433
@@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer,
434
435
s->dgram_dst = saddr;
436
437
+ /* Store additional startup parameters (extend net_socket_fd_init) */
438
+ stored = &s->nc.stored_config->u.socket;
439
+
440
+ if (!stored->has_mcast) {
441
+ stored->has_mcast = true;
442
+ stored->mcast = g_strdup(host_str);
443
+ }
444
+
445
+ if (localaddr_str) {
446
+ stored->has_localaddr = true;
447
+ stored->localaddr = g_strdup(localaddr_str);
448
+ }
449
+
450
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
451
"socket: mcast=%s:%d",
452
inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
453
@@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer,
454
NetSocketState *s;
455
int fd, ret;
456
struct sockaddr_in laddr, raddr;
457
+ NetdevSocketOptions *stored;
458
459
if (parse_host_port(&laddr, lhost, errp) < 0) {
460
return -1;
461
@@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer,
462
463
s->dgram_dst = raddr;
464
465
+ /* Store additional startup parameters (extend net_socket_fd_init) */
466
+ stored = &s->nc.stored_config->u.socket;
467
+
468
+ stored->has_localaddr = true;
469
+ stored->localaddr = g_strdup(lhost);
470
+
471
+ stored->has_udp = true;
472
+ stored->udp = g_strdup(rhost);
473
+
474
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
475
"socket: udp=%s:%d",
476
inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
477
diff --git a/net/tap-win32.c b/net/tap-win32.c
478
index XXXXXXX..XXXXXXX 100644
479
--- a/net/tap-win32.c
480
+++ b/net/tap-win32.c
481
@@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model,
482
NetClientState *nc;
483
TAPState *s;
484
tap_win32_overlapped_t *handle;
485
+ NetdevTapOptions *stored;
486
487
if (tap_win32_open(&handle, ifname) < 0) {
488
printf("tap: Could not open '%s'\n", ifname);
489
@@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model,
490
491
s = DO_UPCAST(TAPState, nc, nc);
492
493
+ /* Store startup parameters */
494
+ nc->stored_config = g_new0(NetdevInfo, 1);
495
+ nc->stored_config->type = NET_BACKEND_TAP;
496
+ stored = &nc->stored_config->u.tap;
497
+
498
+ stored->has_ifname = true;
499
+ stored->ifname = g_strdup(ifname);
500
+
501
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
502
"tap: ifname=%s", ifname);
503
504
diff --git a/net/tap.c b/net/tap.c
505
index XXXXXXX..XXXXXXX 100644
506
--- a/net/tap.c
507
+++ b/net/tap.c
508
@@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name,
509
const char *helper, *br;
510
TAPState *s;
511
int fd, vnet_hdr;
512
+ NetdevBridgeOptions *stored;
513
514
assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
515
bridge = &netdev->u.bridge;
516
@@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name,
517
}
518
s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr);
519
520
+ /* Store startup parameters */
521
+ s->nc.stored_config = g_new0(NetdevInfo, 1);
522
+ s->nc.stored_config->type = NET_BACKEND_BRIDGE;
523
+ stored = &s->nc.stored_config->u.bridge;
524
+
525
+ if (br) {
526
+ stored->has_br = true;
527
+ stored->br = g_strdup(br);
528
+ }
529
+
530
+ if (helper) {
531
+ stored->has_helper = true;
532
+ stored->helper = g_strdup(helper);
533
+ }
534
+
535
snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
536
br);
537
538
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
539
const char *model, const char *name,
540
const char *ifname, const char *script,
541
const char *downscript, const char *vhostfdname,
542
- int vnet_hdr, int fd, Error **errp)
543
+ int vnet_hdr, int fd, NetdevInfo **common_stored,
544
+ Error **errp)
545
{
546
Error *err = NULL;
547
TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
548
int vhostfd;
549
+ NetdevTapOptions *stored;
550
551
tap_set_sndbuf(s->fd, tap, &err);
552
if (err) {
553
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
554
return;
555
}
556
557
+ /* Store startup parameters */
558
+ if (!*common_stored) {
559
+ *common_stored = g_new0(NetdevInfo, 1);
560
+ (*common_stored)->type = NET_BACKEND_TAP;
561
+ s->nc.stored_config = *common_stored;
562
+ }
563
+ stored = &(*common_stored)->u.tap;
564
+
565
+ if (tap->has_sndbuf && !stored->has_sndbuf) {
566
+ stored->has_sndbuf = true;
567
+ stored->sndbuf = tap->sndbuf;
568
+ }
569
+
570
+ if (vnet_hdr && !stored->has_vnet_hdr) {
571
+ stored->has_vnet_hdr = true;
572
+ stored->vnet_hdr = true;
573
+ }
574
+
575
if (tap->has_fd || tap->has_fds) {
576
+ if (!stored->has_fds) {
577
+ stored->has_fds = true;
578
+ stored->fds = g_strdup_printf("%d", fd);
579
+ } else {
580
+ char *tmp_s = stored->fds;
581
+ stored->fds = g_strdup_printf("%s:%d", stored->fds, fd);
582
+ g_free(tmp_s);
583
+ }
584
+
585
snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
586
} else if (tap->has_helper) {
587
+ if (!stored->has_helper) {
588
+ stored->has_helper = true;
589
+ stored->helper = g_strdup(tap->helper);
590
+ }
591
+
592
+ if (!stored->has_br) {
593
+ stored->has_br = true;
594
+ stored->br = tap->has_br ? g_strdup(tap->br) :
595
+ g_strdup(DEFAULT_BRIDGE_INTERFACE);
596
+ }
597
+
598
snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s",
599
tap->helper);
600
} else {
601
+ if (ifname && !stored->has_ifname) {
602
+ stored->has_ifname = true;
603
+ stored->ifname = g_strdup(ifname);
604
+ }
605
+
606
+ if (script && !stored->has_script) {
607
+ stored->has_script = true;
608
+ stored->script = g_strdup(script);
609
+ }
610
+
611
+ if (downscript && !stored->has_downscript) {
612
+ stored->has_downscript = true;
613
+ stored->downscript = g_strdup(downscript);
614
+ }
615
+
616
snprintf(s->nc.info_str, sizeof(s->nc.info_str),
617
"ifname=%s,script=%s,downscript=%s", ifname, script,
618
downscript);
619
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
620
vhostfdname || (tap->has_vhostforce && tap->vhostforce)) {
621
VhostNetOptions options;
622
623
+ stored->has_vhost = true;
624
+ stored->vhost = true;
625
+
626
+ if (tap->has_vhostforce && tap->vhostforce) {
627
+ stored->has_vhostforce = true;
628
+ stored->vhostforce = true;
629
+ }
630
+
631
options.backend_type = VHOST_BACKEND_TYPE_KERNEL;
632
options.net_backend = &s->nc;
633
if (tap->has_poll_us) {
634
+ stored->has_poll_us = true;
635
+ stored->poll_us = tap->poll_us;
636
+
637
options.busyloop_timeout = tap->poll_us;
638
} else {
639
options.busyloop_timeout = 0;
640
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
641
}
642
options.opaque = (void *)(uintptr_t)vhostfd;
643
644
+ if (!stored->has_vhostfds) {
645
+ stored->has_vhostfds = true;
646
+ stored->vhostfds = g_strdup_printf("%d", vhostfd);
647
+ } else {
648
+ char *tmp_s = stored->vhostfds;
649
+ stored->vhostfds = g_strdup_printf("%s:%d", stored->fds, vhostfd);
650
+ g_free(tmp_s);
651
+ }
652
+
653
s->vhost_net = vhost_net_init(&options);
654
if (!s->vhost_net) {
655
if (tap->has_vhostforce && tap->vhostforce) {
656
@@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name,
657
const char *vhostfdname;
658
char ifname[128];
659
int ret = 0;
660
+ NetdevInfo *common_stored = NULL; /* will store configuration */
661
662
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
663
tap = &netdev->u.tap;
664
@@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name,
665
666
net_init_tap_one(tap, peer, "tap", name, NULL,
667
script, downscript,
668
- vhostfdname, vnet_hdr, fd, &err);
669
+ vhostfdname, vnet_hdr, fd, &common_stored, &err);
670
if (err) {
671
error_propagate(errp, err);
672
close(fd);
673
@@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name,
674
net_init_tap_one(tap, peer, "tap", name, ifname,
675
script, downscript,
676
tap->has_vhostfds ? vhost_fds[i] : NULL,
677
- vnet_hdr, fd, &err);
678
+ vnet_hdr, fd, &common_stored, &err);
679
if (err) {
680
error_propagate(errp, err);
681
ret = -1;
682
@@ -XXX,XX +XXX,XX @@ free_fail:
683
684
net_init_tap_one(tap, peer, "bridge", name, ifname,
685
script, downscript, vhostfdname,
686
- vnet_hdr, fd, &err);
687
+ vnet_hdr, fd, &common_stored, &err);
688
if (err) {
689
error_propagate(errp, err);
690
close(fd);
691
@@ -XXX,XX +XXX,XX @@ free_fail:
692
net_init_tap_one(tap, peer, "tap", name, ifname,
693
i >= 1 ? "no" : script,
694
i >= 1 ? "no" : downscript,
695
- vhostfdname, vnet_hdr, fd, &err);
696
+ vhostfdname, vnet_hdr, fd,
697
+ &common_stored, &err);
698
if (err) {
699
error_propagate(errp, err);
700
close(fd);
701
diff --git a/net/vde.c b/net/vde.c
702
index XXXXXXX..XXXXXXX 100644
703
--- a/net/vde.c
704
+++ b/net/vde.c
705
@@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model,
706
VDECONN *vde;
707
char *init_group = (char *)group;
708
char *init_sock = (char *)sock;
709
+ NetdevVdeOptions *stored;
710
711
struct vde_open_args args = {
712
.port = port,
713
@@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model,
714
715
qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
716
717
+ /* Store startup parameters */
718
+ nc->stored_config = g_new0(NetdevInfo, 1);
719
+ nc->stored_config->type = NET_BACKEND_VDE;
720
+ stored = &nc->stored_config->u.vde;
721
+
722
+ if (sock) {
723
+ stored->has_sock = true;
724
+ stored->sock = g_strdup(sock);
725
+ }
726
+
727
+ stored->has_port = true;
728
+ stored->port = port;
729
+
730
+ if (group) {
731
+ stored->has_group = true;
732
+ stored->group = g_strdup(group);
733
+ }
734
+
735
+ stored->has_mode = true;
736
+ stored->mode = mode;
737
+
738
return 0;
739
}
740
741
diff --git a/net/vhost-user.c b/net/vhost-user.c
742
index XXXXXXX..XXXXXXX 100644
743
--- a/net/vhost-user.c
744
+++ b/net/vhost-user.c
745
@@ -XXX,XX +XXX,XX @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event)
746
}
747
748
static int net_vhost_user_init(NetClientState *peer, const char *device,
749
- const char *name, Chardev *chr,
750
- int queues)
751
+ const char *name, const char *chardev,
752
+ Chardev *chr, int queues)
753
{
754
Error *err = NULL;
755
NetClientState *nc, *nc0 = NULL;
756
NetVhostUserState *s = NULL;
757
VhostUserState *user;
758
int i;
759
+ NetdevVhostUserOptions *stored;
760
761
assert(name);
762
assert(queues > 0);
763
@@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
764
765
assert(s->vhost_net);
766
767
+ /* Store startup parameters */
768
+ nc0->stored_config = g_new0(NetdevInfo, 1);
769
+ nc0->stored_config->type = NET_BACKEND_VHOST_USER;
770
+ stored = &nc0->stored_config->u.vhost_user;
771
+
772
+ stored->chardev = g_strdup(chardev);
773
+
774
+ stored->has_queues = true;
775
+ stored->queues = queues;
776
+
777
return 0;
778
779
err:
780
@@ -XXX,XX +XXX,XX @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
781
return -1;
782
}
783
784
- return net_vhost_user_init(peer, "vhost_user", name, chr, queues);
785
+ return net_vhost_user_init(peer, "vhost_user", name,
786
+ vhost_user_opts->chardev, chr, queues);
787
}
16
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
788
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
17
index XXXXXXX..XXXXXXX 100644
789
index XXXXXXX..XXXXXXX 100644
18
--- a/net/vhost-vdpa.c
790
--- a/net/vhost-vdpa.c
19
+++ b/net/vhost-vdpa.c
791
+++ b/net/vhost-vdpa.c
20
@@ -XXX,XX +XXX,XX @@ static bool vhost_vdpa_has_ufo(NetClientState *nc)
792
@@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
21
793
VhostVDPAState *s;
22
}
794
int vdpa_device_fd = -1;
23
795
int ret = 0;
24
+/*
796
+ NetdevVhostVDPAOptions *stored;
25
+ * FIXME: vhost_vdpa doesn't have an API to "set h/w endianness". But it's
797
+
26
+ * reasonable to assume that h/w is LE by default, because LE is what
798
assert(name);
27
+ * virtio 1.0 and later ask for. So, this function just says "yes, the h/w is
799
nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name);
28
+ * LE". Otherwise, on a BE machine, higher-level code would mistakely think
800
+
29
+ * the h/w is BE and can't support VDPA for a virtio 1.0 client.
801
+ /* Store startup parameters */
30
+ */
802
+ nc->stored_config = g_new0(NetdevInfo, 1);
31
+static int vhost_vdpa_set_vnet_le(NetClientState *nc, bool enable)
803
+ nc->stored_config->type = NET_BACKEND_VHOST_VDPA;
32
+{
804
+ stored = &nc->stored_config->u.vhost_vdpa;
33
+ return 0;
805
+
34
+}
806
+ stored->has_vhostdev = true;
35
+
807
+ stored->vhostdev = g_strdup(vhostdev);
36
static bool vhost_vdpa_check_peer_type(NetClientState *nc, ObjectClass *oc,
808
+
37
Error **errp)
809
+ stored->has_queues = true;
38
{
810
+ stored->queues = 1; /* TODO: change when support multiqueue */
39
@@ -XXX,XX +XXX,XX @@ static NetClientInfo net_vhost_vdpa_info = {
811
+
40
.cleanup = vhost_vdpa_cleanup,
812
snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
41
.has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
813
nc->queue_index = 0;
42
.has_ufo = vhost_vdpa_has_ufo,
814
s = DO_UPCAST(VhostVDPAState, nc, nc);
43
+ .set_vnet_le = vhost_vdpa_set_vnet_le,
815
diff --git a/qapi/net.json b/qapi/net.json
44
.check_peer_type = vhost_vdpa_check_peer_type,
816
index XXXXXXX..XXXXXXX 100644
45
.set_steering_ebpf = vhost_vdpa_set_steering_ebpf,
817
--- a/qapi/net.json
46
};
818
+++ b/qapi/net.json
819
@@ -XXX,XX +XXX,XX @@
820
##
821
{ 'event': 'FAILOVER_NEGOTIATED',
822
'data': {'device-id': 'str'} }
823
+
824
+##
825
+# @NetBackend:
826
+#
827
+# Available netdev backend drivers.
828
+#
829
+# Since: 6.0
830
+##
831
+{ 'enum': 'NetBackend',
832
+ 'data': [ 'bridge', 'l2tpv3', 'netmap', 'socket', 'tap', 'user', 'vde',
833
+ 'vhost-user', 'vhost-vdpa' ] }
834
+
835
+##
836
+# @NetdevInfo:
837
+#
838
+# Configuration of a network backend device (netdev).
839
+#
840
+# @id: Device identifier.
841
+#
842
+# @type: Specify the driver used for interpreting remaining arguments.
843
+#
844
+# @peer-id: The connected frontend network device name (absent if no frontend
845
+# is connected).
846
+#
847
+# Since: 6.0
848
+##
849
+{ 'union': 'NetdevInfo',
850
+ 'base': { 'id': 'str',
851
+ 'type': 'NetBackend',
852
+ '*peer-id': 'str' },
853
+ 'discriminator': 'type',
854
+ 'data': {
855
+ 'bridge': 'NetdevBridgeOptions',
856
+ 'l2tpv3': 'NetdevL2TPv3Options',
857
+ 'netmap': 'NetdevNetmapOptions',
858
+ 'socket': 'NetdevSocketOptions',
859
+ 'tap': 'NetdevTapOptions',
860
+ 'user': 'NetdevUserOptions',
861
+ 'vde': 'NetdevVdeOptions',
862
+ 'vhost-user': 'NetdevVhostUserOptions',
863
+ 'vhost-vdpa': 'NetdevVhostVDPAOptions' } }
864
+
865
+##
866
+# @query-netdev:
867
+#
868
+# Get a list of @NetdevInfo for all virtual network backend devices (netdevs).
869
+#
870
+# Returns: a list of @NetdevInfo describing each netdev.
871
+#
872
+# Since: 6.0
873
+#
874
+# Example:
875
+#
876
+# -> { "execute": "query-netdev" }
877
+# <- { "return": [
878
+# {
879
+# "ipv6": true,
880
+# "ipv4": true,
881
+# "host": "10.0.2.2",
882
+# "ipv6-dns": "fec0::3",
883
+# "ipv6-prefix": "fec0::",
884
+# "net": "10.0.2.0/255.255.255.0",
885
+# "ipv6-host": "fec0::2",
886
+# "type": "user",
887
+# "peer-id": "net0",
888
+# "dns": "10.0.2.3",
889
+# "hostfwd": [
890
+# {
891
+# "str": "tcp::20004-:22"
892
+# }
893
+# ],
894
+# "ipv6-prefixlen": 64,
895
+# "id": "netdev0",
896
+# "restrict": false
897
+# }
898
+# ]
899
+# }
900
+#
901
+##
902
+{ 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
47
--
903
--
48
2.42.0
904
2.7.4
49
905
50
906
diff view generated by jsdifflib
New patch
1
From: Alexey Kirillov <lekiravi@yandex-team.ru>
1
2
3
A simply qtest that checks for correct number of netdevs in the response
4
of the query-netdev.
5
6
Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru>
7
Acked-by: Thomas Huth <thuth@redhat.com>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
---
10
tests/qtest/meson.build | 3 +
11
tests/qtest/test-query-netdev.c | 120 ++++++++++++++++++++++++++++++++++++++++
12
2 files changed, 123 insertions(+)
13
create mode 100644 tests/qtest/test-query-netdev.c
14
15
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tests/qtest/meson.build
18
+++ b/tests/qtest/meson.build
19
@@ -XXX,XX +XXX,XX @@ qtests_generic = [
20
if config_host.has_key('CONFIG_MODULES')
21
qtests_generic += [ 'modules-test' ]
22
endif
23
+if slirp.found()
24
+ qtests_generic += [ 'test-query-netdev' ]
25
+endif
26
27
qtests_pci = \
28
(config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) + \
29
diff --git a/tests/qtest/test-query-netdev.c b/tests/qtest/test-query-netdev.c
30
new file mode 100644
31
index XXXXXXX..XXXXXXX
32
--- /dev/null
33
+++ b/tests/qtest/test-query-netdev.c
34
@@ -XXX,XX +XXX,XX @@
35
+/*
36
+ * QTest testcase for the query-netdev
37
+ *
38
+ * Copyright Yandex N.V., 2019
39
+ *
40
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
41
+ * See the COPYING file in the top-level directory.
42
+ *
43
+ */
44
+
45
+#include "qemu/osdep.h"
46
+
47
+#include "libqos/libqtest.h"
48
+#include "qapi/qmp/qdict.h"
49
+#include "qapi/qmp/qlist.h"
50
+
51
+/*
52
+ * Events can get in the way of responses we are actually waiting for.
53
+ */
54
+GCC_FMT_ATTR(2, 3)
55
+static QObject *wait_command(QTestState *who, const char *command, ...)
56
+{
57
+ va_list ap;
58
+ QDict *response;
59
+ QObject *result;
60
+
61
+ va_start(ap, command);
62
+ qtest_qmp_vsend(who, command, ap);
63
+ va_end(ap);
64
+
65
+ response = qtest_qmp_receive(who);
66
+
67
+ result = qdict_get(response, "return");
68
+ g_assert(result);
69
+ qobject_ref(result);
70
+ qobject_unref(response);
71
+
72
+ return result;
73
+}
74
+
75
+static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_count)
76
+{
77
+ QObject *resp;
78
+ QList *netdevs;
79
+
80
+ resp = wait_command(qts, "{'execute': 'query-netdev'}");
81
+
82
+ netdevs = qobject_to(QList, resp);
83
+ g_assert(netdevs);
84
+ g_assert(qlist_size(netdevs) == netdevs_count);
85
+
86
+ qobject_unref(resp);
87
+}
88
+
89
+static void test_query_netdev(void)
90
+{
91
+ const char *arch = qtest_get_arch();
92
+ QObject *resp;
93
+ QTestState *state;
94
+
95
+ /* Choosing machine for platforms without default one */
96
+ if (g_str_equal(arch, "arm") ||
97
+ g_str_equal(arch, "aarch64")) {
98
+ state = qtest_init(
99
+ "-nodefaults "
100
+ "-M virt "
101
+ "-netdev user,id=slirp0");
102
+ } else if (g_str_equal(arch, "tricore")) {
103
+ state = qtest_init(
104
+ "-nodefaults "
105
+ "-M tricore_testboard "
106
+ "-netdev user,id=slirp0");
107
+ } else if (g_str_equal(arch, "avr")) {
108
+ state = qtest_init(
109
+ "-nodefaults "
110
+ "-M mega2560 "
111
+ "-netdev user,id=slirp0");
112
+ } else if (g_str_equal(arch, "rx")) {
113
+ state = qtest_init(
114
+ "-nodefaults "
115
+ "-M gdbsim-r5f562n8 "
116
+ "-netdev user,id=slirp0");
117
+ } else {
118
+ state = qtest_init(
119
+ "-nodefaults "
120
+ "-netdev user,id=slirp0");
121
+ }
122
+ g_assert(state);
123
+
124
+ qmp_query_netdev_no_error(state, 1);
125
+
126
+ resp = wait_command(state,
127
+ "{'execute': 'netdev_add', 'arguments': {"
128
+ " 'id': 'slirp1',"
129
+ " 'type': 'user'}}");
130
+ qobject_unref(resp);
131
+
132
+ qmp_query_netdev_no_error(state, 2);
133
+
134
+ resp = wait_command(state,
135
+ "{'execute': 'netdev_del', 'arguments': {"
136
+ " 'id': 'slirp1'}}");
137
+ qobject_unref(resp);
138
+
139
+ qmp_query_netdev_no_error(state, 1);
140
+
141
+ qtest_quit(state);
142
+}
143
+
144
+int main(int argc, char **argv)
145
+{
146
+ int ret = 0;
147
+ g_test_init(&argc, &argv, NULL);
148
+
149
+ qtest_add_func("/net/qapi/query_netdev", test_query_netdev);
150
+
151
+ ret = g_test_run();
152
+
153
+ return ret;
154
+}
155
--
156
2.7.4
157
158
diff view generated by jsdifflib
New patch
1
1
From: Alexey Kirillov <lekiravi@yandex-team.ru>
2
3
The info_str field of the NetClientState structure is static and has a size
4
of 256 bytes. This amount is often unclaimed, and the field itself is used
5
exclusively for HMP "info network".
6
7
The patch translates info_str to dynamic memory allocation.
8
9
This action is also allows us to painlessly discard usage of this field
10
for backend devices.
11
12
Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
15
hw/net/xen_nic.c | 5 ++---
16
include/net/net.h | 2 +-
17
net/l2tpv3.c | 3 +--
18
net/net.c | 14 ++++++++------
19
net/slirp.c | 5 ++---
20
net/socket.c | 43 ++++++++++++++++++++++++-------------------
21
net/tap-win32.c | 3 +--
22
net/tap.c | 13 +++++--------
23
net/vde.c | 3 +--
24
net/vhost-user.c | 3 +--
25
net/vhost-vdpa.c | 2 +-
26
11 files changed, 47 insertions(+), 49 deletions(-)
27
28
diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/hw/net/xen_nic.c
31
+++ b/hw/net/xen_nic.c
32
@@ -XXX,XX +XXX,XX @@ static int net_init(struct XenLegacyDevice *xendev)
33
netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf,
34
"xen", NULL, netdev);
35
36
- snprintf(qemu_get_queue(netdev->nic)->info_str,
37
- sizeof(qemu_get_queue(netdev->nic)->info_str),
38
- "nic: xenbus vif macaddr=%s", netdev->mac);
39
+ qemu_get_queue(netdev->nic)->info_str = g_strdup_printf(
40
+ "nic: xenbus vif macaddr=%s", netdev->mac);
41
42
/* fill info */
43
xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1);
44
diff --git a/include/net/net.h b/include/net/net.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/include/net/net.h
47
+++ b/include/net/net.h
48
@@ -XXX,XX +XXX,XX @@ struct NetClientState {
49
NetQueue *incoming_queue;
50
char *model;
51
char *name;
52
- char info_str[256];
53
+ char *info_str;
54
NetdevInfo *stored_config;
55
unsigned receive_disabled : 1;
56
NetClientDestructor *destructor;
57
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
58
index XXXXXXX..XXXXXXX 100644
59
--- a/net/l2tpv3.c
60
+++ b/net/l2tpv3.c
61
@@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev,
62
QAPI_CLONE_MEMBERS(NetdevL2TPv3Options,
63
&nc->stored_config->u.l2tpv3, l2tpv3);
64
65
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
66
- "l2tpv3: connected");
67
+ s->nc.info_str = g_strdup_printf("l2tpv3: connected");
68
return 0;
69
outerr:
70
qemu_del_net_client(nc);
71
diff --git a/net/net.c b/net/net.c
72
index XXXXXXX..XXXXXXX 100644
73
--- a/net/net.c
74
+++ b/net/net.c
75
@@ -XXX,XX +XXX,XX @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr)
76
77
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
78
{
79
- snprintf(nc->info_str, sizeof(nc->info_str),
80
- "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
81
- nc->model,
82
- macaddr[0], macaddr[1], macaddr[2],
83
- macaddr[3], macaddr[4], macaddr[5]);
84
+ g_free(nc->info_str);
85
+ nc->info_str = g_strdup_printf(
86
+ "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
87
+ nc->model,
88
+ macaddr[0], macaddr[1], macaddr[2],
89
+ macaddr[3], macaddr[4], macaddr[5]);
90
}
91
92
static int mac_table[256] = {0};
93
@@ -XXX,XX +XXX,XX @@ static void qemu_free_net_client(NetClientState *nc)
94
}
95
g_free(nc->name);
96
g_free(nc->model);
97
+ g_free(nc->info_str);
98
qapi_free_NetdevInfo(nc->stored_config);
99
if (nc->destructor) {
100
nc->destructor(nc);
101
@@ -XXX,XX +XXX,XX @@ void print_net_client(Monitor *mon, NetClientState *nc)
102
monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
103
nc->queue_index,
104
NetClientDriver_str(nc->info->type),
105
- nc->info_str);
106
+ nc->info_str ? nc->info_str : "");
107
if (!QTAILQ_EMPTY(&nc->filters)) {
108
monitor_printf(mon, "filters:\n");
109
}
110
diff --git a/net/slirp.c b/net/slirp.c
111
index XXXXXXX..XXXXXXX 100644
112
--- a/net/slirp.c
113
+++ b/net/slirp.c
114
@@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model,
115
stored->tftp_server_name = g_strdup(tftp_server_name);
116
}
117
118
- snprintf(nc->info_str, sizeof(nc->info_str),
119
- "net=%s,restrict=%s", inet_ntoa(net),
120
- restricted ? "on" : "off");
121
+ nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net),
122
+ restricted ? "on" : "off");
123
124
s = DO_UPCAST(SlirpState, nc, nc);
125
126
diff --git a/net/socket.c b/net/socket.c
127
index XXXXXXX..XXXXXXX 100644
128
--- a/net/socket.c
129
+++ b/net/socket.c
130
@@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque)
131
s->fd = -1;
132
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
133
s->nc.link_down = true;
134
- memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
135
+ g_free(s->nc.info_str);
136
+ s->nc.info_str = g_new0(char, 1);
137
138
return;
139
}
140
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
141
stored->mcast = g_strdup(mcast);
142
143
s->dgram_dst = saddr;
144
- snprintf(nc->info_str, sizeof(nc->info_str),
145
- "socket: fd=%d (cloned mcast=%s:%d)",
146
- fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
147
+ nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)",
148
+ fd, inet_ntoa(saddr.sin_addr),
149
+ ntohs(saddr.sin_port));
150
} else {
151
if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) {
152
s->dgram_dst.sin_family = AF_UNIX;
153
}
154
155
- snprintf(nc->info_str, sizeof(nc->info_str),
156
- "socket: fd=%d %s", fd, SocketAddressType_str(sa_type));
157
+ nc->info_str = g_strdup_printf("socket: fd=%d %s",
158
+ fd, SocketAddressType_str(sa_type));
159
}
160
161
return s;
162
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
163
164
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
165
166
- snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd);
167
+ nc->info_str = g_strdup_printf("socket: fd=%d", fd);
168
169
s = DO_UPCAST(NetSocketState, nc, nc);
170
171
@@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque)
172
stored->has_fd = true;
173
stored->fd = g_strdup_printf("%d", fd);
174
175
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
176
- "socket: connection from %s:%d",
177
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
178
+ g_free(s->nc.info_str);
179
+ s->nc.info_str = g_strdup_printf("socket: connection from %s:%d",
180
+ inet_ntoa(saddr.sin_addr),
181
+ ntohs(saddr.sin_port));
182
}
183
184
static int net_socket_listen_init(NetClientState *peer,
185
@@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer,
186
stored->has_connect = true;
187
stored->connect = g_strdup(host_str);
188
189
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
190
- "socket: connect to %s:%d",
191
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
192
+ g_free(s->nc.info_str);
193
+ s->nc.info_str = g_strdup_printf("socket: connect to %s:%d",
194
+ inet_ntoa(saddr.sin_addr),
195
+ ntohs(saddr.sin_port));
196
return 0;
197
}
198
199
@@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer,
200
stored->localaddr = g_strdup(localaddr_str);
201
}
202
203
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
204
- "socket: mcast=%s:%d",
205
- inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port));
206
+ g_free(s->nc.info_str);
207
+ s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d",
208
+ inet_ntoa(saddr.sin_addr),
209
+ ntohs(saddr.sin_port));
210
return 0;
211
212
}
213
@@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer,
214
stored->has_udp = true;
215
stored->udp = g_strdup(rhost);
216
217
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
218
- "socket: udp=%s:%d",
219
- inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port));
220
+ g_free(s->nc.info_str);
221
+ s->nc.info_str = g_strdup_printf("socket: udp=%s:%d",
222
+ inet_ntoa(raddr.sin_addr),
223
+ ntohs(raddr.sin_port));
224
return 0;
225
}
226
227
diff --git a/net/tap-win32.c b/net/tap-win32.c
228
index XXXXXXX..XXXXXXX 100644
229
--- a/net/tap-win32.c
230
+++ b/net/tap-win32.c
231
@@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model,
232
stored->has_ifname = true;
233
stored->ifname = g_strdup(ifname);
234
235
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
236
- "tap: ifname=%s", ifname);
237
+ s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname);
238
239
s->handle = handle;
240
241
diff --git a/net/tap.c b/net/tap.c
242
index XXXXXXX..XXXXXXX 100644
243
--- a/net/tap.c
244
+++ b/net/tap.c
245
@@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name,
246
stored->helper = g_strdup(helper);
247
}
248
249
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper,
250
- br);
251
+ s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br);
252
253
return 0;
254
}
255
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
256
g_free(tmp_s);
257
}
258
259
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd);
260
+ s->nc.info_str = g_strdup_printf("fd=%d", fd);
261
} else if (tap->has_helper) {
262
if (!stored->has_helper) {
263
stored->has_helper = true;
264
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
265
g_strdup(DEFAULT_BRIDGE_INTERFACE);
266
}
267
268
- snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s",
269
- tap->helper);
270
+ s->nc.info_str = g_strdup_printf("helper=%s", tap->helper);
271
} else {
272
if (ifname && !stored->has_ifname) {
273
stored->has_ifname = true;
274
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
275
stored->downscript = g_strdup(downscript);
276
}
277
278
- snprintf(s->nc.info_str, sizeof(s->nc.info_str),
279
- "ifname=%s,script=%s,downscript=%s", ifname, script,
280
- downscript);
281
+ s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s",
282
+ ifname, script, downscript);
283
284
if (strcmp(downscript, "no") != 0) {
285
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
286
diff --git a/net/vde.c b/net/vde.c
287
index XXXXXXX..XXXXXXX 100644
288
--- a/net/vde.c
289
+++ b/net/vde.c
290
@@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model,
291
292
nc = qemu_new_net_client(&net_vde_info, peer, model, name);
293
294
- snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d",
295
- sock, vde_datafd(vde));
296
+ nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde));
297
298
s = DO_UPCAST(VDEState, nc, nc);
299
300
diff --git a/net/vhost-user.c b/net/vhost-user.c
301
index XXXXXXX..XXXXXXX 100644
302
--- a/net/vhost-user.c
303
+++ b/net/vhost-user.c
304
@@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
305
user = g_new0(struct VhostUserState, 1);
306
for (i = 0; i < queues; i++) {
307
nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
308
- snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s",
309
- i, chr->label);
310
+ nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label);
311
nc->queue_index = i;
312
if (!nc0) {
313
nc0 = nc;
314
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
315
index XXXXXXX..XXXXXXX 100644
316
--- a/net/vhost-vdpa.c
317
+++ b/net/vhost-vdpa.c
318
@@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
319
stored->has_queues = true;
320
stored->queues = 1; /* TODO: change when support multiqueue */
321
322
- snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA);
323
+ nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA);
324
nc->queue_index = 0;
325
s = DO_UPCAST(VhostVDPAState, nc, nc);
326
vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR);
327
--
328
2.7.4
329
330
diff view generated by jsdifflib
New patch
1
1
From: Alexey Kirillov <lekiravi@yandex-team.ru>
2
3
Replace usage of legacy field info_str of NetClientState for backend
4
network devices with QAPI NetdevInfo stored_config that already used
5
in QMP query-netdev.
6
7
This change increases the detail of the "info network" output and takes
8
a more general approach to composing the output.
9
10
NIC and hubports still use legacy info_str field.
11
12
Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
14
---
15
include/qapi/hmp-output-visitor.h | 30 ++++++
16
net/net.c | 31 +++++-
17
qapi/hmp-output-visitor.c | 193 ++++++++++++++++++++++++++++++++++++++
18
qapi/meson.build | 1 +
19
4 files changed, 254 insertions(+), 1 deletion(-)
20
create mode 100644 include/qapi/hmp-output-visitor.h
21
create mode 100644 qapi/hmp-output-visitor.c
22
23
diff --git a/include/qapi/hmp-output-visitor.h b/include/qapi/hmp-output-visitor.h
24
new file mode 100644
25
index XXXXXXX..XXXXXXX
26
--- /dev/null
27
+++ b/include/qapi/hmp-output-visitor.h
28
@@ -XXX,XX +XXX,XX @@
29
+/*
30
+ * HMP string output Visitor
31
+ *
32
+ * Copyright Yandex N.V., 2021
33
+ *
34
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
35
+ * See the COPYING file in the top-level directory.
36
+ *
37
+ */
38
+
39
+#ifndef HMP_OUTPUT_VISITOR_H
40
+#define HMP_OUTPUT_VISITOR_H
41
+
42
+#include "qapi/visitor.h"
43
+
44
+typedef struct HMPOutputVisitor HMPOutputVisitor;
45
+
46
+/**
47
+ * Create a HMP string output visitor for @obj
48
+ *
49
+ * Flattens dicts/structures, only shows arrays borders.
50
+ *
51
+ * Errors are not expected to happen.
52
+ *
53
+ * The caller is responsible for freeing the visitor with
54
+ * visit_free().
55
+ */
56
+Visitor *hmp_output_visitor_new(char **result);
57
+
58
+#endif
59
diff --git a/net/net.c b/net/net.c
60
index XXXXXXX..XXXXXXX 100644
61
--- a/net/net.c
62
+++ b/net/net.c
63
@@ -XXX,XX +XXX,XX @@
64
#include "sysemu/sysemu.h"
65
#include "net/filter.h"
66
#include "qapi/string-output-visitor.h"
67
+#include "qapi/hmp-output-visitor.h"
68
69
/* Net bridge is currently not supported for W32. */
70
#if !defined(_WIN32)
71
@@ -XXX,XX +XXX,XX @@ static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
72
monitor_printf(mon, "\n");
73
}
74
75
+static char *generate_info_str(NetClientState *nc)
76
+{
77
+ NetdevInfo *ni = nc->stored_config;
78
+ char *ret_out = NULL;
79
+ Visitor *v;
80
+
81
+ /* Use legacy field info_str for NIC and hubports */
82
+ if ((nc->info->type == NET_CLIENT_DRIVER_NIC) ||
83
+ (nc->info->type == NET_CLIENT_DRIVER_HUBPORT)) {
84
+ return g_strdup(nc->info_str ? nc->info_str : "");
85
+ }
86
+
87
+ if (!ni) {
88
+ return g_malloc0(1);
89
+ }
90
+
91
+ v = hmp_output_visitor_new(&ret_out);
92
+ if (visit_type_NetdevInfo(v, "", &ni, NULL)) {
93
+ visit_complete(v, &ret_out);
94
+ }
95
+ visit_free(v);
96
+
97
+ return ret_out;
98
+}
99
+
100
void print_net_client(Monitor *mon, NetClientState *nc)
101
{
102
NetFilterState *nf;
103
+ char *info_str = generate_info_str(nc);
104
105
monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
106
nc->queue_index,
107
NetClientDriver_str(nc->info->type),
108
- nc->info_str ? nc->info_str : "");
109
+ info_str);
110
+ g_free(info_str);
111
+
112
if (!QTAILQ_EMPTY(&nc->filters)) {
113
monitor_printf(mon, "filters:\n");
114
}
115
diff --git a/qapi/hmp-output-visitor.c b/qapi/hmp-output-visitor.c
116
new file mode 100644
117
index XXXXXXX..XXXXXXX
118
--- /dev/null
119
+++ b/qapi/hmp-output-visitor.c
120
@@ -XXX,XX +XXX,XX @@
121
+/*
122
+ * HMP string output Visitor
123
+ *
124
+ * Copyright Yandex N.V., 2021
125
+ *
126
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
127
+ * See the COPYING file in the top-level directory.
128
+ *
129
+ */
130
+
131
+#include "qemu/osdep.h"
132
+#include "qemu/cutils.h"
133
+#include "qapi/hmp-output-visitor.h"
134
+#include "qapi/visitor-impl.h"
135
+
136
+struct HMPOutputVisitor {
137
+ Visitor visitor;
138
+ char **result;
139
+ GString *buffer;
140
+ bool is_continue;
141
+};
142
+
143
+static HMPOutputVisitor *to_hov(Visitor *v)
144
+{
145
+ return container_of(v, HMPOutputVisitor, visitor);
146
+}
147
+
148
+static void hmp_output_append_formatted(Visitor *v, const char *fmt, ...)
149
+{
150
+ HMPOutputVisitor *ov = to_hov(v);
151
+ va_list args;
152
+
153
+ if (ov->is_continue) {
154
+ g_string_append(ov->buffer, ",");
155
+ } else {
156
+ ov->is_continue = true;
157
+ }
158
+
159
+ va_start(args, fmt);
160
+ g_string_append_vprintf(ov->buffer, fmt, args);
161
+ va_end(args);
162
+}
163
+
164
+static void hmp_output_skip_comma(Visitor *v)
165
+{
166
+ HMPOutputVisitor *ov = to_hov(v);
167
+
168
+ ov->is_continue = false;
169
+}
170
+
171
+static bool hmp_output_start_struct(Visitor *v, const char *name,
172
+ void **obj, size_t unused, Error **errp)
173
+{
174
+ return true;
175
+}
176
+
177
+static void hmp_output_end_struct(Visitor *v, void **obj) {}
178
+
179
+static bool hmp_output_start_list(Visitor *v, const char *name,
180
+ GenericList **listp, size_t size,
181
+ Error **errp)
182
+{
183
+ hmp_output_append_formatted(v, "%s=[", name);
184
+ /* First element in array without comma before it */
185
+ hmp_output_skip_comma(v);
186
+
187
+ return true;
188
+}
189
+
190
+static GenericList *hmp_output_next_list(Visitor *v, GenericList *tail,
191
+ size_t size)
192
+{
193
+ return tail->next;
194
+}
195
+
196
+static void hmp_output_end_list(Visitor *v, void **obj)
197
+{
198
+ /* Don't need comma after last array element */
199
+ hmp_output_skip_comma(v);
200
+ hmp_output_append_formatted(v, "]");
201
+}
202
+
203
+static bool hmp_output_type_int64(Visitor *v, const char *name,
204
+ int64_t *obj, Error **errp)
205
+{
206
+ hmp_output_append_formatted(v, "%s=%" PRId64, name, *obj);
207
+
208
+ return true;
209
+}
210
+
211
+static bool hmp_output_type_uint64(Visitor *v, const char *name,
212
+ uint64_t *obj, Error **errp)
213
+{
214
+ hmp_output_append_formatted(v, "%s=%" PRIu64, name, *obj);
215
+
216
+ return true;
217
+}
218
+
219
+static bool hmp_output_type_bool(Visitor *v, const char *name, bool *obj,
220
+ Error **errp)
221
+{
222
+ hmp_output_append_formatted(v, "%s=%s", name, *obj ? "true" : "false");
223
+
224
+ return true;
225
+}
226
+
227
+static bool hmp_output_type_str(Visitor *v, const char *name, char **obj,
228
+ Error **errp)
229
+{
230
+ /* Skip already printed or unused fields */
231
+ if (!*obj || g_str_equal(name, "id") || g_str_equal(name, "type")) {
232
+ return true;
233
+ }
234
+
235
+ /* Do not print stub name for StringList elements */
236
+ if (g_str_equal(name, "str")) {
237
+ hmp_output_append_formatted(v, "%s", *obj);
238
+ } else {
239
+ hmp_output_append_formatted(v, "%s=%s", name, *obj);
240
+ }
241
+
242
+ return true;
243
+}
244
+
245
+static bool hmp_output_type_number(Visitor *v, const char *name,
246
+ double *obj, Error **errp)
247
+{
248
+ hmp_output_append_formatted(v, "%s=%.17g", name, *obj);
249
+
250
+ return true;
251
+}
252
+
253
+/* TODO: remove this function? */
254
+static bool hmp_output_type_any(Visitor *v, const char *name,
255
+ QObject **obj, Error **errp)
256
+{
257
+ return true;
258
+}
259
+
260
+static bool hmp_output_type_null(Visitor *v, const char *name,
261
+ QNull **obj, Error **errp)
262
+{
263
+ hmp_output_append_formatted(v, "%s=NULL", name);
264
+
265
+ return true;
266
+}
267
+
268
+static void hmp_output_complete(Visitor *v, void *opaque)
269
+{
270
+ HMPOutputVisitor *ov = to_hov(v);
271
+
272
+ *ov->result = g_string_free(ov->buffer, false);
273
+ ov->buffer = NULL;
274
+}
275
+
276
+static void hmp_output_free(Visitor *v)
277
+{
278
+ HMPOutputVisitor *ov = to_hov(v);
279
+
280
+ if (ov->buffer) {
281
+ g_string_free(ov->buffer, true);
282
+ }
283
+ g_free(v);
284
+}
285
+
286
+Visitor *hmp_output_visitor_new(char **result)
287
+{
288
+ HMPOutputVisitor *v;
289
+
290
+ v = g_malloc0(sizeof(*v));
291
+
292
+ v->visitor.type = VISITOR_OUTPUT;
293
+ v->visitor.start_struct = hmp_output_start_struct;
294
+ v->visitor.end_struct = hmp_output_end_struct;
295
+ v->visitor.start_list = hmp_output_start_list;
296
+ v->visitor.next_list = hmp_output_next_list;
297
+ v->visitor.end_list = hmp_output_end_list;
298
+ v->visitor.type_int64 = hmp_output_type_int64;
299
+ v->visitor.type_uint64 = hmp_output_type_uint64;
300
+ v->visitor.type_bool = hmp_output_type_bool;
301
+ v->visitor.type_str = hmp_output_type_str;
302
+ v->visitor.type_number = hmp_output_type_number;
303
+ v->visitor.type_any = hmp_output_type_any;
304
+ v->visitor.type_null = hmp_output_type_null;
305
+ v->visitor.complete = hmp_output_complete;
306
+ v->visitor.free = hmp_output_free;
307
+
308
+ v->result = result;
309
+ v->buffer = g_string_new("");
310
+ v->is_continue = false;
311
+
312
+ return &v->visitor;
313
+}
314
diff --git a/qapi/meson.build b/qapi/meson.build
315
index XXXXXXX..XXXXXXX 100644
316
--- a/qapi/meson.build
317
+++ b/qapi/meson.build
318
@@ -XXX,XX +XXX,XX @@ util_ss.add(files(
319
'qobject-output-visitor.c',
320
'string-input-visitor.c',
321
'string-output-visitor.c',
322
+ 'hmp-output-visitor.c',
323
))
324
if have_system or have_tools
325
util_ss.add(files(
326
--
327
2.7.4
328
329
diff view generated by jsdifflib
New patch
1
1
From: Alexey Kirillov <lekiravi@yandex-team.ru>
2
3
As we use QAPI NetClientState->stored_config to store and get information
4
about backend network devices, we can drop fill of legacy field info_str
5
for them.
6
7
We still use info_str field for NIC and hubports, so we can not completely
8
remove it.
9
10
Signed-off-by: Alexey Kirillov <lekiravi@yandex-team.ru>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
13
net/l2tpv3.c | 2 --
14
net/slirp.c | 3 ---
15
net/socket.c | 28 ----------------------------
16
net/tap-win32.c | 2 --
17
net/tap.c | 9 ---------
18
net/vde.c | 2 --
19
net/vhost-user.c | 1 -
20
net/vhost-vdpa.c | 1 -
21
8 files changed, 48 deletions(-)
22
23
diff --git a/net/l2tpv3.c b/net/l2tpv3.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/net/l2tpv3.c
26
+++ b/net/l2tpv3.c
27
@@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev,
28
29
QAPI_CLONE_MEMBERS(NetdevL2TPv3Options,
30
&nc->stored_config->u.l2tpv3, l2tpv3);
31
-
32
- s->nc.info_str = g_strdup_printf("l2tpv3: connected");
33
return 0;
34
outerr:
35
qemu_del_net_client(nc);
36
diff --git a/net/slirp.c b/net/slirp.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/net/slirp.c
39
+++ b/net/slirp.c
40
@@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model,
41
stored->tftp_server_name = g_strdup(tftp_server_name);
42
}
43
44
- nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net),
45
- restricted ? "on" : "off");
46
-
47
s = DO_UPCAST(SlirpState, nc, nc);
48
49
s->slirp = slirp_init(restricted, ipv4, net, mask, host,
50
diff --git a/net/socket.c b/net/socket.c
51
index XXXXXXX..XXXXXXX 100644
52
--- a/net/socket.c
53
+++ b/net/socket.c
54
@@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque)
55
s->fd = -1;
56
net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
57
s->nc.link_down = true;
58
- g_free(s->nc.info_str);
59
- s->nc.info_str = g_new0(char, 1);
60
61
return;
62
}
63
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
64
stored->mcast = g_strdup(mcast);
65
66
s->dgram_dst = saddr;
67
- nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)",
68
- fd, inet_ntoa(saddr.sin_addr),
69
- ntohs(saddr.sin_port));
70
} else {
71
if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) {
72
s->dgram_dst.sin_family = AF_UNIX;
73
}
74
-
75
- nc->info_str = g_strdup_printf("socket: fd=%d %s",
76
- fd, SocketAddressType_str(sa_type));
77
}
78
79
return s;
80
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
81
82
nc = qemu_new_net_client(&net_socket_info, peer, model, name);
83
84
- nc->info_str = g_strdup_printf("socket: fd=%d", fd);
85
-
86
s = DO_UPCAST(NetSocketState, nc, nc);
87
88
s->fd = fd;
89
@@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque)
90
91
stored->has_fd = true;
92
stored->fd = g_strdup_printf("%d", fd);
93
-
94
- g_free(s->nc.info_str);
95
- s->nc.info_str = g_strdup_printf("socket: connection from %s:%d",
96
- inet_ntoa(saddr.sin_addr),
97
- ntohs(saddr.sin_port));
98
}
99
100
static int net_socket_listen_init(NetClientState *peer,
101
@@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer,
102
stored->has_connect = true;
103
stored->connect = g_strdup(host_str);
104
105
- g_free(s->nc.info_str);
106
- s->nc.info_str = g_strdup_printf("socket: connect to %s:%d",
107
- inet_ntoa(saddr.sin_addr),
108
- ntohs(saddr.sin_port));
109
return 0;
110
}
111
112
@@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer,
113
stored->localaddr = g_strdup(localaddr_str);
114
}
115
116
- g_free(s->nc.info_str);
117
- s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d",
118
- inet_ntoa(saddr.sin_addr),
119
- ntohs(saddr.sin_port));
120
return 0;
121
-
122
}
123
124
static int net_socket_udp_init(NetClientState *peer,
125
@@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer,
126
stored->has_udp = true;
127
stored->udp = g_strdup(rhost);
128
129
- g_free(s->nc.info_str);
130
- s->nc.info_str = g_strdup_printf("socket: udp=%s:%d",
131
- inet_ntoa(raddr.sin_addr),
132
- ntohs(raddr.sin_port));
133
return 0;
134
}
135
136
diff --git a/net/tap-win32.c b/net/tap-win32.c
137
index XXXXXXX..XXXXXXX 100644
138
--- a/net/tap-win32.c
139
+++ b/net/tap-win32.c
140
@@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model,
141
stored->has_ifname = true;
142
stored->ifname = g_strdup(ifname);
143
144
- s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname);
145
-
146
s->handle = handle;
147
148
qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s);
149
diff --git a/net/tap.c b/net/tap.c
150
index XXXXXXX..XXXXXXX 100644
151
--- a/net/tap.c
152
+++ b/net/tap.c
153
@@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name,
154
stored->helper = g_strdup(helper);
155
}
156
157
- s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br);
158
-
159
return 0;
160
}
161
162
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
163
stored->fds = g_strdup_printf("%s:%d", stored->fds, fd);
164
g_free(tmp_s);
165
}
166
-
167
- s->nc.info_str = g_strdup_printf("fd=%d", fd);
168
} else if (tap->has_helper) {
169
if (!stored->has_helper) {
170
stored->has_helper = true;
171
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
172
stored->br = tap->has_br ? g_strdup(tap->br) :
173
g_strdup(DEFAULT_BRIDGE_INTERFACE);
174
}
175
-
176
- s->nc.info_str = g_strdup_printf("helper=%s", tap->helper);
177
} else {
178
if (ifname && !stored->has_ifname) {
179
stored->has_ifname = true;
180
@@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
181
stored->downscript = g_strdup(downscript);
182
}
183
184
- s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s",
185
- ifname, script, downscript);
186
-
187
if (strcmp(downscript, "no") != 0) {
188
snprintf(s->down_script, sizeof(s->down_script), "%s", downscript);
189
snprintf(s->down_script_arg, sizeof(s->down_script_arg),
190
diff --git a/net/vde.c b/net/vde.c
191
index XXXXXXX..XXXXXXX 100644
192
--- a/net/vde.c
193
+++ b/net/vde.c
194
@@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model,
195
196
nc = qemu_new_net_client(&net_vde_info, peer, model, name);
197
198
- nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde));
199
-
200
s = DO_UPCAST(VDEState, nc, nc);
201
202
s->vde = vde;
203
diff --git a/net/vhost-user.c b/net/vhost-user.c
204
index XXXXXXX..XXXXXXX 100644
205
--- a/net/vhost-user.c
206
+++ b/net/vhost-user.c
207
@@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device,
208
user = g_new0(struct VhostUserState, 1);
209
for (i = 0; i < queues; i++) {
210
nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name);
211
- nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label);
212
nc->queue_index = i;
213
if (!nc0) {
214
nc0 = nc;
215
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
216
index XXXXXXX..XXXXXXX 100644
217
--- a/net/vhost-vdpa.c
218
+++ b/net/vhost-vdpa.c
219
@@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device,
220
stored->has_queues = true;
221
stored->queues = 1; /* TODO: change when support multiqueue */
222
223
- nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA);
224
nc->queue_index = 0;
225
s = DO_UPCAST(VhostVDPAState, nc, nc);
226
vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR);
227
--
228
2.7.4
229
230
diff view generated by jsdifflib