C++20 port 3/14: compile crypto, config, DNS, ACL and plugin modules as C++ (#3067)

* Make the crypto, config, DNS and plugin modules compile as C++

Cast allocator and memchr results explicitly, pass mbedtls_operation_t
to mbedtls_cipher_setkey, and declare the two locals in
ss2022_encrypt_first() before the gotos that jump past them. Drop the
unused RESOLV_MODE global that resolv.c defined by accident through an
anonymous enum declaration. Still valid C.

* Raise the test origin's listen backlog

socketserver listens with a backlog of 5. With concurrent connections
through the proxy on a loaded machine (parallel ctest), the backlog
overflows, the kernel resets the origin connection, and the proxy
correctly drops the client, which surfaced as intermittent
alloc_audit_report failures ("getpeername: Invalid argument" in
ss-local, "Connection reset by peer" in ss-server). Reproduced
reliably at 64 concurrent connections; gone with a backlog of 256.

* Compile the crypto, config, DNS, ACL and plugin modules as C++

Rename netutils, jconf, stream, aead, aead2022, aead2022_udp, crypto,
acl, plugin, plugin_disabled and resolv from .c to .cpp without changing
their contents, and update source lists, snippet references, test
comments and debian/copyright.

The Doxygen source list and scripts/check_cli_docs.py now accept either
extension for each module, so the remaining programs can move one at a
time. The new .cpp files are added to the no-heap ratchet baseline.
This commit is contained in:
Max Lv
2026-10-15 09:52:17 +08:00
committed by GitHub
parent 384810efce
commit a577ae0927
25 changed files with 101 additions and 74 deletions
+9 -9
View File
@@ -103,23 +103,23 @@ A library `libshadowsocks-c` (legacy names `libshadowsocks-libev.*` are kept) is
**Shared by all binaries:**
- `utils.c` - logging, system utilities, `ss_malloc`/`ss_free`
- `jconf.c` / `json.cpp` - JSON config file parsing
- `netutils.c` - network address utilities
- `jconf.cpp` / `json.cpp` - JSON config file parsing
- `netutils.cpp` - network address utilities
- `cache.cpp` - uthash-based connection cache (UDP relay, AEAD-2022 tables)
- `udprelay.c` - UDP relay implementation (shared, but uses `#ifdef MODULE_*` for per-binary behavior)
- `ss_event.c` / `ss_event.h` - event loop API over libuv
- `resolv.c` - asynchronous DNS via c-ares
- `resolv.cpp` - asynchronous DNS via c-ares
**Crypto layer** (behind a common `crypto_t` function-pointer interface):
- `crypto.c` / `crypto.h` - crypto initialization, key derivation (HKDF), `buffer_t` management
- `stream.c` - legacy stream ciphers
- `aead.c` - AEAD ciphers (AES-GCM via Mbed TLS/libsodium, ChaCha20-Poly1305 via libsodium)
- `aead2022.c` / `aead2022_udp.c` - Shadowsocks 2022 (SIP022), BLAKE3 from `src/blake3`
- `crypto.cpp` / `crypto.h` - crypto initialization, key derivation (HKDF), `buffer_t` management
- `stream.cpp` - legacy stream ciphers
- `aead.cpp` - AEAD ciphers (AES-GCM via Mbed TLS/libsodium, ChaCha20-Poly1305 via libsodium)
- `aead2022.cpp` / `aead2022_udp.cpp` - Shadowsocks 2022 (SIP022), BLAKE3 from `src/blake3`
- `ppbloom.cpp` - ping-pong bloom filter for salt replay detection (`third_party/bloom`)
**ACL:** `acl.c` / `rule.cpp` / `ipset.cpp` - IP prefix sets and PCRE2/literal domain rules.
**ACL:** `acl.cpp` / `rule.cpp` / `ipset.cpp` - IP prefix sets and PCRE2/literal domain rules.
**Plugins:** `plugin.c` / `process.cpp` - SIP003 plugin subprocess management.
**Plugins:** `plugin.cpp` / `process.cpp` - SIP003 plugin subprocess management.
**C++ core:** `src/core/*.hpp` - header-only ownership and allocation primitives (pools, handles, fixed
buffers, arena, fixed hash map/LRU, intrusive list, bounded heap). See `docs/cpp-core.md`.
+1 -1
View File
@@ -49,7 +49,7 @@ Files: src/json.cpp src/json.h
Copyright: 2012-2014, James McLaughlin et al.
License: BSD-2-clause
Files: src/resolv.c src/resolv.h
Files: src/resolv.cpp src/resolv.h
Copyright: 2011-2014, Dustin Lundquist <dustin@null-ptr.net>
License: BSD-2-clause
+6 -1
View File
@@ -16,7 +16,12 @@ foreach(name IN LISTS DOC_NAMES)
endforeach()
set(DOC_SOURCES)
foreach(name local server tunnel redir manager utils aead stream)
list(APPEND DOC_SOURCES "${PROJECT_SOURCE_DIR}/src/${name}.c")
# Modules are moving from C to C++ one at a time.
if(EXISTS "${PROJECT_SOURCE_DIR}/src/${name}.cpp")
list(APPEND DOC_SOURCES "${PROJECT_SOURCE_DIR}/src/${name}.cpp")
else()
list(APPEND DOC_SOURCES "${PROJECT_SOURCE_DIR}/src/${name}.c")
endif()
endforeach()
list(APPEND DOC_SOURCES "${PROJECT_SOURCE_DIR}/src/ss-nat")
+10 -2
View File
@@ -98,13 +98,21 @@ def documented_options(source_name, sources):
return result
def module_source(sources, module):
"""Source file name for a program module; modules move from .c to .cpp."""
for suffix in ('.c', '.cpp'):
if module + suffix in sources:
return module + suffix
raise ValueError(f"No source file for module {module}")
def check(root=ROOT, rendered=None):
sources = {path.name: path.read_text(encoding='utf-8')
for path in (root / 'src').glob('*.c')}
for pattern in ('*.c', '*.cpp') for path in (root / 'src').glob(pattern)}
sources['ss-nat'] = (root / 'src/ss-nat').read_text(encoding='utf-8')
for module in PROGRAMS:
program = 'ss-' + module
filename = 'ss-nat' if module == 'nat' else module + '.c'
filename = 'ss-nat' if module == 'nat' else module_source(sources, module)
declared = options(sources[filename], shell=module == 'nat')
documented = documented_options(filename, sources)
missing = declared.keys() - documented.keys()
+8
View File
@@ -2,9 +2,17 @@
# Format: <path> <violations>. check_no_heap.py fails if a file gains
# violations, and also when it loses some, so the number here always goes
# down. Remove a file once it is rewritten on the src/core primitives.
src/aead.cpp 4
src/aead2022.cpp 3
src/aead2022_udp.cpp 5
src/cache.cpp 3
src/crypto.cpp 4
src/ipset.cpp 3
src/jconf.cpp 16
src/json.cpp 2
src/plugin.cpp 3
src/process.cpp 26
src/resolv.cpp 6
src/rule.cpp 2
src/ssurl.cpp 3
src/stream.cpp 3
+1 -1
View File
@@ -14,7 +14,7 @@ readonly CONFIG_DIR="/etc/shadowsocks-libev"
readonly SYSTEMD_UNIT_DIR="/etc/systemd/system"
readonly SYSTEMD_TEMPLATE="shadowsocks-libev-server@.service"
# AEAD ciphers supported by shadowsocks-libev (from src/aead.c)
# AEAD ciphers supported by shadowsocks-libev (from src/aead.cpp)
readonly AEAD_CIPHERS=(
"chacha20-ietf-poly1305"
"aes-256-gcm"
+12 -12
View File
@@ -9,16 +9,16 @@ endif ()
set(SS_ACL_SOURCE
acl.c
acl.cpp
ipset.cpp
rule.cpp
)
set(SS_CRYPTO_SOURCE
crypto.c
aead.c
aead2022.c
aead2022_udp.c
crypto.cpp
aead.cpp
aead2022.cpp
aead2022_udp.cpp
base64.cpp
)
@@ -40,20 +40,20 @@ target_compile_options(blake3 PRIVATE -Wno-error -Wno-unused-function)
set_target_properties(blake3 PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(SS_ENABLE_LEGACY)
list(APPEND SS_CRYPTO_SOURCE stream.c)
list(APPEND SS_CRYPTO_SOURCE stream.cpp)
endif()
if(SS_ENABLE_PLUGINS)
set(SS_PLUGIN_SOURCE plugin.c process.cpp)
set(SS_PLUGIN_SOURCE plugin.cpp process.cpp)
else()
set(SS_PLUGIN_SOURCE plugin_disabled.c)
set(SS_PLUGIN_SOURCE plugin_disabled.cpp)
endif()
set(SS_SHARED_SOURCES
ppbloom.cpp
utils.c
jconf.c
jconf.cpp
json.cpp
netutils.c
netutils.cpp
)
if (MINGW)
set(SS_SHARED_SOURCES ${SS_SHARED_SOURCES} winsock.c)
@@ -64,7 +64,7 @@ set(LIBSHADOWSOCKS_LIBEV_SOURCE
udprelay.c
cache.cpp
local.c
resolv.c
resolv.cpp
ssurl.cpp
${SS_CRYPTO_SOURCE}
${SS_PLUGIN_SOURCE}
@@ -89,7 +89,7 @@ set(SS_SERVER_SOURCE
${SS_SHARED_SOURCES}
udprelay.c
cache.cpp
resolv.c
resolv.cpp
server.c
${SS_CRYPTO_SOURCE}
${SS_PLUGIN_SOURCE}
View File
+3 -3
View File
@@ -335,7 +335,7 @@ aead_cipher_ctx_set_key(cipher_ctx_t *cipher_ctx, int enc)
return;
}
if (mbedtls_cipher_setkey(cipher_ctx->evp, cipher_ctx->skey,
cipher_ctx->cipher->key_len * 8, enc) != 0) {
cipher_ctx->cipher->key_len * 8, (mbedtls_operation_t)enc) != 0) {
FATAL("Cannot set mbed TLS cipher key");
}
if (mbedtls_cipher_reset(cipher_ctx->evp) != 0) {
@@ -360,11 +360,11 @@ aead_cipher_ctx_init(cipher_ctx_t *cipher_ctx, int method, int enc)
const cipher_kt_t *cipher = aead_get_cipher_type(method);
if (method == AES256GCM && crypto_aead_aes256gcm_is_available()) {
cipher_ctx->aes256gcm_ctx = ss_aligned_malloc(sizeof(aes256gcm_ctx));
cipher_ctx->aes256gcm_ctx = (aes256gcm_ctx *)ss_aligned_malloc(sizeof(aes256gcm_ctx));
memset(cipher_ctx->aes256gcm_ctx, 0, sizeof(aes256gcm_ctx));
} else {
cipher_ctx->aes256gcm_ctx = NULL;
cipher_ctx->evp = ss_malloc(sizeof(cipher_evp_t));
cipher_ctx->evp = (cipher_evp_t *)ss_malloc(sizeof(cipher_evp_t));
memset(cipher_ctx->evp, 0, sizeof(cipher_evp_t));
cipher_evp_t *evp = cipher_ctx->evp;
mbedtls_cipher_init(evp);
+6 -4
View File
@@ -246,7 +246,7 @@ ss2022_build_req_varhdr(const uint8_t *first, size_t first_len,
}
size_t total = addr_len + 2 + pad_len + payload_len;
uint8_t *buf = ss_malloc(total);
uint8_t *buf = (uint8_t *)ss_malloc(total);
memcpy(buf, first, addr_len);
store16_be(buf + addr_len, pad_len);
@@ -277,6 +277,8 @@ ss2022_emit_header(cipher_ctx_t *ctx, buffer_t *out, size_t *out_len,
size_t body_len = 0;
int body_owned = 0;
int rc = CRYPTO_ERROR;
size_t o;
int n;
if (ctx->role == CRYPTO_ROLE_CLIENT) {
if (ss2022_build_req_varhdr(first, first_len, &body, &body_len)
@@ -322,9 +324,9 @@ ss2022_emit_header(cipher_ctx_t *ctx, buffer_t *out, size_t *out_len,
+ body_len + SS2022_TAG_LEN, capacity);
memcpy(out->data, ctx->salt, salt_len);
size_t o = salt_len;
o = salt_len;
int n = ss2022_seal(ctx, (uint8_t *)out->data + o, fixed, fixed_len);
n = ss2022_seal(ctx, (uint8_t *)out->data + o, fixed, fixed_len);
if (n < 0)
goto done;
o += n;
@@ -595,7 +597,7 @@ ss2022_tcp_decrypt(buffer_t *ciphertext, cipher_ctx_t *ctx, size_t capacity)
return CRYPTO_NEED_MORE;
}
uint8_t *body = ss_malloc(want);
uint8_t *body = (uint8_t *)ss_malloc(want);
int n = ss2022_open(ctx, body,
(uint8_t *)chunk->data + chunk->idx, need);
if (n < 0) {
+5 -5
View File
@@ -179,7 +179,7 @@ window_update(ss2022_udp_session_t *s, uint64_t id)
static ss2022_udp_session_t *
session_new(cipher_t *cipher)
{
ss2022_udp_session_t *s = ss_malloc(sizeof(ss2022_udp_session_t));
ss2022_udp_session_t *s = (ss2022_udp_session_t *)ss_malloc(sizeof(ss2022_udp_session_t));
memset(s, 0, sizeof(ss2022_udp_session_t));
s->cipher = cipher;
return s;
@@ -285,7 +285,7 @@ body_seal(const cipher_t *cipher, const uint8_t *key,
tmp_ctx.cipher = &tmp_cipher;
/* Reuse the shared one-shot helper with an mbedTLS GCM context. */
tmp_ctx.evp = ss_malloc(sizeof(cipher_evp_t));
tmp_ctx.evp = (cipher_evp_t *)ss_malloc(sizeof(cipher_evp_t));
memset(tmp_ctx.evp, 0, sizeof(cipher_evp_t));
mbedtls_cipher_init(tmp_ctx.evp);
const cipher_kt_t *kt = mbedtls_cipher_info_from_string(
@@ -327,7 +327,7 @@ body_open(const cipher_t *cipher, const uint8_t *key,
memset(&tmp_ctx, 0, sizeof(tmp_ctx));
tmp_ctx.cipher = &tmp_cipher;
tmp_ctx.evp = ss_malloc(sizeof(cipher_evp_t));
tmp_ctx.evp = (cipher_evp_t *)ss_malloc(sizeof(cipher_evp_t));
memset(tmp_ctx.evp, 0, sizeof(cipher_evp_t));
mbedtls_cipher_init(tmp_ctx.evp);
const cipher_kt_t *kt = mbedtls_cipher_info_from_string(
@@ -377,7 +377,7 @@ aead_2022_encrypt_udp(buffer_t *plaintext, cipher_t *cipher, size_t capacity,
size_t hdr_len = SS2022_UDP_MIN_HDR + extra;
size_t body_len = hdr_len + plaintext->len;
uint8_t *body = ss_malloc(body_len);
uint8_t *body = (uint8_t *)ss_malloc(body_len);
size_t o = 0;
body[o++] = is_server ? SS2022_UDP_TYPE_SERVER : SS2022_UDP_TYPE_CLIENT;
@@ -407,7 +407,7 @@ aead_2022_encrypt_udp(buffer_t *plaintext, cipher_t *cipher, size_t capacity,
* main header || payload)
*/
size_t merged_len = SS2022_UDP_SEP_HDR_LEN + body_len;
uint8_t *merged = ss_malloc(merged_len);
uint8_t *merged = (uint8_t *)ss_malloc(merged_len);
memcpy(merged, s->tx_session_id, SS2022_SESSION_ID_LEN);
store64_be(merged + SS2022_SESSION_ID_LEN, s->tx_packet_id);
memcpy(merged + SS2022_UDP_SEP_HDR_LEN, body, body_len);
+3 -3
View File
@@ -1,5 +1,5 @@
/*
* aead_internal.h - Internal interface shared by aead.c and aead2022.c
* aead_internal.h - Internal interface shared by aead.cpp and aead2022.cpp
*
* Copyright (C) 2013 - 2026, Max Lv <max.c.lv@gmail.com>
*
@@ -54,7 +54,7 @@ is_aead_2022(int method)
|| method == CHACHA20POLY1305IETF2022;
}
/* Low-level one-shot AEAD operations implemented in aead.c */
/* Low-level one-shot AEAD operations implemented in aead.cpp */
int aead_cipher_encrypt(cipher_ctx_t *cipher_ctx,
uint8_t *c, size_t *clen,
uint8_t *m, size_t mlen,
@@ -67,7 +67,7 @@ int aead_cipher_decrypt(cipher_ctx_t *cipher_ctx,
uint8_t *n, uint8_t *k);
void aead_cipher_ctx_set_key(cipher_ctx_t *cipher_ctx, int enc);
/* AEAD-2022 pieces implemented in aead2022.c */
/* AEAD-2022 pieces implemented in aead2022.cpp */
int aead_get_role(void);
void ss2022_derive_subkey(const uint8_t *key, size_t key_len,
const uint8_t *salt, size_t salt_len,
+2 -2
View File
@@ -47,7 +47,7 @@ int
balloc(buffer_t *ptr, size_t capacity)
{
sodium_memzero(ptr, sizeof(buffer_t));
ptr->data = ss_malloc(capacity);
ptr->data = (char *)ss_malloc(capacity);
ptr->capacity = capacity;
return capacity;
}
@@ -59,7 +59,7 @@ brealloc(buffer_t *ptr, size_t len, size_t capacity)
return -1;
size_t real_capacity = max(len, capacity);
if (ptr->capacity < real_capacity) {
ptr->data = ss_realloc(ptr->data, real_capacity);
ptr->data = (char *)ss_realloc(ptr->data, real_capacity);
ptr->capacity = real_capacity;
}
return real_capacity;
+1 -1
View File
@@ -283,7 +283,7 @@ read_jconf(const char *file)
FATAL("Too large config file.");
}
buf = ss_malloc(pos + 1);
buf = (char *)ss_malloc(pos + 1);
if (buf == NULL) {
FATAL("No enough memory.");
}
+1 -1
View File
@@ -312,7 +312,7 @@ validate_hostname(const char *hostname, const int hostname_len)
const char *label = hostname;
while (label < hostname_end) {
size_t label_len = hostname_end - label;
const char *next_dot = memchr(label, '.', label_len);
const char *next_dot = (const char *)memchr(label, '.', label_len);
if (next_dot != NULL)
label_len = next_dot - label;
+1 -1
View File
@@ -137,7 +137,7 @@ start_obfsproxy(const char *plugin,
ss_process_arg(sub, "--data-dir");
buf_size = 20 + strlen(plugin) + strlen(remote_host)
+ strlen(remote_port) + strlen(local_host) + strlen(local_port);
buf = ss_malloc(buf_size);
buf = (char *)ss_malloc(buf_size);
snprintf(buf, buf_size, TEMPDIR "%s_%s:%s_%s:%s", plugin,
remote_host, remote_port, local_host, local_port);
ss_process_arg(sub, buf);
+7 -7
View File
@@ -94,7 +94,7 @@ static struct ss_loop *default_loop;
enum {
MODE_IPV4_FIRST = 0,
MODE_IPV6_FIRST = 1
} RESOLV_MODE;
};
static int resolv_mode = MODE_IPV4_FIRST;
@@ -207,7 +207,7 @@ resolv_start(const char *hostname, uint16_t port,
/*
* Wrap c-ares's call back in our own
*/
struct resolv_query *query = ss_malloc(sizeof(struct resolv_query));
struct resolv_query *query = (struct resolv_query *)ss_malloc(sizeof(struct resolv_query));
memset(query, 0, sizeof(struct resolv_query));
@@ -254,7 +254,7 @@ dns_query_v4_cb(void *arg, int status, int timeouts, struct hostent *he)
n++;
if (n > 0) {
struct sockaddr **new_responses = ss_realloc(query->responses,
struct sockaddr **new_responses = (struct sockaddr **)ss_realloc(query->responses,
(query->response_count + n)
* sizeof(struct sockaddr *));
@@ -264,7 +264,7 @@ dns_query_v4_cb(void *arg, int status, int timeouts, struct hostent *he)
query->responses = new_responses;
for (i = 0; i < n; i++) {
struct sockaddr_in *sa = ss_malloc(sizeof(struct sockaddr_in));
struct sockaddr_in *sa = (struct sockaddr_in *)ss_malloc(sizeof(struct sockaddr_in));
memset(sa, 0, sizeof(struct sockaddr_in));
sa->sin_family = AF_INET;
sa->sin_port = query->port;
@@ -316,7 +316,7 @@ dns_query_v6_cb(void *arg, int status, int timeouts, struct hostent *he)
n++;
if (n > 0) {
struct sockaddr **new_responses = ss_realloc(query->responses,
struct sockaddr **new_responses = (struct sockaddr **)ss_realloc(query->responses,
(query->response_count + n)
* sizeof(struct sockaddr *));
@@ -326,7 +326,7 @@ dns_query_v6_cb(void *arg, int status, int timeouts, struct hostent *he)
query->responses = new_responses;
for (i = 0; i < n; i++) {
struct sockaddr_in6 *sa = ss_malloc(sizeof(struct sockaddr_in6));
struct sockaddr_in6 *sa = (struct sockaddr_in6 *)ss_malloc(sizeof(struct sockaddr_in6));
memset(sa, 0, sizeof(struct sockaddr_in6));
sa->sin6_family = AF_INET6;
sa->sin6_port = query->port;
@@ -472,7 +472,7 @@ resolv_sock_state_cb(void *data, ares_socket_t s, int read, int write)
return;
}
if (!node) {
node = ss_malloc(sizeof(*node));
node = (struct resolv_io *)ss_malloc(sizeof(*node));
node->next = NULL;
*entry = node;
ss_io_init(&node->io, resolv_sock_cb, (int)s, events);
+2 -2
View File
@@ -211,7 +211,7 @@ stream_cipher_ctx_init(cipher_ctx_t *ctx, int method, int enc)
const char *ciphername = supported_stream_ciphers[method];
const cipher_kt_t *cipher = stream_get_cipher_type(method);
ctx->evp = ss_malloc(sizeof(cipher_evp_t));
ctx->evp = (cipher_evp_t *)ss_malloc(sizeof(cipher_evp_t));
memset(ctx->evp, 0, sizeof(cipher_evp_t));
cipher_evp_t *evp = ctx->evp;
@@ -274,7 +274,7 @@ cipher_ctx_set_nonce(cipher_ctx_t *cipher_ctx, uint8_t *nonce, size_t nonce_len,
LOGE("cipher_ctx_set_nonce(): Cipher context is null");
return;
}
if (mbedtls_cipher_setkey(evp, true_key, cipher->key_len * 8, enc) != 0) {
if (mbedtls_cipher_setkey(evp, true_key, cipher->key_len * 8, (mbedtls_operation_t)enc) != 0) {
mbedtls_cipher_free(evp);
FATAL("Cannot set mbed TLS cipher key");
}
+2 -2
View File
@@ -364,11 +364,11 @@ later on the command line override the values taken from the URL.
Set the cipher. The default is `chacha20-ietf-poly1305`.
AEAD cipher names from the source (availability depends on the build):
\snippet aead.c cli-aead-ciphers
\snippet aead.cpp cli-aead-ciphers
Legacy stream cipher names recognized by the source (disabled in minimal builds;
some require backend support):
\snippet stream.c cli-stream-ciphers
\snippet stream.cpp cli-stream-ciphers
The `2022-blake3-*` ciphers implement Shadowsocks 2022 (SIP022). They require
a base64-encoded pre-shared key supplied with `--key` or `--password` (*-k*): 16 bytes for
+13 -13
View File
@@ -117,7 +117,7 @@ set(TEST_NETUTILS_LIBS
ss_cares
)
ss_add_test(test_netutils
"test_netutils.c;${PROJECT_SOURCE_DIR}/src/netutils.c;${PROJECT_SOURCE_DIR}/src/utils.c"
"test_netutils.c;${PROJECT_SOURCE_DIR}/src/netutils.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"${TEST_NETUTILS_LIBS}")
# test_cache - expiration uses a platform monotonic clock
@@ -145,7 +145,7 @@ ss_add_test(test_rule
# test_acl - ACL precedence and prefix matching
set(TEST_ACL_LIBS ${TEST_RULE_LIBS})
ss_add_test(test_acl
"test_acl.c;${PROJECT_SOURCE_DIR}/src/acl.c;${PROJECT_SOURCE_DIR}/src/ipset.cpp;${PROJECT_SOURCE_DIR}/src/rule.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"test_acl.c;${PROJECT_SOURCE_DIR}/src/acl.cpp;${PROJECT_SOURCE_DIR}/src/ipset.cpp;${PROJECT_SOURCE_DIR}/src/rule.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"${TEST_ACL_LIBS}")
endif()
@@ -157,17 +157,17 @@ set(TEST_JCONF_LIBS
ss_cares
)
ss_add_test(test_jconf
"test_jconf.c;${PROJECT_SOURCE_DIR}/src/jconf.c;${PROJECT_SOURCE_DIR}/src/json.cpp;${PROJECT_SOURCE_DIR}/src/utils.c;${PROJECT_SOURCE_DIR}/src/netutils.c"
"test_jconf.c;${PROJECT_SOURCE_DIR}/src/jconf.cpp;${PROJECT_SOURCE_DIR}/src/json.cpp;${PROJECT_SOURCE_DIR}/src/utils.c;${PROJECT_SOURCE_DIR}/src/netutils.cpp"
"${TEST_JCONF_LIBS};${SS_MATH_LIBRARY}")
# Crypto sources shared by the tests that link the crypto layer. The AEAD-2022
# ciphers pull in BLAKE3 (linked as the `blake3` target) and the session-based
# UDP codec, so they must be built together with crypto.c.
# UDP codec, so they must be built together with crypto.cpp.
set(SS_CRYPTO_TEST_SOURCES
${PROJECT_SOURCE_DIR}/src/crypto.c
${PROJECT_SOURCE_DIR}/src/aead.c
${PROJECT_SOURCE_DIR}/src/aead2022.c
${PROJECT_SOURCE_DIR}/src/aead2022_udp.c
${PROJECT_SOURCE_DIR}/src/crypto.cpp
${PROJECT_SOURCE_DIR}/src/aead.cpp
${PROJECT_SOURCE_DIR}/src/aead2022.cpp
${PROJECT_SOURCE_DIR}/src/aead2022_udp.cpp
${PROJECT_SOURCE_DIR}/src/ppbloom.cpp
${PROJECT_SOURCE_DIR}/src/cache.cpp
${PROJECT_SOURCE_DIR}/src/base64.cpp
@@ -175,10 +175,10 @@ set(SS_CRYPTO_TEST_SOURCES
)
if(SS_ENABLE_LEGACY)
list(APPEND SS_CRYPTO_TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/stream.c)
list(APPEND SS_CRYPTO_TEST_SOURCES ${PROJECT_SOURCE_DIR}/src/stream.cpp)
endif()
# test_buffer - needs sodium and mbedtls for crypto.c buffer functions
# test_buffer - needs sodium and mbedtls for crypto.cpp buffer functions
ss_add_test(test_buffer
"test_buffer.c;${SS_CRYPTO_TEST_SOURCES}"
"ss_sodium;;ss_mbedcrypto;ss_ev;${TEST_PPBLOOM_LIBS};blake3;${SS_MATH_LIBRARY}")
@@ -229,7 +229,7 @@ ss_add_test(test_process
set_tests_properties(test_process PROPERTIES TIMEOUT 20)
ss_add_test(test_resolv
"test_resolv.c;${PROJECT_SOURCE_DIR}/src/resolv.c;${PROJECT_SOURCE_DIR}/src/utils.c"
"test_resolv.c;${PROJECT_SOURCE_DIR}/src/resolv.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"ss_ev;ss_cares;ss_sodium")
set_tests_properties(test_resolv PROPERTIES TIMEOUT 20)
@@ -238,13 +238,13 @@ if(SS_ENABLE_REGEX)
list(APPEND TEST_LITERAL_LIBS ss_pcre2)
endif()
ss_add_test(test_acl_literal
"test_acl_literal.c;${PROJECT_SOURCE_DIR}/src/acl.c;${PROJECT_SOURCE_DIR}/src/ipset.cpp;${PROJECT_SOURCE_DIR}/src/rule.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"test_acl_literal.c;${PROJECT_SOURCE_DIR}/src/acl.cpp;${PROJECT_SOURCE_DIR}/src/ipset.cpp;${PROJECT_SOURCE_DIR}/src/rule.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"${TEST_LITERAL_LIBS}")
ss_add_test(test_event "test_event.c" "ss_ev")
set_tests_properties(test_event PROPERTIES TIMEOUT 30)
ss_add_test(test_resolv_async
"test_resolv_async.c;${PROJECT_SOURCE_DIR}/src/resolv.c;${PROJECT_SOURCE_DIR}/src/utils.c"
"test_resolv_async.c;${PROJECT_SOURCE_DIR}/src/resolv.cpp;${PROJECT_SOURCE_DIR}/src/utils.c"
"ss_ev;ss_cares;ss_sodium")
set_tests_properties(test_resolv_async PROPERTIES TIMEOUT 30)
+4
View File
@@ -34,6 +34,10 @@ class UDPHandler(socketserver.BaseRequestHandler):
class TCPOrigin(socketserver.ThreadingTCPServer):
daemon_threads = True
# socketserver's default listen backlog is 5. Concurrent connections
# through the proxy overflow it on a loaded machine; the kernel then
# resets the origin connection, which looks like a proxy failure.
request_queue_size = 256
class UDPOrigin(socketserver.ThreadingUDPServer):
+1 -1
View File
@@ -19,7 +19,7 @@ int verbose = 0;
#include "utils.h"
#include "blake3/blake3.h"
/* Provide nonce_cache symbol needed by crypto.c */
/* Provide nonce_cache symbol needed by crypto.cpp */
struct cache *nonce_cache = NULL;
/* 32-byte and 16-byte PSKs in base64 */
+1 -1
View File
@@ -10,7 +10,7 @@ int verbose = 0;
#include "crypto.h"
/* Provide nonce_cache symbol needed by crypto.c */
/* Provide nonce_cache symbol needed by crypto.cpp */
struct cache *nonce_cache = NULL;
static void
+2 -2
View File
@@ -13,7 +13,7 @@ int verbose = 0;
#include "ppbloom.h"
#include "utils.h"
/* Provide nonce_cache symbol needed by crypto.c */
/* Provide nonce_cache symbol needed by crypto.cpp */
struct cache *nonce_cache = NULL;
static void
@@ -366,7 +366,7 @@ main(void)
#if SS_ENABLE_LEGACY
/* mbedTLS-backed ciphers and libsodium-backed ciphers use different
* code paths in stream.c, so cover both. */
* code paths in stream.cpp, so cover both. */
test_stream_multi_segment_roundtrip("aes-256-cfb");
test_stream_multi_segment_roundtrip("aes-256-ctr");
test_stream_multi_segment_roundtrip("camellia-128-cfb");