X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fconnlist.c;h=ebb276e757d96c7be2aa73fbb17409ac9900e735;hp=12a501f12dc32d4d5c3f60c5bf48c2a5c8874735;hb=d47d5932a3bbc4940aa6453ebfe617ef330783c8;hpb=950fb8e916b0e248dcaa72c96859acd6046683aa diff --git a/src/connlist.c b/src/connlist.c index 12a501f1..ebb276e7 100644 --- a/src/connlist.c +++ b/src/connlist.c @@ -17,13 +17,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: connlist.c,v 1.1.2.1 2000/10/11 10:35:15 guus Exp $ + $Id: connlist.c,v 1.1.2.9 2000/10/28 16:41:37 guus Exp $ */ +#include + +#include "net.h" /* Don't ask. */ #include "config.h" +#include "conf.h" #include -#include "connlist.h" +#include "system.h" /* Root of the connection list */ @@ -34,7 +38,7 @@ conn_list_t *myself = NULL; conn_list_t *new_conn_list(void) { - conn_list_t *p = xmalloc(sizeof(*p)); + conn_list_t *p = (conn_list_t *)xmalloc(sizeof(*p)); cp /* initialise all those stupid pointers at once */ memset(p, '\0', sizeof(*p)); @@ -49,12 +53,16 @@ cp destroy_queue(p->sq); if(p->rq) destroy_queue(p->rq); - if(p->name) + if(p->name && p->name!=unknown) free(p->name); if(p->hostname) free(p->hostname); - free_key(p->public_key); - free_key(p->datakey); + if(p->rsa_key) + RSA_free(p->rsa_key); + if(p->cipher_pktkey) + free(p->cipher_pktkey); + if(p->buffer) + free(p->buffer); free(p); cp } @@ -77,7 +85,7 @@ cp else conn_list = next; - free_conn_element(p); + free_conn_list(p); } else prev = p; @@ -97,7 +105,7 @@ cp for(p = conn_list; p != NULL; ) { next = p->next; - free_conn_element(p); + free_conn_list(p); p = next; } @@ -110,10 +118,11 @@ cp void conn_list_add(conn_list_t *cl) { cp - cl->next = connlist; + cl->next = conn_list; cl->prev = NULL; - cl->next->prev = cl; - connlist = cl; + if(cl->next) + cl->next->prev = cl; + conn_list = cl; cp } @@ -123,7 +132,7 @@ cp if(cl->prev) cl->prev->next = cl->next; else - connlist = cl->next; + conn_list = cl->next; cl->next->prev = cl->prev; free_conn_list(cl); @@ -132,35 +141,14 @@ cp /* Lookup functions */ -conn_list_t *lookup_conn_list_mac(mac_t address) -{ - conn_list_t *p; -cp - for(p = conn_list; p != NULL; p = p->next) - if(lookup_subnet_mac(p, address)) - break; -cp - return p; -} - -conn_list_t *lookup_conn_list_ipv4(ipv4_t address) -{ - conn_list_t *p; -cp - for(p = conn_list; p != NULL; p = p->next) - if(lookup_subnet_ipv4(p, address)) - break; -cp - return p; -} - -conn_list_t *lookup_conn_list_ipv6(ipv6_t address) +conn_list_t *lookup_id(char *name) { conn_list_t *p; cp for(p = conn_list; p != NULL; p = p->next) - if(lookup_subnet_ipv6(p, address)) - break; + if(p->status.active) + if(strcmp(name, p->name) == 0) + break; cp return p; } @@ -170,14 +158,48 @@ cp void dump_conn_list(void) { conn_list_t *p; + subnet_t *s; + char *netstr; cp syslog(LOG_DEBUG, _("Connection list:")); + syslog(LOG_DEBUG, _("%s at %s port %hd flags %d sockets %d, %d status %04x"), + myself->name, myself->hostname, myself->port, myself->flags, + myself->socket, myself->meta_socket, myself->status); + + for(s = myself->subnets; s != NULL; s = s->next) + { + netstr = net2str(s); + syslog(LOG_DEBUG, ": %s", netstr); + free(netstr); + } + for(p = conn_list; p != NULL; p = p->next) { - syslog(LOG_DEBUG, _("%s netmask %d.%d.%d.%d at %s port %hd flags %d sockets %d, %d status %04x"), - p->name, IP_ADDR_V(p->vpn_mask), p->hostname, p->port, p->flags, + syslog(LOG_DEBUG, _("%s at %s port %hd flags %d sockets %d, %d status %04x"), + p->name, p->hostname, p->port, p->flags, p->socket, p->meta_socket, p->status); + + for(s = p->subnets; s != NULL; s = s->next) + { + netstr = net2str(s); + syslog(LOG_DEBUG, ": %s", netstr); + free(netstr); + } } + + syslog(LOG_DEBUG, _("End of connection list.")); +cp +} + +int read_host_config(conn_list_t *cl) +{ + char *fname; + int x; +cp + asprintf(&fname, "%s/hosts/%s", confbase, cl->name); + x = read_config_file(&cl->config, fname); + free(fname); cp + return x; }