Skip to contentSkip to conversation

Bypass specific network traffic in COLO

PATCH Superseded Zhang Chen 4 participants 46 messages Mar 19, 2021 – Apr 20, 2021 Networking

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

v4 cover Bypass specific network traffic in COLO

Due to some real user scenarios don't need to monitor all traffic. And qemu net-filter also need function to more detailed flow control. This series give user ability to bypass kinds of COLO network stream.

For example, windows guest user want to enable windows remote desktop to touch guest(UDP/TCP 3389), This case use UDP and TCP mixed, and the tcp part payload always different caused by real desktop display data(for guest time/ mouse display....).

Another case is some real user application will actively transmit information include guest time part, primary guest send data with time 10:01.000, At the same time secondary guest send data with time 10:01.001,
it will always trigger COLO checkpoint(live migrate) to drop guest performance.

V4:
- Fix QAPI code conflict for V6.0 merged patches.
- Note this feature for V6.1.

V3:
- Add COLO passthrough list lock.
- Add usage demo and more comments.

V2:
- Add the n-tuple support.
- 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    | 135 ++++++++--------------------------
 net/colo-compare.h    | 117 ++++++++++++++++++++++++++++++
 net/net.c             | 163 ++++++++++++++++++++++++++++++++++++++++++
 qapi/net.json         |  97 +++++++++++++++++++++++++
 7 files changed, 468 insertions(+), 106 deletions(-)
Signature · 1 line
2.25.1
author
#13 lore raw

PATCH v4 2/7 qapi/net.json: Add L4_Connection definition

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
index 498ea7aa72..cd4a8ed95e 100644
@@ -825,3 +825,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.1
+##
+{ '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
author
#37 lore raw

PATCH v4 4/7 hmp-commands: Add new HMP command for COLO passthrough

In reply to Zhang Chen

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
index d4001f9c5d..b67a5a04cb 100644
@@ -1335,6 +1335,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
index ed2913fd18..3c4943b09f 100644
@@ -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
index 3c88a4faef..b57e3430ab 100644
@@ -1668,6 +1668,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
author
#45 lore raw

PATCH v4 7/7 net/net.c: Add handler for COLO passthrough connection

In reply to Zhang Chen

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 | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 153 insertions(+)
net/net.c +153 -0
index 7c7cefe0e0..4a9ab29cca 100644
@@ -56,6 +56,8 @@
 #include "net/filter.h"
 #include "qapi/string-output-visitor.h"
 #include "qapi/hmp-output-visitor.h"
+#include "net/colo-compare.h"
+#include "qom/object_interfaces.h"
 
 /* Net bridge is currently not supported for W32. */
 #if !defined(_WIN32)
@@ -1199,14 +1201,165 @@ void qmp_netdev_del(const char *id, Error **errp)
     }
 }
 
+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;
+    }
+
+    qemu_mutex_lock(&s->passthroughlist_mutex);
+    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);
+                qemu_mutex_unlock(&s->passthroughlist_mutex);
+                return;
+            }
+        }
+    }
+
+    QLIST_INSERT_HEAD(&s->passthroughlist, bypass, node);
+    qemu_mutex_unlock(&s->passthroughlist_mutex);
+}
+
+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;
+    }
+
+    qemu_mutex_lock(&s->passthroughlist_mutex);
+    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);
+                qemu_mutex_unlock(&s->passthroughlist_mutex);
+                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);
+    qemu_mutex_unlock(&s->passthroughlist_mutex);
+}
+
 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
author
#1 lore raw

PATCH v4 1/7 qapi/net.json: Add IP_PROTOCOL definition

In reply to Zhang Chen

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP commands.

---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json +31 -0
index 87361ebd9a..498ea7aa72 100644
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }
+
Signature · 1 line
2.25.1
author
#41 lore raw

PATCH v4 5/7 net/colo-compare: Move data structure and define to .h file.

In reply to Zhang Chen

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
index 84db4978ac..a803f8b888 100644
@@ -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
author
#26 lore raw

PATCH v4 3/7 qapi/net: Add new QMP command for COLO passthrough

In reply to Zhang Chen

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
index 725a4e1450..7c7cefe0e0 100644
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error **errp)
     }
 }
 
+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
index cd4a8ed95e..ec7d3b1128 100644
@@ -851,3 +851,43 @@
   '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.1
+#
+# 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.1
+#
+# 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
author
#44 lore raw

PATCH v4 6/7 net/colo-compare: Add passthrough list to CompareState

In reply to Zhang Chen

Add passthrough list for each CompareState.

---
 net/colo-compare.c | 29 +++++++++++++++++++++++++++++
 net/colo-compare.h | 11 +++++++++++
 2 files changed, 40 insertions(+)
net/colo-compare.c +29 -0
index a803f8b888..40af8cd501 100644
@@ -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,32 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)
     }
     fill_connection_key(pkt, &key);
 
+    /* Check COLO passthrough connenction */
+    qemu_mutex_lock(&s->passthroughlist_mutex);
+    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;
+                                qemu_mutex_unlock(&s->passthroughlist_mutex);
+                                return -1;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    qemu_mutex_unlock(&s->passthroughlist_mutex);
+
     conn = connection_get(s->connection_track_table,
                           &key,
                           &s->conn_list);
@@ -1224,6 +1251,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,
@@ -1236,6 +1264,7 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp)
     if (!colo_compare_active) {
         qemu_mutex_init(&event_mtx);
         qemu_cond_init(&event_complete_cond);
+        qemu_mutex_init(&s->passthroughlist_mutex);
         colo_compare_active = true;
     }
     QTAILQ_INSERT_TAIL(&net_compares, s, next);
net/colo-compare.h +11 -0
index 2a9dcac0a7..2259abcd63 100644
@@ -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,8 @@ struct CompareState {
 
     QEMUBH *event_bh;
     enum colo_event event;
+    QLIST_HEAD(, PassthroughEntry) passthroughlist;
+    QemuMutex passthroughlist_mutex;
 
     QTAILQ_ENTRY(CompareState) next;
 };
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Zhang Chen
Quoted 12 lines · Zhang Chen

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP commands.

---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json +0 -0
index 87361ebd9a..498ea7aa72 100644

qapi/net.json line 803

Quoted 10 lines
qapi/net.json +7 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @IP_PROTOCOL:
+#
+# Transport layer protocol.
+#
+# Just for IPv4.

Really?

Quoted 14 lines
qapi/net.json +14 -0
+#
+# @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.

qapi/net.json line 827

Quoted 10 lines
qapi/net.json +10 -0
+#
+# @ipv6: IPv6 Encapsulation.
+#
+# TODO: Need to add more transport layer protocol.
+#
+# Since: 6.1
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }
+

docs/devel/qapi-code-gen.txt: "type definitions should always use CamelCase".

Make this something like 'enum': 'IpProtocol', please.

#14 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Zhang Chen
Quoted 17 lines · Zhang Chen

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 +1 -0
index 498ea7aa72..cd4a8ed95e 100644
@@ -825,3 +825,29 @@
 { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
     'icmp', 'igmp', 'ipv6' ] }
 
+##

qapi/net.json line 838

Quoted 10 lines
qapi/net.json +10 -0
+# @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.

Clear as mud.

See my review of PATCH 3.

Quoted 15 lines
qapi/net.json +15 -0
+#
+# @src_ip: Source IP.
+#
+# @dst_ip: Destination IP.
+#
+# @src_port: Source port.
+#
+# @dst_port: Destination port.
+#
+# Since: 6.1
+##
+{ 'struct': 'L4_Connection',
+  'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
+    '*src_port': 'int', '*dst_port': 'int' } }
+
#24 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Zhang Chen

One more little thing...

Quoted 32 lines · Zhang Chen

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 +16 -0
index 498ea7aa72..cd4a8ed95e 100644
@@ -825,3 +825,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.
+#

qapi/net.json line 853

Quoted 10 lines
qapi/net.json +10 -0
+# @src_port: Source port.
+#
+# @dst_port: Destination port.
+#
+# Since: 6.1
+##
+{ 'struct': 'L4_Connection',
+  'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
+    '*src_port': 'int', '*dst_port': 'int' } }
+

Please avoid the long line, e.g. like this:

{ 'struct': 'L4_Connection',

     'data': {
       'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str',
       '*dst_ip': 'str', '*src_port': 'int', '*dst_port': 'int' } }
#27 lore raw

Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Zhang Chen
Quoted 15 lines · Zhang Chen

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 +0 -0
index 725a4e1450..7c7cefe0e0 100644

net/net.c void qmp_netdev_del(const char *id, Error **errp) · line 1204

Quoted 6 lines
net/net.c +3 -0
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error **errp)
     }
 }
 
+void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp)
+{
+    /* Setup passthrough connection */

Do you mean to say

       /* TODO implement */

?

net/net.c void qmp_netdev_del(const char *id, Error **errp) · line 1210

Quoted 6 lines
net/net.c +6 -0
+}
+
+void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp)
+{
+    /* Delete passthrough connection */
+}

Likewise.

