X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;ds=sidebyside;f=src%2Fprotocol.c;h=51d95e9dd2e2c30a43ebed43a3b08563c6f3e80a;hb=028659bfbf164cb7a72831506896e291010b251f;hp=5d84c5d7292d69a4688a48ed111cf8b015f11a34;hpb=74b0cbecce5194dc5c594cc4e2aa3e97c14ea6c1;p=tinc diff --git a/src/protocol.c b/src/protocol.c index 5d84c5d7..51d95e9d 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1,6 +1,6 @@ /* protocol.c -- handle the meta-protocol - Copyright (C) 1999 Ivo Timmermans + Copyright (C) 1999,2000 Ivo Timmermans 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 @@ -40,6 +40,8 @@ char buffer[MAXBUFSIZE+1]; int buflen; +/* Outgoing request routines */ + int send_ack(conn_list_t *cl) { cp @@ -68,9 +70,10 @@ cp buflen = snprintf(buffer, MAXBUFSIZE, "%d %lx\n", TERMREQ, myself->vpn_ip); - if((write(cl->meta_socket, buffer, buflen)) < 0) + if(write(cl->meta_socket, buffer, buflen) < 0) { - syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); + if(debug_lvl > 1) + syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__); return -1; } cp @@ -180,12 +183,12 @@ cp return 0; } -void send_key_changed2(void) +void send_key_changed_all(void) { conn_list_t *p; cp for(p = conn_list; p != NULL; p = p->next) - if(p->status.meta && p->protocol_version > PROT_3) + if(p->status.meta && p->status.active) send_key_changed(p, myself); cp } @@ -329,7 +332,7 @@ int notify_others(conn_list_t *new, conn_list_t *source, conn_list_t *p; cp for(p = conn_list; p != NULL; p = p->next) - if(p != new && p != source && p->status.meta) + if(p != new && p != source && p->status.meta && p->status.active) function(p, new); cp return 0; @@ -344,7 +347,7 @@ int notify_one(conn_list_t *new) conn_list_t *p; cp for(p = conn_list; p != NULL; p = p->next) - if(p != new && p->protocol_version > PROT_3) + if(p != new && p->status.active) send_add_host(new, p); cp return 0; @@ -389,8 +392,6 @@ cp return -1; send_passphrase(cl); } - - cl->status.active = 0; cp return 0; } @@ -398,7 +399,8 @@ cp int passphrase_h(conn_list_t *cl) { cp - cl->pp=xmalloc(sizeof(*(cl->pp))); + cl->pp = xmalloc(sizeof(*(cl->pp))); + if(sscanf(cl->buffer, "%*d %as", &(cl->pp->phrase)) != 1) { syslog(LOG_ERR, "got bad PASSPHRASE request: %s", cl->buffer); @@ -420,6 +422,7 @@ cp int public_key_h(conn_list_t *cl) { char *g_n; + conn_list_t *old; cp if(sscanf(cl->buffer, "%*d %as", &g_n) != 1) { @@ -445,6 +448,14 @@ cp else 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. */ + + while(old=lookup_conn(cl->vpn_ip)) + terminate_connection(old); + cl->status.active = 1; notify_others(cl, NULL, send_add_host); notify_one(cl);