- Cleaned up and checked for some more NULL pointers in rbl.c

- Two connection lists: one for incoming connections, sorted on ip/port,
  one for connections whose identity we know, sorted on id ofcourse...
This commit is contained in:
Guus Sliepen 2000-11-22 18:54:08 +00:00
parent 785684f0ec
commit f8b4a000d0
4 changed files with 89 additions and 44 deletions

View file

@ -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: 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"
@ -40,11 +40,23 @@
/* 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);
}
@ -52,6 +64,7 @@ int connection_compare(connection_t *a, connection_t *b)
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 */
@ -114,6 +127,7 @@ cp
void destroy_connection_tree(void)
{
cp
rbl_delete_rbltree(id_tree);
rbl_delete_rbltree(connection_tree);
cp
}
@ -127,26 +141,43 @@ 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 */

View file

@ -16,7 +16,7 @@
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"
@ -111,7 +111,9 @@ cp
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;
}

View file

@ -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: 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"
@ -216,7 +216,7 @@ cp
}
/* Load information about peer */
cp
if(read_host_config(cl))
{
syslog(LOG_ERR, _("Peer %s had unknown identity (%s)"), cl->hostname, cl->name);
@ -227,7 +227,7 @@ cp
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)))
@ -240,7 +240,13 @@ cp
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();
@ -722,6 +728,17 @@ cp
{
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;
}
@ -896,6 +913,7 @@ cp
/* Hook it up into the connection */
connection_add(new);
id_add(new);
/* Tell the rest about the new host */