source: packages/net/igmpproxy/patches/100-use-monotic-clock-instead-of-time-of-day.patch @ 31332

Last change on this file since 31332 was 31332, checked in by jogo, 5 years ago

packages: igmpproxy: use monotonic clock

Prevents issues when time changes during runtime of igmpproxy.

Contributed by T-Labs, Deutsche Telekom Innovation Laboratories

File size: 3.8 KB
  • configure.ac

    From d0e66e0719ae8eb549f7cc220fdc66575d3db332 Mon Sep 17 00:00:00 2001
    From: Jonas Gorski <jonas.gorski@gmail.com>
    Date: Thu, 29 Mar 2012 17:01:11 +0200
    Subject: [PATCH 4/4] use monotic clock instead of time of day
    
    The time of day might chance e.g. by daylight savings time during the
    runtime, which causes timers to fire repeatedly for a long time.
    
    Contributed by T-Labs, Deutsche Telekom Innovation Laboratories
    
    Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
    ---
     configure.ac    |    2 ++
     src/igmpproxy.c |   26 +++++++++++++-------------
     src/igmpproxy.h |    3 ++-
     3 files changed, 17 insertions(+), 14 deletions(-)
    
    diff --git a/configure.ac b/configure.ac
    index 85beb08..bd84eba 100644
    a b AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], [], [], [[ 
    2525#include <netinet/in.h> 
    2626]]) 
    2727 
     28AC_SEARCH_LIBS([clock_gettime],[rt]) 
     29 
    2830AC_CONFIG_FILES([ 
    2931        Makefile 
    3032        doc/Makefile 
  • src/igmpproxy.c

    diff --git a/src/igmpproxy.c b/src/igmpproxy.c
    index 35000c7..3a9ccad 100644
    a b void igmpProxyRun() { 
    234234    int     MaxFD, Rt, secs; 
    235235    fd_set  ReadFDS; 
    236236    socklen_t dummy = 0; 
    237     struct  timeval  curtime, lasttime, difftime, tv;  
     237    struct  timespec  curtime, lasttime, difftime, tv;  
    238238    // The timeout is a pointer in order to set it to NULL if nessecary. 
    239     struct  timeval  *timeout = &tv; 
     239    struct  timespec  *timeout = &tv; 
    240240 
    241241    // Initialize timer vars 
    242     difftime.tv_usec = 0; 
    243     gettimeofday(&curtime, NULL); 
     242    difftime.tv_nsec = 0; 
     243    clock_gettime(CLOCK_MONOTONIC, &curtime); 
    244244    lasttime = curtime; 
    245245 
    246246    // First thing we send a membership query in downstream VIF's... 
    void igmpProxyRun() { 
    263263        if(secs == -1) { 
    264264            timeout = NULL; 
    265265        } else { 
    266             timeout->tv_usec = 0; 
     266            timeout->tv_nsec = 0; 
    267267            timeout->tv_sec = secs; 
    268268        } 
    269269 
    void igmpProxyRun() { 
    274274        FD_SET( MRouterFD, &ReadFDS ); 
    275275 
    276276        // wait for input 
    277         Rt = select( MaxFD +1, &ReadFDS, NULL, NULL, timeout ); 
     277        Rt = pselect( MaxFD +1, &ReadFDS, NULL, NULL, timeout, NULL ); 
    278278 
    279279        // log and ignore failures 
    280280        if( Rt < 0 ) { 
    void igmpProxyRun() { 
    307307             */ 
    308308            if (Rt == 0) { 
    309309                curtime.tv_sec = lasttime.tv_sec + secs; 
    310                 curtime.tv_usec = lasttime.tv_usec; 
     310                curtime.tv_nsec = lasttime.tv_nsec; 
    311311                Rt = -1; /* don't do this next time through the loop */ 
    312312            } else { 
    313                 gettimeofday(&curtime, NULL); 
     313                clock_gettime(CLOCK_MONOTONIC, &curtime); 
    314314            } 
    315315            difftime.tv_sec = curtime.tv_sec - lasttime.tv_sec; 
    316             difftime.tv_usec += curtime.tv_usec - lasttime.tv_usec; 
    317             while (difftime.tv_usec > 1000000) { 
     316            difftime.tv_nsec += curtime.tv_nsec - lasttime.tv_nsec; 
     317            while (difftime.tv_nsec > 1000000000) { 
    318318                difftime.tv_sec++; 
    319                 difftime.tv_usec -= 1000000; 
     319                difftime.tv_nsec -= 1000000000; 
    320320            } 
    321             if (difftime.tv_usec < 0) { 
     321            if (difftime.tv_nsec < 0) { 
    322322                difftime.tv_sec--; 
    323                 difftime.tv_usec += 1000000; 
     323                difftime.tv_nsec += 1000000000; 
    324324            } 
    325325            lasttime = curtime; 
    326326            if (secs == 0 || difftime.tv_sec > 0) 
  • src/igmpproxy.h

    diff --git a/src/igmpproxy.h b/src/igmpproxy.h
    index 4df8a79..36a4f04 100644
    a b  
    4444#include <string.h> 
    4545#include <fcntl.h> 
    4646#include <stdbool.h> 
     47#include <time.h> 
    4748 
    4849#include <sys/socket.h> 
    4950#include <sys/un.h> 
    50 #include <sys/time.h> 
    5151#include <sys/ioctl.h> 
    5252#include <sys/param.h> 
     53#include <sys/select.h> 
    5354 
    5455#include <net/if.h> 
    5556#include <netinet/in.h> 
Note: See TracBrowser for help on using the repository browser.