1*d50c96bbSriastradh /* $NetBSD: netbsd32_nfssvc.c,v 1.8 2021/09/07 11:43:05 riastradh Exp $ */ 2fb961482Smrg 3fb961482Smrg /* 4fb961482Smrg * Copyright (c) 2015 Matthew R. Green 5fb961482Smrg * All rights reserved. 6fb961482Smrg * 7fb961482Smrg * Redistribution and use in source and binary forms, with or without 8fb961482Smrg * modification, are permitted provided that the following conditions 9fb961482Smrg * are met: 10fb961482Smrg * 1. Redistributions of source code must retain the above copyright 11fb961482Smrg * notice, this list of conditions and the following disclaimer. 12fb961482Smrg * 2. Redistributions in binary form must reproduce the above copyright 13fb961482Smrg * notice, this list of conditions and the following disclaimer in the 14fb961482Smrg * documentation and/or other materials provided with the distribution. 15fb961482Smrg * 3. The name of the author may not be used to endorse or promote products 16fb961482Smrg * derived from this software without specific prior written permission. 17fb961482Smrg * 18fb961482Smrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19fb961482Smrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20fb961482Smrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21fb961482Smrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22fb961482Smrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23fb961482Smrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24fb961482Smrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25fb961482Smrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26fb961482Smrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27fb961482Smrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28fb961482Smrg * SUCH DAMAGE. 29fb961482Smrg */ 30fb961482Smrg 31fb961482Smrg #include <sys/cdefs.h> 32*d50c96bbSriastradh __KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.8 2021/09/07 11:43:05 riastradh Exp $"); 33fb961482Smrg 34fb961482Smrg #if defined(_KERNEL_OPT) 35fb961482Smrg #include "opt_nfs.h" 36cc0095b0Sdholland #include "opt_nfsserver.h" 37fb961482Smrg #include "opt_compat_netbsd.h" 38fb961482Smrg #endif 39fb961482Smrg 40fb961482Smrg #include <sys/param.h> 41fb961482Smrg #include <sys/vnode.h> 42fb961482Smrg #include <sys/filedesc.h> 430f7d4fd6Spgoyette #include <sys/module.h> 440f7d4fd6Spgoyette #include <sys/syscallvar.h> 45fb961482Smrg 46fb961482Smrg #include <compat/netbsd32/netbsd32.h> 47fb961482Smrg #include <compat/netbsd32/netbsd32_syscall.h> 48fb961482Smrg #include <compat/netbsd32/netbsd32_syscallargs.h> 49fb961482Smrg #include <compat/netbsd32/netbsd32_conv.h> 50fb961482Smrg 51fb961482Smrg #include <nfs/rpcv2.h> 52fb961482Smrg #include <nfs/nfsproto.h> 53fb961482Smrg #include <nfs/nfs.h> 54fb961482Smrg #include <nfs/nfs_var.h> 55fb961482Smrg 56fb961482Smrg static int nfssvc32_addsock_in(struct nfsd_args *, const void *); 57fb961482Smrg static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *); 58fb961482Smrg static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *); 59fb961482Smrg static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *); 60fb961482Smrg static int nfssvc32_exp_in(struct export_args *, const void *, size_t); 61fb961482Smrg 62fb961482Smrg static int 63fb961482Smrg nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp) 64fb961482Smrg { 65fb961482Smrg struct netbsd32_nfsd_args args32; 66fb961482Smrg int error; 67fb961482Smrg 68fb961482Smrg error = copyin(argp, &args32, sizeof args32); 69fb961482Smrg if (!error) { 70fb961482Smrg nfsdarg->sock = args32.sock; 71fb961482Smrg nfsdarg->name = NETBSD32PTR64(args32.name); 72fb961482Smrg nfsdarg->namelen = args32.namelen; 73fb961482Smrg } 74fb961482Smrg 75fb961482Smrg return error; 76fb961482Smrg } 77fb961482Smrg 78fb961482Smrg static int 79fb961482Smrg nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp) 80fb961482Smrg { 81fb961482Smrg struct netbsd32_mountd_exports_list args32; 82fb961482Smrg int error; 83fb961482Smrg 84fb961482Smrg error = copyin(argp, &args32, sizeof args32); 85fb961482Smrg if (!error) { 86fb961482Smrg mel->mel_path = NETBSD32PTR64(args32.mel_path); 87fb961482Smrg mel->mel_nexports = args32.mel_nexports; 88fb961482Smrg mel->mel_exports = NETBSD32PTR64(args32.mel_exports); 89fb961482Smrg } 90fb961482Smrg 91fb961482Smrg return error; 92fb961482Smrg } 93fb961482Smrg 94fb961482Smrg static int 95fb961482Smrg nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp) 96fb961482Smrg { 97fb961482Smrg struct netbsd32_nfsd_srvargs args32; 98fb961482Smrg int error; 99fb961482Smrg 100fb961482Smrg error = copyin(argp, &args32, sizeof args32); 101fb961482Smrg if (!error) { 102fb961482Smrg nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd); 103fb961482Smrg nsd->nsd_uid = args32.nsd_uid; 104fb961482Smrg nsd->nsd_haddr = args32.nsd_haddr; 105fb961482Smrg nsd->nsd_cr = args32.nsd_cr; 106fb961482Smrg nsd->nsd_authlen = args32.nsd_authlen; 107fb961482Smrg nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr); 108fb961482Smrg nsd->nsd_verflen = args32.nsd_verflen; 109fb961482Smrg nsd->nsd_uid = args32.nsd_uid; 110fb961482Smrg netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp); 111fb961482Smrg nsd->nsd_ttl = args32.nsd_ttl; 112fb961482Smrg nsd->nsd_key[0] = args32.nsd_key[0]; 113fb961482Smrg nsd->nsd_key[1] = args32.nsd_key[1]; 114fb961482Smrg } 115fb961482Smrg 116fb961482Smrg return error; 117fb961482Smrg } 118fb961482Smrg 119fb961482Smrg static int 120fb961482Smrg nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd) 121fb961482Smrg { 122fb961482Smrg struct netbsd32_nfsd_srvargs args32; 123fb961482Smrg 124*d50c96bbSriastradh memset(&args32, 0, sizeof(args32)); 125fb961482Smrg NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd); 126fb961482Smrg args32.nsd_uid = nsd->nsd_uid; 127fb961482Smrg args32.nsd_haddr = nsd->nsd_haddr; 128fb961482Smrg args32.nsd_cr = nsd->nsd_cr; 129fb961482Smrg args32.nsd_authlen = nsd->nsd_authlen; 130fb961482Smrg NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr); 131fb961482Smrg args32.nsd_verflen = nsd->nsd_verflen; 132fb961482Smrg args32.nsd_uid = nsd->nsd_uid; 133fb961482Smrg netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp); 134fb961482Smrg args32.nsd_ttl = nsd->nsd_ttl; 135fb961482Smrg args32.nsd_key[0] = nsd->nsd_key[0]; 136fb961482Smrg args32.nsd_key[1] = nsd->nsd_key[1]; 137fb961482Smrg 138d1e24b8fSriastradh return copyout(&args32, argp, sizeof args32); 139fb961482Smrg } 140fb961482Smrg 141fb961482Smrg static int 142fb961482Smrg nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports) 143fb961482Smrg { 144face296eSmrg struct netbsd32_export_args exp32; 145face296eSmrg struct netbsd32_export_args const *argp32 = argp; 146fb961482Smrg int error = 0; 147fb961482Smrg 148fb961482Smrg for (size_t i = 0; i < nexports; i++) { 149face296eSmrg error = copyin(argp32, &exp32, sizeof exp32); 150fb961482Smrg if (error) 151fb961482Smrg break; 152face296eSmrg exp->ex_flags = exp32.ex_flags; 153face296eSmrg exp->ex_root = exp32.ex_root; 154face296eSmrg exp->ex_anon = exp32.ex_anon; 155face296eSmrg exp->ex_addr = NETBSD32PTR64(exp32.ex_addr); 156face296eSmrg exp->ex_addrlen = exp32.ex_addrlen; 157face296eSmrg exp->ex_mask = NETBSD32PTR64(exp32.ex_mask); 158face296eSmrg exp->ex_masklen = exp32.ex_masklen; 159face296eSmrg exp->ex_indexfile = NETBSD32PTR64(exp32.ex_indexfile); 160fb961482Smrg exp++; 161face296eSmrg argp32++; 162fb961482Smrg } 163fb961482Smrg 164fb961482Smrg return error; 165fb961482Smrg } 166fb961482Smrg 167fb961482Smrg /* 168fb961482Smrg * NFS server system calls 169fb961482Smrg */ 170fb961482Smrg 171fb961482Smrg static struct nfssvc_copy_ops netbsd32_ops = { 172fb961482Smrg .addsock_in = nfssvc32_addsock_in, 173fb961482Smrg .setexports_in = nfssvc32_setexports_in, 174fb961482Smrg .nsd_in = nfssvc32_nsd_in, 175fb961482Smrg .nsd_out = nfssvc32_nsd_out, 176fb961482Smrg .exp_in = nfssvc32_exp_in, 177fb961482Smrg }; 178fb961482Smrg 179fb961482Smrg int 180fb961482Smrg netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap, 181fb961482Smrg register_t *retval) 182fb961482Smrg { 183fb961482Smrg /* { 184fb961482Smrg syscallarg(int) flag; 185fb961482Smrg syscallarg(netbsd32_voidp *) argp; 186fb961482Smrg } */ 187fb961482Smrg int flag = SCARG(uap, flag); 188fb961482Smrg void *argp = SCARG_P32(uap, argp); 189fb961482Smrg 190fb961482Smrg return do_nfssvc(&netbsd32_ops, l, flag, argp, retval); 191fb961482Smrg } 1920f7d4fd6Spgoyette 1930f7d4fd6Spgoyette static const struct syscall_package compat_nfssvc_syscalls[] = { 1940f7d4fd6Spgoyette { NETBSD32_SYS_netbsd32_nfssvc, 0, (sy_call_t *)netbsd32_nfssvc }, 1950f7d4fd6Spgoyette { 0, 0, NULL }, 1960f7d4fd6Spgoyette }; 1970f7d4fd6Spgoyette 1980f7d4fd6Spgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_nfssrv, "nfsserver,compat_netbsd32"); 1990f7d4fd6Spgoyette 2000f7d4fd6Spgoyette static int 2010f7d4fd6Spgoyette compat_netbsd32_nfssrv_modcmd(modcmd_t cmd, void *arg) 2020f7d4fd6Spgoyette { 2030f7d4fd6Spgoyette int error; 2040f7d4fd6Spgoyette 2050f7d4fd6Spgoyette switch (cmd) { 2060f7d4fd6Spgoyette case MODULE_CMD_INIT: 2070f7d4fd6Spgoyette error = syscall_establish(&emul_netbsd32, 2080f7d4fd6Spgoyette compat_nfssvc_syscalls); 2090f7d4fd6Spgoyette break; 2100f7d4fd6Spgoyette case MODULE_CMD_FINI: 2110f7d4fd6Spgoyette error = syscall_disestablish(&emul_netbsd32, 2120f7d4fd6Spgoyette compat_nfssvc_syscalls); 2130f7d4fd6Spgoyette break; 2140f7d4fd6Spgoyette default: 2150f7d4fd6Spgoyette error = ENOTTY; 2160f7d4fd6Spgoyette break; 2170f7d4fd6Spgoyette } 2180f7d4fd6Spgoyette return error; 2190f7d4fd6Spgoyette } 220