Add INET6 support for the upcalls to the nfsuserd daemon.

The kernel code uses UDP to do upcalls to the nfsuserd(8) daemon to get
updates to the username<->uid and groupname<->gid mappings.
A change to AF_LOCAL last year had to be reverted, since it could result
in vnode locking issues on the AF_LOCAL socket.
This patch adds INET6 support and the required #ifdef INET and INET6
to the code.

Requested by:	bz
PR:		205193
Reviewed by:	bz, rgrimes
MFC after:	2 weeks
Differential Revision:	http://reviews.freebsd.org/D19218
This commit is contained in:
Rick Macklem 2019-04-06 21:53:46 +00:00
parent 04f9afae18
commit 80405bcf79
4 changed files with 57 additions and 13 deletions

View File

@ -252,6 +252,11 @@ struct nfsd_oidargs {
int nid_namelen; /* and its length */
};
struct nfsuserd_args {
sa_family_t nuserd_family; /* Address family to use */
u_short nuserd_port; /* Port# */
};
struct nfsd_clid {
int nclid_idlen; /* Length of client id */
u_char nclid_id[NFSV4_OPAQUELIMIT]; /* and name */

View File

@ -631,14 +631,24 @@ nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
goto out;
} else if (uap->flag & NFSSVC_NFSUSERDPORT) {
u_short sockport;
struct nfsuserd_args nargs;
if ((uap->flag & NFSSVC_NEWSTRUCT) == 0)
if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) {
error = copyin(uap->argp, (caddr_t)&sockport,
sizeof (u_short));
else
error = ENXIO;
if (error == 0) {
nargs.nuserd_family = AF_INET;
nargs.nuserd_port = sockport;
}
} else {
/*
* New nfsuserd_args structure, which indicates
* which IP version to use along with the port#.
*/
error = copyin(uap->argp, &nargs, sizeof(nargs));
}
if (!error)
error = nfsrv_nfsuserdport(sockport, p);
error = nfsrv_nfsuserdport(&nargs, p);
} else if (uap->flag & NFSSVC_NFSUSERDDELPORT) {
nfsrv_nfsuserddelport();
error = 0;

View File

@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
* copy data between mbuf chains and uio lists.
*/
#ifndef APPLEKEXT
#include "opt_inet.h"
#include "opt_inet6.h"
#include <fs/nfs/nfsport.h>
@ -3504,10 +3505,16 @@ nfsrv_cmpmixedcase(u_char *cp, u_char *cp2, int len)
* Set the port for the nfsuserd.
*/
APPLESTATIC int
nfsrv_nfsuserdport(u_short port, NFSPROC_T *p)
nfsrv_nfsuserdport(struct nfsuserd_args *nargs, NFSPROC_T *p)
{
struct nfssockreq *rp;
#ifdef INET
struct sockaddr_in *ad;
#endif
#ifdef INET6
struct sockaddr_in6 *ad6;
const struct in6_addr in6loopback = IN6ADDR_LOOPBACK_INIT;
#endif
int error;
NFSLOCKNAMEID();
@ -3527,15 +3534,37 @@ nfsrv_nfsuserdport(u_short port, NFSPROC_T *p)
rp->nr_soproto = IPPROTO_UDP;
rp->nr_lock = (NFSR_RESERVEDPORT | NFSR_LOCALHOST);
rp->nr_cred = NULL;
rp->nr_nam = malloc(sizeof(*rp->nr_nam), M_SONAME, M_WAITOK | M_ZERO);
NFSSOCKADDRSIZE(rp->nr_nam, sizeof (struct sockaddr_in));
ad = NFSSOCKADDR(rp->nr_nam, struct sockaddr_in *);
ad->sin_family = AF_INET;
ad->sin_addr.s_addr = htonl((u_int32_t)0x7f000001); /* 127.0.0.1 */
ad->sin_port = port;
rp->nr_prog = RPCPROG_NFSUSERD;
error = 0;
switch (nargs->nuserd_family) {
#ifdef INET
case AF_INET:
rp->nr_nam = malloc(sizeof(struct sockaddr_in), M_SONAME,
M_WAITOK | M_ZERO);
ad = (struct sockaddr_in *)rp->nr_nam;
ad->sin_len = sizeof(struct sockaddr_in);
ad->sin_family = AF_INET;
ad->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
ad->sin_port = nargs->nuserd_port;
break;
#endif
#ifdef INET6
case AF_INET6:
rp->nr_nam = malloc(sizeof(struct sockaddr_in6), M_SONAME,
M_WAITOK | M_ZERO);
ad6 = (struct sockaddr_in6 *)rp->nr_nam;
ad6->sin6_len = sizeof(struct sockaddr_in6);
ad6->sin6_family = AF_INET6;
ad6->sin6_addr = in6loopback;
ad6->sin6_port = nargs->nuserd_port;
break;
#endif
default:
error = ENXIO;
}
rp->nr_vers = RPCNFSUSERD_VERS;
error = newnfs_connect(NULL, rp, NFSPROCCRED(p), p, 0);
if (error == 0)
error = newnfs_connect(NULL, rp, NFSPROCCRED(p), p, 0);
if (error) {
free(rp->nr_nam, M_SONAME);
nfsrv_nfsuserd = 0;

View File

@ -136,7 +136,7 @@ int nfsrv_checksetattr(vnode_t, struct nfsrv_descript *,
NFSPROC_T *);
int nfsrv_checkgetattr(struct nfsrv_descript *, vnode_t,
struct nfsvattr *, nfsattrbit_t *, NFSPROC_T *);
int nfsrv_nfsuserdport(u_short, NFSPROC_T *);
int nfsrv_nfsuserdport(struct nfsuserd_args *, NFSPROC_T *);
void nfsrv_nfsuserddelport(void);
void nfsrv_throwawayallstate(NFSPROC_T *);
int nfsrv_checksequence(struct nfsrv_descript *, uint32_t, uint32_t *,