Merge branch 'master' of git://tinc-vpn.org/tinc into 1.1

Conflicts:
	NEWS
	configure.in
	doc/tincd.8.in
	lib/pidfile.c
	lib/pidfile.h
	lib/xalloc.h
	lib/xmalloc.c
	src/conf.c
	src/conf.h
	src/connection.c
	src/connection.h
	src/event.c
	src/graph.c
	src/graph.h
	src/net.c
	src/net.h
	src/node.h
	src/openssl/crypto.c
	src/process.c
	src/protocol.c
	src/protocol_key.c
	src/route.c
This commit is contained in:
Guus Sliepen 2011-06-06 20:42:15 +02:00
commit 33f241d978
34 changed files with 90 additions and 63 deletions

View file

@ -22,6 +22,7 @@
#include "system.h"
#include "conf.h"
#include "device.h"
#include "logger.h"
#include "net.h"
#include "route.h"

View file

@ -26,6 +26,7 @@
#include "splay_tree.h"
#include "connection.h"
#include "conf.h"
#include "list.h"
#include "logger.h"
#include "netutl.h" /* for str2address */
#include "protocol.h"

View file

@ -27,8 +27,6 @@
#include "control_common.h"
#include "list.h"
#include "logger.h"
#include "net.h" /* Don't ask. */
#include "netutl.h"
#include "subnet.h"
#include "utils.h"
#include "xalloc.h"

View file

@ -48,7 +48,6 @@ typedef struct connection_status_t {
} connection_status_t;
#include "edge.h"
#include "list.h"
#include "net.h"
#include "node.h"

View file

@ -24,6 +24,7 @@
#include <w32api/winioctl.h>
#include "conf.h"
#include "device.h"
#include "logger.h"
#include "net.h"
#include "route.h"

View file

@ -19,6 +19,7 @@
#include "system.h"
#include "device.h"
#include "logger.h"
#include "net.h"

View file

