// 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;
/* 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 */
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)
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;
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;
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];
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];
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];
}
-char *get_name(void) {
+char *get_name(meshlink_handle_t *mesh) {
char *name = NULL;
get_config_string(lookup_config(mesh->config, "Name"), &name);
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;
}
/*
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) {
/*
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;
}
mesh->self->options |= PROT_MINOR << 24;
- if(!read_ecdsa_private_key())
+ if(!read_ecdsa_private_key(mesh))
return false;
/* Ensure mesh->myport is numeric */
/* Check some options */
- if(!setup_myself_reloadable())
+ if(!setup_myself_reloadable(mesh))
return false;
/* Compression */
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) {
/*
initialize network
*/
-bool setup_network(void) {
+bool setup_network(meshlink_handle_t *mesh) {
init_connections();
init_nodes();
init_edges();
mesh->pingtimeout = 5;
maxoutbufsize = 10 * MTU;
- if(!setup_myself())
+ if(!setup_myself(mesh))
return false;
return true;
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;
}
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;
}
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;
}
}
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;