Skip to content

Commit 119187e

Browse files
committed
Revert "Merge pull request #188 from expressvpn/multi-thread-support"
This reverts commit 9e867a4, reversing changes made to b98d3e9.
1 parent aa67b35 commit 119187e

24 files changed

+485
-674
lines changed

Diff for: .github/workflows/ci.yml

+2-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-22.04
1414
strategy:
1515
matrix:
16-
distro: [bookworm]
16+
distro: [bullseye, bookworm]
1717
env:
1818
FORCE_COLOR: 1
1919
steps:
@@ -46,20 +46,6 @@ jobs:
4646
./wolfcrypt/test/testwolfcrypt
4747
- name: Run build and test
4848
run: ceedling project:linux verbosity[4] test:all
49-
linux-multithread:
50-
runs-on: ubuntu-22.04
51-
steps:
52-
- uses: actions/checkout@v4
53-
- name: Install Ceedling
54-
run: sudo gem install ceedling -v 0.31.1 --no-user-install
55-
- name: Build dependencies
56-
run: ceedling project:linux_multithread verbosity[4] clobber dependencies:make
57-
- name: Run wolfSSL Tests
58-
run: |
59-
cd third_party/wolfssl
60-
./wolfcrypt/test/testwolfcrypt
61-
- name: Run build and test
62-
run: ceedling project:linux_multithread verbosity[4] test:all
6349
linux-386:
6450
runs-on: ubuntu-22.04
6551
steps:
@@ -182,7 +168,6 @@ jobs:
182168
config:
183169
[
184170
{ project: windows_64, arch: x64 },
185-
{ project: windows_64_multithread, arch: x64 },
186171
{ project: windows_32, arch: x86 },
187172
{ project: windows_arm64, arch: amd64_arm64 },
188173
]
@@ -196,7 +181,7 @@ jobs:
196181
uses: TheMrMilchmann/setup-msvc-dev@v3
197182
with:
198183
arch: ${{ matrix.config.arch }}
199-
- if: ${{ matrix.config.project != 'windows_arm64' }}
184+
- if: ${{ matrix.config.project != 'windows_arm64' }}
200185
# Skip making dependencies for ARM64 as we can only apply git patch once for WolfSSL
201186
name: Build dependencies
202187
run: ceedling project:${{ matrix.config.project }} verbosity[4] clobber dependencies:make

Diff for: 3rd_party_deps.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
--enable-dtls-frag-ch
1717
--enable-dtls-mtu
1818
--enable-secure-renegotiation
19-
--disable-singlethreaded
19+
--enable-singlethreaded
2020
--enable-sni
2121
--enable-sp=yes,4096
2222
--enable-static

Diff for: linux_multithread.yml

-12
This file was deleted.

Diff for: src/he/conn.c

+6-25
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ he_return_code_t he_internal_send_message(he_conn_t *conn, uint8_t *message, uin
473473
if(res == 0) {
474474
return HE_ERR_CONNECTION_WAS_CLOSED;
475475
} else {
476-
he_conn_set_ssl_error(conn, error);
476+
conn->wolf_error = error;
477477
return HE_ERR_SSL_ERROR;
478478
}
479479
}
@@ -536,7 +536,7 @@ bool he_internal_is_valid_state_for_server_config(he_conn_t *conn) {
536536
}
537537

538538
// The server config message is only valid after the TLS link is established
539-
switch((int)conn->state) {
539+
switch(conn->state) {
540540
case HE_STATE_LINK_UP:
541541
case HE_STATE_AUTHENTICATING:
542542
case HE_STATE_CONFIGURING:
@@ -746,7 +746,7 @@ he_return_code_t he_internal_renegotiate_ssl(he_conn_t *conn) {
746746
case SECURE_RENEGOTIATION_E:
747747
return HE_ERR_SECURE_RENEGOTIATION_ERROR;
748748
default:
749-
he_conn_set_ssl_error(conn, error);
749+
conn->wolf_error = error;
750750
return HE_ERR_SSL_ERROR;
751751
}
752752
}
@@ -1213,7 +1213,7 @@ he_return_code_t he_conn_start_pmtu_discovery(he_conn_t *conn) {
12131213
if(conn->pmtud_state_change_cb == NULL || conn->pmtud_time_cb == NULL) {
12141214
return HE_ERR_PMTUD_CALLBACKS_NOT_SET;
12151215
}
1216-
if(conn->pmtud.state != HE_PMTUD_STATE_DISABLED) {
1216+
if(conn->pmtud_state != HE_PMTUD_STATE_DISABLED) {
12171217
// PMTUD is already started
12181218
return HE_SUCCESS;
12191219
}
@@ -1223,10 +1223,10 @@ he_return_code_t he_conn_start_pmtu_discovery(he_conn_t *conn) {
12231223
}
12241224

12251225
uint16_t he_conn_get_effective_pmtu(he_conn_t *conn) {
1226-
if(!conn || conn->pmtud.effective_pmtu == 0 || conn->pmtud.state != HE_PMTUD_STATE_SEARCH_COMPLETE) {
1226+
if(!conn || conn->effective_pmtu == 0) {
12271227
return HE_MAX_MTU;
12281228
}
1229-
return conn->pmtud.effective_pmtu;
1229+
return conn->effective_pmtu;
12301230
}
12311231

12321232
he_return_code_t he_conn_pmtud_probe_timeout(he_conn_t *conn) {
@@ -1236,25 +1236,6 @@ he_return_code_t he_conn_pmtud_probe_timeout(he_conn_t *conn) {
12361236
return he_internal_pmtud_handle_probe_timeout(conn);
12371237
}
12381238

1239-
#ifdef HE_ENABLE_MULTITHREADED
1240-
// wolf_error as thread local variable, so it can be used
1241-
// from multiple threads without collision
1242-
HE_THREAD_LOCAL int wolf_error = 0;
1243-
#endif
1244-
1245-
void he_conn_set_ssl_error(he_conn_t *conn, int error) {
1246-
#ifdef HE_ENABLE_MULTITHREADED
1247-
(void) conn;
1248-
wolf_error = error;
1249-
#else
1250-
conn->wolf_error = error;
1251-
#endif
1252-
}
1253-
12541239
int he_conn_get_ssl_error(he_conn_t *conn) {
1255-
#ifdef HE_ENABLE_MULTITHREADED
1256-
return wolf_error;
1257-
#else
12581240
return conn->wolf_error;
1259-
#endif
12601241
}

Diff for: src/he/conn.h

-3
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,4 @@ he_return_code_t he_conn_pmtud_probe_timeout(he_conn_t *conn);
517517
*/
518518
int he_conn_get_ssl_error(he_conn_t* conn);
519519

520-
521-
void he_conn_set_ssl_error(he_conn_t *conn, int error);
522-
523520
#endif // CONN_H

Diff for: src/he/core.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
*/
1919

2020
#include "core.h"
21-
#include "conn.h"
2221

2322
he_return_code_t he_internal_setup_stream_state(he_conn_t *conn, uint8_t *data, size_t length) {
2423
if(conn->incoming_data_left_to_read != 0) {
2524
// Somehow this function was called without reading all data from a previous buffer
2625
// This is bad
27-
he_conn_set_ssl_error(conn, 0);
26+
conn->wolf_error = 0;
2827
return HE_ERR_SSL_ERROR;
2928
}
3029
// Set up the location of the buffer and its length

Diff for: src/he/flow.c

+39-42
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
#include <wolfssl/wolfcrypt/settings.h>
3636

3737
bool he_internal_flow_should_fragment(he_conn_t *conn, uint16_t effective_pmtu, uint16_t length) {
38-
return conn->connection_type == HE_CONNECTION_TYPE_DATAGRAM && length > effective_pmtu;
38+
return conn->connection_type == HE_CONNECTION_TYPE_DATAGRAM &&
39+
conn->pmtud_state == HE_PMTUD_STATE_SEARCH_COMPLETE && length > effective_pmtu;
3940
}
4041

4142
he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet, size_t length) {
@@ -69,9 +70,11 @@ he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet
6970
// Clamp the MSS if PMTU has been fixed
7071
he_return_code_t ret = HE_SUCCESS;
7172
uint16_t effective_pmtu = he_conn_get_effective_pmtu(conn);
72-
ret = he_internal_clamp_mss(packet, length, effective_pmtu - HE_MSS_OVERHEAD);
73-
if(ret != HE_SUCCESS) {
74-
return ret;
73+
if(conn->pmtud_state == HE_PMTUD_STATE_SEARCH_COMPLETE) {
74+
ret = he_internal_clamp_mss(packet, length, effective_pmtu - HE_MSS_OVERHEAD);
75+
if(ret != HE_SUCCESS) {
76+
return ret;
77+
}
7578
}
7679

7780
// Process the packet with plugins.
@@ -141,24 +144,26 @@ he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet
141144
return ret;
142145
}
143146

144-
he_return_code_t he_internal_flow_process_message(he_conn_t *conn, he_packet_buffer_t *read_packet) {
147+
he_return_code_t he_internal_flow_process_message(he_conn_t *conn) {
145148
// Return if conn is null
146-
if(!conn || !read_packet) {
149+
if(!conn) {
147150
return HE_ERR_NULL_POINTER;
148151
}
149152

150153
// If the packet is too small then either the client is sending corrupted data or something is
151154
// very wrong with the SSL connection
152-
if(read_packet->packet_size < sizeof(he_msg_hdr_t)) {
153-
read_packet->has_packet = false;
154-
he_conn_set_ssl_error(conn, 0);
155+
if(conn->read_packet.packet_size < sizeof(he_msg_hdr_t)) {
156+
conn->read_packet.has_packet = false;
157+
conn->wolf_error = 0;
155158
return HE_ERR_SSL_ERROR;
156159
}
157160

161+
he_packet_buffer_t *pkt_buff = &conn->read_packet;
162+
158163
// Cast the header
159-
he_msg_hdr_t *msg_hdr = (he_msg_hdr_t *)&read_packet->packet;
160-
uint8_t *buf = read_packet->packet;
161-
int buf_len = read_packet->packet_size;
164+
he_msg_hdr_t *msg_hdr = (he_msg_hdr_t *)&pkt_buff->packet;
165+
uint8_t *buf = pkt_buff->packet;
166+
int buf_len = pkt_buff->packet_size;
162167

163168
switch(msg_hdr->msgid) {
164169
case HE_MSGID_NOOP:
@@ -213,19 +218,19 @@ he_return_code_t he_internal_flow_process_message(he_conn_t *conn, he_packet_buf
213218
return HE_SUCCESS;
214219
}
215220

216-
he_return_code_t he_internal_flow_fetch_message(he_conn_t *conn, he_packet_buffer_t *read_packet) {
221+
he_return_code_t he_internal_flow_fetch_message(he_conn_t *conn) {
217222
// Return if conn is null
218-
if(!conn || !read_packet) {
223+
if(!conn) {
219224
return HE_ERR_NULL_POINTER;
220225
}
221226

222227
// Try to read out a packet
223228
int res =
224-
wolfSSL_read(conn->wolf_ssl, read_packet->packet, sizeof(read_packet->packet));
229+
wolfSSL_read(conn->wolf_ssl, conn->read_packet.packet, sizeof(conn->read_packet.packet));
225230

226231
if(res <= 0) {
227-
read_packet->has_packet = false;
228-
read_packet->packet_size = 0;
232+
conn->read_packet.has_packet = false;
233+
conn->read_packet.packet_size = 0;
229234

230235
int error = wolfSSL_get_error(conn->wolf_ssl, res);
231236
switch(error) {
@@ -234,7 +239,7 @@ he_return_code_t he_internal_flow_fetch_message(he_conn_t *conn, he_packet_buffe
234239
return HE_SUCCESS;
235240

236241
case APP_DATA_READY:
237-
return he_internal_flow_fetch_message(conn, read_packet);
242+
return he_internal_flow_fetch_message(conn);
238243

239244
case SSL_ERROR_WANT_READ:
240245
case SSL_ERROR_WANT_WRITE:
@@ -246,7 +251,7 @@ he_return_code_t he_internal_flow_fetch_message(he_conn_t *conn, he_packet_buffe
246251
if(res == 0) {
247252
return HE_ERR_CONNECTION_WAS_CLOSED;
248253
} else {
249-
he_conn_set_ssl_error(conn, error);
254+
conn->wolf_error = error;
250255
// if this is TCP then any SSL error is fatal (stream corruption).
251256
// If this is D/TLS we can actually ignore corrupted packets.
252257
if(conn->connection_type == HE_CONNECTION_TYPE_STREAM) {
@@ -257,8 +262,8 @@ he_return_code_t he_internal_flow_fetch_message(he_conn_t *conn, he_packet_buffe
257262
}
258263
}
259264
} else {
260-
read_packet->has_packet = true;
261-
read_packet->packet_size = res;
265+
conn->read_packet.has_packet = true;
266+
conn->read_packet.packet_size = res;
262267
}
263268

264269
return HE_SUCCESS;
@@ -335,12 +340,6 @@ he_return_code_t he_conn_outside_data_received(he_conn_t *conn, uint8_t *buffer,
335340
}
336341
}
337342

338-
#ifdef HE_ENABLE_MULTITHREADED
339-
HE_THREAD_LOCAL uint8_t *cur_packet = NULL;
340-
HE_THREAD_LOCAL size_t cur_packet_length = 0;
341-
HE_THREAD_LOCAL bool packet_seen = false;
342-
#endif
343-
344343
he_return_code_t he_internal_flow_outside_packet_received(he_conn_t *conn, uint8_t *packet,
345344
size_t length) {
346345
// Return if packet or conn is null
@@ -381,10 +380,11 @@ he_return_code_t he_internal_flow_outside_packet_received(he_conn_t *conn, uint8
381380

382381
// Update pointer and length in our connection state
383382
// We need to pull the wire header off first
384-
he_internal_set_packet(conn, packet + sizeof(he_wire_hdr_t), length - sizeof(he_wire_hdr_t));
383+
conn->incoming_data_length = length - sizeof(he_wire_hdr_t);
384+
conn->incoming_data = packet + sizeof(he_wire_hdr_t);
385385

386386
// Make sure that this packet is marked as unseen
387-
he_internal_set_packet_seen(conn, false);
387+
conn->packet_seen = false;
388388

389389
return HE_DISPATCH(he_internal_flow_outside_data_verify_connection, conn);
390390
}
@@ -410,13 +410,8 @@ he_return_code_t he_internal_flow_outside_data_verify_connection(he_conn_t *conn
410410
}
411411

412412
// Check to see if this is our first message and trigger an event change if it is
413-
#ifdef HE_ENABLE_MULTITHREADED
414-
bool expected = false;
415-
if (atomic_compare_exchange_strong(&conn->first_message_received, &expected, true)) {
416-
#else
417-
if (!conn->first_message_received) {
413+
if(!conn->first_message_received) {
418414
conn->first_message_received = true;
419-
#endif
420415
he_internal_generate_event(conn, HE_EVENT_FIRST_MESSAGE_RECEIVED);
421416
}
422417

@@ -439,7 +434,7 @@ he_return_code_t he_internal_flow_outside_data_verify_connection(he_conn_t *conn
439434
}
440435

441436
// We can't recover from any other errors
442-
he_conn_set_ssl_error(conn, error);
437+
conn->wolf_error = error;
443438
return HE_ERR_SSL_ERROR;
444439
}
445440

@@ -461,8 +456,6 @@ he_return_code_t he_internal_flow_outside_data_verify_connection(he_conn_t *conn
461456
}
462457

463458
he_return_code_t he_internal_flow_outside_data_handle_messages(he_conn_t *conn) {
464-
he_packet_buffer_t read_packet = { 0 };
465-
466459
// Return if conn is null
467460
if(!conn) {
468461
return HE_ERR_NULL_POINTER;
@@ -471,18 +464,18 @@ he_return_code_t he_internal_flow_outside_data_handle_messages(he_conn_t *conn)
471464
// Handle messages
472465
while(true) {
473466
// Do we have a message?
474-
he_return_code_t ret = he_internal_flow_fetch_message(conn, &read_packet);
467+
he_return_code_t ret = he_internal_flow_fetch_message(conn);
475468

476469
if(ret != HE_SUCCESS) {
477470
return ret;
478471
}
479472

480-
if(!read_packet.has_packet) {
473+
if(!conn->read_packet.has_packet) {
481474
break;
482475
}
483476

484477
// Process the message
485-
ret = he_internal_flow_process_message(conn, &read_packet);
478+
ret = he_internal_flow_process_message(conn);
486479

487480
if(ret != HE_SUCCESS) return ret;
488481
}
@@ -505,7 +498,7 @@ he_return_code_t he_internal_flow_outside_data_handle_messages(he_conn_t *conn)
505498
// D/TLS 1.3
506499
int wolf_rc = 0;
507500
if((wolf_rc = wolfSSL_key_update_response(conn->wolf_ssl, &resp_pending)) != 0) {
508-
he_conn_set_ssl_error(conn, wolfSSL_get_error(conn->wolf_ssl, wolf_rc));
501+
conn->wolf_error = wolfSSL_get_error(conn->wolf_ssl, wolf_rc);
509502
return HE_ERR_SSL_ERROR;
510503
}
511504
}
@@ -520,6 +513,10 @@ he_return_code_t he_internal_flow_outside_data_handle_messages(he_conn_t *conn)
520513
he_internal_update_timeout(conn);
521514
}
522515

516+
// Zero out the packet, ensures that if the connection is unused
517+
// for extended periods the old outdated data is cleared from memory
518+
memset(&conn->read_packet, 0, sizeof(conn->read_packet));
519+
523520
// All went well
524521
return HE_SUCCESS;
525522
}

0 commit comments

Comments
 (0)