From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0AF2F5A026E for ; Thu, 16 Feb 2023 06:43:22 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4L0FTVz4x8M; Thu, 16 Feb 2023 16:43:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526194; bh=i4mr84D/iYUcjtv/l/JKbH/8vu3HFCxbqnzjCsT96uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i358CscTXBZ7WuhetyQe46spMtC1wCOhdSEit2Amnk5StlvVoWNHNLdAnUTNcxfxX OFEGsxBzMSFSG0ymixcDH2qhgCFHTidwNPvs9HjclhzZKdA+sl8cGRybZo+j/vD7L8 BesTjqVpCtv1zencLDBaTOg6GRg0AiJVSAAGNYH8= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 1/4] tap: Don't pcap frames that didn't get sent Date: Thu, 16 Feb 2023 16:43:08 +1100 Message-Id: <20230216054311.2131853-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216054311.2131853-1-david@gibson.dropbear.id.au> References: <20230216054311.2131853-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 2UG3TE55YKTKM5FPNMUE4ZZM4VRUFE6S X-Message-ID-Hash: 2UG3TE55YKTKM5FPNMUE4ZZM4VRUFE6S X-MailFrom: dgibson@gandalf.ozlabs.org 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: David Gibson 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: 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. Signed-off-by: David Gibson --- tap.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tap.c b/tap.c index 716d887..ae60fd4 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 * + * Return: number of frames successfully sent + * * #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; @@ -325,6 +327,8 @@ static void tap_send_frames_pasta(struct ctx *c, iov--; } } + + return n; } /** @@ -357,10 +361,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 * + * Return: number of frames successfully sent + * * #syscalls:passt sendmsg */ -static void tap_send_frames_passt(const struct ctx *c, - const struct iovec *iov, size_t n) +static size_t tap_send_frames_passt(const struct ctx *c, + const struct iovec *iov, size_t n) { struct msghdr mh = { .msg_iov = (void *)iov, @@ -371,7 +377,7 @@ static void tap_send_frames_passt(const struct ctx *c, sent = sendmsg(c->fd_tap, &mh, MSG_NOSIGNAL | MSG_DONTWAIT); if (sent < 0) - return; + return 0; /* Check for any partial frames due to short send */ for (i = 0; i < n; i++) { @@ -386,8 +392,7 @@ static void tap_send_frames_passt(const struct ctx *c, i++; } - if (i < n) - debug("tap: dropped %lu frames due to short send", n - i); + return i; } /** @@ -398,15 +403,20 @@ static void tap_send_frames_passt(const struct ctx *c, */ void tap_send_frames(struct ctx *c, const struct iovec *iov, size_t n) { + size_t m; + if (!n) return; if (c->mode == MODE_PASST) - tap_send_frames_passt(c, iov, n); + m = tap_send_frames_passt(c, iov, n); else - tap_send_frames_pasta(c, iov, n); + m = tap_send_frames_pasta(c, iov, n); + + if (m < n) + debug("tap: dropped %lu frames of %lu due to short send", n - m, n); - pcap_multiple(iov, n, c->mode == MODE_PASST ? sizeof(uint32_t) : 0); + pcap_multiple(iov, m, c->mode == MODE_PASST ? sizeof(uint32_t) : 0); } /** -- 2.39.1