Download raw body.
net/darkstat support of mulptiple -l
ports@,
I'd like to add to net/darkstat support of mulptiple -l options, to easy
measure IPv6 and IPv4 traffic.
Tested for a few weeks on -current/octeon which runs as:
-i rport0 -b 172.31.0.1 -p 80 -l 172.31.0.0/16 -l fd00::/8
no regression.
I also had openned a PR to upstream which seems not that active:
https://github.com/emikulic/darkstat/pull/26
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 25 Jul 2025 21:01:36 -0000
@@ -6,7 +6,7 @@ DISTNAME= darkstat-3.0.719
CATEGORIES= net www
SITES= ${HOMEPAGE}
EXTRACT_SUFX= .tar.bz2
-REVISION= 3
+REVISION= 4
HOMEPAGE= https://unix4lyfe.org/darkstat/
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 24 Jul 2025 22:53:13 -0000
@@ -0,0 +1,67 @@
+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-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 24 Jul 2025 22:53:13 -0000
@@ -3,63 +3,12 @@ Re-instate the chroot by default code.
Index: darkstat.c
--- darkstat.c.orig
+++ darkstat.c
-@@ -134,16 +134,44 @@ const char *opt_privdrop_user = NULL;
- static void cb_user(const char *arg) { opt_privdrop_user = arg; }
-
- const char *opt_daylog_fn = NULL;
--static void cb_daylog(const char *arg) { opt_daylog_fn = arg; }
-+static void cb_daylog(const char *arg)
-+{
-+ if (opt_chroot_dir == NULL)
-+ errx(1, "the daylog file is relative to the chroot.\n"
-+ "You must specify a --chroot dir before you can use --daylog.");
-+ else
-+ opt_daylog_fn = arg;
-+}
-
- const char *import_fn = NULL;
--static void cb_import(const char *arg) { import_fn = arg; }
-+static void cb_import(const char *arg)
-+{
-+ if (opt_chroot_dir == NULL)
-+ errx(1, "the import file is relative to the chroot.\n"
-+ "You must specify a --chroot dir before you can use --import.");
-+ else
-+ import_fn = arg;
-+}
-
- const char *export_fn = NULL;
--static void cb_export(const char *arg) { export_fn = arg; }
-+static void cb_export(const char *arg)
-+{
-+ if ((opt_chroot_dir == NULL) && (opt_capfile == NULL))
-+ errx(1, "the export file is relative to the chroot.\n"
-+ "You must specify a --chroot dir before you can use --export.");
-+ else
-+ export_fn = arg;
-+}
-
- static const char *pid_fn = NULL;
--static void cb_pidfile(const char *arg) { pid_fn = arg; }
-+static void cb_pidfile(const char *arg)
-+{
-+ if (opt_chroot_dir == NULL)
-+ errx(1, "the pidfile is relative to the chroot.\n"
-+ "You must specify a --chroot dir before you can use --pidfile.");
-+ else
-+ pid_fn = arg;
-+}
-
- unsigned int opt_hosts_max = 1000;
- static void cb_hosts_max(const char *arg)
-@@ -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);
-
-- /* default value */
-+ /* some default values */
-+ if (opt_chroot_dir == NULL)
-+ opt_chroot_dir = CHROOT_DIR;
- if (opt_privdrop_user == NULL)
- opt_privdrop_user = PRIVDROP_USER;
-
+@@ -221,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},
net/darkstat support of mulptiple -l