NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Issues with trickle



Any chance of that getting added to the pkgsrc package?


-----Original Message-----
From: RVP [mailto:rvp%SDF.ORG@localhost]
Sent: Thursday, February 20, 2025 01:39 AM -05
To: Charadon
Cc: netbsd-users%netbsd.org@localhost
Subject: Re: Issues with trickle

On Wed, 19 Feb 2025, Charadon wrote:

I installed trickle using pkgin, and for some reason whenever I run it
with anything it dies with a Memory Fault.

Anyone had any luck running this? I can't find anyone else online
having this issue.


This is a NetBSD-specific issue caused by compat-related symbol renaming.
Apply the following 2 patches in sequence. The first, collects most of the
important (except the thread-related one) from GitHub. This fixes some
issues
in trickle-1.07.

The second is the NetBSD-specific fix. Compile trickle as:

ac_cv_func_sendfile=no ./configure --prefix=/usr/pkg --sysconfdir=/usr/
pkg/etc

otherwise, `configure' thinks NetBSD has sendfile(1)--which it doesn't.
(Else
delete line 79 in `configure.in` then regen `configure` the std. way...)

-RVP

PS. Oh! and make sure none of the `-D_FORTIFY_SOURCE=N` / `-fstack-
protector-XXX`
flags are set either. Those too will play havoc with the way this thing is
implemented.

---START GitHub PATCH---
diff -urN trickle-1.07.orig/bwstat.c trickle-1.07/bwstat.c
--- trickle-1.07.orig/bwstat.c    2004-10-24 09:31:27.000000000 +0000
+++ trickle-1.07/bwstat.c    2025-02-20 05:55:50.358534095 +0000
@@ -69,6 +69,7 @@
      if ((bs = calloc(1, sizeof(*bs))) == NULL)
          return (NULL);

+    bs->pts = 1;
      TAILQ_INSERT_TAIL(&statq, bs, next);

      return (bs);
@@ -143,7 +144,8 @@
  struct timeval *
  bwstat_getdelay(struct bwstat *bs, size_t *len, uint lim, short which)
  {
-    uint rate = 0, ncli = 0, npts = 0, pool = 0, ent, xent;
+    uint rate = 0, npts = 0, ent;
+    int ncli = 0, pool = 0, xent;
      double delay;
      static struct timeval tv;
      struct bwstathead poolq;
@@ -201,7 +203,7 @@
          if (ncli > 0) {
              xent = pool / npts;

-            if (xent == 0)
+            if (xent <= 0)
                  break;

              TAILQ_FOREACH(xbs, &poolq, qnext)
diff -urN trickle-1.07.orig/trickle-overload.c trickle-1.07/trickle-
overload.c
--- trickle-1.07.orig/trickle-overload.c    2004-12-13
01:21:53.000000000 +0000
+++ trickle-1.07/trickle-overload.c    2025-02-20 06:01:22.992531037 +0000
@@ -302,6 +302,13 @@
          domain, type, protocol, sock);
  #endif /* DEBUG */

+#ifdef SOCK_NONBLOCK
+    type &= ~SOCK_NONBLOCK;
+#endif
+#ifdef SOCK_CLOEXEC
+    type &= ~SOCK_CLOEXEC;
+#endif
+
      if (sock != -1 && domain == AF_INET && type == SOCK_STREAM) {
          if ((sd = calloc(1, sizeof(*sd))) == NULL)
              return (-1);
@@ -311,7 +318,6 @@
          }

          /* All sockets are equals. */
-        sd->stat->pts = 1;
          sd->stat->lsmooth = lsmooth;
          sd->stat->tsmooth = tsmooth;
          sd->sock = sock;
@@ -393,18 +399,14 @@
  }

  static struct delay *
-select_shift(struct delayhead *dhead, struct timeval *inittv,
+select_shift(struct delayhead *dhead, struct timeval *difftv,
      struct timeval **delaytv)
  {
-    struct timeval curtv, difftv;
      struct delay *d;
      struct sockdesc *sd;

-    gettimeofday(&curtv, NULL);
-    timersub(&curtv, inittv, &difftv);
-
      TAILQ_FOREACH(d, dhead, next) {
-        if (timercmp(&d->delaytv, &difftv, >))
+        if (timercmp(&d->delaytv, difftv, >))
              break;
          sd = d->sd;

@@ -413,7 +415,7 @@
      }

      if (d != NULL)
-        timersub(&d->delaytv, &difftv, *delaytv);
+        timersub(&d->delaytv, difftv, *delaytv);
      else
          *delaytv = NULL;

@@ -431,8 +433,8 @@
  {
      struct sockdesc *sd;
      fd_set *fdsets[] = { wfds, rfds }, *fds;
-    struct timeval *delaytv, *selecttv = NULL, *timeout = NULL, _timeout,
-        inittv, curtv, difftv;
+    struct timeval *delaytv, _delaytv, *selecttv = NULL, *timeout = NULL,
+        _timeout, inittv, curtv, difftv;
      short which;
      struct delayhead dhead;
      struct delay *d, *_d;
@@ -462,15 +464,18 @@
                  FD_ISSET(sd->sock, fds) &&
                  select_delay(&dhead, sd, which)) {
                  FD_CLR(sd->sock, fds);
-                nfds--;
              }

      gettimeofday(&inittv, NULL);
      curtv = inittv;
      d = TAILQ_FIRST(&dhead);
-    delaytv = d != NULL ? &d->delaytv : NULL;
+    if (d != NULL) {
+        _delaytv = d->delaytv;
+        delaytv = &_delaytv;
+    } else
+        delaytv = NULL;
+    timersub(&curtv, &inittv, &difftv);
   again:
-    timersub(&inittv, &curtv, &difftv);
      selecttv = NULL;

      if (delaytv != NULL)
@@ -498,15 +503,15 @@
  #endif /* DEBUG */

      if (ret == 0 && delaytv != NULL && selecttv == delaytv) {
-        _d = select_shift(&dhead, &inittv, &delaytv);
+        gettimeofday(&curtv, NULL);
+        timersub(&curtv, &inittv, &difftv);
+        _d = select_shift(&dhead, &difftv, &delaytv);
          while ((d = TAILQ_FIRST(&dhead)) != _d) {
              FD_SET(d->sd->sock, fdsets[d->which]);
-            nfds++;
              TAILQ_REMOVE(&dhead, d, next);
              free(d);
          }

-        gettimeofday(&curtv, NULL);
          goto again;
      }

@@ -994,7 +999,6 @@
          }

          sd->sock = ret;
-        sd->stat->pts = 1;
          sd->stat->lsmooth = lsmooth;
          sd->stat->tsmooth = tsmooth;
          TAILQ_INSERT_TAIL(&sdhead, sd, next);
---END GitHub PATCH---

---START NetBSD PATCH---
diff -urN trickle-1.07.orig/trickle-overload.c trickle-1.07/trickle-
overload.c
--- trickle-1.07.orig/trickle-overload.c    2025-02-20
05:50:22.992531037 +0000
+++ trickle-1.07/trickle-overload.c    2025-02-20 06:21:15.397992571 +0000
@@ -196,7 +196,12 @@

      GETADDR(write);

+#ifdef __NetBSD__
+    if ((libc_socket = dlsym(dh, "__socket30")) == NULL)
+        errx(0, "[trickle] Failed to get __socket30() address");
+#else
      GETADDR(socket);
+#endif
  /*    GETADDR(setsockopt); */
      GETADDR(close);

@@ -213,7 +218,12 @@
  #endif /* !__FreeBSD__ */
      GETADDR(sendto);

+#ifdef __NetBSD__
+    if ((libc_select = dlsym(dh, "__select50")) == NULL)
+        errx(0, "[trickle] Failed to get __select50() address");
+#else
      GETADDR(select);
+#endif
  //    GETADDR(poll);

      GETADDR(dup);
@@ -527,7 +537,7 @@
  #define POLL_WRMASK (POLLOUT | POLLWRNORM | POLLWRBAND)
  #define POLL_RDMASK (POLLIN | /* POLLNORM | */  POLLPRI | POLLRDNORM |
POLLRDBAND)

-#if defined(__linux__) || (defined(__svr4__) && defined(__sun__)) ||
defined(__OpenBSD__)
+#if defined(__linux__) || (defined(__svr4__) && defined(__sun__)) ||
defined(__OpenBSD__) || defined(__NetBSD__)
  int
  poll(struct pollfd *fds, nfds_t nfds, int __timeout)
  #elif defined(__FreeBSD__)
---END NetBSD PATCH---



Home | Main Index | Thread Index | Old Index