From 884a7df94b9bf83ba2915d64f2658e0c55e6491d Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 5 Oct 2018 07:24:16 +0100 Subject: [PATCH] Make Socket and Plug into structs. I think that means that _every_ one of my traitoids is now a struct containing a vtable pointer as one of its fields (albeit sometimes the only field), and never just a bare pointer. --- defs.h | 7 ++---- errsock.c | 12 ++++----- network.h | 46 +++++++++++++++++++++++----------- nullplug.c | 4 +-- pageant.c | 22 ++++++++-------- portfwd.c | 24 +++++++++--------- proxy.c | 42 +++++++++++++++---------------- proxy.h | 4 +-- raw.c | 14 +++++------ rlogin.c | 14 +++++------ ssh.c | 16 ++++++------ sshshare.c | 22 ++++++++-------- telnet.c | 14 +++++------ unix/uxnet.c | 62 +++++++++++++++++++++++----------------------- unix/uxpgnt.c | 6 ++--- unix/uxproxy.c | 28 ++++++++++----------- windows/winhsock.c | 24 +++++++++--------- windows/winnet.c | 46 +++++++++++++++++----------------- windows/winnps.c | 12 ++++----- x11fwd.c | 12 ++++----- 20 files changed, 222 insertions(+), 209 deletions(-) diff --git a/defs.h b/defs.h index f1119d10..776ab888 100644 --- a/defs.h +++ b/defs.h @@ -42,8 +42,8 @@ typedef struct IdempotentCallback IdempotentCallback; typedef struct SockAddr SockAddr; -typedef struct SocketVtable SocketVtable; -typedef struct PlugVtable PlugVtable; +typedef struct Socket Socket; +typedef struct Plug Plug; typedef struct Backend Backend; typedef struct BackendVtable BackendVtable; @@ -74,9 +74,6 @@ typedef struct settings_e settings_e; typedef struct SessionSpecial SessionSpecial; -typedef const SocketVtable *Socket; -typedef const PlugVtable *Plug; - /* * A small structure wrapping up a (pointer, length) pair so that it * can be conveniently passed to or from a function. diff --git a/errsock.c b/errsock.c index b38497ee..a15f75cf 100644 --- a/errsock.c +++ b/errsock.c @@ -14,12 +14,12 @@ typedef struct { char *error; Plug *plug; - const SocketVtable *sockvt; + Socket sock; } ErrorSocket; static Plug *sk_error_plug(Socket *s, Plug *p) { - ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt); + ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock); Plug *ret = es->plug; if (p) es->plug = p; @@ -28,7 +28,7 @@ static Plug *sk_error_plug(Socket *s, Plug *p) static void sk_error_close(Socket *s) { - ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt); + ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock); sfree(es->error); sfree(es); @@ -36,7 +36,7 @@ static void sk_error_close(Socket *s) static const char *sk_error_socket_error(Socket *s) { - ErrorSocket *es = FROMFIELD(s, ErrorSocket, sockvt); + ErrorSocket *es = FROMFIELD(s, ErrorSocket, sock); return es->error; } @@ -60,8 +60,8 @@ static const SocketVtable ErrorSocket_sockvt = { Socket *new_error_socket(const char *errmsg, Plug *plug) { ErrorSocket *es = snew(ErrorSocket); - es->sockvt = &ErrorSocket_sockvt; + es->sock.vt = &ErrorSocket_sockvt; es->plug = plug; es->error = dupstr(errmsg); - return &es->sockvt; + return &es->sock; } diff --git a/network.h b/network.h index 6096a745..10492665 100644 --- a/network.h +++ b/network.h @@ -15,6 +15,13 @@ #include "defs.h" +typedef struct SocketVtable SocketVtable; +typedef struct PlugVtable PlugVtable; + +struct Socket { + const struct SocketVtable *vt; +}; + struct SocketVtable { Plug *(*plug) (Socket *s, Plug *p); /* use a different plug (return the old one) */ @@ -34,6 +41,10 @@ struct SocketVtable { typedef union { void *p; int i; } accept_ctx_t; typedef Socket *(*accept_fn_t)(accept_ctx_t ctx, Plug *plug); +struct Plug { + const struct PlugVtable *vt; +}; + struct PlugVtable { void (*log)(Plug *p, int type, SockAddr *addr, int port, const char *error_msg, int error_code); @@ -138,19 +149,24 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, int local_host_only, int address_family); -#define sk_plug(s,p) (((*s)->plug) (s, p)) -#define sk_close(s) (((*s)->close) (s)) -#define sk_write(s,buf,len) (((*s)->write) (s, buf, len)) -#define sk_write_oob(s,buf,len) (((*s)->write_oob) (s, buf, len)) -#define sk_write_eof(s) (((*s)->write_eof) (s)) -#define sk_flush(s) (((*s)->flush) (s)) +#define sk_plug(s,p) (((s)->vt->plug) (s, p)) +#define sk_close(s) (((s)->vt->close) (s)) +#define sk_write(s,buf,len) (((s)->vt->write) (s, buf, len)) +#define sk_write_oob(s,buf,len) (((s)->vt->write_oob) (s, buf, len)) +#define sk_write_eof(s) (((s)->vt->write_eof) (s)) +#define sk_flush(s) (((s)->vt->flush) (s)) #ifdef DEFINE_PLUG_METHOD_MACROS -#define plug_log(p,type,addr,port,msg,code) (((*p)->log) (p, type, addr, port, msg, code)) -#define plug_closing(p,msg,code,callback) (((*p)->closing) (p, msg, code, callback)) -#define plug_receive(p,urgent,buf,len) (((*p)->receive) (p, urgent, buf, len)) -#define plug_sent(p,bufsize) (((*p)->sent) (p, bufsize)) -#define plug_accepting(p, constructor, ctx) (((*p)->accepting)(p, constructor, ctx)) +#define plug_log(p,type,addr,port,msg,code) \ + (((p)->vt->log) (p, type, addr, port, msg, code)) +#define plug_closing(p,msg,code,callback) \ + (((p)->vt->closing) (p, msg, code, callback)) +#define plug_receive(p,urgent,buf,len) \ + (((p)->vt->receive) (p, urgent, buf, len)) +#define plug_sent(p,bufsize) \ + (((p)->vt->sent) (p, bufsize)) +#define plug_accepting(p, constructor, ctx) \ + (((p)->vt->accepting)(p, constructor, ctx)) #endif /* @@ -159,7 +175,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, * or return NULL if there's no problem. */ const char *sk_addr_error(SockAddr *addr); -#define sk_socket_error(s) (((*s)->socket_error) (s)) +#define sk_socket_error(s) (((s)->vt->socket_error) (s)) /* * Set the `frozen' flag on a socket. A frozen socket is one in @@ -178,14 +194,14 @@ const char *sk_addr_error(SockAddr *addr); * associated local socket in order to avoid unbounded buffer * growth. */ -#define sk_set_frozen(s, is_frozen) (((*s)->set_frozen) (s, is_frozen)) +#define sk_set_frozen(s, is_frozen) (((s)->vt->set_frozen) (s, is_frozen)) /* * Return a (dynamically allocated) string giving some information * about the other end of the socket, suitable for putting in log * files. May be NULL if nothing is available at all. */ -#define sk_peer_info(s) (((*s)->peer_info) (s)) +#define sk_peer_info(s) (((s)->vt->peer_info) (s)) /* * Simple wrapper on getservbyname(), needed by ssh.c. Returns the @@ -211,7 +227,7 @@ Socket *new_error_socket(const char *errmsg, Plug *plug); /* * Trivial plug that does absolutely nothing. Found in nullplug.c. */ -extern Plug *nullplug; +extern Plug *const nullplug; /* ---------------------------------------------------------------------- * Functions defined outside the network code, which have to be diff --git a/nullplug.c b/nullplug.c index 26c3ae8a..4fc16841 100644 --- a/nullplug.c +++ b/nullplug.c @@ -33,10 +33,10 @@ static const PlugVtable nullplug_plugvt = { NULL }; -static const PlugVtable *nullplug_plugvt_ptr = &nullplug_plugvt; +static Plug nullplug_plug = { &nullplug_plugvt }; /* * There's a singleton instance of nullplug, because it's not * interesting enough to worry about making more than one of them. */ -Plug *nullplug = &nullplug_plugvt_ptr; +Plug *const nullplug = &nullplug_plug; diff --git a/pageant.c b/pageant.c index 12b86638..438fbe58 100644 --- a/pageant.c +++ b/pageant.c @@ -707,14 +707,14 @@ struct pageant_conn_state { int real_packet; int crLine; /* for coroutine in pageant_conn_receive */ - const PlugVtable *plugvt; + Plug plug; }; static void pageant_conn_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { struct pageant_conn_state *pc = FROMFIELD( - plug, struct pageant_conn_state, plugvt); + plug, struct pageant_conn_state, plug); if (error_msg) plog(pc->logctx, pc->logfn, "%p: error: %s", pc, error_msg); else @@ -726,7 +726,7 @@ static void pageant_conn_closing(Plug *plug, const char *error_msg, static void pageant_conn_sent(Plug *plug, int bufsize) { /* struct pageant_conn_state *pc = FROMFIELD( - plug, struct pageant_conn_state, plugvt); */ + plug, struct pageant_conn_state, plug); */ /* * We do nothing here, because we expect that there won't be a @@ -748,7 +748,7 @@ static void pageant_conn_log(void *logctx, const char *fmt, va_list ap) static void pageant_conn_receive(Plug *plug, int urgent, char *data, int len) { struct pageant_conn_state *pc = FROMFIELD( - plug, struct pageant_conn_state, plugvt); + plug, struct pageant_conn_state, plug); char c; crBegin(pc->crLine); @@ -801,14 +801,14 @@ struct pageant_listen_state { void *logctx; pageant_logfn_t logfn; - const PlugVtable *plugvt; + Plug plug; }; static void pageant_listen_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { struct pageant_listen_state *pl = FROMFIELD( - plug, struct pageant_listen_state, plugvt); + plug, struct pageant_listen_state, plug); if (error_msg) plog(pl->logctx, pl->logfn, "listening socket: error: %s", error_msg); sk_close(pl->listensock); @@ -827,18 +827,18 @@ static int pageant_listen_accepting(Plug *plug, accept_fn_t constructor, accept_ctx_t ctx) { struct pageant_listen_state *pl = FROMFIELD( - plug, struct pageant_listen_state, plugvt); + plug, struct pageant_listen_state, plug); struct pageant_conn_state *pc; const char *err; char *peerinfo; pc = snew(struct pageant_conn_state); - pc->plugvt = &pageant_connection_plugvt; + pc->plug.vt = &pageant_connection_plugvt; pc->logfn = pl->logfn; pc->logctx = pl->logctx; pc->crLine = 0; - pc->connsock = constructor(ctx, &pc->plugvt); + pc->connsock = constructor(ctx, &pc->plug); if ((err = sk_socket_error(pc->connsock)) != NULL) { sk_close(pc->connsock); sfree(pc); @@ -869,11 +869,11 @@ static const PlugVtable pageant_listener_plugvt = { struct pageant_listen_state *pageant_listener_new(Plug **plug) { struct pageant_listen_state *pl = snew(struct pageant_listen_state); - pl->plugvt = &pageant_listener_plugvt; + pl->plug.vt = &pageant_listener_plugvt; pl->logctx = NULL; pl->logfn = NULL; pl->listensock = NULL; - *plug = &pl->plugvt; + *plug = &pl->plug; return pl; } diff --git a/portfwd.c b/portfwd.c index 6934bb31..40c09c7b 100644 --- a/portfwd.c +++ b/portfwd.c @@ -56,7 +56,7 @@ typedef struct PortForwarding { strbuf *socksbuf; size_t socksbuf_consumed; - const PlugVtable *plugvt; + Plug plug; Channel chan; } PortForwarding; @@ -71,7 +71,7 @@ struct PortListener { char *hostname; int port; - const PlugVtable *plugvt; + Plug plug; }; static struct PortForwarding *new_portfwd_state(void) @@ -124,7 +124,7 @@ static void pfd_close(struct PortForwarding *pf); static void pfd_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plugvt); + struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plug); if (error_msg) { /* @@ -205,7 +205,7 @@ static char *ipv6_to_string(ptrlen ipv6) static void pfd_receive(Plug *plug, int urgent, char *data, int len) { - struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plugvt); + struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plug); if (len == 0) return; @@ -429,7 +429,7 @@ static void pfd_receive(Plug *plug, int urgent, char *data, int len) static void pfd_sent(Plug *plug, int bufsize) { - struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plugvt); + struct PortForwarding *pf = FROMFIELD(plug, struct PortForwarding, plug); if (pf->c) sshfwd_unthrottle(pf->c, bufsize); @@ -473,9 +473,9 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) Socket *s; const char *err; - pl = FROMFIELD(p, struct PortListener, plugvt); + pl = FROMFIELD(p, struct PortListener, plug); pf = new_portfwd_state(); - pf->plugvt = &PortForwarding_plugvt; + pf->plug.vt = &PortForwarding_plugvt; pf->chan.initial_fixed_window_size = 0; pf->chan.vt = &PortForwarding_channelvt; pf->input_wanted = TRUE; @@ -483,7 +483,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) pf->c = NULL; pf->cl = pl->cl; - pf->s = s = constructor(ctx, &pf->plugvt); + pf->s = s = constructor(ctx, &pf->plug); if ((err = sk_socket_error(s)) != NULL) { free_portfwd_state(pf); return err != NULL; @@ -536,7 +536,7 @@ static char *pfl_listen(char *desthost, int destport, char *srcaddr, * Open socket. */ pl = *pl_ret = new_portlistener_state(); - pl->plugvt = &PortListener_plugvt; + pl->plug.vt = &PortListener_plugvt; if (desthost) { pl->hostname = dupstr(desthost); pl->port = destport; @@ -545,7 +545,7 @@ static char *pfl_listen(char *desthost, int destport, char *srcaddr, pl->is_dynamic = TRUE; pl->cl = cl; - pl->s = new_listener(srcaddr, port, &pl->plugvt, + pl->s = new_listener(srcaddr, port, &pl->plug, !conf_get_int(conf, CONF_lport_acceptall), conf, address_family); if ((err = sk_socket_error(pl->s)) != NULL) { @@ -1042,7 +1042,7 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret, */ pf = new_portfwd_state(); *chan_ret = &pf->chan; - pf->plugvt = &PortForwarding_plugvt; + pf->plug.vt = &PortForwarding_plugvt; pf->chan.initial_fixed_window_size = 0; pf->chan.vt = &PortForwarding_channelvt; pf->input_wanted = TRUE; @@ -1052,7 +1052,7 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret, pf->socks_state = SOCKS_NONE; pf->s = new_connection(addr, dummy_realhost, port, - 0, 1, 0, 0, &pf->plugvt, mgr->conf); + 0, 1, 0, 0, &pf->plug, mgr->conf); sfree(dummy_realhost); if ((err = sk_socket_error(pf->s)) != NULL) { char *err_ret = dupstr(err); diff --git a/proxy.c b/proxy.c index 213c0042..138d12aa 100644 --- a/proxy.c +++ b/proxy.c @@ -73,14 +73,14 @@ void proxy_activate (ProxySocket *p) * unfreezing the actual underlying socket. */ if (!p->freeze) - sk_set_frozen(&p->sockvt, 0); + sk_set_frozen(&p->sock, 0); } /* basic proxy socket functions */ static Plug *sk_proxy_plug (Socket *s, Plug *p) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); Plug *ret = ps->plug; if (p) ps->plug = p; @@ -89,7 +89,7 @@ static Plug *sk_proxy_plug (Socket *s, Plug *p) static void sk_proxy_close (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); sk_close(ps->sub_socket); sk_addr_free(ps->remote_addr); @@ -98,7 +98,7 @@ static void sk_proxy_close (Socket *s) static int sk_proxy_write (Socket *s, const void *data, int len) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { bufchain_add(&ps->pending_output_data, data, len); @@ -109,7 +109,7 @@ static int sk_proxy_write (Socket *s, const void *data, int len) static int sk_proxy_write_oob (Socket *s, const void *data, int len) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { bufchain_clear(&ps->pending_output_data); @@ -122,7 +122,7 @@ static int sk_proxy_write_oob (Socket *s, const void *data, int len) static void sk_proxy_write_eof (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_eof = 1; @@ -133,7 +133,7 @@ static void sk_proxy_write_eof (Socket *s) static void sk_proxy_flush (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->pending_flush = 1; @@ -144,7 +144,7 @@ static void sk_proxy_flush (Socket *s) static void sk_proxy_set_frozen (Socket *s, int is_frozen) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); if (ps->state != PROXY_STATE_ACTIVE) { ps->freeze = is_frozen; @@ -183,7 +183,7 @@ static void sk_proxy_set_frozen (Socket *s, int is_frozen) static const char * sk_proxy_socket_error (Socket *s) { - ProxySocket *ps = FROMFIELD(s, ProxySocket, sockvt); + ProxySocket *ps = FROMFIELD(s, ProxySocket, sock); if (ps->error != NULL || ps->sub_socket == NULL) { return ps->error; } @@ -195,7 +195,7 @@ static const char * sk_proxy_socket_error (Socket *s) static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - ProxySocket *ps = FROMFIELD(plug, ProxySocket, plugvt); + ProxySocket *ps = FROMFIELD(plug, ProxySocket, plugimpl); plug_log(ps->plug, type, addr, port, error_msg, error_code); } @@ -203,7 +203,7 @@ static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port, static void plug_proxy_closing (Plug *p, const char *error_msg, int error_code, int calling_back) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugvt); + ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { ps->closing_error_msg = error_msg; @@ -217,7 +217,7 @@ static void plug_proxy_closing (Plug *p, const char *error_msg, static void plug_proxy_receive (Plug *p, int urgent, char *data, int len) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugvt); + ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { /* we will lose the urgentness of this data, but since most, @@ -236,7 +236,7 @@ static void plug_proxy_receive (Plug *p, int urgent, char *data, int len) static void plug_proxy_sent (Plug *p, int bufsize) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugvt); + ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { ps->sent_bufsize = bufsize; @@ -249,7 +249,7 @@ static void plug_proxy_sent (Plug *p, int bufsize) static int plug_proxy_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx) { - ProxySocket *ps = FROMFIELD(p, ProxySocket, plugvt); + ProxySocket *ps = FROMFIELD(p, ProxySocket, plugimpl); if (ps->state != PROXY_STATE_ACTIVE) { ps->accepting_constructor = constructor; @@ -438,8 +438,8 @@ Socket *new_connection(SockAddr *addr, const char *hostname, return sret; ret = snew(ProxySocket); - ret->sockvt = &ProxySocket_sockvt; - ret->plugvt = &ProxySocket_plugvt; + ret->sock.vt = &ProxySocket_sockvt; + ret->plugimpl.vt = &ProxySocket_plugvt; ret->conf = conf_copy(conf); ret->plug = plug; ret->remote_addr = addr; /* will need to be freed on close */ @@ -473,7 +473,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname, proxy_type = "Telnet"; } else { ret->error = "Proxy error: Unknown proxy method"; - return &ret->sockvt; + return &ret->sock; } { @@ -501,7 +501,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname, if (sk_addr_error(proxy_addr) != NULL) { ret->error = "Proxy error: Unable to resolve proxy host name"; sk_addr_free(proxy_addr); - return &ret->sockvt; + return &ret->sock; } sfree(proxy_canonical_name); @@ -521,15 +521,15 @@ Socket *new_connection(SockAddr *addr, const char *hostname, ret->sub_socket = sk_new(proxy_addr, conf_get_int(conf, CONF_proxy_port), privport, oobinline, - nodelay, keepalive, &ret->plugvt); + nodelay, keepalive, &ret->plugimpl); if (sk_socket_error(ret->sub_socket) != NULL) - return &ret->sockvt; + return &ret->sock; /* start the proxy negotiation process... */ sk_set_frozen(ret->sub_socket, 0); ret->negotiate(ret, PROXY_CHANGE_NEW); - return &ret->sockvt; + return &ret->sock; } /* no proxy, so just return the direct socket */ diff --git a/proxy.h b/proxy.h index 0abb7d3b..e37b820c 100644 --- a/proxy.h +++ b/proxy.h @@ -87,8 +87,8 @@ struct ProxySocket { int chap_current_attribute; int chap_current_datalen; - const SocketVtable *sockvt; - const PlugVtable *plugvt; + Socket sock; + Plug plugimpl; }; extern void proxy_activate (ProxySocket *); diff --git a/raw.c b/raw.c index dc6a40c5..9e451d9c 100644 --- a/raw.c +++ b/raw.c @@ -20,7 +20,7 @@ struct Raw { Conf *conf; - const PlugVtable *plugvt; + Plug plug; Backend backend; }; @@ -35,7 +35,7 @@ static void c_write(Raw *raw, const void *buf, int len) static void raw_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Raw *raw = FROMFIELD(plug, Raw, plugvt); + Raw *raw = FROMFIELD(plug, Raw, plug); backend_socket_log(raw->frontend, type, addr, port, error_msg, error_code, raw->conf, raw->session_started); } @@ -58,7 +58,7 @@ static void raw_check_close(Raw *raw) static void raw_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Raw *raw = FROMFIELD(plug, Raw, plugvt); + Raw *raw = FROMFIELD(plug, Raw, plug); if (error_msg) { /* A socket error has occurred. */ @@ -90,7 +90,7 @@ static void raw_closing(Plug *plug, const char *error_msg, int error_code, static void raw_receive(Plug *plug, int urgent, char *data, int len) { - Raw *raw = FROMFIELD(plug, Raw, plugvt); + Raw *raw = FROMFIELD(plug, Raw, plug); c_write(raw, data, len); /* We count 'session start', for proxy logging purposes, as being * when data is received from the network and printed. */ @@ -99,7 +99,7 @@ static void raw_receive(Plug *plug, int urgent, char *data, int len) static void raw_sent(Plug *plug, int bufsize) { - Raw *raw = FROMFIELD(plug, Raw, plugvt); + Raw *raw = FROMFIELD(plug, Raw, plug); raw->bufsize = bufsize; } @@ -130,7 +130,7 @@ static const char *raw_init(Frontend *frontend, Backend **backend_handle, char *loghost; raw = snew(Raw); - raw->plugvt = &Raw_plugvt; + raw->plug.vt = &Raw_plugvt; raw->backend.vt = &raw_backend; raw->s = NULL; raw->closed_on_socket_error = FALSE; @@ -160,7 +160,7 @@ static const char *raw_init(Frontend *frontend, Backend **backend_handle, * Open socket. */ raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive, - &raw->plugvt, conf); + &raw->plug, conf); if ((err = sk_socket_error(raw->s)) != NULL) return err; diff --git a/rlogin.c b/rlogin.c index 600e9f1c..01f79fc3 100644 --- a/rlogin.c +++ b/rlogin.c @@ -26,7 +26,7 @@ struct Rlogin { /* In case we need to read a username from the terminal before starting */ prompts_t *prompt; - const PlugVtable *plugvt; + Plug plug; Backend backend; }; @@ -39,7 +39,7 @@ static void c_write(Rlogin *rlogin, const void *buf, int len) static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plugvt); + Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); backend_socket_log(rlogin->frontend, type, addr, port, error_msg, error_code, rlogin->conf, !rlogin->firstbyte); @@ -48,7 +48,7 @@ static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port, static void rlogin_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plugvt); + Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); /* * We don't implement independent EOF in each direction for Telnet @@ -72,7 +72,7 @@ static void rlogin_closing(Plug *plug, const char *error_msg, int error_code, static void rlogin_receive(Plug *plug, int urgent, char *data, int len) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plugvt); + Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); if (urgent == 2) { char c; @@ -109,7 +109,7 @@ static void rlogin_receive(Plug *plug, int urgent, char *data, int len) static void rlogin_sent(Plug *plug, int bufsize) { - Rlogin *rlogin = FROMFIELD(plug, Rlogin, plugvt); + Rlogin *rlogin = FROMFIELD(plug, Rlogin, plug); rlogin->bufsize = bufsize; } @@ -162,7 +162,7 @@ static const char *rlogin_init(Frontend *frontend, Backend **backend_handle, char *loghost; rlogin = snew(Rlogin); - rlogin->plugvt = &Rlogin_plugvt; + rlogin->plug.vt = &Rlogin_plugvt; rlogin->backend.vt = &rlogin_backend; rlogin->s = NULL; rlogin->closed_on_socket_error = FALSE; @@ -193,7 +193,7 @@ static const char *rlogin_init(Frontend *frontend, Backend **backend_handle, * Open socket. */ rlogin->s = new_connection(addr, *realhost, port, 1, 0, - nodelay, keepalive, &rlogin->plugvt, conf); + nodelay, keepalive, &rlogin->plug, conf); if ((err = sk_socket_error(rlogin->s)) != NULL) return err; diff --git a/ssh.c b/ssh.c index 7a361319..c94554dd 100644 --- a/ssh.c +++ b/ssh.c @@ -37,7 +37,7 @@ struct Ssh { struct ssh_version_receiver version_receiver; int remote_bugs; - const PlugVtable *plugvt; + Plug plug; Backend backend; Ldisc *ldisc; @@ -489,7 +489,7 @@ void ssh_user_close(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) { - Ssh *ssh = FROMFIELD(plug, Ssh, plugvt); + Ssh *ssh = FROMFIELD(plug, Ssh, plug); /* * While we're attempting connection sharing, don't loudly log @@ -509,7 +509,7 @@ static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port, static void ssh_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Ssh *ssh = FROMFIELD(plug, Ssh, plugvt); + Ssh *ssh = FROMFIELD(plug, Ssh, plug); if (error_msg) { ssh_remote_error(ssh, "Network error: %s", error_msg); } else if (ssh->bpp) { @@ -520,7 +520,7 @@ static void ssh_closing(Plug *plug, const char *error_msg, int error_code, static void ssh_receive(Plug *plug, int urgent, char *data, int len) { - Ssh *ssh = FROMFIELD(plug, Ssh, plugvt); + Ssh *ssh = FROMFIELD(plug, Ssh, plug); /* Log raw data, if we're in that mode. */ if (ssh->logctx) @@ -534,7 +534,7 @@ static void ssh_receive(Plug *plug, int urgent, char *data, int len) static void ssh_sent(Plug *plug, int bufsize) { - Ssh *ssh = FROMFIELD(plug, Ssh, plugvt); + Ssh *ssh = FROMFIELD(plug, Ssh, plug); /* * If the send backlog on the SSH socket itself clears, we should * unthrottle the whole world if it was throttled. Also trigger an @@ -624,7 +624,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port, ssh_hostport_setup(host, port, ssh->conf, &ssh->savedhost, &ssh->savedport, &loghost); - ssh->plugvt = &Ssh_plugvt; + ssh->plug.vt = &Ssh_plugvt; /* * Try connection-sharing, in case that means we don't open a @@ -639,7 +639,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port, ssh->attempting_connshare = TRUE; /* affects socket logging behaviour */ ssh->s = ssh_connection_sharing_init( ssh->savedhost, ssh->savedport, ssh->conf, ssh->frontend, - &ssh->plugvt, &ssh->connshare); + &ssh->plug, &ssh->connshare); ssh->attempting_connshare = FALSE; if (ssh->s != NULL) { /* @@ -677,7 +677,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port, ssh->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive, - &ssh->plugvt, ssh->conf); + &ssh->plug, ssh->conf); if ((err = sk_socket_error(ssh->s)) != NULL) { ssh->s = NULL; notify_remote_exit(ssh->frontend); diff --git a/sshshare.c b/sshshare.c index 3b9bef50..0f35635e 100644 --- a/sshshare.c +++ b/sshshare.c @@ -147,7 +147,7 @@ struct ssh_sharing_state { ConnectionLayer *cl; /* instance of the ssh connection layer */ char *server_verstring; /* server version string after "SSH-" */ - const PlugVtable *plugvt; + Plug plug; }; struct share_globreq; @@ -200,7 +200,7 @@ struct ssh_sharing_connstate { /* Global requests we've sent on to the server, pending replies. */ struct share_globreq *globreq_head, *globreq_tail; - const PlugVtable *plugvt; + Plug plug; }; struct share_halfchannel { @@ -951,7 +951,7 @@ static void share_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { struct ssh_sharing_connstate *cs = FROMFIELD( - plug, struct ssh_sharing_connstate, plugvt); + plug, struct ssh_sharing_connstate, plug); if (error_msg) { #ifdef BROKEN_PIPE_ERROR_CODE @@ -1767,7 +1767,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs, static void share_receive(Plug *plug, int urgent, char *data, int len) { ssh_sharing_connstate *cs = FROMFIELD( - plug, ssh_sharing_connstate, plugvt); + plug, ssh_sharing_connstate, plug); static const char expected_verstring_prefix[] = "SSHCONNECTION@putty.projects.tartarus.org-2.0-"; unsigned char c; @@ -1843,7 +1843,7 @@ static void share_receive(Plug *plug, int urgent, char *data, int len) static void share_sent(Plug *plug, int bufsize) { /* ssh_sharing_connstate *cs = FROMFIELD( - plug, ssh_sharing_connstate, plugvt); */ + plug, ssh_sharing_connstate, plug); */ /* * We do nothing here, because we expect that there won't be a @@ -1858,7 +1858,7 @@ static void share_sent(Plug *plug, int bufsize) static void share_listen_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - ssh_sharing_state *sharestate = FROMFIELD(plug, ssh_sharing_state, plugvt); + ssh_sharing_state *sharestate = FROMFIELD(plug, ssh_sharing_state, plug); if (error_msg) log_general(sharestate, "listening socket: %s", error_msg); sk_close(sharestate->listensock); @@ -1922,7 +1922,7 @@ static int share_listen_accepting(Plug *plug, accept_fn_t constructor, accept_ctx_t ctx) { struct ssh_sharing_state *sharestate = FROMFIELD( - plug, struct ssh_sharing_state, plugvt); + plug, struct ssh_sharing_state, plug); struct ssh_sharing_connstate *cs; const char *err; char *peerinfo; @@ -1931,7 +1931,7 @@ static int share_listen_accepting(Plug *plug, * A new downstream has connected to us. */ cs = snew(struct ssh_sharing_connstate); - cs->plugvt = &ssh_sharing_conn_plugvt; + cs->plug.vt = &ssh_sharing_conn_plugvt; cs->parent = sharestate; if ((cs->id = share_find_unused_id(sharestate, sharestate->nextid)) == 0 && @@ -1943,7 +1943,7 @@ static int share_listen_accepting(Plug *plug, if (sharestate->nextid == 0) sharestate->nextid++; /* only happens in VERY long-running upstreams */ - cs->sock = constructor(ctx, &cs->plugvt); + cs->sock = constructor(ctx, &cs->plug); if ((err = sk_socket_error(cs->sock)) != NULL) { sfree(cs); return err != NULL; @@ -2104,7 +2104,7 @@ Socket *ssh_connection_sharing_init( * to be an upstream. */ sharestate = snew(struct ssh_sharing_state); - sharestate->plugvt = &ssh_sharing_listen_plugvt; + sharestate->plug.vt = &ssh_sharing_listen_plugvt; sharestate->listensock = NULL; sharestate->cl = NULL; @@ -2118,7 +2118,7 @@ Socket *ssh_connection_sharing_init( sock = NULL; logtext = ds_err = us_err = NULL; result = platform_ssh_share( - sockname, conf, sshplug, &sharestate->plugvt, &sock, &logtext, + sockname, conf, sshplug, &sharestate->plug, &sock, &logtext, &ds_err, &us_err, can_upstream, can_downstream); switch (result) { case SHARE_NONE: diff --git a/telnet.c b/telnet.c index 9e386fb8..dee0aab9 100644 --- a/telnet.c +++ b/telnet.c @@ -197,7 +197,7 @@ struct Telnet { Pinger *pinger; - const PlugVtable *plugvt; + Plug plug; Backend backend; }; @@ -645,7 +645,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len) static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, const char *error_msg, int error_code) { - Telnet *telnet = FROMFIELD(plug, Telnet, plugvt); + Telnet *telnet = FROMFIELD(plug, Telnet, plug); backend_socket_log(telnet->frontend, type, addr, port, error_msg, error_code, telnet->conf, telnet->session_started); @@ -654,7 +654,7 @@ static void telnet_log(Plug *plug, int type, SockAddr *addr, int port, static void telnet_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { - Telnet *telnet = FROMFIELD(plug, Telnet, plugvt); + Telnet *telnet = FROMFIELD(plug, Telnet, plug); /* * We don't implement independent EOF in each direction for Telnet @@ -678,7 +678,7 @@ static void telnet_closing(Plug *plug, const char *error_msg, int error_code, static void telnet_receive(Plug *plug, int urgent, char *data, int len) { - Telnet *telnet = FROMFIELD(plug, Telnet, plugvt); + Telnet *telnet = FROMFIELD(plug, Telnet, plug); if (urgent) telnet->in_synch = TRUE; telnet->session_started = TRUE; @@ -687,7 +687,7 @@ static void telnet_receive(Plug *plug, int urgent, char *data, int len) static void telnet_sent(Plug *plug, int bufsize) { - Telnet *telnet = FROMFIELD(plug, Telnet, plugvt); + Telnet *telnet = FROMFIELD(plug, Telnet, plug); telnet->bufsize = bufsize; } @@ -717,7 +717,7 @@ static const char *telnet_init(Frontend *frontend, Backend **backend_handle, int addressfamily; telnet = snew(Telnet); - telnet->plugvt = &Telnet_plugvt; + telnet->plug.vt = &Telnet_plugvt; telnet->backend.vt = &telnet_backend; telnet->conf = conf_copy(conf); telnet->s = NULL; @@ -754,7 +754,7 @@ static const char *telnet_init(Frontend *frontend, Backend **backend_handle, * Open socket. */ telnet->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive, - &telnet->plugvt, telnet->conf); + &telnet->plug, telnet->conf); if ((err = sk_socket_error(telnet->s)) != NULL) return err; diff --git a/unix/uxnet.c b/unix/uxnet.c index 3c0f3c1f..41cc0758 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -89,7 +89,7 @@ struct NetSocket { */ NetSocket *parent, *child; - const SocketVtable *sockvt; + Socket sock; }; struct SockAddr { @@ -484,7 +484,7 @@ SockAddr *sk_addr_dup(SockAddr *addr) static Plug *sk_net_plug(Socket *sock, Plug *p) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); Plug *ret = s->plug; if (p) s->plug = p; @@ -528,7 +528,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -549,7 +549,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) if (ret->s < 0) { ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } ret->oobinline = 0; @@ -557,7 +557,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) uxsel_tell(ret); add234(sktree, ret); - return &ret->sockvt; + return &ret->sock; } static int try_connect(NetSocket *sock) @@ -769,7 +769,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -801,7 +801,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, if (err) ret->error = strerror(err); - return &ret->sockvt; + return &ret->sock; } Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, @@ -824,7 +824,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -875,7 +875,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (s < 0) { ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } cloexec(s); @@ -886,7 +886,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, (const char *)&on, sizeof(on)) < 0) { ret->error = strerror(errno); close(s); - return &ret->sockvt; + return &ret->sock; } retcode = -1; @@ -964,13 +964,13 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (retcode < 0) { close(s); ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } if (listen(s, SOMAXCONN) < 0) { close(s); ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } #ifndef NO_IPV6 @@ -984,7 +984,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, other = FROMFIELD( sk_newlistener(srcaddr, port, plug, local_host_only, ADDRTYPE_IPV4), - NetSocket, sockvt); + NetSocket, sock); if (other) { if (!other->error) { @@ -995,7 +995,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, * as IPv6, we must return an error overall. */ close(s); sfree(ret); - return &other->sockvt; + return &other->sock; } } } @@ -1006,15 +1006,15 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, uxsel_tell(ret); add234(sktree, ret); - return &ret->sockvt; + return &ret->sock; } static void sk_net_close(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); if (s->child) - sk_net_close(&s->child->sockvt); + sk_net_close(&s->child->sock); del234(sktree, s); if (s->s >= 0) { @@ -1038,9 +1038,9 @@ void *sk_getxdmdata(Socket *sock, int *lenp) * We must check that this socket really _is_ a NetSocket before * downcasting it. */ - if (*sock != &NetSocket_sockvt) + if (sock->vt != &NetSocket_sockvt) return NULL; /* failure */ - s = FROMFIELD(sock, NetSocket, sockvt); + s = FROMFIELD(sock, NetSocket, sock); addrlen = sizeof(u); if (getsockname(s->s, &u.sa, &addrlen) < 0) @@ -1186,7 +1186,7 @@ void try_send(NetSocket *s) static int sk_net_write(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1212,7 +1212,7 @@ static int sk_net_write(Socket *sock, const void *buf, int len) static int sk_net_write_oob(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1241,7 +1241,7 @@ static int sk_net_write_oob(Socket *sock, const void *buf, int len) static void sk_net_write_eof(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1468,13 +1468,13 @@ const char *sk_addr_error(SockAddr *addr) } static const char *sk_net_socket_error(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); return s->error; } static void sk_net_set_frozen(Socket *sock, int is_frozen) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); if (s->frozen == is_frozen) return; s->frozen = is_frozen; @@ -1483,7 +1483,7 @@ static void sk_net_set_frozen(Socket *sock, int is_frozen) static char *sk_net_peer_info(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); union sockaddr_union addr; socklen_t addrlen = sizeof(addr); #ifndef NO_IPV6 @@ -1644,7 +1644,7 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug) * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -1669,7 +1669,7 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug) s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) { ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } cloexec(s); @@ -1692,20 +1692,20 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug) if (unlink(u.su.sun_path) < 0 && errno != ENOENT) { close(s); ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } retcode = bind(s, &addr->sa, addrlen); if (retcode < 0) { close(s); ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } if (listen(s, SOMAXCONN) < 0) { close(s); ret->error = strerror(errno); - return &ret->sockvt; + return &ret->sock; } ret->s = s; @@ -1713,5 +1713,5 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug) uxsel_tell(ret); add234(sktree, ret); - return &ret->sockvt; + return &ret->sock; } diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 13f44c7b..8feff9df 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -176,7 +176,7 @@ static void x11_closing(Plug *plug, const char *error_msg, int error_code, time_to_die = TRUE; } struct X11Connection { - const PlugVtable *plugvt; + Plug plug; }; char *socketname; @@ -809,10 +809,10 @@ void run_agent(void) disp = x11_setup_display(display, conf); conn = snew(struct X11Connection); - conn->plugvt = &X11Connection_plugvt; + conn->plug.vt = &X11Connection_plugvt; s = new_connection(sk_addr_dup(disp->addr), disp->realhost, disp->port, - 0, 1, 0, 0, &conn->plugvt, conf); + 0, 1, 0, 0, &conn->plug, conf); if ((err = sk_socket_error(s)) != NULL) { fprintf(stderr, "pageant: unable to connect to X server: %s", err); exit(1); diff --git a/unix/uxproxy.c b/unix/uxproxy.c index 2dce0418..67757ca6 100644 --- a/unix/uxproxy.c +++ b/unix/uxproxy.c @@ -29,7 +29,7 @@ typedef struct LocalProxySocket { int pending_error; - const SocketVtable *sockvt; + Socket sock; } LocalProxySocket; static void localproxy_select_result(int fd, int event); @@ -105,7 +105,7 @@ static int localproxy_errfd_find(void *av, void *bv) static Plug *sk_localproxy_plug (Socket *s, Plug *p) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); + LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); Plug *ret = ps->plug; if (p) ps->plug = p; @@ -114,7 +114,7 @@ static Plug *sk_localproxy_plug (Socket *s, Plug *p) static void sk_localproxy_close (Socket *s) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); + LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); if (ps->to_cmd >= 0) { del234(localproxy_by_tofd, ps); @@ -202,7 +202,7 @@ static int localproxy_try_send(LocalProxySocket *ps) static int sk_localproxy_write (Socket *s, const void *data, int len) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); + LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); assert(ps->outgoingeof == EOF_NO); @@ -224,7 +224,7 @@ static int sk_localproxy_write_oob (Socket *s, const void *data, int len) static void sk_localproxy_write_eof (Socket *s) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); + LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); assert(ps->outgoingeof == EOF_NO); ps->outgoingeof = EOF_PENDING; @@ -234,13 +234,13 @@ static void sk_localproxy_write_eof (Socket *s) static void sk_localproxy_flush (Socket *s) { - /* LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); */ + /* LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); */ /* do nothing */ } static void sk_localproxy_set_frozen (Socket *s, int is_frozen) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); + LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); if (ps->from_cmd < 0) return; @@ -253,7 +253,7 @@ static void sk_localproxy_set_frozen (Socket *s, int is_frozen) static const char * sk_localproxy_socket_error (Socket *s) { - LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sockvt); + LocalProxySocket *ps = FROMFIELD(s, LocalProxySocket, sock); return ps->error; } @@ -330,7 +330,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, return NULL; ret = snew(LocalProxySocket); - ret->sockvt = &LocalProxySocket_sockvt; + ret->sock.vt = &LocalProxySocket_sockvt; ret->plug = plug; ret->error = NULL; ret->outgoingeof = EOF_NO; @@ -358,7 +358,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, pipe(cmd_err_pipe) < 0) { ret->error = dupprintf("pipe: %s", strerror(errno)); sfree(cmd); - return &ret->sockvt; + return &ret->sock; } cloexec(to_cmd_pipe[1]); cloexec(from_cmd_pipe[0]); @@ -369,7 +369,7 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, if (pid < 0) { ret->error = dupprintf("fork: %s", strerror(errno)); sfree(cmd); - return &ret->sockvt; + return &ret->sock; } else if (pid == 0) { close(0); close(1); @@ -399,13 +399,13 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, if (ret->to_cmd == -1) { ret->error = dupprintf("/dev/null: %s", strerror(errno)); sfree(cmd); - return &ret->sockvt; + return &ret->sock; } ret->from_cmd = open(cmd, O_RDONLY); if (ret->from_cmd == -1) { ret->error = dupprintf("%s: %s", cmd, strerror(errno)); sfree(cmd); - return &ret->sockvt; + return &ret->sock; } sfree(cmd); ret->cmd_err = -1; @@ -430,5 +430,5 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname, /* We are responsible for this and don't need it any more */ sk_addr_free(addr); - return &ret->sockvt; + return &ret->sock; } diff --git a/windows/winhsock.c b/windows/winhsock.c index 4fefe31f..b120c143 100644 --- a/windows/winhsock.c +++ b/windows/winhsock.c @@ -43,7 +43,7 @@ typedef struct HandleSocket { Plug *plug; - const SocketVtable *sockvt; + Socket sock; } HandleSocket; static int handle_gotdata(struct handle *h, void *data, int len) @@ -107,7 +107,7 @@ static void handle_sentdata(struct handle *h, int new_backlog) static Plug *sk_handle_plug(Socket *s, Plug *p) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); Plug *ret = hs->plug; if (p) hs->plug = p; @@ -116,7 +116,7 @@ static Plug *sk_handle_plug(Socket *s, Plug *p) static void sk_handle_close(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); if (hs->defer_close) { hs->deferred_close = TRUE; @@ -136,7 +136,7 @@ static void sk_handle_close(Socket *s) static int sk_handle_write(Socket *s, const void *data, int len) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); return handle_write(hs->send_h, data, len); } @@ -152,14 +152,14 @@ static int sk_handle_write_oob(Socket *s, const void *data, int len) static void sk_handle_write_eof(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); handle_write_eof(hs->send_h); } static void sk_handle_flush(Socket *s) { - /* HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); */ + /* HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); */ /* do nothing */ } @@ -191,7 +191,7 @@ static void handle_socket_unfreeze(void *hsv) bufchain_consume(&hs->inputdata, len); hs->defer_close = FALSE; if (hs->deferred_close) { - sk_handle_close(&hs->sockvt); + sk_handle_close(&hs->sock); return; } @@ -212,7 +212,7 @@ static void handle_socket_unfreeze(void *hsv) static void sk_handle_set_frozen(Socket *s, int is_frozen) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); if (is_frozen) { switch (hs->frozen) { @@ -267,13 +267,13 @@ static void sk_handle_set_frozen(Socket *s, int is_frozen) static const char *sk_handle_socket_error(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); return hs->error; } static char *sk_handle_peer_info(Socket *s) { - HandleSocket *hs = FROMFIELD(s, HandleSocket, sockvt); + HandleSocket *hs = FROMFIELD(s, HandleSocket, sock); ULONG pid; static HMODULE kernel32_module; DECL_WINDOWS_FUNCTION(static, BOOL, GetNamedPipeClientProcessId, @@ -325,7 +325,7 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, int flags = (overlapped ? HANDLE_FLAG_OVERLAPPED : 0); hs = snew(HandleSocket); - hs->sockvt = &HandleSocket_sockvt; + hs->sock.vt = &HandleSocket_sockvt; hs->plug = plug; hs->error = NULL; hs->frozen = UNFROZEN; @@ -343,5 +343,5 @@ Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H, hs->defer_close = hs->deferred_close = FALSE; - return &hs->sockvt; + return &hs->sock; } diff --git a/windows/winnet.c b/windows/winnet.c index 2427b688..8d0c4ac6 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -76,7 +76,7 @@ struct NetSocket { */ NetSocket *parent, *child; - const SocketVtable *sockvt; + Socket sock; }; struct SockAddr { @@ -910,7 +910,7 @@ SockAddr *sk_addr_dup(SockAddr *addr) static Plug *sk_net_plug(Socket *sock, Plug *p) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); Plug *ret = s->plug; if (p) s->plug = p; @@ -957,7 +957,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -976,7 +976,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) if (ret->s == INVALID_SOCKET) { err = p_WSAGetLastError(); ret->error = winsock_error_string(err); - return &ret->sockvt; + return &ret->sock; } ret->oobinline = 0; @@ -986,12 +986,12 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug) errstr = do_select(ret->s, 1); if (errstr) { ret->error = errstr; - return &ret->sockvt; + return &ret->sock; } add234(sktree, ret); - return &ret->sockvt; + return &ret->sock; } static DWORD try_connect(NetSocket *sock) @@ -1202,7 +1202,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -1229,7 +1229,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline, err = try_connect(ret); } while (err && sk_nextaddr(ret->addr, &ret->step)); - return &ret->sockvt; + return &ret->sock; } Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, @@ -1253,7 +1253,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, * Create NetSocket structure. */ ret = snew(NetSocket); - ret->sockvt = &NetSocket_sockvt; + ret->sock.vt = &NetSocket_sockvt; ret->error = NULL; ret->plug = plug; bufchain_init(&ret->output_data); @@ -1295,7 +1295,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (s == INVALID_SOCKET) { err = p_WSAGetLastError(); ret->error = winsock_error_string(err); - return &ret->sockvt; + return &ret->sock; } SetHandleInformation((HANDLE)s, HANDLE_FLAG_INHERIT, 0); @@ -1381,14 +1381,14 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (err) { p_closesocket(s); ret->error = winsock_error_string(err); - return &ret->sockvt; + return &ret->sock; } if (p_listen(s, SOMAXCONN) == SOCKET_ERROR) { p_closesocket(s); ret->error = winsock_error_string(p_WSAGetLastError()); - return &ret->sockvt; + return &ret->sock; } /* Set up a select mechanism. This could be an AsyncSelect on a @@ -1397,7 +1397,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, if (errstr) { p_closesocket(s); ret->error = errstr; - return &ret->sockvt; + return &ret->sock; } add234(sktree, ret); @@ -1412,7 +1412,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, local_host_only, ADDRTYPE_IPV6); if (other) { - NetSocket *ns = FROMFIELD(other, NetSocket, sockvt); + NetSocket *ns = FROMFIELD(other, NetSocket, sock); if (!ns->error) { ns->parent = ret; ret->child = ns; @@ -1423,16 +1423,16 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug, } #endif - return &ret->sockvt; + return &ret->sock; } static void sk_net_close(Socket *sock) { extern char *do_select(SOCKET skt, int startup); - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); if (s->child) - sk_net_close(&s->child->sockvt); + sk_net_close(&s->child->sock); del234(sktree, s); do_select(s->s, 0); @@ -1540,7 +1540,7 @@ void try_send(NetSocket *s) static int sk_net_write(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1560,7 +1560,7 @@ static int sk_net_write(Socket *sock, const void *buf, int len) static int sk_net_write_oob(Socket *sock, const void *buf, int len) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1583,7 +1583,7 @@ static int sk_net_write_oob(Socket *sock, const void *buf, int len) static void sk_net_write_eof(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); assert(s->outgoingeof == EOF_NO); @@ -1786,13 +1786,13 @@ const char *sk_addr_error(SockAddr *addr) } static const char *sk_net_socket_error(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); return s->error; } static char *sk_net_peer_info(Socket *sock) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); #ifdef NO_IPV6 struct sockaddr_in addr; #else @@ -1824,7 +1824,7 @@ static char *sk_net_peer_info(Socket *sock) static void sk_net_set_frozen(Socket *sock, int is_frozen) { - NetSocket *s = FROMFIELD(sock, NetSocket, sockvt); + NetSocket *s = FROMFIELD(sock, NetSocket, sock); if (s->frozen == is_frozen) return; s->frozen = is_frozen; diff --git a/windows/winnps.c b/windows/winnps.c index c6a9f6a6..908b0435 100644 --- a/windows/winnps.c +++ b/windows/winnps.c @@ -34,12 +34,12 @@ typedef struct NamedPipeServerSocket { Plug *plug; char *error; - const SocketVtable *sockvt; + Socket sock; } NamedPipeServerSocket; static Plug *sk_namedpipeserver_plug(Socket *s, Plug *p) { - NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sockvt); + NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sock); Plug *ret = ps->plug; if (p) ps->plug = p; @@ -48,7 +48,7 @@ static Plug *sk_namedpipeserver_plug(Socket *s, Plug *p) static void sk_namedpipeserver_close(Socket *s) { - NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sockvt); + NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sock); if (ps->callback_handle) handle_free(ps->callback_handle); @@ -65,7 +65,7 @@ static void sk_namedpipeserver_close(Socket *s) static const char *sk_namedpipeserver_socket_error(Socket *s) { - NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sockvt); + NamedPipeServerSocket *ps = FROMFIELD(s, NamedPipeServerSocket, sock); return ps->error; } @@ -219,7 +219,7 @@ static const SocketVtable NamedPipeServerSocket_sockvt = { Socket *new_named_pipe_listener(const char *pipename, Plug *plug) { NamedPipeServerSocket *ret = snew(NamedPipeServerSocket); - ret->sockvt = &NamedPipeServerSocket_sockvt; + ret->sock.vt = &NamedPipeServerSocket_sockvt; ret->plug = plug; ret->error = NULL; ret->psd = NULL; @@ -249,7 +249,7 @@ Socket *new_named_pipe_listener(const char *pipename, Plug *plug) named_pipe_accept_loop(ret, FALSE); cleanup: - return &ret->sockvt; + return &ret->sock; } #endif /* !defined NO_SECURITY */ diff --git a/x11fwd.c b/x11fwd.c index 34c5cb96..b975bd19 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -42,7 +42,7 @@ typedef struct X11Connection { SshChannel *c; /* channel structure held by SSH backend */ Socket *s; - const PlugVtable *plugvt; + Plug plug; Channel chan; } X11Connection; @@ -635,7 +635,7 @@ static void x11_closing(Plug *plug, const char *error_msg, int error_code, int calling_back) { struct X11Connection *xconn = FROMFIELD( - plug, struct X11Connection, plugvt); + plug, struct X11Connection, plug); if (error_msg) { /* @@ -667,7 +667,7 @@ static void x11_closing(Plug *plug, const char *error_msg, int error_code, static void x11_receive(Plug *plug, int urgent, char *data, int len) { struct X11Connection *xconn = FROMFIELD( - plug, struct X11Connection, plugvt); + plug, struct X11Connection, plug); xconn->no_data_sent_to_x_client = FALSE; sshfwd_write(xconn->c, data, len); @@ -676,7 +676,7 @@ static void x11_receive(Plug *plug, int urgent, char *data, int len) static void x11_sent(Plug *plug, int bufsize) { struct X11Connection *xconn = FROMFIELD( - plug, struct X11Connection, plugvt); + plug, struct X11Connection, plug); sshfwd_unthrottle(xconn->c, bufsize); } @@ -738,7 +738,7 @@ Channel *x11_new_channel(tree234 *authtree, SshChannel *c, * Open socket. */ xconn = snew(struct X11Connection); - xconn->plugvt = &X11Connection_plugvt; + xconn->plug.vt = &X11Connection_plugvt; xconn->chan.vt = &X11Connection_channelvt; xconn->chan.initial_fixed_window_size = (connection_sharing_possible ? 128 : 0); @@ -945,7 +945,7 @@ static int x11_send(Channel *chan, int is_stderr, const void *vdata, int len) xconn->disp = auth_matched->disp; xconn->s = new_connection(sk_addr_dup(xconn->disp->addr), xconn->disp->realhost, xconn->disp->port, - 0, 1, 0, 0, &xconn->plugvt, + 0, 1, 0, 0, &xconn->plug, sshfwd_get_conf(xconn->c)); if ((err = sk_socket_error(xconn->s)) != NULL) { char *err_message = dupprintf("unable to connect to"