Date: Sat, 20 Apr 2019 23:46:06 +0000 (UTC) From: Rick Macklem <rmacklem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r346460 - in stable/12/sys: fs/nfs modules/nfscommon Message-ID: <201904202346.x3KNk6br094271@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rmacklem Date: Sat Apr 20 23:46:06 2019 New Revision: 346460 URL: https://svnweb.freebsd.org/changeset/base/346460 Log: MFC: r345992, r346087 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. This patch also reverts the unused AF_LOCAL socket code. Modified: stable/12/sys/fs/nfs/nfs.h stable/12/sys/fs/nfs/nfs_commonport.c stable/12/sys/fs/nfs/nfs_commonsubs.c stable/12/sys/fs/nfs/nfs_var.h stable/12/sys/modules/nfscommon/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/fs/nfs/nfs.h ============================================================================== --- stable/12/sys/fs/nfs/nfs.h Sat Apr 20 23:18:19 2019 (r346459) +++ stable/12/sys/fs/nfs/nfs.h Sat Apr 20 23:46:06 2019 (r346460) @@ -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 */ Modified: stable/12/sys/fs/nfs/nfs_commonport.c ============================================================================== --- stable/12/sys/fs/nfs/nfs_commonport.c Sat Apr 20 23:18:19 2019 (r346459) +++ stable/12/sys/fs/nfs/nfs_commonport.c Sat Apr 20 23:46:06 2019 (r346460) @@ -631,30 +631,24 @@ nfssvc_call(struct thread *p, struct nfssvc_args *uap, goto out; } else if (uap->flag & NFSSVC_NFSUSERDPORT) { u_short sockport; - struct sockaddr *sad; - struct sockaddr_un *sun; + struct nfsuserd_args nargs; - if ((uap->flag & NFSSVC_NEWSTRUCT) != 0) { - /* New nfsuserd using an AF_LOCAL socket. */ - sun = malloc(sizeof(struct sockaddr_un), M_SONAME, - M_WAITOK | M_ZERO); - error = copyinstr(uap->argp, sun->sun_path, - sizeof(sun->sun_path), NULL); - if (error != 0) { - free(sun, M_SONAME); - return (error); - } - sun->sun_family = AF_LOCAL; - sun->sun_len = SUN_LEN(sun); - sockport = 0; - sad = (struct sockaddr *)sun; - } else { + if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) { error = copyin(uap->argp, (caddr_t)&sockport, sizeof (u_short)); - sad = NULL; + 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 == 0) - error = nfsrv_nfsuserdport(sad, sockport, p); + if (!error) + error = nfsrv_nfsuserdport(&nargs, p); } else if (uap->flag & NFSSVC_NFSUSERDDELPORT) { nfsrv_nfsuserddelport(); error = 0; Modified: stable/12/sys/fs/nfs/nfs_commonsubs.c ============================================================================== --- stable/12/sys/fs/nfs/nfs_commonsubs.c Sat Apr 20 23:18:19 2019 (r346459) +++ stable/12/sys/fs/nfs/nfs_commonsubs.c Sat Apr 20 23:46:06 2019 (r346460) @@ -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> @@ -3510,17 +3511,22 @@ nfsrv_cmpmixedcase(u_char *cp, u_char *cp2, int len) * Set the port for the nfsuserd. */ APPLESTATIC int -nfsrv_nfsuserdport(struct sockaddr *sad, 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(); if (nfsrv_nfsuserd) { NFSUNLOCKNAMEID(); error = EPERM; - free(sad, M_SONAME); goto out; } nfsrv_nfsuserd = 1; @@ -3530,28 +3536,41 @@ nfsrv_nfsuserdport(struct sockaddr *sad, u_short port, */ rp = &nfsrv_nfsuserdsock; rp->nr_client = NULL; - rp->nr_cred = NULL; + rp->nr_sotype = SOCK_DGRAM; + rp->nr_soproto = IPPROTO_UDP; rp->nr_lock = (NFSR_RESERVEDPORT | NFSR_LOCALHOST); - if (sad != NULL) { - /* Use the AF_LOCAL socket address passed in. */ - rp->nr_sotype = SOCK_STREAM; - rp->nr_soproto = 0; - rp->nr_nam = sad; - } else { - /* Use the port# for a UDP socket (old nfsuserd). */ - rp->nr_sotype = SOCK_DGRAM; - rp->nr_soproto = IPPROTO_UDP; - 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); - ad->sin_port = port; - } + rp->nr_cred = NULL; 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; Modified: stable/12/sys/fs/nfs/nfs_var.h ============================================================================== --- stable/12/sys/fs/nfs/nfs_var.h Sat Apr 20 23:18:19 2019 (r346459) +++ stable/12/sys/fs/nfs/nfs_var.h Sat Apr 20 23:46:06 2019 (r346460) @@ -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(struct sockaddr *, 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 *, Modified: stable/12/sys/modules/nfscommon/Makefile ============================================================================== --- stable/12/sys/modules/nfscommon/Makefile Sat Apr 20 23:18:19 2019 (r346459) +++ stable/12/sys/modules/nfscommon/Makefile Sat Apr 20 23:46:06 2019 (r346460) @@ -7,6 +7,7 @@ SRCS= vnode_if.h \ nfs_commonkrpc.c \ nfs_commonport.c \ nfs_commonsubs.c \ + opt_inet.h \ opt_inet6.h \ opt_kgssapi.h \ opt_nfs.h \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904202346.x3KNk6br094271>