| @@ -1,1851 +1,1892 @@ | | | @@ -1,1851 +1,1892 @@ |
1 | /* $NetBSD: svr4_stream.c,v 1.79 2011/06/26 16:42:41 christos Exp $ */ | | 1 | /* $NetBSD: svr4_stream.c,v 1.79.22.1 2017/08/19 03:40:48 snj Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Pretend that we have streams... | | 33 | * Pretend that we have streams... |
34 | * Yes, this is gross. | | 34 | * Yes, this is gross. |
35 | * | | 35 | * |
36 | * ToDo: The state machine for getmsg needs re-thinking | | 36 | * ToDo: The state machine for getmsg needs re-thinking |
37 | * | | 37 | * |
38 | * The svr4_32 version is built from this file as well. | | 38 | * The svr4_32 version is built from this file as well. |
39 | */ | | 39 | */ |
40 | | | 40 | |
41 | #include <sys/cdefs.h> | | 41 | #include <sys/cdefs.h> |
42 | __KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.79 2011/06/26 16:42:41 christos Exp $"); | | 42 | __KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.79.22.1 2017/08/19 03:40:48 snj Exp $"); |
43 | | | 43 | |
44 | #include <sys/param.h> | | 44 | #include <sys/param.h> |
45 | #include <sys/kernel.h> | | 45 | #include <sys/kernel.h> |
46 | #include <sys/systm.h> | | 46 | #include <sys/systm.h> |
47 | #include <sys/buf.h> | | 47 | #include <sys/buf.h> |
48 | #include <sys/malloc.h> | | 48 | #include <sys/malloc.h> |
49 | #include <sys/ioctl.h> | | 49 | #include <sys/ioctl.h> |
50 | #include <sys/tty.h> | | 50 | #include <sys/tty.h> |
51 | #include <sys/file.h> | | 51 | #include <sys/file.h> |
52 | #include <sys/filedesc.h> | | 52 | #include <sys/filedesc.h> |
53 | #include <sys/namei.h> | | 53 | #include <sys/namei.h> |
54 | #include <sys/select.h> | | 54 | #include <sys/select.h> |
55 | #include <sys/socket.h> | | 55 | #include <sys/socket.h> |
56 | #include <sys/socketvar.h> | | 56 | #include <sys/socketvar.h> |
57 | #include <sys/protosw.h> | | 57 | #include <sys/protosw.h> |
58 | #include <sys/un.h> | | 58 | #include <sys/un.h> |
59 | #include <net/if.h> | | 59 | #include <net/if.h> |
60 | #include <netinet/in.h> | | 60 | #include <netinet/in.h> |
61 | #include <sys/mbuf.h> | | 61 | #include <sys/mbuf.h> |
62 | #include <sys/mount.h> | | 62 | #include <sys/mount.h> |
63 | #include <sys/proc.h> | | 63 | #include <sys/proc.h> |
64 | #include <sys/vfs_syscalls.h> | | 64 | #include <sys/vfs_syscalls.h> |
65 | #include <sys/vnode.h> | | 65 | #include <sys/vnode.h> |
66 | #include <sys/device.h> | | 66 | #include <sys/device.h> |
67 | #include <sys/stat.h> | | 67 | #include <sys/stat.h> |
68 | | | 68 | |
69 | #include <sys/syscallargs.h> | | 69 | #include <sys/syscallargs.h> |
70 | | | 70 | |
71 | #ifndef SVR4_32 | | 71 | #ifndef SVR4_32 |
72 | #define compat(name) <compat/svr4/svr4_##name> | | 72 | #define compat(name) <compat/svr4/svr4_##name> |
73 | #else | | 73 | #else |
74 | #define compat(name) <compat/svr4_32/svr4_32_##name> | | 74 | #define compat(name) <compat/svr4_32/svr4_32_##name> |
75 | #endif | | 75 | #endif |
76 | | | 76 | |
77 | #include compat(types.h) | | 77 | #include compat(types.h) |
78 | #include compat(util.h) | | 78 | #include compat(util.h) |
79 | #include compat(signal.h) | | 79 | #include compat(signal.h) |
80 | #include compat(lwp.h) | | 80 | #include compat(lwp.h) |
81 | #include compat(ucontext.h) | | 81 | #include compat(ucontext.h) |
82 | #include compat(syscallargs.h) | | 82 | #include compat(syscallargs.h) |
83 | #include compat(stropts.h) | | 83 | #include compat(stropts.h) |
84 | #include compat(timod.h) | | 84 | #include compat(timod.h) |
85 | #include <compat/svr4/svr4_sockmod.h> | | 85 | #include <compat/svr4/svr4_sockmod.h> |
86 | #include compat(ioctl.h) | | 86 | #include compat(ioctl.h) |
87 | #include compat(socket.h) | | 87 | #include compat(socket.h) |
88 | | | 88 | |
89 | #undef compat | | 89 | #undef compat |
90 | | | 90 | |
91 | #ifndef SVR4_32 | | 91 | #ifndef SVR4_32 |
92 | | | 92 | |
93 | #define SCARG_PTR(uap, arg) SCARG(uap, arg) | | 93 | #define SCARG_PTR(uap, arg) SCARG(uap, arg) |
94 | #define NETBSD32PTR(ptr) (ptr) | | 94 | #define NETBSD32PTR(ptr) (ptr) |
95 | | | 95 | |
96 | #else | | 96 | #else |
97 | | | 97 | |
98 | #define SCARG_PTR(uap, arg) SCARG_P32(uap, arg) | | 98 | #define SCARG_PTR(uap, arg) SCARG_P32(uap, arg) |
99 | #define NETBSD32PTR(ptr) NETBSD32PTR64(ptr) | | 99 | #define NETBSD32PTR(ptr) NETBSD32PTR64(ptr) |
100 | | | 100 | |
101 | /* Rename stuff that is different for the svr4_32 build */ | | 101 | /* Rename stuff that is different for the svr4_32 build */ |
102 | #define svr4_infocmd svr4_32_infocmd | | 102 | #define svr4_infocmd svr4_32_infocmd |
103 | #define svr4_ino_t svr4_32_ino_t | | 103 | #define svr4_ino_t svr4_32_ino_t |
104 | #define svr4_netaddr_in svr4_32_netaddr_in | | 104 | #define svr4_netaddr_in svr4_32_netaddr_in |
105 | #define svr4_netaddr_un svr4_32_netaddr_un | | 105 | #define svr4_netaddr_un svr4_32_netaddr_un |
106 | #define svr4_strbuf svr4_32_strbuf | | 106 | #define svr4_strbuf svr4_32_strbuf |
107 | #define svr4_stream_get svr4_32_stream_get | | 107 | #define svr4_stream_get svr4_32_stream_get |
108 | #define svr4_stream_ioctl svr4_32_stream_ioctl | | 108 | #define svr4_stream_ioctl svr4_32_stream_ioctl |
109 | #define svr4_stream_ti_ioctl svr4_32_stream_ti_ioctl | | 109 | #define svr4_stream_ti_ioctl svr4_32_stream_ti_ioctl |
110 | #define svr4_strfdinsert svr4_32_strfdinsert | | 110 | #define svr4_strfdinsert svr4_32_strfdinsert |
111 | #define svr4_strioctl svr4_32_strioctl | | 111 | #define svr4_strioctl svr4_32_strioctl |
112 | #define svr4_strmcmd svr4_32_strmcmd | | 112 | #define svr4_strmcmd svr4_32_strmcmd |
113 | #define svr4_sys_getmsg svr4_32_sys_getmsg | | 113 | #define svr4_sys_getmsg svr4_32_sys_getmsg |
114 | #define svr4_sys_getmsg_args svr4_32_sys_getmsg_args | | 114 | #define svr4_sys_getmsg_args svr4_32_sys_getmsg_args |
115 | #define svr4_sys_putmsg svr4_32_sys_putmsg | | 115 | #define svr4_sys_putmsg svr4_32_sys_putmsg |
116 | #define svr4_sys_putmsg_args svr4_32_sys_putmsg_args | | 116 | #define svr4_sys_putmsg_args svr4_32_sys_putmsg_args |
117 | | | 117 | |
118 | #endif /* SVR4_32 */ | | 118 | #endif /* SVR4_32 */ |
119 | | | 119 | |
120 | /* Utils */ | | 120 | /* Utils */ |
121 | static int clean_pipe(struct lwp *, const char *); | | 121 | static int clean_pipe(struct lwp *, const char *); |
122 | static void getparm(file_t *, struct svr4_si_sockparms *); | | 122 | static void getparm(file_t *, struct svr4_si_sockparms *); |
123 | | | 123 | |
124 | /* Address Conversions */ | | 124 | /* Address Conversions */ |
125 | static void sockaddr_to_netaddr_in(struct svr4_strmcmd *, | | 125 | static void sockaddr_to_netaddr_in(struct svr4_strmcmd *, |
126 | const struct sockaddr_in *); | | 126 | const struct sockaddr_in *); |
127 | static void sockaddr_to_netaddr_un(struct svr4_strmcmd *, | | 127 | static void sockaddr_to_netaddr_un(struct svr4_strmcmd *, |
128 | const struct sockaddr_un *); | | 128 | const struct sockaddr_un *); |
129 | static void netaddr_to_sockaddr_in(struct sockaddr_in *, | | 129 | static void netaddr_to_sockaddr_in(struct sockaddr_in *, |
130 | const struct svr4_strmcmd *); | | 130 | const struct svr4_strmcmd *); |
131 | static void netaddr_to_sockaddr_un(struct sockaddr_un *, | | 131 | static void netaddr_to_sockaddr_un(struct sockaddr_un *, |
132 | const struct svr4_strmcmd *); | | 132 | const struct svr4_strmcmd *); |
133 | | | 133 | |
134 | /* stream ioctls */ | | 134 | /* stream ioctls */ |
135 | static int i_nread(file_t *, struct lwp *, register_t *, int, | | 135 | static int i_nread(file_t *, struct lwp *, register_t *, int, |
136 | u_long, void *); | | 136 | u_long, void *); |
137 | static int i_fdinsert(file_t *, struct lwp *, register_t *, int, | | 137 | static int i_fdinsert(file_t *, struct lwp *, register_t *, int, |
138 | u_long, void *); | | 138 | u_long, void *); |
139 | static int i_str(file_t *, struct lwp *, register_t *, int, | | 139 | static int i_str(file_t *, struct lwp *, register_t *, int, |
140 | u_long, void *); | | 140 | u_long, void *); |
141 | static int i_setsig(file_t *, struct lwp *, register_t *, int, | | 141 | static int i_setsig(file_t *, struct lwp *, register_t *, int, |
142 | u_long, void *); | | 142 | u_long, void *); |
143 | static int i_getsig(file_t *, struct lwp *, register_t *, int, | | 143 | static int i_getsig(file_t *, struct lwp *, register_t *, int, |
144 | u_long, void *); | | 144 | u_long, void *); |
145 | static int _i_bind_rsvd(file_t *, struct lwp *, register_t *, int, | | 145 | static int _i_bind_rsvd(file_t *, struct lwp *, register_t *, int, |
146 | u_long, void *); | | 146 | u_long, void *); |
147 | static int _i_rele_rsvd(file_t *, struct lwp *, register_t *, int, | | 147 | static int _i_rele_rsvd(file_t *, struct lwp *, register_t *, int, |
148 | u_long, void *); | | 148 | u_long, void *); |
149 | | | 149 | |
150 | /* i_str sockmod calls */ | | 150 | /* i_str sockmod calls */ |
151 | static int sockmod(file_t *, int, struct svr4_strioctl *, | | 151 | static int sockmod(file_t *, int, struct svr4_strioctl *, |
152 | struct lwp *); | | 152 | struct lwp *); |
153 | static int si_listen(file_t *, int, struct svr4_strioctl *, | | 153 | static int si_listen(file_t *, int, struct svr4_strioctl *, |
154 | struct lwp *); | | 154 | struct lwp *); |
155 | static int si_ogetudata(file_t *, int, struct svr4_strioctl *, | | 155 | static int si_ogetudata(file_t *, int, struct svr4_strioctl *, |
156 | struct lwp *); | | 156 | struct lwp *); |
157 | static int si_sockparams(file_t *, int, struct svr4_strioctl *, | | 157 | static int si_sockparams(file_t *, int, struct svr4_strioctl *, |
158 | struct lwp *); | | 158 | struct lwp *); |
159 | static int si_shutdown(file_t *, int, struct svr4_strioctl *, | | 159 | static int si_shutdown(file_t *, int, struct svr4_strioctl *, |
160 | struct lwp *); | | 160 | struct lwp *); |
161 | static int si_getudata(file_t *, int, struct svr4_strioctl *, | | 161 | static int si_getudata(file_t *, int, struct svr4_strioctl *, |
162 | struct lwp *); | | 162 | struct lwp *); |
163 | | | 163 | |
164 | /* i_str timod calls */ | | 164 | /* i_str timod calls */ |
165 | static int timod(file_t *, int, struct svr4_strioctl *, | | 165 | static int timod(file_t *, int, struct svr4_strioctl *, |
166 | struct lwp *); | | 166 | struct lwp *); |
167 | static int ti_getinfo(file_t *, int, struct svr4_strioctl *, | | 167 | static int ti_getinfo(file_t *, int, struct svr4_strioctl *, |
168 | struct lwp *); | | 168 | struct lwp *); |
169 | static int ti_bind(file_t *, int, struct svr4_strioctl *, | | 169 | static int ti_bind(file_t *, int, struct svr4_strioctl *, |
170 | struct lwp *); | | 170 | struct lwp *); |
171 | | | 171 | |
172 | #ifdef DEBUG_SVR4 | | 172 | #ifdef DEBUG_SVR4 |
173 | static void bufprint(u_char *, size_t); | | 173 | static void bufprint(u_char *, size_t); |
174 | static int show_ioc(const char *, struct svr4_strioctl *); | | 174 | static int show_ioc(const char *, struct svr4_strioctl *); |
175 | static int show_strbuf(struct svr4_strbuf *); | | 175 | static int show_strbuf(struct svr4_strbuf *); |
176 | static void show_msg(const char *, int, struct svr4_strbuf *, | | 176 | static void show_msg(const char *, int, struct svr4_strbuf *, |
177 | struct svr4_strbuf *, int); | | 177 | struct svr4_strbuf *, int); |
178 | | | 178 | |
179 | static void | | 179 | static void |
180 | bufprint(u_char *buf, size_t len) | | 180 | bufprint(u_char *buf, size_t len) |
181 | { | | 181 | { |
182 | size_t i; | | 182 | size_t i; |
183 | | | 183 | |
184 | uprintf("\n\t"); | | 184 | uprintf("\n\t"); |
185 | for (i = 0; i < len; i++) { | | 185 | for (i = 0; i < len; i++) { |
186 | uprintf("%x ", buf[i]); | | 186 | uprintf("%x ", buf[i]); |
187 | if (i && (i % 16) == 0) | | 187 | if (i && (i % 16) == 0) |
188 | uprintf("\n\t"); | | 188 | uprintf("\n\t"); |
189 | } | | 189 | } |
190 | } | | 190 | } |
191 | | | 191 | |
192 | static int | | 192 | static int |
193 | show_ioc(const char *str, struct svr4_strioctl *ioc) | | 193 | show_ioc(const char *str, struct svr4_strioctl *ioc) |
194 | { | | 194 | { |
195 | u_char *ptr; | | 195 | u_char *ptr; |
196 | int error, len; | | 196 | int error, len; |
197 | | | 197 | |
198 | len = ioc->len; | | 198 | len = ioc->len; |
199 | if (len > 1024) | | 199 | if (len > 1024) |
200 | len = 1024; | | 200 | len = 1024; |
201 | | | 201 | |
202 | ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); | | 202 | ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); |
203 | uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ", | | 203 | uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ", |
204 | str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf); | | 204 | str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf); |
205 | | | 205 | |
206 | if ((error = copyin(ioc->buf, ptr, len)) != 0) { | | 206 | if ((error = copyin(ioc->buf, ptr, len)) != 0) { |
207 | free((char *) ptr, M_TEMP); | | 207 | free((char *) ptr, M_TEMP); |
208 | return error; | | 208 | return error; |
209 | } | | 209 | } |
210 | | | 210 | |
211 | bufprint(ptr, len); | | 211 | bufprint(ptr, len); |
212 | | | 212 | |
213 | uprintf("}\n"); | | 213 | uprintf("}\n"); |
214 | | | 214 | |
215 | free((char *) ptr, M_TEMP); | | 215 | free((char *) ptr, M_TEMP); |
216 | return 0; | | 216 | return 0; |
217 | } | | 217 | } |
218 | | | 218 | |
219 | | | 219 | |
220 | static int | | 220 | static int |
221 | show_strbuf(struct svr4_strbuf *str) | | 221 | show_strbuf(struct svr4_strbuf *str) |
222 | { | | 222 | { |
223 | int error; | | 223 | int error; |
224 | u_char *ptr = NULL; | | 224 | u_char *ptr = NULL; |
225 | int maxlen = str->maxlen; | | 225 | int maxlen = str->maxlen; |
226 | int len = str->len; | | 226 | int len = str->len; |
227 | | | 227 | |
228 | if (maxlen > 8192) | | 228 | if (maxlen > 8192) |
229 | maxlen = 8192; | | 229 | maxlen = 8192; |
230 | | | 230 | |
231 | if (maxlen < 0) | | 231 | if (maxlen < 0) |
232 | maxlen = 0; | | 232 | maxlen = 0; |
233 | | | 233 | |
234 | if (len >= maxlen) | | 234 | if (len >= maxlen) |
235 | len = maxlen; | | 235 | len = maxlen; |
236 | | | 236 | |
237 | if (len > 0) { | | 237 | if (len > 0) { |
238 | ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); | | 238 | ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); |
239 | | | 239 | |
240 | if ((error = copyin(str->buf, ptr, len)) != 0) { | | 240 | if ((error = copyin(str->buf, ptr, len)) != 0) { |
241 | free((char *) ptr, M_TEMP); | | 241 | free((char *) ptr, M_TEMP); |
242 | return error; | | 242 | return error; |
243 | } | | 243 | } |
244 | } | | 244 | } |
245 | | | 245 | |
246 | uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf); | | 246 | uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf); |
247 | | | 247 | |
248 | if (ptr) | | 248 | if (ptr) |
249 | bufprint(ptr, len); | | 249 | bufprint(ptr, len); |
250 | | | 250 | |
251 | uprintf("]}"); | | 251 | uprintf("]}"); |
252 | | | 252 | |
253 | if (ptr) | | 253 | if (ptr) |
254 | free((char *) ptr, M_TEMP); | | 254 | free((char *) ptr, M_TEMP); |
255 | | | 255 | |
256 | return 0; | | 256 | return 0; |
257 | } | | 257 | } |
258 | | | 258 | |
259 | | | 259 | |
260 | static void | | 260 | static void |
261 | show_msg(const char *str, int fd, struct svr4_strbuf *ctl, struct svr4_strbuf *dat, int flags) | | 261 | show_msg(const char *str, int fd, struct svr4_strbuf *ctl, struct svr4_strbuf *dat, int flags) |
262 | { | | 262 | { |
263 | struct svr4_strbuf buf; | | 263 | struct svr4_strbuf buf; |
264 | int error; | | 264 | int error; |
265 | | | 265 | |
266 | uprintf("%s(%d", str, fd); | | 266 | uprintf("%s(%d", str, fd); |
267 | if (ctl != NULL) { | | 267 | if (ctl != NULL) { |
268 | if ((error = copyin(ctl, &buf, sizeof(buf))) != 0) | | 268 | if ((error = copyin(ctl, &buf, sizeof(buf))) != 0) |
269 | return; | | 269 | return; |
270 | show_strbuf(&buf); | | 270 | show_strbuf(&buf); |
271 | } | | 271 | } |
272 | else | | 272 | else |
273 | uprintf(", NULL"); | | 273 | uprintf(", NULL"); |
274 | | | 274 | |
275 | if (dat != NULL) { | | 275 | if (dat != NULL) { |
276 | if ((error = copyin(dat, &buf, sizeof(buf))) != 0) | | 276 | if ((error = copyin(dat, &buf, sizeof(buf))) != 0) |
277 | return; | | 277 | return; |
278 | show_strbuf(&buf); | | 278 | show_strbuf(&buf); |
279 | } | | 279 | } |
280 | else | | 280 | else |
281 | uprintf(", NULL"); | | 281 | uprintf(", NULL"); |
282 | | | 282 | |
283 | uprintf(", %x);\n", flags); | | 283 | uprintf(", %x);\n", flags); |
284 | } | | 284 | } |
285 | | | 285 | |
286 | #endif /* DEBUG_SVR4 */ | | 286 | #endif /* DEBUG_SVR4 */ |
287 | | | 287 | |
288 | | | 288 | |
289 | /* | | 289 | /* |
290 | * We are faced with an interesting situation. On svr4 unix sockets | | 290 | * We are faced with an interesting situation. On svr4 unix sockets |
291 | * are really pipes. But we really have sockets, and we might as | | 291 | * are really pipes. But we really have sockets, and we might as |
292 | * well use them. At the point where svr4 calls TI_BIND, it has | | 292 | * well use them. At the point where svr4 calls TI_BIND, it has |
293 | * already created a named pipe for the socket using mknod(2). | | 293 | * already created a named pipe for the socket using mknod(2). |
294 | * We need to create a socket with the same name when we bind, | | 294 | * We need to create a socket with the same name when we bind, |
295 | * so we need to remove the pipe before, otherwise we'll get address | | 295 | * so we need to remove the pipe before, otherwise we'll get address |
296 | * already in use. So we *carefully* remove the pipe, to avoid | | 296 | * already in use. So we *carefully* remove the pipe, to avoid |
297 | * using this as a random file removal tool. | | 297 | * using this as a random file removal tool. |
298 | */ | | 298 | */ |
299 | static int | | 299 | static int |
300 | clean_pipe(struct lwp *l, const char *path) | | 300 | clean_pipe(struct lwp *l, const char *path) |
301 | { | | 301 | { |
302 | struct pathbuf *pb; | | 302 | struct pathbuf *pb; |
303 | struct nameidata nd; | | 303 | struct nameidata nd; |
304 | struct vattr va; | | 304 | struct vattr va; |
305 | int error; | | 305 | int error; |
306 | | | 306 | |
307 | pb = pathbuf_create(path); | | 307 | pb = pathbuf_create(path); |
308 | if (pb == NULL) { | | 308 | if (pb == NULL) { |
309 | return ENOMEM; | | 309 | return ENOMEM; |
310 | } | | 310 | } |
311 | | | 311 | |
312 | NDINIT(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF | TRYEMULROOT, pb); | | 312 | NDINIT(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF | TRYEMULROOT, pb); |
313 | error = namei(&nd); | | 313 | error = namei(&nd); |
314 | if (error != 0) { | | 314 | if (error != 0) { |
315 | pathbuf_destroy(pb); | | 315 | pathbuf_destroy(pb); |
316 | return error; | | 316 | return error; |
317 | } | | 317 | } |
318 | | | 318 | |
319 | /* | | 319 | /* |
320 | * Make sure we are dealing with a mode 0 named pipe. | | 320 | * Make sure we are dealing with a mode 0 named pipe. |
321 | */ | | 321 | */ |
322 | if (nd.ni_vp->v_type != VFIFO) | | 322 | if (nd.ni_vp->v_type != VFIFO) |
323 | goto bad; | | 323 | goto bad; |
324 | error = VOP_GETATTR(nd.ni_vp, &va, l->l_cred); | | 324 | error = VOP_GETATTR(nd.ni_vp, &va, l->l_cred); |
325 | if (error != 0) | | 325 | if (error != 0) |
326 | goto bad; | | 326 | goto bad; |
327 | if ((va.va_mode & ALLPERMS) != 0) | | 327 | if ((va.va_mode & ALLPERMS) != 0) |
328 | goto bad; | | 328 | goto bad; |
329 | | | 329 | |
330 | error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd); | | 330 | error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd); |
331 | pathbuf_destroy(pb); | | 331 | pathbuf_destroy(pb); |
332 | return error; | | 332 | return error; |
333 | | | 333 | |
334 | bad: | | 334 | bad: |
335 | if (nd.ni_dvp == nd.ni_vp) | | 335 | if (nd.ni_dvp == nd.ni_vp) |
336 | vrele(nd.ni_dvp); | | 336 | vrele(nd.ni_dvp); |
337 | else | | 337 | else |
338 | vput(nd.ni_dvp); | | 338 | vput(nd.ni_dvp); |
339 | vput(nd.ni_vp); | | 339 | vput(nd.ni_vp); |
340 | pathbuf_destroy(pb); | | 340 | pathbuf_destroy(pb); |
341 | return error; | | 341 | return error; |
342 | } | | 342 | } |
343 | | | 343 | |
344 | | | 344 | |
345 | static void | | 345 | static void |
346 | sockaddr_to_netaddr_in(struct svr4_strmcmd *sc, const struct sockaddr_in *sain) | | 346 | sockaddr_to_netaddr_in(struct svr4_strmcmd *sc, const struct sockaddr_in *sain) |
347 | { | | 347 | { |
348 | struct svr4_netaddr_in *na; | | 348 | struct svr4_netaddr_in *na; |
349 | na = SVR4_ADDROF(sc); | | 349 | na = SVR4_ADDROF(sc); |
350 | | | 350 | |
351 | na->family = sain->sin_family; | | 351 | na->family = sain->sin_family; |
352 | na->port = sain->sin_port; | | 352 | na->port = sain->sin_port; |
353 | na->addr = sain->sin_addr.s_addr; | | 353 | na->addr = sain->sin_addr.s_addr; |
354 | DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port, | | 354 | DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port, |
355 | na->addr)); | | 355 | na->addr)); |
356 | } | | 356 | } |
357 | | | 357 | |
358 | | | 358 | |
359 | static void | | 359 | static void |
360 | sockaddr_to_netaddr_un(struct svr4_strmcmd *sc, const struct sockaddr_un *saun) | | 360 | sockaddr_to_netaddr_un(struct svr4_strmcmd *sc, const struct sockaddr_un *saun) |
361 | { | | 361 | { |
362 | struct svr4_netaddr_un *na; | | 362 | struct svr4_netaddr_un *na; |
363 | char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 - | | 363 | char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 - |
364 | sizeof(*sc); | | 364 | sizeof(*sc); |
365 | const char *src; | | 365 | const char *src; |
366 | | | 366 | |
367 | na = SVR4_ADDROF(sc); | | 367 | na = SVR4_ADDROF(sc); |
368 | na->family = saun->sun_family; | | 368 | na->family = saun->sun_family; |
369 | for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; ) | | 369 | for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; ) |
370 | if (dst == edst) | | 370 | if (dst == edst) |
371 | break; | | 371 | break; |
372 | DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path)); | | 372 | DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path)); |
373 | } | | 373 | } |
374 | | | 374 | |
375 | | | 375 | |
376 | static void | | 376 | static void |
377 | netaddr_to_sockaddr_in(struct sockaddr_in *sain, const struct svr4_strmcmd *sc) | | 377 | netaddr_to_sockaddr_in(struct sockaddr_in *sain, const struct svr4_strmcmd *sc) |
378 | { | | 378 | { |
379 | const struct svr4_netaddr_in *na; | | 379 | const struct svr4_netaddr_in *na; |
380 | | | 380 | |
381 | | | 381 | |
382 | na = SVR4_C_ADDROF(sc); | | 382 | na = SVR4_C_ADDROF(sc); |
383 | memset(sain, 0, sizeof(*sain)); | | 383 | memset(sain, 0, sizeof(*sain)); |
384 | sain->sin_len = sizeof(*sain); | | 384 | sain->sin_len = sizeof(*sain); |
385 | sain->sin_family = na->family; | | 385 | sain->sin_family = na->family; |
386 | sain->sin_port = na->port; | | 386 | sain->sin_port = na->port; |
387 | sain->sin_addr.s_addr = na->addr; | | 387 | sain->sin_addr.s_addr = na->addr; |
388 | DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family, | | 388 | DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family, |
389 | sain->sin_port, sain->sin_addr.s_addr)); | | 389 | sain->sin_port, sain->sin_addr.s_addr)); |
390 | } | | 390 | } |
391 | | | 391 | |
392 | | | 392 | |
393 | static void | | 393 | static void |
394 | netaddr_to_sockaddr_un(struct sockaddr_un *saun, const struct svr4_strmcmd *sc) | | 394 | netaddr_to_sockaddr_un(struct sockaddr_un *saun, const struct svr4_strmcmd *sc) |
395 | { | | 395 | { |
396 | const struct svr4_netaddr_un *na; | | 396 | const struct svr4_netaddr_un *na; |
397 | char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1]; | | 397 | char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1]; |
398 | const char *src; | | 398 | const char *src; |
399 | | | 399 | |
400 | na = SVR4_C_ADDROF(sc); | | 400 | na = SVR4_C_ADDROF(sc); |
401 | memset(saun, 0, sizeof(*saun)); | | 401 | memset(saun, 0, sizeof(*saun)); |
402 | saun->sun_family = na->family; | | 402 | saun->sun_family = na->family; |
403 | for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; ) | | 403 | for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; ) |
404 | if (dst == edst) | | 404 | if (dst == edst) |
405 | break; | | 405 | break; |
406 | saun->sun_len = dst - saun->sun_path; | | 406 | saun->sun_len = dst - saun->sun_path; |
407 | DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family, | | 407 | DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family, |
408 | saun->sun_path)); | | 408 | saun->sun_path)); |
409 | } | | 409 | } |
410 | | | 410 | |
411 | | | 411 | |
412 | static void | | 412 | static void |
413 | getparm(file_t *fp, struct svr4_si_sockparms *pa) | | 413 | getparm(file_t *fp, struct svr4_si_sockparms *pa) |
414 | { | | 414 | { |
415 | struct svr4_strm *st = svr4_stream_get(fp); | | 415 | struct svr4_strm *st = svr4_stream_get(fp); |
416 | struct socket *so = (struct socket *) fp->f_data; | | 416 | struct socket *so = (struct socket *) fp->f_data; |
417 | | | 417 | |
418 | if (st == NULL) | | 418 | if (st == NULL) |
419 | return; | | 419 | return; |
420 | | | 420 | |
421 | pa->family = st->s_family; | | 421 | pa->family = st->s_family; |
422 | | | 422 | |
423 | switch (so->so_type) { | | 423 | switch (so->so_type) { |
424 | case SOCK_DGRAM: | | 424 | case SOCK_DGRAM: |
425 | pa->type = SVR4_T_CLTS; | | 425 | pa->type = SVR4_T_CLTS; |
426 | pa->protocol = IPPROTO_UDP; | | 426 | pa->protocol = IPPROTO_UDP; |
427 | DPRINTF(("getparm(dgram)\n")); | | 427 | DPRINTF(("getparm(dgram)\n")); |
428 | return; | | 428 | return; |
429 | | | 429 | |
430 | case SOCK_STREAM: | | 430 | case SOCK_STREAM: |
431 | pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */ | | 431 | pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */ |
432 | pa->protocol = IPPROTO_IP; | | 432 | pa->protocol = IPPROTO_IP; |
433 | DPRINTF(("getparm(stream)\n")); | | 433 | DPRINTF(("getparm(stream)\n")); |
434 | return; | | 434 | return; |
435 | | | 435 | |
436 | case SOCK_RAW: | | 436 | case SOCK_RAW: |
437 | pa->type = SVR4_T_CLTS; | | 437 | pa->type = SVR4_T_CLTS; |
438 | pa->protocol = IPPROTO_RAW; | | 438 | pa->protocol = IPPROTO_RAW; |
439 | DPRINTF(("getparm(raw)\n")); | | 439 | DPRINTF(("getparm(raw)\n")); |
440 | return; | | 440 | return; |
441 | | | 441 | |
442 | default: | | 442 | default: |
443 | pa->type = 0; | | 443 | pa->type = 0; |
444 | pa->protocol = 0; | | 444 | pa->protocol = 0; |
445 | DPRINTF(("getparm(type %d?)\n", so->so_type)); | | 445 | DPRINTF(("getparm(type %d?)\n", so->so_type)); |
446 | return; | | 446 | return; |
447 | } | | 447 | } |
448 | } | | 448 | } |
449 | | | 449 | |
450 | | | 450 | |
451 | static int | | 451 | static int |
452 | si_ogetudata(file_t *fp, int fd, struct svr4_strioctl *ioc, | | 452 | si_ogetudata(file_t *fp, int fd, struct svr4_strioctl *ioc, |
453 | struct lwp *l) | | 453 | struct lwp *l) |
454 | { | | 454 | { |
455 | int error; | | 455 | int error; |
456 | struct svr4_si_oudata ud; | | 456 | struct svr4_si_oudata ud; |
457 | struct svr4_si_sockparms pa; | | 457 | struct svr4_si_sockparms pa; |
458 | (void)memset(&pa, 0, sizeof(pa)); /* XXX: GCC */ | | 458 | (void)memset(&pa, 0, sizeof(pa)); /* XXX: GCC */ |
459 | | | 459 | |
460 | if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) { | | 460 | if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) { |
461 | DPRINTF(("SI_OGETUDATA: Wrong size %ld != %d\n", | | 461 | DPRINTF(("SI_OGETUDATA: Wrong size %ld != %d\n", |
462 | (unsigned long)sizeof(ud), ioc->len)); | | 462 | (unsigned long)sizeof(ud), ioc->len)); |
463 | return EINVAL; | | 463 | return EINVAL; |
464 | } | | 464 | } |
465 | | | 465 | |
466 | if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0) | | 466 | if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0) |
467 | return error; | | 467 | return error; |
468 | | | 468 | |
469 | getparm(fp, &pa); | | 469 | getparm(fp, &pa); |
470 | | | 470 | |
471 | switch (pa.family) { | | 471 | switch (pa.family) { |
472 | case AF_INET: | | 472 | case AF_INET: |
473 | ud.tidusize = 16384; | | 473 | ud.tidusize = 16384; |
474 | ud.addrsize = sizeof(struct sockaddr_in); | | 474 | ud.addrsize = sizeof(struct sockaddr_in); |
475 | if (pa.type == SVR4_SOCK_STREAM) | | 475 | if (pa.type == SVR4_SOCK_STREAM) |
476 | ud.etsdusize = 1; | | 476 | ud.etsdusize = 1; |
477 | else | | 477 | else |
478 | ud.etsdusize = 0; | | 478 | ud.etsdusize = 0; |
479 | break; | | 479 | break; |
480 | | | 480 | |
481 | case AF_LOCAL: | | 481 | case AF_LOCAL: |
482 | ud.tidusize = 65536; | | 482 | ud.tidusize = 65536; |
483 | ud.addrsize = 128; | | 483 | ud.addrsize = 128; |
484 | ud.etsdusize = 128; | | 484 | ud.etsdusize = 128; |
485 | break; | | 485 | break; |
486 | | | 486 | |
487 | default: | | 487 | default: |
488 | DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n", | | 488 | DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n", |
489 | pa.family)); | | 489 | pa.family)); |
490 | return ENOSYS; | | 490 | return ENOSYS; |
491 | } | | 491 | } |
492 | | | 492 | |
493 | /* I have no idea what these should be! */ | | 493 | /* I have no idea what these should be! */ |
494 | ud.optsize = 128; | | 494 | ud.optsize = 128; |
495 | ud.tsdusize = 128; | | 495 | ud.tsdusize = 128; |
496 | | | 496 | |
497 | ud.servtype = pa.type; | | 497 | ud.servtype = pa.type; |
498 | | | 498 | |
499 | /* XXX: Fixme */ | | 499 | /* XXX: Fixme */ |
500 | ud.so_state = 0; | | 500 | ud.so_state = 0; |
501 | ud.so_options = 0; | | 501 | ud.so_options = 0; |
502 | return copyout(&ud, NETBSD32PTR(ioc->buf), ioc->len); | | 502 | return copyout(&ud, NETBSD32PTR(ioc->buf), ioc->len); |
503 | } | | 503 | } |
504 | | | 504 | |
505 | | | 505 | |
506 | static int | | 506 | static int |
507 | si_sockparams(file_t *fp, int fd, struct svr4_strioctl *ioc, | | 507 | si_sockparams(file_t *fp, int fd, struct svr4_strioctl *ioc, |
508 | struct lwp *l) | | 508 | struct lwp *l) |
509 | { | | 509 | { |
510 | struct svr4_si_sockparms pa; | | 510 | struct svr4_si_sockparms pa; |
511 | | | 511 | |
512 | getparm(fp, &pa); | | 512 | getparm(fp, &pa); |
513 | return copyout(&pa, NETBSD32PTR(ioc->buf), sizeof(pa)); | | 513 | return copyout(&pa, NETBSD32PTR(ioc->buf), sizeof(pa)); |
514 | } | | 514 | } |
515 | | | 515 | |
516 | | | 516 | |
517 | static int | | 517 | static int |
518 | si_listen(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) | | 518 | si_listen(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) |
519 | { | | 519 | { |
520 | int error; | | 520 | int error; |
521 | struct svr4_strm *st = svr4_stream_get(fp); | | 521 | struct svr4_strm *st = svr4_stream_get(fp); |
522 | register_t retval; | | 522 | register_t retval; |
523 | struct svr4_strmcmd lst; | | 523 | struct svr4_strmcmd lst; |
524 | struct sys_listen_args la; | | 524 | struct sys_listen_args la; |
525 | | | 525 | |
526 | if (st == NULL) | | 526 | if (st == NULL) |
527 | return EINVAL; | | 527 | return EINVAL; |
528 | | | 528 | |
529 | if (ioc->len > sizeof(lst)) | | 529 | if (ioc->len < offsetof(struct svr4_strmcmd, pad) || |
| | | 530 | ioc->len > sizeof(lst)) |
530 | return EINVAL; | | 531 | return EINVAL; |
531 | | | 532 | |
532 | if ((error = copyin(NETBSD32PTR(ioc->buf), &lst, ioc->len)) != 0) | | 533 | if ((error = copyin(NETBSD32PTR(ioc->buf), &lst, ioc->len)) != 0) |
533 | return error; | | 534 | return error; |
| | | 535 | if (lst.offs < 0 || |
| | | 536 | lst.len < 0 || |
| | | 537 | lst.len > ioc->len || |
| | | 538 | ioc->len - lst.len < lst.offs) |
| | | 539 | return EINVAL; |
534 | | | 540 | |
535 | if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) { | | 541 | if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) { |
536 | DPRINTF(("si_listen: bad request %ld\n", lst.cmd)); | | 542 | DPRINTF(("si_listen: bad request %ld\n", lst.cmd)); |
537 | return EINVAL; | | 543 | return EINVAL; |
538 | } | | 544 | } |
539 | | | 545 | |
540 | /* | | 546 | /* |
541 | * We are making assumptions again... | | 547 | * We are making assumptions again... |
542 | */ | | 548 | */ |
543 | SCARG(&la, s) = fd; | | 549 | SCARG(&la, s) = fd; |
544 | DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5)); | | 550 | DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5)); |
545 | SCARG(&la, backlog) = 5; | | 551 | SCARG(&la, backlog) = 5; |
546 | | | 552 | |
547 | if ((error = sys_listen(l, &la, &retval)) != 0) { | | 553 | if ((error = sys_listen(l, &la, &retval)) != 0) { |
548 | DPRINTF(("SI_LISTEN: listen failed %d\n", error)); | | 554 | DPRINTF(("SI_LISTEN: listen failed %d\n", error)); |
549 | return error; | | 555 | return error; |
550 | } | | 556 | } |
551 | | | 557 | |
552 | st->s_cmd = SVR4_TI__ACCEPT_WAIT; | | 558 | st->s_cmd = SVR4_TI__ACCEPT_WAIT; |
553 | lst.cmd = SVR4_TI_BIND_REPLY; | | 559 | lst.cmd = SVR4_TI_BIND_REPLY; |
554 | | | 560 | |
555 | switch (st->s_family) { | | 561 | switch (st->s_family) { |
556 | case AF_INET: | | 562 | case AF_INET: |
557 | /* XXX: Fill the length here */ | | 563 | /* XXX: Fill the length here */ |
558 | break; | | 564 | break; |
559 | | | 565 | |
560 | case AF_LOCAL: | | 566 | case AF_LOCAL: |
561 | lst.len = 140; | | 567 | lst.len = 140; |
562 | lst.pad[28] = 0x00000000; /* magic again */ | | 568 | lst.pad[28] = 0x00000000; /* magic again */ |
563 | lst.pad[29] = 0x00000800; /* magic again */ | | 569 | lst.pad[29] = 0x00000800; /* magic again */ |
564 | lst.pad[30] = 0x80001400; /* magic again */ | | 570 | lst.pad[30] = 0x80001400; /* magic again */ |
565 | break; | | 571 | break; |
566 | | | 572 | |
567 | default: | | 573 | default: |
568 | DPRINTF(("SI_LISTEN: Unsupported address family %d\n", | | 574 | DPRINTF(("SI_LISTEN: Unsupported address family %d\n", |
569 | st->s_family)); | | 575 | st->s_family)); |
570 | return ENOSYS; | | 576 | return ENOSYS; |
571 | } | | 577 | } |
572 | | | 578 | |
573 | | | 579 | |
574 | if ((error = copyout(&lst, NETBSD32PTR(ioc->buf), ioc->len)) != 0) | | 580 | if ((error = copyout(&lst, NETBSD32PTR(ioc->buf), ioc->len)) != 0) |
575 | return error; | | 581 | return error; |
576 | | | 582 | |
577 | return 0; | | 583 | return 0; |
578 | } | | 584 | } |
579 | | | 585 | |
580 | | | 586 | |
581 | static int | | 587 | static int |
582 | si_getudata(file_t *fp, int fd, struct svr4_strioctl *ioc, | | 588 | si_getudata(file_t *fp, int fd, struct svr4_strioctl *ioc, |
583 | struct lwp *l) | | 589 | struct lwp *l) |
584 | { | | 590 | { |
585 | int error; | | 591 | int error; |
586 | struct svr4_si_udata ud; | | 592 | struct svr4_si_udata ud; |
587 | | | 593 | |
588 | if (sizeof(ud) != ioc->len) { | | 594 | if (sizeof(ud) != ioc->len) { |
589 | DPRINTF(("SI_GETUDATA: Wrong size %ld != %d\n", | | 595 | DPRINTF(("SI_GETUDATA: Wrong size %ld != %d\n", |
590 | (unsigned long)sizeof(ud), ioc->len)); | | 596 | (unsigned long)sizeof(ud), ioc->len)); |
591 | return EINVAL; | | 597 | return EINVAL; |
592 | } | | 598 | } |
593 | | | 599 | |
594 | if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0) | | 600 | if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0) |
595 | return error; | | 601 | return error; |
596 | | | 602 | |
597 | getparm(fp, &ud.sockparms); | | 603 | getparm(fp, &ud.sockparms); |
598 | | | 604 | |
599 | switch (ud.sockparms.family) { | | 605 | switch (ud.sockparms.family) { |
600 | case AF_INET: | | 606 | case AF_INET: |
601 | ud.tidusize = 16384; | | 607 | ud.tidusize = 16384; |
602 | ud.tsdusize = 16384; | | 608 | ud.tsdusize = 16384; |
603 | ud.addrsize = sizeof(struct sockaddr_in); | | 609 | ud.addrsize = sizeof(struct sockaddr_in); |
604 | if (ud.sockparms.type == SVR4_SOCK_STREAM) | | 610 | if (ud.sockparms.type == SVR4_SOCK_STREAM) |
605 | ud.etsdusize = 1; | | 611 | ud.etsdusize = 1; |
606 | else | | 612 | else |
607 | ud.etsdusize = 0; | | 613 | ud.etsdusize = 0; |
608 | ud.optsize = 0; | | 614 | ud.optsize = 0; |
609 | break; | | 615 | break; |
610 | | | 616 | |
611 | case AF_LOCAL: | | 617 | case AF_LOCAL: |
612 | ud.tidusize = 65536; | | 618 | ud.tidusize = 65536; |
613 | ud.tsdusize = 128; | | 619 | ud.tsdusize = 128; |
614 | ud.addrsize = 128; | | 620 | ud.addrsize = 128; |
615 | ud.etsdusize = 128; | | 621 | ud.etsdusize = 128; |
616 | ud.optsize = 128; | | 622 | ud.optsize = 128; |
617 | break; | | 623 | break; |
618 | | | 624 | |
619 | default: | | 625 | default: |
620 | DPRINTF(("SI_GETUDATA: Unsupported address family %d\n", | | 626 | DPRINTF(("SI_GETUDATA: Unsupported address family %d\n", |
621 | ud.sockparms.family)); | | 627 | ud.sockparms.family)); |
622 | return ENOSYS; | | 628 | return ENOSYS; |
623 | } | | 629 | } |
624 | | | 630 | |
625 | | | 631 | |
626 | ud.servtype = ud.sockparms.type; | | 632 | ud.servtype = ud.sockparms.type; |
627 | | | 633 | |
628 | /* XXX: Fixme */ | | 634 | /* XXX: Fixme */ |
629 | ud.so_state = 0; | | 635 | ud.so_state = 0; |
630 | ud.so_options = 0; | | 636 | ud.so_options = 0; |
631 | return copyout(&ud, NETBSD32PTR(ioc->buf), sizeof(ud)); | | 637 | return copyout(&ud, NETBSD32PTR(ioc->buf), sizeof(ud)); |
632 | } | | 638 | } |
633 | | | 639 | |
634 | | | 640 | |
635 | static int | | 641 | static int |
636 | si_shutdown(file_t *fp, int fd, struct svr4_strioctl *ioc, | | 642 | si_shutdown(file_t *fp, int fd, struct svr4_strioctl *ioc, |
637 | struct lwp *l) | | 643 | struct lwp *l) |
638 | { | | 644 | { |
639 | int error; | | 645 | int error; |
640 | struct sys_shutdown_args ap; | | 646 | struct sys_shutdown_args ap; |
641 | register_t retval; | | 647 | register_t retval; |
642 | | | 648 | |
643 | if (ioc->len != sizeof(SCARG(&ap, how))) { | | 649 | if (ioc->len != sizeof(SCARG(&ap, how))) { |
644 | DPRINTF(("SI_SHUTDOWN: Wrong size %ld != %d\n", | | 650 | DPRINTF(("SI_SHUTDOWN: Wrong size %ld != %d\n", |
645 | (unsigned long)sizeof(SCARG(&ap, how)), ioc->len)); | | 651 | (unsigned long)sizeof(SCARG(&ap, how)), ioc->len)); |
646 | return EINVAL; | | 652 | return EINVAL; |
647 | } | | 653 | } |
648 | | | 654 | |
649 | if ((error = copyin(NETBSD32PTR(ioc->buf), &SCARG(&ap, how), ioc->len)) != 0) | | 655 | if ((error = copyin(NETBSD32PTR(ioc->buf), &SCARG(&ap, how), ioc->len)) != 0) |
650 | return error; | | 656 | return error; |
651 | | | 657 | |
652 | SCARG(&ap, s) = fd; | | 658 | SCARG(&ap, s) = fd; |
653 | | | 659 | |
654 | return sys_shutdown(l, &ap, &retval); | | 660 | return sys_shutdown(l, &ap, &retval); |
655 | } | | 661 | } |
656 | | | 662 | |
657 | | | 663 | |
658 | static int | | 664 | static int |
659 | sockmod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) | | 665 | sockmod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) |
660 | { | | 666 | { |
661 | switch (ioc->cmd) { | | 667 | switch (ioc->cmd) { |
662 | case SVR4_SI_OGETUDATA: | | 668 | case SVR4_SI_OGETUDATA: |
663 | DPRINTF(("SI_OGETUDATA\n")); | | 669 | DPRINTF(("SI_OGETUDATA\n")); |
664 | return si_ogetudata(fp, fd, ioc, l); | | 670 | return si_ogetudata(fp, fd, ioc, l); |
665 | | | 671 | |
666 | case SVR4_SI_SHUTDOWN: | | 672 | case SVR4_SI_SHUTDOWN: |
667 | DPRINTF(("SI_SHUTDOWN\n")); | | 673 | DPRINTF(("SI_SHUTDOWN\n")); |
668 | return si_shutdown(fp, fd, ioc, l); | | 674 | return si_shutdown(fp, fd, ioc, l); |
669 | | | 675 | |
670 | case SVR4_SI_LISTEN: | | 676 | case SVR4_SI_LISTEN: |
671 | DPRINTF(("SI_LISTEN\n")); | | 677 | DPRINTF(("SI_LISTEN\n")); |
672 | return si_listen(fp, fd, ioc, l); | | 678 | return si_listen(fp, fd, ioc, l); |
673 | | | 679 | |
674 | case SVR4_SI_SETMYNAME: | | 680 | case SVR4_SI_SETMYNAME: |
675 | DPRINTF(("SI_SETMYNAME\n")); | | 681 | DPRINTF(("SI_SETMYNAME\n")); |
676 | return 0; | | 682 | return 0; |
677 | | | 683 | |
678 | case SVR4_SI_SETPEERNAME: | | 684 | case SVR4_SI_SETPEERNAME: |
679 | DPRINTF(("SI_SETPEERNAME\n")); | | 685 | DPRINTF(("SI_SETPEERNAME\n")); |
680 | return 0; | | 686 | return 0; |
681 | | | 687 | |
682 | case SVR4_SI_GETINTRANSIT: | | 688 | case SVR4_SI_GETINTRANSIT: |
683 | DPRINTF(("SI_GETINTRANSIT\n")); | | 689 | DPRINTF(("SI_GETINTRANSIT\n")); |
684 | return 0; | | 690 | return 0; |
685 | | | 691 | |
686 | case SVR4_SI_TCL_LINK: | | 692 | case SVR4_SI_TCL_LINK: |
687 | DPRINTF(("SI_TCL_LINK\n")); | | 693 | DPRINTF(("SI_TCL_LINK\n")); |
688 | return 0; | | 694 | return 0; |
689 | | | 695 | |
690 | case SVR4_SI_TCL_UNLINK: | | 696 | case SVR4_SI_TCL_UNLINK: |
691 | DPRINTF(("SI_TCL_UNLINK\n")); | | 697 | DPRINTF(("SI_TCL_UNLINK\n")); |
692 | return 0; | | 698 | return 0; |
693 | | | 699 | |
694 | case SVR4_SI_SOCKPARAMS: | | 700 | case SVR4_SI_SOCKPARAMS: |
695 | DPRINTF(("SI_SOCKPARAMS\n")); | | 701 | DPRINTF(("SI_SOCKPARAMS\n")); |
696 | return si_sockparams(fp, fd, ioc, l); | | 702 | return si_sockparams(fp, fd, ioc, l); |
697 | | | 703 | |
698 | case SVR4_SI_GETUDATA: | | 704 | case SVR4_SI_GETUDATA: |
699 | DPRINTF(("SI_GETUDATA\n")); | | 705 | DPRINTF(("SI_GETUDATA\n")); |
700 | return si_getudata(fp, fd, ioc, l); | | 706 | return si_getudata(fp, fd, ioc, l); |
701 | | | 707 | |
702 | default: | | 708 | default: |
703 | DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd)); | | 709 | DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd)); |
704 | return 0; | | 710 | return 0; |
705 | | | 711 | |
706 | } | | 712 | } |
707 | } | | 713 | } |
708 | | | 714 | |
709 | | | 715 | |
710 | static int | | 716 | static int |
711 | ti_getinfo(file_t *fp, int fd, struct svr4_strioctl *ioc, | | 717 | ti_getinfo(file_t *fp, int fd, struct svr4_strioctl *ioc, |
712 | struct lwp *l) | | 718 | struct lwp *l) |
713 | { | | 719 | { |
714 | int error; | | 720 | int error; |
715 | struct svr4_infocmd info; | | 721 | struct svr4_infocmd info; |
716 | | | 722 | |
717 | memset(&info, 0, sizeof(info)); | | 723 | memset(&info, 0, sizeof(info)); |
718 | | | 724 | |
719 | if (ioc->len > sizeof(info)) | | 725 | /* tsdu is next after cmd, the only field we read */ |
| | | 726 | if (ioc->len < offsetof(struct svr4_infocmd, tsdu) || |
| | | 727 | ioc->len > sizeof(info)) |
720 | return EINVAL; | | 728 | return EINVAL; |
721 | | | 729 | |
722 | if ((error = copyin(NETBSD32PTR(ioc->buf), &info, ioc->len)) != 0) | | 730 | if ((error = copyin(NETBSD32PTR(ioc->buf), &info, ioc->len)) != 0) |
723 | return error; | | 731 | return error; |
724 | | | 732 | |
725 | if (info.cmd != SVR4_TI_INFO_REQUEST) | | 733 | if (info.cmd != SVR4_TI_INFO_REQUEST) |
726 | return EINVAL; | | 734 | return EINVAL; |
727 | | | 735 | |
728 | info.cmd = SVR4_TI_INFO_REPLY; | | 736 | info.cmd = SVR4_TI_INFO_REPLY; |
729 | info.tsdu = 0; | | 737 | info.tsdu = 0; |
730 | info.etsdu = 1; | | 738 | info.etsdu = 1; |
731 | info.cdata = -2; | | 739 | info.cdata = -2; |
732 | info.ddata = -2; | | 740 | info.ddata = -2; |
733 | info.addr = 16; | | 741 | info.addr = 16; |
734 | info.opt = -1; | | 742 | info.opt = -1; |
735 | info.tidu = 16384; | | 743 | info.tidu = 16384; |
736 | info.serv = 2; | | 744 | info.serv = 2; |
737 | info.current = 0; | | 745 | info.current = 0; |
738 | info.provider = 2; | | 746 | info.provider = 2; |
739 | | | 747 | |
740 | ioc->len = sizeof(info); | | 748 | ioc->len = sizeof(info); |
741 | if ((error = copyout(&info, NETBSD32PTR(ioc->buf), ioc->len)) != 0) | | 749 | if ((error = copyout(&info, NETBSD32PTR(ioc->buf), ioc->len)) != 0) |
742 | return error; | | 750 | return error; |
743 | | | 751 | |
744 | return 0; | | 752 | return 0; |
745 | } | | 753 | } |
746 | | | 754 | |
747 | | | 755 | |
748 | static int | | 756 | static int |
749 | ti_bind(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) | | 757 | ti_bind(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) |
750 | { | | 758 | { |
751 | int error; | | 759 | int error; |
752 | struct svr4_strm *st = svr4_stream_get(fp); | | 760 | struct svr4_strm *st = svr4_stream_get(fp); |
753 | struct sockaddr_in sain; | | 761 | struct sockaddr_in sain; |
754 | struct sockaddr_un saun; | | 762 | struct sockaddr_un saun; |
755 | void *skp, *sup = NULL; | | 763 | void *skp, *sup = NULL; |
756 | int sasize; | | 764 | int sasize; |
757 | struct svr4_strmcmd bnd; | | 765 | struct svr4_strmcmd bnd; |
758 | struct mbuf *name; | | 766 | struct mbuf *name; |
759 | | | 767 | |
760 | if (st == NULL) { | | 768 | if (st == NULL) { |
761 | DPRINTF(("ti_bind: bad file descriptor\n")); | | 769 | DPRINTF(("ti_bind: bad file descriptor\n")); |
762 | return EINVAL; | | 770 | return EINVAL; |
763 | } | | 771 | } |
764 | | | 772 | |
765 | if (ioc->len > sizeof(bnd)) | | 773 | if (ioc->len < offsetof(struct svr4_strmcmd, pad) || |
| | | 774 | ioc->len > sizeof(bnd)) |
766 | return EINVAL; | | 775 | return EINVAL; |
767 | | | 776 | |
768 | if ((error = copyin(NETBSD32PTR(ioc->buf), &bnd, ioc->len)) != 0) | | 777 | if ((error = copyin(NETBSD32PTR(ioc->buf), &bnd, ioc->len)) != 0) |
769 | return error; | | 778 | return error; |
770 | | | 779 | |
771 | if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) { | | 780 | if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) { |
772 | DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd)); | | 781 | DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd)); |
773 | return EINVAL; | | 782 | return EINVAL; |
774 | } | | 783 | } |
| | | 784 | if (bnd.offs < 0 || |
| | | 785 | bnd.len < 0 || |
| | | 786 | bnd.len > ioc->len || |
| | | 787 | ioc->len - bnd.len < bnd.offs) |
| | | 788 | return EINVAL; |
775 | | | 789 | |
776 | switch (st->s_family) { | | 790 | switch (st->s_family) { |
777 | case AF_INET: | | 791 | case AF_INET: |
778 | skp = &sain; | | 792 | skp = &sain; |
779 | sasize = sizeof(sain); | | 793 | sasize = sizeof(sain); |
780 | | | 794 | |
781 | if (bnd.offs == 0) | | 795 | if (bnd.offs == 0) |
782 | goto reply; | | 796 | goto reply; |
783 | | | 797 | |
| | | 798 | if (ioc->len < sizeof(struct svr4_netaddr_in) || |
| | | 799 | bnd.offs > ioc->len - sizeof(struct svr4_netaddr_in)) |
| | | 800 | return EINVAL; |
784 | netaddr_to_sockaddr_in(&sain, &bnd); | | 801 | netaddr_to_sockaddr_in(&sain, &bnd); |
785 | | | 802 | |
786 | DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n", | | 803 | DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n", |
787 | sain.sin_family, sain.sin_port, | | 804 | sain.sin_family, sain.sin_port, |
788 | sain.sin_addr.s_addr)); | | 805 | sain.sin_addr.s_addr)); |
789 | break; | | 806 | break; |
790 | | | 807 | |
791 | case AF_LOCAL: | | 808 | case AF_LOCAL: |
792 | skp = &saun; | | 809 | skp = &saun; |
793 | sasize = sizeof(saun); | | 810 | sasize = sizeof(saun); |
794 | if (bnd.offs == 0) | | 811 | if (bnd.offs == 0) |
795 | goto reply; | | 812 | goto reply; |
796 | | | 813 | |
| | | 814 | if (ioc->len < sizeof(struct svr4_netaddr_un) || |
| | | 815 | bnd.offs > ioc->len - sizeof(struct svr4_netaddr_un)) |
| | | 816 | return EINVAL; |
797 | netaddr_to_sockaddr_un(&saun, &bnd); | | 817 | netaddr_to_sockaddr_un(&saun, &bnd); |
798 | | | 818 | |
799 | if (saun.sun_path[0] == '\0') | | 819 | if (saun.sun_path[0] == '\0') |
800 | goto reply; | | 820 | goto reply; |
801 | | | 821 | |
802 | DPRINTF(("TI_BIND: fam %d, path %s\n", | | 822 | DPRINTF(("TI_BIND: fam %d, path %s\n", |
803 | saun.sun_family, saun.sun_path)); | | 823 | saun.sun_family, saun.sun_path)); |
804 | | | 824 | |
805 | if ((error = clean_pipe(l, saun.sun_path)) != 0) | | 825 | if ((error = clean_pipe(l, saun.sun_path)) != 0) |
806 | return error; | | 826 | return error; |
807 | | | 827 | |
808 | bnd.pad[28] = 0x00001000; /* magic again */ | | 828 | bnd.pad[28] = 0x00001000; /* magic again */ |
809 | break; | | 829 | break; |
810 | | | 830 | |
811 | default: | | 831 | default: |
812 | DPRINTF(("TI_BIND: Unsupported address family %d\n", | | 832 | DPRINTF(("TI_BIND: Unsupported address family %d\n", |
813 | st->s_family)); | | 833 | st->s_family)); |
814 | return ENOSYS; | | 834 | return ENOSYS; |
815 | } | | 835 | } |
816 | | | 836 | |
817 | name = m_get(M_WAIT, MT_SONAME); | | 837 | name = m_get(M_WAIT, MT_SONAME); |
818 | if (sasize > MLEN) | | 838 | if (sasize > MLEN) |
819 | MEXTMALLOC(name, sasize, M_WAITOK); | | 839 | MEXTMALLOC(name, sasize, M_WAITOK); |
820 | | | 840 | |
821 | memcpy(mtod(name, void *), skp, sasize); | | 841 | memcpy(mtod(name, void *), skp, sasize); |
822 | | | 842 | |
823 | DPRINTF(("TI_BIND: fileno %d\n", fd)); | | 843 | DPRINTF(("TI_BIND: fileno %d\n", fd)); |
824 | | | 844 | |
825 | error = do_sys_bind(l, fd, name); | | 845 | error = do_sys_bind(l, fd, name); |
826 | if (error != 0) { | | 846 | if (error != 0) { |
827 | DPRINTF(("TI_BIND: bind failed %d\n", error)); | | 847 | DPRINTF(("TI_BIND: bind failed %d\n", error)); |
828 | return error; | | 848 | return error; |
829 | } | | 849 | } |
830 | | | 850 | |
831 | reply: | | 851 | reply: |
832 | if (sup == NULL) { | | 852 | if (sup == NULL) { |
833 | memset(&bnd, 0, sizeof(bnd)); | | 853 | memset(&bnd, 0, sizeof(bnd)); |
834 | bnd.len = sasize + 4; | | 854 | bnd.len = sasize + 4; |
835 | bnd.offs = 0x10; /* XXX */ | | 855 | bnd.offs = 0x10; /* XXX */ |
836 | } | | 856 | } |
837 | | | 857 | |
838 | bnd.cmd = SVR4_TI_BIND_REPLY; | | 858 | bnd.cmd = SVR4_TI_BIND_REPLY; |
839 | | | 859 | |
840 | if ((error = copyout(&bnd, NETBSD32PTR(ioc->buf), ioc->len)) != 0) | | 860 | if ((error = copyout(&bnd, NETBSD32PTR(ioc->buf), ioc->len)) != 0) |
841 | return error; | | 861 | return error; |
842 | | | 862 | |
843 | return 0; | | 863 | return 0; |
844 | } | | 864 | } |
845 | | | 865 | |
846 | | | 866 | |
847 | static int | | 867 | static int |
848 | timod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) | | 868 | timod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) |
849 | { | | 869 | { |
850 | switch (ioc->cmd) { | | 870 | switch (ioc->cmd) { |
851 | case SVR4_TI_GETINFO: | | 871 | case SVR4_TI_GETINFO: |
852 | DPRINTF(("TI_GETINFO\n")); | | 872 | DPRINTF(("TI_GETINFO\n")); |
853 | return ti_getinfo(fp, fd, ioc, l); | | 873 | return ti_getinfo(fp, fd, ioc, l); |
854 | | | 874 | |
855 | case SVR4_TI_OPTMGMT: | | 875 | case SVR4_TI_OPTMGMT: |
856 | DPRINTF(("TI_OPTMGMT\n")); | | 876 | DPRINTF(("TI_OPTMGMT\n")); |
857 | return 0; | | 877 | return 0; |
858 | | | 878 | |
859 | case SVR4_TI_BIND: | | 879 | case SVR4_TI_BIND: |
860 | DPRINTF(("TI_BIND\n")); | | 880 | DPRINTF(("TI_BIND\n")); |
861 | return ti_bind(fp, fd, ioc, l); | | 881 | return ti_bind(fp, fd, ioc, l); |
862 | | | 882 | |
863 | case SVR4_TI_UNBIND: | | 883 | case SVR4_TI_UNBIND: |
864 | DPRINTF(("TI_UNBIND\n")); | | 884 | DPRINTF(("TI_UNBIND\n")); |
865 | return 0; | | 885 | return 0; |
866 | | | 886 | |
867 | default: | | 887 | default: |
868 | DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd)); | | 888 | DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd)); |
869 | return 0; | | 889 | return 0; |
870 | } | | 890 | } |
871 | } | | 891 | } |
872 | | | 892 | |
873 | | | 893 | |
874 | int | | 894 | int |
875 | svr4_stream_ti_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat) | | 895 | svr4_stream_ti_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat) |
876 | { | | 896 | { |
877 | struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat; | | 897 | struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat; |
878 | struct svr4_strm *st = svr4_stream_get(fp); | | 898 | struct svr4_strm *st = svr4_stream_get(fp); |
879 | int error; | | 899 | int error; |
880 | struct svr4_strmcmd sc; | | 900 | struct svr4_strmcmd sc; |
881 | struct mbuf *name; | | 901 | struct mbuf *name; |
882 | | | 902 | |
883 | if (st == NULL) | | 903 | if (st == NULL) |
884 | return EINVAL; | | 904 | return EINVAL; |
885 | | | 905 | |
886 | sc.offs = 0x10; | | 906 | sc.offs = 0x10; |
887 | | | 907 | |
888 | if ((error = copyin(sub, &skb, sizeof(skb))) != 0) { | | 908 | if ((error = copyin(sub, &skb, sizeof(skb))) != 0) { |
889 | DPRINTF(("ti_ioctl: error copying in strbuf\n")); | | 909 | DPRINTF(("ti_ioctl: error copying in strbuf\n")); |
890 | return error; | | 910 | return error; |
891 | } | | 911 | } |
892 | | | 912 | |
893 | switch (cmd) { | | 913 | switch (cmd) { |
894 | case SVR4_TI_GETMYNAME: | | 914 | case SVR4_TI_GETMYNAME: |
895 | DPRINTF(("TI_GETMYNAME\n")); | | 915 | DPRINTF(("TI_GETMYNAME\n")); |
896 | cmd = PRU_SOCKADDR; | | 916 | cmd = PRU_SOCKADDR; |
897 | break; | | 917 | break; |
898 | | | 918 | |
899 | case SVR4_TI_GETPEERNAME: | | 919 | case SVR4_TI_GETPEERNAME: |
900 | DPRINTF(("TI_GETPEERNAME\n")); | | 920 | DPRINTF(("TI_GETPEERNAME\n")); |
901 | cmd = PRU_PEERADDR; | | 921 | cmd = PRU_PEERADDR; |
902 | break; | | 922 | break; |
903 | | | 923 | |
904 | case SVR4_TI_SETMYNAME: | | 924 | case SVR4_TI_SETMYNAME: |
905 | DPRINTF(("TI_SETMYNAME\n")); | | 925 | DPRINTF(("TI_SETMYNAME\n")); |
906 | return 0; | | 926 | return 0; |
907 | | | 927 | |
908 | case SVR4_TI_SETPEERNAME: | | 928 | case SVR4_TI_SETPEERNAME: |
909 | DPRINTF(("TI_SETPEERNAME\n")); | | 929 | DPRINTF(("TI_SETPEERNAME\n")); |
910 | return 0; | | 930 | return 0; |
911 | default: | | 931 | default: |
912 | DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd)); | | 932 | DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd)); |
913 | return ENOSYS; | | 933 | return ENOSYS; |
914 | } | | 934 | } |
915 | | | 935 | |
916 | error = do_sys_getsockname(l, fd, cmd, &name); | | 936 | error = do_sys_getsockname(l, fd, cmd, &name); |
917 | if (error != 0) | | 937 | if (error != 0) |
918 | return error; | | 938 | return error; |
919 | | | 939 | |
920 | switch (st->s_family) { | | 940 | switch (st->s_family) { |
921 | case AF_INET: | | 941 | case AF_INET: |
922 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); | | 942 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); |
923 | skb.len = sizeof (struct sockaddr_in); | | 943 | skb.len = sizeof (struct sockaddr_in); |
924 | break; | | 944 | break; |
925 | | | 945 | |
926 | case AF_LOCAL: | | 946 | case AF_LOCAL: |
927 | sockaddr_to_netaddr_un(&sc, mtod(name, void *)); | | 947 | sockaddr_to_netaddr_un(&sc, mtod(name, void *)); |
928 | /* XXX: the length gets adjusted but the copyout doesn't */ | | 948 | /* XXX: the length gets adjusted but the copyout doesn't */ |
929 | skb.len = sizeof (struct sockaddr_un) + 4; | | 949 | skb.len = sizeof (struct sockaddr_un) + 4; |
930 | break; | | 950 | break; |
931 | | | 951 | |
932 | default: | | 952 | default: |
933 | DPRINTF(("ti_ioctl: Unsupported address family %d\n", | | 953 | DPRINTF(("ti_ioctl: Unsupported address family %d\n", |
934 | st->s_family)); | | 954 | st->s_family)); |
935 | m_free(name); | | 955 | m_free(name); |
936 | return ENOSYS; | | 956 | return ENOSYS; |
937 | } | | 957 | } |
938 | | | 958 | |
939 | error = copyout(SVR4_ADDROF(&sc), NETBSD32PTR(skb.buf), name->m_len); | | 959 | error = copyout(SVR4_ADDROF(&sc), NETBSD32PTR(skb.buf), name->m_len); |
940 | m_free(name); | | 960 | m_free(name); |
941 | if (error != 0) { | | 961 | if (error != 0) { |
942 | DPRINTF(("ti_ioctl: error copying out socket data\n")); | | 962 | DPRINTF(("ti_ioctl: error copying out socket data\n")); |
943 | return error; | | 963 | return error; |
944 | } | | 964 | } |
945 | | | 965 | |
946 | | | 966 | |
947 | if ((error = copyout(&skb, sub, sizeof(skb))) != 0) { | | 967 | if ((error = copyout(&skb, sub, sizeof(skb))) != 0) { |
948 | DPRINTF(("ti_ioctl: error copying out strbuf\n")); | | 968 | DPRINTF(("ti_ioctl: error copying out strbuf\n")); |
949 | return error; | | 969 | return error; |
950 | } | | 970 | } |
951 | | | 971 | |
952 | return error; | | 972 | return error; |
953 | } | | 973 | } |
954 | | | 974 | |
955 | | | 975 | |
956 | | | 976 | |
957 | | | 977 | |
958 | static int | | 978 | static int |
959 | i_nread(file_t *fp, struct lwp *l, register_t *retval, int fd, | | 979 | i_nread(file_t *fp, struct lwp *l, register_t *retval, int fd, |
960 | u_long cmd, void *dat) | | 980 | u_long cmd, void *dat) |
961 | { | | 981 | { |
962 | int error; | | 982 | int error; |
963 | int nread = 0; | | 983 | int nread = 0; |
964 | | | 984 | |
965 | /* | | 985 | /* |
966 | * We are supposed to return the message length in nread, and the | | 986 | * We are supposed to return the message length in nread, and the |
967 | * number of messages in retval. We don't have the notion of number | | 987 | * number of messages in retval. We don't have the notion of number |
968 | * of stream messages, so we just find out if we have any bytes waiting | | 988 | * of stream messages, so we just find out if we have any bytes waiting |
969 | * for us, and if we do, then we assume that we have at least one | | 989 | * for us, and if we do, then we assume that we have at least one |
970 | * message waiting for us. | | 990 | * message waiting for us. |
971 | */ | | 991 | */ |
972 | if ((error = (*fp->f_ops->fo_ioctl)(fp, FIONREAD, &nread)) != 0) | | 992 | if ((error = (*fp->f_ops->fo_ioctl)(fp, FIONREAD, &nread)) != 0) |
973 | return error; | | 993 | return error; |
974 | | | 994 | |
975 | if (nread != 0) | | 995 | if (nread != 0) |
976 | *retval = 1; | | 996 | *retval = 1; |
977 | else | | 997 | else |
978 | *retval = 0; | | 998 | *retval = 0; |
979 | | | 999 | |
980 | return copyout(&nread, dat, sizeof(nread)); | | 1000 | return copyout(&nread, dat, sizeof(nread)); |
981 | } | | 1001 | } |
982 | | | 1002 | |
983 | static int | | 1003 | static int |
984 | i_fdinsert(file_t *fp, struct lwp *l, register_t *retval, int fd, | | 1004 | i_fdinsert(file_t *fp, struct lwp *l, register_t *retval, int fd, |
985 | u_long cmd, void *dat) | | 1005 | u_long cmd, void *dat) |
986 | { | | 1006 | { |
987 | /* | | 1007 | /* |
988 | * Major hack again here. We assume that we are using this to | | 1008 | * Major hack again here. We assume that we are using this to |
989 | * implement accept(2). If that is the case, we have already | | 1009 | * implement accept(2). If that is the case, we have already |
990 | * called accept, and we have stored the file descriptor in | | 1010 | * called accept, and we have stored the file descriptor in |
991 | * afd. We find the file descriptor that the code wants to use | | 1011 | * afd. We find the file descriptor that the code wants to use |
992 | * in fd insert, and then we dup2() our accepted file descriptor | | 1012 | * in fd insert, and then we dup2() our accepted file descriptor |
993 | * to it. | | 1013 | * to it. |
994 | */ | | 1014 | */ |
995 | int error; | | 1015 | int error; |
996 | struct svr4_strm *st = svr4_stream_get(fp); | | 1016 | struct svr4_strm *st = svr4_stream_get(fp); |
997 | struct svr4_strfdinsert fdi; | | 1017 | struct svr4_strfdinsert fdi; |
998 | struct sys_dup2_args d2p; | | 1018 | struct sys_dup2_args d2p; |
999 | struct sys_close_args clp; | | 1019 | struct sys_close_args clp; |
1000 | | | 1020 | |
1001 | if (st == NULL) { | | 1021 | if (st == NULL) { |
1002 | DPRINTF(("fdinsert: bad file type\n")); | | 1022 | DPRINTF(("fdinsert: bad file type\n")); |
1003 | return EINVAL; | | 1023 | return EINVAL; |
1004 | } | | 1024 | } |
1005 | | | 1025 | |
1006 | if (st->s_afd == -1) { | | 1026 | if (st->s_afd == -1) { |
1007 | DPRINTF(("fdinsert: accept fd not found\n")); | | 1027 | DPRINTF(("fdinsert: accept fd not found\n")); |
1008 | return ENOENT; | | 1028 | return ENOENT; |
1009 | } | | 1029 | } |
1010 | | | 1030 | |
1011 | if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) { | | 1031 | if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) { |
1012 | DPRINTF(("fdinsert: copyin failed %d\n", error)); | | 1032 | DPRINTF(("fdinsert: copyin failed %d\n", error)); |
1013 | return error; | | 1033 | return error; |
1014 | } | | 1034 | } |
1015 | | | 1035 | |
1016 | SCARG(&d2p, from) = st->s_afd; | | 1036 | SCARG(&d2p, from) = st->s_afd; |
1017 | SCARG(&d2p, to) = fdi.fd; | | 1037 | SCARG(&d2p, to) = fdi.fd; |
1018 | | | 1038 | |
1019 | if ((error = sys_dup2(l, &d2p, retval)) != 0) { | | 1039 | if ((error = sys_dup2(l, &d2p, retval)) != 0) { |
1020 | DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n", | | 1040 | DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n", |
1021 | st->s_afd, fdi.fd, error)); | | 1041 | st->s_afd, fdi.fd, error)); |
1022 | return error; | | 1042 | return error; |
1023 | } | | 1043 | } |
1024 | | | 1044 | |
1025 | SCARG(&clp, fd) = st->s_afd; | | 1045 | SCARG(&clp, fd) = st->s_afd; |
1026 | | | 1046 | |
1027 | if ((error = sys_close(l, &clp, retval)) != 0) { | | 1047 | if ((error = sys_close(l, &clp, retval)) != 0) { |
1028 | DPRINTF(("fdinsert: close(%d) failed %d\n", | | 1048 | DPRINTF(("fdinsert: close(%d) failed %d\n", |
1029 | st->s_afd, error)); | | 1049 | st->s_afd, error)); |
1030 | return error; | | 1050 | return error; |
1031 | } | | 1051 | } |
1032 | | | 1052 | |
1033 | st->s_afd = -1; | | 1053 | st->s_afd = -1; |
1034 | | | 1054 | |
1035 | *retval = 0; | | 1055 | *retval = 0; |
1036 | return 0; | | 1056 | return 0; |
1037 | } | | 1057 | } |
1038 | | | 1058 | |
1039 | | | 1059 | |
1040 | static int | | 1060 | static int |
1041 | _i_bind_rsvd(file_t *fp, struct lwp *l, register_t *retval, | | 1061 | _i_bind_rsvd(file_t *fp, struct lwp *l, register_t *retval, |
1042 | int fd, u_long cmd, void *dat) | | 1062 | int fd, u_long cmd, void *dat) |
1043 | { | | 1063 | { |
1044 | struct sys_mkfifo_args ap; | | 1064 | struct sys_mkfifo_args ap; |
1045 | | | 1065 | |
1046 | /* | | 1066 | /* |
1047 | * This is a supposed to be a kernel and library only ioctl. | | 1067 | * This is a supposed to be a kernel and library only ioctl. |
1048 | * It gets called before ti_bind, when we have a unix | | 1068 | * It gets called before ti_bind, when we have a unix |
1049 | * socket, to physically create the socket transport and | | 1069 | * socket, to physically create the socket transport and |
1050 | * ``reserve'' it. I don't know how this get reserved inside | | 1070 | * ``reserve'' it. I don't know how this get reserved inside |
1051 | * the kernel, but we are going to create it nevertheless. | | 1071 | * the kernel, but we are going to create it nevertheless. |
1052 | */ | | 1072 | */ |
1053 | SCARG(&ap, path) = dat; | | 1073 | SCARG(&ap, path) = dat; |
1054 | SCARG(&ap, mode) = S_IFIFO; | | 1074 | SCARG(&ap, mode) = S_IFIFO; |
1055 | | | 1075 | |
1056 | return sys_mkfifo(l, &ap, retval); | | 1076 | return sys_mkfifo(l, &ap, retval); |
1057 | } | | 1077 | } |
1058 | | | 1078 | |
1059 | static int | | 1079 | static int |
1060 | _i_rele_rsvd(file_t *fp, struct lwp *l, register_t *retval, | | 1080 | _i_rele_rsvd(file_t *fp, struct lwp *l, register_t *retval, |
1061 | int fd, u_long cmd, void *dat) | | 1081 | int fd, u_long cmd, void *dat) |
1062 | { | | 1082 | { |
1063 | struct sys_unlink_args ap; | | 1083 | struct sys_unlink_args ap; |
1064 | | | 1084 | |
1065 | /* | | 1085 | /* |
1066 | * This is a supposed to be a kernel and library only ioctl. | | 1086 | * This is a supposed to be a kernel and library only ioctl. |
1067 | * I guess it is supposed to release the socket. | | 1087 | * I guess it is supposed to release the socket. |
1068 | */ | | 1088 | */ |
1069 | SCARG(&ap, path) = dat; | | 1089 | SCARG(&ap, path) = dat; |
1070 | | | 1090 | |
1071 | return sys_unlink(l, &ap, retval); | | 1091 | return sys_unlink(l, &ap, retval); |
1072 | } | | 1092 | } |
1073 | | | 1093 | |
1074 | static int | | 1094 | static int |
1075 | i_str(file_t *fp, struct lwp *l, register_t *retval, int fd, | | 1095 | i_str(file_t *fp, struct lwp *l, register_t *retval, int fd, |
1076 | u_long cmd, void *dat) | | 1096 | u_long cmd, void *dat) |
1077 | { | | 1097 | { |
1078 | int error; | | 1098 | int error; |
1079 | struct svr4_strioctl ioc; | | 1099 | struct svr4_strioctl ioc; |
1080 | | | 1100 | |
1081 | /* | | 1101 | /* |
1082 | * Noop on non sockets | | 1102 | * Noop on non sockets |
1083 | */ | | 1103 | */ |
1084 | if (fp->f_type != DTYPE_SOCKET) | | 1104 | if (fp->f_type != DTYPE_SOCKET) |
1085 | return 0; | | 1105 | return 0; |
1086 | | | 1106 | |
1087 | if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0) | | 1107 | if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0) |
1088 | return error; | | 1108 | return error; |
1089 | | | 1109 | |
1090 | #ifdef DEBUG_SVR4 | | 1110 | #ifdef DEBUG_SVR4 |
1091 | if ((error = show_ioc(">", &ioc)) != 0) | | 1111 | if ((error = show_ioc(">", &ioc)) != 0) |
1092 | return error; | | 1112 | return error; |
1093 | #endif /* DEBUG_SVR4 */ | | 1113 | #endif /* DEBUG_SVR4 */ |
1094 | | | 1114 | |
1095 | switch (ioc.cmd & 0xff00) { | | 1115 | switch (ioc.cmd & 0xff00) { |
1096 | case SVR4_SIMOD: | | 1116 | case SVR4_SIMOD: |
1097 | if ((error = sockmod(fp, fd, &ioc, l)) != 0) | | 1117 | if ((error = sockmod(fp, fd, &ioc, l)) != 0) |
1098 | return error; | | 1118 | return error; |
1099 | break; | | 1119 | break; |
1100 | | | 1120 | |
1101 | case SVR4_TIMOD: | | 1121 | case SVR4_TIMOD: |
1102 | if ((error = timod(fp, fd, &ioc, l)) != 0) | | 1122 | if ((error = timod(fp, fd, &ioc, l)) != 0) |
1103 | return error; | | 1123 | return error; |
1104 | break; | | 1124 | break; |
1105 | | | 1125 | |
1106 | default: | | 1126 | default: |
1107 | DPRINTF(("Unimplemented module %c %ld\n", | | 1127 | DPRINTF(("Unimplemented module %c %ld\n", |
1108 | (char) (cmd >> 8), cmd & 0xff)); | | 1128 | (char) (cmd >> 8), cmd & 0xff)); |
1109 | return 0; | | 1129 | return 0; |
1110 | } | | 1130 | } |
1111 | | | 1131 | |
1112 | #ifdef DEBUG_SVR4 | | 1132 | #ifdef DEBUG_SVR4 |
1113 | if ((error = show_ioc("<", &ioc)) != 0) | | 1133 | if ((error = show_ioc("<", &ioc)) != 0) |
1114 | return error; | | 1134 | return error; |
1115 | #endif /* DEBUG_SVR4 */ | | 1135 | #endif /* DEBUG_SVR4 */ |
1116 | return copyout(&ioc, dat, sizeof(ioc)); | | 1136 | return copyout(&ioc, dat, sizeof(ioc)); |
1117 | } | | 1137 | } |
1118 | | | 1138 | |
1119 | static int | | 1139 | static int |
1120 | i_setsig(file_t *fp, struct lwp *l, register_t *retval, int fd, | | 1140 | i_setsig(file_t *fp, struct lwp *l, register_t *retval, int fd, |
1121 | u_long cmd, void *dat) | | 1141 | u_long cmd, void *dat) |
1122 | { | | 1142 | { |
1123 | /* | | 1143 | /* |
1124 | * This is the best we can do for now; we cannot generate | | 1144 | * This is the best we can do for now; we cannot generate |
1125 | * signals only for specific events so the signal mask gets | | 1145 | * signals only for specific events so the signal mask gets |
1126 | * ignored; we save it just to pass it to a possible I_GETSIG... | | 1146 | * ignored; we save it just to pass it to a possible I_GETSIG... |
1127 | * | | 1147 | * |
1128 | * We alse have to fix the O_ASYNC fcntl bit, so the | | 1148 | * We alse have to fix the O_ASYNC fcntl bit, so the |
1129 | * process will get SIGPOLLs. | | 1149 | * process will get SIGPOLLs. |
1130 | */ | | 1150 | */ |
1131 | struct sys_fcntl_args fa; | | 1151 | struct sys_fcntl_args fa; |
1132 | int error; | | 1152 | int error; |
1133 | register_t oflags, flags; | | 1153 | register_t oflags, flags; |
1134 | struct svr4_strm *st = svr4_stream_get(fp); | | 1154 | struct svr4_strm *st = svr4_stream_get(fp); |
1135 | | | 1155 | |
1136 | if (st == NULL) { | | 1156 | if (st == NULL) { |
1137 | DPRINTF(("i_setsig: bad file descriptor\n")); | | 1157 | DPRINTF(("i_setsig: bad file descriptor\n")); |
1138 | return EINVAL; | | 1158 | return EINVAL; |
1139 | } | | 1159 | } |
1140 | /* get old status flags */ | | 1160 | /* get old status flags */ |
1141 | SCARG(&fa, fd) = fd; | | 1161 | SCARG(&fa, fd) = fd; |
1142 | SCARG(&fa, cmd) = F_GETFL; | | 1162 | SCARG(&fa, cmd) = F_GETFL; |
1143 | | | 1163 | |
1144 | if ((error = sys_fcntl(l, &fa, &oflags)) != 0) | | 1164 | if ((error = sys_fcntl(l, &fa, &oflags)) != 0) |
1145 | return error; | | 1165 | return error; |
1146 | | | 1166 | |
1147 | /* update the flags */ | | 1167 | /* update the flags */ |
1148 | if (dat != NULL) { | | 1168 | if (dat != NULL) { |
1149 | int mask; | | 1169 | int mask; |
1150 | | | 1170 | |
1151 | flags = oflags | O_ASYNC; | | 1171 | flags = oflags | O_ASYNC; |
1152 | mask = (int)(u_long)dat; | | 1172 | mask = (int)(u_long)dat; |
1153 | if (mask & ~SVR4_S_ALLMASK) { | | 1173 | if (mask & ~SVR4_S_ALLMASK) { |
1154 | DPRINTF(("i_setsig: bad eventmask data %x\n", mask)); | | 1174 | DPRINTF(("i_setsig: bad eventmask data %x\n", mask)); |
1155 | return EINVAL; | | 1175 | return EINVAL; |
1156 | } | | 1176 | } |
1157 | st->s_eventmask = mask; | | 1177 | st->s_eventmask = mask; |
1158 | } | | 1178 | } |
1159 | else { | | 1179 | else { |
1160 | flags = oflags & ~O_ASYNC; | | 1180 | flags = oflags & ~O_ASYNC; |
1161 | st->s_eventmask = 0; | | 1181 | st->s_eventmask = 0; |
1162 | } | | 1182 | } |
1163 | | | 1183 | |
1164 | /* set the new flags, if changed */ | | 1184 | /* set the new flags, if changed */ |
1165 | if (flags != oflags) { | | 1185 | if (flags != oflags) { |
1166 | SCARG(&fa, cmd) = F_SETFL; | | 1186 | SCARG(&fa, cmd) = F_SETFL; |
1167 | SCARG(&fa, arg) = (void *) flags; | | 1187 | SCARG(&fa, arg) = (void *) flags; |
1168 | if ((error = sys_fcntl(l, &fa, &flags)) != 0) | | 1188 | if ((error = sys_fcntl(l, &fa, &flags)) != 0) |
1169 | return error; | | 1189 | return error; |
1170 | } | | 1190 | } |
1171 | | | 1191 | |
1172 | /* set up SIGIO receiver if needed */ | | 1192 | /* set up SIGIO receiver if needed */ |
1173 | if (dat != NULL) { | | 1193 | if (dat != NULL) { |
1174 | SCARG(&fa, cmd) = F_SETOWN; | | 1194 | SCARG(&fa, cmd) = F_SETOWN; |
1175 | SCARG(&fa, arg) = (void *)(u_long)l->l_proc->p_pid; | | 1195 | SCARG(&fa, arg) = (void *)(u_long)l->l_proc->p_pid; |
1176 | return sys_fcntl(l, &fa, &flags); | | 1196 | return sys_fcntl(l, &fa, &flags); |
1177 | } | | 1197 | } |
1178 | return 0; | | 1198 | return 0; |
1179 | } | | 1199 | } |
1180 | | | 1200 | |
1181 | static int | | 1201 | static int |
1182 | i_getsig(file_t *fp, struct lwp *l, register_t *retval, | | 1202 | i_getsig(file_t *fp, struct lwp *l, register_t *retval, |
1183 | int fd, u_long cmd, void *dat) | | 1203 | int fd, u_long cmd, void *dat) |
1184 | { | | 1204 | { |
1185 | int error; | | 1205 | int error; |
1186 | | | 1206 | |
1187 | if (dat != NULL) { | | 1207 | if (dat != NULL) { |
1188 | struct svr4_strm *st = svr4_stream_get(fp); | | 1208 | struct svr4_strm *st = svr4_stream_get(fp); |
1189 | | | 1209 | |
1190 | if (st == NULL) { | | 1210 | if (st == NULL) { |
1191 | DPRINTF(("i_getsig: bad file descriptor\n")); | | 1211 | DPRINTF(("i_getsig: bad file descriptor\n")); |
1192 | return EINVAL; | | 1212 | return EINVAL; |
1193 | } | | 1213 | } |
1194 | if ((error = copyout(&st->s_eventmask, dat, | | 1214 | if ((error = copyout(&st->s_eventmask, dat, |
1195 | sizeof(st->s_eventmask))) != 0) { | | 1215 | sizeof(st->s_eventmask))) != 0) { |
1196 | DPRINTF(("i_getsig: bad eventmask pointer\n")); | | 1216 | DPRINTF(("i_getsig: bad eventmask pointer\n")); |
1197 | return error; | | 1217 | return error; |
1198 | } | | 1218 | } |
1199 | } | | 1219 | } |
1200 | return 0; | | 1220 | return 0; |
1201 | } | | 1221 | } |
1202 | | | 1222 | |
1203 | int | | 1223 | int |
1204 | svr4_stream_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat) | | 1224 | svr4_stream_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat) |
1205 | { | | 1225 | { |
1206 | *retval = 0; | | 1226 | *retval = 0; |
1207 | | | 1227 | |
1208 | /* | | 1228 | /* |
1209 | * All the following stuff assumes "sockmod" is pushed... | | 1229 | * All the following stuff assumes "sockmod" is pushed... |
1210 | */ | | 1230 | */ |
1211 | switch (cmd) { | | 1231 | switch (cmd) { |
1212 | case SVR4_I_NREAD: | | 1232 | case SVR4_I_NREAD: |
1213 | DPRINTF(("I_NREAD\n")); | | 1233 | DPRINTF(("I_NREAD\n")); |
1214 | return i_nread(fp, l, retval, fd, cmd, dat); | | 1234 | return i_nread(fp, l, retval, fd, cmd, dat); |
1215 | | | 1235 | |
1216 | case SVR4_I_PUSH: | | 1236 | case SVR4_I_PUSH: |
1217 | DPRINTF(("I_PUSH\n")); | | 1237 | DPRINTF(("I_PUSH\n")); |
1218 | return 0; | | 1238 | return 0; |
1219 | | | 1239 | |
1220 | case SVR4_I_POP: | | 1240 | case SVR4_I_POP: |
1221 | DPRINTF(("I_POP\n")); | | 1241 | DPRINTF(("I_POP\n")); |
1222 | return 0; | | 1242 | return 0; |
1223 | | | 1243 | |
1224 | case SVR4_I_LOOK: | | 1244 | case SVR4_I_LOOK: |
1225 | DPRINTF(("I_LOOK\n")); | | 1245 | DPRINTF(("I_LOOK\n")); |
1226 | return 0; | | 1246 | return 0; |
1227 | | | 1247 | |
1228 | case SVR4_I_FLUSH: | | 1248 | case SVR4_I_FLUSH: |
1229 | DPRINTF(("I_FLUSH\n")); | | 1249 | DPRINTF(("I_FLUSH\n")); |
1230 | return 0; | | 1250 | return 0; |
1231 | | | 1251 | |
1232 | case SVR4_I_SRDOPT: | | 1252 | case SVR4_I_SRDOPT: |
1233 | DPRINTF(("I_SRDOPT\n")); | | 1253 | DPRINTF(("I_SRDOPT\n")); |
1234 | return 0; | | 1254 | return 0; |
1235 | | | 1255 | |
1236 | case SVR4_I_GRDOPT: | | 1256 | case SVR4_I_GRDOPT: |
1237 | DPRINTF(("I_GRDOPT\n")); | | 1257 | DPRINTF(("I_GRDOPT\n")); |
1238 | return 0; | | 1258 | return 0; |
1239 | | | 1259 | |
1240 | case SVR4_I_STR: | | 1260 | case SVR4_I_STR: |
1241 | DPRINTF(("I_STR\n")); | | 1261 | DPRINTF(("I_STR\n")); |
1242 | return i_str(fp, l, retval, fd, cmd, dat); | | 1262 | return i_str(fp, l, retval, fd, cmd, dat); |
1243 | | | 1263 | |
1244 | case SVR4_I_SETSIG: | | 1264 | case SVR4_I_SETSIG: |
1245 | DPRINTF(("I_SETSIG\n")); | | 1265 | DPRINTF(("I_SETSIG\n")); |
1246 | return i_setsig(fp, l, retval, fd, cmd, dat); | | 1266 | return i_setsig(fp, l, retval, fd, cmd, dat); |
1247 | | | 1267 | |
1248 | case SVR4_I_GETSIG: | | 1268 | case SVR4_I_GETSIG: |
1249 | DPRINTF(("I_GETSIG\n")); | | 1269 | DPRINTF(("I_GETSIG\n")); |
1250 | return i_getsig(fp, l, retval, fd, cmd, dat); | | 1270 | return i_getsig(fp, l, retval, fd, cmd, dat); |
1251 | | | 1271 | |
1252 | case SVR4_I_FIND: | | 1272 | case SVR4_I_FIND: |
1253 | DPRINTF(("I_FIND\n")); | | 1273 | DPRINTF(("I_FIND\n")); |
1254 | /* | | 1274 | /* |
1255 | * Here we are not pushing modules really, we just | | 1275 | * Here we are not pushing modules really, we just |
1256 | * pretend all are present | | 1276 | * pretend all are present |
1257 | */ | | 1277 | */ |
1258 | *retval = 1; | | 1278 | *retval = 1; |
1259 | return 0; | | 1279 | return 0; |
1260 | | | 1280 | |
1261 | case SVR4_I_LINK: | | 1281 | case SVR4_I_LINK: |
1262 | DPRINTF(("I_LINK\n")); | | 1282 | DPRINTF(("I_LINK\n")); |
1263 | return 0; | | 1283 | return 0; |
1264 | | | 1284 | |
1265 | case SVR4_I_UNLINK: | | 1285 | case SVR4_I_UNLINK: |
1266 | DPRINTF(("I_UNLINK\n")); | | 1286 | DPRINTF(("I_UNLINK\n")); |
1267 | return 0; | | 1287 | return 0; |
1268 | | | 1288 | |
1269 | case SVR4_I_ERECVFD: | | 1289 | case SVR4_I_ERECVFD: |
1270 | DPRINTF(("I_ERECVFD\n")); | | 1290 | DPRINTF(("I_ERECVFD\n")); |
1271 | return 0; | | 1291 | return 0; |
1272 | | | 1292 | |
1273 | case SVR4_I_PEEK: | | 1293 | case SVR4_I_PEEK: |
1274 | DPRINTF(("I_PEEK\n")); | | 1294 | DPRINTF(("I_PEEK\n")); |
1275 | return 0; | | 1295 | return 0; |
1276 | | | 1296 | |
1277 | case SVR4_I_FDINSERT: | | 1297 | case SVR4_I_FDINSERT: |
1278 | DPRINTF(("I_FDINSERT\n")); | | 1298 | DPRINTF(("I_FDINSERT\n")); |
1279 | return i_fdinsert(fp, l, retval, fd, cmd, dat); | | 1299 | return i_fdinsert(fp, l, retval, fd, cmd, dat); |
1280 | | | 1300 | |
1281 | case SVR4_I_SENDFD: | | 1301 | case SVR4_I_SENDFD: |
1282 | DPRINTF(("I_SENDFD\n")); | | 1302 | DPRINTF(("I_SENDFD\n")); |
1283 | return 0; | | 1303 | return 0; |
1284 | | | 1304 | |
1285 | case SVR4_I_RECVFD: | | 1305 | case SVR4_I_RECVFD: |
1286 | DPRINTF(("I_RECVFD\n")); | | 1306 | DPRINTF(("I_RECVFD\n")); |
1287 | return 0; | | 1307 | return 0; |
1288 | | | 1308 | |
1289 | case SVR4_I_SWROPT: | | 1309 | case SVR4_I_SWROPT: |
1290 | DPRINTF(("I_SWROPT\n")); | | 1310 | DPRINTF(("I_SWROPT\n")); |
1291 | return 0; | | 1311 | return 0; |
1292 | | | 1312 | |
1293 | case SVR4_I_GWROPT: | | 1313 | case SVR4_I_GWROPT: |
1294 | DPRINTF(("I_GWROPT\n")); | | 1314 | DPRINTF(("I_GWROPT\n")); |
1295 | return 0; | | 1315 | return 0; |
1296 | | | 1316 | |
1297 | case SVR4_I_LIST: | | 1317 | case SVR4_I_LIST: |
1298 | DPRINTF(("I_LIST\n")); | | 1318 | DPRINTF(("I_LIST\n")); |
1299 | return 0; | | 1319 | return 0; |
1300 | | | 1320 | |
1301 | case SVR4_I_PLINK: | | 1321 | case SVR4_I_PLINK: |
1302 | DPRINTF(("I_PLINK\n")); | | 1322 | DPRINTF(("I_PLINK\n")); |
1303 | return 0; | | 1323 | return 0; |
1304 | | | 1324 | |
1305 | case SVR4_I_PUNLINK: | | 1325 | case SVR4_I_PUNLINK: |
1306 | DPRINTF(("I_PUNLINK\n")); | | 1326 | DPRINTF(("I_PUNLINK\n")); |
1307 | return 0; | | 1327 | return 0; |
1308 | | | 1328 | |
1309 | case SVR4_I_SETEV: | | 1329 | case SVR4_I_SETEV: |
1310 | DPRINTF(("I_SETEV\n")); | | 1330 | DPRINTF(("I_SETEV\n")); |
1311 | return 0; | | 1331 | return 0; |
1312 | | | 1332 | |
1313 | case SVR4_I_GETEV: | | 1333 | case SVR4_I_GETEV: |
1314 | DPRINTF(("I_GETEV\n")); | | 1334 | DPRINTF(("I_GETEV\n")); |
1315 | return 0; | | 1335 | return 0; |
1316 | | | 1336 | |
1317 | case SVR4_I_STREV: | | 1337 | case SVR4_I_STREV: |
1318 | DPRINTF(("I_STREV\n")); | | 1338 | DPRINTF(("I_STREV\n")); |
1319 | return 0; | | 1339 | return 0; |
1320 | | | 1340 | |
1321 | case SVR4_I_UNSTREV: | | 1341 | case SVR4_I_UNSTREV: |
1322 | DPRINTF(("I_UNSTREV\n")); | | 1342 | DPRINTF(("I_UNSTREV\n")); |
1323 | return 0; | | 1343 | return 0; |
1324 | | | 1344 | |
1325 | case SVR4_I_FLUSHBAND: | | 1345 | case SVR4_I_FLUSHBAND: |
1326 | DPRINTF(("I_FLUSHBAND\n")); | | 1346 | DPRINTF(("I_FLUSHBAND\n")); |
1327 | return 0; | | 1347 | return 0; |
1328 | | | 1348 | |
1329 | case SVR4_I_CKBAND: | | 1349 | case SVR4_I_CKBAND: |
1330 | DPRINTF(("I_CKBAND\n")); | | 1350 | DPRINTF(("I_CKBAND\n")); |
1331 | return 0; | | 1351 | return 0; |
1332 | | | 1352 | |
1333 | case SVR4_I_GETBAND: | | 1353 | case SVR4_I_GETBAND: |
1334 | DPRINTF(("I_GETBANK\n")); | | 1354 | DPRINTF(("I_GETBANK\n")); |
1335 | return 0; | | 1355 | return 0; |
1336 | | | 1356 | |
1337 | case SVR4_I_ATMARK: | | 1357 | case SVR4_I_ATMARK: |
1338 | DPRINTF(("I_ATMARK\n")); | | 1358 | DPRINTF(("I_ATMARK\n")); |
1339 | return 0; | | 1359 | return 0; |
1340 | | | 1360 | |
1341 | case SVR4_I_SETCLTIME: | | 1361 | case SVR4_I_SETCLTIME: |
1342 | DPRINTF(("I_SETCLTIME\n")); | | 1362 | DPRINTF(("I_SETCLTIME\n")); |
1343 | return 0; | | 1363 | return 0; |
1344 | | | 1364 | |
1345 | case SVR4_I_GETCLTIME: | | 1365 | case SVR4_I_GETCLTIME: |
1346 | DPRINTF(("I_GETCLTIME\n")); | | 1366 | DPRINTF(("I_GETCLTIME\n")); |
1347 | return 0; | | 1367 | return 0; |
1348 | | | 1368 | |
1349 | case SVR4_I_CANPUT: | | 1369 | case SVR4_I_CANPUT: |
1350 | DPRINTF(("I_CANPUT\n")); | | 1370 | DPRINTF(("I_CANPUT\n")); |
1351 | return 0; | | 1371 | return 0; |
1352 | | | 1372 | |
1353 | case SVR4__I_BIND_RSVD: | | 1373 | case SVR4__I_BIND_RSVD: |
1354 | DPRINTF(("_I_BIND_RSVD\n")); | | 1374 | DPRINTF(("_I_BIND_RSVD\n")); |
1355 | return _i_bind_rsvd(fp, l, retval, fd, cmd, dat); | | 1375 | return _i_bind_rsvd(fp, l, retval, fd, cmd, dat); |
1356 | | | 1376 | |
1357 | case SVR4__I_RELE_RSVD: | | 1377 | case SVR4__I_RELE_RSVD: |
1358 | DPRINTF(("_I_RELE_RSVD\n")); | | 1378 | DPRINTF(("_I_RELE_RSVD\n")); |
1359 | return _i_rele_rsvd(fp, l, retval, fd, cmd, dat); | | 1379 | return _i_rele_rsvd(fp, l, retval, fd, cmd, dat); |
1360 | | | 1380 | |
1361 | default: | | 1381 | default: |
1362 | DPRINTF(("unimpl cmd = %lx\n", cmd)); | | 1382 | DPRINTF(("unimpl cmd = %lx\n", cmd)); |
1363 | break; | | 1383 | break; |
1364 | } | | 1384 | } |
1365 | | | 1385 | |
1366 | return 0; | | 1386 | return 0; |
1367 | } | | 1387 | } |
1368 | | | 1388 | |
1369 | | | 1389 | |
1370 | | | 1390 | |
1371 | | | 1391 | |
1372 | int | | 1392 | int |
1373 | svr4_sys_putmsg(struct lwp *l, const struct svr4_sys_putmsg_args *uap, register_t *retval) | | 1393 | svr4_sys_putmsg(struct lwp *l, const struct svr4_sys_putmsg_args *uap, register_t *retval) |
1374 | { | | 1394 | { |
1375 | struct proc *p = l->l_proc; | | 1395 | struct proc *p = l->l_proc; |
1376 | file_t *fp; | | 1396 | file_t *fp; |
1377 | struct svr4_strbuf dat, ctl; | | 1397 | struct svr4_strbuf dat, ctl; |
1378 | struct svr4_strmcmd sc; | | 1398 | struct svr4_strmcmd sc; |
1379 | struct sockaddr_in sain; | | 1399 | struct sockaddr_in sain; |
1380 | struct sockaddr_un saun; | | 1400 | struct sockaddr_un saun; |
1381 | void *skp; | | 1401 | void *skp; |
1382 | int sasize; | | 1402 | int sasize; |
1383 | struct svr4_strm *st; | | 1403 | struct svr4_strm *st; |
1384 | int error; | | 1404 | int error; |
1385 | struct mbuf *nam; | | 1405 | struct mbuf *nam; |
1386 | struct msghdr msg; | | 1406 | struct msghdr msg; |
1387 | struct iovec aiov; | | 1407 | struct iovec aiov; |
1388 | | | 1408 | |
1389 | | | 1409 | |
1390 | #ifdef DEBUG_SVR4 | | 1410 | #ifdef DEBUG_SVR4 |
1391 | show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl), | | 1411 | show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl), |
1392 | SCARG(uap, dat), SCARG(uap, flags)); | | 1412 | SCARG(uap, dat), SCARG(uap, flags)); |
1393 | #endif /* DEBUG_SVR4 */ | | 1413 | #endif /* DEBUG_SVR4 */ |
1394 | | | 1414 | |
1395 | if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) | | 1415 | if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) |
1396 | return EBADF; | | 1416 | return EBADF; |
1397 | | | 1417 | |
1398 | KERNEL_LOCK(1, NULL); /* svr4_find_socket */ | | 1418 | KERNEL_LOCK(1, NULL); /* svr4_find_socket */ |
1399 | | | 1419 | |
1400 | if (SCARG_PTR(uap, ctl) != NULL) { | | 1420 | if (SCARG_PTR(uap, ctl) != NULL) { |
1401 | if ((error = copyin(SCARG_PTR(uap, ctl), | | 1421 | if ((error = copyin(SCARG_PTR(uap, ctl), |
1402 | &ctl, sizeof(ctl))) != 0) | | 1422 | &ctl, sizeof(ctl))) != 0) |
1403 | goto out; | | 1423 | goto out; |
1404 | } else | | 1424 | } else |
1405 | ctl.len = -1; | | 1425 | ctl.len = -1; |
1406 | | | 1426 | |
1407 | if (SCARG_PTR(uap, dat) != NULL) { | | 1427 | if (SCARG_PTR(uap, dat) != NULL) { |
1408 | if ((error = copyin(SCARG_PTR(uap, dat), | | 1428 | if ((error = copyin(SCARG_PTR(uap, dat), |
1409 | &dat, sizeof(dat))) != 0) | | 1429 | &dat, sizeof(dat))) != 0) |
1410 | goto out; | | 1430 | goto out; |
1411 | } else | | 1431 | } else |
1412 | dat.len = -1; | | 1432 | dat.len = -1; |
1413 | | | 1433 | |
1414 | /* | | 1434 | /* |
1415 | * Only for sockets for now. | | 1435 | * Only for sockets for now. |
1416 | */ | | 1436 | */ |
1417 | if ((st = svr4_stream_get(fp)) == NULL) { | | 1437 | if ((st = svr4_stream_get(fp)) == NULL) { |
1418 | DPRINTF(("putmsg: bad file type\n")); | | 1438 | DPRINTF(("putmsg: bad file type\n")); |
1419 | error = EINVAL; | | 1439 | error = EINVAL; |
1420 | goto out; | | 1440 | goto out; |
1421 | } | | 1441 | } |
1422 | | | 1442 | |
1423 | if (ctl.len > sizeof(sc)) { | | 1443 | if (ctl.len < offsetof(struct svr4_strmcmd, pad) || |
| | | 1444 | ctl.len > sizeof(sc)) { |
1424 | DPRINTF(("putmsg: Bad control size %ld != %d\n", | | 1445 | DPRINTF(("putmsg: Bad control size %ld != %d\n", |
1425 | (unsigned long)sizeof(struct svr4_strmcmd), ctl.len)); | | 1446 | (unsigned long)sizeof(struct svr4_strmcmd), ctl.len)); |
1426 | error = EINVAL; | | 1447 | error = EINVAL; |
1427 | goto out; | | 1448 | goto out; |
1428 | } | | 1449 | } |
1429 | | | 1450 | |
1430 | if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0) | | 1451 | if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0) |
1431 | goto out; | | 1452 | goto out; |
| | | 1453 | if (sc.offs < 0 || |
| | | 1454 | sc.len < 0 || |
| | | 1455 | sc.len > ctl.len || |
| | | 1456 | sc.offs > ctl.len - sc.len) { |
| | | 1457 | error = EINVAL; |
| | | 1458 | goto out; |
| | | 1459 | } |
1432 | | | 1460 | |
1433 | switch (st->s_family) { | | 1461 | switch (st->s_family) { |
1434 | case AF_INET: | | 1462 | case AF_INET: |
1435 | if (sc.len != sizeof(sain)) { | | 1463 | if (sc.len != sizeof(sain)) { |
1436 | #ifdef notyet | | 1464 | #ifdef notyet |
1437 | if (sc.cmd == SVR4_TI_DATA_REQUEST) { | | 1465 | if (sc.cmd == SVR4_TI_DATA_REQUEST) { |
1438 | struct sys_write_args wa; | | 1466 | struct sys_write_args wa; |
1439 | | | 1467 | |
1440 | /* Solaris seems to use sc.cmd = 3 to | | 1468 | /* Solaris seems to use sc.cmd = 3 to |
1441 | * send "expedited" data. telnet uses | | 1469 | * send "expedited" data. telnet uses |
1442 | * this for options processing, sending EOF, | | 1470 | * this for options processing, sending EOF, |
1443 | * etc. I'm sure other things use it too. | | 1471 | * etc. I'm sure other things use it too. |
1444 | * I don't have any documentation | | 1472 | * I don't have any documentation |
1445 | * on it, so I'm making a guess that this | | 1473 | * on it, so I'm making a guess that this |
1446 | * is how it works. newton@atdot.dotat.org XXX | | 1474 | * is how it works. newton@atdot.dotat.org XXX |
1447 | * | | 1475 | * |
1448 | * Hmm, expedited data seems to be sc.cmd = 4. | | 1476 | * Hmm, expedited data seems to be sc.cmd = 4. |
1449 | * I think 3 is normal data. (christos) | | 1477 | * I think 3 is normal data. (christos) |
1450 | */ | | 1478 | */ |
1451 | DPRINTF(("sending expedited data (?)\n")); | | 1479 | DPRINTF(("sending expedited data (?)\n")); |
1452 | SCARG(&wa, fd) = SCARG(uap, fd); | | 1480 | SCARG(&wa, fd) = SCARG(uap, fd); |
1453 | SCARG(&wa, buf) = dat.buf; | | 1481 | SCARG(&wa, buf) = dat.buf; |
1454 | SCARG(&wa, nbyte) = dat.len; | | 1482 | SCARG(&wa, nbyte) = dat.len; |
1455 | error = sys_write(l, &wa, retval); | | 1483 | error = sys_write(l, &wa, retval); |
1456 | goto out; | | 1484 | goto out; |
1457 | } | | 1485 | } |
1458 | #endif | | 1486 | #endif |
1459 | DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len)); | | 1487 | DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len)); |
1460 | error = EINVAL; | | 1488 | error = EINVAL; |
1461 | goto out; | | 1489 | goto out; |
1462 | } | | 1490 | } |
1463 | netaddr_to_sockaddr_in(&sain, &sc); | | 1491 | netaddr_to_sockaddr_in(&sain, &sc); |
1464 | skp = &sain; | | 1492 | skp = &sain; |
1465 | sasize = sizeof(sain); | | 1493 | sasize = sizeof(sain); |
1466 | error = sain.sin_family != st->s_family; | | 1494 | error = sain.sin_family != st->s_family; |
1467 | break; | | 1495 | break; |
1468 | | | 1496 | |
1469 | case AF_LOCAL: | | 1497 | case AF_LOCAL: |
1470 | if (ctl.len == 8) { | | 1498 | if (ctl.len == 8) { |
1471 | /* We are doing an accept; succeed */ | | 1499 | /* We are doing an accept; succeed */ |
1472 | DPRINTF(("putmsg: Do nothing\n")); | | 1500 | DPRINTF(("putmsg: Do nothing\n")); |
1473 | *retval = 0; | | 1501 | *retval = 0; |
1474 | error = 0; | | 1502 | error = 0; |
1475 | goto out; | | 1503 | goto out; |
1476 | } | | 1504 | } else if (sc.len < sizeof(dev_t[2])) { |
1477 | else { | | 1505 | *retval = 0; |
| | | 1506 | error = EINVAL; |
| | | 1507 | goto out; |
| | | 1508 | } else { |
1478 | /* Maybe we've been given a device/inode pair */ | | 1509 | /* Maybe we've been given a device/inode pair */ |
1479 | dev_t *dev = SVR4_ADDROF(&sc); | | 1510 | dev_t *dev = SVR4_ADDROF(&sc); |
1480 | svr4_ino_t *ino = (svr4_ino_t *) &dev[1]; | | 1511 | svr4_ino_t *ino = (svr4_ino_t *) &dev[1]; |
1481 | skp = svr4_find_socket(p, fp, *dev, *ino); | | 1512 | skp = svr4_find_socket(p, fp, *dev, *ino); |
1482 | if (skp == NULL) { | | 1513 | if (skp == NULL) { |
1483 | skp = &saun; | | 1514 | skp = &saun; |
1484 | /* I guess we have it by name */ | | 1515 | /* I guess we have it by name */ |
1485 | netaddr_to_sockaddr_un(skp, &sc); | | 1516 | netaddr_to_sockaddr_un(skp, &sc); |
1486 | } | | 1517 | } |
1487 | sasize = sizeof(saun); | | 1518 | sasize = sizeof(saun); |
1488 | } | | 1519 | } |
1489 | break; | | 1520 | break; |
1490 | | | 1521 | |
1491 | default: | | 1522 | default: |
1492 | DPRINTF(("putmsg: Unsupported address family %d\n", | | 1523 | DPRINTF(("putmsg: Unsupported address family %d\n", |
1493 | st->s_family)); | | 1524 | st->s_family)); |
1494 | error = ENOSYS; | | 1525 | error = ENOSYS; |
1495 | goto out; | | 1526 | goto out; |
1496 | } | | 1527 | } |
1497 | | | 1528 | |
1498 | nam = m_get(M_WAIT, MT_SONAME); | | 1529 | nam = m_get(M_WAIT, MT_SONAME); |
1499 | nam->m_len = sasize; | | 1530 | nam->m_len = sasize; |
1500 | memcpy(mtod(nam, void *), skp, sasize); | | 1531 | memcpy(mtod(nam, void *), skp, sasize); |
1501 | | | 1532 | |
1502 | switch (st->s_cmd = sc.cmd) { | | 1533 | switch (st->s_cmd = sc.cmd) { |
1503 | case SVR4_TI_CONNECT_REQUEST: /* connect */ | | 1534 | case SVR4_TI_CONNECT_REQUEST: /* connect */ |
1504 | KERNEL_UNLOCK_ONE(NULL); | | 1535 | KERNEL_UNLOCK_ONE(NULL); |
| | | 1536 | fd_putfile(SCARG(uap, fd)); |
1505 | return do_sys_connect(l, SCARG(uap, fd), nam); | | 1537 | return do_sys_connect(l, SCARG(uap, fd), nam); |
1506 | | | 1538 | |
1507 | case SVR4_TI_SENDTO_REQUEST: /* sendto */ | | 1539 | case SVR4_TI_SENDTO_REQUEST: /* sendto */ |
1508 | KERNEL_UNLOCK_ONE(NULL); | | 1540 | KERNEL_UNLOCK_ONE(NULL); |
| | | 1541 | fd_putfile(SCARG(uap, fd)); |
1509 | msg.msg_name = nam; | | 1542 | msg.msg_name = nam; |
1510 | msg.msg_namelen = sasize; | | 1543 | msg.msg_namelen = sasize; |
1511 | msg.msg_iov = &aiov; | | 1544 | msg.msg_iov = &aiov; |
1512 | msg.msg_iovlen = 1; | | 1545 | msg.msg_iovlen = 1; |
1513 | msg.msg_control = NULL; | | 1546 | msg.msg_control = NULL; |
1514 | msg.msg_flags = MSG_NAMEMBUF; | | 1547 | msg.msg_flags = MSG_NAMEMBUF; |
1515 | aiov.iov_base = NETBSD32PTR(dat.buf); | | 1548 | aiov.iov_base = NETBSD32PTR(dat.buf); |
1516 | aiov.iov_len = dat.len; | | 1549 | aiov.iov_len = dat.len; |
1517 | error = do_sys_sendmsg(l, SCARG(uap, fd), &msg, | | 1550 | error = do_sys_sendmsg(l, SCARG(uap, fd), &msg, |
1518 | SCARG(uap, flags), retval); | | 1551 | SCARG(uap, flags), retval); |
1519 | | | 1552 | |
1520 | *retval = 0; | | 1553 | *retval = 0; |
1521 | return error; | | 1554 | return error; |
1522 | | | 1555 | |
1523 | default: | | 1556 | default: |
1524 | m_free(nam); | | 1557 | m_free(nam); |
1525 | DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); | | 1558 | DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); |
1526 | error = ENOSYS; | | 1559 | error = ENOSYS; |
1527 | goto out; | | 1560 | goto out; |
1528 | } | | 1561 | } |
1529 | | | 1562 | |
1530 | out: | | 1563 | out: |
1531 | KERNEL_UNLOCK_ONE(NULL); | | 1564 | KERNEL_UNLOCK_ONE(NULL); |
1532 | fd_putfile(SCARG(uap, fd)); | | 1565 | fd_putfile(SCARG(uap, fd)); |
1533 | return error; | | 1566 | return error; |
1534 | } | | 1567 | } |
1535 | | | 1568 | |
1536 | | | 1569 | |
1537 | int | | 1570 | int |
1538 | svr4_sys_getmsg(struct lwp *l, const struct svr4_sys_getmsg_args *uap, register_t *retval) | | 1571 | svr4_sys_getmsg(struct lwp *l, const struct svr4_sys_getmsg_args *uap, register_t *retval) |
1539 | { | | 1572 | { |
1540 | file_t *fp; | | 1573 | file_t *fp; |
1541 | struct svr4_strbuf dat, ctl; | | 1574 | struct svr4_strbuf dat, ctl; |
1542 | struct svr4_strmcmd sc; | | 1575 | struct svr4_strmcmd sc; |
1543 | int error = 0; | | 1576 | int error = 0; |
1544 | struct msghdr msg; | | 1577 | struct msghdr msg; |
1545 | struct iovec aiov; | | 1578 | struct iovec aiov; |
1546 | struct svr4_strm *st; | | 1579 | struct svr4_strm *st; |
1547 | int fl; | | 1580 | int fl; |
1548 | struct mbuf *name; | | 1581 | struct mbuf *name; |
1549 | | | 1582 | |
1550 | memset(&sc, 0, sizeof(sc)); | | 1583 | memset(&sc, 0, sizeof(sc)); |
1551 | | | 1584 | |
1552 | #ifdef DEBUG_SVR4 | | 1585 | #ifdef DEBUG_SVR4 |
1553 | show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl), | | 1586 | show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl), |
1554 | SCARG(uap, dat), 0); | | 1587 | SCARG(uap, dat), 0); |
1555 | #endif /* DEBUG_SVR4 */ | | 1588 | #endif /* DEBUG_SVR4 */ |
1556 | | | 1589 | |
1557 | if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) | | 1590 | if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) |
1558 | return EBADF; | | 1591 | return EBADF; |
1559 | | | 1592 | |
1560 | if (SCARG_PTR(uap, ctl) != NULL) { | | 1593 | if (SCARG_PTR(uap, ctl) != NULL) { |
1561 | if ((error = copyin(SCARG_PTR(uap, ctl), &ctl, | | 1594 | if ((error = copyin(SCARG_PTR(uap, ctl), &ctl, |
1562 | sizeof(ctl))) != 0) | | 1595 | sizeof(ctl))) != 0) |
1563 | goto out; | | 1596 | goto out; |
1564 | } else { | | 1597 | } else { |
1565 | ctl.len = -1; | | 1598 | ctl.len = -1; |
1566 | ctl.maxlen = 0; | | 1599 | ctl.maxlen = 0; |
1567 | } | | 1600 | } |
1568 | | | 1601 | |
1569 | if (SCARG_PTR(uap, dat) != NULL) { | | 1602 | if (SCARG_PTR(uap, dat) != NULL) { |
1570 | if ((error = copyin(SCARG_PTR(uap, dat), &dat, | | 1603 | if ((error = copyin(SCARG_PTR(uap, dat), &dat, |
1571 | sizeof(dat))) != 0) | | 1604 | sizeof(dat))) != 0) |
1572 | goto out; | | 1605 | goto out; |
1573 | } else { | | 1606 | } else { |
1574 | dat.len = -1; | | 1607 | dat.len = -1; |
1575 | dat.maxlen = 0; | | 1608 | dat.maxlen = 0; |
1576 | } | | 1609 | } |
1577 | | | 1610 | |
1578 | /* | | 1611 | /* |
1579 | * Only for sockets for now. | | 1612 | * Only for sockets for now. |
1580 | */ | | 1613 | */ |
1581 | if ((st = svr4_stream_get(fp)) == NULL) { | | 1614 | if ((st = svr4_stream_get(fp)) == NULL) { |
1582 | DPRINTF(("getmsg: bad file type\n")); | | 1615 | DPRINTF(("getmsg: bad file type\n")); |
1583 | error = EINVAL; | | 1616 | error = EINVAL; |
1584 | goto out; | | 1617 | goto out; |
1585 | } | | 1618 | } |
1586 | | | 1619 | |
1587 | if (ctl.maxlen == -1 || dat.maxlen == -1) { | | 1620 | if (ctl.maxlen == -1 || dat.maxlen == -1) { |
1588 | DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n")); | | 1621 | DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n")); |
1589 | error = ENOSYS; | | 1622 | error = ENOSYS; |
1590 | goto out; | | 1623 | goto out; |
1591 | } | | 1624 | } |
1592 | | | 1625 | |
1593 | switch (st->s_family) { | | 1626 | switch (st->s_family) { |
1594 | case AF_INET: | | 1627 | case AF_INET: |
1595 | case AF_LOCAL: | | 1628 | case AF_LOCAL: |
1596 | break; | | 1629 | break; |
1597 | | | 1630 | |
1598 | default: | | 1631 | default: |
1599 | DPRINTF(("getmsg: Unsupported address family %d\n", | | 1632 | DPRINTF(("getmsg: Unsupported address family %d\n", |
1600 | st->s_family)); | | 1633 | st->s_family)); |
1601 | goto out; | | 1634 | goto out; |
1602 | } | | 1635 | } |
1603 | | | 1636 | |
1604 | switch (st->s_cmd) { | | 1637 | switch (st->s_cmd) { |
1605 | case SVR4_TI_CONNECT_REQUEST: | | 1638 | case SVR4_TI_CONNECT_REQUEST: |
1606 | DPRINTF(("getmsg: TI_CONNECT_REQUEST\n")); | | 1639 | DPRINTF(("getmsg: TI_CONNECT_REQUEST\n")); |
1607 | /* | | 1640 | /* |
1608 | * We do the connect in one step, so the putmsg should | | 1641 | * We do the connect in one step, so the putmsg should |
1609 | * have gotten the error. | | 1642 | * have gotten the error. |
1610 | */ | | 1643 | */ |
1611 | sc.cmd = SVR4_TI_OK_REPLY; | | 1644 | sc.cmd = SVR4_TI_OK_REPLY; |
1612 | sc.len = 0; | | 1645 | sc.len = 0; |
1613 | | | 1646 | |
1614 | ctl.len = 8; | | 1647 | ctl.len = 8; |
1615 | dat.len = -1; | | 1648 | dat.len = -1; |
1616 | fl = 1; | | 1649 | fl = 1; |
1617 | st->s_cmd = sc.cmd; | | 1650 | st->s_cmd = sc.cmd; |
1618 | break; | | 1651 | break; |
1619 | | | 1652 | |
1620 | case SVR4_TI_OK_REPLY: | | 1653 | case SVR4_TI_OK_REPLY: |
1621 | DPRINTF(("getmsg: TI_OK_REPLY\n")); | | 1654 | DPRINTF(("getmsg: TI_OK_REPLY\n")); |
1622 | /* | | 1655 | /* |
1623 | * We are immediately after a connect reply, so we send | | 1656 | * We are immediately after a connect reply, so we send |
1624 | * a connect verification. | | 1657 | * a connect verification. |
1625 | */ | | 1658 | */ |
1626 | | | 1659 | |
1627 | error = do_sys_getsockname(l, SCARG(uap, fd), PRU_SOCKADDR, | | 1660 | error = do_sys_getsockname(l, SCARG(uap, fd), PRU_SOCKADDR, |
1628 | &name); | | 1661 | &name); |
1629 | if (error != 0) { | | 1662 | if (error != 0) { |
1630 | DPRINTF(("getmsg: getpeername failed %d\n", error)); | | 1663 | DPRINTF(("getmsg: getpeername failed %d\n", error)); |
1631 | goto out; | | 1664 | goto out; |
1632 | } | | 1665 | } |
1633 | | | 1666 | |
1634 | sc.cmd = SVR4_TI_CONNECT_REPLY; | | 1667 | sc.cmd = SVR4_TI_CONNECT_REPLY; |
1635 | sc.pad[0] = 0x4; | | 1668 | sc.pad[0] = 0x4; |
1636 | sc.offs = 0x18; | | 1669 | sc.offs = 0x18; |
1637 | sc.pad[1] = 0x14; | | 1670 | sc.pad[1] = 0x14; |
1638 | sc.pad[2] = 0x04000402; | | 1671 | sc.pad[2] = 0x04000402; |
1639 | | | 1672 | |
1640 | switch (st->s_family) { | | 1673 | switch (st->s_family) { |
1641 | case AF_INET: | | 1674 | case AF_INET: |
1642 | sc.len = sizeof (struct sockaddr_in) + 4; | | 1675 | sc.len = sizeof (struct sockaddr_in) + 4; |
1643 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); | | 1676 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); |
1644 | break; | | 1677 | break; |
1645 | | | 1678 | |
1646 | case AF_LOCAL: | | 1679 | case AF_LOCAL: |
1647 | sc.len = sizeof (struct sockaddr_un) + 4; | | 1680 | sc.len = sizeof (struct sockaddr_un) + 4; |
1648 | sockaddr_to_netaddr_un(&sc, mtod(name, void *)); | | 1681 | sockaddr_to_netaddr_un(&sc, mtod(name, void *)); |
1649 | break; | | 1682 | break; |
1650 | | | 1683 | |
1651 | default: | | 1684 | default: |
1652 | m_free(name); | | 1685 | m_free(name); |
1653 | error = ENOSYS; | | 1686 | error = ENOSYS; |
1654 | goto out; | | 1687 | goto out; |
1655 | } | | 1688 | } |
1656 | m_free(name); | | 1689 | m_free(name); |
1657 | | | 1690 | |
1658 | ctl.len = 40; | | 1691 | ctl.len = 40; |
1659 | dat.len = -1; | | 1692 | dat.len = -1; |
1660 | fl = 0; | | 1693 | fl = 0; |
1661 | st->s_cmd = sc.cmd; | | 1694 | st->s_cmd = sc.cmd; |
1662 | break; | | 1695 | break; |
1663 | | | 1696 | |
1664 | case SVR4_TI__ACCEPT_OK: | | 1697 | case SVR4_TI__ACCEPT_OK: |
1665 | DPRINTF(("getmsg: TI__ACCEPT_OK\n")); | | 1698 | DPRINTF(("getmsg: TI__ACCEPT_OK\n")); |
1666 | /* | | 1699 | /* |
1667 | * We do the connect in one step, so the putmsg should | | 1700 | * We do the connect in one step, so the putmsg should |
1668 | * have gotten the error. | | 1701 | * have gotten the error. |
1669 | */ | | 1702 | */ |
1670 | sc.cmd = SVR4_TI_OK_REPLY; | | 1703 | sc.cmd = SVR4_TI_OK_REPLY; |
1671 | sc.len = 1; | | 1704 | sc.len = 1; |
1672 | | | 1705 | |
1673 | ctl.len = 8; | | 1706 | ctl.len = 8; |
1674 | dat.len = -1; | | 1707 | dat.len = -1; |
1675 | fl = 1; | | 1708 | fl = 1; |
1676 | st->s_cmd = SVR4_TI__ACCEPT_WAIT; | | 1709 | st->s_cmd = SVR4_TI__ACCEPT_WAIT; |
1677 | break; | | 1710 | break; |
1678 | | | 1711 | |
1679 | case SVR4_TI__ACCEPT_WAIT: | | 1712 | case SVR4_TI__ACCEPT_WAIT: |
1680 | DPRINTF(("getmsg: TI__ACCEPT_WAIT\n")); | | 1713 | DPRINTF(("getmsg: TI__ACCEPT_WAIT\n")); |
1681 | /* | | 1714 | /* |
1682 | * We are after a listen, so we try to accept... | | 1715 | * We are after a listen, so we try to accept... |
1683 | */ | | 1716 | */ |
1684 | | | 1717 | |
1685 | error = do_sys_accept(l, SCARG(uap, fd), &name, retval, | | 1718 | error = do_sys_accept(l, SCARG(uap, fd), &name, retval, |
1686 | NULL, 0, FNONBLOCK); | | 1719 | NULL, 0, FNONBLOCK); |
1687 | if (error != 0) { | | 1720 | if (error != 0) { |
1688 | DPRINTF(("getmsg: accept failed %d\n", error)); | | 1721 | DPRINTF(("getmsg: accept failed %d\n", error)); |
1689 | goto out; | | 1722 | goto out; |
1690 | } | | 1723 | } |
1691 | | | 1724 | |
1692 | st->s_afd = *retval; | | 1725 | st->s_afd = *retval; |
1693 | | | 1726 | |
1694 | DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd)); | | 1727 | DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd)); |
1695 | | | 1728 | |
1696 | sc.cmd = SVR4_TI_ACCEPT_REPLY; | | 1729 | sc.cmd = SVR4_TI_ACCEPT_REPLY; |
1697 | sc.offs = 0x18; | | 1730 | sc.offs = 0x18; |
1698 | sc.pad[0] = 0x0; | | 1731 | sc.pad[0] = 0x0; |
1699 | | | 1732 | |
1700 | switch (st->s_family) { | | 1733 | switch (st->s_family) { |
1701 | case AF_INET: | | 1734 | case AF_INET: |
1702 | sc.pad[1] = 0x28; | | 1735 | sc.pad[1] = 0x28; |
1703 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); | | 1736 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); |
1704 | ctl.len = 40; | | 1737 | ctl.len = 40; |
1705 | sc.len = sizeof (struct sockaddr_in); | | 1738 | sc.len = sizeof (struct sockaddr_in); |
1706 | break; | | 1739 | break; |
1707 | | | 1740 | |
1708 | case AF_LOCAL: | | 1741 | case AF_LOCAL: |
1709 | sc.pad[1] = 0x00010000; | | 1742 | sc.pad[1] = 0x00010000; |
1710 | sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */ | | 1743 | sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */ |
1711 | sc.pad[3] = 0x00010000; | | 1744 | sc.pad[3] = 0x00010000; |
1712 | ctl.len = 134; | | 1745 | ctl.len = 134; |
1713 | sc.len = sizeof (struct sockaddr_un) + 4; | | 1746 | sc.len = sizeof (struct sockaddr_un) + 4; |
1714 | break; | | 1747 | break; |
1715 | | | 1748 | |
1716 | default: | | 1749 | default: |
1717 | m_free(name); | | 1750 | m_free(name); |
1718 | error = ENOSYS; | | 1751 | error = ENOSYS; |
1719 | goto out; | | 1752 | goto out; |
1720 | } | | 1753 | } |
1721 | m_free(name); | | 1754 | m_free(name); |
1722 | | | 1755 | |
1723 | dat.len = -1; | | 1756 | dat.len = -1; |
1724 | fl = 0; | | 1757 | fl = 0; |
1725 | st->s_cmd = SVR4_TI__ACCEPT_OK; | | 1758 | st->s_cmd = SVR4_TI__ACCEPT_OK; |
1726 | break; | | 1759 | break; |
1727 | | | 1760 | |
1728 | case SVR4_TI_SENDTO_REQUEST: | | 1761 | case SVR4_TI_SENDTO_REQUEST: |
1729 | /* | | 1762 | /* |
1730 | * XXX: dsl - I think this means that because we last did a | | 1763 | * XXX: dsl - I think this means that because we last did a |
1731 | * 'sendto' we'd better do a recvfrom now. | | 1764 | * 'sendto' we'd better do a recvfrom now. |
1732 | */ | | 1765 | */ |
1733 | DPRINTF(("getmsg: TI_SENDTO_REQUEST\n")); | | 1766 | DPRINTF(("getmsg: TI_SENDTO_REQUEST\n")); |
1734 | if (ctl.maxlen > 36 && ctl.len < 36) | | 1767 | if (ctl.maxlen > 36 && ctl.len < 36) |
1735 | ctl.len = 36; | | 1768 | ctl.len = 36; |
1736 | if (ctl.len > sizeof(sc)) | | 1769 | if (ctl.len > sizeof(sc)) |
1737 | ctl.len = sizeof(sc); | | 1770 | ctl.len = sizeof(sc); |
1738 | | | 1771 | |
| | | 1772 | if (ctl.len < offsetof(struct svr4_strmcmd, pad)) { |
| | | 1773 | error = EINVAL; |
| | | 1774 | goto out; |
| | | 1775 | } |
1739 | if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0) | | 1776 | if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0) |
1740 | goto out; | | 1777 | goto out; |
| | | 1778 | if (sc.offs < 0) { |
| | | 1779 | error = EINVAL; |
| | | 1780 | goto out; |
| | | 1781 | } |
1741 | | | 1782 | |
1742 | msg.msg_name = NULL; | | 1783 | msg.msg_name = NULL; |
1743 | msg.msg_namelen = 0; | | 1784 | msg.msg_namelen = 0; |
1744 | msg.msg_iov = &aiov; | | 1785 | msg.msg_iov = &aiov; |
1745 | msg.msg_iovlen = 1; | | 1786 | msg.msg_iovlen = 1; |
1746 | msg.msg_control = 0; | | 1787 | msg.msg_control = 0; |
1747 | aiov.iov_base = NETBSD32PTR(dat.buf); | | 1788 | aiov.iov_base = NETBSD32PTR(dat.buf); |
1748 | aiov.iov_len = dat.maxlen; | | 1789 | aiov.iov_len = dat.maxlen; |
1749 | msg.msg_flags = 0; | | 1790 | msg.msg_flags = 0; |
1750 | | | 1791 | |
1751 | error = do_sys_recvmsg(l, SCARG(uap, fd), &msg, &name, NULL, | | 1792 | error = do_sys_recvmsg(l, SCARG(uap, fd), &msg, &name, NULL, |
1752 | retval); | | 1793 | retval); |
1753 | | | 1794 | |
1754 | if (error) { | | 1795 | if (error) { |
1755 | DPRINTF(("getmsg: do_sys_recvmsg failed %d\n", error)); | | 1796 | DPRINTF(("getmsg: do_sys_recvmsg failed %d\n", error)); |
1756 | goto out; | | 1797 | goto out; |
1757 | } | | 1798 | } |
1758 | | | 1799 | |
1759 | sc.cmd = SVR4_TI_RECVFROM_IND; | | 1800 | sc.cmd = SVR4_TI_RECVFROM_IND; |
1760 | | | 1801 | |
1761 | switch (st->s_family) { | | 1802 | switch (st->s_family) { |
1762 | case AF_INET: | | 1803 | case AF_INET: |
1763 | sc.len = sizeof (struct sockaddr_in); | | 1804 | sc.len = sizeof (struct sockaddr_in); |
1764 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); | | 1805 | sockaddr_to_netaddr_in(&sc, mtod(name, void *)); |
1765 | break; | | 1806 | break; |
1766 | | | 1807 | |
1767 | case AF_LOCAL: | | 1808 | case AF_LOCAL: |
1768 | sc.len = sizeof (struct sockaddr_un) + 4; | | 1809 | sc.len = sizeof (struct sockaddr_un) + 4; |
1769 | sockaddr_to_netaddr_un(&sc, mtod(name, void *)); | | 1810 | sockaddr_to_netaddr_un(&sc, mtod(name, void *)); |
1770 | break; | | 1811 | break; |
1771 | | | 1812 | |
1772 | default: | | 1813 | default: |
1773 | m_free(name); | | 1814 | m_free(name); |
1774 | error = ENOSYS; | | 1815 | error = ENOSYS; |
1775 | goto out; | | 1816 | goto out; |
1776 | } | | 1817 | } |
1777 | m_free(name); | | 1818 | m_free(name); |
1778 | | | 1819 | |
1779 | dat.len = *retval; | | 1820 | dat.len = *retval; |
1780 | fl = 0; | | 1821 | fl = 0; |
1781 | st->s_cmd = sc.cmd; | | 1822 | st->s_cmd = sc.cmd; |
1782 | break; | | 1823 | break; |
1783 | | | 1824 | |
1784 | default: | | 1825 | default: |
1785 | st->s_cmd = sc.cmd; | | 1826 | st->s_cmd = sc.cmd; |
1786 | #ifdef notyet | | 1827 | #ifdef notyet |
1787 | if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) { | | 1828 | if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) { |
1788 | struct sys_read_args ra; | | 1829 | struct sys_read_args ra; |
1789 | | | 1830 | |
1790 | /* More weirdness: Again, I can't find documentation | | 1831 | /* More weirdness: Again, I can't find documentation |
1791 | * to back this up, but when a process does a generic | | 1832 | * to back this up, but when a process does a generic |
1792 | * "getmsg()" call it seems that the command field is | | 1833 | * "getmsg()" call it seems that the command field is |
1793 | * zero and the length of the data area is zero. I | | 1834 | * zero and the length of the data area is zero. I |
1794 | * think processes expect getmsg() to fill in dat.len | | 1835 | * think processes expect getmsg() to fill in dat.len |
1795 | * after reading at most dat.maxlen octets from the | | 1836 | * after reading at most dat.maxlen octets from the |
1796 | * stream. Since we're using sockets I can let | | 1837 | * stream. Since we're using sockets I can let |
1797 | * read() look after it and frob return values | | 1838 | * read() look after it and frob return values |
1798 | * appropriately (or inappropriately :-) | | 1839 | * appropriately (or inappropriately :-) |
1799 | * -- newton@atdot.dotat.org XXX | | 1840 | * -- newton@atdot.dotat.org XXX |
1800 | */ | | 1841 | */ |
1801 | SCARG(&ra, fd) = SCARG(uap, fd); | | 1842 | SCARG(&ra, fd) = SCARG(uap, fd); |
1802 | SCARG(&ra, buf) = dat.buf; | | 1843 | SCARG(&ra, buf) = dat.buf; |
1803 | SCARG(&ra, nbyte) = dat.maxlen; | | 1844 | SCARG(&ra, nbyte) = dat.maxlen; |
1804 | if ((error = sys_read(p, &ra, retval)) != 0) | | 1845 | if ((error = sys_read(p, &ra, retval)) != 0) |
1805 | goto out; | | 1846 | goto out; |
1806 | dat.len = *retval; | | 1847 | dat.len = *retval; |
1807 | *retval = 0; | | 1848 | *retval = 0; |
1808 | st->s_cmd = SVR4_TI_SENDTO_REQUEST; | | 1849 | st->s_cmd = SVR4_TI_SENDTO_REQUEST; |
1809 | break; | | 1850 | break; |
1810 | | | 1851 | |
1811 | } | | 1852 | } |
1812 | #endif | | 1853 | #endif |
1813 | DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd)); | | 1854 | DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd)); |
1814 | error = EINVAL; | | 1855 | error = EINVAL; |
1815 | goto out; | | 1856 | goto out; |
1816 | } | | 1857 | } |
1817 | | | 1858 | |
1818 | if (SCARG_PTR(uap, ctl)) { | | 1859 | if (SCARG_PTR(uap, ctl)) { |
1819 | if (ctl.len != -1) | | 1860 | if (ctl.len != -1) |
1820 | if ((error = copyout(&sc, NETBSD32PTR(ctl.buf), | | 1861 | if ((error = copyout(&sc, NETBSD32PTR(ctl.buf), |
1821 | ctl.len)) != 0) | | 1862 | ctl.len)) != 0) |
1822 | goto out; | | 1863 | goto out; |
1823 | | | 1864 | |
1824 | if ((error = copyout(&ctl, SCARG_PTR(uap, ctl), | | 1865 | if ((error = copyout(&ctl, SCARG_PTR(uap, ctl), |
1825 | sizeof(ctl))) != 0) | | 1866 | sizeof(ctl))) != 0) |
1826 | goto out; | | 1867 | goto out; |
1827 | } | | 1868 | } |
1828 | | | 1869 | |
1829 | if (SCARG_PTR(uap, dat)) { | | 1870 | if (SCARG_PTR(uap, dat)) { |
1830 | if ((error = copyout(&dat, SCARG_PTR(uap, dat), | | 1871 | if ((error = copyout(&dat, SCARG_PTR(uap, dat), |
1831 | sizeof(dat))) != 0) | | 1872 | sizeof(dat))) != 0) |
1832 | goto out; | | 1873 | goto out; |
1833 | } | | 1874 | } |
1834 | | | 1875 | |
1835 | if (SCARG_PTR(uap, flags)) { /* XXX: Need translation */ | | 1876 | if (SCARG_PTR(uap, flags)) { /* XXX: Need translation */ |
1836 | if ((error = copyout(&fl, SCARG_PTR(uap, flags), | | 1877 | if ((error = copyout(&fl, SCARG_PTR(uap, flags), |
1837 | sizeof(fl))) != 0) | | 1878 | sizeof(fl))) != 0) |
1838 | goto out; | | 1879 | goto out; |
1839 | } | | 1880 | } |
1840 | | | 1881 | |
1841 | *retval = 0; | | 1882 | *retval = 0; |
1842 | | | 1883 | |
1843 | #ifdef DEBUG_SVR4 | | 1884 | #ifdef DEBUG_SVR4 |
1844 | show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl), | | 1885 | show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl), |
1845 | SCARG(uap, dat), fl); | | 1886 | SCARG(uap, dat), fl); |
1846 | #endif /* DEBUG_SVR4 */ | | 1887 | #endif /* DEBUG_SVR4 */ |
1847 | | | 1888 | |
1848 | out: | | 1889 | out: |
1849 | fd_putfile(SCARG(uap, fd)); | | 1890 | fd_putfile(SCARG(uap, fd)); |
1850 | return error; | | 1891 | return error; |
1851 | } | | 1892 | } |