DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ssh_forward.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file ssh_forward.h
6 * @brief SSH direct-tcpip port-forwarding owner (the `ssh -L` target side).
7 *
8 * The forwarding owner that the channel codec's forward seam
9 * (ssh_channel_set_forward_open_cb / _data_cb) plugs into. The codec parses a
10 * direct-tcpip request and routes channel data; this layer does the actual I/O -
11 * it opens the outbound TCP connection through the client transport (det_client)
12 * and bridges bytes both ways - so no socket code leaks into the codec. One fixed
13 * table maps each forward channel to a client-transport connection; all storage is
14 * static (no heap). Compiled only when DETWS_SSH_PORT_FORWARD is set.
15 *
16 * Security: any authenticated client can ask the server to connect anywhere (an
17 * open proxy / SSRF surface), so forwarding is opt-in twice over - compiled out by
18 * default, and inert until the application calls ssh_forward_begin(). Install a
19 * policy callback to restrict the reachable targets.
20 */
21
22#ifndef DETERMINISTICESPASYNCWEBSERVER_SSH_FORWARD_H
23#define DETERMINISTICESPASYNCWEBSERVER_SSH_FORWARD_H
24
25#include "ServerConfig.h"
26
27#include <stdint.h>
28
29#if DETWS_SSH_PORT_FORWARD
30
31/**
32 * @brief Allow/deny policy for a forward target. Return true to permit the connect.
33 *
34 * @p host is NUL-terminated. If no policy is installed every post-authentication
35 * forward is permitted (an open proxy for authenticated users) - install one to
36 * restrict the reachable host:port set.
37 */
38typedef bool (*SshForwardPolicyCb)(const char *host, uint16_t port);
39
40/** @brief Install the forward-target policy (optional; default permits all). */
41void ssh_forward_set_policy_cb(SshForwardPolicyCb cb);
42
43/**
44 * @brief Enable direct-tcpip forwarding: install the channel forward callbacks.
45 *
46 * Call once after ssh_conn_setup(). Until then (or if DETWS_SSH_PORT_FORWARD is 0)
47 * the channel codec refuses every direct-tcpip open, so there is no open relay.
48 */
49void ssh_forward_begin(void);
50
51/**
52 * @brief Pump every forward on SSH connection @p ssh_slot: move buffered target
53 * bytes to the client (bounded by the channel's peer window) and propagate
54 * a close from either side. Called from the SSH connection poll each loop.
55 */
56void ssh_forward_pump(uint8_t ssh_slot);
57
58/** @brief Tear down all forwards on @p ssh_slot (its SSH connection is closing). */
59void ssh_forward_reset(uint8_t ssh_slot);
60
61#endif // DETWS_SSH_PORT_FORWARD
62#endif // DETERMINISTICESPASYNCWEBSERVER_SSH_FORWARD_H
User-facing configuration for DeterministicESPAsyncWebServer.