@ -49,6 +49,7 @@
#include "connection.h"
#include "device.h"
#include "edge.h"
#include "graph.h"
#include "logger.h"
#include "netutl.h"
#include "node.h"
@ -183,9 +184,6 @@ static void sssp_dijkstra(void) {
n->address is set to the e->address of the edge left of n to n.
We are currently examining the edge e right of n from n:
- If e->reverse->address != n->address, then e->to is probably
not reachable for the nodes left of n. We do as if the indirectdata
flag is set on edge e.
- If edge e provides for better reachability of e->to, update e->to.
*/
@ -203,27 +201,8 @@ static void sssp_dijkstra(void) {
e->to->via = indirect ? n->via : e->to;
e->to->options = e->options;
if(sockaddrcmp(&e->to->address, &e->address)) {
node = splay_unlink(node_udp_tree, e->to);
sockaddrfree(&e->to->address);
sockaddrcpy(&e->to->address, &e->address);
if(e->to->hostname)
free(e->to->hostname);
e->to->hostname = sockaddr2hostname(&e->to->address);
if(node)
splay_insert_node(node_udp_tree, node);
if(e->to->options & OPTION_PMTU_DISCOVERY) {
e->to->mtuprobes = 0;
e->to->minmtu = 0;
e->to->maxmtu = MTU;
if(e->to->status.validkey)
send_mtu_probe(e->to);
}
}
if(e->to->address.sa.sa_family == AF_UNSPEC && e->address.sa.sa_family != AF_UNKNOWN)
update_node_udp(e->to, &e->address);
ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Updating edge %s - %s weight %d distance %d", e->from->name,
e->to->name, e->weight, e->to->distance);

View file

@ -22,7 +22,6 @@
#define __TINC_GRAPH_H__
extern void graph(void);
extern void mst_kruskal(void);
extern void sssp_bfs(void);
extern void dump_graph(void);
#endif /* __TINC_GRAPH_H__ */

View file

@ -24,6 +24,7 @@
#define DEFAULT_DEVICE "/dev/net/tun"
#include "conf.h"
#include "device.h"
#include "logger.h"
#include "net.h"
#include "route.h"

View file

@ -44,14 +44,18 @@ void openlogger(const char *ident, logmode_t mode) {
case LOGMODE_FILE:
logpid = getpid();
logfile = fopen(logfilename, "a");
if(!logfile)
if(!logfile) {
fprintf(stderr, "Could not open log file %s: %s\n", logfilename, strerror(errno));
logmode = LOGMODE_NULL;
}
break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
loghandle = RegisterEventSource(NULL, logident);
if(!loghandle)
if(!loghandle) {
fprintf(stderr, "Could not open log handle!");
logmode = LOGMODE_NULL;
}
break;
#else
#ifdef HAVE_SYSLOG_H
@ -64,8 +68,24 @@ void openlogger(const char *ident, logmode_t mode) {
}
}
void reopenlogger() {
if(logmode != LOGMODE_FILE)
return;
fflush(logfile);
FILE *newfile = fopen(logfilename, "a");
if(!newfile) {
logger(LOG_ERR, "Unable to reopen log file %s: %s\n", logfilename, strerror(errno));
return;
}
fclose(logfile);
logfile = newfile;
}
void logger(int priority, const char *format, ...) {
va_list ap;
char timestr[32] = "";
time_t now;
va_start(ap, format);
@ -76,7 +96,9 @@ void logger(int priority, const char *format, ...) {
fflush(stderr);
break;
case LOGMODE_FILE:
fprintf(logfile, "%ld %s[%ld]: ", time(NULL), logident, (long)logpid);
now = time(NULL);
strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now));
fprintf(logfile, "%s %s[%ld]: ", timestr, logident, (long)logpid);
vfprintf(logfile, format, ap);
fprintf(logfile, "\n");
fflush(logfile);

View file

@ -47,6 +47,7 @@ enum {
extern debug_t debug_level;
extern void openlogger(const char *, logmode_t);
extern void reopenlogger(void);
extern void logger(int, const char *, ...) __attribute__ ((__format__(printf, 2, 3)));
extern void closelogger(void);

View file

@ -24,6 +24,7 @@
#include <winioctl.h>
#include "conf.h"
#include "device.h"
#include "logger.h"
#include "net.h"
#include "route.h"

View file

@ -3,6 +3,7 @@
Copyright (C) 1998-2005 Ivo Timmermans,
2000-2011 Guus Sliepen <guus@tinc-vpn.org>
2006 Scott Lamb <slamb@slamb.org>
2011 Loïc Grenié <loic.grenie@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
@ -166,14 +167,14 @@ static void timeout_handler(int fd, short events, void *event) {
next = node->next;
c = node->data;
if(c->last_ping_time + pingtimeout < now) {
if(c->last_ping_time + pingtimeout <= now) {
if(c->status.active) {
if(c->status.pinged) {
ifdebug(CONNECTIONS) logger(LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds",
c->name, c->hostname, now - c->last_ping_time);
terminate_connection(c, true);
continue;
} else if(c->last_ping_time + pinginterval < now) {
} else if(c->last_ping_time + pinginterval <= now) {
send_ping(c);
}
} else {

View file

@ -132,7 +132,7 @@ extern void handle_new_meta_connection(int, short, void *);
extern int setup_listen_socket(const sockaddr_t *);
extern int setup_vpn_in_socket(const sockaddr_t *);
extern void send_packet(struct node_t *, vpn_packet_t *);
extern void receive_tcppacket(struct connection_t *, char *, int);
extern void receive_tcppacket(struct connection_t *, const char *, int);
extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
extern bool setup_network(void);
extern void setup_outgoing_connection(struct outgoing_t *);
@ -145,11 +145,11 @@ extern bool read_rsa_public_key(struct connection_t *);
extern void send_mtu_probe(struct node_t *);
extern void handle_device_data(int, short, void *);
extern void handle_meta_connection_data(int, short, void *);
extern void regenerate_key();
extern void regenerate_key(void);
extern void purge(void);
extern void retry(void);
extern int reload_configuration(void);
extern void load_all_subnets();
extern void load_all_subnets(void);
#ifndef HAVE_MINGW
#define closesocket(s) close(s)

View file

@ -45,7 +45,6 @@
#include "device.h"
#include "ethernet.h"
#include "graph.h"
#include "list.h"
#include "logger.h"
#include "net.h"
#include "netutl.h"
@ -357,7 +356,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
receive_packet(n, inpkt);
}
void receive_tcppacket(connection_t *c, char *buffer, int len) {
void receive_tcppacket(connection_t *c, const char *buffer, int len) {
vpn_packet_t outpkt;
outpkt.len = len;
@ -398,7 +397,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
"No valid key known yet for %s (%s), forwarding via TCP",
n->name, n->hostname);
if(n->last_req_key + 10 < now) {
if(n->last_req_key + 10 <= now) {
send_req_key(n);
n->last_req_key = now;
}

View file

@ -25,7 +25,6 @@
#include "cipher.h"
#include "connection.h"
#include "digest.h"
#include "list.h"
#include "subnet.h"
typedef struct node_status_t {

View file

@ -26,6 +26,7 @@
#include "device.h"
#include "edge.h"
#include "logger.h"
#include "net.h"
#include "node.h"
#include "process.h"
#include "subnet.h"

View file

@ -205,7 +205,7 @@ static void age_past_requests(int fd, short events, void *data) {
next = node->next;
p = node->data;
if(p->firstseen + pinginterval < now)
if(p->firstseen + pinginterval <= now)
splay_delete_node(past_request_tree, node), deleted++;
else
left++;

View file

@ -96,10 +96,10 @@ extern bool send_add_subnet(struct connection_t *, const struct subnet_t *);
extern bool send_del_subnet(struct connection_t *, const struct subnet_t *);
extern bool send_add_edge(struct connection_t *, const struct edge_t *);
extern bool send_del_edge(struct connection_t *, const struct edge_t *);
extern void send_key_changed();
extern void send_key_changed(void);
extern bool send_req_key(struct node_t *);
extern bool send_ans_key(struct node_t *);
extern bool send_tcppacket(struct connection_t *, struct vpn_packet_t *);
extern bool send_tcppacket(struct connection_t *, const struct vpn_packet_t *);
/* Request handlers */

View file

@ -115,7 +115,7 @@ bool pong_h(connection_t *c, char *request) {
/* Sending and receiving packets via TCP */
bool send_tcppacket(connection_t *c, vpn_packet_t *packet) {
bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) {
/* If there already is a lot of data in the outbuf buffer, discard this packet.
We use a very simple Random Early Drop algorithm. */

View file

@ -23,6 +23,7 @@
#include <netpacket/packet.h>
#include "conf.h"
#include "device.h"
#include "net.h"
#include "logger.h"
#include "utils.h"

View file

@ -26,6 +26,7 @@
#include <net/if_tun.h>
#include "conf.h"
#include "device.h"
#include "logger.h"
#include "net.h"
#include "utils.h"

View file

@ -339,7 +339,7 @@ static bool drop_privs(void) {
}
#ifdef HAVE_MINGW
# define setpriority(level) SetPriorityClass(GetCurrentProcess(), (level))
# define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level))
#else
# define NORMAL_PRIORITY_CLASS 0
# define BELOW_NORMAL_PRIORITY_CLASS 10

View file

@ -23,6 +23,7 @@
#include <sys/un.h>
#include "conf.h"
#include "device.h"
#include "net.h"
#include "logger.h"
#include "utils.h"

View file

@ -67,7 +67,7 @@ const char *winerror(int err) {
}
#endif
unsigned int bitfield_to_int(void *bitfield, size_t size) {
unsigned int bitfield_to_int(const void *bitfield, size_t size) {
unsigned int value = 0;
if(size > sizeof value)
size = sizeof value;

View file

@ -42,6 +42,6 @@ extern const char *winerror(int);
#define sockinuse(x) ((x) == EADDRINUSE)
#endif
extern unsigned int bitfield_to_int(void *bitfield, size_t size);
extern unsigned int bitfield_to_int(const void *bitfield, size_t size);
#endif /* __TINC_UTILS_H__ */

View file

@ -22,6 +22,7 @@
#include <libvdeplug_dyn.h>
#include "conf.h"
#include "device.h"
#include "net.h"
#include "logger.h"
#include "utils.h"