=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/channels.c,v retrieving revision 1.428 retrieving revision 1.429 diff -u -r1.428 -r1.429 --- src/usr.bin/ssh/channels.c 2023/03/04 03:22:59 1.428 +++ src/usr.bin/ssh/channels.c 2023/03/07 21:47:42 1.429 @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.c,v 1.428 2023/03/04 03:22:59 dtucker Exp $ */ +/* $OpenBSD: channels.c,v 1.429 2023/03/07 21:47:42 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -1974,11 +1974,14 @@ fatal_f("channel %d: no remote id", c->self); /* for rdynamic the OPEN_CONFIRMATION has been sent already */ isopen = (c->type == SSH_CHANNEL_RDYNAMIC_FINISH); + if (getsockopt(c->sock, SOL_SOCKET, SO_ERROR, &err, &sz) == -1) { err = errno; error("getsockopt SO_ERROR failed"); } + if (err == 0) { + /* Non-blocking connection completed */ debug("channel %d: connected to %s port %d", c->self, c->connect_ctx.host, c->connect_ctx.port); channel_connect_ctx_free(&c->connect_ctx); @@ -1996,16 +1999,17 @@ (r = sshpkt_send(ssh)) != 0) fatal_fr(r, "channel %i open confirm", c->self); } - } else { - debug("channel %d: connection failed: %s", - c->self, strerror(err)); - /* Try next address, if any */ - if ((sock = connect_next(&c->connect_ctx)) > 0) { - close(c->sock); - c->sock = c->rfd = c->wfd = sock; - return; - } - /* Exhausted all addresses */ + return; + } + if (err == EINTR || err == EAGAIN || err == EINPROGRESS) + return; + + /* Non-blocking connection failed */ + debug("channel %d: connection failed: %s", c->self, strerror(err)); + + /* Try next address, if any */ + if ((sock = connect_next(&c->connect_ctx)) == -1) { + /* Exhausted all addresses for this destination */ error("connect_to %.100s port %d: failed.", c->connect_ctx.host, c->connect_ctx.port); channel_connect_ctx_free(&c->connect_ctx); @@ -2024,6 +2028,10 @@ chan_mark_dead(ssh, c); } } + + /* New non-blocking connection in progress */ + close(c->sock); + c->sock = c->rfd = c->wfd = sock; } static int