6#if PC_ENABLE_FORWARDED_TRUST
11struct pc_forwarded_trust_rule
19struct pc_forwarded_trust_ctx
24pc_forwarded_trust_ctx s_trust;
28void pc_forwarded_trust_reset(
void)
33bool pc_forwarded_trust_add(
const pc_ip *network, uint8_t prefix_len)
48 if (bits < 0 || prefix_len > (uint8_t)bits)
56 s_trust.rules[s_trust.count].network = *network;
57 s_trust.rules[s_trust.count].prefix_len = prefix_len;
62bool pc_forwarded_trust_add_cidr(
const char *cidr)
72 const char *slash =
nullptr;
74 for (
const char *p = cidr; *p; p++)
81 if (n + 1 >=
sizeof(addr))
97 uint8_t prefix = width;
102 const char *p = slash + 1;
109 if (*p <
'0' || *p >
'9')
113 v = v * 10 + (uint32_t)(*p -
'0');
122 return pc_forwarded_trust_add(&net, prefix);
125bool pc_forwarded_trust_contains(
const pc_ip *peer)
131 for (uint8_t i = 0; i < s_trust.count; i++)
141bool pc_forwarded_effective_ip(
const pc_ip *peer,
const char *fwd_ip_str,
pc_ip *out)
156 if (!peer || !pc_forwarded_trust_contains(peer))
160 if (!fwd_ip_str || !fwd_ip_str[0])
Trusted-reverse-proxy resolution of a forwarded client address (PC_ENABLE_FORWARDED_TRUST).
bool pc_ip_prefix_match(const pc_ip *addr, const pc_ip *net, uint8_t prefix_len)
CIDR containment: is addr inside the net / prefix_len block?
bool pc_ip_parse(const char *s, pc_ip *out)
Parse an IPv4 or IPv6 textual address (RFC 4291 ยง2.2) into out.
bool pc_ip_is_unspecified(const pc_ip *ip)
True if ip is empty (pc_ip_family::PC_IP_NONE) or the all-zero unspecified address (0....
@ PC_IP_NONE
empty / unparsed
@ PC_IP_V6
IPv6 (bytes[0..15])
@ PC_IP_V4
IPv4 (bytes[0..3])
#define PC_IP_STR_MAX
Longest text an pc_ip_format can produce, including the NUL (RFC 5952 v4-mapped).
#define PC_TRUSTED_PROXY_MAX
Number of trusted-upstream CIDR rules the forwarded-client resolver holds (BSS table).
A v4 or v6 address in network (big-endian) byte order.
pc_ip_family family
address family tag