- Improved handling of errors on connection attempts.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 27 Jun 2000 20:10:48 +0000 (20:10 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 27 Jun 2000 20:10:48 +0000 (20:10 +0000)
src/conf.c
src/conf.h
src/net.c
src/protocol.c

index 1e1c60f..f8838d7 100644 (file)
@@ -19,7 +19,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: conf.c,v 1.9.4.2 2000/06/27 15:08:57 guus Exp $
+    $Id: conf.c,v 1.9.4.3 2000/06/27 20:10:47 guus Exp $
 */
 
 
 */
 
 
@@ -75,7 +75,7 @@ static internal_config_t hazahaza[] = {
 config_t *
 add_config_val(config_t **cfg, int argtype, char *val)
 {
 config_t *
 add_config_val(config_t **cfg, int argtype, char *val)
 {
-  config_t *p;
+  config_t *p, *r;
   char *q;
 
   p = (config_t*)xmalloc(sizeof(*p));
   char *q;
 
   p = (config_t*)xmalloc(sizeof(*p));
@@ -106,8 +106,16 @@ add_config_val(config_t **cfg, int argtype, char *val)
 
   if(p->data.val)
     {
 
   if(p->data.val)
     {
-      p->next = *cfg;
-      *cfg = p;
+      if(*cfg)
+        {
+          r = *cfg;
+          while(r->next)
+            r = r->next;
+          r->next = p;
+        }
+      else
+        *cfg = p;
+      p->next = NULL;
       return p;
     }
 
       return p;
     }
 
index 36bc9a4..d930912 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.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: conf.h,v 1.6.4.2 2000/06/27 15:08:57 guus Exp $
+    $Id: conf.h,v 1.6.4.3 2000/06/27 20:10:47 guus Exp $
 */
 
 #ifndef __TINC_CONF_H__
 */
 
 #ifndef __TINC_CONF_H__
@@ -70,6 +70,7 @@ enum {
 extern config_t *config;
 extern int debug_lvl;
 extern int timeout;
 extern config_t *config;
 extern int debug_lvl;
 extern int timeout;
+extern int upstreamindex;
 
 extern config_t *add_config_val(config_t **, int, char *);
 extern int read_config_file(const char *);
 
 extern config_t *add_config_val(config_t **, int, char *);
 extern int read_config_file(const char *);
index cdb593e..bc3540e 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net.c,v 1.35.4.9 2000/06/27 15:08:58 guus Exp $
+    $Id: net.c,v 1.35.4.10 2000/06/27 20:10:48 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -56,6 +56,7 @@ int total_tap_out = 0;
 int total_socket_in = 0;
 int total_socket_out = 0;
 
 int total_socket_in = 0;
 int total_socket_out = 0;
 
+int upstreamindex = 0;
 static int seconds_till_retry;
 
 /* The global list of existing connections */
 static int seconds_till_retry;
 
 /* The global list of existing connections */
@@ -496,6 +497,9 @@ int setup_outgoing_meta_socket(conn_list_t *cl)
   struct sockaddr_in a;
   config_t const *cfg;
 cp
   struct sockaddr_in a;
   config_t const *cfg;
 cp
+  if(debug_lvl > 0)
+    syslog(LOG_INFO, _("Trying to connect to %s"), cl->hostname);
+
   if((cfg = get_config_val(upstreamport)) == NULL)
     cl->port = 655;
   else
   if((cfg = get_config_val(upstreamport)) == NULL)
     cl->port = 655;
   else
@@ -615,9 +619,8 @@ RETSIGTYPE
 sigalrm_handler(int a)
 {
   config_t const *cfg;
 sigalrm_handler(int a)
 {
   config_t const *cfg;
-  int index = 1;
 cp
 cp
-  cfg = get_config_val(upstreamip);
+  cfg = get_next_config_val(upstreamip, upstreamindex++);
 
   while(cfg)
     {
 
   while(cfg)
     {
@@ -626,10 +629,11 @@ cp
           signal(SIGALRM, SIG_IGN);
           return;
         }
           signal(SIGALRM, SIG_IGN);
           return;
         }
-      cfg = get_next_config_val(upstreamip, index++); /* Or else we try the next ConnectTo line */
+      cfg = get_next_config_val(upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */
     }
 
   signal(SIGALRM, sigalrm_handler);
     }
 
   signal(SIGALRM, sigalrm_handler);
+  upstreamindex = 0;
   seconds_till_retry += 5;
   if(seconds_till_retry>300)    /* Don't wait more than 5 minutes. */
     seconds_till_retry = 300;
   seconds_till_retry += 5;
   if(seconds_till_retry>300)    /* Don't wait more than 5 minutes. */
     seconds_till_retry = 300;
@@ -645,7 +649,6 @@ cp
 int setup_network_connections(void)
 {
   config_t const *cfg;
 int setup_network_connections(void)
 {
   config_t const *cfg;
-  int index = 1;
 cp
   if((cfg = get_config_val(pingtimeout)) == NULL)
     timeout = 5;
 cp
   if((cfg = get_config_val(pingtimeout)) == NULL)
     timeout = 5;
@@ -658,7 +661,7 @@ cp
   if(setup_myself() < 0)
     return -1;
 
   if(setup_myself() < 0)
     return -1;
 
-  if((cfg = get_config_val(upstreamip)) == NULL)
+  if((cfg = get_next_config_val(upstreamip, upstreamindex++)) == NULL)
     /* No upstream IP given, we're listen only. */
     return 0;
 
     /* No upstream IP given, we're listen only. */
     return 0;
 
@@ -666,10 +669,11 @@ cp
     {
       if(!setup_outgoing_connection(cfg->data.ip->ip))   /* function returns 0 when there are no problems */
         return 0;
     {
       if(!setup_outgoing_connection(cfg->data.ip->ip))   /* function returns 0 when there are no problems */
         return 0;
-      cfg = get_next_config_val(upstreamip, index++); /* Or else we try the next ConnectTo line */
+      cfg = get_next_config_val(upstreamip, upstreamindex++); /* Or else we try the next ConnectTo line */
     }
     
   signal(SIGALRM, sigalrm_handler);
     }
     
   signal(SIGALRM, sigalrm_handler);
+  upstreamindex = 0;
   seconds_till_retry = 300;
   alarm(seconds_till_retry);
   syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 minutes"));
   seconds_till_retry = 300;
   alarm(seconds_till_retry);
   syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 minutes"));
index 70122c1..1fe75e7 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.
 
     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.10 2000/06/27 12:58:04 guus Exp $
+    $Id: protocol.c,v 1.28.4.11 2000/06/27 20:10:48 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -403,16 +403,6 @@ cp
     {
        syslog(LOG_ERR, _("Got bad BASIC_INFO from %s"),
               cl->hostname);
     {
        syslog(LOG_ERR, _("Got bad BASIC_INFO from %s"),
               cl->hostname);
-       if(cl->status.outgoing)
-         {
-           /* If we get here, it means that our uplink uses the wrong protocol.
-              If we don't do anything, we will reconnect every 5 seconds. Pretty dumb.
-              So we disable the outgoing flag, so that we won't reconnect anymore.
-              This still allows other tinc daemons to connect to us.
-            */
-           syslog(LOG_ERR, _("Warning: disabling uplink!"));
-           cl->status.outgoing = 0;
-         }
        return -1;
     }  
 
        return -1;
     }  
 
@@ -519,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);
   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;
 }
 cp
   return 0;
 }