Skip to contentSkip to conversation

mountd: Disabling UDP listeners

PATCH New Steve Dickson 1 participant 3 messages Oct 28, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mountd: Disabling UDP listeners

To start down the road of a V4-only environment, there needs to be a way to turn off UDP listeners in mountd, similar to how TCP listeners are disabled.

The patch does that by added the [-u|--no-udp] flags which allows the disabling of the UDP listener

Steve Dickson (2):
mountd: Use protocol bit fields to turn protocols off.
mountd: Add the ability to disable UDP listeners.

 support/include/rpcmisc.h |  2 +-
 support/nfs/rpcmisc.c     | 19 ++++++++++++++-----
 support/nfs/svc_create.c  |  8 ++++++++
 utils/mountd/mountd.c     | 12 ++++++++----
 utils/mountd/mountd.man   |  3 +++
 5 files changed, 34 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 mountd: Use protocol bit fields to turn protocols off.

Convert the current code to used the NFSCTL_XXX macros to turn off the TCP listener.

---
 support/include/rpcmisc.h |  2 +-
 support/nfs/rpcmisc.c     | 19 ++++++++++++++-----
 support/nfs/svc_create.c  |  5 +++++
 utils/mountd/mountd.c     |  2 +-
 4 files changed, 21 insertions(+), 7 deletions(-)
