Do not append an address to ANS_KEY messages if we don't know any address.
[oweals/tinc.git] / src / protocol_key.c
index 8096af57fc9c8f8843812b5e094510fa015b3d61..22692bb614e97632d2224bedbd77b1fb28647976 100644 (file)
@@ -1,7 +1,7 @@
 /*
     protocol_key.c -- handle the meta-protocol, key exchange
     Copyright (C) 1999-2005 Ivo Timmermans,
-                  2000-2009 Guus Sliepen <guus@tinc-vpn.org>
+                  2000-2010 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 bool mykeyused = false;
 
-bool send_key_changed() {
-       /* Only send this message if some other daemon requested our key previously.
-          This reduces unnecessary key_changed broadcasts.
-        */
+void send_key_changed() {
+       avl_node_t *node;
+       connection_t *c;
 
-       if(!mykeyused)
-               return true;
+       send_request(broadcast, "%d %x %s", KEY_CHANGED, rand(), myself->name);
+
+       /* Immediately send new keys to directly connected nodes to keep UDP mappings alive */
 
-       return send_request(broadcast, "%d %x %s", KEY_CHANGED, rand(), myself->name);
+       for(node = connection_tree->head; node; node = node->next) {
+               c = node->data;
+               if(c->status.active && c->node && c->node->status.reachable)
+                       send_ans_key(c->node);
+       }
 }
 
 bool key_changed_h(connection_t *c) {
@@ -225,7 +229,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);