From nobody Sun Apr 12 05:51:24 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=1770966726; cv=none; d=zohomail.com; s=zohoarc; b=QJRHwk+ZvH0ru1R4/SmLnHcVKVhQpBXEHi0QebWJwMOInnfVYpTKsBz0lhYofNSgwZunUDvFX41wYd2eK3tn4/zmVxDasTER50zhqCTEBXongKDFEnd3II45hkfWQrofKssLFJBAlGbtNrjCVTY7JSh5pojGmY02avY7N5Djxl0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770966726; h=Content-Transfer-Encoding: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:Cc; bh=b20rCQGyrr0CElHyI5DWoeAQC2Icos6G8aSwcR9I31E=; b=kZ9CwEeFvLmhLIE0bh4RQ8R9Pte2O/tvA3d6PkdPxQFwmq41+N3HiebbkFXAnCyoa35bS7e/k3zvhFfvnOA8hyuv7EVYgCCjXh0Bd+3BJJtx5gmI6yUCKrKQH2OAQdc/l9eMY5cwdI4N179qVqkviS+yO/oCpSE1dl5JXDt/zrw= 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 1770966726202328.9152221981817; Thu, 12 Feb 2026 23:12:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqnKR-0002a1-6K; Fri, 13 Feb 2026 02:11:03 -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 1vqnKO-0002ZS-Gu for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqnKM-0005bM-Td for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:00 -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-621-aqfdaTGSOnS9mUayZnDwYQ-1; Fri, 13 Feb 2026 02:10:55 -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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A4F81956054; Fri, 13 Feb 2026 07:10:54 +0000 (UTC) Received: from S2.redhat.com (unknown [10.72.112.33]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DEBE030001B9; Fri, 13 Feb 2026 07:10:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770966657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b20rCQGyrr0CElHyI5DWoeAQC2Icos6G8aSwcR9I31E=; b=Rod+xbv3AK2v7DYXfCSa/54OgNLLei4wKSY2pJt2vqBik+3K/HAox9q+s/oL0+BtjPNfRB rnRmmrswDhyZEn5qn0OJF819GohY92xMZPRke/gYYimVRkvPM1Fe8iAgWpHA4FQKXWBs1B xgeH+jqmU00ogAD2ayxPH5QaojL49Fw= X-MC-Unique: aqfdaTGSOnS9mUayZnDwYQ-1 X-Mimecast-MFC-AGG-ID: aqfdaTGSOnS9mUayZnDwYQ_1770966654 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com, lizhijian@fujitsu.com, qemu-devel@nongnu.org Subject: [RFC 1/5] net/filter: Allow redirector on vhost backends Date: Fri, 13 Feb 2026 15:08:01 +0800 Message-ID: <20260213071042.3733239-2-lulu@redhat.com> In-Reply-To: <20260213071042.3733239-1-lulu@redhat.com> References: <20260213071042.3733239-1-lulu@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.129.124; envelope-from=lulu@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_H4=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: 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: 1770966727333154100 Content-Type: text/plain; charset="utf-8" Allow filter redirector on vhost backends Signed-off-by: Cindy Lu --- net/filter.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/filter.c b/net/filter.c index 76345c1a9d..bbede6b085 100644 --- a/net/filter.c +++ b/net/filter.c @@ -255,8 +255,10 @@ static void netfilter_complete(UserCreatable *uc, Erro= r **errp) } =20 if (get_vhost_net(ncs[0])) { - error_setg(errp, "Vhost is not supported"); - return; + if (!object_dynamic_cast(OBJECT(uc), "filter-redirector")) { + error_setg(errp, "Vhost is not supported"); + return; + } } =20 if (strcmp(nf->position, "head") && strcmp(nf->position, "tail")) { --=20 2.52.0 From nobody Sun Apr 12 05:51:24 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=1770966708; cv=none; d=zohomail.com; s=zohoarc; b=kg8pToMN/A9ZNRlI5I7aWlIcNIEIXkMPKh4f+BVVAHgqCo/dRGQxeE7v6oqEkq07B/Jaj505V9MpN6U9m0sA84M6kKcfzMkW6Kzsk5kczb4IdaA+pt4jLCYp4JJFpoUDBzFFV4V/WHoWSU29rfXSSgABAVmsdVkQyPmkyxC6j2A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770966708; h=Content-Transfer-Encoding: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:Cc; bh=+6tgYpf+/FYgfC1vv57KmxBOSXnI9Crz3Q86VSJhAq4=; b=U2Lkys3ZMScwgSHEJmNrVQCruRTDPKkxNsuLWGH9/o3KyywyyPwnxctxHCnr28d+/Ula4lk90FcjxU/NrspgNAcNBbw/0whf9ZV0tnPCsFXeigzMObu+Szck/kfibdlr6EfgjlJ1nOnsqNLbAv59Lh6rc7G0xdhk5DpQEF31cnk= 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 1770966708204385.1886633014086; Thu, 12 Feb 2026 23:11:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqnKU-0002aq-LV; Fri, 13 Feb 2026 02:11:06 -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 1vqnKS-0002aZ-RH for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqnKR-0005bw-CC for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:04 -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-661-gHJW0tTyOAOYOtOdCW75lA-1; Fri, 13 Feb 2026 02:10:58 -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 EC5F11955D8D; Fri, 13 Feb 2026 07:10:57 +0000 (UTC) Received: from S2.redhat.com (unknown [10.72.112.33]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C931930001BE; Fri, 13 Feb 2026 07:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770966662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+6tgYpf+/FYgfC1vv57KmxBOSXnI9Crz3Q86VSJhAq4=; b=ZDKGknM0HtEYQsG0Aa3y/NkimJtM9VGUWanbbYuI+1GgkBo4tRC8qtx5KdzuP+z5YddLn9 bwCz2INbtwh84rTnOgEJ62a+EnUqCEK039nC2r2dFUKMhhJEuh2O9JhE4Yi5EbJLez7P4J kxsRIm05pqPJJ1AOdStvq0HgtktnMwA= X-MC-Unique: gHJW0tTyOAOYOtOdCW75lA-1 X-Mimecast-MFC-AGG-ID: gHJW0tTyOAOYOtOdCW75lA_1770966658 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com, lizhijian@fujitsu.com, qemu-devel@nongnu.org Subject: [RFC 2/5] net/filter-redirector: add in/out_netdev properties Date: Fri, 13 Feb 2026 15:08:02 +0800 Message-ID: <20260213071042.3733239-3-lulu@redhat.com> In-Reply-To: <20260213071042.3733239-1-lulu@redhat.com> References: <20260213071042.3733239-1-lulu@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.129.124; envelope-from=lulu@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_H4=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: 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: 1770966711121154100 Content-Type: text/plain; charset="utf-8" Introduce two new optional properties for filter-redirector: - in_netdev: specifies a TAP netdev to capture packets from using AF_PACKET sockets - out_netdev: specifies a netdev to inject packets into using AF_PACKET sockets These properties enable filter-redirector to work with vhost-net backends by bypassing the QEMU network stack entirely. Instead of relying on chardev sockets (indev/outdev), the redirector can directly capture/inject packets at the host TAP interface level. The in_netdev and out_netdev are mutually exclusive with each other and with their chardev counterparts (indev/outdev) on the same direction. Signed-off-by: Cindy Lu --- net/filter-mirror.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index ab711e8835..37035f3892 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -40,6 +40,8 @@ struct MirrorState { NetFilterState parent_obj; char *indev; char *outdev; + char *in_netdev; + char *out_netdev; CharFrontend chr_in; CharFrontend chr_out; SocketReadState rs; @@ -510,6 +512,40 @@ static void filter_redirector_set_outdev(Object *obj, s->outdev =3D g_strdup(value); } =20 +static char *filter_redirector_get_in_netdev(Object *obj, Error **errp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(obj); + + return g_strdup(s->in_netdev); +} + +static void filter_redirector_set_in_netdev(Object *obj, + const char *value, + Error **errp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(obj); + + g_free(s->in_netdev); + s->in_netdev =3D g_strdup(value); +} + +static char *filter_redirector_get_out_netdev(Object *obj, Error **errp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(obj); + + return g_strdup(s->out_netdev); +} + +static void filter_redirector_set_out_netdev(Object *obj, + const char *value, + Error **errp) +{ + MirrorState *s =3D FILTER_REDIRECTOR(obj); + + g_free(s->out_netdev); + s->out_netdev =3D g_strdup(value); +} + static bool filter_redirector_get_vnet_hdr(Object *obj, Error **errp) { MirrorState *s =3D FILTER_REDIRECTOR(obj); @@ -597,6 +633,12 @@ static void filter_redirector_class_init(ObjectClass *= oc, const void *data) filter_redirector_set_indev); object_class_property_add_str(oc, "outdev", filter_redirector_get_outd= ev, filter_redirector_set_outdev); + object_class_property_add_str(oc, "in_netdev", + filter_redirector_get_in_netdev, + filter_redirector_set_in_netdev); + object_class_property_add_str(oc, "out_netdev", + filter_redirector_get_out_netdev, + filter_redirector_set_out_netdev); object_class_property_add_bool(oc, "vnet_hdr_support", filter_redirector_get_vnet_hdr, filter_redirector_set_vnet_hdr); @@ -638,6 +680,8 @@ static void filter_redirector_fini(Object *obj) =20 g_free(s->indev); g_free(s->outdev); + g_free(s->in_netdev); + g_free(s->out_netdev); } =20 static const TypeInfo filter_redirector_info =3D { --=20 2.52.0 From nobody Sun Apr 12 05:51:24 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=1770966709; cv=none; d=zohomail.com; s=zohoarc; b=lgxYUI0rrJ4zhyyxtz6sOxujk9bp4vG0PiT0pWtZ0b9ZU65QzFrwduMy75ZkBHUzR3HF7Wterlgmmdo1rFaqUGH4WgFRSe6Z0duH9QeGVU23blct42cOkHkQPE2PnV9jmFql83Sotd17IT1NVwYsv80ZWbYu4oKuQaeckUYu4eE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770966709; h=Content-Transfer-Encoding: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:Cc; bh=JAZphhdyLWX/lOPr43JYhLTuyzZzE7b582uHiu2GZm8=; b=nEt7Py04Xl5+Mt3hmJfWjlLxeZFtE+TPEc1dnq+uyn2zRvEvzAjG7pUZBSR5gYyC0ue2Yph6gz+dbVhfqwsWPDGosVCoRF7XxpFRWFuq38RbnyU3PwDjoUX3ttyGICZskxLrkFrvAe4NdNv0on1y+cenkonWHZ8pNRbTrRVarvo= 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 1770966709336634.4431242688427; Thu, 12 Feb 2026 23:11:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqnKZ-0002bY-99; Fri, 13 Feb 2026 02:11:11 -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 1vqnKY-0002bO-4o for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:10 -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 1vqnKV-0005cG-L0 for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:09 -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-562-gw1XUclDP4uce-TG4dpkpQ-1; Fri, 13 Feb 2026 02:11:03 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EAF4818003F6; Fri, 13 Feb 2026 07:11:01 +0000 (UTC) Received: from S2.redhat.com (unknown [10.72.112.33]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AEE9530001B9; Fri, 13 Feb 2026 07:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770966666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JAZphhdyLWX/lOPr43JYhLTuyzZzE7b582uHiu2GZm8=; b=bu3aU2VIVokHY4a8AaNgSFiCa6xMV18+CqEpDirVaQCZ3mltXSE2O7L4Quo8YyIZA6WBpm zO4r8lxr9qIFJ6p12QbnmkH4FQGO1OakGisZQ7Nwl7XxCRmWdRd2EOxgdUyFKgT1RRY6Ov hLJm+eNkrSbdbu9wiDMVn3tfVJA/Ick= X-MC-Unique: gw1XUclDP4uce-TG4dpkpQ-1 X-Mimecast-MFC-AGG-ID: gw1XUclDP4uce-TG4dpkpQ_1770966662 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com, lizhijian@fujitsu.com, qemu-devel@nongnu.org Subject: [RFC 3/5] net/filter-redirector: Add AF_PACKET sockets initialization Date: Fri, 13 Feb 2026 15:08:03 +0800 Message-ID: <20260213071042.3733239-4-lulu@redhat.com> In-Reply-To: <20260213071042.3733239-1-lulu@redhat.com> References: <20260213071042.3733239-1-lulu@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=lulu@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_H2=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: 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: 1770966712302158500 Content-Type: text/plain; charset="utf-8" Implement the initialization logic for AF_PACKET based netdev endpoints in filter-redirector: 1. filter_redirector_netdev_setup(): Creates and binds AF_PACKET sockets to the specified TAP interface. For in_netdev, the socket is used to receive packets; for out_netdev, it is used to send. 2. filter_redirector_netdev_read(): Async handler for reading packets from the in_netdev AF_PACKET socket. Packets are forwarded through the redirector chain. 3. Updated cleanup to properly close AF_PACKET sockets and free associated buffers. 4. Modified allow_send_when_stopped logic to consider both chardev and netdev output endpoints, and to only enable when the redirector is active (status=3Don). 5. VM state change handler now manages the AF_PACKET read handler activation based on VM running state and enable_when_stopped. Signed-off-by: Cindy Lu --- net/filter-mirror.c | 241 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 224 insertions(+), 17 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 37035f3892..f8001612ec 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -26,6 +26,13 @@ #include "qemu/sockets.h" #include "block/aio-wait.h" #include "system/runstate.h" +#include "net/tap.h" +#include "net/tap_int.h" + +#include +#include +#include +#include =20 typedef struct MirrorState MirrorState; DECLARE_INSTANCE_CHECKER(MirrorState, FILTER_MIRROR, @@ -42,6 +49,10 @@ struct MirrorState { char *outdev; char *in_netdev; char *out_netdev; + NetClientState *out_net; + int in_netfd; + uint8_t *in_netbuf; + int out_netfd; CharFrontend chr_in; CharFrontend chr_out; SocketReadState rs; @@ -172,6 +183,17 @@ static int redirector_chr_can_read(void *opaque) return REDIRECTOR_MAX_LEN; } =20 +static bool filter_redirector_input_active(NetFilterState *nf, bool enable) +{ + MirrorState *s =3D FILTER_REDIRECTOR(nf); + + if (!enable) { + return false; + } + + return runstate_is_running() || s->enable_when_stopped; +} + static void redirector_chr_read(void *opaque, const uint8_t *buf, int size) { NetFilterState *nf =3D opaque; @@ -208,6 +230,40 @@ static void redirector_chr_event(void *opaque, QEMUChr= Event event) } } =20 +static void filter_redirector_netdev_read(void *opaque) +{ + NetFilterState *nf =3D opaque; + MirrorState *s =3D FILTER_REDIRECTOR(nf); + struct sockaddr_ll sll; + socklen_t sll_len; + ssize_t len; + + if (!s->in_netbuf || s->in_netfd < 0) { + return; + } + + for (;;) { + sll_len =3D sizeof(sll); + len =3D recvfrom(s->in_netfd, s->in_netbuf, REDIRECTOR_MAX_LEN, 0, + (struct sockaddr *)&sll, &sll_len); + if (len <=3D 0) { + break; + } + + if (sll.sll_pkttype !=3D PACKET_OUTGOING) { + continue; + } + + redirector_to_filter(nf, s->in_netbuf, len); + } + + if (len < 0 && errno !=3D EAGAIN && errno !=3D EWOULDBLOCK && + errno !=3D EINTR) { + error_report("filter redirector read in_netdev failed(%s)", + strerror(errno)); + } +} + static ssize_t filter_mirror_receive_iov(NetFilterState *nf, NetClientState *sender, unsigned flags, @@ -268,7 +324,19 @@ static void filter_redirector_cleanup(NetFilterState *= nf) =20 qemu_chr_fe_deinit(&s->chr_in, false); qemu_chr_fe_deinit(&s->chr_out, false); - qemu_del_vm_change_state_handler(s->vmsentry); + if (s->vmsentry) { + qemu_del_vm_change_state_handler(s->vmsentry); + s->vmsentry =3D NULL; + } + if (s->in_netfd >=3D 0) { + qemu_set_fd_handler(s->in_netfd, NULL, NULL, NULL); + close(s->in_netfd); + s->in_netfd =3D -1; + } + if (s->out_netfd >=3D 0) { + close(s->out_netfd); + s->out_netfd =3D -1; + } =20 if (nf->netdev) { nf->netdev->allow_send_when_stopped =3D 0; @@ -320,13 +388,13 @@ filter_redirector_refresh_allow_send_when_stopped(Net= FilterState *nf) =20 /* * Allow sending when stopped if enable_when_stopped is set and we have - * an outdev. This must be independent of nf->on (status) so that pack= ets - * can still flow through the filter chain to other filters even when = this - * redirector is disabled. Otherwise, tap_send() will disable read_poll - * when qemu_can_send_packet() returns false, preventing further packet - * processing. + * a redirector output endpoint and the redirector is enabled. + * Keeping this active while redirector status=3Doff can unexpectedly + * drain packets in migration stop windows and perturb vhost ring stat= e. */ - nc->allow_send_when_stopped =3D (s->enable_when_stopped && s->outdev); + nc->allow_send_when_stopped =3D (nf->on && + s->enable_when_stopped && + (s->outdev || s->out_netdev)); } =20 static void filter_redirector_vm_state_change(void *opaque, bool running, @@ -335,8 +403,16 @@ static void filter_redirector_vm_state_change(void *op= aque, bool running, NetFilterState *nf =3D opaque; MirrorState *s =3D FILTER_REDIRECTOR(nf); NetClientState *nc =3D nf->netdev; + bool active =3D filter_redirector_input_active(nf, nf->on); + + if (s->in_netfd >=3D 0) { + qemu_set_fd_handler(s->in_netfd, + active ? filter_redirector_netdev_read : NULL, + NULL, + active ? nf : NULL); + } =20 - if (!running && s->enable_when_stopped && nc->info->read_poll) { + if (!running && nc && s->enable_when_stopped && nc->info->read_poll) { nc->info->read_poll(nc, true); } } @@ -362,21 +438,127 @@ static void filter_redirector_maybe_enable_read_poll= (NetFilterState *nf) } } =20 +static bool filter_redirector_netdev_setup(MirrorState *s, Error **errp) +{ + struct sockaddr_ll sll =3D { 0 }; + char ifname[IFNAMSIZ] =3D { 0 }; + int ifindex; + int fd; + NetClientState *nc; + + if (s->in_netdev) { + int tapfd; + nc =3D qemu_find_netdev(s->in_netdev); + if (!nc) { + error_setg(errp, "in_netdev '%s' not found", s->in_netdev); + return false; + } + + if (nc->info->type !=3D NET_CLIENT_DRIVER_TAP) { + error_setg(errp, "in_netdev '%s' must be a TAP netdev", + s->in_netdev); + return false; + } + + tapfd =3D tap_get_fd(nc); + if (tapfd < 0 || tap_fd_get_ifname(tapfd, ifname) !=3D 0) { + error_setg(errp, "failed to resolve TAP ifname for in_netdev '= %s'", + s->in_netdev); + return false; + } + } else if (s->out_netdev) { + nc =3D qemu_find_netdev(s->out_netdev); + if (!nc) { + error_setg(errp, "out_netdev '%s' not found", s->out_netdev); + return false; + } + /* + * out_netdev always uses AF_PACKET. For TAP netdev we resolve the + * interface name from tap fd; for non-TAP netdev we interpret + * out_netdev string as host interface name. + */ + if (nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { + int tapfd =3D tap_get_fd(nc); + + if (tapfd < 0 || tap_fd_get_ifname(tapfd, ifname) !=3D 0) { + error_setg(errp, + "failed to resolve TAP ifname for out_netdev '%= s'", + s->out_netdev); + return false; + } + } else { + snprintf(ifname, sizeof(ifname), "%s", s->out_netdev); + } + } + + ifindex =3D if_nametoindex(ifname); + if (!ifindex) { + error_setg_errno(errp, errno, + "failed to resolve ifindex for '%s'", ifname); + return false; + } + + fd =3D qemu_socket(AF_PACKET, SOCK_RAW | SOCK_NONBLOCK, htons(ETH_P_AL= L)); + if (fd < 0) { + error_setg_errno(errp, errno, "failed to create AF_PACKET socket"); + return false; + } + + sll.sll_family =3D AF_PACKET; + sll.sll_ifindex =3D ifindex; + sll.sll_protocol =3D htons(ETH_P_ALL); + if (bind(fd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { + error_setg_errno(errp, errno, + "failed to bind AF_PACKET socket for ifname '%s'", + ifname); + close(fd); + return false; + } + + if (s->in_netdev) { + s->in_netfd =3D fd; + g_free(s->in_netbuf); + s->in_netbuf =3D g_malloc(REDIRECTOR_MAX_LEN); + } else { + s->out_netfd =3D fd; + s->out_net =3D nc; + } + return true; +} + static void filter_redirector_setup(NetFilterState *nf, Error **errp) { MirrorState *s =3D FILTER_REDIRECTOR(nf); Chardev *chr; =20 - if (!s->indev && !s->outdev) { - error_setg(errp, "filter redirector needs 'indev' or " - "'outdev' at least one property set"); + if (!s->indev && !s->outdev && !s->in_netdev && !s->out_netdev) { + error_setg(errp, "filter redirector needs at least one of " + "'indev', 'outdev', 'in_netdev', or 'out_netdev'"); + return; + } + + if (s->indev && s->in_netdev) { + error_setg(errp, "'indev' and 'in_netdev' cannot both be set " + "for filter redirector"); + return; + } + + if (s->outdev && s->out_netdev) { + error_setg(errp, "'outdev' and 'out_netdev' cannot both be set " + "for filter redirector"); + return; + } + + if (s->in_netdev && s->out_netdev) { + error_setg(errp, "'in_netdev' and 'out_netdev' cannot both be set " + "for filter redirector"); + return; + } + + if (s->indev && s->outdev && !strcmp(s->indev, s->outdev)) { + error_setg(errp, "'indev' and 'outdev' could not be same " + "for filter redirector"); return; - } else if (s->indev && s->outdev) { - if (!strcmp(s->indev, s->outdev)) { - error_setg(errp, "'indev' and 'outdev' could not be same " - "for filter redirector"); - return; - } } =20 net_socket_rs_init(&s->rs, redirector_rs_finalize, s->vnet_hdr); @@ -412,9 +594,23 @@ static void filter_redirector_setup(NetFilterState *nf= , Error **errp) } } =20 + if (s->out_netdev || s->in_netdev) { + if (!filter_redirector_netdev_setup(s, errp)) { + return; + } + } + s->vmsentry =3D qemu_add_vm_change_state_handler( filter_redirector_vm_state_change, nf); =20 + if (s->in_netfd >=3D 0) { + bool active =3D filter_redirector_input_active(nf, nf->on); + + qemu_set_fd_handler(s->in_netfd, + active ? filter_redirector_netdev_read : NULL, + NULL, + active ? nf : NULL); + } filter_redirector_maybe_enable_read_poll(nf); =20 filter_redirector_refresh_allow_send_when_stopped(nf); @@ -423,6 +619,7 @@ static void filter_redirector_setup(NetFilterState *nf,= Error **errp) static void filter_redirector_status_changed(NetFilterState *nf, Error **e= rrp) { MirrorState *s =3D FILTER_REDIRECTOR(nf); + bool active =3D filter_redirector_input_active(nf, nf->on); =20 if (s->indev) { if (nf->on) { @@ -435,6 +632,13 @@ static void filter_redirector_status_changed(NetFilter= State *nf, Error **errp) } } =20 + if (s->in_netfd >=3D 0) { + qemu_set_fd_handler(s->in_netfd, + active ? filter_redirector_netdev_read : NULL, + NULL, + active ? nf : NULL); + } + if (nf->on) { filter_redirector_maybe_enable_read_poll(nf); } @@ -665,6 +869,8 @@ static void filter_redirector_init(Object *obj) MirrorState *s =3D FILTER_REDIRECTOR(obj); =20 s->vnet_hdr =3D false; + s->in_netfd =3D -1; + s->out_netfd =3D -1; } =20 static void filter_mirror_fini(Object *obj) @@ -682,6 +888,7 @@ static void filter_redirector_fini(Object *obj) g_free(s->outdev); g_free(s->in_netdev); g_free(s->out_netdev); + g_free(s->in_netbuf); } =20 static const TypeInfo filter_redirector_info =3D { --=20 2.52.0 From nobody Sun Apr 12 05:51:24 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=1770966741; cv=none; d=zohomail.com; s=zohoarc; b=dbBgD32Bv51m6bhkVkk9G+cgtsYIjPkYskxhnpeUBUQ6hUIVHgMBNWy3PmZhzmbbUu4VwZAQ1Dt41Cym5NO2n6RmzRZwcMiYivZoMSyFhnhtwDDGKizwK/BFEDJEkVVtf0qhzh5mBeqPV8DH2SQP2A0wl+wAIVbepR4qcLgHGvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770966741; h=Content-Transfer-Encoding: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:Cc; bh=HfmaBTP49ifwDZty9C9MLcDDDX6UwWiMdcZezZPYKs0=; b=a5CE8PpDKsHLqgqLdLJFVBQHok4k9sX2LYrT5gsO7ke+2fdQaLz97fqUN8rgOLHtq7AKqwm5IzeSgBsi9LiCn7rK4eVSWGmXYWhzzsqgqKg7jtR8MrtIK5+Ji+u0zqt+hVVEj91ran3mjF+V7mPEPAqOaL+xdxMVAG0xUHkVpL8= 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 1770966741089107.41824109825757; Thu, 12 Feb 2026 23:12:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqnL2-0002k7-0T; Fri, 13 Feb 2026 02:11:40 -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 1vqnKy-0002jb-2G for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:36 -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 1vqnKv-0005eC-PB for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:35 -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-176-3GPXCd5hOvuvtV6Qi5_0cA-1; Fri, 13 Feb 2026 02:11: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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 343651955D8F; Fri, 13 Feb 2026 07:11:28 +0000 (UTC) Received: from S2.redhat.com (unknown [10.72.112.33]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E09801800464; Fri, 13 Feb 2026 07:11:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770966693; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HfmaBTP49ifwDZty9C9MLcDDDX6UwWiMdcZezZPYKs0=; b=BCgWYEQKnImQpGsDAP94XN9e62koCQUo53WXDXqE0mtN5BLV99bQmkGaerXgIvSqYKzJIG Ii9tV5SOIhWjIJ4HA7nshg2d5sLeoHv7aIjtDXorV+pySp6bzxe6GAtBiwzebopQyyWWjw VgSjJ5zAvt/wP9jbU3ZlX9KgBhGCw7E= X-MC-Unique: 3GPXCd5hOvuvtV6Qi5_0cA-1 X-Mimecast-MFC-AGG-ID: 3GPXCd5hOvuvtV6Qi5_0cA_1770966688 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com, lizhijian@fujitsu.com, qemu-devel@nongnu.org Subject: [RFC 4/5] net/filter-redirector: add AF_PACKET redirect datapath Date: Fri, 13 Feb 2026 15:08:04 +0800 Message-ID: <20260213071042.3733239-5-lulu@redhat.com> In-Reply-To: <20260213071042.3733239-1-lulu@redhat.com> References: <20260213071042.3733239-1-lulu@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 client-ip=170.10.133.124; envelope-from=lulu@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_H2=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: 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: 1770966743164154100 Content-Type: text/plain; charset="utf-8" Complete the AF_PACKET based packet forwarding implementation for filter-redirector: 1. filter_redirector_send_netdev_packet(): Send packets via AF_PACKET socket to out_netdev. Updates netdev_tx statistics. 2. filter_redirector_recv_from_chardev(): Handle packets received from chardev indev. Can forward to either chardev outdev, AF_PACKET out_netdev, or inject into the netfilter chain. 3. filter_redirector_recv_from_netdev(): Handle packets received from AF_PACKET in_netdev. Can forward to chardev outdev or inject into the netfilter chain. 4. Updated filter_redirector_receive_iov() to support out_netdev as an output endpoint. Added logic to skip netdev path consumption when redirector has an input endpoint (indev/in_netdev) to prevent packet loops. 5. Added netdev_rx and netdev_tx counters to query-netfilter-stats output for monitoring AF_PACKET datapath activity. Signed-off-by: Cindy Lu --- net/filter-mirror.c | 177 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 171 insertions(+), 6 deletions(-) diff --git a/net/filter-mirror.c b/net/filter-mirror.c index f8001612ec..d9e8fcba59 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -65,6 +65,11 @@ struct MirrorState { uint64_t indev_bytes; uint64_t outdev_packets; uint64_t outdev_bytes; + /* netdev replay/capture statistics for filter-redirector */ + uint64_t netdev_rx_packets; + uint64_t netdev_rx_bytes; + uint64_t netdev_tx_packets; + uint64_t netdev_tx_bytes; }; =20 typedef struct FilterSendCo { @@ -158,6 +163,59 @@ static int filter_send(MirrorState *s, return data.ret; } =20 +static ssize_t filter_redirector_send_netdev_packet(MirrorState *s, + const struct iovec *io= v, + int iovcnt) +{ + ssize_t size =3D iov_size(iov, iovcnt); + g_autofree uint8_t *buf =3D NULL; + + if (s->out_netfd < 0) { + return -ENODEV; + } + if (size > NET_BUFSIZE) { + return -EINVAL; + } + + buf =3D g_malloc(size); + iov_to_buf(iov, iovcnt, 0, buf, size); + + ssize_t ret =3D send(s->out_netfd, buf, size, 0); + if (ret < 0) { + return -errno; + } + if (ret > 0) { + s->netdev_tx_packets++; + s->netdev_tx_bytes +=3D ret; + } + return ret; +} +static ssize_t filter_redirector_send_chardev_iov(MirrorState *s, + const struct iovec *iov, + int iovcnt) +{ + if (!s->outdev) { + return -ENODEV; + } + + if (!qemu_chr_fe_backend_connected(&s->chr_out)) { + return 0; + } + + return filter_send(s, iov, iovcnt); +} + +static ssize_t filter_redirector_send_netdev_iov(MirrorState *s, + const struct iovec *iov, + int iovcnt) +{ + if (!s->out_netdev) { + return -ENODEV; + } + + return filter_redirector_send_netdev_packet(s, iov, iovcnt); +} + static void redirector_to_filter(NetFilterState *nf, const uint8_t *buf, int len) @@ -230,6 +288,75 @@ static void redirector_chr_event(void *opaque, QEMUChr= Event event) } } =20 +static void filter_redirector_recv_from_chardev(NetFilterState *nf, + const uint8_t *buf, + int len) +{ + MirrorState *s =3D FILTER_REDIRECTOR(nf); + ssize_t ret; + struct iovec iov =3D { + .iov_base =3D (void *)buf, + .iov_len =3D len, + }; + + if (len <=3D 0) { + return; + } + + /* chardev indev */ + s->indev_packets++; + s->indev_bytes +=3D len; + + if (s->out_netdev) { + ret =3D filter_redirector_send_netdev_iov(s, &iov, 1); + if (ret < 0) { + error_report("filter redirector send failed(%s)", strerror(-re= t)); + } + return; + } + + if (s->outdev) { + ret =3D filter_redirector_send_chardev_iov(s, &iov, 1); + if (ret < 0) { + error_report("filter redirector send failed(%s)", strerror(-re= t)); + } else if (ret > 0) { + s->outdev_packets++; + s->outdev_bytes +=3D ret; + } + return; + } + + redirector_to_filter(nf, buf, len); +} + +static bool filter_redirector_recv_from_netdev(NetFilterState *nf, + const uint8_t *b= uf, + int len) +{ + MirrorState *s =3D FILTER_REDIRECTOR(nf); + ssize_t ret; + struct iovec iov =3D { + .iov_base =3D (void *)buf, + .iov_len =3D len, + }; + + if (len <=3D 0) { + return false; + } + if (s->outdev) { + ret =3D filter_redirector_send_chardev_iov(s, &iov, 1); + } else { + redirector_to_filter(nf, buf, len); + return true; + } + + if (ret < 0) { + error_report("filter redirector send failed(%s)", strerror(-ret)); + return false; + } + return true; +} + static void filter_redirector_netdev_read(void *opaque) { NetFilterState *nf =3D opaque; @@ -254,7 +381,9 @@ static void filter_redirector_netdev_read(void *opaque) continue; } =20 - redirector_to_filter(nf, s->in_netbuf, len); + s->netdev_rx_packets++; + s->netdev_rx_bytes +=3D len; + filter_redirector_recv_from_netdev(nf, s->in_netbuf, len); } =20 if (len < 0 && errno !=3D EAGAIN && errno !=3D EWOULDBLOCK && @@ -296,19 +425,33 @@ static ssize_t filter_redirector_receive_iov(NetFilte= rState *nf, MirrorState *s =3D FILTER_REDIRECTOR(nf); int ret; =20 - if (qemu_chr_fe_backend_connected(&s->chr_out)) { - ret =3D filter_send(s, iov, iovcnt); + /* + * If this redirector has an explicit input endpoint (indev/in_netdev), + * it acts as an injector for that endpoint and must not consume packe= ts + * from the regular netdev data path. Consuming here can create loops = when + * out_netdev points back to the same TAP netdev. + */ + if (s->indev || s->in_netdev) { + return 0; + } + + if (s->out_netdev || s->outdev) { + if (s->out_netdev) { + ret =3D filter_redirector_send_netdev_iov(s, iov, iovcnt); + } else { + ret =3D filter_redirector_send_chardev_iov(s, iov, iovcnt); + } if (ret < 0) { error_report("filter redirector send failed(%s)", strerror(-re= t)); - } else if (ret > 0) { + } else if (ret > 0 && !s->out_netdev) { /* Update outdev statistics on successful send */ s->outdev_packets++; s->outdev_bytes +=3D ret; } return iov_size(iov, iovcnt); - } else { - return 0; } + + return 0; } =20 static void filter_mirror_cleanup(NetFilterState *nf) @@ -369,6 +512,16 @@ static void redirector_rs_finalize(SocketReadState *rs) MirrorState *s =3D container_of(rs, MirrorState, rs); NetFilterState *nf =3D NETFILTER(s); =20 + /* + * If redirector has an explicit output endpoint, keep the redirect pa= th + * (e.g. indev=3Dred0 -> out_netdev=3Dnet0). + * Fallback to direct netfilter injection only when no output is set. + */ + if (s->outdev || s->out_netdev) { + filter_redirector_recv_from_chardev(nf, rs->buf, rs->packet_len); + return; + } + /* Update indev statistics */ s->indev_packets++; s->indev_bytes +=3D rs->packet_len; @@ -826,6 +979,18 @@ static GList *filter_redirector_get_stats(NetFilterSta= te *nf) counter->bytes =3D s->outdev_bytes; list =3D g_list_append(list, counter); =20 + counter =3D g_new0(NetFilterCounter, 1); + counter->name =3D g_strdup("netdev_rx"); + counter->packets =3D s->netdev_rx_packets; + counter->bytes =3D s->netdev_rx_bytes; + list =3D g_list_append(list, counter); + + counter =3D g_new0(NetFilterCounter, 1); + counter->name =3D g_strdup("netdev_tx"); + counter->packets =3D s->netdev_tx_packets; + counter->bytes =3D s->netdev_tx_bytes; + list =3D g_list_append(list, counter); + return list; } =20 --=20 2.52.0 From nobody Sun Apr 12 05:51:24 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=1770966708; cv=none; d=zohomail.com; s=zohoarc; b=ImiDMFKHodUHytRZj0q4jLl4jqX8J9advwPxQ+ihIjVHgmeeBxyM0UYj1exgjq2GTkWleJBh9aPMkbw1OJ3rTQXAHfE9P92ZR36VCcNVjo53khkTwd2tHIxe/yWRbPnf254KZMxME0DPDv601MdOmcrlwZYsyp+QbTPP6T37Y00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770966708; h=Content-Transfer-Encoding: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:Cc; bh=7XqBAWjNfsCkJWkYmrEfgAktWS9f9SYgLSbaxuuB2Dc=; b=KvV+0fDv62vS20CLa22vU2bQgB/O9zwYV+ubKOLKTbg4Q7IxcsRLBqsEvx+eP/rVZ3Jck4hCODDnumFCUDLue5tKNJivVZ9cV6CMIcxLAMw9cQFeZSpEQEhbK9XG9AgF0ZztQ08zOpD+8WwbGzkuF+/GQQPHW8U0+QC03tlImDI= 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 1770966708197135.34986197886371; Thu, 12 Feb 2026 23:11:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vqnL7-0002lL-OF; Fri, 13 Feb 2026 02:11:45 -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 1vqnL2-0002kG-5M for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vqnKz-0005eb-Lx for qemu-devel@nongnu.org; Fri, 13 Feb 2026 02:11:38 -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-385-K0e8aoZdNBSe0yWh8aIrMA-1; Fri, 13 Feb 2026 02:11:33 -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 2DEDE18003F5; Fri, 13 Feb 2026 07:11:32 +0000 (UTC) Received: from S2.redhat.com (unknown [10.72.112.33]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E9BE318003F5; Fri, 13 Feb 2026 07:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1770966697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7XqBAWjNfsCkJWkYmrEfgAktWS9f9SYgLSbaxuuB2Dc=; b=dbRRzf+x1zp/vIEjndMvidrJop5eMuHwcExJ97wtJf/r1q2CGY2tq4hdfVIpbm0eqb+5vD pgi3GDtKs2HtxCfycGkg4Xwn/plFx6+GZotycMLTp+TFBlEb02bC4OmbYaLxRsmXs5HE3b G7r1WszHJ158lnO57Q/LsWE0ohSt4+k= X-MC-Unique: K0e8aoZdNBSe0yWh8aIrMA-1 X-Mimecast-MFC-AGG-ID: K0e8aoZdNBSe0yWh8aIrMA_1770966692 From: Cindy Lu To: lulu@redhat.com, mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com, lizhijian@fujitsu.com, qemu-devel@nongnu.org Subject: [RFC 5/5] qapi: add in/out_netdev to filter-redirector Date: Fri, 13 Feb 2026 15:08:05 +0800 Message-ID: <20260213071042.3733239-6-lulu@redhat.com> In-Reply-To: <20260213071042.3733239-1-lulu@redhat.com> References: <20260213071042.3733239-1-lulu@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 client-ip=170.10.129.124; envelope-from=lulu@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_H4=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: 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: 1770966711076154100 Content-Type: text/plain; charset="utf-8" Document the new in_netdev and out_netdev properties in the QAPI schema for FilterRedirectorProperties: - in_netdev: Name of an input netdev endpoint captured via AF_PACKET. Allows capturing packets directly from a TAP interface, bypassing the QEMU network stack. - out_netdev: Name of an output netdev endpoint injected via AF_PACKET. Allows injecting packets directly to a TAP interface. These properties are mutually exclusive with each other and with indev/outdev on the same direction. They enable filter-redirector to work with vhost-net backends for live migration packet mirroring. Signed-off-by: Cindy Lu --- qapi/qom.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/qapi/qom.json b/qapi/qom.json index b1fe55944c..a62a824403 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -476,8 +476,15 @@ # # Properties for filter-redirector objects. # -# At least one of @indev or @outdev must be present. If both are -# present, they must not refer to the same character device backend. +# At least one of @indev, @outdev, @in_netdev, or @out_netdev must be +# present. +# +# If both @indev and @outdev are present, they must not refer to the +# same character device backend. +# +# @in_netdev and @out_netdev are Linux AF_PACKET based endpoints. +# They are mutually exclusive with each other, and also with +# @indev/@outdev on the same direction. # # @indev: the name of a character device backend from which packets # are received and redirected to the filtered network device @@ -485,6 +492,12 @@ # @outdev: the name of a character device backend to which all # incoming packets are redirected # +# @in_netdev: the name of an input netdev endpoint captured via +# AF_PACKET +# +# @out_netdev: the name of an output netdev endpoint injected via +# AF_PACKET +# # @vnet_hdr_support: if true, vnet header support is enabled # (default: false) # @@ -498,6 +511,8 @@ 'base': 'NetfilterProperties', 'data': { '*indev': 'str', '*outdev': 'str', + '*in_netdev': 'str', + '*out_netdev': 'str', '*vnet_hdr_support': 'bool', '*enable_when_stopped': 'bool' } } =20 --=20 2.52.0