Pass the Ssh structure to portfwd.c with a tag.

Again, safer than using a 'void *'.
This commit is contained in:
Simon Tatham 2018-09-11 15:33:10 +01:00
Родитель 3814a5cee8
Коммит c51fe7c217
4 изменённых файлов: 13 добавлений и 14 удалений

1
defs.h
Просмотреть файл

@ -47,6 +47,7 @@ typedef struct Plug_vtable Plug_vtable;
typedef struct Ldisc_tag Ldisc;
typedef struct LogContext_tag LogContext;
typedef struct ssh_tag *Ssh;
/* Note indirection: for historical reasons (it used to be closer to
* the OS socket type), the type that most code uses for a socket is
* 'Socket', not 'Socket *'. So an implementation of Socket or Plug

Просмотреть файл

@ -23,8 +23,8 @@ typedef enum {
struct PortForwarding {
struct ssh_channel *c; /* channel structure held by ssh.c */
void *backhandle; /* instance of SSH backend itself */
/* Note that backhandle need not be filled in if c is non-NULL */
Ssh ssh; /* instance of SSH backend itself */
/* Note that ssh need not be filled in if c is non-NULL */
Socket s;
int throttled, throttle_override;
int ready;
@ -47,7 +47,7 @@ struct PortForwarding {
};
struct PortListener {
void *backhandle; /* instance of SSH backend itself */
Ssh ssh; /* instance of SSH backend itself */
Socket s;
int is_dynamic;
/*
@ -396,7 +396,7 @@ static void pfd_receive(Plug plug, int urgent, char *data, int len)
*/
sk_set_frozen(pf->s, 1);
pf->c = new_sock_channel(pf->backhandle, pf);
pf->c = new_sock_channel(pf->ssh, pf);
if (pf->c == NULL) {
pfd_close(pf);
return;
@ -464,7 +464,7 @@ char *pfd_connect(struct PortForwarding **pf_ret, char *hostname,int port,
pf->throttled = pf->throttle_override = 0;
pf->ready = 1;
pf->c = c;
pf->backhandle = NULL; /* we shouldn't need this */
pf->ssh = NULL; /* we shouldn't need this */
pf->socks_state = SOCKS_NONE;
pf->s = new_connection(addr, dummy_realhost, port,
@ -497,7 +497,7 @@ static int pfl_accepting(Plug p, accept_fn_t constructor, accept_ctx_t ctx)
pf->plugvt = &PortForwarding_plugvt;
pf->c = NULL;
pf->backhandle = pl->backhandle;
pf->ssh = pl->ssh;
pf->s = s = constructor(ctx, &pf->plugvt);
if ((err = sk_socket_error(s)) != NULL) {
@ -518,7 +518,7 @@ static int pfl_accepting(Plug p, accept_fn_t constructor, accept_ctx_t ctx)
pf->socks_state = SOCKS_NONE;
pf->hostname = dupstr(pl->hostname);
pf->port = pl->port;
pf->c = new_sock_channel(pl->backhandle, pf);
pf->c = new_sock_channel(pl->ssh, pf);
if (pf->c == NULL) {
free_portfwd_state(pf);
@ -547,7 +547,7 @@ static const Plug_vtable PortListener_plugvt = {
* dynamically allocated error message string.
*/
char *pfl_listen(char *desthost, int destport, char *srcaddr,
int port, void *backhandle, Conf *conf,
int port, Ssh ssh, Conf *conf,
struct PortListener **pl_ret, int address_family)
{
const char *err;
@ -564,7 +564,7 @@ char *pfl_listen(char *desthost, int destport, char *srcaddr,
pl->is_dynamic = FALSE;
} else
pl->is_dynamic = TRUE;
pl->backhandle = backhandle;
pl->ssh = ssh;
pl->s = new_listener(srcaddr, port, &pl->plugvt,
!conf_get_int(conf, CONF_lport_acceptall),

3
ssh.c
Просмотреть файл

@ -11293,9 +11293,8 @@ static void ssh_special(void *handle, Telnet_Special code)
}
}
void *new_sock_channel(void *handle, struct PortForwarding *pf)
void *new_sock_channel(Ssh ssh, struct PortForwarding *pf)
{
Ssh ssh = (Ssh) handle;
struct ssh_channel *c;
c = snew(struct ssh_channel);

5
ssh.h
Просмотреть файл

@ -8,7 +8,6 @@
#include "misc.h"
struct ssh_channel;
typedef struct ssh_tag *Ssh;
extern int sshfwd_write(struct ssh_channel *c, const void *, int);
extern void sshfwd_write_eof(struct ssh_channel *c);
@ -666,7 +665,7 @@ void logevent(void *, const char *);
struct PortForwarding;
/* Allocate and register a new channel for port forwarding */
void *new_sock_channel(void *handle, struct PortForwarding *pf);
void *new_sock_channel(Ssh ssh, struct PortForwarding *pf);
void ssh_send_port_open(void *channel, const char *hostname, int port,
const char *org);
@ -682,7 +681,7 @@ extern void pfd_override_throttle(struct PortForwarding *, int enable);
struct PortListener;
/* desthost == NULL indicates dynamic (SOCKS) port forwarding */
extern char *pfl_listen(char *desthost, int destport, char *srcaddr,
int port, void *backhandle, Conf *conf,
int port, Ssh ssh, Conf *conf,
struct PortListener **pl, int address_family);
extern void pfl_terminate(struct PortListener *);