projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Replace pointers to global splay trees with structs.
[tinc]
/
src
/
net_socket.c
diff --git
a/src/net_socket.c
b/src/net_socket.c
index
91f0bbb
..
6439a74
100644
(file)
--- a/
src/net_socket.c
+++ b/
src/net_socket.c
@@
-25,10
+25,8
@@
#include "address_cache.h"
#include "conf.h"
#include "connection.h"
#include "address_cache.h"
#include "conf.h"
#include "connection.h"
-#include "control_common.h"
#include "list.h"
#include "logger.h"
#include "list.h"
#include "logger.h"
-#include "meta.h"
#include "names.h"
#include "net.h"
#include "netutl.h"
#include "names.h"
#include "net.h"
#include "netutl.h"
@@
-51,7
+49,18
@@
int listen_sockets;
#ifndef HAVE_MINGW
io_t unix_socket;
#endif
#ifndef HAVE_MINGW
io_t unix_socket;
#endif
-list_t *outgoing_list = NULL;
+
+static void free_outgoing(outgoing_t *outgoing) {
+ timeout_del(&outgoing->ev);
+ free(outgoing);
+}
+
+list_t outgoing_list = {
+ .head = NULL,
+ .tail = NULL,
+ .count = 0,
+ .delete = (list_action_t)free_outgoing,
+};
/* Setup sockets */
/* Setup sockets */
@@
-106,7
+115,7
@@
static bool bind_to_interface(int sd) {
int status;
#endif /* defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) */
int status;
#endif /* defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) */
- if(!get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) {
+ if(!get_config_string(lookup_config(
&
config_tree, "BindToInterface"), &iface)) {
return true;
}
return true;
}
@@
-207,7
+216,7
@@
int setup_listen_socket(const sockaddr_t *sa) {
#endif
if(get_config_string
#endif
if(get_config_string
- (lookup_config(config_tree, "BindToInterface"), &iface)) {
+ (lookup_config(
&
config_tree, "BindToInterface"), &iface)) {
#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
struct ifreq ifr;
#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE)
struct ifreq ifr;
@@
-677,7
+686,7
@@
void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) {
return;
remove:
return;
remove:
- list_delete(outgoing_list, outgoing);
+ list_delete(
&
outgoing_list, outgoing);
}
/*
}
/*
@@
-706,8
+715,8
@@
void handle_new_meta_connection(void *data, int flags) {
static sockaddr_t prev_sa;
if(!sockaddrcmp_noport(&sa, &prev_sa)) {
static sockaddr_t prev_sa;
if(!sockaddrcmp_noport(&sa, &prev_sa)) {
- static
in
t samehost_burst;
- static
in
t samehost_burst_time;
+ static
time_
t samehost_burst;
+ static
time_
t samehost_burst_time;
if(now.tv_sec - samehost_burst_time > samehost_burst) {
samehost_burst = 0;
if(now.tv_sec - samehost_burst_time > samehost_burst) {
samehost_burst = 0;
@@
-728,8
+737,8
@@
void handle_new_meta_connection(void *data, int flags) {
// Check if we get many connections from different hosts
// Check if we get many connections from different hosts
- static
in
t connection_burst;
- static
in
t connection_burst_time;
+ static
time_
t connection_burst;
+ static
time_
t connection_burst_time;
if(now.tv_sec - connection_burst_time > connection_burst) {
connection_burst = 0;
if(now.tv_sec - connection_burst_time > connection_burst) {
connection_burst = 0;
@@
-811,25
+820,16
@@
void handle_new_unix_connection(void *data, int flags) {
}
#endif
}
#endif
-static void free_outgoing(outgoing_t *outgoing) {
- timeout_del(&outgoing->ev);
- free(outgoing);
-}
-
void try_outgoing_connections(void) {
/* If there is no outgoing list yet, create one. Otherwise, mark all outgoings as deleted. */
void try_outgoing_connections(void) {
/* If there is no outgoing list yet, create one. Otherwise, mark all outgoings as deleted. */
- if(!outgoing_list) {
- outgoing_list = list_alloc((list_action_t)free_outgoing);
- } else {
- for list_each(outgoing_t, outgoing, outgoing_list) {
- outgoing->timeout = -1;
- }
+ for list_each(outgoing_t, outgoing, &outgoing_list) {
+ outgoing->timeout = -1;
}
/* Make sure there is one outgoing_t in the list for each ConnectTo. */
}
/* Make sure there is one outgoing_t in the list for each ConnectTo. */
- for(config_t *cfg = lookup_config(
config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(
config_tree, cfg)) {
+ for(config_t *cfg = lookup_config(
&config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(&
config_tree, cfg)) {
char *name;
get_config_string(cfg, &name);
char *name;
get_config_string(cfg, &name);
@@
-848,7
+848,7
@@
void try_outgoing_connections(void) {
bool found = false;
bool found = false;
- for list_each(outgoing_t, outgoing, outgoing_list) {
+ for list_each(outgoing_t, outgoing,
&
outgoing_list) {
if(!strcmp(outgoing->node->name, name)) {
found = true;
outgoing->timeout = 0;
if(!strcmp(outgoing->node->name, name)) {
found = true;
outgoing->timeout = 0;
@@
-869,14
+869,14
@@
void try_outgoing_connections(void) {
free(name);
outgoing->node = n;
free(name);
outgoing->node = n;
- list_insert_tail(outgoing_list, outgoing);
+ list_insert_tail(
&
outgoing_list, outgoing);
setup_outgoing_connection(outgoing, true);
}
}
/* Terminate any connections whose outgoing_t is to be deleted. */
setup_outgoing_connection(outgoing, true);
}
}
/* Terminate any connections whose outgoing_t is to be deleted. */
- for list_each(connection_t, c, connection_list) {
+ for list_each(connection_t, c,
&
connection_list) {
if(c->outgoing && c->outgoing->timeout == -1) {
c->outgoing = NULL;
logger(DEBUG_CONNECTIONS, LOG_INFO, "No more outgoing connection to %s", c->name);
if(c->outgoing && c->outgoing->timeout == -1) {
c->outgoing = NULL;
logger(DEBUG_CONNECTIONS, LOG_INFO, "No more outgoing connection to %s", c->name);
@@
-886,8
+886,8
@@
void try_outgoing_connections(void) {
/* Delete outgoing_ts for which there is no ConnectTo. */
/* Delete outgoing_ts for which there is no ConnectTo. */
- for list_each(outgoing_t, outgoing, outgoing_list)
+ for list_each(outgoing_t, outgoing,
&
outgoing_list)
if(outgoing->timeout == -1) {
if(outgoing->timeout == -1) {
- list_delete_node(outgoing_list, node);
+ list_delete_node(
&
outgoing_list, node);
}
}
}
}