along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: rbl.c,v 1.1.2.9 2000/11/21 09:13:59 guus Exp $
+ $Id: rbl.c,v 1.1.2.10 2000/11/22 18:54:07 guus Exp $
*/
#include "config.h"
#include <stdlib.h>
#include <xalloc.h>
+#include <stdio.h>
#include "rbl.h"
#include <system.h>
{
rbl_t *rbl, *next;
int result;
-
+
next = rbl = tree->top;
while(next)
void *rbl_search_closest(rbltree_t *tree, void *data)
{
- return rbl_search_closest_rbl(tree, data)->data;
+ rbl_t *rbl;
+
+ rbl = rbl_search_closest_rbl(tree, data);
+
+ if(rbl)
+ return rbl->data;
+ else
+ return NULL;
}
/* Search exact match or return NULL pointer */
rbl_t *rbl_search_rbl(rbltree_t *tree, void *data)
{
- rbl_t *rbl, *next;
+ rbl_t *rbl;
int result;
+
+ rbl = tree->top;
- next = rbl = tree->top;
-
- while(next)
+ while(rbl)
{
- rbl = next;
-
result = tree->compare(data, rbl->data);
if(result < 0)
- next = rbl->left;
+ rbl = rbl->left;
else if(result > 0)
- next = rbl->right;
+ rbl = rbl->right;
else
return rbl;
}
-
+
return NULL;
}
if(y->color == RBL_BLACK && x)
rbl_delete_fixup(x);
-
+
return rbl;
}
rbl = rbl_search_rbl(tree, data);
if(rbl)
- return rbl_unlink_rbl(rbl);
- else
- return NULL;
+ rbl_unlink_rbl(rbl);
+
+ return rbl;
}
/* Unlink node and free it */
void rbl_delete_rbl(rbl_t *rbl)
{
- free_rbl(rbl_unlink_rbl(rbl));
+ rbl_unlink_rbl(rbl);
+ free_rbl(rbl);
}
/* Search node in tree, unlink and free it */
void rbl_delete(rbltree_t *tree, void *data)
{
- free_rbl(rbl_unlink(tree, data));
-}
-
-rbl_unlink_rbltree_branch(rbl_t *rbl)
-{
- if(rbl->left)
- rbl_unlink_rbltree_branch(rbl->left);
+ rbl_t *rbl;
- if(rbl->right)
- rbl_unlink_rbltree_branch(rbl->right);
+ rbl = rbl_unlink(tree, data);
- if(rbl->parent)
- {
- if(rbl == rbl->parent->left)
- rbl->parent->left = NULL;
- else
- rbl->parent->right = NULL;
- }
+ if(rbl)
+ free_rbl(rbl);
}
/* Optimized unlinking for a complete tree */
for(rbl = tree->head; rbl; rbl = next)
{
next = rbl->next;
- if(tree->delete)
- tree->delete(rbl->data);
+ free_rbl(rbl);
}
tree->top = NULL;
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: connection.c,v 1.1.2.3 2000/11/20 22:13:03 guus Exp $
+ $Id: connection.c,v 1.1.2.4 2000/11/22 18:54:07 guus Exp $
*/
#include "config.h"
/* Root of the connection list */
rbltree_t *connection_tree;
+rbltree_t *id_tree;
+
connection_t *myself = NULL;
/* Initialization and callbacks */
int connection_compare(connection_t *a, connection_t *b)
+{
+ ipv4_t result;
+ result = a->address - b->address;
+ if(result)
+ return result;
+ else
+ return a->port - b->port;
+}
+
+int id_compare(connection_t *a, connection_t *b)
{
return strcmp(a->name, b->name);
}
void init_connections(void)
{
connection_tree = new_rbltree((rbl_compare_t)connection_compare, (rbl_action_t)free_connection);
+ id_tree = new_rbltree((rbl_compare_t)id_compare, NULL);
}
/* Creation and deletion of connection elements */
void destroy_connection_tree(void)
{
cp
+ rbl_delete_rbltree(id_tree);
rbl_delete_rbltree(connection_tree);
cp
}
cp
}
+void id_add(connection_t *cl)
+{
+cp
+ rbl_insert(id_tree, cl);
+cp
+}
+
void connection_del(connection_t *cl)
{
cp
+ rbl_delete(id_tree, cl);
rbl_delete(connection_tree, cl);
cp
}
/* Lookup functions */
+connection_t *lookup_connection(ipv4_t address, short unsigned int port)
+{
+ connection_t cl, *p;
+cp
+ cl.address = address;
+ cl.port = port;
+
+ return rbl_search(connection_tree, &cl);
+}
+
connection_t *lookup_id(char *name)
{
connection_t cl, *p;
cp
cl.name = name;
- p = rbl_search(connection_tree, &cl);
+ p = rbl_search(id_tree, &cl);
if(p && p->status.active)
return p;
else
return NULL;
-cp
}
/* Debugging */
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: netutl.c,v 1.12.4.15 2000/11/04 22:57:31 guus Exp $
+ $Id: netutl.c,v 1.12.4.16 2000/11/22 18:54:08 guus Exp $
*/
#include "config.h"
if(!(h = gethostbyname(p)))
{
- fprintf(stderr, _("Error looking up `%s': %s\n"), p, strerror(errno));
+ if(debug_lvl >= DEBUG_ERROR)
+ syslog(LOG_WARNING, _("Error looking up `%s': %s\n"), p, strerror(errno));
+
return NULL;
}
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: protocol.c,v 1.28.4.62 2000/11/20 19:12:13 guus Exp $
+ $Id: protocol.c,v 1.28.4.63 2000/11/22 18:54:08 guus Exp $
*/
#include "config.h"
}
/* Load information about peer */
-cp
+
if(read_host_config(cl))
{
syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->name);
connection list. If so, we are probably making a loop, which
is not desirable.
*/
-cp
+
if(cl->status.outgoing)
{
if((old = lookup_id(cl->name)))
return 0;
}
}
-cp
+
+ /* Now we can add the name to the id tree */
+
+ id_add(cl);
+
+ /* Read in the public key, so that we can send a challenge */
+
if((cfg = get_config_val(cl->config, config_publickey)))
{
cl->rsa_key = RSA_new();
{
syslog(LOG_ERR, _("Got ADD_SUBNET for %s from %s (%s) which is not in our connection list"),
name, cl->name, cl->hostname);
+ cp_trace();
+ dump_connection_list();
+ {
+ connection_t cl;
+ rbl_t *rbl;
+ cl.name = name;
+ rbl = rbl_search_rbl(connection_tree, &cl);
+ syslog(LOG_ERR, "rbl_search_rbl: %p", rbl);
+ if(rbl)
+ syslog(LOG_ERR, "rbl->data->name: %s", ((connection_t *)rbl->data)->name);
+ }
free(name);
return -1;
}
/* Hook it up into the connection */
connection_add(new);
+ id_add(new);
/* Tell the rest about the new host */