Module Name: src
Committed By: pgoyette
Date: Mon Aug 13 12:22:21 UTC 2012
Modified Files:
src/usr.sbin/rpc.lockd: lockd.c rpc.lockd.8
Log Message:
Add -4 and -6 options to rpd.lockd for consistent control over the
protocols to which it listens. As discussed on tech-userlevel.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/rpc.lockd/lockd.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/rpc.lockd/rpc.lockd.8
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/rpc.lockd/lockd.c
diff -u src/usr.sbin/rpc.lockd/lockd.c:1.10 src/usr.sbin/rpc.lockd/lockd.c:1.11
--- src/usr.sbin/rpc.lockd/lockd.c:1.10 Sat Dec 15 19:44:56 2007
+++ src/usr.sbin/rpc.lockd/lockd.c Mon Aug 13 12:22:21 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: lockd.c,v 1.10 2007/12/15 19:44:56 perry Exp $ */
+/* $NetBSD: lockd.c,v 1.11 2012/08/13 12:22:21 pgoyette Exp $ */
/*
* Copyright (c) 1995
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: lockd.c,v 1.10 2007/12/15 19:44:56 perry Exp $");
+__RCSID("$NetBSD: lockd.c,v 1.11 2012/08/13 12:22:21 pgoyette Exp $");
#endif
/*
@@ -51,6 +51,7 @@ __RCSID("$NetBSD: lockd.c,v 1.10 2007/12
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <errno.h>
#include <syslog.h>
#include <signal.h>
@@ -84,14 +85,16 @@ int
main(int argc, char **argv)
{
SVCXPRT *transp;
- int ch, i, maxindex, s;
+ int ch, i, minindex, maxindex, s;
+ bool use_ipv4, use_ipv6;
struct sigaction sigchild, sigalarm;
int grace_period = 30;
struct netconfig *nconf;
int maxrec = RPC_MAXDATASIZE;
(void)setprogname(*argv);
- while ((ch = getopt(argc, argv, "d:g:")) != (-1)) {
+ use_ipv4 = use_ipv6 = false;
+ while ((ch = getopt(argc, argv, "d:g:46")) != (-1)) {
switch (ch) {
case 'd':
debug_level = atoi(optarg);
@@ -107,6 +110,12 @@ main(int argc, char **argv)
/* NOTREACHED */
}
break;
+ case '4':
+ use_ipv4 = true;
+ break;
+ case '6':
+ use_ipv6 = true;
+ break;
default:
case '?':
usage();
@@ -119,23 +128,31 @@ main(int argc, char **argv)
(void)rpcb_unset(NLM_PROG, NLM_VERSX, NULL);
(void)rpcb_unset(NLM_PROG, NLM_VERS4, NULL);
- /*
- * Check if IPv6 support is present.
- */
- s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
- if (s < 0)
- maxindex = 2;
- else {
- (void)close(s);
- maxindex = 4;
+ if (!use_ipv4 && !use_ipv6) {
+ s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
+ if (s < 0)
+ use_ipv4 = true;
+ else {
+ (void)close(s);
+ use_ipv4 = use_ipv6 = true;
+ }
}
+ if (use_ipv4)
+ minindex = 0;
+ else
+ minindex = 2;
+
+ if (use_ipv6)
+ maxindex = 4;
+ else
+ maxindex = 2;
(void)rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
- for (i = 0; i < maxindex; i++) {
+ for (i = minindex; i < maxindex; i++) {
nconf = getnetconfigent(transports[i]);
if (nconf == NULL)
- errx(1, "cannot get udp netconf.");
+ errx(1, "cannot get %s netconf.", transports[i]);
transp = svc_tli_create(RPC_ANYFD, nconf, NULL, RPC_MAXDATASIZE,
RPC_MAXDATASIZE);
Index: src/usr.sbin/rpc.lockd/rpc.lockd.8
diff -u src/usr.sbin/rpc.lockd/rpc.lockd.8:1.6 src/usr.sbin/rpc.lockd/rpc.lockd.8:1.7
--- src/usr.sbin/rpc.lockd/rpc.lockd.8:1.6 Sat Feb 2 01:42:45 2002
+++ src/usr.sbin/rpc.lockd/rpc.lockd.8 Mon Aug 13 12:22:21 2012
@@ -1,4 +1,4 @@
-.\" $NetBSD: rpc.lockd.8,v 1.6 2002/02/02 01:42:45 wiz Exp $
+.\" $NetBSD: rpc.lockd.8,v 1.7 2012/08/13 12:22:21 pgoyette Exp $
.\"
.\" Copyright (c) 1995 A.R.Gordon, [email protected]
.\" All rights reserved.
@@ -32,7 +32,7 @@
.\" SUCH DAMAGE.
.\"
.\"
-.Dd September 24, 1995
+.Dd August 11, 2012
.Dt RPC.LOCKD 8
.Os
.Sh NAME
@@ -42,6 +42,7 @@
.Nm
.Op Fl d Ar debug_level
.Op Fl g Ar grace period
+.Op Fl 46
.Sh DESCRIPTION
The
.Nm
@@ -71,6 +72,17 @@ option allow to specify the grace period
.Nm
only accepts requests from hosts which are reinitialising locks which
existed before the server restart. Default is 30 seconds.
+.It Fl 4
+Listen for requests using IPv4.
+Do not listen using IPv6 unless the
+.Fl 6
+option is also specified.
+By default,
+.Nm
+listens for requests using both IPv4 and IPv6 if available.
+.It Fl 6
+Listen for requests using IPv6.
+It is an error if IPv6 is not available.
.El
.Pp
Error conditions are logged to syslog, irrespective of the debug level,