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 525BF5A026D for ; Wed, 8 Nov 2023 04:18:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1699413479; bh=Toi1I+OFHkQDvh3ySOY48wEoUjlP1CJDujD2TJbjtYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ELMjZziw6f1B+w2NCmrB4g8IX321gHOtUNIZXsNTp5Se6ENpl7CjilCHA4Wx2X6yC aZeJsDXizmd+plSrbc6Dzb+YssFGXoWTm/v7OBkVrzEmnpRRu79bz4vSWH5n4dgWXr RzJbSre0Njv+HVn0chQgiyptALfoI3ZZKB9Wmd0g= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SQ9JR0VF8z4xPQ; Wed, 8 Nov 2023 14:17:59 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] tap, pasta: Handle short writes to /dev/tap Date: Wed, 8 Nov 2023 14:17:54 +1100 Message-ID: <20231108031754.2670078-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231108031754.2670078-1-david@gibson.dropbear.id.au> References: <20231108031754.2670078-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: QUYUDWZYUXR24SIHLJP4KPKRERSAD3WT X-Message-ID-Hash: QUYUDWZYUXR24SIHLJP4KPKRERSAD3WT 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.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: tap_send_frames_pasta() sends frames to the namespace by sending them to our the /dev/tap device. If that write() returns an error, we already handle it. However we don't handle the case where the write() returns short, meaning we haven't successfully transmitted the whole frame. I don't know if this can ever happen with the kernel tap device, but we should at least report the case so we don't get a cryptic failure. For the purposes of the return value for tap_send_frames_pasta() we treat this case as though it was an error (on the grounds that a partial frame is no use to the namespace). Signed-off-by: David Gibson --- tap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tap.c b/tap.c index 00622e7..4f11000 100644 --- a/tap.c +++ b/tap.c @@ -321,7 +321,9 @@ static size_t tap_send_frames_pasta(const struct ctx *c, size_t i; for (i = 0; i < n; i++) { - if (write(c->fd_tap, iov[i].iov_base, iov[i].iov_len) < 0) { + ssize_t rc = write(c->fd_tap, iov[i].iov_base, iov[i].iov_len); + + if (rc < 0) { debug("tap write: %s", strerror(errno)); switch (errno) { @@ -336,6 +338,10 @@ static size_t tap_send_frames_pasta(const struct ctx *c, default: die("Write error on tap device, exiting"); } + } else if ((size_t)rc < iov[i].iov_len) { + debug("short write on tuntap: %zd/%zu", + rc, iov[i].iov_len); + break; } } -- 2.41.0