|
From: | Zhang Chen |
Subject: | Re: [Qemu-devel] [PATCH V3 04/10] net/filter-mirror.c: Add filter-mirror and filter-redirector vnet support. |
Date: | Wed, 3 May 2017 10:18:20 +0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
On 05/02/2017 12:47 PM, Jason Wang wrote:
On 2017年04月28日 17:47, Zhang Chen wrote:In this patch, we change the send packet format fromstruct {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); + }Any reason to query peer here?
That's depend on using NetClientState, If we using nf->netdev that need to query, Otherwise we query nf->netdev->peer, then we can get the real vnet_hdr_len in my test.
Thanks Zhang Chen
+ + 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));}Do we need to strip vnet_hdr_len in redirector_to_filter() ? Thanks .
-- Thanks Zhang Chen
[Prev in Thread] | Current Thread | [Next in Thread] |