Bypass specific network traffic in COLO
v2 cover Bypass specific network traffic in COLO
From: Zhang Chen <[email protected]>
Since the real user scenario does not need to monitor all traffic. This series give user ability to bypass kinds of network stream.
V2:
- Add some qapi definitions.
- Support multi colo-compare objects.
- Support setup each rules for each objects individually.
- Clean up COLO compare definition to .h file.
- Rebase HMP command for stable tree.
- Add redundant rules check.
Zhang Chen (7):
qapi/net.json: Add IP_PROTOCOL definition qapi/net.json: Add L4_Connection definition qapi/net: Add new QMP command for COLO passthrough
hmp-commands: Add new HMP command for COLO passthrough net/colo-compare: Move data structure and define to .h file. net/colo-compare: Add passthrough list to CompareState net/net.c: Add handler for COLO passthrough connection
hmp-commands.hx | 26 +++++++ include/monitor/hmp.h | 2 + monitor/hmp-cmds.c | 34 +++++++++ net/colo-compare.c | 131 +++++++---------------------------- net/colo-compare.h | 116 +++++++++++++++++++++++++++++++ net/net.c | 157 ++++++++++++++++++++++++++++++++++++++++++ qapi/net.json | 96 ++++++++++++++++++++++++++ 7 files changed, 456 insertions(+), 106 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/7 qapi/net.json: Add IP_PROTOCOL definition
From: Zhang Chen <[email protected]>
Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP commands.
--- qapi/net.json | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
qapi/net.json +30 -0
@@ -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' ] }
Signature · 1 line
2.25.1
PATCH v2 2/7 qapi/net.json: Add L4_Connection definition
In reply to Zhang ChenFrom: Zhang Chen <[email protected]>
Add L4_Connection struct for other QMP commands. Except protocol field is necessary, other fields are optional.
--- qapi/net.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
qapi/net.json +26 -0
@@ -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' } }
Signature · 1 line
2.25.1
PATCH v2 3/7 qapi/net: Add new QMP command for COLO passthrough
In reply to Zhang ChenFrom: Zhang Chen <[email protected]>
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.
--- net/net.c | 10 ++++++++++ qapi/net.json | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
net/net.c +10 -0
@@ -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;
qapi/net.json +40 -0
@@ -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' }
Signature · 1 line
2.25.1
PATCH v2 4/7 hmp-commands: Add new HMP command for COLO passthrough
In reply to Zhang ChenFrom: Zhang Chen <[email protected]>
Add hmp_colo_passthrough_add and hmp_colo_passthrough_del make user can maintain COLO network passthrough list in human monitor.
--- hmp-commands.hx | 26 ++++++++++++++++++++++++++ include/monitor/hmp.h | 2 ++ monitor/hmp-cmds.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+)
hmp-commands.hx +26 -0
@@ -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",
include/monitor/hmp.h +2 -0
@@ -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);
monitor/hmp-cmds.c +34 -0
@@ -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 ;
Signature · 1 line
2.25.1
PATCH v2 5/7 net/colo-compare: Move data structure and define to .h file.
In reply to Zhang ChenFrom: Zhang Chen <[email protected]>
Make other modules can reuse COLO code.
--- net/colo-compare.c | 106 --------------------------------------------- net/colo-compare.h | 106 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 106 deletions(-)
net/colo-compare.c +0 -106
@@ -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" ,
net/colo-compare.h +106 -0
112 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 6/7 net/colo-compare: Add passthrough list to CompareState
In reply to Zhang ChenFrom: Zhang Chen <[email protected]>
Add passthrough list for each CompareState.
--- net/colo-compare.c | 25 +++++++++++++++++++++++++ net/colo-compare.h | 10 ++++++++++ 2 files changed, 35 insertions(+)
net/colo-compare.c +25 -0
@@ -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,
net/colo-compare.h +10 -0
@@ -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; };
Signature · 1 line
2.25.1
Re: [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState
Quoted 39 lines · On Wed, 3 Mar 2021 12:15:38 +0800 Zhang Chen <[email protected] > wrote:
From: Zhang Chen <[email protected]>
Add passthrough list for each CompareState.
Signed-off-by Zhang Chen <[email protected]>--- net/colo-compare.c | 25 +++++++++++++++++++++++++ net/colo-compare.h | 10 ++++++++++ 2 files changed, 35 insertions(+)net/colo-compare.c +14
-0@@ -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 );
net/colo-compare.c static int packet_enqueue(CompareState *s, int mode, Connection **con) · line 186
Quoted 10 lines
net/colo-compare.c +10
-0+ pkt =NULL ; +return -1 ; + } + } + } + } + } + } + } +
Hi,
Access to s->passthroughlist still needs to be protected by a lock.
Regards,
Lukas Straub
Quoted 39 lines
net/colo-compare.c +1
-0conn =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,net/colo-compare.h +10
-0@@ -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; };
RE: [PATCH V2 6/7] net/colo-compare: Add passthrough list to CompareState
Quoted 71 lines
-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Thursday, March 18, 2021 5:16 AM
To: Zhang, Chen <[email protected]>
Cc: Jason Wang <[email protected]>; qemu-dev <qemu- [email protected]>; Eric Blake <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Markus Armbruster <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V2 6/7]net/colo-compare: Add passthrough list to CompareStateQuoted 7 lines · On Wed, 3 Mar 2021 12:15:38 +0800 Zhang Chen <[email protected] > wrote:
From: Zhang Chen <[email protected]>
Add passthrough list for each CompareState.
Signed-off-by Zhang Chen <[email protected]>---
net/colo-compare.c| 25 +++++++++++++++++++++++++net/colo-
compare.hnet/colo-compare.c static int packet_enqueue(CompareState *s, int
Quoted 8 lines
| 10 ++++++++++
2 files changed, 35 insertions(+)net/colo-compare.c index renamed from net/colo-compare.c +0
-0
a803f8b888..80cea32c20100644net/colo-compare.c +0
-0@@ -141,6 +141,7 @@ static int packet_enqueue(CompareState *s, intmode, Connection **con)
net/colo-compare.c static int packet_enqueue(CompareState *s, int
Quoted 8 lines
net/colo-compare.c +1
-0ConnectionKey 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, intmode, Connection **con)
net/colo-compare.c static int packet_enqueue(CompareState *s, int mode, Connection **con)
Quoted 7 lines
net/colo-compare.c +4
-0}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))){
Quoted 8 lines
net/colo-compare.c +8
-0+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 );net/colo-compare.c static int packet_enqueue(CompareState *s, int mode, Connection **con) · line 186
Quoted 10 lines
net/colo-compare.c +10
-0+ pkt =NULL ; +return -1 ; + } + } + } + } + } + } + } +
Quoted 3 lines
Hi,
Access tos->passthroughliststill needs to be protected by a lock.
OK, will fix it in next version.
Thanks
Chen
Quoted 46 lines
Regards,
Lukas StraubQuoted 10 lines
net/colo-compare.c +0
-0conn =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,
Quoted 21 lines
connection_key_equal, diff --gita/net/colo-compare.hb/net/colo-compare.hindex2a9dcac0a7..31644f145b100644net/colo-compare.h +8
-0@@ -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 ++ * | | net/colo-compare.h struct CompareState { · line 125
Quoted 7 lines
net/colo-compare.h +1
-0@@ -110,6 +119,7 @@ struct CompareState {QEMUBH *event_bh;enum colo_event event; + QLIST_HEAD(, PassthroughEntry) passthroughlist;QTAILQ_ENTRY (CompareState) next; };--
PATCH v2 7/7 net/net.c: Add handler for COLO passthrough connection
In reply to Zhang ChenFrom: Zhang Chen <[email protected]>
Use connection protocol,src port,dst port,src ip,dst ip as the key to bypass certain network traffic in COLO compare.
--- net/net.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+)
net/net.c +147 -0
@@ -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)
Signature · 1 line
2.25.1