Quoted 9 lines
net/net.c +1 -0
+
 static void netfilter_print_info(Monitor *mon, NetFilterState *nf)
 {
     char *str;
qapi/net.json +0 -0
index cd4a8ed95e..ec7d3b1128 100644

qapi/net.json line 857

Quoted 7 lines
qapi/net.json +4 -0
@@ -851,3 +851,43 @@
   '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.

QEMU doesn't have customers, it has users :)

Quoted 26 lines
qapi/net.json +26 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# 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.1
+#
+# Example:

qapi/net.json line 893

Quoted 10 lines
qapi/net.json +10 -0
+#
+# -> { "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' }
+

To make sense of this, I have to refer back to PATCH 1 and 2:

{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',

       'icmp', 'igmp', 'ipv6' ] }

{ 'struct': 'L4_Connection',

     'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
       '*src_port': 'int', '*dst_port': 'int' } }

Please squash the three patches together.

I figure colo-passthrough-add adds some kind of packet matching thingy that can match packets by source IP, source port, destination IP, destination port, and protocol. Correct?

The protocol is mandatory, all others are optional. What does it mean to omit an optional one? Match all?

I have no idea what @id is supposed to mean. Please explain intended use.

I'm ignoring colo-passthrough-del for now, because I feel need to understand -add first.

#28 lore raw

RE: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 34 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Saturday, March 20, 2021 12:03 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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

net/net.c void qmp_netdev_del(const char *id, Error

Quoted 15 lines · Zhang Chen

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 +0 -0
index 725a4e1450..7c7cefe0e0 100644
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error

**errp)

Quoted 3 lines
net/net.c +0 -0
     }
 }
 
Quoted 8 lines

net/net.c void qmp_netdev_del(const char *id, Error · line 1203

Quoted 2 lines
net/net.c +2 -0
+void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp) {
+    /* Setup passthrough connection */

Do you mean to say

       /* TODO implement */

?

Yes, I will input real code here in 7/7 patch.

Quoted 19 lines

net/net.c void qmp_netdev_del(const char *id, Error **errp)

Quoted 5 lines
net/net.c +4 -0
+}
+
+void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp) {
+    /* Delete passthrough connection */ }

Likewise.

Quoted 11 lines
net/net.c +1 -0
+
 static void netfilter_print_info(Monitor *mon, NetFilterState *nf)  {
     char *str;
qapi/net.json index renamed from qapi/net.json +0 -0

cd4a8ed95e..ec7d3b1128 100644

qapi/net.json +0 -0
@@ -851,3 +851,43 @@
   'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
     '*src_port': 'int', '*dst_port': 'int' } }
 
Quoted 6 lines

qapi/net.json line 857

Quoted 4 lines
qapi/net.json +4 -0
+##
+# @colo-passthrough-add:
+#
+# Add passthrough entry according to customer's needs in COLO-compare.

QEMU doesn't have customers, it has users :)

Thanks note.

Quoted 43 lines

qapi/net.json

Quoted 10 lines
qapi/net.json +9 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-add",
+#      "arguments": { "protocol": "tcp", "id": "object0", "src_ip":

"192.168.1.1",

qapi/net.json

Quoted 11 lines
qapi/net.json +11 -0
+#      "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.

qapi/net.json

Quoted 9 lines
qapi/net.json +9 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-del",
+#      "arguments": { "protocol": "tcp", "id": "object0", "src_ip":

"192.168.1.1",

qapi/net.json line 893

Quoted 7 lines
qapi/net.json +7 -0
+#      "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'colo-passthrough-del', 'boxed': true,
+     'data': 'L4_Connection' }
+

To make sense of this, I have to refer back to PATCH 1 and 2:

Quoted 8 lines
   { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
       'icmp', 'igmp', 'ipv6' ] }

   { 'struct': 'L4_Connection',
     'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
       '*src_port': 'int', '*dst_port': 'int' } }

Please squash the three patches together.

OK.

Quoted 4 lines

I figure colo-passthrough-add adds some kind of packet matching thingy that can match packets by source IP, source port, destination IP, destination port, and protocol. Correct?

Yes, you are right.

Quoted 3 lines

The protocol is mandatory, all others are optional. What does it mean to omit an optional one? Match all?

Yes, match all. The idea from Jason Wang, for example:
User just set the protocol/source IP(tcp/192.168.1.1) , others empty. The rule will bypass all the TCP packet from the source IP.

Quoted 2 lines

I have no idea what @id is supposed to mean. Please explain intended use.

The @id means packet hander in Qemu. Because not all the guest network packet into the colo-compare module, the net-filters are same cases. There modules attach to NIC or chardev socket to work, VM maybe have multi modules running. So we use the ID to set the rule to the specific module.

Thanks
Chen

Quoted 3 lines

I'm ignoring colo-passthrough-del for now, because I feel need to understand -add first.

#3 lore raw

RE: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Markus Armbruster
Quoted 31 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, March 19, 2021 11:47 PM
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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · Zhang Chen

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 15 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +1 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
Quoted 8 lines

qapi/net.json line 803

Quoted 6 lines
qapi/net.json +6 -0
+##
+# @IP_PROTOCOL:
+#
+# Transport layer protocol.
+#
+# Just for IPv4.

Really?

Current tcp/udp/icmp field from IPv4 header definition, I think maybe we need add more to support IPv6. So, looks change to #TODO support IPv6 part is better?

Quoted 29 lines
Quoted 15 lines
qapi/net.json +14 -0
+#
+# @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.

qapi/net.json line 827

Quoted 10 lines
qapi/net.json +10 -0
+#
+# @ipv6: IPv6 Encapsulation.
+#
+# TODO: Need to add more transport layer protocol.
+#
+# Since: 6.1
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }
+

docs/devel/qapi-code-gen.txt: "type definitions should always use CamelCase".

Quoted 1 line

Make this something like 'enum': 'IpProtocol', please.

OK, I will fix it in next version.

Thanks
Chen

#15 lore raw

RE: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Markus Armbruster
Quoted 31 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, March 19, 2021 11:48 PM
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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 16 lines · Zhang Chen

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 index renamed from qapi/net.json +0 -0

498ea7aa72..cd4a8ed95e 100644

qapi/net.json +0 -0
@@ -825,3 +825,29 @@
 { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
     'icmp', 'igmp', 'ipv6' ] }
 
Quoted 13 lines

qapi/net.json line 838

Quoted 11 lines
qapi/net.json +11 -0
+##
+# @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.

Clear as mud.

Sorry, let me re-clear it.
If I understand correctly, The ID shouldn't be here, but I found the 'boxed' flag just can add only one 'data' like this:
+##
+{ 'command': 'colo-passthrough-add', 'boxed': true,
+ 'data': 'L4_Connection' }

I original want to this:
+##
+{ 'command': 'colo-passthrough-add',
+ 'data': { 'id': 'str', 'boxed': false, 'conn': 'L4_Connection', 'boxed': true }

So, I add the @id as an optional argument here.

rewrite the comments:
+# @id: Assign the rule to Qemu network handle module object ID. Like colo-compare, net-filter.

Please see the ID details in patch3 too.

Thanks
Chen

Quoted 18 lines

See my review of PATCH 3.

Quoted 15 lines
qapi/net.json +15 -0
+#
+# @src_ip: Source IP.
+#
+# @dst_ip: Destination IP.
+#
+# @src_port: Source port.
+#
+# @dst_port: Destination port.
+#
+# Since: 6.1
+##
+{ 'struct': 'L4_Connection',
+  'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
+    '*src_port': 'int', '*dst_port': 'int' } }
+
#29 lore raw

Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Zhang, Chen
Quoted 35 lines · Chen
Quoted 35 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Saturday, March 20, 2021 12:03 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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

net/net.c void qmp_netdev_del(const char *id, Error

Quoted 15 lines · Zhang Chen

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 +0 -0
index 725a4e1450..7c7cefe0e0 100644
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error

**errp)

Quoted 5 lines
net/net.c +2 -0
     }
 }
 
+void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp) {
+    /* Setup passthrough connection */
Quoted 7 lines
Quoted 5 lines

Do you mean to say

       /* TODO implement */

?

Yes, I will input real code here in 7/7 patch.

Use a TODO comment then.

Quoted 87 lines
Quoted 19 lines

net/net.c void qmp_netdev_del(const char *id, Error **errp)

Quoted 5 lines
net/net.c +4 -0
+}
+
+void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp) {
+    /* Delete passthrough connection */ }

Likewise.

Quoted 11 lines
net/net.c +1 -0
+
 static void netfilter_print_info(Monitor *mon, NetFilterState *nf)  {
     char *str;
qapi/net.json index renamed from qapi/net.json +0 -0

cd4a8ed95e..ec7d3b1128 100644

qapi/net.json +0 -0
@@ -851,3 +851,43 @@
   'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
     '*src_port': 'int', '*dst_port': 'int' } }
 
Quoted 6 lines

qapi/net.json line 857

Quoted 4 lines
qapi/net.json +4 -0
+##
+# @colo-passthrough-add:
+#
+# Add passthrough entry according to customer's needs in COLO-compare.

QEMU doesn't have customers, it has users :)

Thanks note.

Quoted 40 lines
Quoted 27 lines
qapi/net.json +26 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# 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.1
+#
+# Example:

qapi/net.json line 893

Quoted 10 lines
qapi/net.json +10 -0
+#
+# -> { "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' }
+

To make sense of this, I have to refer back to PATCH 1 and 2:

Quoted 8 lines
   { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
       'icmp', 'igmp', 'ipv6' ] }

   { 'struct': 'L4_Connection',
     'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
       '*src_port': 'int', '*dst_port': 'int' } }

Please squash the three patches together.

OK.

Quoted 4 lines

