X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Flibmeshlink.c;h=db0362b1e89680ae62ea54abdd44517fa0544a8c;hb=fb7b6e7a0c966a88a682f656ca1caeb9a0583c5b;hp=f45faa388ae998e6d1e688f46be8e93408628a3b;hpb=1ffa0e102dc0d036241ee1ea2a13df42526c0872;p=meshlink diff --git a/src/libmeshlink.c b/src/libmeshlink.c index f45faa38..db0362b1 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -1,6 +1,6 @@ /* libmeshlink.h -- Tincd Library - Copyright (C) 2014 Guus Sliepen Saverio Proto + Copyright (C) 2014 Guus Sliepen Saverio Proto 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 @@ -18,7 +18,6 @@ */ #include "libmeshlink.h" -#include LZO1X_H #ifdef HAVE_SYS_MMAN_H #include #endif @@ -62,9 +61,6 @@ bool setup_meshlink_network(void) { if(!setup_myself()) return false; - if(!init_control()) - return false; - return true; } @@ -267,63 +263,6 @@ bool ecdsa_keygen(bool ask) { return true; } -/* - Generate a public/private RSA keypair, and ask for a file to store - them in. -*/ -bool rsa_keygen(int bits, bool ask) { - rsa_t *key; - FILE *f; - char *pubname, *privname; - - fprintf(stderr, "Generating %d bits keys:\n", bits); - - if(!(key = rsa_generate(bits, 0x10001))) { - fprintf(stderr, "Error during key generation!\n"); - return false; - } else - fprintf(stderr, "Done.\n"); - - xasprintf(&privname, "%s" SLASH "rsa_key.priv", confbase); - f = ask_and_open(privname, "private RSA key", "a", ask, 0600); - free(privname); - - if(!f) - return false; - - if(!rsa_write_pem_private_key(key, f)) { - fprintf(stderr, "Error writing private key!\n"); - fclose(f); - rsa_free(key); - return false; - } - - fclose(f); - - if(name) - xasprintf(&pubname, "%s" SLASH "hosts" SLASH "%s", confbase, name); - else - xasprintf(&pubname, "%s" SLASH "rsa_key.pub", confbase); - - f = ask_and_open(pubname, "public RSA key", "a", ask, 0666); - free(pubname); - - if(!f) - return false; - - if(!rsa_write_pem_public_key(key, f)) { - fprintf(stderr, "Error writing public key!\n"); - fclose(f); - rsa_free(key); - return false; - } - - fclose(f); - rsa_free(key); - - return true; -} - static bool try_bind(int port) { struct addrinfo *ai = NULL; struct addrinfo hint = { @@ -383,8 +322,7 @@ int check_port(char *name) { } //tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script. bool tinc_setup(const char* confbaseapi, const char* name) { - confbase = confbaseapi; - make_names(); + confbase = xstrdup(confbaseapi); xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase); xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase); if(!access(tinc_conf, F_OK)) { @@ -397,11 +335,6 @@ bool tinc_setup(const char* confbaseapi, const char* name) { return false; } - if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) { - fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno)); - return false; - } - if(mkdir(confbase, 0777) && errno != EEXIST) { fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno)); return false; @@ -421,7 +354,7 @@ bool tinc_setup(const char* confbaseapi, const char* name) { fprintf(f, "Name = %s\n", name); fclose(f); - if(!rsa_keygen(2048, false) || !ecdsa_keygen(false)) + if(!ecdsa_keygen(false)) return false; check_port(name); @@ -440,15 +373,14 @@ return true; } bool tinc_main_thread(void * in) { + static bool status = false; -static bool status = false; + /* If nonzero, write log entries to a separate file. */ + bool use_logfile = false; -/* If nonzero, write log entries to a separate file. */ -bool use_logfile = false; + confbase = (char*) in; -confbase = (char*) in; - - openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR); + openlogger("tinc", LOGMODE_STDERR); init_configuration(&config_tree); @@ -461,13 +393,6 @@ confbase = (char*) in; if(!read_server_config()) return false; -#ifdef HAVE_LZO - if(lzo_init() != LZO_E_OK) { - logger(DEBUG_ALWAYS, LOG_ERR, "Error initializing LZO compressor!"); - return false; - } -#endif - //char *priority = NULL; //shoud be not needed in libmeshlink #ifdef HAVE_MLOCKALL @@ -534,8 +459,6 @@ end: crypto_exit(); exit_configuration(&config_tree); - free(cmdline_conf); - free_names(); return status; @@ -543,56 +466,30 @@ end: bool tinc_stop(); -bool route_meshlink(node_t *source,vpn_packet_t *packet) { - - printf("data %s\n",packet->data); - printf("data 11%s\n",packet->data+11); - printf("data 32%s\n",packet->data+32); - node_t* owner = NULL; - - tincpackethdr* hdr = (tincpackethdr*)packet->data; - owner = lookup_node(hdr->destination); - - if (owner == NULL) { - //Lookup failed - printf("NULL\n"); - return false; - } - printf("lookupnode %s\n",owner->name); - - if(!owner->status.reachable) { - //Do some here - return false; - } - - //TODO: I skipped here a lot of checks ! - - send_packet(owner,packet); - -} // can be called from any thread bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) { vpn_packet_t packet; tincpackethdr* hdr = malloc(sizeof(tincpackethdr)); - - if (sizeof(hdr) + len > MAXSIZE) { + if (sizeof(tincpackethdr) + len > MAXSIZE) { //log something return false; } + memset(hdr->legacymtu,1,sizeof(hdr->legacymtu)); memcpy(hdr->destination,receiver->name,sizeof(hdr->destination)); memcpy(hdr->source,myself->name,sizeof(hdr->source)); packet.priority = 0; + packet.len = sizeof(tincpackethdr) + len; - memcpy(packet.data,hdr,32); - memcpy(packet.data+32,buf,len); + memcpy(packet.data,hdr,sizeof(tincpackethdr)); + memcpy(packet.data+sizeof(tincpackethdr),buf,len); myself->in_packets++; myself->in_bytes += packet.len; - route_meshlink(myself, &packet); + route(myself, &packet); return true; }