Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof

This commit is contained in:
thorkill 2015-05-26 12:57:15 +02:00
commit 9bf36c8666
10 changed files with 83 additions and 14 deletions

View file

@ -15,7 +15,7 @@
This is the info manual for @value{PACKAGE} version @value{VERSION}, a Virtual Private Network daemon. This is the info manual for @value{PACKAGE} version @value{VERSION}, a Virtual Private Network daemon.
Copyright @copyright{} 1998-2014 Ivo Timmermans, Copyright @copyright{} 1998-2015 Ivo Timmermans,
Guus Sliepen <guus@@tinc-vpn.org> and Guus Sliepen <guus@@tinc-vpn.org> and
Wessel Dankers <wsl@@tinc-vpn.org>. Wessel Dankers <wsl@@tinc-vpn.org>.
@ -43,7 +43,7 @@ permission notice identical to this one.
@vskip 0pt plus 1filll @vskip 0pt plus 1filll
This is the info manual for @value{PACKAGE} version @value{VERSION}, a Virtual Private Network daemon. This is the info manual for @value{PACKAGE} version @value{VERSION}, a Virtual Private Network daemon.
Copyright @copyright{} 1998-2014 Ivo Timmermans, Copyright @copyright{} 1998-2015 Ivo Timmermans,
Guus Sliepen <guus@@tinc-vpn.org> and Guus Sliepen <guus@@tinc-vpn.org> and
Wessel Dankers <wsl@@tinc-vpn.org>. Wessel Dankers <wsl@@tinc-vpn.org>.

View file

