net/colo: check vnet_hdr_support flag when using virtio-net
PATCH v2 1/1 net/colo: check vnet_hdr_support flag when using virtio-net
When COLO use only one vnet_hdr_support parameter between COLO network filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, check vnet_hdr_support flag of COLO network filter and colo-compare.
---
Changelog:
v2:
Detect virtio-net driver and apply vnet_hdr_support automatically. (Jason)
--- net/colo-compare.c | 57 +++++++++++++++++++++++++++++++++++++++++++ net/colo.c | 20 +++++++++++++++ net/colo.h | 4 +++ net/filter-mirror.c | 21 ++++++++++++++++ net/filter-rewriter.c | 10 ++++++++ qapi/qom.json | 6 +++++ qemu-options.hx | 6 +++-- 7 files changed, 122 insertions(+), 2 deletions(-)
net/colo-compare.c +57 -0
@@ -110,6 +110,7 @@ struct CompareState {char *sec_indev;char *outdev;char *notify_dev; +char *netdev;CharBackend chr_pri_in;CharBackend chr_sec_in;CharBackend chr_out;
@@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)return COMPARE_READ_LEN_MAX ; } +static int colo_set_default_netdev (void *opaque,QemuOpts *opts,Error **errp) +{ +const char *colo_obj_type, *netdev_from_filter; +char **netdev = (char **)opaque; + + colo_obj_type =qemu_opt_get (opts,"qom-type" ); + +if (colo_obj_type && + (strcmp (colo_obj_type,"filter-mirror" ) ==0 || +strcmp (colo_obj_type,"filter-redirector" ) ==0 || +strcmp (colo_obj_type,"filter-rewriter" ) ==0 )) { + netdev_from_filter =qemu_opt_get (opts,"netdev" ); +if (*netdev ==NULL ) { + *netdev =g_strdup (netdev_from_filter); + }else if (strcmp (*netdev, netdev_from_filter) !=0 ) { +warn_report ("%s is using a different netdev from other COLO " +"component" , colo_obj_type); + } + } +return 0 ; +} +/* * Called from the main thread on the primary for packets * arriving over the socket from the primary.
@@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj, s->vnet_hdr = value; } +static char *compare_get_netdev (Object *obj,Error **errp) +{ +CompareState *s =COLO_COMPARE (obj); + +return g_strdup (s->netdev); +} + +static void compare_set_netdev (Object *obj,const char *value,Error **errp) +{ +CompareState *s =COLO_COMPARE (obj); + +g_free (s->netdev); + s->netdev =g_strdup (value); +} +static char *compare_get_notify_dev (Object *obj,Error **errp) {CompareState *s =COLO_COMPARE (obj);
@@ -1274,6 +1312,12 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) max_queue_size =MAX_QUEUE_SIZE ; } +if (!s->netdev) { +/* Set default netdev as the first colo netfilter found */ +qemu_opts_foreach (qemu_find_opts ("object" ), + colo_set_default_netdev, &s->netdev,NULL ); + } +if (find_and_check_chardev (&chr, s->pri_indev, errp) || !qemu_chr_fe_init (&s->chr_pri_in, chr, errp)) {return ;
@@ -1289,6 +1333,16 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, s->netdev,NULL )) { +/* +* colo compare needs 'vnet_hdr_support' when it works on virtio-net, +* add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +net_socket_rs_init (&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);
@@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj) s->vnet_hdr = false;object_property_add_bool (obj,"vnet_hdr_support" , compare_get_vnet_hdr, compare_set_vnet_hdr); +/* colo compare can't varify that netdev is correct */ +object_property_add_str (obj,"netdev" , compare_get_netdev, + compare_set_netdev); }void colo_compare_cleanup (void )
net/colo.c +20 -0
@@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table,return conn ? true : false; } + +/* check the network driver related to COLO, return 1 if it is virtio-net */ +int vnet_driver_check (void *opaque,QemuOpts *opts,Error **errp) +{ +const char *driver_type, *netdev_from_driver; +char *netdev_from_filter = (char *)opaque; + + driver_type =qemu_opt_get (opts,"driver" ); + netdev_from_driver =qemu_opt_get (opts,"netdev" ); + +if (!driver_type || !netdev_from_driver || !netdev_from_filter) { +return 0 ; + } + +if (g_str_has_prefix (driver_type,"virtio-net" ) && +strcmp (netdev_from_driver, netdev_from_filter) ==0 ) { +return 1 ; + } +return 0 ; +}
net/colo.h +4 -0
@@ -18,6 +18,9 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "qemu/option.h" +#include "qemu/option_int.h" +#include "qemu/config-file.h" #define HASHTABLE_MAX_SIZE 16384
@@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int vnet_hdr_len);Packet *packet_new_nocopy (void *data,int size,int vnet_hdr_len);void packet_destroy (void *opaque,void *user_data);void packet_destroy_partial (void *opaque,void *user_data); +int vnet_driver_check (void *opaque,QemuOpts *opts,Error **errp);#endif /* NET_COLO_H */
net/filter-mirror.c +21 -0
@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "net/filter.h" #include "net/net.h" +#include "net/colo.h" #include "qapi/error.h" #include "qom/object.h" #include "qemu/main-loop.h"
@@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp)return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter mirror needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +qemu_chr_fe_init (&s->chr_out, chr, errp); }
@@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) } } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter redirector needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +net_socket_rs_init (&s->rs, redirector_rs_finalize, s->vnet_hdr);if (s->indev) {
net/filter-rewriter.c +10 -0
@@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) {RewriterState *s =FILTER_REWRITER (nf); +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter rewriter needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } + s->connection_track_table = g_hash_table_new_full(connection_key_hash, connection_key_equal, g_free,
qapi/qom.json +6 -0
@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used to communicate # with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare, although +# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working on +# # @compare_timeout: the maximum time to hold a packet from @primary_in for # comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)
@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32',
qemu-options.hx +4 -2
@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]`` + ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primary packet and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework to do - checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although colo-compare + does not depend on network device directly, netdevid help + colo-compare know what network driver it is working on. In order to improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.
Signature · 1 line
2.25.1
Quoted 13 lines · Tao Xu
When COLO use only one
vnet_hdr_supportparameter between COLO network filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, checkvnet_hdr_supportflag of COLO network filter and colo-compare.Signed-off-by Tao Xu <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
+++
b/qapi/qom.json
qapi/qom.json line 247
Quoted 7 lines
qapi/qom.json +4
-0@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used to communicate # with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare, although +# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working on
Missing a '(since 6.2)' tag.
Grammar suggestion: s/colo-compare, although/colo-compare. Although/ s/help/helps/
Quoted 19 lines
qapi/qom.json +2
-0+# # @compare_timeout: the maximum time to hold a packet from @primary_in for # comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32',qemu-options.hx +0
-0@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark.
qemu-options.hx SRST · line 4966
Quoted 10 lines
qemu-options.hx +3
-2- ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]`` + ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primary packet and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework to do - checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although colo-compare + does not depend on network device directly, netdevid help
s/help/helps/
Quoted 8 lines
qemu-options.hx +1
-0+ colo-compare know what network driver it is working on. In order to improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.Signature · 1 line
2.25.1
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 36 lines
-----Original Message-----
From: Eric Blake <[email protected]>
Sent: Saturday, August 21, 2021 5:43 AM
To: Xu, Tao3 <[email protected]>
Cc: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] net/colo: checkvnet_hdr_supportflag when using virtio-netQuoted 1 line · Tao Xu
When COLO use only one
vnet_hdr_supportparameter between COLOnetwork
Review line 241
Quoted 12 lines
filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, check
vnet_hdr_supportflag of COLO network filter and colo-compare.Signed-off-by Tao Xu <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
+++
b/qapi/qom.json(quoted diff) +0
-0@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used tocommunicate
qapi/qom.json line 247
Quoted 6 lines
qapi/qom.json +4
-0# with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare, although +# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working onMissing a '(since 6.2)' tag.
Quoted 3 lines
Grammar suggestion: s/colo-compare, although/colo-compare. Although/ s/help/helps/
OK.
Quoted 40 lines
Review line 249
Quoted 4 lines
(quoted diff) +1
-0+# # @compare_timeout: the maximum time to hold a packet from@primary_in for
Quoted 14 lines
qapi/qom.json +1
-0# comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32', diff --git a/qemu-options.hxb/qemu-options.hx index
83aa59a920..b31ce3c87d100644qemu-options.hx SRST · line 4960
Quoted 4 lines
qemu-options.hx +0
-1@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chard evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@ var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
qemu-options.hx SRST · line 4961
Quoted 2 lines
qemu-options.hx +2
-0+ ``-object + colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
qemu-options.hx SRST · line 4963
Quoted 2 lines
qemu-options.hx +2
-0+ v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify +_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][, m
qemu-options.hx SRST
Quoted 7 lines
qemu-options.hx +2
-1+ ax_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primary packet and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework to do - checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although colo-
Quoted 4 lines
compare
qemu-options.hx SRST · line 4966
Quoted 1 line
qemu-options.hx +1
-0+ does not depend on network device directly, netdevid helps/help/helps/
OK, will fix in next version.
Thanks
Chen
Quoted 15 lines
Quoted 10 lines
+ colo-compare know what network driver it is working on. In
+ order to
improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.
--
2.25.1--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
Quoted 53 lines · On Thu, 19 Aug 2021 09:27:17 +0800 Tao Xu <[email protected]> wrote:
When COLO use only one
vnet_hdr_supportparameter between COLO network filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, checkvnet_hdr_supportflag of COLO network filter and colo-compare.Signed-off-by Tao Xu <[email protected]>Signed-off-by Zhang Chen <[email protected]>---
Changelog:
v2:
Detect virtio-net driver and applyvnet_hdr_supportautomatically. (Jason)--- net/colo-compare.c | 57 +++++++++++++++++++++++++++++++++++++++++++ net/colo.c | 20 +++++++++++++++ net/colo.h | 4 +++ net/filter-mirror.c | 21 ++++++++++++++++ net/filter-rewriter.c | 10 ++++++++ qapi/qom.json | 6 +++++ qemu-options.hx | 6 +++-- 7 files changed, 122 insertions(+), 2 deletions(-)net/colo-compare.c +13
-0@@ -110,6 +110,7 @@ struct CompareState {char *sec_indev;char *outdev;char *notify_dev; +char *netdev;CharBackend chr_pri_in;CharBackend chr_sec_in;CharBackend chr_out;@@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)return COMPARE_READ_LEN_MAX ; } +static int colo_set_default_netdev (void *opaque,QemuOpts *opts,Error **errp) +{ +const char *colo_obj_type, *netdev_from_filter; +char **netdev = (char **)opaque; + + colo_obj_type =qemu_opt_get (opts,"qom-type" ); + +if (colo_obj_type && + (strcmp (colo_obj_type,"filter-mirror" ) ==0 || +strcmp (colo_obj_type,"filter-redirector" ) ==0 || +strcmp (colo_obj_type,"filter-rewriter" ) ==0 )) { + netdev_from_filter =qemu_opt_get (opts,"netdev" );
net/colo-compare.c static int compare_chr_can_read(void *opaque) · line 863
Quoted 10 lines
net/colo-compare.c +10
-0+if (*netdev ==NULL ) { + *netdev =g_strdup (netdev_from_filter); + }else if (strcmp (*netdev, netdev_from_filter) !=0 ) { +warn_report ("%s is using a different netdev from other COLO " +"component" , colo_obj_type); + } + } +return 0 ; +} +
Hi,
This doesn't properly handle the case where there are multiple network devices and one is virtio-net and the other isn't. This would be a regression as this worked fine before.
Quoted 42 lines
net/colo-compare.c +21
-0/* * Called from the main thread on the primary for packets * arriving over the socket from the primary. @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj, s->vnet_hdr = value; } +static char *compare_get_netdev (Object *obj,Error **errp) +{ +CompareState *s =COLO_COMPARE (obj); + +return g_strdup (s->netdev); +} + +static void compare_set_netdev (Object *obj,const char *value,Error **errp) +{ +CompareState *s =COLO_COMPARE (obj); + +g_free (s->netdev); + s->netdev =g_strdup (value); +} +static char *compare_get_notify_dev (Object *obj,Error **errp) {CompareState *s =COLO_COMPARE (obj);@@ -1274,6 +1312,12 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) max_queue_size =MAX_QUEUE_SIZE ; } +if (!s->netdev) { +/* Set default netdev as the first colo netfilter found */ +qemu_opts_foreach (qemu_find_opts ("object" ), + colo_set_default_netdev, &s->netdev,NULL ); + } +if (find_and_check_chardev (&chr, s->pri_indev, errp) || !qemu_chr_fe_init (&s->chr_pri_in, chr, errp)) {return ;@@ -1289,6 +1333,16 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)return ; }
net/colo-compare.c static void colo_compare_complete(UserCreatable *uc, Error **errp) · line 1345
Quoted 10 lines
net/colo-compare.c +10
-0+if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, s->netdev,NULL )) { +/* +* colo compare needs 'vnet_hdr_support' when it works on virtio-net, +* add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +
There is no way to disable vnet_hdr_support with virtio-net now.
Quoted 174 lines
net/colo-compare.c +3
-0net_socket_rs_init (&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);@@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj) s->vnet_hdr = false;object_property_add_bool (obj,"vnet_hdr_support" , compare_get_vnet_hdr, compare_set_vnet_hdr); +/* colo compare can't varify that netdev is correct */ +object_property_add_str (obj,"netdev" , compare_get_netdev, + compare_set_netdev); }void colo_compare_cleanup (void )net/colo.c +20
-0@@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table,return conn ? true : false; } + +/* check the network driver related to COLO, return 1 if it is virtio-net */ +int vnet_driver_check (void *opaque,QemuOpts *opts,Error **errp) +{ +const char *driver_type, *netdev_from_driver; +char *netdev_from_filter = (char *)opaque; + + driver_type =qemu_opt_get (opts,"driver" ); + netdev_from_driver =qemu_opt_get (opts,"netdev" ); + +if (!driver_type || !netdev_from_driver || !netdev_from_filter) { +return 0 ; + } + +if (g_str_has_prefix (driver_type,"virtio-net" ) && +strcmp (netdev_from_driver, netdev_from_filter) ==0 ) { +return 1 ; + } +return 0 ; +}net/colo.h +4
-0@@ -18,6 +18,9 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "qemu/option.h" +#include "qemu/option_int.h" +#include "qemu/config-file.h" #define HASHTABLE_MAX_SIZE 16384@@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int vnet_hdr_len);Packet *packet_new_nocopy (void *data,int size,int vnet_hdr_len);void packet_destroy (void *opaque,void *user_data);void packet_destroy_partial (void *opaque,void *user_data); +int vnet_driver_check (void *opaque,QemuOpts *opts,Error **errp);#endif /* NET_COLO_H */ net/filter-mirror.c +21
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "net/filter.h" #include "net/net.h" +#include "net/colo.h" #include "qapi/error.h" #include "qom/object.h" #include "qemu/main-loop.h" @@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf, Error **errp)return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter mirror needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +qemu_chr_fe_init (&s->chr_out, chr, errp); }@@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState *nf, Error **errp) } } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter redirector needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +net_socket_rs_init (&s->rs, redirector_rs_finalize, s->vnet_hdr);if (s->indev) {net/filter-rewriter.c +10
-0@@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) {RewriterState *s =FILTER_REWRITER (nf); +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter rewriter needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } + s->connection_track_table = g_hash_table_new_full(connection_key_hash, connection_key_equal, g_free,qapi/qom.json +6
-0@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used to communicate # with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare, although +# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working on +# # @compare_timeout: the maximum time to hold a packet from @primary_in for # comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32',qemu-options.hx +4
-2@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]`` + ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primary packet and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework to do - checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although colo-compare + does not depend on network device directly, netdevid help + colo-compare know what network driver it is working on. In order to improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.
Quoted 75 lines
-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Sunday, August 22, 2021 12:25 AM
To: Xu, Tao3 <[email protected]>
Cc: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] net/colo: checkvnet_hdr_supportflag when using virtio-netQuoted 1 line · On Thu, 19 Aug 2021 09:27:17 +0800 Tao Xu <[email protected]> wrote:
When COLO use only one
vnet_hdr_supportparameter between COLOnetwork
Quoted 7 lines
filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, check
vnet_hdr_supportflag of COLO network filter and colo-compare.Signed-off-by Tao Xu <[email protected]>Signed-off-by Zhang Chen <[email protected]>Quoted 8 lines
---
Changelog:
v2:
Detect virtio-net driver and applyvnet_hdr_supportautomatically. (Jason)--- net/colo-compare.c | 57+++++++++++++++++++++++++++++++++++++++++++
Quoted 43 lines
net/colo.c | 20 +++++++++++++++ net/colo.h | 4 +++ net/filter-mirror.c | 21 ++++++++++++++++ net/filter-rewriter.c | 10 ++++++++ qapi/qom.json | 6 +++++ qemu-options.hx | 6 +++-- 7 files changed, 122 insertions(+), 2 deletions(-)net/colo-compare.c index renamed from net/colo-compare.c +0
-0
b100e7b51f..870bd05a41100644net/colo-compare.c +20
-0@@ -110,6 +110,7 @@ struct CompareState {char *sec_indev;char *outdev;char *notify_dev; +char *netdev;CharBackend chr_pri_in;CharBackend chr_sec_in;CharBackend chr_out;@@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)return COMPARE_READ_LEN_MAX ; } +static int colo_set_default_netdev (void *opaque,QemuOpts *opts, +Error **errp) { +const char *colo_obj_type, *netdev_from_filter; +char **netdev = (char **)opaque; + + colo_obj_type =qemu_opt_get (opts,"qom-type" ); + +if (colo_obj_type && + (strcmp (colo_obj_type,"filter-mirror" ) ==0 || +strcmp (colo_obj_type,"filter-redirector" ) ==0 || +strcmp (colo_obj_type,"filter-rewriter" ) ==0 )) { + netdev_from_filter =qemu_opt_get (opts,"netdev" ); +if (*netdev ==NULL ) { + *netdev =g_strdup (netdev_from_filter); + }else if (strcmp (*netdev, netdev_from_filter) !=0 ) { +warn_report ("%s is using a different netdev from other COLO " +"component" , colo_obj_type); + } + }
Quoted 8 lines
net/colo-compare.c static int compare_chr_can_read(void *opaque) · line 863
Quoted 3 lines
net/colo-compare.c +3
-0+return 0 ; +} +Hi,
This doesn't properly handle the case where there are multiple network devices and one is virtio-net and the other isn't. This would be a regression as this worked fine before.
No, If have multiple network device this patch just report a warning for it. You can still use virtio-net and others at the same time.
Quoted 53 lines
net/colo-compare.c static void
Quoted 38 lines
net/colo-compare.c +20
-0/* * Called from the main thread on the primary for packets * arriving over the socket from the primary. @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj, s->vnet_hdr = value; } +static char *compare_get_netdev (Object *obj,Error **errp) { +CompareState *s =COLO_COMPARE (obj); + +return g_strdup (s->netdev); +} + +static void compare_set_netdev (Object *obj,const char *value,Error +**errp) { +CompareState *s =COLO_COMPARE (obj); + +g_free (s->netdev); + s->netdev =g_strdup (value); +} +static char *compare_get_notify_dev (Object *obj,Error **errp) { CompareState *s = COLO_COMPARE(obj); @@ -1274,6 +1312,12 @@static void colo_compare_complete (UserCreatable *uc,Error **errp) max_queue_size =MAX_QUEUE_SIZE ; } +if (!s->netdev) { +/* Set default netdev as the first colo netfilter found */ +qemu_opts_foreach (qemu_find_opts ("object" ), + colo_set_default_netdev, &s->netdev,NULL ); + } +if (find_and_check_chardev (&chr, s->pri_indev, errp) || !qemu_chr_fe_init (&s->chr_pri_in, chr, errp)) {return ;@@ -1289,6 +1333,16 @@ static void
colo_compare_complete(UserCreatable *uc, Error **errp)net/colo-compare.c static void colo_compare_complete(UserCreatable *uc, Error **errp) · line 1345
Quoted 13 lines
net/colo-compare.c +10
-0return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, s->netdev,NULL )) { +/* +* colo compare needs 'vnet_hdr_support' when it works on virtio-net, +* add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +
Quoted 1 line
There is no way to disable
vnet_hdr_supportwith virtio-net now.
Yes, It looks no reason to do this.
Please show me some details?
Thanks
Chen
Quoted 197 lines
net/colo-compare.c static void colo_compare_init(Object *obj) · line 1455
Quoted 8 lines
net/colo-compare.c +0
-0net_socket_rs_init (&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);@@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj) s->vnet_hdr = false; object_property_add_bool(obj, "vnet_hdr_support",
compare_get_vnet_hdr,net/filter-mirror.c static void filter_mirror_setup(NetFilterState *nf,
Quoted 70 lines
net/colo-compare.c +3
-0compare_set_vnet_hdr); +/* colo compare can't varify that netdev is correct */ +object_property_add_str (obj,"netdev" , compare_get_netdev, + compare_set_netdev); }void colo_compare_cleanup (void )net/colo.c +20
-0@@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table, return conn ? true : false; } + +/* check the network driver related to COLO, return 1 if it is +virtio-net */ int vnet_driver_check (void *opaque,QemuOpts *opts, +Error **errp) { +const char *driver_type, *netdev_from_driver; +char *netdev_from_filter = (char *)opaque; + + driver_type =qemu_opt_get (opts,"driver" ); + netdev_from_driver =qemu_opt_get (opts,"netdev" ); + +if (!driver_type || !netdev_from_driver || !netdev_from_filter) { +return 0 ; + } + +if (g_str_has_prefix (driver_type,"virtio-net" ) && +strcmp (netdev_from_driver, netdev_from_filter) ==0 ) { +return 1 ; + } +return 0 ; +}net/colo.h +3
-0@@ -18,6 +18,9 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "qemu/option.h" +#include "qemu/option_int.h" +#include "qemu/config-file.h" #define HASHTABLE_MAX_SIZE 16384@@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int
vnet_hdr_len); Packet *packet_new_nocopy(void *data, int size, intvnet_hdr_len); voidpacket_destroy(void *opaque, void *user_data); voidpacket_destroy_partial(void *opaque, void *user_data);net/colo.h +1
-0+int vnet_driver_check (void *opaque,QemuOpts *opts,Error **errp);#endif /* NET_COLO_H */ net/filter-mirror.c index renamed from net/filter-mirror.c +0
-0
f20240cc9f..69ca9c9839100644net/filter-mirror.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "net/filter.h" #include "net/net.h" +#include "net/colo.h" #include "qapi/error.h" #include "qom/object.h" #include "qemu/main-loop.h" @@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf,Error **errp)
net/filter-mirror.c static void filter_redirector_setup(NetFilterState
Quoted 16 lines
net/filter-mirror.c +10
-0return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter mirror needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +qemu_chr_fe_init (&s->chr_out, chr, errp); }@@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState*nf, Error **errp)
Quoted 25 lines
net/filter-mirror.c +10
-0} } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter redirector needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +net_socket_rs_init (&s->rs, redirector_rs_finalize, s->vnet_hdr);if (s->indev) {net/filter-rewriter.c index renamed from net/filter-rewriter.c +0
-0
cb3a96cde1..637ef4ce71100644net/filter-rewriter.c +1
-0@@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) {RewriterState *s =FILTER_REWRITER (nf); + if (!s->vnet_hdr &&net/filter-rewriter.c static void colo_rewriter_setup(NetFilterState · line 401
Quoted 10 lines
net/filter-rewriter.c +9
-0+ qemu_opts_foreach(qemu_find_opts("device"), + vnet_driver_check, nf->netdev_id, NULL)) { +/* +* filter rewriter needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } + s->connection_track_table =g_hash_table_new_full(connection_key_hash,
qapi/qom.json line 241
Quoted 8 lines
net/filter-rewriter.c +0
-1connection_key_equal, g_free, diff --git a/qapi/qom.json b/qapi/qom.json index 6d5f4a88e6..442a963ba4100644
qapi/qom.json +0
-0@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used tocommunicate
qapi/qom.json
Quoted 8 lines
qapi/qom.json +5
-0# with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare, although +# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working on +# # @compare_timeout: the maximum time to hold a packet from@primary_in for
Quoted 14 lines
qapi/qom.json +1
-0# comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32', diff --git a/qemu-options.hxb/qemu-options.hx index
83aa59a920..b31ce3c87d100644qemu-options.hx SRST · line 4960
Quoted 4 lines
qemu-options.hx +0
-1@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chard evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@ var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
qemu-options.hx SRST · line 4961
Quoted 2 lines
qemu-options.hx +2
-0+ ``-object + colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
qemu-options.hx SRST · line 4963
Quoted 2 lines
qemu-options.hx +2
-0+ v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify +_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][, m
qemu-options.hx SRST
Quoted 7 lines
qemu-options.hx +2
-1+ ax_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primary packet and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework to do - checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although colo-compare
qemu-options.hx SRST · line 4970
Quoted 6 lines
qemu-options.hx +3
-0+ does not depend on network device directly, netdevid help + colo-compare know what network driver it is working on. In + order to improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.--
Quoted 82 lines · Chen
Quoted 73 lines
-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Sunday, August 22, 2021 12:25 AM
To: Xu, Tao3 <[email protected]>
Cc: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] net/colo: checkvnet_hdr_supportflag when using virtio-netQuoted 1 line · On Thu, 19 Aug 2021 09:27:17 +0800 Tao Xu <[email protected]> wrote:
When COLO use only one
vnet_hdr_supportparameter between COLOnetwork
Quoted 7 lines
filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, check
vnet_hdr_supportflag of COLO network filter and colo-compare.Signed-off-by Tao Xu <[email protected]>Signed-off-by Zhang Chen <[email protected]>Quoted 8 lines
---
Changelog:
v2:
Detect virtio-net driver and applyvnet_hdr_supportautomatically. (Jason)--- net/colo-compare.c | 57+++++++++++++++++++++++++++++++++++++++++++
Quoted 43 lines
net/colo.c | 20 +++++++++++++++ net/colo.h | 4 +++ net/filter-mirror.c | 21 ++++++++++++++++ net/filter-rewriter.c | 10 ++++++++ qapi/qom.json | 6 +++++ qemu-options.hx | 6 +++-- 7 files changed, 122 insertions(+), 2 deletions(-)net/colo-compare.c index renamed from net/colo-compare.c +0
-0
b100e7b51f..870bd05a41100644net/colo-compare.c +20
-0@@ -110,6 +110,7 @@ struct CompareState {char *sec_indev;char *outdev;char *notify_dev; +char *netdev;CharBackend chr_pri_in;CharBackend chr_sec_in;CharBackend chr_out;@@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)return COMPARE_READ_LEN_MAX ; } +static int colo_set_default_netdev (void *opaque,QemuOpts *opts, +Error **errp) { +const char *colo_obj_type, *netdev_from_filter; +char **netdev = (char **)opaque; + + colo_obj_type =qemu_opt_get (opts,"qom-type" ); + +if (colo_obj_type && + (strcmp (colo_obj_type,"filter-mirror" ) ==0 || +strcmp (colo_obj_type,"filter-redirector" ) ==0 || +strcmp (colo_obj_type,"filter-rewriter" ) ==0 )) { + netdev_from_filter =qemu_opt_get (opts,"netdev" ); +if (*netdev ==NULL ) { + *netdev =g_strdup (netdev_from_filter); + }else if (strcmp (*netdev, netdev_from_filter) !=0 ) { +warn_report ("%s is using a different netdev from other COLO " +"component" , colo_obj_type); + } + }Quoted 8 lines
net/colo-compare.c static int compare_chr_can_read(void *opaque) · line 863
Quoted 3 lines
net/colo-compare.c +3
-0+return 0 ; +} +Hi,
This doesn't properly handle the case where there are multiple network devices and one is virtio-net and the other isn't. This would be a regression as this worked fine before.
Quoted 2 lines
No, If have multiple network device this patch just report a warning for it. You can still use virtio-net and others at the same time.
As you see it sets netdev to the first filter's netdev. So if the first netdev is virtio-net and the 2nd is e1000 (for example) it'll see virtio-net first and set *netdev to it for _both_ devices. Then it sees the e1000 and prints the warning, but *netdev is still set to virtio-net. So it'll enable vnet_hdr for e1000 too and segfault when processing a packet because e1000 doesn't support vnet_hdr.
Quoted 259 lines
Quoted 53 lines
net/colo-compare.c static void
Quoted 38 lines
net/colo-compare.c +20
-0/* * Called from the main thread on the primary for packets * arriving over the socket from the primary. @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object *obj, s->vnet_hdr = value; } +static char *compare_get_netdev (Object *obj,Error **errp) { +CompareState *s =COLO_COMPARE (obj); + +return g_strdup (s->netdev); +} + +static void compare_set_netdev (Object *obj,const char *value,Error +**errp) { +CompareState *s =COLO_COMPARE (obj); + +g_free (s->netdev); + s->netdev =g_strdup (value); +} +static char *compare_get_notify_dev (Object *obj,Error **errp) { CompareState *s = COLO_COMPARE(obj); @@ -1274,6 +1312,12 @@static void colo_compare_complete (UserCreatable *uc,Error **errp) max_queue_size =MAX_QUEUE_SIZE ; } +if (!s->netdev) { +/* Set default netdev as the first colo netfilter found */ +qemu_opts_foreach (qemu_find_opts ("object" ), + colo_set_default_netdev, &s->netdev,NULL ); + } +if (find_and_check_chardev (&chr, s->pri_indev, errp) || !qemu_chr_fe_init (&s->chr_pri_in, chr, errp)) {return ;@@ -1289,6 +1333,16 @@ static void
colo_compare_complete(UserCreatable *uc, Error **errp)net/colo-compare.c static void colo_compare_complete(UserCreatable *uc, Error **errp) · line 1345
Quoted 13 lines
net/colo-compare.c +10
-0return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, s->netdev,NULL )) { +/* +* colo compare needs 'vnet_hdr_support' when it works on virtio-net, +* add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +Quoted 1 line
There is no way to disable
vnet_hdr_supportwith virtio-net now.Yes, It looks no reason to do this.
Please show me some details?Thanks
ChenQuoted 197 lines
net/colo-compare.c static void colo_compare_init(Object *obj) · line 1455
Quoted 8 lines
net/colo-compare.c +0
-0net_socket_rs_init (&s->pri_rs, compare_pri_rs_finalize, s->vnet_hdr);net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);@@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj) s->vnet_hdr = false; object_property_add_bool(obj, "vnet_hdr_support",
compare_get_vnet_hdr,net/filter-mirror.c static void filter_mirror_setup(NetFilterState *nf,
Quoted 70 lines
net/colo-compare.c +3
-0compare_set_vnet_hdr); +/* colo compare can't varify that netdev is correct */ +object_property_add_str (obj,"netdev" , compare_get_netdev, + compare_set_netdev); }void colo_compare_cleanup (void )net/colo.c +20
-0@@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table, return conn ? true : false; } + +/* check the network driver related to COLO, return 1 if it is +virtio-net */ int vnet_driver_check (void *opaque,QemuOpts *opts, +Error **errp) { +const char *driver_type, *netdev_from_driver; +char *netdev_from_filter = (char *)opaque; + + driver_type =qemu_opt_get (opts,"driver" ); + netdev_from_driver =qemu_opt_get (opts,"netdev" ); + +if (!driver_type || !netdev_from_driver || !netdev_from_filter) { +return 0 ; + } + +if (g_str_has_prefix (driver_type,"virtio-net" ) && +strcmp (netdev_from_driver, netdev_from_filter) ==0 ) { +return 1 ; + } +return 0 ; +}net/colo.h +3
-0@@ -18,6 +18,9 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "qemu/option.h" +#include "qemu/option_int.h" +#include "qemu/config-file.h" #define HASHTABLE_MAX_SIZE 16384@@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size, int
vnet_hdr_len); Packet *packet_new_nocopy(void *data, int size, intvnet_hdr_len); voidpacket_destroy(void *opaque, void *user_data); voidpacket_destroy_partial(void *opaque, void *user_data);net/colo.h +1
-0+int vnet_driver_check (void *opaque,QemuOpts *opts,Error **errp);#endif /* NET_COLO_H */ net/filter-mirror.c index renamed from net/filter-mirror.c +0
-0
f20240cc9f..69ca9c9839100644net/filter-mirror.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "net/filter.h" #include "net/net.h" +#include "net/colo.h" #include "qapi/error.h" #include "qom/object.h" #include "qemu/main-loop.h" @@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf,Error **errp)
net/filter-mirror.c static void filter_redirector_setup(NetFilterState
Quoted 16 lines
net/filter-mirror.c +10
-0return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter mirror needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +qemu_chr_fe_init (&s->chr_out, chr, errp); }@@ -252,6 +263,16 @@ static void filter_redirector_setup(NetFilterState*nf, Error **errp)
Quoted 25 lines
net/filter-mirror.c +10
-0} } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter redirector needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +net_socket_rs_init (&s->rs, redirector_rs_finalize, s->vnet_hdr);if (s->indev) {net/filter-rewriter.c index renamed from net/filter-rewriter.c +0
-0
cb3a96cde1..637ef4ce71100644net/filter-rewriter.c +1
-0@@ -388,6 +388,16 @@ static void colo_rewriter_setup(NetFilterState *nf, Error **errp) {RewriterState *s =FILTER_REWRITER (nf); + if (!s->vnet_hdr &&net/filter-rewriter.c static void colo_rewriter_setup(NetFilterState · line 401
Quoted 10 lines
net/filter-rewriter.c +9
-0+ qemu_opts_foreach(qemu_find_opts("device"), + vnet_driver_check, nf->netdev_id, NULL)) { +/* +* filter rewriter needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } + s->connection_track_table =g_hash_table_new_full(connection_key_hash,
qapi/qom.json line 241
Quoted 8 lines
net/filter-rewriter.c +0
-1connection_key_equal, g_free, diff --git a/qapi/qom.json b/qapi/qom.json index 6d5f4a88e6..442a963ba4100644
qapi/qom.json +0
-0@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used tocommunicate
qapi/qom.json
Quoted 8 lines
qapi/qom.json +5
-0# with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare, although +# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working on +# # @compare_timeout: the maximum time to hold a packet from@primary_in for
Quoted 14 lines
qapi/qom.json +1
-0# comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32', diff --git a/qemu-options.hxb/qemu-options.hx index
83aa59a920..b31ce3c87d100644qemu-options.hx SRST · line 4960
Quoted 4 lines
qemu-options.hx +0
-1@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark. - ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=chard evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout=@ var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
qemu-options.hx SRST · line 4961
Quoted 2 lines
qemu-options.hx +2
-0+ ``-object + colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
qemu-options.hx SRST · line 4963
Quoted 2 lines
qemu-options.hx +2
-0+ v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,notify +_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][, m
qemu-options.hx SRST
Quoted 7 lines
qemu-options.hx +2
-1+ ax_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primary packet and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework to do - checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although colo-compare
Quoted 6 lines
qemu-options.hx +3
-0+ does not depend on network device directly, netdevid help + colo-compare know what network driver it is working on. In + order to improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.
Quoted 99 lines
-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Sunday, September 5, 2021 7:48 PM
To: Zhang, Chen <[email protected]>
Cc: Xu, Tao3 <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] net/colo: checkvnet_hdr_supportflag when using virtio-netQuoted 82 lines · Chen
Quoted 73 lines
-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Sunday, August 22, 2021 12:25 AM
To: Xu, Tao3 <[email protected]>
Cc: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] net/colo: checkvnet_hdr_supportflag when using virtio-netQuoted 1 line · On Thu, 19 Aug 2021 09:27:17 +0800 Tao Xu <[email protected]> wrote:
When COLO use only one
vnet_hdr_supportparameter between COLOnetwork
Quoted 7 lines
filter(filter-mirror, filter-redirector or filter-rewriter and colo-compare, packet will not be parsed correctly. Acquire network driver related to COLO, if it is nirtio-net, check
vnet_hdr_supportflag of COLO network filter and colo-compare.Signed-off-by Tao Xu <[email protected]>Signed-off-by Zhang Chen <[email protected]>Quoted 8 lines
---
Changelog:
v2:
Detect virtio-net driver and applyvnet_hdr_supportautomatically. (Jason)--- net/colo-compare.c | 57+++++++++++++++++++++++++++++++++++++++++++
Quoted 43 lines
net/colo.c | 20 +++++++++++++++ net/colo.h | 4 +++ net/filter-mirror.c | 21 ++++++++++++++++ net/filter-rewriter.c | 10 ++++++++ qapi/qom.json | 6 +++++ qemu-options.hx | 6 +++-- 7 files changed, 122 insertions(+), 2 deletions(-)net/colo-compare.c index renamed from net/colo-compare.c +0
-0
b100e7b51f..870bd05a41100644net/colo-compare.c +20
-0@@ -110,6 +110,7 @@ struct CompareState {char *sec_indev;char *outdev;char *notify_dev; +char *netdev;CharBackend chr_pri_in;CharBackend chr_sec_in;CharBackend chr_out;@@ -838,6 +839,28 @@ static int compare_chr_can_read(void *opaque)return COMPARE_READ_LEN_MAX ; } +static int colo_set_default_netdev (void *opaque,QemuOpts *opts, +Error **errp) { +const char *colo_obj_type, *netdev_from_filter; +char **netdev = (char **)opaque; + + colo_obj_type =qemu_opt_get (opts,"qom-type" ); + +if (colo_obj_type && + (strcmp (colo_obj_type,"filter-mirror" ) ==0 || +strcmp (colo_obj_type,"filter-redirector" ) ==0 || +strcmp (colo_obj_type,"filter-rewriter" ) ==0 )) { + netdev_from_filter =qemu_opt_get (opts,"netdev" ); +if (*netdev ==NULL ) { + *netdev =g_strdup (netdev_from_filter); + }else if (strcmp (*netdev, netdev_from_filter) !=0 ) { +warn_report ("%s is using a different netdev from other COLO " +"component" , colo_obj_type); + } + }Quoted 8 lines
net/colo-compare.c static int compare_chr_can_read(void *opaque) · line 863
Quoted 3 lines
net/colo-compare.c +3
-0+return 0 ; +} +Hi,
This doesn't properly handle the case where there are multiple network devices and one is virtio-net and the other isn't. This would be a regression as this worked fine before.Quoted 2 lines
No, If have multiple network device this patch just report a warning for it. You can still use virtio-net and others at the same time.
Quoted 6 lines
As you see it sets netdev to the first filter's netdev. So if the first netdev is virtio-net and the 2nd is e1000 (for example) it'll see virtio-net first and set *netdev to it for _both_ devices. Then it sees the e1000 and prints the warning, but *netdev is still set to virtio-net. So it'll enable
vnet_hdrfor e1000 too and segfault when processing a packet because e1000 doesn't supportvnet_hdr.
Hi Lukas,
Thanks your review~ This patch just focus on colo-compare and net-filter's vnet_hdr flag, not related to real netdev's flag (like e1000 vnet_hdr).
So, we can't setup the vnet_hdr to e1000 at any time.
Back to this question, If the first filter's netdev is virtio-net, we will set the "*netdev" in colo-compare module,
As we know, The colo-compare module won't really attach to any netdev, the "*netdev" just a flag to show we have a related filter used virtio-net. We'd better to enable other filter's flag to make all colo-proxy works. And the filter module with e1000, we haven't enough information to repair.
Thanks
Chen
Quoted 288 lines
Quoted 6 lines
Quoted 6 lines
net/colo-compare.c static void compare_set_vnet_hdr(Object
Quoted 6 lines
net/colo-compare.c +0
-0/* * Called from the main thread on the primary for packets * arriving over the socket from the primary. @@ -1050,6 +1073,21 @@ static void compare_set_vnet_hdr(Object*obj,
Quoted 35 lines
Quoted 35 lines
net/colo-compare.c static void
Quoted 34 lines
net/colo-compare.c +15
-0s->vnet_hdr = value; } +static char *compare_get_netdev (Object *obj,Error **errp) { +CompareState *s =COLO_COMPARE (obj); + +return g_strdup (s->netdev); +} + +static void compare_set_netdev (Object *obj,const char *value, +Error +**errp) { +CompareState *s =COLO_COMPARE (obj); + +g_free (s->netdev); + s->netdev =g_strdup (value); +} +static char *compare_get_notify_dev (Object *obj,Error **errp) { CompareState *s = COLO_COMPARE(obj); @@ -1274,6 +1312,12 @@static void colo_compare_complete (UserCreatable *uc,Error **errp)max_queue_size = MAX_QUEUE_SIZE; }net/colo-compare.c +6
-0+if (!s->netdev) { +/* Set default netdev as the first colo netfilter found */ +qemu_opts_foreach (qemu_find_opts ("object" ), + colo_set_default_netdev, &s->netdev,NULL ); + } +if (find_and_check_chardev (&chr, s->pri_indev, errp) || !qemu_chr_fe_init (&s->chr_pri_in, chr, errp)) {return ;@@ -1289,6 +1333,16 @@ static void
colo_compare_complete(UserCreatable *uc, Error **errp)Quoted 8 lines
Quoted 8 lines
net/colo-compare.c static void colo_compare_complete(UserCreatable *uc, Error **errp)
Quoted 8 lines
net/colo-compare.c +5
-0return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, s->netdev,NULL )) { +/* +* colo compare needs 'vnet_hdr_support' when it works on virtio-net,
Quoted 11 lines
Quoted 7 lines
net/colo-compare.c static void colo_compare_complete(UserCreatable *uc, Error **errp) · line 1345
Quoted 5 lines
net/colo-compare.c +5
-0+* add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +There is no way to disable
vnet_hdr_supportwith virtio-net now.Yes, It looks no reason to do this.
Please show me some details?Quoted 113 lines
Thanks
ChenQuoted 2 lines
net/colo-compare.c static void · line 1346
Quoted 2 lines
net/colo-compare.c +0
-0net_socket_rs_init(&s->pri_rs, compare_pri_rs_finalize, s-
vnet_hdr);Quoted 107 lines
net/colo-compare.c static void colo_compare_init(Object *obj) · line 1455
Quoted 6 lines
net/colo-compare.c +0
-0net_socket_rs_init (&s->sec_rs, compare_sec_rs_finalize, s->vnet_hdr);@@ -1400,6 +1454,9 @@ static void colo_compare_init(Object *obj) s->vnet_hdr = false; object_property_add_bool(obj, "vnet_hdr_support",
compare_get_vnet_hdr,Quoted 72 lines
net/colo-compare.c +3
-0compare_set_vnet_hdr); +/* colo compare can't varify that netdev is correct */ +object_property_add_str (obj,"netdev" , compare_get_netdev, + compare_set_netdev); }void colo_compare_cleanup (void )net/colo.c index 3a3e6e89a0..4a03780f45 renamed from net/colo.c +0
-0100644
net/colo.c +20
-0@@ -243,3 +243,23 @@ bool connection_has_tracked(GHashTable *connection_track_table, return conn ? true : false; } + +/* check the network driver related to COLO, return 1 if it is +virtio-net */ int vnet_driver_check (void *opaque,QemuOpts *opts, +Error **errp) { +const char *driver_type, *netdev_from_driver; +char *netdev_from_filter = (char *)opaque; + + driver_type =qemu_opt_get (opts,"driver" ); + netdev_from_driver =qemu_opt_get (opts,"netdev" ); + +if (!driver_type || !netdev_from_driver || !netdev_from_filter) { +return 0 ; + } + +if (g_str_has_prefix (driver_type,"virtio-net" ) && +strcmp (netdev_from_driver, netdev_from_filter) ==0 ) { +return 1 ; + } +return 0 ; +}net/colo.h index d91cd245c4..d401fc76b6 renamed from net/colo.h +0
-0100644
net/colo.h +3
-0@@ -18,6 +18,9 @@#include "qemu/jhash.h" #include "qemu/timer.h" #include "net/eth.h" +#include "qemu/option.h" +#include "qemu/option_int.h" +#include "qemu/config-file.h" #define HASHTABLE_MAX_SIZE 16384@@ -104,5 +107,6 @@ Packet *packet_new(const void *data, int size,int
vnet_hdr_len); Packet *packet_new_nocopy(void *data, int size, intvnet_hdr_len); voidpacket_destroy(void *opaque, void *user_data); voidpacket_destroy_partial(void *opaque, void *user_data);net/colo.h +2
-0+int vnet_driver_check (void *opaque,QemuOpts *opts,Error +**errp);#endif /* NET_COLO_H */ net/filter-mirror.c index renamed from net/filter-mirror.c +0
-0
f20240cc9f..69ca9c9839100644net/filter-mirror.c +1
-0@@ -12,6 +12,7 @@#include "qemu/osdep.h" #include "net/filter.h" #include "net/net.h" +#include "net/colo.h" #include "qapi/error.h" #include "qom/object.h" #include "qemu/main-loop.h" net/filter-mirror.c static void · line 225
Quoted 1 line
net/filter-mirror.c +0
-0@@ -224,6 +225,16 @@ static void filter_mirror_setup(NetFilterState *nf,Error **errp)
Quoted 16 lines
net/filter-mirror.c +10
-0return ; } +if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter mirror needs 'vnet_hdr_support' when colo filter modules +* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } +qemu_chr_fe_init (&s->chr_out, chr, errp); }@@ -252,6 +263,16 @@ static voidQuoted 1 line
filter_redirector_setup(NetFilterState
*nf, Error **errp)
Quoted 8 lines
} }net/filter-mirror.c +5
-0+if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter redirector needs 'vnet_hdr_support' when colo filter modules
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
net/filter-mirror.c +5
-0+* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } + net_socket_rs_init(&s->rs, redirector_rs_finalize,
s->vnet_hdr);if (s->indev) {net/filter-rewriter.c index renamed from net/filter-rewriter.c +0
-0
cb3a96cde1..637ef4ce71100644net/filter-rewriter.c +0
-0@@ -388,6 +388,16 @@ static voidcolo_rewriter_setup(NetFilterState
*nf, Error **errp) { RewriterState *s = FILTER_REWRITER(nf);Quoted 5 lines
Quoted 5 lines
net/filter-rewriter.c
Quoted 5 lines
net/filter-rewriter.c +5
-0+if (!s->vnet_hdr && +qemu_opts_foreach (qemu_find_opts ("device" ), + vnet_driver_check, nf->netdev_id,NULL )) { +/* +* filter rewriter needs 'vnet_hdr_support' when colo filter modules
Quoted 17 lines
Quoted 17 lines
net/filter-rewriter.c
Quoted 6 lines
net/filter-rewriter.c +5
-0+* work on virtio-net, add 'vnet_hdr_support' automatically +*/ + s->vnet_hdr = true; + } + s->connection_track_table =g_hash_table_new_full(connection_key_hash,
qapi/qom.json line 241
Quoted 9 lines
connection_key_equal, g_free,qapi/qom.json index renamed from qapi/qom.json +0
-0
6d5f4a88e6..442a963ba4
100644qapi/qom.json +0
-0@@ -241,6 +241,11 @@ # @notify_dev: name of the character device backend to be used tocommunicate
Quoted 3 lines
Quoted 3 lines
qapi/qom.json
Quoted 3 lines
qapi/qom.json +1
-0# with the remote colo-frame (only for Xen COLO) # +# @netdev: id of the network device backend to colo-compare,although
Quoted 24 lines
Quoted 24 lines
qapi/qom.json
Quoted 5 lines
qapi/qom.json +4
-0+# colo-compare doesn't depend on network device directly, this +# parameter help colo-compare know what network driver it is +# working on +# # @compare_timeout: the maximum time to hold a packet from@primary_in for
Quoted 18 lines
qapi/qom.json +1
-0# comparison with an incoming packet on @secondary_in in # milliseconds (default: 3000)@@ -264,6 +269,7 @@ 'outdev': 'str', 'iothread': 'str', '*notify_dev': 'str', + '*netdev': 'str', '*compare_timeout': 'uint64', '*expired_scan_cycle': 'uint32', '*max_queue_size': 'uint32', diff --gita/qemu-options.hx b/qemu-options.hx index
83aa59a920..b31ce3c87d100644qemu-options.hx +0
-0@@ -4957,12 +4957,14 @@ SRST stored. The file format is libpcap, so it can be analyzed with tools such as tcpdump or Wireshark.Quoted 2 lines
Quoted 2 lines
qemu-options.hx SRST · line 4960
Quoted 1 line
qemu-options.hx +0
-1- ``-object colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outdev=cha
Quoted 4 lines
Quoted 4 lines
rd evid,iothread=id[,vnet_hdr_support][,notify_dev=id][,compare_timeout =@
var{ms}][,expired_scan_cycle=@var{ms}][,max_queue_size=@var{size}]``
Quoted 7 lines
Quoted 7 lines
qemu-options.hx SRST · line 4961
Quoted 2 lines
qemu-options.hx +2
-0+ ``-object + colo-compare,id=id,primary_in=chardevid,secondary_in=chardevid,outde
Quoted 3 lines
qemu-options.hx +3
-0+ v=chardevid,iothread=id[,netdev=netdevid][,vnet_hdr_support][,no + tify +_dev=id][,compare_timeout=@var{ms}][,expired_scan_cycle=@var{ms}][,
Quoted 4 lines
Quoted 4 lines
m
Quoted 3 lines
qemu-options.hx +1
-0+ ax_queue_size=@var{size}]`` Colo-compare gets packet from primary\_in chardevid and secondary\_in, then compare whether the payload of primarypacket
Quoted 2 lines
Quoted 2 lines
qemu-options.hx SRST · line 4969
Quoted 2 lines
qemu-options.hx +0
-0and secondary packet are the same. If same, it will output primary packet to out\_dev, else it will notify COLO-framework todo
Quoted 13 lines
Quoted 13 lines
qemu-options.hx SRST
Quoted 3 lines
qemu-options.hx +2
-1- checkpoint and send primary packet to out\_dev. In order to + checkpoint and send primary packet to out\_dev. Although + colo-compare
Quoted 6 lines
qemu-options.hx +3
-0+ does not depend on network device directly, netdevid help + colo-compare know what network driver it is working on. + In order to improve efficiency, we need to put the task of comparison in another iothread. If it has the vnet\_hdr\_support flag, colo compare will send/recv packet with vnet\_hdr\_len.Quoted 2 lines
Quoted 1 line
--
--