]> git.meshlink.io Git - meshlink/commitdiff
The maximum unreliable packet size is 65535 bytes.
authorGuus Sliepen <guus@meshlink.io>
Sun, 24 May 2020 19:23:13 +0000 (21:23 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sun, 24 May 2020 19:23:13 +0000 (21:23 +0200)
This matches how real UDP works and avoids 16 bit integer overflow.

src/utcp.c
src/utcp_priv.h
test/channels-udp.c

index dc5a2fcfa59237d2d291ba8e0fc12d1563c98916..c4305cd4de4978d265155f2dcb537cd746e39251 100644 (file)
@@ -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;
        }
 
index 197fd2685a32416f46bc87652ddae5bb27664553..7ef147780f1b9a8ade6a2831aed70ae595c13f4b 100644 (file)
@@ -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
index 4e628c017fb77efbd31b2a0d243d46a47a396d65..f4ddbe2b0f1efb3988022233b89195b028183915 100644 (file)
@@ -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)