I figure colo-passthrough-add adds some kind of packet matching thingy that can match packets by source IP, source port, destination IP, destination port, and protocol. Correct?

Yes, you are right.

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

The protocol is mandatory, all others are optional. What does it mean to omit an optional one? Match all?

Yes, match all. The idea from Jason Wang, for example:
User just set the protocol/source IP(tcp/192.168.1.1) , others empty. The rule will bypass all the TCP packet from the source IP.

Work this into the doc comment, please.

Quoted 4 lines
Quoted 1 line

I have no idea what @id is supposed to mean. Please explain intended use.

The @id means packet hander in Qemu. Because not all the guest network packet into the colo-compare module, the net-filters are same cases. There modules attach to NIC or chardev socket to work, VM maybe have multi modules running. So we use the ID to set the rule to the specific module.

I'm not sure I understand, but then I'm a QEMU networking ignoramus :)

Work it into the doc comment.

Quoted 6 lines

Thanks
Chen

Quoted 3 lines

I'm ignoring colo-passthrough-del for now, because I feel need to understand -add first.

#4 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Zhang, Chen
Quoted 38 lines · Chen
Quoted 29 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, March 19, 2021 11:47 PM
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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · Zhang Chen

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 15 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +1 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
Quoted 8 lines

qapi/net.json line 803

Quoted 6 lines
qapi/net.json +6 -0
+##
+# @IP_PROTOCOL:
+#
+# Transport layer protocol.
+#
+# Just for IPv4.

Really?

Quoted 3 lines

Current tcp/udp/icmp field from IPv4 header definition, I think maybe we need add more to support IPv6. So, looks change to #TODO support IPv6 part is better?

IPv4 and IPv6 share internet protocol numbers. IPv4 has it in header field "protocol", IPv6 in "next header".

Canonical registry:
https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
qapi/net.json +10 -0
+#
+# @tcp: Transmission Control Protocol.
+#
+# @udp: User Datagram Protocol.
+#
+# @dccp: Datagram Congestion Control Protocol.
+#
+# @sctp: Stream Control Transmission Protocol.
+#
+# @udplite: Lightweight User Datagram Protocol.
Quoted 8 lines
Quoted 8 lines

qapi/net.json line 821

Quoted 8 lines
qapi/net.json +8 -0
+#
+# @icmp: Internet Control Message Protocol.
+#
+# @igmp: Internet Group Management Protocol.
+#
+# @ipv6: IPv6 Encapsulation.
+#
+# TODO: Need to add more transport layer protocol.

If there's a need *now*, we should add them now. If the may be a need in the future, then this isn't a TODO. Perhaps

# Additional protocols may be added as needed.

How did you pick the ones to add now?

What if a user wants to use a protocol number not in this enum? If that makes no sense (say because use requires code in QEMU), fine. If it does make sense, we need to talk. You tell me :)

Quoted 16 lines
Quoted 11 lines

qapi/net.json line 827

Quoted 6 lines
qapi/net.json +6 -0
+#
+# Since: 6.1
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }
+

docs/devel/qapi-code-gen.txt: "type definitions should always use CamelCase".

Make this something like 'enum': 'IpProtocol', please.

OK, I will fix it in next version.

Thanks
Chen

#16 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Zhang, Chen
Quoted 54 lines · Chen
Quoted 29 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, March 19, 2021 11:48 PM
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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 16 lines · Zhang Chen

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 index renamed from qapi/net.json +0 -0

498ea7aa72..cd4a8ed95e 100644

qapi/net.json +0 -0
@@ -825,3 +825,29 @@
 { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
     'icmp', 'igmp', 'ipv6' ] }
 
Quoted 13 lines

qapi/net.json line 838

Quoted 11 lines
qapi/net.json +11 -0
+##
+# @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.

Clear as mud.

Sorry, let me re-clear it.
If I understand correctly, The ID shouldn't be here, but I found the 'boxed' flag just can add only one 'data' like this:

(quoted diff) +3 -0
+##
+{ 'command': 'colo-passthrough-add', 'boxed': true,
+     'data': 'L4_Connection' }

I original want to this:

(quoted diff) +3 -0
+##
+{ 'command': 'colo-passthrough-add', 
+     'data': { 'id': 'str', 'boxed': false, 'conn': 'L4_Connection', 'boxed': true  }
Quoted 6 lines

So, I add the @id as an optional argument here.

rewrite the comments:
+# @id: Assign the rule to Qemu network handle module object ID. Like colo-compare, net-filter.

Please see the ID details in patch3 too.

So, colo-passthrough-add takes an @id argument (to be tacked onto packets to help with further processing, I understand), and arguments to match packets.

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be misleading. "Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination port. Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

You need a named type for colo-passthrough-add's argument because you share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

#31 lore raw

Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Zhang Chen
Quoted 69 lines · Zhang Chen

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
index 725a4e1450..7c7cefe0e0 100644
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error **errp)
     }
 }
 
+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 +30 -0
index cd4a8ed95e..ec7d3b1128 100644
@@ -851,3 +851,43 @@
   '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.1
+#
+# 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.1
+#
+# Example:

qapi/net.json line 893

Quoted 10 lines
qapi/net.json +10 -0
+#
+# -> { "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' }
+

Now let's look at colo-passthrough-del. I figure it is for deleting the kind of things colo-passthrough-add adds.

What exactly is deleted? The thing created with the exact same arguments?

This would be unusual. Commonly, FOO-add and FOO-del both take a string ID argument. The FOO created by FOO-add remembers its ID, and FOO-del deletes by ID.

#5 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Zhang, Chen
Quoted 40 lines · Chen
Quoted 31 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, March 19, 2021 11:47 PM
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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · Zhang Chen

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 15 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +1 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
Quoted 8 lines

qapi/net.json line 803

Quoted 6 lines
qapi/net.json +6 -0
+##
+# @IP_PROTOCOL:
+#
+# Transport layer protocol.
+#
+# Just for IPv4.

Really?

Quoted 3 lines

Current tcp/udp/icmp field from IPv4 header definition, I think maybe we need add more to support IPv6. So, looks change to #TODO support IPv6 part is better?

I'm inclined to say that this should implement IPv6 from the start.

No modern software should be implementing network functionality
for IPv4 only anymore IMHO. Especially when there are potential
implications for the design of public APIs like QMP, we should expect dual-stack support from the start.

Quoted 30 lines
Quoted 30 lines
Quoted 16 lines
qapi/net.json +14 -0
+#
+# @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.

qapi/net.json line 827

Quoted 10 lines
qapi/net.json +10 -0
+#
+# @ipv6: IPv6 Encapsulation.
+#
+# TODO: Need to add more transport layer protocol.
+#
+# Since: 6.1
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }
+

docs/devel/qapi-code-gen.txt: "type definitions should always use CamelCase".

Quoted 8 lines
Quoted 1 line

Make this something like 'enum': 'IpProtocol', please.

OK, I will fix it in next version.

Thanks
Chen

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#17 lore raw

RE: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Markus Armbruster
Quoted 78 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Monday, March 22, 2021 8:31 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 7 lines · Chen
Quoted 7 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Friday, March 19, 2021 11:48 PM
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]>;

Quoted 37 lines
Quoted 23 lines

Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 16 lines · Zhang Chen

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 index renamed from qapi/net.json +0 -0

498ea7aa72..cd4a8ed95e 100644

qapi/net.json +0 -0
@@ -825,3 +825,29 @@
 { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
     'icmp', 'igmp', 'ipv6' ] }
 
Quoted 13 lines

qapi/net.json line 838

Quoted 11 lines
qapi/net.json +11 -0
+##
+# @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.

Clear as mud.

Quoted 2 lines

Sorry, let me re-clear it.
If I understand correctly, The ID shouldn't be here, but I found the 'boxed'

flag just can add only one 'data' like this:

Quoted 10 lines
(quoted diff) +3 -0
+##
+{ 'command': 'colo-passthrough-add', 'boxed': true,
+     'data': 'L4_Connection' }

I original want to this:

(quoted diff) +4 -0
+##
+{ 'command': 'colo-passthrough-add',
+     'data': { 'id': 'str', 'boxed': false, 'conn': 'L4_Connection',
+'boxed': true  }
Quoted 4 lines

So, I add the @id as an optional argument here.

rewrite the comments:
+# @id: Assign the rule to Qemu network handle module object ID. Like

colo-compare, net-filter.

Quoted 1 line
Quoted 5 lines
Quoted 1 line

Please see the ID details in patch3 too.

So, colo-passthrough-add takes an @id argument (to be tacked onto packets to help with further processing, I understand), and arguments to match packets.

Yes.

Quoted 13 lines

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be misleading. "Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination port.
Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

Quoted 4 lines

You need a named type for colo-passthrough-add's argument because you share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

What do you think the "L4BypassRule" or "NetworkRule" ?

Thanks
Chen

#30 lore raw

RE: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Markus Armbruster
Quoted 156 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Monday, March 22, 2021 8:16 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 8 lines · Chen
Quoted 8 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Saturday, March 20, 2021 12:03 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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen

<[email protected]>

Quoted 21 lines
Quoted 21 lines

Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

net/net.c void qmp_netdev_del(const char *id, Error

Quoted 15 lines · Zhang Chen

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 +0 -0
index 725a4e1450..7c7cefe0e0 100644
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error

**errp)

Quoted 4 lines
Quoted 4 lines

net/net.c void qmp_netdev_del(const char *id, Error **errp) · line 1202

Quoted 4 lines
net/net.c +1 -0
     }
 }
 
