Skip to content

Commit

Permalink
Instead of checking pmtud state everywhere, use default max value
Browse files Browse the repository at this point in the history
if PMTUD is not completed yet.
  • Loading branch information
kp-mariappan-ramasamy committed Jan 3, 2025
1 parent df92ff0 commit 4eca7f6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/he/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ he_return_code_t he_conn_start_pmtu_discovery(he_conn_t *conn) {
}

uint16_t he_conn_get_effective_pmtu(he_conn_t *conn) {
if(!conn || conn->pmtud.effective_pmtu == 0) {
if(!conn || conn->pmtud.effective_pmtu == 0 || conn->pmtud.state != HE_PMTUD_STATE_SEARCH_COMPLETE) {
return HE_MAX_MTU;
}
return conn->pmtud.effective_pmtu;
Expand Down
11 changes: 4 additions & 7 deletions src/he/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
#include <wolfssl/wolfcrypt/settings.h>

bool he_internal_flow_should_fragment(he_conn_t *conn, uint16_t effective_pmtu, uint16_t length) {
return conn->connection_type == HE_CONNECTION_TYPE_DATAGRAM &&
conn->pmtud.state == HE_PMTUD_STATE_SEARCH_COMPLETE && length > effective_pmtu;
return conn->connection_type == HE_CONNECTION_TYPE_DATAGRAM && length > effective_pmtu;
}

he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet, size_t length) {
Expand Down Expand Up @@ -70,11 +69,9 @@ he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet
// Clamp the MSS if PMTU has been fixed
he_return_code_t ret = HE_SUCCESS;
uint16_t effective_pmtu = he_conn_get_effective_pmtu(conn);
if(conn->pmtud.state == HE_PMTUD_STATE_SEARCH_COMPLETE) {
ret = he_internal_clamp_mss(packet, length, effective_pmtu - HE_MSS_OVERHEAD);
if(ret != HE_SUCCESS) {
return ret;
}
ret = he_internal_clamp_mss(packet, length, effective_pmtu - HE_MSS_OVERHEAD);
if(ret != HE_SUCCESS) {
return ret;
}

// Process the packet with plugins.
Expand Down
2 changes: 1 addition & 1 deletion src/he/he_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ typedef struct he_internal_pmtud_ {
he_pmtud_state_t state;

/// Current effective PMTU
uint16_t effective_pmtu;
_Atomic uint16_t effective_pmtu;

/// PMTUD internal data
uint16_t base;
Expand Down
10 changes: 9 additions & 1 deletion test/he/test_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1759,14 +1759,22 @@ void test_he_conn_start_pmtu_discovery_callback_not_set(void) {
TEST_ASSERT_EQUAL(HE_ERR_PMTUD_CALLBACKS_NOT_SET, he_conn_start_pmtu_discovery(&conn));
}

void test_he_conn_get_effective_pmtu(void) {
void test_he_conn_get_effective_pmtu_after_complete(void) {
TEST_ASSERT_EQUAL(HE_MAX_MTU, he_conn_get_effective_pmtu(NULL));
TEST_ASSERT_EQUAL(HE_MAX_MTU, he_conn_get_effective_pmtu(&conn));

conn.pmtud.state = HE_PMTUD_STATE_SEARCH_COMPLETE;
conn.pmtud.effective_pmtu = 1212;
TEST_ASSERT_EQUAL(1212, he_conn_get_effective_pmtu(&conn));
}

void test_he_conn_get_effective_pmtu_before_complete(void) {
TEST_ASSERT_EQUAL(HE_MAX_MTU, he_conn_get_effective_pmtu(NULL));
TEST_ASSERT_EQUAL(HE_MAX_MTU, he_conn_get_effective_pmtu(&conn));

conn.pmtud.effective_pmtu = 1212;
TEST_ASSERT_EQUAL(1350, he_conn_get_effective_pmtu(&conn));
}
void test_he_conn_pmtud_probe_timeout(void) {
TEST_ASSERT_EQUAL(HE_ERR_NULL_POINTER, he_conn_pmtud_probe_timeout(NULL));

Expand Down
19 changes: 13 additions & 6 deletions test/he/test_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ void test_inside_pkt_good_packet(void) {
he_internal_is_ipv4_packet_valid_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
true);
he_conn_get_effective_pmtu_ExpectAndReturn(conn, 1350);
he_internal_clamp_mss_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
1350 - HE_MSS_OVERHEAD, HE_SUCCESS);
he_plugin_ingress_ExpectAnyArgsAndReturn(HE_SUCCESS);
he_internal_calculate_data_packet_length_ExpectAndReturn(conn, sizeof(fake_ipv4_packet), 1242);
he_internal_send_message_ExpectAndReturn(conn, NULL, 1242 + sizeof(he_msg_data_t), HE_SUCCESS);
Expand All @@ -164,6 +166,8 @@ void test_inside_pkt_good_packet_with_legacy_behaviour(void) {
conn->protocol_version.minor_version = 0;

he_conn_get_effective_pmtu_ExpectAndReturn(conn, 1350);
he_internal_clamp_mss_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
1350 - HE_MSS_OVERHEAD, HE_SUCCESS);
he_internal_calculate_data_packet_length_ExpectAndReturn(conn, sizeof(fake_ipv4_packet), 1242);
he_internal_send_message_ExpectAndReturn(conn, NULL, 1242 + sizeof(he_msg_data_t), HE_SUCCESS);
he_internal_send_message_IgnoreArg_message();
Expand All @@ -178,11 +182,6 @@ void test_he_internal_flow_should_fragment(void) {
conn->connection_type = HE_CONNECTION_TYPE_STREAM;
TEST_ASSERT_FALSE(he_internal_flow_should_fragment(conn, 1200, 1350));

// Don't frag if PMTUD search hasn't completed
conn->connection_type = HE_CONNECTION_TYPE_DATAGRAM;
conn->pmtud.state = HE_PMTUD_STATE_SEARCHING;
TEST_ASSERT_FALSE(he_internal_flow_should_fragment(conn, 1200, 1350));

// Don't frag if the packet length is exactly effective_pmtu
conn->connection_type = HE_CONNECTION_TYPE_DATAGRAM;
conn->pmtud.state = HE_PMTUD_STATE_SEARCH_COMPLETE;
Expand Down Expand Up @@ -227,6 +226,8 @@ void test_inside_pkt_plugin_drop(void) {
he_internal_is_ipv4_packet_valid_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
true);
he_conn_get_effective_pmtu_ExpectAndReturn(conn, 1350);
he_internal_clamp_mss_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
1350 - HE_MSS_OVERHEAD, HE_SUCCESS);
he_plugin_ingress_ExpectAnyArgsAndReturn(HE_ERR_PLUGIN_DROP);

he_return_code_t res1 =
Expand All @@ -241,6 +242,8 @@ void test_inside_pkt_plugin_fail(void) {
he_internal_is_ipv4_packet_valid_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
true);
he_conn_get_effective_pmtu_ExpectAndReturn(conn, 1350);
he_internal_clamp_mss_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
1350 - HE_MSS_OVERHEAD, HE_SUCCESS);
he_plugin_ingress_ExpectAnyArgsAndReturn(HE_ERR_FAILED);

he_return_code_t res1 =
Expand All @@ -255,6 +258,8 @@ void test_inside_pkt_plugin_overflow_fail(void) {
he_internal_is_ipv4_packet_valid_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
true);
he_conn_get_effective_pmtu_ExpectAndReturn(conn, 1350);
he_internal_clamp_mss_ExpectAndReturn(fake_ipv4_packet, sizeof(fake_ipv4_packet),
1350 - HE_MSS_OVERHEAD, HE_SUCCESS);
he_plugin_ingress_Stub(stub_overflow_plugin);

he_return_code_t res1 =
Expand All @@ -269,7 +274,9 @@ void test_inside_pkt_plugin_large_mtu(void) {
conn->outside_mtu = 9000;

he_internal_is_ipv4_packet_valid_ExpectAndReturn(buffer, sizeof(buffer), true);
he_conn_get_effective_pmtu_ExpectAndReturn(conn, 1350);
he_conn_get_effective_pmtu_ExpectAndReturn(conn, 9000);
he_internal_clamp_mss_ExpectAndReturn(buffer, sizeof(buffer),
9000 - HE_MSS_OVERHEAD, HE_SUCCESS);
he_plugin_ingress_ExpectAnyArgsAndReturn(HE_SUCCESS);

he_return_code_t res1 = he_conn_inside_packet_received(conn, buffer, sizeof(buffer));
Expand Down

0 comments on commit 4eca7f6

Please sign in to comment.