Add COLO-proxy virtio-net support
v6 cover Add COLO-proxy virtio-net support
If user use -device virtio-net-pci, virtio-net driver will add a header to raw net packet that colo-proxy can't handle it. COLO-proxy just focus on the packet payload, so we skip the virtio-net header to compare the sent packet that primary guest's to secondary guest's.
V6:
- p1: Remove the using_vnet_hdr, I will send a independent patchset about it.
- p2: Change option input way from vnet_hdr=on/off to vnet_hdr_support.
Use nf->direction to decide check nf->netdev->vnet_hdr_len or nf->netdev->peer->vnet_hdr_len.
- p3: Change option input way from vnet_hdr=on/off to vnet_hdr_support.
- p4: No change.
- p5: No change.
- p6: Change option input way from vnet_hdr=on/off to vnet_hdr_support.
Fix commit log.
- p7: No change.
- p8: No change.
- p9: Change option input way from vnet_hdr=on/off to vnet_hdr_support.
Use nf->direction to decide check nf->netdev->vnet_hdr_len or nf->netdev->peer->vnet_hdr_len.- p10: New patch to add new example for the case needs vnet hdr.
V5:
- patch1: No change.
- patch2: Keep the long line in qemu-option.hx.
Squash patch2 into old patch3.
Add more comments.
Fix the return value.
- patch3: Add more comments in commit log.
- patch4: Add Suggested-by tag.
Fix commit log.
Move vnet_hdr to SocketReadState.
- patch5: No change.
- patch6: Squash old patch6 into this patch.
- patch7: No change.
- patch8: Remove the offset_all.
- patch9: Squash old patch11 and the patch12.
V4:
- Add vnet_hdr option for filter-mirror, filter-redirector, filter-rewriter,colo-compare.
- Use new design to impliment virtio-net support for colo-proxy.
- Fix codestyle.
- Remove unused option for filter-rewriter.
- Add filter-rewriter virtio-net support.
- Address other comments.
Zhang Chen (10):
net: Add vnet_hdr_len arguments in NetClientState net/filter-mirror.c: Make filter mirror support vnet support. net/filter-mirror.c: Add new option to enable vnet support for
filter-redirector
net/net.c: Add vnet_hdr support in SocketReadState net/colo.c: Make vnet_hdr_len as packet property net/colo-compare.c: Make colo-compare support vnet_hdr_len net/colo.c: Add vnet packet parse feature in colo-proxy net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len docs/colo-proxy.txt: Update colo-proxy usage of net driver with
vnet_header
docs/colo-proxy.txt | 26 ++++++++++++++ include/net/net.h | 7 +++- net/colo-compare.c | 86 +++++++++++++++++++++++++++++++++++++------- net/colo.c | 9 ++--- net/colo.h | 4 ++- net/filter-mirror.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++--- net/filter-rewriter.c | 51 ++++++++++++++++++++++++++- net/net.c | 34 ++++++++++++++++-- qemu-options.hx | 19 +++++----- 9 files changed, 296 insertions(+), 38 deletions(-)
Signature · 1 line
2.7.4
PATCH v6 1/10 net: Add vnet_hdr_len arguments in NetClientState
Add vnet_hdr_len arguments in NetClientState that make other module get real vnet_hdr_len easily.
--- include/net/net.h | 1 + net/net.c | 1 + 2 files changed, 2 insertions(+)
include/net/net.h +1 -0
@@ -100,6 +100,7 @@ struct NetClientState {unsigned int queue_index; unsigned rxfilter_notify_enabled:1;int vring_enable; +int vnet_hdr_len; QTAILQ_HEAD(NetFilterHead, NetFilterState) filters; };
net/net.c +1 -0
@@ -491,6 +491,7 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len)return ; } + nc->vnet_hdr_len = len; nc->info->set_vnet_hdr_len (nc, len); }
Signature · 1 line
2.7.4
PATCH v6 2/10 net/filter-mirror.c: Make filter mirror support vnet support.
In reply to Zhang ChenWe add the vnet_hdr_support option for filter-mirror, default is disable. If you use virtio-net-pci net driver, please enable it.
You can use it for example:
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support
If have vnet_hdr_support flag, we will 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.
--- net/filter-mirror.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---- qemu-options.hx | 5 ++-- 2 files changed, 66 insertions(+), 8 deletions(-)
net/filter-mirror.c +64 -5
@@ -38,15 +38,17 @@ typedef struct MirrorState {NetFilterState parent_obj;char *indev;char *outdev; +bool vnet_hdr;CharBackend chr_in;CharBackend chr_out;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 ;uint32_t len =0 ;
@@ -58,14 +60,43 @@ 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; } +if (s->vnet_hdr) { +/* +* If vnet_hdr = on, we send vnet header len to make other +* module(like colo-compare) know how to parse net +* packet correctly. +*/ +ssize_t vnet_hdr_len; + +/* +* In anytime, nf->netdev and nf->netdev->peer both have a vnet_hdr_len, +* Here we just find out which is we need. When filter set RX or TX +* that the real vnet_hdr_len are different. +*/ +if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len; + }else if (nf->direction ==NET_FILTER_DIRECTION_TX ) { + vnet_hdr_len = nf->netdev->peer->vnet_hdr_len; + }else { +return 0 ; + } + + 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 +172,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 +195,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)); }
@@ -308,6 +339,13 @@ static char *filter_mirror_get_outdev(Object *obj, Error **errp)return g_strdup (s->outdev); } +static bool filter_mirror_get_vnet_hdr (Object *obj,Error **errp) +{ +MirrorState *s =FILTER_MIRROR (obj); + +return s->vnet_hdr; +} +static void filter_mirror_set_outdev (Object *obj,const char *value,Error **errp) {
@@ -322,6 +360,15 @@ filter_mirror_set_outdev(Object *obj, const char *value, Error **errp) } } +static void filter_mirror_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +MirrorState *s =FILTER_MIRROR (obj); + + s->vnet_hdr = value; +} +static char *filter_redirector_get_outdev (Object *obj,Error **errp) {MirrorState *s =FILTER_REDIRECTOR (obj);
@@ -340,8 +387,20 @@ filter_redirector_set_outdev(Object *obj, const char *value, Error **errp)static void filter_mirror_init (Object *obj) { +MirrorState *s =FILTER_MIRROR (obj); +object_property_add_str (obj,"outdev" , filter_mirror_get_outdev, filter_mirror_set_outdev,NULL ); + +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/ + s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_mirror_get_vnet_hdr, + filter_mirror_set_vnet_hdr,NULL ); }static void filter_redirector_init (Object *obj)
qemu-options.hx +2 -3
@@ -4024,10 +4024,9 @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. @option{tx}: the filter is attached to the transmit queue of the netdev, where it will receive packets sent by the netdev. -@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}] +@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] -filter-mirror on netdev @var{netdevid},mirror net packet to chardev -@var{chardevid} +filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if have the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. @item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid}, outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 1 line · Zhang Chen
We add the
vnet_hdr_supportoption for filter-mirror, default is disable.
s/disable/disabled/
Quoted 5 lines
If you use virtio-net-pci net driver, please enable it.
You can use it for example:
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_supportIf have
vnet_hdr_supportflag,
If it has
Quoted 1 line
we will change the send packet format from
s/send/sending/
Quoted 2 lines
struct {int size; const
uint8_tbuf[];} to {int size; intvnet_hdr_len; constuint8_tbuf[];}. make other module(like colo-compare) know how to parse net packet correctly.
Please double check the commit logs, some have obvious grammar issues.
Quoted 15 lines
Signed-off-by Zhang Chen <[email protected]>--- net/filter-mirror.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---- qemu-options.hx | 5 ++-- 2 files changed, 66 insertions(+), 8 deletions(-)net/filter-mirror.c +0
-0@@ -38,15 +38,17 @@ typedef struct MirrorState {NetFilterState parent_obj;char *indev;char *outdev;
net/filter-mirror.c typedef struct MirrorState { · line 49
Quoted 10 lines
net/filter-mirror.c +2
-1+bool vnet_hdr;CharBackend chr_in;CharBackend chr_out;SocketReadState rs; } MirrorState; -static int filter_mirror_send (CharBackend *chr_out, +static int filter_mirror_send (MirrorState *s,const struct iovec *iov,int iovcnt)
This function were renamed to filter_send in your commit e05dc4cf56d70225fc76225a3fd7df9f7b8ca5f9 ("net/filter-mirror.c: Rename filter_mirror_send() and fix codestyle")
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 63
Quoted 11 lines
net/filter-mirror.c +2
-1{ +NetFilterState *nf =NETFILTER (s);int ret =0 ;ssize_t size =0 ;uint32_t len =0 ;@@ -58,14 +60,43 @@ 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));
This looks a independent change, please do it in another patch.
Quoted 7 lines
net/filter-mirror.c +3
-0if (ret !=sizeof (len)) { goto err; } +if (s->vnet_hdr) { +/* +* If vnet_hdr = on, we send vnet header len to make other
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 80
Quoted 10 lines
net/filter-mirror.c +10
-0+* module(like colo-compare) know how to parse net +* packet correctly. +*/ +ssize_t vnet_hdr_len; + +/* +* In anytime, nf->netdev and nf->netdev->peer both have a vnet_hdr_len, +* Here we just find out which is we need. When filter set RX or TX +* that the real vnet_hdr_len are different. +*/
Let's remove the comment and let code explain itself.
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 83
Quoted 3 lines
net/filter-mirror.c +3
-0+if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;
This can only work if e.g virtio-net set its own vnet_hdr_len. But looks like it use guest_hdr_len instead.
And using NET_FILTER_DIRECTION_ALL looks suspicious. Maybe we should accept sender from its caller and compare it with nf->netdev to get the correct direction.
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 85
Quoted 2 lines
net/filter-mirror.c +2
-0+ }else if (nf->direction ==NET_FILTER_DIRECTION_TX ) { + vnet_hdr_len = nf->netdev->peer->vnet_hdr_len;
This looks wrong, TX means the packet were sent from netdev, we should care nf->netdev's hdrlen.
Quoted 70 lines
net/filter-mirror.c +30
-3+ }else { +return 0 ; + } + + 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 +172,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 +195,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)); }@@ -308,6 +339,13 @@ static char *filter_mirror_get_outdev(Object *obj, Error **errp)return g_strdup (s->outdev); } +static bool filter_mirror_get_vnet_hdr (Object *obj,Error **errp) +{ +MirrorState *s =FILTER_MIRROR (obj); + +return s->vnet_hdr; +} +static void filter_mirror_set_outdev (Object *obj,const char *value,Error **errp) {@@ -322,6 +360,15 @@ filter_mirror_set_outdev(Object *obj, const char *value, Error **errp) } } +static void filter_mirror_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +MirrorState *s =FILTER_MIRROR (obj); + + s->vnet_hdr = value; +} +static char *filter_redirector_get_outdev (Object *obj,Error **errp) {MirrorState *s =FILTER_REDIRECTOR (obj);@@ -340,8 +387,20 @@ filter_redirector_set_outdev(Object *obj, const char *value, Error **errp)static void filter_mirror_init (Object *obj) {
net/filter-mirror.c filter_redirector_set_outdev(Object *obj, const char *value, Error **errp) · line 399
Quoted 10 lines
net/filter-mirror.c +8
-0+MirrorState *s =FILTER_MIRROR (obj); +object_property_add_str (obj,"outdev" , filter_mirror_get_outdev, filter_mirror_set_outdev,NULL ); + +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/
This comment makes sense for docs but is useless here, let code explain itself.
Thanks
Quoted 24 lines
net/filter-mirror.c +4
-0+ s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_mirror_get_vnet_hdr, + filter_mirror_set_vnet_hdr,NULL ); }static void filter_redirector_init (Object *obj)qemu-options.hx +2
-3@@ -4024,10 +4024,9 @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. @option{tx}: the filter is attached to the transmit queue of the netdev, where it will receive packets sent by the netdev. -@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}] +@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] -filter-mirror on netdev @var{netdevid},mirror net packet to chardev -@var{chardevid} +filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if have the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. @item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid}, outdev=@var{chardevid}[,queue=@var{all|rx|tx}]
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 16 lines · Jason Wang
Quoted 1 line · Zhang Chen
We add the
vnet_hdr_supportoption for filter-mirror, default is disable.s/disable/disabled/
Quoted 6 lines
If you use virtio-net-pci net driver, please enable it.
You can use it for example:
-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_supportIf have
vnet_hdr_supportflag,If it has
Quoted 8 lines
Quoted 1 line
we will change the send packet format from
s/send/sending/
Quoted 2 lines
struct {int size; const
uint8_tbuf[];} to {int size; intvnet_hdr_len; constuint8_tbuf[];}. make other module(like colo-compare) know how to parse net packet correctly.Please double check the commit logs, some have obvious grammar issues.
OK, I will fix the garmmar issues.
Quoted 20 lines
Quoted 20 lines
Signed-off-by Zhang Chen <[email protected]>--- net/filter-mirror.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---- qemu-options.hx | 5 ++-- 2 files changed, 66 insertions(+), 8 deletions(-)net/filter-mirror.c +1
-0@@ -38,15 +38,17 @@ typedef struct MirrorState {NetFilterState parent_obj;char *indev;char *outdev; +bool vnet_hdr;CharBackend chr_in;CharBackend chr_out;
Quoted 8 lines
net/filter-mirror.c typedef struct MirrorState { · line 49
Quoted 6 lines
net/filter-mirror.c +1
-0SocketReadState rs; } MirrorState; -static int filter_mirror_send(CharBackend *chr_out, +static int filter_mirror_send (MirrorState *s,const struct iovec *iov, int iovcnt)This function were renamed to
filter_sendin your commite05dc4cf56d70225fc76225a3fd7df9f7b8ca5f9("net/filter-mirror.c: Renamefilter_mirror_send()and fix codestyle")
I will rebase the code for upstream.
Quoted 14 lines
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 63
Quoted 12 lines
net/filter-mirror.c +2
-1{ +NetFilterState *nf =NETFILTER (s);int ret =0 ;ssize_t size =0 ;uint32_t len =0 ;@@ -58,14 +60,43 @@ 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));This looks a independent change, please do it in another patch.
OK.
Quoted 20 lines
Quoted 17 lines
net/filter-mirror.c +10
-0if (ret !=sizeof (len)) { goto err; } + if (s->vnet_hdr) { +/* +* If vnet_hdr = on, we send vnet header len to make other +* module(like colo-compare) know how to parse net +* packet correctly. +*/ +ssize_t vnet_hdr_len; + +/* +* In anytime, nf->netdev and nf->netdev->peer both have a vnet_hdr_len, +* Here we just find out which is we need. When filter set RX or TX
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 80
Quoted 2 lines
net/filter-mirror.c +2
-0+* that the real vnet_hdr_len are different. +*/
Quoted 1 line
Let's remove the comment and let code explain itself.
I will remove it in next version.
Quoted 6 lines
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 83
Quoted 4 lines
net/filter-mirror.c +3
-0+if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.
I see in hw/net/virtio-net.c use the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set the nf->netdev->vnet_hdr_len, any case not include here?
Quoted 7 lines
And using
NET_FILTER_DIRECTION_ALLlooks suspicious. Maybe we should accept sender from its caller and compare it withnf->netdevto get the correct direction.net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 85
Quoted 2 lines
net/filter-mirror.c +2
-0+ }else if (nf->direction ==NET_FILTER_DIRECTION_TX ) { + vnet_hdr_len = nf->netdev->peer->vnet_hdr_len;This looks wrong, TX means the packet were sent from netdev, we should care nf->netdev's hdrlen.
I rethink and test the code, you are right. I will remove it.
Quoted 77 lines
Quoted 77 lines
net/filter-mirror.c +6
-0+ }else { +return 0 ; + } + + len =htonl (vnet_hdr_len); + ret = qemu_chr_fe_write_all(&s->chr_out, (uint8_t *)&len,sizeof(len));
net/filter-mirror.c +8
-2+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 +172,7 @@ static ssize_tfilter_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 +195,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));}net/filter-mirror.c +16
-0@@ -308,6 +339,13 @@ static char *filter_mirror_get_outdev(Object *obj, Error **errp)return g_strdup (s->outdev); } +static bool filter_mirror_get_vnet_hdr(Object *obj, Error **errp) +{ +MirrorState *s =FILTER_MIRROR (obj); + +return s->vnet_hdr; +} +static void filter_mirror_set_outdev (Object *obj,const char *value,Error **errp) {@@ -322,6 +360,15 @@ filter_mirror_set_outdev(Object *obj, const char *value, Error **errp) } } +static void filter_mirror_set_vnet_hdr(Object *obj, +bool value, +Error **errp) +{ +MirrorState *s =FILTER_MIRROR (obj); + + s->vnet_hdr = value; +} +static char *filter_redirector_get_outdev (Object *obj,Error **errp) {MirrorState *s =FILTER_REDIRECTOR (obj);@@ -340,8 +387,20 @@ filter_redirector_set_outdev(Object *obj, const char *value, Error **errp) static void filter_mirror_init(Object *obj) { + MirrorState *s = FILTER_MIRROR(obj); +object_property_add_str (obj,"outdev" , filter_mirror_get_outdev, filter_mirror_set_outdev,NULL );
Quoted 8 lines
net/filter-mirror.c filter_redirector_set_outdev(Object *obj, const char *value, Error **errp) · line 399
Quoted 6 lines
net/filter-mirror.c +6
-0+ +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/ This comment makes sense for docs but is useless here, let code explain itself.
OK.
Thanks
Zhang Chen
Quoted 34 lines
Thanks
Quoted 18 lines
net/filter-mirror.c +4
-0+ s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_mirror_get_vnet_hdr, + filter_mirror_set_vnet_hdr,NULL ); }static void filter_redirector_init (Object *obj)qemu-options.hx +0
-0@@ -4024,10 +4024,9 @@ queue @var{all|rx|tx} is an option that can beapplied to any netfilter.
@option{tx}: the filter is attached to the transmit queue of the
netdev,
where it will receive packets sent by the netdev.
-@item -object
filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid}[,queue=@var{all|rx|tx}] +@item -objectQuoted 8 lines
filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support]
-filter-mirror on netdev @var{netdevid},mirror net packet to chardev
-@var{chardevid}
+filter-mirror on netdev @var{netdevid},mirror net packet to
chardev@var{chardevid}, if have thevnet_hdr_supportflag, filter-mirror will mirror packet withvnet_hdr_len.
@item -object
filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},
outdev=@var{chardevid}[,queue=@var{all|rx|tx}].
Signature · 2 lines
Thanks Zhang Chen
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 9 lines · Zhang Chen
Quoted 6 lines
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 83
Quoted 4 lines
net/filter-mirror.c +3
-0+if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.I see in
hw/net/virtio-net.cuse the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set thenf->netdev->vnet_hdr_len, any case not include here?
You mean:
if (peer_has_vnet_hdr(n) &&
qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) {
qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);
n->host_hdr_len = n->guest_hdr_len;
}?
From the code, it only set peer's vnet header when peer supports vnet_hdr up to n->guest_hdr_len. If peer can't, virtio-net will strip the header.
Thanks
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 21 lines · Jason Wang
Quoted 9 lines · Zhang Chen
Quoted 6 lines
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 83
Quoted 4 lines
net/filter-mirror.c +3
-0+if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.I see in
hw/net/virtio-net.cuse the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set thenf->netdev->vnet_hdr_len, any case not include here?You mean:
if (peer_has_vnet_hdr(n) && qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) { qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len); n->host_hdr_len = n->guest_hdr_len; }
Quoted 3 lines
?
From the code, it only set peer's vnet header when peer supports
vnet_hdrup ton->guest_hdr_len. If peer can't, virtio-net will strip the header.
So, We should get the n->guest_hdr_len in another way? like set a new parameter in NetClientState? Any suggestion about it?
Thanks
Zhang Chen
Quoted 5 lines
Thanks
Signature · 2 lines
Thanks Zhang Chen
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 26 lines · Zhang Chen
Quoted 23 lines · Jason Wang
Quoted 9 lines · Zhang Chen
Quoted 6 lines
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 83
Quoted 4 lines
net/filter-mirror.c +3
-0+if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.I see in
hw/net/virtio-net.cuse the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set thenf->netdev->vnet_hdr_len, any case not include here?You mean:
if (peer_has_vnet_hdr(n) && qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) { qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len); n->host_hdr_len = n->guest_hdr_len; }?
Quoted 7 lines
Quoted 1 line
From the code, it only set peer's vnet header when peer supports
vnet_hdrup ton->guest_hdr_len. If peer can't, virtio-net will strip the header.So, We should get the
n->guest_hdr_lenin another way? like set a new parameter in NetClientState? Any suggestion about it?Thanks
Zhang Chen
Rethink about this, a question is do we really care guest vnet header len? During guest transmission, when packet reaches netfilter. The vnet_header should have been stripped to netdev->vnet_hdr_len.
I still think use nf->netdev->vnet_hdr_len is sufficient.
Thanks
Quoted 7 lines
Quoted 6 lines
Thanks
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 31 lines · Jason Wang
Quoted 28 lines · Zhang Chen
Quoted 24 lines · Jason Wang
Quoted 9 lines · Zhang Chen
Quoted 6 lines
net/filter-mirror.c static int filter_mirror_send(CharBackend *chr_out, · line 83
Quoted 4 lines
net/filter-mirror.c +3
-0+if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.I see in
hw/net/virtio-net.cuse the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set thenf->netdev->vnet_hdr_len, any case not include here?You mean:
if (peer_has_vnet_hdr(n) && qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) { qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len); n->host_hdr_len = n->guest_hdr_len; }?
From the code, it only set peer's vnet header when peer supports
vnet_hdrup ton->guest_hdr_len. If peer can't, virtio-net will strip the header.
Quoted 7 lines
Quoted 5 lines
So, We should get the
n->guest_hdr_lenin another way? like set a new parameter in NetClientState? Any suggestion about it?Thanks
Zhang ChenRethink about this, a question is do we really care guest vnet header len? During guest transmission, when packet reaches netfilter. The
vnet_headershould have been stripped tonetdev->vnet_hdr_len.
But we use filter-redirector send packet to colo-compare that get the packet with the vnet header.
That is colo-compare see:
[email protected]:colo_compare_pkt_info_src src/dst: 192.168.4.144 s: seq/ack=2181260317/2075177759 res=0 flags=18 spkt_size: 95
[email protected]:colo_compare_pkt_info_dst src/dst: 192.168.4.88 d: seq/ack=2181260317/2075177759 res=0 flags=18 dpkt_size: 95
colo-compare ppkt: 0000: 01 00 00 00 00 00 22 00 10 00 00 00 12 14 fc 1d ......"......... colo-compare ppkt: 0010: 1a 6b 52 54 00 12 34 56 08 00 45 00 00 45 12 61 .kRT..4V..E..E.a colo-compare ppkt: 0020: 40 00 40 06 9e 19 c0 a8 04 90 c0 a8 04 58 04 d2 @[email protected].. colo-compare ppkt: 0030: ca 98 82 03 64 1d 7b b0 b3 1f 80 18 00 e3 8a 70 ....d.{........p colo-compare ppkt: 0040: 00 00 01 01 08 0a 00 00 5b fa 00 4d f1 aa 73 65 ........[..M..se
colo-compare ppkt: 0050: 72 76 65 72 20 67 65 74 20 69 74 20 34 36 38 rver get it 468
colo-compare spkt: 0000: 01 00 00 00 00 00 22 00 10 00 00 00 12 14 fc 1d ......"......... colo-compare spkt: 0010: 1a 6b 52 54 00 12 34 56 08 00 45 00 00 45 12 61 .kRT..4V..E..E.a colo-compare spkt: 0020: 40 00 40 06 9e 19 c0 a8 04 90 c0 a8 04 58 04 d2 @[email protected].. colo-compare spkt: 0030: ca 98 82 03 64 1d 7b b0 b3 1f 80 18 00 e3 8a 70 ....d.{........p colo-compare spkt: 0040: 00 00 01 01 08 0a 00 00 5c 02 00 4d f1 aa 73 65 ........\..M..se
colo-compare spkt: 0050: 72 76 65 72 20 67 65 74 20 69 74 20 34 36 38 rver get it 468
So, colo-compare need to know the vnet_hdr_len for skip this field, then colo-compare can parse the net packet correctly.
Back to this patch, how should I fix it?
Thanks
Zhang Chen
Quoted 17 lines
I still think use
nf->netdev->vnet_hdr_lenis sufficient.Thanks
Quoted 7 lines
Quoted 6 lines
Thanks
.
Signature · 2 lines
Thanks Zhang Chen
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 63 lines · Zhang Chen
Quoted 31 lines · Jason Wang
Quoted 28 lines · Zhang Chen
Quoted 24 lines · Jason Wang
Quoted 9 lines · Zhang Chen
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ if (nf->direction == NET_FILTER_DIRECTION_RX || + nf->direction == NET_FILTER_DIRECTION_ALL) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.I see in
hw/net/virtio-net.cuse the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set thenf->netdev->vnet_hdr_len, any case not include here?You mean:
if (peer_has_vnet_hdr(n) && qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) { qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len); n->host_hdr_len = n->guest_hdr_len; }?
From the code, it only set peer's vnet header when peer supports
vnet_hdrup ton->guest_hdr_len. If peer can't, virtio-net will strip the header.Quoted 7 lines
Quoted 5 lines
So, We should get the
n->guest_hdr_lenin another way? like set a new parameter in NetClientState? Any suggestion about it?Thanks
Zhang ChenRethink about this, a question is do we really care guest vnet header len? During guest transmission, when packet reaches netfilter. The
vnet_headershould have been stripped tonetdev->vnet_hdr_len.But we use filter-redirector send packet to colo-compare that get the packet with the vnet header.
That is colo-compare see:
[email protected]:colo_compare_pkt_info_src src/dst: 192.168.4.144 s: seq/ack=2181260317/2075177759 res=0 flags=18
spkt_size: 95[email protected]:colo_compare_pkt_info_dst src/dst: 192.168.4.88 d: seq/ack=2181260317/2075177759 res=0 flags=18
dpkt_size: 95colo-compare ppkt: 0000: 01 00 00 00 00 00 22 00 10 00 00 00 12 14 fc 1d ......"......... colo-compare ppkt: 0010: 1a 6b 52 54 00 12 34 56 08 00 45 00 00 45 12 61 .kRT..4V..E..E.a colo-compare ppkt: 0020: 40 00 40 06 9e 19 c0 a8 04 90 c0 a8 04 58 04 d2 @[email protected].. colo-compare ppkt: 0030: ca 98 82 03 64 1d 7b b0 b3 1f 80 18 00 e3 8a 70 ....d.{........p colo-compare ppkt: 0040: 00 00 01 01 08 0a 00 00 5b fa 00 4d f1 aa 73 65 ........[..M..se
colo-compare ppkt: 0050: 72 76 65 72 20 67 65 74 20 69 74 20 34 36 38 rver get it 468
colo-compare spkt: 0000: 01 00 00 00 00 00 22 00 10 00 00 00 12 14 fc 1d ......"......... colo-compare spkt: 0010: 1a 6b 52 54 00 12 34 56 08 00 45 00 00 45 12 61 .kRT..4V..E..E.a colo-compare spkt: 0020: 40 00 40 06 9e 19 c0 a8 04 90 c0 a8 04 58 04 d2 @[email protected].. colo-compare spkt: 0030: ca 98 82 03 64 1d 7b b0 b3 1f 80 18 00 e3 8a 70 ....d.{........p colo-compare spkt: 0040: 00 00 01 01 08 0a 00 00 5c 02 00 4d f1 aa 73 65 ........\..M..se
colo-compare spkt: 0050: 72 76 65 72 20 67 65 74 20 69 74 20 34 36 38 rver get it 468
Quoted 3 lines
So, colo-compare need to know the
vnet_hdr_lenfor skip this field, then colo-compare can parse the net packet correctly.
Back to this patch, how should I fix it?
Let me explain a little bit more. What I mean is that we should care only about the vnet header len of netdev instead of guest.
On RX direction (guest transmission). If you look at virtio_net_flush_tx(), before calling qemu_sendv_packet_async() where the packet can reach netfilers, virtio-net will copy only the parts that host is interested. So what we can see in e.g filter-mirror is netdev's vnet_hdr_len which is not guaranteed to be equal to guest hdr len.
On TX direction, the packet will reach netfilter before it reaches virtio-net backend, so the vnet header is also netdev's vnet_hdr_len.
Does this explain?
Thanks
Quoted 23 lines
Thanks
Zhang ChenQuoted 17 lines
I still think use
nf->netdev->vnet_hdr_lenis sufficient.Thanks
Quoted 7 lines
Quoted 6 lines
Thanks
.
Re: [Qemu-devel] [PATCH V6 02/10] net/filter-mirror.c: Make filter mirror support vnet support.
Quoted 66 lines · Jason Wang
Quoted 63 lines · Zhang Chen
Quoted 31 lines · Jason Wang
Quoted 28 lines · Zhang Chen
Quoted 24 lines · Jason Wang
Quoted 9 lines · Zhang Chen
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ if (nf->direction == NET_FILTER_DIRECTION_RX || + nf->direction == NET_FILTER_DIRECTION_ALL) { + vnet_hdr_len = nf->netdev->vnet_hdr_len;This can only work if e.g virtio-net set its own
vnet_hdr_len. But looks like it useguest_hdr_leninstead.I see in
hw/net/virtio-net.cuse the "qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len);" to set thenf->netdev->vnet_hdr_len, any case not include here?You mean:
if (peer_has_vnet_hdr(n) && qemu_has_vnet_hdr_len(nc->peer, n->guest_hdr_len)) { qemu_set_vnet_hdr_len(nc->peer, n->guest_hdr_len); n->host_hdr_len = n->guest_hdr_len; }?
From the code, it only set peer's vnet header when peer supports
vnet_hdrup ton->guest_hdr_len. If peer can't, virtio-net will strip the header.Quoted 7 lines
Quoted 5 lines
So, We should get the
n->guest_hdr_lenin another way? like set a new parameter in NetClientState? Any suggestion about it?Thanks
Zhang ChenRethink about this, a question is do we really care guest vnet header len? During guest transmission, when packet reaches netfilter. The
vnet_headershould have been stripped tonetdev->vnet_hdr_len.But we use filter-redirector send packet to colo-compare that get the packet with the vnet header.
That is colo-compare see:
[email protected]:colo_compare_pkt_info_src src/dst: 192.168.4.144 s: seq/ack=2181260317/2075177759 res=0 flags=18
spkt_size: 95[email protected]:colo_compare_pkt_info_dst src/dst: 192.168.4.88 d: seq/ack=2181260317/2075177759 res=0 flags=18
dpkt_size: 95colo-compare ppkt: 0000: 01 00 00 00 00 00 22 00 10 00 00 00 12 14 fc 1d ......"......... colo-compare ppkt: 0010: 1a 6b 52 54 00 12 34 56 08 00 45 00 00 45 12 61 .kRT..4V..E..E.a colo-compare ppkt: 0020: 40 00 40 06 9e 19 c0 a8 04 90 c0 a8 04 58 04 d2 @[email protected].. colo-compare ppkt: 0030: ca 98 82 03 64 1d 7b b0 b3 1f 80 18 00 e3 8a 70 ....d.{........p colo-compare ppkt: 0040: 00 00 01 01 08 0a 00 00 5b fa 00 4d f1 aa 73 65 ........[..M..se
colo-compare ppkt: 0050: 72 76 65 72 20 67 65 74 20 69 74 20 34 36 38 rver get it 468
colo-compare spkt: 0000: 01 00 00 00 00 00 22 00 10 00 00 00 12 14 fc 1d ......"......... colo-compare spkt: 0010: 1a 6b 52 54 00 12 34 56 08 00 45 00 00 45 12 61 .kRT..4V..E..E.a colo-compare spkt: 0020: 40 00 40 06 9e 19 c0 a8 04 90 c0 a8 04 58 04 d2 @[email protected].. colo-compare spkt: 0030: ca 98 82 03 64 1d 7b b0 b3 1f 80 18 00 e3 8a 70 ....d.{........p colo-compare spkt: 0040: 00 00 01 01 08 0a 00 00 5c 02 00 4d f1 aa 73 65 ........\..M..se
colo-compare spkt: 0050: 72 76 65 72 20 67 65 74 20 69 74 20 34 36 38 rver get it 468
Quoted 8 lines
Quoted 3 lines
So, colo-compare need to know the
vnet_hdr_lenfor skip this field, then colo-compare can parse the net packet correctly.
Back to this patch, how should I fix it?Let me explain a little bit more. What I mean is that we should care only about the vnet header len of netdev instead of guest.
On RX direction (guest transmission). If you look at
virtio_net_flush_tx(), before callingqemu_sendv_packet_async()where the packet can reach netfilers, virtio-net will copy only the parts that host is interested. So what we can see in e.g filter-mirror is netdev'svnet_hdr_lenwhich is not guaranteed to be equal to guest hdr len.
If I understand correctly, should I copy the n->needs_vnet_hdr_swap flag to NetClientState ? Then, e.g filter-mirror can read the flag to decide the vnet_hdr_len value to send.
Quoted 3 lines
On TX direction, the packet will reach netfilter before it reaches virtio-net backend, so the vnet header is also netdev's
vnet_hdr_len.Does this explain?
Make sense.
Thanks
Zhang Chen
Quoted 32 lines
Thanks
Quoted 23 lines
Thanks
Zhang ChenQuoted 17 lines
I still think use
nf->netdev->vnet_hdr_lenis sufficient.Thanks
Quoted 7 lines
Quoted 6 lines
Thanks
.
.
Signature · 2 lines
Thanks Zhang Chen
PATCH v6 3/10 net/filter-mirror.c: Add new option to enable vnet support for filter-redirector
In reply to Zhang ChenWe add the vnet_hdr_support option for filter-redirector, default is disable. If you use virtio-net-pci net driver, please enable it.
Because colo-compare or other modules needs the vnet_hdr_len to parse packet, so we add this new option send the len to others.
You can use it for example:
-object filter-redirector,id=r0,netdev=hn0,queue=tx,outdev=red0,vnet_hdr_support
--- net/filter-mirror.c | 28 ++++++++++++++++++++++++++++ qemu-options.hx | 6 +++--- 2 files changed, 31 insertions(+), 3 deletions(-)
net/filter-mirror.c +28 -0
@@ -376,6 +376,13 @@ static char *filter_redirector_get_outdev(Object *obj, Error **errp)return g_strdup (s->outdev); } +static bool filter_redirector_get_vnet_hdr (Object *obj,Error **errp) +{ +MirrorState *s =FILTER_REDIRECTOR (obj); + +return s->vnet_hdr; +} +static void filter_redirector_set_outdev (Object *obj,const char *value,Error **errp) {
@@ -385,6 +392,15 @@ filter_redirector_set_outdev(Object *obj, const char *value, Error **errp) s->outdev =g_strdup (value); } +static void filter_redirector_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +MirrorState *s =FILTER_REDIRECTOR (obj); + + s->vnet_hdr = value; +} +static void filter_mirror_init (Object *obj) {MirrorState *s =FILTER_MIRROR (obj);
@@ -405,10 +421,22 @@ static void filter_mirror_init(Object *obj)static void filter_redirector_init (Object *obj) { +MirrorState *s =FILTER_REDIRECTOR (obj); +object_property_add_str (obj,"indev" , filter_redirector_get_indev, filter_redirector_set_indev,NULL );object_property_add_str (obj,"outdev" , filter_redirector_get_outdev, filter_redirector_set_outdev,NULL ); + +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/ + s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_redirector_get_vnet_hdr, + filter_redirector_set_vnet_hdr,NULL ); }static void filter_mirror_fini (Object *obj)
qemu-options.hx +3 -3
@@ -4028,11 +4028,11 @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if have the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. -@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid}, -outdev=@var{chardevid}[,queue=@var{all|rx|tx}] +@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] filter-redirector on netdev @var{netdevid},redirect filter's net packet to chardev -@var{chardevid},and redirect indev's packet to filter. +@var{chardevid},and redirect indev's packet to filter.if have the vnet_hdr_support flag, +filter-redirector will redirect packet with vnet_hdr_len. Create a filter-redirector we need to differ outdev id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or outdev need to be specified.
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH V6 03/10] net/filter-mirror.c: Add new option to enable vnet support for filter-redirector
Quoted 1 line · Zhang Chen
We add the
vnet_hdr_supportoption for filter-redirector, default is disable.
s/disable/disabled/
Quoted 3 lines
If you use virtio-net-pci net driver, please enable it. Because colo-compare or other modules needs the
vnet_hdr_lento parse packet, so we add this new option send the len to others.
s/so//
Quoted 49 lines
You can use it for example:
-object filter-redirector,id=r0,netdev=hn0,queue=tx,outdev=red0,vnet_hdr_supportSigned-off-by Zhang Chen <[email protected]>--- net/filter-mirror.c | 28 ++++++++++++++++++++++++++++ qemu-options.hx | 6 +++--- 2 files changed, 31 insertions(+), 3 deletions(-)net/filter-mirror.c +18
-0@@ -376,6 +376,13 @@ static char *filter_redirector_get_outdev(Object *obj, Error **errp)return g_strdup (s->outdev); } +static bool filter_redirector_get_vnet_hdr (Object *obj,Error **errp) +{ +MirrorState *s =FILTER_REDIRECTOR (obj); + +return s->vnet_hdr; +} +static void filter_redirector_set_outdev (Object *obj,const char *value,Error **errp) {@@ -385,6 +392,15 @@ filter_redirector_set_outdev(Object *obj, const char *value, Error **errp) s->outdev =g_strdup (value); } +static void filter_redirector_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +MirrorState *s =FILTER_REDIRECTOR (obj); + + s->vnet_hdr = value; +} +static void filter_mirror_init (Object *obj) {MirrorState *s =FILTER_MIRROR (obj);@@ -405,10 +421,22 @@ static void filter_mirror_init(Object *obj)static void filter_redirector_init (Object *obj) { +MirrorState *s =FILTER_REDIRECTOR (obj); +
net/filter-mirror.c static void filter_mirror_init(Object *obj) · line 435
Quoted 10 lines
net/filter-mirror.c +6
-0object_property_add_str (obj,"indev" , filter_redirector_get_indev, filter_redirector_set_indev,NULL );object_property_add_str (obj,"outdev" , filter_redirector_get_outdev, filter_redirector_set_outdev,NULL ); + +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/
Let's remove the comment here.
Quoted 26 lines
net/filter-mirror.c +4
-0+ s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_redirector_get_vnet_hdr, + filter_redirector_set_vnet_hdr,NULL ); }static void filter_mirror_fini (Object *obj)qemu-options.hx +3
-3@@ -4028,11 +4028,11 @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if have the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. -@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid}, -outdev=@var{chardevid}[,queue=@var{all|rx|tx}] +@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] filter-redirector on netdev @var{netdevid},redirect filter's net packet to chardev -@var{chardevid},and redirect indev's packet to filter. +@var{chardevid},and redirect indev's packet to filter.if have the vnet_hdr_support flag, +filter-redirector will redirect packet with vnet_hdr_len. Create a filter-redirector we need to differ outdev id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or outdev need to be specified.
PATCH v6 4/10 net/net.c: Add vnet_hdr support in SocketReadState
In reply to Zhang ChenWe add a flag to dicide whether net_fill_rstate() to read the vnet_hdr_len or not.
--- include/net/net.h | 6 +++++- net/filter-mirror.c | 1 + net/net.c | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-)
include/net/net.h +5 -1
@@ -112,9 +112,13 @@ typedef struct NICState { } NICState;struct SocketReadState { -int state;/* 0 = getting length, 1 = getting data */ +/* 0 = getting length, 1 = getting vnet header length, 2 = getting data */ +int state; +/* This flag decide whether to read the vnet_hdr_len field */ +bool vnet_hdr;uint32_t index;uint32_t packet_len; +uint32_t vnet_hdr_len;uint8_t buf[NET_BUFSIZE ];SocketReadStateFinalize *finalize; };
net/filter-mirror.c +1 -0
@@ -267,6 +267,7 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) }net_socket_rs_init (&s->rs, redirector_rs_finalize); + s->rs.vnet_hdr = s->vnet_hdr;if (s->indev) { chr =qemu_chr_find (s->indev);
net/net.c +30 -3
@@ -1606,8 +1606,10 @@ void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize) { rs->state =0 ; + rs->vnet_hdr = false; rs->index =0 ; rs->packet_len =0 ; + rs->vnet_hdr_len =0 ;memset (rs->buf,0 ,sizeof (rs->buf)); rs->finalize = finalize; }
@@ -1622,8 +1624,12 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)unsigned int l;while (size >0 ) { -/* reassemble a packet from the network */ -switch (rs->state) {/* 0 = getting length, 1 = getting data */ +/* Reassemble a packet from the network. +* 0 = getting length. +* 1 = getting vnet header length. +* 2 = getting data. +*/ +switch (rs->state) {case 0 : l =4 - rs->index;if (l > size) {
@@ -1637,10 +1643,31 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)/* got length */ rs->packet_len =ntohl (*(uint32_t *)rs->buf); rs->index =0 ; - rs->state =1 ; +if (rs->vnet_hdr) { + rs->state =1 ; + }else { + rs->state =2 ; + rs->vnet_hdr_len =0 ; + } }break ;case 1 : + l =4 - rs->index; +if (l > size) { + l = size; + } +memcpy (rs->buf + rs->index, buf, l); + buf += l; + size -= l; + rs->index += l; +if (rs->index ==4 ) { +/* got vnet header length */ + rs->vnet_hdr_len =ntohl (*(uint32_t *)rs->buf); + rs->index =0 ; + rs->state =2 ; + } +break ; +case 2 : l = rs->packet_len - rs->index;if (l > size) { l = size;
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH V6 04/10] net/net.c: Add vnet_hdr support in SocketReadState
Quoted 1 line · Zhang Chen
We add a flag to dicide whether
net_fill_rstate()to read
s/dicide/decide/ and s/to/needs/
Quoted 34 lines
the
vnet_hdr_lenor not.Signed-off-by Zhang Chen <[email protected]>Suggested-by Jason Wang <[email protected]>--- include/net/net.h | 6 +++++- net/filter-mirror.c | 1 + net/net.c | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 4 deletions(-)include/net/net.h +5
-1@@ -112,9 +112,13 @@ typedef struct NICState { } NICState;struct SocketReadState { -int state;/* 0 = getting length, 1 = getting data */ +/* 0 = getting length, 1 = getting vnet header length, 2 = getting data */ +int state; +/* This flag decide whether to read the vnet_hdr_len field */ +bool vnet_hdr;uint32_t index;uint32_t packet_len; +uint32_t vnet_hdr_len;uint8_t buf[NET_BUFSIZE ];SocketReadStateFinalize *finalize; };net/filter-mirror.c +0
-0
net/filter-mirror.c static void filter_redirector_setup(NetFilterState *nf, Error **errp) · line 270
Quoted 4 lines
net/filter-mirror.c +1
-0@@ -267,6 +267,7 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) }net_socket_rs_init (&s->rs, redirector_rs_finalize); + s->rs.vnet_hdr = s->vnet_hdr;
This looks like a follow up patch on top for this. And I would like to reoder the series and make this patch as 02/10.
net/net.c void net_socket_rs_init(SocketReadState *rs, · line 1609
Quoted 12 lines
net/filter-mirror.c +0
-0if (s->indev) { chr =qemu_chr_find (s->indev);net/net.c +1
-0@@ -1606,8 +1606,10 @@ void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize) { rs->state =0 ; + rs->vnet_hdr = false;
Let's introduce a parameter for this function and let's caller set it instead of manually toggling it like above.
Quoted 54 lines
net/net.c +29
-3rs->index =0 ; rs->packet_len =0 ; + rs->vnet_hdr_len =0 ;memset (rs->buf,0 ,sizeof (rs->buf)); rs->finalize = finalize; }@@ -1622,8 +1624,12 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)unsigned int l;while (size >0 ) { -/* reassemble a packet from the network */ -switch (rs->state) {/* 0 = getting length, 1 = getting data */ +/* Reassemble a packet from the network. +* 0 = getting length. +* 1 = getting vnet header length. +* 2 = getting data. +*/ +switch (rs->state) {case 0 : l =4 - rs->index;if (l > size) {@@ -1637,10 +1643,31 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size)/* got length */ rs->packet_len =ntohl (*(uint32_t *)rs->buf); rs->index =0 ; - rs->state =1 ; +if (rs->vnet_hdr) { + rs->state =1 ; + }else { + rs->state =2 ; + rs->vnet_hdr_len =0 ; + } }break ;case 1 : + l =4 - rs->index; +if (l > size) { + l = size; + } +memcpy (rs->buf + rs->index, buf, l); + buf += l; + size -= l; + rs->index += l; +if (rs->index ==4 ) { +/* got vnet header length */ + rs->vnet_hdr_len =ntohl (*(uint32_t *)rs->buf); + rs->index =0 ; + rs->state =2 ; + } +break ; +case 2 : l = rs->packet_len - rs->index;if (l > size) { l = size;
PATCH v6 5/10 net/colo.c: Make vnet_hdr_len as packet property
In reply to Zhang ChenWe can use this property flush and send packet with vnet_hdr_len.
--- net/colo-compare.c | 8 ++++++-- net/colo.c | 3 ++- net/colo.h | 4 +++- net/filter-rewriter.c | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-)
net/colo-compare.c +6 -2
@@ -121,9 +121,13 @@ static int packet_enqueue(CompareState *s, int mode)Connection *conn;if (mode ==PRIMARY_IN ) { - pkt =packet_new (s->pri_rs.buf, s->pri_rs.packet_len); + pkt =packet_new (s->pri_rs.buf, + s->pri_rs.packet_len, + s->pri_rs.vnet_hdr_len); }else { - pkt =packet_new (s->sec_rs.buf, s->sec_rs.packet_len); + pkt =packet_new (s->sec_rs.buf, + s->sec_rs.packet_len, + s->sec_rs.vnet_hdr_len); }if (parse_packet_early (pkt)) {
net/colo.c +2 -1
@@ -153,13 +153,14 @@ void connection_destroy(void *opaque)g_slice_free (Connection, conn); } -Packet *packet_new (const void *data,int size) +Packet *packet_new (const void *data,int size,int vnet_hdr_len) {Packet *pkt =g_slice_new (Packet); pkt->data =g_memdup (data, size); pkt->size = size; pkt->creation_ms =qemu_clock_get_ms (QEMU_CLOCK_HOST ); + pkt->vnet_hdr_len = vnet_hdr_len;return pkt; }
net/colo.h +3 -1
@@ -43,6 +43,8 @@ typedef struct Packet {int size;/* Time of packet creation, in wall clock ms */ int64_t creation_ms; +/* Get vnet_hdr_len from filter */ +uint32_t vnet_hdr_len; } Packet; typedef struct ConnectionKey {
@@ -82,7 +84,7 @@ Connection *connection_get(GHashTable *connection_track_table, ConnectionKey *key, GQueue *conn_list);void connection_hashtable_reset (GHashTable *connection_track_table); -Packet *packet_new (const void *data,int size); +Packet *packet_new (const void *data,int size,int vnet_hdr_len);void packet_destroy (void *opaque,void *user_data);#endif /* QEMU_COLO_PROXY_H */
net/filter-rewriter.c +1 -1
@@ -158,7 +158,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,char *buf =g_malloc0 (size);iov_to_buf (iov, iovcnt,0 , buf, size); - pkt =packet_new (buf, size); + pkt =packet_new (buf, size,0 );g_free (buf);/*
Signature · 1 line
2.7.4
PATCH v6 6/10 net/colo-compare.c: Make colo-compare support vnet_hdr_len
In reply to Zhang ChenWe add the vnet_hdr_support option for colo-compare, default is disable.
If you use virtio-net-pci or other driver needs vnet_hdr, please enable it.
You can use it for example:
-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support
COLO-compare can get vnet header length from filter, Add vnet_hdr_len to struct packet and output packet with the vnet_hdr_len.
--- net/colo-compare.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++------- qemu-options.hx | 4 ++-- 2 files changed, 63 insertions(+), 11 deletions(-)
net/colo-compare.c +61 -9
@@ -73,6 +73,7 @@ typedef struct CompareState {CharBackend chr_out;SocketReadState pri_rs;SocketReadState sec_rs; +bool vnet_hdr;/* connection list: the connections belonged to this NIC could be found * in this list.
@@ -97,9 +98,10 @@ enum { SECONDARY_IN, }; -static int compare_chr_send (CharBackend *out, +static int compare_chr_send (CompareState *s,const uint8_t *buf, -uint32_t size); +uint32_t size, +uint32_t vnet_hdr_len);static gint seq_sorter (Packet *a,Packet *b,gpointer data) {
@@ -472,7 +474,10 @@ static void colo_compare_connection(void *opaque, void *user_data) }if (result) { - ret =compare_chr_send (&s->chr_out, pkt->data, pkt->size); + ret =compare_chr_send (s, + pkt->data, + pkt->size, + pkt->vnet_hdr_len);if (ret <0 ) {error_report ("colo_send_primary_packet failed" ); }
@@ -493,9 +498,10 @@ static void colo_compare_connection(void *opaque, void *user_data) } } -static int compare_chr_send (CharBackend *out, +static int compare_chr_send (CompareState *s,const uint8_t *buf, -uint32_t size) +uint32_t size, +uint32_t vnet_hdr_len) {int ret =0 ;uint32_t len =htonl (size);
@@ -504,12 +510,24 @@ static int compare_chr_send(CharBackend *out,return 0 ; } - ret =qemu_chr_fe_write_all (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; } - ret =qemu_chr_fe_write_all (out, (uint8_t *)buf, size); +if (s->vnet_hdr) { +/* +* We send vnet header len make other module(like filter-redirector) +* know how to parse net packet correctly. +*/ + 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; + } + } + + ret =qemu_chr_fe_write_all (&s->chr_out, (uint8_t *)buf, size);if (ret != size) { goto err; }
@@ -646,13 +664,32 @@ static void compare_set_outdev(Object *obj, const char *value, Error **errp) s->outdev =g_strdup (value); } +static bool compare_get_vnet_hdr (Object *obj,Error **errp) +{ +CompareState *s =COLO_COMPARE (obj); + +return s->vnet_hdr; +} + +static void compare_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +CompareState *s =COLO_COMPARE (obj); + + s->vnet_hdr = value; +} +static void compare_pri_rs_finalize (SocketReadState *pri_rs) {CompareState *s =container_of (pri_rs, CompareState, pri_rs);if (packet_enqueue (s,PRIMARY_IN )) {trace_colo_compare_main ("primary: unsupported packet in" ); -compare_chr_send (&s->chr_out, pri_rs->buf, pri_rs->packet_len); +compare_chr_send (s, + pri_rs->buf, + pri_rs->packet_len, + pri_rs->vnet_hdr_len); }else {/* compare connection */ g_queue_foreach (&s->conn_list, colo_compare_connection, s);
@@ -735,7 +772,9 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) }net_socket_rs_init (&s->pri_rs, compare_pri_rs_finalize); + s->pri_rs.vnet_hdr = s->vnet_hdr;net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize); + s->sec_rs.vnet_hdr = s->vnet_hdr;g_queue_init (&s->conn_list);
@@ -761,7 +800,10 @@ static void colo_flush_packets(void *opaque, void *user_data)while (!g_queue_is_empty (&conn->primary_list)) { pkt =g_queue_pop_head (&conn->primary_list); -compare_chr_send (&s->chr_out, pkt->data, pkt->size); +compare_chr_send (s, + pkt->data, + pkt->size, + pkt->vnet_hdr_len);packet_destroy (pkt,NULL ); }while (!g_queue_is_empty (&conn->secondary_list)) {
@@ -779,6 +821,8 @@ static void colo_compare_class_init(ObjectClass *oc, void *data)static void colo_compare_init (Object *obj) { +CompareState *s =COLO_COMPARE (obj); +object_property_add_str (obj,"primary_in" , compare_get_pri_indev, compare_set_pri_indev,NULL );
@@ -788,6 +832,14 @@ static void colo_compare_init(Object *obj)object_property_add_str (obj,"outdev" , compare_get_outdev, compare_set_outdev,NULL ); +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/ + s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , compare_get_vnet_hdr, + compare_set_vnet_hdr,NULL ); }static void colo_compare_finalize (Object *obj)
qemu-options.hx +2 -2
@@ -4057,13 +4057,13 @@ Dump the network traffic on netdev @var{dev} to the file specified by The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. -@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid}, -outdev=@var{chardevid} +@item -object colo-compare,id=@var{id},primary_in=@var{chardevid},secondary_in=@var{chardevid},outdev=@var{chardevid}[,vnet_hdr_support] Colo-compare gets packet from primary_in@var{chardevid} and secondary_in@var{chardevid}, than compare primary packet with secondary packet. If the packets are same, we will output primary packet to outdev@var{chardevid}, else we will notify colo-frame do checkpoint and send primary packet to outdev@var{chardevid}. +if have the vnet_hdr_support flag, colo compare will send/recv packet with vnet_hdr_len. we must use it with the help of filter-mirror and filter-redirector.
Signature · 1 line
2.7.4
PATCH v6 7/10 net/colo.c: Add vnet packet parse feature in colo-proxy
In reply to Zhang ChenMake colo-compare and filter-rewriter can parse vnet packet.
--- net/colo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/colo.c +3 -3
@@ -43,11 +43,11 @@ int parse_packet_early(Packet *pkt) {int network_length;static const uint8_t vlan[] = {0x81 ,0x00 }; -uint8_t *data = pkt->data; +uint8_t *data = pkt->data + pkt->vnet_hdr_len;uint16_t l3_proto;ssize_t l2hdr_len =eth_get_l2_hdr_length (data); -if (pkt->size <ETH_HLEN ) { +if (pkt->size <ETH_HLEN + pkt->vnet_hdr_len) {trace_colo_proxy_main ("pkt->size < ETH_HLEN" );return 1 ; }
@@ -73,7 +73,7 @@ int parse_packet_early(Packet *pkt) } network_length = pkt->ip->ip_hl *4 ; -if (pkt->size < l2hdr_len + network_length) { +if (pkt->size < l2hdr_len + network_length + pkt->vnet_hdr_len) {trace_colo_proxy_main ("pkt->size < network_header + network_length" );return 1 ; }
Signature · 1 line
2.7.4
PATCH v6 8/10 net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare
In reply to Zhang ChenCOLO-Proxy just focus on packet payload, So we skip vnet header.
--- net/colo-compare.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/colo-compare.c +6 -2
@@ -201,8 +201,11 @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset) sec_ip_src, sec_ip_dst); } + offset = ppkt->vnet_hdr_len + offset; +if (ppkt->size == spkt->size) { -return memcmp (ppkt->data + offset, spkt->data + offset, +return memcmp (ppkt->data + offset, + spkt->data + offset, spkt->size - offset); }else {trace_colo_compare_main ("Net packet size are not the same" );
@@ -261,8 +264,9 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)*/ if (ptcp->th_off >5 ) {ptrdiff_t tcp_offset; + tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data - + (ptcp->th_off *4 ); + + (ptcp->th_off *4 ) - ppkt->vnet_hdr_len; res =colo_packet_compare_common (ppkt, spkt, tcp_offset); }else if (ptcp->th_sum == stcp->th_sum) { res =colo_packet_compare_common (ppkt, spkt,ETH_HLEN );
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH V6 08/10] net/colo-compare.c: Add vnet packet's tcp/udp/icmp compare
Quoted 1 line · Zhang Chen
COLO-Proxy just focus on packet payload, So we skip vnet header.
s/So/so/
Quoted 34 lines
Signed-off-by Zhang Chen <[email protected]>--- net/colo-compare.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)net/colo-compare.c +6
-2@@ -201,8 +201,11 @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset) sec_ip_src, sec_ip_dst); } + offset = ppkt->vnet_hdr_len + offset; +if (ppkt->size == spkt->size) { -return memcmp (ppkt->data + offset, spkt->data + offset, +return memcmp (ppkt->data + offset, + spkt->data + offset, spkt->size - offset); }else {trace_colo_compare_main ("Net packet size are not the same" );@@ -261,8 +264,9 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)*/ if (ptcp->th_off >5 ) {ptrdiff_t tcp_offset; + tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data - + (ptcp->th_off *4 ); + + (ptcp->th_off *4 ) - ppkt->vnet_hdr_len; res =colo_packet_compare_common (ppkt, spkt, tcp_offset); }else if (ptcp->th_sum == stcp->th_sum) { res =colo_packet_compare_common (ppkt, spkt,ETH_HLEN );
PATCH v6 9/10 net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len
In reply to Zhang ChenWe add the vnet_hdr_support option for filter-rewriter, default is disable. If you use virtio-net-pci net driver, please enable it.
You can use it for example:
-object filter-rewriter,id=rew0,netdev=hn0,queue=all,vnet_hdr_support
We get the vnet_hdr_len from NetClientState that make us parse net packet correctly.
--- net/filter-rewriter.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 4 ++-- 2 files changed, 52 insertions(+), 3 deletions(-)
net/filter-rewriter.c +50 -1
@@ -17,6 +17,7 @@#include "qemu-common.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qapi-visit.h" #include "qom/object.h" #include "qemu/main-loop.h"
@@ -33,6 +34,7 @@ typedef struct RewriterState {NetQueue *incoming_queue;/* hashtable to save connection */ GHashTable *connection_track_table; +bool vnet_hdr; } RewriterState;static void filter_rewriter_flush (NetFilterState *nf)
@@ -155,10 +157,25 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,ConnectionKey key;Packet *pkt;ssize_t size =iov_size (iov, iovcnt); +ssize_t vnet_hdr_len =0 ;char *buf =g_malloc0 (size);iov_to_buf (iov, iovcnt,0 , buf, size); - pkt =packet_new (buf, size,0 ); + +if (s->vnet_hdr) { +if (nf->direction ==NET_FILTER_DIRECTION_RX || + nf->direction ==NET_FILTER_DIRECTION_ALL ) { + vnet_hdr_len = nf->netdev->vnet_hdr_len; + }else if (nf->direction ==NET_FILTER_DIRECTION_TX ) { + vnet_hdr_len = nf->netdev->peer->vnet_hdr_len; + }else { +error_report ("filter-rewriter get vnet_hdr_len failed" ); +/* When error occurred we drop the packet */ +return 1 ; + } + } + + pkt =packet_new (buf, size, vnet_hdr_len);g_free (buf);/*
@@ -237,6 +254,37 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) s->incoming_queue =qemu_new_net_queue (qemu_netfilter_pass_to_next, nf); } +static bool filter_rewriter_get_vnet_hdr (Object *obj,Error **errp) +{ +RewriterState *s =FILTER_COLO_REWRITER (obj); + +return s->vnet_hdr; +} + +static void filter_rewriter_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +RewriterState *s =FILTER_COLO_REWRITER (obj); + + s->vnet_hdr = value; +} + +static void filter_rewriter_init (Object *obj) +{ +RewriterState *s =FILTER_COLO_REWRITER (obj); + +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/ + s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_rewriter_get_vnet_hdr, + filter_rewriter_set_vnet_hdr,NULL ); +} +static void colo_rewriter_class_init (ObjectClass *oc,void *data) {NetFilterClass *nfc =NETFILTER_CLASS (oc);
@@ -250,6 +298,7 @@ static const TypeInfo colo_rewriter_info = { .name = TYPE_FILTER_REWRITER, .parent = TYPE_NETFILTER, .class_init = colo_rewriter_class_init, + .instance_init = filter_rewriter_init, .instance_size = sizeof(RewriterState), };
qemu-options.hx +2 -2
@@ -4037,12 +4037,12 @@ Create a filter-redirector we need to differ outdev id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or outdev need to be specified. -@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},rewriter-mode=@var{mode}[,queue=@var{all|rx|tx}] +@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},rewriter-mode=@var{mode},queue=@var{all|rx|tx},[vnet_hdr_support] Filter-rewriter is a part of COLO project.It will rewrite tcp packet to secondary from primary to keep secondary tcp connection,and rewrite tcp packet to primary from secondary make tcp packet can be handled by -client. +client.if have the vnet_hdr_support flag, we can parse packet with vnet header. usage: colo secondary:
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH V6 09/10] net/filter-rewriter.c: Make filter-rewriter support vnet_hdr_len
Quoted 46 lines · Zhang Chen
We add the
vnet_hdr_supportoption for filter-rewriter, default is disable. If you use virtio-net-pci net driver, please enable it.
You can use it for example:
-object filter-rewriter,id=rew0,netdev=hn0,queue=all,vnet_hdr_supportWe get the
vnet_hdr_lenfrom NetClientState that make us parse net packet correctly.Signed-off-by Zhang Chen <[email protected]>--- net/filter-rewriter.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 4 ++-- 2 files changed, 52 insertions(+), 3 deletions(-)net/filter-rewriter.c +6
-1@@ -17,6 +17,7 @@#include "qemu-common.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qemu/error-report.h" #include "qapi-visit.h" #include "qom/object.h" #include "qemu/main-loop.h" @@ -33,6 +34,7 @@ typedef struct RewriterState {NetQueue *incoming_queue;/* hashtable to save connection */ GHashTable *connection_track_table; +bool vnet_hdr; } RewriterState;static void filter_rewriter_flush (NetFilterState *nf)@@ -155,10 +157,25 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,ConnectionKey key;Packet *pkt;ssize_t size =iov_size (iov, iovcnt); +ssize_t vnet_hdr_len =0 ;char *buf =g_malloc0 (size);iov_to_buf (iov, iovcnt,0 , buf, size); - pkt =packet_new (buf, size,0 ); + +if (s->vnet_hdr) { + if (nf->direction == NET_FILTER_DIRECTION_RX ||
net/filter-rewriter.c static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, · line 176
Quoted 10 lines
net/filter-rewriter.c +10
-0+ nf->direction == NET_FILTER_DIRECTION_ALL) { + vnet_hdr_len = nf->netdev->vnet_hdr_len; + } else if (nf->direction == NET_FILTER_DIRECTION_TX) { + vnet_hdr_len = nf->netdev->peer->vnet_hdr_len; + } else { +error_report ("filter-rewriter get vnet_hdr_len failed" ); +/* When error occurred we drop the packet */ +return 1 ; + } + }
Similar issue as patch 02, and we can probably use a helper to avoid duplicating codes.
Thanks
Quoted 70 lines
net/filter-rewriter.c +34
-0+ + pkt =packet_new (buf, size, vnet_hdr_len);g_free (buf);/* @@ -237,6 +254,37 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) s->incoming_queue =qemu_new_net_queue (qemu_netfilter_pass_to_next, nf); } +static bool filter_rewriter_get_vnet_hdr (Object *obj,Error **errp) +{ +RewriterState *s =FILTER_COLO_REWRITER (obj); + +return s->vnet_hdr; +} + +static void filter_rewriter_set_vnet_hdr (Object *obj, +bool value, +Error **errp) +{ +RewriterState *s =FILTER_COLO_REWRITER (obj); + + s->vnet_hdr = value; +} + +static void filter_rewriter_init (Object *obj) +{ +RewriterState *s =FILTER_COLO_REWRITER (obj); + +/* +* The vnet_hdr is disabled by default, if you want to enable +* this option, you must enable all the option on related modules +* (like other filter or colo-compare). +*/ + s->vnet_hdr = false; +object_property_add_bool (obj,"vnet_hdr_support" , + filter_rewriter_get_vnet_hdr, + filter_rewriter_set_vnet_hdr,NULL ); +} +static void colo_rewriter_class_init (ObjectClass *oc,void *data) {NetFilterClass *nfc =NETFILTER_CLASS (oc);@@ -250,6 +298,7 @@ static const TypeInfo colo_rewriter_info = { .name = TYPE_FILTER_REWRITER, .parent = TYPE_NETFILTER, .class_init = colo_rewriter_class_init, + .instance_init = filter_rewriter_init, .instance_size = sizeof(RewriterState), };qemu-options.hx +2
-2@@ -4037,12 +4037,12 @@ Create a filter-redirector we need to differ outdev id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or outdev need to be specified. -@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},rewriter-mode=@var{mode}[,queue=@var{all|rx|tx}] +@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},rewriter-mode=@var{mode},queue=@var{all|rx|tx},[vnet_hdr_support] Filter-rewriter is a part of COLO project.It will rewrite tcp packet to secondary from primary to keep secondary tcp connection,and rewrite tcp packet to primary from secondary make tcp packet can be handled by -client. +client.if have the vnet_hdr_support flag, we can parse packet with vnet header. usage: colo secondary:
PATCH v6 10/10 docs/colo-proxy.txt: Update colo-proxy usage of net driver with vnet_header
In reply to Zhang Chen--- docs/colo-proxy.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
docs/colo-proxy.txt +26 -0
@@ -182,6 +182,32 @@ Secondary(ip:3.3.3.8): -chardev socket,id=red1,host=3.3.3.3,port=9004 -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 +-object filter-rewriter,id=f3,netdev=hn0,queue=all + +If you want to use virtio-net-pci or other driver with vnet_header: + +Primary(ip:3.3.3.3): +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown +-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait +-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait +-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait +-chardev socket,id=compare0-0,host=3.3.3.3,port=9001 +-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait +-chardev socket,id=compare_out0,host=3.3.3.3,port=9005 +-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support +-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out,vnet_hdr_support +-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0,vnet_hdr_support +-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support + +Secondary(ip:3.3.3.8): +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown +-device e1000,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=red0,host=3.3.3.3,port=9003 +-chardev socket,id=red1,host=3.3.3.3,port=9004 +-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0,vnet_hdr_support +-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1,vnet_hdr_support +-object filter-rewriter,id=f3,netdev=hn0,queue=all,vnet_hdr_support Note: a.COLO-proxy must work with COLO-frame and Block-replication.
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH V6 10/10] docs/colo-proxy.txt: Update colo-proxy usage of net driver with vnet_header
Quoted 10 lines · Zhang Chen
Signed-off-by Zhang Chen <[email protected]>--- docs/colo-proxy.txt | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)docs/colo-proxy.txt +0
-0
docs/colo-proxy.txt Secondary(ip:3.3.3.8): · line 187
Quoted 6 lines
docs/colo-proxy.txt +3
-0@@ -182,6 +182,32 @@ Secondary(ip:3.3.3.8): -chardev socket,id=red1,host=3.3.3.3,port=9004 -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 +-object filter-rewriter,id=f3,netdev=hn0,queue=all + +If you want to use virtio-net-pci or other driver with vnet_header:
s/virtio-net-pci/virtio-net/ and s/driver/device/
Thanks
Quoted 26 lines
docs/colo-proxy.txt +23
-0+ +Primary(ip:3.3.3.3): +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown +-device e1000,id=e0,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=mirror0,host=3.3.3.3,port=9003,server,nowait +-chardev socket,id=compare1,host=3.3.3.3,port=9004,server,nowait +-chardev socket,id=compare0,host=3.3.3.3,port=9001,server,nowait +-chardev socket,id=compare0-0,host=3.3.3.3,port=9001 +-chardev socket,id=compare_out,host=3.3.3.3,port=9005,server,nowait +-chardev socket,id=compare_out0,host=3.3.3.3,port=9005 +-object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0,vnet_hdr_support +-object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out,vnet_hdr_support +-object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0,vnet_hdr_support +-object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,outdev=compare_out0,vnet_hdr_support + +Secondary(ip:3.3.3.8): +-netdev tap,id=hn0,vhost=off,script=/etc/qemu-ifup,down script=/etc/qemu-ifdown +-device e1000,netdev=hn0,mac=52:a4:00:12:78:66 +-chardev socket,id=red0,host=3.3.3.3,port=9003 +-chardev socket,id=red1,host=3.3.3.3,port=9004 +-object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0,vnet_hdr_support +-object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1,vnet_hdr_support +-object filter-rewriter,id=f3,netdev=hn0,queue=all,vnet_hdr_support Note: a.COLO-proxy must work with COLO-frame and Block-replication.