- Back out the last (wrong) commit, and readd a modified version
of pingnfsserver(). The pingnfsport() function is now called everytime. If we don't get RPC_SUCCESS or RPC_PROGVERSMISMATCH back, there's something wrong with the NFS server and we just exit. - Fix cfs mount on IPv4-only machines - Fixed the looping when we did not run background mode. - Fixed a getnameinfo() call with uninitialized adress. This is a NetBSD bug I didn't notified :-( Thanks Ian ! - Added some #ifdef NFSKERB - Removed some unused variables. - Fixed idention - Remove unnecessary ":" in openlog ident Submitted by: Martin Blapp <mb@imp.ch> Reviewed by: Ian Dowse <iedowse@maths.tcd.ie>
This commit is contained in:
parent
7ea7bc591b
commit
deffdffafa
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=75046
@ -172,7 +172,7 @@ int retrycnt = DEF_RETRY;
|
||||
int opflags = 0;
|
||||
int nfsproto = IPPROTO_UDP;
|
||||
int mnttcp_ok = 1;
|
||||
char *port_no = "nfs";
|
||||
u_short port_no = 0;
|
||||
enum {
|
||||
ANY,
|
||||
V2,
|
||||
@ -199,6 +199,7 @@ int getnfsargs __P((char *, struct nfs_args *));
|
||||
void usage __P((void)) __dead2;
|
||||
int xdr_dir __P((XDR *, char *));
|
||||
int xdr_fh __P((XDR *, struct nfhret *));
|
||||
enum clnt_stat pingnfsport(int, struct netconfig *, struct netbuf *);
|
||||
|
||||
/*
|
||||
* Used to set mount flags with getmntopts. Call with dir=TRUE to
|
||||
@ -366,11 +367,8 @@ main(argc, argv)
|
||||
nfsargsp->sotype = SOCK_STREAM;
|
||||
nfsproto = IPPROTO_TCP;
|
||||
}
|
||||
if(altflags & ALTF_PORT) {
|
||||
port_no = strdup(strstr(optarg, "port=") + 5);
|
||||
if (port_no == NULL)
|
||||
err(1, NULL);
|
||||
}
|
||||
if(altflags & ALTF_PORT)
|
||||
port_no = atoi(strstr(optarg, "port=") + 5);
|
||||
mountmode = ANY;
|
||||
if(altflags & ALTF_NFSV2)
|
||||
mountmode = V2;
|
||||
@ -486,7 +484,7 @@ main(argc, argv)
|
||||
(void) close(STDERR_FILENO);
|
||||
(void) chdir("/");
|
||||
}
|
||||
openlog("mount_nfs:", LOG_PID, LOG_DAEMON);
|
||||
openlog("mount_nfs", LOG_PID, LOG_DAEMON);
|
||||
nfssvc_flag = NFSSVC_MNTD;
|
||||
ncd.ncd_dirp = mntpath;
|
||||
while (nfssvc(nfssvc_flag, (caddr_t)&ncd) < 0) {
|
||||
@ -585,7 +583,9 @@ getnfsargs(spec, nfsargsp)
|
||||
CLIENT *clp;
|
||||
struct addrinfo hints, *ai_nfs, *ai;
|
||||
int ecode;
|
||||
#ifdef NFSKERB
|
||||
char host[NI_MAXHOST], serv[NI_MAXSERV];
|
||||
#endif
|
||||
static struct netbuf nfs_nb;
|
||||
static struct sockaddr_storage nfs_ss;
|
||||
struct netconfig *nconf;
|
||||
@ -644,19 +644,21 @@ getnfsargs(spec, nfsargsp)
|
||||
memset(&hints, 0, sizeof hints);
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
hints.ai_socktype = nfsargsp->sotype;
|
||||
if (getaddrinfo(hostp, port_no, &hints, &ai_nfs) == 0) {
|
||||
if (getaddrinfo(hostp, "nfs", &hints, &ai_nfs) == 0) {
|
||||
#ifdef NFSKERB
|
||||
if ((nfsargsp->flags & NFSMNT_KERB)) {
|
||||
hints.ai_flags = 0;
|
||||
if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host,
|
||||
sizeof host, serv, sizeof serv, 0) != 0) {
|
||||
if (getnameinfo(ai_nfs->ai_addr, ai_nfs->ai_addrlen,
|
||||
host, sizeof host, serv, sizeof serv, 0) != 0) {
|
||||
warnx("can't reverse resolve net address");
|
||||
return (0);
|
||||
}
|
||||
hostp = host;
|
||||
}
|
||||
#endif /* NFSKERB */
|
||||
} else {
|
||||
hints.ai_flags = 0;
|
||||
if ((ecode = getaddrinfo(hostp, port_no, &hints, &ai_nfs)) != 0) {
|
||||
if ((ecode = getaddrinfo(hostp, "nfs", &hints, &ai_nfs)) != 0) {
|
||||
warnx("can't get net id for host/nfs: %s",
|
||||
gai_strerror(ecode));
|
||||
return (0);
|
||||
@ -673,15 +675,6 @@ getnfsargs(spec, nfsargsp)
|
||||
|
||||
orgcnt = retrycnt;
|
||||
|
||||
if (mountmode == ANY || mountmode == V3) {
|
||||
nfsvers = 3;
|
||||
mntvers = 3;
|
||||
nfsargsp->flags |= NFSMNT_NFSV3;
|
||||
} else {
|
||||
nfsvers = 2;
|
||||
mntvers = 1;
|
||||
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
||||
}
|
||||
nfhret.stat = EACCES; /* Mark not yet successful */
|
||||
ai = ai_nfs;
|
||||
while (ai != NULL) {
|
||||
@ -706,23 +699,73 @@ getnfsargs(spec, nfsargsp)
|
||||
tryagain:
|
||||
retrycnt = orgcnt;
|
||||
|
||||
if (mountmode == ANY || mountmode == V3) {
|
||||
nfsvers = 3;
|
||||
mntvers = 3;
|
||||
nfsargsp->flags |= NFSMNT_NFSV3;
|
||||
} else {
|
||||
nfsvers = 2;
|
||||
mntvers = 1;
|
||||
nfsargsp->flags &= ~NFSMNT_NFSV3;
|
||||
}
|
||||
while (retrycnt > 0) {
|
||||
if (port_no != 0) {
|
||||
if (ai_nfs->ai_family == AF_INET6) {
|
||||
((struct sockaddr_in6 *)ai_nfs->
|
||||
ai_addr)->sin6_port = htons(port_no);
|
||||
nfs_nb.len =
|
||||
sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
((struct sockaddr_in *)ai_nfs->
|
||||
ai_addr)->sin_port = htons(port_no);
|
||||
nfs_nb.len = sizeof(struct sockaddr_in);
|
||||
}
|
||||
memset(&nfs_ss, 0, sizeof(nfs_ss));
|
||||
memcpy(&nfs_ss, ai_nfs->ai_addr, nfs_nb.len);
|
||||
}
|
||||
nfs_nb.buf = &nfs_ss;
|
||||
nfs_nb.maxlen = sizeof nfs_ss;
|
||||
if (!rpcb_getaddr(RPCPROG_NFS, nfsvers, nconf,
|
||||
&nfs_nb, hostp)){
|
||||
if (rpc_createerr.cf_stat == RPC_SYSTEMERROR) {
|
||||
nfhret.stat = rpc_createerr.cf_error.re_errno;
|
||||
if (port_no == 0 && !rpcb_getaddr(RPCPROG_NFS,
|
||||
nfsvers, nconf, &nfs_nb, hostp)) {
|
||||
switch (rpc_createerr.cf_stat) {
|
||||
case RPC_SYSTEMERROR:
|
||||
nfhret.stat =
|
||||
rpc_createerr.cf_error.re_errno;
|
||||
break;
|
||||
}
|
||||
if (rpc_createerr.cf_stat == RPC_UNKNOWNPROTO) {
|
||||
case RPC_UNKNOWNPROTO:
|
||||
nfhret.stat = EPROTONOSUPPORT;
|
||||
break;
|
||||
case RPC_PROGVERSMISMATCH:
|
||||
if (mountmode == ANY) {
|
||||
mountmode = V2;
|
||||
goto tryagain;
|
||||
} else {
|
||||
errx(1,
|
||||
"can't contact NFS server");
|
||||
}
|
||||
default:
|
||||
}
|
||||
if ((opflags & ISBGRND) == 0)
|
||||
clnt_pcreateerror(
|
||||
"mount_nfs: rpcbind on server");
|
||||
}
|
||||
/*
|
||||
* Check if the nfs server supports this
|
||||
* version of the protocol we want to use.
|
||||
*/
|
||||
clnt_stat = pingnfsport(nfsvers, nconf, &nfs_nb);
|
||||
|
||||
if (clnt_stat == RPC_PROGVERSMISMATCH) {
|
||||
if (mountmode == ANY) {
|
||||
mountmode = V2;
|
||||
goto tryagain;
|
||||
} else {
|
||||
errx(1, "can't contact NFS server");
|
||||
}
|
||||
}
|
||||
if (clnt_stat != RPC_SUCCESS)
|
||||
errx(1, "can't contact NFS server");
|
||||
|
||||
pertry.tv_sec = 10;
|
||||
pertry.tv_usec = 0;
|
||||
/*
|
||||
@ -754,7 +797,8 @@ getnfsargs(spec, nfsargsp)
|
||||
goto tryagain;
|
||||
} else {
|
||||
errx(1, "%s",
|
||||
clnt_sperror(clp, "MNT RPC"));
|
||||
clnt_sperror(clp,
|
||||
"MNT RPC"));
|
||||
}
|
||||
}
|
||||
if ((opflags & ISBGRND) == 0)
|
||||
@ -784,10 +828,11 @@ getnfsargs(spec, nfsargsp)
|
||||
(void) close(STDERR_FILENO);
|
||||
(void) chdir("/");
|
||||
opflags |= ISBGRND;
|
||||
} else {
|
||||
exit (1);
|
||||
}
|
||||
sleep(60);
|
||||
}
|
||||
}
|
||||
if (nfhret.stat == 0)
|
||||
break;
|
||||
ai = ai->ai_next;
|
||||
@ -865,6 +910,39 @@ xdr_fh(xdrsp, np)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return RPC_SUCCESS if server responds on the port. We have to use
|
||||
* clnt_tli_create and then call the null proc of the nfs-server, to
|
||||
* be sure it works.
|
||||
*/
|
||||
enum clnt_stat
|
||||
pingnfsport(version, nconf, nfs_nb)
|
||||
int version;
|
||||
struct netconfig *nconf;
|
||||
struct netbuf *nfs_nb;
|
||||
{
|
||||
CLIENT *clp;
|
||||
enum clnt_stat stat;
|
||||
struct timeval try;
|
||||
int so = RPC_ANYSOCK;
|
||||
|
||||
clp = clnt_tli_create(so, nconf, nfs_nb, RPCPROG_NFS,
|
||||
version, 0, 0);
|
||||
|
||||
if (clp == NULL)
|
||||
return rpc_createerr.cf_stat;
|
||||
|
||||
try.tv_sec = 10;
|
||||
try.tv_usec = 0;
|
||||
|
||||
stat = clnt_call(clp, NFSPROC_NULL,
|
||||
xdr_void, NULL, xdr_void, NULL, try);
|
||||
|
||||
clnt_destroy(clp);
|
||||
|
||||
return stat;
|
||||
}
|
||||
|
||||
void
|
||||
usage()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user