Make svr a global in order to be able to check if the process is a server

Mask or set the high bit of the nonce according to this value.
Properly initialize the nonce in little-endian mode
This commit is contained in:
Frank Denis 2015-11-15 17:45:12 +01:00
parent d3b16d7829
commit bb747e6e36
3 changed files with 19 additions and 10 deletions

View File

@ -48,10 +48,17 @@ init_nonce(unsigned char *nonce, size_t nonce_size)
sleep(SLEEP_WHEN_CLOCK_IS_OFF); sleep(SLEEP_WHEN_CLOCK_IS_OFF);
randombytes_buf(nonce, nonce_size); randombytes_buf(nonce, nonce_size);
} else { } else {
randombytes_buf(nonce + 4, nonce_size - 4); randombytes_buf(nonce, nonce_size - 3);
now <<= 2; nonce[nonce_size - 1] = (unsigned char) (now >> 22);
memcpy(nonce, &now, 3); nonce[nonce_size - 2] = (unsigned char) (now >> 14);
nonce[3] = (nonce[3] & 0x3) ^ *(((unsigned char *) &now) + 3); nonce[nonce_size - 3] = (unsigned char) (now >> 6);
nonce[nonce_size - 4] =
(unsigned char) (now << 2) ^ (nonce[nonce_size - 4] & 0x3);
}
if (vtun.svr != 0) {
nonce[nonce_size - 1] |= 0x80;
} else {
nonce[nonce_size - 1] &= ~0x80;
} }
return 0; return 0;
} }

13
main.c
View File

@ -66,7 +66,7 @@ int is_rmt_fd_connected=1;
int main(int argc, char *argv[], char *env[]) int main(int argc, char *argv[], char *env[])
{ {
int svr, daemon, sock, fd, opt; int daemon, sock, fd, opt;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
int dofork; int dofork;
#endif #endif
@ -75,7 +75,7 @@ int main(int argc, char *argv[], char *env[])
char *hst; char *hst;
/* Configure default settings */ /* Configure default settings */
svr = 0; daemon = 1; sock = 0; daemon = 1; sock = 0;
#if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
dofork = 1; dofork = 1;
#endif #endif
@ -94,6 +94,7 @@ int main(int argc, char *argv[], char *env[])
vtun.svr_name = NULL; vtun.svr_name = NULL;
vtun.svr_addr = NULL; vtun.svr_addr = NULL;
vtun.bind_addr.port = -1; vtun.bind_addr.port = -1;
vtun.svr = 0;
vtun.svr_type = -1; vtun.svr_type = -1;
vtun.syslog = LOG_DAEMON; vtun.syslog = LOG_DAEMON;
@ -122,7 +123,7 @@ int main(int argc, char *argv[], char *env[])
#ifdef HAVE_WORKING_FORK #ifdef HAVE_WORKING_FORK
case 's': case 's':
#endif #endif
svr = 1; vtun.svr = 1;
break; break;
case 'L': case 'L':
vtun.svr_addr = strdup(optarg); vtun.svr_addr = strdup(optarg);
@ -158,9 +159,9 @@ int main(int argc, char *argv[], char *env[])
openlog("vtund", LOG_PID|LOG_NDELAY|LOG_PERROR, vtun.syslog); openlog("vtund", LOG_PID|LOG_NDELAY|LOG_PERROR, vtun.syslog);
} }
clear_nat_hack_flags(svr); clear_nat_hack_flags(vtun.svr);
if(!svr){ if(!vtun.svr){
if( argc - optind < 2 ){ if( argc - optind < 2 ){
usage(); usage();
exit(1); exit(1);
@ -225,7 +226,7 @@ int main(int argc, char *argv[], char *env[])
chdir("/"); chdir("/");
} }
if(svr){ if(vtun.svr){
memset(&sa,0,sizeof(sa)); memset(&sa,0,sizeof(sa));
sa.sa_handler=reread_config; sa.sa_handler=reread_config;
sigaction(SIGHUP,&sa,NULL); sigaction(SIGHUP,&sa,NULL);

1
vtun.h
View File

@ -204,6 +204,7 @@ struct vtun_opts {
char *svr_name; /* Server's host name */ char *svr_name; /* Server's host name */
char *svr_addr; /* Server's address (string) */ char *svr_addr; /* Server's address (string) */
struct vtun_addr bind_addr; /* Server should listen on this address */ struct vtun_addr bind_addr; /* Server should listen on this address */
int svr; /* 0=process is a client 1=process is a server */
int svr_type; /* Server mode */ int svr_type; /* Server mode */
int syslog; /* Facility to log messages to syslog under */ int syslog; /* Facility to log messages to syslog under */
int quiet; /* Be quiet about common errors */ int quiet; /* Be quiet about common errors */