Commit f4eee0ee authored by Niels Möller's avatar Niels Möller
Browse files

* src/tcpforward.c (lookup_forward): Use CAST_SUBTYPE.

(do_tcpip_channel_die): Call close_fd() rather than kill_fd().
(tcpip_channel_start_io): Don't call channel_start_receive().
(make_exc_tcpip_connect_handler): New exception handler, which
raises EXC_CHANNEL_OPEN on connect and dns errors.
(do_open_forwarded_tcpip_continuation): Require that channel !=
NULL.
(make_open_forwarded_tcpip_continuation): Removed
exception_handler argument.
(do_channel_open_direct_tcpip): Use a better exception handler.
(do_channel_open_forwarded_tcpip): -"-

Rev: src/tcpforward.c:1.36
parent ff05f893
...@@ -71,7 +71,7 @@ lookup_forward(struct object_queue *q, ...@@ -71,7 +71,7 @@ lookup_forward(struct object_queue *q,
{ {
FOR_OBJECT_QUEUE(q, n) FOR_OBJECT_QUEUE(q, n)
{ {
CAST(forwarded_port, f, n); CAST_SUBTYPE(forwarded_port, f, n);
if ( (port == f->listen->port) if ( (port == f->listen->port)
&& lsh_string_eq_l(f->listen->ip, length, ip) ) && lsh_string_eq_l(f->listen->ip, length, ip) )
...@@ -155,7 +155,7 @@ do_tcpip_channel_die(struct ssh_channel *c) ...@@ -155,7 +155,7 @@ do_tcpip_channel_die(struct ssh_channel *c)
CAST(tcpip_channel, channel, c); CAST(tcpip_channel, channel, c);
if (channel->socket) if (channel->socket)
kill_fd(&channel->socket->super); close_fd(&channel->socket->super, 0);
} }
struct ssh_channel *make_tcpip_channel(struct io_fd *socket, UINT32 max_window) struct ssh_channel *make_tcpip_channel(struct io_fd *socket, UINT32 max_window)
...@@ -165,6 +165,8 @@ struct ssh_channel *make_tcpip_channel(struct io_fd *socket, UINT32 max_window) ...@@ -165,6 +165,8 @@ struct ssh_channel *make_tcpip_channel(struct io_fd *socket, UINT32 max_window)
init_channel(&self->super); init_channel(&self->super);
/* The rest of the callbacks are not set up until tcpip_start_io. */
self->super.close = do_tcpip_channel_die; self->super.close = do_tcpip_channel_die;
self->super.max_window = max_window; self->super.max_window = max_window;
...@@ -178,8 +180,11 @@ struct ssh_channel *make_tcpip_channel(struct io_fd *socket, UINT32 max_window) ...@@ -178,8 +180,11 @@ struct ssh_channel *make_tcpip_channel(struct io_fd *socket, UINT32 max_window)
return &self->super; return &self->super;
} }
/* FIXME: Where should we install a proper I/O-error handler, that /* NOTE: Because this function is called by
* closes the channel? */ * do_open_forwarded_tcpip_continuation, the same restrictions apply.
* I.e we can not assume that the channel is completely initialized
* (channel_open_continuation has not yet done its work), and we can't
* send any packets. */
void tcpip_channel_start_io(struct ssh_channel *c) void tcpip_channel_start_io(struct ssh_channel *c)
{ {
...@@ -188,16 +193,13 @@ void tcpip_channel_start_io(struct ssh_channel *c) ...@@ -188,16 +193,13 @@ void tcpip_channel_start_io(struct ssh_channel *c)
channel->super.receive = do_tcpip_receive; channel->super.receive = do_tcpip_receive;
channel->super.send = do_tcpip_send; channel->super.send = do_tcpip_send;
channel->super.eof = do_tcpip_eof; channel->super.eof = do_tcpip_eof;
/* Install callbacks on the local socket */ /* Install callbacks on the local socket */
io_read_write(channel->socket, io_read_write(channel->socket,
make_channel_read_data(&channel->super), make_channel_read_data(&channel->super),
/* FIXME: Make this configurable */ /* FIXME: Make this configurable */
SSH_MAX_PACKET * 10, /* self->block_size, */ SSH_MAX_PACKET * 10, /* self->block_size, */
make_channel_read_close_callback(&channel->super)); make_channel_read_close_callback(&channel->super));
/* Start receiving */
channel_start_receive(&channel->super);
/* Flow control */ /* Flow control */
channel->socket->write_buffer->report = &channel->super.super; channel->socket->write_buffer->report = &channel->super.super;
...@@ -206,14 +208,45 @@ void tcpip_channel_start_io(struct ssh_channel *c) ...@@ -206,14 +208,45 @@ void tcpip_channel_start_io(struct ssh_channel *c)
/* Handle channel open requests */ /* Handle channel open requests */
/* Exception handler that promotes connect and dns errors to
* CHANNEL_OPEN exceptions */
static void
do_exc_tcip_connect_handler(struct exception_handler *s,
const struct exception *e)
{
switch(e->type)
{
case EXC_IO_CONNECT:
case EXC_RESOLVE:
EXCEPTION_RAISE(s->parent,
make_channel_open_exception(SSH_OPEN_CONNECT_FAILED,
e->msg));
break;
default:
EXCEPTION_RAISE(s->parent, e);
}
}
static struct exception_handler *
make_exc_tcpip_connect_handler(struct exception_handler *parent,
const char *context)
{
return make_exception_handler(do_exc_tcip_connect_handler, parent, context);
}
/* GABA: /* GABA:
(class (class
(name open_forwarded_tcpip_continuation) (name open_forwarded_tcpip_continuation)
(super command_frame) (super command_continuation)
(vars (vars
(up object command_continuation)
(connection object ssh_connection))) (connection object ssh_connection)))
*/ */
/* NOTE: This continuation should not duplicate the work done by
* channel_open_continuation. It must also not send any packets on the
* channel, because it is not yet completely initialized. */
static void static void
do_open_forwarded_tcpip_continuation(struct command_continuation *s, do_open_forwarded_tcpip_continuation(struct command_continuation *s,
struct lsh_object *x) struct lsh_object *x)
...@@ -221,33 +254,26 @@ do_open_forwarded_tcpip_continuation(struct command_continuation *s, ...@@ -221,33 +254,26 @@ do_open_forwarded_tcpip_continuation(struct command_continuation *s,
CAST(open_forwarded_tcpip_continuation, self, s); CAST(open_forwarded_tcpip_continuation, self, s);
CAST_SUBTYPE(ssh_channel, channel, x); CAST_SUBTYPE(ssh_channel, channel, x);
if (channel) assert(channel);
{
channel->write = self->connection->write;
tcpip_channel_start_io(channel);
COMMAND_RETURN(self->super.up, channel); tcpip_channel_start_io(channel);
}
else COMMAND_RETURN(self->up, channel);
EXCEPTION_RAISE(self->super.e,
make_channel_open_exception(SSH_OPEN_CONNECT_FAILED,
NULL));
} }
static struct command_continuation * static struct command_continuation *
make_open_forwarded_tcpip_continuation(struct ssh_connection *connection, make_open_forwarded_tcpip_continuation(struct ssh_connection *connection,
struct command_continuation *c, struct command_continuation *c)
struct exception_handler *e)
{ {
NEW(open_forwarded_tcpip_continuation, self); NEW(open_forwarded_tcpip_continuation, self);
self->super.super.c = do_open_forwarded_tcpip_continuation; self->super.c = do_open_forwarded_tcpip_continuation;
self->super.up = c; self->up = c;
self->super.e = e;
self->connection = connection; self->connection = connection;
return &self->super.super; return &self->super;
} }
/* GABA: /* GABA:
(class (class
(name channel_open_direct_tcpip) (name channel_open_direct_tcpip)
...@@ -283,9 +309,10 @@ do_channel_open_direct_tcpip(struct channel_open *s, ...@@ -283,9 +309,10 @@ do_channel_open_direct_tcpip(struct channel_open *s,
COMMAND_CALL COMMAND_CALL
(closure->callback, (closure->callback,
make_address_info(dest_host, dest_port), make_address_info(dest_host, dest_port),
make_open_forwarded_tcpip_continuation(connection, c, e), make_open_forwarded_tcpip_continuation(connection, c),
/* FIXME: Which exception handler should we use? */ /* NOTE: This exception handler will be associated with the
e /* make_open_forwarded_tcpip_raise(response) */); * fd for its entire lifetime. */
make_exc_tcpip_connect_handler(e, HANDLER_CONTEXT));
} }
else else
{ {
...@@ -524,10 +551,11 @@ do_channel_open_forwarded_tcpip(struct channel_open *s UNUSED, ...@@ -524,10 +551,11 @@ do_channel_open_forwarded_tcpip(struct channel_open *s UNUSED,
{ {
COMMAND_CALL(port->callback, COMMAND_CALL(port->callback,
make_address_info(peer_host, peer_port), make_address_info(peer_host, peer_port),
make_open_forwarded_tcpip_continuation(connection, c, e), make_open_forwarded_tcpip_continuation(connection, c),
/* FIXME: Use a better exception handler */ /* NOTE: This exception handler will be
e * associated with the fd for its entire
/* make_open_forwarded_tcpip_raise(response) */); * lifetime. */
make_exc_tcpip_connect_handler(e, HANDLER_CONTEXT));
return; return;
} }
werror("Received a forwarded-tcpip request on a port for which we\n" werror("Received a forwarded-tcpip request on a port for which we\n"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment