Skip to content

Commit

Permalink
fixup: LIT-134 implementing pmtud state machines
Browse files Browse the repository at this point in the history
  • Loading branch information
expressvpn-tom-l committed Oct 9, 2023
1 parent b1c1abe commit 3e5559f
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 17 deletions.
19 changes: 7 additions & 12 deletions src/he/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "conn.h"
#include "conn_internal.h"
#include "core.h"
#include "config.h"
#include "ssl_ctx.h"
#include "pmtud.h"

#ifndef WOLFSSL_USER_SETTINGS
#include <wolfssl/options.h>
#endif
#include <wolfssl/error-ssl.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/settings.h>

#include "conn.h"
#include "conn_internal.h"
#include "core.h"
#include "config.h"
#include "ssl_ctx.h"
#include "pmtud.h"
#include "memory.h"

bool he_conn_is_error_fatal(he_conn_t *conn, he_return_code_t error_msg) {
Expand Down Expand Up @@ -1189,11 +1187,8 @@ he_return_code_t he_conn_start_pmtu_discovery(he_conn_t *conn) {
return HE_ERR_INVALID_CONN_STATE;
}

// Generate event
he_internal_generate_event(conn, HE_EVENT_PMTU_DISCOVERY_STARTED);

// Enter Base state
conn->pmtud_state = HE_PMTUD_STATE_BASE;
he_internal_change_pmtud_state(conn, HE_PMTUD_STATE_BASE);

return HE_SUCCESS;
}
Expand Down
7 changes: 5 additions & 2 deletions src/he/he_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,17 @@ struct he_conn {
/// Identifier of the ping message pending reply
uint16_t ping_pending_id;

/// Path MTU Discovery
/// Path MTU Discovery state
he_pmtud_state_t pmtud_state;

/// Current effective PMTU
uint16_t effective_pmtu;

/// PMTUD internal data
uint16_t base_pmtu;
uint16_t pmtud_base;
uint8_t pmtud_probe_count;
uint16_t pmtud_probing_size;
bool pmtud_is_using_big_step;
};

struct he_plugin_chain {
Expand Down
80 changes: 80 additions & 0 deletions src/he/pmtud.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,86 @@ he_return_code_t he_internal_pmtud_send_probe(he_conn_t *conn, uint16_t probe_mt
void he_internal_pmtud_pong_received(he_conn_t *conn) {
}

void he_internal_change_pmtud_state(he_conn_t *conn, he_pmtud_state_t state) {
if(conn == NULL || conn->pmtud_state == state) {
return;
}

switch(conn->state) {
case HE_PMTUD_STATE_DISABLED:
switch(state) {
case HE_PMTUD_STATE_BASE:
// DISABLED -> BASE
he_internal_generate_event(conn, HE_EVENT_PMTU_DISCOVERY_STARTED);

// Initialize PMTU internal data
conn->pmtud_base = HE_MAX_MTU;
conn->pmtud_is_using_big_step = true;
conn->pmtud_probe_count = 0;

// TODO: start timers?
break;
default:
// Invalid state transition, do nothing
return;
}
break;
case HE_PMTUD_STATE_BASE:
switch(state) {
case HE_PMTUD_STATE_SEARCHING:
// TODO: enter searching state
break;
case HE_PMTUD_STATE_ERROR:
// TODO: enter error state
break;
case HE_PMTUD_STATE_SEARCH_COMPLETE:
// TODO: enter search complete state
break;
default:
// Invalid state transition, do nothing
return;
}
break;
case HE_PMTUD_STATE_SEARCHING:
switch(state) {
case HE_PMTUD_STATE_BASE:
// TODO: Return to Base when blackhole is detected
break;
case HE_PMTUD_STATE_SEARCH_COMPLETE:
// TODO: Probe acked
break;
default:
// Invalid state transition, do nothing
return;
}
break;
case HE_PMTUD_STATE_ERROR:
switch(state) {
case HE_PMTUD_STATE_SEARCHING:
// TODO: Enter Searching state when probe succeeds
break;
default:
// Invalid state transition, do nothing
return;
}
break;
case HE_PMTUD_STATE_SEARCH_COMPLETE:
switch(state) {
case HE_PMTUD_STATE_BASE:
// TODO: enter Base state if MAX_PROBES successive PLPMTUD-sized probes fail to be
// acknowledged
break;

default:
break;
}
break;
}

// State changed
conn->state = state;
}

void he_internal_pmtud_update(he_conn_t *conn) {
if(conn == NULL || conn->pmtud_state == HE_PMTUD_STATE_DISABLED) {
// Invalid state, do nothing
Expand Down
9 changes: 9 additions & 0 deletions src/he/pmtud.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#ifndef PMTUD_H
#define PMTUD_H

/// The maximum value of the PROBE_COUNT counter. MAX_PROBES represents the limit for the number of
/// consecutive probe attempts of any size.
#define MAX_PROBES 3

/// The smallest PMTU the discovery process will attempt to use
#define MIN_PLPMTU 512

Expand Down Expand Up @@ -69,6 +73,11 @@ typedef enum he_pmtud_state {

// Internal functions for PMTUD

/**
* @brief Change PMTUD state
*/
void he_internal_change_pmtud_state(he_conn_t *conn, he_pmtud_state_t state);

/**
* @brief Update PMTUD state machine.
*/
Expand Down
6 changes: 3 additions & 3 deletions test/he/test_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// Internal Mocks
#include "mock_fake_dispatch.h"
#include "mock_wolf.h"
#include "mock_pmtud.h"

// External Mocks
#include "mock_ssl.h"
Expand Down Expand Up @@ -1619,11 +1620,10 @@ void test_he_conn_get_curve_name(void) {

void test_he_conn_start_pmtu_discovery(void) {
conn.state = HE_STATE_ONLINE;
conn.event_cb = event_cb;

he_internal_change_pmtud_state_Expect(&conn, HE_PMTUD_STATE_BASE);

TEST_ASSERT_EQUAL(HE_SUCCESS, he_conn_start_pmtu_discovery(&conn));
TEST_ASSERT_EQUAL(HE_PMTUD_STATE_BASE, conn.pmtud_state);
TEST_ASSERT_EQUAL(1, call_counter);
}

void test_he_conn_start_pmtu_discovery_null(void) {
Expand Down
1 change: 1 addition & 0 deletions test/he/test_conn_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "mock_wolf.h"
#include "mock_ssl_ctx.h"
#include "mock_fake_dispatch.h"
#include "mock_pmtud.h"

// External Mocks
#include "mock_ssl.h"
Expand Down

0 comments on commit 3e5559f

Please sign in to comment.