[PATCH/RFC 6/6] [mux.c] new request to list open forwardings

Bert Wesarg bert.wesarg at googlemail.com
Thu May 3 21:33:52 EST 2012


---
 PROTOCOL.mux |   36 +++++++++++++++++++++++++++++++++---
 mux.c        |   31 +++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/PROTOCOL.mux b/PROTOCOL.mux
index 49cbe5b..26b5f8d 100644
--- a/PROTOCOL.mux
+++ b/PROTOCOL.mux
@@ -171,13 +171,41 @@ and remove its listener socket.
 A server may reply with a MUX_S_OK, a MUX_S_PERMISSION_DENIED or a
 MUX_S_FAILURE.
 
-9. Status messages
+9. Request a list of open forwardings from the mux listener
+
+A client may request the master to send the list of open port forwardings.
+
+	uint32	MUX_C_LIST_FWDS
+	uint32	request id
+
+The server will reply with a MUX_S_RESULT and the following payload:
+
+	uint32	MUX_S_RESULT
+	uint32	client request id
+	[ uint32	forwarding id
+	  uint32	forwarding type
+	  string	listen host
+	  uint32	listen port
+	  string	connect host
+	  uint32	connect port
+	  uint32	allocated port [if appropriate] ]...
+
+The allocated port entry is only there for remote forwardings with a listen port
+equal zero.
+
+10. Status messages
 
 The MUX_S_OK message is empty:
 
 	uint32	MUX_S_OK
 	uint32	client request id
 
+The MUX_S_RESULT message has a payload depending on the client request:
+
+	uint32	MUX_S_RESULT
+	uint32	client request id
+	[payload]
+
 The MUX_S_PERMISSION_DENIED and MUX_S_FAILURE include a reason:
 
 	uint32	MUX_S_PERMISSION_DENIED
@@ -188,7 +216,7 @@ The MUX_S_PERMISSION_DENIED and MUX_S_FAILURE include a reason:
 	uint32	client request id
 	string	reason
 
-10. Protocol numbers
+11. Protocol numbers
 
 #define MUX_MSG_HELLO		0x00000001
 #define MUX_C_NEW_SESSION	0x10000002
@@ -198,6 +226,7 @@ The MUX_S_PERMISSION_DENIED and MUX_S_FAILURE include a reason:
 #define MUX_C_CLOSE_FWD		0x10000007
 #define MUX_C_NEW_STDIO_FWD	0x10000008
 #define MUX_C_STOP_LISTENING	0x10000009
+#define MUX_C_LIST_FWDS		0x1000000a
 #define MUX_S_OK		0x80000001
 #define MUX_S_PERMISSION_DENIED	0x80000002
 #define MUX_S_FAILURE		0x80000003
@@ -206,13 +235,14 @@ The MUX_S_PERMISSION_DENIED and MUX_S_FAILURE include a reason:
 #define MUX_S_SESSION_OPENED	0x80000006
 #define MUX_S_REMOTE_PORT	0x80000007
 #define MUX_S_TTY_ALLOC_FAIL	0x80000008
+#define MUX_S_RESULT		0x80000009
 
 #define MUX_FWD_LOCAL	1
 #define MUX_FWD_REMOTE	2
 #define MUX_FWD_DYNAMIC	3
 
 XXX TODO
-XXX extended status (e.g. report open channels / forwards)
+XXX extended status (e.g. report open channels)
 XXX lock (maybe)
 XXX watch in/out traffic (pre/post crypto)
 XXX inject packet (what about replies)
diff --git a/mux.c b/mux.c
index c59bb97..d975007 100644
--- a/mux.c
+++ b/mux.c
@@ -146,6 +146,7 @@ struct mux_master_state {
 #define MUX_C_CLOSE_FWD		0x10000007
 #define MUX_C_NEW_STDIO_FWD	0x10000008
 #define MUX_C_STOP_LISTENING	0x10000009
+#define MUX_C_LIST_FWDS		0x1000000a
 #define MUX_S_OK		0x80000001
 #define MUX_S_PERMISSION_DENIED	0x80000002
 #define MUX_S_FAILURE		0x80000003
@@ -154,6 +155,7 @@ struct mux_master_state {
 #define MUX_S_SESSION_OPENED	0x80000006
 #define MUX_S_REMOTE_PORT	0x80000007
 #define MUX_S_TTY_ALLOC_FAIL	0x80000008
+#define MUX_S_RESULT		0x80000009
 
 /* type codes for MUX_C_OPEN_FWD and MUX_C_CLOSE_FWD */
 #define MUX_FWD_LOCAL   SSH_FWD_LOCAL
@@ -170,6 +172,7 @@ static int process_mux_open_fwd(u_int, Channel *, Buffer *, Buffer *);
 static int process_mux_close_fwd(u_int, Channel *, Buffer *, Buffer *);
 static int process_mux_stdio_fwd(u_int, Channel *, Buffer *, Buffer *);
 static int process_mux_stop_listening(u_int, Channel *, Buffer *, Buffer *);
+static int process_mux_list_fwds(u_int, Channel *, Buffer *, Buffer *);
 
 static const struct {
 	u_int type;
@@ -183,6 +186,7 @@ static const struct {
 	{ MUX_C_CLOSE_FWD, process_mux_close_fwd },
 	{ MUX_C_NEW_STDIO_FWD, process_mux_stdio_fwd },
 	{ MUX_C_STOP_LISTENING, process_mux_stop_listening },
+	{ MUX_C_LIST_FWDS, process_mux_list_fwds },
 	{ 0, NULL }
 };
 
@@ -982,6 +986,33 @@ process_mux_stop_listening(u_int rid, Channel *c, Buffer *m, Buffer *r)
 	return 0;
 }
 
+static int
+process_mux_list_fwds(u_int rid, Channel *c, Buffer *m, Buffer *r)
+{
+	int i;
+
+	debug("%s: channel %d: list forwardings", __func__, c->self);
+
+	/* prepare reply */
+	buffer_put_int(r, MUX_S_RESULT);
+	buffer_put_int(r, rid);
+
+	for (i = 0; i < options.num_forwards; i++) {
+		Forward *fwd = &options.forwards[i];
+		buffer_put_int(r, fwd->id);
+		buffer_put_int(r, fwd->type);
+		buffer_put_cstring(r, fwd->listen_host ? fwd->listen_host : "");
+		buffer_put_int(r, fwd->listen_port);
+		buffer_put_cstring(r, fwd->connect_host ? fwd->connect_host : "");
+		buffer_put_int(r, fwd->connect_port);
+		if (fwd->type == MUX_FWD_REMOTE && fwd->listen_port == 0) {
+			buffer_put_int(r, fwd->allocated_port);
+		}
+	}
+
+	return 0;
+}
+
 /* Channel callbacks fired on read/write from mux slave fd */
 static int
 mux_master_read_cb(Channel *c)
-- 
1.7.9.rc0.542.g07ca1



More information about the openssh-unix-dev mailing list