X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=9daf8c81c0012758c189abeff688e53fb8319821;hp=2d16ae8363f571a72ccb585fa445f6f0d25cca6f;hb=61e71ab74ad9b5edb044b84ccf1111a33eb468cb;hpb=e4ff969a9868ecc25a85daab620f97227de8d493 diff --git a/src/net.c b/src/net.c index 2d16ae83..9daf8c81 100644 --- a/src/net.c +++ b/src/net.c @@ -51,6 +51,8 @@ int total_tap_out = 0; int total_socket_in = 0; int total_socket_out = 0; +static int seconds_till_retry; + /* The global list of existing connections */ conn_list_t *conn_list = NULL; conn_list_t *myself = NULL; @@ -541,6 +543,30 @@ cp return 0; } +RETSIGTYPE +sigalrm_handler(int a) +{ + config_t const *cfg; +cp + cfg = get_config_val(upstreamip); + + if(!setup_outgoing_connection(cfg->data.ip->ip)) + { + signal(SIGALRM, SIG_IGN); + } + else + { + signal(SIGALRM, sigalrm_handler); + seconds_till_retry += 5; + if(seconds_till_retry>300) /* Don't wait more than 5 minutes. */ + seconds_till_retry = 300; + alarm(seconds_till_retry); + syslog(LOG_ERR, "Still failed to connect to other. Will retry in %d seconds.", + seconds_till_retry); + } +cp +} + /* setup all initial network connections */ @@ -564,33 +590,14 @@ cp return 0; if(setup_outgoing_connection(cfg->data.ip->ip)) - return -1; -cp - return 0; -} - -RETSIGTYPE -sigalrm_handler(int a) -{ - config_t const *cfg; - static int seconds_till_retry; -cp - cfg = get_config_val(upstreamip); - - if(!setup_outgoing_connection(cfg->data.ip->ip)) - { - signal(SIGALRM, SIG_IGN); - seconds_till_retry = 5; - } - else { signal(SIGALRM, sigalrm_handler); - seconds_till_retry += 5; + seconds_till_retry = 300; alarm(seconds_till_retry); - syslog(LOG_ERR, "Still failed to connect to other. Will retry in %d seconds.", - seconds_till_retry); + syslog(LOG_NOTICE, "Try to re-establish outgoing connection in 5 minutes."); } cp + return 0; } /* @@ -822,10 +829,12 @@ cp if(cl->status.outgoing) { signal(SIGALRM, sigalrm_handler); - alarm(5); + seconds_till_retry = 5; + alarm(seconds_till_retry); syslog(LOG_NOTICE, "Try to re-establish outgoing connection in 5 seconds."); } + cl->status.active = 0; cl->status.remove = 1; cp } @@ -926,8 +935,8 @@ cp if(cl->buflen >= MAXBUFSIZE) { - syslog(LOG_ERR, "Metadata read buffer full! Discarding contents."); - cl->buflen = 0; + syslog(LOG_ERR, "Metadata read buffer overflow."); + return -1; } lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE-cl->buflen); @@ -962,17 +971,22 @@ cp if(request_handlers[request] == NULL) { syslog(LOG_ERR, "Unknown request: %s", cl->buffer); - return 0; + return -1; } if(debug_lvl > 3) syslog(LOG_DEBUG, "Got request: %s", cl->buffer); - request_handlers[request](cl); + if(request_handlers[request](cl)) /* Something went wrong. Probably scriptkiddies. Terminate. */ + { + syslog(LOG_ERR, "Error while processing request from IP_ADDR_S", IP_ADDR_V(cl->real_ip)); + return -1; + } } else { - syslog(LOG_ERR, "Bogus data received: %s", cl->buffer); + syslog(LOG_ERR, "Bogus data received."); + return -1; } cl->buflen -= cl->reqlen;