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);
187typedef void (*
SshChannelDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
201typedef int (*
SshForwardOpenCb)(uint8_t slot, uint32_t channel,
const char *host,
size_t host_len, uint16_t port);
204typedef void (*
SshForwardDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
239typedef void (*
SshSftpDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
241#if PROTOCORE_ENABLE_SSH_SFTP
247typedef void (*
SshScpOpenCb)(uint8_t slot, uint32_t channel,
const char *cmd,
size_t cmd_len);
249typedef void (*
SshScpDataCb)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
251#if PROTOCORE_ENABLE_SSH_SCP
382typedef void (*
SshWindowChangeCb)(uint8_t i, uint32_t channel, uint32_t width_chars, uint32_t height_rows,
383 uint32_t width_px, uint32_t height_px);
415#if PROTOCORE_ENABLE_SSH_SFTP || PROTOCORE_ENABLE_SSH_SCP
477#define SSH_CHANNEL_EOF_LEN 5u
480#define SSH_CHANNEL_CLOSE_LEN 5u
528#if PROTOCORE_SSH_PORT_FORWARD
679 void (*
const flow_init)(uint8_t *work);
680 void (*
const flow_recv_take)(uint8_t *work);
681 void (*
const flow_replenish_due)(uint8_t *work);
682 void (*
const flow_local_credit)(uint8_t *work);
683 void (*
const flow_send_allows)(uint8_t *work);
684 void (*
const flow_send_cap)(uint8_t *work);
685 void (*
const flow_send_take)(uint8_t *work);
686 void (*
const flow_peer_add)(uint8_t *work);
687 void (*
const channel_init)(uint8_t *work);
688 void (*
const chan_alloc)(uint8_t *work);
689 void (*
const chan_by_id)(uint8_t *work);
690 void (*
const channel_bind_service)(uint8_t *work);
691 void (*
const channel_handle_open)(uint8_t *work);
692 void (*
const channel_handle_open_confirm)(uint8_t *work);
693 void (*
const channel_handle_open_failure)(uint8_t *work);
694 void (*
const channel_handle_request)(uint8_t *work);
695 void (*
const channel_handle_data)(uint8_t *work);
696 void (*
const channel_handle_extended_data)(uint8_t *work);
697 void (*
const channel_handle_window_adjust)(uint8_t *work);
698 void (*
const channel_handle_eof)(uint8_t *work);
699 void (*
const channel_handle_close)(uint8_t *work);
700 void (*
const channel_build_data)(uint8_t *work);
701 void (*
const channel_build_eof)(uint8_t *work);
702 void (*
const channel_build_close)(uint8_t *work);
703 void (*
const channel_send_data)(uint8_t *work);
704 void (*
const channel_send_eof)(uint8_t *work);
705 void (*
const channel_send_close)(uint8_t *work);
706 void (*
const channel_send_exit_status)(uint8_t *work);
707 void (*
const channel_send_exit_signal)(uint8_t *work);
708 void (*
const channel_open_forwarded)(uint8_t *work);
709 void (*
const channel_send_open_forwarded)(uint8_t *work);
710 void (*
const channel_pty)(uint8_t *work);
711 void (*
const req_strings_present)(uint8_t *work);
712 void (*
const pty_req_fields_present)(uint8_t *work);
713 void (*
const pty_modes_valid)(uint8_t *work);
714 void (*
const pty_req_parse)(uint8_t *work);
715 void (*
const window_change_parse)(uint8_t *work);
716 void (*
const forward_begin)(uint8_t *work);
717 void (*
const forward_pump)(uint8_t *work);
718 void (*
const forward_binding)(uint8_t *work);
719 void (*
const forward_reset)(uint8_t *work);
720 void (*
const global_request_handle)(uint8_t *work);
721 void (*
const dispatch)(uint8_t *work);
722 void (*
const set_data_cb)(uint8_t *work);
723 void (*
const set_pty_req_cb)(uint8_t *work);
724 void (*
const set_window_change_cb)(uint8_t *work);
725 void (*
const set_forward_open_cb)(uint8_t *work);
726 void (*
const set_forward_data_cb)(uint8_t *work);
727 void (*
const set_forward_confirm_cb)(uint8_t *work);
728 void (*
const set_forward_policy_cb)(uint8_t *work);
729 void (*
const set_rforward_open_cb)(uint8_t *work);
730 void (*
const set_rforward_cancel_cb)(uint8_t *work);
731 void (*
const set_sftp_open_cb)(uint8_t *work);
732 void (*
const set_sftp_data_cb)(uint8_t *work);
733 void (*
const set_scp_open_cb)(uint8_t *work);
734 void (*
const set_scp_data_cb)(uint8_t *work);
#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).
PROTO_ENUM_PACKED
Application protocol spoken on a listener port or connection slot.
void protocore_ssh_connection_set_sftp_open_cb(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(uint8_t *work)
void protocore_ssh_connection_channel_handle_close(uint8_t *work)
void protocore_ssh_connection_set_scp_data_cb(uint8_t *work)
void protocore_ssh_connection_set_window_change_cb(uint8_t *work)
void protocore_ssh_connection_channel_handle_open(uint8_t *work)
void protocore_ssh_connection_forward_binding(uint8_t *work)
proto_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_extended_data(uint8_t *work)
void protocore_ssh_connection_channel_send_exit_signal(uint8_t *work)
void protocore_ssh_connection_forward_pump(uint8_t *work)
void protocore_ssh_connection_set_rforward_open_cb(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_data_cb(uint8_t *work)
proto_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_channel_handle_request(uint8_t *work)
void protocore_ssh_connection_flow_peer_add(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_set_forward_open_cb(uint8_t *work)
void protocore_ssh_connection_channel_open_forwarded(uint8_t *work)
void(* SshForwardConfirmCb)(uint8_t slot, uint32_t channel, proto_bool ok)
Install the remote-forward (ssh -R) open-policy callback (opt-in).
void protocore_ssh_connection_flow_local_credit(uint8_t *work)
void protocore_ssh_connection_channel_build_eof(uint8_t *work)
void protocore_ssh_connection_flow_send_cap(uint8_t *work)
void protocore_ssh_connection_channel_send_exit_status(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_global_request_handle(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).
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_forward_begin(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_channel_build_close(uint8_t *work)
uint8_t * protocore_ssh_connection_span(void)
The PROTOCORE_SSH_CONNECTION_BORROW bytes this module's state lives in.
enum PROTO_ENUM_PACKED SshChanType
Channel type (RFC 4254).
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_cancel_cb(uint8_t *work)
void protocore_ssh_connection_flow_send_take(uint8_t *work)
void protocore_ssh_connection_channel_build_data(uint8_t *work)
void protocore_ssh_connection_req_strings_present(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_pty_req_cb(uint8_t *work)
void protocore_ssh_connection_pty_modes_valid(uint8_t *work)
void protocore_ssh_connection_channel_bind_service(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_set_forward_policy_cb(uint8_t *work)
void protocore_ssh_connection_channel_pty(uint8_t *work)
void protocore_ssh_connection_channel_handle_window_adjust(uint8_t *work)
void protocore_ssh_connection_set_forward_data_cb(uint8_t *work)
@ SSH_CHAN_FORWARDED_TCPIP
"forwarded-tcpip" - server-initiated TCP forward (ssh -R)
@ SSH_CHAN_SERVICE_SFTP
subsystem "sftp" (PROTOCORE_ENABLE_SSH_SFTP)
@ SSH_CHAN_DIRECT_TCPIP
"direct-tcpip" - client-initiated TCP forward (ssh -L)
@ SSH_CHAN_SERVICE_SCP
exec "scp ..." (PROTOCORE_ENABLE_SSH_SCP)
@ SSH_CHAN_SERVICE_NONE
shell / exec output, handed to the channel-data callback
@ SSH_CHAN_SESSION
"session" - shell / exec / data
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.
SshConnectionVars SshConnectionV
The operands and the outcome.
void protocore_ssh_connection_set_forward_confirm_cb(uint8_t *work)
void protocore_ssh_connection_channel_handle_open_failure(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.
void protocore_ssh_connection_flow_init(uint8_t *work)
void protocore_ssh_connection_channel_handle_eof(uint8_t *work)
void protocore_ssh_connection_channel_handle_open_confirm(uint8_t *work)
void protocore_ssh_connection_pty_req_fields_present(uint8_t *work)
void protocore_ssh_connection_channel_send_close(uint8_t *work)
void protocore_ssh_connection_set_scp_open_cb(uint8_t *work)
void protocore_ssh_connection_forward_reset(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_flow_send_allows(uint8_t *work)
void protocore_ssh_connection_chan_alloc(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.
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_set_sftp_data_cb(uint8_t *work)
void protocore_ssh_connection_channel_send_data(uint8_t *work)
enum PROTO_ENUM_PACKED SshChanService
What a session channel's sec 6 request bound to it, if anything.
void protocore_ssh_connection_channel_handle_data(uint8_t *work)
void protocore_ssh_connection_window_change_parse(uint8_t *work)
void protocore_ssh_connection_flow_replenish_due(uint8_t *work)
void protocore_ssh_connection_channel_init(uint8_t *work)
void protocore_ssh_connection_chan_by_id(uint8_t *work)
void protocore_ssh_connection_pty_req_parse(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
const uint8_t * rtype
sec 5.4 request type
SshChanService service
the service a bind attaches
proto_bool core_dumped
whether it dumped core
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
proto_bool pty
A "pty-req" was accepted on this channel.
proto_bool pending
True for a server-initiated channel we opened, awaiting the client's confirmation.
proto_bool relay_eof
The peer sent CHANNEL_EOF.
SshChanType type
session, direct-tcpip, or forwarded-tcpip.
proto_bool close_received
The peer sent CHANNEL_CLOSE.
uint32_t height_rows
terminal height, rows
uint32_t local_id
Our channel id (== slot index).
proto_bool close_sent
We sent CHANNEL_CLOSE.
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.
proto_bool eof_sent
We sent CHANNEL_EOF (RFC 4254 sec 5.3).
proto_bool open
True once the channel is confirmed open both ways.
void(*const flow_init)(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
uint32_t width_chars
terminal width, characters
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
_Bool proto_bool
The truth value.
#define PROTOCORE_END_DECLS