projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed some errors
[tinc]
/
src
/
subnet.c
diff --git
a/src/subnet.c
b/src/subnet.c
index
8e50646
..
a08e2de
100644
(file)
--- a/
src/subnet.c
+++ b/
src/subnet.c
@@
-1,7
+1,7
@@
/*
subnet.c -- handle subnet lookups and lists
/*
subnet.c -- handle subnet lookups and lists
- Copyright (C) 2000 Guus Sliepen <guus@sliepen.warande.net>,
- 2000 Ivo Timmermans <itimmermans@bigfoot.com>
+ Copyright (C) 2000
,2001
Guus Sliepen <guus@sliepen.warande.net>,
+ 2000
,2001
Ivo Timmermans <itimmermans@bigfoot.com>
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
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.
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: subnet.c,v 1.1.2.1
4 2000/11/20 22:13:13
guus Exp $
+ $Id: subnet.c,v 1.1.2.1
8 2001/01/07 20:19:08
guus Exp $
*/
#include "config.h"
*/
#include "config.h"
@@
-33,16
+33,16
@@
#include <utils.h>
#include <xalloc.h>
#include <utils.h>
#include <xalloc.h>
-#include <
rbl
.h>
+#include <
avl_tree
.h>
/* lists type of subnet */
/* lists type of subnet */
-
rbl
tree_t *subnet_tree;
+
avl_
tree_t *subnet_tree;
void init_subnets(void)
{
cp
void init_subnets(void)
{
cp
- subnet_tree =
new_rbltree((rbl_compare_t)subnet_compare, (rb
l_action_t)free_subnet);
+ subnet_tree =
avl_alloc_tree((avl_compare_t)subnet_compare, (av
l_action_t)free_subnet);
cp
}
cp
}
@@
-131,16
+131,17
@@
void subnet_add(connection_t *cl, subnet_t *subnet)
{
cp
subnet->owner = cl;
{
cp
subnet->owner = cl;
-
rb
l_insert(subnet_tree, subnet);
-
rb
l_insert(cl->subnet_tree, subnet);
+
av
l_insert(subnet_tree, subnet);
+
av
l_insert(cl->subnet_tree, subnet);
cp
}
void subnet_del(subnet_t *subnet)
{
cp
cp
}
void subnet_del(subnet_t *subnet)
{
cp
- rbl_delete(subnet->owner->subnet_tree, subnet);
- rbl_delete(subnet_tree, subnet);
+ avl_delete(subnet->owner->subnet_tree, subnet);
+cp
+ avl_delete(subnet_tree, subnet);
cp
}
cp
}
@@
-255,45
+256,65
@@
cp
/* Subnet lookup routines */
/* Subnet lookup routines */
-subnet_t *lookup_subnet_mac(mac_t address)
+subnet_t *lookup_subnet_mac(mac_t
*
address)
{
{
- subnet_t subnet;
+ subnet_t subnet
, *p
;
cp
subnet.type = SUBNET_MAC;
cp
subnet.type = SUBNET_MAC;
- subnet.net.mac.address = address;
- return (subnet_t *)rbl_search_closest(subnet_tree, &subnet);
+ memcpy(&subnet.net.mac.address, address, sizeof(mac_t));
+
+ p = (subnet_t *)avl_search(subnet_tree, &subnet);
+cp
+ return p;
}
}
-subnet_t *lookup_subnet_ipv4(ipv4_t address)
+subnet_t *lookup_subnet_ipv4(ipv4_t
*
address)
{
{
- subnet_t subnet;
+ subnet_t subnet
, *p
;
cp
subnet.type = SUBNET_IPV4;
cp
subnet.type = SUBNET_IPV4;
- subnet.net.ipv4.address = address;
+ subnet.net.ipv4.address =
*
address;
subnet.net.ipv4.mask = 0xFFFFFFFF;
subnet.net.ipv4.mask = 0xFFFFFFFF;
- return (subnet_t *)rbl_search_closest(subnet_tree, &subnet);
+
+ p = (subnet_t *)avl_search_closest_greater(subnet_tree, &subnet);
+
+ /* Check if the found subnet REALLY matches */
+cp
+ if(p && ((*address & p->net.ipv4.mask) == p->net.ipv4.address))
+ return p;
+ else
+ return NULL;
}
}
-subnet_t *lookup_subnet_ipv6(ipv6_t address)
+subnet_t *lookup_subnet_ipv6(ipv6_t
*
address)
{
{
- subnet_t subnet;
+ subnet_t subnet, *p;
+ int i;
cp
subnet.type = SUBNET_IPV6;
cp
subnet.type = SUBNET_IPV6;
-
subnet.net.ipv6.address = address
;
+
memcpy(&subnet.net.ipv6.address, address, sizeof(ipv6_t))
;
memset(&subnet.net.ipv6.mask, 0xFF, 16);
memset(&subnet.net.ipv6.mask, 0xFF, 16);
- return (subnet_t *)rbl_search_closest(subnet_tree, &subnet);
+
+ p = (subnet_t *)avl_search_closest_greater(subnet_tree, &subnet);
+
+ if(p)
+ for(i=0; i<8; i++)
+ if((address->x[i] & p->net.ipv6.address.x[i]) != p->net.ipv6.address.x[i])
+ return NULL;
+
+ return p;
}
void dump_subnet_list(void)
{
char *netstr;
subnet_t *subnet;
}
void dump_subnet_list(void)
{
char *netstr;
subnet_t *subnet;
-
rbl_t *rbl
;
+
avl_node_t *node
;
cp
syslog(LOG_DEBUG, _("Subnet list:"));
cp
syslog(LOG_DEBUG, _("Subnet list:"));
-
RBL_FOREACH(subnet_tree, rbl
)
+
for(node = subnet_tree->head; node; node = node->next
)
{
{
- subnet = (subnet_t *)
rbl
->data;
+ subnet = (subnet_t *)
node
->data;
netstr = net2str(subnet);
syslog(LOG_DEBUG, " %s owner %s", netstr, subnet->owner->name);
free(netstr);
netstr = net2str(subnet);
syslog(LOG_DEBUG, " %s owner %s", netstr, subnet->owner->name);
free(netstr);