kern_uipc_socket_50.c revision 1.1 1 /* $NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $ */
2
3 /*
4 * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
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
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 2004 The FreeBSD Foundation
34 * Copyright (c) 2004 Robert Watson
35 * Copyright (c) 1982, 1986, 1988, 1990, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95
63 */
64
65 /*
66 * Copyright (c) 1988 University of Utah.
67 * Copyright (c) 1990, 1993
68 * The Regents of the University of California. All rights reserved.
69 *
70 * This code is derived from software contributed to Berkeley by
71 * the Systems Programming Group of the University of Utah Computer
72 * Science Department.
73 *
74 * Redistribution and use in source and binary forms, with or without
75 * modification, are permitted provided that the following conditions
76 * are met:
77 * 1. Redistributions of source code must retain the above copyright
78 * notice, this list of conditions and the following disclaimer.
79 * 2. Redistributions in binary form must reproduce the above copyright
80 * notice, this list of conditions and the following disclaimer in the
81 * documentation and/or other materials provided with the distribution.
82 * 3. Neither the name of the University nor the names of its contributors
83 * may be used to endorse or promote products derived from this software
84 * without specific prior written permission.
85 *
86 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
87 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
92 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 * SUCH DAMAGE.
97 *
98 * from: Utah $Hdr: vn.c 1.13 94/04/02$
99 *
100 * @(#)vn.c 8.9 (Berkeley) 5/14/95
101 */
102
103 #include <sys/cdefs.h>
104 __KERNEL_RCSID(0, "$NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $");
105
106 #if defined(_KERNEL_OPT)
107 #include "opt_compat_netbsd.h"
108 #endif
109
110 #include <sys/param.h>
111 #include <sys/systm.h>
112 #include <sys/kernel.h>
113 #include <sys/proc.h>
114 #include <sys/file.h>
115 #include <sys/compat_stub.h>
116 #include <sys/socketvar.h>
117
118 #include <compat/sys/time.h>
119 #include <compat/sys/socket.h>
120
121 #include <compat/common/compat_mod.h>
122
123 static int
124 uipc_socket_50_getopt1(int opt, struct socket *so, struct sockopt *sopt,
125 struct timeval *tv)
126 {
127 int optval, error;
128 struct timeval50 otv;
129
130 switch (opt) {
131
132 case SO_OSNDTIMEO:
133 case SO_ORCVTIMEO:
134 optval = (opt == SO_OSNDTIMEO ?
135 so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
136
137 otv.tv_sec = optval / hz;
138 otv.tv_usec = (optval % hz) * tick;
139
140 error = sockopt_set(sopt, &otv, sizeof(otv));
141 break;
142
143 case SO_OTIMESTAMP:
144 error = sockopt_setint(sopt, (so->so_options & opt) ? 1 : 0);
145 break;
146
147 default:
148 error = EPASSTHROUGH;
149 }
150 return error;
151 }
152
153 static int
154 uipc_socket_50_setopt1(int opt, struct socket *so, const struct sockopt *sopt,
155 struct timeval *tv)
156 {
157 int optval, error;
158 struct timeval50 otv;
159
160 switch (opt) {
161
162 case SO_OSNDTIMEO:
163 case SO_ORCVTIMEO:
164 error = sockopt_get(sopt, &otv, sizeof(otv));
165 if (error) {
166 solock(so);
167 break;
168 }
169 timeval50_to_timeval(&otv, tv);
170 opt = opt == SO_OSNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO;
171 /*
172 * Processing will continue as for SO_SNDTIMEO
173 * and SO_RCVTIMEO, using the new-format tv
174 */
175 break;
176
177 case SO_OTIMESTAMP:
178 error = sockopt_getint(sopt, &optval);
179 solock(so);
180 if (error)
181 break;
182 if (optval)
183 so->so_options |= opt;
184 else
185 so->so_options &= ~opt;
186 break;
187
188 default:
189 error = EPASSTHROUGH;
190 }
191 return error;
192 }
193
194 static int
195 uipc_socket_50_sbts(int opt, struct mbuf **mp)
196 {
197 struct timeval50 tv50;
198 struct timeval tv;
199
200 microtime(&tv);
201
202 if (opt & SO_OTIMESTAMP) {
203
204 timeval_to_timeval50(&tv, &tv50);
205 *mp = sbcreatecontrol(&tv50, sizeof(tv50), SCM_OTIMESTAMP,
206 SOL_SOCKET);
207 if (*mp)
208 mp = &(*mp)->m_next;
209 return 0;
210 } else
211 return EPASSTHROUGH;
212 }
213
214 void
215 kern_uipc_socket_50_init(void)
216 {
217
218 MODULE_HOOK_SET(uipc_socket_50_setopt1_hook, "sockop_50",
219 uipc_socket_50_setopt1);
220 MODULE_HOOK_SET(uipc_socket_50_getopt1_hook, "sockop_50",
221 uipc_socket_50_getopt1);
222 MODULE_HOOK_SET(uipc_socket_50_sbts_hook, "sbts_50",
223 uipc_socket_50_sbts);
224 }
225
226 void
227 kern_uipc_socket_50_fini(void)
228 {
229
230 MODULE_HOOK_UNSET(uipc_socket_50_setopt1_hook);
231 MODULE_HOOK_UNSET(uipc_socket_50_getopt1_hook);
232 MODULE_HOOK_UNSET(uipc_socket_50_sbts_hook);
233 }
234