Howdy,
I work at Yahoo!, where we use npsr in a couple different products.
We've
made one change which may be of general use:
The SO_REUSEPORT flag allows duplicate address and port bindings,
which
is useful in certain applications such as NAT traversal. This flag
is not available on win32 (duplicate bindings are allowed by default)
nor on linux (afaict there's now way to get this behavior). it _is_
available on many BSD based systems.
Attached is a small patch against nspr 4.6.7 which allows a user of
NSPR
to specify that SO_REUSEPORT through the PR_SetSockOpt abstraction.
Hope this is useful to someone else!
best,
Lloyd Hilaiel (lloydh at yahoo-inc d0t com)
diff -ur nspr-4.6.7.orig/mozilla/nsprpub/pr/include/prio.h nspr-4.6.7/
mozilla/nsprpub/pr/include/prio.h
--- nspr-4.6.7.orig/mozilla/nsprpub/pr/include/prio.h 2007-11-01
14:37:28.000000000 -0600
+++ nspr-4.6.7/mozilla/nsprpub/pr/include/prio.h 2007-11-01
14:37:58.000000000 -0600
@@ -224,6 +224,8 @@
PR_SockOpt_Nonblocking, /* nonblocking io */
PR_SockOpt_Linger, /* linger on close if data present */
PR_SockOpt_Reuseaddr, /* allow local address reuse */
+ PR_SockOpt_Reuseport, /* allow duplicate bindings on
+ * platforms that support it */
PR_SockOpt_Keepalive, /* keep connections alive */
PR_SockOpt_RecvBufferSize, /* send buffer size */
PR_SockOpt_SendBufferSize, /* receive buffer size */
@@ -263,6 +265,8 @@
PRUintn tos; /* IP type of service and
precedence */
PRBool non_blocking; /* Non-blocking (network) I/O */
PRBool reuse_addr; /* Allow local address reuse */
+ PRBool reuse_port; /* allow duplicate bindings on
+ * platforms that support it */
PRBool keep_alive; /* Keep connections alive */
PRBool mcast_loopback; /* IP multicast loopback */
PRBool no_delay; /* Don't delay send to coalesce
packets */
diff -ur nspr-4.6.7.orig/mozilla/nsprpub/pr/src/io/prmapopt.c
nspr-4.6.7/mozilla/nsprpub/pr/src/io/prmapopt.c
--- nspr-4.6.7.orig/mozilla/nsprpub/pr/src/io/prmapopt.c 2007-11-01
14:37:28.000000000 -0600
+++ nspr-4.6.7/mozilla/nsprpub/pr/src/io/prmapopt.c 2007-11-01
14:37:58.000000000 -0600
@@ -118,6 +118,7 @@
return PR_FAILURE;
#endif
}
+ case PR_SockOpt_Reuseport:
case PR_SockOpt_Reuseaddr:
case PR_SockOpt_Keepalive:
case PR_SockOpt_NoDelay:
@@ -270,6 +271,7 @@
#endif
}
case PR_SockOpt_Reuseaddr:
+ case PR_SockOpt_Reuseport:
case PR_SockOpt_Keepalive:
case PR_SockOpt_NoDelay:
case PR_SockOpt_Broadcast:
@@ -481,19 +483,23 @@
#define SO_BROADCAST _PR_NO_SUCH_SOCKOPT
#endif
+#ifndef SO_REUSEPORT /* enable duplicate socket
bindings */
+#define SO_REUSEPORT _PR_NO_SUCH_SOCKOPT
+#endif
+
PRStatus _PR_MapOptionName(
PRSockOption optname, PRInt32 *level, PRInt32 *name)
{
static PRInt32 socketOptions[PR_SockOpt_Last] =
{
- 0, SO_LINGER, SO_REUSEADDR, SO_KEEPALIVE, SO_RCVBUF,
SO_SNDBUF,
+ 0, SO_LINGER, SO_REUSEADDR, SO_REUSEPORT, SO_KEEPALIVE,
SO_RCVBUF, SO_SNDBUF,
IP_TTL, IP_TOS, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,
IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP,
TCP_NODELAY, TCP_MAXSEG, SO_BROADCAST
};
static PRInt32 socketLevels[PR_SockOpt_Last] =
{
- 0, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET,
SOL_SOCKET,
+ 0, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET,
SOL_SOCKET, SOL_SOCKET,
IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, IPPROTO_IP,
IPPROTO_IP, IPPROTO_IP, IPPROTO_IP,
IPPROTO_TCP, IPPROTO_TCP, SOL_SOCKET
diff -ur nspr-4.6.7.orig/mozilla/nsprpub/pr/src/md/mac/macsockotpt.c
nspr-4.6.7/mozilla/nsprpub/pr/src/md/mac/macsockotpt.c
--- nspr-4.6.7.orig/mozilla/nsprpub/pr/src/md/mac/macsockotpt.c
2007-11-01 14:37:28.000000000 -0600
+++ nspr-4.6.7/mozilla/nsprpub/pr/src/md/mac/macsockotpt.c 2007-11-01
14:37:58.000000000 -0600
@@ -48,6 +48,8 @@
#define GESTALT_OPEN_TPT_PRESENT gestaltOpenTptPresentMask
#define GESTALT_OPEN_TPT_TCP_PRESENT gestaltOpenTptTCPPresentMask
+#error "I'm broken. I don't have reuseport. kill me."
+
#include <OpenTptInternet.h> // All the internet typedefs
#if (UNIVERSAL_INTERFACES_VERSION >= 0x0330)
diff -ur nspr-4.6.7.orig/mozilla/nsprpub/pr/src/pthreads/ptio.c
nspr-4.6.7/mozilla/nsprpub/pr/src/pthreads/ptio.c
--- nspr-4.6.7.orig/mozilla/nsprpub/pr/src/pthreads/ptio.c 2007-11-01
14:37:28.000000000 -0600
+++ nspr-4.6.7/mozilla/nsprpub/pr/src/pthreads/ptio.c 2007-11-01
14:37:58.000000000 -0600
@@ -2831,6 +2831,7 @@
break;
}
case PR_SockOpt_Reuseaddr:
+ case PR_SockOpt_Reuseport:
case PR_SockOpt_Keepalive:
case PR_SockOpt_NoDelay:
case PR_SockOpt_Broadcast:
@@ -2950,6 +2951,7 @@
break;
}
case PR_SockOpt_Reuseaddr:
+ case PR_SockOpt_Reuseport:
case PR_SockOpt_Keepalive:
case PR_SockOpt_NoDelay:
case PR_SockOpt_Broadcast:
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.