[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH V3 04/10] net/filter-mirror.c: Add filter-mirror and
From: |
Zhang Chen |
Subject: |
[Qemu-devel] [PATCH V3 04/10] net/filter-mirror.c: Add filter-mirror and filter-redirector vnet support. |
Date: |
Fri, 28 Apr 2017 17:47:14 +0800 |
In this patch, we change the send packet format from
struct {int size; const uint8_t buf[];} to {int size; int vnet_hdr_len; const
uint8_t buf[];}.
make other module(like colo-compare) know how to parse net packet correctly.
Signed-off-by: Zhang Chen <address@hidden>
---
net/filter-mirror.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
index 72fa7c2..bb9ecf3 100644
--- a/net/filter-mirror.c
+++ b/net/filter-mirror.c
@@ -43,12 +43,14 @@ typedef struct MirrorState {
SocketReadState rs;
} MirrorState;
-static int filter_mirror_send(CharBackend *chr_out,
+static int filter_mirror_send(MirrorState *s,
const struct iovec *iov,
int iovcnt)
{
+ NetFilterState *nf = NETFILTER(s);
int ret = 0;
ssize_t size = 0;
+ ssize_t vnet_hdr_len;
uint32_t len = 0;
char *buf;
@@ -58,14 +60,30 @@ static int filter_mirror_send(CharBackend *chr_out,
}
len = htonl(size);
- ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)&len, sizeof(len));
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
+ if (ret != sizeof(len)) {
+ goto err;
+ }
+
+ /*
+ * We send vnet header len make other module(like colo-compare)
+ * know how to parse net packet correctly.
+ */
+ if (qemu_get_using_vnet_hdr(nf->netdev)) {
+ vnet_hdr_len = qemu_get_vnet_hdr_len(nf->netdev);
+ } else {
+ vnet_hdr_len = qemu_get_vnet_hdr_len(nf->netdev->peer);
+ }
+
+ len = htonl(vnet_hdr_len);
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len, sizeof(len));
if (ret != sizeof(len)) {
goto err;
}
buf = g_malloc(size);
iov_to_buf(iov, iovcnt, 0, buf, size);
- ret = qemu_chr_fe_write_all(chr_out, (uint8_t *)buf, size);
+ ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)buf, size);
g_free(buf);
if (ret != size) {
goto err;
@@ -141,7 +159,7 @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
MirrorState *s = FILTER_MIRROR(nf);
int ret;
- ret = filter_mirror_send(&s->chr_out, iov, iovcnt);
+ ret = filter_mirror_send(s, iov, iovcnt);
if (ret) {
error_report("filter_mirror_send failed(%s)", strerror(-ret));
}
@@ -164,7 +182,7 @@ static ssize_t filter_redirector_receive_iov(NetFilterState
*nf,
int ret;
if (qemu_chr_fe_get_driver(&s->chr_out)) {
- ret = filter_mirror_send(&s->chr_out, iov, iovcnt);
+ ret = filter_mirror_send(s, iov, iovcnt);
if (ret) {
error_report("filter_mirror_send failed(%s)", strerror(-ret));
}
--
2.7.4
- [Qemu-devel] [PATCH V3 00/10] Add COLO-proxy virtio-net support, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 02/10] net/tap.c: Add tap_get_vnet_hdr_len and tap_get_using_vnet_hdr function, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 01/10] net: Add vnet_hdr_len related callback in NetClientInfo, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 10/10] net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 07/10] tests/virtio-net-test.c : change virtio-net test case iov send data format, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 04/10] net/filter-mirror.c: Add filter-mirror and filter-redirector vnet support.,
Zhang Chen <=
- [Qemu-devel] [PATCH V3 08/10] net/colo-compare.c: Make colo-compare support vnet_hdr_len, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 05/10] net/net.c: Add vnet header length to SocketReadState, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 06/10] tests/e1000e-test.c : change e1000e test case send data format, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 09/10] net/colo.c: Add vnet packet parse feature in colo-proxy, Zhang Chen, 2017/04/28
- [Qemu-devel] [PATCH V3 03/10] net/netmap.c: Add netmap_get_vnet_hdr_len function, Zhang Chen, 2017/04/28