summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.c92
-rw-r--r--src/args.h2
-rw-r--r--src/assert.c2
-rw-r--r--src/bpft.c2
-rw-r--r--src/bpft.h2
-rw-r--r--src/daemon.c2
-rw-r--r--src/daemon.h2
-rw-r--r--src/dnscap.1.in2
-rw-r--r--src/dnscap.c2
-rw-r--r--src/dnscap.h2
-rw-r--r--src/dnscap_common.h2
-rw-r--r--src/dump_cbor.c2
-rw-r--r--src/dump_cbor.h2
-rw-r--r--src/dump_cds.c2
-rw-r--r--src/dump_cds.h2
-rw-r--r--src/dump_dns.c2
-rw-r--r--src/dump_dns.h2
-rw-r--r--src/dumper.c6
-rw-r--r--src/dumper.h2
-rw-r--r--src/endian_compat.h2
-rw-r--r--src/endpoint.c2
-rw-r--r--src/endpoint.h2
-rw-r--r--src/hashtbl.c2
-rw-r--r--src/hashtbl.h2
-rw-r--r--src/iaddr.c2
-rw-r--r--src/iaddr.h2
-rw-r--r--src/log.c2
-rw-r--r--src/log.h2
-rw-r--r--src/memzero.c2
-rw-r--r--src/memzero.h2
-rw-r--r--src/network.c2
-rw-r--r--src/network.h2
-rw-r--r--src/options.c2
-rw-r--r--src/options.h2
-rw-r--r--src/pcaps.c2
-rw-r--r--src/pcaps.h2
-rw-r--r--src/sig.c2
-rw-r--r--src/sig.h2
-rw-r--r--src/tcpreasm.c4
-rw-r--r--src/tcpreasm.h2
-rw-r--r--src/tcpstate.c43
-rw-r--r--src/tcpstate.h2
42 files changed, 110 insertions, 111 deletions
diff --git a/src/args.c b/src/args.c
index 79bb43b..d4b1c0d 100644
--- a/src/args.c
+++ b/src/args.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -564,71 +564,71 @@ void parse_args(int argc, char* argv[])
char* fn = strdup(optarg);
char* t;
char sn[256];
- struct plugin* p = calloc(1, sizeof(*p));
- assert(p != NULL);
- INIT_LINK(p, link);
- t = strrchr(fn, '/');
- p->name = strdup(t ? t + 1 : fn);
- if ((t = strstr(p->name, ".so")))
+ struct plugin* pl = calloc(1, sizeof(*pl));
+ assert(pl != NULL);
+ INIT_LINK(pl, link);
+ t = strrchr(fn, '/');
+ pl->name = strdup(t ? t + 1 : fn);
+ if ((t = strstr(pl->name, ".so")))
*t = 0;
- p->handle = dlopen(fn, RTLD_NOW);
- if (!p->handle) {
+ pl->handle = dlopen(fn, RTLD_NOW);
+ if (!pl->handle) {
logerr("%s: %s", fn, dlerror());
exit(1);
}
- snprintf(sn, sizeof(sn), "%s_type", p->name);
- p->type = dlsym(p->handle, sn);
- if (p->type) {
- p->pt = (*p->type)();
- switch (p->pt) {
+ snprintf(sn, sizeof(sn), "%s_type", pl->name);
+ pl->type = dlsym(pl->handle, sn);
+ if (pl->type) {
+ pl->pt = (*pl->type)();
+ switch (pl->pt) {
case plugin_output:
case plugin_filter:
break;
default:
- logerr("invalid plugin type for plugin '%s'", p->name);
+ logerr("invalid plugin type for plugin '%s'", pl->name);
exit(1);
}
} else {
- p->pt = plugin_output;
+ pl->pt = plugin_output;
}
- snprintf(sn, sizeof(sn), "%s_start", p->name);
- p->start = dlsym(p->handle, sn);
- snprintf(sn, sizeof(sn), "%s_stop", p->name);
- p->stop = dlsym(p->handle, sn);
- snprintf(sn, sizeof(sn), "%s_open", p->name);
- p->open = dlsym(p->handle, sn);
- snprintf(sn, sizeof(sn), "%s_close", p->name);
- p->close = dlsym(p->handle, sn);
- snprintf(sn, sizeof(sn), "%s_output", p->name);
- p->output = dlsym(p->handle, sn);
- if (p->pt == plugin_output && !p->output) {
+ snprintf(sn, sizeof(sn), "%s_start", pl->name);
+ pl->start = dlsym(pl->handle, sn);
+ snprintf(sn, sizeof(sn), "%s_stop", pl->name);
+ pl->stop = dlsym(pl->handle, sn);
+ snprintf(sn, sizeof(sn), "%s_open", pl->name);
+ pl->open = dlsym(pl->handle, sn);
+ snprintf(sn, sizeof(sn), "%s_close", pl->name);
+ pl->close = dlsym(pl->handle, sn);
+ snprintf(sn, sizeof(sn), "%s_output", pl->name);
+ pl->output = dlsym(pl->handle, sn);
+ if (pl->pt == plugin_output && !pl->output) {
logerr("%s", dlerror());
exit(1);
}
- snprintf(sn, sizeof(sn), "%s_filter", p->name);
- p->filter = dlsym(p->handle, sn);
- if (p->pt == plugin_filter && !p->filter) {
+ snprintf(sn, sizeof(sn), "%s_filter", pl->name);
+ pl->filter = dlsym(pl->handle, sn);
+ if (pl->pt == plugin_filter && !pl->filter) {
logerr("%s", dlerror());
exit(1);
}
- snprintf(sn, sizeof(sn), "%s_usage", p->name);
- p->usage = dlsym(p->handle, sn);
- snprintf(sn, sizeof(sn), "%s_extension", p->name);
- p->extension = dlsym(p->handle, sn);
- if (p->extension) {
- (*p->extension)(DNSCAP_EXT_IS_RESPONDER, (void*)is_responder);
- (*p->extension)(DNSCAP_EXT_IA_STR, (void*)_ia_str);
- (*p->extension)(DNSCAP_EXT_TCPSTATE_GETCURR, (void*)_tcpstate_getcurr);
- (*p->extension)(DNSCAP_EXT_TCPSTATE_RESET, (void*)_tcpstate_reset);
- (*p->extension)(DNSCAP_EXT_SET_IADDR, (void*)set_iaddr);
+ snprintf(sn, sizeof(sn), "%s_usage", pl->name);
+ pl->usage = dlsym(pl->handle, sn);
+ snprintf(sn, sizeof(sn), "%s_extension", pl->name);
+ pl->extension = dlsym(pl->handle, sn);
+ if (pl->extension) {
+ (*pl->extension)(DNSCAP_EXT_IS_RESPONDER, (void*)is_responder);
+ (*pl->extension)(DNSCAP_EXT_IA_STR, (void*)_ia_str);
+ (*pl->extension)(DNSCAP_EXT_TCPSTATE_GETCURR, (void*)_tcpstate_getcurr);
+ (*pl->extension)(DNSCAP_EXT_TCPSTATE_RESET, (void*)_tcpstate_reset);
+ (*pl->extension)(DNSCAP_EXT_SET_IADDR, (void*)set_iaddr);
}
- snprintf(sn, sizeof(sn), "%s_getopt", p->name);
- p->getopt = dlsym(p->handle, sn);
- if (p->getopt)
- (*p->getopt)(&argc, &argv);
- APPEND(plugins, p, link);
+ snprintf(sn, sizeof(sn), "%s_getopt", pl->name);
+ pl->getopt = dlsym(pl->handle, sn);
+ if (pl->getopt)
+ (*pl->getopt)(&argc, &argv);
+ APPEND(plugins, pl, link);
if (dumptrace)
- fprintf(stderr, "Plugin '%s' loaded\n", p->name);
+ fprintf(stderr, "Plugin '%s' loaded\n", pl->name);
free(fn);
} break;
case 'U':
diff --git a/src/args.h b/src/args.h
index cf9eaff..3d34784 100644
--- a/src/args.h
+++ b/src/args.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/assert.c b/src/assert.c
index 2cb18fd..4c86762 100644
--- a/src/assert.c
+++ b/src/assert.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/bpft.c b/src/bpft.c
index f0e506a..6ee5862 100644
--- a/src/bpft.c
+++ b/src/bpft.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/bpft.h b/src/bpft.h
index 47b7ff3..fd0ca9f 100644
--- a/src/bpft.h
+++ b/src/bpft.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/daemon.c b/src/daemon.c
index 596b863..83e614c 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/daemon.h b/src/daemon.h
index aa80f5f..e120eaf 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dnscap.1.in b/src/dnscap.1.in
index 58c4b90..55289cb 100644
--- a/src/dnscap.1.in
+++ b/src/dnscap.1.in
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2016-2022, OARC, Inc.
+.\" Copyright (c) 2016-2023, OARC, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
diff --git a/src/dnscap.c b/src/dnscap.c
index 82b7c96..a3e2ba1 100644
--- a/src/dnscap.c
+++ b/src/dnscap.c
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dnscap.h b/src/dnscap.h
index d3a519c..ebdde87 100644
--- a/src/dnscap.h
+++ b/src/dnscap.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dnscap_common.h b/src/dnscap_common.h
index f39758f..fa869cd 100644
--- a/src/dnscap_common.h
+++ b/src/dnscap_common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dump_cbor.c b/src/dump_cbor.c
index da0b532..89cf5be 100644
--- a/src/dump_cbor.c
+++ b/src/dump_cbor.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dump_cbor.h b/src/dump_cbor.h
index be3cf7f..a032cd8 100644
--- a/src/dump_cbor.h
+++ b/src/dump_cbor.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dump_cds.c b/src/dump_cds.c
index f2b7634..3f680b5 100644
--- a/src/dump_cds.c
+++ b/src/dump_cds.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dump_cds.h b/src/dump_cds.h
index 95b987e..3eb2818 100644
--- a/src/dump_cds.h
+++ b/src/dump_cds.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dump_dns.c b/src/dump_dns.c
index 6e50736..121a97e 100644
--- a/src/dump_dns.c
+++ b/src/dump_dns.c
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dump_dns.h b/src/dump_dns.h
index ddd58b6..e3394f3 100644
--- a/src/dump_dns.h
+++ b/src/dump_dns.h
@@ -4,7 +4,7 @@
*/
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/dumper.c b/src/dumper.c
index 56f0c70..95d92a5 100644
--- a/src/dumper.c
+++ b/src/dumper.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -241,8 +241,6 @@ int dumper_close(my_bpftimeval ts)
dumper = FALSE;
}
} else if (options.dump_format == cbor) {
- int ret;
-
if (dump_type == to_stdout) {
ret = dump_cbor(stdout);
@@ -265,8 +263,6 @@ int dumper_close(my_bpftimeval ts)
}
}
} else if (options.dump_format == cds) {
- int ret;
-
if (dump_type == to_stdout) {
ret = dump_cds(stdout);
diff --git a/src/dumper.h b/src/dumper.h
index b9ddd92..cec2ddd 100644
--- a/src/dumper.h
+++ b/src/dumper.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/endian_compat.h b/src/endian_compat.h
index 27f53d1..b7b89c1 100644
--- a/src/endian_compat.h
+++ b/src/endian_compat.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/endpoint.c b/src/endpoint.c
index 78f4691..a2b848f 100644
--- a/src/endpoint.c
+++ b/src/endpoint.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/endpoint.h b/src/endpoint.h
index 19762a2..2ad2cf3 100644
--- a/src/endpoint.h
+++ b/src/endpoint.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/hashtbl.c b/src/hashtbl.c
index 48671d6..c497b78 100644
--- a/src/hashtbl.c
+++ b/src/hashtbl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/hashtbl.h b/src/hashtbl.h
index 4aad3b4..6243b09 100644
--- a/src/hashtbl.h
+++ b/src/hashtbl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/iaddr.c b/src/iaddr.c
index 330df8e..43f0b8f 100644
--- a/src/iaddr.c
+++ b/src/iaddr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/iaddr.h b/src/iaddr.h
index 8921a77..ea27049 100644
--- a/src/iaddr.h
+++ b/src/iaddr.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/log.c b/src/log.c
index e4283ca..4cd5fa7 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/log.h b/src/log.h
index 460db39..be93ddd 100644
--- a/src/log.h
+++ b/src/log.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/memzero.c b/src/memzero.c
index 449f528..6b983a4 100644
--- a/src/memzero.c
+++ b/src/memzero.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/memzero.h b/src/memzero.h
index f835b27..02ede71 100644
--- a/src/memzero.h
+++ b/src/memzero.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/network.c b/src/network.c
index 6e969c8..1042f80 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/network.h b/src/network.h
index 4cb4502..0d1bb5f 100644
--- a/src/network.h
+++ b/src/network.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/options.c b/src/options.c
index 8d03c26..ce0c047 100644
--- a/src/options.c
+++ b/src/options.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/options.h b/src/options.h
index 99acb8d..ce601e1 100644
--- a/src/options.h
+++ b/src/options.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/pcaps.c b/src/pcaps.c
index 69855ea..f89b9bb 100644
--- a/src/pcaps.c
+++ b/src/pcaps.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/pcaps.h b/src/pcaps.h
index 0f348bd..554b8b8 100644
--- a/src/pcaps.h
+++ b/src/pcaps.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/sig.c b/src/sig.c
index ab14cde..de01508 100644
--- a/src/sig.c
+++ b/src/sig.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/sig.h b/src/sig.h
index 768f6f7..f93d1f4 100644
--- a/src/sig.h
+++ b/src/sig.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2022, OARC, Inc.
+ * Copyright (c) 2016-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/tcpreasm.c b/src/tcpreasm.c
index 9eb056e..e3df539 100644
--- a/src/tcpreasm.c
+++ b/src/tcpreasm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022, OARC, Inc.
+ * Copyright (c) 2018-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -356,7 +356,7 @@ int pcap_handle_tcp_segment(u_char* segment, int len, uint32_t seq, tcpstate_ptr
if (!tcpstate->segbuf[s])
continue;
/* TODO: seq >= 0 */
- if (tcpstate->segbuf[s]->seq - seq > 0 && tcpstate->segbuf[s]->seq - seq < dnslen) {
+ if (tcpstate->segbuf[s]->seq > seq && tcpstate->segbuf[s]->seq - seq < dnslen) {
tcp_segbuf_t* segbuf = tcpstate->segbuf[s];
tcpstate->segbuf[s] = NULL;
dfprintf(1, "pcap_handle_tcp_segment: %s", "message reassembled");
diff --git a/src/tcpreasm.h b/src/tcpreasm.h
index fd920df..37260e0 100644
--- a/src/tcpreasm.h
+++ b/src/tcpreasm.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022, OARC, Inc.
+ * Copyright (c) 2018-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
diff --git a/src/tcpstate.c b/src/tcpstate.c
index 19f5420..fce5ba1 100644
--- a/src/tcpstate.c
+++ b/src/tcpstate.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022, OARC, Inc.
+ * Copyright (c) 2018-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,6 +48,17 @@ tcpstate_ptr tcpstate_find(iaddr from, iaddr to, unsigned sport, unsigned dport,
static time_t next_gc = 0;
tcpstate_ptr tcpstate;
+#ifndef __clang_analyzer__
+ /* disabled during scan-build due to false-positives */
+ if (t >= next_gc || tcpstate_count > MAX_TCP_IDLE_COUNT) {
+ /* garbage collect stale states */
+ while ((tcpstate = TAIL(tcpstates)) && tcpstate->last_use < t - MAX_TCP_IDLE_TIME) {
+ tcpstate_discard(tcpstate, "gc stale");
+ }
+ next_gc = t + TCP_GC_TIME;
+ }
+#endif
+
for (tcpstate = HEAD(tcpstates);
tcpstate != NULL;
tcpstate = NEXT(tcpstate, link)) {
@@ -63,22 +74,11 @@ tcpstate_ptr tcpstate_find(iaddr from, iaddr to, unsigned sport, unsigned dport,
}
}
- if (t >= next_gc || tcpstate_count > MAX_TCP_IDLE_COUNT) {
- /* garbage collect stale states */
- time_t min_last_use = t - MAX_TCP_IDLE_TIME;
- while ((tcpstate = TAIL(tcpstates)) && tcpstate->last_use < min_last_use) {
- UNLINK(tcpstates, tcpstate, link);
- tcpstate_count--;
- }
- next_gc = t + TCP_GC_TIME;
- }
-
return tcpstate;
}
tcpstate_ptr tcpstate_new(iaddr from, iaddr to, unsigned sport, unsigned dport)
{
-
tcpstate_ptr tcpstate = calloc(1, sizeof *tcpstate);
if (tcpstate == NULL) {
/* Out of memory; recycle the least recently used */
@@ -86,6 +86,7 @@ tcpstate_ptr tcpstate_new(iaddr from, iaddr to, unsigned sport, unsigned dport)
"discarding some TCP state early");
tcpstate = TAIL(tcpstates);
assert(tcpstate != NULL);
+ UNLINK(tcpstates, tcpstate, link);
} else {
tcpstate_count++;
}
@@ -98,6 +99,13 @@ tcpstate_ptr tcpstate_new(iaddr from, iaddr to, unsigned sport, unsigned dport)
return tcpstate;
}
+tcpstate_ptr _curr_tcpstate = 0;
+
+tcpstate_ptr tcpstate_getcurr(void)
+{
+ return _curr_tcpstate;
+}
+
/* Discard this packet. If it's part of TCP stream, all subsequent pkts on
* the same tcp stream will also be discarded. */
void tcpstate_discard(tcpstate_ptr tcpstate, const char* msg)
@@ -110,18 +118,13 @@ void tcpstate_discard(tcpstate_ptr tcpstate, const char* msg)
tcpreasm_free(tcpstate->reasm);
}
free(tcpstate);
+ if (_curr_tcpstate == tcpstate) {
+ _curr_tcpstate = 0;
+ }
tcpstate_count--;
- return;
}
}
-tcpstate_ptr _curr_tcpstate = 0;
-
-tcpstate_ptr tcpstate_getcurr(void)
-{
- return _curr_tcpstate;
-}
-
void tcpstate_reset(tcpstate_ptr tcpstate, const char* msg)
{
if (options.allow_reset_tcpstate && tcpstate) {
diff --git a/src/tcpstate.h b/src/tcpstate.h
index 9a82b2d..1191f9d 100644
--- a/src/tcpstate.h
+++ b/src/tcpstate.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2022, OARC, Inc.
+ * Copyright (c) 2018-2023, OARC, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without