提交 93a972f8 编写于 作者: G Gavin Grant 提交者: Samuel Thibault

slirp: Propagate host TCP RST packet to the guest after socket disconnected

Commit 27d92ebc handled the case where the TCP
connection is abruptly closed via a RST packet, by checking for the ECONNRESET
errno. However it does not consider the case where the connection has been
half-closed by the host (FIN/ACK), then the host socket is disconnected. For
example, if the host application calls close() on the socket, then the
application exits.

In this case, the socket still exists due to the file descriptor in SLIRP, but
it is disconnected. recv() does not indicate an error since an orderly socket
close has previously occurred. The socket will then be stuck in FIN_WAIT_2,
until the peer sends FIN/ACK or a timeout occurs. Instead we can send a RST
to the peer and transition to the CLOSED state.
Signed-off-by: NGavin Grant <gavingrant@protonmail.com>
Signed-off-by: NSamuel Thibault <samuel.thibault@ens-lyon.org>
上级 3d090aef
......@@ -204,12 +204,19 @@ soread(struct socket *so)
return 0;
else {
int err;
socklen_t slen = sizeof err;
socklen_t elen = sizeof err;
struct sockaddr_storage addr;
struct sockaddr *paddr = (struct sockaddr *) &addr;
socklen_t alen = sizeof addr;
err = errno;
if (nn == 0) {
getsockopt(so->s, SOL_SOCKET, SO_ERROR,
&err, &slen);
if (getpeername(so->s, paddr, &alen) < 0) {
err = errno;
} else {
getsockopt(so->s, SOL_SOCKET, SO_ERROR,
&err, &elen);
}
}
DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册