public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: [PATCH 2/2] tap: Return -EIO from tap_handler_passt() on inconsistent packet stream
Date: Tue,  8 Nov 2022 09:54:19 +0100	[thread overview]
Message-ID: <20221108085419.3220900-3-sbrivio@redhat.com> (raw)
In-Reply-To: <20221108085419.3220900-1-sbrivio@redhat.com>

While it's important to fail in that case, it makes little sense to
fail quietly: it's better to tell qemu explicitly that something went
wrong and that we won't recover, by closing the socket.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tap.c b/tap.c
index 11ac732..abeff25 100644
--- a/tap.c
+++ b/tap.c
@@ -757,7 +757,7 @@ redo:
 			rem = recv(c->fd_tap, p + n,
 				   (ssize_t)sizeof(uint32_t) - n, 0);
 			if ((n += rem) != (ssize_t)sizeof(uint32_t))
-				return 0;
+				return -EIO;
 		}
 
 		len = ntohl(*(uint32_t *)p);
@@ -771,7 +771,7 @@ redo:
 		if (len > n) {
 			rem = recv(c->fd_tap, p + n, len - n, 0);
 			if ((n += rem) != len)
-				return 0;
+				return -EIO;
 		}
 
 		/* Complete the partial read above before discarding a malformed
-- 
@@ -757,7 +757,7 @@ redo:
 			rem = recv(c->fd_tap, p + n,
 				   (ssize_t)sizeof(uint32_t) - n, 0);
 			if ((n += rem) != (ssize_t)sizeof(uint32_t))
-				return 0;
+				return -EIO;
 		}
 
 		len = ntohl(*(uint32_t *)p);
@@ -771,7 +771,7 @@ redo:
 		if (len > n) {
 			rem = recv(c->fd_tap, p + n, len - n, 0);
 			if ((n += rem) != len)
-				return 0;
+				return -EIO;
 		}
 
 		/* Complete the partial read above before discarding a malformed
-- 
2.35.1


      parent reply	other threads:[~2022-11-08  8:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08  8:54 [PATCH 0/2] Try harder to avoid inconsistent qemu packet stream Stefano Brivio
2022-11-08  8:54 ` [PATCH 1/2] tap: Keep stream consistent if qemu length descriptor spans two recv() calls Stefano Brivio
2022-11-09 10:15   ` David Gibson
2022-11-09 10:29     ` Stefano Brivio
2022-11-10 12:59       ` Stefano Brivio
2022-11-08  8:54 ` Stefano Brivio [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221108085419.3220900-3-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).