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