marjohn56 / udpbroadcastrelay

UDP multicast/unicast relayer
GNU General Public License v2.0
127 stars 23 forks source link

Support SO_REUSEPORT in FreeBSD #13

Open marcos-ng opened 1 year ago

marcos-ng commented 1 year ago

SO_REUSEPORT enables duplicate address and port bindings

https://man.freebsd.org/cgi/man.cgi?query=setsockopt&manpath=FreeBSD+14.0-CURRENT

With this added to the package, both this app and miniupnpd (as of 2.2.2) can both listen to e.g. UDP/1900 at the same time.

From 29e5b998f922c1e04052e5ffc4e0d642ed8b78cb Mon Sep 17 00:00:00 2001
From: Kristof Provost <kp@FreeBSD.org>
Date: Fri, 10 May 2024 13:36:13 -0600
Subject: [PATCH] set SO_REUSEPORT

Allows udpbroadcastrelay to share the port binding with other processes.

diff --git a/main.c b/main.c
index db28944..0712bde 100644
--- a/main.c
+++ b/main.c
@@ -1975,6 +1975,11 @@ srandom(time(NULL) ^ getpid());
           exit(1);
       };

+    int yes = 1;
+    if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) != 0) {
+        perror("setsockopt");
+        exit(1);
+    }

     /* For each interface on the command line */
     for (int i = 0; i < interfaceNamesNum; i++) {

I'm making this available here instead of an MR given that it's only been tested with a previous version (currently available in FreeBSD 15).