Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2220684/?format=api
{ "id": 2220684, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2220684/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260407050818.2249570-3-lulu@redhat.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.1/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260407050818.2249570-3-lulu@redhat.com>", "date": "2026-04-07T05:05:49", "name": "[RFC,v4,2/5] chardev/socket: add AF_PACKET initialization", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "b8ae6622293291884ee72a394f5bcf0e92a73452", "submitter": { "id": 78960, "url": "http://patchwork.ozlabs.org/api/1.1/people/78960/?format=api", "name": "Cindy Lu", "email": "lulu@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260407050818.2249570-3-lulu@redhat.com/mbox/", "series": [ { "id": 499026, "url": "http://patchwork.ozlabs.org/api/1.1/series/499026/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=499026", "date": "2026-04-07T05:05:51", "name": "net/filter: Add AF_PACKET support for vhost-net", "version": 4, "mbox": "http://patchwork.ozlabs.org/series/499026/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2220684/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2220684/checks/", "tags": {}, "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=D2wyNQjM;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fqxBL0cLWz1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 08 Apr 2026 05:30:50 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wABXb-0000HR-MP; Tue, 07 Apr 2026 14:52:47 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <lulu@redhat.com>) id 1wABUI-0003uc-DO\n for qemu-devel@nongnu.org; Tue, 07 Apr 2026 14:49:22 -0400", "from us-smtp-delivery-124.mimecast.com ([170.10.133.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <lulu@redhat.com>) id 1w9yg3-0003HK-8N\n for qemu-devel@nongnu.org; Tue, 07 Apr 2026 01:08:41 -0400", "from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-522-Xke8I1JmOIud50myCEc5-g-1; Tue,\n 07 Apr 2026 01:08:35 -0400", "from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 04146195609F; Tue, 7 Apr 2026 05:08:34 +0000 (UTC)", "from S2.redhat.com (unknown [10.72.112.55])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 978301800351; Tue, 7 Apr 2026 05:08:30 +0000 (UTC)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1775538518;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=bSYhPjyMUCbINJQbYKmJPxVIaDBsqWDh+L4xXLOW1QQ=;\n b=D2wyNQjM/4xTm+h2D/OYZnLnTP25I6s/9oasKSK0l8OxQgVQrxJAbqm23Sa+KtM0e3757E\n og04+ETToayrMCBaxgENEZmI6Uf97uYuZMCHAHoK15h+i/S2XvVMpFyxlAbMLY0O3m/1K0\n rHYVTpds7q/VcLWwlkM4W/9Q5XyD84Q=", "X-MC-Unique": "Xke8I1JmOIud50myCEc5-g-1", "X-Mimecast-MFC-AGG-ID": "Xke8I1JmOIud50myCEc5-g_1775538514", "From": "Cindy Lu <lulu@redhat.com>", "To": "lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com,\n lizhijian@fujitsu.com, jmarcin@redhat.com, qemu-devel@nongnu.org", "Subject": "[RFC v4 2/5] chardev/socket: add AF_PACKET initialization", "Date": "Tue, 7 Apr 2026 13:05:49 +0800", "Message-ID": "<20260407050818.2249570-3-lulu@redhat.com>", "In-Reply-To": "<20260407050818.2249570-1-lulu@redhat.com>", "References": "<20260407050818.2249570-1-lulu@redhat.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.111", "Received-SPF": "pass client-ip=170.10.133.124; envelope-from=lulu@redhat.com;\n helo=us-smtp-delivery-124.mimecast.com", "X-Spam_score_int": "-25", "X-Spam_score": "-2.6", "X-Spam_bar": "--", "X-Spam_report": "(-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no", "X-Spam_action": "no action", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "qemu development <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "Teach socket chardevs to recognize AF_PACKET fds and record the state\nneeded by later TX/RX support. Add af-packet-mode=capture|inject to\nQAPI and command-line parsing, reject it for non-fd address types, and\nvalidate after a client fd is attached that the supplied fd really is\nAF_PACKET.\n\nThe socket chardev now tracks whether the underlying socket is\nAF_PACKET, owns separate send/receive staging buffers, and resets that\nstate on connection teardown and reconnect. The follow-up TX and RX\ncommits use this setup to translate between the redirector's existing\nlength-prefixed chardev framing and raw L2 packets.\n\nSigned-off-by: Cindy Lu <lulu@redhat.com>\n---\n chardev/char-socket.c | 104 +++++++++++++++++++++++++++++++++-\n chardev/char.c | 3 +\n include/chardev/char-socket.h | 13 +++++\n qapi/char.json | 23 +++++++-\n qemu-options.hx | 5 +-\n 5 files changed, 145 insertions(+), 3 deletions(-)", "diff": "diff --git a/chardev/char-socket.c b/chardev/char-socket.c\nindex 62852e3caf..c710fdb497 100644\n--- a/chardev/char-socket.c\n+++ b/chardev/char-socket.c\n@@ -23,6 +23,9 @@\n */\n \n #include \"qemu/osdep.h\"\n+#ifdef CONFIG_LINUX\n+#include <netpacket/packet.h>\n+#endif\n #include \"chardev/char.h\"\n #include \"io/channel-socket.h\"\n #include \"io/channel-websock.h\"\n@@ -32,6 +35,7 @@\n #include \"qapi/error.h\"\n #include \"qapi/clone-visitor.h\"\n #include \"qapi/qapi-visit-sockets.h\"\n+#include \"qapi/util.h\"\n #include \"qemu/yank.h\"\n #include \"trace.h\"\n \n@@ -326,6 +330,28 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, size_t len)\n return ret;\n }\n \n+static bool tcp_chr_is_af_packet(SocketChardev *s)\n+{\n+#ifdef CONFIG_LINUX\n+ return s->sioc && s->sioc->localAddr.ss_family == AF_PACKET;\n+#else\n+ return false;\n+#endif\n+}\n+\n+static void tcp_chr_reset_af_packet_buf(SocketChardev *s)\n+{\n+ s->af_packet_buf_len = 0;\n+ s->af_packet_buf_offset = 0;\n+}\n+\n+static void tcp_chr_reset_af_packet_send(SocketChardev *s)\n+{\n+ s->af_packet_send_len = 0;\n+ s->af_packet_send_offset = 0;\n+ s->af_packet_send_len_bytes = 0;\n+}\n+\n static GSource *tcp_chr_add_watch(Chardev *chr, GIOCondition cond)\n {\n SocketChardev *s = SOCKET_CHARDEV(chr);\n@@ -384,6 +410,15 @@ static void tcp_chr_free_connection(Chardev *chr)\n s->sioc = NULL;\n object_unref(OBJECT(s->ioc));\n s->ioc = NULL;\n+ g_free(s->af_packet_buf);\n+ s->af_packet_buf = NULL;\n+ s->af_packet_buf_size = 0;\n+ tcp_chr_reset_af_packet_buf(s);\n+ g_free(s->af_packet_send_buf);\n+ s->af_packet_send_buf = NULL;\n+ s->af_packet_send_buf_size = 0;\n+ tcp_chr_reset_af_packet_send(s);\n+ s->is_af_packet = false;\n g_free(chr->filename);\n chr->filename = NULL;\n tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);\n@@ -889,6 +924,26 @@ static void tcp_chr_set_client_ioc_name(Chardev *chr,\n \n }\n \n+static bool tcp_chr_validate_af_packet_mode_fd(Chardev *chr,\n+ QIOChannelSocket *sioc,\n+ Error **errp)\n+{\n+ SocketChardev *s = SOCKET_CHARDEV(chr);\n+\n+ if (!s->af_packet_mode_set) {\n+ return true;\n+ }\n+\n+#ifdef CONFIG_LINUX\n+ if (sioc->localAddr.ss_family == AF_PACKET) {\n+ return true;\n+ }\n+#endif\n+\n+ error_setg(errp, \"'af-packet-mode' requires an AF_PACKET fd\");\n+ return false;\n+}\n+\n static int tcp_chr_new_client(Chardev *chr, QIOChannelSocket *sioc)\n {\n SocketChardev *s = SOCKET_CHARDEV(chr);\n@@ -907,6 +962,9 @@ static int tcp_chr_new_client(Chardev *chr, QIOChannelSocket *sioc)\n object_ref(OBJECT(sioc));\n s->sioc = sioc;\n object_ref(OBJECT(sioc));\n+ s->is_af_packet = tcp_chr_is_af_packet(s);\n+ tcp_chr_reset_af_packet_buf(s);\n+ tcp_chr_reset_af_packet_send(s);\n \n if (s->do_nodelay) {\n qio_channel_set_delay(s->ioc, false);\n@@ -951,6 +1009,11 @@ static int tcp_chr_add_client(Chardev *chr, int fd)\n char_socket_yank_iochannel,\n QIO_CHANNEL(sioc));\n }\n+ if (!tcp_chr_validate_af_packet_mode_fd(chr, sioc, NULL)) {\n+ tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);\n+ object_unref(OBJECT(sioc));\n+ return -1;\n+ }\n ret = tcp_chr_new_client(chr, sioc);\n object_unref(OBJECT(sioc));\n return ret;\n@@ -990,7 +1053,17 @@ static int tcp_chr_connect_client_sync(Chardev *chr, Error **errp)\n char_socket_yank_iochannel,\n QIO_CHANNEL(sioc));\n }\n- tcp_chr_new_client(chr, sioc);\n+ if (!tcp_chr_validate_af_packet_mode_fd(chr, sioc, errp)) {\n+ tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);\n+ object_unref(OBJECT(sioc));\n+ return -1;\n+ }\n+ if (tcp_chr_new_client(chr, sioc) < 0) {\n+ tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);\n+ object_unref(OBJECT(sioc));\n+ error_setg(errp, \"failed to initialize socket chardev client\");\n+ return -1;\n+ }\n object_unref(OBJECT(sioc));\n return 0;\n }\n@@ -1312,6 +1385,11 @@ static bool qmp_chardev_validate_socket(ChardevSocket *sock,\n break;\n \n case SOCKET_ADDRESS_TYPE_UNIX:\n+ if (sock->has_af_packet_mode) {\n+ error_setg(errp,\n+ \"'af-packet-mode' option requires 'fd' address type\");\n+ return false;\n+ }\n if (sock->tls_creds) {\n error_setg(errp,\n \"'tls_creds' option is incompatible with \"\n@@ -1321,9 +1399,19 @@ static bool qmp_chardev_validate_socket(ChardevSocket *sock,\n break;\n \n case SOCKET_ADDRESS_TYPE_INET:\n+ if (sock->has_af_packet_mode) {\n+ error_setg(errp,\n+ \"'af-packet-mode' option requires 'fd' address type\");\n+ return false;\n+ }\n break;\n \n case SOCKET_ADDRESS_TYPE_VSOCK:\n+ if (sock->has_af_packet_mode) {\n+ error_setg(errp,\n+ \"'af-packet-mode' option requires 'fd' address type\");\n+ return false;\n+ }\n if (sock->tls_creds) {\n error_setg(errp,\n \"'tls_creds' option is incompatible with \"\n@@ -1386,6 +1474,10 @@ static void qmp_chardev_open_socket(Chardev *chr,\n s->is_tn3270 = is_tn3270;\n s->is_websock = is_websock;\n s->do_nodelay = do_nodelay;\n+ s->af_packet_mode_set = sock->has_af_packet_mode;\n+ if (sock->has_af_packet_mode) {\n+ s->af_packet_mode = sock->af_packet_mode;\n+ }\n if (sock->tls_creds) {\n Object *creds;\n creds = object_resolve_path_component(\n@@ -1463,6 +1555,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,\n const char *host = qemu_opt_get(opts, \"host\");\n const char *port = qemu_opt_get(opts, \"port\");\n const char *fd = qemu_opt_get(opts, \"fd\");\n+ const char *af_packet_mode = qemu_opt_get(opts, \"af-packet-mode\");\n #ifdef CONFIG_LINUX\n bool tight = qemu_opt_get_bool(opts, \"tight\", true);\n bool abstract = qemu_opt_get_bool(opts, \"abstract\", false);\n@@ -1516,6 +1609,15 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend,\n sock->wait = qemu_opt_get_bool(opts, \"wait\", true);\n sock->has_reconnect_ms = qemu_opt_find(opts, \"reconnect-ms\");\n sock->reconnect_ms = qemu_opt_get_number(opts, \"reconnect-ms\", 0);\n+ if (af_packet_mode) {\n+ sock->af_packet_mode =\n+ qapi_enum_parse(&ChardevSocketAfPacketMode_lookup,\n+ af_packet_mode, -1, errp);\n+ if (*errp) {\n+ return;\n+ }\n+ sock->has_af_packet_mode = true;\n+ }\n \n sock->tls_creds = g_strdup(qemu_opt_get(opts, \"tls-creds\"));\n sock->tls_authz = g_strdup(qemu_opt_get(opts, \"tls-authz\"));\ndiff --git a/chardev/char.c b/chardev/char.c\nindex 3e432195a5..39bb0d5b68 100644\n--- a/chardev/char.c\n+++ b/chardev/char.c\n@@ -910,6 +910,9 @@ QemuOptsList qemu_chardev_opts = {\n },{\n .name = \"websocket\",\n .type = QEMU_OPT_BOOL,\n+ },{\n+ .name = \"af-packet-mode\",\n+ .type = QEMU_OPT_STRING,\n },{\n .name = \"width\",\n .type = QEMU_OPT_NUMBER,\ndiff --git a/include/chardev/char-socket.h b/include/chardev/char-socket.h\nindex d6d13ad37f..8af8af6cf8 100644\n--- a/include/chardev/char-socket.h\n+++ b/include/chardev/char-socket.h\n@@ -63,6 +63,19 @@ struct SocketChardev {\n int *write_msgfds;\n size_t write_msgfds_num;\n bool registered_yank;\n+ bool is_af_packet;\n+ bool af_packet_mode_set;\n+ ChardevSocketAfPacketMode af_packet_mode;\n+ uint8_t *af_packet_buf;\n+ size_t af_packet_buf_size;\n+ size_t af_packet_buf_len;\n+ size_t af_packet_buf_offset;\n+ uint8_t *af_packet_send_buf;\n+ size_t af_packet_send_buf_size;\n+ size_t af_packet_send_len;\n+ size_t af_packet_send_offset;\n+ uint8_t af_packet_send_len_buf[sizeof(uint32_t)];\n+ size_t af_packet_send_len_bytes;\n \n SocketAddress *addr;\n bool is_listen;\ndiff --git a/qapi/char.json b/qapi/char.json\nindex 140614f82c..61a785727d 100644\n--- a/qapi/char.json\n+++ b/qapi/char.json\n@@ -237,6 +237,22 @@\n 'data': { 'device': 'str' },\n 'base': 'ChardevCommon' }\n \n+##\n+# @ChardevSocketAfPacketMode:\n+#\n+# AF_PACKET fd mode for socket chardevs.\n+#\n+# @capture: use recvfrom() to capture raw L2 frames and forward them\n+# through the existing chardev packet framing\n+#\n+# @inject: use sendmsg() to inject framed chardev packets back as raw\n+# L2 frames\n+#\n+# Since: 10.1\n+##\n+{ 'enum': 'ChardevSocketAfPacketMode',\n+ 'data': [ 'capture', 'inject' ] }\n+\n ##\n # @ChardevSocket:\n #\n@@ -274,6 +290,10 @@\n # Setting this to zero disables this function.\n # (default: 0) (Since: 9.2)\n #\n+# @af-packet-mode: when @addr is an fd that refers to an AF_PACKET\n+# socket, use raw packet capture or inject instead of stream\n+# socket I/O (Since: 10.1)\n+#\n # Since: 1.4\n ##\n { 'struct': 'ChardevSocket',\n@@ -286,7 +306,8 @@\n '*telnet': 'bool',\n '*tn3270': 'bool',\n '*websocket': 'bool',\n- '*reconnect-ms': 'int' },\n+ '*reconnect-ms': 'int',\n+ '*af-packet-mode': 'ChardevSocketAfPacketMode' },\n 'base': 'ChardevCommon' }\n \n ##\ndiff --git a/qemu-options.hx b/qemu-options.hx\nindex fca2b7bc74..0e3ce7f493 100644\n--- a/qemu-options.hx\n+++ b/qemu-options.hx\n@@ -4062,7 +4062,7 @@ The available backends are:\n A void device. This device will not emit any data, and will drop any\n data it receives. The null backend does not take any options.\n \n-``-chardev socket,id=id[,TCP options or unix options][,server=on|off][,wait=on|off][,telnet=on|off][,websocket=on|off][,reconnect-ms=milliseconds][,tls-creds=id][,tls-authz=id]``\n+``-chardev socket,id=id[,TCP options or unix options][,server=on|off][,wait=on|off][,telnet=on|off][,websocket=on|off][,reconnect-ms=milliseconds][,tls-creds=id][,tls-authz=id][,af-packet-mode=capture|inject]``\n Create a two-way stream socket, which can be either a TCP or a unix\n socket. A unix socket will be created if ``path`` is specified.\n Behaviour is undefined if TCP options are specified for a unix\n@@ -4095,6 +4095,9 @@ The available backends are:\n deleted and recreated on the fly while the chardev server is active.\n If missing, it will default to denying access.\n \n+ ``af-packet-mode=capture|inject`` is only valid with ``fd=...`` when\n+ the provided file descriptor is an AF_PACKET socket.\n+\n TCP and unix socket options are given below:\n \n ``TCP options: port=port[,host=host][,to=to][,ipv4=on|off][,ipv6=on|off][,nodelay=on|off]``\n", "prefixes": [ "RFC", "v4", "2/5" ] }