+void qmp_colo_passthrough_add(L4_Connection *conn, Error **errp)

{

Quoted 9 lines
Quoted 7 lines

net/net.c void qmp_netdev_del(const char *id, Error **errp) · line 1204

Quoted 1 line
net/net.c +1 -0
+    /* Setup passthrough connection */

Do you mean to say

       /* TODO implement */

?

Yes, I will input real code here in 7/7 patch.

Use a TODO comment then.

Quoted 4 lines
Quoted 4 lines

net/net.c void qmp_netdev_del(const char *id, Error **errp) · line 1207

Quoted 4 lines
net/net.c +3 -0
+}
+
+void qmp_colo_passthrough_del(L4_Connection *conn, Error **errp)

{

Quoted 4 lines
Quoted 4 lines

net/net.c void qmp_netdev_del(const char *id, Error · line 1207

Quoted 1 line
net/net.c +1 -0
+    /* Delete passthrough connection */ }

Likewise.

Quoted 9 lines
Quoted 9 lines

qapi/net.json line 851

Quoted 9 lines
net/net.c +1 -0
+
 static void netfilter_print_info(Monitor *mon, NetFilterState *nf)  {
     char *str;
qapi/net.json index renamed from qapi/net.json +0 -0

cd4a8ed95e..ec7d3b1128 100644

qapi/net.json +0 -0
@@ -851,3 +851,43 @@
   'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip':

'str',

Quoted 6 lines
Quoted 6 lines

qapi/net.json

Quoted 6 lines
qapi/net.json +4 -0
     '*src_port': 'int', '*dst_port': 'int' } }
 
+##
+# @colo-passthrough-add:
+#
+# Add passthrough entry according to customer's needs in COLO-

compare.

Quoted 6 lines
Quoted 2 lines

QEMU doesn't have customers, it has users :)

Thanks note.

Quoted 1 line
Quoted 9 lines
Quoted 9 lines

qapi/net.json

Quoted 9 lines
qapi/net.json +9 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-add",
+#      "arguments": { "protocol": "tcp", "id": "object0", "src_ip":

"192.168.1.1",

Quoted 11 lines
Quoted 11 lines

qapi/net.json

Quoted 11 lines
qapi/net.json +11 -0
+#      "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.

Quoted 9 lines
Quoted 9 lines

qapi/net.json

Quoted 9 lines
qapi/net.json +9 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-del",
+#      "arguments": { "protocol": "tcp", "id": "object0", "src_ip":

"192.168.1.1",

Quoted 10 lines
Quoted 10 lines

qapi/net.json line 893

Quoted 7 lines
qapi/net.json +7 -0
+#      "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'colo-passthrough-del', 'boxed': true,
+     'data': 'L4_Connection' }
+

To make sense of this, I have to refer back to PATCH 1 and 2:

Quoted 5 lines
Quoted 5 lines
   { 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
       'icmp', 'igmp', 'ipv6' ] }

   { 'struct': 'L4_Connection',
     'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip':

'str',

Quoted 14 lines
Quoted 3 lines
       '*src_port': 'int', '*dst_port': 'int' } }

Please squash the three patches together.

OK.

Quoted 4 lines

I figure colo-passthrough-add adds some kind of packet matching thingy that can match packets by source IP, source port, destination IP, destination port, and protocol. Correct?

Yes, you are right.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The protocol is mandatory, all others are optional. What does it mean to omit an optional one? Match all?

Yes, match all. The idea from Jason Wang, for example:
User just set the protocol/source IP(tcp/192.168.1.1) , others empty. The rule will bypass all the TCP packet from the source IP.

Work this into the doc comment, please.

OK.

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

I have no idea what @id is supposed to mean. Please explain intended

use.

Quoted 2 lines

The @id means packet hander in Qemu. Because not all the guest network

Quoted 8 lines

packet into the colo-compare module, the net-filters are same cases.

Quoted 1 line

There modules attach to NIC or chardev socket to work, VM maybe have

multi modules running. So we use the ID to set the rule to the specific module.

I'm not sure I understand, but then I'm a QEMU networking ignoramus :)

Work it into the doc comment.

Sure, I will add more comments in qapi/net.json next version.

Thanks
Chen

Quoted 7 lines
Quoted 7 lines

Thanks
Chen

Quoted 3 lines

I'm ignoring colo-passthrough-del for now, because I feel need to understand -add first.

#32 lore raw

RE: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Markus Armbruster
Quoted 86 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Monday, March 22, 2021 8:36 PM
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]>; Li Zhijian <[email protected]>; Lukas Straub <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

net/net.c void qmp_netdev_del(const char *id, Error

Quoted 15 lines · Zhang Chen

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 +0 -0
index 725a4e1450..7c7cefe0e0 100644
@@ -1199,6 +1199,16 @@ void qmp_netdev_del(const char *id, Error

**errp)

Quoted 22 lines
net/net.c +6 -0
     }
 }
 
+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 index renamed from qapi/net.json +0 -0

cd4a8ed95e..ec7d3b1128 100644

qapi/net.json +3 -0
@@ -851,3 +851,43 @@
   'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
     '*src_port': 'int', '*dst_port': 'int' } }
 
+##
+# @colo-passthrough-add:
+#

qapi/net.json line 866

Quoted 10 lines
qapi/net.json +10 -0
+# Add passthrough entry according to customer's needs in COLO-compare.
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-add",
+#      "arguments": { "protocol": "tcp", "id": "object0", "src_ip":

"192.168.1.1",

qapi/net.json

Quoted 11 lines
qapi/net.json +11 -0
+#      "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.

qapi/net.json

Quoted 9 lines
qapi/net.json +9 -0
+#
+# Returns: Nothing on success
+#
+# Since: 6.1
+#
+# Example:
+#
+# -> { "execute": "colo-passthrough-del",
+#      "arguments": { "protocol": "tcp", "id": "object0", "src_ip":

"192.168.1.1",

Quoted 11 lines

qapi/net.json line 893

Quoted 7 lines
qapi/net.json +7 -0
+#      "dst_ip": "192.168.1.2", "src_port": 1234, "dst_port": 4321 } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'colo-passthrough-del', 'boxed': true,
+     'data': 'L4_Connection' }
+

Now let's look at colo-passthrough-del. I figure it is for deleting the kind of things colo-passthrough-add adds.

Yes.

Quoted 2 lines

What exactly is deleted? The thing created with the exact same arguments?

Delete the rule from the module's private bypass list.
When user input a rule, the colo-passthrough-del will find the specific module by the object ID, Then delete the rule.

Quoted 3 lines

This would be unusual. Commonly, FOO-add and FOO-del both take a string ID argument. The FOO created by FOO-add remembers its ID, and FOO-del deletes by ID.

The ID not for rules itself, it just logged the modules(ID tagged) affected by the rule.

Thanks
Chen

#18 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Zhang, Chen
Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 12 lines
Quoted 12 lines

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be misleading. "Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination port.
Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

Quoted 6 lines
Quoted 4 lines

You need a named type for colo-passthrough-add's argument because you share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

What do you think the "L4BypassRule" or "NetworkRule" ?

NetworkRule is too generic.

What about ColoPassthroughRule?

#33 lore raw

Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Zhang, Chen
Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 13 lines
Quoted 3 lines

Now let's look at colo-passthrough-del. I figure it is for deleting the kind of things colo-passthrough-add adds.

Yes.

Quoted 2 lines

What exactly is deleted? The thing created with the exact same arguments?

Delete the rule from the module's private bypass list.
When user input a rule, the colo-passthrough-del will find the specific module by the object ID, Then delete the rule.

Quoted 5 lines
Quoted 3 lines

This would be unusual. Commonly, FOO-add and FOO-del both take a string ID argument. The FOO created by FOO-add remembers its ID, and FOO-del deletes by ID.

The ID not for rules itself, it just logged the modules(ID tagged) affected by the rule.

I'm not sure I understand.

If you're pointing out that existing colo-passthrough-del parameter @id is not suitable for use as unique rule ID: you can always add another parameter that is suitable.

#6 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Zhang Chen
Quoted 35 lines · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP commands.

---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json +20 -0
index 87361ebd9a..498ea7aa72 100644
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.
+#

qapi/net.json line 826

Quoted 10 lines
qapi/net.json +10 -0
+# @igmp: Internet Group Management Protocol.
+#
+# @ipv6: IPv6 Encapsulation.
+#
+# TODO: Need to add more transport layer protocol.
+#
+# Since: 6.1
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Dave

Quoted 4 lines
qapi/net.json +1 -0
+
Signature · 1 line
2.25.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#19 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Markus Armbruster
Quoted 22 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 17 lines
Quoted 16 lines

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be misleading. "Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination port.
Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

You need a named type for colo-passthrough-add's argument because you share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

Quoted 5 lines
Quoted 1 line

What do you think the "L4BypassRule" or "NetworkRule" ?

NetworkRule is too generic.

What about ColoPassthroughRule?

Which is a bit specific; there's not actually anything Colo specific in there; can I suggest 'L4FlowSpec'; I think there should also be a separate type that represents an IP address+port, so that what you end up with is:

IPFlowSpec
ID
Protocol
Source
Dest

Dave

Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#23 lore raw

