ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
diffserv.cpp
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 diffserv.cpp
6 * @brief DiffServ QoS marking (RFC 2474) - the two server-wide DSCP defaults.
7 *
8 * Owns the default DSCP applied to outbound TCP connections and the default for UDP datagrams. The
9 * per-listener override (pc_listen_set_dscp) lives in listener.cpp and the per-connection setter
10 * (pc_conn_set_dscp) in tcp.cpp - each next to the pcb pool it touches - but both read these defaults.
11 */
12
13#include "diffserv.h"
14
15#if PC_ENABLE_DIFFSERV
16
17namespace
18{
19/// The single owner of all DiffServ file-scope state.
20struct DiffServCtx
21{
22 uint8_t tcp_dscp; ///< server-wide default DSCP for outbound TCP connections (0 = best-effort)
23 uint8_t udp_dscp; ///< default DSCP for outbound UDP datagrams (0 = best-effort)
24};
25DiffServCtx s_diffserv = {0, 0};
26} // namespace
27
28void pc_set_default_dscp(uint8_t dscp)
29{
30 s_diffserv.tcp_dscp = (uint8_t)(dscp & 0x3F);
31}
32
33uint8_t pc_diffserv_default_dscp(void)
34{
35 return s_diffserv.tcp_dscp;
36}
37
38void pc_udp_set_dscp(uint8_t dscp)
39{
40 s_diffserv.udp_dscp = (uint8_t)(dscp & 0x3F);
41}
42
43uint8_t pc_diffserv_udp_dscp(void)
44{
45 return s_diffserv.udp_dscp;
46}
47
48#endif // PC_ENABLE_DIFFSERV
Layer 4 (Transport) - DiffServ QoS marking (RFC 2474) for outbound traffic.