Revision: 408
http://vde.svn.sourceforge.net/vde/?rev=408&view=rev
Author: danielel
Date: 2010-04-29 22:23:15 +0000 (Thu, 29 Apr 2010)
Log Message:
-----------
SIGALRM-based timers removed.
This may solve sourceforge #2866481
Modified Paths:
--------------
trunk/vde-2/src/vde_cryptcab/vde_cryptcab_client.c
trunk/vde-2/src/vde_cryptcab/vde_cryptcab_server.c
Modified: trunk/vde-2/src/vde_cryptcab/vde_cryptcab_client.c
===================================================================
--- trunk/vde-2/src/vde_cryptcab/vde_cryptcab_client.c 2010-04-26 17:00:47 UTC
(rev 407)
+++ trunk/vde-2/src/vde_cryptcab/vde_cryptcab_client.c 2010-04-29 22:23:15 UTC
(rev 408)
@@ -13,7 +13,7 @@
#include "cryptcab.h"
#define KEEPALIVE_INTERVAL 30
-static unsigned char may_login = 1, keepalives = 0;
+static unsigned char keepalives = 0;
static char *remoteusr, *remotehost;
static unsigned short remoteport;
static char *plugname, *pre_shared;
@@ -29,12 +29,7 @@
gettimeofday(&last_out_time, NULL);
}
-static void client_maylogin(int signo)
-{
- may_login=1;
-}
-
/*
* Send a login packet. This is the first phase of 4WHS
*/
@@ -46,18 +41,17 @@
static void try_to_login(struct peer *p)
{
-
- struct itimerval *old=NULL;
- struct itimerval nxt={
- .it_interval={.tv_sec=0, .tv_usec=0},
- .it_value={.tv_sec=5, .tv_usec=0}
- };
- if(!may_login)
+ static struct timeval last_login_time;
+ struct timeval now;
+ gettimeofday(&now, 0);
+ if (now.tv_sec < last_login_time.tv_sec || now.tv_sec -
last_login_time.tv_sec < 5) {
+ vc_printlog(4,"Attempt to login to %s (udp port %hu): please
wait, login in progress...",remotehost,remoteport);
return;
+ }
+
vc_printlog(2,"Logging in to %s (udp port %hu)",remotehost,remoteport);
blowfish_login(p);
- may_login=0;
- setitimer(ITIMER_REAL, &nxt, old);
+ gettimeofday(&last_login_time, 0);
}
@@ -105,7 +99,10 @@
memset(ret,0, sizeof(struct peer));
for(i=0; i<FILENAMESIZE-1;i++){
- read(fd,&c,1);
+ if (read(fd,&c,1) < 0) {
+ perror("could not read filename ");
+ goto failure;
+ }
c=(c%25);
//fprintf(stderr,"c=%u\n",c);
ret->id[i]=(char)('a' + c);
@@ -120,8 +117,10 @@
}
memcpy(ret->key,key,16);
memcpy(ret->iv,iv,8);
- write(od,key,16);
- write(od,iv,8);
+ if (write(od,key,16) < 0 || write(od,iv,8) < 0) {
+ perror("Could not write blowfish key");
+ goto failure;
+ }
close (od);
vc_printlog(2,"Done.");
return ret;
@@ -262,7 +261,6 @@
struct datagram pkt, pkt_dec;
struct peer _peer;
struct peer *p1 = &_peer;
- struct sigaction sa_timer;
plugname = _plugname;
remoteusr = _remoteusr;
@@ -275,11 +273,6 @@
memset(&last_out_time,0, sizeof(struct timeval));
- sigemptyset(&sa_timer.sa_mask);
- sa_timer.sa_handler = client_maylogin;
- sigaction(SIGALRM, &sa_timer, NULL);
-
-
if(enc_type == ENC_PRESHARED && (!pre_shared ||
access(pre_shared,R_OK)!=0)){
vc_printlog(0,"Error accessing pre-shared key %s:
%s\n",pre_shared,strerror(errno));
exit(1);
Modified: trunk/vde-2/src/vde_cryptcab/vde_cryptcab_server.c
===================================================================
--- trunk/vde-2/src/vde_cryptcab/vde_cryptcab_server.c 2010-04-26 17:00:47 UTC
(rev 407)
+++ trunk/vde-2/src/vde_cryptcab/vde_cryptcab_server.c 2010-04-29 22:23:15 UTC
(rev 408)
@@ -16,11 +16,6 @@
static char *plugname;
static enum e_enc_type enc_type = ENC_SSH;
-static struct itimerval TIMER = {
- .it_interval={ .tv_sec=0, .tv_usec=0},
- .it_value={ .tv_sec=SESSION_TIMEOUT/2, .tv_usec=0 }
-};
-
/*
* Add a peer to the main list.
* Client will have a list of one peer only,
@@ -112,6 +107,10 @@
struct timeval now;
char filename[128];
struct peer *nxt;
+
+ if (sublist == list) {
+ vc_printlog(4, "Cleaning list of peer from expired
clients....");
+ }
if(!sublist)
return NULL;
@@ -176,14 +175,6 @@
*/
static void
-autocleaner(int signo)
-{
- struct itimerval *old=NULL;
- list=clean_peerlist(list);
- setitimer(ITIMER_REAL, &TIMER, old);
-}
-
-static void
do_exit(int signo){
vc_printlog(1,"Caught signal, exiting.");
remove_peerlist(list);
@@ -328,15 +319,17 @@
pfd[0].events=POLLIN|POLLHUP;
peerlist = populate_peerlist(pfd);
- do{
- pollret = poll(pfd,1+numberofpeers(),1000);
- if(pollret<0){
- if(errno==EINTR)
- return 0;
- perror("poll");
- exit(1);
- }
- } while (pollret==0);
+ pollret = poll(pfd,1+numberofpeers(),1000);
+ if(pollret<0){
+ if(errno==EINTR)
+ return 0;
+ perror("poll");
+ exit(1);
+ }
+ if (pollret == 0) {
+ list = clean_peerlist(list);
+ return 0;
+ }
for(;;){
@@ -362,9 +355,13 @@
}
// This increment comes with "static int i" def, to ensure
fairness among peers.
+ // whenever a loop is complete, try to cleanup old peers from
list.
i++;
- if(i>numberofpeers())
+ if(i>numberofpeers()) {
+ list = clean_peerlist(list);
i=1;
+ return 0;
+ }
if (pfd[i].revents&POLLNVAL || pfd[i].revents&POLLHUP){
usleep(10000);
@@ -400,11 +397,8 @@
sigemptyset(&sa_timer.sa_mask);
sigemptyset(&sa_exit.sa_mask);
sa_exit.sa_handler = do_exit;
- sa_timer.sa_handler = autocleaner;
- sigaction(SIGALRM, &sa_timer, NULL);
sigaction(SIGINT, &sa_exit, NULL);
sigaction(SIGTERM, &sa_exit, NULL);
- kill(getpid(),SIGALRM);
if(enc_type == ENC_PRESHARED && (!pre_shared ||
access(pre_shared,R_OK)!=0)){
fprintf(stderr,"Error accessing pre-shared key
%s\n",pre_shared);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
vde-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vde-users