1 | The following changes since commit 6632f6ff96f0537fc34cdc00c760656fc62e23c5: | 1 | The following changes since commit d0d3dd401b70168a353450e031727affee828527: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/famz/tags/block-and-testing-pull-request' into staging (2017-07-17 11:46:36 +0100) | 3 | Update version for v6.0.0-rc2 release (2021-04-06 18:34:34 +0100) |
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 189ae6bb5ce1f5a322f8691d00fe942ba43dd601: | 9 | for you to fetch changes up to 21df394d9e2ffce9fa308f496d1ae228cf6cdb57: |
10 | 10 | ||
11 | virtio-net: fix offload ctrl endian (2017-07-17 20:13:56 +0800) | 11 | tap-win32: correctly recycle buffers (2021-04-08 17:33:59 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | 14 | ||
15 | - fix virtio-net ctrl offload endian | 15 | Fixes for rc3: |
16 | - vnet header support for variou COLO netfilters and compare thread | 16 | |
17 | - query-netdev is reverted (that's why the changeset is huge) | ||
18 | - fix a regression caused by padding for in TAP for win32 | ||
19 | |||
17 | 20 | ||
18 | ---------------------------------------------------------------- | 21 | ---------------------------------------------------------------- |
19 | Jason Wang (1): | 22 | Jason Wang (6): |
20 | virtio-net: fix offload ctrl endian | 23 | Revert "net: Do not fill legacy info_str for backends" |
24 | Revert "hmp: Use QAPI NetdevInfo in hmp_info_network" | ||
25 | Revert "net: Move NetClientState.info_str to dynamic allocations" | ||
26 | Revert "tests: Add tests for query-netdev command" | ||
27 | Revert "qapi: net: Add query-netdev command" | ||
28 | tap-win32: correctly recycle buffers | ||
21 | 29 | ||
22 | Michal Privoznik (1): | 30 | hw/net/xen_nic.c | 5 +- |
23 | virtion-net: Prefer is_power_of_2() | 31 | include/net/net.h | 5 +- |
24 | 32 | include/qapi/hmp-output-visitor.h | 30 ------ | |
25 | Zhang Chen (12): | 33 | net/l2tpv3.c | 8 +- |
26 | net: Add vnet_hdr_len arguments in NetClientState | 34 | net/net.c | 73 ++------------ |
27 | net/net.c: Add vnet_hdr support in SocketReadState | 35 | net/netmap.c | 7 -- |
28 | net/filter-mirror.c: Introduce parameter for filter_send() | 36 | net/slirp.c | 124 +----------------------- |
29 | net/filter-mirror.c: Make filter mirror support vnet support. | 37 | net/socket.c | 92 +++++------------- |
30 | net/filter-mirror.c: Add new option to enable vnet support for filter-redirector | 38 | net/tap-win32.c | 16 ++-- |
31 | net/colo.c: Make vnet_hdr_len as packet property | 39 | net/tap.c | 107 +++------------------ |
32 | net/colo-compare.c: Introduce parameter for compare_chr_send() | 40 | net/vde.c | 25 +---- |
33 | net/colo-compare.c: Make colo-compare support vnet_hdr_len | 41 | net/vhost-user.c | 20 +--- |
34 | net/colo.c: Add vnet packet parse feature in colo-proxy | 42 | net/vhost-vdpa.c | 15 +-- |
35 | net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare | 43 | qapi/hmp-output-visitor.c | 193 -------------------------------------- |
36 | net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len | 44 | qapi/meson.build | 1 - |
37 | docs/colo-proxy.txt: Update colo-proxy usage of net driver with vnet_header | 45 | qapi/net.json | 80 ---------------- |
38 | 46 | tests/qtest/meson.build | 3 - | |
39 | docs/colo-proxy.txt | 26 ++++++++++++++++ | 47 | tests/qtest/test-query-netdev.c | 120 ------------------------ |
40 | hw/net/virtio-net.c | 4 ++- | 48 | 18 files changed, 66 insertions(+), 858 deletions(-) |
41 | include/net/net.h | 10 ++++-- | 49 | delete mode 100644 include/qapi/hmp-output-visitor.h |
42 | net/colo-compare.c | 84 ++++++++++++++++++++++++++++++++++++++++++--------- | 50 | delete mode 100644 qapi/hmp-output-visitor.c |
43 | net/colo.c | 9 +++--- | 51 | delete mode 100644 tests/qtest/test-query-netdev.c |
44 | net/colo.h | 4 ++- | ||
45 | net/filter-mirror.c | 75 +++++++++++++++++++++++++++++++++++++++++---- | ||
46 | net/filter-rewriter.c | 37 ++++++++++++++++++++++- | ||
47 | net/net.c | 37 ++++++++++++++++++++--- | ||
48 | net/socket.c | 8 ++--- | ||
49 | qemu-options.hx | 19 ++++++------ | ||
50 | 11 files changed, 265 insertions(+), 48 deletions(-) | ||
51 | 52 | ||
52 | 53 | ||
54 | diff view generated by jsdifflib |
1 | Spec said offloads should be le64, so use virtio_ldq_p() to guarantee | 1 | Several issues has been reported for query-netdev info |
---|---|---|---|
2 | valid endian. | 2 | series. Consider it's late in the rc, this reverts commit |
3 | 3 | f2e8319d456724c3d8514d943dc4607e2f08e88a. | |
4 | Fixes: 644c98587d4c ("virtio-net: dynamic network offloads configuration") | 4 | |
5 | Cc: qemu-stable@nongnu.org | ||
6 | Cc: Dmitry Fleytman <dfleytma@redhat.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 5 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 6 | --- |
9 | hw/net/virtio-net.c | 2 ++ | 7 | net/l2tpv3.c | 2 ++ |
10 | 1 file changed, 2 insertions(+) | 8 | net/slirp.c | 3 +++ |
11 | 9 | net/socket.c | 28 ++++++++++++++++++++++++++++ | |
12 | diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c | 10 | net/tap-win32.c | 2 ++ |
13 | index XXXXXXX..XXXXXXX 100644 | 11 | net/tap.c | 9 +++++++++ |
14 | --- a/hw/net/virtio-net.c | 12 | net/vde.c | 2 ++ |
15 | +++ b/hw/net/virtio-net.c | 13 | net/vhost-user.c | 1 + |
16 | @@ -XXX,XX +XXX,XX @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd, | 14 | net/vhost-vdpa.c | 1 + |
17 | if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) { | 15 | 8 files changed, 48 insertions(+) |
18 | uint64_t supported_offloads; | 16 | |
19 | 17 | diff --git a/net/l2tpv3.c b/net/l2tpv3.c | |
20 | + offloads = virtio_ldq_p(vdev, &offloads); | 18 | index XXXXXXX..XXXXXXX 100644 |
21 | + | 19 | --- a/net/l2tpv3.c |
22 | if (!n->has_vnet_hdr) { | 20 | +++ b/net/l2tpv3.c |
23 | return VIRTIO_NET_ERR; | 21 | @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, |
24 | } | 22 | |
23 | QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, | ||
24 | &nc->stored_config->u.l2tpv3, l2tpv3); | ||
25 | + | ||
26 | + s->nc.info_str = g_strdup_printf("l2tpv3: connected"); | ||
27 | return 0; | ||
28 | outerr: | ||
29 | qemu_del_net_client(nc); | ||
30 | diff --git a/net/slirp.c b/net/slirp.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/net/slirp.c | ||
33 | +++ b/net/slirp.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
35 | stored->tftp_server_name = g_strdup(tftp_server_name); | ||
36 | } | ||
37 | |||
38 | + nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net), | ||
39 | + restricted ? "on" : "off"); | ||
40 | + | ||
41 | s = DO_UPCAST(SlirpState, nc, nc); | ||
42 | |||
43 | s->slirp = slirp_init(restricted, ipv4, net, mask, host, | ||
44 | diff --git a/net/socket.c b/net/socket.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/net/socket.c | ||
47 | +++ b/net/socket.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque) | ||
49 | s->fd = -1; | ||
50 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
51 | s->nc.link_down = true; | ||
52 | + g_free(s->nc.info_str); | ||
53 | + s->nc.info_str = g_new0(char, 1); | ||
54 | |||
55 | return; | ||
56 | } | ||
57 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
58 | stored->mcast = g_strdup(mcast); | ||
59 | |||
60 | s->dgram_dst = saddr; | ||
61 | + nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)", | ||
62 | + fd, inet_ntoa(saddr.sin_addr), | ||
63 | + ntohs(saddr.sin_port)); | ||
64 | } else { | ||
65 | if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) { | ||
66 | s->dgram_dst.sin_family = AF_UNIX; | ||
67 | } | ||
68 | + | ||
69 | + nc->info_str = g_strdup_printf("socket: fd=%d %s", | ||
70 | + fd, SocketAddressType_str(sa_type)); | ||
71 | } | ||
72 | |||
73 | return s; | ||
74 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | ||
75 | |||
76 | nc = qemu_new_net_client(&net_socket_info, peer, model, name); | ||
77 | |||
78 | + nc->info_str = g_strdup_printf("socket: fd=%d", fd); | ||
79 | + | ||
80 | s = DO_UPCAST(NetSocketState, nc, nc); | ||
81 | |||
82 | s->fd = fd; | ||
83 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | ||
84 | |||
85 | stored->has_fd = true; | ||
86 | stored->fd = g_strdup_printf("%d", fd); | ||
87 | + | ||
88 | + g_free(s->nc.info_str); | ||
89 | + s->nc.info_str = g_strdup_printf("socket: connection from %s:%d", | ||
90 | + inet_ntoa(saddr.sin_addr), | ||
91 | + ntohs(saddr.sin_port)); | ||
92 | } | ||
93 | |||
94 | static int net_socket_listen_init(NetClientState *peer, | ||
95 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
96 | stored->has_connect = true; | ||
97 | stored->connect = g_strdup(host_str); | ||
98 | |||
99 | + g_free(s->nc.info_str); | ||
100 | + s->nc.info_str = g_strdup_printf("socket: connect to %s:%d", | ||
101 | + inet_ntoa(saddr.sin_addr), | ||
102 | + ntohs(saddr.sin_port)); | ||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
107 | stored->localaddr = g_strdup(localaddr_str); | ||
108 | } | ||
109 | |||
110 | + g_free(s->nc.info_str); | ||
111 | + s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d", | ||
112 | + inet_ntoa(saddr.sin_addr), | ||
113 | + ntohs(saddr.sin_port)); | ||
114 | return 0; | ||
115 | + | ||
116 | } | ||
117 | |||
118 | static int net_socket_udp_init(NetClientState *peer, | ||
119 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
120 | stored->has_udp = true; | ||
121 | stored->udp = g_strdup(rhost); | ||
122 | |||
123 | + g_free(s->nc.info_str); | ||
124 | + s->nc.info_str = g_strdup_printf("socket: udp=%s:%d", | ||
125 | + inet_ntoa(raddr.sin_addr), | ||
126 | + ntohs(raddr.sin_port)); | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | diff --git a/net/tap-win32.c b/net/tap-win32.c | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/net/tap-win32.c | ||
133 | +++ b/net/tap-win32.c | ||
134 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
135 | stored->has_ifname = true; | ||
136 | stored->ifname = g_strdup(ifname); | ||
137 | |||
138 | + s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname); | ||
139 | + | ||
140 | s->handle = handle; | ||
141 | |||
142 | qemu_add_wait_object(s->handle->tap_semaphore, tap_win32_send, s); | ||
143 | diff --git a/net/tap.c b/net/tap.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/net/tap.c | ||
146 | +++ b/net/tap.c | ||
147 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
148 | stored->helper = g_strdup(helper); | ||
149 | } | ||
150 | |||
151 | + s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br); | ||
152 | + | ||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
157 | stored->fds = g_strdup_printf("%s:%d", stored->fds, fd); | ||
158 | g_free(tmp_s); | ||
159 | } | ||
160 | + | ||
161 | + s->nc.info_str = g_strdup_printf("fd=%d", fd); | ||
162 | } else if (tap->has_helper) { | ||
163 | if (!stored->has_helper) { | ||
164 | stored->has_helper = true; | ||
165 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
166 | stored->br = tap->has_br ? g_strdup(tap->br) : | ||
167 | g_strdup(DEFAULT_BRIDGE_INTERFACE); | ||
168 | } | ||
169 | + | ||
170 | + s->nc.info_str = g_strdup_printf("helper=%s", tap->helper); | ||
171 | } else { | ||
172 | if (ifname && !stored->has_ifname) { | ||
173 | stored->has_ifname = true; | ||
174 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
175 | stored->downscript = g_strdup(downscript); | ||
176 | } | ||
177 | |||
178 | + s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s", | ||
179 | + ifname, script, downscript); | ||
180 | + | ||
181 | if (strcmp(downscript, "no") != 0) { | ||
182 | snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); | ||
183 | snprintf(s->down_script_arg, sizeof(s->down_script_arg), | ||
184 | diff --git a/net/vde.c b/net/vde.c | ||
185 | index XXXXXXX..XXXXXXX 100644 | ||
186 | --- a/net/vde.c | ||
187 | +++ b/net/vde.c | ||
188 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
189 | |||
190 | nc = qemu_new_net_client(&net_vde_info, peer, model, name); | ||
191 | |||
192 | + nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde)); | ||
193 | + | ||
194 | s = DO_UPCAST(VDEState, nc, nc); | ||
195 | |||
196 | s->vde = vde; | ||
197 | diff --git a/net/vhost-user.c b/net/vhost-user.c | ||
198 | index XXXXXXX..XXXXXXX 100644 | ||
199 | --- a/net/vhost-user.c | ||
200 | +++ b/net/vhost-user.c | ||
201 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
202 | user = g_new0(struct VhostUserState, 1); | ||
203 | for (i = 0; i < queues; i++) { | ||
204 | nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); | ||
205 | + nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label); | ||
206 | nc->queue_index = i; | ||
207 | if (!nc0) { | ||
208 | nc0 = nc; | ||
209 | diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c | ||
210 | index XXXXXXX..XXXXXXX 100644 | ||
211 | --- a/net/vhost-vdpa.c | ||
212 | +++ b/net/vhost-vdpa.c | ||
213 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, | ||
214 | stored->has_queues = true; | ||
215 | stored->queues = 1; /* TODO: change when support multiqueue */ | ||
216 | |||
217 | + nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA); | ||
218 | nc->queue_index = 0; | ||
219 | s = DO_UPCAST(VhostVDPAState, nc, nc); | ||
220 | vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR); | ||
25 | -- | 221 | -- |
26 | 2.7.4 | 222 | 2.7.4 |
27 | 223 | ||
28 | 224 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | Several issues has been reported for query-netdev info |
---|---|---|---|
2 | series. Consider it's late in the rc, this reverts commit | ||
3 | a0724776c5a98a08fc946bb5a4ad16410ca64c0e. | ||
2 | 4 | ||
3 | We add the vnet_hdr_support option for filter-rewriter, default is disabled. | ||
4 | If you use virtio-net-pci or other driver needs vnet_hdr, please enable it. | ||
5 | You can use it for example: | ||
6 | -object filter-rewriter,id=rew0,netdev=hn0,queue=all,vnet_hdr_support | ||
7 | |||
8 | We get the vnet_hdr_len from NetClientState that make us | ||
9 | parse net packet correctly. | ||
10 | |||
11 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
12 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 5 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
13 | --- | 6 | --- |
14 | net/filter-rewriter.c | 37 ++++++++++++++++++++++++++++++++++++- | 7 | include/qapi/hmp-output-visitor.h | 30 ------ |
15 | qemu-options.hx | 4 ++-- | 8 | net/net.c | 31 +----- |
16 | 2 files changed, 38 insertions(+), 3 deletions(-) | 9 | qapi/hmp-output-visitor.c | 193 -------------------------------------- |
10 | qapi/meson.build | 1 - | ||
11 | 4 files changed, 1 insertion(+), 254 deletions(-) | ||
12 | delete mode 100644 include/qapi/hmp-output-visitor.h | ||
13 | delete mode 100644 qapi/hmp-output-visitor.c | ||
17 | 14 | ||
18 | diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c | 15 | diff --git a/include/qapi/hmp-output-visitor.h b/include/qapi/hmp-output-visitor.h |
16 | deleted file mode 100644 | ||
17 | index XXXXXXX..XXXXXXX | ||
18 | --- a/include/qapi/hmp-output-visitor.h | ||
19 | +++ /dev/null | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | -/* | ||
22 | - * HMP string output Visitor | ||
23 | - * | ||
24 | - * Copyright Yandex N.V., 2021 | ||
25 | - * | ||
26 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
27 | - * See the COPYING file in the top-level directory. | ||
28 | - * | ||
29 | - */ | ||
30 | - | ||
31 | -#ifndef HMP_OUTPUT_VISITOR_H | ||
32 | -#define HMP_OUTPUT_VISITOR_H | ||
33 | - | ||
34 | -#include "qapi/visitor.h" | ||
35 | - | ||
36 | -typedef struct HMPOutputVisitor HMPOutputVisitor; | ||
37 | - | ||
38 | -/** | ||
39 | - * Create a HMP string output visitor for @obj | ||
40 | - * | ||
41 | - * Flattens dicts/structures, only shows arrays borders. | ||
42 | - * | ||
43 | - * Errors are not expected to happen. | ||
44 | - * | ||
45 | - * The caller is responsible for freeing the visitor with | ||
46 | - * visit_free(). | ||
47 | - */ | ||
48 | -Visitor *hmp_output_visitor_new(char **result); | ||
49 | - | ||
50 | -#endif | ||
51 | diff --git a/net/net.c b/net/net.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/net/filter-rewriter.c | 53 | --- a/net/net.c |
21 | +++ b/net/filter-rewriter.c | 54 | +++ b/net/net.c |
22 | @@ -XXX,XX +XXX,XX @@ | 55 | @@ -XXX,XX +XXX,XX @@ |
23 | #include "qemu-common.h" | 56 | #include "sysemu/sysemu.h" |
24 | #include "qapi/error.h" | 57 | #include "net/filter.h" |
25 | #include "qapi/qmp/qerror.h" | 58 | #include "qapi/string-output-visitor.h" |
26 | +#include "qemu/error-report.h" | 59 | -#include "qapi/hmp-output-visitor.h" |
27 | #include "qapi-visit.h" | 60 | |
28 | #include "qom/object.h" | 61 | /* Net bridge is currently not supported for W32. */ |
29 | #include "qemu/main-loop.h" | 62 | #if !defined(_WIN32) |
30 | @@ -XXX,XX +XXX,XX @@ typedef struct RewriterState { | 63 | @@ -XXX,XX +XXX,XX @@ static void netfilter_print_info(Monitor *mon, NetFilterState *nf) |
31 | NetQueue *incoming_queue; | 64 | monitor_printf(mon, "\n"); |
32 | /* hashtable to save connection */ | ||
33 | GHashTable *connection_track_table; | ||
34 | + bool vnet_hdr; | ||
35 | } RewriterState; | ||
36 | |||
37 | static void filter_rewriter_flush(NetFilterState *nf) | ||
38 | @@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, | ||
39 | ConnectionKey key; | ||
40 | Packet *pkt; | ||
41 | ssize_t size = iov_size(iov, iovcnt); | ||
42 | + ssize_t vnet_hdr_len = 0; | ||
43 | char *buf = g_malloc0(size); | ||
44 | |||
45 | iov_to_buf(iov, iovcnt, 0, buf, size); | ||
46 | - pkt = packet_new(buf, size, 0); | ||
47 | + | ||
48 | + if (s->vnet_hdr) { | ||
49 | + vnet_hdr_len = nf->netdev->vnet_hdr_len; | ||
50 | + } | ||
51 | + | ||
52 | + pkt = packet_new(buf, size, vnet_hdr_len); | ||
53 | g_free(buf); | ||
54 | |||
55 | /* | ||
56 | @@ -XXX,XX +XXX,XX @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) | ||
57 | s->incoming_queue = qemu_new_net_queue(qemu_netfilter_pass_to_next, nf); | ||
58 | } | 65 | } |
59 | 66 | ||
60 | +static bool filter_rewriter_get_vnet_hdr(Object *obj, Error **errp) | 67 | -static char *generate_info_str(NetClientState *nc) |
61 | +{ | 68 | -{ |
62 | + RewriterState *s = FILTER_COLO_REWRITER(obj); | 69 | - NetdevInfo *ni = nc->stored_config; |
63 | + | 70 | - char *ret_out = NULL; |
64 | + return s->vnet_hdr; | 71 | - Visitor *v; |
65 | +} | 72 | - |
66 | + | 73 | - /* Use legacy field info_str for NIC and hubports */ |
67 | +static void filter_rewriter_set_vnet_hdr(Object *obj, | 74 | - if ((nc->info->type == NET_CLIENT_DRIVER_NIC) || |
68 | + bool value, | 75 | - (nc->info->type == NET_CLIENT_DRIVER_HUBPORT)) { |
69 | + Error **errp) | 76 | - return g_strdup(nc->info_str ? nc->info_str : ""); |
70 | +{ | 77 | - } |
71 | + RewriterState *s = FILTER_COLO_REWRITER(obj); | 78 | - |
72 | + | 79 | - if (!ni) { |
73 | + s->vnet_hdr = value; | 80 | - return g_malloc0(1); |
74 | +} | 81 | - } |
75 | + | 82 | - |
76 | +static void filter_rewriter_init(Object *obj) | 83 | - v = hmp_output_visitor_new(&ret_out); |
77 | +{ | 84 | - if (visit_type_NetdevInfo(v, "", &ni, NULL)) { |
78 | + RewriterState *s = FILTER_COLO_REWRITER(obj); | 85 | - visit_complete(v, &ret_out); |
79 | + | 86 | - } |
80 | + s->vnet_hdr = false; | 87 | - visit_free(v); |
81 | + object_property_add_bool(obj, "vnet_hdr_support", | 88 | - |
82 | + filter_rewriter_get_vnet_hdr, | 89 | - return ret_out; |
83 | + filter_rewriter_set_vnet_hdr, NULL); | 90 | -} |
84 | +} | 91 | - |
85 | + | 92 | void print_net_client(Monitor *mon, NetClientState *nc) |
86 | static void colo_rewriter_class_init(ObjectClass *oc, void *data) | ||
87 | { | 93 | { |
88 | NetFilterClass *nfc = NETFILTER_CLASS(oc); | 94 | NetFilterState *nf; |
89 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo colo_rewriter_info = { | 95 | - char *info_str = generate_info_str(nc); |
90 | .name = TYPE_FILTER_REWRITER, | 96 | |
91 | .parent = TYPE_NETFILTER, | 97 | monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, |
92 | .class_init = colo_rewriter_class_init, | 98 | nc->queue_index, |
93 | + .instance_init = filter_rewriter_init, | 99 | NetClientDriver_str(nc->info->type), |
94 | .instance_size = sizeof(RewriterState), | 100 | - info_str); |
95 | }; | 101 | - g_free(info_str); |
96 | 102 | - | |
97 | diff --git a/qemu-options.hx b/qemu-options.hx | 103 | + nc->info_str ? nc->info_str : ""); |
104 | if (!QTAILQ_EMPTY(&nc->filters)) { | ||
105 | monitor_printf(mon, "filters:\n"); | ||
106 | } | ||
107 | diff --git a/qapi/hmp-output-visitor.c b/qapi/hmp-output-visitor.c | ||
108 | deleted file mode 100644 | ||
109 | index XXXXXXX..XXXXXXX | ||
110 | --- a/qapi/hmp-output-visitor.c | ||
111 | +++ /dev/null | ||
112 | @@ -XXX,XX +XXX,XX @@ | ||
113 | -/* | ||
114 | - * HMP string output Visitor | ||
115 | - * | ||
116 | - * Copyright Yandex N.V., 2021 | ||
117 | - * | ||
118 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
119 | - * See the COPYING file in the top-level directory. | ||
120 | - * | ||
121 | - */ | ||
122 | - | ||
123 | -#include "qemu/osdep.h" | ||
124 | -#include "qemu/cutils.h" | ||
125 | -#include "qapi/hmp-output-visitor.h" | ||
126 | -#include "qapi/visitor-impl.h" | ||
127 | - | ||
128 | -struct HMPOutputVisitor { | ||
129 | - Visitor visitor; | ||
130 | - char **result; | ||
131 | - GString *buffer; | ||
132 | - bool is_continue; | ||
133 | -}; | ||
134 | - | ||
135 | -static HMPOutputVisitor *to_hov(Visitor *v) | ||
136 | -{ | ||
137 | - return container_of(v, HMPOutputVisitor, visitor); | ||
138 | -} | ||
139 | - | ||
140 | -static void hmp_output_append_formatted(Visitor *v, const char *fmt, ...) | ||
141 | -{ | ||
142 | - HMPOutputVisitor *ov = to_hov(v); | ||
143 | - va_list args; | ||
144 | - | ||
145 | - if (ov->is_continue) { | ||
146 | - g_string_append(ov->buffer, ","); | ||
147 | - } else { | ||
148 | - ov->is_continue = true; | ||
149 | - } | ||
150 | - | ||
151 | - va_start(args, fmt); | ||
152 | - g_string_append_vprintf(ov->buffer, fmt, args); | ||
153 | - va_end(args); | ||
154 | -} | ||
155 | - | ||
156 | -static void hmp_output_skip_comma(Visitor *v) | ||
157 | -{ | ||
158 | - HMPOutputVisitor *ov = to_hov(v); | ||
159 | - | ||
160 | - ov->is_continue = false; | ||
161 | -} | ||
162 | - | ||
163 | -static bool hmp_output_start_struct(Visitor *v, const char *name, | ||
164 | - void **obj, size_t unused, Error **errp) | ||
165 | -{ | ||
166 | - return true; | ||
167 | -} | ||
168 | - | ||
169 | -static void hmp_output_end_struct(Visitor *v, void **obj) {} | ||
170 | - | ||
171 | -static bool hmp_output_start_list(Visitor *v, const char *name, | ||
172 | - GenericList **listp, size_t size, | ||
173 | - Error **errp) | ||
174 | -{ | ||
175 | - hmp_output_append_formatted(v, "%s=[", name); | ||
176 | - /* First element in array without comma before it */ | ||
177 | - hmp_output_skip_comma(v); | ||
178 | - | ||
179 | - return true; | ||
180 | -} | ||
181 | - | ||
182 | -static GenericList *hmp_output_next_list(Visitor *v, GenericList *tail, | ||
183 | - size_t size) | ||
184 | -{ | ||
185 | - return tail->next; | ||
186 | -} | ||
187 | - | ||
188 | -static void hmp_output_end_list(Visitor *v, void **obj) | ||
189 | -{ | ||
190 | - /* Don't need comma after last array element */ | ||
191 | - hmp_output_skip_comma(v); | ||
192 | - hmp_output_append_formatted(v, "]"); | ||
193 | -} | ||
194 | - | ||
195 | -static bool hmp_output_type_int64(Visitor *v, const char *name, | ||
196 | - int64_t *obj, Error **errp) | ||
197 | -{ | ||
198 | - hmp_output_append_formatted(v, "%s=%" PRId64, name, *obj); | ||
199 | - | ||
200 | - return true; | ||
201 | -} | ||
202 | - | ||
203 | -static bool hmp_output_type_uint64(Visitor *v, const char *name, | ||
204 | - uint64_t *obj, Error **errp) | ||
205 | -{ | ||
206 | - hmp_output_append_formatted(v, "%s=%" PRIu64, name, *obj); | ||
207 | - | ||
208 | - return true; | ||
209 | -} | ||
210 | - | ||
211 | -static bool hmp_output_type_bool(Visitor *v, const char *name, bool *obj, | ||
212 | - Error **errp) | ||
213 | -{ | ||
214 | - hmp_output_append_formatted(v, "%s=%s", name, *obj ? "true" : "false"); | ||
215 | - | ||
216 | - return true; | ||
217 | -} | ||
218 | - | ||
219 | -static bool hmp_output_type_str(Visitor *v, const char *name, char **obj, | ||
220 | - Error **errp) | ||
221 | -{ | ||
222 | - /* Skip already printed or unused fields */ | ||
223 | - if (!*obj || g_str_equal(name, "id") || g_str_equal(name, "type")) { | ||
224 | - return true; | ||
225 | - } | ||
226 | - | ||
227 | - /* Do not print stub name for StringList elements */ | ||
228 | - if (g_str_equal(name, "str")) { | ||
229 | - hmp_output_append_formatted(v, "%s", *obj); | ||
230 | - } else { | ||
231 | - hmp_output_append_formatted(v, "%s=%s", name, *obj); | ||
232 | - } | ||
233 | - | ||
234 | - return true; | ||
235 | -} | ||
236 | - | ||
237 | -static bool hmp_output_type_number(Visitor *v, const char *name, | ||
238 | - double *obj, Error **errp) | ||
239 | -{ | ||
240 | - hmp_output_append_formatted(v, "%s=%.17g", name, *obj); | ||
241 | - | ||
242 | - return true; | ||
243 | -} | ||
244 | - | ||
245 | -/* TODO: remove this function? */ | ||
246 | -static bool hmp_output_type_any(Visitor *v, const char *name, | ||
247 | - QObject **obj, Error **errp) | ||
248 | -{ | ||
249 | - return true; | ||
250 | -} | ||
251 | - | ||
252 | -static bool hmp_output_type_null(Visitor *v, const char *name, | ||
253 | - QNull **obj, Error **errp) | ||
254 | -{ | ||
255 | - hmp_output_append_formatted(v, "%s=NULL", name); | ||
256 | - | ||
257 | - return true; | ||
258 | -} | ||
259 | - | ||
260 | -static void hmp_output_complete(Visitor *v, void *opaque) | ||
261 | -{ | ||
262 | - HMPOutputVisitor *ov = to_hov(v); | ||
263 | - | ||
264 | - *ov->result = g_string_free(ov->buffer, false); | ||
265 | - ov->buffer = NULL; | ||
266 | -} | ||
267 | - | ||
268 | -static void hmp_output_free(Visitor *v) | ||
269 | -{ | ||
270 | - HMPOutputVisitor *ov = to_hov(v); | ||
271 | - | ||
272 | - if (ov->buffer) { | ||
273 | - g_string_free(ov->buffer, true); | ||
274 | - } | ||
275 | - g_free(v); | ||
276 | -} | ||
277 | - | ||
278 | -Visitor *hmp_output_visitor_new(char **result) | ||
279 | -{ | ||
280 | - HMPOutputVisitor *v; | ||
281 | - | ||
282 | - v = g_malloc0(sizeof(*v)); | ||
283 | - | ||
284 | - v->visitor.type = VISITOR_OUTPUT; | ||
285 | - v->visitor.start_struct = hmp_output_start_struct; | ||
286 | - v->visitor.end_struct = hmp_output_end_struct; | ||
287 | - v->visitor.start_list = hmp_output_start_list; | ||
288 | - v->visitor.next_list = hmp_output_next_list; | ||
289 | - v->visitor.end_list = hmp_output_end_list; | ||
290 | - v->visitor.type_int64 = hmp_output_type_int64; | ||
291 | - v->visitor.type_uint64 = hmp_output_type_uint64; | ||
292 | - v->visitor.type_bool = hmp_output_type_bool; | ||
293 | - v->visitor.type_str = hmp_output_type_str; | ||
294 | - v->visitor.type_number = hmp_output_type_number; | ||
295 | - v->visitor.type_any = hmp_output_type_any; | ||
296 | - v->visitor.type_null = hmp_output_type_null; | ||
297 | - v->visitor.complete = hmp_output_complete; | ||
298 | - v->visitor.free = hmp_output_free; | ||
299 | - | ||
300 | - v->result = result; | ||
301 | - v->buffer = g_string_new(""); | ||
302 | - v->is_continue = false; | ||
303 | - | ||
304 | - return &v->visitor; | ||
305 | -} | ||
306 | diff --git a/qapi/meson.build b/qapi/meson.build | ||
98 | index XXXXXXX..XXXXXXX 100644 | 307 | index XXXXXXX..XXXXXXX 100644 |
99 | --- a/qemu-options.hx | 308 | --- a/qapi/meson.build |
100 | +++ b/qemu-options.hx | 309 | +++ b/qapi/meson.build |
101 | @@ -XXX,XX +XXX,XX @@ Create a filter-redirector we need to differ outdev id from indev id, id can not | 310 | @@ -XXX,XX +XXX,XX @@ util_ss.add(files( |
102 | be the same. we can just use indev or outdev, but at least one of indev or outdev | 311 | 'qobject-output-visitor.c', |
103 | need to be specified. | 312 | 'string-input-visitor.c', |
104 | 313 | 'string-output-visitor.c', | |
105 | -@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid}[,queue=@var{all|rx|tx}] | 314 | - 'hmp-output-visitor.c', |
106 | +@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},queue=@var{all|rx|tx},[vnet_hdr_support] | 315 | )) |
107 | 316 | if have_system or have_tools | |
108 | Filter-rewriter is a part of COLO project.It will rewrite tcp packet to | 317 | util_ss.add(files( |
109 | secondary from primary to keep secondary tcp connection,and rewrite | ||
110 | tcp packet to primary from secondary make tcp packet can be handled by | ||
111 | -client. | ||
112 | +client.if it has the vnet_hdr_support flag, we can parse packet with vnet header. | ||
113 | |||
114 | usage: | ||
115 | colo secondary: | ||
116 | -- | 318 | -- |
117 | 2.7.4 | 319 | 2.7.4 |
118 | 320 | ||
119 | 321 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | Several issues has been reported for query-netdev info |
---|---|---|---|
2 | series. Consider it's late in the rc, this reverts commit | ||
3 | commit 59b5437eb732d6b103a9bc279c3482c834d1eff9. | ||
2 | 4 | ||
3 | We add a flag to decide whether net_fill_rstate() need read | ||
4 | the vnet_hdr_len or not. | ||
5 | |||
6 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
7 | Suggested-by: Jason Wang <jasowang@redhat.com> | ||
8 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 5 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
9 | --- | 6 | --- |
10 | include/net/net.h | 9 +++++++-- | 7 | hw/net/xen_nic.c | 5 +++-- |
11 | net/colo-compare.c | 4 ++-- | 8 | include/net/net.h | 2 +- |
12 | net/filter-mirror.c | 2 +- | 9 | net/l2tpv3.c | 3 ++- |
13 | net/net.c | 36 ++++++++++++++++++++++++++++++++---- | 10 | net/net.c | 14 ++++++-------- |
14 | net/socket.c | 8 ++++---- | 11 | net/slirp.c | 5 +++-- |
15 | 5 files changed, 46 insertions(+), 13 deletions(-) | 12 | net/socket.c | 43 +++++++++++++++++++------------------------ |
13 | net/tap-win32.c | 3 ++- | ||
14 | net/tap.c | 13 ++++++++----- | ||
15 | net/vde.c | 3 ++- | ||
16 | net/vhost-user.c | 3 ++- | ||
17 | net/vhost-vdpa.c | 2 +- | ||
18 | 11 files changed, 49 insertions(+), 47 deletions(-) | ||
16 | 19 | ||
20 | diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/net/xen_nic.c | ||
23 | +++ b/hw/net/xen_nic.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static int net_init(struct XenLegacyDevice *xendev) | ||
25 | netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf, | ||
26 | "xen", NULL, netdev); | ||
27 | |||
28 | - qemu_get_queue(netdev->nic)->info_str = g_strdup_printf( | ||
29 | - "nic: xenbus vif macaddr=%s", netdev->mac); | ||
30 | + snprintf(qemu_get_queue(netdev->nic)->info_str, | ||
31 | + sizeof(qemu_get_queue(netdev->nic)->info_str), | ||
32 | + "nic: xenbus vif macaddr=%s", netdev->mac); | ||
33 | |||
34 | /* fill info */ | ||
35 | xenstore_write_be_int(&netdev->xendev, "feature-rx-copy", 1); | ||
17 | diff --git a/include/net/net.h b/include/net/net.h | 36 | diff --git a/include/net/net.h b/include/net/net.h |
18 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/net/net.h | 38 | --- a/include/net/net.h |
20 | +++ b/include/net/net.h | 39 | +++ b/include/net/net.h |
21 | @@ -XXX,XX +XXX,XX @@ typedef struct NICState { | 40 | @@ -XXX,XX +XXX,XX @@ struct NetClientState { |
22 | } NICState; | 41 | NetQueue *incoming_queue; |
23 | 42 | char *model; | |
24 | struct SocketReadState { | 43 | char *name; |
25 | - int state; /* 0 = getting length, 1 = getting data */ | 44 | - char *info_str; |
26 | + /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */ | 45 | + char info_str[256]; |
27 | + int state; | 46 | NetdevInfo *stored_config; |
28 | + /* This flag decide whether to read the vnet_hdr_len field */ | 47 | unsigned receive_disabled : 1; |
29 | + bool vnet_hdr; | 48 | NetClientDestructor *destructor; |
30 | uint32_t index; | 49 | diff --git a/net/l2tpv3.c b/net/l2tpv3.c |
31 | uint32_t packet_len; | 50 | index XXXXXXX..XXXXXXX 100644 |
32 | + uint32_t vnet_hdr_len; | 51 | --- a/net/l2tpv3.c |
33 | uint8_t buf[NET_BUFSIZE]; | 52 | +++ b/net/l2tpv3.c |
34 | SocketReadStateFinalize *finalize; | 53 | @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, |
35 | }; | 54 | QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, |
36 | @@ -XXX,XX +XXX,XX @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender, | 55 | &nc->stored_config->u.l2tpv3, l2tpv3); |
37 | void print_net_client(Monitor *mon, NetClientState *nc); | 56 | |
38 | void hmp_info_network(Monitor *mon, const QDict *qdict); | 57 | - s->nc.info_str = g_strdup_printf("l2tpv3: connected"); |
39 | void net_socket_rs_init(SocketReadState *rs, | 58 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), |
40 | - SocketReadStateFinalize *finalize); | 59 | + "l2tpv3: connected"); |
41 | + SocketReadStateFinalize *finalize, | 60 | return 0; |
42 | + bool vnet_hdr); | 61 | outerr: |
43 | 62 | qemu_del_net_client(nc); | |
44 | /* NIC info */ | ||
45 | |||
46 | diff --git a/net/colo-compare.c b/net/colo-compare.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/net/colo-compare.c | ||
49 | +++ b/net/colo-compare.c | ||
50 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) | ||
51 | return; | ||
52 | } | ||
53 | |||
54 | - net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize); | ||
55 | - net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize); | ||
56 | + net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false); | ||
57 | + net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false); | ||
58 | |||
59 | g_queue_init(&s->conn_list); | ||
60 | |||
61 | diff --git a/net/filter-mirror.c b/net/filter-mirror.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/net/filter-mirror.c | ||
64 | +++ b/net/filter-mirror.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) | ||
66 | } | ||
67 | } | ||
68 | |||
69 | - net_socket_rs_init(&s->rs, redirector_rs_finalize); | ||
70 | + net_socket_rs_init(&s->rs, redirector_rs_finalize, false); | ||
71 | |||
72 | if (s->indev) { | ||
73 | chr = qemu_chr_find(s->indev); | ||
74 | diff --git a/net/net.c b/net/net.c | 63 | diff --git a/net/net.c b/net/net.c |
75 | index XXXXXXX..XXXXXXX 100644 | 64 | index XXXXXXX..XXXXXXX 100644 |
76 | --- a/net/net.c | 65 | --- a/net/net.c |
77 | +++ b/net/net.c | 66 | +++ b/net/net.c |
78 | @@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_net_opts = { | 67 | @@ -XXX,XX +XXX,XX @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr) |
79 | }; | 68 | |
80 | 69 | void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]) | |
81 | void net_socket_rs_init(SocketReadState *rs, | ||
82 | - SocketReadStateFinalize *finalize) | ||
83 | + SocketReadStateFinalize *finalize, | ||
84 | + bool vnet_hdr) | ||
85 | { | 70 | { |
86 | rs->state = 0; | 71 | - g_free(nc->info_str); |
87 | + rs->vnet_hdr = vnet_hdr; | 72 | - nc->info_str = g_strdup_printf( |
88 | rs->index = 0; | 73 | - "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x", |
89 | rs->packet_len = 0; | 74 | - nc->model, |
90 | + rs->vnet_hdr_len = 0; | 75 | - macaddr[0], macaddr[1], macaddr[2], |
91 | memset(rs->buf, 0, sizeof(rs->buf)); | 76 | - macaddr[3], macaddr[4], macaddr[5]); |
92 | rs->finalize = finalize; | 77 | + snprintf(nc->info_str, sizeof(nc->info_str), |
93 | } | 78 | + "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x", |
94 | @@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size) | 79 | + nc->model, |
95 | unsigned int l; | 80 | + macaddr[0], macaddr[1], macaddr[2], |
96 | 81 | + macaddr[3], macaddr[4], macaddr[5]); | |
97 | while (size > 0) { | 82 | } |
98 | - /* reassemble a packet from the network */ | 83 | |
99 | - switch (rs->state) { /* 0 = getting length, 1 = getting data */ | 84 | static int mac_table[256] = {0}; |
100 | + /* Reassemble a packet from the network. | 85 | @@ -XXX,XX +XXX,XX @@ static void qemu_free_net_client(NetClientState *nc) |
101 | + * 0 = getting length. | 86 | } |
102 | + * 1 = getting vnet header length. | 87 | g_free(nc->name); |
103 | + * 2 = getting data. | 88 | g_free(nc->model); |
104 | + */ | 89 | - g_free(nc->info_str); |
105 | + switch (rs->state) { | 90 | qapi_free_NetdevInfo(nc->stored_config); |
106 | case 0: | 91 | if (nc->destructor) { |
107 | l = 4 - rs->index; | 92 | nc->destructor(nc); |
108 | if (l > size) { | 93 | @@ -XXX,XX +XXX,XX @@ void print_net_client(Monitor *mon, NetClientState *nc) |
109 | @@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size) | 94 | monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name, |
110 | /* got length */ | 95 | nc->queue_index, |
111 | rs->packet_len = ntohl(*(uint32_t *)rs->buf); | 96 | NetClientDriver_str(nc->info->type), |
112 | rs->index = 0; | 97 | - nc->info_str ? nc->info_str : ""); |
113 | - rs->state = 1; | 98 | + nc->info_str); |
114 | + if (rs->vnet_hdr) { | 99 | if (!QTAILQ_EMPTY(&nc->filters)) { |
115 | + rs->state = 1; | 100 | monitor_printf(mon, "filters:\n"); |
116 | + } else { | 101 | } |
117 | + rs->state = 2; | 102 | diff --git a/net/slirp.c b/net/slirp.c |
118 | + rs->vnet_hdr_len = 0; | 103 | index XXXXXXX..XXXXXXX 100644 |
119 | + } | 104 | --- a/net/slirp.c |
120 | } | 105 | +++ b/net/slirp.c |
121 | break; | 106 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, |
122 | case 1: | 107 | stored->tftp_server_name = g_strdup(tftp_server_name); |
123 | + l = 4 - rs->index; | 108 | } |
124 | + if (l > size) { | 109 | |
125 | + l = size; | 110 | - nc->info_str = g_strdup_printf("net=%s,restrict=%s", inet_ntoa(net), |
126 | + } | 111 | - restricted ? "on" : "off"); |
127 | + memcpy(rs->buf + rs->index, buf, l); | 112 | + snprintf(nc->info_str, sizeof(nc->info_str), |
128 | + buf += l; | 113 | + "net=%s,restrict=%s", inet_ntoa(net), |
129 | + size -= l; | 114 | + restricted ? "on" : "off"); |
130 | + rs->index += l; | 115 | |
131 | + if (rs->index == 4) { | 116 | s = DO_UPCAST(SlirpState, nc, nc); |
132 | + /* got vnet header length */ | 117 | |
133 | + rs->vnet_hdr_len = ntohl(*(uint32_t *)rs->buf); | ||
134 | + rs->index = 0; | ||
135 | + rs->state = 2; | ||
136 | + } | ||
137 | + break; | ||
138 | + case 2: | ||
139 | l = rs->packet_len - rs->index; | ||
140 | if (l > size) { | ||
141 | l = size; | ||
142 | diff --git a/net/socket.c b/net/socket.c | 118 | diff --git a/net/socket.c b/net/socket.c |
143 | index XXXXXXX..XXXXXXX 100644 | 119 | index XXXXXXX..XXXXXXX 100644 |
144 | --- a/net/socket.c | 120 | --- a/net/socket.c |
145 | +++ b/net/socket.c | 121 | +++ b/net/socket.c |
146 | @@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque) | 122 | @@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque) |
147 | closesocket(s->fd); | ||
148 | |||
149 | s->fd = -1; | 123 | s->fd = -1; |
150 | - net_socket_rs_init(&s->rs, net_socket_rs_finalize); | 124 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); |
151 | + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
152 | s->nc.link_down = true; | 125 | s->nc.link_down = true; |
153 | memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); | 126 | - g_free(s->nc.info_str); |
154 | 127 | - s->nc.info_str = g_new0(char, 1); | |
128 | + memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); | ||
129 | |||
130 | return; | ||
131 | } | ||
155 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | 132 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, |
156 | s->fd = fd; | 133 | stored->mcast = g_strdup(mcast); |
157 | s->listen_fd = -1; | 134 | |
158 | s->send_fn = net_socket_send_dgram; | 135 | s->dgram_dst = saddr; |
159 | - net_socket_rs_init(&s->rs, net_socket_rs_finalize); | 136 | - nc->info_str = g_strdup_printf("socket: fd=%d (cloned mcast=%s:%d)", |
160 | + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | 137 | - fd, inet_ntoa(saddr.sin_addr), |
161 | net_socket_read_poll(s, true); | 138 | - ntohs(saddr.sin_port)); |
162 | 139 | + snprintf(nc->info_str, sizeof(nc->info_str), | |
163 | /* mcast: save bound address as dst */ | 140 | + "socket: fd=%d (cloned mcast=%s:%d)", |
141 | + fd, inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
142 | } else { | ||
143 | if (sa_type == SOCKET_ADDRESS_TYPE_UNIX) { | ||
144 | s->dgram_dst.sin_family = AF_UNIX; | ||
145 | } | ||
146 | |||
147 | - nc->info_str = g_strdup_printf("socket: fd=%d %s", | ||
148 | - fd, SocketAddressType_str(sa_type)); | ||
149 | + snprintf(nc->info_str, sizeof(nc->info_str), | ||
150 | + "socket: fd=%d %s", fd, SocketAddressType_str(sa_type)); | ||
151 | } | ||
152 | |||
153 | return s; | ||
164 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | 154 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, |
165 | 155 | ||
166 | s->fd = fd; | 156 | nc = qemu_new_net_client(&net_socket_info, peer, model, name); |
167 | s->listen_fd = -1; | 157 | |
168 | - net_socket_rs_init(&s->rs, net_socket_rs_finalize); | 158 | - nc->info_str = g_strdup_printf("socket: fd=%d", fd); |
169 | + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | 159 | + snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd); |
170 | 160 | ||
171 | /* Disable Nagle algorithm on TCP sockets to reduce latency */ | 161 | s = DO_UPCAST(NetSocketState, nc, nc); |
172 | socket_set_nodelay(fd); | 162 | |
173 | @@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer, | 163 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) |
174 | s->fd = -1; | 164 | stored->has_fd = true; |
175 | s->listen_fd = fd; | 165 | stored->fd = g_strdup_printf("%d", fd); |
176 | s->nc.link_down = true; | 166 | |
177 | - net_socket_rs_init(&s->rs, net_socket_rs_finalize); | 167 | - g_free(s->nc.info_str); |
178 | + net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | 168 | - s->nc.info_str = g_strdup_printf("socket: connection from %s:%d", |
179 | 169 | - inet_ntoa(saddr.sin_addr), | |
180 | qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); | 170 | - ntohs(saddr.sin_port)); |
181 | return 0; | 171 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), |
172 | + "socket: connection from %s:%d", | ||
173 | + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
174 | } | ||
175 | |||
176 | static int net_socket_listen_init(NetClientState *peer, | ||
177 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
178 | stored->has_connect = true; | ||
179 | stored->connect = g_strdup(host_str); | ||
180 | |||
181 | - g_free(s->nc.info_str); | ||
182 | - s->nc.info_str = g_strdup_printf("socket: connect to %s:%d", | ||
183 | - inet_ntoa(saddr.sin_addr), | ||
184 | - ntohs(saddr.sin_port)); | ||
185 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
186 | + "socket: connect to %s:%d", | ||
187 | + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
188 | return 0; | ||
189 | } | ||
190 | |||
191 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
192 | stored->localaddr = g_strdup(localaddr_str); | ||
193 | } | ||
194 | |||
195 | - g_free(s->nc.info_str); | ||
196 | - s->nc.info_str = g_strdup_printf("socket: mcast=%s:%d", | ||
197 | - inet_ntoa(saddr.sin_addr), | ||
198 | - ntohs(saddr.sin_port)); | ||
199 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
200 | + "socket: mcast=%s:%d", | ||
201 | + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
202 | return 0; | ||
203 | |||
204 | } | ||
205 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
206 | stored->has_udp = true; | ||
207 | stored->udp = g_strdup(rhost); | ||
208 | |||
209 | - g_free(s->nc.info_str); | ||
210 | - s->nc.info_str = g_strdup_printf("socket: udp=%s:%d", | ||
211 | - inet_ntoa(raddr.sin_addr), | ||
212 | - ntohs(raddr.sin_port)); | ||
213 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
214 | + "socket: udp=%s:%d", | ||
215 | + inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | diff --git a/net/tap-win32.c b/net/tap-win32.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/net/tap-win32.c | ||
222 | +++ b/net/tap-win32.c | ||
223 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
224 | stored->has_ifname = true; | ||
225 | stored->ifname = g_strdup(ifname); | ||
226 | |||
227 | - s->nc.info_str = g_strdup_printf("tap: ifname=%s", ifname); | ||
228 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
229 | + "tap: ifname=%s", ifname); | ||
230 | |||
231 | s->handle = handle; | ||
232 | |||
233 | diff --git a/net/tap.c b/net/tap.c | ||
234 | index XXXXXXX..XXXXXXX 100644 | ||
235 | --- a/net/tap.c | ||
236 | +++ b/net/tap.c | ||
237 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
238 | stored->helper = g_strdup(helper); | ||
239 | } | ||
240 | |||
241 | - s->nc.info_str = g_strdup_printf("helper=%s,br=%s", helper, br); | ||
242 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper, | ||
243 | + br); | ||
244 | |||
245 | return 0; | ||
246 | } | ||
247 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
248 | g_free(tmp_s); | ||
249 | } | ||
250 | |||
251 | - s->nc.info_str = g_strdup_printf("fd=%d", fd); | ||
252 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); | ||
253 | } else if (tap->has_helper) { | ||
254 | if (!stored->has_helper) { | ||
255 | stored->has_helper = true; | ||
256 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
257 | g_strdup(DEFAULT_BRIDGE_INTERFACE); | ||
258 | } | ||
259 | |||
260 | - s->nc.info_str = g_strdup_printf("helper=%s", tap->helper); | ||
261 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", | ||
262 | + tap->helper); | ||
263 | } else { | ||
264 | if (ifname && !stored->has_ifname) { | ||
265 | stored->has_ifname = true; | ||
266 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
267 | stored->downscript = g_strdup(downscript); | ||
268 | } | ||
269 | |||
270 | - s->nc.info_str = g_strdup_printf("ifname=%s,script=%s,downscript=%s", | ||
271 | - ifname, script, downscript); | ||
272 | + snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
273 | + "ifname=%s,script=%s,downscript=%s", ifname, script, | ||
274 | + downscript); | ||
275 | |||
276 | if (strcmp(downscript, "no") != 0) { | ||
277 | snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); | ||
278 | diff --git a/net/vde.c b/net/vde.c | ||
279 | index XXXXXXX..XXXXXXX 100644 | ||
280 | --- a/net/vde.c | ||
281 | +++ b/net/vde.c | ||
282 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
283 | |||
284 | nc = qemu_new_net_client(&net_vde_info, peer, model, name); | ||
285 | |||
286 | - nc->info_str = g_strdup_printf("sock=%s,fd=%d", sock, vde_datafd(vde)); | ||
287 | + snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d", | ||
288 | + sock, vde_datafd(vde)); | ||
289 | |||
290 | s = DO_UPCAST(VDEState, nc, nc); | ||
291 | |||
292 | diff --git a/net/vhost-user.c b/net/vhost-user.c | ||
293 | index XXXXXXX..XXXXXXX 100644 | ||
294 | --- a/net/vhost-user.c | ||
295 | +++ b/net/vhost-user.c | ||
296 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
297 | user = g_new0(struct VhostUserState, 1); | ||
298 | for (i = 0; i < queues; i++) { | ||
299 | nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); | ||
300 | - nc->info_str = g_strdup_printf("vhost-user%d to %s", i, chr->label); | ||
301 | + snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s", | ||
302 | + i, chr->label); | ||
303 | nc->queue_index = i; | ||
304 | if (!nc0) { | ||
305 | nc0 = nc; | ||
306 | diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c | ||
307 | index XXXXXXX..XXXXXXX 100644 | ||
308 | --- a/net/vhost-vdpa.c | ||
309 | +++ b/net/vhost-vdpa.c | ||
310 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, | ||
311 | stored->has_queues = true; | ||
312 | stored->queues = 1; /* TODO: change when support multiqueue */ | ||
313 | |||
314 | - nc->info_str = g_strdup_printf(TYPE_VHOST_VDPA); | ||
315 | + snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); | ||
316 | nc->queue_index = 0; | ||
317 | s = DO_UPCAST(VhostVDPAState, nc, nc); | ||
318 | vdpa_device_fd = qemu_open_old(vhostdev, O_RDWR); | ||
182 | -- | 319 | -- |
183 | 2.7.4 | 320 | 2.7.4 |
184 | 321 | ||
185 | 322 | diff view generated by jsdifflib |
1 | From: Michal Privoznik <mprivozn@redhat.com> | 1 | Several issues has been reported for query-netdev series. Consider |
---|---|---|---|
2 | it's late in the rc, this reverts commit | ||
3 | 3c3b656885473ef0d699290ba966177f17839aa5. | ||
2 | 4 | ||
3 | We have a function that checks if given number is power of two. | ||
4 | We should prefer it instead of expanding the check on our own. | ||
5 | |||
6 | Signed-off-by: Michal Privoznik <mprivozn@redhat.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 5 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 6 | --- |
9 | hw/net/virtio-net.c | 2 +- | 7 | tests/qtest/meson.build | 3 - |
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | 8 | tests/qtest/test-query-netdev.c | 120 ---------------------------------------- |
9 | 2 files changed, 123 deletions(-) | ||
10 | delete mode 100644 tests/qtest/test-query-netdev.c | ||
11 | 11 | ||
12 | diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c | 12 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
13 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/net/virtio-net.c | 14 | --- a/tests/qtest/meson.build |
15 | +++ b/hw/net/virtio-net.c | 15 | +++ b/tests/qtest/meson.build |
16 | @@ -XXX,XX +XXX,XX @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) | 16 | @@ -XXX,XX +XXX,XX @@ qtests_generic = \ |
17 | */ | 17 | if config_host.has_key('CONFIG_MODULES') |
18 | if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE || | 18 | qtests_generic += [ 'modules-test' ] |
19 | n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE || | 19 | endif |
20 | - (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) { | 20 | -if slirp.found() |
21 | + !is_power_of_2(n->net_conf.rx_queue_size)) { | 21 | - qtests_generic += [ 'test-query-netdev' ] |
22 | error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), " | 22 | -endif |
23 | "must be a power of 2 between %d and %d.", | 23 | |
24 | n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE, | 24 | qtests_pci = \ |
25 | (config_all_devices.has_key('CONFIG_VGA') ? ['display-vga-test'] : []) + \ | ||
26 | diff --git a/tests/qtest/test-query-netdev.c b/tests/qtest/test-query-netdev.c | ||
27 | deleted file mode 100644 | ||
28 | index XXXXXXX..XXXXXXX | ||
29 | --- a/tests/qtest/test-query-netdev.c | ||
30 | +++ /dev/null | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | -/* | ||
33 | - * QTest testcase for the query-netdev | ||
34 | - * | ||
35 | - * Copyright Yandex N.V., 2019 | ||
36 | - * | ||
37 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
38 | - * See the COPYING file in the top-level directory. | ||
39 | - * | ||
40 | - */ | ||
41 | - | ||
42 | -#include "qemu/osdep.h" | ||
43 | - | ||
44 | -#include "libqos/libqtest.h" | ||
45 | -#include "qapi/qmp/qdict.h" | ||
46 | -#include "qapi/qmp/qlist.h" | ||
47 | - | ||
48 | -/* | ||
49 | - * Events can get in the way of responses we are actually waiting for. | ||
50 | - */ | ||
51 | -GCC_FMT_ATTR(2, 3) | ||
52 | -static QObject *wait_command(QTestState *who, const char *command, ...) | ||
53 | -{ | ||
54 | - va_list ap; | ||
55 | - QDict *response; | ||
56 | - QObject *result; | ||
57 | - | ||
58 | - va_start(ap, command); | ||
59 | - qtest_qmp_vsend(who, command, ap); | ||
60 | - va_end(ap); | ||
61 | - | ||
62 | - response = qtest_qmp_receive(who); | ||
63 | - | ||
64 | - result = qdict_get(response, "return"); | ||
65 | - g_assert(result); | ||
66 | - qobject_ref(result); | ||
67 | - qobject_unref(response); | ||
68 | - | ||
69 | - return result; | ||
70 | -} | ||
71 | - | ||
72 | -static void qmp_query_netdev_no_error(QTestState *qts, size_t netdevs_count) | ||
73 | -{ | ||
74 | - QObject *resp; | ||
75 | - QList *netdevs; | ||
76 | - | ||
77 | - resp = wait_command(qts, "{'execute': 'query-netdev'}"); | ||
78 | - | ||
79 | - netdevs = qobject_to(QList, resp); | ||
80 | - g_assert(netdevs); | ||
81 | - g_assert(qlist_size(netdevs) == netdevs_count); | ||
82 | - | ||
83 | - qobject_unref(resp); | ||
84 | -} | ||
85 | - | ||
86 | -static void test_query_netdev(void) | ||
87 | -{ | ||
88 | - const char *arch = qtest_get_arch(); | ||
89 | - QObject *resp; | ||
90 | - QTestState *state; | ||
91 | - | ||
92 | - /* Choosing machine for platforms without default one */ | ||
93 | - if (g_str_equal(arch, "arm") || | ||
94 | - g_str_equal(arch, "aarch64")) { | ||
95 | - state = qtest_init( | ||
96 | - "-nodefaults " | ||
97 | - "-M virt " | ||
98 | - "-netdev user,id=slirp0"); | ||
99 | - } else if (g_str_equal(arch, "tricore")) { | ||
100 | - state = qtest_init( | ||
101 | - "-nodefaults " | ||
102 | - "-M tricore_testboard " | ||
103 | - "-netdev user,id=slirp0"); | ||
104 | - } else if (g_str_equal(arch, "avr")) { | ||
105 | - state = qtest_init( | ||
106 | - "-nodefaults " | ||
107 | - "-M mega2560 " | ||
108 | - "-netdev user,id=slirp0"); | ||
109 | - } else if (g_str_equal(arch, "rx")) { | ||
110 | - state = qtest_init( | ||
111 | - "-nodefaults " | ||
112 | - "-M gdbsim-r5f562n8 " | ||
113 | - "-netdev user,id=slirp0"); | ||
114 | - } else { | ||
115 | - state = qtest_init( | ||
116 | - "-nodefaults " | ||
117 | - "-netdev user,id=slirp0"); | ||
118 | - } | ||
119 | - g_assert(state); | ||
120 | - | ||
121 | - qmp_query_netdev_no_error(state, 1); | ||
122 | - | ||
123 | - resp = wait_command(state, | ||
124 | - "{'execute': 'netdev_add', 'arguments': {" | ||
125 | - " 'id': 'slirp1'," | ||
126 | - " 'type': 'user'}}"); | ||
127 | - qobject_unref(resp); | ||
128 | - | ||
129 | - qmp_query_netdev_no_error(state, 2); | ||
130 | - | ||
131 | - resp = wait_command(state, | ||
132 | - "{'execute': 'netdev_del', 'arguments': {" | ||
133 | - " 'id': 'slirp1'}}"); | ||
134 | - qobject_unref(resp); | ||
135 | - | ||
136 | - qmp_query_netdev_no_error(state, 1); | ||
137 | - | ||
138 | - qtest_quit(state); | ||
139 | -} | ||
140 | - | ||
141 | -int main(int argc, char **argv) | ||
142 | -{ | ||
143 | - int ret = 0; | ||
144 | - g_test_init(&argc, &argv, NULL); | ||
145 | - | ||
146 | - qtest_add_func("/net/qapi/query_netdev", test_query_netdev); | ||
147 | - | ||
148 | - ret = g_test_run(); | ||
149 | - | ||
150 | - return ret; | ||
151 | -} | ||
25 | -- | 152 | -- |
26 | 2.7.4 | 153 | 2.7.4 |
27 | 154 | ||
28 | 155 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | Several issues has been reported for query-netdev series. Consider |
---|---|---|---|
2 | it's late in the rc, this reverts commit | ||
3 | d32ad10a14d46dfe9304e3ed5858a11dcd5c71a0. | ||
2 | 4 | ||
3 | Add vnet_hdr_len arguments in NetClientState | ||
4 | that make other module get real vnet_hdr_len easily. | ||
5 | |||
6 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 5 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 6 | --- |
9 | include/net/net.h | 1 + | 7 | include/net/net.h | 3 -- |
10 | net/net.c | 1 + | 8 | net/l2tpv3.c | 7 ---- |
11 | 2 files changed, 2 insertions(+) | 9 | net/net.c | 30 +------------- |
10 | net/netmap.c | 7 ---- | ||
11 | net/slirp.c | 122 ------------------------------------------------------ | ||
12 | net/socket.c | 71 ------------------------------- | ||
13 | net/tap-win32.c | 9 ---- | ||
14 | net/tap.c | 103 +++------------------------------------------ | ||
15 | net/vde.c | 22 ---------- | ||
16 | net/vhost-user.c | 18 ++------ | ||
17 | net/vhost-vdpa.c | 14 ------- | ||
18 | qapi/net.json | 80 ----------------------------------- | ||
19 | 12 files changed, 9 insertions(+), 477 deletions(-) | ||
12 | 20 | ||
13 | diff --git a/include/net/net.h b/include/net/net.h | 21 | diff --git a/include/net/net.h b/include/net/net.h |
14 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/net/net.h | 23 | --- a/include/net/net.h |
16 | +++ b/include/net/net.h | 24 | +++ b/include/net/net.h |
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | #include "qapi/qapi-types-net.h" | ||
27 | #include "net/queue.h" | ||
28 | #include "hw/qdev-properties-system.h" | ||
29 | -#include "qapi/clone-visitor.h" | ||
30 | -#include "qapi/qapi-visit-net.h" | ||
31 | |||
32 | #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X" | ||
33 | #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \ | ||
17 | @@ -XXX,XX +XXX,XX @@ struct NetClientState { | 34 | @@ -XXX,XX +XXX,XX @@ struct NetClientState { |
35 | char *model; | ||
36 | char *name; | ||
37 | char info_str[256]; | ||
38 | - NetdevInfo *stored_config; | ||
39 | unsigned receive_disabled : 1; | ||
40 | NetClientDestructor *destructor; | ||
18 | unsigned int queue_index; | 41 | unsigned int queue_index; |
19 | unsigned rxfilter_notify_enabled:1; | 42 | diff --git a/net/l2tpv3.c b/net/l2tpv3.c |
20 | int vring_enable; | 43 | index XXXXXXX..XXXXXXX 100644 |
21 | + int vnet_hdr_len; | 44 | --- a/net/l2tpv3.c |
22 | QTAILQ_HEAD(NetFilterHead, NetFilterState) filters; | 45 | +++ b/net/l2tpv3.c |
23 | }; | 46 | @@ -XXX,XX +XXX,XX @@ int net_init_l2tpv3(const Netdev *netdev, |
24 | 47 | ||
48 | l2tpv3_read_poll(s, true); | ||
49 | |||
50 | - /* Store startup parameters */ | ||
51 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
52 | - nc->stored_config->type = NET_BACKEND_L2TPV3; | ||
53 | - | ||
54 | - QAPI_CLONE_MEMBERS(NetdevL2TPv3Options, | ||
55 | - &nc->stored_config->u.l2tpv3, l2tpv3); | ||
56 | - | ||
57 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
58 | "l2tpv3: connected"); | ||
59 | return 0; | ||
25 | diff --git a/net/net.c b/net/net.c | 60 | diff --git a/net/net.c b/net/net.c |
26 | index XXXXXXX..XXXXXXX 100644 | 61 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/net/net.c | 62 | --- a/net/net.c |
28 | +++ b/net/net.c | 63 | +++ b/net/net.c |
29 | @@ -XXX,XX +XXX,XX @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) | 64 | @@ -XXX,XX +XXX,XX @@ |
65 | #include "monitor/monitor.h" | ||
66 | #include "qemu/help_option.h" | ||
67 | #include "qapi/qapi-commands-net.h" | ||
68 | +#include "qapi/qapi-visit-net.h" | ||
69 | #include "qapi/qmp/qdict.h" | ||
70 | #include "qapi/qmp/qerror.h" | ||
71 | #include "qemu/error-report.h" | ||
72 | @@ -XXX,XX +XXX,XX @@ static void qemu_free_net_client(NetClientState *nc) | ||
73 | } | ||
74 | g_free(nc->name); | ||
75 | g_free(nc->model); | ||
76 | - qapi_free_NetdevInfo(nc->stored_config); | ||
77 | if (nc->destructor) { | ||
78 | nc->destructor(nc); | ||
79 | } | ||
80 | @@ -XXX,XX +XXX,XX @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name, | ||
81 | return filter_list; | ||
82 | } | ||
83 | |||
84 | -NetdevInfoList *qmp_query_netdev(Error **errp) | ||
85 | -{ | ||
86 | - NetdevInfoList *list = NULL; | ||
87 | - NetClientState *nc; | ||
88 | - | ||
89 | - QTAILQ_FOREACH(nc, &net_clients, next) { | ||
90 | - /* | ||
91 | - * Only look at netdevs (backend network devices), not for each queue | ||
92 | - * or NIC / hubport | ||
93 | - */ | ||
94 | - if (nc->stored_config) { | ||
95 | - NetdevInfo *element = QAPI_CLONE(NetdevInfo, nc->stored_config); | ||
96 | - | ||
97 | - g_free(element->id); /* Need to dealloc empty id after clone */ | ||
98 | - element->id = g_strdup(nc->name); | ||
99 | - | ||
100 | - element->has_peer_id = nc->peer != NULL; | ||
101 | - if (element->has_peer_id) { | ||
102 | - element->peer_id = g_strdup(nc->peer->name); | ||
103 | - } | ||
104 | - | ||
105 | - QAPI_LIST_PREPEND(list, element); | ||
106 | - } | ||
107 | - } | ||
108 | - | ||
109 | - return list; | ||
110 | -} | ||
111 | - | ||
112 | void hmp_info_network(Monitor *mon, const QDict *qdict) | ||
113 | { | ||
114 | NetClientState *nc, *peer; | ||
115 | diff --git a/net/netmap.c b/net/netmap.c | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/net/netmap.c | ||
118 | +++ b/net/netmap.c | ||
119 | @@ -XXX,XX +XXX,XX @@ int net_init_netmap(const Netdev *netdev, | ||
120 | pstrcpy(s->ifname, sizeof(s->ifname), netmap_opts->ifname); | ||
121 | netmap_read_poll(s, true); /* Initially only poll for reads. */ | ||
122 | |||
123 | - /* Store startup parameters */ | ||
124 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
125 | - nc->stored_config->type = NET_BACKEND_NETMAP; | ||
126 | - | ||
127 | - QAPI_CLONE_MEMBERS(NetdevNetmapOptions, | ||
128 | - &nc->stored_config->u.netmap, netmap_opts); | ||
129 | - | ||
130 | return 0; | ||
131 | } | ||
132 | |||
133 | diff --git a/net/slirp.c b/net/slirp.c | ||
134 | index XXXXXXX..XXXXXXX 100644 | ||
135 | --- a/net/slirp.c | ||
136 | +++ b/net/slirp.c | ||
137 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
138 | int shift; | ||
139 | char *end; | ||
140 | struct slirp_config_str *config; | ||
141 | - NetdevUserOptions *stored; | ||
142 | - StringList **stored_hostfwd; | ||
143 | - StringList **stored_guestfwd; | ||
144 | |||
145 | if (!ipv4 && (vnetwork || vhost || vnameserver)) { | ||
146 | error_setg(errp, "IPv4 disabled but netmask/host/dns provided"); | ||
147 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
148 | |||
149 | nc = qemu_new_net_client(&net_slirp_info, peer, model, name); | ||
150 | |||
151 | - /* Store startup parameters */ | ||
152 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
153 | - nc->stored_config->type = NET_BACKEND_USER; | ||
154 | - stored = &nc->stored_config->u.user; | ||
155 | - | ||
156 | - if (vhostname) { | ||
157 | - stored->has_hostname = true; | ||
158 | - stored->hostname = g_strdup(vhostname); | ||
159 | - } | ||
160 | - | ||
161 | - stored->has_q_restrict = true; | ||
162 | - stored->q_restrict = restricted; | ||
163 | - | ||
164 | - stored->has_ipv4 = true; | ||
165 | - stored->ipv4 = ipv4; | ||
166 | - | ||
167 | - stored->has_ipv6 = true; | ||
168 | - stored->ipv6 = ipv6; | ||
169 | - | ||
170 | - if (ipv4) { | ||
171 | - uint8_t *net_bytes = (uint8_t *)&net; | ||
172 | - uint8_t *mask_bytes = (uint8_t *)&mask; | ||
173 | - | ||
174 | - stored->has_net = true; | ||
175 | - stored->net = g_strdup_printf("%d.%d.%d.%d/%d.%d.%d.%d", | ||
176 | - net_bytes[0], net_bytes[1], | ||
177 | - net_bytes[2], net_bytes[3], | ||
178 | - mask_bytes[0], mask_bytes[1], | ||
179 | - mask_bytes[2], mask_bytes[3]); | ||
180 | - | ||
181 | - stored->has_host = true; | ||
182 | - stored->host = g_strdup(inet_ntoa(host)); | ||
183 | - } | ||
184 | - | ||
185 | - if (tftp_export) { | ||
186 | - stored->has_tftp = true; | ||
187 | - stored->tftp = g_strdup(tftp_export); | ||
188 | - } | ||
189 | - | ||
190 | - if (bootfile) { | ||
191 | - stored->has_bootfile = true; | ||
192 | - stored->bootfile = g_strdup(bootfile); | ||
193 | - } | ||
194 | - | ||
195 | - if (vdhcp_start) { | ||
196 | - stored->has_dhcpstart = true; | ||
197 | - stored->dhcpstart = g_strdup(vdhcp_start); | ||
198 | - } | ||
199 | - | ||
200 | - if (ipv4) { | ||
201 | - stored->has_dns = true; | ||
202 | - stored->dns = g_strdup(inet_ntoa(dns)); | ||
203 | - } | ||
204 | - | ||
205 | - if (dnssearch) { | ||
206 | - stored->has_dnssearch = true; | ||
207 | - StringList **stored_list = &stored->dnssearch; | ||
208 | - | ||
209 | - for (int i = 0; dnssearch[i]; i++) { | ||
210 | - String *element = g_new0(String, 1); | ||
211 | - | ||
212 | - element->str = g_strdup(dnssearch[i]); | ||
213 | - QAPI_LIST_APPEND(stored_list, element); | ||
214 | - } | ||
215 | - } | ||
216 | - | ||
217 | - if (vdomainname) { | ||
218 | - stored->has_domainname = true; | ||
219 | - stored->domainname = g_strdup(vdomainname); | ||
220 | - } | ||
221 | - | ||
222 | - if (ipv6) { | ||
223 | - char addrstr[INET6_ADDRSTRLEN]; | ||
224 | - const char *res; | ||
225 | - | ||
226 | - stored->has_ipv6_prefix = true; | ||
227 | - stored->ipv6_prefix = g_strdup(vprefix6); | ||
228 | - | ||
229 | - stored->has_ipv6_prefixlen = true; | ||
230 | - stored->ipv6_prefixlen = vprefix6_len; | ||
231 | - | ||
232 | - res = inet_ntop(AF_INET6, &ip6_host, | ||
233 | - addrstr, sizeof(addrstr)); | ||
234 | - | ||
235 | - stored->has_ipv6_host = true; | ||
236 | - stored->ipv6_host = g_strdup(res); | ||
237 | - | ||
238 | - res = inet_ntop(AF_INET6, &ip6_dns, | ||
239 | - addrstr, sizeof(addrstr)); | ||
240 | - | ||
241 | - stored->has_ipv6_dns = true; | ||
242 | - stored->ipv6_dns = g_strdup(res); | ||
243 | - } | ||
244 | - | ||
245 | - if (smb_export) { | ||
246 | - stored->has_smb = true; | ||
247 | - stored->smb = g_strdup(smb_export); | ||
248 | - } | ||
249 | - | ||
250 | - if (vsmbserver) { | ||
251 | - stored->has_smbserver = true; | ||
252 | - stored->smbserver = g_strdup(vsmbserver); | ||
253 | - } | ||
254 | - | ||
255 | - if (tftp_server_name) { | ||
256 | - stored->has_tftp_server_name = true; | ||
257 | - stored->tftp_server_name = g_strdup(tftp_server_name); | ||
258 | - } | ||
259 | - | ||
260 | snprintf(nc->info_str, sizeof(nc->info_str), | ||
261 | "net=%s,restrict=%s", inet_ntoa(net), | ||
262 | restricted ? "on" : "off"); | ||
263 | @@ -XXX,XX +XXX,XX @@ static int net_slirp_init(NetClientState *peer, const char *model, | ||
264 | s->poll_notifier.notify = net_slirp_poll_notify; | ||
265 | main_loop_poll_add_notifier(&s->poll_notifier); | ||
266 | |||
267 | - stored_hostfwd = &stored->hostfwd; | ||
268 | - stored_guestfwd = &stored->guestfwd; | ||
269 | - | ||
270 | for (config = slirp_configs; config; config = config->next) { | ||
271 | - String *element = g_new0(String, 1); | ||
272 | - | ||
273 | - element->str = g_strdup(config->str); | ||
274 | if (config->flags & SLIRP_CFG_HOSTFWD) { | ||
275 | if (slirp_hostfwd(s, config->str, errp) < 0) { | ||
276 | goto error; | ||
277 | } | ||
278 | - stored->has_hostfwd = true; | ||
279 | - QAPI_LIST_APPEND(stored_hostfwd, element); | ||
280 | } else { | ||
281 | if (slirp_guestfwd(s, config->str, errp) < 0) { | ||
282 | goto error; | ||
283 | } | ||
284 | - stored->has_guestfwd = true; | ||
285 | - QAPI_LIST_APPEND(stored_guestfwd, element); | ||
286 | } | ||
287 | } | ||
288 | #ifndef _WIN32 | ||
289 | diff --git a/net/socket.c b/net/socket.c | ||
290 | index XXXXXXX..XXXXXXX 100644 | ||
291 | --- a/net/socket.c | ||
292 | +++ b/net/socket.c | ||
293 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
294 | NetSocketState *s; | ||
295 | SocketAddress *sa; | ||
296 | SocketAddressType sa_type; | ||
297 | - NetdevSocketOptions *stored; | ||
298 | |||
299 | sa = socket_local_address(fd, errp); | ||
300 | if (!sa) { | ||
301 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, | ||
302 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
303 | net_socket_read_poll(s, true); | ||
304 | |||
305 | - /* Store startup parameters */ | ||
306 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
307 | - nc->stored_config->type = NET_BACKEND_SOCKET; | ||
308 | - stored = &nc->stored_config->u.socket; | ||
309 | - | ||
310 | - stored->has_fd = true; | ||
311 | - stored->fd = g_strdup_printf("%d", fd); | ||
312 | - | ||
313 | /* mcast: save bound address as dst */ | ||
314 | if (is_connected && mcast != NULL) { | ||
315 | - stored->has_mcast = true; | ||
316 | - stored->mcast = g_strdup(mcast); | ||
317 | - | ||
318 | s->dgram_dst = saddr; | ||
319 | snprintf(nc->info_str, sizeof(nc->info_str), | ||
320 | "socket: fd=%d (cloned mcast=%s:%d)", | ||
321 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | ||
322 | { | ||
323 | NetClientState *nc; | ||
324 | NetSocketState *s; | ||
325 | - NetdevSocketOptions *stored; | ||
326 | |||
327 | nc = qemu_new_net_client(&net_socket_info, peer, model, name); | ||
328 | |||
329 | @@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, | ||
330 | } else { | ||
331 | qemu_set_fd_handler(s->fd, NULL, net_socket_connect, s); | ||
332 | } | ||
333 | - | ||
334 | - /* Store startup parameters */ | ||
335 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
336 | - nc->stored_config->type = NET_BACKEND_SOCKET; | ||
337 | - stored = &nc->stored_config->u.socket; | ||
338 | - | ||
339 | - stored->has_fd = true; | ||
340 | - stored->fd = g_strdup_printf("%d", fd); | ||
341 | - | ||
342 | return s; | ||
343 | } | ||
344 | |||
345 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | ||
346 | struct sockaddr_in saddr; | ||
347 | socklen_t len; | ||
348 | int fd; | ||
349 | - NetdevSocketOptions *stored; | ||
350 | |||
351 | for(;;) { | ||
352 | len = sizeof(saddr); | ||
353 | @@ -XXX,XX +XXX,XX @@ static void net_socket_accept(void *opaque) | ||
354 | s->fd = fd; | ||
355 | s->nc.link_down = false; | ||
356 | net_socket_connect(s); | ||
357 | - | ||
358 | - /* Store additional startup parameters (extend net_socket_listen_init) */ | ||
359 | - stored = &s->nc.stored_config->u.socket; | ||
360 | - | ||
361 | - stored->has_fd = true; | ||
362 | - stored->fd = g_strdup_printf("%d", fd); | ||
363 | - | ||
364 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
365 | "socket: connection from %s:%d", | ||
366 | inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
367 | @@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer, | ||
368 | NetSocketState *s; | ||
369 | struct sockaddr_in saddr; | ||
370 | int fd, ret; | ||
371 | - NetdevSocketOptions *stored; | ||
372 | |||
373 | if (parse_host_port(&saddr, host_str, errp) < 0) { | ||
374 | return -1; | ||
375 | @@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer, | ||
376 | net_socket_rs_init(&s->rs, net_socket_rs_finalize, false); | ||
377 | |||
378 | qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); | ||
379 | - | ||
380 | - /* Store startup parameters */ | ||
381 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
382 | - nc->stored_config->type = NET_BACKEND_SOCKET; | ||
383 | - stored = &nc->stored_config->u.socket; | ||
384 | - | ||
385 | - stored->has_listen = true; | ||
386 | - stored->listen = g_strdup(host_str); | ||
387 | - | ||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
392 | NetSocketState *s; | ||
393 | int fd, connected, ret; | ||
394 | struct sockaddr_in saddr; | ||
395 | - NetdevSocketOptions *stored; | ||
396 | |||
397 | if (parse_host_port(&saddr, host_str, errp) < 0) { | ||
398 | return -1; | ||
399 | @@ -XXX,XX +XXX,XX @@ static int net_socket_connect_init(NetClientState *peer, | ||
400 | return -1; | ||
401 | } | ||
402 | |||
403 | - /* Store additional startup parameters (extend net_socket_fd_init) */ | ||
404 | - stored = &s->nc.stored_config->u.socket; | ||
405 | - | ||
406 | - stored->has_connect = true; | ||
407 | - stored->connect = g_strdup(host_str); | ||
408 | - | ||
409 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
410 | "socket: connect to %s:%d", | ||
411 | inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
412 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
413 | int fd; | ||
414 | struct sockaddr_in saddr; | ||
415 | struct in_addr localaddr, *param_localaddr; | ||
416 | - NetdevSocketOptions *stored; | ||
417 | |||
418 | if (parse_host_port(&saddr, host_str, errp) < 0) { | ||
419 | return -1; | ||
420 | @@ -XXX,XX +XXX,XX @@ static int net_socket_mcast_init(NetClientState *peer, | ||
421 | |||
422 | s->dgram_dst = saddr; | ||
423 | |||
424 | - /* Store additional startup parameters (extend net_socket_fd_init) */ | ||
425 | - stored = &s->nc.stored_config->u.socket; | ||
426 | - | ||
427 | - if (!stored->has_mcast) { | ||
428 | - stored->has_mcast = true; | ||
429 | - stored->mcast = g_strdup(host_str); | ||
430 | - } | ||
431 | - | ||
432 | - if (localaddr_str) { | ||
433 | - stored->has_localaddr = true; | ||
434 | - stored->localaddr = g_strdup(localaddr_str); | ||
435 | - } | ||
436 | - | ||
437 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
438 | "socket: mcast=%s:%d", | ||
439 | inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); | ||
440 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
441 | NetSocketState *s; | ||
442 | int fd, ret; | ||
443 | struct sockaddr_in laddr, raddr; | ||
444 | - NetdevSocketOptions *stored; | ||
445 | |||
446 | if (parse_host_port(&laddr, lhost, errp) < 0) { | ||
447 | return -1; | ||
448 | @@ -XXX,XX +XXX,XX @@ static int net_socket_udp_init(NetClientState *peer, | ||
449 | |||
450 | s->dgram_dst = raddr; | ||
451 | |||
452 | - /* Store additional startup parameters (extend net_socket_fd_init) */ | ||
453 | - stored = &s->nc.stored_config->u.socket; | ||
454 | - | ||
455 | - stored->has_localaddr = true; | ||
456 | - stored->localaddr = g_strdup(lhost); | ||
457 | - | ||
458 | - stored->has_udp = true; | ||
459 | - stored->udp = g_strdup(rhost); | ||
460 | - | ||
461 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
462 | "socket: udp=%s:%d", | ||
463 | inet_ntoa(raddr.sin_addr), ntohs(raddr.sin_port)); | ||
464 | diff --git a/net/tap-win32.c b/net/tap-win32.c | ||
465 | index XXXXXXX..XXXXXXX 100644 | ||
466 | --- a/net/tap-win32.c | ||
467 | +++ b/net/tap-win32.c | ||
468 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
469 | NetClientState *nc; | ||
470 | TAPState *s; | ||
471 | tap_win32_overlapped_t *handle; | ||
472 | - NetdevTapOptions *stored; | ||
473 | |||
474 | if (tap_win32_open(&handle, ifname) < 0) { | ||
475 | printf("tap: Could not open '%s'\n", ifname); | ||
476 | @@ -XXX,XX +XXX,XX @@ static int tap_win32_init(NetClientState *peer, const char *model, | ||
477 | |||
478 | s = DO_UPCAST(TAPState, nc, nc); | ||
479 | |||
480 | - /* Store startup parameters */ | ||
481 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
482 | - nc->stored_config->type = NET_BACKEND_TAP; | ||
483 | - stored = &nc->stored_config->u.tap; | ||
484 | - | ||
485 | - stored->has_ifname = true; | ||
486 | - stored->ifname = g_strdup(ifname); | ||
487 | - | ||
488 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
489 | "tap: ifname=%s", ifname); | ||
490 | |||
491 | diff --git a/net/tap.c b/net/tap.c | ||
492 | index XXXXXXX..XXXXXXX 100644 | ||
493 | --- a/net/tap.c | ||
494 | +++ b/net/tap.c | ||
495 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
496 | const char *helper, *br; | ||
497 | TAPState *s; | ||
498 | int fd, vnet_hdr; | ||
499 | - NetdevBridgeOptions *stored; | ||
500 | |||
501 | assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE); | ||
502 | bridge = &netdev->u.bridge; | ||
503 | @@ -XXX,XX +XXX,XX @@ int net_init_bridge(const Netdev *netdev, const char *name, | ||
504 | } | ||
505 | s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); | ||
506 | |||
507 | - /* Store startup parameters */ | ||
508 | - s->nc.stored_config = g_new0(NetdevInfo, 1); | ||
509 | - s->nc.stored_config->type = NET_BACKEND_BRIDGE; | ||
510 | - stored = &s->nc.stored_config->u.bridge; | ||
511 | - | ||
512 | - if (br) { | ||
513 | - stored->has_br = true; | ||
514 | - stored->br = g_strdup(br); | ||
515 | - } | ||
516 | - | ||
517 | - if (helper) { | ||
518 | - stored->has_helper = true; | ||
519 | - stored->helper = g_strdup(helper); | ||
520 | - } | ||
521 | - | ||
522 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s,br=%s", helper, | ||
523 | br); | ||
524 | |||
525 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
526 | const char *model, const char *name, | ||
527 | const char *ifname, const char *script, | ||
528 | const char *downscript, const char *vhostfdname, | ||
529 | - int vnet_hdr, int fd, NetdevInfo **common_stored, | ||
530 | - Error **errp) | ||
531 | + int vnet_hdr, int fd, Error **errp) | ||
532 | { | ||
533 | Error *err = NULL; | ||
534 | TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr); | ||
535 | int vhostfd; | ||
536 | - NetdevTapOptions *stored; | ||
537 | |||
538 | tap_set_sndbuf(s->fd, tap, &err); | ||
539 | if (err) { | ||
540 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
30 | return; | 541 | return; |
31 | } | 542 | } |
32 | 543 | ||
33 | + nc->vnet_hdr_len = len; | 544 | - /* Store startup parameters */ |
34 | nc->info->set_vnet_hdr_len(nc, len); | 545 | - if (!*common_stored) { |
546 | - *common_stored = g_new0(NetdevInfo, 1); | ||
547 | - (*common_stored)->type = NET_BACKEND_TAP; | ||
548 | - s->nc.stored_config = *common_stored; | ||
549 | - } | ||
550 | - stored = &(*common_stored)->u.tap; | ||
551 | - | ||
552 | - if (tap->has_sndbuf && !stored->has_sndbuf) { | ||
553 | - stored->has_sndbuf = true; | ||
554 | - stored->sndbuf = tap->sndbuf; | ||
555 | - } | ||
556 | - | ||
557 | - if (vnet_hdr && !stored->has_vnet_hdr) { | ||
558 | - stored->has_vnet_hdr = true; | ||
559 | - stored->vnet_hdr = true; | ||
560 | - } | ||
561 | - | ||
562 | if (tap->has_fd || tap->has_fds) { | ||
563 | - if (!stored->has_fds) { | ||
564 | - stored->has_fds = true; | ||
565 | - stored->fds = g_strdup_printf("%d", fd); | ||
566 | - } else { | ||
567 | - char *tmp_s = stored->fds; | ||
568 | - stored->fds = g_strdup_printf("%s:%d", stored->fds, fd); | ||
569 | - g_free(tmp_s); | ||
570 | - } | ||
571 | - | ||
572 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); | ||
573 | } else if (tap->has_helper) { | ||
574 | - if (!stored->has_helper) { | ||
575 | - stored->has_helper = true; | ||
576 | - stored->helper = g_strdup(tap->helper); | ||
577 | - } | ||
578 | - | ||
579 | - if (!stored->has_br) { | ||
580 | - stored->has_br = true; | ||
581 | - stored->br = tap->has_br ? g_strdup(tap->br) : | ||
582 | - g_strdup(DEFAULT_BRIDGE_INTERFACE); | ||
583 | - } | ||
584 | - | ||
585 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", | ||
586 | tap->helper); | ||
587 | } else { | ||
588 | - if (ifname && !stored->has_ifname) { | ||
589 | - stored->has_ifname = true; | ||
590 | - stored->ifname = g_strdup(ifname); | ||
591 | - } | ||
592 | - | ||
593 | - if (script && !stored->has_script) { | ||
594 | - stored->has_script = true; | ||
595 | - stored->script = g_strdup(script); | ||
596 | - } | ||
597 | - | ||
598 | - if (downscript && !stored->has_downscript) { | ||
599 | - stored->has_downscript = true; | ||
600 | - stored->downscript = g_strdup(downscript); | ||
601 | - } | ||
602 | - | ||
603 | snprintf(s->nc.info_str, sizeof(s->nc.info_str), | ||
604 | "ifname=%s,script=%s,downscript=%s", ifname, script, | ||
605 | downscript); | ||
606 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
607 | vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { | ||
608 | VhostNetOptions options; | ||
609 | |||
610 | - stored->has_vhost = true; | ||
611 | - stored->vhost = true; | ||
612 | - | ||
613 | - if (tap->has_vhostforce && tap->vhostforce) { | ||
614 | - stored->has_vhostforce = true; | ||
615 | - stored->vhostforce = true; | ||
616 | - } | ||
617 | - | ||
618 | options.backend_type = VHOST_BACKEND_TYPE_KERNEL; | ||
619 | options.net_backend = &s->nc; | ||
620 | if (tap->has_poll_us) { | ||
621 | - stored->has_poll_us = true; | ||
622 | - stored->poll_us = tap->poll_us; | ||
623 | - | ||
624 | options.busyloop_timeout = tap->poll_us; | ||
625 | } else { | ||
626 | options.busyloop_timeout = 0; | ||
627 | @@ -XXX,XX +XXX,XX @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, | ||
628 | } | ||
629 | options.opaque = (void *)(uintptr_t)vhostfd; | ||
630 | |||
631 | - if (!stored->has_vhostfds) { | ||
632 | - stored->has_vhostfds = true; | ||
633 | - stored->vhostfds = g_strdup_printf("%d", vhostfd); | ||
634 | - } else { | ||
635 | - char *tmp_s = stored->vhostfds; | ||
636 | - stored->vhostfds = g_strdup_printf("%s:%d", stored->fds, vhostfd); | ||
637 | - g_free(tmp_s); | ||
638 | - } | ||
639 | - | ||
640 | s->vhost_net = vhost_net_init(&options); | ||
641 | if (!s->vhost_net) { | ||
642 | if (tap->has_vhostforce && tap->vhostforce) { | ||
643 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, | ||
644 | const char *vhostfdname; | ||
645 | char ifname[128]; | ||
646 | int ret = 0; | ||
647 | - NetdevInfo *common_stored = NULL; /* will store configuration */ | ||
648 | |||
649 | assert(netdev->type == NET_CLIENT_DRIVER_TAP); | ||
650 | tap = &netdev->u.tap; | ||
651 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, | ||
652 | |||
653 | net_init_tap_one(tap, peer, "tap", name, NULL, | ||
654 | script, downscript, | ||
655 | - vhostfdname, vnet_hdr, fd, &common_stored, &err); | ||
656 | + vhostfdname, vnet_hdr, fd, &err); | ||
657 | if (err) { | ||
658 | error_propagate(errp, err); | ||
659 | close(fd); | ||
660 | @@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name, | ||
661 | net_init_tap_one(tap, peer, "tap", name, ifname, | ||
662 | script, downscript, | ||
663 | tap->has_vhostfds ? vhost_fds[i] : NULL, | ||
664 | - vnet_hdr, fd, &common_stored, &err); | ||
665 | + vnet_hdr, fd, &err); | ||
666 | if (err) { | ||
667 | error_propagate(errp, err); | ||
668 | ret = -1; | ||
669 | @@ -XXX,XX +XXX,XX @@ free_fail: | ||
670 | |||
671 | net_init_tap_one(tap, peer, "bridge", name, ifname, | ||
672 | script, downscript, vhostfdname, | ||
673 | - vnet_hdr, fd, &common_stored, &err); | ||
674 | + vnet_hdr, fd, &err); | ||
675 | if (err) { | ||
676 | error_propagate(errp, err); | ||
677 | close(fd); | ||
678 | @@ -XXX,XX +XXX,XX @@ free_fail: | ||
679 | net_init_tap_one(tap, peer, "tap", name, ifname, | ||
680 | i >= 1 ? "no" : script, | ||
681 | i >= 1 ? "no" : downscript, | ||
682 | - vhostfdname, vnet_hdr, fd, | ||
683 | - &common_stored, &err); | ||
684 | + vhostfdname, vnet_hdr, fd, &err); | ||
685 | if (err) { | ||
686 | error_propagate(errp, err); | ||
687 | close(fd); | ||
688 | diff --git a/net/vde.c b/net/vde.c | ||
689 | index XXXXXXX..XXXXXXX 100644 | ||
690 | --- a/net/vde.c | ||
691 | +++ b/net/vde.c | ||
692 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
693 | VDECONN *vde; | ||
694 | char *init_group = (char *)group; | ||
695 | char *init_sock = (char *)sock; | ||
696 | - NetdevVdeOptions *stored; | ||
697 | |||
698 | struct vde_open_args args = { | ||
699 | .port = port, | ||
700 | @@ -XXX,XX +XXX,XX @@ static int net_vde_init(NetClientState *peer, const char *model, | ||
701 | |||
702 | qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); | ||
703 | |||
704 | - /* Store startup parameters */ | ||
705 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
706 | - nc->stored_config->type = NET_BACKEND_VDE; | ||
707 | - stored = &nc->stored_config->u.vde; | ||
708 | - | ||
709 | - if (sock) { | ||
710 | - stored->has_sock = true; | ||
711 | - stored->sock = g_strdup(sock); | ||
712 | - } | ||
713 | - | ||
714 | - stored->has_port = true; | ||
715 | - stored->port = port; | ||
716 | - | ||
717 | - if (group) { | ||
718 | - stored->has_group = true; | ||
719 | - stored->group = g_strdup(group); | ||
720 | - } | ||
721 | - | ||
722 | - stored->has_mode = true; | ||
723 | - stored->mode = mode; | ||
724 | - | ||
725 | return 0; | ||
35 | } | 726 | } |
36 | 727 | ||
728 | diff --git a/net/vhost-user.c b/net/vhost-user.c | ||
729 | index XXXXXXX..XXXXXXX 100644 | ||
730 | --- a/net/vhost-user.c | ||
731 | +++ b/net/vhost-user.c | ||
732 | @@ -XXX,XX +XXX,XX @@ static void net_vhost_user_event(void *opaque, QEMUChrEvent event) | ||
733 | } | ||
734 | |||
735 | static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
736 | - const char *name, const char *chardev, | ||
737 | - Chardev *chr, int queues) | ||
738 | + const char *name, Chardev *chr, | ||
739 | + int queues) | ||
740 | { | ||
741 | Error *err = NULL; | ||
742 | NetClientState *nc, *nc0 = NULL; | ||
743 | NetVhostUserState *s = NULL; | ||
744 | VhostUserState *user; | ||
745 | int i; | ||
746 | - NetdevVhostUserOptions *stored; | ||
747 | |||
748 | assert(name); | ||
749 | assert(queues > 0); | ||
750 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_user_init(NetClientState *peer, const char *device, | ||
751 | |||
752 | assert(s->vhost_net); | ||
753 | |||
754 | - /* Store startup parameters */ | ||
755 | - nc0->stored_config = g_new0(NetdevInfo, 1); | ||
756 | - nc0->stored_config->type = NET_BACKEND_VHOST_USER; | ||
757 | - stored = &nc0->stored_config->u.vhost_user; | ||
758 | - | ||
759 | - stored->chardev = g_strdup(chardev); | ||
760 | - | ||
761 | - stored->has_queues = true; | ||
762 | - stored->queues = queues; | ||
763 | - | ||
764 | return 0; | ||
765 | |||
766 | err: | ||
767 | @@ -XXX,XX +XXX,XX @@ int net_init_vhost_user(const Netdev *netdev, const char *name, | ||
768 | return -1; | ||
769 | } | ||
770 | |||
771 | - return net_vhost_user_init(peer, "vhost_user", name, | ||
772 | - vhost_user_opts->chardev, chr, queues); | ||
773 | + return net_vhost_user_init(peer, "vhost_user", name, chr, queues); | ||
774 | } | ||
775 | diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c | ||
776 | index XXXXXXX..XXXXXXX 100644 | ||
777 | --- a/net/vhost-vdpa.c | ||
778 | +++ b/net/vhost-vdpa.c | ||
779 | @@ -XXX,XX +XXX,XX @@ static int net_vhost_vdpa_init(NetClientState *peer, const char *device, | ||
780 | VhostVDPAState *s; | ||
781 | int vdpa_device_fd = -1; | ||
782 | int ret = 0; | ||
783 | - NetdevVhostVDPAOptions *stored; | ||
784 | - | ||
785 | assert(name); | ||
786 | nc = qemu_new_net_client(&net_vhost_vdpa_info, peer, device, name); | ||
787 | - | ||
788 | - /* Store startup parameters */ | ||
789 | - nc->stored_config = g_new0(NetdevInfo, 1); | ||
790 | - nc->stored_config->type = NET_BACKEND_VHOST_VDPA; | ||
791 | - stored = &nc->stored_config->u.vhost_vdpa; | ||
792 | - | ||
793 | - stored->has_vhostdev = true; | ||
794 | - stored->vhostdev = g_strdup(vhostdev); | ||
795 | - | ||
796 | - stored->has_queues = true; | ||
797 | - stored->queues = 1; /* TODO: change when support multiqueue */ | ||
798 | - | ||
799 | snprintf(nc->info_str, sizeof(nc->info_str), TYPE_VHOST_VDPA); | ||
800 | nc->queue_index = 0; | ||
801 | s = DO_UPCAST(VhostVDPAState, nc, nc); | ||
802 | diff --git a/qapi/net.json b/qapi/net.json | ||
803 | index XXXXXXX..XXXXXXX 100644 | ||
804 | --- a/qapi/net.json | ||
805 | +++ b/qapi/net.json | ||
806 | @@ -XXX,XX +XXX,XX @@ | ||
807 | ## | ||
808 | { 'event': 'FAILOVER_NEGOTIATED', | ||
809 | 'data': {'device-id': 'str'} } | ||
810 | - | ||
811 | -## | ||
812 | -# @NetBackend: | ||
813 | -# | ||
814 | -# Available netdev backend drivers. | ||
815 | -# | ||
816 | -# Since: 6.0 | ||
817 | -## | ||
818 | -{ 'enum': 'NetBackend', | ||
819 | - 'data': [ 'bridge', 'l2tpv3', 'netmap', 'socket', 'tap', 'user', 'vde', | ||
820 | - 'vhost-user', 'vhost-vdpa' ] } | ||
821 | - | ||
822 | -## | ||
823 | -# @NetdevInfo: | ||
824 | -# | ||
825 | -# Configuration of a network backend device (netdev). | ||
826 | -# | ||
827 | -# @id: Device identifier. | ||
828 | -# | ||
829 | -# @type: Specify the driver used for interpreting remaining arguments. | ||
830 | -# | ||
831 | -# @peer-id: The connected frontend network device name (absent if no frontend | ||
832 | -# is connected). | ||
833 | -# | ||
834 | -# Since: 6.0 | ||
835 | -## | ||
836 | -{ 'union': 'NetdevInfo', | ||
837 | - 'base': { 'id': 'str', | ||
838 | - 'type': 'NetBackend', | ||
839 | - '*peer-id': 'str' }, | ||
840 | - 'discriminator': 'type', | ||
841 | - 'data': { | ||
842 | - 'bridge': 'NetdevBridgeOptions', | ||
843 | - 'l2tpv3': 'NetdevL2TPv3Options', | ||
844 | - 'netmap': 'NetdevNetmapOptions', | ||
845 | - 'socket': 'NetdevSocketOptions', | ||
846 | - 'tap': 'NetdevTapOptions', | ||
847 | - 'user': 'NetdevUserOptions', | ||
848 | - 'vde': 'NetdevVdeOptions', | ||
849 | - 'vhost-user': 'NetdevVhostUserOptions', | ||
850 | - 'vhost-vdpa': 'NetdevVhostVDPAOptions' } } | ||
851 | - | ||
852 | -## | ||
853 | -# @query-netdev: | ||
854 | -# | ||
855 | -# Get a list of @NetdevInfo for all virtual network backend devices (netdevs). | ||
856 | -# | ||
857 | -# Returns: a list of @NetdevInfo describing each netdev. | ||
858 | -# | ||
859 | -# Since: 6.0 | ||
860 | -# | ||
861 | -# Example: | ||
862 | -# | ||
863 | -# -> { "execute": "query-netdev" } | ||
864 | -# <- { "return": [ | ||
865 | -# { | ||
866 | -# "ipv6": true, | ||
867 | -# "ipv4": true, | ||
868 | -# "host": "10.0.2.2", | ||
869 | -# "ipv6-dns": "fec0::3", | ||
870 | -# "ipv6-prefix": "fec0::", | ||
871 | -# "net": "10.0.2.0/255.255.255.0", | ||
872 | -# "ipv6-host": "fec0::2", | ||
873 | -# "type": "user", | ||
874 | -# "peer-id": "net0", | ||
875 | -# "dns": "10.0.2.3", | ||
876 | -# "hostfwd": [ | ||
877 | -# { | ||
878 | -# "str": "tcp::20004-:22" | ||
879 | -# } | ||
880 | -# ], | ||
881 | -# "ipv6-prefixlen": 64, | ||
882 | -# "id": "netdev0", | ||
883 | -# "restrict": false | ||
884 | -# } | ||
885 | -# ] | ||
886 | -# } | ||
887 | -# | ||
888 | -## | ||
889 | -{ 'command': 'query-netdev', 'returns': ['NetdevInfo'] } | ||
37 | -- | 890 | -- |
38 | 2.7.4 | 891 | 2.7.4 |
39 | 892 | ||
40 | 893 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | This patch change the filter_send() parameter from CharBackend to MirrorState, | ||
4 | we can get more information like vnet_hdr(We use it to support packet with vnet_header). | ||
5 | |||
6 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
8 | --- | ||
9 | net/filter-mirror.c | 10 +++++----- | ||
10 | 1 file changed, 5 insertions(+), 5 deletions(-) | ||
11 | |||
12 | diff --git a/net/filter-mirror.c b/net/filter-mirror.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/net/filter-mirror.c | ||
15 | +++ b/net/filter-mirror.c | ||
16 | @@ -XXX,XX +XXX,XX @@ typedef struct MirrorState { | ||
17 | SocketReadState rs; | ||
18 | } MirrorState; | ||
19 | |||
20 | -static int filter_send(CharBackend *chr_out, | ||
21 | +static int filter_send(MirrorState *s, | ||
22 | const struct iovec *iov, | ||
23 | int iovcnt) | ||
24 | { | ||
25 | @@ -XXX,XX +XXX,XX @@ static int filter_send(CharBackend *chr_out, | ||
26 | } | ||
27 | |||
28 | len = htonl(size); | ||
29 | - ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)&len, sizeof(len)); | ||
30 | + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); | ||
31 | if (ret != sizeof(len)) { | ||
32 | goto err; | ||
33 | } | ||
34 | |||
35 | buf = g_malloc(size); | ||
36 | iov_to_buf(iov, iovcnt, 0, buf, size); | ||
37 | - ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)buf, size); | ||
38 | + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); | ||
39 | g_free(buf); | ||
40 | if (ret != size) { | ||
41 | goto err; | ||
42 | @@ -XXX,XX +XXX,XX @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf, | ||
43 | MirrorState *s = FILTER_MIRROR(nf); | ||
44 | int ret; | ||
45 | |||
46 | - ret = filter_send(&s->chr_out, iov, iovcnt); | ||
47 | + ret = filter_send(s, iov, iovcnt); | ||
48 | if (ret) { | ||
49 | error_report("filter mirror send failed(%s)", strerror(-ret)); | ||
50 | } | ||
51 | @@ -XXX,XX +XXX,XX @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf, | ||
52 | int ret; | ||
53 | |||
54 | if (qemu_chr_fe_backend_connected(&s->chr_out)) { | ||
55 | - ret = filter_send(&s->chr_out, iov, iovcnt); | ||
56 | + ret = filter_send(s, iov, iovcnt); | ||
57 | if (ret) { | ||
58 | error_report("filter redirector send failed(%s)", strerror(-ret)); | ||
59 | } | ||
60 | -- | ||
61 | 2.7.4 | ||
62 | |||
63 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | We add the vnet_hdr_support option for filter-mirror, default is disabled. | ||
4 | If you use virtio-net-pci or other driver needs vnet_hdr, please enable it. | ||
5 | You can use it for example: | ||
6 | -object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support | ||
7 | |||
8 | If it has vnet_hdr_support flag, we will change the sending packet format from | ||
9 | struct {int size; const uint8_t buf[];} to {int size; int vnet_hdr_len; const uint8_t buf[];}. | ||
10 | make other module(like colo-compare) know how to parse net packet correctly. | ||
11 | |||
12 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
13 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
14 | --- | ||
15 | net/filter-mirror.c | 42 +++++++++++++++++++++++++++++++++++++++++- | ||
16 | qemu-options.hx | 5 ++--- | ||
17 | 2 files changed, 43 insertions(+), 4 deletions(-) | ||
18 | |||
19 | diff --git a/net/filter-mirror.c b/net/filter-mirror.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/net/filter-mirror.c | ||
22 | +++ b/net/filter-mirror.c | ||
23 | @@ -XXX,XX +XXX,XX @@ typedef struct MirrorState { | ||
24 | CharBackend chr_in; | ||
25 | CharBackend chr_out; | ||
26 | SocketReadState rs; | ||
27 | + bool vnet_hdr; | ||
28 | } MirrorState; | ||
29 | |||
30 | static int filter_send(MirrorState *s, | ||
31 | const struct iovec *iov, | ||
32 | int iovcnt) | ||
33 | { | ||
34 | + NetFilterState *nf = NETFILTER(s); | ||
35 | int ret = 0; | ||
36 | ssize_t size = 0; | ||
37 | uint32_t len = 0; | ||
38 | @@ -XXX,XX +XXX,XX @@ static int filter_send(MirrorState *s, | ||
39 | goto err; | ||
40 | } | ||
41 | |||
42 | + if (s->vnet_hdr) { | ||
43 | + /* | ||
44 | + * If vnet_hdr = on, we send vnet header len to make other | ||
45 | + * module(like colo-compare) know how to parse net | ||
46 | + * packet correctly. | ||
47 | + */ | ||
48 | + ssize_t vnet_hdr_len; | ||
49 | + | ||
50 | + vnet_hdr_len = nf->netdev->vnet_hdr_len; | ||
51 | + | ||
52 | + len = htonl(vnet_hdr_len); | ||
53 | + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); | ||
54 | + if (ret != sizeof(len)) { | ||
55 | + goto err; | ||
56 | + } | ||
57 | + } | ||
58 | + | ||
59 | buf = g_malloc(size); | ||
60 | iov_to_buf(iov, iovcnt, 0, buf, size); | ||
61 | ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); | ||
62 | @@ -XXX,XX +XXX,XX @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) | ||
63 | } | ||
64 | } | ||
65 | |||
66 | - net_socket_rs_init(&s->rs, redirector_rs_finalize, false); | ||
67 | + net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr); | ||
68 | |||
69 | if (s->indev) { | ||
70 | chr = qemu_chr_find(s->indev); | ||
71 | @@ -XXX,XX +XXX,XX @@ static void filter_mirror_set_outdev(Object *obj, | ||
72 | } | ||
73 | } | ||
74 | |||
75 | +static bool filter_mirror_get_vnet_hdr(Object *obj, Error **errp) | ||
76 | +{ | ||
77 | + MirrorState *s = FILTER_MIRROR(obj); | ||
78 | + | ||
79 | + return s->vnet_hdr; | ||
80 | +} | ||
81 | + | ||
82 | +static void filter_mirror_set_vnet_hdr(Object *obj, bool value, Error **errp) | ||
83 | +{ | ||
84 | + MirrorState *s = FILTER_MIRROR(obj); | ||
85 | + | ||
86 | + s->vnet_hdr = value; | ||
87 | +} | ||
88 | + | ||
89 | static char *filter_redirector_get_outdev(Object *obj, Error **errp) | ||
90 | { | ||
91 | MirrorState *s = FILTER_REDIRECTOR(obj); | ||
92 | @@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj, | ||
93 | |||
94 | static void filter_mirror_init(Object *obj) | ||
95 | { | ||
96 | + MirrorState *s = FILTER_MIRROR(obj); | ||
97 | + | ||
98 | object_property_add_str(obj, "outdev", filter_mirror_get_outdev, | ||
99 | filter_mirror_set_outdev, NULL); | ||
100 | + | ||
101 | + s->vnet_hdr = false; | ||
102 | + object_property_add_bool(obj, "vnet_hdr_support", | ||
103 | + filter_mirror_get_vnet_hdr, | ||
104 | + filter_mirror_set_vnet_hdr, NULL); | ||
105 | } | ||
106 | |||
107 | static void filter_redirector_init(Object *obj) | ||
108 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/qemu-options.hx | ||
111 | +++ b/qemu-options.hx | ||
112 | @@ -XXX,XX +XXX,XX @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. | ||
113 | @option{tx}: the filter is attached to the transmit queue of the netdev, | ||
114 | where it will receive packets sent by the netdev. | ||
115 | |||
116 | -@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}] | ||
117 | +@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] | ||
118 | |||
119 | -filter-mirror on netdev @var{netdevid},mirror net packet to chardev | ||
120 | -@var{chardevid} | ||
121 | +filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. | ||
122 | |||
123 | @item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid}, | ||
124 | outdev=@var{chardevid}[,queue=@var{all|rx|tx}] | ||
125 | -- | ||
126 | 2.7.4 | ||
127 | |||
128 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | We add the vnet_hdr_support option for filter-redirector, default is disabled. | ||
4 | If you use virtio-net-pci net driver or other driver needs vnet_hdr, please enable it. | ||
5 | Because colo-compare or other modules needs the vnet_hdr_len to parse | ||
6 | packet, we add this new option send the len to others. | ||
7 | You can use it for example: | ||
8 | -object filter-redirector,id=r0,netdev=hn0,queue=tx,outdev=red0,vnet_hdr_support | ||
9 | |||
10 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
11 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
12 | --- | ||
13 | net/filter-mirror.c | 23 +++++++++++++++++++++++ | ||
14 | qemu-options.hx | 6 +++--- | ||
15 | 2 files changed, 26 insertions(+), 3 deletions(-) | ||
16 | |||
17 | diff --git a/net/filter-mirror.c b/net/filter-mirror.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/net/filter-mirror.c | ||
20 | +++ b/net/filter-mirror.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj, | ||
22 | s->outdev = g_strdup(value); | ||
23 | } | ||
24 | |||
25 | +static bool filter_redirector_get_vnet_hdr(Object *obj, Error **errp) | ||
26 | +{ | ||
27 | + MirrorState *s = FILTER_REDIRECTOR(obj); | ||
28 | + | ||
29 | + return s->vnet_hdr; | ||
30 | +} | ||
31 | + | ||
32 | +static void filter_redirector_set_vnet_hdr(Object *obj, | ||
33 | + bool value, | ||
34 | + Error **errp) | ||
35 | +{ | ||
36 | + MirrorState *s = FILTER_REDIRECTOR(obj); | ||
37 | + | ||
38 | + s->vnet_hdr = value; | ||
39 | +} | ||
40 | + | ||
41 | static void filter_mirror_init(Object *obj) | ||
42 | { | ||
43 | MirrorState *s = FILTER_MIRROR(obj); | ||
44 | @@ -XXX,XX +XXX,XX @@ static void filter_mirror_init(Object *obj) | ||
45 | |||
46 | static void filter_redirector_init(Object *obj) | ||
47 | { | ||
48 | + MirrorState *s = FILTER_REDIRECTOR(obj); | ||
49 | + | ||
50 | object_property_add_str(obj, "indev", filter_redirector_get_indev, | ||
51 | filter_redirector_set_indev, NULL); | ||
52 | object_property_add_str(obj, "outdev", filter_redirector_get_outdev, | ||
53 | filter_redirector_set_outdev, NULL); | ||
54 | + | ||
55 | + s->vnet_hdr = false; | ||
56 | + object_property_add_bool(obj, "vnet_hdr_support", | ||
57 | + filter_redirector_get_vnet_hdr, | ||
58 | + filter_redirector_set_vnet_hdr, NULL); | ||
59 | } | ||
60 | |||
61 | static void filter_mirror_fini(Object *obj) | ||
62 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/qemu-options.hx | ||
65 | +++ b/qemu-options.hx | ||
66 | @@ -XXX,XX +XXX,XX @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. | ||
67 | |||
68 | filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. | ||
69 | |||
70 | -@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid}, | ||
71 | -outdev=@var{chardevid}[,queue=@var{all|rx|tx}] | ||
72 | +@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] | ||
73 | |||
74 | filter-redirector on netdev @var{netdevid},redirect filter's net packet to chardev | ||
75 | -@var{chardevid},and redirect indev's packet to filter. | ||
76 | +@var{chardevid},and redirect indev's packet to filter.if it has the vnet_hdr_support flag, | ||
77 | +filter-redirector will redirect packet with vnet_hdr_len. | ||
78 | Create a filter-redirector we need to differ outdev id from indev id, id can not | ||
79 | be the same. we can just use indev or outdev, but at least one of indev or outdev | ||
80 | need to be specified. | ||
81 | -- | ||
82 | 2.7.4 | ||
83 | |||
84 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | We can use this property flush and send packet with vnet_hdr_len. | ||
4 | |||
5 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
6 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
7 | --- | ||
8 | net/colo-compare.c | 8 ++++++-- | ||
9 | net/colo.c | 3 ++- | ||
10 | net/colo.h | 4 +++- | ||
11 | net/filter-rewriter.c | 2 +- | ||
12 | 4 files changed, 12 insertions(+), 5 deletions(-) | ||
13 | |||
14 | diff --git a/net/colo-compare.c b/net/colo-compare.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/net/colo-compare.c | ||
17 | +++ b/net/colo-compare.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static int packet_enqueue(CompareState *s, int mode) | ||
19 | Connection *conn; | ||
20 | |||
21 | if (mode == PRIMARY_IN) { | ||
22 | - pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len); | ||
23 | + pkt = packet_new(s->pri_rs.buf, | ||
24 | + s->pri_rs.packet_len, | ||
25 | + s->pri_rs.vnet_hdr_len); | ||
26 | } else { | ||
27 | - pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len); | ||
28 | + pkt = packet_new(s->sec_rs.buf, | ||
29 | + s->sec_rs.packet_len, | ||
30 | + s->sec_rs.vnet_hdr_len); | ||
31 | } | ||
32 | |||
33 | if (parse_packet_early(pkt)) { | ||
34 | diff --git a/net/colo.c b/net/colo.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/net/colo.c | ||
37 | +++ b/net/colo.c | ||
38 | @@ -XXX,XX +XXX,XX @@ void connection_destroy(void *opaque) | ||
39 | g_slice_free(Connection, conn); | ||
40 | } | ||
41 | |||
42 | -Packet *packet_new(const void *data, int size) | ||
43 | +Packet *packet_new(const void *data, int size, int vnet_hdr_len) | ||
44 | { | ||
45 | Packet *pkt = g_slice_new(Packet); | ||
46 | |||
47 | pkt->data = g_memdup(data, size); | ||
48 | pkt->size = size; | ||
49 | pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST); | ||
50 | + pkt->vnet_hdr_len = vnet_hdr_len; | ||
51 | |||
52 | return pkt; | ||
53 | } | ||
54 | diff --git a/net/colo.h b/net/colo.h | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/net/colo.h | ||
57 | +++ b/net/colo.h | ||
58 | @@ -XXX,XX +XXX,XX @@ typedef struct Packet { | ||
59 | int size; | ||
60 | /* Time of packet creation, in wall clock ms */ | ||
61 | int64_t creation_ms; | ||
62 | + /* Get vnet_hdr_len from filter */ | ||
63 | + uint32_t vnet_hdr_len; | ||
64 | } Packet; | ||
65 | |||
66 | typedef struct ConnectionKey { | ||
67 | @@ -XXX,XX +XXX,XX @@ Connection *connection_get(GHashTable *connection_track_table, | ||
68 | ConnectionKey *key, | ||
69 | GQueue *conn_list); | ||
70 | void connection_hashtable_reset(GHashTable *connection_track_table); | ||
71 | -Packet *packet_new(const void *data, int size); | ||
72 | +Packet *packet_new(const void *data, int size, int vnet_hdr_len); | ||
73 | void packet_destroy(void *opaque, void *user_data); | ||
74 | |||
75 | #endif /* QEMU_COLO_PROXY_H */ | ||
76 | diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/net/filter-rewriter.c | ||
79 | +++ b/net/filter-rewriter.c | ||
80 | @@ -XXX,XX +XXX,XX @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, | ||
81 | char *buf = g_malloc0(size); | ||
82 | |||
83 | iov_to_buf(iov, iovcnt, 0, buf, size); | ||
84 | - pkt = packet_new(buf, size); | ||
85 | + pkt = packet_new(buf, size, 0); | ||
86 | g_free(buf); | ||
87 | |||
88 | /* | ||
89 | -- | ||
90 | 2.7.4 | ||
91 | |||
92 | diff view generated by jsdifflib |
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 1 | Commit 969e50b61a28 ("net: Pad short frames to minimum size before |
---|---|---|---|
2 | sending from SLiRP/TAP") tries to pad frames but try to recyle the | ||
3 | local array that is used for padding to tap thread. This patch fixes | ||
4 | this by recyling the original buffer. | ||
2 | 5 | ||
3 | This patch change the compare_chr_send() parameter from CharBackend to CompareState, | 6 | Fixes: 969e50b61a28 ("net: Pad short frames to minimum size before sending from SLiRP/TAP") |
4 | we can get more information like vnet_hdr(We use it to support packet with vnet_header). | 7 | Tested-by: Howard Spoelstra <hsp.cat7@gmail.com> |
5 | 8 | Tested-by: Bin Meng <bmeng.cn@gmail.com> | |
6 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | 9 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
7 | Signed-off-by: Jason Wang <jasowang@redhat.com> | 10 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
8 | --- | 11 | --- |
9 | net/colo-compare.c | 14 +++++++------- | 12 | net/tap-win32.c | 6 ++++-- |
10 | 1 file changed, 7 insertions(+), 7 deletions(-) | 13 | 1 file changed, 4 insertions(+), 2 deletions(-) |
11 | 14 | ||
12 | diff --git a/net/colo-compare.c b/net/colo-compare.c | 15 | diff --git a/net/tap-win32.c b/net/tap-win32.c |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/net/colo-compare.c | 17 | --- a/net/tap-win32.c |
15 | +++ b/net/colo-compare.c | 18 | +++ b/net/tap-win32.c |
16 | @@ -XXX,XX +XXX,XX @@ enum { | 19 | @@ -XXX,XX +XXX,XX @@ static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size) |
17 | SECONDARY_IN, | 20 | static void tap_win32_send(void *opaque) |
18 | }; | 21 | { |
19 | 22 | TAPState *s = opaque; | |
20 | -static int compare_chr_send(CharBackend *out, | 23 | - uint8_t *buf; |
21 | +static int compare_chr_send(CompareState *s, | 24 | + uint8_t *buf, *orig_buf; |
22 | const uint8_t *buf, | 25 | int max_size = 4096; |
23 | uint32_t size); | 26 | int size; |
24 | 27 | uint8_t min_pkt[ETH_ZLEN]; | |
25 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data) | 28 | @@ -XXX,XX +XXX,XX @@ static void tap_win32_send(void *opaque) |
29 | |||
30 | size = tap_win32_read(s->handle, &buf, max_size); | ||
31 | if (size > 0) { | ||
32 | + orig_buf = buf; | ||
33 | + | ||
34 | if (!s->nc.peer->do_not_pad) { | ||
35 | if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) { | ||
36 | buf = min_pkt; | ||
37 | @@ -XXX,XX +XXX,XX @@ static void tap_win32_send(void *opaque) | ||
26 | } | 38 | } |
27 | 39 | ||
28 | if (result) { | 40 | qemu_send_packet(&s->nc, buf, size); |
29 | - ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size); | 41 | - tap_win32_free_buffer(s->handle, buf); |
30 | + ret = compare_chr_send(s, pkt->data, pkt->size); | 42 | + tap_win32_free_buffer(s->handle, orig_buf); |
31 | if (ret < 0) { | ||
32 | error_report("colo_send_primary_packet failed"); | ||
33 | } | ||
34 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data) | ||
35 | } | 43 | } |
36 | } | 44 | } |
37 | 45 | ||
38 | -static int compare_chr_send(CharBackend *out, | ||
39 | +static int compare_chr_send(CompareState *s, | ||
40 | const uint8_t *buf, | ||
41 | uint32_t size) | ||
42 | { | ||
43 | @@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CharBackend *out, | ||
44 | return 0; | ||
45 | } | ||
46 | |||
47 | - ret = qemu_chr_fe_write_all(out, (uint8_t *)&len, sizeof(len)); | ||
48 | + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); | ||
49 | if (ret != sizeof(len)) { | ||
50 | goto err; | ||
51 | } | ||
52 | |||
53 | - ret = qemu_chr_fe_write_all(out, (uint8_t *)buf, size); | ||
54 | + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); | ||
55 | if (ret != size) { | ||
56 | goto err; | ||
57 | } | ||
58 | @@ -XXX,XX +XXX,XX @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) | ||
59 | |||
60 | if (packet_enqueue(s, PRIMARY_IN)) { | ||
61 | trace_colo_compare_main("primary: unsupported packet in"); | ||
62 | - compare_chr_send(&s->chr_out, pri_rs->buf, pri_rs->packet_len); | ||
63 | + compare_chr_send(s, pri_rs->buf, pri_rs->packet_len); | ||
64 | } else { | ||
65 | /* compare connection */ | ||
66 | g_queue_foreach(&s->conn_list, colo_compare_connection, s); | ||
67 | @@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data) | ||
68 | |||
69 | while (!g_queue_is_empty(&conn->primary_list)) { | ||
70 | pkt = g_queue_pop_head(&conn->primary_list); | ||
71 | - compare_chr_send(&s->chr_out, pkt->data, pkt->size); | ||
72 | + compare_chr_send(s, pkt->data, pkt->size); | ||
73 | packet_destroy(pkt, NULL); | ||
74 | } | ||
75 | while (!g_queue_is_empty(&conn->secondary_list)) { | ||
76 | -- | 46 | -- |
77 | 2.7.4 | 47 | 2.7.4 |
78 | 48 | ||
79 | 49 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | We add the vnet_hdr_support option for colo-compare, default is disabled. | ||
4 | If you use virtio-net-pci or other driver needs vnet_hdr, please enable it. | ||
5 | You can use it for example: | ||
6 | -object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support | ||
7 | |||
8 | COLO-compare can get vnet header length from filter, | ||
9 | Add vnet_hdr_len to struct packet and output packet with | ||
10 | the vnet_hdr_len. | ||
11 | |||
12 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
13 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
14 | --- | ||
15 | net/colo-compare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++------- | ||
16 | qemu-options.hx | 4 ++-- | ||
17 | 2 files changed, 55 insertions(+), 9 deletions(-) | ||
18 | |||
19 | diff --git a/net/colo-compare.c b/net/colo-compare.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/net/colo-compare.c | ||
22 | +++ b/net/colo-compare.c | ||
23 | @@ -XXX,XX +XXX,XX @@ typedef struct CompareState { | ||
24 | CharBackend chr_out; | ||
25 | SocketReadState pri_rs; | ||
26 | SocketReadState sec_rs; | ||
27 | + bool vnet_hdr; | ||
28 | |||
29 | /* connection list: the connections belonged to this NIC could be found | ||
30 | * in this list. | ||
31 | @@ -XXX,XX +XXX,XX @@ enum { | ||
32 | |||
33 | static int compare_chr_send(CompareState *s, | ||
34 | const uint8_t *buf, | ||
35 | - uint32_t size); | ||
36 | + uint32_t size, | ||
37 | + uint32_t vnet_hdr_len); | ||
38 | |||
39 | static gint seq_sorter(Packet *a, Packet *b, gpointer data) | ||
40 | { | ||
41 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data) | ||
42 | } | ||
43 | |||
44 | if (result) { | ||
45 | - ret = compare_chr_send(s, pkt->data, pkt->size); | ||
46 | + ret = compare_chr_send(s, | ||
47 | + pkt->data, | ||
48 | + pkt->size, | ||
49 | + pkt->vnet_hdr_len); | ||
50 | if (ret < 0) { | ||
51 | error_report("colo_send_primary_packet failed"); | ||
52 | } | ||
53 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data) | ||
54 | |||
55 | static int compare_chr_send(CompareState *s, | ||
56 | const uint8_t *buf, | ||
57 | - uint32_t size) | ||
58 | + uint32_t size, | ||
59 | + uint32_t vnet_hdr_len) | ||
60 | { | ||
61 | int ret = 0; | ||
62 | uint32_t len = htonl(size); | ||
63 | @@ -XXX,XX +XXX,XX @@ static int compare_chr_send(CompareState *s, | ||
64 | goto err; | ||
65 | } | ||
66 | |||
67 | + if (s->vnet_hdr) { | ||
68 | + /* | ||
69 | + * We send vnet header len make other module(like filter-redirector) | ||
70 | + * know how to parse net packet correctly. | ||
71 | + */ | ||
72 | + len = htonl(vnet_hdr_len); | ||
73 | + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len)); | ||
74 | + if (ret != sizeof(len)) { | ||
75 | + goto err; | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size); | ||
80 | if (ret != size) { | ||
81 | goto err; | ||
82 | @@ -XXX,XX +XXX,XX @@ static void compare_set_outdev(Object *obj, const char *value, Error **errp) | ||
83 | s->outdev = g_strdup(value); | ||
84 | } | ||
85 | |||
86 | +static bool compare_get_vnet_hdr(Object *obj, Error **errp) | ||
87 | +{ | ||
88 | + CompareState *s = COLO_COMPARE(obj); | ||
89 | + | ||
90 | + return s->vnet_hdr; | ||
91 | +} | ||
92 | + | ||
93 | +static void compare_set_vnet_hdr(Object *obj, | ||
94 | + bool value, | ||
95 | + Error **errp) | ||
96 | +{ | ||
97 | + CompareState *s = COLO_COMPARE(obj); | ||
98 | + | ||
99 | + s->vnet_hdr = value; | ||
100 | +} | ||
101 | + | ||
102 | static void compare_pri_rs_finalize(SocketReadState *pri_rs) | ||
103 | { | ||
104 | CompareState *s = container_of(pri_rs, CompareState, pri_rs); | ||
105 | |||
106 | if (packet_enqueue(s, PRIMARY_IN)) { | ||
107 | trace_colo_compare_main("primary: unsupported packet in"); | ||
108 | - compare_chr_send(s, pri_rs->buf, pri_rs->packet_len); | ||
109 | + compare_chr_send(s, | ||
110 | + pri_rs->buf, | ||
111 | + pri_rs->packet_len, | ||
112 | + pri_rs->vnet_hdr_len); | ||
113 | } else { | ||
114 | /* compare connection */ | ||
115 | g_queue_foreach(&s->conn_list, colo_compare_connection, s); | ||
116 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | - net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, false); | ||
121 | - net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, false); | ||
122 | + net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr); | ||
123 | + net_socket_rs_init(&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr); | ||
124 | |||
125 | g_queue_init(&s->conn_list); | ||
126 | |||
127 | @@ -XXX,XX +XXX,XX @@ static void colo_flush_packets(void *opaque, void *user_data) | ||
128 | |||
129 | while (!g_queue_is_empty(&conn->primary_list)) { | ||
130 | pkt = g_queue_pop_head(&conn->primary_list); | ||
131 | - compare_chr_send(s, pkt->data, pkt->size); | ||
132 | + compare_chr_send(s, | ||
133 | + pkt->data, | ||
134 | + pkt->size, | ||
135 | + pkt->vnet_hdr_len); | ||
136 | packet_destroy(pkt, NULL); | ||
137 | } | ||
138 | while (!g_queue_is_empty(&conn->secondary_list)) { | ||
139 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_class_init(ObjectClass *oc, void *data) | ||
140 | |||
141 | static void colo_compare_init(Object *obj) | ||
142 | { | ||
143 | + CompareState *s = COLO_COMPARE(obj); | ||
144 | + | ||
145 | object_property_add_str(obj, "primary_in", | ||
146 | compare_get_pri_indev, compare_set_pri_indev, | ||
147 | NULL); | ||
148 | @@ -XXX,XX +XXX,XX @@ static void colo_compare_init(Object *obj) | ||
149 | object_property_add_str(obj, "outdev", | ||
150 | compare_get_outdev, compare_set_outdev, | ||
151 | NULL); | ||
152 | + | ||
153 | + s->vnet_hdr = false; | ||
154 | + object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr, | ||
155 | + compare_set_vnet_hdr, NULL); | ||
156 | } | ||
157 | |||
158 | static void colo_compare_finalize(Object *obj) | ||
159 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/qemu-options.hx | ||
162 | +++ b/qemu-options.hx | ||
163 | @@ -XXX,XX +XXX,XX @@ Dump the network traffic on netdev @var{dev} to the file specified by | ||
164 | The file format is libpcap, so it can be analyzed with tools such as tcpdump | ||
165 | or Wireshark. | ||
166 | |||
167 | -@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid}, | ||
168 | -outdev=@var{chardevid} | ||
169 | +@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},outdev=@var{chardevid}[,vnet_hdr_support] | ||
170 | |||
171 | Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with | ||
172 | secondary packet. If the packets are same, we will output primary | ||
173 | packet to outdev@var{chardevid}, else we will notify colo-frame | ||
174 | do checkpoint and send primary packet to outdev@var{chardevid}. | ||
175 | +if it has the vnet_hdr_support flag, colo compare will send/recv packet with vnet_hdr_len. | ||
176 | |||
177 | we must use it with the help of filter-mirror and filter-redirector. | ||
178 | |||
179 | -- | ||
180 | 2.7.4 | ||
181 | |||
182 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | Make colo-compare and filter-rewriter can parse vnet packet. | ||
4 | |||
5 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
6 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
7 | --- | ||
8 | net/colo.c | 6 +++--- | ||
9 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
10 | |||
11 | diff --git a/net/colo.c b/net/colo.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/net/colo.c | ||
14 | +++ b/net/colo.c | ||
15 | @@ -XXX,XX +XXX,XX @@ int parse_packet_early(Packet *pkt) | ||
16 | { | ||
17 | int network_length; | ||
18 | static const uint8_t vlan[] = {0x81, 0x00}; | ||
19 | - uint8_t *data = pkt->data; | ||
20 | + uint8_t *data = pkt->data + pkt->vnet_hdr_len; | ||
21 | uint16_t l3_proto; | ||
22 | ssize_t l2hdr_len = eth_get_l2_hdr_length(data); | ||
23 | |||
24 | - if (pkt->size < ETH_HLEN) { | ||
25 | + if (pkt->size < ETH_HLEN + pkt->vnet_hdr_len) { | ||
26 | trace_colo_proxy_main("pkt->size < ETH_HLEN"); | ||
27 | return 1; | ||
28 | } | ||
29 | @@ -XXX,XX +XXX,XX @@ int parse_packet_early(Packet *pkt) | ||
30 | } | ||
31 | |||
32 | network_length = pkt->ip->ip_hl * 4; | ||
33 | - if (pkt->size < l2hdr_len + network_length) { | ||
34 | + if (pkt->size < l2hdr_len + network_length + pkt->vnet_hdr_len) { | ||
35 | trace_colo_proxy_main("pkt->size < network_header + network_length"); | ||
36 | return 1; | ||
37 | } | ||
38 | -- | ||
39 | 2.7.4 | ||
40 | |||
41 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | COLO-Proxy just focus on packet payload, so we skip vnet header. | ||
4 | |||
5 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
6 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
7 | --- | ||
8 | net/colo-compare.c | 8 ++++++-- | ||
9 | 1 file changed, 6 insertions(+), 2 deletions(-) | ||
10 | |||
11 | diff --git a/net/colo-compare.c b/net/colo-compare.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/net/colo-compare.c | ||
14 | +++ b/net/colo-compare.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset) | ||
16 | sec_ip_src, sec_ip_dst); | ||
17 | } | ||
18 | |||
19 | + offset = ppkt->vnet_hdr_len + offset; | ||
20 | + | ||
21 | if (ppkt->size == spkt->size) { | ||
22 | - return memcmp(ppkt->data + offset, spkt->data + offset, | ||
23 | + return memcmp(ppkt->data + offset, | ||
24 | + spkt->data + offset, | ||
25 | spkt->size - offset); | ||
26 | } else { | ||
27 | trace_colo_compare_main("Net packet size are not the same"); | ||
28 | @@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt) | ||
29 | */ | ||
30 | if (ptcp->th_off > 5) { | ||
31 | ptrdiff_t tcp_offset; | ||
32 | + | ||
33 | tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data | ||
34 | - + (ptcp->th_off * 4); | ||
35 | + + (ptcp->th_off * 4) - ppkt->vnet_hdr_len; | ||
36 | res = colo_packet_compare_common(ppkt, spkt, tcp_offset); | ||
37 | } else if (ptcp->th_sum == stcp->th_sum) { | ||
38 | res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN); | ||
39 | -- | ||
40 | 2.7.4 | ||
41 | |||
42 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
2 | 1 | ||
3 | Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com> | ||
4 | Signed-off-by: Jason Wang <jasowang@redhat.com> | ||
5 | --- | ||
6 | docs/colo-proxy.txt | 26 ++++++++++++++++++++++++++ | ||
7 | 1 file changed, 26 insertions(+) | ||
8 | |||
9 | diff --git a/docs/colo-proxy.txt b/docs/colo-proxy.txt | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/docs/colo-proxy.txt | ||
12 | +++ b/docs/colo-proxy.txt | ||
13 | @@ -XXX,XX +XXX,XX @@ Secondary(ip:3.3.3.8): | ||
14 | -chardev socket,id=red1,host=3.3.3.3,port=9004 | ||
15 | -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 | ||
16 | -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 | ||
17 | +-object filter-rewriter,id=f3,netdev=hn0,queue=all | ||
18 | + | ||
19 | +If you want to use virtio-net-pci or other driver with vnet_header: | ||
20 | + | ||
21 | +Primary(ip:3.3.3.3): | ||
22 | +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown | ||
23 | +-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66 | ||
24 | +-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait | ||
25 | +-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait | ||
26 | +-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait | ||
27 | +-chardev socket,id=compare0-0,host=3.3.3.3,port=9001 | ||
28 | +-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait | ||
29 | +-chardev socket,id=compare_out0,host=3.3.3.3,port=9005 | ||
30 | +-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support | ||
31 | +-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out,vnet_hdr_support | ||
32 | +-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0,vnet_hdr_support | ||
33 | +-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support | ||
34 | + | ||
35 | +Secondary(ip:3.3.3.8): | ||
36 | +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown | ||
37 | +-device e1000,netdev=hn0,mac=52:a4:00:12:78:66 | ||
38 | +-chardev socket,id=red0,host=3.3.3.3,port=9003 | ||
39 | +-chardev socket,id=red1,host=3.3.3.3,port=9004 | ||
40 | +-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0,vnet_hdr_support | ||
41 | +-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1,vnet_hdr_support | ||
42 | +-object filter-rewriter,id=f3,netdev=hn0,queue=all,vnet_hdr_support | ||
43 | |||
44 | Note: | ||
45 | a.COLO-proxy must work with COLO-frame and Block-replication. | ||
46 | -- | ||
47 | 2.7.4 | ||
48 | |||
49 | diff view generated by jsdifflib |