From: Guus Sliepen Date: Sun, 24 May 2020 19:23:13 +0000 (+0200) Subject: The maximum unreliable packet size is 65535 bytes. X-Git-Url: http://git.meshlink.io/?a=commitdiff_plain;h=36a7403d3ab239a03c4085fa46f0df2127394a95;hp=e22b3cef15764699e2bc05b6d9f3fbebf8ccef03;p=meshlink The maximum unreliable packet size is 65535 bytes. This matches how real UDP works and avoids 16 bit integer overflow. --- diff --git a/src/utcp.c b/src/utcp.c index dc5a2fcf..c4305cd4 100644 --- a/src/utcp.c +++ b/src/utcp.c @@ -1147,7 +1147,7 @@ static void handle_unreliable(struct utcp_connection *c, const struct hdr *hdr, } // Ensure reassembled packet are not larger than 64 kiB - if(hdr->wnd >= MAX_UNRELIABLE_SIZE || hdr->wnd + len > MAX_UNRELIABLE_SIZE) { + if(hdr->wnd > MAX_UNRELIABLE_SIZE || hdr->wnd + len > MAX_UNRELIABLE_SIZE) { return; } diff --git a/src/utcp_priv.h b/src/utcp_priv.h index 197fd268..7ef14778 100644 --- a/src/utcp_priv.h +++ b/src/utcp_priv.h @@ -42,7 +42,7 @@ #define DEFAULT_RCVBUFSIZE 0 #define DEFAULT_MAXRCVBUFSIZE 131072 -#define MAX_UNRELIABLE_SIZE 65536 +#define MAX_UNRELIABLE_SIZE 65535 #define DEFAULT_MTU 1000 #define USEC_PER_SEC 1000000L diff --git a/test/channels-udp.c b/test/channels-udp.c index 4e628c01..f4ddbe2b 100644 --- a/test/channels-udp.c +++ b/test/channels-udp.c @@ -55,10 +55,10 @@ static void client_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *chann // We expect always the same amount of data from the server. assert(mesh->priv); struct client *client = mesh->priv; - assert(len == 512 || len == 65536); + assert(len == 512 || len == 65535); client->received += len; - if(len == 65536) { + if(len == 65535) { client->got_large_packet = true; } } @@ -142,16 +142,15 @@ int main(void) { // Check that we can send up to 65535 bytes without errors - char large_data[65536] = ""; + char large_data[65535] = ""; for(int i = 0; i < 3; i++) { - assert(meshlink_channel_send(server, channels[i], large_data, sizeof(large_data) + 1) == -1); assert(meshlink_channel_send(server, channels[i], large_data, sizeof(large_data)) == sizeof(large_data)); } - // Assert that packets larger than 64 kiB are not allowed + // Assert that any larger packets are not allowed - assert(meshlink_channel_send(server, channels[0], large_data, 65537) == -1); + assert(meshlink_channel_send(server, channels[0], large_data, 65536) == -1); // Stream packets from server to clients for 5 seconds at 40 Mbps (1 kB * 500 Hz)