|
|
@ -476,13 +476,13 @@ static void help() { |
|
|
|
"-c <community> " |
|
|
|
"[-k <encrypt key> | -K <key file>] " |
|
|
|
"[-s <netmask>] " |
|
|
|
#if defined(N2N_HAVE_SETUID) |
|
|
|
#ifndef WIN32 |
|
|
|
"[-u <uid> -g <gid>]" |
|
|
|
#endif /* #ifndef N2N_HAVE_SETUID */ |
|
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
|
|
|
|
#if defined(N2N_HAVE_DAEMON) |
|
|
|
#ifndef WIN32 |
|
|
|
"[-f]" |
|
|
|
#endif /* #if defined(N2N_HAVE_DAEMON) */ |
|
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
"[-m <MAC address>]" |
|
|
|
"\n" |
|
|
|
"-l <supernode host:port> " |
|
|
@ -506,9 +506,9 @@ static void help() { |
|
|
|
printf("-u <UID> | User ID (numeric) to use when privileges are dropped.\n"); |
|
|
|
printf("-g <GID> | Group ID (numeric) to use when privileges are dropped.\n"); |
|
|
|
#endif /* ifndef WIN32 */ |
|
|
|
#ifdef N2N_HAVE_DAEMON |
|
|
|
#ifndef WIN32 |
|
|
|
printf("-f | Do not fork and run as a daemon; rather run in foreground.\n"); |
|
|
|
#endif /* #ifdef N2N_HAVE_DAEMON */ |
|
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
printf("-m <MAC address> | Fix MAC address for the TAP interface (otherwise it may be random)\n" |
|
|
|
" : eg. -m 01:02:03:04:05:06\n"); |
|
|
|
printf("-M <mtu> | Specify n2n MTU of edge interface (default %d).\n", DEFAULT_MTU); |
|
|
@ -1383,7 +1383,7 @@ static int handle_PACKET( n2n_edge_t * eee, |
|
|
|
{ |
|
|
|
uint8_t decodebuf[N2N_PKT_BUF_SIZE]; |
|
|
|
size_t eth_size; |
|
|
|
size_t rx_transop_idx=0; |
|
|
|
int rx_transop_idx; |
|
|
|
|
|
|
|
rx_transop_idx = transop_enum_to_index(pkt->transform); |
|
|
|
|
|
|
@ -1925,6 +1925,55 @@ static int run_loop(n2n_edge_t * eee ); |
|
|
|
#define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/ |
|
|
|
#define N2N_IF_MODE_SIZE 16 /* static | dhcp */ |
|
|
|
|
|
|
|
/* *************************************************** */ |
|
|
|
|
|
|
|
void daemonize() { |
|
|
|
#ifndef WIN32 |
|
|
|
int childpid; |
|
|
|
|
|
|
|
traceEvent(TRACE_NORMAL, "Parent process is exiting (this is normal)"); |
|
|
|
|
|
|
|
signal(SIGPIPE, SIG_IGN); |
|
|
|
signal(SIGHUP, SIG_IGN); |
|
|
|
signal(SIGCHLD, SIG_IGN); |
|
|
|
signal(SIGQUIT, SIG_IGN); |
|
|
|
|
|
|
|
if((childpid = fork()) < 0) |
|
|
|
traceEvent(TRACE_ERROR, "Occurred while daemonizing (errno=%d)", |
|
|
|
errno); |
|
|
|
else { |
|
|
|
if(!childpid) { /* child */ |
|
|
|
int rc; |
|
|
|
|
|
|
|
//traceEvent(TRACE_NORMAL, "Bye bye: I'm becoming a daemon...");
|
|
|
|
rc = chdir("/"); |
|
|
|
if(rc != 0) |
|
|
|
traceEvent(TRACE_ERROR, "Error while moving to / directory"); |
|
|
|
|
|
|
|
setsid(); /* detach from the terminal */ |
|
|
|
|
|
|
|
fclose(stdin); |
|
|
|
fclose(stdout); |
|
|
|
/* fclose(stderr); */ |
|
|
|
|
|
|
|
/*
|
|
|
|
* clear any inherited file mode creation mask |
|
|
|
*/ |
|
|
|
//umask(0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use line buffered stdout |
|
|
|
*/ |
|
|
|
/* setlinebuf (stdout); */ |
|
|
|
setvbuf(stdout, (char *)NULL, _IOLBF, 0); |
|
|
|
} else /* father */ |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
/* *************************************************** */ |
|
|
|
|
|
|
|
/** Entry point to program from kernel. */ |
|
|
|
int main(int argc, char* argv[]) |
|
|
|
{ |
|
|
@ -2017,8 +2066,7 @@ int main(int argc, char* argv[]) |
|
|
|
optarg = NULL; |
|
|
|
while((opt = getopt_long(effectiveargc, |
|
|
|
effectiveargv, |
|
|
|
"K:k:a:bc:Eu:g:m:M:s:d:l:p:fvhrt:", long_options, NULL)) != EOF) |
|
|
|
{ |
|
|
|
"K:k:a:bc:Eu:g:m:M:s:d:l:p:fvhrt:", long_options, NULL)) != EOF) { |
|
|
|
switch (opt) |
|
|
|
{ |
|
|
|
case'K': |
|
|
@ -2069,13 +2117,13 @@ int main(int argc, char* argv[]) |
|
|
|
break; |
|
|
|
} |
|
|
|
#endif |
|
|
|
#ifdef N2N_HAVE_DAEMON |
|
|
|
#ifndef WIN32 |
|
|
|
case 'f' : /* do not fork as daemon */ |
|
|
|
{ |
|
|
|
eee.daemon=0; |
|
|
|
break; |
|
|
|
} |
|
|
|
#endif /* #ifdef N2N_HAVE_DAEMON */ |
|
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
|
|
|
|
case 'm' : /* TUNTAP MAC address */ |
|
|
|
{ |
|
|
@ -2176,17 +2224,13 @@ int main(int argc, char* argv[]) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#ifdef N2N_HAVE_DAEMON |
|
|
|
#ifndef WIN32 |
|
|
|
if(eee.daemon) |
|
|
|
{ |
|
|
|
useSyslog = 1; /* traceEvent output now goes to syslog. */ |
|
|
|
if ( -1 == daemon( 0, 0 ) ) |
|
|
|
{ |
|
|
|
traceEvent( TRACE_ERROR, "Failed to become daemon." ); |
|
|
|
exit(-5); |
|
|
|
} |
|
|
|
daemonize(); |
|
|
|
} |
|
|
|
#endif /* #ifdef N2N_HAVE_DAEMON */ |
|
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
|
|
|
|
|
|
|
|
traceEvent(TRACE_NORMAL, "Starting n2n edge %s %s", n2n_sw_version, n2n_sw_buildDate); |
|
|
|