]> git.meshlink.io Git - meshlink/commitdiff
Count the number of correctly received UDP packets.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 15 Jan 2013 12:33:16 +0000 (13:33 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 15 Jan 2013 12:33:16 +0000 (13:33 +0100)
Keep track of the number of correct, non-replayed UDP packets that have been
received, regardless of their content. This can be compared to the sequence
number to determine the real packet loss.

src/net_packet.c
src/node.h
src/protocol_key.c
src/sptps.c
src/sptps.h

index 3c3397cdd103ba17c10b999d6ba3c147cfc94ac7..c0be8c4de2f074538041c03d89639025403e0927 100644 (file)
@@ -365,6 +365,8 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
        if(inpkt->seqno > n->received_seqno)
                n->received_seqno = inpkt->seqno;
 
+       n->received++;
+
        if(n->received_seqno > MAX_SEQNO)
                regenerate_key();
 
index c567ad92c346806ef3a2685a5b3cb012328b68f6..662ad68311b7ad0e53b8ac138fd9c038a4339f35 100644 (file)
@@ -77,6 +77,7 @@ typedef struct node_t {
 
        uint32_t sent_seqno;                    /* Sequence number last sent to this node */
        uint32_t received_seqno;                /* Sequence number last received from this node */
+       uint32_t received;                      /* Total valid packets received from this node */
        uint32_t farfuture;                     /* Packets in a row that have arrived from the far future */
        unsigned char* late;                    /* Bitfield marking late packets */
 
index b54df3c8292998370c4664eb03f2166cb093d7f1..f96c24e8a8191f3a6cf93b04b517dfcf71afdd13 100644 (file)
@@ -278,6 +278,7 @@ bool send_ans_key(node_t *to) {
        // Reset sequence number and late packet window
        mykeyused = true;
        to->received_seqno = 0;
+       to->received = 0;
        if(replaywin) memset(to->late, 0, replaywin);
 
        return send_request(to->nexthop->connection, "%d %s %s %s %d %d %d %d", ANS_KEY,
index 386b6fd2a1bedb7917d76bae113e5dddf463de20..c22926a84184353ee59fbad823442074dc561a37 100644 (file)
@@ -486,6 +486,10 @@ static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len
        if(seqno > s->inseqno)
                s->inseqno = seqno + 1;
 
+       if(!s->inseqno)
+               s->received = 0;
+       else
+               s->received++;
 
        // Decrypt.
        cipher_set_counter(&s->incipher, &seqno, sizeof seqno);
index a19be9791d61862b6dc768d8832523a827019a4e..bf3a3b96c1c209abb20323dccb6d09d7a51725f3 100644 (file)
@@ -56,6 +56,7 @@ typedef struct sptps {
        cipher_t incipher;
        digest_t indigest;
        uint32_t inseqno;
+       uint32_t received;
        unsigned int replaywin;
        unsigned int farfuture;
        char *late;