]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
Never set SO_REUSEADDR on a UDP socket.
authorNeil Brown <neilb@suse.de>
Thu, 22 Mar 2007 05:06:22 +0000 (16:06 +1100)
committerNeil Brown <neilb@suse.de>
Thu, 22 Mar 2007 05:06:22 +0000 (16:06 +1100)
The effect is quite different from TCP sockets.
For TCP, it allows you to listen for new connections even if there
are outstanding old connections with the same local address.
For UDP, it allows other people to steal your packets by
binding to the same address.

support/nfs/rpcmisc.c
support/nfs/svc_socket.c

index 5b0a88ff76745ea86c019718272bd3c10c66fa77..22ea62c1a88f5d8458968c4fe82cf88dc802025a 100644 (file)
@@ -184,8 +184,11 @@ int makesock(int port, int proto)
        sin.sin_port = htons(port);
 
        val = 1;
-       if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0)
-               xlog(L_ERROR, "setsockopt failed: %s\n", strerror(errno));
+       if (proto == IPPROTO_TCP)
+               if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
+                              &val, sizeof(val)) < 0)
+                       xlog(L_ERROR, "setsockopt failed: %s\n",
+                            strerror(errno));
 
 #if 0
        /* I was told it didn't work with gigabit ethernet.
index 33076009ac0538de8569fd3489282bbeb2d672ed..6799d16230e5278f74c2f404c39b14dd1f21c72b 100644 (file)
@@ -162,7 +162,7 @@ svctcp_socket (u_long number, int reuse)
 int
 svcudp_socket (u_long number, int reuse)
 {
-  return svc_socket (number, SOCK_DGRAM, IPPROTO_UDP, reuse);
+  return svc_socket (number, SOCK_DGRAM, IPPROTO_UDP, 0);
 }
 
 #ifdef TEST