From: Samuel Thibault <samuel.thibault@ens-lyon.org>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org
Cc: steven@steven676.net, jan.kiszka@siemens.com,
Steven Luo <steven+qemu@steven676.net>,
Samuel Thibault <samuel.thibault@ens-lyon.org>,
edgar.iglesias@gmail.com
Subject: [Qemu-devel] [PULL 4/4] slirp: handle deferred ECONNREFUSED on non-blocking TCP sockets
Date: Thu, 7 Apr 2016 13:04:13 +0200 [thread overview]
Message-ID: <1460027053-21211-5-git-send-email-samuel.thibault@ens-lyon.org> (raw)
In-Reply-To: <1460027053-21211-1-git-send-email-samuel.thibault@ens-lyon.org>
From: Steven Luo <steven+qemu@steven676.net>
slirp currently only handles ECONNREFUSED in the case where connect()
returns immediately with that error; since we use non-blocking sockets,
most of the time we won't receive the error until we later try to read
from the socket. Ensure that we deliver the appropriate RST to the
guest in this case.
Signed-off-by: Steven Luo <steven+qemu@steven676.net>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
---
slirp/socket.c | 2 +-
slirp/tcp_input.c | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/slirp/socket.c b/slirp/socket.c
index 0d67b12..bd97b2d 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -188,7 +188,7 @@ soread(struct socket *so)
DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
sofcantrcvmore(so);
- if (err == ECONNRESET
+ if (err == ECONNRESET || err == ECONNREFUSED
|| err == ENOTCONN || err == EPIPE) {
tcp_drop(sototcpcb(so), err);
} else {
diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c
index 1fcca30..5433e7f 100644
--- a/slirp/tcp_input.c
+++ b/slirp/tcp_input.c
@@ -725,6 +725,12 @@ findso:
so->so_ti = ti;
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
tp->t_state = TCPS_SYN_RECEIVED;
+ /*
+ * Initialize receive sequence numbers now so that we can send a
+ * valid RST if the remote end rejects our connection.
+ */
+ tp->irs = ti->ti_seq;
+ tcp_rcvseqinit(tp);
tcp_template(tp);
}
return;
--
2.8.0.rc3
next prev parent reply other threads:[~2016-04-07 11:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 11:04 [Qemu-devel] [PULL 0/4] slirp: deliver received TCP RSTs to the guest Samuel Thibault
2016-04-07 11:04 ` [Qemu-devel] [PULL 1/4] slirp: don't crash when tcp_sockclosed() is called with a NULL tp Samuel Thibault
2016-04-07 11:04 ` [Qemu-devel] [PULL 2/4] slirp: avoid use-after-free in slirp_pollfds_poll() if soread() returns an error Samuel Thibault
2016-04-07 11:04 ` [Qemu-devel] [PULL 3/4] slirp: Propagate host TCP RST to the guest Samuel Thibault
2016-04-07 11:04 ` Samuel Thibault [this message]
2016-04-07 11:59 ` [Qemu-devel] [PULL 0/4] slirp: deliver received TCP RSTs " Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2016-04-07 8:34 Samuel Thibault
2016-04-07 8:34 ` [Qemu-devel] [PULL 4/4] slirp: handle deferred ECONNREFUSED on non-blocking TCP sockets Samuel Thibault
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=1460027053-21211-5-git-send-email-samuel.thibault@ens-lyon.org \
--to=samuel.thibault@ens-lyon.org \
--cc=edgar.iglesias@gmail.com \
--cc=jan.kiszka@siemens.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=steven+qemu@steven676.net \
--cc=steven@steven676.net \
/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.
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 NNTP newsgroup(s).