24#ifndef DETERMINISTICESPASYNCWEBSERVER_SSH_CHANNEL_H
25#define DETERMINISTICESPASYNCWEBSERVER_SSH_CHANNEL_H
59typedef void (*
SshChannelDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
75typedef int (*
SshForwardOpenCb)(uint8_t slot, uint32_t channel,
const char *host,
size_t host_len, uint16_t port);
79typedef void (*
SshForwardDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
133 uint16_t orig_port, uint8_t *out,
size_t *out_len,
size_t cap);
177int ssh_channel_handle_open(uint8_t i,
const uint8_t *payload,
size_t len, uint8_t *out,
size_t *out_len,
size_t cap);
196int ssh_channel_handle_data(uint8_t i,
const uint8_t *payload,
size_t len, uint8_t *out,
size_t *out_len,
size_t cap);
204int ssh_channel_build_data(uint8_t i, uint32_t channel,
const uint8_t *data,
size_t len, uint8_t *out,
size_t *out_len,
225int ssh_channel_handle_close(uint8_t i,
const uint8_t *payload,
size_t len, uint8_t *out,
size_t *out_len,
size_t cap);
User-facing configuration for DeterministicESPAsyncWebServer.
#define MAX_SSH_CONNS
Maximum simultaneous SSH connections.
#define DETWS_SSH_MAX_CHANNELS
Maximum concurrent SSH channels per connection (RFC 4254 multiplexing).
void ssh_channel_set_forward_data_cb(SshForwardDataCb cb)
Install the direct-tcpip forward inbound-data callback.
int(* SshForwardOpenCb)(uint8_t slot, uint32_t channel, const char *host, size_t host_len, uint16_t port)
"direct-tcpip" forward request: a client asked the server to open a TCP connection to host : port (ss...
int ssh_channel_open_forwarded(uint8_t i, const char *conn_addr, uint16_t conn_port, const char *orig_addr, uint16_t orig_port, uint8_t *out, size_t *out_len, size_t cap)
Open a server-initiated "forwarded-tcpip" channel (RFC 4254 §7.2, ssh -R).
int ssh_channel_handle_data(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_CHANNEL_DATA: bounds-check, update the window, and invoke the data callback....
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.
int ssh_channel_build_data(uint8_t i, uint32_t channel, const uint8_t *data, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Build an SSH_MSG_CHANNEL_DATA message carrying data to the client on channel channel (a local channel...
int ssh_global_request_handle(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_GLOBAL_REQUEST (RFC 4254 §4).
void ssh_channel_set_forward_open_cb(SshForwardOpenCb cb)
Install the direct-tcpip forward open-policy callback (opt-in).
void ssh_channel_set_forward_confirm_cb(SshForwardConfirmCb cb)
Install the forwarded-tcpip open-confirmation callback (opt-in, ssh -R).
int ssh_channel_build_close(uint8_t i, uint32_t channel, uint8_t *out, size_t *out_len, size_t cap)
Build SSH_MSG_CHANNEL_EOF + SSH_MSG_CHANNEL_CLOSE for channel channel and mark it closed.
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)....
void ssh_channel_set_rforward_cancel_cb(SshRemoteForwardCancelCb cb)
Install the remote-forward (ssh -R) cancel callback (opt-in).
int ssh_channel_handle_window_adjust(uint8_t i, const uint8_t *payload, size_t len)
Handle SSH_MSG_CHANNEL_WINDOW_ADJUST (grows the peer window).
SshChanType
Channel type (RFC 4254).
@ SSH_CHAN_DIRECT_TCPIP
"direct-tcpip" - client-initiated TCP forward (ssh -L)
@ SSH_CHAN_SESSION
"session" - shell / exec / data
@ SSH_CHAN_FORWARDED_TCPIP
"forwarded-tcpip" - server-initiated TCP forward (ssh -R)
void ssh_channel_set_data_cb(SshChannelDataCb cb)
Install the inbound-data callback (session channels).
void ssh_channel_init(uint8_t i)
Reset channel state for slot i.
int ssh_channel_handle_close(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle an inbound SSH_MSG_CHANNEL_CLOSE: route to the recipient channel, reply with EOF + CLOSE,...
void(* SshForwardConfirmCb)(uint8_t slot, uint32_t channel, bool ok)
Result of the client's reply to a server-initiated forwarded-tcpip channel: ok = true on CHANNEL_OPEN...
int ssh_channel_handle_open_failure(uint8_t i, const uint8_t *payload, size_t len)
Handle SSH_MSG_CHANNEL_OPEN_FAILURE for a channel we opened (ssh -R).
int ssh_channel_handle_request(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_CHANNEL_REQUEST.
int ssh_channel_handle_open(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_CHANNEL_OPEN and emit CHANNEL_OPEN_CONFIRMATION.
SshChannel ssh_chan[MAX_SSH_CONNS][DETWS_SSH_MAX_CHANNELS]
Channel pool: DETWS_SSH_MAX_CHANNELS channels per SSH connection (BSS). Owned by this layer; src/ cod...
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.
int(* SshRemoteForwardOpenCb)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port)
"tcpip-forward" remote-forward request (ssh -R): the client asks the server to listen on bind_addr : ...
int ssh_channel_handle_open_confirm(uint8_t i, const uint8_t *payload, size_t len)
Handle SSH_MSG_CHANNEL_OPEN_CONFIRMATION for a channel we opened (ssh -R).
void ssh_channel_set_rforward_open_cb(SshRemoteForwardOpenCb cb)
Install the remote-forward (ssh -R) open-policy callback (opt-in).
Per-connection channel state.
bool open
True once the channel is confirmed open both ways.
uint32_t peer_max_pkt
Client's maximum packet size.
uint32_t peer_window
Bytes we may still send to the client.
SshChanType type
session, direct-tcpip, or forwarded-tcpip.
bool pending
True for a server-initiated channel we opened, awaiting the client's confirmation.
uint32_t local_id
Our channel id (== slot index).
uint32_t local_window
Bytes we may still receive before WINDOW_ADJUST.
uint32_t peer_id
Client's channel id.