DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ssh_conn.cpp File Reference

TCP-transport ↔ SSH-protocol glue. More...

Go to the source code of this file.

Classes

struct  SshConnCtx
 

Functions

void ssh_conn_setup ()
 One-time setup: install the dispatcher's binary-packet emit callback.
 
const ProtoHandlerssh_proto_handler (void)
 
int ssh_conn_send (uint8_t ssh_slot, uint32_t channel, const uint8_t *data, size_t len)
 Send application data to the client over an SSH channel.
 
int ssh_conn_close_channel (uint8_t ssh_slot, uint32_t channel)
 Close an SSH channel from the server side: frame CHANNEL_EOF and CHANNEL_CLOSE as two binary packets and write them to the socket.
 
int ssh_conn_open_forwarded (uint8_t ssh_slot, const char *conn_addr, uint16_t conn_port, const char *orig_addr, uint16_t orig_port)
 Open a server-initiated "forwarded-tcpip" channel to the client (ssh -R): build the CHANNEL_OPEN (RFC 4254 §7.2) via the channel codec, frame + send it on ssh_slot's socket, and return the new local channel id. The client's CHANNEL_OPEN_CONFIRMATION (or FAILURE) later drives the forward-confirm callback.
 
void ssh_conn_poll (uint8_t conn_slot)
 Per-loop poll hook for an SSH connection (registered as the SSH protocol handler's on_poll). Drives the port-forwarding pump; a no-op when forwarding is compiled out.
 
void ssh_conn_accept (uint8_t conn_slot)
 Handle a new ConnProto::PROTO_SSH connection on conn_slot.
 
void ssh_conn_rx (uint8_t conn_slot)
 Drain conn_slot's receive ring buffer through the SSH stack.
 
void ssh_conn_close (uint8_t conn_slot)
 Tear down SSH state for conn_slot (disconnect / error).
 

Detailed Description

TCP-transport ↔ SSH-protocol glue.

Definition in file ssh_conn.cpp.

Function Documentation

◆ ssh_conn_setup()

void ssh_conn_setup ( )

One-time setup: install the dispatcher's binary-packet emit callback.

Called from ssh_proto_handler() (the accessor every consumer uses to install SSH), so registering the handler always wires the emit callback - it can never be forgotten. Idempotent. Until it runs, the dispatcher's emit callback is null and every framed SSH packet after the plaintext banner is silently dropped.

Definition at line 77 of file ssh_conn.cpp.

References ssh_server_set_emit_cb().

Referenced by ssh_proto_handler().

◆ ssh_proto_handler()

const ProtoHandler * ssh_proto_handler ( void  )

Definition at line 86 of file ssh_conn.cpp.

References ssh_conn_setup().

Referenced by proto_register_builtins().

◆ ssh_conn_send()

int ssh_conn_send ( uint8_t  ssh_slot,
uint32_t  channel,
const uint8_t *  data,
size_t  len 
)

Send application data to the client over an SSH channel.

Frames data as SSH_MSG_CHANNEL_DATA on channel channel, encrypts+MACs it, and writes it to the socket. ssh_slot and channel are the values passed to the data callback registered via ssh_channel_set_data_cb(). A single call sends at most one channel-data message (bounded by the peer's flow-control window).

Returns
Number of bytes sent, or -1 on error (bad slot, channel closed/unknown, peer window/packet limit, or no active connection).

Definition at line 97 of file ssh_conn.cpp.

References SshConnCtx::conn_for_ssh, conn_pool, det_conn_flush(), det_conn_send(), TcpConn::id, MAX_SSH_CONNS, scratch_alloc(), ssh_channel_build_data(), SSH_PKT_BUF_SIZE, ssh_pkt_send(), and SSH_WIRE_CAP.

◆ ssh_conn_close_channel()

int ssh_conn_close_channel ( uint8_t  ssh_slot,
uint32_t  channel 
)

Close an SSH channel from the server side: frame CHANNEL_EOF and CHANNEL_CLOSE as two binary packets and write them to the socket.

Used by the port-forwarding owner when the forwarded TCP peer closes.

Returns
0 on success, -1 on error (bad slot, channel closed/unknown, no active connection, or scratch exhausted).

Definition at line 126 of file ssh_conn.cpp.

References SshConnCtx::conn_for_ssh, conn_pool, det_conn_flush(), det_conn_send(), TcpConn::id, MAX_SSH_CONNS, scratch_alloc(), ssh_channel_build_close(), ssh_pkt_send(), and SSH_WIRE_CAP.

◆ ssh_conn_open_forwarded()

int ssh_conn_open_forwarded ( uint8_t  ssh_slot,
const char *  conn_addr,
uint16_t  conn_port,
const char *  orig_addr,
uint16_t  orig_port 
)

Open a server-initiated "forwarded-tcpip" channel to the client (ssh -R): build the CHANNEL_OPEN (RFC 4254 §7.2) via the channel codec, frame + send it on ssh_slot's socket, and return the new local channel id. The client's CHANNEL_OPEN_CONFIRMATION (or FAILURE) later drives the forward-confirm callback.

Parameters
conn_addr/ conn_port the forward's bound address/port (address connected).
orig_addr/ orig_port the peer that connected to the forwarded port (advisory).
Returns
the local channel id (>= 0), or -1 (no active connection, channel pool full, or scratch exhausted). Used by the remote-forward owner.

Definition at line 158 of file ssh_conn.cpp.

References SshConnCtx::conn_for_ssh, conn_pool, det_conn_flush(), det_conn_send(), TcpConn::id, MAX_SSH_CONNS, scratch_alloc(), ssh_channel_open_forwarded(), SSH_PKT_BUF_SIZE, ssh_pkt_send(), and SSH_WIRE_CAP.

◆ ssh_conn_poll()

void ssh_conn_poll ( uint8_t  conn_slot)

Per-loop poll hook for an SSH connection (registered as the SSH protocol handler's on_poll). Drives the port-forwarding pump; a no-op when forwarding is compiled out.

Definition at line 188 of file ssh_conn.cpp.

References SshConnCtx::conn_for_ssh, conn_pool, detws_millis(), SshPacketState::kex_active, SshSession::last_kex_ms, MAX_SSH_CONNS, SshSession::phase, TcpConn::proto_slot, SSH_PHASE_OPEN, ssh_pkt, SSH_PKT_BUF_SIZE, ssh_rekey_due(), SSH_REKEY_PACKET_THRESHOLD, SSH_REKEY_TIME_MS, ssh_sess, and ssh_transport_begin_rekey().

◆ ssh_conn_accept()

void ssh_conn_accept ( uint8_t  conn_slot)

Handle a new ConnProto::PROTO_SSH connection on conn_slot.

Allocates an SSH session slot, initializes the transport/packet/channel state, and sends the server identification banner. If no SSH slot is free the connection is aborted.

Definition at line 226 of file ssh_conn.cpp.

References SshConnCtx::close, SshConnCtx::conn_for_ssh, conn_pool, det_conn_close(), det_conn_flush(), det_conn_send(), TcpConn::id, MAX_SSH_CONNS, TcpConn::proto_slot, ssh_channel_init(), ssh_pkt_init(), ssh_transport_init(), and ssh_transport_server_banner().

◆ ssh_conn_rx()

void ssh_conn_rx ( uint8_t  conn_slot)

Drain conn_slot's receive ring buffer through the SSH stack.

Feeds the banner parser until the client identification string completes, then the binary-packet layer; complete messages are dispatched and any responses are written to the socket. Closes the connection if the protocol signals a fatal condition.

Definition at line 273 of file ssh_conn.cpp.

References SshConnCtx::close, SshConnCtx::conn_for_ssh, conn_pool, MAX_SSH_CONNS, SshSession::phase, TcpConn::proto_slot, RX_BUF_SIZE, SSH_PHASE_BANNER, SSH_PHASE_KEXINIT, ssh_pkt_recv(), ssh_sess, and ssh_transport_recv_banner().

◆ ssh_conn_close()

void ssh_conn_close ( uint8_t  conn_slot)

Tear down SSH state for conn_slot (disconnect / error).

Definition at line 311 of file ssh_conn.cpp.

References SshConnCtx::conn_for_ssh, conn_pool, DETWS_PROTO_SLOT_NONE, MAX_SSH_CONNS, TcpConn::proto_slot, and ssh_sess.