From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 742C75A005E for ; Wed, 15 Feb 2023 13:17:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676463450; 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=FcjJxxl64RW2oTad7oU6V68k0Jmh+4Aznzsj76IfxCI=; b=iBdKFiYwZkPD/k4lGrwxPa5pHShUQJy20DU4gx3TtZyGXWmdodO00KRI/Fe2vn1udHHnyI Es8oR3GA1zIHzeuSTvH6v4pkgTeeNe2Ykb7+23GFMFIhp8TPLKpMywl42nNlsH0fvxM744 GDgjSUyJLymK/4JpNSvcM+kPK0v442E= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630--D1iQPG8M1W32MC8jm4Ejg-1; Wed, 15 Feb 2023 07:17:29 -0500 X-MC-Unique: -D1iQPG8M1W32MC8jm4Ejg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3A70101A52E; Wed, 15 Feb 2023 12:17:28 +0000 (UTC) Received: from maya.cloud.tilaa.com (unknown [10.33.32.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB8CE40C10FA; Wed, 15 Feb 2023 12:17:28 +0000 (UTC) Date: Wed, 15 Feb 2023 13:17:25 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/4] tap: Don't pcap frames that didn't get sent Message-ID: <20230215131725.02d3c6fd@elisabeth> In-Reply-To: <20230127051110.2513363-2-david@gibson.dropbear.id.au> References: <20230127051110.2513363-1-david@gibson.dropbear.id.au> <20230127051110.2513363-2-david@gibson.dropbear.id.au> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: JZ3OA4U3NA2HG4D3Q25H5TO7CIJCDX5L X-Message-ID-Hash: JZ3OA4U3NA2HG4D3Q25H5TO7CIJCDX5L X-MailFrom: sbrivio@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: passt-dev@passt.top X-Mailman-Version: 3.3.3 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: On Fri, 27 Jan 2023 16:11:07 +1100 David Gibson wrote: > In tap_send_frames() we send a number of frames to the tap device, then > also write them to the pcap capture file (if configured). However the tap > send can partially fail (short write()s or similar), meaning that some > of the requested frames weren't actually sent, but we still write those > frames to the capture file. > > We do give a debug message in this case, but it's misleading to add frames > that we know weren't sent to the capture file. Rework to avoid this. To be really "correct", I guess we should also truncate messages in captures if they were sent partially, by returning the number of bytes sent from tap_send_frames_{pasta,passt}() and then modifying the argument to pcap_frame() in the pcap_multiple() loop. This is relevant because, if a packet has a checksum, we could consider it lost while checking captures. Still, it's a vast improvement on the original, so I would apply this even like it is -- except for two nits, below: > Signed-off-by: David Gibson > --- > tap.c | 30 ++++++++++++++++++++---------- > 1 file changed, 20 insertions(+), 10 deletions(-) > > diff --git a/tap.c b/tap.c > index af9bc15..dd22490 100644 > --- a/tap.c > +++ b/tap.c > @@ -309,10 +309,12 @@ void tap_icmp6_send(const struct ctx *c, > * @iov: Array of buffers, each containing one frame > * @n: Number of buffers/frames in @iov > * > + * Returns: number of frames successfully sent For consistency: "Return:" -- I see now that one slipped through in pcap_frame(). I can "fix" this on merge or in a follow-up patch, too. > + * > * #syscalls:pasta write > */ > -static void tap_send_frames_pasta(struct ctx *c, > - const struct iovec *iov, size_t n) > +static size_t tap_send_frames_pasta(struct ctx *c, > + const struct iovec *iov, size_t n) > { > size_t i; > > @@ -324,6 +326,8 @@ static void tap_send_frames_pasta(struct ctx *c, > i--; > } > } > + > + return n; > } > > /** > @@ -356,10 +360,12 @@ static void tap_send_remainder(const struct ctx *c, const struct iovec *iov, > * @iov: Array of buffers, each containing one frame > * @n: Number of buffers/frames in @iov > * > + * Returns: number of frames successfully sent Same here. -- Stefano