RE: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Markus Armbruster
Quoted 35 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Tuesday, March 23, 2021 5:55 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 6 lines
Quoted 6 lines

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be misleading. "Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

Quoted 7 lines
Quoted 7 lines

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination port. Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

You need a named type for colo-passthrough-add's argument because

you

Quoted 4 lines
Quoted 3 lines

share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

Quoted 5 lines
Quoted 1 line

What do you think the "L4BypassRule" or "NetworkRule" ?

NetworkRule is too generic.

What about ColoPassthroughRule?

It can be used by net filter modules(filter mirror,filter-dump....) in the future, that's not just for COLO. PassthroughRule is better?

Thanks
Chen

#20 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Dr. David Alan Gilbert
Quoted 23 lines · Dr. David Alan Gilbert
Quoted 22 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 17 lines
Quoted 16 lines

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be misleading. "Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination port.
Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

You need a named type for colo-passthrough-add's argument because you share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What do you think the "L4BypassRule" or "NetworkRule" ?

NetworkRule is too generic.

What about ColoPassthroughRule?

Which is a bit specific; there's not actually anything Colo specific in there; can I suggest 'L4FlowSpec';

"A bit too specific" is mostly harmless, since we can rename types at any time (they are not visible in external interfaces).

This is *not* an objection to less specific names. All I want is names that don't give me wrong ideas on the thing's purpose. L4FlowSpec and IPFlowSpec (below) feel fine in that regard.

Quoted 9 lines

I think there should also beb
a separate type that represents an IP address+port, so that what you end up with is:

IPFlowSpec
ID
Protocol
Source
Dest

I understand the motivation. Three drawbacks, though.

One, it gets us another level of nesting on the wire, i.e. something like

    {"source": {"address": SRC-ADDR, "port": SRC-PORT},
     "destination": {"address": DST-ADDR, "port": DST-PORT}}

instead of

{"source-address": SRC-ADDR, "source-port": SRC-PORT,
"destination-address": DST-ADDR, "destination-port": DST-PORT}

QMP clients shouldn't care.

Two, we have many (address, port) pairs in the schema that don't use nesting. Adding nesting sometimes makes QMP less consistent.

Three, human-friendly interface wrappers tend to dislike nesting. This particular case seems okay; we end up with dotted keys like source.address instead of source-address. In a case where we need just one (address, port), we'd get some-silly-name.address instead of just address, though.

I've occasionally felt a mild need for letting me say "this struct member should be unboxed on the wire", i.e. have its curlies peeled off. Never enough to justify the additional generator complexity, though.

#21 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 1 line · Markus Armbruster

"Dr. David Alan Gilbert" <[email protected]> writes:

[...]

Quoted 34 lines
Quoted 9 lines

I think there should also beb
a separate type that represents an IP address+port, so that what you end up with is:

IPFlowSpec
ID
Protocol
Source
Dest

I understand the motivation. Three drawbacks, though.

One, it gets us another level of nesting on the wire, i.e. something like

    {"source": {"address": SRC-ADDR, "port": SRC-PORT},
     "destination": {"address": DST-ADDR, "port": DST-PORT}}

instead of

{"source-address": SRC-ADDR, "source-port": SRC-PORT,
"destination-address": DST-ADDR, "destination-port": DST-PORT}

QMP clients shouldn't care.

Two, we have many (address, port) pairs in the schema that don't use nesting. Adding nesting sometimes makes QMP less consistent.

Three, human-friendly interface wrappers tend to dislike nesting. This particular case seems okay; we end up with dotted keys like source.address instead of source-address. In a case where we need just one (address, port), we'd get some-silly-name.address instead of just address, though.

Quoted 3 lines

I've occasionally felt a mild need for letting me say "this struct member should be unboxed on the wire", i.e. have its curlies peeled off. Never enough to justify the additional generator complexity, though.

Just remembered we actually have

    ##
    # @InetSocketAddressBase:
    #
    # @host: host part of the address
    # @port: port part of the address
    ##
    { 'struct': 'InetSocketAddressBase',
      'data': {
        'host': 'str',
        'port': 'str' } }

It's from commit eb87203b64 "rbd: Reject -blockdev server.*.{numeric, to, ipv4, ipv6}".

#25 lore raw

Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Zhang Chen
Quoted 32 lines · Zhang Chen

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 +16 -0
index 498ea7aa72..cd4a8ed95e 100644
@@ -825,3 +825,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.
+#

qapi/net.json line 853

Quoted 10 lines
qapi/net.json +10 -0
+# @src_port: Source port.
+#
+# @dst_port: Destination port.
+#
+# Since: 6.1
+##
+{ 'struct': 'L4_Connection',
+  'data': { 'protocol': 'IP_PROTOCOL', '*id': 'str', '*src_ip': 'str', '*dst_ip': 'str',
+    '*src_port': 'int', '*dst_port': 'int' } }
+

Please use '-' instead of '_' in member names. Patches to enforce this rule just landed in master.

We tend to avoid abbreviations like src and dst in QMP. Consider spelling them out, except when it makes things less consistent.

#38 lore raw

Re: [PATCH V4 4/7] hmp-commands: Add new HMP command for COLO passthrough

In reply to Zhang Chen
Quoted 15 lines · * Zhang Chen ([email protected]) wrote:

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 +0 -0
index d4001f9c5d..b67a5a04cb 100644

hmp-commands.hx SRST · line 1341

Quoted 7 lines
hmp-commands.hx +4 -0
@@ -1335,6 +1335,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]",

That ordering is a bit unnatural; it's normal to keep ip and port together; maybe this would be better as:

protocol:s,id:s,src:s?,dst:s?

then pass src and dst through inet_parse to get your hostname and port ?

Dave

Quoted 86 lines
hmp-commands.hx +22 -0
+        .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
index ed2913fd18..3c4943b09f 100644
@@ -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
index 3c88a4faef..b57e3430ab 100644
@@ -1668,6 +1668,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
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#42 lore raw

Re: [PATCH V4 5/7] net/colo-compare: Move data structure and define to .h file.

In reply to Zhang Chen
Quoted 8 lines · * Zhang Chen ([email protected]) wrote:

Make other modules can reuse COLO code.

---
 net/colo-compare.c | 106 ---------------------------------------------
 net/colo-compare.h | 106 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 106 deletions(-)

<snip>

Quoted 12 lines
net/colo-compare.h +4 -0
index 22ddd512e2..2a9dcac0a7 100644
@@ -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"

net/colo-compare.h line 33

Quoted 10 lines
net/colo-compare.h +10 -0
+#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

^^^^

Quoted 5 lines
net/colo-compare.h +5 -0
+#define COLO_COMPARE_FREE_PRIMARY     0x01
+#define COLO_COMPARE_FREE_SECONDARY   0x02
+
+#define REGULAR_PACKET_CHECK_MS 1000
+#define DEFAULT_TIME_OUT_MS 3000

net/colo-compare.h line 49

Quoted 10 lines
net/colo-compare.h +10 -0
+
+typedef struct SendCo {
+    Coroutine *co;
+    struct CompareState *s;
+    CharBackend *chr;
+    GQueue send_list;
+    bool notify_remote_frame;
+    bool done;
+    int ret;
+} SendCo;

^^^^^

net/colo-compare.h line 55

Quoted 5 lines
net/colo-compare.h +5 -0
+typedef struct SendEntry {
+    uint32_t size;
+    uint32_t vnet_hdr_len;
+    uint8_t *buf;
+} SendEntry;

^^^^^

Quoted 13 lines
net/colo-compare.h +13 -0
+/*
+ *  + CompareState ++
+ *  |               |
+ *  +---------------+   +---------------+         +---------------+
+ *  |   conn list   + - >      conn     + ------- >      conn     + -- > ......
+ *  +---------------+   +---------------+         +---------------+
+ *  |               |     |           |             |          |
+ *  +---------------+ +---v----+  +---v----+    +---v----+ +---v----+
+ *                    |primary |  |secondary    |primary | |secondary
+ *                    |packet  |  |packet  +    |packet  | |packet  +
+ *                    +--------+  +--------+    +--------+ +--------+
+ *                        |           |             |          |
+ *                    +---v----+  +---v----+    +---v----+ +---v----+

net/colo-compare.h line 79

Quoted 10 lines
net/colo-compare.h +10 -0
+ *                    |primary |  |secondary    |primary | |secondary
+ *                    |packet  |  |packet  +    |packet  | |packet  +
+ *                    +--------+  +--------+    +--------+ +--------+
+ *                        |           |             |          |
+ *                    +---v----+  +---v----+    +---v----+ +---v----+
+ *                    |primary |  |secondary    |primary | |secondary
+ *                    |packet  |  |packet  +    |packet  | |packet  +
+ *                    +--------+  +--------+    +--------+ +--------+
+ */
+struct CompareState {

^^^^^

For a header, these are too generic names - they need to have Colo in them; e.g. MAX_COLOQUEUE_SIZE and COLOSendEntry etc

Dave

Quoted 52 lines
net/colo-compare.h +46 -0
+    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);
Signature · 1 line
2.25.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#22 lore raw

RE: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

In reply to Markus Armbruster
Quoted 82 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Wednesday, March 24, 2021 2:47 PM
To: Dr. David Alan Gilbert <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Zhang, Chen <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 2/7] qapi/net.json: Add L4_Connection definition

Quoted 9 lines · Dr. David Alan Gilbert
Quoted 8 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 3 lines
Quoted 3 lines

