From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iIP2CxMf; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 2619E5A0271 for ; Thu, 11 Sep 2025 10:55:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757580929; 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; bh=FX06YqehbSTA5MqLkLVWsSETQNFF8hF+6y6/IDIK2bk=; b=iIP2CxMfF7rYntmx58Bez4OZQ+RgZyrMUsH9U5r3tij+vksQVr5wlPPdYtKCF2KdOzoPTM qxZSiDGhMlgWor1fqJ/x19rHHm2YnLMetmtGd3N74MfeC37GoUdbFwe1Rfxd0PErr+czQP BwKPurJntMMPgG044cAy02CY3HJhV2g= Received: from mx-prod-mc-01.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-453-4H2nKqqwPT-nMNnlfx2Llw-1; Thu, 11 Sep 2025 04:55:28 -0400 X-MC-Unique: 4H2nKqqwPT-nMNnlfx2Llw-1 X-Mimecast-MFC-AGG-ID: 4H2nKqqwPT-nMNnlfx2Llw_1757580927 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 401771953957; Thu, 11 Sep 2025 08:55:26 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.75]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D6FB019560B1; Thu, 11 Sep 2025 08:55:22 +0000 (UTC) From: Yumei Huang To: passt-dev@passt.top Subject: [PATCH] tap: Drop frames if no client connected Date: Thu, 11 Sep 2025 16:55:19 +0800 Message-ID: <20250911085519.24395-1-yuhuang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: MvnJ0yG5eMqK37-nmuz49UAeNmM-376MBg_OJgBscRc_1757580927 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: YI2BVICBRARXBQK4XICEMUCOSJ7CERSB X-Message-ID-Hash: YI2BVICBRARXBQK4XICEMUCOSJ7CERSB X-MailFrom: yuhuang@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: sbrivio@redhat.com, david@gibson.dropbear.id.au, yuhuang@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If no client is attached, discard outgoing frames and report them as sent. This mimics the behavior of a physical host with its network cable unplugged. Suggested-by: David Gibson Signed-off-by: Yumei Huang --- tap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tap.c b/tap.c index 7ba6399..e01219d 100644 --- a/tap.c +++ b/tap.c @@ -507,13 +507,17 @@ static size_t tap_send_frames_passt(const struct ctx *c, * @iov must have total length @bufs_per_frame * @nframes, with each set of * @bufs_per_frame contiguous buffers representing a single frame. * - * Return: number of frames actually sent + * Return: number of frames actually sent, or accounted as sent */ size_t tap_send_frames(const struct ctx *c, const struct iovec *iov, size_t bufs_per_frame, size_t nframes) { size_t m; + if (c->fd_tap == -1) + /* If no client connected, account the frames have been sent */ + return nframes; + if (!nframes) return 0; -- 2.47.0