Add -Z in nfcapd/sfcapd for timezone extension. Breaks expire for now

This commit is contained in:
Peter Haag 2016-01-10 12:42:40 +01:00
parent 3b72bdac13
commit a12087c1e9
2 changed files with 54 additions and 38 deletions

View File

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag * Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag * Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung * Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,12 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $Author: haag $ * Author: peter
*
* $Id: nfcapd.c 51 2010-01-29 09:01:54Z haag $
*
* $LastChangedRevision: 51 $
*
* *
*/ */
@ -153,7 +149,7 @@ static void daemonize(void);
static void SetPriv(char *userid, char *groupid ); static void SetPriv(char *userid, char *groupid );
static void run(packet_function_t receive_packet, int socket, send_peer_t peer, static void run(packet_function_t receive_packet, int socket, send_peer_t peer,
time_t twin, time_t t_begin, int report_seq, int use_subdirs, int compress, int do_xstat); time_t twin, time_t t_begin, int report_seq, int use_subdirs, char *time_extension, int compress, int do_xstat);
/* Functions */ /* Functions */
static void usage(char *name) { static void usage(char *name) {
@ -185,6 +181,7 @@ static void usage(char *name) {
"-4\t\tListen on IPv4 (default).\n" "-4\t\tListen on IPv4 (default).\n"
"-6\t\tListen on IPv6.\n" "-6\t\tListen on IPv6.\n"
"-V\t\tPrint version and exit.\n" "-V\t\tPrint version and exit.\n"
"-Z\t\tAdd timezone offset to filenamet.\n"
, name); , name);
} // End of usage } // End of usage
@ -363,7 +360,7 @@ int err;
#include "collector_inline.c" #include "collector_inline.c"
static void run(packet_function_t receive_packet, int socket, send_peer_t peer, static void run(packet_function_t receive_packet, int socket, send_peer_t peer,
time_t twin, time_t t_begin, int report_seq, int use_subdirs, int compress, int do_xstat) { time_t twin, time_t t_begin, int report_seq, int use_subdirs, char *time_extension, int compress, int do_xstat) {
common_flow_header_t *nf_header; common_flow_header_t *nf_header;
FlowSource_t *fs; FlowSource_t *fs;
struct sockaddr_storage nf_sender; struct sockaddr_storage nf_sender;
@ -469,10 +466,11 @@ srecord_t *commbuff;
if ( ((t_now - t_start) >= twin) || done ) { if ( ((t_now - t_start) >= twin) || done ) {
char subfilename[64]; char subfilename[64];
struct tm *now; struct tm *now;
char *subdir; char *subdir, fmt[64];
alarm(0); alarm(0);
now = localtime(&t_start); now = localtime(&t_start);
strftime(fmt, sizeof fmt, time_extension, now);
// prepare sub dir hierarchy // prepare sub dir hierarchy
if ( use_subdirs ) { if ( use_subdirs ) {
@ -483,16 +481,13 @@ srecord_t *commbuff;
// failed to generate subdir path - put flows into base directory // failed to generate subdir path - put flows into base directory
subdir = NULL; subdir = NULL;
snprintf(subfilename, 63, "nfcapd.%i%02i%02i%02i%02i", snprintf(subfilename, 63, "nfcapd.%s", fmt);
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min);
} else { } else {
snprintf(subfilename, 63, "%s/nfcapd.%i%02i%02i%02i%02i", subdir, snprintf(subfilename, 63, "%s/nfcapd.%s", subdir, fmt);
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min);
} }
} else { } else {
subdir = NULL; subdir = NULL;
snprintf(subfilename, 63, "nfcapd.%i%02i%02i%02i%02i", snprintf(subfilename, 63, "nfcapd.%s", fmt);
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min);
} }
subfilename[63] = '\0'; subfilename[63] = '\0';
@ -765,7 +760,7 @@ int main(int argc, char **argv) {
char *bindhost, *filter, *datadir, pidstr[32], *launch_process; char *bindhost, *filter, *datadir, pidstr[32], *launch_process;
char *userid, *groupid, *checkptr, *listenport, *mcastgroup, *extension_tags; char *userid, *groupid, *checkptr, *listenport, *mcastgroup, *extension_tags;
char *Ident, *dynsrcdir, pidfile[MAXPATHLEN]; char *Ident, *dynsrcdir, *time_extension, pidfile[MAXPATHLEN];
struct stat fstat; struct stat fstat;
packet_function_t receive_packet; packet_function_t receive_packet;
send_peer_t peer; send_peer_t peer;
@ -773,7 +768,7 @@ FlowSource_t *fs;
struct sigaction act; struct sigaction act;
int family, bufflen; int family, bufflen;
time_t twin, t_start; time_t twin, t_start;
int sock, synctime, do_daemonize, expire, report_sequence, do_xstat; int sock, synctime, do_daemonize, expire, spec_time_extension, report_sequence, do_xstat;
int subdir_index, sampling_rate, compress; int subdir_index, sampling_rate, compress;
int c; int c;
#ifdef PCAP #ifdef PCAP
@ -799,6 +794,8 @@ char *pcap_file;
twin = TIME_WINDOW; twin = TIME_WINDOW;
datadir = NULL; datadir = NULL;
subdir_index = 0; subdir_index = 0;
time_extension = "%Y%m%d%H%M";
spec_time_extension = 0;
expire = 0; expire = 0;
sampling_rate = 1; sampling_rate = 1;
compress = NOT_COMPRESSED; compress = NOT_COMPRESSED;
@ -810,7 +807,7 @@ char *pcap_file;
extension_tags = DefaultExtensions; extension_tags = DefaultExtensions;
dynsrcdir = NULL; dynsrcdir = NULL;
while ((c = getopt(argc, argv, "46ef:whEVI:DB:b:jl:J:M:n:p:P:R:S:s:T:t:x:Xru:g:z")) != EOF) { while ((c = getopt(argc, argv, "46ef:whEVI:DB:b:jl:J:M:n:p:P:R:S:s:T:t:x:Xru:g:zZ")) != EOF) {
switch (c) { switch (c) {
case 'h': case 'h':
usage(argv[0]); usage(argv[0]);
@ -988,6 +985,10 @@ char *pcap_file;
} }
compress = LZO_COMPRESSED; compress = LZO_COMPRESSED;
break; break;
case 'Z':
time_extension = "%Y%m%d%H%M%z";
spec_time_extension = 1;
break;
case '4': case '4':
if ( family == AF_UNSPEC ) if ( family == AF_UNSPEC )
family = AF_INET; family = AF_INET;
@ -1028,6 +1029,11 @@ char *pcap_file;
exit(255); exit(255);
} }
if ( expire && spec_time_extension ) {
fprintf(stderr, "ERROR, -Z timezone extension breaks expire -e\n");
exit(255);
}
InitExtensionMaps(NO_EXTENSION_LIST); InitExtensionMaps(NO_EXTENSION_LIST);
SetupExtensionDescriptors(strdup(extension_tags)); SetupExtensionDescriptors(strdup(extension_tags));
@ -1219,7 +1225,8 @@ char *pcap_file;
sigaction(SIGCHLD, &act, NULL); sigaction(SIGCHLD, &act, NULL);
LogInfo("Startup."); LogInfo("Startup.");
run(receive_packet, sock, peer, twin, t_start, report_sequence, subdir_index, compress, do_xstat); run(receive_packet, sock, peer, twin, t_start, report_sequence, subdir_index,
time_extension, compress, do_xstat);
close(sock); close(sock);
kill_launcher(launcher_pid); kill_launcher(launcher_pid);

View File

@ -1,4 +1,5 @@
/* /*
* Copyright (c) 2016, Peter Haag
* Copyright (c) 2014, Peter Haag * Copyright (c) 2014, Peter Haag
* Copyright (c) 2009, Peter Haag * Copyright (c) 2009, Peter Haag
* Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung * Copyright (c) 2004-2008, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
@ -28,12 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* $Author: haag $ * Author: peter
*
* $Id: sfcapd.c 69 2010-09-09 07:17:43Z haag $
*
* $LastChangedRevision: 69 $
*
* *
*/ */
@ -129,7 +125,8 @@ static void daemonize(void);
static void SetPriv(char *userid, char *groupid ); static void SetPriv(char *userid, char *groupid );
static void run(packet_function_t receive_packet, int socket, send_peer_t peer, time_t twin, time_t t_begin, int report_seq, char *datadir, int use_subdirs, int compress, int do_xstat); static void run(packet_function_t receive_packet, int socket, send_peer_t peer,
time_t twin, time_t t_begin, int report_seq, int use_subdirs, char *time_extension, int compress, int do_xstat);
/* Functions */ /* Functions */
static void usage(char *name) { static void usage(char *name) {
@ -159,6 +156,7 @@ static void usage(char *name) {
"-4\t\tListen on IPv4 (default).\n" "-4\t\tListen on IPv4 (default).\n"
"-6\t\tListen on IPv6.\n" "-6\t\tListen on IPv6.\n"
"-V\t\tPrint version and exit.\n" "-V\t\tPrint version and exit.\n"
"-Z\t\tAdd timezone offset to filenamet.\n"
, name); , name);
} // End of usage } // End of usage
@ -334,7 +332,8 @@ int err;
#include "nffile_inline.c" #include "nffile_inline.c"
#include "collector_inline.c" #include "collector_inline.c"
static void run(packet_function_t receive_packet, int socket, send_peer_t peer, time_t twin, time_t t_begin, int report_seq, char *datadir, int use_subdirs, int compress, int do_xstat) { static void run(packet_function_t receive_packet, int socket, send_peer_t peer,
time_t twin, time_t t_begin, int report_seq, int use_subdirs, char *time_extension, int compress, int do_xstat) {
FlowSource_t *fs; FlowSource_t *fs;
struct sockaddr_storage sf_sender; struct sockaddr_storage sf_sender;
socklen_t sf_sender_size = sizeof(sf_sender); socklen_t sf_sender_size = sizeof(sf_sender);
@ -437,9 +436,10 @@ srecord_t *commbuff;
if ( ((t_now - t_start) >= twin) || done ) { if ( ((t_now - t_start) >= twin) || done ) {
char subfilename[64]; char subfilename[64];
struct tm *now; struct tm *now;
char *subdir; char *subdir, fmt[64];
alarm(0); alarm(0);
now = localtime(&t_start); now = localtime(&t_start);
strftime(fmt, sizeof fmt, time_extension, now);
// prepare sub dir hierarchy // prepare sub dir hierarchy
if ( use_subdirs ) { if ( use_subdirs ) {
@ -450,16 +450,13 @@ srecord_t *commbuff;
// failed to generate subdir path - put flows into base directory // failed to generate subdir path - put flows into base directory
subdir = NULL; subdir = NULL;
snprintf(subfilename, 63, "nfcapd.%i%02i%02i%02i%02i", snprintf(subfilename, 63, "nfcapd.%s", fmt);
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min);
} else { } else {
snprintf(subfilename, 63, "%s/nfcapd.%i%02i%02i%02i%02i", subdir, snprintf(subfilename, 63, "%s/nfcapd.%s", subdir, fmt);
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min);
} }
} else { } else {
subdir = NULL; subdir = NULL;
snprintf(subfilename, 63, "nfcapd.%i%02i%02i%02i%02i", snprintf(subfilename, 63, "nfcapd.%s", fmt);
now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, now->tm_hour, now->tm_min);
} }
subfilename[63] = '\0'; subfilename[63] = '\0';
@ -675,7 +672,7 @@ int main(int argc, char **argv) {
char *bindhost, *filter, *datadir, pidstr[32], *launch_process; char *bindhost, *filter, *datadir, pidstr[32], *launch_process;
char *userid, *groupid, *checkptr, *listenport, *mcastgroup, *extension_tags; char *userid, *groupid, *checkptr, *listenport, *mcastgroup, *extension_tags;
char *Ident, *pcap_file, pidfile[MAXPATHLEN]; char *Ident, *pcap_file, *time_extension, pidfile[MAXPATHLEN];
struct stat fstat; struct stat fstat;
srecord_t *commbuff; srecord_t *commbuff;
packet_function_t receive_packet; packet_function_t receive_packet;
@ -684,7 +681,7 @@ FlowSource_t *fs;
struct sigaction act; struct sigaction act;
int family, bufflen; int family, bufflen;
time_t twin, t_start; time_t twin, t_start;
int sock, err, synctime, do_daemonize, expire, report_sequence, do_xstat; int sock, err, synctime, do_daemonize, expire, spec_time_extension, report_sequence, do_xstat;
int subdir_index, compress; int subdir_index, compress;
int c; int c;
@ -705,7 +702,9 @@ int c;
twin = TIME_WINDOW; twin = TIME_WINDOW;
datadir = NULL; datadir = NULL;
subdir_index = 0; subdir_index = 0;
time_extension = "%Y%m%d%H%M";
expire = 0; expire = 0;
spec_time_extension = 0;
compress = NOT_COMPRESSED; compress = NOT_COMPRESSED;
do_xstat = 0; do_xstat = 0;
memset((void *)&peer, 0, sizeof(send_peer_t)); memset((void *)&peer, 0, sizeof(send_peer_t));
@ -715,7 +714,7 @@ int c;
extension_tags = DefaultExtensions; extension_tags = DefaultExtensions;
pcap_file = NULL; pcap_file = NULL;
while ((c = getopt(argc, argv, "46ewhEVI:DB:b:f:jl:n:p:J:P:R:S:T:t:x:ru:g:z")) != EOF) { while ((c = getopt(argc, argv, "46ewhEVI:DB:b:f:jl:n:p:J:P:R:S:T:t:x:ru:g:zZ")) != EOF) {
switch (c) { switch (c) {
case 'h': case 'h':
usage(argv[0]); usage(argv[0]);
@ -860,6 +859,10 @@ int c;
case 'x': case 'x':
launch_process = optarg; launch_process = optarg;
break; break;
case 'Z':
time_extension = "%Y%m%d%H%M%z";
spec_time_extension = 1;
break;
case '4': case '4':
if ( family == AF_UNSPEC ) if ( family == AF_UNSPEC )
family = AF_INET; family = AF_INET;
@ -882,6 +885,11 @@ int c;
} }
} }
if ( expire && spec_time_extension ) {
fprintf(stderr, "ERROR, -Z timezone extension breaks expire -e\n");
exit(255);
}
InitExtensionMaps(NO_EXTENSION_LIST); InitExtensionMaps(NO_EXTENSION_LIST);
SetupExtensionDescriptors(strdup(extension_tags)); SetupExtensionDescriptors(strdup(extension_tags));
@ -1081,7 +1089,8 @@ int c;
sigaction(SIGCHLD, &act, NULL); sigaction(SIGCHLD, &act, NULL);
syslog(LOG_INFO, "Startup."); syslog(LOG_INFO, "Startup.");
run(receive_packet, sock, peer, twin, t_start, report_sequence, datadir, subdir_index, compress, do_xstat); run(receive_packet, sock, peer, twin, t_start, report_sequence, subdir_index,
time_extension, compress, do_xstat);
close(sock); close(sock);
kill_launcher(launcher_pid); kill_launcher(launcher_pid);