diff --git a/sim/sim.py b/sim/sim.py index 661ecb3..e8248ac 100755 --- a/sim/sim.py +++ b/sim/sim.py @@ -1,24 +1,29 @@ #!/usr/bin/env python3 -import sys import socket import os from time import sleep +import argparse -DEST = ("127.0.0.1", 4200) -FNAME = 1 +DEST = "127.0.0.1" -def main(fname): - with open(os.path.join(os.path.dirname(__file__), fname), "r") as f: +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("file") + parser.add_argument("port", type=int, default=4200) + parser.add_argument("rate", type=float, default=1) + args = parser.parse_args() + + with open(os.path.join(os.path.dirname(args.file), args.file), "r") as f: lines = [line.rstrip().encode("UTF-8") for line in f] sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) while True: for line in lines: - sock.sendto(line, DEST) - sleep(1) + sock.sendto(line, (DEST, args.port)) + sleep(args.rate) if __name__ == '__main__': - main(sys.argv[FNAME]) + main() diff --git a/src/Dockerfile b/src/Dockerfile index b3b021a..b070e18 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,6 +1,8 @@ FROM scratch ADD csyslog /csyslog +ADD GeoLiteCity.dat / +ADD GeoLiteCityv6.dat / STOPSIGNAL 9 diff --git a/src/geo.c b/src/geo.c index c8c2483..e25519d 100644 --- a/src/geo.c +++ b/src/geo.c @@ -36,7 +36,6 @@ const char* geo_country_name(GeoIPRecord* rec) { } #ifdef TEST - static const char * _mk_NA( const char * p ){ return p ? p : "N/A"; } @@ -44,7 +43,7 @@ static const char * _mk_NA( const char * p ){ int main(int argc, char** argv) { geo_init(); char* host = "24.4.129.164"; - char* host6 = "2601:647:4701:733:5bf:f3c2:f2b2:9c1f"; + // char* host6 = "2601:647:4701:733:5bf:f3c2:f2b2:9c1f"; GeoIPRecord *gir = GeoIP_record_by_name(gi, (const char *) host); // GeoIP_record_by_name_v6 // GeoIPRecord *gir = GeoIP_record_by_name_v6(gi, (const char *) host6); @@ -64,5 +63,4 @@ int main(int argc, char** argv) { geo_close(); } - #endif diff --git a/src/main.c b/src/main.c index 6d5023d..e514b92 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ int main(int argc, char** argv) { char* portend; unsigned int portl; portl = strtol(argv[1], &portend, 10); - if (portend == NULL) { + if (portend == NULL || portend == argv[1]) { fprintf(stderr, "usage: %s \n", argv[0]); exit(1); } diff --git a/src/server.c b/src/server.c index 1e80b64..d30276f 100644 --- a/src/server.c +++ b/src/server.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -40,7 +39,6 @@ void sig_handler(int signum) { int submit_events(char* message) { - // Send it if(put_events(message, "http://192.168.1.120:8298") == 0) { return 0; } else { @@ -51,6 +49,10 @@ int submit_events(char* message) { char* collect_buffer(int max_size, int* howmany) { + /* + Pop up to $howmany items from the message buffer and allocate a buffer of at most $max_size bytes containing them. + Returns a char pointer to the buffer + */ char header[72]; // sprintf(header, "{\"index\": {\"_index\": \"firewall-test\", \"_type\": \"event\"}}\n"); sprintf(header, "{\"index\": {\"_index\": \"firewall-%04d.%02d.%02d\", \"_type\": \"event\"}}\n", @@ -89,7 +91,9 @@ char* collect_buffer(int max_size, int* howmany) { void* buffer_watch() { - /*flush the buffer when larger than 10 messages or older than 5 seconds*/ + /* + Threaded task that flushes the buffer when it is larger than 10 messages or older than 5 seconds + */ time_t last_flush = time(NULL); char* buffer = NULL; while(running) { @@ -125,6 +129,9 @@ void* buffer_watch() { void start_bufwatch() { + /* + Start the bufwatch thread + */ if (pthread_mutex_init(&buflock, NULL) != 0) { printf("\n mutex init failed\n"); exit(1); @@ -262,5 +269,5 @@ int run_server(int port) { bufwatch_cleanup(); buff_freeall(); geo_close(); - return 1; + return 0; }