Use iface instead of interface because it might already be declared in
[oweals/tinc.git] / src / graph.c
index b7c285fa32dd59b852c5222b64fdc8b9ab674149..147586e50220bf286faffc840b0e8c506ea436ea 100644 (file)
@@ -1,7 +1,7 @@
 /*
     graph.c -- graph algorithms
-    Copyright (C) 2001-2002 Guus Sliepen <guus@sliepen.eu.org>,
-                  2001-2002 Ivo Timmermans <ivo@o2w.nl>
+    Copyright (C) 2001-2003 Guus Sliepen <guus@sliepen.eu.org>,
+                  2001-2003 Ivo Timmermans <ivo@o2w.nl>
 
     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
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: graph.c,v 1.1.2.21 2002/09/10 22:12:33 guus Exp $
+    $Id: graph.c,v 1.1.2.26 2003/07/18 13:45:06 guus Exp $
 */
 
 /* We need to generate two trees from the graph:
    destination address and port of a node if possible.
 */
 
-#include "config.h"
-
-#include <stdio.h>
-#include <syslog.h>
-#include <string.h>
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#include <netinet/in.h>
-
-#include <avl_tree.h>
-#include <utils.h>
+#include "system.h"
 
+#include "avl_tree.h"
+#include "connection.h"
+#include "device.h"
+#include "edge.h"
+#include "logger.h"
 #include "netutl.h"
 #include "node.h"
-#include "edge.h"
-#include "connection.h"
 #include "process.h"
-#include "device.h"
-
-#include "system.h"
+#include "utils.h"
 
 /* Implementation of Kruskal's algorithm.
    Running time: O(EN)
@@ -95,8 +85,7 @@ void mst_kruskal(void)
        if(!edge_weight_tree->head)
                return;
 
-       if(debug_lvl >= DEBUG_SCARY_THINGS)
-               syslog(LOG_DEBUG, "Running Kruskal's algorithm:");
+       ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Running Kruskal's algorithm:");
 
        /* Clear visited status on nodes */
 
@@ -132,8 +121,7 @@ void mst_kruskal(void)
 
                safe_edges++;
 
-               if(debug_lvl >= DEBUG_SCARY_THINGS)
-                       syslog(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
+               ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
                                   e->to->name, e->weight);
 
                if(skipped) {
@@ -143,8 +131,7 @@ void mst_kruskal(void)
                }
        }
 
-       if(debug_lvl >= DEBUG_SCARY_THINGS)
-               syslog(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
+       ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
                           safe_edges);
 }
 
@@ -201,26 +188,25 @@ void sssp_bfs(void)
 
                                /* Situation:
 
-                                  /
+                                   /
                                   /
                                   ------(n)-----(e->to)
                                   \
-                                  \
+                                   \
 
                                   n->address is set to the e->address of the edge left of n to n.
                                   We are currently examining the edge e right of n from n:
 
                                   - If e->reverse->address != n->address, then e->to is probably
-                                  not reachable for the nodes left of n. We do as if the indirectdata
-                                  flag is set on edge e.
+                                    not reachable for the nodes left of n. We do as if the indirectdata
+                                    flag is set on edge e.
                                   - If edge e provides for better reachability of e->to, update
-                                  e->to and (re)add it to the todo_tree to (re)examine the reachability
-                                  of nodes behind it.
+                                    e->to and (re)add it to the todo_tree to (re)examine the reachability
+                                    of nodes behind it.
                                 */
 
                                indirect = n->status.indirect || e->options & OPTION_INDIRECT
-                                       || ((n != myself)
-                                               && sockaddrcmp(&n->address, &e->reverse->address));
+                                       || ((n != myself) && sockaddrcmp(&n->address, &e->reverse->address));
 
                                if(e->to->status.visited
                                   && (!e->to->status.indirect || indirect))
@@ -263,13 +249,12 @@ void sssp_bfs(void)
                if(n->status.visited != n->status.reachable) {
                        n->status.reachable = !n->status.reachable;
 
-                       if(debug_lvl >= DEBUG_TRAFFIC) {
-                               if(n->status.reachable)
-                                       syslog(LOG_DEBUG, _("Node %s (%s) became reachable"),
-                                                  n->name, n->hostname);
-                               else
-                                       syslog(LOG_DEBUG, _("Node %s (%s) became unreachable"),
-                                                  n->name, n->hostname);
+                       if(n->status.reachable) {
+                               ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Node %s (%s) became reachable"),
+                                          n->name, n->hostname);
+                       } else {
+                               ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Node %s (%s) became unreachable"),
+                                          n->name, n->hostname);
                        }
 
                        n->status.validkey = 0;
@@ -277,7 +262,7 @@ void sssp_bfs(void)
 
                        asprintf(&envp[0], "NETNAME=%s", netname ? : "");
                        asprintf(&envp[1], "DEVICE=%s", device ? : "");
-                       asprintf(&envp[2], "INTERFACE=%s", interface ? : "");
+                       asprintf(&envp[2], "INTERFACE=%s", iface ? : "");
                        asprintf(&envp[3], "NODE=%s", n->name);
                        sockaddr2str(&n->address, &address, &port);
                        asprintf(&envp[4], "REMOTEADDRESS=%s", address);