From: Kirill A. Korinsky Subject: net/darkstat: update to 3.0.721 and support of multiple -l To: OpenBSD ports Date: Fri, 15 Aug 2025 14:26:44 +0200 ports@, Stuart had pointed that I sent wrong diff which lost chroot-related changes, and when I had dig how does it happend, I discovered that our net/darkstat is also outdated. Here and updated diff which: - updates it to the last version 3.0.721 which was released 3 years ago; - brings support of multipke -l option. Like before, I had tested it on -current/octeon and it works. Ok? Index: Makefile =================================================================== RCS file: /home/cvs/ports/net/darkstat/Makefile,v diff -u -p -r1.33 Makefile --- Makefile 27 Sep 2023 14:18:03 -0000 1.33 +++ Makefile 15 Aug 2025 12:22:26 -0000 @@ -1,12 +1,10 @@ COMMENT= network statistics gatherer with graphs -PORTROACH= site:https://github.com/emikulic/darkstat/archive/ +GH_ACCOUNT= emikulic +GH_PROJECT= darkstat +GH_TAGNAME= 3.0.721 -DISTNAME= darkstat-3.0.719 CATEGORIES= net www -SITES= ${HOMEPAGE} -EXTRACT_SUFX= .tar.bz2 -REVISION= 3 HOMEPAGE= https://unix4lyfe.org/darkstat/ Index: distinfo =================================================================== RCS file: /home/cvs/ports/net/darkstat/distinfo,v diff -u -p -r1.15 distinfo --- distinfo 25 May 2015 06:01:43 -0000 1.15 +++ distinfo 15 Aug 2025 10:49:17 -0000 @@ -1,2 +1,2 @@ -SHA256 (darkstat-3.0.719.tar.bz2) = rq+QlYX39D3AMqdTKP22IRTlhAWwapKhPA02UyNt7dc= -SIZE (darkstat-3.0.719.tar.bz2) = 117695 +SHA256 (darkstat-3.0.721.tar.gz) = C0BabAESQPV3VZ2E2yJoSmNJslBnw6gA3xJDl4PCVJQ= +SIZE (darkstat-3.0.721.tar.gz) = 104050 Index: patches/patch-acct_c =================================================================== RCS file: patches/patch-acct_c diff -N patches/patch-acct_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-acct_c 15 Aug 2025 10:58:15 -0000 @@ -0,0 +1,69 @@ +Support multiple -l. + +Index: acct.c +--- acct.c.orig ++++ acct.c +@@ -37,8 +37,9 @@ + + uint64_t acct_total_packets = 0, acct_total_bytes = 0; + +-static int using_localnet4 = 0, using_localnet6 = 0; +-static struct addr localnet4, localmask4, localnet6, localmask6; ++static int total_localnets4 = 0, total_localnets6 = 0; ++static struct addr *localnets4 = NULL, *localmasks4 = NULL; ++static struct addr *localnets6 = NULL, *localmasks6 = NULL; + + /* Parse the net/mask specification into two IPs or die trying. */ + void +@@ -120,13 +121,19 @@ acct_init_localnet(const char *spec) + /* Register the correct netmask and calculate the correct net. */ + addr_mask(&localnet, &localmask); + if (localnet.family == IPv6) { +- using_localnet6 = 1; +- localnet6 = localnet; +- localmask6 = localmask; ++ j = total_localnets6 + 1; ++ localnets6 = xrealloc(localnets6, sizeof(*(localnets6)) * j); ++ localmasks6 = xrealloc(localmasks6, sizeof(*(localmasks6)) * j); ++ localnets6[total_localnets6] = localnet; ++ localmasks6[total_localnets6] = localmask; ++ total_localnets6++; + } else { +- using_localnet4 = 1; +- localnet4 = localnet; +- localmask4 = localmask; ++ j = total_localnets4 + 1; ++ localnets4 = xrealloc(localnets4, sizeof(*(localnets4)) * j); ++ localmasks4 = xrealloc(localmasks4, sizeof(*(localmasks4)) * j); ++ localnets4[total_localnets4] = localnet; ++ localmasks4[total_localnets4] = localmask; ++ total_localnets4++; + } + + verbosef("local network address: %s", addr_to_str(&localnet)); +@@ -135,14 +142,19 @@ acct_init_localnet(const char *spec) + + static int addr_is_local(const struct addr * const a, + const struct local_ips *local_ips) { ++ int i; + if (is_localip(a, local_ips)) + return 1; +- if (a->family == IPv4 && using_localnet4) { +- if (addr_inside(a, &localnet4, &localmask4)) +- return 1; +- } else if (a->family == IPv6 && using_localnet6) { +- if (addr_inside(a, &localnet6, &localmask6)) +- return 1; ++ if (a->family == IPv4) { ++ for (i = 0; i < total_localnets4; i++) { ++ if (addr_inside(a, &localnets4[i], &localmasks4[i])) ++ return 1; ++ } ++ } else if (a->family == IPv6) { ++ for (i = 0; i < total_localnets6; i++) { ++ if (addr_inside(a, &localnets6[i], &localmasks6[i])) ++ return 1; ++ } + } + return 0; + } Index: patches/patch-configure_ac =================================================================== RCS file: /home/cvs/ports/net/darkstat/patches/patch-configure_ac,v diff -u -p -r1.5 patch-configure_ac --- patches/patch-configure_ac 21 Mar 2022 13:12:04 -0000 1.5 +++ patches/patch-configure_ac 15 Aug 2025 10:58:50 -0000 @@ -3,7 +3,7 @@ Re-instate the chroot by default code. Index: configure.ac --- configure.ac.orig +++ configure.ac -@@ -6,6 +6,31 @@ AC_CONFIG_HEADER([config.h]) +@@ -5,6 +5,31 @@ AC_CONFIG_HEADERS([config.h]) RULE="------------------------------------------------------------" Index: patches/patch-conv_c =================================================================== RCS file: /home/cvs/ports/net/darkstat/patches/patch-conv_c,v diff -u -p -r1.4 patch-conv_c --- patches/patch-conv_c 21 Mar 2022 13:12:04 -0000 1.4 +++ patches/patch-conv_c 15 Aug 2025 10:59:10 -0000 @@ -22,6 +22,6 @@ Index: conv.c - verbosef("no --chroot dir specified, darkstat will not chroot()"); - } else { + if (chroot_dir != NULL) { - tzset(); /* read /etc/localtime before we chroot */ - if (chdir(chroot_dir) == -1) - err(1, "chdir(\"%s\") failed", chroot_dir); + /* Read /etc/localtime before we chroot. This works on FreeBSD but not + * on Linux / with glibc (as of 2.22) */ + tzset(); Index: patches/patch-darkstat_c =================================================================== RCS file: /home/cvs/ports/net/darkstat/patches/patch-darkstat_c,v diff -u -p -r1.5 patch-darkstat_c --- patches/patch-darkstat_c 21 Mar 2022 13:12:04 -0000 1.5 +++ patches/patch-darkstat_c 15 Aug 2025 10:58:27 -0000 @@ -1,13 +1,15 @@ -Re-instate the chroot by default code. +Re-instate the chroot by default code and support multiple -l. Index: darkstat.c --- darkstat.c.orig +++ darkstat.c -@@ -134,16 +134,44 @@ const char *opt_privdrop_user = NULL; +@@ -133,17 +133,45 @@ static void cb_base(const char *arg) { opt_base = arg; + static const char *opt_privdrop_user = NULL; static void cb_user(const char *arg) { opt_privdrop_user = arg; } - const char *opt_daylog_fn = NULL; +-static const char *opt_daylog_fn = NULL; -static void cb_daylog(const char *arg) { opt_daylog_fn = arg; } ++const char *opt_daylog_fn = NULL; +static void cb_daylog(const char *arg) +{ + if (opt_chroot_dir == NULL) @@ -17,8 +19,9 @@ Index: darkstat.c + opt_daylog_fn = arg; +} - const char *import_fn = NULL; +-static const char *import_fn = NULL; -static void cb_import(const char *arg) { import_fn = arg; } ++const char *import_fn = NULL; +static void cb_import(const char *arg) +{ + if (opt_chroot_dir == NULL) @@ -28,8 +31,9 @@ Index: darkstat.c + import_fn = arg; +} - const char *export_fn = NULL; +-static const char *export_fn = NULL; -static void cb_export(const char *arg) { export_fn = arg; } ++const char *export_fn = NULL; +static void cb_export(const char *arg) +{ + if ((opt_chroot_dir == NULL) && (opt_capfile == NULL)) @@ -52,6 +56,15 @@ Index: darkstat.c unsigned int opt_hosts_max = 1000; static void cb_hosts_max(const char *arg) +@@ -193,7 +221,7 @@ static struct cmdline_arg cmdline_args[] = { + {"-r", "capfile", cb_capfile, 0}, + {"-p", "port", cb_port, 0}, + {"-b", "bindaddr", cb_bindaddr, -1}, +- {"-l", "network/netmask", cb_local, 0}, ++ {"-l", "network/netmask", cb_local, -1}, + {"--base", "path", cb_base, 0}, + {"--local-only", NULL, cb_local_only, 0}, + {"--snaplen", "bytes", cb_snaplen, 0}, @@ -306,7 +334,9 @@ static void parse_cmdline(const int argc, char * const if (opt_want_syslog) openlog("darkstat", LOG_NDELAY | LOG_PID, LOG_DAEMON);