support/include/rpcmisc.h +1 -1
index b806227..31c8e5d 100644
@@ -56,7 +56,7 @@ void		rpc_dispatch(struct svc_req *rq, SVCXPRT *xprt,
 int		getservport(u_long number, const char *proto);
 
 extern int	_rpcpmstart;
-extern int	_rpcfdtype;
+extern unsigned int	_rpcprotobits;
 extern int	_rpcsvcdirty;
 
 static inline struct sockaddr_in *nfs_getrpccaller_in(SVCXPRT *xprt)
support/nfs/rpcmisc.c +14 -5
index b73187a..64c98ff 100644
@@ -39,7 +39,7 @@
 
 #define _RPCSVC_CLOSEDOWN	120
 int	_rpcpmstart = 0;
-int	_rpcfdtype = 0;
+unsigned int _rpcprotobits = (NFSCTL_UDPBIT|NFSCTL_TCPBIT);
 int	_rpcsvcdirty = 0;
 
 static void
@@ -51,7 +51,7 @@ closedown(int sig)
 		static int size;
 		int i, openfd;
 
-		if (_rpcfdtype == SOCK_DGRAM)
+		if (NFSCTL_TCPISSET(_rpcprotobits) == 0)
 			exit(0);
 
 		if (size == 0)
@@ -130,7 +130,16 @@ rpc_init(char *name, int prog, int vers,
 		 * listen will fail on a connected TCP socket(passed by rsh).
 		 */
 		if (!(fdtype == SOCK_STREAM && listen(0,5) == -1)) {
-			_rpcfdtype = fdtype;
+			switch(fdtype) {
+			case SOCK_DGRAM:
+				NFSCTL_UDPSET(_rpcprotobits);
+				break;
+			case SOCK_STREAM:
+				NFSCTL_TCPSET(_rpcprotobits);
+				break;
+			default:
+				xlog(L_FATAL, "getsockopt returns bad socket type: %d", fdtype);
+			}
 			_rpcpmstart = 1;
 		}
 	}
@@ -139,7 +148,7 @@ rpc_init(char *name, int prog, int vers,
 		sock = RPC_ANYSOCK;
 	}
 
-	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_DGRAM)) {
+	if (NFSCTL_UDPISSET(_rpcprotobits)) {
 		static SVCXPRT *last_transp = NULL;
 
 		if (_rpcpmstart == 0) {
@@ -167,7 +176,7 @@ rpc_init(char *name, int prog, int vers,
 		last_transp = transp;
 	}
 
-	if ((_rpcfdtype == 0) || (_rpcfdtype == SOCK_STREAM)) {
+	if (NFSCTL_TCPISSET(_rpcprotobits)) {
 		static SVCXPRT *last_transp = NULL;
 
 		if (_rpcpmstart == 0) {
support/nfs/svc_create.c +5 -0
index c159fc8..9ae2965 100644
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <netdb.h>
+#include "nfslib.h"
 
 #include <netinet/in.h>
 
@@ -417,6 +418,10 @@ nfs_svc_create(char *name, const rpcprog_t program, const rpcvers_t version,
 		if (!(nconf->nc_flag & NC_VISIBLE))
 			continue;
 		visible++;
+
+		if (!strcmp(nconf->nc_proto, NC_TCP) && !NFSCTL_TCPISSET(_rpcprotobits))
+			continue;
+
 		if (port == 0)
 			servport = getservport(program, nconf->nc_proto);
 		else
utils/mountd/mountd.c +1 -1
index 993b6e6..f918472 100644
@@ -755,7 +755,7 @@ main(int argc, char **argv)
 			nfs_version &= ~NFSVERSBIT(vers);
 			break;
 		case 'n':
-			_rpcfdtype = SOCK_DGRAM;
+			NFSCTL_TCPUNSET(_rpcprotobits);
 			break;
 		case 'r':
 			reverse_resolve = 1;
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/2 mountd: Add the ability to disable UDP listeners.

In reply to Steve Dickson

Add the ability to turn off UDP listeners with the new "-u | --no-udp" flag.

---
 support/nfs/svc_create.c |  3 +++
 utils/mountd/mountd.c    | 10 +++++++---
 utils/mountd/mountd.man  |  3 +++
 3 files changed, 13 insertions(+), 3 deletions(-)
support/nfs/svc_create.c +3 -0
index 9ae2965..6b9e85b 100644
@@ -419,6 +419,9 @@ nfs_svc_create(char *name, const rpcprog_t program, const rpcvers_t version,
 			continue;
 		visible++;
 
+		if (!strcmp(nconf->nc_proto, NC_UDP) && !NFSCTL_UDPISSET(_rpcprotobits))
+			continue;
+
 		if (!strcmp(nconf->nc_proto, NC_TCP) && !NFSCTL_TCPISSET(_rpcprotobits))
 			continue;
 
utils/mountd/mountd.c +7 -3
index f918472..9fe0f40 100644
@@ -68,6 +68,7 @@ static struct option longopts[] =
 	{ "num-threads", 1, 0, 't' },
 	{ "reverse-lookup", 0, 0, 'r' },
 	{ "manage-gids", 0, 0, 'g' },
+	{ "no-udp", 0, 0, 'u' },
 	{ NULL, 0, 0, 0 }
 };
 
@@ -708,7 +709,7 @@ main(int argc, char **argv)
 
 	/* Parse the command line options and arguments. */
 	opterr = 0;
-	while ((c = getopt_long(argc, argv, "o:nFd:f:p:P:hH:N:V:vrs:t:g", longopts, NULL)) != EOF)
+	while ((c = getopt_long(argc, argv, "o:nFd:f:p:P:hH:N:V:vurs:t:g", longopts, NULL)) != EOF)
 		switch (c) {
 		case 'g':
 			manage_gids = 1;
@@ -782,6 +783,9 @@ main(int argc, char **argv)
 		case 'v':
 			printf("%s version " VERSION "\n", progname);
 			exit(0);
+		case 'u':
+			NFSCTL_UDPUNSET(_rpcprotobits);
+			break;
 		case 0:
 			break;
 		case '?':
@@ -849,7 +853,7 @@ main(int argc, char **argv)
 		listeners += nfs_svc_create("mountd", MOUNTPROG,
 					MOUNTVERS_NFSV3, mount_dispatch, port);
 	if (version23() && listeners == 0)
-		xlog(L_FATAL, "mountd: could not create listeners\n");
+		xlog(L_WARNING, "mountd: No V2 or V3 listeners created!");
 
 	sa.sa_handler = killer;
 	sigaction(SIGINT, &sa, NULL);
@@ -907,6 +911,6 @@ usage(const char *prog, int n)
 "	[-p|--port port] [-V version|--nfs-version version]\n"
 "	[-N version|--no-nfs-version version] [-n|--no-tcp]\n"
 "	[-H ha-callout-prog] [-s|--state-directory-path path]\n"
-"	[-g|--manage-gids] [-t num|--num-threads=num]\n", prog);
+"	[-g|--manage-gids] [-t num|--num-threads=num] [-u|--no-udp]\n", prog);
 	exit(n);
 }
utils/mountd/mountd.man +3 -0
index b60dc90..e59a559 100644
@@ -181,6 +181,9 @@ threads are usually only needed for NFS servers which need to handle
 mount storms of hundreds of NFS mounts in a few seconds, or when
 your DNS server is slow or unreliable.
 .TP
+.B  \-u " or " \-\-no-udp
+Don't advertise UDP for mounting
+.TP
 .B \-V " or " \-\-nfs-version
 This option can be used to request that
 .B rpc.mountd
Signature · 1 line
1.8.3.1