From nobody Sun Jan 25 11:58:47 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=1769171259; cv=none; d=zohomail.com; s=zohoarc; b=HdGhqpLAghhjFu5YyYeaX+gnvwTtNTInzI6aqxQRSlcGNO3Sr80DHrbVkOAO2F3tzx3d/wJKwjaJLEkrVip+ltcfXcRs23Ayyxyz6NBAq+OhUEEohCIslhrEsKt/LBL+2FsIrudTpCAW7uiV6w1hR9XZWq6Ct+OmW5V2LmJbvFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769171259; h=Content-Type: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=vaPMnSfoRztdHHij+NJ9O+nGEqaIxYFd+PHUxdtCIXI=; b=FXAwZ04d/1bBrYsTHu2AgImwSAbxVGaaDOFiYC0sZ7eYoR3Uj4gFn0AmgMcUpE7ouWhRuBlnK6mXNhyC4WfMD3DaAsFaSFX49Zi2Zh2YSJKN5POuZnroc75hLGY9dwRYecykzIPIUa1HRPHYwJbPHgg9e70y0IpqAqBh2I1cIt8= 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 1769171259021753.2516483925409; Fri, 23 Jan 2026 04:27:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vjGB3-0005vA-V1; Fri, 23 Jan 2026 07:22:14 -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 1vjGAj-0005LE-67 for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:56 -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 1vjGAh-00056X-Ar for qemu-devel@nongnu.org; Fri, 23 Jan 2026 07:21:52 -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-138-tNTOyCYFPIC-0Gz-wqlhAw-1; Fri, 23 Jan 2026 07:21:48 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 C7C8419775A8 for ; Fri, 23 Jan 2026 12:21:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.72.112.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0F4FF30002DC; Fri, 23 Jan 2026 12:21:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769170910; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vaPMnSfoRztdHHij+NJ9O+nGEqaIxYFd+PHUxdtCIXI=; b=ZTTckaCMZBx5vvcrLPFwZB8SPjLz3aH+/8LYQiF44XmXFxcU1bzuJwy7GwMg+oQGFtQqd9 Ro6HpCGIyuz6JShcO+r6fjJo1k8N1leLV/3zDm5a+FoamW2i10oC95OPFrcnvuViGwnqEp 37V5xPjztLtRuaSqIR7y83+9ANM40dg= X-MC-Unique: tNTOyCYFPIC-0Gz-wqlhAw-1 X-Mimecast-MFC-AGG-ID: tNTOyCYFPIC-0Gz-wqlhAw_1769170907 From: Jason Wang To: qemu-devel@nongnu.org Cc: Jason Wang Subject: [PULL 11/13] net/filter-redirector: add support for dynamic status on/off switching Date: Fri, 23 Jan 2026 20:21:00 +0800 Message-ID: <20260123122102.51422-12-jasowang@redhat.com> In-Reply-To: <20260123122102.51422-1-jasowang@redhat.com> References: <20260123122102.51422-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.079, 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_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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 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: 1769171261199158500 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 d2bfde42e8..6ac28067a2 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.42.0