diff --git a/be_misc.c b/be_misc.c index 9bd3bdd3..ea8fac88 100644 --- a/be_misc.c +++ b/be_misc.c @@ -9,14 +9,14 @@ #include "network.h" void backend_socket_log(Seat *seat, LogContext *logctx, - int type, SockAddr *addr, int port, + PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code, Conf *conf, bool session_started) { char addrbuf[256], *msg; switch (type) { - case 0: + case PLUGLOG_CONNECT_TRYING: sk_getaddr(addr, addrbuf, lenof(addrbuf)); if (sk_addr_needs_port(addr)) { msg = dupprintf("Connecting to %s port %d", addrbuf, port); @@ -24,11 +24,11 @@ void backend_socket_log(Seat *seat, LogContext *logctx, msg = dupprintf("Connecting to %s", addrbuf); } break; - case 1: + case PLUGLOG_CONNECT_FAILED: sk_getaddr(addr, addrbuf, lenof(addrbuf)); msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg); break; - case 2: + case PLUGLOG_PROXY_MSG: /* Proxy-related log messages have their own identifying * prefix already, put on by our caller. */ { @@ -114,7 +114,7 @@ void log_proxy_stderr(Plug *plug, ProxyStderrBuf *psb, endpos--; char *msg = dupprintf( "proxy: %.*s", (int)(endpos - pos), psb->buf + pos); - plug_log(plug, 2, NULL, 0, msg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0); sfree(msg); pos = nlpos - psb->buf + 1; @@ -129,7 +129,7 @@ void log_proxy_stderr(Plug *plug, ProxyStderrBuf *psb, if (pos == 0 && psb->size == lenof(psb->buf)) { char *msg = dupprintf( "proxy (partial line): %.*s", (int)psb->size, psb->buf); - plug_log(plug, 2, NULL, 0, msg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0); sfree(msg); pos = psb->size = 0; diff --git a/network.h b/network.h index 9f3c2d9a..664304b7 100644 --- a/network.h +++ b/network.h @@ -44,25 +44,33 @@ struct Plug { const struct PlugVtable *vt; }; +typedef enum PlugLogType { + PLUGLOG_CONNECT_TRYING, + PLUGLOG_CONNECT_FAILED, + PLUGLOG_PROXY_MSG, +} PlugLogType; + struct PlugVtable { - void (*log)(Plug *p, int type, SockAddr *addr, int port, + void (*log)(Plug *p, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code); /* * Passes the client progress reports on the process of setting * up the connection. * - * - type==0 means we are about to try to connect to address - * `addr' (error_msg and error_code are ignored) - * - type==1 means we have failed to connect to address `addr' - * (error_msg and error_code are supplied). This is not a - * fatal error - we may well have other candidate addresses - * to fall back to. When it _is_ fatal, the closing() + * - PLUGLOG_CONNECT_TRYING means we are about to try to connect + * to address `addr' (error_msg and error_code are ignored) + * + * - PLUGLOG_CONNECT_FAILED means we have failed to connect to + * address `addr' (error_msg and error_code are supplied). This + * is not a fatal error - we may well have other candidate + * addresses to fall back to. When it _is_ fatal, the closing() * function will be called. - * - type==2 means that error_msg contains a line of generic - * logging information about setting up the connection. This - * will typically be a wodge of standard-error output from a - * proxy command, so the receiver should probably prefix it to - * indicate this. + * + * - PLUGLOG_PROXY_MSG means that error_msg contains a line of + * logging information from whatever the connection is being + * proxied through. This will typically be a wodge of + * standard-error output from a local proxy command, so the + * receiver should probably prefix it to indicate this. */ void (*closing) (Plug *p, const char *error_msg, int error_code, bool calling_back); @@ -287,7 +295,7 @@ extern Plug *const nullplug; * Exports from be_misc.c. */ void backend_socket_log(Seat *seat, LogContext *logctx, - int type, SockAddr *addr, int port, + PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code, Conf *conf, bool session_started); diff --git a/portfwd.c b/portfwd.c index 5bd4aacf..f10cc8d1 100644 --- a/portfwd.c +++ b/portfwd.c @@ -95,13 +95,13 @@ static void free_portlistener_state(struct PortListener *pl) sfree(pl); } -static void pfd_log(Plug *plug, int type, SockAddr *addr, int port, +static void pfd_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { /* we have to dump these since we have no interface to logging.c */ } -static void pfl_log(Plug *plug, int type, SockAddr *addr, int port, +static void pfl_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { /* we have to dump these since we have no interface to logging.c */ diff --git a/proxy.c b/proxy.c index 2659de7d..772f4e04 100644 --- a/proxy.c +++ b/proxy.c @@ -171,8 +171,8 @@ static const char * sk_proxy_socket_error (Socket *s) /* basic proxy plug functions */ -static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, - const char *error_msg, int error_code) +static void plug_proxy_log(Plug *plug, PlugLogType type, SockAddr *addr, + int port, const char *error_msg, int error_code) { ProxySocket *ps = container_of(plug, ProxySocket, plugimpl); @@ -455,7 +455,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname, conf_get_str(conf, CONF_proxy_host), conf_get_int(conf, CONF_proxy_port), hostname, port); - plug_log(plug, 2, NULL, 0, logmsg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0); sfree(logmsg); } @@ -463,7 +463,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname, char *logmsg = dns_log_msg(conf_get_str(conf, CONF_proxy_host), conf_get_int(conf, CONF_addressfamily), "proxy"); - plug_log(plug, 2, NULL, 0, logmsg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0); sfree(logmsg); } @@ -484,7 +484,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname, logmsg = dupprintf("Connecting to %s proxy at %s port %d", proxy_type, addrbuf, conf_get_int(conf, CONF_proxy_port)); - plug_log(plug, 2, NULL, 0, logmsg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0); sfree(logmsg); } @@ -1456,7 +1456,7 @@ int proxy_telnet_negotiate (ProxySocket *p, int change) *out = '\0'; logmsg = dupprintf("Sending Telnet proxy command: %s", reescaped); - plug_log(p->plug, 2, NULL, 0, logmsg, 0); + plug_log(p->plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0); sfree(logmsg); sfree(reescaped); } diff --git a/raw.c b/raw.c index abea744a..226739b0 100644 --- a/raw.c +++ b/raw.c @@ -33,7 +33,7 @@ static void c_write(Raw *raw, const void *buf, size_t len) sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG); } -static void raw_log(Plug *plug, int type, SockAddr *addr, int port, +static void raw_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { Raw *raw = container_of(plug, Raw, plug); diff --git a/rlogin.c b/rlogin.c index c4f582b1..2cc66fb6 100644 --- a/rlogin.c +++ b/rlogin.c @@ -37,7 +37,7 @@ static void c_write(Rlogin *rlogin, const void *buf, size_t len) sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG); } -static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, +static void rlogin_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { Rlogin *rlogin = container_of(plug, Rlogin, plug); diff --git a/sesschan.c b/sesschan.c index 703f1fdc..1f5d06dd 100644 --- a/sesschan.c +++ b/sesschan.c @@ -352,7 +352,7 @@ bool sesschan_run_subsystem(Channel *chan, ptrlen subsys) return false; } -static void fwd_log(Plug *plug, int type, SockAddr *addr, int port, +static void fwd_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { /* don't expect any weirdnesses from a listening socket */ } static void fwd_closing(Plug *plug, const char *error_msg, int error_code, diff --git a/ssh.c b/ssh.c index 8228fba4..87d4c624 100644 --- a/ssh.c +++ b/ssh.c @@ -576,8 +576,8 @@ void ssh_sw_abort_deferred(Ssh *ssh, const char *fmt, ...) } } -static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port, - const char *error_msg, int error_code) +static void ssh_socket_log(Plug *plug, PlugLogType type, SockAddr *addr, + int port, const char *error_msg, int error_code) { Ssh *ssh = container_of(plug, Ssh, plug); diff --git a/sshserver.c b/sshserver.c index 34ecd923..46f68659 100644 --- a/sshserver.c +++ b/sshserver.c @@ -124,8 +124,8 @@ static const SeatVtable server_seat_vt = { nullseat_interactive_no, }; -static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port, - const char *error_msg, int error_code) +static void server_socket_log(Plug *plug, PlugLogType type, SockAddr *addr, + int port, const char *error_msg, int error_code) { /* server *srv = container_of(plug, server, plug); */ /* FIXME */ diff --git a/telnet.c b/telnet.c index 832a4434..3f3170cd 100644 --- a/telnet.c +++ b/telnet.c @@ -613,7 +613,7 @@ static void do_telnet_read(Telnet *telnet, const char *buf, size_t len) strbuf_free(outbuf); } -static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, +static void telnet_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { Telnet *telnet = container_of(plug, Telnet, plug); diff --git a/unix/uxnet.c b/unix/uxnet.c index dbef8b23..02d18202 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -575,7 +575,8 @@ static int try_connect(NetSocket *sock) { SockAddr thisaddr = sk_extractaddr_tmp( sock->addr, &sock->step); - plug_log(sock->plug, 0, &thisaddr, sock->port, NULL, 0); + plug_log(sock->plug, PLUGLOG_CONNECT_TRYING, + &thisaddr, sock->port, NULL, 0); } /* @@ -746,7 +747,8 @@ static int try_connect(NetSocket *sock) if (err) { SockAddr thisaddr = sk_extractaddr_tmp( sock->addr, &sock->step); - plug_log(sock->plug, 1, &thisaddr, sock->port, strerror(err), err); + plug_log(sock->plug, PLUGLOG_CONNECT_FAILED, + &thisaddr, sock->port, strerror(err), err); } return err; } @@ -1421,7 +1423,8 @@ static void net_select_result(int fd, int event) assert(s->addr); thisaddr = sk_extractaddr_tmp(s->addr, &s->step); - plug_log(s->plug, 1, &thisaddr, s->port, errmsg, err); + plug_log(s->plug, PLUGLOG_CONNECT_FAILED, + &thisaddr, s->port, errmsg, err); while (err && s->addr && sk_nextaddr(s->addr, &s->step)) { err = try_connect(s); diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 9978ed4d..18fb5968 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -199,7 +199,7 @@ void chan_no_request_response(Channel *chan, bool success) {} * except that x11_closing has to signal back to the main loop that * it's time to terminate. */ -static void x11_log(Plug *p, int type, SockAddr *addr, int port, +static void x11_log(Plug *p, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) {} static void x11_receive(Plug *plug, int urgent, const char *data, size_t len) {} static void x11_sent(Plug *plug, size_t bufsize) {} diff --git a/unix/uxproxy.c b/unix/uxproxy.c index 7fb46efd..0a637bd9 100644 --- a/unix/uxproxy.c +++ b/unix/uxproxy.c @@ -33,7 +33,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, { char *logmsg = dupprintf("Starting local proxy command: %s", cmd); - plug_log(plug, 2, NULL, 0, logmsg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, logmsg, 0); sfree(logmsg); } diff --git a/unix/uxserver.c b/unix/uxserver.c index cbb8a256..f8f6d549 100644 --- a/unix/uxserver.c +++ b/unix/uxserver.c @@ -447,7 +447,7 @@ static Plug *server_conn_plug( &inst->ap, &inst->logpolicy, &unix_live_sftpserver_vt); } -static void server_log(Plug *plug, int type, SockAddr *addr, int port, +static void server_log(Plug *plug, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { log_to_stderr((unsigned)-1, error_msg); diff --git a/windows/winnet.c b/windows/winnet.c index 558b5b3e..71ebc53b 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -908,7 +908,8 @@ static DWORD try_connect(NetSocket *sock) { SockAddr thisaddr = sk_extractaddr_tmp( sock->addr, &sock->step); - plug_log(sock->plug, 0, &thisaddr, sock->port, NULL, 0); + plug_log(sock->plug, PLUGLOG_CONNECT_TRYING, + &thisaddr, sock->port, NULL, 0); } /* @@ -1081,7 +1082,8 @@ static DWORD try_connect(NetSocket *sock) if (err) { SockAddr thisaddr = sk_extractaddr_tmp( sock->addr, &sock->step); - plug_log(sock->plug, 1, &thisaddr, sock->port, sock->error, err); + plug_log(sock->plug, PLUGLOG_CONNECT_FAILED, + &thisaddr, sock->port, sock->error, err); } return err; } @@ -1527,7 +1529,7 @@ void select_result(WPARAM wParam, LPARAM lParam) if (s->addr) { SockAddr thisaddr = sk_extractaddr_tmp( s->addr, &s->step); - plug_log(s->plug, 1, &thisaddr, s->port, + plug_log(s->plug, PLUGLOG_CONNECT_FAILED, &thisaddr, s->port, winsock_error_string(err), err); while (err && s->addr && sk_nextaddr(s->addr, &s->step)) { err = try_connect(s); diff --git a/windows/winproxy.c b/windows/winproxy.c index 24ca261c..94e31fcb 100644 --- a/windows/winproxy.c +++ b/windows/winproxy.c @@ -35,7 +35,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, { char *msg = dupprintf("Starting local proxy command: %s", cmd); - plug_log(plug, 2, NULL, 0, msg, 0); + plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0); sfree(msg); } diff --git a/x11fwd.c b/x11fwd.c index faca7862..be024804 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -684,7 +684,7 @@ void x11_format_auth_for_authfile( put_stringpl_xauth(bs, authdata); } -static void x11_log(Plug *p, int type, SockAddr *addr, int port, +static void x11_log(Plug *p, PlugLogType type, SockAddr *addr, int port, const char *error_msg, int error_code) { /* We have no interface to the logging module here, so we drop these. */