@ -84,7 +84,7 @@ char *get_my_hostname() {
char *port = NULL; char *port = NULL;
char *hostport = NULL; char *hostport = NULL;
char *name = get_my_name(false); char *name = get_my_name(false);
char filename[PATH_MAX]; char filename[PATH_MAX] = {0};
// Use first Address statement in own host config file // Use first Address statement in own host config file
if(check_id(name)) { if(check_id(name)) {
@ -182,7 +182,7 @@ again:
hostname = xstrdup(line); hostname = xstrdup(line);
save: save:
if(filename) { if(*filename) {
FILE *f = fopen(filename, "a"); FILE *f = fopen(filename, "a");
if(f) { if(f) {
fprintf(f, "\nAddress = %s\n", hostname); fprintf(f, "\nAddress = %s\n", hostname);

View file

@ -26,6 +26,7 @@
#include "logger.h" #include "logger.h"
#include "connection.h" #include "connection.h"
#include "control_common.h" #include "control_common.h"
#include "process.h"
#include "sptps.h" #include "sptps.h"
debug_t debug_level = DEBUG_NOTHING; debug_t debug_level = DEBUG_NOTHING;
@ -37,7 +38,7 @@ static HANDLE loghandle = NULL;
#endif #endif
static const char *logident = NULL; static const char *logident = NULL;
bool logcontrol = false; bool logcontrol = false;
int umbilical = 0;
static void real_logger(int level, int priority, const char *message) { static void real_logger(int level, int priority, const char *message) {
char timestr[32] = ""; char timestr[32] = "";
@ -79,6 +80,11 @@ static void real_logger(int level, int priority, const char *message) {
case LOGMODE_NULL: case LOGMODE_NULL:
break; break;
} }
if(umbilical && do_detach) {
write(umbilical, message, strlen(message));
write(umbilical, "\n", 1);
}
} }
if(logcontrol) { if(logcontrol) {

View file

@ -69,6 +69,7 @@ enum {
extern debug_t debug_level; extern debug_t debug_level;
extern bool logcontrol; extern bool logcontrol;
extern int umbilical;
extern void openlogger(const char *, logmode_t); extern void openlogger(const char *, logmode_t);
extern void reopenlogger(void); extern void reopenlogger(void);
extern void logger(int, int, const char *, ...) __attribute__ ((__format__(printf, 3, 4))); extern void logger(int, int, const char *, ...) __attribute__ ((__format__(printf, 3, 4)));

View file

@ -1196,7 +1196,7 @@ static void try_tx_sptps(node_t *n, bool mtu) {
if(via != n) { if(via != n) {
if((via->options >> 24) < 4) if((via->options >> 24) < 4)
return; return;
return try_tx_sptps(via, mtu); return try_tx(via, mtu);
} }
/* Otherwise, try to establish UDP connectivity. */ /* Otherwise, try to establish UDP connectivity. */
@ -1209,7 +1209,7 @@ static void try_tx_sptps(node_t *n, bool mtu) {
while we try to establish direct connectivity. */ while we try to establish direct connectivity. */
if(!n->status.udp_confirmed && n != n->nexthop && (n->nexthop->options >> 24) >= 4) if(!n->status.udp_confirmed && n != n->nexthop && (n->nexthop->options >> 24) >= 4)
try_tx_sptps(n->nexthop, mtu); try_tx(n->nexthop, mtu);
} }
static void try_tx_legacy(node_t *n, bool mtu) { static void try_tx_legacy(node_t *n, bool mtu) {
@ -1234,6 +1234,8 @@ static void try_tx_legacy(node_t *n, bool mtu) {
} }
void try_tx(node_t *n, bool mtu) { void try_tx(node_t *n, bool mtu) {
if(!n->status.reachable)
return;
if(n->status.sptps) if(n->status.sptps)
try_tx_sptps(n, mtu); try_tx_sptps(n, mtu);
else else
@ -1270,7 +1272,7 @@ void send_packet(node_t *n, vpn_packet_t *packet) {
if(n->status.sptps) { if(n->status.sptps) {
send_sptps_packet(n, packet); send_sptps_packet(n, packet);
try_tx_sptps(n, true); try_tx(n, true);
return; return;
} }
@ -1290,7 +1292,7 @@ void send_packet(node_t *n, vpn_packet_t *packet) {
} }
send_udppacket(via, packet); send_udppacket(via, packet);
try_tx_legacy(via, true); try_tx(via, true);
} }
void broadcast_packet(const node_t *from, vpn_packet_t *packet) { void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
@ -1473,7 +1475,7 @@ skip_harder:
if(to != myself) { if(to != myself) {
send_sptps_data(to, from, 0, DATA(&pkt), pkt.len); send_sptps_data(to, from, 0, DATA(&pkt), pkt.len);
try_tx_sptps(to, true); try_tx(to, true);
return; return;
} }
} else { } else {

View file

@ -800,6 +800,11 @@ void try_outgoing_connections(void) {
continue; continue;
} }
if(!strcmp(name, myself->name)) {
free(name);
continue;
}
bool found = false; bool found = false;
for list_each(outgoing_t, outgoing, outgoing_list) { for list_each(outgoing_t, outgoing, outgoing_list) {

View file

@ -33,6 +33,7 @@ bool send_request(void *c, const char *msg, ...) { return false; }
struct list_t *connection_list = NULL; struct list_t *connection_list = NULL;
bool send_meta(void *c, const char *msg , int len) { return false; } bool send_meta(void *c, const char *msg , int len) { return false; }
char *logfilename = NULL; char *logfilename = NULL;
bool do_detach = false;
struct timeval now; struct timeval now;
static bool send_data(void *handle, uint8_t type, const void *data, size_t len) { static bool send_data(void *handle, uint8_t type, const void *data, size_t len) {

View file

@ -35,6 +35,7 @@ bool send_request(void *c, const char *msg, ...) { return false; }
struct list_t *connection_list = NULL; struct list_t *connection_list = NULL;
bool send_meta(void *c, const char *msg , int len) { return false; } bool send_meta(void *c, const char *msg , int len) { return false; }
char *logfilename = NULL; char *logfilename = NULL;
bool do_detach = false;
struct timeval now; struct timeval now;
static bool verbose; static bool verbose;

View file

@ -89,7 +89,7 @@ static struct option const long_options[] = {
static void version(void) { static void version(void) {
printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE, printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR); BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
printf("Copyright (C) 1998-2014 Ivo Timmermans, Guus Sliepen and others.\n" printf("Copyright (C) 1998-2015 Ivo Timmermans, Guus Sliepen and others.\n"
"See the AUTHORS file for a complete list.\n\n" "See the AUTHORS file for a complete list.\n\n"
"tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
"and you are welcome to redistribute it under certain conditions;\n" "and you are welcome to redistribute it under certain conditions;\n"
@ -853,6 +853,13 @@ static int cmd_start(int argc, char *argv[]) {
} }
return status; return status;
#else #else
int pfd[2] = {-1, -1};
if(socketpair(AF_UNIX, SOCK_STREAM, 0, pfd)) {
fprintf(stderr, "Could not create umbilical socket: %s\n", strerror(errno));
free(nargv);
return 1;
}
pid_t pid = fork(); pid_t pid = fork();
if(pid == -1) { if(pid == -1) {
fprintf(stderr, "Could not fork: %s\n", strerror(errno)); fprintf(stderr, "Could not fork: %s\n", strerror(errno));
@ -860,8 +867,15 @@ static int cmd_start(int argc, char *argv[]) {
return 1; return 1;
} }
if(!pid) if(!pid) {
close(pfd[0]);
char buf[100] = "";
snprintf(buf, sizeof buf, "%d", pfd[1]);
setenv("TINC_UMBILICAL", buf, true);
exit(execvp(c, nargv)); exit(execvp(c, nargv));
} else {
close(pfd[1]);
}
free(nargv); free(nargv);
@ -869,12 +883,33 @@ static int cmd_start(int argc, char *argv[]) {
#ifdef SIGINT #ifdef SIGINT
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
#endif #endif
// Pass all log messages from the umbilical to stderr.
// A nul-byte right before closure means tincd started succesfully.
bool failure = true;
char buf[1024];
ssize_t len;
while((len = read(pfd[0], buf, sizeof buf)) > 0) {
failure = buf[len - 1];
if(!failure)
len--;
write(2, buf, len);
}
if(len)
failure = true;
close(pfd[0]);
// Make sure the child process is really gone.
result = waitpid(pid, &status, 0); result = waitpid(pid, &status, 0);
#ifdef SIGINT #ifdef SIGINT
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
#endif #endif
if(result != pid || !WIFEXITED(status) || WEXITSTATUS(status)) { if(failure || result != pid || !WIFEXITED(status) || WEXITSTATUS(status)) {
fprintf(stderr, "Error starting %s\n", c); fprintf(stderr, "Error starting %s\n", c);
return 1; return 1;
} }

View file

@ -344,7 +344,7 @@ int main(int argc, char **argv) {
if(show_version) { if(show_version) {
printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE, printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR); BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
printf("Copyright (C) 1998-2014 Ivo Timmermans, Guus Sliepen and others.\n" printf("Copyright (C) 1998-2015 Ivo Timmermans, Guus Sliepen and others.\n"
"See the AUTHORS file for a complete list.\n\n" "See the AUTHORS file for a complete list.\n\n"
"tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "tinc comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
"and you are welcome to redistribute it under certain conditions;\n" "and you are welcome to redistribute it under certain conditions;\n"
@ -363,6 +363,18 @@ int main(int argc, char **argv) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError())); logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
return 1; return 1;
} }
#else
// Check if we got an umbilical fd from the process that started us
char *umbstr = getenv("TINC_UMBILICAL");
if(umbstr) {
umbilical = atoi(umbstr);
if(fcntl(umbilical, F_GETFL) < 0)
umbilical = 0;
#ifdef FD_CLOEXEC
if(umbilical)
fcntl(umbilical, F_SETFD, FD_CLOEXEC);
#endif
}
#endif #endif
openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR); openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
@ -466,6 +478,12 @@ int main2(int argc, char **argv) {
logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready"); logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
if(umbilical) { // snip!
write(umbilical, "", 1);
close(umbilical);
umbilical = 0;
}
try_outgoing_connections(); try_outgoing_connections();
status = main_loop(); status = main_loop();