Naming the argument type L4_Connection is misleading.

Even naming the match arguments L4_Connection would be

misleading.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

"Connection" has a specific meaning in networking. There are TCP connections. There is no such thing as an UDP connection.

A TCP connection is uniquely identified by a pair of endpoints, i.e. by source address, source port, destination address, destination

port.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

Same for other connection-oriented protocols. The protocol is not part of the connection. Thus, L4_Connection would be misleading even for the connection-oriented case.

You need a named type for colo-passthrough-add's argument because you share it with colo-passthrough-del. I'm not sure that's what we want (I'm going to write more on that in a moment). If it is what we want, then please pick a another, descriptive name.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

What do you think the "L4BypassRule" or "NetworkRule" ?

NetworkRule is too generic.

What about ColoPassthroughRule?

Which is a bit specific; there's not actually anything Colo specific in there; can I suggest 'L4FlowSpec';

"A bit too specific" is mostly harmless, since we can rename types at any time (they are not visible in external interfaces).

This is *not* an objection to less specific names. All I want is names that don't give me wrong ideas on the thing's purpose. L4FlowSpec and IPFlowSpec (below) feel fine in that regard.

Quoted 9 lines

I think there should also beb a
separate type that represents an IP address+port, so that what you end up with is:

IPFlowSpec
ID
Protocol
Source
Dest

I understand the motivation. Three drawbacks, though.

One, it gets us another level of nesting on the wire, i.e. something like

    {"source": {"address": SRC-ADDR, "port": SRC-PORT},
     "destination": {"address": DST-ADDR, "port": DST-PORT}}

instead of

{"source-address": SRC-ADDR, "source-port": SRC-PORT,
"destination-address": DST-ADDR, "destination-port": DST-PORT}

QMP clients shouldn't care.

Two, we have many (address, port) pairs in the schema that don't use nesting. Adding nesting sometimes makes QMP less consistent.

Quoted 8 lines

Three, human-friendly interface wrappers tend to dislike nesting. This particular case seems okay; we end up with dotted keys like source.address instead of source-address. In a case where we need just one (address, port), we'd get some-silly-name.address instead of just address, though.

I've occasionally felt a mild need for letting me say "this struct member should be unboxed on the wire", i.e. have its curlies peeled off. Never enough to justify the additional generator complexity, though.

The initial patch of this series used unboxed struct, Eric's comments is change it to boxed.
I think it's OK, for the unused field we can keep 0 for it. The n-tuple(src IP, dst IP, src port, dst port, protocol) will be used in many place on Qemu network related code(like migrate, NBD....).
For the name, I think Dave's comments is well, for the @InetSocketAddressBase we can remove it and change it to use IPFlowSpec. Markus, what do you think about it?

Thanks
Chen

#43 lore raw

RE: [PATCH V4 5/7] net/colo-compare: Move data structure and define to .h file.

In reply to Dr. David Alan Gilbert
Quoted 103 lines

-----Original Message-----
From: Dr. David Alan Gilbert <[email protected]>
Sent: Wednesday, March 24, 2021 7:02 PM
To: Zhang, Chen <[email protected]>
Cc: Jason Wang <[email protected]>; qemu-dev <qemu- [email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Li Zhijian <[email protected]>; Zhang Chen <[email protected]>; Lukas Straub <[email protected]>
Subject: Re: [PATCH V4 5/7] net/colo-compare: Move data structure and define to .h file.

Quoted 10 lines · * Zhang Chen ([email protected]) wrote:

Make other modules can reuse COLO code.

---
 net/colo-compare.c | 106
---------------------------------------------
 net/colo-compare.h | 106
+++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 106 deletions(-)

<snip>

Quoted 11 lines
net/colo-compare.h index renamed from net/colo-compare.h +0 -0

22ddd512e2..2a9dcac0a7 100644

net/colo-compare.h +3 -0
@@ -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"

net/colo-compare.h line 32

Quoted 10 lines
net/colo-compare.h +10 -0
+#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

^^^^

Quoted 5 lines
net/colo-compare.h +5 -0
+#define COLO_COMPARE_FREE_PRIMARY     0x01
+#define COLO_COMPARE_FREE_SECONDARY   0x02
+
+#define REGULAR_PACKET_CHECK_MS 1000
+#define DEFAULT_TIME_OUT_MS 3000

net/colo-compare.h line 49

Quoted 10 lines
net/colo-compare.h +10 -0
+
+typedef struct SendCo {
+    Coroutine *co;
+    struct CompareState *s;
+    CharBackend *chr;
+    GQueue send_list;
+    bool notify_remote_frame;
+    bool done;
+    int ret;
+} SendCo;

^^^^^

net/colo-compare.h line 55

Quoted 5 lines
net/colo-compare.h +5 -0
+typedef struct SendEntry {
+    uint32_t size;
+    uint32_t vnet_hdr_len;
+    uint8_t *buf;
+} SendEntry;

^^^^^

Quoted 13 lines
net/colo-compare.h +13 -0
+/*
+ *  + CompareState ++
+ *  |               |
+ *  +---------------+   +---------------+         +---------------+
+ *  |   conn list   + - >      conn     + ------- >      conn     + -- > ......
+ *  +---------------+   +---------------+         +---------------+
+ *  |               |     |           |             |          |
+ *  +---------------+ +---v----+  +---v----+    +---v----+ +---v----+
+ *                    |primary |  |secondary    |primary | |secondary
+ *                    |packet  |  |packet  +    |packet  | |packet  +
+ *                    +--------+  +--------+    +--------+ +--------+
+ *                        |           |             |          |
+ *                    +---v----+  +---v----+    +---v----+ +---v----+

net/colo-compare.h line 79

Quoted 10 lines
net/colo-compare.h +10 -0
+ *                    |primary |  |secondary    |primary | |secondary
+ *                    |packet  |  |packet  +    |packet  | |packet  +
+ *                    +--------+  +--------+    +--------+ +--------+
+ *                        |           |             |          |
+ *                    +---v----+  +---v----+    +---v----+ +---v----+
+ *                    |primary |  |secondary    |primary | |secondary
+ *                    |packet  |  |packet  +    |packet  | |packet  +
+ *                    +--------+  +--------+    +--------+ +--------+
+ */
+struct CompareState {

^^^^^

Quoted 2 lines

For a header, these are too generic names - they need to have Colo in them; e.g. MAX_COLOQUEUE_SIZE and COLOSendEntry etc

Thanks Dave, I will fix it in next version.

Thanks
Chen

Quoted 57 lines

Dave

Quoted 50 lines
net/colo-compare.h +46 -1
+    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);
--
Quoted 2 lines

2.25.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#34 lore raw

RE: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

In reply to Markus Armbruster
Quoted 38 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Markus Armbruster
Sent: Tuesday, March 23, 2021 5:58 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 7 lines
Quoted 3 lines

Now let's look at colo-passthrough-del. I figure it is for deleting the kind of things colo-passthrough-add adds.

Yes.

Quoted 1 line

What exactly is deleted? The thing created with the exact same

arguments?

Quoted 10 lines
Quoted 1 line

Delete the rule from the module's private bypass list. When user input a rule, the colo-passthrough-del will find the specific module by the object ID, Then delete the rule.

Quoted 3 lines

This would be unusual. Commonly, FOO-add and FOO-del both take a string ID argument. The FOO created by FOO-add remembers its ID, and FOO-del deletes by ID.

Quoted 8 lines
Quoted 1 line

The ID not for rules itself, it just logged the modules(ID tagged) affected by

the rule.

I'm not sure I understand.

If you're pointing out that existing colo-passthrough-del parameter @id is not suitable for use as unique rule ID: you can always add another parameter that is suitable.

Sorry to missed this mail.

For example:
The VM running with filter-mirror(object id==0), filter-redirector(object id==1) and colo-compare(object id==2), We use colo-passthrough-add/del to add/del a rule with a ID, if the ID==2, the rule just affect to colo-compare. The filter-mirror and filter-redirector feel nothing after the add/del.

Thanks
Chen

Quoted 1 line
#35 lore raw

Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 45 lines · Chen
Quoted 36 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Markus Armbruster
Sent: Tuesday, March 23, 2021 5:58 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 7 lines
Quoted 3 lines

Now let's look at colo-passthrough-del. I figure it is for deleting the kind of things colo-passthrough-add adds.

Yes.

Quoted 1 line

What exactly is deleted? The thing created with the exact same

arguments?

Quoted 10 lines
Quoted 1 line

Delete the rule from the module's private bypass list. When user input a rule, the colo-passthrough-del will find the specific module by the object ID, Then delete the rule.

Quoted 3 lines

This would be unusual. Commonly, FOO-add and FOO-del both take a string ID argument. The FOO created by FOO-add remembers its ID, and FOO-del deletes by ID.

Quoted 8 lines
Quoted 1 line

The ID not for rules itself, it just logged the modules(ID tagged) affected by

the rule.

I'm not sure I understand.

If you're pointing out that existing colo-passthrough-del parameter @id is not suitable for use as unique rule ID: you can always add another parameter that is suitable.

Quoted 6 lines

Sorry to missed this mail.

For example:
The VM running with filter-mirror(object id==0), filter-redirector(object id==1) and colo-compare(object id==2), We use colo-passthrough-add/del to add/del a rule with a ID, if the ID==2, the rule just affect to colo-compare. The filter-mirror and filter-redirector feel nothing after the add/del.

I think you're trying to explain existing parameter @id. The point I was trying to make is unrelated to this parameter, except by name collision.

My point is: our existing "delete" operations select the object to be deleted by some unique name that is assigned by the "add" operation. The unique name is a property of the object. The property name is often, but not always "id".

Examples:

device_add argument "id" sets the device's unique name. device_del argument "id" selects the device to delete by its name.

blockdev-add argument "node-name" sets the block backend device's unique name.
blockdev-del argument "node-name" selects the block backend device to delete by its name.

Is there any particular reason why deletion of your kind of object can't work the same way?

#36 lore raw

RE: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 83 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Tuesday, April 6, 2021 4:01 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 46 lines · Chen
Quoted 38 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Markus Armbruster
Sent: Tuesday, March 23, 2021 5:58 PM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 3/7] qapi/net: Add new QMP command for COLO passthrough

