/*
libmeshlink.h -- Tincd Library
- Copyright (C) 2014 Guus Sliepen <guus@tinc-vpn.org> Saverio Proto <zioproto@gmail.com>
+ Copyright (C) 2014 Guus Sliepen <guus@meshlink.io> Saverio Proto <zioproto@gmail.com>
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
*/
#include "libmeshlink.h"
- #include LZO1X_H
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
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 = {
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);
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
crypto_exit();
exit_configuration(&config_tree);
- free(cmdline_conf);
return status;
bool tinc_stop();
-bool route_meshlink(node_t *source,vpn_packet_t *packet) {
-
- printf("data %s\n",packet->data);
- printf("data 16%s\n",packet->data+16);
- 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 = len + 32;
+ 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;
}
/*
route.c -- routing
- Copyright (C) 2000-2005 Ivo Timmermans,
- 2000-2013 Guus Sliepen <guus@tinc-vpn.org>
+ Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
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
#include "net.h"
#include "route.h"
#include "utils.h"
+#include "libmeshlink.h"
rmode_t routing_mode = RMODE_ROUTER;
fmode_t forwarding_mode = FMODE_INTERNAL;
bool directonly = false;
bool priorityinheritance = false;
int macexpire = 600;
- bool overwrite_mac = false;
mac_t mymac = {{0xFE, 0xFD, 0, 0, 0, 0}};
bool pcap = false;
return true;
}
-void route(node_t *source, vpn_packet_t *packet) {
- // TODO: route on name or key
+void route(node_t *source,vpn_packet_t *packet) {
+ // TODO: route on name or key
+
+ node_t* owner = NULL;
+ tincpackethdr* hdr = (tincpackethdr*)packet->data;
+ owner = lookup_node(hdr->destination);
+ if (owner == NULL) {
+ //Lookup failed
+ logger(DEBUG_TRAFFIC, LOG_WARNING, "Cant lookup the owner of a packet in the route() function. This should never happen \n");
+ return;
+ }
+
+ if (owner == myself ) {
+ //TODO: implement sending received data from meshlink library to the application
+ logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + 46);
+ return;
+ }
+
+ if(!owner->status.reachable) {
+ //TODO: check what to do here, not just print a warning
+ logger(DEBUG_TRAFFIC, LOG_WARNING, "The owner of a packet in the route() function is unreachable. Dropping packet. \n");
+ return;
+ }
+
+ //TODO: I skipped here a lot of checks !
+
+ send_packet(owner,packet);
+ return;
}