1
The following changes since commit 56821559f0ba682fe6b367815572e6f974d329ab:
1
The following changes since commit 6632f6ff96f0537fc34cdc00c760656fc62e23c5:
2
2
3
Merge remote-tracking branch 'dgilbert/tags/pull-hmp-20170517' into staging (2017-05-18 13:36:15 +0100)
3
Merge remote-tracking branch 'remotes/famz/tags/block-and-testing-pull-request' into staging (2017-07-17 11:46:36 +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 82342e91b60a4a078811df4e1a545e57abffa11d:
9
for you to fetch changes up to 189ae6bb5ce1f5a322f8691d00fe942ba43dd601:
10
10
11
e1000e: Fix ICR "Other" causes clear logic (2017-05-23 10:10:38 +0800)
11
virtio-net: fix offload ctrl endian (2017-07-17 20:13:56 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
14
15
- fix virtio-net ctrl offload endian
16
- vnet header support for variou COLO netfilters and compare thread
17
15
----------------------------------------------------------------
18
----------------------------------------------------------------
16
Sameeh Jubran (1):
19
Jason Wang (1):
17
e1000e: Fix ICR "Other" causes clear logic
20
virtio-net: fix offload ctrl endian
18
21
19
Thomas Huth (3):
22
Michal Privoznik (1):
20
net/tap: Replace tap-haiku.c and tap-aix.c by a generic tap-stub.c
23
virtion-net: Prefer is_power_of_2()
21
net/dump: Issue a warning for the deprecated "-net dump"
22
hmp / net: Mark host_net_add/remove as deprecated
23
24
24
Yunjian Wang (1):
25
Zhang Chen (12):
25
virtio-net: fix wild pointer when remove virtio-net queues
26
net: Add vnet_hdr_len arguments in NetClientState
27
net/net.c: Add vnet_hdr support in SocketReadState
28
net/filter-mirror.c: Introduce parameter for filter_send()
29
net/filter-mirror.c: Make filter mirror support vnet support.
30
net/filter-mirror.c: Add new option to enable vnet support for filter-redirector
31
net/colo.c: Make vnet_hdr_len as packet property
32
net/colo-compare.c: Introduce parameter for compare_chr_send()
33
net/colo-compare.c: Make colo-compare support vnet_hdr_len
34
net/colo.c: Add vnet packet parse feature in colo-proxy
35
net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare
36
net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len
37
docs/colo-proxy.txt: Update colo-proxy usage of net driver with vnet_header
26
38
27
Zhang Chen (4):
39
docs/colo-proxy.txt | 26 ++++++++++++++++
28
COLO-compare: Improve tcp compare trace event readability
40
hw/net/virtio-net.c | 4 ++-
29
net/filter-mirror.c: Remove duplicate check code.
41
include/net/net.h | 10 ++++--
30
net/filter-mirror.c: Rename filter_mirror_send() and fix codestyle
42
net/colo-compare.c | 84 ++++++++++++++++++++++++++++++++++++++++++---------
31
net/filter-rewriter: Remove unused option in filter-rewriter
43
net/colo.c | 9 +++---
32
44
net/colo.h | 4 ++-
33
hmp-commands.hx | 8 ++--
45
net/filter-mirror.c | 75 +++++++++++++++++++++++++++++++++++++++++----
34
hw/net/e1000e_core.c | 10 ++++-
46
net/filter-rewriter.c | 37 ++++++++++++++++++++++-
35
hw/net/virtio-net.c | 3 ++
47
net/net.c | 37 ++++++++++++++++++++---
36
net/Makefile.objs | 15 ++++----
48
net/socket.c | 8 ++---
37
net/colo-compare.c | 33 ++++++++++------
49
qemu-options.hx | 19 ++++++------
38
net/dump.c | 3 ++
50
11 files changed, 265 insertions(+), 48 deletions(-)
39
net/filter-mirror.c | 35 ++++++++---------
40
net/net.c | 13 +++++++
41
net/tap-haiku.c | 87 -------------------------------------------
42
net/{tap-aix.c => tap-stub.c} | 3 +-
43
net/trace-events | 3 +-
44
qemu-options.hx | 2 +-
45
12 files changed, 80 insertions(+), 135 deletions(-)
46
delete mode 100644 net/tap-haiku.c
47
rename net/{tap-aix.c => tap-stub.c} (97%)
48
51
49
52
diff view generated by jsdifflib
1
From: Sameeh Jubran <sameeh@daynix.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
2
3
This commit fixes a bug which causes the guest to hang. The bug was
3
Add vnet_hdr_len arguments in NetClientState
4
observed upon a "receive overrun" (bit #6 of the ICR register)
4
that make other module get real vnet_hdr_len easily.
5
interrupt which could be triggered post migration in a heavy traffic
6
environment. Even though the "receive overrun" bit (#6) is masked out
7
by the IMS register (refer to the log below) the driver still receives
8
an interrupt as the "receive overrun" bit (#6) causes the "Other" -
9
bit #24 of the ICR register - bit to be set as documented below. The
10
driver handles the interrupt and clears the "Other" bit (#24) but
11
doesn't clear the "receive overrun" bit (#6) which leads to an
12
infinite loop. Apparently the Windows driver expects that the "receive
13
overrun" bit and other ones - documented below - to be cleared when
14
the "Other" bit (#24) is cleared.
15
5
16
So to sum that up:
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
17
1. Bit #6 of the ICR register is set by heavy traffic
18
2. As a results of setting bit #6, bit #24 is set
19
3. The driver receives an interrupt for bit 24 (it doesn't receieve an
20
interrupt for bit #6 as it is masked out by IMS)
21
4. The driver handles and clears the interrupt of bit #24
22
5. Bit #6 is still set.
23
6. 2 happens all over again
24
25
The Interrupt Cause Read - ICR register:
26
27
The ICR has the "Other" bit - bit #24 - that is set when one or more
28
of the following ICR register's bits are set:
29
30
LSC - bit #2, RXO - bit #6, MDAC - bit #9, SRPD - bit #16, ACK - bit
31
#17, MNG - bit #18
32
33
This bug can occur with any of these bits depending on the driver's
34
behaviour and the way it configures the device. However, trying to
35
reproduce it with any bit other than RX0 is challenging and came to
36
failure as the drivers don't implement most of these bits, trying to
37
reproduce it with LSC (Link Status Change - bit #2) bit didn't succeed
38
too as it seems that Windows handles this bit differently.
39
40
Log sample of the storm:
41
42
27563@1494850819.411877:e1000e_irq_pending_interrupts ICR PENDING: 0x1000000 (ICR: 0x815000c2, IMS: 0x1a00004)
43
27563@1494850819.411900:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 0x815000c2, IMS: 0xa00004)
44
27563@1494850819.411915:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 0x815000c2, IMS: 0xa00004)
45
27563@1494850819.412380:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 0x815000c2, IMS: 0xa00004)
46
27563@1494850819.412395:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 0x815000c2, IMS: 0xa00004)
47
27563@1494850819.412436:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 0x815000c2, IMS: 0xa00004)
48
27563@1494850819.412441:e1000e_irq_pending_interrupts ICR PENDING: 0x0 (ICR: 0x815000c2, IMS: 0xa00004)
49
27563@1494850819.412998:e1000e_irq_pending_interrupts ICR PENDING: 0x1000000 (ICR: 0x815000c2, IMS: 0x1a00004)
50
51
* This bug behaviour wasn't observed with the Linux driver.
52
53
This commit solves:
54
https://bugzilla.redhat.com/show_bug.cgi?id=1447935
55
https://bugzilla.redhat.com/show_bug.cgi?id=1449490
56
57
Cc: qemu-stable@nongnu.org
58
Signed-off-by: Sameeh Jubran <sjubran@redhat.com>
59
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
60
---
8
---
61
hw/net/e1000e_core.c | 10 ++++++++--
9
include/net/net.h | 1 +
62
1 file changed, 8 insertions(+), 2 deletions(-)
10
net/net.c | 1 +
11
2 files changed, 2 insertions(+)
63
12
64
diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
13
diff --git a/include/net/net.h b/include/net/net.h
65
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
66
--- a/hw/net/e1000e_core.c
15
--- a/include/net/net.h
67
+++ b/hw/net/e1000e_core.c
16
+++ b/include/net/net.h
68
@@ -XXX,XX +XXX,XX @@ e1000e_set_ics(E1000ECore *core, int index, uint32_t val)
17
@@ -XXX,XX +XXX,XX @@ struct NetClientState {
69
static void
18
unsigned int queue_index;
70
e1000e_set_icr(E1000ECore *core, int index, uint32_t val)
19
unsigned rxfilter_notify_enabled:1;
71
{
20
int vring_enable;
72
+ uint32_t icr = 0;
21
+ int vnet_hdr_len;
73
if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
22
QTAILQ_HEAD(NetFilterHead, NetFilterState) filters;
74
(core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
23
};
75
trace_e1000e_irq_icr_process_iame();
24
76
e1000e_clear_ims_bits(core, core->mac[IAM]);
25
diff --git a/net/net.c b/net/net.c
26
index XXXXXXX..XXXXXXX 100644
27
--- a/net/net.c
28
+++ b/net/net.c
29
@@ -XXX,XX +XXX,XX @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len)
30
return;
77
}
31
}
78
32
79
- trace_e1000e_irq_icr_write(val, core->mac[ICR], core->mac[ICR] & ~val);
33
+ nc->vnet_hdr_len = len;
80
- core->mac[ICR] &= ~val;
34
nc->info->set_vnet_hdr_len(nc, len);
81
+ icr = core->mac[ICR] & ~val;
82
+ /* Windows driver expects that the "receive overrun" bit and other
83
+ * ones to be cleared when the "Other" bit (#24) is cleared.
84
+ */
85
+ icr = (val & E1000_ICR_OTHER) ? (icr & ~E1000_ICR_OTHER_CAUSES) : icr;
86
+ trace_e1000e_irq_icr_write(val, core->mac[ICR], icr);
87
+ core->mac[ICR] = icr;
88
e1000e_update_interrupt_state(core);
89
}
35
}
90
36
91
--
37
--
92
2.7.4
38
2.7.4
93
39
94
40
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
2
3
The netdev_add and netdev_del commands should be used nowadays instead.
3
We add a flag to decide whether net_fill_rstate() need read
4
the vnet_hdr_len or not.
4
5
5
Signed-off-by: Thomas Huth <thuth@redhat.com>
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Suggested-by: Jason Wang <jasowang@redhat.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
9
---
8
hmp-commands.hx | 8 ++++----
10
include/net/net.h | 9 +++++++--
9
net/net.c | 13 +++++++++++++
11
net/colo-compare.c | 4 ++--
10
2 files changed, 17 insertions(+), 4 deletions(-)
12
net/filter-mirror.c | 2 +-
13
net/net.c | 36 ++++++++++++++++++++++++++++++++----
14
net/socket.c | 8 ++++----
15
5 files changed, 46 insertions(+), 13 deletions(-)
11
16
12
diff --git a/hmp-commands.hx b/hmp-commands.hx
17
diff --git a/include/net/net.h b/include/net/net.h
13
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
14
--- a/hmp-commands.hx
19
--- a/include/net/net.h
15
+++ b/hmp-commands.hx
20
+++ b/include/net/net.h
16
@@ -XXX,XX +XXX,XX @@ ETEXI
21
@@ -XXX,XX +XXX,XX @@ typedef struct NICState {
17
.name = "host_net_add",
22
} NICState;
18
.args_type = "device:s,opts:s?",
23
19
.params = "tap|user|socket|vde|netmap|bridge|vhost-user|dump [options]",
24
struct SocketReadState {
20
- .help = "add host VLAN client",
25
- int state; /* 0 = getting length, 1 = getting data */
21
+ .help = "add host VLAN client (deprecated, use netdev_add instead)",
26
+ /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
22
.cmd = hmp_host_net_add,
27
+ int state;
23
.command_completion = host_net_add_completion,
28
+ /* This flag decide whether to read the vnet_hdr_len field */
24
},
29
+ bool vnet_hdr;
25
@@ -XXX,XX +XXX,XX @@ ETEXI
30
uint32_t index;
26
STEXI
31
uint32_t packet_len;
27
@item host_net_add
32
+ uint32_t vnet_hdr_len;
28
@findex host_net_add
33
uint8_t buf[NET_BUFSIZE];
29
-Add host VLAN client.
34
SocketReadStateFinalize *finalize;
30
+Add host VLAN client. Deprecated, please use @code{netdev_add} instead.
35
};
31
ETEXI
36
@@ -XXX,XX +XXX,XX @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender,
32
37
void print_net_client(Monitor *mon, NetClientState *nc);
33
{
38
void hmp_info_network(Monitor *mon, const QDict *qdict);
34
.name = "host_net_remove",
39
void net_socket_rs_init(SocketReadState *rs,
35
.args_type = "vlan_id:i,device:s",
40
- SocketReadStateFinalize *finalize);
36
.params = "vlan_id name",
41
+ SocketReadStateFinalize *finalize,
37
- .help = "remove host VLAN client",
42
+ bool vnet_hdr);
38
+ .help = "remove host VLAN client (deprecated, use netdev_del instead)",
43
39
.cmd = hmp_host_net_remove,
44
/* NIC info */
40
.command_completion = host_net_remove_completion,
45
41
},
46
diff --git a/net/colo-compare.c b/net/colo-compare.c
42
@@ -XXX,XX +XXX,XX @@ ETEXI
47
index XXXXXXX..XXXXXXX 100644
43
STEXI
48
--- a/net/colo-compare.c
44
@item host_net_remove
49
+++ b/net/colo-compare.c
45
@findex host_net_remove
50
@@ -XXX,XX +XXX,XX @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
46
-Remove host VLAN client.
51
return;
47
+Remove host VLAN client. Deprecated, please use @code{netdev_del} instead.
52
}
48
ETEXI
53
49
54
- net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize);
50
{
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);
51
diff --git a/net/net.c b/net/net.c
74
diff --git a/net/net.c b/net/net.c
52
index XXXXXXX..XXXXXXX 100644
75
index XXXXXXX..XXXXXXX 100644
53
--- a/net/net.c
76
--- a/net/net.c
54
+++ b/net/net.c
77
+++ b/net/net.c
55
@@ -XXX,XX +XXX,XX @@
78
@@ -XXX,XX +XXX,XX @@ QemuOptsList qemu_net_opts = {
56
#include "qapi-visit.h"
79
};
57
#include "qapi/opts-visitor.h"
80
58
#include "sysemu/sysemu.h"
81
void net_socket_rs_init(SocketReadState *rs,
59
+#include "sysemu/qtest.h"
82
- SocketReadStateFinalize *finalize)
60
#include "net/filter.h"
83
+ SocketReadStateFinalize *finalize,
61
#include "qapi/string-output-visitor.h"
84
+ bool vnet_hdr)
62
85
{
63
@@ -XXX,XX +XXX,XX @@ void hmp_host_net_add(Monitor *mon, const QDict *qdict)
86
rs->state = 0;
64
const char *opts_str = qdict_get_try_str(qdict, "opts");
87
+ rs->vnet_hdr = vnet_hdr;
65
Error *local_err = NULL;
88
rs->index = 0;
66
QemuOpts *opts;
89
rs->packet_len = 0;
67
+ static bool warned;
90
+ rs->vnet_hdr_len = 0;
68
+
91
memset(rs->buf, 0, sizeof(rs->buf));
69
+ if (!warned && !qtest_enabled()) {
92
rs->finalize = finalize;
70
+ error_report("host_net_add is deprecated, use netdev_add instead");
93
}
71
+ warned = true;
94
@@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
72
+ }
95
unsigned int l;
73
96
74
if (!net_host_check_device(device)) {
97
while (size > 0) {
75
monitor_printf(mon, "invalid host network device %s\n", device);
98
- /* reassemble a packet from the network */
76
@@ -XXX,XX +XXX,XX @@ void hmp_host_net_remove(Monitor *mon, const QDict *qdict)
99
- switch (rs->state) { /* 0 = getting length, 1 = getting data */
77
NetClientState *nc;
100
+ /* Reassemble a packet from the network.
78
int vlan_id = qdict_get_int(qdict, "vlan_id");
101
+ * 0 = getting length.
79
const char *device = qdict_get_str(qdict, "device");
102
+ * 1 = getting vnet header length.
80
+ static bool warned;
103
+ * 2 = getting data.
81
+
104
+ */
82
+ if (!warned && !qtest_enabled()) {
105
+ switch (rs->state) {
83
+ error_report("host_net_remove is deprecated, use netdev_del instead");
106
case 0:
84
+ warned = true;
107
l = 4 - rs->index;
85
+ }
108
if (l > size) {
86
109
@@ -XXX,XX +XXX,XX @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)
87
nc = net_hub_find_client_by_name(vlan_id, device);
110
/* got length */
88
if (!nc) {
111
rs->packet_len = ntohl(*(uint32_t *)rs->buf);
112
rs->index = 0;
113
- rs->state = 1;
114
+ if (rs->vnet_hdr) {
115
+ rs->state = 1;
116
+ } else {
117
+ rs->state = 2;
118
+ rs->vnet_hdr_len = 0;
119
+ }
120
}
121
break;
122
case 1:
123
+ l = 4 - rs->index;
124
+ if (l > size) {
125
+ l = size;
126
+ }
127
+ memcpy(rs->buf + rs->index, buf, l);
128
+ buf += l;
129
+ size -= l;
130
+ rs->index += l;
131
+ if (rs->index == 4) {
132
+ /* got vnet header length */
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
143
index XXXXXXX..XXXXXXX 100644
144
--- a/net/socket.c
145
+++ b/net/socket.c
146
@@ -XXX,XX +XXX,XX @@ static void net_socket_send(void *opaque)
147
closesocket(s->fd);
148
149
s->fd = -1;
150
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
151
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
152
s->nc.link_down = true;
153
memset(s->nc.info_str, 0, sizeof(s->nc.info_str));
154
155
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer,
156
s->fd = fd;
157
s->listen_fd = -1;
158
s->send_fn = net_socket_send_dgram;
159
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
160
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
161
net_socket_read_poll(s, true);
162
163
/* mcast: save bound address as dst */
164
@@ -XXX,XX +XXX,XX @@ static NetSocketState *net_socket_fd_init_stream(NetClientState *peer,
165
166
s->fd = fd;
167
s->listen_fd = -1;
168
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
169
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
170
171
/* Disable Nagle algorithm on TCP sockets to reduce latency */
172
socket_set_nodelay(fd);
173
@@ -XXX,XX +XXX,XX @@ static int net_socket_listen_init(NetClientState *peer,
174
s->fd = -1;
175
s->listen_fd = fd;
176
s->nc.link_down = true;
177
- net_socket_rs_init(&s->rs, net_socket_rs_finalize);
178
+ net_socket_rs_init(&s->rs, net_socket_rs_finalize, false);
179
180
qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s);
181
return 0;
89
--
182
--
90
2.7.4
183
2.7.4
91
184
92
185
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
2
3
Because filter_mirror_receive_iov() and filter_redirector_receive_iov()
3
This patch change the filter_send() parameter from CharBackend to MirrorState,
4
both use the filter_mirror_send() to send packet, so I change
4
we can get more information like vnet_hdr(We use it to support packet with vnet_header).
5
filter_mirror_send() to filter_send() that looks more common.
6
And fix some codestyle.
7
5
8
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
8
---
11
net/filter-mirror.c | 29 ++++++++++++++++-------------
9
net/filter-mirror.c | 10 +++++-----
12
1 file changed, 16 insertions(+), 13 deletions(-)
10
1 file changed, 5 insertions(+), 5 deletions(-)
13
11
14
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
12
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
15
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
16
--- a/net/filter-mirror.c
14
--- a/net/filter-mirror.c
17
+++ b/net/filter-mirror.c
15
+++ b/net/filter-mirror.c
18
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorState {
16
@@ -XXX,XX +XXX,XX @@ typedef struct MirrorState {
19
SocketReadState rs;
17
SocketReadState rs;
20
} MirrorState;
18
} MirrorState;
21
19
22
-static int filter_mirror_send(CharBackend *chr_out,
20
-static int filter_send(CharBackend *chr_out,
23
- const struct iovec *iov,
21
+static int filter_send(MirrorState *s,
24
- int iovcnt)
22
const struct iovec *iov,
25
+static int filter_send(CharBackend *chr_out,
23
int iovcnt)
26
+ const struct iovec *iov,
27
+ int iovcnt)
28
{
24
{
29
int ret = 0;
25
@@ -XXX,XX +XXX,XX @@ static int filter_send(CharBackend *chr_out,
30
ssize_t size = 0;
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;
31
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
42
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
32
MirrorState *s = FILTER_MIRROR(nf);
43
MirrorState *s = FILTER_MIRROR(nf);
33
int ret;
44
int ret;
34
45
35
- ret = filter_mirror_send(&s->chr_out, iov, iovcnt);
46
- ret = filter_send(&s->chr_out, iov, iovcnt);
36
+ ret = filter_send(&s->chr_out, iov, iovcnt);
47
+ ret = filter_send(s, iov, iovcnt);
37
if (ret) {
48
if (ret) {
38
- error_report("filter_mirror_send failed(%s)", strerror(-ret));
49
error_report("filter mirror send failed(%s)", strerror(-ret));
39
+ error_report("filter mirror send failed(%s)", strerror(-ret));
40
}
50
}
41
42
/*
43
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf,
51
@@ -XXX,XX +XXX,XX @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf,
44
int ret;
52
int ret;
45
53
46
if (qemu_chr_fe_get_driver(&s->chr_out)) {
54
if (qemu_chr_fe_backend_connected(&s->chr_out)) {
47
- ret = filter_mirror_send(&s->chr_out, iov, iovcnt);
55
- ret = filter_send(&s->chr_out, iov, iovcnt);
48
+ ret = filter_send(&s->chr_out, iov, iovcnt);
56
+ ret = filter_send(s, iov, iovcnt);
49
if (ret) {
57
if (ret) {
50
- error_report("filter_mirror_send failed(%s)", strerror(-ret));
58
error_report("filter redirector send failed(%s)", strerror(-ret));
51
+ error_report("filter redirector send failed(%s)", strerror(-ret));
52
}
59
}
53
return iov_size(iov, iovcnt);
54
} else {
55
@@ -XXX,XX +XXX,XX @@ static char *filter_redirector_get_indev(Object *obj, Error **errp)
56
return g_strdup(s->indev);
57
}
58
59
-static void
60
-filter_redirector_set_indev(Object *obj, const char *value, Error **errp)
61
+static void filter_redirector_set_indev(Object *obj,
62
+ const char *value,
63
+ Error **errp)
64
{
65
MirrorState *s = FILTER_REDIRECTOR(obj);
66
67
@@ -XXX,XX +XXX,XX @@ static char *filter_mirror_get_outdev(Object *obj, Error **errp)
68
return g_strdup(s->outdev);
69
}
70
71
-static void
72
-filter_mirror_set_outdev(Object *obj, const char *value, Error **errp)
73
+static void filter_mirror_set_outdev(Object *obj,
74
+ const char *value,
75
+ Error **errp)
76
{
77
MirrorState *s = FILTER_MIRROR(obj);
78
79
@@ -XXX,XX +XXX,XX @@ static char *filter_redirector_get_outdev(Object *obj, Error **errp)
80
return g_strdup(s->outdev);
81
}
82
83
-static void
84
-filter_redirector_set_outdev(Object *obj, const char *value, Error **errp)
85
+static void filter_redirector_set_outdev(Object *obj,
86
+ const char *value,
87
+ Error **errp)
88
{
89
MirrorState *s = FILTER_REDIRECTOR(obj);
90
91
--
60
--
92
2.7.4
61
2.7.4
93
62
94
63
diff view generated by jsdifflib
New patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
2
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
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
2
3
The s->outdev have checked in filter_mirror_set_outdev().
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
4
9
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
10
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
---
12
---
8
net/filter-mirror.c | 6 ------
13
net/filter-mirror.c | 23 +++++++++++++++++++++++
9
1 file changed, 6 deletions(-)
14
qemu-options.hx | 6 +++---
15
2 files changed, 26 insertions(+), 3 deletions(-)
10
16
11
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
17
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
12
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
13
--- a/net/filter-mirror.c
19
--- a/net/filter-mirror.c
14
+++ b/net/filter-mirror.c
20
+++ b/net/filter-mirror.c
15
@@ -XXX,XX +XXX,XX @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp)
21
@@ -XXX,XX +XXX,XX @@ static void filter_redirector_set_outdev(Object *obj,
16
MirrorState *s = FILTER_MIRROR(nf);
22
s->outdev = g_strdup(value);
17
Chardev *chr;
23
}
18
24
19
- if (!s->outdev) {
25
+static bool filter_redirector_get_vnet_hdr(Object *obj, Error **errp)
20
- error_setg(errp, "filter mirror needs 'outdev' "
26
+{
21
- "property set");
27
+ MirrorState *s = FILTER_REDIRECTOR(obj);
22
- return;
28
+
23
- }
29
+ return s->vnet_hdr;
24
-
30
+}
25
chr = qemu_chr_find(s->outdev);
31
+
26
if (chr == NULL) {
32
+static void filter_redirector_set_vnet_hdr(Object *obj,
27
error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
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.
28
--
81
--
29
2.7.4
82
2.7.4
30
83
31
84
diff view generated by jsdifflib
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
2
3
Because of previous patch's trace arguments over the limit
3
We can use this property flush and send packet with vnet_hdr_len.
4
of UST backend, so I rewrite the patch.
5
4
6
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
5
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
6
Signed-off-by: Jason Wang <jasowang@redhat.com>
8
---
7
---
9
net/colo-compare.c | 33 ++++++++++++++++++++++-----------
8
net/colo-compare.c | 8 ++++++--
10
net/trace-events | 3 +--
9
net/colo.c | 3 ++-
11
2 files changed, 23 insertions(+), 13 deletions(-)
10
net/colo.h | 4 +++-
11
net/filter-rewriter.c | 2 +-
12
4 files changed, 12 insertions(+), 5 deletions(-)
12
13
13
diff --git a/net/colo-compare.c b/net/colo-compare.c
14
diff --git a/net/colo-compare.c b/net/colo-compare.c
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/net/colo-compare.c
16
--- a/net/colo-compare.c
16
+++ b/net/colo-compare.c
17
+++ b/net/colo-compare.c
17
@@ -XXX,XX +XXX,XX @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
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);
18
}
31
}
19
32
20
if (res != 0 && trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
33
if (parse_packet_early(pkt)) {
21
- trace_colo_compare_pkt_info_src(inet_ntoa(ppkt->ip->ip_src),
34
diff --git a/net/colo.c b/net/colo.c
22
- ntohl(stcp->th_seq),
23
- ntohl(stcp->th_ack),
24
- res, stcp->th_flags,
25
- spkt->size);
26
-
27
- trace_colo_compare_pkt_info_dst(inet_ntoa(ppkt->ip->ip_dst),
28
- ntohl(ptcp->th_seq),
29
- ntohl(ptcp->th_ack),
30
- res, ptcp->th_flags,
31
- ppkt->size);
32
+ char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];
33
+
34
+ strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src));
35
+ strcpy(pri_ip_dst, inet_ntoa(ppkt->ip->ip_dst));
36
+ strcpy(sec_ip_src, inet_ntoa(spkt->ip->ip_src));
37
+ strcpy(sec_ip_dst, inet_ntoa(spkt->ip->ip_dst));
38
+
39
+ trace_colo_compare_ip_info(ppkt->size, pri_ip_src,
40
+ pri_ip_dst, spkt->size,
41
+ sec_ip_src, sec_ip_dst);
42
+
43
+ trace_colo_compare_tcp_info("pri tcp packet",
44
+ ntohl(ptcp->th_seq),
45
+ ntohl(ptcp->th_ack),
46
+ res, ptcp->th_flags,
47
+ ppkt->size);
48
+
49
+ trace_colo_compare_tcp_info("sec tcp packet",
50
+ ntohl(stcp->th_seq),
51
+ ntohl(stcp->th_ack),
52
+ res, stcp->th_flags,
53
+ spkt->size);
54
55
qemu_hexdump((char *)ppkt->data, stderr,
56
"colo-compare ppkt", ppkt->size);
57
diff --git a/net/trace-events b/net/trace-events
58
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
59
--- a/net/trace-events
36
--- a/net/colo.c
60
+++ b/net/trace-events
37
+++ b/net/colo.c
61
@@ -XXX,XX +XXX,XX @@ colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d"
38
@@ -XXX,XX +XXX,XX @@ void connection_destroy(void *opaque)
62
colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
39
g_slice_free(Connection, conn);
63
colo_old_packet_check_found(int64_t old_time) "%" PRId64
40
}
64
colo_compare_miscompare(void) ""
41
65
-colo_compare_pkt_info_src(const char *src, uint32_t sseq, uint32_t sack, int res, uint32_t sflag, int ssize) "src/dst: %s s: seq/ack=%u/%u res=%d flags=%x spkt_size: %d\n"
42
-Packet *packet_new(const void *data, int size)
66
-colo_compare_pkt_info_dst(const char *dst, uint32_t dseq, uint32_t dack, int res, uint32_t dflag, int dsize) "src/dst: %s d: seq/ack=%u/%u res=%d flags=%x dpkt_size: %d\n"
43
+Packet *packet_new(const void *data, int size, int vnet_hdr_len)
67
+colo_compare_tcp_info(const char *pkt, uint32_t seq, uint32_t ack, int res, uint32_t flag, int size) "side: %s seq/ack= %u/%u res= %d flags= %x pkt_size: %d\n"
44
{
68
45
Packet *pkt = g_slice_new(Packet);
69
# net/filter-rewriter.c
46
70
colo_filter_rewriter_debug(void) ""
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
/*
71
--
89
--
72
2.7.4
90
2.7.4
73
91
74
92
diff view generated by jsdifflib
New patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
2
3
This patch change the compare_chr_send() parameter from CharBackend to CompareState,
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/colo-compare.c | 14 +++++++-------
10
1 file changed, 7 insertions(+), 7 deletions(-)
11
12
diff --git a/net/colo-compare.c b/net/colo-compare.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/net/colo-compare.c
15
+++ b/net/colo-compare.c
16
@@ -XXX,XX +XXX,XX @@ enum {
17
SECONDARY_IN,
18
};
19
20
-static int compare_chr_send(CharBackend *out,
21
+static int compare_chr_send(CompareState *s,
22
const uint8_t *buf,
23
uint32_t size);
24
25
@@ -XXX,XX +XXX,XX @@ static void colo_compare_connection(void *opaque, void *user_data)
26
}
27
28
if (result) {
29
- ret = compare_chr_send(&s->chr_out, pkt->data, pkt->size);
30
+ ret = compare_chr_send(s, pkt->data, pkt->size);
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
}
36
}
37
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
--
77
2.7.4
78
79
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
2
3
The files tap-haiku.c and tap-aix.c are identical (except one line
3
We add the vnet_hdr_support option for colo-compare, default is disabled.
4
of error message). We should avoid such code duplication, so replace
4
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
5
these by a generic tap-stub.c file instead.
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
6
7
7
Signed-off-by: Thomas Huth <thuth@redhat.com>
8
COLO-compare can get vnet header length from filter,
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
13
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
14
---
11
net/Makefile.objs | 15 +++++-----
15
net/colo-compare.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++-------
12
net/tap-aix.c | 88 -------------------------------------------------------
16
qemu-options.hx | 4 ++--
13
net/tap-haiku.c | 87 ------------------------------------------------------
17
2 files changed, 55 insertions(+), 9 deletions(-)
14
net/tap-stub.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
4 files changed, 95 insertions(+), 182 deletions(-)
16
delete mode 100644 net/tap-aix.c
17
delete mode 100644 net/tap-haiku.c
18
create mode 100644 net/tap-stub.c
19
18
20
diff --git a/net/Makefile.objs b/net/Makefile.objs
19
diff --git a/net/colo-compare.c b/net/colo-compare.c
21
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
22
--- a/net/Makefile.objs
21
--- a/net/colo-compare.c
23
+++ b/net/Makefile.objs
22
+++ b/net/colo-compare.c
24
@@ -XXX,XX +XXX,XX @@ common-obj-y += socket.o
23
@@ -XXX,XX +XXX,XX @@ typedef struct CompareState {
25
common-obj-y += dump.o
24
CharBackend chr_out;
26
common-obj-y += eth.o
25
SocketReadState pri_rs;
27
common-obj-$(CONFIG_L2TPV3) += l2tpv3.o
26
SocketReadState sec_rs;
28
-common-obj-$(CONFIG_POSIX) += tap.o vhost-user.o
27
+ bool vnet_hdr;
29
-common-obj-$(CONFIG_LINUX) += tap-linux.o
28
30
-common-obj-$(CONFIG_WIN32) += tap-win32.o
29
/* connection list: the connections belonged to this NIC could be found
31
-common-obj-$(CONFIG_BSD) += tap-bsd.o
30
* in this list.
32
-common-obj-$(CONFIG_SOLARIS) += tap-solaris.o
31
@@ -XXX,XX +XXX,XX @@ enum {
33
-common-obj-$(CONFIG_AIX) += tap-aix.o
32
34
-common-obj-$(CONFIG_HAIKU) += tap-haiku.o
33
static int compare_chr_send(CompareState *s,
35
+common-obj-$(CONFIG_POSIX) += vhost-user.o
34
const uint8_t *buf,
36
common-obj-$(CONFIG_SLIRP) += slirp.o
35
- uint32_t size);
37
common-obj-$(CONFIG_VDE) += vde.o
36
+ uint32_t size,
38
common-obj-$(CONFIG_NETMAP) += netmap.o
37
+ uint32_t vnet_hdr_len);
39
@@ -XXX,XX +XXX,XX @@ common-obj-y += colo-compare.o
38
40
common-obj-y += colo.o
39
static gint seq_sorter(Packet *a, Packet *b, gpointer data)
41
common-obj-y += filter-rewriter.o
40
{
42
common-obj-y += filter-replay.o
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
+ }
43
+
78
+
44
+tap-obj-$(CONFIG_LINUX) = tap-linux.o
79
ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
45
+tap-obj-$(CONFIG_BSD) = tap-bsd.o
80
if (ret != size) {
46
+tap-obj-$(CONFIG_SOLARIS) = tap-solaris.o
81
goto err;
47
+tap-obj-y ?= tap-stub.o
82
@@ -XXX,XX +XXX,XX @@ static void compare_set_outdev(Object *obj, const char *value, Error **errp)
48
+common-obj-$(CONFIG_POSIX) += tap.o $(tap-obj-y)
83
s->outdev = g_strdup(value);
49
+common-obj-$(CONFIG_WIN32) += tap-win32.o
84
}
50
diff --git a/net/tap-aix.c b/net/tap-aix.c
85
51
deleted file mode 100644
86
+static bool compare_get_vnet_hdr(Object *obj, Error **errp)
52
index XXXXXXX..XXXXXXX
87
+{
53
--- a/net/tap-aix.c
88
+ CompareState *s = COLO_COMPARE(obj);
54
+++ /dev/null
55
@@ -XXX,XX +XXX,XX @@
56
-/*
57
- * QEMU System Emulator
58
- *
59
- * Copyright (c) 2003-2008 Fabrice Bellard
60
- *
61
- * Permission is hereby granted, free of charge, to any person obtaining a copy
62
- * of this software and associated documentation files (the "Software"), to deal
63
- * in the Software without restriction, including without limitation the rights
64
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
65
- * copies of the Software, and to permit persons to whom the Software is
66
- * furnished to do so, subject to the following conditions:
67
- *
68
- * The above copyright notice and this permission notice shall be included in
69
- * all copies or substantial portions of the Software.
70
- *
71
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
72
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
73
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
74
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
76
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
77
- * THE SOFTWARE.
78
- */
79
-
80
-#include "qemu/osdep.h"
81
-#include "qapi/error.h"
82
-#include "tap_int.h"
83
-
84
-int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
85
- int vnet_hdr_required, int mq_required, Error **errp)
86
-{
87
- error_setg(errp, "no tap on AIX");
88
- return -1;
89
-}
90
-
91
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
92
-{
93
-}
94
-
95
-int tap_probe_vnet_hdr(int fd)
96
-{
97
- return 0;
98
-}
99
-
100
-int tap_probe_has_ufo(int fd)
101
-{
102
- return 0;
103
-}
104
-
105
-int tap_probe_vnet_hdr_len(int fd, int len)
106
-{
107
- return 0;
108
-}
109
-
110
-void tap_fd_set_vnet_hdr_len(int fd, int len)
111
-{
112
-}
113
-
114
-int tap_fd_set_vnet_le(int fd, int is_le)
115
-{
116
- return -EINVAL;
117
-}
118
-
119
-int tap_fd_set_vnet_be(int fd, int is_be)
120
-{
121
- return -EINVAL;
122
-}
123
-
124
-void tap_fd_set_offload(int fd, int csum, int tso4,
125
- int tso6, int ecn, int ufo)
126
-{
127
-}
128
-
129
-int tap_fd_enable(int fd)
130
-{
131
- return -1;
132
-}
133
-
134
-int tap_fd_disable(int fd)
135
-{
136
- return -1;
137
-}
138
-
139
-int tap_fd_get_ifname(int fd, char *ifname)
140
-{
141
- return -1;
142
-}
143
-
144
diff --git a/net/tap-haiku.c b/net/tap-haiku.c
145
deleted file mode 100644
146
index XXXXXXX..XXXXXXX
147
--- a/net/tap-haiku.c
148
+++ /dev/null
149
@@ -XXX,XX +XXX,XX @@
150
-/*
151
- * QEMU System Emulator
152
- *
153
- * Copyright (c) 2003-2008 Fabrice Bellard
154
- *
155
- * Permission is hereby granted, free of charge, to any person obtaining a copy
156
- * of this software and associated documentation files (the "Software"), to deal
157
- * in the Software without restriction, including without limitation the rights
158
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
159
- * copies of the Software, and to permit persons to whom the Software is
160
- * furnished to do so, subject to the following conditions:
161
- *
162
- * The above copyright notice and this permission notice shall be included in
163
- * all copies or substantial portions of the Software.
164
- *
165
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
166
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
167
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
168
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
169
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
170
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
171
- * THE SOFTWARE.
172
- */
173
-
174
-#include "qemu/osdep.h"
175
-#include "qapi/error.h"
176
-#include "tap_int.h"
177
-
178
-int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
179
- int vnet_hdr_required, int mq_required, Error **errp)
180
-{
181
- error_setg(errp, "no tap on Haiku");
182
- return -1;
183
-}
184
-
185
-void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
186
-{
187
-}
188
-
189
-int tap_probe_vnet_hdr(int fd)
190
-{
191
- return 0;
192
-}
193
-
194
-int tap_probe_has_ufo(int fd)
195
-{
196
- return 0;
197
-}
198
-
199
-int tap_probe_vnet_hdr_len(int fd, int len)
200
-{
201
- return 0;
202
-}
203
-
204
-void tap_fd_set_vnet_hdr_len(int fd, int len)
205
-{
206
-}
207
-
208
-int tap_fd_set_vnet_le(int fd, int is_le)
209
-{
210
- return -EINVAL;
211
-}
212
-
213
-int tap_fd_set_vnet_be(int fd, int is_be)
214
-{
215
- return -EINVAL;
216
-}
217
-
218
-void tap_fd_set_offload(int fd, int csum, int tso4,
219
- int tso6, int ecn, int ufo)
220
-{
221
-}
222
-
223
-int tap_fd_enable(int fd)
224
-{
225
- return -1;
226
-}
227
-
228
-int tap_fd_disable(int fd)
229
-{
230
- return -1;
231
-}
232
-
233
-int tap_fd_get_ifname(int fd, char *ifname)
234
-{
235
- return -1;
236
-}
237
diff --git a/net/tap-stub.c b/net/tap-stub.c
238
new file mode 100644
239
index XXXXXXX..XXXXXXX
240
--- /dev/null
241
+++ b/net/tap-stub.c
242
@@ -XXX,XX +XXX,XX @@
243
+/*
244
+ * QEMU System Emulator
245
+ *
246
+ * Copyright (c) 2003-2008 Fabrice Bellard
247
+ *
248
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
249
+ * of this software and associated documentation files (the "Software"), to deal
250
+ * in the Software without restriction, including without limitation the rights
251
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
252
+ * copies of the Software, and to permit persons to whom the Software is
253
+ * furnished to do so, subject to the following conditions:
254
+ *
255
+ * The above copyright notice and this permission notice shall be included in
256
+ * all copies or substantial portions of the Software.
257
+ *
258
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
259
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
260
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
261
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
262
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
263
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
264
+ * THE SOFTWARE.
265
+ */
266
+
89
+
267
+#include "qemu/osdep.h"
90
+ return s->vnet_hdr;
268
+#include "qapi/error.h"
269
+#include "tap_int.h"
270
+
271
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
272
+ int vnet_hdr_required, int mq_required, Error **errp)
273
+{
274
+ error_setg(errp, "tap is not supported in this build");
275
+ return -1;
276
+}
91
+}
277
+
92
+
278
+void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp)
93
+static void compare_set_vnet_hdr(Object *obj,
94
+ bool value,
95
+ Error **errp)
279
+{
96
+{
97
+ CompareState *s = COLO_COMPARE(obj);
98
+
99
+ s->vnet_hdr = value;
280
+}
100
+}
281
+
101
+
282
+int tap_probe_vnet_hdr(int fd)
102
static void compare_pri_rs_finalize(SocketReadState *pri_rs)
283
+{
103
{
284
+ return 0;
104
CompareState *s = container_of(pri_rs, CompareState, pri_rs);
285
+}
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);
286
+
144
+
287
+int tap_probe_has_ufo(int fd)
145
object_property_add_str(obj, "primary_in",
288
+{
146
compare_get_pri_indev, compare_set_pri_indev,
289
+ return 0;
147
NULL);
290
+}
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);
291
+
152
+
292
+int tap_probe_vnet_hdr_len(int fd, int len)
153
+ s->vnet_hdr = false;
293
+{
154
+ object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
294
+ return 0;
155
+ compare_set_vnet_hdr, NULL);
295
+}
156
}
296
+
157
297
+void tap_fd_set_vnet_hdr_len(int fd, int len)
158
static void colo_compare_finalize(Object *obj)
298
+{
159
diff --git a/qemu-options.hx b/qemu-options.hx
299
+}
160
index XXXXXXX..XXXXXXX 100644
300
+
161
--- a/qemu-options.hx
301
+int tap_fd_set_vnet_le(int fd, int is_le)
162
+++ b/qemu-options.hx
302
+{
163
@@ -XXX,XX +XXX,XX @@ Dump the network traffic on netdev @var{dev} to the file specified by
303
+ return -EINVAL;
164
The file format is libpcap, so it can be analyzed with tools such as tcpdump
304
+}
165
or Wireshark.
305
+
166
306
+int tap_fd_set_vnet_be(int fd, int is_be)
167
-@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},
307
+{
168
-outdev=@var{chardevid}
308
+ return -EINVAL;
169
+@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},outdev=@var{chardevid}[,vnet_hdr_support]
309
+}
170
310
+
171
Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with
311
+void tap_fd_set_offload(int fd, int csum, int tso4,
172
secondary packet. If the packets are same, we will output primary
312
+ int tso6, int ecn, int ufo)
173
packet to outdev@var{chardevid}, else we will notify colo-frame
313
+{
174
do checkpoint and send primary packet to outdev@var{chardevid}.
314
+}
175
+if it has the vnet_hdr_support flag, colo compare will send/recv packet with vnet_hdr_len.
315
+
176
316
+int tap_fd_enable(int fd)
177
we must use it with the help of filter-mirror and filter-redirector.
317
+{
178
318
+ return -1;
319
+}
320
+
321
+int tap_fd_disable(int fd)
322
+{
323
+ return -1;
324
+}
325
+
326
+int tap_fd_get_ifname(int fd, char *ifname)
327
+{
328
+ return -1;
329
+}
330
--
179
--
331
2.7.4
180
2.7.4
332
181
333
182
diff view generated by jsdifflib
New patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
2
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
New patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
2
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
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
2
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.
2
10
3
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
11
Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
4
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
Signed-off-by: Jason Wang <jasowang@redhat.com>
5
---
13
---
6
qemu-options.hx | 2 +-
14
net/filter-rewriter.c | 37 ++++++++++++++++++++++++++++++++++++-
7
1 file changed, 1 insertion(+), 1 deletion(-)
15
qemu-options.hx | 4 ++--
16
2 files changed, 38 insertions(+), 3 deletions(-)
8
17
18
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/net/filter-rewriter.c
21
+++ b/net/filter-rewriter.c
22
@@ -XXX,XX +XXX,XX @@
23
#include "qemu-common.h"
24
#include "qapi/error.h"
25
#include "qapi/qmp/qerror.h"
26
+#include "qemu/error-report.h"
27
#include "qapi-visit.h"
28
#include "qom/object.h"
29
#include "qemu/main-loop.h"
30
@@ -XXX,XX +XXX,XX @@ typedef struct RewriterState {
31
NetQueue *incoming_queue;
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
}
59
60
+static bool filter_rewriter_get_vnet_hdr(Object *obj, Error **errp)
61
+{
62
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
63
+
64
+ return s->vnet_hdr;
65
+}
66
+
67
+static void filter_rewriter_set_vnet_hdr(Object *obj,
68
+ bool value,
69
+ Error **errp)
70
+{
71
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
72
+
73
+ s->vnet_hdr = value;
74
+}
75
+
76
+static void filter_rewriter_init(Object *obj)
77
+{
78
+ RewriterState *s = FILTER_COLO_REWRITER(obj);
79
+
80
+ s->vnet_hdr = false;
81
+ object_property_add_bool(obj, "vnet_hdr_support",
82
+ filter_rewriter_get_vnet_hdr,
83
+ filter_rewriter_set_vnet_hdr, NULL);
84
+}
85
+
86
static void colo_rewriter_class_init(ObjectClass *oc, void *data)
87
{
88
NetFilterClass *nfc = NETFILTER_CLASS(oc);
89
@@ -XXX,XX +XXX,XX @@ static const TypeInfo colo_rewriter_info = {
90
.name = TYPE_FILTER_REWRITER,
91
.parent = TYPE_NETFILTER,
92
.class_init = colo_rewriter_class_init,
93
+ .instance_init = filter_rewriter_init,
94
.instance_size = sizeof(RewriterState),
95
};
96
9
diff --git a/qemu-options.hx b/qemu-options.hx
97
diff --git a/qemu-options.hx b/qemu-options.hx
10
index XXXXXXX..XXXXXXX 100644
98
index XXXXXXX..XXXXXXX 100644
11
--- a/qemu-options.hx
99
--- a/qemu-options.hx
12
+++ b/qemu-options.hx
100
+++ b/qemu-options.hx
13
@@ -XXX,XX +XXX,XX @@ Create a filter-redirector we need to differ outdev id from indev id, id can not
101
@@ -XXX,XX +XXX,XX @@ Create a filter-redirector we need to differ outdev id from indev id, id can not
14
be the same. we can just use indev or outdev, but at least one of indev or outdev
102
be the same. we can just use indev or outdev, but at least one of indev or outdev
15
need to be specified.
103
need to be specified.
16
104
17
-@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},rewriter-mode=@var{mode}[,queue=@var{all|rx|tx}]
105
-@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid}[,queue=@var{all|rx|tx}]
18
+@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid}[,queue=@var{all|rx|tx}]
106
+@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},queue=@var{all|rx|tx},[vnet_hdr_support]
19
107
20
Filter-rewriter is a part of COLO project.It will rewrite tcp packet to
108
Filter-rewriter is a part of COLO project.It will rewrite tcp packet to
21
secondary from primary to keep secondary tcp connection,and rewrite
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:
22
--
116
--
23
2.7.4
117
2.7.4
24
118
25
119
diff view generated by jsdifflib
New patch
1
From: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
1
2
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
1
From: Yunjian Wang <wangyunjian@huawei.com>
1
From: Michal Privoznik <mprivozn@redhat.com>
2
2
3
The tx_bh or tx_timer will free in virtio_net_del_queue() function, when
3
We have a function that checks if given number is power of two.
4
removing virtio-net queues if the guest doesn't support multiqueue. But
4
We should prefer it instead of expanding the check on our own.
5
it might be still referenced by virtio_net_set_status(), which needs to
6
be set NULL. And also the tx_waiting needs to be set zero to prevent
7
virtio_net_set_status() accessing tx_bh or tx_timer.
8
5
9
Cc: qemu-stable@nongnu.org
6
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
8
---
13
hw/net/virtio-net.c | 3 +++
9
hw/net/virtio-net.c | 2 +-
14
1 file changed, 3 insertions(+)
10
1 file changed, 1 insertion(+), 1 deletion(-)
15
11
16
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
12
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
17
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/net/virtio-net.c
14
--- a/hw/net/virtio-net.c
19
+++ b/hw/net/virtio-net.c
15
+++ b/hw/net/virtio-net.c
20
@@ -XXX,XX +XXX,XX @@ static void virtio_net_del_queue(VirtIONet *n, int index)
16
@@ -XXX,XX +XXX,XX @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
21
if (q->tx_timer) {
17
*/
22
timer_del(q->tx_timer);
18
if (n->net_conf.rx_queue_size < VIRTIO_NET_RX_QUEUE_MIN_SIZE ||
23
timer_free(q->tx_timer);
19
n->net_conf.rx_queue_size > VIRTQUEUE_MAX_SIZE ||
24
+ q->tx_timer = NULL;
20
- (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size - 1))) {
25
} else {
21
+ !is_power_of_2(n->net_conf.rx_queue_size)) {
26
qemu_bh_delete(q->tx_bh);
22
error_setg(errp, "Invalid rx_queue_size (= %" PRIu16 "), "
27
+ q->tx_bh = NULL;
23
"must be a power of 2 between %d and %d.",
28
}
24
n->net_conf.rx_queue_size, VIRTIO_NET_RX_QUEUE_MIN_SIZE,
29
+ q->tx_waiting = 0;
30
virtio_del_queue(vdev, index * 2 + 1);
31
}
32
33
--
25
--
34
2.7.4
26
2.7.4
35
27
36
28
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
Spec said offloads should be le64, so use virtio_ldq_p() to guarantee
2
valid endian.
2
3
3
Network dumping should be done with "-object filter-dump" nowadays.
4
Fixes: 644c98587d4c ("virtio-net: dynamic network offloads configuration")
4
Using "-net dump" via the VLAN mechanism is considered as deprecated
5
Cc: qemu-stable@nongnu.org
5
and might be removed in a future release. So warn the users now
6
Cc: Dmitry Fleytman <dfleytma@redhat.com>
6
to inform them to user the filter-dump method instead.
7
8
Signed-off-by: Thomas Huth <thuth@redhat.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
7
Signed-off-by: Jason Wang <jasowang@redhat.com>
10
---
8
---
11
net/dump.c | 3 +++
9
hw/net/virtio-net.c | 2 ++
12
1 file changed, 3 insertions(+)
10
1 file changed, 2 insertions(+)
13
11
14
diff --git a/net/dump.c b/net/dump.c
12
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
15
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
16
--- a/net/dump.c
14
--- a/hw/net/virtio-net.c
17
+++ b/net/dump.c
15
+++ b/hw/net/virtio-net.c
18
@@ -XXX,XX +XXX,XX @@ int net_init_dump(const Netdev *netdev, const char *name,
16
@@ -XXX,XX +XXX,XX @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t cmd,
19
17
if (cmd == VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET) {
20
assert(peer);
18
uint64_t supported_offloads;
21
19
22
+ error_report("'-net dump' is deprecated. "
20
+ offloads = virtio_ldq_p(vdev, &offloads);
23
+ "Please use '-object filter-dump' instead.");
24
+
21
+
25
if (dump->has_file) {
22
if (!n->has_vnet_hdr) {
26
file = dump->file;
23
return VIRTIO_NET_ERR;
27
} else {
24
}
28
--
25
--
29
2.7.4
26
2.7.4
30
27
31
28
diff view generated by jsdifflib