Quoted 2 lines · Chen
Quoted 2 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>

[...]

Quoted 7 lines
Quoted 3 lines

Now let's look at colo-passthrough-del. I figure it is for deleting the kind of things colo-passthrough-add adds.

Yes.

Quoted 1 line

What exactly is deleted? The thing created with the exact same

arguments?

Quoted 6 lines
Quoted 1 line

Delete the rule from the module's private bypass list. When user input a rule, the colo-passthrough-del will find the specific module by the object ID, Then delete the rule.

Quoted 6 lines
Quoted 3 lines

This would be unusual. Commonly, FOO-add and FOO-del both take a string ID argument. The FOO created by FOO-add remembers its ID, and FOO-del deletes by ID.

The ID not for rules itself, it just logged the modules(ID tagged) affected by

Quoted 7 lines

the rule.

I'm not sure I understand.

If you're pointing out that existing colo-passthrough-del parameter @id is not suitable for use as unique rule ID: you can always add another parameter that is suitable.

Quoted 5 lines

Sorry to missed this mail.

For example:
The VM running with filter-mirror(object id==0), filter-redirector(object id==1) and colo-compare(object id==2), We use

colo-passthrough-add/del to add/del a rule with a ID, if the ID==2, the rule just affect to colo-compare.

Quoted 1 line

The filter-mirror and filter-redirector feel nothing after the add/del.

I think you're trying to explain existing parameter @id. The point I was trying to make is unrelated to this parameter, except by name collision.

My point is: our existing "delete" operations select the object to be deleted by some unique name that is assigned by the "add" operation.
The unique name is a property of the object. The property name is often, but not always "id".

Examples:

device_add argument "id" sets the device's unique name. device_del argument "id" selects the device to delete by its name.

Quoted 7 lines

blockdev-add argument "node-name" sets the block backend device's unique name.
blockdev-del argument "node-name" selects the block backend device to delete by its name.

Is there any particular reason why deletion of your kind of object can't work the same way?

Current command can work in this way, It seems that name "ID" can be misunderstood. The id=object0 is OK here. I will change the "id" to "object-name". Thank you for clear the comments.

Thanks
Chen

#7 lore raw

RE: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Dr. David Alan Gilbert
Quoted 58 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Dr. David Alan Gilbert
Sent: Wednesday, March 24, 2021 4:01 AM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Markus Armbruster <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 41 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +27 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
Quoted 9 lines

qapi/net.json line 826

Quoted 3 lines
qapi/net.json +3 -0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Hi Dave,

Considering that most of the scenes in Qemu don't call the getprotobyname, looks keep the string are more readable. Please review the V5 patches, Thanks.

Thanks
Chen

Quoted 9 lines

Dave

Quoted 4 lines
qapi/net.json +1 -1
+
--

2.25.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#39 lore raw

RE: [PATCH V4 4/7] hmp-commands: Add new HMP command for COLO passthrough

In reply to Dr. David Alan Gilbert
Quoted 37 lines

-----Original Message-----
From: Dr. David Alan Gilbert <[email protected]>
Sent: Wednesday, March 24, 2021 6:40 PM
To: Zhang, Chen <[email protected]>
Cc: Jason Wang <[email protected]>; qemu-dev <qemu- [email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Li Zhijian <[email protected]>; Zhang Chen <[email protected]>; Lukas Straub <[email protected]>
Subject: Re: [PATCH V4 4/7] hmp-commands: Add new HMP command for COLO passthrough

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add hmp_colo_passthrough_add and hmp_colo_passthrough_del make

user

Quoted 14 lines

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 index renamed from hmp-commands.hx +0 -0

d4001f9c5d..b67a5a04cb 100644

hmp-commands.hx SRST · line 1340

Quoted 6 lines
hmp-commands.hx +3 -0
@@ -1335,6 +1335,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?",

Quoted 8 lines

hmp-commands.hx SRST · line 1341

Quoted 1 line
hmp-commands.hx +1 -0
+        .params     = "protocol [id] [src_ip] [dst_ip] [src_port] [dst_port]",

That ordering is a bit unnatural; it's normal to keep ip and port together; maybe this would be better as:

   protocol:s,id:s,src:s?,dst:s?

then pass src and dst through inet_parse to get your hostname and port ?

OK, already update to V5, please review it.

Thanks
Chen

Quoted 94 lines

Dave

hmp-commands.hx SRST

Quoted 12 lines
hmp-commands.hx +12 -0
+        .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?",

Quoted 18 lines
hmp-commands.hx +10 -0
+        .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 index renamed from include/monitor/hmp.h +0 -0

ed2913fd18..3c4943b09f 100644

include/monitor/hmp.h void hmp_device_del(Monitor *mon, const QDict · line 84

Quoted 4 lines
include/monitor/hmp.h +1 -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

Quoted 5 lines
include/monitor/hmp.h +1 -0
+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

3c88a4faef..b57e3430ab

monitor/hmp-cmds.c void hmp_netdev_del(Monitor *mon, const

Quoted 4 lines

100644

monitor/hmp-cmds.c +0 -0
@@ -1668,6 +1668,40 @@ void hmp_netdev_del(Monitor *mon, const

QDict *qdict)

monitor/hmp-cmds.c void hmp_netdev_del(Monitor *mon, const QDict *qdict)

Quoted 10 lines
monitor/hmp-cmds.c +7 -0
     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);

Quoted 6 lines
monitor/hmp-cmds.c +6 -0
+    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);

monitor/hmp-cmds.c void hmp_netdev_del(Monitor *mon, const QDict *qdict)

Quoted 10 lines
monitor/hmp-cmds.c +10 -0
+    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);

Quoted 12 lines
monitor/hmp-cmds.c +9 -1
+    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;
--
Quoted 2 lines

2.25.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#8 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Zhang, Chen
Quoted 66 lines · Chen
Quoted 56 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Dr. David Alan Gilbert
Sent: Wednesday, March 24, 2021 4:01 AM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Markus Armbruster <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 41 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +27 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
Quoted 9 lines

qapi/net.json line 826

Quoted 3 lines
qapi/net.json +3 -0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Quoted 3 lines

Hi Dave,

Considering that most of the scenes in Qemu don't call the getprotobyname, looks keep the string are more readable.

Unless I'm missing something,

(1) this enum is only used for matching packets by source IP, source port, destination IP, destination port, and protocol, and

(2) the packet matching works just fine for *any* protocol.

By using an enum for the protocol, you're limiting the matcher to whatever protocols we bother to include in the enum for no particular reason. Feels wrong to me.

Quoted 14 lines

Please review the V5 patches, Thanks.

Thanks
Chen

Quoted 9 lines

Dave

Quoted 4 lines
qapi/net.json +1 -1
+
--

2.25.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#40 lore raw

RE: [PATCH V4 4/7] hmp-commands: Add new HMP command for COLO passthrough

In reply to Dr. David Alan Gilbert
Quoted 37 lines

-----Original Message-----
From: Dr. David Alan Gilbert <[email protected]>
Sent: Wednesday, March 24, 2021 6:40 PM
To: Zhang, Chen <[email protected]>
Cc: Jason Wang <[email protected]>; qemu-dev <qemu- [email protected]>; Eric Blake <[email protected]>; Markus Armbruster <[email protected]>; Li Zhijian <[email protected]>; Zhang Chen <[email protected]>; Lukas Straub <[email protected]>
Subject: Re: [PATCH V4 4/7] hmp-commands: Add new HMP command for COLO passthrough

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add hmp_colo_passthrough_add and hmp_colo_passthrough_del make

user

Quoted 14 lines

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 index renamed from hmp-commands.hx +0 -0

d4001f9c5d..b67a5a04cb 100644

hmp-commands.hx SRST · line 1340

Quoted 6 lines
hmp-commands.hx +3 -0
@@ -1335,6 +1335,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?",

Quoted 8 lines

hmp-commands.hx SRST · line 1341

Quoted 1 line
hmp-commands.hx +1 -0
+        .params     = "protocol [id] [src_ip] [dst_ip] [src_port] [dst_port]",

That ordering is a bit unnatural; it's normal to keep ip and port together; maybe this would be better as:

   protocol:s,id:s,src:s?,dst:s?

then pass src and dst through inet_parse to get your hostname and port ?

OK, already update to V5, please review it.

Thanks
Chen

Quoted 94 lines

Dave

hmp-commands.hx SRST

Quoted 12 lines
hmp-commands.hx +12 -0
+        .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?",

Quoted 18 lines
hmp-commands.hx +10 -0
+        .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 index renamed from include/monitor/hmp.h +0 -0

