Add -4 and -6 options to rpd.lockd for consistent control over the

protocols to which it listens.  As discussed on tech-userlevel.
This commit is contained in:
pgoyette 2012-08-13 12:22:21 +00:00
parent bcbfa15ea9
commit f283cd004e
2 changed files with 46 additions and 17 deletions

View File

@ -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/15 19:44:56 perry Exp $");
#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);

View File

@ -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, andrew.gordon@net-tel.co.uk
.\" 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, in seconds. During 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,