blob: 3da9e37aeb4017fe98e3e297d6f58f75ed3fe5a4 [file] [log] [blame]
Damien Millerb401f922010-02-10 10:17:49 +11001This document describes the multiplexing protocol used by ssh(1)'s
2ControlMaster connection-sharing.
3
4Most messages from the client to the server contain a "request id" field.
5This field is returned in replies as "client request id" to facilitate
6matching of responses to requests.
7
81. Connection setup
9
10When a multiplexing connection is made to a ssh(1) operating as a
11ControlMaster from a ssh(1) in multiplex slave mode, the first
12action of each is to exchange hello messages:
13
14 uint32 MUX_MSG_HELLO
15 uint32 protocol version
16 string extension name [optional]
17 string extension value [optional]
18 ...
19
20The current version of the mux protocol is 4. A slave should refuse
21to connect to a master that speaks an unsupported protocol version.
22Following the version identifier are zero or more extensions
23represented as a name/value pair. No extensions are currently
24defined.
25
262. Opening sessions
27
28To open a new multiplexed session, a client may send the following
29request:
30
Damien Miller42747df2011-01-14 12:01:50 +110031 uint32 MUX_C_NEW_SESSION
Damien Millerb401f922010-02-10 10:17:49 +110032 uint32 request id
33 string reserved
34 bool want tty flag
35 bool want X11 forwarding flag
36 bool want agent flag
37 bool subsystem flag
38 uint32 escape char
39 string terminal type
40 string command
41 string environment string 0 [optional]
42 ...
43
44To disable the use of an escape character, "escape char" may be set
45to 0xffffffff. "terminal type" is generally set to the value of
46$TERM. zero or more environment strings may follow the command.
47
48The client then sends its standard input, output and error file
49descriptors (in that order) using Unix domain socket control messages.
50
51The contents of "reserved" are currently ignored.
52
53If successful, the server will reply with MUX_S_SESSION_OPENED
54
55 uint32 MUX_S_SESSION_OPENED
56 uint32 client request id
57 uint32 session id
58
59Otherwise it will reply with an error: MUX_S_PERMISSION_DENIED or
60MUX_S_FAILURE.
61
62Once the server has received the fds, it will respond with MUX_S_OK
63indicating that the session is up. The client now waits for the
64session to end. When it does, the server will send an exit status
65message:
66
67 uint32 MUX_S_EXIT_MESSAGE
68 uint32 session id
69 uint32 exit value
70
71The client should exit with this value to mimic the behaviour of a
72non-multiplexed ssh(1) connection. Two additional cases that the
73client must cope with are it receiving a signal itself and the
74server disconnecting without sending an exit message.
75
763. Health checks
77
78The client may request a health check/PID report from a server:
79
80 uint32 MUX_C_ALIVE_CHECK
81 uint32 request id
82
83The server replies with:
84
85 uint32 MUX_S_ALIVE
86 uint32 client request id
87 uint32 server pid
88
894. Remotely terminating a master
90
91A client may request that a master terminate immediately:
92
93 uint32 MUX_C_TERMINATE
94 uint32 request id
95
96The server will reply with one of MUX_S_OK or MUX_S_PERMISSION_DENIED.
97
985. Requesting establishment of port forwards
99
100A client may request the master to establish a port forward:
101
Damien Miller42747df2011-01-14 12:01:50 +1100102 uint32 MUX_C_OPEN_FWD
Damien Millerb401f922010-02-10 10:17:49 +1100103 uint32 request id
104 uint32 forwarding type
105 string listen host
106 string listen port
107 string connect host
108 string connect port
109
110forwarding type may be MUX_FWD_LOCAL, MUX_FWD_REMOTE, MUX_FWD_DYNAMIC.
111
Damien Miller388f6fc2010-05-21 14:57:35 +1000112A server may reply with a MUX_S_OK, a MUX_S_REMOTE_PORT, a
113MUX_S_PERMISSION_DENIED or a MUX_S_FAILURE.
114
115For dynamically allocated listen port the server replies with
116
117 uint32 MUX_S_REMOTE_PORT
118 uint32 client request id
119 uint32 allocated remote listen port
Damien Millerb401f922010-02-10 10:17:49 +1100120
Damien Miller42747df2011-01-14 12:01:50 +11001216. Requesting closure of port forwards
122
123Note: currently unimplemented (server will always reply with MUX_S_FAILURE).
Damien Millerb401f922010-02-10 10:17:49 +1100124
Damien Millerb407dd82011-02-04 11:46:39 +1100125A client may request the master to close a port forward:
Damien Millerb401f922010-02-10 10:17:49 +1100126
Damien Miller42747df2011-01-14 12:01:50 +1100127 uint32 MUX_C_CLOSE_FWD
Damien Millerb401f922010-02-10 10:17:49 +1100128 uint32 request id
Damien Millerb401f922010-02-10 10:17:49 +1100129 string listen host
130 string listen port
131 string connect host
132 string connect port
133
Damien Millerb401f922010-02-10 10:17:49 +1100134A server may reply with a MUX_S_OK, a MUX_S_PERMISSION_DENIED or a
135MUX_S_FAILURE.
136
Damien Miller42747df2011-01-14 12:01:50 +11001377. Requesting stdio forwarding
Damien Millerb401f922010-02-10 10:17:49 +1100138
139A client may request the master to establish a stdio forwarding:
140
141 uint32 MUX_C_NEW_STDIO_FWD
142 uint32 request id
143 string reserved
144 string connect host
145 string connect port
146
147The client then sends its standard input and output file descriptors
148(in that order) using Unix domain socket control messages.
149
150The contents of "reserved" are currently ignored.
151
Damien Miller6c3eec72011-05-05 14:16:22 +1000152A server may reply with a MUX_S_SESSION_OPENED, a MUX_S_PERMISSION_DENIED
Damien Millerb401f922010-02-10 10:17:49 +1100153or a MUX_S_FAILURE.
154
Damien Miller6c3eec72011-05-05 14:16:22 +10001558. Requesting shutdown of mux listener
156
157A client may request the master to stop accepting new multiplexing requests
158and remove its listener socket.
159
160 uint32 MUX_C_STOP_LISTENING
161 uint32 request id
162
163A server may reply with a MUX_S_OK, a MUX_S_PERMISSION_DENIED or a
164MUX_S_FAILURE.
165
1669. Status messages
Damien Millerb401f922010-02-10 10:17:49 +1100167
168The MUX_S_OK message is empty:
169
170 uint32 MUX_S_OK
171 uint32 client request id
172
173The MUX_S_PERMISSION_DENIED and MUX_S_FAILURE include a reason:
174
175 uint32 MUX_S_PERMISSION_DENIED
176 uint32 client request id
177 string reason
178
179 uint32 MUX_S_FAILURE
180 uint32 client request id
181 string reason
182
Damien Millerc067f622011-05-15 08:46:54 +100018310. Protocol numbers
Damien Millerb401f922010-02-10 10:17:49 +1100184
185#define MUX_MSG_HELLO 0x00000001
186#define MUX_C_NEW_SESSION 0x10000002
187#define MUX_C_ALIVE_CHECK 0x10000004
188#define MUX_C_TERMINATE 0x10000005
Damien Miller42747df2011-01-14 12:01:50 +1100189#define MUX_C_OPEN_FWD 0x10000006
190#define MUX_C_CLOSE_FWD 0x10000007
191#define MUX_C_NEW_STDIO_FWD 0x10000008
Damien Miller6c3eec72011-05-05 14:16:22 +1000192#define MUX_C_STOP_LISTENING 0x10000009
Damien Millerb401f922010-02-10 10:17:49 +1100193#define MUX_S_OK 0x80000001
194#define MUX_S_PERMISSION_DENIED 0x80000002
195#define MUX_S_FAILURE 0x80000003
196#define MUX_S_EXIT_MESSAGE 0x80000004
197#define MUX_S_ALIVE 0x80000005
198#define MUX_S_SESSION_OPENED 0x80000006
Damien Miller388f6fc2010-05-21 14:57:35 +1000199#define MUX_S_REMOTE_PORT 0x80000007
Damien Millerb401f922010-02-10 10:17:49 +1100200
201#define MUX_FWD_LOCAL 1
202#define MUX_FWD_REMOTE 2
203#define MUX_FWD_DYNAMIC 3
204
205XXX TODO
206XXX extended status (e.g. report open channels / forwards)
Damien Millerb401f922010-02-10 10:17:49 +1100207XXX lock (maybe)
208XXX watch in/out traffic (pre/post crypto)
209XXX inject packet (what about replies)
210XXX server->client error/warning notifications
211XXX port0 rfwd (need custom response message)
212XXX send signals via mux
213
Damien Millerc067f622011-05-15 08:46:54 +1000214$OpenBSD: PROTOCOL.mux,v 1.6 2011/05/06 22:20:10 djm Exp $