From 8f5e9a4f8dc796aee8789847c2a946d1065a7f39 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 13 Sep 2021 14:28:47 +0100 Subject: [PATCH] Send PLUGLOG_CONNECT_SUCCESS in proxied socket types. Now the non-SSH backends critically depend on it, it's important not to forget to send it, for any socket type that's going to be used for any of those backends. But ProxySocket, and the Unix and Windows 'socket' types wrapping pipes to local subprocesses, were not doing so. Some of these socket types don't have a SockAddr available to represent the destination host. (Sometimes the concept isn't even meaningful). Therefore, I've also expanded the semantics of PLUGLOG_CONNECT_SUCCESS so that the addr parameter is allowed to be NULL, and invented a noncommittal fallback version of the log message in that situation. --- be_misc.c | 5 ++++- network.h | 7 +++++-- proxy.c | 2 ++ unix/fd-socket.c | 8 ++++++++ windows/handle-socket.c | 8 ++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/be_misc.c b/be_misc.c index 7f50a643..de15a34e 100644 --- a/be_misc.c +++ b/be_misc.c @@ -29,7 +29,10 @@ void backend_socket_log(Seat *seat, LogContext *logctx, msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg); break; case PLUGLOG_CONNECT_SUCCESS: - sk_getaddr(addr, addrbuf, lenof(addrbuf)); + if (addr) + sk_getaddr(addr, addrbuf, lenof(addrbuf)); + else /* fallback if address unavailable */ + sprintf(addrbuf, "remote host"); msg = dupprintf("Connected to %s", addrbuf); break; case PLUGLOG_PROXY_MSG: { diff --git a/network.h b/network.h index 92662ac7..05b71279 100644 --- a/network.h +++ b/network.h @@ -67,8 +67,11 @@ struct PlugVtable { * addresses to fall back to. When it _is_ fatal, the closing() * function will be called. * - * - PLUGLOG_CONNECT_SUCCESS means we have succeeded in - * connecting to address `addr'. + * - PLUGLOG_CONNECT_SUCCESS means we have succeeded in making a + * connection. `addr' gives the address we connected to, if + * available. (But sometimes, in cases of complicated proxy + * setups, it might not be available, so receivers of this log + * event should be prepared to deal with addr==NULL.) * * - PLUGLOG_PROXY_MSG means that error_msg contains a line of * logging information from whatever the connection is being diff --git a/proxy.c b/proxy.c index 1a737cae..4fa8f16f 100644 --- a/proxy.c +++ b/proxy.c @@ -28,6 +28,8 @@ void proxy_activate (ProxySocket *p) p->state = PROXY_STATE_ACTIVE; + plug_log(p->plug, PLUGLOG_CONNECT_SUCCESS, NULL, 0, NULL, 0); + /* we want to ignore new receive events until we have sent * all of our buffered receive data. */ diff --git a/unix/fd-socket.c b/unix/fd-socket.c index 6c468e6b..afd37957 100644 --- a/unix/fd-socket.c +++ b/unix/fd-socket.c @@ -315,6 +315,12 @@ static const SocketVtable FdSocket_sockvt = { .peer_info = NULL, }; +static void fdsocket_connect_success_callback(void *ctx) +{ + FdSocket *fds = (FdSocket *)ctx; + plug_log(fds->plug, PLUGLOG_CONNECT_SUCCESS, NULL, 0, NULL, 0); +} + Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug) { FdSocket *fds; @@ -354,5 +360,7 @@ Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug) uxsel_set(fds->inerrfd, SELECT_R, fdsocket_select_result_input_error); } + queue_toplevel_callback(fdsocket_connect_success_callback, fds); + return &fds->sock; } diff --git a/windows/handle-socket.c b/windows/handle-socket.c index 93bb500a..77b9067c 100644 --- a/windows/handle-socket.c +++ b/windows/handle-socket.c @@ -314,6 +314,12 @@ static const SocketVtable HandleSocket_sockvt = { .peer_info = sk_handle_peer_info, }; +static void sk_handle_connect_success_callback(void *ctx) +{ + HandleSocket *hs = (HandleSocket *)ctx; + plug_log(hs->plug, PLUGLOG_CONNECT_SUCCESS, NULL, 0, NULL, 0); +} + Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, Plug *plug, bool overlapped) { @@ -339,5 +345,7 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, hs->defer_close = hs->deferred_close = false; + queue_toplevel_callback(sk_handle_connect_success_callback, hs); + return &hs->sock; }