* [PATCH V2 1/7] qapi/net.json: Add IP_PROTOCOL definition
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
2021-03-03 4:15 ` [PATCH V2 2/7] qapi/net.json: Add L4_Connection definition Zhang Chen
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP commands.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
qapi/net.json | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/qapi/net.json b/qapi/net.json
index c31748c87f..dc4c87dc7b 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -714,3 +714,33 @@
##
{ 'event': 'FAILOVER_NEGOTIATED',
'data': {'device-id': 'str'} }
+
+##
+# @IP_PROTOCOL:
+#
+# Transport layer protocol.
+#
+# Just for IPv4.
+#
+# @tcp: Transmission Control Protocol.
+#
+# @udp: User Datagram Protocol.
+#
+# @dccp: Datagram Congestion Control Protocol.
+#
+# @sctp: Stream Control Transmission Protocol.
+#
+# @udplite: Lightweight User Datagram Protocol.
+#
+# @icmp: Internet Control Message Protocol.
+#
+# @igmp: Internet Group Management Protocol.
+#
+# @ipv6: IPv6 Encapsulation.
+#
+# TODO: Need to add more transport layer protocol.
+#
+# Since: 6.0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+ 'icmp', 'igmp', 'ipv6' ] }
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH V2 2/7] qapi/net.json: Add L4_Connection definition
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
2021-03-03 4:15 ` [PATCH V2 1/7] qapi/net.json: Add IP_PROTOCOL definition Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
2021-03-03 4:15 ` [PATCH V2 3/7] qapi/net: Add new QMP command for COLO passthrough Zhang Chen
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Add L4_Connection struct for other QMP commands.
Except protocol field is necessary, other fields are optional.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
qapi/net.json | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/qapi/net.json b/qapi/net.json
index dc4c87dc7b..b4958447f2 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -744,3 +744,29 @@
##
{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
'icmp', 'igmp', 'ipv6' ] }
+
+##
+# @L4_Connection:
+#
+# Layer 4 network connection.
+#
+# Just for IPv4.
+#
+# @protocol: Transport layer protocol like TCP/UDP...
+#
+# @id: For specific module with Qemu object ID, If there is no such part,
+# it means global rules.
+#
+# @src_ip: Source IP.
+#
+# @dst_ip: Destination IP.
+#
+# @src_port: Source port.
+#
+# @dst_port: Destination port.
+#
+# Since: 6.0
+##
+{ 'struct': 'L4_Connection',
+ 'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
+ '*src_port': 'int', '*dst_port': 'int' } }
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH V2 3/7] qapi/net: Add new QMP command for COLO passthrough
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
2021-03-03 4:15 ` [PATCH V2 1/7] qapi/net.json: Add IP_PROTOCOL definition Zhang Chen
2021-03-03 4:15 ` [PATCH V2 2/7] qapi/net.json: Add L4_Connection definition Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
2021-03-03 4:15 ` [PATCH V2 4/7] hmp-commands: Add new HMP " Zhang Chen
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Since the real user scenario does not need COLO to monitor all traffic.
Add colo-passthrough-add and colo-passthrough-del to maintain
a COLO network passthrough list.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
net/net.c | 10 ++++++++++
qapi/net.json | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/net/net.c b/net/net.c
index e1035f21d1..037dcc5973 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1151,6 +1151,16 @@ void qmp_netdev_del(const char *id, Error **errp)
qemu_del_net_client(nc);
}
+void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp)
+{
+ /* Setup passthrough connection */
+}
+
+void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp)
+{
+ /* Delete passthrough connection */
+}
+
static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
{
char *str;
diff --git a/qapi/net.json b/qapi/net.json
index b4958447f2..e0c6e1d8f3 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -770,3 +770,43 @@
{ 'struct': 'L4_Connection',
'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
'*src_port': 'int', '*dst_port': 'int' } }
+
+##
+# @colo-passthrough-add:
+#
+# Add passthrough entry according to customer's needs in COLO-compare.
+#
+# Returns: Nothing on success
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-add",
+# "arguments": { "protocol": "tcp", "id": "object0", "src_ip": "192.168.1.1",
+# "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'colo-passthrough-add', 'boxed': true,
+ 'data': 'L4_Connection' }
+
+##
+# @colo-passthrough-del:
+#
+# Delete passthrough entry according to customer's needs in COLO-compare.
+#
+# Returns: Nothing on success
+#
+# Since: 6.0
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-del",
+# "arguments": { "protocol": "tcp", "id": "object0", "src_ip": "192.168.1.1",
+# "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'colo-passthrough-del', 'boxed': true,
+ 'data': 'L4_Connection' }
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH V2 4/7] hmp-commands: Add new HMP command for COLO passthrough
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
` (2 preceding siblings ...)
2021-03-03 4:15 ` [PATCH V2 3/7] qapi/net: Add new QMP command for COLO passthrough Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
2021-03-03 4:15 ` [PATCH V2 5/7] net/colo-compare: Move data structure and define to .h file Zhang Chen
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Add hmp_colo_passthrough_add and hmp_colo_passthrough_del make user
can maintain COLO network passthrough list in human monitor.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
hmp-commands.hx | 26 ++++++++++++++++++++++++++
include/monitor/hmp.h | 2 ++
monitor/hmp-cmds.c | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 62 insertions(+)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 73e0832ea1..c71521303c 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1341,6 +1341,32 @@ SRST
Remove host network device.
ERST
+ {
+ .name = "colo_passthrough_add",
+ .args_type = "protocol:s,id:s?,src_ip:s?,dst_ip:s?,src_port:i?,dst_port:i?",
+ .params = "protocol [id] [src_ip] [dst_ip] [src_port] [dst_port]",
+ .help = "Add network stream to colo passthrough list",
+ .cmd = hmp_colo_passthrough_add,
+ },
+
+SRST
+``colo_passthrough_add``
+ Add network stream to colo passthrough list.
+ERST
+
+ {
+ .name = "colo_passthrough_del",
+ .args_type = "protocol:s,id:s?,src_ip:s?,dst_ip:s?,src_port:i?,dst_port:i?",
+ .params = "protocol [id] [src_ip] [dst_ip] [src_port] [dst_port]",
+ .help = "Delete network stream from colo passthrough list",
+ .cmd = hmp_colo_passthrough_del,
+ },
+
+SRST
+``colo_passthrough_del``
+ Delete network stream from colo passthrough list.
+ERST
+
{
.name = "object_add",
.args_type = "object:O",
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index ed2913fd18..3c4943b09f 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -81,6 +81,8 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);
void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
void hmp_netdev_add(Monitor *mon, const QDict *qdict);
void hmp_netdev_del(Monitor *mon, const QDict *qdict);
+void hmp_colo_passthrough_add(Monitor *mon, const QDict *qdict);
+void hmp_colo_passthrough_del(Monitor *mon, const QDict *qdict);
void hmp_getfd(Monitor *mon, const QDict *qdict);
void hmp_closefd(Monitor *mon, const QDict *qdict);
void hmp_sendkey(Monitor *mon, const QDict *qdict);
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index fd4d77e246..de675d16e7 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -1660,6 +1660,40 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
hmp_handle_error(mon, err);
}
+void hmp_colo_passthrough_add(Monitor *mon, const QDict *qdict)
+{
+ const char *prot = qdict_get_str(qdict, "protocol");
+ L4_Connection *l4_conn = g_new0(L4_Connection, 1);
+ Error *err = NULL;
+
+ l4_conn->id = g_strdup(qdict_get_try_str(qdict, "id"));
+ l4_conn->protocol = qapi_enum_parse(&IP_PROTOCOL_lookup, prot, -1, &err);
+ l4_conn->src_ip = g_strdup(qdict_get_try_str(qdict, "src_ip"));
+ l4_conn->dst_ip = g_strdup(qdict_get_try_str(qdict, "dst_ip"));
+ l4_conn->src_port = qdict_get_try_int(qdict, "src_port", 0);
+ l4_conn->dst_port = qdict_get_try_int(qdict, "dst_port", 0);
+
+ qmp_colo_passthrough_add(l4_conn, &err);
+ hmp_handle_error(mon, err);
+}
+
+void hmp_colo_passthrough_del(Monitor *mon, const QDict *qdict)
+{
+ const char *prot = qdict_get_str(qdict, "protocol");
+ L4_Connection *l4_conn = g_new0(L4_Connection, 1);
+ Error *err = NULL;
+
+ l4_conn->id = g_strdup(qdict_get_try_str(qdict, "id"));
+ l4_conn->protocol = qapi_enum_parse(&IP_PROTOCOL_lookup, prot, -1, &err);
+ l4_conn->src_ip = g_strdup(qdict_get_try_str(qdict, "src_ip"));
+ l4_conn->dst_ip = g_strdup(qdict_get_try_str(qdict, "dst_ip"));
+ l4_conn->src_port = qdict_get_try_int(qdict, "src_port", 0);
+ l4_conn->dst_port = qdict_get_try_int(qdict, "dst_port", 0);
+
+ qmp_colo_passthrough_del(l4_conn, &err);
+ hmp_handle_error(mon, err);
+}
+
void hmp_object_add(Monitor *mon, const QDict *qdict)
{
Error *err = NULL;
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH V2 5/7] net/colo-compare: Move data structure and define to .h file.
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
` (3 preceding siblings ...)
2021-03-03 4:15 ` [PATCH V2 4/7] hmp-commands: Add new HMP " Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
2021-03-03 4:15 ` [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState Zhang Chen
2021-03-03 4:15 ` [PATCH V2 7/7] net/net.c: Add handler for COLO passthrough connection Zhang Chen
6 siblings, 0 replies; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Make other modules can reuse COLO code.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
net/colo-compare.c | 106 ---------------------------------------------
net/colo-compare.h | 106 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 106 insertions(+), 106 deletions(-)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 84db4978ac..a803f8b888 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -17,44 +17,24 @@
#include "qemu/error-report.h"
#include "trace.h"
#include "qapi/error.h"
-#include "net/net.h"
#include "net/eth.h"
#include "qom/object_interfaces.h"
#include "qemu/iov.h"
#include "qom/object.h"
#include "net/queue.h"
-#include "chardev/char-fe.h"
#include "qemu/sockets.h"
-#include "colo.h"
-#include "sysemu/iothread.h"
#include "net/colo-compare.h"
-#include "migration/colo.h"
-#include "migration/migration.h"
#include "util.h"
#include "block/aio-wait.h"
#include "qemu/coroutine.h"
-#define TYPE_COLO_COMPARE "colo-compare"
-typedef struct CompareState CompareState;
-DECLARE_INSTANCE_CHECKER(CompareState, COLO_COMPARE,
- TYPE_COLO_COMPARE)
-
static QTAILQ_HEAD(, CompareState) net_compares =
QTAILQ_HEAD_INITIALIZER(net_compares);
static NotifierList colo_compare_notifiers =
NOTIFIER_LIST_INITIALIZER(colo_compare_notifiers);
-#define COMPARE_READ_LEN_MAX NET_BUFSIZE
-#define MAX_QUEUE_SIZE 1024
-
-#define COLO_COMPARE_FREE_PRIMARY 0x01
-#define COLO_COMPARE_FREE_SECONDARY 0x02
-
-#define REGULAR_PACKET_CHECK_MS 1000
-#define DEFAULT_TIME_OUT_MS 3000
-
/* #define DEBUG_COLO_PACKETS */
static QemuMutex colo_compare_mutex;
@@ -64,92 +44,6 @@ static QemuCond event_complete_cond;
static int event_unhandled_count;
static uint32_t max_queue_size;
-/*
- * + CompareState ++
- * | |
- * +---------------+ +---------------+ +---------------+
- * | conn list + - > conn + ------- > conn + -- > ......
- * +---------------+ +---------------+ +---------------+
- * | | | | | |
- * +---------------+ +---v----+ +---v----+ +---v----+ +---v----+
- * |primary | |secondary |primary | |secondary
- * |packet | |packet + |packet | |packet +
- * +--------+ +--------+ +--------+ +--------+
- * | | | |
- * +---v----+ +---v----+ +---v----+ +---v----+
- * |primary | |secondary |primary | |secondary
- * |packet | |packet + |packet | |packet +
- * +--------+ +--------+ +--------+ +--------+
- * | | | |
- * +---v----+ +---v----+ +---v----+ +---v----+
- * |primary | |secondary |primary | |secondary
- * |packet | |packet + |packet | |packet +
- * +--------+ +--------+ +--------+ +--------+
- */
-
-typedef struct SendCo {
- Coroutine *co;
- struct CompareState *s;
- CharBackend *chr;
- GQueue send_list;
- bool notify_remote_frame;
- bool done;
- int ret;
-} SendCo;
-
-typedef struct SendEntry {
- uint32_t size;
- uint32_t vnet_hdr_len;
- uint8_t *buf;
-} SendEntry;
-
-struct CompareState {
- Object parent;
-
- char *pri_indev;
- char *sec_indev;
- char *outdev;
- char *notify_dev;
- CharBackend chr_pri_in;
- CharBackend chr_sec_in;
- CharBackend chr_out;
- CharBackend chr_notify_dev;
- SocketReadState pri_rs;
- SocketReadState sec_rs;
- SocketReadState notify_rs;
- SendCo out_sendco;
- SendCo notify_sendco;
- bool vnet_hdr;
- uint64_t compare_timeout;
- uint32_t expired_scan_cycle;
-
- /*
- * Record the connection that through the NIC
- * Element type: Connection
- */
- GQueue conn_list;
- /* Record the connection without repetition */
- GHashTable *connection_track_table;
-
- IOThread *iothread;
- GMainContext *worker_context;
- QEMUTimer *packet_check_timer;
-
- QEMUBH *event_bh;
- enum colo_event event;
-
- QTAILQ_ENTRY(CompareState) next;
-};
-
-typedef struct CompareClass {
- ObjectClass parent_class;
-} CompareClass;
-
-enum {
- PRIMARY_IN = 0,
- SECONDARY_IN,
-};
-
static const char *colo_mode[] = {
[PRIMARY_IN] = "primary",
[SECONDARY_IN] = "secondary",
diff --git a/net/colo-compare.h b/net/colo-compare.h
index 22ddd512e2..2a9dcac0a7 100644
--- a/net/colo-compare.h
+++ b/net/colo-compare.h
@@ -17,6 +17,112 @@
#ifndef QEMU_COLO_COMPARE_H
#define QEMU_COLO_COMPARE_H
+#include "net/net.h"
+#include "chardev/char-fe.h"
+#include "migration/colo.h"
+#include "migration/migration.h"
+#include "sysemu/iothread.h"
+#include "colo.h"
+
+#define TYPE_COLO_COMPARE "colo-compare"
+typedef struct CompareState CompareState;
+DECLARE_INSTANCE_CHECKER(CompareState, COLO_COMPARE,
+ TYPE_COLO_COMPARE)
+
+#define COMPARE_READ_LEN_MAX NET_BUFSIZE
+#define MAX_QUEUE_SIZE 1024
+
+#define COLO_COMPARE_FREE_PRIMARY 0x01
+#define COLO_COMPARE_FREE_SECONDARY 0x02
+
+#define REGULAR_PACKET_CHECK_MS 1000
+#define DEFAULT_TIME_OUT_MS 3000
+
+typedef struct SendCo {
+ Coroutine *co;
+ struct CompareState *s;
+ CharBackend *chr;
+ GQueue send_list;
+ bool notify_remote_frame;
+ bool done;
+ int ret;
+} SendCo;
+
+typedef struct SendEntry {
+ uint32_t size;
+ uint32_t vnet_hdr_len;
+ uint8_t *buf;
+} SendEntry;
+
+/*
+ * + CompareState ++
+ * | |
+ * +---------------+ +---------------+ +---------------+
+ * | conn list + - > conn + ------- > conn + -- > ......
+ * +---------------+ +---------------+ +---------------+
+ * | | | | | |
+ * +---------------+ +---v----+ +---v----+ +---v----+ +---v----+
+ * |primary | |secondary |primary | |secondary
+ * |packet | |packet + |packet | |packet +
+ * +--------+ +--------+ +--------+ +--------+
+ * | | | |
+ * +---v----+ +---v----+ +---v----+ +---v----+
+ * |primary | |secondary |primary | |secondary
+ * |packet | |packet + |packet | |packet +
+ * +--------+ +--------+ +--------+ +--------+
+ * | | | |
+ * +---v----+ +---v----+ +---v----+ +---v----+
+ * |primary | |secondary |primary | |secondary
+ * |packet | |packet + |packet | |packet +
+ * +--------+ +--------+ +--------+ +--------+
+ */
+struct CompareState {
+ Object parent;
+
+ char *pri_indev;
+ char *sec_indev;
+ char *outdev;
+ char *notify_dev;
+ CharBackend chr_pri_in;
+ CharBackend chr_sec_in;
+ CharBackend chr_out;
+ CharBackend chr_notify_dev;
+ SocketReadState pri_rs;
+ SocketReadState sec_rs;
+ SocketReadState notify_rs;
+ SendCo out_sendco;
+ SendCo notify_sendco;
+ bool vnet_hdr;
+ uint64_t compare_timeout;
+ uint32_t expired_scan_cycle;
+
+ /*
+ * Record the connection that through the NIC
+ * Element type: Connection
+ */
+ GQueue conn_list;
+ /* Record the connection without repetition */
+ GHashTable *connection_track_table;
+
+ IOThread *iothread;
+ GMainContext *worker_context;
+ QEMUTimer *packet_check_timer;
+
+ QEMUBH *event_bh;
+ enum colo_event event;
+
+ QTAILQ_ENTRY(CompareState) next;
+};
+
+typedef struct CompareClass {
+ ObjectClass parent_class;
+} CompareClass;
+
+enum {
+ PRIMARY_IN = 0,
+ SECONDARY_IN,
+};
+
void colo_notify_compares_event(void *opaque, int event, Error **errp);
void colo_compare_register_notifier(Notifier *notify);
void colo_compare_unregister_notifier(Notifier *notify);
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
` (4 preceding siblings ...)
2021-03-03 4:15 ` [PATCH V2 5/7] net/colo-compare: Move data structure and define to .h file Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
2021-03-17 21:15 ` Lukas Straub
2021-03-03 4:15 ` [PATCH V2 7/7] net/net.c: Add handler for COLO passthrough connection Zhang Chen
6 siblings, 1 reply; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Add passthrough list for each CompareState.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
net/colo-compare.c | 25 +++++++++++++++++++++++++
net/colo-compare.h | 10 ++++++++++
2 files changed, 35 insertions(+)
diff --git a/net/colo-compare.c b/net/colo-compare.c
index a803f8b888..80cea32c20 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -141,6 +141,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
ConnectionKey key;
Packet *pkt = NULL;
Connection *conn;
+ PassthroughEntry *bypass, *next;
int ret;
if (mode == PRIMARY_IN) {
@@ -160,6 +161,29 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
}
fill_connection_key(pkt, &key);
+ /* Check COLO passthrough connenction */
+ if (!QLIST_EMPTY(&s->passthroughlist)) {
+ QLIST_FOREACH_SAFE(bypass, &s->passthroughlist, node, next) {
+ if (((key.ip_proto == IPPROTO_TCP) && (bypass->l4_protocol == 0)) ||
+ ((key.ip_proto == IPPROTO_UDP) && (bypass->l4_protocol == 1))) {
+ if (bypass->src_port == 0 || bypass->src_port == key.dst_port) {
+ if (bypass->src_ip.s_addr == 0 ||
+ bypass->src_ip.s_addr == key.src.s_addr) {
+ if (bypass->dst_port == 0 ||
+ bypass->dst_port == key.src_port) {
+ if (bypass->dst_ip.s_addr == 0 ||
+ bypass->dst_ip.s_addr == key.dst.s_addr) {
+ packet_destroy(pkt, NULL);
+ pkt = NULL;
+ return -1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
conn = connection_get(s->connection_track_table,
&key,
&s->conn_list);
@@ -1224,6 +1248,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
}
g_queue_init(&s->conn_list);
+ QLIST_INIT(&s->passthroughlist);
s->connection_track_table = g_hash_table_new_full(connection_key_hash,
connection_key_equal,
diff --git a/net/colo-compare.h b/net/colo-compare.h
index 2a9dcac0a7..31644f145b 100644
--- a/net/colo-compare.h
+++ b/net/colo-compare.h
@@ -54,6 +54,15 @@ typedef struct SendEntry {
uint8_t *buf;
} SendEntry;
+typedef struct PassthroughEntry {
+ int l4_protocol;
+ int src_port;
+ int dst_port;
+ struct in_addr src_ip;
+ struct in_addr dst_ip;
+ QLIST_ENTRY(PassthroughEntry) node;
+} PassthroughEntry;
+
/*
* + CompareState ++
* | |
@@ -110,6 +119,7 @@ struct CompareState {
QEMUBH *event_bh;
enum colo_event event;
+ QLIST_HEAD(, PassthroughEntry) passthroughlist;
QTAILQ_ENTRY(CompareState) next;
};
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState
2021-03-03 4:15 ` [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState Zhang Chen
@ 2021-03-17 21:15 ` Lukas Straub
2021-03-18 1:13 ` Zhang, Chen
0 siblings, 1 reply; 10+ messages in thread
From: Lukas Straub @ 2021-03-17 21:15 UTC (permalink / raw)
To: Zhang Chen
Cc: Jason Wang, Markus Armbruster, qemu-dev, Zhang Chen,
Dr. David Alan Gilbert
[-- Attachment #1: Type: text/plain, Size: 3455 bytes --]
On Wed, 3 Mar 2021 12:15:38 +0800
Zhang Chen <chen.zhang@intel.com > wrote:
> From: Zhang Chen <chen.zhang@intel.com>
>
> Add passthrough list for each CompareState.
>
> Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> ---
> net/colo-compare.c | 25 +++++++++++++++++++++++++
> net/colo-compare.h | 10 ++++++++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index a803f8b888..80cea32c20 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -141,6 +141,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
> ConnectionKey key;
> Packet *pkt = NULL;
> Connection *conn;
> + PassthroughEntry *bypass, *next;
> int ret;
>
> if (mode == PRIMARY_IN) {
> @@ -160,6 +161,29 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
> }
> fill_connection_key(pkt, &key);
>
> + /* Check COLO passthrough connenction */
> + if (!QLIST_EMPTY(&s->passthroughlist)) {
> + QLIST_FOREACH_SAFE(bypass, &s->passthroughlist, node, next) {
> + if (((key.ip_proto == IPPROTO_TCP) && (bypass->l4_protocol == 0)) ||
> + ((key.ip_proto == IPPROTO_UDP) && (bypass->l4_protocol == 1))) {
> + if (bypass->src_port == 0 || bypass->src_port == key.dst_port) {
> + if (bypass->src_ip.s_addr == 0 ||
> + bypass->src_ip.s_addr == key.src.s_addr) {
> + if (bypass->dst_port == 0 ||
> + bypass->dst_port == key.src_port) {
> + if (bypass->dst_ip.s_addr == 0 ||
> + bypass->dst_ip.s_addr == key.dst.s_addr) {
> + packet_destroy(pkt, NULL);
> + pkt = NULL;
> + return -1;
> + }
> + }
> + }
> + }
> + }
> + }
> + }
> +
Hi,
Access to s->passthroughlist still needs to be protected by a lock.
Regards,
Lukas Straub
> conn = connection_get(s->connection_track_table,
> &key,
> &s->conn_list);
> @@ -1224,6 +1248,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
> }
>
> g_queue_init(&s->conn_list);
> + QLIST_INIT(&s->passthroughlist);
>
> s->connection_track_table = g_hash_table_new_full(connection_key_hash,
> connection_key_equal,
> diff --git a/net/colo-compare.h b/net/colo-compare.h
> index 2a9dcac0a7..31644f145b 100644
> --- a/net/colo-compare.h
> +++ b/net/colo-compare.h
> @@ -54,6 +54,15 @@ typedef struct SendEntry {
> uint8_t *buf;
> } SendEntry;
>
> +typedef struct PassthroughEntry {
> + int l4_protocol;
> + int src_port;
> + int dst_port;
> + struct in_addr src_ip;
> + struct in_addr dst_ip;
> + QLIST_ENTRY(PassthroughEntry) node;
> +} PassthroughEntry;
> +
> /*
> * + CompareState ++
> * | |
> @@ -110,6 +119,7 @@ struct CompareState {
>
> QEMUBH *event_bh;
> enum colo_event event;
> + QLIST_HEAD(, PassthroughEntry) passthroughlist;
>
> QTAILQ_ENTRY(CompareState) next;
> };
--
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState
2021-03-17 21:15 ` Lukas Straub
@ 2021-03-18 1:13 ` Zhang, Chen
0 siblings, 0 replies; 10+ messages in thread
From: Zhang, Chen @ 2021-03-18 1:13 UTC (permalink / raw)
To: Lukas Straub
Cc: Jason Wang, Markus Armbruster, qemu-dev, Zhang Chen,
Dr. David Alan Gilbert
> -----Original Message-----
> From: Lukas Straub <lukasstraub2@web.de>
> Sent: Thursday, March 18, 2021 5:16 AM
> To: Zhang, Chen <chen.zhang@intel.com>
> Cc: Jason Wang <jasowang@redhat.com>; qemu-dev <qemu-
> devel@nongnu.org>; Eric Blake <eblake@redhat.com>; Dr. David Alan
> Gilbert <dgilbert@redhat.com>; Markus Armbruster <armbru@redhat.com>;
> Zhang Chen <zhangckid@gmail.com>
> Subject: Re: [PATCH V2 6/7] net/colo-compare: Add passthrough list to
> CompareState
>
> On Wed, 3 Mar 2021 12:15:38 +0800
> Zhang Chen <chen.zhang@intel.com > wrote:
>
> > From: Zhang Chen <chen.zhang@intel.com>
> >
> > Add passthrough list for each CompareState.
> >
> > Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> > ---
> > net/colo-compare.c | 25 +++++++++++++++++++++++++ net/colo-
> compare.h
> > | 10 ++++++++++
> > 2 files changed, 35 insertions(+)
> >
> > diff --git a/net/colo-compare.c b/net/colo-compare.c index
> > a803f8b888..80cea32c20 100644
> > --- a/net/colo-compare.c
> > +++ b/net/colo-compare.c
> > @@ -141,6 +141,7 @@ static int packet_enqueue(CompareState *s, int
> mode, Connection **con)
> > ConnectionKey key;
> > Packet *pkt = NULL;
> > Connection *conn;
> > + PassthroughEntry *bypass, *next;
> > int ret;
> >
> > if (mode == PRIMARY_IN) {
> > @@ -160,6 +161,29 @@ static int packet_enqueue(CompareState *s, int
> mode, Connection **con)
> > }
> > fill_connection_key(pkt, &key);
> >
> > + /* Check COLO passthrough connenction */
> > + if (!QLIST_EMPTY(&s->passthroughlist)) {
> > + QLIST_FOREACH_SAFE(bypass, &s->passthroughlist, node, next) {
> > + if (((key.ip_proto == IPPROTO_TCP) && (bypass->l4_protocol == 0))
> ||
> > + ((key.ip_proto == IPPROTO_UDP) && (bypass->l4_protocol == 1)))
> {
> > + if (bypass->src_port == 0 || bypass->src_port == key.dst_port) {
> > + if (bypass->src_ip.s_addr == 0 ||
> > + bypass->src_ip.s_addr == key.src.s_addr) {
> > + if (bypass->dst_port == 0 ||
> > + bypass->dst_port == key.src_port) {
> > + if (bypass->dst_ip.s_addr == 0 ||
> > + bypass->dst_ip.s_addr == key.dst.s_addr) {
> > + packet_destroy(pkt, NULL);
> > + pkt = NULL;
> > + return -1;
> > + }
> > + }
> > + }
> > + }
> > + }
> > + }
> > + }
> > +
>
> Hi,
> Access to s->passthroughlist still needs to be protected by a lock.
>
OK, will fix it in next version.
Thanks
Chen
> Regards,
> Lukas Straub
>
> > conn = connection_get(s->connection_track_table,
> > &key,
> > &s->conn_list); @@ -1224,6 +1248,7 @@
> > static void colo_compare_complete(UserCreatable *uc, Error **errp)
> > }
> >
> > g_queue_init(&s->conn_list);
> > + QLIST_INIT(&s->passthroughlist);
> >
> > s->connection_track_table =
> g_hash_table_new_full(connection_key_hash,
> >
> > connection_key_equal, diff --git a/net/colo-compare.h
> > b/net/colo-compare.h index 2a9dcac0a7..31644f145b 100644
> > --- a/net/colo-compare.h
> > +++ b/net/colo-compare.h
> > @@ -54,6 +54,15 @@ typedef struct SendEntry {
> > uint8_t *buf;
> > } SendEntry;
> >
> > +typedef struct PassthroughEntry {
> > + int l4_protocol;
> > + int src_port;
> > + int dst_port;
> > + struct in_addr src_ip;
> > + struct in_addr dst_ip;
> > + QLIST_ENTRY(PassthroughEntry) node; } PassthroughEntry;
> > +
> > /*
> > * + CompareState ++
> > * | |
> > @@ -110,6 +119,7 @@ struct CompareState {
> >
> > QEMUBH *event_bh;
> > enum colo_event event;
> > + QLIST_HEAD(, PassthroughEntry) passthroughlist;
> >
> > QTAILQ_ENTRY(CompareState) next;
> > };
>
>
>
> --
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH V2 7/7] net/net.c: Add handler for COLO passthrough connection
2021-03-03 4:15 [PATCH V2 0/7] Bypass specific network traffic in COLO Zhang Chen
` (5 preceding siblings ...)
2021-03-03 4:15 ` [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState Zhang Chen
@ 2021-03-03 4:15 ` Zhang Chen
6 siblings, 0 replies; 10+ messages in thread
From: Zhang Chen @ 2021-03-03 4:15 UTC (permalink / raw)
To: Jason Wang, qemu-dev, Eric Blake, Dr. David Alan Gilbert,
Markus Armbruster, Lukas Straub
Cc: Zhang Chen, Zhang Chen
From: Zhang Chen <chen.zhang@intel.com>
Use connection protocol,src port,dst port,src ip,dst ip as the key
to bypass certain network traffic in COLO compare.
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
---
net/net.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
diff --git a/net/net.c b/net/net.c
index 037dcc5973..bb2fb1d8b5 100644
--- a/net/net.c
+++ b/net/net.c
@@ -55,6 +55,8 @@
#include "sysemu/sysemu.h"
#include "net/filter.h"
#include "qapi/string-output-visitor.h"
+#include "net/colo-compare.h"
+#include "qom/object_interfaces.h"
/* Net bridge is currently not supported for W32. */
#if !defined(_WIN32)
@@ -1151,14 +1153,159 @@ void qmp_netdev_del(const char *id, Error **errp)
qemu_del_net_client(nc);
}
+static CompareState *colo_passthrough_check(L4_Connection *conn, Error **errp)
+{
+ Object *container;
+ Object *obj;
+ CompareState *s;
+
+ if (!conn->id) {
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "id",
+ "Need input colo-compare object id");
+ return NULL;
+ }
+
+ container = object_get_objects_root();
+ obj = object_resolve_path_component(container, conn->id);
+ if (!obj) {
+ error_setg(errp, "colo-compare '%s' not found", conn->id);
+ return NULL;
+ }
+
+ s = COLO_COMPARE(obj);
+
+ if (conn->protocol == -1) {
+ error_setg(errp, "COLO pass through get wrong protocol");
+ return NULL;
+ }
+
+ if ((conn->src_ip && !qemu_isdigit(conn->src_ip[0])) ||
+ (conn->dst_ip && !qemu_isdigit(conn->dst_ip[0]))) {
+ error_setg(errp, "COLO pass through get wrong IP");
+ return NULL;
+ }
+
+ if (conn->src_port > 65536 || conn->src_port < 0 ||
+ conn->dst_port > 65536 || conn->dst_port < 0) {
+ error_setg(errp, "COLO pass through get wrong port");
+ return NULL;
+ }
+
+ return s;
+}
+
+static void compare_passthrough_add(CompareState *s,
+ L4_Connection *conn,
+ Error **errp)
+{
+ PassthroughEntry *bypass = NULL, *next = NULL, *origin = NULL;
+
+ bypass = g_new0(PassthroughEntry, 1);
+
+ bypass->l4_protocol = conn->protocol;
+ bypass->src_port = conn->src_port;
+ bypass->dst_port = conn->dst_port;
+
+ if (!inet_aton(conn->src_ip, &bypass->src_ip)) {
+ bypass->src_ip.s_addr = 0;
+ }
+
+ if (!inet_aton(conn->dst_ip, &bypass->dst_ip)) {
+ bypass->dst_ip.s_addr = 0;
+ }
+
+ if (!QLIST_EMPTY(&s->passthroughlist)) {
+ QLIST_FOREACH_SAFE(origin, &s->passthroughlist, node, next) {
+ if ((bypass->l4_protocol == origin->l4_protocol) &&
+ (bypass->src_port == origin->src_port) &&
+ (bypass->src_ip.s_addr == origin->src_ip.s_addr) &&
+ (bypass->dst_ip.s_addr == origin->dst_ip.s_addr)) {
+ error_setg(errp, "The pass through connection already exists");
+ g_free(bypass);
+ return;
+ }
+ }
+ }
+
+ QLIST_INSERT_HEAD(&s->passthroughlist, bypass, node);
+}
+
+static void compare_passthrough_del(CompareState *s,
+ L4_Connection *conn,
+ Error **errp)
+{
+ PassthroughEntry *bypass = NULL, *next = NULL, *origin = NULL;
+
+ bypass = g_new0(PassthroughEntry, 1);
+
+ bypass->l4_protocol = conn->protocol;
+ bypass->src_port = conn->src_port;
+ bypass->dst_port = conn->dst_port;
+
+ if (!inet_aton(conn->src_ip, &bypass->src_ip)) {
+ bypass->src_ip.s_addr = 0;
+ }
+
+ if (!inet_aton(conn->dst_ip, &bypass->dst_ip)) {
+ bypass->dst_ip.s_addr = 0;
+ }
+
+ if (!QLIST_EMPTY(&s->passthroughlist)) {
+ QLIST_FOREACH_SAFE(origin, &s->passthroughlist, node, next) {
+ if ((bypass->l4_protocol == origin->l4_protocol) &&
+ (bypass->src_port == origin->src_port) &&
+ (bypass->src_ip.s_addr == origin->src_ip.s_addr) &&
+ (bypass->dst_ip.s_addr == origin->dst_ip.s_addr)) {
+ QLIST_REMOVE(origin, node);
+ g_free(origin);
+ g_free(bypass);
+ return;
+ }
+ }
+ error_setg(errp, "The pass through list can't find the connection");
+ } else {
+ error_setg(errp, "The pass through connection list is empty");
+ }
+
+ g_free(bypass);
+}
+
void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp)
{
/* Setup passthrough connection */
+ CompareState *s;
+ Error *err = NULL;
+
+ s = colo_passthrough_check(conn, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
+
+ compare_passthrough_add(s, conn, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
}
void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp)
{
/* Delete passthrough connection */
+ CompareState *s;
+ Error *err = NULL;
+
+ s = colo_passthrough_check(conn, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
+
+ compare_passthrough_del(s, conn, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
}
static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
--
2.25.1
^ permalink raw reply related [flat|nested] 10+ messages in thread