From: Guus Sliepen Date: Sat, 26 Apr 2014 08:12:33 +0000 (+0200) Subject: Stop using global variable mesh in net_setup.[ch]. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=a42b1de9411a578f6af6fc0e9fe04b5781a0bd60;p=meshlink Stop using global variable mesh in net_setup.[ch]. --- diff --git a/src/meshlink.c b/src/meshlink.c index 6f4bff4f..b5664985 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -243,7 +243,7 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { // Setup up everything // TODO: we should not open listening sockets yet - if(!setup_network()) + if(!setup_network(mesh)) return meshlink_close(mesh), NULL; return mesh; diff --git a/src/net.c b/src/net.c index 0f5908e0..d271a346 100644 --- a/src/net.c +++ b/src/net.c @@ -286,7 +286,7 @@ int reload_configuration(void) { /* Parse some options that are allowed to be changed while tinc is running */ - setup_myself_reloadable(); + setup_myself_reloadable(mesh); /* Try to make outgoing connections */ diff --git a/src/net.h b/src/net.h index 2e384778..524a52e6 100644 --- a/src/net.h +++ b/src/net.h @@ -93,24 +93,22 @@ extern bool receive_sptps_record(void *handle, uint8_t type, const char *data, u extern void send_packet(struct node_t *, struct vpn_packet_t *); extern void receive_tcppacket(struct connection_t *, const char *, int); extern void broadcast_packet(const struct node_t *, struct vpn_packet_t *); -extern char *get_name(void); -extern bool setup_myself_reloadable(void); -extern bool setup_network(void); +extern char *get_name(struct meshlink_handle *mesh); +extern bool setup_myself_reloadable(struct meshlink_handle *mesh); +extern bool setup_network(struct meshlink_handle *mesh); extern void setup_outgoing_connection(struct outgoing_t *); extern void try_outgoing_connections(void); extern void close_network_connections(void); extern int main_loop(void); extern void terminate_connection(struct connection_t *, bool); -extern bool node_read_ecdsa_public_key(struct node_t *); -extern bool read_ecdsa_public_key(struct connection_t *); +extern bool node_read_ecdsa_public_key(struct meshlink_handle *mesh, struct node_t *); +extern bool read_ecdsa_public_key(struct meshlink_handle *mesh, struct connection_t *); extern void send_mtu_probe(struct node_t *); extern void handle_meta_connection_data(struct connection_t *); extern void regenerate_key(void); extern void purge(void); extern void retry(void); extern int reload_configuration(void); -extern void load_all_subnets(void); -extern void load_all_nodes(void); #ifndef HAVE_MINGW #define closesocket(s) close(s) diff --git a/src/net_setup.c b/src/net_setup.c index 5390d804..1ebacffa 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -34,7 +34,7 @@ int autoconnect = 3; -bool node_read_ecdsa_public_key(node_t *n) { +bool node_read_ecdsa_public_key(meshlink_handle_t *mesh, node_t *n) { if(ecdsa_active(n->ecdsa)) return true; @@ -57,7 +57,7 @@ exit: return n->ecdsa; } -bool read_ecdsa_public_key(connection_t *c) { +bool read_ecdsa_public_key(meshlink_handle_t *mesh, connection_t *c) { if(ecdsa_active(c->ecdsa)) return true; @@ -80,7 +80,7 @@ bool read_ecdsa_public_key(connection_t *c) { return false; } -static bool read_ecdsa_private_key(void) { +static bool read_ecdsa_private_key(meshlink_handle_t *mesh) { FILE *fp; char filename[PATH_MAX]; @@ -101,7 +101,7 @@ static bool read_ecdsa_private_key(void) { return mesh->self->connection->ecdsa; } -static bool read_invitation_key(void) { +static bool read_invitation_key(meshlink_handle_t *mesh) { FILE *fp; char filename[PATH_MAX]; @@ -124,7 +124,7 @@ static bool read_invitation_key(void) { return mesh->invitation_key; } -void load_all_nodes(void) { +static void load_all_nodes(meshlink_handle_t *mesh) { DIR *dir; struct dirent *ent; char dname[PATH_MAX]; @@ -153,7 +153,7 @@ void load_all_nodes(void) { } -char *get_name(void) { +char *get_name(meshlink_handle_t *mesh) { char *name = NULL; get_config_string(lookup_config(mesh->config, "Name"), &name); @@ -170,14 +170,14 @@ char *get_name(void) { return name; } -bool setup_myself_reloadable(void) { +bool setup_myself_reloadable(meshlink_handle_t *mesh) { mesh->localdiscovery = true; keylifetime = 3600; // TODO: check if this can be removed as well mesh->maxtimeout = 900; autoconnect = 3; mesh->self->options |= OPTION_PMTU_DISCOVERY; - read_invitation_key(); + read_invitation_key(mesh); return true; } @@ -185,7 +185,7 @@ bool setup_myself_reloadable(void) { /* Add listening sockets. */ -static bool add_listen_address(char *address, bool bindto) { +static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bindto) { char *port = mesh->myport; if(address) { @@ -264,12 +264,12 @@ static bool add_listen_address(char *address, bool bindto) { /* Configure node_t mesh->self and set up the local sockets (listen only) */ -bool setup_myself(void) { +bool setup_myself(meshlink_handle_t *mesh) { char *name, *hostname, *cipher, *digest, *type; char *address = NULL; bool port_specified = false; - if(!(name = get_name())) { + if(!(name = get_name(mesh))) { logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!"); return false; } @@ -291,7 +291,7 @@ bool setup_myself(void) { mesh->self->options |= PROT_MINOR << 24; - if(!read_ecdsa_private_key()) + if(!read_ecdsa_private_key(mesh)) return false; /* Ensure mesh->myport is numeric */ @@ -308,7 +308,7 @@ bool setup_myself(void) { /* Check some options */ - if(!setup_myself_reloadable()) + if(!setup_myself_reloadable(mesh)) return false; /* Compression */ @@ -328,14 +328,14 @@ bool setup_myself(void) { graph(); if(autoconnect) - load_all_nodes(); + load_all_nodes(mesh); /* Open sockets */ mesh->listen_sockets = 0; int cfgs = 0; - if(!add_listen_address(address, NULL)) + if(!add_listen_address(mesh, address, NULL)) return false; if(!mesh->listen_sockets) { @@ -361,7 +361,7 @@ bool setup_myself(void) { /* initialize network */ -bool setup_network(void) { +bool setup_network(meshlink_handle_t *mesh) { init_connections(); init_nodes(); init_edges(); @@ -371,7 +371,7 @@ bool setup_network(void) { mesh->pingtimeout = 5; maxoutbufsize = 10 * MTU; - if(!setup_myself()) + if(!setup_myself(mesh)) return false; return true; diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 7864ee58..107280c1 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -322,7 +322,7 @@ bool id_h(connection_t *c, const char *request) { return false; } - read_ecdsa_public_key(c); + read_ecdsa_public_key(mesh, c); } else { if(c->protocol_minor && !ecdsa_active(c->ecdsa)) c->protocol_minor = 1; diff --git a/src/protocol_key.c b/src/protocol_key.c index 6ffc7ce9..6f4364f2 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -80,7 +80,7 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const char *data } bool send_req_key(node_t *to) { - if(!node_read_ecdsa_public_key(to)) { + if(!node_read_ecdsa_public_key(mesh, to)) { logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", to->name, to->hostname); send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY); return true; @@ -111,7 +111,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in } case ANS_PUBKEY: { - if(node_read_ecdsa_public_key(from)) { + if(node_read_ecdsa_public_key(mesh, from)) { logger(DEBUG_PROTOCOL, LOG_WARNING, "Got ANS_PUBKEY from %s (%s) even though we already have his pubkey", from->name, from->hostname); return true; } @@ -128,7 +128,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in } case REQ_KEY: { - if(!node_read_ecdsa_public_key(from)) { + if(!node_read_ecdsa_public_key(mesh, from)) { logger(DEBUG_PROTOCOL, LOG_DEBUG, "No ECDSA key known for %s (%s)", from->name, from->hostname); send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY); return true;