Only accept an ADD_HOST request for a host that already exists in our conn_list if...
[tinc] / src / protocol.c
index f0b7cb9..e9bad82 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: protocol.c,v 1.26 2000/05/29 21:01:25 zarq Exp $
+    $Id: protocol.c,v 1.28 2000/05/30 21:36:16 zarq Exp $
 */
 
 #include "config.h"
@@ -451,19 +451,21 @@ cp
   if(cl->status.outgoing)
     send_public_key(cl);
   else
-    send_ack(cl);
+    {
+      send_ack(cl);
 
-  /* Okay, before we active the connection, we check if there is another entry
-     in the connection list with the same vpn_ip. If so, it presumably is an
-     old connection that has timed out but we don't know it yet. Because our
-     conn_list entry is not active, lookup_conn will skip ourself. */
+      /* Okay, before we active the connection, we check if there is another entry
+         in the connection list with the same vpn_ip. If so, it presumably is an
+         old connection that has timed out but we don't know it yet. Because our
+         conn_list entry is not active, lookup_conn will skip ourself. */
 
-  while(old=lookup_conn(cl->vpn_ip)) 
-    terminate_connection(old);
+      while(old=lookup_conn(cl->vpn_ip)) 
+        terminate_connection(old);
 
-  cl->status.active = 1;
-  notify_others(cl, NULL, send_add_host);
-  notify_one(cl);
+      cl->status.active = 1;
+      notify_others(cl, NULL, send_add_host);
+      notify_one(cl);
+    }
 cp
   return 0;
 }
@@ -568,7 +570,8 @@ int add_host_h(conn_list_t *cl)
   unsigned short port;
   conn_list_t *ncn, *fw;
 cp
-  if(!cl->status.active) return -1;
+  if(!cl->status.active)
+    return -1;
   if(sscanf(cl->buffer, "%*d %lx %lx/%lx:%hx", &real_ip, &vpn_ip, &vpn_mask, &port) != 4)
     {
        syslog(LOG_ERR, _("got bad ADD_HOST request: %s"), cl->buffer);
@@ -586,7 +589,12 @@ cp
   */
   if((fw = lookup_conn(vpn_ip)))
     {
-      notify_others(fw, cl, send_add_host);
+      if(fw->nexthop == cl)
+       notify_others(fw, cl, send_add_host);
+      else
+       if(debug_lvl > 1)
+         syslog(LOG_DEBUG, _("Invalid add_host request from " IP_ADDR_S),
+                             IP_ADDR_V(cl->vpn_ip));
       return 0;
     }