- Removed even more warnings.
[tinc] / src / connlist.c
index df10ce3..105049e 100644 (file)
     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.2 2000/10/11 22:00:58 guus Exp $
+    $Id: connlist.c,v 1.1.2.13 2000/11/04 11:49:56 guus Exp $
 */
 
+#include "config.h"
+
+#include <stdio.h>
 #include <syslog.h>
 
+#include "net.h"       /* Don't ask. */
+#include "netutl.h"
 #include "config.h"
+#include "conf.h"
 #include <utils.h>
 
-#include "net.h"       /* Don't ask. */
+#include "xalloc.h"
+#include "system.h"
 
 /* Root of the connection list */
 
@@ -51,12 +58,18 @@ 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);
+  if(p->config)
+    clear_config(&p->config);
   free(p);
 cp
 }
@@ -73,14 +86,7 @@ cp
       next = p->next;
 
       if(p->status.remove)
-       {
-         if(prev)
-           prev->next = next;
-         else
-           conn_list = next;
-
-         free_conn_element(p);
-       }
+        conn_list_del(p);
       else
        prev = p;
 
@@ -99,7 +105,7 @@ cp
   for(p = conn_list; p != NULL; )
     {
       next = p->next;
-      free_conn_element(p);
+      free_conn_list(p);
       p = next;
     }
 
@@ -114,7 +120,10 @@ void conn_list_add(conn_list_t *cl)
 cp
   cl->next = conn_list;
   cl->prev = NULL;
-  cl->next->prev = cl;
+
+  if(cl->next)
+    cl->next->prev = cl;
+
   conn_list = cl;
 cp
 }
@@ -127,7 +136,9 @@ cp
   else
     conn_list = cl->next;
   
-  cl->next->prev = cl->prev;
+  if(cl->next)
+    cl->next->prev = cl->prev;
+
   free_conn_list(cl);
 cp
 }
@@ -139,41 +150,9 @@ conn_list_t *lookup_id(char *name)
   conn_list_t *p;
 cp
   for(p = conn_list; p != NULL; p = p->next)
-    if(strcmp(name, p->name) == 0)
-      break;
-cp
-  return p;
-}
-
-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->subnets, 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->subnets, address))
-      break;
-cp
-  return p;
-}
-
-conn_list_t *lookup_conn_list_ipv6(ipv6_t address)
-{
-  conn_list_t *p;
-cp
-  for(p = conn_list; p != NULL; p = p->next)
-    if(lookup_subnet_ipv6(p->subnets, address))
-      break;
+    if(p->status.active)
+      if(strcmp(name, p->name) == 0)
+        break;
 cp
   return p;
 }
@@ -188,15 +167,27 @@ void dump_conn_list(void)
 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 at %s port %hd flags %d sockets %d, %d status %04x"),
+      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);
+          syslog(LOG_DEBUG, "  %s", netstr);
           free(netstr);
         }
     }
@@ -204,3 +195,15 @@ cp
   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;
+}