Skip to content

Commit

Permalink
slirp: handle deferred ECONNREFUSED on non-blocking TCP sockets
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Steven Luo authored and sthibaul committed Apr 7, 2016
1 parent 27d92eb commit 6625d83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion slirp/socket.c
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions slirp/tcp_input.c
Expand Up @@ -725,6 +725,12 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso, unsigned short af)
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;
Expand Down

0 comments on commit 6625d83

Please sign in to comment.