if(!setup_myself())
return false;
- if(!init_control())
- return false;
-
return true;
}
}
//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)) {
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;
}
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);
exit_configuration(&config_tree);
free(cmdline_conf);
- free_names();
return status;
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;
}