|
From: <jn...@us...> - 2007-05-10 22:52:54
|
Revision: 23
http://opencalea.svn.sourceforge.net/opencalea/?rev=23&view=rev
Author: jnorell
Date: 2007-05-10 15:52:39 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Added full config file parsing to df_collector.
DF collector now listens on, and tap sends to,
a single df_port for all cmii/cmc content.
(We could use that for the route/ctrl message too.)
Removed collector and controller, preparing for upcoming
controllerd.
Need to run autoreconf (keeping that as a separate commit).
Modified Paths:
--------------
etc/opencalea/opencalea.conf
src/Makefile.am
src/common.h
src/df_collector.c
src/lea_collector.c
src/tap.c
src/tap.h
src/util.c
src/util.h
Removed Paths:
-------------
src/collector.c
src/controller.c
src/process_registry.c
src/process_registry.h
Modified: etc/opencalea/opencalea.conf
===================================================================
--- etc/opencalea/opencalea.conf 2007-05-10 16:13:21 UTC (rev 22)
+++ etc/opencalea/opencalea.conf 2007-05-10 22:52:39 UTC (rev 23)
@@ -25,38 +25,35 @@
Debug_Level = 4
Debug_Destination = /var/log/opencalea/opencalea.debug
-pid_directory = /var/run/opencalea
-state_directory = /var/run/opencalea
+PID_Dir = /var/run/opencalea
+State_Dir = /var/run/opencalea
[TAP]
Program_Name = tap
-Interface = eth0,eth1,eth2
+Interface = eth0
Debug_Level = 4
Debug_Destination = /var/log/opencalea/tap.debug
-ContentID = Test1234
-
[TAP_CONTROLLER]
Program_Name = tap_controller
-
-pid_file = tap_controller.pid
+PID_File = tap_controller.pid
#Control_Socket = /var/run/opencalea/
+Tap_Exe = /usr/local/bin/tap
[DF_COLLECTOR]
-Program_Name = df_collector
-CmII_Path = /var/log/opencalea/capture
-CmC_Path = /var/log/opencalea/capture
-Log_Path = /var/log/opencalea/log
+Program_Name = df_collector
+CmII_Path = /var/lib/opencalea/storage
+CmC_Path = /var/lib/opencalea/storage
+Log_Path = /var/log/opencalea
+
[LEA_COLLECTOR]
Program_Name = lea_collector
+CF_Data_Path = /var/lib/opencalea/cf_data
+Log_File = /var/log/opencalea/lea_collector.log
+Debug_Destination = /var/log/opencalea/lea_collector.debug
-capturefile_directory = /var/lib/opencalea
-
-logfile = /var/log/opencalea/lea_collector.log
-errorlog = /var/log/opencalea/lea_collector.err
-
Modified: src/Makefile.am
===================================================================
--- src/Makefile.am 2007-05-10 16:13:21 UTC (rev 22)
+++ src/Makefile.am 2007-05-10 22:52:39 UTC (rev 23)
@@ -14,10 +14,3 @@
lea_collector_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
lea_collector_LDADD = -lpcap $(GLIB_LIBS)
-controller_SOURCES = controller.c common.h process_registry.c process_registry.h log_debug.c log_debug.h util.h util.c
-controller_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
-controller_LDADD = -lpthread $(GLIB_LIBS)
-
-collector_SOURCES = collector.c common.h process_registry.c process_registry.h log_debug.c log_debug.h util.h util.c
-collector_CFLAGS = $(AM_CFLAGS) $(GLIB_CFLAGS)
-collector_LDADD = -lpthread $(GLIB_LIBS)
Deleted: src/collector.c
===================================================================
--- src/collector.c 2007-05-10 16:13:21 UTC (rev 22)
+++ src/collector.c 2007-05-10 22:52:39 UTC (rev 23)
@@ -1,373 +0,0 @@
-/*
- * Copyright (c) 2007, Merit Network, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Merit Network, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY MERIT NETWORK, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL MERIT NETWORK, INC. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "common.h"
-#include "process_registry.h"
-
-#include <signal.h>
-#include <sys/wait.h>
-#include <pthread.h>
-#include <glob.h>
-
-char *prog_name = "collector";
-int syslog_facility = DEF_SYSLOG_FACILITY;
-
-extern char **environ;
-
-int get_command ( char* msgbuf ) {
- int msg_id;
- sscanf ( msgbuf, "%d", &msg_id );
- return msg_id ;
-}
-
-int get_target_pid ( char* msgbuf ) {
- int msg_id, target_pid, batch_id;
- sscanf ( msgbuf, "%d %d %d", &msg_id, &batch_id, &target_pid );
- return target_pid;
-}
-
-int get_batch_id ( char* msgbuf ) {
- int msg_id, target_pid, batch_id;
- sscanf ( msgbuf, "%d %d %d", &msg_id, &batch_id, &target_pid );
- return batch_id;
-}
-
-void* reply ( void* args, uint reply_code ) {
- int *handler_socket;
- char* buf;
-
- if (! ( buf = (char*) malloc ( 128 ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- memset ( buf, '\0', 128 );
- snprintf ( buf, 128, "%u", reply_code );
- printf( "about to send: %s\n", buf);
-
- handler_socket = ( int* ) args;
- if ( (send( *handler_socket, buf, strlen( buf ), 0 )) == -1 ) {
- perror("send");
- exit (-1);
- }
-
- free ( buf );
- return ( NULL );
-}
-
-void* controller_thread ( void* args ) {
- int recv_len;
- char *msg_buf;
- int *handler_socket;
- int msg_id = 0;
- int pid = 0;
- int target_pid = 0;
-
- handler_socket = ( int* ) args;
- char* return_buf;
- int send_len = 0;
- if (! ( return_buf = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- if (! ( msg_buf = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
-
- while ( 1 ) {
-
- memset ( msg_buf, '\0', MAX_MSGSIZE );
- memset ( return_buf, '\0', MAX_MSGSIZE );
-
- if ( (recv_len = recv ( *handler_socket, msg_buf, MAX_MSGSIZE - 1, 0 )) == -1 )
- if ( errno != EAGAIN ) {
- perror("recv");
- exit (-1);
- }
-
- if ( recv_len > 0 ) {
-
- msg_id = get_command ( msg_buf );
- switch ( msg_id ) {
- case TAP_START:
- printf ( "start...\n" );
- char *f;
-
- /* send an ACK for the start command */
- reply ( handler_socket, ACK );
-
- /* extract the batch-id */
- int batch_id = 0;
- batch_id = get_batch_id ( msg_buf );
-
- /* extract the filter from the start command */
- char *filter;
- int len = 0;
- printf ( "the msg is: %s\n", msg_buf );
- if ( (f = strstr ( msg_buf, " \"" )) == NULL ) {
- printf ( "syntax error: filter not found\n" );
- break;
- }
- if (! ( filter = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- memset ( filter, '\0', MAX_MSGSIZE );
- memcpy ( filter, f+2, MAX_MSGSIZE - (f+2 - msg_buf) );
-
- len = strlen ( filter );
- filter[len-2] = '\0';
- printf ( "the filter is: %s\n", filter );
-
- /* ignore signals temporarily before we fork
- we re-enable them on the child process only */
-
- signal ( SIGCHLD, SIG_IGN );
- signal ( SIGUSR1, SIG_IGN );
-
- pid = fork( );
-
- if ( pid == 0 ) {
-
- /* this is the child process re-enable signals */
- signal ( SIGUSR1, SIG_DFL );
-
- /* get the arguments with which to run the tap */
- char* argv[32];
- char item[64];
- char filter_item[1024];
- int filter_start = 0 ;
- pid = getpid ( );
- argv[0] = strdup ( "tap" );
- int n = 0;
- char* iter = filter;
- while ( iter < filter + strlen ( filter ) ) {
- n++;
- sscanf ( iter, "%s", item );
- if ( strncmp ( item , "\"", 1 ) == 0 ) {
- if ( filter_start == 0 ) {
- n--;
- filter_start = 1;
- } else {
- /* end of filter */
- printf ( "filter_item: %s\n", filter_item );
- argv[n] = strdup ( filter_item );
- memset ( filter_item , '\0', 1024 );
- }
- } else {
- if ( filter_start == 0 ) {
- argv[n] = strdup ( item );
- } else {
- n--;
- strcat ( filter_item, " " );
- strcat ( filter_item, item );
- }
- }
- iter = iter + strlen ( item ) + 1;
- }
- argv[n+1] = NULL;
- free ( filter );
-
- /* run the tap program with the correct args */
- printf ( "attempting to run tap...\n" );
- execv ( TAP, argv );
-
- exit( 0 );
-
- } else {
- /* if this is the parent process we register
- the child
- attempt to validate whether the process
- actually started correctly first
- */
- int retval = 0;
- sleep ( 1 );
- retval = kill ( pid, 0 );
- if ( retval == 0 ) {
- /* process exists */
- char cmd[1024];
- sprintf ( cmd, "%s %s", TAP, filter );
- free ( filter );
- pid_registry_add ( batch_id, pid, cmd );
- syslog ( LOG_ALERT,
- "starting monitoring session with pid: %d and filter: %s", pid, filter );
- } else {
- syslog ( LOG_ALERT,
- "tap process did not start correctly...\n");
- }
- }
- break;
- case TAP_STOP:
- printf ( "stop...\n" );
-
- /* send an ACK for the stop command */
- reply ( handler_socket, ACK );
-
- /* get batch_id */
- batch_id = get_batch_id ( msg_buf );
-
- if ( batch_id == 0 ) {
- /* this is a stop command */
- /* extract the pid which we want to stop */
- target_pid = get_target_pid ( msg_buf );
- if ( pid_validate ( target_pid ) == 0 ) {
- /* pid was not in our process registry */
- break;
- }
- int retval = 0;
-
- /* send kill signal to the tap pid and make
- sure it actually died */
-
- if ( target_pid != 0 ) {
- syslog ( LOG_ALERT,
- "stoping monitoring session %d", target_pid );
- retval = kill ( target_pid, SIGUSR1 );
- if ( retval == 0 ) {
- /* the kill worked */
- pid_registry_del ( target_pid );
- } else {
- /* unable to kill the process */
- }
- } else {
- /* killing with pid zero will kill all processes
- in the same process group so dont do it */
- }
-
- } else {
- /* batch stop: we lookup all pid for this batch id
- and stop them all */
- int pid_list[128];
- int i = 0;
- int retval = 0;
- printf ( "looking up pids...\n");
- pid_batch_id_lookup ( batch_id, (int*) &pid_list );
- for ( i = 0; i <= 128; i++ ) {
- printf ( "killing pids... %d\n", pid_list[i]);
- syslog ( LOG_ALERT,
- "stoping monitoring session %d", target_pid );
- if ( pid_list[i] != 0 ) {
- retval = kill ( pid_list[i], SIGUSR1 );
- if ( retval == 0 ) {
- /* the kill worked */
- pid_registry_del ( pid_list[i] );
- } else {
- /* unable to kill the process */
- }
- }
- }
-
- }
- break;
- case SHOW_PROCESS_REGISTRY:
- printf ( "show...\n" );
- memset ( return_buf, '\0', MAX_MSGSIZE );
- pid_registry_show ( return_buf );
- send_len = send ( *handler_socket, return_buf,
- strlen ( return_buf ), 0 );
- break;
- case CLOSE_SESSION:
- printf ( "close...\n" );
- reply ( handler_socket, QUIT );
- close ( *handler_socket );
- pthread_exit( NULL );
- exit(-1);
- break;
- case CONNECT:
- printf ( "connect...\n" );
- memset ( return_buf, '\0', MAX_MSGSIZE );
- reply ( handler_socket, ACK );
- break;
- case PING:
- printf ( "ping...\n" );
- reply ( handler_socket, ACK );
- break;
- case NOP:
- printf ( "nop ...\n" );
- reply ( handler_socket, ACK );
- break;
- default:
- printf ( "command code not valid\n" );
- reply ( handler_socket, ACK );
- break;
- }
- }
-
- }
- free ( msg_buf );
- free ( return_buf );
- return ( NULL );
-}
-
-
-int main ( void ) {
-
- int s;
- int handler_socket;;
- struct sockaddr_in myaddr;
- socklen_t myaddrlen;
- int retval = 0;
- int errno;
-
- printf ( "Starting server...\n" );
-
- s = socket ( AF_INET, SOCK_STREAM, 0 );
-
- if ( s == -1 ) {
- printf ( "Error while creating server socket\n" );
- exit ( -1 );
- }
-
- memset ( (char *) &myaddr, 0, sizeof(myaddr) );
- myaddr.sin_family = AF_INET;
- myaddr.sin_port = htons( Collector_PORT );
- myaddr.sin_addr.s_addr = htonl ( INADDR_ANY );
-
- myaddrlen = sizeof( struct sockaddr_in );
- retval = bind ( s, (struct sockaddr*) &myaddr, sizeof(myaddr) );
- if ( retval == -1 ) {
- perror ( "Error while binding socket" );
- exit ( -1 );
- }
-
- syslog ( LOG_ALERT, "Starting CALEA Collector...\n" );
- listen ( s, MAX_CONNECTIONS );
-
- myaddrlen = sizeof( struct sockaddr_in );
-
- while ( 1 ) {
- handler_socket = accept( s, (struct sockaddr*) &myaddr, &myaddrlen );
- if ( handler_socket == -1 ) {
- printf ( "Error while accepting client connection\n" );
- exit ( -1 );
- }
- pthread_t ctrl_thread;
- pthread_create ( &ctrl_thread, NULL, controller_thread, &handler_socket );
- }
- return 0;
-}
Modified: src/common.h
===================================================================
--- src/common.h 2007-05-10 16:13:21 UTC (rev 22)
+++ src/common.h 2007-05-10 22:52:39 UTC (rev 23)
@@ -88,34 +88,31 @@
#endif
+/* default control port (controllerd) */
#ifndef Controller_PORT
#define Controller_PORT 41800
#endif
-#ifndef Collector_PORT
-#define Collector_PORT 41805 /* deprecated - collector will be gone soon */
+/* default port to send to df_controller */
+#ifndef DF_PORT
+#define DF_PORT 41805
#endif
-#ifndef CmII_PORT
-#define CmII_PORT 41810
+/* default lea_collector CmII port */
+#ifndef CF_CmII_PORT
+#define CF_CmII_PORT 41810
#endif
-#ifndef CmC_PORT
-#define CmC_PORT 41820
+/* default lea_collector CmC port */
+#ifndef CF_CmC_PORT
+#define CF_CmC_PORT 41820
#endif
+/* tmp df controller port */
#ifndef DF_CONTROL_PORT
#define DF_CONTROL_PORT 41816
#endif
-#ifndef LEA_COLLECTOR_CmII_PORT
-#define LEA_COLLECTOR_CmII_PORT 41817
-#endif
-
-#ifndef LEA_COLLECTOR_CmC_PORT
-#define LEA_COLLECTOR_CmC_PORT 41818
-#endif
-
#define MAX_CONNECTIONS 10 /* for socket connections, limit the queue of incoming connections */
#define MAX_CONTENT_ID_LENGTH 128
@@ -130,25 +127,8 @@
#define DEF_TAP_USER DEF_USER
#define DEF_TAP_GROUP DEF_GROUP
-/* temporary */
-#define TAP "./tap"
-
-/* valid command codes */
-#define TAP_START 1
-#define TAP_STOP 2
-#define SHOW_PROCESS_REGISTRY 3
-#define CLOSE_SESSION 4
-#define CONNECT 5
-#define PING 6
-#define NOP 7
-
-/* valid repsonse codes */
-#define ACK 0
-#define NACK 1
-#define QUIT 2
-
#define MAX_MSGSIZE 4096 /* max size of control message/response */
-#define MAX_LINE 100
+#define MAX_LINE 512
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
Deleted: src/controller.c
===================================================================
--- src/controller.c 2007-05-10 16:13:21 UTC (rev 22)
+++ src/controller.c 2007-05-10 22:52:39 UTC (rev 23)
@@ -1,382 +0,0 @@
-/*
- * Copyright (c) 2007, Merit Network, Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Merit Network, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY MERIT NETWORK, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL MERIT NETWORK, INC. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "common.h"
-
-#include <fcntl.h>
-
-char *prog_name = "controller";
-int syslog_facility = DEF_SYSLOG_FACILITY;
-
-#define PROMPT "CALEA-CTRL> "
-
-int controller_socket = -1;
-struct sockaddr_in collector_addr;
-
-int connected_flag = 0;
-int batch_mode = 0;
-
-void print_help_msg (void) {
- printf ( " Valid commands are: \n" );
- printf ( " batch-start <ip-list> <filter>\tStart a new collection process\n" );
- printf ( " batch-stop <ip-list> <batch-id>\tStop a collection process\n" );
- printf ( " connect <ip-addr>\t\tConnect to a collector\n" );
- printf ( " start <filter>\t\t\tStart a new collection process\n" );
- printf ( " status\t\t\t\tShow currently running collection processes\n" );
- printf ( " stop <pid>\t\t\tStop a collection process\n" );
- printf ( " quit\t\t\t\tQuit this session\n" );
- printf ( " help\t\t\t\tThis Message\n" );
- printf ( " \n" );
- printf ( " Examples: \n" );
- printf ( " start \"-n host 1.1.1.1\" \n");
- printf ( " batch-start \"1.1.1.1 2.2.2.2\" \"-x x -y y -z z\"\n");
- printf ( " stop 9999 \n");
-}
-
-int process_response ( char* recv_buf ) {
- int response_code = -1;
-
- sscanf ( recv_buf, "%d", &response_code );
- return response_code;
-}
-
-int process_user_cmd ( char* user_input, char* msgbuf ) {
-
- char cmd[64];
- memset ( cmd, '\0', 64 );
-
- if ( strlen ( user_input ) >= MAX_MSGSIZE ) {
- fprintf ( stderr, "Input too long.\n" );
- exit ( -1 );
- }
- if ( strcmp ( user_input, "\n" ) == 0 ) {
- return 0;
- }
- sscanf ( user_input, "%63s", cmd );
-
- if ( strcmp ( cmd, "batch-start" ) == 0 ) {
- if ( controller_socket > 0 ) {
- close ( controller_socket );
- controller_socket = -1;
- }
- batch_mode = 1;
- return 1;
- }
- if ( strcmp ( cmd, "batch-stop" ) == 0 ) {
- if ( controller_socket > 0 ) {
- close ( controller_socket );
- controller_socket = -1;
- connected_flag = 0;
- }
- batch_mode = 2;
- return 1;
- }
- if ( strcmp ( cmd, "quit" ) == 0 ) {
- exit ( 0 ) ;
- }
- if ( ( strcmp ( cmd, "exit" ) == 0 ) || ( strcmp ( cmd, "quit" ) == 0 ) ) {
- if ( connected_flag ) {
- snprintf ( msgbuf, 64, "%d", CLOSE_SESSION );
- return 1;
- } else {
- printf ("Closing.\n");
- exit ( 0 );
- }
- return 0;
- }
-
- if ( strcmp ( cmd, "help" ) == 0 ) {
- print_help_msg ( );
- return 0;
- }
-
- if ( (strcmp ( cmd, "connect" ) != 0) && ( !connected_flag ) ) {
- printf ("Error: Bad Command. (maybe \"connect\" first?)\n\n");
- print_help_msg ( );
- return 0;
- }
-
- if ( strcmp ( cmd, "connect" ) == 0 ) {
- char *collector_ipaddr;
-
- /* how large do we need to support ipv6 addrs? */
- if (! ( collector_ipaddr = (char*) malloc ( 16 ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- memset ( collector_ipaddr, '\0', 16 );
-
- sscanf ( user_input, "%63s %15s", cmd, collector_ipaddr );
-
- controller_socket = socket ( AF_INET, SOCK_STREAM, 0 );
- if ( controller_socket == -1 ) {
- perror ( "Error while creating server socket: socket" );
- exit ( -1 );
- }
- if (fcntl ( controller_socket, F_SETFL, O_NONBLOCK ) == -1) {
- perror ( "fcntl" );
- exit ( -1 );
- }
-
- collector_addr.sin_family = AF_INET;
- collector_addr.sin_port = htons ( Collector_PORT ) ;
- collector_addr.sin_addr.s_addr = inet_addr( collector_ipaddr );
- free ( collector_ipaddr );
-
- if (collector_addr.sin_addr.s_addr == INADDR_NONE) {
- printf ( "Bad IP Addr\n" );
- return 0;
- }
-
- int i = 0;
- printf ( "Connecting." );
- fflush ( stdout );
- for ( i = 0; i < 5 ; i++ ) {
- if (connect ( controller_socket,
- (struct sockaddr*) &collector_addr,
- sizeof(struct sockaddr_in) ) == 0 )
- break;
- sleep ( 1 );
- if ( errno == EISCONN ) {
- printf ( "Done." );
- break;
- }
- printf ( "." );
- fflush ( stdout );
- }
- printf ( "\n" );
- fcntl ( controller_socket, F_SETFL, 2 );
-
- char return_buf[MAX_MSGSIZE];
- snprintf ( msgbuf, MAX_MSGSIZE, "%d", NOP );
- if ( send ( controller_socket, msgbuf, strlen ( msgbuf ), 0 ) != -1 ) {
- if ( recv ( controller_socket, return_buf, MAX_MSGSIZE, 0 ) == -1 ) {
- if ( errno != EAGAIN ) {
- perror("recv");
- exit (-1);
- }
- }
- /* we were able to send on socket and recv ACK so we must be connected */
- if ( batch_mode == 0 ) {
- connected_flag = 1;
- }
- snprintf ( msgbuf, MAX_MSGSIZE, "%d", CONNECT );
- } else {
- perror ( "Connect failed" );
- return 0;
- }
-
- return 1;
- }
-
- if ( strcmp ( cmd, "start" ) == 0 ) {
- char *filter;
- int batch_id = 0;
-
- if (! ( filter = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- memset ( filter, '\0', MAX_MSGSIZE );
-
- sscanf ( user_input, " %63s ", cmd );
- strncpy ( filter, &user_input[ strlen ( cmd ) ], MAX_MSGSIZE - strlen ( cmd ) );
- snprintf ( msgbuf, MAX_MSGSIZE, "%d %d %s", TAP_START, batch_id, filter );
- free ( filter );
- return 1;
- }
- if ( strcmp ( cmd, "stop" ) == 0 ) {
- int target_pid = 0;
- sscanf ( user_input, "%63s %d", cmd, &target_pid );
- snprintf ( msgbuf, 64, "%d %d %d", TAP_STOP, 0, target_pid );
- return 1;
- }
- if ( strcmp ( cmd, "status" ) == 0 ) {
- snprintf ( msgbuf, 64, "%d", SHOW_PROCESS_REGISTRY );
- return 1;
- }
-
- return -1;
-}
-
-int main ( void ) {
-
- char* msgbuf;
- char* return_buf;
- char* user_input;
-
- printf ( "Starting client...\n" );
- srand (getpid());
-
- if (! ( msgbuf = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- if (! ( user_input = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- if (! ( return_buf = (char*) malloc ( MAX_MSGSIZE ) ) ) {
- perror("malloc");
- exit ( -1 );
- }
- int send_len = 0;
- int recv_len = 0;
- int retval = 0;
-
- /* process user commands till we exit */
- while ( 1 ) {
- printf ( "%s ", PROMPT );
- memset ( user_input, '\0', MAX_MSGSIZE );
- memset ( msgbuf, '\0', MAX_MSGSIZE );
-
- if ( fgets ( user_input, MAX_MSGSIZE, stdin ) == NULL ) {
- perror( "fgets" );
- exit( -1 );
- }
-
- retval = process_user_cmd ( user_input, msgbuf );
-
- if ( batch_mode == 0 ) {
- if ( retval == 1) {
- if ( (send_len = send ( controller_socket, msgbuf, strlen ( msgbuf ), 0 )) == -1 ) {
- perror("send");
- exit (-1);
- }
- memset ( return_buf, '\0', MAX_MSGSIZE );
- if ( (recv_len = recv ( controller_socket, return_buf, MAX_MSGSIZE, 0 )) == -1 )
- if ( errno != EAGAIN ) {
- perror("recv");
- exit (-1);
- }
- if ( recv_len > 0 ) {
- int resp_code;
- resp_code = process_response ( return_buf );
- switch ( resp_code ) {
- case QUIT:
- /* collector ACKed our request to quit */
- break;
- case ACK:
- /* collector ACKed our request */
- break;
- default:
- printf ( "%s\n", return_buf );
- break;
- }
- }
- } else {
- /* command was not valid */
- if ( retval == -1 ) {
- printf ( "%s ", "Invalid command\n" );
- print_help_msg ( );
- }
- }
-
- } else if ( batch_mode >= 1 ) {
-
- char *batch_cmd;
- char *filter = NULL;
- char *f;
- char *start = NULL;
- char *str_end;
- char *tok;
- int end;
- char cmd[64];
- char my_input[MAX_MSGSIZE];
- int batch_id = rand();
-
- sscanf ( user_input, "%63s", cmd );
- batch_cmd = user_input + strlen ( cmd ) + 1;
-
- if ( batch_mode == 1 ) {
- /* extract the filter */
- f = strstr ( batch_cmd, " \"" );
- filter = strdup (f);
- /* shorten the string to only have the ip address list */
- f[0] = '\0';
- /* get rid of starting and ending quote characters */
- start = batch_cmd + 1;
- end = strlen ( batch_cmd ) - 1;
- batch_cmd[end] = '\0';
- } else if ( batch_mode == 2 ) {
- /* extract the batch_id */
- f = strstr ( batch_cmd, "\" " );
- f = f + 2;
- batch_id = atoi ( f );
- f[0] = '\0';
- printf ( "batch_id is: %d\n", batch_id );
- printf ( "ip list is: %s\n", batch_cmd );
- /* get rid of starting and ending quote characters */
- start = batch_cmd + 1;
- end = strlen ( batch_cmd ) - 2;
- batch_cmd[end] = '\0';
- }
-
- str_end = start + strlen ( batch_cmd );
-
- while (start < str_end) {
- tok = strtok ( start, " " );
- printf ("tok: %s\n", tok);
- snprintf ( my_input, MAX_MSGSIZE, "connect %s", tok );
- retval = process_user_cmd ( my_input, msgbuf );
- if ( batch_mode == 1 ) {
- snprintf ( msgbuf, MAX_MSGSIZE, "%d %d %s",
- TAP_START, batch_id, filter );
- } else if ( batch_mode == 2 ) {
- snprintf ( msgbuf, MAX_MSGSIZE, "%d %d %d", TAP_STOP, batch_id, 0 );
- }
- if ( (send_len = send ( controller_socket, msgbuf, strlen ( msgbuf ), 0 )) == -1 ) {
- perror("send");
- exit (-1);
- }
- snprintf ( msgbuf, 64, "%d", CLOSE_SESSION );
- if ( (send_len = send ( controller_socket, msgbuf, strlen ( msgbuf ), 0 )) == -1 ) {
- perror("send");
- exit (-1);
- }
-
- start = start + strlen ( tok ) + 1;
- memset ( msgbuf, '\0', MAX_MSGSIZE);
- }
- batch_mode = 0;
- connected_flag = 0;
- if ( filter )
- free ( filter );
- }
- }
-
- free ( return_buf );
- free ( user_input );
- free ( msgbuf );
-
- close( controller_socket );
- controller_socket = -1;
-
- return 0;
-}
-
Modified: src/df_collector.c
===================================================================
--- src/df_collector.c 2007-05-10 16:13:21 UTC (rev 22)
+++ src/df_collector.c 2007-05-10 22:52:39 UTC (rev 23)
@@ -24,8 +24,6 @@
* SUCH DAMAGE.
*/
-#include <string.h>
-
#include "common.h"
#include "msg.h"
#include "calea.h"
@@ -39,14 +37,9 @@
#define DF_REPLY 1
-char *prog_name = "df_collector";
-int syslog_facility = DEF_SYSLOG_FACILITY;
+char *prog_name = "df_collector";
+int syslog_facility = DEF_SYSLOG_FACILITY;
-char *cmc_file = NULL;
-char *cmii_file = NULL;
-int cmc_port = 0;
-int cmii_port = 0;
-
/* Routes to LEA */
#define MAXROUTES 10
@@ -64,9 +57,12 @@
struct addrinfo hints, *res;
char *bind_addr = NULL;
-const int on = 1;
-const int off = 0;
+char *df_port = NULL;
+char *ctrl_port = NULL;
+const int on = 1;
+const int off = 0;
+
int change_user = 0;
int change_group = 0;
struct passwd *pwent;
@@ -94,51 +90,39 @@
int i=0;
/* command line options processing */
- while (( i = getopt ( argc, argv, "t:f:b:hm:n:u:g:vD:l:L:" )) != -1 ) {
+ while (( i = getopt ( argc, argv, "f:u:g:b:p:m:n:vD:l:L:h" )) != -1 ) {
switch ( i ) {
- case 'f': // CmC file
- if ( ( cmc_file = strdup ( optarg ) ) == NULL )
- pdie ( "strdup" );
- debug_5 ( "got opt %c: %s", i, optarg );
- break;
- case 't': // CmII file
- if ( ( cmii_file = strdup ( optarg ) ) == NULL )
- pdie ( "strdup" );
- debug_5 ( "got opt %c: %s", i, optarg );
- break;
- case 'b': // address to bind to
- if ( ( bind_addr = strdup ( optarg ) ) == NULL )
- pdie ( "strdup" );
- debug_5 ( "got opt %c: %s", i, optarg );
- break;
+ case 'f': // config file
+ conf_file = Strdup ( optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
+ break;
case 'u': // username
strncpy ( (char *)user, optarg, 31 );
- debug_5 ( "got opt %c: %s", i, optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
change_user = 1;
break;
case 'g': // group name
strncpy ( &group[0], optarg, 31 );
- debug_5 ( "got opt %c: %s", i, optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
change_group = 1;
break;
- case 'm': // cmc port
- cmc_port = atoi ( optarg );
- debug_5 ( "got opt %c: %s", i, optarg );
+ case 'b': // address to bind to
+ bind_addr = Strdup ( optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
break;
- case 'n': // cmii port
- cmii_port = atoi ( optarg );
- debug_5 ( "got opt %c: %s", i, optarg );
+ case 'p': // df listening port
+ df_port = Strdup ( optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
break;
case 'v': // debug ('d' was taken)
debug_level_set++;
- debug_5 ( "got opt %c, debug level now %d",
+ debug_4 ( "got opt %c, debug level now %d",
i, debug_level_set );
break;
case 'D': // debug file
- if ( ( debug_file_name = strdup ( optarg ) ) == NULL )
- pdie ( "strdup" );
- debug_5 ( "got opt %c: %s", i, optarg );
+ debug_file_name = Strdup ( optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
break;
case 'l': // log level
errno = 0;
@@ -149,12 +133,11 @@
else
die ( "invalid log_level_set" );
}
- debug_5 ( "got opt %c: %d", i, log_level_set );
+ debug_4 ( "got opt %c: %d", i, log_level_set );
break;
case 'L': // logfile
- if ( ( log_file_name = strdup ( optarg ) ) == NULL )
- pdie ( "strdup" );
- debug_5 ( "got opt %c: %s", i, optarg );
+ log_file_name = Strdup ( optarg );
+ debug_4 ( "got opt %c: %s", i, optarg );
break;
case 'h': // help
usage();
@@ -185,79 +168,91 @@
die("Error parsing config file: %s", DEF_DF_COLLECTOR_CONF);
}
+
+ /* Now determine what user/group to change to */
+ if ( ! change_user ) {
+ if ((confptr = get_config(&config, "User")) != NULL) {
+ strncpy ( user, *confptr->nextval++, 31 );
+ debug_4("user set from config file: %s", user);
+ }
+ }
+ if ( ! change_group ) {
+ if ((confptr = get_config(&config, "Group")) != NULL) {
+ strncpy ( group, *confptr->nextval++, 31 );
+ debug_4("group set from config file: %s", group);
+ }
+ }
+
+ /* Drop privs if running as root or if requested */
+ if ( ((uid_t)getegid() == 0) || change_group ) {
+ debug_3 ( "changing group id to: %s", group );
+ errno = 0;
+ if (! (grent = getgrnam(group)) ) {
+ if (errno) {
+ pdie ( "getgrnam" );
+ } else {
+ die ( "Group %s not found\n", group );
+ }
+ }
+ if ( setgid(grent->gr_gid) < 0 )
+ pdie ( "setgid" );
+ }
+ if ( ((uid_t)geteuid() == 0) || change_user ) {
+ debug_3 ( "changing userid to: %s", user );
+ errno = 0;
+ if (! (pwent = getpwnam(user)) ) {
+ if (errno) {
+ pdie ( "getpwnam" );
+ } else {
+ die ( "User %s not found\n", user );
+ }
+ }
+ if ( setuid(pwent->pw_uid) < 0 )
+ pdie ( "setuid" );
+ }
+
+ /* We're running as non-root from here on... */
+
/* Get CmII_Path from config file */
if ((confptr = get_config(&config, "CmII_Path")) != NULL) {
- cmii_path = Calloc(strlen(*confptr->nextval) + 1);
- bzero(cmii_path,strlen(*confptr->nextval) + 1);
- strncpy(cmii_path, *confptr->nextval, strlen(*confptr->nextval));
- debug_5("df_collector: CmII_Path [%s]", cmii_path);
+ cmii_path = Strdup(*confptr->nextval++);
+ debug_4("df_collector: CmII_Path [%s]", cmii_path);
}
/* Get CmC_Path from config file */
if ((confptr = get_config(&config, "CmC_Path")) != NULL) {
- cmc_path = Calloc(strlen(*confptr->nextval) + 1);
- bzero(cmc_path,strlen(*confptr->nextval) + 1);
- strncpy(cmc_path, *confptr->nextval, strlen(*confptr->nextval));
- debug_5("df_collector: CmC_Path [%s]", cmc_path);
+ cmc_path = Strdup(*confptr->nextval++);
+ debug_4("df_collector: CmC_Path [%s]", cmc_path);
}
/* Get Log_Path from config file */
if ((confptr = get_config(&config, "Log_Path")) != NULL) {
- log_path = Calloc(strlen(*confptr->nextval) + 1);
- bzero(log_path, strlen(*confptr->nextval) + 1);
- strncpy(log_path, *confptr->nextval, strlen(*confptr->nextval));
- debug_5("df_collector: log_path [%s]", log_path);
+ log_path = Strdup(*confptr->nextval++);
+ debug_4("df_collector: log_path [%s]", log_path);
}
- if ( cmii_file == NULL ) {
- usage();
- die ( "CmII file not specified (need -f)." );
- }
+ if ( bind_addr == NULL ) {
+ if ((confptr = get_config(&config, "Bind_Addr"))) {
+ bind_addr = Strdup ( *confptr->nextval++ );
+ debug_4("df_collector: bind address set from config file (%s)", bind_addr);
+ } else {
+ bind_addr = Strdup ( "127.0.0.1" );
+ debug_4("df_collector: Using default bind address (%s)", bind_addr);
+ }
+ }
- /* drop privs if running as root or told to do so */
- if ( ((uid_t)geteuid() == 0) || change_user ) {
- debug_5 ( "changing userid to: %s", user );
- errno = 0;
- if (! (pwent = getpwnam(user)) ) {
- if (errno) {
- pdie ( "getpwnam" );
- } else {
- die ( "User %s not found\n", user );
- }
- }
- if ( setuid(pwent->pw_uid) < 0 )
- pdie ( "setuid" );
+ if ( df_port == NULL ) {
+ if ((confptr = get_config(&config, "DF_Port"))) {
+ df_port = Strdup ( *confptr->nextval++ );
+ debug_5 ( "df_collector: DF listener port set from config file (%d)", df_port );
+ } else {
+ df_port = Calloc ( 64 );
+ snprintf ( df_port, 64, "%d", DF_PORT );
+ debug_5 ( "df_collector: Using default DF listener port (%d)", df_port );
+ }
}
- if ( ((uid_t)geteuid() == 0) || change_group ) {
- debug_5 ( "changing group id to: %s", group );
- errno = 0;
- if (! (grent = getgrnam(group)) ) {
- if (errno) {
- pdie ( "getgrnam" );
- } else {
- die ( "Group %s not found\n", group );
- }
- }
- if (setgid(grent->gr_gid) < 0)
- pdie ( "setgid" );
- }
- if (!bind_addr) {
- bind_addr = "127.0.0.1";
- debug_5 ( "df_collector: Using default bind address (%s)", bind_addr );
- }
- if ( cmii_port == 0 ) {
- cmii_port = CmII_PORT;
- debug_5 ( "df_collector: Using default CmII listener port (%d)", cmii_port );
- }
-
- if ( cmc_port == 0 ) {
- cmc_port = CmC_PORT;
- debug_5 ( "df_collector: Using default CmC listener port (%d)", cmc_port );
- }
-
-
return;
}
@@ -271,7 +266,7 @@
int id;
char route_port[8];
char filename[MAX_LINE];
- int socktype;
+
socklen_t socklen;
/* returned by Getsockopt */
union sockval {
@@ -284,11 +279,11 @@
switch(msg->msgh.msgtype) {
case MSGTYPE_NONE:
- debug_5("df_collector: MSGTYPE_NONE uninitialized or not present");
+ debug_2("df_collector: MSGTYPE_NONE uninitialized or not present");
break;
case MSGTYPE_CONTROL:
- //debug_5("df_collector: MSGTYPE_CONTROL OpenCALEA Control message");
+ debug_3("df_collector: MSGTYPE_CONTROL OpenCALEA Control message");
ctrlmsg = (CtrlMsg *)((char *)msg + msg_len);
//print_hex((const u_char *)msg, msg_len);
@@ -297,7 +292,7 @@
switch (ctrlmsg->ctrlh.cmd) {
case CTRLCMD_ROUTE_ADD:
- //debug_5("df_collector: ROUTE ADD Control message received");
+ debug_3("df_collector: ROUTE ADD Control message received");
/* look for a free slot in the route[] table */
for (id=0; id<MAXROUTES; id++) {
@@ -306,7 +301,8 @@
}
if (id == MAXROUTES) {
- debug_5("df_collector: no available routes");
+ debug_1("df_collector: no available routes");
+ log_2("df_collector: no available routes");
return -1;
}
@@ -315,12 +311,12 @@
/************************************/
if (!route[id].cmii_fp) {
bzero(filename,MAX_LINE);
- strcat(filename,cmii_path);
- strcat(filename,"/");
- strcat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID);
- strcat(filename,".CmII");
- if (!(route[id].cmii_fp = fopen(filename, "ab"))) {
- debug_5("df_collector: CmII_fp open failed for %s", filename);
+ strncat(filename,cmii_path,MAX_LINE);
+ strncat(filename,"/",MAX_LINE - strlen(filename));
+ strncat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID,MAX_LINE - strlen(filename));
+ strncat(filename,".CmII",MAX_LINE - strlen(filename));
+ if (!(route[id].cmii_fp = fopen(filename, "wb"))) {
+ error("df_collector: CmII_fp open failed for %s", filename);
pdie("df_collector: CmII_fp fopen");
}
}
@@ -330,12 +326,12 @@
/************************************/
if (!route[id].cmc_fp) {
bzero(filename,MAX_LINE);
- strcat(filename,cmc_path);
- strcat(filename,"/");
- strcat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID);
- strcat(filename,".CmC");
- if (!(route[id].cmc_fp = fopen(filename, "ab"))) {
- debug_5("df_collector: CmC_fp open failed for %s", filename);
+ strncat(filename,cmc_path,MAX_LINE - strlen(filename));
+ strncat(filename,"/",MAX_LINE - strlen(filename));
+ strncat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID,MAX_LINE - strlen(filename));
+ strncat(filename,".CmC",MAX_LINE - strlen(filename));
+ if (!(route[id].cmc_fp = fopen(filename, "wb"))) {
+ error("df_collector: CmC_fp open failed for %s", filename);
pdie("df_collector: CmC_fp fopen");
}
}
@@ -345,12 +341,12 @@
/******************************************/
if (!route[id].log_fp) {
bzero(filename,MAX_LINE);
- strcat(filename,log_path);
- strcat(filename,"/");
- strcat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID);
- strcat(filename,".LOG");
- if (!(route[id].log_fp = fopen(filename, "a"))) {
- debug_5("df_collector: Surveillance log file open failed for %s", filename);
+ strncat(filename,log_path,MAX_LINE - strlen(filename));
+ strncat(filename,"/",MAX_LINE - strlen(filename));
+ strncat(filename,(char *)ctrlmsg->ctrlh.intercept.CaseID,MAX_LINE - strlen(filename));
+ strncat(filename,".LOG",MAX_LINE - strlen(filename));
+ if (!(route[id].log_fp = fopen(filename, "w"))) {
+ error("df_collector: Surveillance log file open failed for %s", filename);
pdie("df_collector: Surveillance log fopen");
}
}
@@ -358,18 +354,25 @@
/*****************************************/
/* Create a Route (generally to the LEA) */
/*****************************************/
+ sprintf(route_port, "%d", ntohs(ctrlmsg->ctrlh.dfhost.port));
+ debug_4("df_collector: route port is %s", route_port);
+
+ bzero(&hints, sizeof(hints));
+ hints.ai_family = AF_INET;
+
if (strcmp((char *)ctrlmsg->ctrlh.dfhost.protocol,"udp") == 0) {
- socktype = SOCK_DGRAM;
+ debug_4("df_collector: route protocol is UDP");
+ hints.ai_socktype = SOCK_DGRAM;
} else if (strcmp((char *)ctrlmsg->ctrlh.dfhost.protocol,"tcp") == 0) {
- socktype = SOCK_STREAM;
+ error("df_collector: TCP is currently an unsupported route protocol");
+ hints.ai_socktype = SOCK_STREAM;
} else {
- debug_5("df_collector: %s is currently an unsupported route protocol. Defaulting to UDP", ctrlmsg->ctrlh.dfhost.protocol);
- socktype = SOCK_DGRAM;
+ debug_2("df_collector: %s is currently an unsupported route protocol. Defaulting to UDP",
+ ctrlmsg->ctrlh.dfhost.protocol);
+ hints.ai_socktype = SOCK_DGRAM;
}
- res = Getaddrinfo1st((char *)ctrlmsg->ctrlh.dfhost.host, ntohs(ctrlmsg->ctrlh.dfhost.port), AF_INET, socktype);
- if (!res) {
- debug_5("df_collector: ROUTE ADD Getaddrinfo1st failed");
+ if (getaddrinfo((char *)ctrlmsg->ctrlh.dfhost.host, route_port, &hints, &res)) {
return -1;
}
@@ -381,17 +384,17 @@
route[id].lea_addr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
route[id].lea_addr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
if ((route[id].lea_fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- debug_5("df_collector: ipv4 route[%d]=%d socket failure", id, route[id].lea_fd);
+ debug_2("df_collector: ipv4 route[%d]=%d socket failure", id, route[id].lea_fd);
break;
}
if (connect(route[id].lea_fd, res->ai_addr, res->ai_addrlen) < 0) {
- debug_4 ( "df_collector: connect error");
- close(route[id].lea_fd);
+ debug_2 ( "df_collector: connect error");
+ Close(route[id].lea_fd);
route[id].lea_fd = -1;
}
- debug_5("df_collector: ROUTE[%d] created to %s://%s:%d [%s %s %s]",
+ debug_3("df_collector: ROUTE[%d] created to %s://%s:%d [%s %s %s]",
id,
ctrlmsg->ctrlh.dfhost.protocol,
ctrlmsg->ctrlh.dfhost.host,
@@ -404,8 +407,10 @@
freeaddrinfo(res);
return DF_REPLY;
case AF_INET6:
+ error("df_collector: we don't handle IPv6 yet.");
break;
default:
+ error("df_collector: we don't handle address family %d.", res->ai_family);
break;
}
break;
@@ -415,7 +420,7 @@
}
case MSGTYPE_LOG:
- debug_5("df_collector: MSGTYPE_LOG Surveillance Log message");
+ debug_4("df_collector: MSGTYPE_LOG Surveillance Log message");
//print_hex((const u_char *)msg, msg_len);
//print_hex((const u_char *)((char *)msg + msg_len), msg->msgh.msglen);
@@ -424,22 +429,34 @@
if (route[id].log_fp) {
ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].log_fp);
if (ret != 1) {
- debug_5("df_collector: error writing to Log file");
+ error("df_collector: error writing to Log file: %s", strerror(errno));
}
} else {
- debug_5("df_collector: Warning Log file is not available");
+ debug_2("df_collector: Warning Log file is not available");
}
break;
case MSGTYPE_CMII:
- //debug_5("df_collector: MSGTYPE_CMII Communications Identifying Information message");
+ debug_5("df_collector: MSGTYPE_CMII Communications Identifying Information message");
//print_hex((const u_char *)msg, msg_len);
//print_hex((const u_char *)((char *)msg + msg_len), msg->msgh.msglen);
id = ntohs(msg->msgh.routeid);
inet_ntop (route[id].lea_addr.sin_family, &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr));
+ /**************************/
+ /* Write packet to a file */
+ /**************************/
+ if (route[id].cmii_fp) {
+ ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmii_fp);
+ if (ret != 1) {
+ error("df_collector: error writing to CmII file: %s", strerror(errno));
+ }
+ } else {
+ debug_5("df_collector: CmII capture file is not available");
+ }
+
num_sent = sendto (route[id].lea_fd,
((char *)msg + msg_len),
msg->msgh.msglen,
@@ -447,34 +464,13 @@
(struct sockaddr *)&route[id].lea_addr,
sizeof(route[id].lea_addr));
- /****************************************************************************/
- /* If there was an error sending the data to the other end of the route[id] */
- /* then save the data locally for future transmission. */
- /* Note that for UDP transmissions, an error will only be indicated if the */
- /* the socket to the route[id] is in an error state. For UDP, there IS NO */
- /* GUARANTEE that the data was actually received at the remote end. */
- /****************************************************************************/
if (num_sent == -1) {
- debug_5("df_collector: CmII packet -> route[%d] %s:%d failed saving to file",
+ debug_3("df_collector: CmII packet -> route[%d] %s:%d failed",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port));
socklen = sizeof(sockval);
Getsockopt(route[id].lea_fd, SOL_SOCKET, SO_ERROR, &sockval, &socklen);
-
- /**************************/
- /* Write packet to a file */
- /**************************/
- if (route[id].cmii_fp) {
- ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmii_fp);
- if (ret != 1) {
- debug_5("df_collector: Error writing to CmII file");
- } else {
- debug_5("df_collector: Wrote %d bytes to CmII file", (ret * msg->msgh.msglen));
- }
- } else {
- debug_5("df_collector: Warning CmII capture file is not available");
- }
} else {
debug_5("df_collector: CmII packet -> route[%d] %s:%d %d bytes sent ",
id,
@@ -486,17 +482,26 @@
break;
case MSGTYPE_CII:
- debug_5("df_collector: MSGTYPE_CII Call Identifying Information message");
+ debug_3("df_collector: MSGTYPE_CII Call Identifying Information message");
break;
case MSGTYPE_CMC:
- //debug_5("df_collector: MSGTYPE_CMC Communications Content message");
+ debug_5("df_collector: MSGTYPE_CMC Communications Content message");
//print_hex((const u_char *)msg, msg_len);
//print_hex((const u_char *)((char *)msg + msg_len), msg->msgh.msglen);
id = ntohs(msg->msgh.routeid);
inet_ntop (route[id].lea_addr.sin_family, &route[id].lea_addr.sin_addr.s_addr, addrstr, sizeof(addrstr));
+ if (route[id].cmc_fp) {
+ ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmc_fp);
+ if (ret != 1) {
+ error("df_collector: error writing to CmC file: %s", strerror(errno));
+ }
+ } else {
+ debug_5("df_collector: CmC capture file is not available");
+ }
+
num_sent = sendto (route[id].lea_fd,
((char *)msg + msg_len),
msg->msgh.msglen,
@@ -504,34 +509,13 @@
(struct sockaddr *)&route[id].lea_addr,
sizeof(route[id].lea_addr));
- /****************************************************************************/
- /* If there was an error sending the data to the other end of the route[id] */
- /* then save the data locally for future transmission. */
- /* Note that for UDP transmissions, an error will only be indicated if the */
- /* the socket to the route[id] is in an error state. For UDP, there IS NO */
- /* GUARANTEE that the data was actually received at the remote end. */
- /****************************************************************************/
if (num_sent == -1) {
- debug_5("df_collector: CmC packet -> route[%d] %s:%d failed saving to file",
+ debug_3("df_collector: CmC packet -> route[%d] %s:%d failed",
id,
addrstr,
ntohs(route[id].lea_addr.sin_port));
socklen = sizeof(sockval);
Getsockopt(route[id].lea_fd, SOL_SOCKET, SO_ERROR, &sockval, &socklen);
- /**************************/
- /* Write packet to a file */
- /**************************/
- if (route[id].cmc_fp) {
- ret = fwrite(((char *)msg + msg_len), msg->msgh.msglen, 1, route[id].cmc_fp);
- if (ret != 1) {
- debug_5("df_collector: Error writing to CmC file");
- } else {
- debug_5("df_collector: Wrote %d bytes to CmC file", (ret * msg->msgh.msglen));
- }
- } else {
- debug_5("df_collector: Warning CmC capture file is not available");
- }
-
} else {
debug_5("df_collector: CmC packet -> route[%d] %s:%d %d bytes sent ",
id,
@@ -543,10 +527,10 @@
break;
case MSGTYPE_CC:
- debug_5("df_collector: MSGTYPE_CC Call Content message");
+ debug_3("df_collector: MSGTYPE_CC Call Content message");
break;
default:
- debug_5("df_collector: Unknown MSGTYPE detected");
+ debug_2("df_collector: Unknown MSGTYPE detected");
break;
}
@@ -589,13 +573,14 @@
void usage ( void ) {
- printf ( "Usage: df_collector -t cmii-capture-file " );
- printf ( "[-f cmc-capture-file] " );
- printf ( "[-b bind-addr] " );
- printf ( "[-u user] [-g group] " );
+ printf ( "Usage: df_collector " );
+ printf ( " [-f config-file]" );
+ printf ( " [-u user] [-g group]" );
+ printf ( " [-b bind-addr] " );
printf ( " [-m cmc-port] [-n cmii-port] [-x]" );
printf ( " [-v [...]] [-D debug-file]" );
printf ( " [-l log-level ] [-L logfile]" );
+ printf ( " [-h]" );
printf ( "\n" );
@@ -604,10 +589,8 @@
int main ( int argc, char *argv[] ) {
int i, maxi, maxfd, connfd, sockfd;
- int CmII_tcpfd = -1;
- int CmC_tcpfd = -1;
- int CmII_udpfd = -1;
- int CmC_udpfd = -1;
+ int df_tcpfd = -1;
+ int df_udpfd = -1;
int controlfd = -1;
int nready, client[FD_SETSIZE];
ssize_t n;
@@ -617,78 +600,44 @@
socklen_t len, clilen;
struct sockaddr_in cliaddr, servaddr;
- setdebug( 5, "stdout", 1 );
+ setdebug( DEF_DEBUG_LEVEL, DEF_DEBUG_DEST, 1 );
+ setlog( DEF_LOG_LEVEL, DEF_LOG_DEST, 1 );
parse_commandline(argc, argv);
- /**************************/
- /* Create CmII TCP socket */
- /**************************/
- res = Getaddrinfo1st(bind_addr, cmii_port, AF_INET, SOCK_STREAM);
- if (!res) {
- debug_5("df_collector: CmII TCP Gteaddrinfo1st failed");
- return -1;
- }
+ /************************/
+ /* Create DF TCP socket */
+ /************************/
+ res = Getaddrinfo1st(bind_addr, df_port, AF_INET, SOCK_STREAM);
switch (res->ai_family) {
case AF_INET:
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = res->ai_family;
servaddr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
servaddr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
- if ((CmII_tcpfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- debug_5("df_collector: CmII TCP socket error");
+ if ((df_tcpfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
+ error("df_collector: DF TCP socket error");
}
break;
default:
- debug_5("df_collector: CmII TCP unsupported family");
+ die("df_collector: DF TCP unsupported family");
break;
}
inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- debug_5("df_collector: CmII TCP IPv%d address: %s (%s) port: %d", res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname, ntohs(servaddr.sin_port));
+ debug_5("df_collector: DF TCP IPv%d address: %s (%s) port: %d",
+ res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname, ntohs(servaddr.sin_port));
freeaddrinfo(res);
- Setsockopt(CmII_tcpfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- Bind(CmII_tcpfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
- Listen(CmII_tcpfd, MAX_CONNECTIONS);
+ Setsockopt(df_tcpfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ Bind(df_tcpfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
+ Listen(df_tcpfd, MAX_CONNECTIONS);
- /*************************/
- /* Create CmC TCP socket */
- /*************************/
- res = Getaddrinfo1st(bind_addr, cmc_port, AF_INET, SOCK_STREAM);
- if (!res) {
- debug_5("df_collector: CmC TCP Getaddrinfo1st failed");
- return -1;
- }
- switch (res->ai_family) {
- case AF_INET:
- bzero(&servaddr, sizeof(servaddr));
- servaddr.sin_family = res->ai_family;
- servaddr.sin_port = ((struct sockaddr_in *)res->ai_addr)->sin_port;
- servaddr.sin_addr.s_addr = ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr;
- if ((CmC_tcpfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
- debug_5("df_collector: CmC TCP socket error");
- }
- break;
- default:
- debug_5("df_collector: CmC TCP unsupported family");
- break;
- }
- inet_ntop (servaddr.sin_family, &servaddr.sin_addr.s_addr, addrstr, sizeof(addrstr));
- debug_5("df_collector: CmC TCP IPv%d address: %s (%s) port: %d", res->ai_family == PF_INET6 ? 6 : 4, addrstr, res->ai_canonname, ntohs(servaddr.sin_port));
- freeaddrinfo(res);
-
- Setsockopt(CmC_tcpfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- Bind(CmC_tcpfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
- Listen(CmC_tcpfd, MAX_CONNECTIONS);
-
/*****************************/
/* Create control TCP socket */
/*****************************/
- res = Getaddrinfo1st(bind_addr, DF_CONTROL_PORT, AF_INET, SOCK_STREAM);
- if (!res) {
- debug_5("df_collector: Control TCP Getaddrinfo1st failed");
- return -1;
- }
+ ctrl_port = Calloc ( 64 );
+ snprintf ( ctrl_port, 64, "%d", DF_CONTROL_PORT );
+ res = Getaddrinfo1st(bind_addr, ctrl_port, AF_INET, SOCK_STREAM);
switch (res->ai_family) {
case AF_INET:
bzero(&servaddr, s...
[truncated message content] |