Configurable ReplayWindow size, zero disables
[oweals/tinc.git] / src / protocol_key.c
index 67f40af45caa660c93b8a207f2c568920878a6ec..fbd7cabb8babafdd89fd09ac16a4fa46254bc8f8 100644 (file)
@@ -145,8 +145,6 @@ bool req_key_h(connection_t *c) {
 }
 
 bool send_ans_key(node_t *to) {
-       char *key;
-
        // Set key parameters
        to->incipher = myself->incipher;
        to->inkeylength = myself->inkeylength;
@@ -165,10 +163,10 @@ bool send_ans_key(node_t *to) {
        // Reset sequence number and late packet window
        mykeyused = true;
        to->received_seqno = 0;
-       memset(to->late, 0, sizeof(to->late));
+       if(replaywin) memset(to->late, 0, replaywin);
 
        // Convert to hexadecimal and send
-       key = alloca(2 * to->inkeylength + 1);
+       char key[2 * to->inkeylength + 1];
        bin2hex(to->inkey, key, to->inkeylength);
        key[to->inkeylength * 2] = '\0';
 
@@ -229,7 +227,7 @@ bool ans_key_h(connection_t *c) {
                        return true;
                }
 
-               if(!*address) {
+               if(!*address && from->address.sa.sa_family != AF_UNSPEC) {
                        char *address, *port;
                        ifdebug(PROTOCOL) logger(LOG_DEBUG, "Appending reflexive UDP address to ANS_KEY from %s to %s", from->name, to->name);
                        sockaddr2str(&from->address, &address, &port);