ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
connection.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file connection.h
6 * @brief RFC 4254 connection protocol: channel multiplexing, windows, and port forwarding.
7 */
8
9#ifndef PROTOCORE_CONNECTION_CONNECTION_H
10#define PROTOCORE_CONNECTION_CONNECTION_H
11
13
14EMBED_BEGIN_DECLS
15
16// ---------------------------------------------------------------------------
17// RFC 4254 sec 5.2 - the window pair
18// ---------------------------------------------------------------------------
19
20/** @brief One channel's flow-control state (RFC 4254 sec 5.2). */
21typedef struct
22{
23 uint32_t local_window; ///< Bytes the peer may still send us before we WINDOW_ADJUST.
24 uint32_t local_max; ///< The window we advertised, and replenish back up to.
25 uint32_t peer_window; ///< Bytes we may still send the peer.
26 uint32_t peer_max_pkt; ///< Peer's maximum packet size; caps a single send independently of the window.
27} SshFlow;
28
29/**
30 * @brief Start a channel's windows: ours at @p local_window, the peer's at what it advertised.
31 *
32 * The local window is a parameter rather than a baked-in constant because the server and the
33 * client advertise different sizes, and the value we replenish to must be the value we told the
34 * peer about. Passing it here keeps the two from drifting apart.
35 *
36 * @param local_window what we advertise in CHANNEL_OPEN / CONFIRMATION; also the replenish target.
37 * @param peer_window the peer's initial window from CHANNEL_OPEN / CONFIRMATION.
38 * @param peer_max_pkt the peer's maximum packet size from the same message.
39 */
40
41/**
42 * @brief Account @p n inbound bytes against our window.
43 *
44 * @return false if @p n exceeds what we advertised - the peer overran the window (RFC 4254 sec 5.2)
45 * and the caller must fail the channel. The window is left untouched on failure.
46 */
47
48/**
49 * @brief Decide whether a WINDOW_ADJUST is due, and for how much. Does not mutate.
50 *
51 * Replenishes once the window has drained past half, which keeps a bulk transfer from stalling
52 * without emitting an adjust per packet.
53 *
54 * Pair it with protocore_ssh_flow_local_credit() only after the adjust has actually gone out. Deciding and
55 * crediting are separate because on some paths the send can fail, and crediting first would leave us
56 * believing we advertised bytes the peer never heard about - the peer then stops at its smaller
57 * window while we wait for data, and the transfer deadlocks.
58 *
59 * @return true if a WINDOW_ADJUST is due; @p *add receives the delta to advertise.
60 */
61
62/** @brief Credit our window by @p add, once that WINDOW_ADJUST has actually been sent. */
63
64/** @brief True if @p len bytes fit both the peer's remaining window and its maximum packet size. */
65
66/**
67 * @brief Clamp a would-be send to what the peer currently permits.
68 *
69 * A producer that pulls from a local source sizes its read to this, so it never reads bytes it
70 * cannot legally forward. Returns 0 when the window is closed, which the caller treats as
71 * "stop pumping until a WINDOW_ADJUST arrives".
72 *
73 * @return min(@p want, peer window, peer maximum packet size).
74 */
75
76/** @brief Account @p n outbound bytes against the peer's window (call only after send_allows()). */
77
78/**
79 * @brief Credit the peer's window from an inbound WINDOW_ADJUST.
80 *
81 * Saturates at UINT32_MAX rather than wrapping: a peer advertising a total past 2^32 is out of spec,
82 * and wrapping would hand us a tiny window and stall the transfer.
83 */
84
85// ---------------------------------------------------------------------------
86// Channel signaling (RFC 4254 sec 5)
87//
88// Every channel-related message is a transition on the window state above: OPEN / OPEN_CONFIRMATION
89// establish it (they carry the initial window and maximum packet size), WINDOW_ADJUST increments it,
90// DATA consumes it, EOF / CLOSE terminate it. Because the transitions and the state are the same
91// concern, they live together - the RFC's rule that no data may be sent until the window allows it is
92// only enforceable where the window is.
93//
94// These take the flow plus the ids the wire carries, never a channel struct: resolving a recipient
95// channel number to a channel is multiplexing, and that stays in ssh_channel.
96// ---------------------------------------------------------------------------
97
98// The connection protocol's message numbers (RFC 4250 §4.1.1: 80 to 89 generic, 90 to 127 channel
99// related). They sit with the builders below, which are what write them onto the wire.
100
101/** @brief CHANNEL_OPEN_FAILURE. @p reason: 1 admin-prohibited, 2 connect-failed, 3 unknown-type, 4 resource. */
102int32_t protocore_ssh_sig_build_open_failure(uint8_t *out, size_t cap, uint32_t peer_id, uint32_t reason,
103 size_t *out_len);
104
105/** @brief CHANNEL_OPEN_CONFIRMATION, advertising our current window and maximum packet size. */
106int32_t protocore_ssh_sig_build_open_confirm(const SshFlow *f, uint32_t peer_id, uint32_t local_id, uint8_t *out,
107 size_t cap, size_t *out_len);
108
109/**
110 * @brief CHANNEL_DATA carrying @p len bytes, and account them against the peer's window.
111 *
112 * Refuses when the send would exceed the peer's window or its maximum packet size, so the RFC 4254
113 * sec 5.2 limit cannot be violated by any caller - the check and the debit are one step here.
114 */
115int32_t protocore_ssh_sig_build_data(SshFlow *f, uint32_t peer_id, const uint8_t *data, size_t len, uint8_t *out,
116 size_t cap, size_t *out_len);
117
118/** @brief CHANNEL_WINDOW_ADJUST granting @p add more bytes. Credit the window only once this is sent. */
119int32_t protocore_ssh_sig_build_window_adjust(uint32_t peer_id, uint32_t add, uint8_t *out, size_t cap,
120 size_t *out_len);
121
122/** @brief CHANNEL_EOF, as one 5-byte message. */
123int32_t protocore_ssh_sig_build_eof(uint32_t peer_id, uint8_t *out, size_t cap, size_t *out_len);
124
125/** @brief CHANNEL_CLOSE, as one 5-byte message. */
126int32_t protocore_ssh_sig_build_close(uint32_t peer_id, uint8_t *out, size_t cap, size_t *out_len);
127
128// ---------------------------------------------------------------------------
129// RFC 4254 sec 5 - channel multiplexing
130// ---------------------------------------------------------------------------
131
132/** @brief Channel type (RFC 4254). */
133EMBED_ENUM_BYTE(SshChanType,
134 SSH_CHAN_SESSION = 0, ///< "session" - shell / exec / data
135 SSH_CHAN_DIRECT_TCPIP = 1, ///< "direct-tcpip" - client-initiated TCP forward (ssh -L)
136 SSH_CHAN_FORWARDED_TCPIP = 2 ///< "forwarded-tcpip" - server-initiated TCP forward (ssh -R)
137);
138
139/**
140 * @brief What a session channel's sec 6 request bound to it, if anything.
141 *
142 * These are not channel types: sec 5.1 names the type on the wire, and a file-transfer service is
143 * a sec 6.5 "subsystem" or `exec` request arriving later on a channel already open as "session".
144 * The type says how the channel was opened; this says what its data means.
145 */
146EMBED_ENUM_BYTE(SshChanService,
147 SSH_CHAN_SERVICE_NONE = 0, ///< shell / exec output, handed to the channel-data callback
148 SSH_CHAN_SERVICE_SFTP = 1, ///< subsystem "sftp" (PROTOCORE_ENABLE_SSH_SFTP)
149 SSH_CHAN_SERVICE_SCP = 2 ///< exec "scp ..." (PROTOCORE_ENABLE_SSH_SCP)
150);
151
152/** @brief Per-connection channel state. */
153typedef struct
154{
155 embed_bool open; ///< True once the channel is confirmed open both ways.
156 embed_bool pending; ///< True for a server-initiated channel we opened, awaiting the client's confirmation.
157 SshChanType type; ///< session, direct-tcpip, or forwarded-tcpip.
158 SshChanService service; ///< What a sec 6 request bound over a session channel, if anything.
159 uint32_t local_id; ///< Our channel id (== slot index).
160 uint32_t peer_id; ///< Client's channel id.
161 SshFlow flow; ///< RFC 4254 sec 5.2 window pair (owner: ssh_flow_control.*).
162 embed_bool eof_sent; ///< We sent CHANNEL_EOF (RFC 4254 sec 5.3).
163 embed_bool relay_eof; ///< The peer sent CHANNEL_EOF.
164 // sec 5.3: "The channel is considered closed for a party when it has both sent and received
165 // SSH_MSG_CHANNEL_CLOSE, and the party may then reuse the channel number." One latch each, so
166 // the number is not handed out again while the peer's CLOSE is still in flight.
167 embed_bool close_sent; ///< We sent CHANNEL_CLOSE.
168 embed_bool close_received; ///< The peer sent CHANNEL_CLOSE.
169 // sec 6.2: a terminal allocated for this session, and the dimensions sec 6.7 updates. The
170 // dimensions are "only informational", so they are carried, not acted on, by this layer.
171 embed_bool pty; ///< A "pty-req" was accepted on this channel.
172 uint32_t width_chars; ///< terminal width, characters
173 uint32_t height_rows; ///< terminal height, rows
174 uint32_t width_px; ///< terminal width, pixels
175 uint32_t height_px; ///< terminal height, pixels
176} SshChannel;
177
178/** @brief Channel pool: PROTOCORE_SSH_MAX_CHANNELS channels per SSH connection (BSS).
179 * Owned by this layer; src/ code routes through the functions below, never the
180 * array (tests inspect it white-box). Index: [connection slot][channel slot]. */
182
183/** @brief Application callback for inbound channel data (raw bytes), tagged with
184 * the channel id it arrived on. */
185typedef void (*SshChannelDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len);
186/** @brief Install the inbound-data callback (session channels). */
187
188/**
189 * @brief "direct-tcpip" forward request: a client asked the server to open a TCP
190 * connection to @p host : @p port (ssh -L). The forwarding owner (which
191 * does the actual TCP I/O - this codec does not) decides whether to allow
192 * it; @p host is not NUL-terminated (@p host_len bytes).
193 * @return 0 to accept (the channel is opened and confirmed), < 0 to refuse
194 * (CHANNEL_OPEN_FAILURE, administratively prohibited / connect failed).
195 *
196 * If no callback is installed, all forward requests are refused - so forwarding is
197 * opt-in (no open relay by default).
198 */
199typedef int (*SshForwardOpenCb)(uint8_t slot, uint32_t channel, const char *host, size_t host_len, uint16_t port);
200/** @brief Inbound data on a direct-tcpip channel (the owner writes it to the
201 * forwarded TCP socket). Kept separate from the session data callback. */
202typedef void (*SshForwardDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len);
203/** @brief Install the direct-tcpip forward open-policy callback (opt-in). */
204
205/** @brief Install the direct-tcpip forward inbound-data callback. */
206
207/**
208 * @brief "tcpip-forward" remote-forward request (ssh -R): the client asks the server
209 * to listen on @p bind_addr : @p bind_port and open a channel back for each
210 * accepted connection (RFC 4254 §7.1). @p bind_addr is @p addr_len bytes (not
211 * NUL-terminated). The forwarding owner (which allocates the real listener -
212 * this codec does no I/O) decides.
213 * @return the bound port on success (echo @p bind_port, or the port the owner picked
214 * when @p bind_port == 0), or < 0 to refuse. If no callback is installed every
215 * request is refused, so remote forwarding is opt-in (no listener is opened).
216 */
217typedef int (*SshRemoteForwardOpenCb)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port);
218/** @brief "cancel-tcpip-forward" request (RFC 4254 §7.1): drop a remote forward.
219 * @return 0 if a matching forward was cancelled, < 0 if none / unsupported. */
220typedef int (*SshRemoteForwardCancelCb)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port);
221/** @brief Install the remote-forward (ssh -R) open-policy callback (opt-in). */
222
223/** @brief Install the remote-forward (ssh -R) cancel callback (opt-in). */
224
225/**
226 * @brief Result of the client's reply to a server-initiated forwarded-tcpip channel:
227 * @p ok = true on CHANNEL_OPEN_CONFIRMATION (the bridge may start), false on
228 * CHANNEL_OPEN_FAILURE (the owner tears the bridge down). @p channel is the
229 * local id returned by protocore_ssh_channel_open_forwarded().
230 */
231typedef void (*SshForwardConfirmCb)(uint8_t slot, uint32_t channel, embed_bool ok);
232/** @brief Install the forwarded-tcpip open-confirmation callback (opt-in, ssh -R). */
233
234/** @brief A `subsystem "sftp"` request was accepted on @p channel; the binding starts an SFTP session. */
235typedef void (*SshSftpOpenCb)(uint8_t slot, uint32_t channel);
236/** @brief Inbound bytes on an SFTP channel (the raw SSH_FXP_* stream) - kept out of the session data cb. */
237typedef void (*SshSftpDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len);
238
239#if PROTOCORE_ENABLE_SSH_SFTP
240/** @brief The registered sftp-open callback, or null; fired when sec 6.5 names the subsystem. */
241SshSftpOpenCb protocore_ssh_channel_sftp_open_cb(void);
242#endif
243
244/** @brief An `exec "scp …"` request was accepted on @p channel (@p cmd is @p cmd_len bytes, not NUL-terminated). */
245typedef void (*SshScpOpenCb)(uint8_t slot, uint32_t channel, const char *cmd, size_t cmd_len);
246/** @brief Inbound bytes on an SCP channel (the RCP protocol stream). */
247typedef void (*SshScpDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len);
248
249#if PROTOCORE_ENABLE_SSH_SCP
250/** @brief The registered scp-open callback, or null; fired when sec 6.5 names an scp command. */
251SshScpOpenCb protocore_ssh_channel_scp_open_cb(void);
252#endif
253
254/**
255 * @brief Open a server-initiated "forwarded-tcpip" channel (RFC 4254 §7.2, ssh -R).
256 *
257 * Allocates a local channel on connection @p i (state = pending, awaiting the
258 * client's confirmation) and builds the SSH_MSG_CHANNEL_OPEN in @p out.
259 * @p conn_addr / @p conn_port are the forward's bound address/port (the "address
260 * that was connected"); @p orig_addr / @p orig_port are the peer that connected.
261 *
262 * @return the local channel id (>= 0) on success, or -1 (pool full, or @p out too
263 * small). On success the caller emits @p out and, on the eventual confirm,
264 * bridges bytes on the returned channel.
265 */
266
267/**
268 * @brief Handle SSH_MSG_CHANNEL_OPEN_CONFIRMATION for a channel we opened (ssh -R).
269 *
270 * Matches the pending channel by our recipient id, records the peer's channel id /
271 * window / max-packet, and marks it open. Fires the confirm callback (@p ok = true).
272 * @return 0 on success, -1 if malformed or no matching pending channel.
273 */
274
275/**
276 * @brief Handle SSH_MSG_CHANNEL_OPEN_FAILURE for a channel we opened (ssh -R).
277 *
278 * Frees the pending channel and fires the confirm callback (@p ok = false).
279 * @return 0 on success, -1 if malformed or no matching pending channel.
280 */
281
282/**
283 * @brief Handle SSH_MSG_GLOBAL_REQUEST (RFC 4254 §4).
284 *
285 * Parses the request name and want_reply flag. "tcpip-forward" /
286 * "cancel-tcpip-forward" are routed to the remote-forward seam above (accepted only
287 * when a callback is installed); a "tcpip-forward" that bound port 0 gets its
288 * allocated port echoed in the reply (RFC 4254 §7.1). Any other request name is
289 * unrecognized: per §4 it is answered with SSH_MSG_REQUEST_FAILURE when want_reply is
290 * set, and silently ignored otherwise (never SSH_MSG_UNIMPLEMENTED - GLOBAL_REQUEST is
291 * a known message type; only the request name is unknown).
292 *
293 * @return 0 on success (a reply is in @p out with *@p out_len bytes, or *@p out_len is
294 * 0 when no reply is due), -1 if the message is malformed.
295 */
296
297/**
298 * @brief Bind a sec 6.5 file-transfer service to an open channel.
299 *
300 * The channel was opened as "session" (sec 5.1); the request that names the service arrives later,
301 * and this records which one so inbound CHANNEL_DATA routes to its binding rather than to the
302 * channel-data callback. This layer owns the channel record, so the request handler above it asks
303 * rather than writes.
304 *
305 * @return 0 on success, -1 when the channel is closed or unknown.
306 */
307
308/** @brief Reset channel state for slot @p i. */
309
310/** @brief The open channel @p id on connection @p i, or null. Local id == slot index. */
311
312/**
313 * @brief First free channel slot on connection @p i, or -1 if the pool is full. A pending
314 * (opened-but-unconfirmed) channel is in use just like an open one.
315 */
316
317/**
318 * @brief Handle SSH_MSG_CHANNEL_OPEN and emit CHANNEL_OPEN_CONFIRMATION.
319 *
320 * Accepts a "session" channel; any other type yields CHANNEL_OPEN_FAILURE.
321 * @return 0 if a response was produced, -1 if malformed.
322 */
323
324// RFC 4250 sec 4.9.3 lists pty-req, env, shell, exec and subsystem under "Connection Protocol
325// Channel Request Names", so what each carries after want_reply is this layer's to check. Both
326// answer one question: are the fields the section names present and whole.
327
328/** @brief Read @p n consecutive strings from @p off: true when every one is present and whole. */
329
330/** @brief RFC 4254 sec 6.2: string TERM, four uint32 dimensions, string encoded terminal modes. */
331
332// ---------------------------------------------------------------------------
333// RFC 4254 sec 6.2 / sec 6.7 / sec 8 - the pseudo-terminal a session channel carries
334// ---------------------------------------------------------------------------
335
336/**
337 * @brief The terminal a "pty-req" asked for, as sec 6.2 orders its fields.
338 *
339 * "Zero dimension parameters MUST be ignored. The character/row dimensions override the pixel
340 * dimensions (when nonzero)." Both pairs are kept as they arrived; a consumer applies that rule.
341 */
342typedef struct
343{
344 char term[PROTOCORE_SSH_PTY_TERM_MAX]; ///< TERM value, null-terminated, truncated to fit.
345 uint32_t width_chars; ///< terminal width, characters
346 uint32_t height_rows; ///< terminal height, rows
347 uint32_t width_px; ///< terminal width, pixels
348 uint32_t height_px; ///< terminal height, pixels
349 const uint8_t *modes; ///< encoded terminal modes, pointing into the request
350 uint32_t modes_len; ///< length of modes
352
353/**
354 * @brief Walk an encoded terminal-mode stream (RFC 4254 sec 8) and report whether it is well formed.
355 *
356 * "Opcodes 1 to 159 have a single uint32 argument. Opcodes 160 to 255 are not yet defined, and cause
357 * parsing to stop... The stream is terminated by opcode TTY_OP_END (0x00)." Only a truncated
358 * argument makes a stream malformed. A stream that runs out before its terminator is accepted for
359 * what it did carry, and an empty one is well formed: it sets no modes.
360 *
361 * @param modes Encoded stream.
362 * @param len Bytes in @p modes.
363 * @param consumed Set to the bytes parsed before TTY_OP_END or an undefined opcode. May be null.
364 */
365
366/**
367 * @brief Parse a "pty-req" body (sec 6.2) starting at @p off.
368 * @return true when every field is present and whole and the mode stream parses.
369 */
370
371/**
372 * @brief Parse a "window-change" body (sec 6.7): four uint32 dimensions, no reply.
373 * @return true when all four are present.
374 */
375
376/** @brief An accepted "pty-req" on channel @p channel. Return false to refuse the terminal. */
377typedef embed_bool (*SshPtyReqCb)(uint8_t i, uint32_t channel, const SshPtyRequest *pty);
378
379/** @brief A "window-change" (sec 6.7) on a channel that already has a terminal. */
380typedef void (*SshWindowChangeCb)(uint8_t i, uint32_t channel, uint32_t width_chars, uint32_t height_rows,
381 uint32_t width_px, uint32_t height_px);
382
383/** @brief Install the sec 6.2 handler. Without one a "pty-req" is refused: no terminal exists. */
384
385/** @brief Install the sec 6.7 handler. */
386
387/** @brief The terminal dimensions channel @p channel carries, or false when it has no pty. */
388
389// ---------------------------------------------------------------------------
390// RFC 4254 sec 6.10 - returning exit status
391// ---------------------------------------------------------------------------
392
393/**
394 * @brief Send "exit-status" for a command that terminated (RFC 4254 sec 6.10).
395 *
396 * "When the command running at the other end terminates, the following message can be sent to
397 * return the exit status of the command. Returning the status is RECOMMENDED. No acknowledgement is
398 * sent for this message. The channel needs to be closed with SSH_MSG_CHANNEL_CLOSE after this
399 * message." want_reply is FALSE, as the section fixes it.
400 *
401 * @return 0 on success, -1 when the channel is closed or the stream is gone.
402 */
403
404/**
405 * @brief Send "exit-signal" for a command killed by a signal (RFC 4254 sec 6.10).
406 *
407 * @param signal_name Signal name without the "SIG" prefix, as sec 6.10 lists them.
408 * @param core_dumped Whether the command dumped core.
409 * @param err_msg Error message in UTF-8; may be null for an empty one.
410 * @return 0 on success, -1 when the channel is closed, the stream is gone, or the names do not fit.
411 */
412
413#if PROTOCORE_ENABLE_SSH_SFTP || PROTOCORE_ENABLE_SSH_SCP
414/**
415 * @brief Tag @p c and fire the open callback when a sec 6.5 request names a file-transfer service.
416 *
417 * Declared here and implemented above, in the layer that owns those services. RFC 4251 sec 1 puts
418 * the connection protocol beneath them, so this layer reaches up through a hook it declares rather
419 * than including a header from the layer above. @p off points at the request-specific argument and
420 * may be advanced; *@p accept is raised for a subsystem the base set does not already admit.
421 */
422#endif
423
424/**
425 * @brief Handle SSH_MSG_CHANNEL_REQUEST.
426 *
427 * "shell", "exec", "pty-req", and "env" are accepted; anything else is refused - except that when
428 * PROTOCORE_ENABLE_SSH_SFTP is set a `subsystem "sftp"` is accepted (the channel binds SSH_CHAN_SERVICE_SFTP and the
429 * sftp-open callback fires), and when PROTOCORE_ENABLE_SSH_SCP is set an `exec "scp …"` is additionally tagged
430 * SSH_CHAN_SERVICE_SCP (the scp-open callback fires with the command). When want_reply is set, CHANNEL_SUCCESS /
431 * CHANNEL_FAILURE is written to @p out and *@p out_len > 0; otherwise *@p out_len is 0.
432 * @return 0 on success, -1 if malformed.
433 */
434
435/**
436 * @brief Handle SSH_MSG_CHANNEL_DATA: bounds-check, update the window, and
437 * invoke the data callback. If the local window is exhausted a
438 * CHANNEL_WINDOW_ADJUST is written to @p out (*@p out_len > 0).
439 * @return 0 on success, -1 if malformed or channel not open.
440 */
441
442/**
443 * @brief Handle SSH_MSG_CHANNEL_EXTENDED_DATA (RFC 4254 §5.2): bounds-check, update
444 * the window, and discard the payload. The data_type_code selects a stream
445 * this end does not surface, so the bytes are accounted for and dropped. If
446 * the local window is exhausted a CHANNEL_WINDOW_ADJUST is written to @p out
447 * (*@p out_len > 0).
448 * @return 0 on success, -1 if malformed or channel not open.
449 */
450
451/**
452 * @brief Build an SSH_MSG_CHANNEL_DATA message carrying @p data to the client on
453 * channel @p channel (a local channel id from a prior open).
454 * @return 0 on success, -1 if the channel is closed/unknown, the peer window is
455 * too small, or @p out is too small.
456 */
457
458/**
459 * @brief Handle SSH_MSG_CHANNEL_WINDOW_ADJUST (grows the peer window).
460 * @return 0 on success, -1 if malformed.
461 */
462
463/**
464 * @brief Build SSH_MSG_CHANNEL_EOF for channel @p channel and latch that we sent it.
465 * The channel stays open (RFC 4254 sec 5.3).
466 * @return 0 on success, -1 if the channel is closed/unknown or @p out is too small.
467 */
468
469/**
470 * @brief Build SSH_MSG_CHANNEL_CLOSE for channel @p channel and mark it closed.
471 * @return 0 on success, -1 if the channel is closed/unknown or @p out is too small.
472 */
473
474/** @brief Bytes in SSH_MSG_CHANNEL_EOF: the message number and the recipient channel. */
475#define SSH_CHANNEL_EOF_LEN 5u
476
477/** @brief Bytes in SSH_MSG_CHANNEL_CLOSE: the message number and the recipient channel. */
478#define SSH_CHANNEL_CLOSE_LEN 5u
479
480/**
481 * @brief Build SSH_MSG_CHANNEL_DATA for @p channel and put it on the slot's stream (sec 5.2).
482 * @return the bytes accepted from @p data, -1 when the stream is gone or the build failed.
483 */
484
485/**
486 * @brief Build SSH_MSG_CHANNEL_EOF for @p channel and put it on the slot's stream (sec 5.3).
487 * @return 0 on success, -1 otherwise.
488 */
489
490/**
491 * @brief Build SSH_MSG_CHANNEL_CLOSE for @p channel and put it on the slot's stream (sec 5.3).
492 * @return 0 on success, -1 otherwise.
493 */
494
495/**
496 * @brief Open a "forwarded-tcpip" channel to the peer and put it on the slot's stream (sec 7.2).
497 * @return the local channel number on success, -1 when the pool is full or the stream is gone.
498 */
499
500/**
501 * @brief Handle an inbound SSH_MSG_CHANNEL_EOF: mark the peer done sending on the
502 * recipient channel. Sends nothing and leaves the channel open, so the other
503 * direction keeps carrying data (RFC 4254 sec 5.3).
504 * @return 0 on success, -1 if malformed or the channel is unknown.
505 */
506
507/**
508 * @brief Handle an inbound SSH_MSG_CHANNEL_CLOSE: route to the recipient channel,
509 * reply with EOF + CLOSE, and mark it closed.
510 * @return 0 if a response was produced, -1 if malformed or the channel is unknown.
511 */
512
513// ---------------------------------------------------------------------------
514// RFC 4254 sec 7 - TCP/IP port forwarding
515// ---------------------------------------------------------------------------
516
517/**
518 * @brief Allow/deny policy for a forward target. Return true to permit the connect.
519 *
520 * @p host is NUL-terminated. If no policy is installed every post-authentication
521 * forward is permitted (an open proxy for authenticated users) - install one to
522 * the reachable host:port set.
523 */
524typedef embed_bool (*SshForwardPolicyCb)(const char *host, uint16_t port);
525
526#if PROTOCORE_SSH_PORT_FORWARD
527
528/** @brief Install the forward-target policy (optional; default permits all). */
529
530/**
531 * @brief Enable direct-tcpip forwarding: install the channel forward callbacks.
532 *
533 * Call once after protocore_ssh_conn_setup(). Until then (or if PROTOCORE_SSH_PORT_FORWARD is 0)
534 * the channel codec refuses every direct-tcpip open, so there is no open relay.
535 */
536
537/**
538 * @brief Pump every forward on SSH connection @p ssh_slot: move buffered target
539 * bytes to the client (bounded by the channel's peer window) and propagate
540 * a close from either side. Called from the SSH connection poll each loop.
541 */
542
543/**
544 * @brief RFC 4254 sec 7.2: the sec 7.1 binding that owns @p listener_idx.
545 *
546 * A connection accepted on a forwarded listener is answered with a "forwarded-tcpip" CHANNEL_OPEN
547 * carrying "the address that was connected" and "port that was connected", which are the ones the
548 * binding requested. False when no active binding owns the listener.
549 */
550
551/** @brief Tear down all forwards on @p ssh_slot (its SSH connection is closing). */
552
553#endif // PROTOCORE_SSH_PORT_FORWARD
554
555/** @brief Dispatch messages 80 to 127 (RFC 4254). */
556
557/** @brief RFC 4254 sec 5.2 window: what a flow-control call reads and writes. */
558typedef struct
559{
560 SshFlow *f; ///< the window a call acts on
561 uint32_t local_window; ///< our initial window
562 uint32_t peer_window; ///< the peer's
563 uint32_t peer_max_pkt; ///< the largest packet it will take
564 uint32_t n; ///< bytes a take accounts for
565 uint32_t add; ///< in: credit to add; out: what a replenish owes
566 uint32_t want; ///< bytes a send would like to put out
567 size_t len; ///< the length a send test measures
569
570/** @brief RFC 4254 sec 5 channels: what a channel call acts on. */
571typedef struct
572{
573 uint8_t slot; ///< the SSH slot
574 uint32_t channel; ///< the channel number on it
575 uint32_t id; ///< the channel a lookup names
576 SshChanService service; ///< the service a bind attaches
577 const uint8_t *payload; ///< the message body
578 size_t len; ///< how many bytes it has
579 const uint8_t *data; ///< payload bytes a send carries
580 uint8_t *out; ///< where a reply is written
581 size_t out_len; ///< what was written
582 size_t cap; ///< how much room it has
583 uint32_t exit_status; ///< sec 6.10 exit-status
584 const char *signal_name; ///< sec 6.10 exit-signal
585 embed_bool core_dumped; ///< whether it dumped core
586 const char *err_msg; ///< the message that accompanies it
587 const uint8_t *rtype; ///< sec 5.4 request type
588 uint32_t rtype_len; ///< its length
590
591/** @brief RFC 4254 sec 6.2 pty-req and sec 6.7 window-change: what a terminal call parses. */
592typedef struct
593{
594 const uint8_t *p; ///< the request bytes
595 size_t len; ///< how many
596 size_t off; ///< where the fields start
597 uint8_t n; ///< strings a presence check counts
598 const uint8_t *modes; ///< the encoded terminal modes
599 uint32_t modes_len; ///< their length
600 uint32_t consumed; ///< what a mode walk consumed
601 SshPtyRequest *req; ///< where a parse lands
602 uint32_t width_chars; ///< the reported terminal width
603 uint32_t height_rows; ///< its height
604 uint32_t width_px; ///< the same in pixels
605 uint32_t height_px; ///<
606} SshPtyArgs;
607
608/** @brief RFC 4254 sec 7 TCP/IP forwarding: what a forwarding call names. */
609typedef struct
610{
611 uint8_t slot; ///< the SSH slot a forward belongs to
612 const char *conn_addr; ///< the address connected to
613 uint16_t conn_port; ///< its port
614 const char *orig_addr; ///< where the connection came from
615 uint16_t orig_port; ///< its port
616 uint8_t listener_idx; ///< the listener row a binding lookup names
617 uint8_t out_slot; ///< the slot that binding belongs to
618 uint16_t bind_port; ///< the port it bound
619 const char *bind_addr; ///< the address it bound
620} SshFwdArgs;
621
622/**
623 * @brief The SSH connection protocol (RFC 4254): channels, their windows, and what runs on them.
624 *
625 * A caller fills the group its call belongs to, invokes the call through ::SshConnection, and reads
626 * the outcome off the same handle. The groups are separate because a window has nothing to do with
627 * a forwarding binding, and neither has anything to do with a pty request.
628 *
629 * @var SshConnectionNs::flow sec 5.2 window arguments
630 * @var SshConnectionNs::chan sec 5 channel arguments
631 * @var SshConnectionNs::pty sec 6.2 / 6.7 terminal arguments
632 * @var SshConnectionNs::fwd sec 7 forwarding arguments
633 * @var SshConnectionNs::msg_type the message a dispatch routes
634 * @var SshConnectionNs::ok a call's true/false outcome
635 * @var SshConnectionNs::i32 a call's signed outcome
636 * @var SshConnectionNs::u32 a call's 32-bit outcome
637 * @var SshConnectionNs::found the channel a lookup reports, or NULL
638 */
670
671/** @brief The operands and the outcome. */
673
674/** @brief The entries. */
675typedef struct
676{
677 void (*const flow_init)(const uint8_t *work);
678 void (*const flow_recv_take)(const uint8_t *work);
679 void (*const flow_replenish_due)(const uint8_t *work);
680 void (*const flow_local_credit)(const uint8_t *work);
681 void (*const flow_send_allows)(const uint8_t *work);
682 void (*const flow_send_cap)(const uint8_t *work);
683 void (*const flow_send_take)(const uint8_t *work);
684 void (*const flow_peer_add)(const uint8_t *work);
685 void (*const channel_init)(const uint8_t *work);
686 void (*const chan_alloc)(const uint8_t *work);
687 void (*const chan_by_id)(const uint8_t *work);
688 void (*const channel_bind_service)(const uint8_t *work);
689 void (*const channel_handle_open)(const uint8_t *work);
690 void (*const channel_handle_open_confirm)(const uint8_t *work);
691 void (*const channel_handle_open_failure)(const uint8_t *work);
692 void (*const channel_handle_request)(uint8_t *work);
693 void (*const channel_handle_data)(const uint8_t *work);
694 void (*const channel_handle_extended_data)(const uint8_t *work);
695 void (*const channel_handle_window_adjust)(const uint8_t *work);
696 void (*const channel_handle_eof)(const uint8_t *work);
697 void (*const channel_handle_close)(const uint8_t *work);
698 void (*const channel_build_data)(const uint8_t *work);
699 void (*const channel_build_eof)(const uint8_t *work);
700 void (*const channel_build_close)(const uint8_t *work);
701 void (*const channel_send_data)(uint8_t *work);
702 void (*const channel_send_eof)(uint8_t *work);
703 void (*const channel_send_close)(uint8_t *work);
704 void (*const channel_send_exit_status)(const uint8_t *work);
705 void (*const channel_send_exit_signal)(const uint8_t *work);
706 void (*const channel_open_forwarded)(const uint8_t *work);
707 void (*const channel_send_open_forwarded)(uint8_t *work);
708 void (*const channel_pty)(const uint8_t *work);
709 void (*const req_strings_present)(const uint8_t *work);
710 void (*const pty_req_fields_present)(uint8_t *work);
711 void (*const pty_modes_valid)(const uint8_t *work);
712 void (*const pty_req_parse)(const uint8_t *work);
713 void (*const window_change_parse)(const uint8_t *work);
714 void (*const forward_begin)(const uint8_t *work);
715 void (*const forward_pump)(uint8_t *work);
716 void (*const forward_binding)(const uint8_t *work);
717 void (*const forward_reset)(const uint8_t *work);
718 void (*const global_request_handle)(const uint8_t *work);
719 void (*const dispatch)(uint8_t *work);
720 void (*const set_data_cb)(const uint8_t *work);
721 void (*const set_pty_req_cb)(const uint8_t *work);
722 void (*const set_window_change_cb)(const uint8_t *work);
723 void (*const set_forward_open_cb)(const uint8_t *work);
724 void (*const set_forward_data_cb)(const uint8_t *work);
725 void (*const set_forward_confirm_cb)(const uint8_t *work);
726 void (*const set_forward_policy_cb)(const uint8_t *work);
727 void (*const set_rforward_open_cb)(const uint8_t *work);
728 void (*const set_rforward_cancel_cb)(const uint8_t *work);
729 void (*const set_sftp_open_cb)(const uint8_t *work);
730 void (*const set_sftp_data_cb)(const uint8_t *work);
731 void (*const set_scp_open_cb)(const uint8_t *work);
732 void (*const set_scp_data_cb)(const uint8_t *work);
734
735// What the table binds, defined once in the .c and taking one parameter each: everything
736// else an entry needs is an operand in SshConnectionV or a region of the borrow at a fixed offset.
737void protocore_ssh_connection_flow_init(const uint8_t *work);
746void protocore_ssh_connection_chan_alloc(const uint8_t *work);
747void protocore_ssh_connection_chan_by_id(const uint8_t *work);
768void protocore_ssh_connection_channel_pty(const uint8_t *work);
780void protocore_ssh_connection_set_data_cb(const uint8_t *work);
793
794// `static const`, initialised HERE rather than `extern` against a definition in the .c: a
795// const object whose initializer every translation unit can see is a COMPILE-TIME FACT, so
796// `SshConnection.flow_init(work)` resolves to a named function and becomes a DIRECT call. An extern table
797// leaves the call indirect and the symbol live at every level, -O2 -flto included.
798static const SshConnectionNs SshConnection __attribute__((unused)) = {
810 .channel_bind_service = protocore_ssh_connection_channel_bind_service,
812 .channel_handle_open_confirm = protocore_ssh_connection_channel_handle_open_confirm,
813 .channel_handle_open_failure = protocore_ssh_connection_channel_handle_open_failure,
814 .channel_handle_request = protocore_ssh_connection_channel_handle_request,
816 .channel_handle_extended_data = protocore_ssh_connection_channel_handle_extended_data,
817 .channel_handle_window_adjust = protocore_ssh_connection_channel_handle_window_adjust,
819 .channel_handle_close = protocore_ssh_connection_channel_handle_close,
826 .channel_send_exit_status = protocore_ssh_connection_channel_send_exit_status,
827 .channel_send_exit_signal = protocore_ssh_connection_channel_send_exit_signal,
828 .channel_open_forwarded = protocore_ssh_connection_channel_open_forwarded,
829 .channel_send_open_forwarded = protocore_ssh_connection_channel_send_open_forwarded,
832 .pty_req_fields_present = protocore_ssh_connection_pty_req_fields_present,
840 .global_request_handle = protocore_ssh_connection_global_request_handle,
844 .set_window_change_cb = protocore_ssh_connection_set_window_change_cb,
847 .set_forward_confirm_cb = protocore_ssh_connection_set_forward_confirm_cb,
848 .set_forward_policy_cb = protocore_ssh_connection_set_forward_policy_cb,
849 .set_rforward_open_cb = protocore_ssh_connection_set_rforward_open_cb,
850 .set_rforward_cancel_cb = protocore_ssh_connection_set_rforward_cancel_cb,
855};
856
857/**
858 * @brief The PROTOCORE_SSH_CONNECTION_BORROW bytes this module's state lives in.
859 *
860 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
861 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
862 * walks, so the state lasts the life of the program.
863 *
864 * @return the span.
865 */
867
868EMBED_END_DECLS
869
870#endif // PROTOCORE_CONNECTION_CONNECTION_H
#define MAX_SSH_CONNS
Maximum simultaneous SSH connections.
#define PROTOCORE_SSH_PTY_TERM_MAX
Max stored TERM value from a pty-req (RFC 4254 sec 6.2).
void protocore_ssh_connection_set_forward_confirm_cb(const uint8_t *work)
int(* SshForwardOpenCb)(uint8_t slot, uint32_t channel, const char *host, size_t host_len, uint16_t port)
Install the inbound-data callback (session channels).
Definition connection.h:199
SshChannel ssh_chan[MAX_SSH_CONNS][PROTOCORE_SSH_MAX_CHANNELS]
Channel pool: PROTOCORE_SSH_MAX_CHANNELS channels per SSH connection (BSS). Owned by this layer; src/...
void protocore_ssh_connection_flow_recv_take(const uint8_t *work)
EMBED_ENUM_BYTE(SshChanType, SSH_CHAN_SESSION=0, SSH_CHAN_DIRECT_TCPIP=1, SSH_CHAN_FORWARDED_TCPIP=2)
Channel type (RFC 4254).
void protocore_ssh_connection_flow_send_cap(const uint8_t *work)
void protocore_ssh_connection_forward_pump(uint8_t *work)
void protocore_ssh_connection_forward_reset(const uint8_t *work)
void(* SshChannelDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len)
Application callback for inbound channel data (raw bytes), tagged with the channel id it arrived on.
Definition connection.h:185
void protocore_ssh_connection_set_scp_open_cb(const uint8_t *work)
void protocore_ssh_connection_channel_handle_close(const uint8_t *work)
void protocore_ssh_connection_channel_handle_request(uint8_t *work)
int32_t protocore_ssh_sig_build_eof(uint32_t peer_id, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_EOF, as one 5-byte message.
void protocore_ssh_connection_chan_alloc(const uint8_t *work)
void protocore_ssh_connection_channel_handle_window_adjust(const uint8_t *work)
int32_t protocore_ssh_sig_build_window_adjust(uint32_t peer_id, uint32_t add, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_WINDOW_ADJUST granting add more bytes. Credit the window only once this is sent.
void protocore_ssh_connection_forward_begin(const uint8_t *work)
void(* SshScpOpenCb)(uint8_t slot, uint32_t channel, const char *cmd, size_t cmd_len)
An exec "scp …" request was accepted on channel (cmd is cmd_len bytes, not NUL-terminated).
Definition connection.h:245
void protocore_ssh_connection_channel_build_eof(const uint8_t *work)
void protocore_ssh_connection_pty_modes_valid(const uint8_t *work)
void protocore_ssh_connection_flow_send_allows(const uint8_t *work)
void protocore_ssh_connection_set_sftp_data_cb(const uint8_t *work)
int32_t protocore_ssh_sig_build_open_failure(uint8_t *out, size_t cap, uint32_t peer_id, uint32_t reason, size_t *out_len)
Start a channel's windows: ours at local_window, the peer's at what it advertised.
void protocore_ssh_connection_flow_replenish_due(const uint8_t *work)
int32_t protocore_ssh_sig_build_open_confirm(const SshFlow *f, uint32_t peer_id, uint32_t local_id, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_OPEN_CONFIRMATION, advertising our current window and maximum packet size.
void(* SshForwardDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len)
Inbound data on a direct-tcpip channel (the owner writes it to the forwarded TCP socket)....
Definition connection.h:202
void protocore_ssh_connection_set_scp_data_cb(const uint8_t *work)
uint8_t * protocore_ssh_connection_span(void)
The PROTOCORE_SSH_CONNECTION_BORROW bytes this module's state lives in.
void protocore_ssh_connection_channel_handle_data(const uint8_t *work)
void protocore_ssh_connection_set_data_cb(const uint8_t *work)
int32_t protocore_ssh_sig_build_data(SshFlow *f, uint32_t peer_id, const uint8_t *data, size_t len, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_DATA carrying len bytes, and account them against the peer's window.
void(* SshWindowChangeCb)(uint8_t i, uint32_t channel, uint32_t width_chars, uint32_t height_rows, uint32_t width_px, uint32_t height_px)
A "window-change" (sec 6.7) on a channel that already has a terminal.
Definition connection.h:380
void protocore_ssh_connection_set_rforward_open_cb(const uint8_t *work)
void protocore_ssh_connection_set_sftp_open_cb(const uint8_t *work)
void(* SshSftpOpenCb)(uint8_t slot, uint32_t channel)
Install the forwarded-tcpip open-confirmation callback (opt-in, ssh -R).
Definition connection.h:235
void protocore_ssh_connection_set_forward_data_cb(const uint8_t *work)
void protocore_ssh_connection_req_strings_present(const uint8_t *work)
void(* SshScpDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len)
Inbound bytes on an SCP channel (the RCP protocol stream).
Definition connection.h:247
void protocore_ssh_connection_chan_by_id(const uint8_t *work)
void protocore_ssh_connection_flow_peer_add(const uint8_t *work)
void protocore_ssh_connection_channel_handle_open_confirm(const uint8_t *work)
void protocore_ssh_connection_channel_handle_eof(const uint8_t *work)
int32_t protocore_ssh_sig_build_close(uint32_t peer_id, uint8_t *out, size_t cap, size_t *out_len)
CHANNEL_CLOSE, as one 5-byte message.
void protocore_ssh_connection_channel_build_data(const uint8_t *work)
SshConnectionVars SshConnectionV
The operands and the outcome.
void(* SshForwardConfirmCb)(uint8_t slot, uint32_t channel, embed_bool ok)
Install the remote-forward (ssh -R) open-policy callback (opt-in).
Definition connection.h:231
void protocore_ssh_connection_flow_init(const uint8_t *work)
void(* SshSftpDataCb)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len)
Inbound bytes on an SFTP channel (the raw SSH_FXP_* stream) - kept out of the session data cb.
Definition connection.h:237
embed_bool(* SshForwardPolicyCb)(const char *host, uint16_t port)
Build SSH_MSG_CHANNEL_DATA for channel and put it on the slot's stream (sec 5.2).
Definition connection.h:524
void protocore_ssh_connection_channel_handle_open(const uint8_t *work)
void protocore_ssh_connection_set_rforward_cancel_cb(const uint8_t *work)
void protocore_ssh_connection_pty_req_fields_present(uint8_t *work)
void protocore_ssh_connection_channel_send_exit_status(const uint8_t *work)
void protocore_ssh_connection_set_pty_req_cb(const uint8_t *work)
void protocore_ssh_connection_channel_send_close(uint8_t *work)
void protocore_ssh_connection_set_window_change_cb(const uint8_t *work)
void protocore_ssh_connection_global_request_handle(const uint8_t *work)
void protocore_ssh_connection_channel_send_exit_signal(const uint8_t *work)
void protocore_ssh_connection_channel_handle_open_failure(const uint8_t *work)
void protocore_ssh_connection_dispatch(uint8_t *work)
void protocore_ssh_connection_channel_send_open_forwarded(uint8_t *work)
void protocore_ssh_connection_forward_binding(const uint8_t *work)
void protocore_ssh_connection_set_forward_policy_cb(const uint8_t *work)
int(* SshRemoteForwardCancelCb)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port)
"cancel-tcpip-forward" request (RFC 4254 §7.1): drop a remote forward.
Definition connection.h:220
void protocore_ssh_connection_channel_pty(const uint8_t *work)
void protocore_ssh_connection_flow_local_credit(const uint8_t *work)
int(* SshRemoteForwardOpenCb)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port)
Install the direct-tcpip forward open-policy callback (opt-in).
Definition connection.h:217
void protocore_ssh_connection_channel_send_eof(uint8_t *work)
void protocore_ssh_connection_window_change_parse(const uint8_t *work)
void protocore_ssh_connection_channel_bind_service(const uint8_t *work)
void protocore_ssh_connection_channel_send_data(uint8_t *work)
void protocore_ssh_connection_channel_init(const uint8_t *work)
void protocore_ssh_connection_flow_send_take(const uint8_t *work)
void protocore_ssh_connection_channel_build_close(const uint8_t *work)
embed_bool(* SshPtyReqCb)(uint8_t i, uint32_t channel, const SshPtyRequest *pty)
Walk an encoded terminal-mode stream (RFC 4254 sec 8) and report whether it is well formed.
Definition connection.h:377
void protocore_ssh_connection_set_forward_open_cb(const uint8_t *work)
void protocore_ssh_connection_pty_req_parse(const uint8_t *work)
void protocore_ssh_connection_channel_open_forwarded(const uint8_t *work)
void protocore_ssh_connection_channel_handle_extended_data(const uint8_t *work)
#define PROTOCORE_SSH_MAX_CHANNELS
Maximum concurrent SSH channels per connection (RFC 4254 multiplexing).
Root infrastructure: fixed widths, serializers, opcodes and sizes, for every layer above.
RFC 4254 sec 5 channels: what a channel call acts on.
Definition connection.h:572
uint8_t slot
the SSH slot
Definition connection.h:573
uint32_t exit_status
sec 6.10 exit-status
Definition connection.h:583
const uint8_t * payload
the message body
Definition connection.h:577
size_t out_len
what was written
Definition connection.h:581
size_t cap
how much room it has
Definition connection.h:582
uint32_t channel
the channel number on it
Definition connection.h:574
uint32_t rtype_len
its length
Definition connection.h:588
uint8_t * out
where a reply is written
Definition connection.h:580
embed_bool core_dumped
whether it dumped core
Definition connection.h:585
const uint8_t * rtype
sec 5.4 request type
Definition connection.h:587
SshChanService service
the service a bind attaches
Definition connection.h:576
uint32_t id
the channel a lookup names
Definition connection.h:575
const uint8_t * data
payload bytes a send carries
Definition connection.h:579
const char * err_msg
the message that accompanies it
Definition connection.h:586
const char * signal_name
sec 6.10 exit-signal
Definition connection.h:584
size_t len
how many bytes it has
Definition connection.h:578
Per-connection channel state.
Definition connection.h:154
uint32_t width_chars
terminal width, characters
Definition connection.h:172
embed_bool close_sent
We sent CHANNEL_CLOSE.
Definition connection.h:167
embed_bool pending
True for a server-initiated channel we opened, awaiting the client's confirmation.
Definition connection.h:156
embed_bool close_received
The peer sent CHANNEL_CLOSE.
Definition connection.h:168
embed_bool relay_eof
The peer sent CHANNEL_EOF.
Definition connection.h:163
SshChanType type
session, direct-tcpip, or forwarded-tcpip.
Definition connection.h:157
embed_bool pty
A "pty-req" was accepted on this channel.
Definition connection.h:171
embed_bool open
True once the channel is confirmed open both ways.
Definition connection.h:155
uint32_t height_rows
terminal height, rows
Definition connection.h:173
uint32_t local_id
Our channel id (== slot index).
Definition connection.h:159
SshChanService service
What a sec 6 request bound over a session channel, if anything.
Definition connection.h:158
uint32_t width_px
terminal width, pixels
Definition connection.h:174
SshFlow flow
RFC 4254 sec 5.2 window pair (owner: ssh_flow_control.*).
Definition connection.h:161
uint32_t height_px
terminal height, pixels
Definition connection.h:175
uint32_t peer_id
Client's channel id.
Definition connection.h:160
embed_bool eof_sent
We sent CHANNEL_EOF (RFC 4254 sec 5.3).
Definition connection.h:162
The entries.
Definition connection.h:676
void(*const set_sftp_open_cb)(const uint8_t *work)
Definition connection.h:729
void(*const set_rforward_cancel_cb)(const uint8_t *work)
Definition connection.h:728
void(*const window_change_parse)(const uint8_t *work)
Definition connection.h:713
void(*const channel_handle_eof)(const uint8_t *work)
Definition connection.h:696
void(*const dispatch)(uint8_t *work)
Definition connection.h:719
void(*const channel_handle_request)(uint8_t *work)
Definition connection.h:692
void(*const set_scp_data_cb)(const uint8_t *work)
Definition connection.h:732
void(*const set_scp_open_cb)(const uint8_t *work)
Definition connection.h:731
void(*const flow_replenish_due)(const uint8_t *work)
Definition connection.h:679
void(*const channel_handle_open)(const uint8_t *work)
Definition connection.h:689
void(*const set_pty_req_cb)(const uint8_t *work)
Definition connection.h:721
void(*const set_sftp_data_cb)(const uint8_t *work)
Definition connection.h:730
void(*const channel_pty)(const uint8_t *work)
Definition connection.h:708
void(*const flow_send_cap)(const uint8_t *work)
Definition connection.h:682
void(*const pty_req_parse)(const uint8_t *work)
Definition connection.h:712
void(*const channel_send_data)(uint8_t *work)
Definition connection.h:701
void(*const channel_build_eof)(const uint8_t *work)
Definition connection.h:699
void(*const channel_handle_close)(const uint8_t *work)
Definition connection.h:697
void(*const flow_send_allows)(const uint8_t *work)
Definition connection.h:681
void(*const flow_peer_add)(const uint8_t *work)
Definition connection.h:684
void(*const req_strings_present)(const uint8_t *work)
Definition connection.h:709
void(*const flow_send_take)(const uint8_t *work)
Definition connection.h:683
void(*const channel_send_exit_status)(const uint8_t *work)
Definition connection.h:704
void(*const set_rforward_open_cb)(const uint8_t *work)
Definition connection.h:727
void(*const channel_send_exit_signal)(const uint8_t *work)
Definition connection.h:705
void(*const channel_open_forwarded)(const uint8_t *work)
Definition connection.h:706
void(*const forward_begin)(const uint8_t *work)
Definition connection.h:714
void(*const chan_alloc)(const uint8_t *work)
Definition connection.h:686
void(*const channel_send_close)(uint8_t *work)
Definition connection.h:703
void(*const channel_bind_service)(const uint8_t *work)
Definition connection.h:688
void(*const channel_handle_extended_data)(const uint8_t *work)
Definition connection.h:694
void(*const set_forward_policy_cb)(const uint8_t *work)
Definition connection.h:726
void(*const forward_binding)(const uint8_t *work)
Definition connection.h:716
void(*const global_request_handle)(const uint8_t *work)
Definition connection.h:718
void(*const channel_init)(const uint8_t *work)
Definition connection.h:685
void(*const pty_req_fields_present)(uint8_t *work)
Definition connection.h:710
void(*const channel_handle_window_adjust)(const uint8_t *work)
Definition connection.h:695
void(*const pty_modes_valid)(const uint8_t *work)
Definition connection.h:711
void(*const chan_by_id)(const uint8_t *work)
Definition connection.h:687
void(*const set_forward_confirm_cb)(const uint8_t *work)
Definition connection.h:725
void(*const set_data_cb)(const uint8_t *work)
Definition connection.h:720
void(*const flow_init)(const uint8_t *work)
Definition connection.h:677
void(*const channel_send_open_forwarded)(uint8_t *work)
Definition connection.h:707
void(*const flow_recv_take)(const uint8_t *work)
Definition connection.h:678
void(*const set_forward_data_cb)(const uint8_t *work)
Definition connection.h:724
void(*const channel_handle_open_failure)(const uint8_t *work)
Definition connection.h:691
void(*const forward_reset)(const uint8_t *work)
Definition connection.h:717
void(*const channel_handle_data)(const uint8_t *work)
Definition connection.h:693
void(*const channel_build_data)(const uint8_t *work)
Definition connection.h:698
void(*const set_window_change_cb)(const uint8_t *work)
Definition connection.h:722
void(*const forward_pump)(uint8_t *work)
Definition connection.h:715
void(*const channel_send_eof)(uint8_t *work)
Definition connection.h:702
void(*const channel_build_close)(const uint8_t *work)
Definition connection.h:700
void(*const flow_local_credit)(const uint8_t *work)
Definition connection.h:680
void(*const set_forward_open_cb)(const uint8_t *work)
Definition connection.h:723
void(*const channel_handle_open_confirm)(const uint8_t *work)
Definition connection.h:690
SshChanArgs chan
Definition connection.h:642
SshForwardConfirmCb forward_confirm_cb
Definition connection.h:661
SshChannel * found
Definition connection.h:649
SshWindowChangeCb window_change_cb
Definition connection.h:658
SshPtyReqCb pty_req_cb
Definition connection.h:657
SshForwardOpenCb forward_open_cb
Definition connection.h:659
SshRemoteForwardCancelCb rforward_cancel_cb
Definition connection.h:664
SshSftpDataCb sftp_data_cb
Definition connection.h:666
SshScpOpenCb scp_open_cb
Definition connection.h:667
SshSftpOpenCb sftp_open_cb
Definition connection.h:665
SshForwardPolicyCb forward_policy_cb
Definition connection.h:662
SshRemoteForwardOpenCb rforward_open_cb
Definition connection.h:663
SshScpDataCb scp_data_cb
Definition connection.h:668
SshForwardDataCb forward_data_cb
Definition connection.h:660
SshFlowArgs flow
Definition connection.h:641
SshChannelDataCb data_cb
Definition connection.h:656
Dispatch messages 80 to 127 (RFC 4254).
Definition connection.h:559
uint32_t peer_window
the peer's
Definition connection.h:562
uint32_t add
in: credit to add; out: what a replenish owes
Definition connection.h:565
uint32_t n
bytes a take accounts for
Definition connection.h:564
uint32_t local_window
our initial window
Definition connection.h:561
SshFlow * f
the window a call acts on
Definition connection.h:560
uint32_t want
bytes a send would like to put out
Definition connection.h:566
uint32_t peer_max_pkt
the largest packet it will take
Definition connection.h:563
size_t len
the length a send test measures
Definition connection.h:567
One channel's flow-control state (RFC 4254 sec 5.2).
Definition connection.h:22
uint32_t peer_max_pkt
Peer's maximum packet size; caps a single send independently of the window.
Definition connection.h:26
uint32_t local_max
The window we advertised, and replenish back up to.
Definition connection.h:24
uint32_t peer_window
Bytes we may still send the peer.
Definition connection.h:25
uint32_t local_window
Bytes the peer may still send us before we WINDOW_ADJUST.
Definition connection.h:23
RFC 4254 sec 7 TCP/IP forwarding: what a forwarding call names.
Definition connection.h:610
uint16_t orig_port
its port
Definition connection.h:615
const char * orig_addr
where the connection came from
Definition connection.h:614
const char * bind_addr
the address it bound
Definition connection.h:619
uint16_t bind_port
the port it bound
Definition connection.h:618
const char * conn_addr
the address connected to
Definition connection.h:612
uint16_t conn_port
its port
Definition connection.h:613
uint8_t out_slot
the slot that binding belongs to
Definition connection.h:617
uint8_t slot
the SSH slot a forward belongs to
Definition connection.h:611
uint8_t listener_idx
the listener row a binding lookup names
Definition connection.h:616
RFC 4254 sec 6.2 pty-req and sec 6.7 window-change: what a terminal call parses.
Definition connection.h:593
const uint8_t * modes
the encoded terminal modes
Definition connection.h:598
uint32_t height_rows
its height
Definition connection.h:603
uint32_t height_px
Definition connection.h:605
uint32_t width_chars
the reported terminal width
Definition connection.h:602
size_t len
how many
Definition connection.h:595
uint8_t n
strings a presence check counts
Definition connection.h:597
uint32_t width_px
the same in pixels
Definition connection.h:604
size_t off
where the fields start
Definition connection.h:596
uint32_t consumed
what a mode walk consumed
Definition connection.h:600
SshPtyRequest * req
where a parse lands
Definition connection.h:601
uint32_t modes_len
their length
Definition connection.h:599
const uint8_t * p
the request bytes
Definition connection.h:594
Open a server-initiated "forwarded-tcpip" channel (RFC 4254 §7.2, ssh -R).
Definition connection.h:343
uint32_t width_px
terminal width, pixels
Definition connection.h:347
uint32_t height_rows
terminal height, rows
Definition connection.h:346
uint32_t height_px
terminal height, pixels
Definition connection.h:348
uint32_t modes_len
length of modes
Definition connection.h:350
const uint8_t * modes
encoded terminal modes, pointing into the request
Definition connection.h:349
char term[PROTOCORE_SSH_PTY_TERM_MAX]
TERM value, null-terminated, truncated to fit.
Definition connection.h:344
uint32_t width_chars
terminal width, characters
Definition connection.h:345