struct addrinfo *ai = NULL;
struct addrinfo *oai = NULL;
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
if(!e->reverse) {
continue;
}
int count = 0;
for list_each(connection_t, c, &connection_list) {
- if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2) {
+ if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree.count < 2) {
continue;
}
int r = rand() % count;
for list_each(connection_t, c, &connection_list) {
- if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2) {
+ if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree.count < 2) {
continue;
}
return strcmp(a->to->name, b->to->name);
}
-splay_tree_t *new_edge_tree(void) {
- return splay_alloc_tree((splay_compare_t) edge_compare, (splay_action_t) free_edge);
-}
-
-void free_edge_tree(splay_tree_t *edge_tree) {
- splay_delete_tree(edge_tree);
+void init_edge_tree(splay_tree_t *tree) {
+ memset(tree, 0, sizeof(*tree));
+ tree->compare = (splay_compare_t) edge_compare;
+ tree->delete = (splay_action_t) free_edge;
}
void exit_edges(void) {
}
void edge_add(edge_t *e) {
- splay_node_t *node = splay_insert(e->from->edge_tree, e);
+ splay_node_t *node = splay_insert(&e->from->edge_tree, e);
if(!node) {
logger(DEBUG_ALWAYS, LOG_ERR, "Edge from %s to %s already exists in edge_tree\n", e->from->name, e->to->name);
}
splay_delete(&edge_weight_tree, e);
- splay_delete(e->from->edge_tree, e);
+ splay_delete(&e->from->edge_tree, e);
}
edge_t *lookup_edge(node_t *from, node_t *to) {
v.from = from;
v.to = to;
- return splay_search(from->edge_tree, &v);
+ return splay_search(&from->edge_tree, &v);
}
bool dump_edges(connection_t *c) {
for splay_each(node_t, n, &node_tree) {
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
char *address = sockaddr2hostname(&e->address);
char *local_address = sockaddr2hostname(&e->local_address);
send_request(c, "%d %d %s %s %s %s %x %d",
extern void exit_edges(void);
extern edge_t *new_edge(void) __attribute__((__malloc__));
extern void free_edge(edge_t *e);
-extern splay_tree_t *new_edge_tree(void) __attribute__((__malloc__));
-extern void free_edge_tree(splay_tree_t *edge_tree);
+extern void init_edge_tree(splay_tree_t *tree);
extern void edge_add(edge_t *e);
extern void edge_del(edge_t *e);
extern edge_t *lookup_edge(struct node_t *from, struct node_t *to);
abort();
}
- for splay_each(edge_t, e, n->edge_tree) { /* "e" is the edge connected to "from" */
+ for splay_each(edge_t, e, &n->edge_tree) { /* "e" is the edge connected to "from" */
if(!e->reverse || e->to == myself) {
continue;
}
if(!n->status.reachable) {
logger(DEBUG_SCARY_THINGS, LOG_DEBUG, "Purging node %s (%s)", n->name, n->hostname);
- for splay_each(subnet_t, s, n->subnet_tree) {
+ for splay_each(subnet_t, s, &n->subnet_tree) {
send_del_subnet(everyone, s);
if(!strictsubnets) {
}
}
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
if(!tunnelserver) {
send_del_edge(everyone, e);
}
return;
}
- if(!autoconnect && (!strictsubnets || !n->subnet_tree->head))
+ if(!autoconnect && (!strictsubnets || !n->subnet_tree.head))
/* in strictsubnets mode do not delete nodes with subnets */
{
node_del(n);
}
}
} else { /* Only read our own subnets back in */
- for splay_each(subnet_t, subnet, myself->subnet_tree)
+ for splay_each(subnet_t, subnet, &myself->subnet_tree)
if(!subnet->expires) {
subnet->expires = 1;
}
cfg = lookup_config_next(&config_tree, cfg);
}
- for splay_each(subnet_t, subnet, myself->subnet_tree) {
+ for splay_each(subnet_t, subnet, &myself->subnet_tree) {
if(subnet->expires == 1) {
send_del_subnet(everyone, subnet);
subnet_update(myself, subnet, false);
So we pick a random edge and a random socket. */
unsigned int i = 0;
- unsigned int j = rand() % n->edge_tree->count;
+ unsigned int j = rand() % n->edge_tree.count;
edge_t *candidate = NULL;
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
if(i++ == j) {
candidate = e->reverse;
break;
/* Pick one of the edges from this node at random, then use its local address. */
unsigned int i = 0;
- unsigned int j = rand() % n->edge_tree->count;
+ unsigned int j = rand() % n->edge_tree.count;
edge_t *candidate = NULL;
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
if(i++ == j) {
candidate = e;
break;
bool soft = false;
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
if(!e->reverse) {
continue;
}
n->late = xzalloc(replaywin);
}
- n->subnet_tree = new_subnet_tree();
- n->edge_tree = new_edge_tree();
+ init_subnet_tree(&n->subnet_tree);
+ init_edge_tree(&n->edge_tree);
+
n->mtu = MTU;
n->maxmtu = MTU;
n->udp_ping_rtt = -1;
}
void free_node(node_t *n) {
- if(n->subnet_tree) {
- free_subnet_tree(n->subnet_tree);
- }
-
- if(n->edge_tree) {
- free_edge_tree(n->edge_tree);
- }
+ splay_empty_tree(&n->subnet_tree);
+ splay_empty_tree(&n->edge_tree);
sockaddrfree(&n->address);
void node_del(node_t *n) {
splay_delete(&node_udp_tree, n);
- for splay_each(subnet_t, s, n->subnet_tree) {
+ for splay_each(subnet_t, s, &n->subnet_tree) {
subnet_del(n, s);
}
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
edge_del(e);
}
struct edge_t *prevedge; /* nearest node from him to us */
struct node_t *via; /* next hop for UDP packets */
- splay_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */
+ splay_tree_t subnet_tree; /* Pointer to a tree of subnets belonging to this node */
- splay_tree_t *edge_tree; /* Edges with this node as one of the endpoints */
+ splay_tree_t edge_tree; /* Edges with this node as one of the endpoints */
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
}
if(tunnelserver) {
- for splay_each(subnet_t, s, myself->subnet_tree) {
+ for splay_each(subnet_t, s, &myself->subnet_tree) {
send_add_subnet(c, s);
}
}
for splay_each(node_t, n, &node_tree) {
- for splay_each(subnet_t, s, n->subnet_tree) {
+ for splay_each(subnet_t, s, &n->subnet_tree) {
send_add_subnet(c, s);
}
- for splay_each(edge_t, e, n->edge_tree) {
+ for splay_each(edge_t, e, &n->edge_tree) {
send_add_edge(c, e);
}
}
(void)data;
bool left = false;
- for splay_each(subnet_t, s, myself->subnet_tree) {
+ for splay_each(subnet_t, s, &myself->subnet_tree) {
if(s->expires && s->expires < now.tv_sec) {
if(debug_level >= DEBUG_TRAFFIC) {
char netstr[MAXNETSTR];
hash_free(mac_cache);
}
-splay_tree_t *new_subnet_tree(void) {
- return splay_alloc_tree((splay_compare_t) subnet_compare, NULL);
-}
-
-void free_subnet_tree(splay_tree_t *subnet_tree) {
- splay_delete_tree(subnet_tree);
+void init_subnet_tree(splay_tree_t *tree) {
+ memset(tree, 0, sizeof(*tree));
+ tree->compare = (splay_compare_t) subnet_compare;
}
/* Allocating and freeing space for subnets */
splay_insert(&subnet_tree, subnet);
if(n) {
- splay_insert(n->subnet_tree, subnet);
+ splay_insert(&n->subnet_tree, subnet);
}
subnet_cache_flush();
void subnet_del(node_t *n, subnet_t *subnet) {
if(n) {
- splay_delete(n->subnet_tree, subnet);
+ splay_delete(&n->subnet_tree, subnet);
}
splay_delete(&subnet_tree, subnet);
/* Subnet lookup routines */
-subnet_t *lookup_subnet(const node_t *owner, const subnet_t *subnet) {
- return splay_search(owner->subnet_tree, subnet);
+subnet_t *lookup_subnet(node_t *owner, const subnet_t *subnet) {
+ return splay_search(&owner->subnet_tree, subnet);
}
subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) {
// Search all subnets for a matching one
- for splay_each(subnet_t, p, owner ? owner->subnet_tree : &subnet_tree) {
+ for splay_each(subnet_t, p, owner ? &owner->subnet_tree : &subnet_tree) {
if(!p || p->type != SUBNET_MAC) {
continue;
}
name = up ? "subnet-up" : "subnet-down";
if(!subnet) {
- for splay_each(subnet_t, subnet, owner->subnet_tree) {
+ for splay_each(subnet_t, subnet, &owner->subnet_tree) {
if(!net2str(netstr, sizeof(netstr), subnet)) {
continue;
}
extern void free_subnet(subnet_t *subnet);
extern void init_subnets(void);
extern void exit_subnets(void);
-extern splay_tree_t *new_subnet_tree(void) __attribute__((__malloc__));
-extern void free_subnet_tree(splay_tree_t *);
+extern void init_subnet_tree(splay_tree_t *tree);
extern void subnet_add(struct node_t *owner, subnet_t *subnet);
extern void subnet_del(struct node_t *owner, subnet_t *subnet);
extern void subnet_update(struct node_t *owner, subnet_t *subnet, bool up);
extern bool maskcheck(const void *mask, size_t masklen, size_t len);
extern bool net2str(char *netstr, size_t len, const subnet_t *subnet);
extern bool str2net(subnet_t *subnet, const char *netstr);
-extern subnet_t *lookup_subnet(const struct node_t *owner, const subnet_t *subnet);
+extern subnet_t *lookup_subnet(struct node_t *owner, const subnet_t *subnet);
extern subnet_t *lookup_subnet_mac(const struct node_t *owner, const mac_t *address);
extern subnet_t *lookup_subnet_ipv4(const ipv4_t *address);
extern subnet_t *lookup_subnet_ipv6(const ipv6_t *address);