Changeset 117

Show
Ignore:
Timestamp:
10.12.2005 02:56:47 (3 years ago)
Author:
tibob
Message:
  • Added left/right dump/clean timestamp for filename (closes #8 and #2)
  • More details in the header of log files
Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/doc/ipfm.conf.man

    r78 r117  
    5959 
    6060.SS 
     61.I Timestamp 
     62.B Syntax : 
     63timestamp left|right clear|dump 
     64 
     65This indicates IPFM to use the begining (left timestamp) or ending (right timestamp) time of the clear/dump interval  to name the output file. 
     66 
     67Default is timestamp right dump 
     68 
     69.SS 
    6170.I NEW LOG 
    6271.B Syntax : 
  • trunk/source/config.h.in

    r96 r117  
    1919#define DEFAULT_OPTIONS_APPEND        0 
    2020#define DEFAULT_OPTIONS_TIMEZONE      local 
     21#define DEFAULT_OPTIONS_TIMESTAMP     right_dump 
    2122 
    2223/* But leave these defines untouched */ 
  • trunk/source/config.l

    r77 r117  
    8585[Uu][Tt][Cc]                     return UNIVERSALTIME; 
    8686[Ww][Ii][Tt][Hh]                 return WITH; 
     87[Tt]ime[Ss]tamp                  return TIMESTAMP; 
     88[Rr]ight                         return RIGHT; 
     89[Ll]eft                          return LEFT; 
    8790 
    8891[Pp][Rr][Oo][Mm][Ii][Ss][Cc]         { yylval.longval = 1; return PROMISC; } 
  • trunk/source/config.y

    r75 r117  
    105105%token UNIVERSALTIME 
    106106%token WITH 
    107  
     107%token TIMESTAMP 
     108%token RIGHT 
     109%token LEFT 
    108110 
    109111%token<SortFunc>  SORTFUNC 
     
    240242          pNewLog->Filter = NULL; 
    241243          pNewLog->Data = NULL; 
     244          pNewLog->TimeStampType = DEFAULT_OPTIONS_TIMESTAMP; 
    242245          pNewLog->DumpInterval = DEFAULT_OPTIONS_DUMPINTERVAL; 
    243246          pNewLog->ClearInterval = DEFAULT_OPTIONS_CLEARINTERVAL; 
    244247          pNewLog->ClearCounter = DEFAULT_OPTIONS_CLEARCOUNTER; 
    245248          pNewLog->NextDump = ((time(NULL) / DEFAULT_OPTIONS_DUMPINTERVAL) + 1) * DEFAULT_OPTIONS_DUMPINTERVAL; 
     249          pNewLog->PrevDump = time(NULL); 
     250          pNewLog->PrevClear = time(NULL); 
     251          /* NextClear is set afterwards */ 
    246252          pNewLog->LogFile = strdup(DEFAULT_OPTIONS_LOGFILE); 
    247253          pNewLog->Sort = DEFAULT_OPTIONS_SORT; 
     
    259265          tz = UTC; 
    260266        } 
     267      | TimeStamp EOL 
    261268      | error EOL { 
    262269          parseerror("Skipping invalid line", line); 
     
    389396      ; 
    390397 
     398TimeStamp: 
     399        TIMESTAMP LEFT CLEAR { 
     400          pAllLogs->TimeStampType = left_clear; 
     401        } 
     402      | TIMESTAMP LEFT DUMP { 
     403          pAllLogs->TimeStampType = left_dump; 
     404        } 
     405      | TIMESTAMP RIGHT CLEAR { 
     406          pAllLogs->TimeStampType = right_clear; 
     407        } 
     408      | TIMESTAMP RIGHT DUMP { 
     409          pAllLogs->TimeStampType = right_dump; 
     410        } 
     411      ; 
     412 
    391413%% 
    392414 
  • trunk/source/data.c

    r101 r117  
    4343#include <sys/types.h> 
    4444#include <arpa/inet.h> 
     45#include <time.h> 
    4546 
    4647#include "config.h" 
     
    4950#include "init.h" 
    5051#include "utils.h" 
     52#include "debug.h" 
    5153 
    5254extern struct OptionsType Options; 
     
    106108  char *FileName; 
    107109 
    108   FileName = timefile(pLog->LogFile, pLog->NextDump); 
     110  switch (pLog->TimeStampType) { 
     111    case left_dump: 
     112      FileName = timefile(pLog->LogFile, pLog->PrevDump); 
     113      break; 
     114    case left_clear: 
     115      FileName = timefile(pLog->LogFile, pLog->PrevClear); 
     116      break; 
     117    case right_clear: 
     118      FileName = timefile(pLog->LogFile, pLog->NextClear); 
     119      break; 
     120    case right_dump: 
     121    default: 
     122      FileName = timefile(pLog->LogFile, pLog->NextDump); 
     123      break; 
     124  } 
     125 
     126  DEBUG_MSG("It's %d and I'm dumping in %s\n", time(NULL), FileName); 
     127 
    109128  /* Avoid stdout conflicts between son and father */ 
    110129  fflush(stdout); 
     
    117136    FILE *logfile; 
    118137    char DataToFile[MAX_DATA_SIZE]; 
    119     char *stringTime; 
     138    /* "=NULL" to avoid a compiler warning */ 
     139    char *stringTime, *DumpTime, *ClearTime=NULL, *PrevClear=NULL, *PrevDump, *stringAction; 
    120140    char *timezonestring; 
    121141 
     
    159179    } 
    160180 
    161     stringTime = timefile("%Y/%m/%d %H:%M:%S", pLog->NextDump); 
    162  
    163     fprintf(logfile, "# IPFMv%s %s (%s) -- dump every %ldd%02ld:%02ld:%02ld -- listening on %s\n", 
    164             VERSION, stringTime, timezonestring, 
    165             pLog->DumpInterval / (60*60*24), 
    166             (pLog->DumpInterval / (60*60)) % 24, 
    167             (pLog->DumpInterval / (60)) % 60, 
    168             pLog->DumpInterval % 60, 
    169             device); 
     181    stringTime = timefile("%Y/%m/%d %H:%M:%S", time(NULL)); 
     182 
     183    DumpTime = timefile("%Y/%m/%d %H:%M:%S", pLog->NextDump); 
     184    PrevDump = timefile("%Y/%m/%d %H:%M:%S", pLog->PrevDump); 
     185    if (pLog->ClearCounter > 1 || pLog->ClearInterval == 0) { 
     186      stringAction = "dumping"; 
     187    } else { 
     188      stringAction = "clearing"; 
     189    } 
     190 
     191    fprintf(logfile, "# ipfm %s %s at %s (%s)\n", 
     192            VERSION, stringAction, stringTime, timezonestring); 
     193    fprintf(logfile, "# Listening on %s\n", device); 
     194    fprintf(logfile, "# Dump period :  %s -- %s\n", 
     195            PrevDump, DumpTime); 
     196 
     197    if (pLog->ClearInterval != 0) { 
     198      ClearTime = timefile("%Y/%m/%d %H:%M:%S", pLog->NextClear); 
     199      PrevClear = timefile("%Y/%m/%d %H:%M:%S", pLog->PrevClear); 
     200      fprintf(logfile, "# Clear period : %s -- %s\n", 
     201              PrevClear, ClearTime); 
     202      xfree(ClearTime); 
     203      xfree(PrevClear); 
     204    } 
     205 
     206    xfree(DumpTime); 
     207    xfree(PrevDump); 
     208    xfree(stringTime); 
    170209 
    171210    fprintf(logfile, "# %-33s%15s%15s%15s\n", 
     
    174213            "Out (bytes)", 
    175214            "Total (bytes)"); 
     215     
    176216    while (NULL != pLog->Data) { 
    177217      DataFormat(pLog, pLog->Data, DataToFile, MAX_DATA_SIZE); 
     
    189229 
    190230    fprintf(logfile, "# end of dump %s\n", stringTime); 
    191     xfree(stringTime); 
    192231    if (1 == pLog->Append) { 
    193232      fprintf(logfile, "\n"); 
    194233    } 
     234 
    195235    fclose(logfile); 
     236 
    196237    /* As under linux, pcap uses atexit to restore non promiscuous mode, 
    197238       we use _exit() to avoid unsetting promiscuous mode when the child 
  • trunk/source/filter.h

    r63 r117  
    5858}; 
    5959 
     60enum enumTimeStampType { left_clear, right_clear, left_dump, right_dump }; 
     61 
    6062struct AllLogsType { 
    6163  struct ipfm_filter *Filter; 
     
    6870  int ReverseLookup; 
    6971  int Append; 
     72   
     73  /* right or left Timestamp selector */ 
     74  enum enumTimeStampType TimeStampType; 
    7075 
    71   unsigned long int NextDump; 
     76  time_t NextDump; 
     77  /* PrefDump, PrevClear and NextClear could (most of the time) be calculated 
     78     when needed , but it's easier to note them when NextDump and ClearCounter 
     79     are Changed */ 
     80  time_t PrevDump; 
     81  time_t PrevClear; 
     82  time_t NextClear; 
     83  /* Defines the Dump Interval in seconds */ 
    7284  unsigned long int DumpInterval; 
     85  /* Used to record in how many dumps the collected data should be cleared */ 
    7386  unsigned long int ClearCounter; 
     87  /* Defines every how many dumps the collected data should be cleared */ 
    7488  unsigned long int ClearInterval; 
    7589 
  • trunk/source/init.c

    r114 r117  
    185185  pNewLog->Data = NULL; 
    186186  pNewLog->DataSize = 0; 
     187  pNewLog->TimeStampType = DEFAULT_OPTIONS_TIMESTAMP; 
    187188  pNewLog->DumpInterval = DEFAULT_OPTIONS_DUMPINTERVAL; 
    188189  pNewLog->ClearInterval = DEFAULT_OPTIONS_CLEARINTERVAL; 
    189190  pNewLog->ClearCounter = DEFAULT_OPTIONS_CLEARCOUNTER; 
     191  pNewLog->PrevDump = time(NULL); 
     192  pNewLog->PrevClear = time(NULL); 
    190193  pNewLog->NextDump = ((time(NULL) / DEFAULT_OPTIONS_DUMPINTERVAL) + 1) * DEFAULT_OPTIONS_DUMPINTERVAL; 
     194  /* NextClear is set afterwards */ 
    191195  pNewLog->LogFile = xstrdup(DEFAULT_OPTIONS_LOGFILE); 
    192196  pNewLog->Sort = DEFAULT_OPTIONS_SORT; 
     
    359363      xfree (pTempLog); 
    360364    } else { 
    361       /* this entry is kept */ 
     365      /* this entry is kept, adjust NextClear */ 
     366      pTempLog->NextClear = pTempLog->NextDump + pTempLog->DumpInterval * (pTempLog->ClearCounter - 1); 
     367 
    362368      pPrevLog = pTempLog; 
    363369    } 
  • trunk/source/ipfm.c

    r116 r117  
    117117  for(;;) { 
    118118    p_packet = (struct ip *) getnextippkt(); 
    119      
     119 
    120120    dofilter(p_packet); 
    121121 
    122122    /* Well that's an approximation. I should perhaps use an alarm() */ 
    123123    for (pTempLog = pAllLogs; NULL != pTempLog; pTempLog = pTempLog->Next) { 
     124      DEBUG_MSG("time %d nextdump %d delta %d\n", time(NULL), pTempLog->NextDump, pTempLog->NextDump - time(NULL)); 
    124125      if (time(NULL) > pTempLog->NextDump) { 
    125126        data_dump(pTempLog); 
    126127        /* Check if we have to clear the logs as well */ 
    127         if (pTempLog->ClearInterval) { 
     128        if (0 != pTempLog->ClearInterval) { 
    128129          pTempLog->ClearCounter--; 
    129130          if (0 >= pTempLog->ClearCounter) { 
    130131            data_clear(pTempLog); 
     132            pTempLog->PrevClear = pTempLog->NextDump; 
     133            pTempLog->NextClear = pTempLog->NextDump + pTempLog->ClearInterval * pTempLog->DumpInterval; 
    131134            pTempLog->ClearCounter = pTempLog->ClearInterval; 
    132135          } 
    133136        } 
    134         pTempLog->NextDump += pTempLog->DumpInterval; 
     137        pTempLog->PrevDump = pTempLog->NextDump; 
     138        pTempLog->NextDump += pTempLog->DumpInterval; 
    135139      } 
    136140    }