From 22a29c0010e8ecee203d610e2477150004c74cf6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 Feb 2023 09:48:28 +0100 Subject: Merging upstream version 2.1.1. Signed-off-by: Daniel Baumann --- LICENSE | 2 +- configure | 20 ++++---- configure.ac | 4 +- plugins/anonaes128/anonaes128.c | 14 ++++-- plugins/anonmask/anonmask.c | 14 ++++-- plugins/cryptopan/cryptopan.c | 14 ++++-- plugins/cryptopant/cryptopant.c | 14 ++++-- plugins/eventlog/eventlog.c | 2 +- plugins/ipcrypt/ipcrypt.c | 14 ++++-- plugins/pcapdump/pcapdump.c | 2 +- plugins/royparse/royparse.c | 2 +- plugins/rssm/dnscap-rssm-rssac002 | 2 +- plugins/rssm/dnscap-rssm-rssac002.1.in | 2 +- plugins/rssm/rssm.c | 5 +- plugins/template/template.c | 2 +- plugins/txtout/txtout.c | 2 +- src/args.c | 92 +++++++++++++++++----------------- src/args.h | 2 +- src/assert.c | 2 +- src/bpft.c | 2 +- src/bpft.h | 2 +- src/daemon.c | 2 +- src/daemon.h | 2 +- src/dnscap.1.in | 2 +- src/dnscap.c | 2 +- src/dnscap.h | 2 +- src/dnscap_common.h | 2 +- src/dump_cbor.c | 2 +- src/dump_cbor.h | 2 +- src/dump_cds.c | 2 +- src/dump_cds.h | 2 +- src/dump_dns.c | 2 +- src/dump_dns.h | 2 +- src/dumper.c | 6 +-- src/dumper.h | 2 +- src/endian_compat.h | 2 +- src/endpoint.c | 2 +- src/endpoint.h | 2 +- src/hashtbl.c | 2 +- src/hashtbl.h | 2 +- src/iaddr.c | 2 +- src/iaddr.h | 2 +- src/log.c | 2 +- src/log.h | 2 +- src/memzero.c | 2 +- src/memzero.h | 2 +- src/network.c | 2 +- src/network.h | 2 +- src/options.c | 2 +- src/options.h | 2 +- src/pcaps.c | 2 +- src/pcaps.h | 2 +- src/sig.c | 2 +- src/sig.h | 2 +- src/tcpreasm.c | 4 +- src/tcpreasm.h | 2 +- src/tcpstate.c | 43 ++++++++-------- src/tcpstate.h | 2 +- 58 files changed, 177 insertions(+), 159 deletions(-) diff --git a/LICENSE b/LICENSE index e5b6b49..f0cf750 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ DNSCAP -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/configure b/configure index a2637b1..b03e668 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for dnscap 2.1.0. +# Generated by GNU Autoconf 2.69 for dnscap 2.1.1. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='dnscap' PACKAGE_TARNAME='dnscap' -PACKAGE_VERSION='2.1.0' -PACKAGE_STRING='dnscap 2.1.0' +PACKAGE_VERSION='2.1.1' +PACKAGE_STRING='dnscap 2.1.1' PACKAGE_BUGREPORT='dnscap-users@dns-oarc.net' PACKAGE_URL='https://github.com/DNS-OARC/dnscap/issues' @@ -1353,7 +1353,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures dnscap 2.1.0 to adapt to many kinds of systems. +\`configure' configures dnscap 2.1.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1424,7 +1424,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of dnscap 2.1.0:";; + short | recursive ) echo "Configuration of dnscap 2.1.1:";; esac cat <<\_ACEOF @@ -1556,7 +1556,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -dnscap configure 2.1.0 +dnscap configure 2.1.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1979,7 +1979,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by dnscap $as_me 2.1.0, which was +It was created by dnscap $as_me 2.1.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2842,7 +2842,7 @@ fi # Define the identity of the package. PACKAGE='dnscap' - VERSION='2.1.0' + VERSION='2.1.1' cat >>confdefs.h <<_ACEOF @@ -15015,7 +15015,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by dnscap $as_me 2.1.0, which was +This file was extended by dnscap $as_me 2.1.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -15082,7 +15082,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -dnscap config.status 2.1.0 +dnscap config.status 2.1.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index e3000a7..b3c5657 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2022, OARC, Inc. +# Copyright (c) 2016-2023, OARC, Inc. # Copyright (c) 2007, The Measurement Factory, Inc. # Copyright (c) 2007, Internet Systems Consortium, Inc. # All rights reserved. @@ -33,7 +33,7 @@ # POSSIBILITY OF SUCH DAMAGE. AC_PREREQ(2.61) -AC_INIT([dnscap], [2.1.0], [dnscap-users@dns-oarc.net], [dnscap], [https://github.com/DNS-OARC/dnscap/issues]) +AC_INIT([dnscap], [2.1.1], [dnscap-users@dns-oarc.net], [dnscap], [https://github.com/DNS-OARC/dnscap/issues]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_SRCDIR([src/dnscap.c]) AC_CONFIG_HEADER([src/config.h]) diff --git a/plugins/anonaes128/anonaes128.c b/plugins/anonaes128/anonaes128.c index aa9539c..56c8656 100644 --- a/plugins/anonaes128/anonaes128.c +++ b/plugins/anonaes128/anonaes128.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 @@ -246,8 +246,10 @@ int anonaes128_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, for (;;) { if (only_clients && sport == dns_port) { - from = 0; - break; + if (sport != dport) { + from = 0; + break; + } } if (only_servers && sport != dns_port) { from = 0; @@ -292,8 +294,10 @@ int anonaes128_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, for (;;) { if (only_clients && dport == dns_port) { - to = 0; - break; + if (dport != sport) { + to = 0; + break; + } } if (only_servers && dport != dns_port) { to = 0; diff --git a/plugins/anonmask/anonmask.c b/plugins/anonmask/anonmask.c index d6c3d89..444f5df 100644 --- a/plugins/anonmask/anonmask.c +++ b/plugins/anonmask/anonmask.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 @@ -182,8 +182,10 @@ int anonmask_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, un for (;;) { if (only_clients && sport == mask_port) { - from = 0; - break; + if (sport != dport) { + from = 0; + break; + } } if (only_servers && sport != mask_port) { from = 0; @@ -210,8 +212,10 @@ int anonmask_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, un for (;;) { if (only_clients && dport == mask_port) { - to = 0; - break; + if (dport != sport) { + to = 0; + break; + } } if (only_servers && dport != mask_port) { to = 0; diff --git a/plugins/cryptopan/cryptopan.c b/plugins/cryptopan/cryptopan.c index 3b3e973..14f185f 100644 --- a/plugins/cryptopan/cryptopan.c +++ b/plugins/cryptopan/cryptopan.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 @@ -397,8 +397,10 @@ int cryptopan_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, u #ifdef USE_OPENSSL for (;;) { if (only_clients && sport == dns_port) { - from = 0; - break; + if (sport != dport) { + from = 0; + break; + } } if (only_servers && sport != dns_port) { from = 0; @@ -433,8 +435,10 @@ int cryptopan_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, u for (;;) { if (only_clients && dport == dns_port) { - to = 0; - break; + if (dport != sport) { + to = 0; + break; + } } if (only_servers && dport != dns_port) { to = 0; diff --git a/plugins/cryptopant/cryptopant.c b/plugins/cryptopant/cryptopant.c index 2f8aa20..7fca715 100644 --- a/plugins/cryptopant/cryptopant.c +++ b/plugins/cryptopant/cryptopant.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 @@ -187,8 +187,10 @@ int cryptopant_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, #ifdef USE_CRYPTOPANT for (;;) { if (only_clients && sport == dns_port) { - from = 0; - break; + if (sport != dport) { + from = 0; + break; + } } if (only_servers && sport != dns_port) { from = 0; @@ -211,8 +213,10 @@ int cryptopant_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, for (;;) { if (only_clients && dport == dns_port) { - to = 0; - break; + if (dport != sport) { + to = 0; + break; + } } if (only_servers && dport != dns_port) { to = 0; diff --git a/plugins/eventlog/eventlog.c b/plugins/eventlog/eventlog.c index 1854741..7f9cb74 100644 --- a/plugins/eventlog/eventlog.c +++ b/plugins/eventlog/eventlog.c @@ -12,7 +12,7 @@ * Below is the original copyright notice from txtout.c. */ /* - * 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/plugins/ipcrypt/ipcrypt.c b/plugins/ipcrypt/ipcrypt.c index b1494e8..f8908a6 100644 --- a/plugins/ipcrypt/ipcrypt.c +++ b/plugins/ipcrypt/ipcrypt.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 @@ -273,8 +273,10 @@ int ipcrypt_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, uns { for (;;) { if (only_clients && sport == dns_port) { - from = 0; - break; + if (sport != dport) { + from = 0; + break; + } } if (only_servers && sport != dns_port) { from = 0; @@ -309,8 +311,10 @@ int ipcrypt_filter(const char* descr, iaddr* from, iaddr* to, uint8_t proto, uns for (;;) { if (only_clients && dport == dns_port) { - to = 0; - break; + if (dport != sport) { + to = 0; + break; + } } if (only_servers && dport != dns_port) { to = 0; diff --git a/plugins/pcapdump/pcapdump.c b/plugins/pcapdump/pcapdump.c index 60a452f..3af1ccd 100644 --- a/plugins/pcapdump/pcapdump.c +++ b/plugins/pcapdump/pcapdump.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/plugins/royparse/royparse.c b/plugins/royparse/royparse.c index b7e9b87..4deed9a 100644 --- a/plugins/royparse/royparse.c +++ b/plugins/royparse/royparse.c @@ -1,7 +1,7 @@ /* * Author Roy Arends * - * Copyright (c) 2017-2022, OARC, Inc. + * Copyright (c) 2017-2023, OARC, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/plugins/rssm/dnscap-rssm-rssac002 b/plugins/rssm/dnscap-rssm-rssac002 index 30c0b3b..aff45e7 100755 --- a/plugins/rssm/dnscap-rssm-rssac002 +++ b/plugins/rssm/dnscap-rssm-rssac002 @@ -1,6 +1,6 @@ #!/usr/bin/env perl # -# 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/plugins/rssm/dnscap-rssm-rssac002.1.in b/plugins/rssm/dnscap-rssm-rssac002.1.in index 92f3f77..6afce8f 100644 --- a/plugins/rssm/dnscap-rssm-rssac002.1.in +++ b/plugins/rssm/dnscap-rssm-rssac002.1.in @@ -1,4 +1,4 @@ -.\" Copyright (c) 2017-2022, OARC, Inc. +.\" Copyright (c) 2017-2023, OARC, Inc. .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without diff --git a/plugins/rssm/rssm.c b/plugins/rssm/rssm.c index 1847cc0..91cbd93 100644 --- a/plugins/rssm/rssm.c +++ b/plugins/rssm/rssm.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 @@ -566,7 +566,6 @@ int rssm_close(my_bpftimeval ts) struct tm tm; if (dont_fork_on_close) { - struct tm tm; gmtime_r((time_t*)&open_ts.tv_sec, &tm); strftime(sbuf, sizeof(sbuf), "%Y%m%d.%H%M%S", &tm); close_ts = ts; @@ -721,7 +720,7 @@ void rssm_output(const char* descr, iaddr from, iaddr to, uint8_t proto, unsigne counts.dns_tcp_responses_sent_ipv6++; } } - if (ldns_pkt_arcount(pkt)) { + if (ldns_pkt_edns(pkt)) { rcode |= ((uint16_t)ldns_pkt_edns_extended_rcode(pkt) << 4); } counts.rcodes[rcode]++; diff --git a/plugins/template/template.c b/plugins/template/template.c index 567c9c9..bf0a89c 100644 --- a/plugins/template/template.c +++ b/plugins/template/template.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/plugins/txtout/txtout.c b/plugins/txtout/txtout.c index 976d18e..2a22e7a 100644 --- a/plugins/txtout/txtout.c +++ b/plugins/txtout/txtout.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/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 -- cgit v1.2.3