@@ -64,11 +64,12 @@ statistics_t stats;
64
64
void usage (void )
65
65
{
66
66
67
- printf ("pcapdj [-h] -b namedpipe [-s redis_server] -p [redis_srv_port]\n\n" );
67
+ printf ("pcapdj [-h] -b namedpipe [-s redis_server] -p [redis_srv_port] [-q redis_queue] \n\n" );
68
68
printf ("Connects to the redis instance specified with by the redis_server\n" );
69
69
printf ("and redis_srv_port.\n\n" );
70
70
71
- printf ("Read a list of pcap-ng files from the queue PCAPDJ_IN_QUEUE.\n" );
71
+ printf ("Read a list of pcap-ng files from the queue PCAPDJ_IN_QUEUE by default\n" );
72
+ printf ("or the queue specified with the -q flag is set.\n" );
72
73
printf ("Open the pcap-ng file and feed each packet to the fifo buffer\n" );
73
74
printf ("specified by with the -b option. When a pcap file from the list\n" );
74
75
printf ("has been transferred to the buffer update the queue PCAPDJ_PROCESSED\n" );
@@ -176,11 +177,11 @@ void delete_next_file_queue(redisContext* ctx)
176
177
}
177
178
178
179
179
- void delete_auth_file (redisContext * ctx )
180
+ void delete_auth_file (redisContext * ctx , char * filename )
180
181
{
181
182
/* FIXME errors are ignored */
182
183
redisReply * reply ;
183
- reply = redisCommand (ctx , "DEL %s" , AKEY );
184
+ reply = redisCommand (ctx , "SREM %s %s " , AKEY , filename );
184
185
if (reply )
185
186
freeReplyObject (reply );
186
187
}
@@ -192,20 +193,15 @@ void wait_auth_to_proceed(redisContext* ctx, char* filename)
192
193
/* If there is an error the program waits forever */
193
194
194
195
do {
195
- reply = redisCommand (ctx ,"GET %s" ,AKEY );
196
+ reply = redisCommand (ctx ,"SISMEMBER %s %s " ,AKEY , filename );
196
197
if (reply ){
197
- if (reply -> type == REDIS_REPLY_STRING ) {
198
- /* Delete the authorized key. So in the next
199
- * iteration the AUTH_KEY is not there anymore and
200
- * the error message is not reated all the times
201
- */
202
- delete_auth_file (ctx );
203
- if (!strncmp (reply -> str , filename , strlen (filename ))) {
198
+ if (reply -> type == REDIS_REPLY_INTEGER ) {
199
+ /* Delete the filename from the set if found */
200
+ if (reply -> integer == 1 ){
201
+ delete_auth_file (ctx , filename );
204
202
fprintf (stderr , "[INFO] Got authorization to process %s\n" ,filename );
205
203
freeReplyObject (reply );
206
204
return ;
207
- }else {
208
- fprintf (stderr ,"[ERROR] Got the wrong authorization. Waited for (%s). Got %s.\n" , filename , reply -> str );
209
205
}
210
206
}
211
207
freeReplyObject (reply );
@@ -257,7 +253,7 @@ void process_file(redisContext* ctx, wtap_dumper* dumper, char* filename)
257
253
}
258
254
}
259
255
260
- int process_input_queue (wtap_dumper * dumper , char * redis_server , int redis_srv_port )
256
+ int process_input_queue (wtap_dumper * dumper , char * redis_server , int redis_srv_port , char * redis_queue )
261
257
{
262
258
redisContext * ctx ;
263
259
redisReply * reply ;
@@ -268,10 +264,9 @@ int process_input_queue(wtap_dumper *dumper, char* redis_server, int redis_srv_p
268
264
fprintf (stderr ,"[ERROR] Could not connect to redis. %s.\n" , ctx -> errstr );
269
265
return EXIT_FAILURE ;
270
266
}
271
-
272
267
273
268
do {
274
- reply = redisCommand (ctx ,"LPOP %s" , PQUEUE );
269
+ reply = redisCommand (ctx ,"LPOP %s" , redis_queue );
275
270
if (!reply ){
276
271
fprintf (stderr ,"[ERROR] Redis error %s\n" ,ctx -> errstr );
277
272
return EXIT_FAILURE ;
@@ -320,36 +315,40 @@ void init(void)
320
315
int main (int argc , char * argv [])
321
316
{
322
317
323
- int opt ;
324
- int r ;
318
+ int opt , r , redis_srv_port , write_err ;
325
319
char * redis_server ;
326
- int redis_srv_port ;
327
- char * namedpipe ;
320
+ char * namedpipe ;
321
+ char * redis_queue ;
328
322
FILE * fifo ;
329
323
wtap_dumper * pdh = NULL ;
330
324
wtap_dump_params params = WTAP_DUMP_PARAMS_INIT ;
331
- int write_err ;
332
325
333
326
init ();
334
327
335
328
namedpipe = calloc (128 ,1 );
336
329
assert (namedpipe );
337
-
330
+
331
+ redis_queue = calloc (128 ,1 );
332
+ assert (redis_queue );
333
+
338
334
redis_server = calloc (64 ,1 );
339
335
assert (redis_server );
340
336
341
337
redis_srv_port = 6379 ;
342
- while ((opt = getopt (argc , argv , "b:hs:p:" )) != -1 ) {
338
+ while ((opt = getopt (argc , argv , "b:hs:p:q: " )) != -1 ) {
343
339
switch (opt ) {
344
340
case 's' :
345
- strncpy (redis_server ,optarg ,64 );
341
+ strncpy (redis_server , optarg , 64 );
346
342
break ;
347
343
case 'p' :
348
344
redis_srv_port = atoi (optarg );
349
345
break ;
350
346
case 'b' :
351
347
strncpy (namedpipe , optarg , 128 );
352
348
break ;
349
+ case 'q' :
350
+ strncpy (redis_queue , optarg , 128 );
351
+ break ;
353
352
case 'h' :
354
353
usage ();
355
354
return EXIT_SUCCESS ;
@@ -365,6 +364,8 @@ int main(int argc, char* argv[])
365
364
fprintf (stderr ,"[ERROR] A named pipe must be specified\n" );
366
365
return EXIT_FAILURE ;
367
366
}
367
+ if (!redis_queue [0 ])
368
+ strncpy (redis_queue ,PQUEUE ,128 );
368
369
369
370
fifo = fopen (namedpipe , "wb" );
370
371
if (fifo == NULL ) {
@@ -373,13 +374,14 @@ int main(int argc, char* argv[])
373
374
374
375
fprintf (stderr , "[INFO] redis_server = %s\n" ,redis_server );
375
376
fprintf (stderr , "[INFO] redis_port = %d\n" ,redis_srv_port );
377
+ fprintf (stderr , "[INFO] redis_queue = %s\n" , redis_queue );
376
378
fprintf (stderr , "[INFO] named pipe = %s\n" , namedpipe );
377
379
fprintf (stderr , "[INFO] pid = %d\n" ,(int )getpid ());
378
380
379
381
params .encap = WTAP_ENCAP_ETHERNET ;
380
382
pdh = wtap_dump_fdopen (fileno (fifo ), WTAP_FILE_TYPE_SUBTYPE_PCAPNG , WTAP_UNCOMPRESSED , & params , & write_err );
381
383
if (pdh != NULL ){
382
- r = process_input_queue (pdh , redis_server , redis_srv_port );
384
+ r = process_input_queue (pdh , redis_server , redis_srv_port , redis_queue );
383
385
if (r == EXIT_FAILURE ) {
384
386
fprintf (stderr ,"[ERROR] Something went wrong in during processing" );
385
387
}else {
0 commit comments