diff --git a/src/he/conn.c b/src/he/conn.c index ea1bc73..347f583 100644 --- a/src/he/conn.c +++ b/src/he/conn.c @@ -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; diff --git a/src/he/flow.c b/src/he/flow.c index a12b9d3..3a2ba95 100644 --- a/src/he/flow.c +++ b/src/he/flow.c @@ -35,8 +35,7 @@ #include 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) { @@ -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. diff --git a/src/he/he_internal.h b/src/he/he_internal.h index 844deb4..d76eb1e 100644 --- a/src/he/he_internal.h +++ b/src/he/he_internal.h @@ -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; diff --git a/test/he/test_conn.c b/test/he/test_conn.c index cfd7548..23833d1 100644 --- a/test/he/test_conn.c +++ b/test/he/test_conn.c @@ -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)); diff --git a/test/he/test_flow.c b/test/he/test_flow.c index a40cbe0..e14d7f1 100644 --- a/test/he/test_flow.c +++ b/test/he/test_flow.c @@ -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); @@ -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(); @@ -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; @@ -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 = @@ -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 = @@ -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 = @@ -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));