ed2913fd18..3c4943b09f 100644

include/monitor/hmp.h void hmp_device_del(Monitor *mon, const QDict · line 84

Quoted 4 lines
include/monitor/hmp.h +1 -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

Quoted 5 lines
include/monitor/hmp.h +1 -0
+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

3c88a4faef..b57e3430ab

monitor/hmp-cmds.c void hmp_netdev_del(Monitor *mon, const

Quoted 4 lines

100644

monitor/hmp-cmds.c +0 -0
@@ -1668,6 +1668,40 @@ void hmp_netdev_del(Monitor *mon, const

QDict *qdict)

monitor/hmp-cmds.c void hmp_netdev_del(Monitor *mon, const QDict *qdict)

Quoted 10 lines
monitor/hmp-cmds.c +7 -0
     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);

Quoted 6 lines
monitor/hmp-cmds.c +6 -0
+    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);

monitor/hmp-cmds.c void hmp_netdev_del(Monitor *mon, const QDict *qdict)

Quoted 10 lines
monitor/hmp-cmds.c +10 -0
+    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);

Quoted 12 lines
monitor/hmp-cmds.c +9 -1
+    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;
--
Quoted 2 lines

2.25.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#9 lore raw

RE: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

In reply to Markus Armbruster
Quoted 89 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, April 15, 2021 11:15 PM
To: Zhang, Chen <[email protected]>
Cc: Dr. David Alan Gilbert <[email protected]>; Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 3 lines · Chen
Quoted 3 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Dr. David

Alan

Quoted 6 lines
Quoted 6 lines

Gilbert
Sent: Wednesday, March 24, 2021 4:01 AM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Markus Armbruster

<[email protected]>;

Quoted 57 lines
Quoted 47 lines

Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 41 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +27 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
Quoted 9 lines

qapi/net.json line 826

Quoted 3 lines
qapi/net.json +3 -0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Quoted 3 lines

Hi Dave,

Considering that most of the scenes in Qemu don't call the

getprotobyname, looks keep the string are more readable.

Unless I'm missing something,

Quoted 8 lines

(1) this enum is only used for matching packets by source IP, source port, destination IP, destination port, and protocol, and

(2) the packet matching works just fine for *any* protocol.

By using an enum for the protocol, you're limiting the matcher to whatever protocols we bother to include in the enum for no particular reason. Feels wrong to me.

Should we remove the IP_PROTOCOL enum here? Make user input string protocol name for this field? Or any other detailed comments here?

Thanks
Chen

Quoted 15 lines
Quoted 15 lines

Please review the V5 patches, Thanks.

Thanks
Chen

Quoted 9 lines

Dave

Quoted 4 lines
qapi/net.json +1 -1
+
--

2.25.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#10 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 90 lines · Chen
Quoted 90 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, April 15, 2021 11:15 PM
To: Zhang, Chen <[email protected]>
Cc: Dr. David Alan Gilbert <[email protected]>; Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 3 lines · Chen
Quoted 3 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Dr. David

Alan

Quoted 6 lines
Quoted 6 lines

Gilbert
Sent: Wednesday, March 24, 2021 4:01 AM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Markus Armbruster

<[email protected]>;

Quoted 57 lines
Quoted 47 lines

Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 41 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +27 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
Quoted 9 lines

qapi/net.json line 826

Quoted 3 lines
qapi/net.json +3 -0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Quoted 3 lines

Hi Dave,

Considering that most of the scenes in Qemu don't call the

getprotobyname, looks keep the string are more readable.

Unless I'm missing something,

(1) this enum is only used for matching packets by source IP, source port, destination IP, destination port, and protocol, and

Quoted 8 lines
Quoted 5 lines

(2) the packet matching works just fine for *any* protocol.

By using an enum for the protocol, you're limiting the matcher to whatever protocols we bother to include in the enum for no particular reason. Feels wrong to me.

Should we remove the IP_PROTOCOL enum here? Make user input string protocol name for this field? Or any other detailed comments here?

I believe that's Dave's point. I.e.:

    { 'struct': 'L4_Connection',
      'data': { 'protocol': 'str', ... }

If we ever need to specify protocols by number in addition to name, we can compatibly evolve the 'str' into an alternation of 'str' and 'uint8'. Unlikely.

#11 lore raw

Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 101 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 90 lines · Chen
Quoted 90 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, April 15, 2021 11:15 PM
To: Zhang, Chen <[email protected]>
Cc: Dr. David Alan Gilbert <[email protected]>; Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 3 lines · Chen
Quoted 3 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Dr. David

Alan

Quoted 6 lines
Quoted 6 lines

Gilbert
Sent: Wednesday, March 24, 2021 4:01 AM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Markus Armbruster

<[email protected]>;

Quoted 57 lines
Quoted 47 lines

Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other QMP

commands.

Quoted 41 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +27 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
Quoted 9 lines

qapi/net.json line 826

Quoted 3 lines
qapi/net.json +3 -0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Quoted 3 lines

Hi Dave,

Considering that most of the scenes in Qemu don't call the

getprotobyname, looks keep the string are more readable.

Unless I'm missing something,

(1) this enum is only used for matching packets by source IP, source port, destination IP, destination port, and protocol, and

Quoted 8 lines
Quoted 5 lines

(2) the packet matching works just fine for *any* protocol.

By using an enum for the protocol, you're limiting the matcher to whatever protocols we bother to include in the enum for no particular reason. Feels wrong to me.

Should we remove the IP_PROTOCOL enum here? Make user input string protocol name for this field? Or any other detailed comments here?

Quoted 8 lines

I believe that's Dave's point. I.e.:

    { 'struct': 'L4_Connection',
      'data': { 'protocol': 'str', ... }

If we ever need to specify protocols by number in addition to name, we can compatibly evolve the 'str' into an alternation of 'str' and 'uint8'. Unlikely.

Right; just using a string and sending it via getprotobyname() actually seems easier than using the enum and having all the conversions.

Dave

Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
#12 lore raw

RE: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 125 lines

-----Original Message-----
From: Dr. David Alan Gilbert <[email protected]>
Sent: Tuesday, April 20, 2021 7:06 PM
To: Markus Armbruster <[email protected]>
Cc: Zhang, Chen <[email protected]>; Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu-dev <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 9 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 7 lines · Chen
Quoted 7 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: Thursday, April 15, 2021 11:15 PM
To: Zhang, Chen <[email protected]>
Cc: Dr. David Alan Gilbert <[email protected]>; Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu-dev <qemu-

[email protected]>; Zhang

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 3 lines · Chen
Quoted 3 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Dr.

David

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Alan

Quoted 6 lines
Quoted 6 lines

Gilbert
Sent: Wednesday, March 24, 2021 4:01 AM
To: Zhang, Chen <[email protected]>
Cc: Lukas Straub <[email protected]>; Li Zhijian <[email protected]>; Jason Wang <[email protected]>; qemu- dev <[email protected]>; Markus Armbruster

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

<[email protected]>;

Quoted 6 lines
Quoted 6 lines

Zhang Chen <[email protected]>
Subject: Re: [PATCH V4 1/7] qapi/net.json: Add IP_PROTOCOL definition

Quoted 1 line · * Zhang Chen ([email protected]) wrote:

Add IP_PROTOCOL as enum include TCP,UDP, ICMP... for other

QMP

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 52 lines
Quoted 42 lines

commands.

Quoted 41 lines
---
 qapi/net.json | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
qapi/net.json index renamed from qapi/net.json +0 -0

87361ebd9a..498ea7aa72 100644

qapi/net.json +27 -0
@@ -794,3 +794,34 @@
 #
 ##
 { 'command': 'query-netdev', 'returns': ['NetdevInfo'] }
+
+##
+# @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.1
Quoted 9 lines

qapi/net.json line 826

Quoted 3 lines
qapi/net.json +3 -0
+##
+{ 'enum': 'IP_PROTOCOL', 'data': [ 'tcp', 'udp', 'dccp', 'sctp', 'udplite',
+    'icmp', 'igmp', 'ipv6' ] }

Isn't the right thing to do here to use a string for protocol and then pass it to getprotobyname; that way your list is never out of date, and you never have to translate between the order of this enum and the integer assignment set in stone.

Quoted 3 lines

Hi Dave,

Considering that most of the scenes in Qemu don't call the

getprotobyname, looks keep the string are more readable.

Unless I'm missing something,

(1) this enum is only used for matching packets by source IP, source port, destination IP, destination port, and protocol, and

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

(2) the packet matching works just fine for *any* protocol.

By using an enum for the protocol, you're limiting the matcher to whatever protocols we bother to include in the enum for no particular reason. Feels wrong to me.

Should we remove the IP_PROTOCOL enum here? Make user input string

protocol name for this field?

Quoted 7 lines
Quoted 1 line

Or any other detailed comments here?

I believe that's Dave's point. I.e.:

    { 'struct': 'L4_Connection',
      'data': { 'protocol': 'str', ... }
Quoted 6 lines
Quoted 3 lines

If we ever need to specify protocols by number in addition to name, we can compatibly evolve the 'str' into an alternation of 'str' and 'uint8'. Unlikely.

Right; just using a string and sending it via getprotobyname() actually seems easier than using the enum and having all the conversions.

OK, Thanks for clear it. I already fixed it.
Please review the V6 of this series.

Thanks
Chen

Quoted 5 lines

Dave

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK