From: Lukas Straub <lukasstraub2@web.de>
To: Zhang Chen <chen.zhang@intel.com >
Cc: Jason Wang <jasowang@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
qemu-dev <qemu-devel@nongnu.org>,
Zhang Chen <zhangckid@gmail.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH 3/3] net/colo-compare: Add handler for passthrough connection
Date: Thu, 14 Jan 2021 14:50:37 +0100 [thread overview]
Message-ID: <20210114145037.706fe8c7@gecko.fritz.box> (raw)
In-Reply-To: <20201224010918.19275-4-chen.zhang@intel.com>
[-- Attachment #1: Type: text/plain, Size: 6058 bytes --]
On Thu, 24 Dec 2020 09:09:18 +0800
Zhang Chen <chen.zhang@intel.com > wrote:
> From: Zhang Chen <chen.zhang@intel.com>
>
> Currently, we just use guest's TCP/UDP source port as the key
> to bypass certain network traffic.
>
> Signed-off-by: Zhang Chen <chen.zhang@intel.com>
> ---
> net/colo-compare.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++
> net/colo-compare.h | 2 ++
> net/net.c | 27 +++++++++++++++++++++++++
> 3 files changed, 78 insertions(+)
>
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index 337025b44f..11a32caa9b 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -46,6 +46,9 @@ static QTAILQ_HEAD(, CompareState) net_compares =
> static NotifierList colo_compare_notifiers =
> NOTIFIER_LIST_INITIALIZER(colo_compare_notifiers);
>
> +static QLIST_HEAD(, PassthroughEntry) passthroughlist =
> + QLIST_HEAD_INITIALIZER(passthroughlist);
> +
> #define COMPARE_READ_LEN_MAX NET_BUFSIZE
> #define MAX_QUEUE_SIZE 1024
>
> @@ -103,6 +106,12 @@ typedef struct SendEntry {
> uint8_t *buf;
> } SendEntry;
>
> +typedef struct PassthroughEntry {
> + bool is_tcp;
> + uint16_t port;
> + QLIST_ENTRY(PassthroughEntry) node;
> +} PassthroughEntry;
> +
> struct CompareState {
> Object parent;
>
> @@ -247,6 +256,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) {
> @@ -264,8 +274,23 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
> pkt = NULL;
> return -1;
> }
> +
> fill_connection_key(pkt, &key);
>
> + /* Check COLO passthrough connenction */
> + if (!QLIST_EMPTY(&passthroughlist)) {
> + QLIST_FOREACH_SAFE(bypass, &passthroughlist, node, next) {
> + if (((key.ip_proto == IPPROTO_TCP) && bypass->is_tcp) ||
> + ((key.ip_proto == IPPROTO_UDP) && !bypass->is_tcp)) {
> + if (bypass->port == key.src_port) {
> + packet_destroy(pkt, NULL);
> + pkt = NULL;
> + return -1;
> + }
> + }
> + }
> + }
> +
> conn = connection_get(s->connection_track_table,
> &key,
> &s->conn_list);
> @@ -1373,6 +1398,30 @@ static void colo_flush_packets(void *opaque, void *user_data)
> }
> }
>
> +void colo_compare_passthrough_add(bool is_tcp, const uint16_t port)
> +{
> + PassthroughEntry *bypass = NULL;
> +
> + bypass = g_new0(PassthroughEntry, 1);
> + bypass->is_tcp = is_tcp;
> + bypass->port = port;
> + QLIST_INSERT_HEAD(&passthroughlist, bypass, node);
> +}
> +
> +void colo_compare_passthrough_del(bool is_tcp, const uint16_t port)
> +{
> + PassthroughEntry *bypass = NULL, *next = NULL;
> +
> + if (!QLIST_EMPTY(&passthroughlist)) {
> + QLIST_FOREACH_SAFE(bypass, &passthroughlist, node, next) {
> + if ((bypass->is_tcp == is_tcp) && (bypass->port == port)) {
> + QLIST_REMOVE(bypass, node);
> + g_free(bypass);
> + }
> + }
> + }
> +}
> +
Access to "passtroughlist" needs to be protected by a lock, as "packet_enqueue" is called from a different iothread.
> static void colo_compare_class_init(ObjectClass *oc, void *data)
> {
> UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
> diff --git a/net/colo-compare.h b/net/colo-compare.h
> index 22ddd512e2..1fa026c85e 100644
> --- a/net/colo-compare.h
> +++ b/net/colo-compare.h
> @@ -20,5 +20,7 @@
> 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);
> +void colo_compare_passthrough_add(bool is_tcp, const uint16_t port);
> +void colo_compare_passthrough_del(bool is_tcp, const uint16_t port);
>
> #endif /* QEMU_COLO_COMPARE_H */
> diff --git a/net/net.c b/net/net.c
> index eac7a92618..1f303e8309 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -55,6 +55,7 @@
> #include "sysemu/sysemu.h"
> #include "net/filter.h"
> #include "qapi/string-output-visitor.h"
> +#include "net/colo-compare.h"
>
> /* Net bridge is currently not supported for W32. */
> #if !defined(_WIN32)
> @@ -1155,12 +1156,38 @@ void qmp_colo_passthrough_add(const char *prot, const uint32_t port,
> Error **errp)
> {
> /* Setup passthrough connection */
> + if (port > 65536) {
> + error_setg(errp, "COLO pass through get wrong port");
> + return;
> + }
> +
> + if (!strcmp(prot, "tcp") || !strcmp(prot, "TCP")) {
> + colo_compare_passthrough_add(true, (uint16_t)port);
> + } else if (!strcmp(prot, "udp") || !strcmp(prot, "UDP")) {
> + colo_compare_passthrough_add(false, (uint16_t)port);
> + } else {
> + error_setg(errp, "COLO pass through just support tcp or udp protocol");
> + return;
> + }
> }
>
> void qmp_colo_passthrough_del(const char *prot, const uint32_t port,
> Error **errp)
> {
> /* Delete passthrough connection */
> + if (port > 65536) {
> + error_setg(errp, "COLO pass through get wrong port");
> + return;
> + }
> +
> + if (!strcmp(prot, "tcp") || !strcmp(prot, "TCP")) {
> + colo_compare_passthrough_del(true, (uint16_t)port);
> + } else if (!strcmp(prot, "udp") || !strcmp(prot, "UDP")) {
> + colo_compare_passthrough_del(false, (uint16_t)port);
> + } else {
> + error_setg(errp, "COLO pass through just support tcp or udp protocol");
> + return;
> + }
> }
>
> static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
--
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-01-14 13:53 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-24 1:09 [PATCH 0/3] Bypass specific network traffic in COLO Zhang Chen
2020-12-24 1:09 ` [PATCH 1/3] qapi/net: Add new QMP command for COLO passthrough Zhang Chen
2020-12-25 6:20 ` Jason Wang
2020-12-28 0:38 ` Zhang, Chen
2020-12-28 7:11 ` Jason Wang
2020-12-29 2:56 ` Zhang, Chen
2020-12-30 3:56 ` Jason Wang
2021-01-05 3:28 ` Zhang, Chen
2021-01-05 4:17 ` Jason Wang
2021-01-05 6:29 ` Zhang, Chen
2021-01-19 19:32 ` Eric Blake
2021-01-21 1:50 ` Zhang, Chen
2020-12-24 1:09 ` [PATCH 2/3] hmp-commands: Add new HMP " Zhang Chen
2020-12-24 1:09 ` [PATCH 3/3] net/colo-compare: Add handler for passthrough connection Zhang Chen
2021-01-14 13:45 ` Lukas Straub
2021-01-15 9:07 ` Zhang, Chen
2021-01-15 16:06 ` Lukas Straub
2021-01-14 13:50 ` Lukas Straub [this message]
2021-01-15 9:08 ` Zhang, Chen
2020-12-25 6:23 ` [PATCH 0/3] Bypass specific network traffic in COLO Jason Wang
2020-12-28 0:38 ` Zhang, Chen
2021-01-04 13:06 ` Dr. David Alan Gilbert
2021-01-05 3:28 ` Zhang, Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210114145037.706fe8c7@gecko.fritz.box \
--to=lukasstraub2@web.de \
--cc=armbru@redhat.com \
--cc=chen.zhang@intel.com \
--cc=dgilbert@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhangckid@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).