mount_nfs.c: Add an NFS mount option to set a port# for Mount
Normally mount_nfs acquires the port# for the NFS server's Mount protocol (mountd(8)) via rpcbind/portmapper for NFSv3 mounts. This patch adds a new mount option, so that the mount command can specify the port# and avoid using rpcbind for NFSv3 mounts. The new option is called "mountport" since that is what Linux calls their mount option for the same semantics. PR: 282481 Reviewed by: delphij Tested by: Ronald Minnich <rminnich@gmail.com> MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D47743
This commit is contained in:
@@ -108,6 +108,7 @@ static u_char *fh = NULL;
|
|||||||
static int fhsize = 0;
|
static int fhsize = 0;
|
||||||
static int secflavor = -1;
|
static int secflavor = -1;
|
||||||
static int got_principal = 0;
|
static int got_principal = 0;
|
||||||
|
static in_port_t mntproto_port = 0;
|
||||||
|
|
||||||
static enum mountmode {
|
static enum mountmode {
|
||||||
ANY,
|
ANY,
|
||||||
@@ -360,6 +361,13 @@ main(int argc, char *argv[])
|
|||||||
softintr = true;
|
softintr = true;
|
||||||
} else if (strcmp(opt, "intr") == 0) {
|
} else if (strcmp(opt, "intr") == 0) {
|
||||||
softintr = true;
|
softintr = true;
|
||||||
|
} else if (strcmp(opt, "mountport") == 0) {
|
||||||
|
num = strtol(val, &p, 10);
|
||||||
|
if (*p || num <= 0 || num > IPPORT_MAX)
|
||||||
|
errx(1, "illegal port num -- "
|
||||||
|
"%s", val);
|
||||||
|
mntproto_port = num;
|
||||||
|
pass_flag_to_nmount=0;
|
||||||
}
|
}
|
||||||
if (pass_flag_to_nmount) {
|
if (pass_flag_to_nmount) {
|
||||||
build_iovec(&iov, &iovlen, opt,
|
build_iovec(&iov, &iovlen, opt,
|
||||||
@@ -900,11 +908,47 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
|||||||
return (TRYRET_SUCCESS);
|
return (TRYRET_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* malloc() and copy the address, so that it can be used for
|
||||||
|
* nfsargs below.
|
||||||
|
*/
|
||||||
|
addrlen = nfs_nb.len;
|
||||||
|
addr = malloc(addrlen);
|
||||||
|
if (addr == NULL)
|
||||||
|
err(1, "malloc");
|
||||||
|
bcopy(nfs_nb.buf, addr, addrlen);
|
||||||
|
|
||||||
/* Send the MOUNTPROC_MNT RPC to get the root filehandle. */
|
/* Send the MOUNTPROC_MNT RPC to get the root filehandle. */
|
||||||
try.tv_sec = 10;
|
try.tv_sec = 10;
|
||||||
try.tv_usec = 0;
|
try.tv_usec = 0;
|
||||||
clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt);
|
if (mntproto_port != 0) {
|
||||||
|
struct sockaddr *sad;
|
||||||
|
struct sockaddr_in *sin;
|
||||||
|
struct sockaddr_in6 *sin6;
|
||||||
|
|
||||||
|
sad = (struct sockaddr *)nfs_nb.buf;
|
||||||
|
switch (sad->sa_family) {
|
||||||
|
case AF_INET:
|
||||||
|
sin = (struct sockaddr_in *)nfs_nb.buf;
|
||||||
|
sin->sin_port = htons(mntproto_port);
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
sin6 = (struct sockaddr_in6 *)nfs_nb.buf;
|
||||||
|
sin6->sin6_port = htons(mntproto_port);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
snprintf(errbuf, sizeof(errbuf),
|
||||||
|
"Mnt port bad addr family %d\n", sad->sa_family);
|
||||||
|
return (TRYRET_LOCALERR);
|
||||||
|
}
|
||||||
|
clp = clnt_tli_create(RPC_ANYFD, nconf_mnt, &nfs_nb, MOUNTPROG,
|
||||||
|
mntvers, 0, 0);
|
||||||
|
} else {
|
||||||
|
/* Get the Mount protocol port# via rpcbind. */
|
||||||
|
clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt);
|
||||||
|
}
|
||||||
if (clp == NULL) {
|
if (clp == NULL) {
|
||||||
|
free(addr);
|
||||||
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt,
|
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt,
|
||||||
hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create"));
|
hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create"));
|
||||||
return (returncode(rpc_createerr.cf_stat,
|
return (returncode(rpc_createerr.cf_stat,
|
||||||
@@ -914,10 +958,10 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
|||||||
nfhret.auth = secflavor;
|
nfhret.auth = secflavor;
|
||||||
nfhret.vers = mntvers;
|
nfhret.vers = mntvers;
|
||||||
clntstat = clnt_call(clp, MOUNTPROC_MNT, (xdrproc_t)xdr_dir, spec,
|
clntstat = clnt_call(clp, MOUNTPROC_MNT, (xdrproc_t)xdr_dir, spec,
|
||||||
(xdrproc_t)xdr_fh, &nfhret,
|
(xdrproc_t)xdr_fh, &nfhret, try);
|
||||||
try);
|
|
||||||
auth_destroy(clp->cl_auth);
|
auth_destroy(clp->cl_auth);
|
||||||
if (clntstat != RPC_SUCCESS) {
|
if (clntstat != RPC_SUCCESS) {
|
||||||
|
free(addr);
|
||||||
if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
|
if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
|
||||||
clnt_destroy(clp);
|
clnt_destroy(clp);
|
||||||
trymntmode = V2;
|
trymntmode = V2;
|
||||||
@@ -932,6 +976,7 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
|||||||
clnt_destroy(clp);
|
clnt_destroy(clp);
|
||||||
|
|
||||||
if (nfhret.stat != 0) {
|
if (nfhret.stat != 0) {
|
||||||
|
free(addr);
|
||||||
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt,
|
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt,
|
||||||
hostp, spec, strerror(nfhret.stat));
|
hostp, spec, strerror(nfhret.stat));
|
||||||
return (TRYRET_REMOTEERR);
|
return (TRYRET_REMOTEERR);
|
||||||
@@ -941,13 +986,10 @@ nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr,
|
|||||||
* Store the filehandle and server address in nfsargsp, making
|
* Store the filehandle and server address in nfsargsp, making
|
||||||
* sure to copy any locally allocated structures.
|
* sure to copy any locally allocated structures.
|
||||||
*/
|
*/
|
||||||
addrlen = nfs_nb.len;
|
|
||||||
addr = malloc(addrlen);
|
|
||||||
fhsize = nfhret.fhsize;
|
fhsize = nfhret.fhsize;
|
||||||
fh = malloc(fhsize);
|
fh = malloc(fhsize);
|
||||||
if (addr == NULL || fh == NULL)
|
if (fh == NULL)
|
||||||
err(1, "malloc");
|
err(1, "malloc");
|
||||||
bcopy(nfs_nb.buf, addr, addrlen);
|
|
||||||
bcopy(nfhret.nfh, fh, fhsize);
|
bcopy(nfhret.nfh, fh, fhsize);
|
||||||
|
|
||||||
build_iovec(iov, iovlen, "addr", addr, addrlen);
|
build_iovec(iov, iovlen, "addr", addr, addrlen);
|
||||||
|
|||||||
Reference in New Issue
Block a user