ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
server.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file server.h
6 * @brief The server engine: the handler the session loop installs.
7 */
8
9#ifndef PROTOCORE_SERVER_SERVER_H
10#define PROTOCORE_SERVER_SERVER_H
11
13
15
16struct ProtoHandler;
17
18/** @brief The SSH ProtoHandler the builtins list installs. */
19
20#if PROTOCORE_SSH_PORT_FORWARD
21/**
22 * @brief The ProtoHandler for sockets accepted on a forwarded listener (RFC 4254 sec 7.2).
23 *
24 * Listening is this role's (sec 4.1); the sec 7.1 bindings that decide which listeners exist are
25 * the connection protocol's. The builtins list installs this handler.
26 */
27
28/**
29 * @brief Start listening on @p bind_port for a sec 7.1 remote forward.
30 *
31 * "The 'address to bind' and 'port number to bind' specify the IP address... and port on which
32 * connections for forwarding are to be accepted." Which bindings exist is the connection protocol's
33 * decision; the socket that accepts on one is this role's, so the pool it comes from is here.
34 *
35 * @return An opaque handle for ssh_rfwd_listener_close() and protocore_ssh_forward_binding(),
36 * or -1 when there is no listener capacity or the port could not be bound.
37 */
38
39/** @brief Stop accepting on a handle from ssh_rfwd_listener_open(). Open bridges are unaffected. */
40#endif
41
42/**
43 * @brief The SSH server role (RFC 4253 sec 4.1): the side that accepts a connection.
44 *
45 * A caller sets the members a call takes, invokes it through ::SshServer, and reads the outcome off
46 * the same handle.
47 *
48 * @var SshServerNs::bind_port the port a remote forward (RFC 4254 sec 7.1) binds
49 * @var SshServerNs::handle the listener a close releases
50 * @var SshServerNs::i32 the listener an open reports, or < 0
51 * @var SshServerNs::handler the ProtoHandler a lookup reports
52 * @var SshServerNs::rfwd_listener_open bind a port for an accepted remote forward
53 * @var SshServerNs::rfwd_listener_close release one
54 * @var SshServerNs::proto_handler the dispatch seam an SSH slot is driven through
55 * @var SshServerNs::rfwd_proto_handler the same for a forwarded slot
56 */
57typedef struct
58{
59 uint16_t bind_port;
60 int handle;
61 int i32;
62 const struct ProtoHandler *handler;
64
65/** @brief The operands and the outcome. */
67
68/** @brief The entries. */
69typedef struct
70{
71 void (*const rfwd_listener_open)(uint8_t *work);
72 void (*const rfwd_listener_close)(uint8_t *work);
73 void (*const proto_handler)(uint8_t *work);
74 void (*const rfwd_proto_handler)(uint8_t *work);
76
77// What the table binds, defined once in the .c and taking one parameter each: everything
78// else an entry needs is an operand in SshServerV or a region of the borrow at a fixed offset.
83
84// `static const`, initialised HERE rather than `extern` against a definition in the .c: a
85// const object whose initializer every translation unit can see is a COMPILE-TIME FACT, so
86// `SshServer.rfwd_listener_open(work)` resolves to a named function and becomes a DIRECT call. An extern table
87// leaves the call indirect and the symbol live at every level, -O2 -flto included.
88static const SshServerNs SshServer __attribute__((unused)) = {
90 .rfwd_listener_close = protocore_ssh_server_rfwd_listener_close,
92 .rfwd_proto_handler = protocore_ssh_server_rfwd_proto_handler,
93};
94
95/**
96 * @brief The PROTOCORE_SSH_SERVER_BORROW bytes this module's state lives in.
97 *
98 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
99 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
100 * walks, so the state lasts the life of the program.
101 *
102 * @return the span.
103 */
105
107
108#endif // PROTOCORE_SERVER_SERVER_H
Root infrastructure: fixed widths, serializers, opcodes and sizes, for every layer above.
void protocore_ssh_server_proto_handler(uint8_t *work)
SshServerVars SshServerV
The operands and the outcome.
void protocore_ssh_server_rfwd_proto_handler(uint8_t *work)
void protocore_ssh_server_rfwd_listener_close(uint8_t *work)
void protocore_ssh_server_rfwd_listener_open(uint8_t *work)
uint8_t * protocore_ssh_server_span(void)
The PROTOCORE_SSH_SERVER_BORROW bytes this module's state lives in.
Per-protocol connection event/poll callbacks (the server's dispatch vtable).
The entries.
Definition server.h:70
void(*const rfwd_listener_open)(uint8_t *work)
Definition server.h:71
const struct ProtoHandler * handler
Definition server.h:62
uint16_t bind_port
Definition server.h:59
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
#define PROTOCORE_END_DECLS
Definition types.h:97