[COLOR=var(--gl-text-color-subtle)]
* Document cs_inet_ntoa startup-only init guard[/COLOR]
Clarify that inet_ntoa_key_initialized is set during single-threaded
startup and is only a misuse guard, not synchronization for lazy
runtime initialization.
* oscam-net: move cs_inet_ntoa TLS init to startup
Initialize the cs_inet_ntoa TLS key from main() instead of using
pthread_once in the hot path.
Also harden the new startup-based initialization by making
cs_inet_ntoa_init() idempotent, failing fast on use-before-init or
TLS setup failures, and returning the writable buffer on inet_ntop
errors instead of a string literal.
* fix(net): make cs_inet_ntoa thread-safe and IPv6-safe at call sites
The existing cs_inet_ntoa() implementation was not thread-safe:
- with IPV6SUPPORT it returned a single static buffer
- without IPV6SUPPORT it returned inet_ntoa(), which also uses shared static storage
That meant concurrent calls from different threads could overwrite each
other's result. A review comment suggested locking around all callers, but
that would be fragile and easy to miss given the large number of call sites.
This change fixes the problem centrally in cs_inet_ntoa() by replacing the
shared storage with per-thread rotating buffers stored via pthread TLS.
That keeps the existing API intact while making concurrent callers safe.
Changes included:
- add pthread_once/pthread_key based TLS storage for cs_inet_ntoa()
- use a small rotating per-thread buffer set so multiple calls in one
expression/thread can coexist briefly
- replace the IPv4 inet_ntoa() path with inet_ntop(AF_INET, ...)
- handle TLS setup/allocation failure safely by returning an empty string
instead of risking writes through invalid storage
- clear/check inet_ntop() output so failed conversions do not leak stale
data from a reused slot
In addition, clean up several callers and builders that assumed IPv4-sized
address strings:
- widen temporary IP buffers to INET6_ADDRSTRLEN in oscam-client.c,
oscam-cache.c, and oscam-ecm.c
- enlarge the disconnect log buffer in oscam-client.c
- update mk_t_iprange() sizing in oscam-conf-mk.c so serialized ranges have
enough room for full IPv6 addresses
Behavioral notes:
- no caller API changes are required
- cs_inet_ntoa() still returns temporary storage and callers should still
copy the string if they need to keep it
- logs/WebIf/config serialization may now contain full IPv6 addresses where [COLOR=var(--gl-text-color-subtle)]
output was previously truncated or racy[/COLOR]