From nobody Wed Jan 7 09:26:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1767513320; cv=none; d=zohomail.com; s=zohoarc; b=RP+wVyKZMrGkgvYuRBb4/89AIrfTphqIG9Y8sThDy4Oq3BhcT+/O3OJN99DcltUZYgGXRrYV4cPRyDoEFxoinB1rMPWBOhtEyoy/kQAPEWIPbKqIjucCEPwRhRkj08QdlpcpPLLeNy00i2xZ01t9ONWaAatqLIkdV9HgexaTfR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767513320; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CVPAboRi8GsKhqIEX/T0rUfTBNXcx/r1uGbvlJ8zEgw=; b=ch4evzgyZuUlRhmkLPEMEiCyQGY0tTLeXfKB5svt+0kegXWw5DPQuBFELhQWyhmg7A9CDmyG7ryrINO99DRnULQn0fvDvHzzSzkeuHSVOeeGePCOwquN5ZWzFjafO5tR7lPEEoEBM/wtzejs8sZpjgPCoMC8XMS38vH81CGEKi0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767513320933697.3629184499767; Sat, 3 Jan 2026 23:55:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vcIwY-00084Z-US; Sun, 04 Jan 2026 02:54:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vcIwV-00083U-U6 for qemu-devel@nongnu.org; Sun, 04 Jan 2026 02:54:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vcIwT-0002Ip-TR for qemu-devel@nongnu.org; Sun, 04 Jan 2026 02:54:27 -0500 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-w250x8OVM_WQmWH1qtkVTA-1; Sun, 04 Jan 2026 02:54:23 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CBF341956050; Sun, 4 Jan 2026 07:54:21 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.156]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 19FE2180044F; Sun, 4 Jan 2026 07:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767513264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CVPAboRi8GsKhqIEX/T0rUfTBNXcx/r1uGbvlJ8zEgw=; b=Ma2POqDnYukHy6m5GazP+Yw5lppMi5OuRmjiwnOzTO0cmr58SkNu1/JLHSq9EyViqx/WRg Oxb5ZNxuyqwBPOcOMcwHeItWp/kPBxQaTMSIowITFKuz0dV6zvNpD6zn6KvFQEoHzMi93G JskqufFAwwj6ByGYZ4AL1vQ/3znChX4= X-MC-Unique: w250x8OVM_WQmWH1qtkVTA-1 X-Mimecast-MFC-AGG-ID: w250x8OVM_WQmWH1qtkVTA_1767513262 From: Jason Wang To: zhangckid@gmail.com, lizhijian@fujitsu.com, jasowang@redhat.com, qemu-devel@nongnu.org Cc: lulu@redhat.com Subject: [PATCH 1/3] net/filter-redirector: add support for dynamic status on/off switching Date: Sun, 4 Jan 2026 15:54:10 +0800 Message-ID: <20260104075412.1262-2-jasowang@redhat.com> In-Reply-To: <20260104075412.1262-1-jasowang@redhat.com> References: <20260104075412.1262-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1767513324032154100 Content-Type: text/plain; charset="utf-8" Currently, filter-redirector does not implement the status_changed callback, which means the 'status' property cannot be used to dynamically enable/disable the filter at runtime. When status is set to 'off' via QMP/HMP, the filter still receives data from the indev chardev because the chardev handlers remain registered. This patch adds proper support for the 'status' property: 1. Implement filter_redirector_status_changed() callback: - When status changes to 'off': remove chardev read handlers - When status changes to 'on': re-register chardev handlers (only if chardev is already open) 2. Update filter_redirector_setup() to respect initial status: - If filter is created with status=3Doff, do not register handlers - This allows creating disabled filters via command line or QMP 3. Handle chardev OPENED/CLOSED events to re-arm handlers on reconnect: - Keep the chr_event callback installed on CLOSE so a later OPENED can re-register the read handlers when nf->on - Use qemu_chr_fe_set_handlers_full(..., set_open=3Dfalse, sync_state=3D= false) instead of qemu_chr_fe_set_handlers() because the latter forces sync_state=3Dtrue and may emit CHR_EVENT_OPENED for an already-open backend. Doing that from inside the chr_event callback would cause recursive/re-entrant OPENED handling. Signed-off-by: Jason Wang --- net/filter-mirror.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 8e01e98f40..aa2ab452fd 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -179,9 +179,16 @@ static void redirector_chr_event(void *opaque, QEMUChr= Event event) MirrorState *s =3D FILTER_REDIRECTOR(nf); =20 switch (event) { + case CHR_EVENT_OPENED: + if (nf->on) { + qemu_chr_fe_set_handlers_full(&s->chr_in, redirector_chr_can_r= ead, + redirector_chr_read, redirector_= chr_event, + NULL, nf, NULL, false, false); + } + break; case CHR_EVENT_CLOSED: - qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, - NULL, NULL, NULL, true); + qemu_chr_fe_set_handlers_full(&s->chr_in, NULL, NULL, redirector_c= hr_event, + NULL, nf, NULL, false, false); break; default: break; @@ -306,9 +313,11 @@ static void filter_redirector_setup(NetFilterState *nf= , Error **errp) return; } =20 - qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, - redirector_chr_read, redirector_chr_event, - NULL, nf, NULL, true); + if (nf->on) { + qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, + redirector_chr_read, redirector_chr_e= vent, + NULL, nf, NULL, true); + } } =20 if (s->outdev) { @@ -324,6 +333,24 @@ static void filter_redirector_setup(NetFilterState *nf= , Error **errp) } } =20 +static void filter_redirector_status_changed(NetFilterState *nf, Error **e= rrp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(nf); + + if (!s->indev) { + return; + } + + if (nf->on) { + qemu_chr_fe_set_handlers(&s->chr_in, redirector_chr_can_read, + redirector_chr_read, redirector_chr_event, + NULL, nf, NULL, true); + } else { + qemu_chr_fe_set_handlers(&s->chr_in, NULL, NULL, NULL, + NULL, NULL, NULL, true); + } +} + static char *filter_redirector_get_indev(Object *obj, Error **errp) { MirrorState *s =3D FILTER_REDIRECTOR(obj); @@ -440,6 +467,7 @@ static void filter_redirector_class_init(ObjectClass *o= c, const void *data) nfc->setup =3D filter_redirector_setup; nfc->cleanup =3D filter_redirector_cleanup; nfc->receive_iov =3D filter_redirector_receive_iov; + nfc->status_changed =3D filter_redirector_status_changed; } =20 static void filter_mirror_init(Object *obj) --=20 2.34.1 From nobody Wed Jan 7 09:26:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1767513324; cv=none; d=zohomail.com; s=zohoarc; b=Ik5fuQ0rgSuDNxqy+qtZGkPOsJ5zlz5zPijSJIr14vI/pPKjdCzNTkRFU7uiXWIIK3V0l45OOy2VQ59HCt+8tn7ZpjWY44NMxrnLhaYdLhvcTjI098TqQOoSkWQkmtPgf6M1GGsRSGK1aOMGq9MvZEnGK4kMAkxxVLwjmJ/t7zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767513324; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JkaPeokfe5utn6p03yAUV+zIHdrTJ9M5DCqbRBawJ3I=; b=SKGiyQc7Xy2B5L8UQA/yLmf5dA7marjk5P1qY3XcYQyip1/1HlrfiAxNM2C7Jj6tUcfu1ka+QsU4IjZxu8lX+OhvCdoDXvo/ujYjBVjFmiGuWEdrCjbqtOwjnYeFJhDNnVZdlGov/x5oMbEJu/RkpaHE9d5ETzhEaf0o7RqhO4g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767513324812529.5114029255068; Sat, 3 Jan 2026 23:55:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vcIwb-00085f-6q; Sun, 04 Jan 2026 02:54:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vcIwZ-00085A-O6 for qemu-devel@nongnu.org; Sun, 04 Jan 2026 02:54:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vcIwY-0002JZ-1K for qemu-devel@nongnu.org; Sun, 04 Jan 2026 02:54:31 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-XOeLbcXBOXetdo_xOVyxLA-1; Sun, 04 Jan 2026 02:54:26 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 284F51956080; Sun, 4 Jan 2026 07:54:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.156]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 83E1C180044F; Sun, 4 Jan 2026 07:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767513269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JkaPeokfe5utn6p03yAUV+zIHdrTJ9M5DCqbRBawJ3I=; b=PlWQy4b9aC/fG6Pug019TEPPDEWe5A6VKZ06cpXvzgZmy6Hkhv6WSOComum0wFJIyiQZvl x3rr0zcUYN5vu7RqDSsfLXK1qYuWOX22wBCEgdDjOmqu8DtnTsuHSxg1oNKFJG5i4G5P9f 8wfEXf6ZUgPKisuX5uwiFvAWu5xfiSM= X-MC-Unique: XOeLbcXBOXetdo_xOVyxLA-1 X-Mimecast-MFC-AGG-ID: XOeLbcXBOXetdo_xOVyxLA_1767513265 From: Jason Wang To: zhangckid@gmail.com, lizhijian@fujitsu.com, jasowang@redhat.com, qemu-devel@nongnu.org Cc: lulu@redhat.com Subject: [PATCH 2/3] qtest: add a test to test redirector status change Date: Sun, 4 Jan 2026 15:54:11 +0800 Message-ID: <20260104075412.1262-3-jasowang@redhat.com> In-Reply-To: <20260104075412.1262-1-jasowang@redhat.com> References: <20260104075412.1262-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1767513327505154100 Content-Type: text/plain; charset="utf-8" This patch adds a qtest to test the status change of filter-redirector. Two subtests were added: - test_redirector_status: tests dynamic on/off switching at runtime using qom-set QMP command - test_redirector_init_status_off: tests creating filter-redirector with status=3Doff from the start via command line Both tests verify that: 1. When status is off, data from indev chardev is not received 2. When status is switched to on, data is received correctly Signed-off-by: Jason Wang Reviewed-by: Zhang Chen --- tests/qtest/test-filter-redirector.c | 192 +++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter= -redirector.c index a996a80c1c..da0c126314 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -196,10 +196,202 @@ static void test_redirector_rx(void) qtest_quit(qts); } =20 +/* + * Test filter-redirector status on/off switching. + * + * This test verifies that: + * 1. When status is set to "off", the filter stops receiving data from in= dev + * 2. When status is set back to "on", the filter resumes receiving data + */ +static void test_redirector_status(void) +{ + int backend_sock[2], send_sock; + uint32_t ret =3D 0, len =3D 0; + char send_buf[] =3D "Hello!!"; + char sock_path0[] =3D "filter-redirector0.XXXXXX"; + char *recv_buf; + uint32_t size =3D sizeof(send_buf); + size =3D htonl(size); + QTestState *qts; + struct timeval tv; + fd_set rfds; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path0); + g_assert_cmpint(ret, !=3D, -1); + + /* + * Setup a simple rx path: + * chardev (sock_path0) -> filter-redirector -> socket backend + */ + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dredirector0,path=3D%s,server=3Don,wait=3Doff= " + "-object filter-redirector,id=3Dqtest-f0,netdev=3Dqtest-bn0," + "queue=3Drx,indev=3Dredirector0 ", + backend_sock[1], sock_path0); + + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + + /* send a qmp command to guarantee that 'connected' is setting to true= . */ + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + /* + * Test 1: Set status to "off" and verify data is not received + */ + qtest_qmp_assert_success(qts, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/qtest-f0', 'property': 'status', 'value': 'of= f' }}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + /* + * Use select with timeout to check if data arrives. + * When status is off, no data should arrive. + */ + FD_ZERO(&rfds); + FD_SET(backend_sock[0], &rfds); + tv.tv_sec =3D 0; + tv.tv_usec =3D 500000; /* 500ms timeout */ + ret =3D select(backend_sock[0] + 1, &rfds, NULL, NULL, &tv); + g_assert_cmpint(ret, =3D=3D, 0); /* Should timeout, no data */ + + /* + * Test 2: Set status back to "on" and verify data is received + */ + qtest_qmp_assert_success(qts, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/qtest-f0', 'property': 'status', 'value': 'on= ' }}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + + g_free(recv_buf); + close(send_sock); + unlink(sock_path0); + qtest_quit(qts); +} + +/* + * Test filter-redirector created with status=3Doff. + * + * This test verifies that when a filter-redirector is created with + * status=3Doff, it does not receive data until status is set to on. + */ +static void test_redirector_init_status_off(void) +{ + int backend_sock[2], send_sock; + uint32_t ret =3D 0, len =3D 0; + char send_buf[] =3D "Hello!!"; + char sock_path0[] =3D "filter-redirector0.XXXXXX"; + char *recv_buf; + uint32_t size =3D sizeof(send_buf); + size =3D htonl(size); + QTestState *qts; + struct timeval tv; + fd_set rfds; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path0); + g_assert_cmpint(ret, !=3D, -1); + + /* + * Create filter-redirector with status=3Doff from the start + */ + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dredirector0,path=3D%s,server=3Don,wait=3Doff= " + "-object filter-redirector,id=3Dqtest-f0,netdev=3Dqtest-bn0," + "queue=3Drx,indev=3Dredirector0,status=3Doff ", + backend_sock[1], sock_path0); + + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + /* + * Test 1: Filter was created with status=3Doff, data should not be re= ceived + */ + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + FD_ZERO(&rfds); + FD_SET(backend_sock[0], &rfds); + tv.tv_sec =3D 0; + tv.tv_usec =3D 500000; + ret =3D select(backend_sock[0] + 1, &rfds, NULL, NULL, &tv); + g_assert_cmpint(ret, =3D=3D, 0); /* Should timeout, no data */ + + /* + * Test 2: Set status to "on" and verify data is received + */ + qtest_qmp_assert_success(qts, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': '/objects/qtest-f0', 'property': 'status', 'value': 'on= ' }}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + + g_free(recv_buf); + close(send_sock); + unlink(sock_path0); + qtest_quit(qts); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); qtest_add_func("/netfilter/redirector_tx", test_redirector_tx); qtest_add_func("/netfilter/redirector_rx", test_redirector_rx); + qtest_add_func("/netfilter/redirector_status", test_redirector_status); + qtest_add_func("/netfilter/redirector_init_status_off", + test_redirector_init_status_off); return g_test_run(); } --=20 2.34.1 From nobody Wed Jan 7 09:26:51 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1767513320; cv=none; d=zohomail.com; s=zohoarc; b=UM3zoKyLl/KcsClNiMZ2ognr6AdD43fupL6F3kcOZ9hFX7mio7LtfCpGmEHV3mZUQWOCJx/y8KLa5JPVfqH9rK4vk5LTXPkfW3U+/XeABZrlIxNKUqPnmshV0dXk46x4j+jGFIE1Ccnhk9kKf3PZRJ4T7ITBk6dr1GCXvZQCm4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767513320; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hYi2AdeJkUKmYKXNm64FjtkWNNMfAqqSRdIJknViB7Q=; b=DAQakHS7dHMm8oVQ7MQxOMlQHe/wfRFx0njt0dppQdFn9VdxiiuvsLMA15CJtmkCKH+64r2mpV2zBqV2wfbhpgAXyJvI1NSETNfFDPeO+UPp7vvHwsaQ/aqj1P/+szIF6WrQq2z5RLuFkOFkBFKLq4CjiQrwO/Kij+EruFzRGF4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767513320789938.0406165489127; Sat, 3 Jan 2026 23:55:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vcIwf-00086Z-ED; Sun, 04 Jan 2026 02:54:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vcIwd-00085r-4T for qemu-devel@nongnu.org; Sun, 04 Jan 2026 02:54:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vcIwb-0002K5-Kf for qemu-devel@nongnu.org; Sun, 04 Jan 2026 02:54:34 -0500 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-mWSuyD5RPpa7mxX-oXFjDA-1; Sun, 04 Jan 2026 02:54:29 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ABD18180035A; Sun, 4 Jan 2026 07:54:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.156]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF862180044F; Sun, 4 Jan 2026 07:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767513273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hYi2AdeJkUKmYKXNm64FjtkWNNMfAqqSRdIJknViB7Q=; b=XZe9AFV7CbeR3s5I+8FgkEOk7C8hbKmjf8xThbg7+ga8uWd/iTweIO21SXdL06VfoJpfmh or50R4NFCp37ssvNQ+2gKJsIlvjWjBSEMInIbQEooOZTiavGDFEFI8ha1I7J+ZaSB5X+0d QoL0XcqjQk7Ep7aRWoXrHJ2kPd76VRY= X-MC-Unique: mWSuyD5RPpa7mxX-oXFjDA-1 X-Mimecast-MFC-AGG-ID: mWSuyD5RPpa7mxX-oXFjDA_1767513268 From: Jason Wang To: zhangckid@gmail.com, lizhijian@fujitsu.com, jasowang@redhat.com, qemu-devel@nongnu.org Cc: lulu@redhat.com Subject: [PATCH 3/3] tests/qtest: Add test for filter-redirector rx event opened Date: Sun, 4 Jan 2026 15:54:12 +0800 Message-ID: <20260104075412.1262-4-jasowang@redhat.com> In-Reply-To: <20260104075412.1262-1-jasowang@redhat.com> References: <20260104075412.1262-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1767513324042154100 Content-Type: text/plain; charset="utf-8" Add a new test case 'test_redirector_rx_event_opened' to verify the handling of the CHR_EVENT_OPENED event in filter-redirector. The test simulates a scenario where the backend character device (socket) is disconnected and then reconnected. It works by: 1. Connecting to the redirector's socket (triggers CHR_EVENT_OPENED). 2. Sending a packet to verify initial connectivity. 3. Disconnecting (triggers CHR_EVENT_CLOSED). 4. Reconnecting (triggers CHR_EVENT_OPENED again). 5. Sending another packet to verify that the redirector correctly re-registers its handlers and resumes passing traffic. This ensures that the filter-redirector can recover and function correctly after a backend reconnection. Signed-off-by: Jason Wang --- tests/qtest/test-filter-redirector.c | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/qtest/test-filter-redirector.c b/tests/qtest/test-filter= -redirector.c index da0c126314..5540c232c0 100644 --- a/tests/qtest/test-filter-redirector.c +++ b/tests/qtest/test-filter-redirector.c @@ -385,6 +385,100 @@ static void test_redirector_init_status_off(void) qtest_quit(qts); } =20 +static void test_redirector_rx_event_opened(void) +{ + int backend_sock[2], send_sock; + uint32_t ret =3D 0, len =3D 0; + char send_buf[] =3D "Hello!!"; + char send_buf2[] =3D "Hello2!!"; + char sock_path0[] =3D "filter-redirector0.XXXXXX"; + char *recv_buf; + uint32_t size =3D sizeof(send_buf); + uint32_t size2 =3D sizeof(send_buf2); + size =3D htonl(size); + size2 =3D htonl(size2); + QTestState *qts; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, backend_sock); + g_assert_cmpint(ret, !=3D, -1); + + ret =3D mkstemp(sock_path0); + g_assert_cmpint(ret, !=3D, -1); + + qts =3D qtest_initf( + "-nic socket,id=3Dqtest-bn0,fd=3D%d " + "-chardev socket,id=3Dredirector0,path=3D%s,server=3Don,wait=3Doff= " + "-object filter-redirector,id=3Dqtest-f0,netdev=3Dqtest-bn0," + "queue=3Drx,indev=3Dredirector0 ", + backend_sock[1], sock_path0); + + struct iovec iov[] =3D { + { + .iov_base =3D &size, + .iov_len =3D sizeof(size), + }, { + .iov_base =3D send_buf, + .iov_len =3D sizeof(send_buf), + }, + }; + + struct iovec iov2[] =3D { + { + .iov_base =3D &size2, + .iov_len =3D sizeof(size2), + }, { + .iov_base =3D send_buf2, + .iov_len =3D sizeof(send_buf2), + }, + }; + + /* First connection */ + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + ret =3D iov_send(send_sock, iov, 2, 0, sizeof(size) + sizeof(send_buf)= ); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf); + g_free(recv_buf); + + close(send_sock); + + /* Verify disconnection handling if needed, but mainly we want to test= Reconnection */ + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + /* Second connection */ + send_sock =3D unix_connect(sock_path0, NULL); + g_assert_cmpint(send_sock, !=3D, -1); + qtest_qmp_assert_success(qts, "{ 'execute' : 'query-status'}"); + + ret =3D iov_send(send_sock, iov2, 2, 0, sizeof(size2) + sizeof(send_bu= f2)); + g_assert_cmpint(ret, =3D=3D, sizeof(send_buf2) + sizeof(size2)); + + ret =3D recv(backend_sock[0], &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + g_assert_cmpint(len, =3D=3D, sizeof(send_buf2)); + recv_buf =3D g_malloc(len); + ret =3D recv(backend_sock[0], recv_buf, len, 0); + g_assert_cmpint(ret, =3D=3D, len); + g_assert_cmpstr(recv_buf, =3D=3D, send_buf2); + g_free(recv_buf); + + close(send_sock); + unlink(sock_path0); + qtest_quit(qts); + close(backend_sock[0]); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -393,5 +487,7 @@ int main(int argc, char **argv) qtest_add_func("/netfilter/redirector_status", test_redirector_status); qtest_add_func("/netfilter/redirector_init_status_off", test_redirector_init_status_off); + qtest_add_func("/netfilter/redirector_rx_event_opened", + test_redirector_rx_event_opened); return g_test_run(); } --=20 2.34.1