Changeset 117
- Timestamp:
- 10.12.2005 02:56:47 (3 years ago)
- Location:
- trunk
- Files:
-
- 8 modified
-
doc/ipfm.conf.man (modified) (1 diff)
-
source/config.h.in (modified) (1 diff)
-
source/config.l (modified) (1 diff)
-
source/config.y (modified) (4 diffs)
-
source/data.c (modified) (7 diffs)
-
source/filter.h (modified) (2 diffs)
-
source/init.c (modified) (2 diffs)
-
source/ipfm.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/ipfm.conf.man
r78 r117 59 59 60 60 .SS 61 .I Timestamp 62 .B Syntax : 63 timestamp left|right clear|dump 64 65 This indicates IPFM to use the begining (left timestamp) or ending (right timestamp) time of the clear/dump interval to name the output file. 66 67 Default is timestamp right dump 68 69 .SS 61 70 .I NEW LOG 62 71 .B Syntax : -
trunk/source/config.h.in
r96 r117 19 19 #define DEFAULT_OPTIONS_APPEND 0 20 20 #define DEFAULT_OPTIONS_TIMEZONE local 21 #define DEFAULT_OPTIONS_TIMESTAMP right_dump 21 22 22 23 /* But leave these defines untouched */ -
trunk/source/config.l
r77 r117 85 85 [Uu][Tt][Cc] return UNIVERSALTIME; 86 86 [Ww][Ii][Tt][Hh] return WITH; 87 [Tt]ime[Ss]tamp return TIMESTAMP; 88 [Rr]ight return RIGHT; 89 [Ll]eft return LEFT; 87 90 88 91 [Pp][Rr][Oo][Mm][Ii][Ss][Cc] { yylval.longval = 1; return PROMISC; } -
trunk/source/config.y
r75 r117 105 105 %token UNIVERSALTIME 106 106 %token WITH 107 107 %token TIMESTAMP 108 %token RIGHT 109 %token LEFT 108 110 109 111 %token<SortFunc> SORTFUNC … … 240 242 pNewLog->Filter = NULL; 241 243 pNewLog->Data = NULL; 244 pNewLog->TimeStampType = DEFAULT_OPTIONS_TIMESTAMP; 242 245 pNewLog->DumpInterval = DEFAULT_OPTIONS_DUMPINTERVAL; 243 246 pNewLog->ClearInterval = DEFAULT_OPTIONS_CLEARINTERVAL; 244 247 pNewLog->ClearCounter = DEFAULT_OPTIONS_CLEARCOUNTER; 245 248 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 */ 246 252 pNewLog->LogFile = strdup(DEFAULT_OPTIONS_LOGFILE); 247 253 pNewLog->Sort = DEFAULT_OPTIONS_SORT; … … 259 265 tz = UTC; 260 266 } 267 | TimeStamp EOL 261 268 | error EOL { 262 269 parseerror("Skipping invalid line", line); … … 389 396 ; 390 397 398 TimeStamp: 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 391 413 %% 392 414 -
trunk/source/data.c
r101 r117 43 43 #include <sys/types.h> 44 44 #include <arpa/inet.h> 45 #include <time.h> 45 46 46 47 #include "config.h" … … 49 50 #include "init.h" 50 51 #include "utils.h" 52 #include "debug.h" 51 53 52 54 extern struct OptionsType Options; … … 106 108 char *FileName; 107 109 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 109 128 /* Avoid stdout conflicts between son and father */ 110 129 fflush(stdout); … … 117 136 FILE *logfile; 118 137 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; 120 140 char *timezonestring; 121 141 … … 159 179 } 160 180 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); 170 209 171 210 fprintf(logfile, "# %-33s%15s%15s%15s\n", … … 174 213 "Out (bytes)", 175 214 "Total (bytes)"); 215 176 216 while (NULL != pLog->Data) { 177 217 DataFormat(pLog, pLog->Data, DataToFile, MAX_DATA_SIZE); … … 189 229 190 230 fprintf(logfile, "# end of dump %s\n", stringTime); 191 xfree(stringTime);192 231 if (1 == pLog->Append) { 193 232 fprintf(logfile, "\n"); 194 233 } 234 195 235 fclose(logfile); 236 196 237 /* As under linux, pcap uses atexit to restore non promiscuous mode, 197 238 we use _exit() to avoid unsetting promiscuous mode when the child -
trunk/source/filter.h
r63 r117 58 58 }; 59 59 60 enum enumTimeStampType { left_clear, right_clear, left_dump, right_dump }; 61 60 62 struct AllLogsType { 61 63 struct ipfm_filter *Filter; … … 68 70 int ReverseLookup; 69 71 int Append; 72 73 /* right or left Timestamp selector */ 74 enum enumTimeStampType TimeStampType; 70 75 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 */ 72 84 unsigned long int DumpInterval; 85 /* Used to record in how many dumps the collected data should be cleared */ 73 86 unsigned long int ClearCounter; 87 /* Defines every how many dumps the collected data should be cleared */ 74 88 unsigned long int ClearInterval; 75 89 -
trunk/source/init.c
r114 r117 185 185 pNewLog->Data = NULL; 186 186 pNewLog->DataSize = 0; 187 pNewLog->TimeStampType = DEFAULT_OPTIONS_TIMESTAMP; 187 188 pNewLog->DumpInterval = DEFAULT_OPTIONS_DUMPINTERVAL; 188 189 pNewLog->ClearInterval = DEFAULT_OPTIONS_CLEARINTERVAL; 189 190 pNewLog->ClearCounter = DEFAULT_OPTIONS_CLEARCOUNTER; 191 pNewLog->PrevDump = time(NULL); 192 pNewLog->PrevClear = time(NULL); 190 193 pNewLog->NextDump = ((time(NULL) / DEFAULT_OPTIONS_DUMPINTERVAL) + 1) * DEFAULT_OPTIONS_DUMPINTERVAL; 194 /* NextClear is set afterwards */ 191 195 pNewLog->LogFile = xstrdup(DEFAULT_OPTIONS_LOGFILE); 192 196 pNewLog->Sort = DEFAULT_OPTIONS_SORT; … … 359 363 xfree (pTempLog); 360 364 } else { 361 /* this entry is kept */ 365 /* this entry is kept, adjust NextClear */ 366 pTempLog->NextClear = pTempLog->NextDump + pTempLog->DumpInterval * (pTempLog->ClearCounter - 1); 367 362 368 pPrevLog = pTempLog; 363 369 } -
trunk/source/ipfm.c
r116 r117 117 117 for(;;) { 118 118 p_packet = (struct ip *) getnextippkt(); 119 119 120 120 dofilter(p_packet); 121 121 122 122 /* Well that's an approximation. I should perhaps use an alarm() */ 123 123 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)); 124 125 if (time(NULL) > pTempLog->NextDump) { 125 126 data_dump(pTempLog); 126 127 /* Check if we have to clear the logs as well */ 127 if ( pTempLog->ClearInterval) {128 if (0 != pTempLog->ClearInterval) { 128 129 pTempLog->ClearCounter--; 129 130 if (0 >= pTempLog->ClearCounter) { 130 131 data_clear(pTempLog); 132 pTempLog->PrevClear = pTempLog->NextDump; 133 pTempLog->NextClear = pTempLog->NextDump + pTempLog->ClearInterval * pTempLog->DumpInterval; 131 134 pTempLog->ClearCounter = pTempLog->ClearInterval; 132 135 } 133 136 } 134 pTempLog->NextDump += pTempLog->DumpInterval; 137 pTempLog->PrevDump = pTempLog->NextDump; 138 pTempLog->NextDump += pTempLog->DumpInterval; 135 139 } 136 140 }
