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

* src/channel_forward.h: Renamed the tcpip_channel to

channel_forward, and moved it to a separate file. It's not really
tcpip-forwarding specific, and can be reused for x11-forwarding.

Rev: src/channel_forward.c:1.1
Rev: src/channel_forward.h:1.1
Rev: src/tcpforward.c:1.62
Rev: src/tcpforward.h:1.17
Rev: src/tcpforward_commands.c:1.33
parent fa272214
/* channel_forward.h
*
* General channel type for forwarding data to an fd
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998, 2001 Balzs Scheidler, Niels Mller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "channel_forward.h"
#include "io.h"
#include "ssh.h"
#include "werror.h"
#include "xalloc.h"
#include <assert.h>
#include <errno.h>
#include <string.h>
#define GABA_DEFINE
#include "channel_forward.h.x"
#undef GABA_DEFINE
/* NOTE: Adds the socket to the channel's resource list */
struct ssh_channel *
make_channel_forward(struct lsh_fd *socket, UINT32 initial_window)
{
NEW(channel_forward, self);
assert(socket);
init_channel(&self->super);
/* The rest of the callbacks are not set up until tcpip_start_io. */
/* NOTE: We don't need a close handler, as the channel's resource
* list is taken care of automatically. */
self->super.rec_window_size = initial_window;
/* FIXME: Make maximum packet size configurable. */
self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ;
self->socket = socket;
REMEMBER_RESOURCE(self->super.resources, &socket->super);
return &self->super;
}
static void
do_channel_forward_receive(struct ssh_channel *c,
int type, struct lsh_string *data)
{
CAST(channel_forward, closure, c);
switch (type)
{
case CHANNEL_DATA:
A_WRITE(&closure->socket->write_buffer->super, data);
break;
case CHANNEL_STDERR_DATA:
werror("Ignoring unexpected stderr data.\n");
lsh_string_free(data);
break;
default:
fatal("Internal error. do_channel_forward_receive");
}
}
static void
do_channel_forward_send_adjust(struct ssh_channel *s,
UINT32 i UNUSED)
{
CAST(channel_forward, self, s);
self->socket->want_read = 1;
}
static void
do_channel_forward_eof(struct ssh_channel *s)
{
CAST(channel_forward, self, s);
if (shutdown (self->socket->fd, SHUT_WR) < 0)
werror("do_channel_forward_eof, shutdown failed, (errno = %i): %z\n",
errno, STRERROR(errno));
}
/* NOTE: Because this function is called by
* 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
channel_forward_start_io(struct ssh_channel *c)
{
CAST(channel_forward, channel, c);
channel->super.receive = do_channel_forward_receive;
channel->super.send_adjust = do_channel_forward_send_adjust;
channel->super.eof = do_channel_forward_eof;
/* Install callbacks on the local socket.
* NOTE: We don't install any channel_io_exception_handler. */
io_read_write(channel->socket,
make_channel_read_data(&channel->super),
/* FIXME: Make this configurable */
SSH_MAX_PACKET * 10, /* self->block_size, */
make_channel_read_close_callback(&channel->super));
/* Flow control */
channel->socket->write_buffer->report = &channel->super.super;
}
/* channel_forward.h
*
* General channel type for forwarding data to an fd
*
* $Id$ */
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998, 2001 Balzs Scheidler, Niels Mller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LSH_CHANNEL_FORWARD_H_INCLUDED
#define LSH_CHANNEL_FORWARD_H_INCLUDED
#include "channel.h"
#define GABA_DECLARE
#include "channel_forward.h.x"
#undef GABA_DECLARE
/* GABA:
(class
(name channel_forward)
(super ssh_channel)
(vars
(socket object lsh_fd)))
*/
struct ssh_channel *
make_channel_forward(struct lsh_fd *socket, UINT32 initial_window);
void
channel_forward_start_io(struct ssh_channel *c);
#endif /* LSH_CHANNEL_FORWARD_H_INCLUDED */
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "tcpforward.h" #include "tcpforward.h"
#include "channel_commands.h" #include "channel_commands.h"
#include "channel_forward.h"
#include "format.h" #include "format.h"
#include "io_commands.h" #include "io_commands.h"
#include "ssh.h" #include "ssh.h"
...@@ -102,108 +103,6 @@ remove_forward(struct object_queue *q, int null_ok, ...@@ -102,108 +103,6 @@ remove_forward(struct object_queue *q, int null_ok,
return NULL; return NULL;
} }
/* TCP forwarding channel */
/* GABA:
(class
(name tcpip_channel)
(super ssh_channel)
(vars
(socket object lsh_fd)))
*/
static void
do_tcpip_receive(struct ssh_channel *c,
int type, struct lsh_string *data)
{
CAST(tcpip_channel, closure, c);
switch (type)
{
case CHANNEL_DATA:
A_WRITE(&closure->socket->write_buffer->super, data);
break;
case CHANNEL_STDERR_DATA:
werror("Ignoring unexpected stderr data.\n");
lsh_string_free(data);
break;
default:
fatal("Internal error. do_tcpip_receive");
}
}
static void
do_tcpip_send_adjust(struct ssh_channel *s,
UINT32 i UNUSED)
{
CAST(tcpip_channel, self, s);
self->socket->want_read = 1;
}
static void
do_tcpip_eof(struct ssh_channel *s)
{
CAST(tcpip_channel, self, s);
if (shutdown (self->socket->fd, SHUT_WR) < 0)
werror("do_tcpip_eof, shutdown failed, (errno = %i): %z\n",
errno, STRERROR(errno));
}
/* NOTE: Adds the socket to the channel's resource list */
struct ssh_channel *
make_tcpip_channel(struct lsh_fd *socket, UINT32 initial_window)
{
NEW(tcpip_channel, self);
assert(socket);
init_channel(&self->super);
/* The rest of the callbacks are not set up until tcpip_start_io. */
/* NOTE: We don't need a close handler, as the channel's resource
* list is taken care of automatically. */
self->super.rec_window_size = initial_window;
/* FIXME: Make maximum packet size configurable. */
self->super.rec_max_packet = SSH_MAX_PACKET - SSH_CHANNEL_MAX_PACKET_FUZZ;
self->socket = socket;
REMEMBER_RESOURCE(self->super.resources, &socket->super);
return &self->super;
}
/* NOTE: Because this function is called by
* 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)
{
CAST(tcpip_channel, channel, c);
channel->super.receive = do_tcpip_receive;
channel->super.send_adjust = do_tcpip_send_adjust;
channel->super.eof = do_tcpip_eof;
/* Install callbacks on the local socket.
* NOTE: We don't install any channel_io_exception_handler. */
io_read_write(channel->socket,
make_channel_read_data(&channel->super),
/* FIXME: Make this configurable */
SSH_MAX_PACKET * 10, /* self->block_size, */
make_channel_read_close_callback(&channel->super));
/* Flow control */
channel->socket->write_buffer->report = &channel->super.super;
}
/* Handle channel open requests */ /* Handle channel open requests */
...@@ -255,7 +154,7 @@ do_open_forwarded_tcpip_continuation(struct command_continuation *s, ...@@ -255,7 +154,7 @@ do_open_forwarded_tcpip_continuation(struct command_continuation *s,
assert(channel); assert(channel);
tcpip_channel_start_io(channel); channel_forward_start_io(channel);
COMMAND_RETURN(self->up, channel); COMMAND_RETURN(self->up, channel);
} }
......
...@@ -72,12 +72,6 @@ struct remote_port * ...@@ -72,12 +72,6 @@ struct remote_port *
make_remote_port(struct address_info *listen, make_remote_port(struct address_info *listen,
struct command *callback); struct command *callback);
struct ssh_channel *
make_tcpip_channel(struct lsh_fd *socket, UINT32 initial_window);
void
tcpip_channel_start_io(struct ssh_channel *c);
struct channel_open * struct channel_open *
make_channel_open_direct_tcpip(struct command *callback); make_channel_open_direct_tcpip(struct command *callback);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "atoms.h" #include "atoms.h"
#include "channel_commands.h" #include "channel_commands.h"
#include "channel_forward.h"
#include "connection_commands.h" #include "connection_commands.h"
#include "format.h" #include "format.h"
#include "io_commands.h" #include "io_commands.h"
...@@ -79,7 +80,7 @@ static struct catch_report_collect catch_channel_open ...@@ -79,7 +80,7 @@ static struct catch_report_collect catch_channel_open
#define TCPIP_WINDOW_SIZE 10000 #define TCPIP_WINDOW_SIZE 10000
/* NOTE: make_tcpip_channel adds the fd to the channel's resource list. */ /* NOTE: make_channel_forward adds the fd to the channel's resource list. */
static void static void
do_tcpip_connect_io(struct command *ignored UNUSED, do_tcpip_connect_io(struct command *ignored UNUSED,
struct lsh_object *x, struct lsh_object *x,
...@@ -91,7 +92,7 @@ do_tcpip_connect_io(struct command *ignored UNUSED, ...@@ -91,7 +92,7 @@ do_tcpip_connect_io(struct command *ignored UNUSED,
assert(lv); assert(lv);
assert(lv->fd); assert(lv->fd);
COMMAND_RETURN(c, make_tcpip_channel(lv->fd, TCPIP_WINDOW_SIZE)); COMMAND_RETURN(c, make_channel_forward(lv->fd, TCPIP_WINDOW_SIZE));
} }
struct command tcpip_connect_io = STATIC_COMMAND(do_tcpip_connect_io); struct command tcpip_connect_io = STATIC_COMMAND(do_tcpip_connect_io);
...@@ -111,7 +112,7 @@ do_tcpip_start_io(struct command *s UNUSED, ...@@ -111,7 +112,7 @@ do_tcpip_start_io(struct command *s UNUSED,
assert(channel); assert(channel);
tcpip_channel_start_io(channel); channel_forward_start_io(channel);
COMMAND_RETURN(c, channel); COMMAND_RETURN(c, channel);
} }
...@@ -154,11 +155,11 @@ new_tcpip_channel(struct channel_open_command *c, ...@@ -154,11 +155,11 @@ new_tcpip_channel(struct channel_open_command *c,
/* NOTE: All accepted fd:s must end up in this function, so it /* NOTE: All accepted fd:s must end up in this function, so it
* should be ok to delay the REMEMBER call until here. It is done * should be ok to delay the REMEMBER call until here. It is done
* by make_tcpip_channel. */ * by make_channel_forward. */
debug("tcpforward_commands.c: new_tcpip_channel\n"); debug("tcpforward_commands.c: new_tcpip_channel\n");
channel = make_tcpip_channel(self->peer->fd, TCPIP_WINDOW_SIZE); channel = make_channel_forward(self->peer->fd, TCPIP_WINDOW_SIZE);
channel->write = connection->write; channel->write = connection->write;
*request = format_channel_open(self->type, local_channel_number, *request = format_channel_open(self->type, local_channel_number,
......
Markdown is supported
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