- Fixed some spelling errors.
[tinc] / src / protocol.c
index 325177b..2cc49ad 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.28.4.7 2000/06/26 17:20:58 guus Exp $
+    $Id: protocol.c,v 1.28.4.13 2000/06/28 11:38:00 guus Exp $
 */
 
 #include "config.h"
@@ -62,7 +62,8 @@ cp
       return -1;
     }
 
-  syslog(LOG_NOTICE, _("Connection with " IP_ADDR_S " (%s) activated"),
+  if(debug_lvl > 0)
+    syslog(LOG_NOTICE, _("Connection with " IP_ADDR_S " (%s) activated"),
                        IP_ADDR_V(cl->vpn_ip), cl->hostname);
 cp
   return 0;
@@ -109,8 +110,8 @@ int send_del_host(conn_list_t *cl, conn_list_t *new_host)
 {
 cp
   if(debug_lvl > 1)
-    syslog(LOG_DEBUG, _("Sending DEL_HOST for " IP_ADDR_S " to " IP_ADDR_S " (%s)"),
-          IP_ADDR_V(new_host->vpn_ip), IP_ADDR_V(cl->vpn_ip), cl->hostname);
+    syslog(LOG_DEBUG, _("Sending DEL_HOST for " IP_ADDR_S " (%s) to " IP_ADDR_S " (%s)"),
+          IP_ADDR_V(new_host->vpn_ip), new_host->hostname, IP_ADDR_V(cl->vpn_ip), cl->hostname);
 
   buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", DEL_HOST, new_host->vpn_ip);
 
@@ -349,7 +350,7 @@ cp
 
   if((write(fw->nexthop->meta_socket, buffer, buflen)) < 0)
     {
-      syslog(LOG_ERR, _("send failed: %s:%d: %m"), __FILE__, __LINE__);
+      syslog(LOG_ERR, _("Send failed: %s:%d: %m"), __FILE__, __LINE__);
       return -1;
     }
 cp
@@ -400,7 +401,7 @@ cp
 
   if(sscanf(cl->buffer, "%*d %d %lx/%lx:%hx %d", &cl->protocol_version, &cl->vpn_ip, &cl->vpn_mask, &cl->port, &cl->flags) != 5)
     {
-       syslog(LOG_ERR, _("Got bad BASIC_INFO from " IP_ADDR_S),
+       syslog(LOG_ERR, _("Got bad BASIC_INFO from %s"),
               cl->hostname);
        return -1;
     }  
@@ -487,7 +488,7 @@ cp
          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)) 
+      while(old = lookup_conn(cl->vpn_ip)) 
         terminate_connection(old);
 
       cl->status.active = 1;
@@ -508,6 +509,7 @@ cp
   cl->status.active = 1;
   syslog(LOG_NOTICE, _("Connection with " IP_ADDR_S " (%s) activated"),
               IP_ADDR_V(cl->vpn_ip), cl->hostname);
+  upstreamindex = 0;
 cp
   return 0;
 }
@@ -527,11 +529,12 @@ cp
              IP_ADDR_V(cl->vpn_ip), cl->hostname);
   
   cl->status.termreq = 1;
-  cl->status.active = 0;
 
   if(cl->status.active)
     notify_others(cl, NULL, send_del_host);
 
+  cl->status.active = 0;
+
   terminate_connection(cl);
 cp
   return 0;
@@ -576,10 +579,6 @@ cp
        return -1;
     }  
 
-  if(debug_lvl > 1)
-    syslog(LOG_DEBUG, _("Got DEL_HOST for " IP_ADDR_S " from " IP_ADDR_S " (%s)"),
-           IP_ADDR_V(vpn_ip), IP_ADDR_V(cl->vpn_ip), cl->hostname);
-
   if(!(fw = lookup_conn(vpn_ip)))
     {
       syslog(LOG_ERR, _("Got DEL_HOST for " IP_ADDR_S " from " IP_ADDR_S " (%s) which does not exist?"),
@@ -587,9 +586,15 @@ cp
       return 0;
     }
 
-  notify_others(cl, fw, send_del_host);
+  if(debug_lvl > 1)
+    syslog(LOG_DEBUG, _("Got DEL_HOST for " IP_ADDR_S " (%s) from " IP_ADDR_S " (%s)"),
+           IP_ADDR_V(fw->vpn_ip), fw->hostname, IP_ADDR_V(cl->vpn_ip), cl->hostname);
+
+  notify_others(fw, cl, send_del_host);
 
   fw->status.termreq = 1;
+  fw->status.active = 0;
+
   terminate_connection(fw);
 cp
   return 0;
@@ -643,7 +648,7 @@ int add_host_h(conn_list_t *cl)
   ip_t vpn_mask;
   unsigned short port;
   int flags;
-  conn_list_t *ncn, *fw;
+  conn_list_t *ncn, *old;
 cp
   if(!cl->status.active)
     {
@@ -659,19 +664,9 @@ cp
        return -1;
     }  
 
-  /*
-    Suggestion of Hans Bayle
-  */
-  if((fw = lookup_conn(vpn_ip)))
-    {
-      if(fw->nexthop == cl)
-       notify_others(fw, cl, send_add_host);
-      else
-       syslog(LOG_DEBUG, _("Invalid ADD_HOST from " IP_ADDR_S " (%s)"),
-            IP_ADDR_V(cl->vpn_ip), cl->hostname);
-      return -1;
-    }
-
+  while(old = lookup_conn(vpn_ip))
+      terminate_connection(old);
+    
   ncn = new_conn_list();
   ncn->real_ip = real_ip;
   ncn->hostname = hostlookup(htonl(real_ip));
@@ -885,7 +880,7 @@ cp
   ik->status.validkey = 0;
   ik->status.waitingforkey = 0;
 
-  notify_others(cl, ik, send_key_changed);
+  notify_others(ik, cl, send_key_changed);
 cp
   return 0;
 }