9#ifndef PROTOCORE_CONNECTION_CONNECTION_H
10#define PROTOCORE_CONNECTION_CONNECTION_H
107 size_t cap,
size_t *out_len);
116 size_t cap,
size_t *out_len);
134 SSH_CHAN_SESSION = 0,
135 SSH_CHAN_DIRECT_TCPIP = 1,
136 SSH_CHAN_FORWARDED_TCPIP = 2
147 SSH_CHAN_SERVICE_NONE = 0,
148 SSH_CHAN_SERVICE_SFTP = 1,
149 SSH_CHAN_SERVICE_SCP = 2
185typedef void (*
SshChannelDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
199typedef int (*
SshForwardOpenCb)(uint8_t slot, uint32_t channel,
const char *host,
size_t host_len, uint16_t port);
202typedef void (*
SshForwardDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
237typedef void (*
SshSftpDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
239#if PROTOCORE_ENABLE_SSH_SFTP
245typedef void (*
SshScpOpenCb)(uint8_t slot, uint32_t channel,
const char *cmd,
size_t cmd_len);
247typedef void (*
SshScpDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
249#if PROTOCORE_ENABLE_SSH_SCP
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);
413#if PROTOCORE_ENABLE_SSH_SFTP || PROTOCORE_ENABLE_SSH_SCP
475#define SSH_CHANNEL_EOF_LEN 5u
478#define SSH_CHANNEL_CLOSE_LEN 5u
526#if PROTOCORE_SSH_PORT_FORWARD
#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).
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.
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).
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)....
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.
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).
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).
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).
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.
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).
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.
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).
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.
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.
uint32_t exit_status
sec 6.10 exit-status
const uint8_t * payload
the message body
size_t out_len
what was written
size_t cap
how much room it has
uint32_t channel
the channel number on it
uint32_t rtype_len
its length
uint8_t * out
where a reply is written
embed_bool core_dumped
whether it dumped core
const uint8_t * rtype
sec 5.4 request type
SshChanService service
the service a bind attaches
uint32_t id
the channel a lookup names
const uint8_t * data
payload bytes a send carries
const char * err_msg
the message that accompanies it
const char * signal_name
sec 6.10 exit-signal
size_t len
how many bytes it has
Per-connection channel state.
uint32_t width_chars
terminal width, characters
embed_bool close_sent
We sent CHANNEL_CLOSE.
embed_bool pending
True for a server-initiated channel we opened, awaiting the client's confirmation.
embed_bool close_received
The peer sent CHANNEL_CLOSE.
embed_bool relay_eof
The peer sent CHANNEL_EOF.
SshChanType type
session, direct-tcpip, or forwarded-tcpip.
embed_bool pty
A "pty-req" was accepted on this channel.
embed_bool open
True once the channel is confirmed open both ways.
uint32_t height_rows
terminal height, rows
uint32_t local_id
Our channel id (== slot index).
SshChanService service
What a sec 6 request bound over a session channel, if anything.
uint32_t width_px
terminal width, pixels
SshFlow flow
RFC 4254 sec 5.2 window pair (owner: ssh_flow_control.*).
uint32_t height_px
terminal height, pixels
uint32_t peer_id
Client's channel id.
embed_bool eof_sent
We sent CHANNEL_EOF (RFC 4254 sec 5.3).
void(*const set_sftp_open_cb)(const uint8_t *work)
void(*const set_rforward_cancel_cb)(const uint8_t *work)
void(*const window_change_parse)(const uint8_t *work)
void(*const channel_handle_eof)(const uint8_t *work)
void(*const dispatch)(uint8_t *work)
void(*const channel_handle_request)(uint8_t *work)
void(*const set_scp_data_cb)(const uint8_t *work)
void(*const set_scp_open_cb)(const uint8_t *work)
void(*const flow_replenish_due)(const uint8_t *work)
void(*const channel_handle_open)(const uint8_t *work)
void(*const set_pty_req_cb)(const uint8_t *work)
void(*const set_sftp_data_cb)(const uint8_t *work)
void(*const channel_pty)(const uint8_t *work)
void(*const flow_send_cap)(const uint8_t *work)
void(*const pty_req_parse)(const uint8_t *work)
void(*const channel_send_data)(uint8_t *work)
void(*const channel_build_eof)(const uint8_t *work)
void(*const channel_handle_close)(const uint8_t *work)
void(*const flow_send_allows)(const uint8_t *work)
void(*const flow_peer_add)(const uint8_t *work)
void(*const req_strings_present)(const uint8_t *work)
void(*const flow_send_take)(const uint8_t *work)
void(*const channel_send_exit_status)(const uint8_t *work)
void(*const set_rforward_open_cb)(const uint8_t *work)
void(*const channel_send_exit_signal)(const uint8_t *work)
void(*const channel_open_forwarded)(const uint8_t *work)
void(*const forward_begin)(const uint8_t *work)
void(*const chan_alloc)(const uint8_t *work)
void(*const channel_send_close)(uint8_t *work)
void(*const channel_bind_service)(const uint8_t *work)
void(*const channel_handle_extended_data)(const uint8_t *work)
void(*const set_forward_policy_cb)(const uint8_t *work)
void(*const forward_binding)(const uint8_t *work)
void(*const global_request_handle)(const uint8_t *work)
void(*const channel_init)(const uint8_t *work)
void(*const pty_req_fields_present)(uint8_t *work)
void(*const channel_handle_window_adjust)(const uint8_t *work)
void(*const pty_modes_valid)(const uint8_t *work)
void(*const chan_by_id)(const uint8_t *work)
void(*const set_forward_confirm_cb)(const uint8_t *work)
void(*const set_data_cb)(const uint8_t *work)
void(*const flow_init)(const uint8_t *work)
void(*const channel_send_open_forwarded)(uint8_t *work)
void(*const flow_recv_take)(const uint8_t *work)
void(*const set_forward_data_cb)(const uint8_t *work)
void(*const channel_handle_open_failure)(const uint8_t *work)
void(*const forward_reset)(const uint8_t *work)
void(*const channel_handle_data)(const uint8_t *work)
void(*const channel_build_data)(const uint8_t *work)
void(*const set_window_change_cb)(const uint8_t *work)
void(*const forward_pump)(uint8_t *work)
void(*const channel_send_eof)(uint8_t *work)
void(*const channel_build_close)(const uint8_t *work)
void(*const flow_local_credit)(const uint8_t *work)
void(*const set_forward_open_cb)(const uint8_t *work)
void(*const channel_handle_open_confirm)(const uint8_t *work)
SshForwardConfirmCb forward_confirm_cb
SshWindowChangeCb window_change_cb
SshForwardOpenCb forward_open_cb
SshRemoteForwardCancelCb rforward_cancel_cb
SshSftpDataCb sftp_data_cb
SshSftpOpenCb sftp_open_cb
SshForwardPolicyCb forward_policy_cb
SshRemoteForwardOpenCb rforward_open_cb
SshForwardDataCb forward_data_cb
Dispatch messages 80 to 127 (RFC 4254).
uint32_t peer_window
the peer's
uint32_t add
in: credit to add; out: what a replenish owes
uint32_t n
bytes a take accounts for
uint32_t local_window
our initial window
SshFlow * f
the window a call acts on
uint32_t want
bytes a send would like to put out
uint32_t peer_max_pkt
the largest packet it will take
size_t len
the length a send test measures
One channel's flow-control state (RFC 4254 sec 5.2).
uint32_t peer_max_pkt
Peer's maximum packet size; caps a single send independently of the window.
uint32_t local_max
The window we advertised, and replenish back up to.
uint32_t peer_window
Bytes we may still send the peer.
uint32_t local_window
Bytes the peer may still send us before we WINDOW_ADJUST.
RFC 4254 sec 7 TCP/IP forwarding: what a forwarding call names.
uint16_t orig_port
its port
const char * orig_addr
where the connection came from
const char * bind_addr
the address it bound
uint16_t bind_port
the port it bound
const char * conn_addr
the address connected to
uint16_t conn_port
its port
uint8_t out_slot
the slot that binding belongs to
uint8_t slot
the SSH slot a forward belongs to
uint8_t listener_idx
the listener row a binding lookup names
RFC 4254 sec 6.2 pty-req and sec 6.7 window-change: what a terminal call parses.
const uint8_t * modes
the encoded terminal modes
uint32_t height_rows
its height
uint32_t width_chars
the reported terminal width
uint8_t n
strings a presence check counts
uint32_t width_px
the same in pixels
size_t off
where the fields start
uint32_t consumed
what a mode walk consumed
SshPtyRequest * req
where a parse lands
uint32_t modes_len
their length
const uint8_t * p
the request bytes
Open a server-initiated "forwarded-tcpip" channel (RFC 4254 §7.2, ssh -R).
uint32_t width_px
terminal width, pixels
uint32_t height_rows
terminal height, rows
uint32_t height_px
terminal height, pixels
uint32_t modes_len
length of modes
const uint8_t * modes
encoded terminal modes, pointing into the request
char term[PROTOCORE_SSH_PTY_TERM_MAX]
TERM value, null-terminated, truncated to fit.
uint32_t width_chars
terminal width, characters