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=Zj4pqNRb; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 049335A0278 for ; Fri, 12 Sep 2025 10:17:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757665036; 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=OMq4rcr8D0y6htjkkYuoJSlZR+lkF3G5C2KcYQlxkKE=; b=Zj4pqNRbS+8FY/VO2Ubuoq+OzZh/6yAJ/l0JhW0uOKlc2kN+j/WBvZ1ZKKYu4HYkhyCLM9 iIGNK0p4PJp7+BNMlHDidXO4ryzbGLAEVSTm/rD/BCvakePEGCMaR4ndDU+x/ELhWQT0v3 /v1Wns7wHvwqV2AQniHSb2KilqTjm+U= Received: from mx-prod-mc-02.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-680-J1VN6LbiNMu-0-x5bN5kNw-1; Fri, 12 Sep 2025 04:17:14 -0400 X-MC-Unique: J1VN6LbiNMu-0-x5bN5kNw-1 X-Mimecast-MFC-AGG-ID: J1VN6LbiNMu-0-x5bN5kNw_1757665033 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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 18FD41956087; Fri, 12 Sep 2025 08:17:13 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.58]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2928730002CA; Fri, 12 Sep 2025 08:17:08 +0000 (UTC) From: Yumei Huang To: passt-dev@passt.top Subject: [PATCH v2] tap: Drop frames if no client connected Date: Fri, 12 Sep 2025 16:17:05 +0800 Message-ID: <20250912081705.20796-1-yuhuang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Y3GOZ1VzghFW5GOC54L1pD474Iq9s0gh-oHpCQ_P05E_1757665033 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: TBKHEF5QPPDBIHAVIKUGVRM3T77SXEON X-Message-ID-Hash: TBKHEF5QPPDBIHAVIKUGVRM3T77SXEON 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, lvivier@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. Without this we will get an EBADF in either writev() (pasta) or sendmsg() (passt). That's basically harmless, but a bit ugly. Explicitly catching this case results in behaviour that's probably a bit clearer to debug if we hit it. There are several different approaches we can take here. Here's some reasoning as David explained: * Don't listen() until the tap connection is ready - It's not clear that the host rejecting the connection is better than the host accepting, then the connection stalling until the guest is ready. - Would require substantial rework because we currently listen() as we parse the command line and don't store the information we'd need to do it later. * Don't accept() until the tap connection is ready - To the peer, will behave basically the same as this patch - the host will complete the TCP handshake, then the connection will stall until the guest is ready. - More work to implement, because essentially every sock-side handler has to check fd_tap and abort early * Drop packets in tap_send_frames(), but return 0 - To the peer, would behave basically the same - Would make the TCP code do a bunch of busy work attempting to resend, probably to no avail - Handling of errors returned by tap_send_frames() is on the basis that it's probably a transient fault (buffer full) and we want to resend very soon. That approach doesn't make sense for a missing guest. Suggested-by: David Gibson Signed-off-by: Yumei Huang --- tap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tap.c b/tap.c index 7ba6399..2e371b3 100644 --- a/tap.c +++ b/tap.c @@ -507,13 +507,16 @@ 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) + return nframes; + if (!nframes) return 0; -- 2.47.0