diff options
author | matteo <matteo@FreeBSD.org> | 2007-04-03 20:58:28 +0000 |
---|---|---|
committer | matteo <matteo@FreeBSD.org> | 2007-04-03 20:58:28 +0000 |
commit | a25d27fb0f15b68dc0524ac87960260bf1abdc4e (patch) | |
tree | 2fb819a49138fde7af2aa6b5ecb3f05ca9765d5e /usr.sbin/rpc.lockd | |
parent | d7b9f1a7cd30f3a8c1eb6b1ad48aed1f82a8e95a (diff) | |
download | FreeBSD-src-a25d27fb0f15b68dc0524ac87960260bf1abdc4e.zip FreeBSD-src-a25d27fb0f15b68dc0524ac87960260bf1abdc4e.tar.gz |
Add the "-p" option, which allows to specify a port which the daemon
should bind to.
PR: bin/100969
Reviewed by: alfred@
MFC after: 1 week
Diffstat (limited to 'usr.sbin/rpc.lockd')
-rw-r--r-- | usr.sbin/rpc.lockd/lockd.c | 91 | ||||
-rw-r--r-- | usr.sbin/rpc.lockd/rpc.lockd.8 | 9 |
2 files changed, 92 insertions, 8 deletions
diff --git a/usr.sbin/rpc.lockd/lockd.c b/usr.sbin/rpc.lockd/lockd.c index 20fec25..15c9d69 100644 --- a/usr.sbin/rpc.lockd/lockd.c +++ b/usr.sbin/rpc.lockd/lockd.c @@ -92,13 +92,17 @@ main(argc, argv) char **argv; { SVCXPRT *transp; - int ch, i, maxindex, s; + int ch, i, maxindex, r, s, sock; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + char *endptr; struct sigaction sigalarm; int grace_period = 30; struct netconfig *nconf; int maxrec = RPC_MAXDATASIZE; + in_port_t svcport = 0; - while ((ch = getopt(argc, argv, "d:g:")) != (-1)) { + while ((ch = getopt(argc, argv, "d:g:p:")) != (-1)) { switch (ch) { case 'd': debug_level = atoi(optarg); @@ -114,6 +118,13 @@ main(argc, argv) /* NOTREACHED */ } break; + case 'p': + endptr = NULL; + svcport = (in_port_t)strtoul(optarg, &endptr, 10); + if (endptr == NULL || *endptr != '\0' || + svcport == 0 || svcport >= IPPORT_MAX) + usage(); + break; default: case '?': usage(); @@ -141,16 +152,81 @@ main(argc, argv) maxindex = 4; } + if (svcport != 0) { + bzero(&sin, sizeof(struct sockaddr_in)); + sin.sin_len = sizeof(struct sockaddr_in); + sin.sin_family = AF_INET; + sin.sin_port = htons(svcport); + + bzero(&sin6, sizeof(struct sockaddr_in6)); + sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_family = AF_INET6; + sin6.sin6_port = htons(svcport); + } + rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec); for (i = 0; i < maxindex; i++) { nconf = getnetconfigent(transports[i]); if (nconf == NULL) - errx(1, "cannot get %s netconf: %s.", transports[i], - nc_sperror()); + errx(1, "cannot get %s netconf: %s.", transports[i], + nc_sperror()); + + if (svcport != 0) { + if (strcmp(nconf->nc_netid, "udp6") == 0) { + sock = socket(AF_INET6, SOCK_DGRAM, + IPPROTO_UDP); + if (sock != -1) { + r = bindresvport_sa(sock, + (struct sockaddr *)&sin6); + if (r != 0) { + syslog(LOG_ERR, "bindresvport: %m"); + exit(1); + } + } + } + else if (strcmp(nconf->nc_netid, "udp") == 0) { + sock = socket(AF_INET, SOCK_DGRAM, + IPPROTO_UDP); + if (sock != -1) { + r = bindresvport(sock, &sin); + if (r != 0) { + syslog(LOG_ERR, "bindresvport: %m"); + exit(1); + } + } + } + else if (strcmp(nconf->nc_netid, "tcp6") == 0) { + sock = socket(AF_INET6, SOCK_STREAM, + IPPROTO_TCP); + if (sock != -1) { + r = bindresvport_sa(sock, + (struct sockaddr *)&sin6); + if (r != 0) { + syslog(LOG_ERR, "bindresvport: %m"); + exit(1); + } + } + } + else if (strcmp(nconf->nc_netid, "tcp") == 0) { + sock = socket(AF_INET, SOCK_STREAM, + IPPROTO_TCP); + if (sock != -1) { + r = bindresvport(sock, &sin); + if (r != 0) { + syslog(LOG_ERR, "bindresvport: %m"); + exit(1); + } + } + } + + transp = svc_tli_create(sock, nconf, NULL, + RPC_MAXDATASIZE, RPC_MAXDATASIZE); + } else { + transp = svc_tli_create(RPC_ANYFD, nconf, NULL, + RPC_MAXDATASIZE, RPC_MAXDATASIZE); + } - transp = svc_tli_create(RPC_ANYFD, nconf, NULL, - RPC_MAXDATASIZE, RPC_MAXDATASIZE); if (transp == NULL) { errx(1, "cannot create %s service.", transports[i]); /* NOTREACHED */ @@ -223,7 +299,8 @@ sigalarm_handler(void) void usage() { - errx(1, "usage: rpc.lockd [-d <debuglevel>] [-g <grace period>]"); + errx(1, "usage: rpc.lockd [-d <debuglevel>]" + " [-g <grace period>] [-p <port>]"); } /* diff --git a/usr.sbin/rpc.lockd/rpc.lockd.8 b/usr.sbin/rpc.lockd/rpc.lockd.8 index 7c86bb6..0b5d348 100644 --- a/usr.sbin/rpc.lockd/rpc.lockd.8 +++ b/usr.sbin/rpc.lockd/rpc.lockd.8 @@ -33,7 +33,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 24, 1995 +.Dd April 3, 2007 .Dt RPC.LOCKD 8 .Os .Sh NAME @@ -43,6 +43,7 @@ .Nm .Op Fl d Ar debug_level .Op Fl g Ar grace period +.Op Fl p Ar port .Sh DESCRIPTION The .Nm @@ -83,6 +84,12 @@ During the grace period only accepts requests from hosts which are reinitialising locks which existed before the server restart. Default is 30 seconds. +.It Fl p +The +.Fl p +option allow to force the daemon to bind to the specified +.Ar port , +for both AF_INET and AF_INET6 address families. .El .Pp Error conditions are logged to syslog, irrespective of the debug level, |