/src/usrsctp/usrsctplib/user_socket.c
Line | Count | Source (jump to first uncovered line) |
1 | | /*- |
2 | | * Copyright (c) 1982, 1986, 1988, 1990, 1993 |
3 | | * The Regents of the University of California. |
4 | | * Copyright (c) 2004 The FreeBSD Foundation |
5 | | * Copyright (c) 2004-2008 Robert N. M. Watson |
6 | | * Copyright (c) 2009-2010 Brad Penoff |
7 | | * Copyright (c) 2009-2010 Humaira Kamal |
8 | | * Copyright (c) 2011-2012 Irene Ruengeler |
9 | | * Copyright (c) 2011-2012 Michael Tuexen |
10 | | * All rights reserved. |
11 | | * |
12 | | * Redistribution and use in source and binary forms, with or without |
13 | | * modification, are permitted provided that the following conditions |
14 | | * are met: |
15 | | * 1. Redistributions of source code must retain the above copyright |
16 | | * notice, this list of conditions and the following disclaimer. |
17 | | * 2. Redistributions in binary form must reproduce the above copyright |
18 | | * notice, this list of conditions and the following disclaimer in the |
19 | | * documentation and/or other materials provided with the distribution. |
20 | | * |
21 | | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
22 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
25 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
27 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
28 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
29 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | | * SUCH DAMAGE. |
32 | | * |
33 | | */ |
34 | | |
35 | | #include <netinet/sctp_os.h> |
36 | | #include <netinet/sctp_pcb.h> |
37 | | #include <netinet/sctputil.h> |
38 | | #include <netinet/sctp_var.h> |
39 | | #include <netinet/sctp_sysctl.h> |
40 | | #include <netinet/sctp_input.h> |
41 | | #include <netinet/sctp_peeloff.h> |
42 | | #include <netinet/sctp_callout.h> |
43 | | #include <netinet/sctp_crc32.h> |
44 | | #ifdef INET6 |
45 | | #include <netinet6/sctp6_var.h> |
46 | | #endif |
47 | | #if defined(__FreeBSD__) |
48 | | #include <sys/param.h> |
49 | | #endif |
50 | | #if defined(__linux__) |
51 | | #define __FAVOR_BSD /* (on Ubuntu at least) enables UDP header field names like BSD in RFC 768 */ |
52 | | #endif |
53 | | #if !defined(_WIN32) |
54 | | #if defined INET || defined INET6 |
55 | | #include <netinet/udp.h> |
56 | | #endif |
57 | | #include <arpa/inet.h> |
58 | | #else |
59 | | #include <user_socketvar.h> |
60 | | #endif |
61 | | userland_mutex_t accept_mtx; |
62 | | userland_cond_t accept_cond; |
63 | | #ifdef _WIN32 |
64 | | #include <time.h> |
65 | | #include <sys/timeb.h> |
66 | | #endif |
67 | | |
68 | | MALLOC_DEFINE(M_PCB, "sctp_pcb", "sctp pcb"); |
69 | | MALLOC_DEFINE(M_SONAME, "sctp_soname", "sctp soname"); |
70 | 0 | #define MAXLEN_MBUF_CHAIN 32 |
71 | | |
72 | | /* Prototypes */ |
73 | | extern int sctp_sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, |
74 | | struct mbuf *top, struct mbuf *control, int flags, |
75 | | /* proc is a dummy in __Userspace__ and will not be passed to sctp_lower_sosend */ |
76 | | struct proc *p); |
77 | | |
78 | | extern int sctp_attach(struct socket *so, int proto, uint32_t vrf_id); |
79 | | extern int sctpconn_attach(struct socket *so, int proto, uint32_t vrf_id); |
80 | | |
81 | 3 | static void init_sync(void) { |
82 | | #if defined(_WIN32) |
83 | | #if defined(INET) || defined(INET6) |
84 | | WSADATA wsaData; |
85 | | |
86 | | if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) { |
87 | | SCTP_PRINTF("WSAStartup failed\n"); |
88 | | exit (-1); |
89 | | } |
90 | | #endif |
91 | | InitializeConditionVariable(&accept_cond); |
92 | | InitializeCriticalSection(&accept_mtx); |
93 | | #else |
94 | 3 | pthread_mutexattr_t mutex_attr; |
95 | | |
96 | 3 | pthread_mutexattr_init(&mutex_attr); |
97 | 3 | #ifdef INVARIANTS |
98 | 3 | pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK); |
99 | 3 | #endif |
100 | 3 | pthread_mutex_init(&accept_mtx, &mutex_attr); |
101 | 3 | pthread_mutexattr_destroy(&mutex_attr); |
102 | 3 | pthread_cond_init(&accept_cond, NULL); |
103 | 3 | #endif |
104 | 3 | } |
105 | | |
106 | | void |
107 | | usrsctp_init(uint16_t port, |
108 | | int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df), |
109 | | void (*debug_printf)(const char *format, ...)) |
110 | 3 | { |
111 | 3 | init_sync(); |
112 | 3 | sctp_init(port, conn_output, debug_printf, 1); |
113 | 3 | } |
114 | | |
115 | | |
116 | | void |
117 | | usrsctp_init_nothreads(uint16_t port, |
118 | | int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df), |
119 | | void (*debug_printf)(const char *format, ...)) |
120 | 0 | { |
121 | 0 | init_sync(); |
122 | 0 | sctp_init(port, conn_output, debug_printf, 0); |
123 | 0 | } |
124 | | |
125 | | |
126 | | /* Taken from usr/src/sys/kern/uipc_sockbuf.c and modified for __Userspace__*/ |
127 | | /* |
128 | | * Socantsendmore indicates that no more data will be sent on the socket; it |
129 | | * would normally be applied to a socket when the user informs the system |
130 | | * that no more data is to be sent, by the protocol code (in case |
131 | | * PRU_SHUTDOWN). Socantrcvmore indicates that no more data will be |
132 | | * received, and will normally be applied to the socket by a protocol when it |
133 | | * detects that the peer will send no more data. Data queued for reading in |
134 | | * the socket may yet be read. |
135 | | */ |
136 | | |
137 | | void socantrcvmore_locked(struct socket *so) |
138 | 3.47k | { |
139 | 3.47k | SOCKBUF_LOCK_ASSERT(&so->so_rcv); |
140 | 3.47k | so->so_rcv.sb_state |= SBS_CANTRCVMORE; |
141 | 3.47k | sorwakeup_locked(so); |
142 | 3.47k | } |
143 | | |
144 | | void socantrcvmore(struct socket *so) |
145 | 1.74k | { |
146 | 1.74k | SOCKBUF_LOCK(&so->so_rcv); |
147 | 1.74k | socantrcvmore_locked(so); |
148 | 1.74k | } |
149 | | |
150 | | void |
151 | | socantsendmore_locked(struct socket *so) |
152 | 1.84k | { |
153 | 1.84k | SOCKBUF_LOCK_ASSERT(&so->so_snd); |
154 | 1.84k | so->so_snd.sb_state |= SBS_CANTSENDMORE; |
155 | 1.84k | sowwakeup_locked(so); |
156 | 1.84k | } |
157 | | |
158 | | void |
159 | | socantsendmore(struct socket *so) |
160 | 1.84k | { |
161 | 1.84k | SOCKBUF_LOCK(&so->so_snd); |
162 | 1.84k | socantsendmore_locked(so); |
163 | 1.84k | } |
164 | | |
165 | | |
166 | | |
167 | | /* Taken from usr/src/sys/kern/uipc_sockbuf.c and called within sctp_lower_sosend. |
168 | | */ |
169 | | int |
170 | | sbwait(struct sockbuf *sb) |
171 | 0 | { |
172 | 0 | SOCKBUF_LOCK_ASSERT(sb); |
173 | | |
174 | 0 | sb->sb_flags |= SB_WAIT; |
175 | | #if defined(_WIN32) |
176 | | if (SleepConditionVariableCS(&(sb->sb_cond), &(sb->sb_mtx), INFINITE)) |
177 | | return (0); |
178 | | else |
179 | | return (-1); |
180 | | #else |
181 | 0 | return (pthread_cond_wait(&(sb->sb_cond), &(sb->sb_mtx))); |
182 | 0 | #endif |
183 | 0 | } |
184 | | |
185 | | |
186 | | |
187 | | |
188 | | /* Taken from /src/sys/kern/uipc_socket.c |
189 | | * and modified for __Userspace__ |
190 | | */ |
191 | | static struct socket * |
192 | | soalloc(void) |
193 | 13.0k | { |
194 | 13.0k | struct socket *so; |
195 | | |
196 | | /* |
197 | | * soalloc() sets of socket layer state for a socket, |
198 | | * called only by socreate() and sonewconn(). |
199 | | * |
200 | | * sodealloc() tears down socket layer state for a socket, |
201 | | * called only by sofree() and sonewconn(). |
202 | | * __Userspace__ TODO : Make sure so is properly deallocated |
203 | | * when tearing down the connection. |
204 | | */ |
205 | | |
206 | 13.0k | so = (struct socket *)malloc(sizeof(struct socket)); |
207 | | |
208 | 13.0k | if (so == NULL) { |
209 | 0 | return (NULL); |
210 | 0 | } |
211 | 13.0k | memset(so, 0, sizeof(struct socket)); |
212 | | |
213 | | /* __Userspace__ Initializing the socket locks here */ |
214 | 13.0k | SOCKBUF_LOCK_INIT(&so->so_snd, "so_snd"); |
215 | 13.0k | SOCKBUF_LOCK_INIT(&so->so_rcv, "so_rcv"); |
216 | 13.0k | SOCKBUF_COND_INIT(&so->so_snd); |
217 | 13.0k | SOCKBUF_COND_INIT(&so->so_rcv); |
218 | 13.0k | SOCK_COND_INIT(so); /* timeo_cond */ |
219 | | |
220 | | /* __Userspace__ Any ref counting required here? Will we have any use for aiojobq? |
221 | | What about gencnt and numopensockets?*/ |
222 | 13.0k | TAILQ_INIT(&so->so_aiojobq); |
223 | 13.0k | return (so); |
224 | 13.0k | } |
225 | | |
226 | | static void |
227 | | sodealloc(struct socket *so) |
228 | 13.0k | { |
229 | | |
230 | 13.0k | KASSERT(so->so_count == 0, ("sodealloc(): so_count %d", so->so_count)); |
231 | 13.0k | KASSERT(so->so_pcb == NULL, ("sodealloc(): so_pcb != NULL")); |
232 | | |
233 | 13.0k | SOCKBUF_COND_DESTROY(&so->so_snd); |
234 | 13.0k | SOCKBUF_COND_DESTROY(&so->so_rcv); |
235 | | |
236 | 13.0k | SOCK_COND_DESTROY(so); |
237 | | |
238 | 13.0k | SOCKBUF_LOCK_DESTROY(&so->so_snd); |
239 | 13.0k | SOCKBUF_LOCK_DESTROY(&so->so_rcv); |
240 | | |
241 | 13.0k | free(so); |
242 | 13.0k | } |
243 | | |
244 | | /* Taken from /src/sys/kern/uipc_socket.c |
245 | | * and modified for __Userspace__ |
246 | | */ |
247 | | void |
248 | | sofree(struct socket *so) |
249 | 13.0k | { |
250 | 13.0k | struct socket *head; |
251 | | |
252 | 13.0k | ACCEPT_LOCK_ASSERT(); |
253 | 13.0k | SOCK_LOCK_ASSERT(so); |
254 | | /* SS_NOFDREF unset in accept call. this condition seems irrelevant |
255 | | * for __Userspace__... |
256 | | */ |
257 | 13.0k | if (so->so_count != 0 || |
258 | 13.0k | (so->so_state & SS_PROTOREF) || (so->so_qstate & SQ_COMP)) { |
259 | 0 | SOCK_UNLOCK(so); |
260 | 0 | ACCEPT_UNLOCK(); |
261 | 0 | return; |
262 | 0 | } |
263 | 13.0k | head = so->so_head; |
264 | 13.0k | if (head != NULL) { |
265 | 0 | KASSERT((so->so_qstate & SQ_COMP) != 0 || |
266 | 0 | (so->so_qstate & SQ_INCOMP) != 0, |
267 | 0 | ("sofree: so_head != NULL, but neither SQ_COMP nor " |
268 | 0 | "SQ_INCOMP")); |
269 | 0 | KASSERT((so->so_qstate & SQ_COMP) == 0 || |
270 | 0 | (so->so_qstate & SQ_INCOMP) == 0, |
271 | 0 | ("sofree: so->so_qstate is SQ_COMP and also SQ_INCOMP")); |
272 | 0 | TAILQ_REMOVE(&head->so_incomp, so, so_list); |
273 | 0 | head->so_incqlen--; |
274 | 0 | so->so_qstate &= ~SQ_INCOMP; |
275 | 0 | so->so_head = NULL; |
276 | 0 | } |
277 | 13.0k | KASSERT((so->so_qstate & SQ_COMP) == 0 && |
278 | 13.0k | (so->so_qstate & SQ_INCOMP) == 0, |
279 | 13.0k | ("sofree: so_head == NULL, but still SQ_COMP(%d) or SQ_INCOMP(%d)", |
280 | 13.0k | so->so_qstate & SQ_COMP, so->so_qstate & SQ_INCOMP)); |
281 | 13.0k | if (so->so_options & SCTP_SO_ACCEPTCONN) { |
282 | 0 | KASSERT((TAILQ_EMPTY(&so->so_comp)), ("sofree: so_comp populated")); |
283 | 0 | KASSERT((TAILQ_EMPTY(&so->so_incomp)), ("sofree: so_comp populated")); |
284 | 0 | } |
285 | 13.0k | SOCK_UNLOCK(so); |
286 | 13.0k | ACCEPT_UNLOCK(); |
287 | 13.0k | sctp_close(so); /* was... sctp_detach(so); */ |
288 | | /* |
289 | | * From this point on, we assume that no other references to this |
290 | | * socket exist anywhere else in the stack. Therefore, no locks need |
291 | | * to be acquired or held. |
292 | | * |
293 | | * We used to do a lot of socket buffer and socket locking here, as |
294 | | * well as invoke sorflush() and perform wakeups. The direct call to |
295 | | * dom_dispose() and sbrelease_internal() are an inlining of what was |
296 | | * necessary from sorflush(). |
297 | | * |
298 | | * Notice that the socket buffer and kqueue state are torn down |
299 | | * before calling pru_detach. This means that protocols should not |
300 | | * assume they can perform socket wakeups, etc, in their detach code. |
301 | | */ |
302 | 13.0k | sodealloc(so); |
303 | 13.0k | } |
304 | | |
305 | | |
306 | | |
307 | | /* Taken from /src/sys/kern/uipc_socket.c */ |
308 | | void |
309 | | soabort(struct socket *so) |
310 | 0 | { |
311 | 0 | sctp_abort(so); |
312 | 0 | ACCEPT_LOCK(); |
313 | 0 | SOCK_LOCK(so); |
314 | 0 | sofree(so); |
315 | 0 | } |
316 | | |
317 | | |
318 | | /* Taken from usr/src/sys/kern/uipc_socket.c and called within sctp_connect (sctp_usrreq.c). |
319 | | * We use sctp_connect for send_one_init_real in ms1. |
320 | | */ |
321 | | void |
322 | | soisconnecting(struct socket *so) |
323 | 13.0k | { |
324 | | |
325 | 13.0k | SOCK_LOCK(so); |
326 | 13.0k | so->so_state &= ~(SS_ISCONNECTED|SS_ISDISCONNECTING); |
327 | 13.0k | so->so_state |= SS_ISCONNECTING; |
328 | 13.0k | SOCK_UNLOCK(so); |
329 | 13.0k | } |
330 | | |
331 | | /* Taken from usr/src/sys/kern/uipc_socket.c and called within sctp_disconnect (sctp_usrreq.c). |
332 | | * TODO Do we use sctp_disconnect? |
333 | | */ |
334 | | void |
335 | | soisdisconnecting(struct socket *so) |
336 | 0 | { |
337 | | |
338 | | /* |
339 | | * Note: This code assumes that SOCK_LOCK(so) and |
340 | | * SOCKBUF_LOCK(&so->so_rcv) are the same. |
341 | | */ |
342 | 0 | SOCKBUF_LOCK(&so->so_rcv); |
343 | 0 | so->so_state &= ~SS_ISCONNECTING; |
344 | 0 | so->so_state |= SS_ISDISCONNECTING; |
345 | 0 | so->so_rcv.sb_state |= SBS_CANTRCVMORE; |
346 | 0 | sorwakeup_locked(so); |
347 | 0 | SOCKBUF_LOCK(&so->so_snd); |
348 | 0 | so->so_snd.sb_state |= SBS_CANTSENDMORE; |
349 | 0 | sowwakeup_locked(so); |
350 | 0 | wakeup("dummy",so); |
351 | | /* requires 2 args but this was in orig */ |
352 | | /* wakeup(&so->so_timeo); */ |
353 | 0 | } |
354 | | |
355 | | |
356 | | /* Taken from sys/kern/kern_synch.c and |
357 | | modified for __Userspace__ |
358 | | */ |
359 | | |
360 | | /* |
361 | | * Make all threads sleeping on the specified identifier runnable. |
362 | | * Associating wakeup with so_timeo identifier and timeo_cond |
363 | | * condition variable. TODO. If we use iterator thread then we need to |
364 | | * modify wakeup so it can distinguish between iterator identifier and |
365 | | * timeo identifier. |
366 | | */ |
367 | | void |
368 | | wakeup(void *ident, struct socket *so) |
369 | 9.35k | { |
370 | 9.35k | SOCK_LOCK(so); |
371 | | #if defined(_WIN32) |
372 | | WakeAllConditionVariable(&(so)->timeo_cond); |
373 | | #else |
374 | 9.35k | pthread_cond_broadcast(&(so)->timeo_cond); |
375 | 9.35k | #endif |
376 | 9.35k | SOCK_UNLOCK(so); |
377 | 9.35k | } |
378 | | |
379 | | |
380 | | /* |
381 | | * Make a thread sleeping on the specified identifier runnable. |
382 | | * May wake more than one thread if a target thread is currently |
383 | | * swapped out. |
384 | | */ |
385 | | void |
386 | | wakeup_one(void *ident) |
387 | 0 | { |
388 | | /* __Userspace__ Check: We are using accept_cond for wakeup_one. |
389 | | It seems that wakeup_one is only called within |
390 | | soisconnected() and sonewconn() with ident &head->so_timeo |
391 | | head is so->so_head, which is back pointer to listen socket |
392 | | This seems to indicate that the use of accept_cond is correct |
393 | | since socket where accepts occur is so_head in all |
394 | | subsidiary sockets. |
395 | | */ |
396 | 0 | ACCEPT_LOCK(); |
397 | | #if defined(_WIN32) |
398 | | WakeAllConditionVariable(&accept_cond); |
399 | | #else |
400 | 0 | pthread_cond_broadcast(&accept_cond); |
401 | 0 | #endif |
402 | 0 | ACCEPT_UNLOCK(); |
403 | 0 | } |
404 | | |
405 | | |
406 | | /* Called within sctp_process_cookie_[existing/new] */ |
407 | | void |
408 | | soisconnected(struct socket *so) |
409 | 7.62k | { |
410 | 7.62k | struct socket *head; |
411 | | |
412 | 7.62k | ACCEPT_LOCK(); |
413 | 7.62k | SOCK_LOCK(so); |
414 | 7.62k | so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING); |
415 | 7.62k | so->so_state |= SS_ISCONNECTED; |
416 | 7.62k | head = so->so_head; |
417 | 7.62k | if (head != NULL && (so->so_qstate & SQ_INCOMP)) { |
418 | 0 | SOCK_UNLOCK(so); |
419 | 0 | TAILQ_REMOVE(&head->so_incomp, so, so_list); |
420 | 0 | head->so_incqlen--; |
421 | 0 | so->so_qstate &= ~SQ_INCOMP; |
422 | 0 | TAILQ_INSERT_TAIL(&head->so_comp, so, so_list); |
423 | 0 | head->so_qlen++; |
424 | 0 | so->so_qstate |= SQ_COMP; |
425 | 0 | ACCEPT_UNLOCK(); |
426 | 0 | sorwakeup(head); |
427 | 0 | wakeup_one(&head->so_timeo); |
428 | 0 | return; |
429 | 0 | } |
430 | 7.62k | SOCK_UNLOCK(so); |
431 | 7.62k | ACCEPT_UNLOCK(); |
432 | 7.62k | wakeup(&so->so_timeo, so); |
433 | 7.62k | sorwakeup(so); |
434 | 7.62k | sowwakeup(so); |
435 | | |
436 | 7.62k | } |
437 | | |
438 | | /* called within sctp_handle_cookie_echo */ |
439 | | |
440 | | struct socket * |
441 | | sonewconn(struct socket *head, int connstatus) |
442 | 0 | { |
443 | 0 | struct socket *so; |
444 | 0 | int over; |
445 | |
|
446 | 0 | ACCEPT_LOCK(); |
447 | 0 | over = (head->so_qlen > 3 * head->so_qlimit / 2); |
448 | 0 | ACCEPT_UNLOCK(); |
449 | | #ifdef REGRESSION |
450 | | if (regression_sonewconn_earlytest && over) |
451 | | #else |
452 | 0 | if (over) |
453 | 0 | #endif |
454 | 0 | return (NULL); |
455 | 0 | so = soalloc(); |
456 | 0 | if (so == NULL) |
457 | 0 | return (NULL); |
458 | 0 | so->so_head = head; |
459 | 0 | so->so_type = head->so_type; |
460 | 0 | so->so_options = head->so_options &~ SCTP_SO_ACCEPTCONN; |
461 | 0 | so->so_linger = head->so_linger; |
462 | 0 | so->so_state = head->so_state | SS_NOFDREF; |
463 | 0 | so->so_dom = head->so_dom; |
464 | | #ifdef MAC |
465 | | SOCK_LOCK(head); |
466 | | mac_create_socket_from_socket(head, so); |
467 | | SOCK_UNLOCK(head); |
468 | | #endif |
469 | 0 | if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat)) { |
470 | 0 | sodealloc(so); |
471 | 0 | return (NULL); |
472 | 0 | } |
473 | 0 | switch (head->so_dom) { |
474 | 0 | #ifdef INET |
475 | 0 | case AF_INET: |
476 | 0 | if (sctp_attach(so, IPPROTO_SCTP, SCTP_DEFAULT_VRFID)) { |
477 | 0 | sodealloc(so); |
478 | 0 | return (NULL); |
479 | 0 | } |
480 | 0 | break; |
481 | 0 | #endif |
482 | 0 | #ifdef INET6 |
483 | 0 | case AF_INET6: |
484 | 0 | if (sctp6_attach(so, IPPROTO_SCTP, SCTP_DEFAULT_VRFID)) { |
485 | 0 | sodealloc(so); |
486 | 0 | return (NULL); |
487 | 0 | } |
488 | 0 | break; |
489 | 0 | #endif |
490 | 0 | case AF_CONN: |
491 | 0 | if (sctpconn_attach(so, IPPROTO_SCTP, SCTP_DEFAULT_VRFID)) { |
492 | 0 | sodealloc(so); |
493 | 0 | return (NULL); |
494 | 0 | } |
495 | 0 | break; |
496 | 0 | default: |
497 | 0 | sodealloc(so); |
498 | 0 | return (NULL); |
499 | 0 | break; |
500 | 0 | } |
501 | 0 | so->so_rcv.sb_lowat = head->so_rcv.sb_lowat; |
502 | 0 | so->so_snd.sb_lowat = head->so_snd.sb_lowat; |
503 | 0 | so->so_rcv.sb_timeo = head->so_rcv.sb_timeo; |
504 | 0 | so->so_snd.sb_timeo = head->so_snd.sb_timeo; |
505 | 0 | so->so_rcv.sb_flags |= head->so_rcv.sb_flags & SB_AUTOSIZE; |
506 | 0 | so->so_snd.sb_flags |= head->so_snd.sb_flags & SB_AUTOSIZE; |
507 | 0 | so->so_state |= connstatus; |
508 | 0 | ACCEPT_LOCK(); |
509 | 0 | if (connstatus) { |
510 | 0 | TAILQ_INSERT_TAIL(&head->so_comp, so, so_list); |
511 | 0 | so->so_qstate |= SQ_COMP; |
512 | 0 | head->so_qlen++; |
513 | 0 | } else { |
514 | | /* |
515 | | * Keep removing sockets from the head until there's room for |
516 | | * us to insert on the tail. In pre-locking revisions, this |
517 | | * was a simple if (), but as we could be racing with other |
518 | | * threads and soabort() requires dropping locks, we must |
519 | | * loop waiting for the condition to be true. |
520 | | */ |
521 | 0 | while (head->so_incqlen > head->so_qlimit) { |
522 | 0 | struct socket *sp; |
523 | 0 | sp = TAILQ_FIRST(&head->so_incomp); |
524 | 0 | TAILQ_REMOVE(&head->so_incomp, sp, so_list); |
525 | 0 | head->so_incqlen--; |
526 | 0 | sp->so_qstate &= ~SQ_INCOMP; |
527 | 0 | sp->so_head = NULL; |
528 | 0 | ACCEPT_UNLOCK(); |
529 | 0 | soabort(sp); |
530 | 0 | ACCEPT_LOCK(); |
531 | 0 | } |
532 | 0 | TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list); |
533 | 0 | so->so_qstate |= SQ_INCOMP; |
534 | 0 | head->so_incqlen++; |
535 | 0 | } |
536 | 0 | ACCEPT_UNLOCK(); |
537 | 0 | if (connstatus) { |
538 | 0 | sorwakeup(head); |
539 | 0 | wakeup_one(&head->so_timeo); |
540 | 0 | } |
541 | 0 | return (so); |
542 | |
|
543 | 0 | } |
544 | | |
545 | | /* |
546 | | Source: /src/sys/gnu/fs/xfs/FreeBSD/xfs_ioctl.c |
547 | | */ |
548 | | static __inline__ int |
549 | 546k | copy_to_user(void *dst, void *src, size_t len) { |
550 | 546k | memcpy(dst, src, len); |
551 | 546k | return 0; |
552 | 546k | } |
553 | | |
554 | | static __inline__ int |
555 | 86.4k | copy_from_user(void *dst, void *src, size_t len) { |
556 | 86.4k | memcpy(dst, src, len); |
557 | 86.4k | return 0; |
558 | 86.4k | } |
559 | | |
560 | | /* |
561 | | References: |
562 | | src/sys/dev/lmc/if_lmc.h: |
563 | | src/sys/powerpc/powerpc/copyinout.c |
564 | | src/sys/sys/systm.h |
565 | | */ |
566 | 86.4k | # define copyin(u, k, len) copy_from_user(k, u, len) |
567 | | |
568 | | /* References: |
569 | | src/sys/powerpc/powerpc/copyinout.c |
570 | | src/sys/sys/systm.h |
571 | | */ |
572 | 546k | # define copyout(k, u, len) copy_to_user(u, k, len) |
573 | | |
574 | | |
575 | | /* copyiniov definition copied/modified from src/sys/kern/kern_subr.c */ |
576 | | int |
577 | | copyiniov(struct iovec *iovp, u_int iovcnt, struct iovec **iov, int error) |
578 | 0 | { |
579 | 0 | u_int iovlen; |
580 | |
|
581 | 0 | *iov = NULL; |
582 | 0 | if (iovcnt > UIO_MAXIOV) |
583 | 0 | return (error); |
584 | 0 | iovlen = iovcnt * sizeof (struct iovec); |
585 | 0 | *iov = malloc(iovlen); /*, M_IOV, M_WAITOK); */ |
586 | 0 | error = copyin(iovp, *iov, iovlen); |
587 | 0 | if (error) { |
588 | 0 | free(*iov); /*, M_IOV); */ |
589 | 0 | *iov = NULL; |
590 | 0 | } |
591 | 0 | return (error); |
592 | 0 | } |
593 | | |
594 | | /* (__Userspace__) version of uiomove */ |
595 | | int |
596 | | uiomove(void *cp, int n, struct uio *uio) |
597 | 607k | { |
598 | 607k | struct iovec *iov; |
599 | 607k | size_t cnt; |
600 | 607k | int error = 0; |
601 | | |
602 | 607k | if ((uio->uio_rw != UIO_READ) && |
603 | 607k | (uio->uio_rw != UIO_WRITE)) { |
604 | 0 | return (EINVAL); |
605 | 0 | } |
606 | | |
607 | 1.21M | while (n > 0 && uio->uio_resid) { |
608 | 607k | iov = uio->uio_iov; |
609 | 607k | cnt = iov->iov_len; |
610 | 607k | if (cnt == 0) { |
611 | 0 | uio->uio_iov++; |
612 | 0 | uio->uio_iovcnt--; |
613 | 0 | continue; |
614 | 0 | } |
615 | 607k | if (cnt > (size_t)n) |
616 | 582k | cnt = n; |
617 | | |
618 | 607k | switch (uio->uio_segflg) { |
619 | | |
620 | 607k | case UIO_USERSPACE: |
621 | 607k | if (uio->uio_rw == UIO_READ) |
622 | 546k | error = copyout(cp, iov->iov_base, cnt); |
623 | 60.2k | else |
624 | 60.2k | error = copyin(iov->iov_base, cp, cnt); |
625 | 607k | if (error) |
626 | 0 | goto out; |
627 | 607k | break; |
628 | | |
629 | 607k | case UIO_SYSSPACE: |
630 | 0 | if (uio->uio_rw == UIO_READ) |
631 | 0 | memcpy(iov->iov_base, cp, cnt); |
632 | 0 | else |
633 | 0 | memcpy(cp, iov->iov_base, cnt); |
634 | 0 | break; |
635 | 607k | } |
636 | 607k | iov->iov_base = (char *)iov->iov_base + cnt; |
637 | 607k | iov->iov_len -= cnt; |
638 | 607k | uio->uio_resid -= cnt; |
639 | 607k | uio->uio_offset += (off_t)cnt; |
640 | 607k | cp = (char *)cp + cnt; |
641 | 607k | n -= (int)cnt; |
642 | 607k | } |
643 | 607k | out: |
644 | 607k | return (error); |
645 | 607k | } |
646 | | |
647 | | |
648 | | /* Source: src/sys/kern/uipc_syscalls.c */ |
649 | | int |
650 | | getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len) |
651 | 26.1k | { |
652 | 26.1k | struct sockaddr *sa; |
653 | 26.1k | int error; |
654 | | |
655 | 26.1k | if (len > SOCK_MAXADDRLEN) |
656 | 0 | return (ENAMETOOLONG); |
657 | 26.1k | if (len < offsetof(struct sockaddr, sa_data)) |
658 | 0 | return (EINVAL); |
659 | 26.1k | MALLOC(sa, struct sockaddr *, len, M_SONAME, M_WAITOK); |
660 | 26.1k | error = copyin(uaddr, sa, len); |
661 | 26.1k | if (error) { |
662 | 0 | FREE(sa, M_SONAME); |
663 | 26.1k | } else { |
664 | | #ifdef HAVE_SA_LEN |
665 | | sa->sa_len = len; |
666 | | #endif |
667 | 26.1k | *namp = sa; |
668 | 26.1k | } |
669 | 26.1k | return (error); |
670 | 26.1k | } |
671 | | |
672 | | int |
673 | | usrsctp_getsockopt(struct socket *so, int level, int option_name, |
674 | | void *option_value, socklen_t *option_len); |
675 | | |
676 | | sctp_assoc_t |
677 | | usrsctp_getassocid(struct socket *sock, struct sockaddr *sa) |
678 | 0 | { |
679 | 0 | struct sctp_paddrinfo sp; |
680 | 0 | socklen_t siz; |
681 | 0 | #ifndef HAVE_SA_LEN |
682 | 0 | size_t sa_len; |
683 | 0 | #endif |
684 | | |
685 | | /* First get the assoc id */ |
686 | 0 | siz = sizeof(sp); |
687 | 0 | memset(&sp, 0, sizeof(sp)); |
688 | | #ifdef HAVE_SA_LEN |
689 | | memcpy((caddr_t)&sp.spinfo_address, sa, sa->sa_len); |
690 | | #else |
691 | 0 | switch (sa->sa_family) { |
692 | 0 | #ifdef INET |
693 | 0 | case AF_INET: |
694 | 0 | sa_len = sizeof(struct sockaddr_in); |
695 | 0 | break; |
696 | 0 | #endif |
697 | 0 | #ifdef INET6 |
698 | 0 | case AF_INET6: |
699 | 0 | sa_len = sizeof(struct sockaddr_in6); |
700 | 0 | break; |
701 | 0 | #endif |
702 | 0 | case AF_CONN: |
703 | 0 | sa_len = sizeof(struct sockaddr_conn); |
704 | 0 | break; |
705 | 0 | default: |
706 | 0 | sa_len = 0; |
707 | 0 | break; |
708 | 0 | } |
709 | 0 | memcpy((caddr_t)&sp.spinfo_address, sa, sa_len); |
710 | 0 | #endif |
711 | 0 | if (usrsctp_getsockopt(sock, IPPROTO_SCTP, SCTP_GET_PEER_ADDR_INFO, &sp, &siz) != 0) { |
712 | | /* We depend on the fact that 0 can never be returned */ |
713 | 0 | return ((sctp_assoc_t) 0); |
714 | 0 | } |
715 | 0 | return (sp.spinfo_assoc_id); |
716 | 0 | } |
717 | | |
718 | | |
719 | | /* Taken from /src/lib/libc/net/sctp_sys_calls.c |
720 | | * and modified for __Userspace__ |
721 | | * calling sctp_generic_sendmsg from this function |
722 | | */ |
723 | | ssize_t |
724 | | userspace_sctp_sendmsg(struct socket *so, |
725 | | const void *data, |
726 | | size_t len, |
727 | | struct sockaddr *to, |
728 | | socklen_t tolen, |
729 | | uint32_t ppid, |
730 | | uint32_t flags, |
731 | | uint16_t stream_no, |
732 | | uint32_t timetolive, |
733 | | uint32_t context) |
734 | 0 | { |
735 | 0 | struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo; |
736 | 0 | struct uio auio; |
737 | 0 | struct iovec iov[1]; |
738 | |
|
739 | 0 | memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo)); |
740 | 0 | sinfo->sinfo_ppid = ppid; |
741 | 0 | sinfo->sinfo_flags = flags; |
742 | 0 | sinfo->sinfo_stream = stream_no; |
743 | 0 | sinfo->sinfo_timetolive = timetolive; |
744 | 0 | sinfo->sinfo_context = context; |
745 | 0 | sinfo->sinfo_assoc_id = 0; |
746 | | |
747 | | |
748 | | /* Perform error checks on destination (to) */ |
749 | 0 | if (tolen > SOCK_MAXADDRLEN) { |
750 | 0 | errno = ENAMETOOLONG; |
751 | 0 | return (-1); |
752 | 0 | } |
753 | 0 | if ((tolen > 0) && |
754 | 0 | ((to == NULL) || (tolen < (socklen_t)sizeof(struct sockaddr)))) { |
755 | 0 | errno = EINVAL; |
756 | 0 | return (-1); |
757 | 0 | } |
758 | 0 | if (data == NULL) { |
759 | 0 | errno = EFAULT; |
760 | 0 | return (-1); |
761 | 0 | } |
762 | | /* Adding the following as part of defensive programming, in case the application |
763 | | does not do it when preparing the destination address.*/ |
764 | | #ifdef HAVE_SA_LEN |
765 | | if (to != NULL) { |
766 | | to->sa_len = tolen; |
767 | | } |
768 | | #endif |
769 | | |
770 | 0 | iov[0].iov_base = (caddr_t)data; |
771 | 0 | iov[0].iov_len = len; |
772 | |
|
773 | 0 | auio.uio_iov = iov; |
774 | 0 | auio.uio_iovcnt = 1; |
775 | 0 | auio.uio_segflg = UIO_USERSPACE; |
776 | 0 | auio.uio_rw = UIO_WRITE; |
777 | 0 | auio.uio_offset = 0; /* XXX */ |
778 | 0 | auio.uio_resid = len; |
779 | 0 | errno = sctp_lower_sosend(so, to, &auio, NULL, NULL, 0, sinfo); |
780 | 0 | if (errno == 0) { |
781 | 0 | return (len - auio.uio_resid); |
782 | 0 | } else { |
783 | 0 | return (-1); |
784 | 0 | } |
785 | 0 | } |
786 | | |
787 | | |
788 | | ssize_t |
789 | | usrsctp_sendv(struct socket *so, |
790 | | const void *data, |
791 | | size_t len, |
792 | | struct sockaddr *to, |
793 | | int addrcnt, |
794 | | void *info, |
795 | | socklen_t infolen, |
796 | | unsigned int infotype, |
797 | | int flags) |
798 | 7.62M | { |
799 | 7.62M | struct sctp_sndrcvinfo sinfo; |
800 | 7.62M | struct uio auio; |
801 | 7.62M | struct iovec iov[1]; |
802 | 7.62M | int use_sinfo; |
803 | 7.62M | sctp_assoc_t *assoc_id; |
804 | | |
805 | 7.62M | if (so == NULL) { |
806 | 0 | errno = EBADF; |
807 | 0 | return (-1); |
808 | 0 | } |
809 | 7.62M | if (data == NULL) { |
810 | 0 | errno = EFAULT; |
811 | 0 | return (-1); |
812 | 0 | } |
813 | 7.62M | memset(&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); |
814 | 7.62M | assoc_id = NULL; |
815 | 7.62M | use_sinfo = 0; |
816 | 7.62M | switch (infotype) { |
817 | 7.62M | case SCTP_SENDV_NOINFO: |
818 | 7.62M | if ((infolen != 0) || (info != NULL)) { |
819 | 0 | errno = EINVAL; |
820 | 0 | return (-1); |
821 | 0 | } |
822 | 7.62M | break; |
823 | 7.62M | case SCTP_SENDV_SNDINFO: |
824 | 0 | if ((info == NULL) || (infolen != sizeof(struct sctp_sndinfo))) { |
825 | 0 | errno = EINVAL; |
826 | 0 | return (-1); |
827 | 0 | } |
828 | 0 | sinfo.sinfo_stream = ((struct sctp_sndinfo *)info)->snd_sid; |
829 | 0 | sinfo.sinfo_flags = ((struct sctp_sndinfo *)info)->snd_flags; |
830 | 0 | sinfo.sinfo_ppid = ((struct sctp_sndinfo *)info)->snd_ppid; |
831 | 0 | sinfo.sinfo_context = ((struct sctp_sndinfo *)info)->snd_context; |
832 | 0 | sinfo.sinfo_assoc_id = ((struct sctp_sndinfo *)info)->snd_assoc_id; |
833 | 0 | assoc_id = &(((struct sctp_sndinfo *)info)->snd_assoc_id); |
834 | 0 | use_sinfo = 1; |
835 | 0 | break; |
836 | 0 | case SCTP_SENDV_PRINFO: |
837 | 0 | if ((info == NULL) || (infolen != sizeof(struct sctp_prinfo))) { |
838 | 0 | errno = EINVAL; |
839 | 0 | return (-1); |
840 | 0 | } |
841 | 0 | sinfo.sinfo_stream = 0; |
842 | 0 | sinfo.sinfo_flags = PR_SCTP_POLICY(((struct sctp_prinfo *)info)->pr_policy); |
843 | 0 | sinfo.sinfo_timetolive = ((struct sctp_prinfo *)info)->pr_value; |
844 | 0 | use_sinfo = 1; |
845 | 0 | break; |
846 | 0 | case SCTP_SENDV_AUTHINFO: |
847 | 0 | errno = EINVAL; |
848 | 0 | return (-1); |
849 | 0 | case SCTP_SENDV_SPA: |
850 | 0 | if ((info == NULL) || (infolen != sizeof(struct sctp_sendv_spa))) { |
851 | 0 | errno = EINVAL; |
852 | 0 | return (-1); |
853 | 0 | } |
854 | 0 | if (((struct sctp_sendv_spa *)info)->sendv_flags & SCTP_SEND_SNDINFO_VALID) { |
855 | 0 | sinfo.sinfo_stream = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_sid; |
856 | 0 | sinfo.sinfo_flags = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_flags; |
857 | 0 | sinfo.sinfo_ppid = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_ppid; |
858 | 0 | sinfo.sinfo_context = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_context; |
859 | 0 | sinfo.sinfo_assoc_id = ((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_assoc_id; |
860 | 0 | assoc_id = &(((struct sctp_sendv_spa *)info)->sendv_sndinfo.snd_assoc_id); |
861 | 0 | } else { |
862 | 0 | sinfo.sinfo_flags = 0; |
863 | 0 | sinfo.sinfo_stream = 0; |
864 | 0 | } |
865 | 0 | if (((struct sctp_sendv_spa *)info)->sendv_flags & SCTP_SEND_PRINFO_VALID) { |
866 | 0 | sinfo.sinfo_flags |= PR_SCTP_POLICY(((struct sctp_sendv_spa *)info)->sendv_prinfo.pr_policy); |
867 | 0 | sinfo.sinfo_timetolive = ((struct sctp_sendv_spa *)info)->sendv_prinfo.pr_value; |
868 | 0 | } |
869 | 0 | if (((struct sctp_sendv_spa *)info)->sendv_flags & SCTP_SEND_AUTHINFO_VALID) { |
870 | 0 | errno = EINVAL; |
871 | 0 | return (-1); |
872 | 0 | } |
873 | 0 | use_sinfo = 1; |
874 | 0 | break; |
875 | 0 | default: |
876 | 0 | errno = EINVAL; |
877 | 0 | return (-1); |
878 | 7.62M | } |
879 | | |
880 | | /* Perform error checks on destination (to) */ |
881 | 7.62M | if (addrcnt > 1) { |
882 | 0 | errno = EINVAL; |
883 | 0 | return (-1); |
884 | 0 | } |
885 | | |
886 | 7.62M | iov[0].iov_base = (caddr_t)data; |
887 | 7.62M | iov[0].iov_len = len; |
888 | | |
889 | 7.62M | auio.uio_iov = iov; |
890 | 7.62M | auio.uio_iovcnt = 1; |
891 | 7.62M | auio.uio_segflg = UIO_USERSPACE; |
892 | 7.62M | auio.uio_rw = UIO_WRITE; |
893 | 7.62M | auio.uio_offset = 0; /* XXX */ |
894 | 7.62M | auio.uio_resid = len; |
895 | 7.62M | errno = sctp_lower_sosend(so, to, &auio, NULL, NULL, flags, use_sinfo ? &sinfo : NULL); |
896 | 7.62M | if (errno == 0) { |
897 | 24.0k | if ((to != NULL) && (assoc_id != NULL)) { |
898 | 0 | *assoc_id = usrsctp_getassocid(so, to); |
899 | 0 | } |
900 | 24.0k | return (len - auio.uio_resid); |
901 | 7.59M | } else { |
902 | 7.59M | return (-1); |
903 | 7.59M | } |
904 | 7.62M | } |
905 | | |
906 | | |
907 | | ssize_t |
908 | | userspace_sctp_sendmbuf(struct socket *so, |
909 | | struct mbuf* mbufdata, |
910 | | size_t len, |
911 | | struct sockaddr *to, |
912 | | socklen_t tolen, |
913 | | uint32_t ppid, |
914 | | uint32_t flags, |
915 | | uint16_t stream_no, |
916 | | uint32_t timetolive, |
917 | | uint32_t context) |
918 | 0 | { |
919 | |
|
920 | 0 | struct sctp_sndrcvinfo sndrcvinfo, *sinfo = &sndrcvinfo; |
921 | | /* struct uio auio; |
922 | | struct iovec iov[1]; */ |
923 | 0 | int error = 0; |
924 | 0 | int uflags = 0; |
925 | 0 | ssize_t retval; |
926 | |
|
927 | 0 | sinfo->sinfo_ppid = ppid; |
928 | 0 | sinfo->sinfo_flags = flags; |
929 | 0 | sinfo->sinfo_stream = stream_no; |
930 | 0 | sinfo->sinfo_timetolive = timetolive; |
931 | 0 | sinfo->sinfo_context = context; |
932 | 0 | sinfo->sinfo_assoc_id = 0; |
933 | | |
934 | | /* Perform error checks on destination (to) */ |
935 | 0 | if (tolen > SOCK_MAXADDRLEN){ |
936 | 0 | error = (ENAMETOOLONG); |
937 | 0 | goto sendmsg_return; |
938 | 0 | } |
939 | 0 | if (tolen < (socklen_t)offsetof(struct sockaddr, sa_data)){ |
940 | 0 | error = (EINVAL); |
941 | 0 | goto sendmsg_return; |
942 | 0 | } |
943 | | /* Adding the following as part of defensive programming, in case the application |
944 | | does not do it when preparing the destination address.*/ |
945 | | #ifdef HAVE_SA_LEN |
946 | | to->sa_len = tolen; |
947 | | #endif |
948 | | |
949 | 0 | error = sctp_lower_sosend(so, to, NULL/*uio*/, |
950 | 0 | (struct mbuf *)mbufdata, (struct mbuf *)NULL, |
951 | 0 | uflags, sinfo); |
952 | 0 | sendmsg_return: |
953 | | /* TODO: Needs a condition for non-blocking when error is EWOULDBLOCK */ |
954 | 0 | if (0 == error) |
955 | 0 | retval = len; |
956 | 0 | else if (error == EWOULDBLOCK) { |
957 | 0 | errno = EWOULDBLOCK; |
958 | 0 | retval = -1; |
959 | 0 | } else { |
960 | 0 | SCTP_PRINTF("%s: error = %d\n", __func__, error); |
961 | 0 | errno = error; |
962 | 0 | retval = -1; |
963 | 0 | } |
964 | 0 | return (retval); |
965 | 0 | } |
966 | | |
967 | | |
968 | | /* taken from usr.lib/sctp_sys_calls.c and needed here */ |
969 | | #define SCTP_SMALL_IOVEC_SIZE 2 |
970 | | |
971 | | /* Taken from /src/lib/libc/net/sctp_sys_calls.c |
972 | | * and modified for __Userspace__ |
973 | | * calling sctp_generic_recvmsg from this function |
974 | | */ |
975 | | ssize_t |
976 | | userspace_sctp_recvmsg(struct socket *so, |
977 | | void *dbuf, |
978 | | size_t len, |
979 | | struct sockaddr *from, |
980 | | socklen_t *fromlenp, |
981 | | struct sctp_sndrcvinfo *sinfo, |
982 | | int *msg_flags) |
983 | 0 | { |
984 | 0 | struct uio auio; |
985 | 0 | struct iovec iov[SCTP_SMALL_IOVEC_SIZE]; |
986 | 0 | struct iovec *tiov; |
987 | 0 | int iovlen = 1; |
988 | 0 | int error = 0; |
989 | 0 | ssize_t ulen; |
990 | 0 | int i; |
991 | 0 | socklen_t fromlen; |
992 | |
|
993 | 0 | iov[0].iov_base = dbuf; |
994 | 0 | iov[0].iov_len = len; |
995 | |
|
996 | 0 | auio.uio_iov = iov; |
997 | 0 | auio.uio_iovcnt = iovlen; |
998 | 0 | auio.uio_segflg = UIO_USERSPACE; |
999 | 0 | auio.uio_rw = UIO_READ; |
1000 | 0 | auio.uio_offset = 0; /* XXX */ |
1001 | 0 | auio.uio_resid = 0; |
1002 | 0 | tiov = iov; |
1003 | 0 | for (i = 0; i <iovlen; i++, tiov++) { |
1004 | 0 | if ((auio.uio_resid += tiov->iov_len) < 0) { |
1005 | 0 | error = EINVAL; |
1006 | 0 | SCTP_PRINTF("%s: error = %d\n", __func__, error); |
1007 | 0 | return (-1); |
1008 | 0 | } |
1009 | 0 | } |
1010 | 0 | ulen = auio.uio_resid; |
1011 | 0 | if (fromlenp != NULL) { |
1012 | 0 | fromlen = *fromlenp; |
1013 | 0 | } else { |
1014 | 0 | fromlen = 0; |
1015 | 0 | } |
1016 | 0 | error = sctp_sorecvmsg(so, &auio, (struct mbuf **)NULL, |
1017 | 0 | from, fromlen, msg_flags, |
1018 | 0 | (struct sctp_sndrcvinfo *)sinfo, 1); |
1019 | |
|
1020 | 0 | if (error) { |
1021 | 0 | if ((auio.uio_resid != ulen) && |
1022 | 0 | (error == EINTR || |
1023 | 0 | #if !defined(__NetBSD__) |
1024 | 0 | error == ERESTART || |
1025 | 0 | #endif |
1026 | 0 | error == EWOULDBLOCK)) { |
1027 | 0 | error = 0; |
1028 | 0 | } |
1029 | 0 | } |
1030 | 0 | if ((fromlenp != NULL) && (fromlen > 0) && (from != NULL)) { |
1031 | 0 | switch (from->sa_family) { |
1032 | 0 | #if defined(INET) |
1033 | 0 | case AF_INET: |
1034 | 0 | *fromlenp = sizeof(struct sockaddr_in); |
1035 | 0 | break; |
1036 | 0 | #endif |
1037 | 0 | #if defined(INET6) |
1038 | 0 | case AF_INET6: |
1039 | 0 | *fromlenp = sizeof(struct sockaddr_in6); |
1040 | 0 | break; |
1041 | 0 | #endif |
1042 | 0 | case AF_CONN: |
1043 | 0 | *fromlenp = sizeof(struct sockaddr_conn); |
1044 | 0 | break; |
1045 | 0 | default: |
1046 | 0 | *fromlenp = 0; |
1047 | 0 | break; |
1048 | 0 | } |
1049 | 0 | if (*fromlenp > fromlen) { |
1050 | 0 | *fromlenp = fromlen; |
1051 | 0 | } |
1052 | 0 | } |
1053 | 0 | if (error == 0) { |
1054 | | /* ready return value */ |
1055 | 0 | return (ulen - auio.uio_resid); |
1056 | 0 | } else { |
1057 | 0 | SCTP_PRINTF("%s: error = %d\n", __func__, error); |
1058 | 0 | return (-1); |
1059 | 0 | } |
1060 | 0 | } |
1061 | | |
1062 | | ssize_t |
1063 | | usrsctp_recvv(struct socket *so, |
1064 | | void *dbuf, |
1065 | | size_t len, |
1066 | | struct sockaddr *from, |
1067 | | socklen_t *fromlenp, |
1068 | | void *info, |
1069 | | socklen_t *infolen, |
1070 | | unsigned int *infotype, |
1071 | | int *msg_flags) |
1072 | 546k | { |
1073 | 546k | struct uio auio; |
1074 | 546k | struct iovec iov[SCTP_SMALL_IOVEC_SIZE]; |
1075 | 546k | struct iovec *tiov; |
1076 | 546k | int iovlen = 1; |
1077 | 546k | ssize_t ulen; |
1078 | 546k | int i; |
1079 | 546k | socklen_t fromlen; |
1080 | 546k | struct sctp_rcvinfo *rcv; |
1081 | 546k | struct sctp_recvv_rn *rn; |
1082 | 546k | struct sctp_extrcvinfo seinfo; |
1083 | | |
1084 | 546k | if (so == NULL) { |
1085 | 0 | errno = EBADF; |
1086 | 0 | return (-1); |
1087 | 0 | } |
1088 | 546k | iov[0].iov_base = dbuf; |
1089 | 546k | iov[0].iov_len = len; |
1090 | | |
1091 | 546k | auio.uio_iov = iov; |
1092 | 546k | auio.uio_iovcnt = iovlen; |
1093 | 546k | auio.uio_segflg = UIO_USERSPACE; |
1094 | 546k | auio.uio_rw = UIO_READ; |
1095 | 546k | auio.uio_offset = 0; /* XXX */ |
1096 | 546k | auio.uio_resid = 0; |
1097 | 546k | tiov = iov; |
1098 | 1.09M | for (i = 0; i <iovlen; i++, tiov++) { |
1099 | 546k | if ((auio.uio_resid += tiov->iov_len) < 0) { |
1100 | 0 | errno = EINVAL; |
1101 | 0 | return (-1); |
1102 | 0 | } |
1103 | 546k | } |
1104 | 546k | ulen = auio.uio_resid; |
1105 | 546k | if (fromlenp != NULL) { |
1106 | 546k | fromlen = *fromlenp; |
1107 | 546k | } else { |
1108 | 0 | fromlen = 0; |
1109 | 0 | } |
1110 | 546k | errno = sctp_sorecvmsg(so, &auio, (struct mbuf **)NULL, |
1111 | 546k | from, fromlen, msg_flags, |
1112 | 546k | (struct sctp_sndrcvinfo *)&seinfo, 1); |
1113 | 546k | if (errno) { |
1114 | 1.74k | if ((auio.uio_resid != ulen) && |
1115 | 1.74k | (errno == EINTR || |
1116 | 0 | #if !defined(__NetBSD__) |
1117 | 0 | errno == ERESTART || |
1118 | 0 | #endif |
1119 | 0 | errno == EWOULDBLOCK)) { |
1120 | 0 | errno = 0; |
1121 | 0 | } |
1122 | 1.74k | } |
1123 | 546k | if (errno != 0) { |
1124 | 1.74k | goto out; |
1125 | 1.74k | } |
1126 | 544k | if ((*msg_flags & MSG_NOTIFICATION) == 0) { |
1127 | 1.24k | struct sctp_inpcb *inp; |
1128 | | |
1129 | 1.24k | inp = (struct sctp_inpcb *)so->so_pcb; |
1130 | 1.24k | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO) && |
1131 | 1.24k | sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO) && |
1132 | 1.24k | *infolen >= (socklen_t)sizeof(struct sctp_recvv_rn) && |
1133 | 1.24k | seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_AVAIL) { |
1134 | 550 | rn = (struct sctp_recvv_rn *)info; |
1135 | 550 | rn->recvv_rcvinfo.rcv_sid = seinfo.sinfo_stream; |
1136 | 550 | rn->recvv_rcvinfo.rcv_ssn = seinfo.sinfo_ssn; |
1137 | 550 | rn->recvv_rcvinfo.rcv_flags = seinfo.sinfo_flags; |
1138 | 550 | rn->recvv_rcvinfo.rcv_ppid = seinfo.sinfo_ppid; |
1139 | 550 | rn->recvv_rcvinfo.rcv_context = seinfo.sinfo_context; |
1140 | 550 | rn->recvv_rcvinfo.rcv_tsn = seinfo.sinfo_tsn; |
1141 | 550 | rn->recvv_rcvinfo.rcv_cumtsn = seinfo.sinfo_cumtsn; |
1142 | 550 | rn->recvv_rcvinfo.rcv_assoc_id = seinfo.sinfo_assoc_id; |
1143 | 550 | rn->recvv_nxtinfo.nxt_sid = seinfo.sreinfo_next_stream; |
1144 | 550 | rn->recvv_nxtinfo.nxt_flags = 0; |
1145 | 550 | if (seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_IS_UNORDERED) { |
1146 | 391 | rn->recvv_nxtinfo.nxt_flags |= SCTP_UNORDERED; |
1147 | 391 | } |
1148 | 550 | if (seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_IS_NOTIFICATION) { |
1149 | 76 | rn->recvv_nxtinfo.nxt_flags |= SCTP_NOTIFICATION; |
1150 | 76 | } |
1151 | 550 | if (seinfo.sreinfo_next_flags & SCTP_NEXT_MSG_ISCOMPLETE) { |
1152 | 550 | rn->recvv_nxtinfo.nxt_flags |= SCTP_COMPLETE; |
1153 | 550 | } |
1154 | 550 | rn->recvv_nxtinfo.nxt_ppid = seinfo.sreinfo_next_ppid; |
1155 | 550 | rn->recvv_nxtinfo.nxt_length = seinfo.sreinfo_next_length; |
1156 | 550 | rn->recvv_nxtinfo.nxt_assoc_id = seinfo.sreinfo_next_aid; |
1157 | 550 | *infolen = (socklen_t)sizeof(struct sctp_recvv_rn); |
1158 | 550 | *infotype = SCTP_RECVV_RN; |
1159 | 695 | } else if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO) && |
1160 | 695 | *infolen >= (socklen_t)sizeof(struct sctp_rcvinfo)) { |
1161 | 695 | rcv = (struct sctp_rcvinfo *)info; |
1162 | 695 | rcv->rcv_sid = seinfo.sinfo_stream; |
1163 | 695 | rcv->rcv_ssn = seinfo.sinfo_ssn; |
1164 | 695 | rcv->rcv_flags = seinfo.sinfo_flags; |
1165 | 695 | rcv->rcv_ppid = seinfo.sinfo_ppid; |
1166 | 695 | rcv->rcv_context = seinfo.sinfo_context; |
1167 | 695 | rcv->rcv_tsn = seinfo.sinfo_tsn; |
1168 | 695 | rcv->rcv_cumtsn = seinfo.sinfo_cumtsn; |
1169 | 695 | rcv->rcv_assoc_id = seinfo.sinfo_assoc_id; |
1170 | 695 | *infolen = (socklen_t)sizeof(struct sctp_rcvinfo); |
1171 | 695 | *infotype = SCTP_RECVV_RCVINFO; |
1172 | 695 | } else { |
1173 | 0 | *infotype = SCTP_RECVV_NOINFO; |
1174 | 0 | *infolen = 0; |
1175 | 0 | } |
1176 | 1.24k | } |
1177 | 544k | if ((fromlenp != NULL) && |
1178 | 544k | (fromlen > 0) && |
1179 | 544k | (from != NULL) && |
1180 | 544k | (ulen > auio.uio_resid)) { |
1181 | 544k | switch (from->sa_family) { |
1182 | 0 | #if defined(INET) |
1183 | 291 | case AF_INET: |
1184 | 291 | *fromlenp = sizeof(struct sockaddr_in); |
1185 | 291 | break; |
1186 | 0 | #endif |
1187 | 0 | #if defined(INET6) |
1188 | 9.13k | case AF_INET6: |
1189 | 9.13k | *fromlenp = sizeof(struct sockaddr_in6); |
1190 | 9.13k | break; |
1191 | 0 | #endif |
1192 | 535k | case AF_CONN: |
1193 | 535k | *fromlenp = sizeof(struct sockaddr_conn); |
1194 | 535k | break; |
1195 | 0 | default: |
1196 | 0 | *fromlenp = 0; |
1197 | 0 | break; |
1198 | 544k | } |
1199 | 544k | if (*fromlenp > fromlen) { |
1200 | 9.13k | *fromlenp = fromlen; |
1201 | 9.13k | } |
1202 | 544k | } |
1203 | 546k | out: |
1204 | 546k | if (errno == 0) { |
1205 | | /* ready return value */ |
1206 | 544k | return (ulen - auio.uio_resid); |
1207 | 544k | } else { |
1208 | 1.74k | return (-1); |
1209 | 1.74k | } |
1210 | 546k | } |
1211 | | |
1212 | | |
1213 | | |
1214 | | |
1215 | | /* Taken from /src/sys/kern/uipc_socket.c |
1216 | | * and modified for __Userspace__ |
1217 | | * socreate returns a socket. The socket should be |
1218 | | * closed with soclose(). |
1219 | | */ |
1220 | | int |
1221 | | socreate(int dom, struct socket **aso, int type, int proto) |
1222 | 13.0k | { |
1223 | 13.0k | struct socket *so; |
1224 | 13.0k | int error; |
1225 | | |
1226 | 13.0k | if ((dom != AF_CONN) && (dom != AF_INET) && (dom != AF_INET6)) { |
1227 | 0 | return (EINVAL); |
1228 | 0 | } |
1229 | 13.0k | if ((type != SOCK_STREAM) && (type != SOCK_SEQPACKET)) { |
1230 | 0 | return (EINVAL); |
1231 | 0 | } |
1232 | 13.0k | if (proto != IPPROTO_SCTP) { |
1233 | 0 | return (EINVAL); |
1234 | 0 | } |
1235 | | |
1236 | 13.0k | so = soalloc(); |
1237 | 13.0k | if (so == NULL) { |
1238 | 0 | return (ENOBUFS); |
1239 | 0 | } |
1240 | | |
1241 | | /* |
1242 | | * so_incomp represents a queue of connections that |
1243 | | * must be completed at protocol level before being |
1244 | | * returned. so_comp field heads a list of sockets |
1245 | | * that are ready to be returned to the listening process |
1246 | | *__Userspace__ These queues are being used at a number of places like accept etc. |
1247 | | */ |
1248 | 13.0k | TAILQ_INIT(&so->so_incomp); |
1249 | 13.0k | TAILQ_INIT(&so->so_comp); |
1250 | 13.0k | so->so_type = type; |
1251 | 13.0k | so->so_count = 1; |
1252 | 13.0k | so->so_dom = dom; |
1253 | | /* |
1254 | | * Auto-sizing of socket buffers is managed by the protocols and |
1255 | | * the appropriate flags must be set in the pru_attach function. |
1256 | | * For __Userspace__ The pru_attach function in this case is sctp_attach. |
1257 | | */ |
1258 | 13.0k | switch (dom) { |
1259 | 0 | #if defined(INET) |
1260 | 0 | case AF_INET: |
1261 | 0 | error = sctp_attach(so, proto, SCTP_DEFAULT_VRFID); |
1262 | 0 | break; |
1263 | 0 | #endif |
1264 | 0 | #if defined(INET6) |
1265 | 0 | case AF_INET6: |
1266 | 0 | error = sctp6_attach(so, proto, SCTP_DEFAULT_VRFID); |
1267 | 0 | break; |
1268 | 0 | #endif |
1269 | 13.0k | case AF_CONN: |
1270 | 13.0k | error = sctpconn_attach(so, proto, SCTP_DEFAULT_VRFID); |
1271 | 13.0k | break; |
1272 | 0 | default: |
1273 | 0 | error = EAFNOSUPPORT; |
1274 | 0 | break; |
1275 | 13.0k | } |
1276 | 13.0k | if (error) { |
1277 | 0 | KASSERT(so->so_count == 1, ("socreate: so_count %d", so->so_count)); |
1278 | 0 | so->so_count = 0; |
1279 | 0 | sodealloc(so); |
1280 | 0 | return (error); |
1281 | 0 | } |
1282 | 13.0k | *aso = so; |
1283 | 13.0k | return (0); |
1284 | 13.0k | } |
1285 | | |
1286 | | |
1287 | | /* Taken from /src/sys/kern/uipc_syscalls.c |
1288 | | * and modified for __Userspace__ |
1289 | | * Removing struct thread td. |
1290 | | */ |
1291 | | struct socket * |
1292 | | userspace_socket(int domain, int type, int protocol) |
1293 | 0 | { |
1294 | 0 | struct socket *so = NULL; |
1295 | |
|
1296 | 0 | errno = socreate(domain, &so, type, protocol); |
1297 | 0 | if (errno) { |
1298 | 0 | return (NULL); |
1299 | 0 | } |
1300 | | /* |
1301 | | * The original socket call returns the file descriptor fd. |
1302 | | * td->td_retval[0] = fd. |
1303 | | * We are returning struct socket *so. |
1304 | | */ |
1305 | 0 | return (so); |
1306 | 0 | } |
1307 | | |
1308 | | struct socket * |
1309 | | usrsctp_socket(int domain, int type, int protocol, |
1310 | | int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data, |
1311 | | size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info), |
1312 | | int (*send_cb)(struct socket *sock, uint32_t sb_free, void *ulp_info), |
1313 | | uint32_t sb_threshold, |
1314 | | void *ulp_info) |
1315 | 13.0k | { |
1316 | 13.0k | struct socket *so = NULL; |
1317 | | |
1318 | 13.0k | if ((protocol == IPPROTO_SCTP) && (SCTP_BASE_VAR(sctp_pcb_initialized) == 0)) { |
1319 | 0 | errno = EPROTONOSUPPORT; |
1320 | 0 | return (NULL); |
1321 | 0 | } |
1322 | 13.0k | if ((receive_cb == NULL) && |
1323 | 13.0k | ((send_cb != NULL) || (sb_threshold != 0) || (ulp_info != NULL))) { |
1324 | 0 | errno = EINVAL; |
1325 | 0 | return (NULL); |
1326 | 0 | } |
1327 | 13.0k | if ((domain == AF_CONN) && (SCTP_BASE_VAR(conn_output) == NULL)) { |
1328 | 0 | errno = EAFNOSUPPORT; |
1329 | 0 | return (NULL); |
1330 | 0 | } |
1331 | 13.0k | errno = socreate(domain, &so, type, protocol); |
1332 | 13.0k | if (errno) { |
1333 | 0 | return (NULL); |
1334 | 0 | } |
1335 | | /* |
1336 | | * The original socket call returns the file descriptor fd. |
1337 | | * td->td_retval[0] = fd. |
1338 | | * We are returning struct socket *so. |
1339 | | */ |
1340 | 13.0k | register_recv_cb(so, receive_cb); |
1341 | 13.0k | register_send_cb(so, sb_threshold, send_cb); |
1342 | 13.0k | register_ulp_info(so, ulp_info); |
1343 | 13.0k | return (so); |
1344 | 13.0k | } |
1345 | | |
1346 | | |
1347 | | u_long sb_max = SB_MAX; |
1348 | | u_long sb_max_adj = |
1349 | | SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */ |
1350 | | |
1351 | | static u_long sb_efficiency = 8; /* parameter for sbreserve() */ |
1352 | | |
1353 | | /* |
1354 | | * Allot mbufs to a sockbuf. Attempt to scale mbmax so that mbcnt doesn't |
1355 | | * become limiting if buffering efficiency is near the normal case. |
1356 | | */ |
1357 | | int |
1358 | | sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so) |
1359 | 26.1k | { |
1360 | 26.1k | SOCKBUF_LOCK_ASSERT(sb); |
1361 | 26.1k | sb->sb_mbmax = (u_int)min(cc * sb_efficiency, sb_max); |
1362 | 26.1k | sb->sb_hiwat = (u_int)cc; |
1363 | 26.1k | if (sb->sb_lowat > (int)sb->sb_hiwat) |
1364 | 0 | sb->sb_lowat = (int)sb->sb_hiwat; |
1365 | 26.1k | return (1); |
1366 | 26.1k | } |
1367 | | |
1368 | | static int |
1369 | | sbreserve(struct sockbuf *sb, u_long cc, struct socket *so) |
1370 | 0 | { |
1371 | 0 | int error; |
1372 | |
|
1373 | 0 | SOCKBUF_LOCK(sb); |
1374 | 0 | error = sbreserve_locked(sb, cc, so); |
1375 | 0 | SOCKBUF_UNLOCK(sb); |
1376 | 0 | return (error); |
1377 | 0 | } |
1378 | | |
1379 | | int |
1380 | | soreserve(struct socket *so, u_long sndcc, u_long rcvcc) |
1381 | 13.0k | { |
1382 | 13.0k | SOCKBUF_LOCK(&so->so_snd); |
1383 | 13.0k | SOCKBUF_LOCK(&so->so_rcv); |
1384 | 13.0k | so->so_snd.sb_hiwat = (uint32_t)sndcc; |
1385 | 13.0k | so->so_rcv.sb_hiwat = (uint32_t)rcvcc; |
1386 | | |
1387 | 13.0k | if (sbreserve_locked(&so->so_snd, sndcc, so) == 0) { |
1388 | 0 | goto bad; |
1389 | 0 | } |
1390 | 13.0k | if (sbreserve_locked(&so->so_rcv, rcvcc, so) == 0) { |
1391 | 0 | goto bad; |
1392 | 0 | } |
1393 | 13.0k | if (so->so_rcv.sb_lowat == 0) |
1394 | 13.0k | so->so_rcv.sb_lowat = 1; |
1395 | 13.0k | if (so->so_snd.sb_lowat == 0) |
1396 | 13.0k | so->so_snd.sb_lowat = MCLBYTES; |
1397 | 13.0k | if (so->so_snd.sb_lowat > (int)so->so_snd.sb_hiwat) |
1398 | 0 | so->so_snd.sb_lowat = (int)so->so_snd.sb_hiwat; |
1399 | 13.0k | SOCKBUF_UNLOCK(&so->so_rcv); |
1400 | 13.0k | SOCKBUF_UNLOCK(&so->so_snd); |
1401 | 13.0k | return (0); |
1402 | | |
1403 | 0 | bad: |
1404 | 0 | SOCKBUF_UNLOCK(&so->so_rcv); |
1405 | 0 | SOCKBUF_UNLOCK(&so->so_snd); |
1406 | 0 | return (ENOBUFS); |
1407 | 0 | } |
1408 | | |
1409 | | |
1410 | | /* Taken from /src/sys/kern/uipc_sockbuf.c |
1411 | | * and modified for __Userspace__ |
1412 | | */ |
1413 | | |
1414 | | void |
1415 | | sowakeup(struct socket *so, struct sockbuf *sb) |
1416 | 587k | { |
1417 | | |
1418 | 587k | SOCKBUF_LOCK_ASSERT(sb); |
1419 | | |
1420 | 587k | sb->sb_flags &= ~SB_SEL; |
1421 | 587k | if (sb->sb_flags & SB_WAIT) { |
1422 | 0 | sb->sb_flags &= ~SB_WAIT; |
1423 | | #if defined(_WIN32) |
1424 | | WakeAllConditionVariable(&(sb)->sb_cond); |
1425 | | #else |
1426 | 0 | pthread_cond_broadcast(&(sb)->sb_cond); |
1427 | 0 | #endif |
1428 | 0 | } |
1429 | 587k | SOCKBUF_UNLOCK(sb); |
1430 | 587k | } |
1431 | | |
1432 | | |
1433 | | /* Taken from /src/sys/kern/uipc_socket.c |
1434 | | * and modified for __Userspace__ |
1435 | | */ |
1436 | | |
1437 | | int |
1438 | | sobind(struct socket *so, struct sockaddr *nam) |
1439 | 13.0k | { |
1440 | 13.0k | switch (nam->sa_family) { |
1441 | 0 | #if defined(INET) |
1442 | 0 | case AF_INET: |
1443 | 0 | return (sctp_bind(so, nam)); |
1444 | 0 | #endif |
1445 | 0 | #if defined(INET6) |
1446 | 0 | case AF_INET6: |
1447 | 0 | return (sctp6_bind(so, nam, NULL)); |
1448 | 0 | #endif |
1449 | 13.0k | case AF_CONN: |
1450 | 13.0k | return (sctpconn_bind(so, nam)); |
1451 | 0 | default: |
1452 | 0 | return EAFNOSUPPORT; |
1453 | 13.0k | } |
1454 | 13.0k | } |
1455 | | |
1456 | | /* Taken from /src/sys/kern/uipc_syscalls.c |
1457 | | * and modified for __Userspace__ |
1458 | | */ |
1459 | | |
1460 | | int |
1461 | | usrsctp_bind(struct socket *so, struct sockaddr *name, int namelen) |
1462 | 13.0k | { |
1463 | 13.0k | struct sockaddr *sa; |
1464 | | |
1465 | 13.0k | if (so == NULL) { |
1466 | 0 | errno = EBADF; |
1467 | 0 | return (-1); |
1468 | 0 | } |
1469 | 13.0k | if ((errno = getsockaddr(&sa, (caddr_t)name, namelen)) != 0) |
1470 | 0 | return (-1); |
1471 | | |
1472 | 13.0k | errno = sobind(so, sa); |
1473 | 13.0k | FREE(sa, M_SONAME); |
1474 | 13.0k | if (errno) { |
1475 | 0 | return (-1); |
1476 | 13.0k | } else { |
1477 | 13.0k | return (0); |
1478 | 13.0k | } |
1479 | 13.0k | } |
1480 | | |
1481 | | int |
1482 | | userspace_bind(struct socket *so, struct sockaddr *name, int namelen) |
1483 | 0 | { |
1484 | 0 | return (usrsctp_bind(so, name, namelen)); |
1485 | 0 | } |
1486 | | |
1487 | | /* Taken from /src/sys/kern/uipc_socket.c |
1488 | | * and modified for __Userspace__ |
1489 | | */ |
1490 | | |
1491 | | int |
1492 | | solisten(struct socket *so, int backlog) |
1493 | 1 | { |
1494 | 1 | if (so == NULL) { |
1495 | 0 | return (EBADF); |
1496 | 1 | } else { |
1497 | 1 | return (sctp_listen(so, backlog, NULL)); |
1498 | 1 | } |
1499 | 1 | } |
1500 | | |
1501 | | |
1502 | | int |
1503 | | solisten_proto_check(struct socket *so) |
1504 | 1 | { |
1505 | | |
1506 | 1 | SOCK_LOCK_ASSERT(so); |
1507 | | |
1508 | 1 | if (so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING | |
1509 | 1 | SS_ISDISCONNECTING)) |
1510 | 0 | return (EINVAL); |
1511 | 1 | return (0); |
1512 | 1 | } |
1513 | | |
1514 | | static int somaxconn = SOMAXCONN; |
1515 | | |
1516 | | void |
1517 | | solisten_proto(struct socket *so, int backlog) |
1518 | 1 | { |
1519 | | |
1520 | 1 | SOCK_LOCK_ASSERT(so); |
1521 | | |
1522 | 1 | if (backlog < 0 || backlog > somaxconn) |
1523 | 0 | backlog = somaxconn; |
1524 | 1 | so->so_qlimit = backlog; |
1525 | 1 | so->so_options |= SCTP_SO_ACCEPTCONN; |
1526 | 1 | } |
1527 | | |
1528 | | |
1529 | | |
1530 | | |
1531 | | /* Taken from /src/sys/kern/uipc_syscalls.c |
1532 | | * and modified for __Userspace__ |
1533 | | */ |
1534 | | |
1535 | | int |
1536 | | usrsctp_listen(struct socket *so, int backlog) |
1537 | 1 | { |
1538 | 1 | errno = solisten(so, backlog); |
1539 | 1 | if (errno) { |
1540 | 0 | return (-1); |
1541 | 1 | } else { |
1542 | 1 | return (0); |
1543 | 1 | } |
1544 | 1 | } |
1545 | | |
1546 | | int |
1547 | | userspace_listen(struct socket *so, int backlog) |
1548 | 0 | { |
1549 | 0 | return (usrsctp_listen(so, backlog)); |
1550 | 0 | } |
1551 | | |
1552 | | /* Taken from /src/sys/kern/uipc_socket.c |
1553 | | * and modified for __Userspace__ |
1554 | | */ |
1555 | | |
1556 | | int |
1557 | | soaccept(struct socket *so, struct sockaddr **nam) |
1558 | 0 | { |
1559 | 0 | int error; |
1560 | |
|
1561 | 0 | SOCK_LOCK(so); |
1562 | 0 | KASSERT((so->so_state & SS_NOFDREF) != 0, ("soaccept: !NOFDREF")); |
1563 | 0 | so->so_state &= ~SS_NOFDREF; |
1564 | 0 | SOCK_UNLOCK(so); |
1565 | 0 | error = sctp_accept(so, nam); |
1566 | 0 | return (error); |
1567 | 0 | } |
1568 | | |
1569 | | |
1570 | | |
1571 | | /* Taken from /src/sys/kern/uipc_syscalls.c |
1572 | | * kern_accept modified for __Userspace__ |
1573 | | */ |
1574 | | int |
1575 | | user_accept(struct socket *head, struct sockaddr **name, socklen_t *namelen, struct socket **ptr_accept_ret_sock) |
1576 | 0 | { |
1577 | 0 | struct sockaddr *sa = NULL; |
1578 | 0 | int error; |
1579 | 0 | struct socket *so = NULL; |
1580 | | |
1581 | |
|
1582 | 0 | if (name) { |
1583 | 0 | *name = NULL; |
1584 | 0 | } |
1585 | |
|
1586 | 0 | if ((head->so_options & SCTP_SO_ACCEPTCONN) == 0) { |
1587 | 0 | error = EINVAL; |
1588 | 0 | goto done; |
1589 | 0 | } |
1590 | | |
1591 | 0 | ACCEPT_LOCK(); |
1592 | 0 | if ((head->so_state & SS_NBIO) && TAILQ_EMPTY(&head->so_comp)) { |
1593 | 0 | ACCEPT_UNLOCK(); |
1594 | 0 | error = EWOULDBLOCK; |
1595 | 0 | goto noconnection; |
1596 | 0 | } |
1597 | 0 | while (TAILQ_EMPTY(&head->so_comp) && head->so_error == 0) { |
1598 | 0 | if (head->so_rcv.sb_state & SBS_CANTRCVMORE) { |
1599 | 0 | head->so_error = ECONNABORTED; |
1600 | 0 | break; |
1601 | 0 | } |
1602 | | #if defined(_WIN32) |
1603 | | if (SleepConditionVariableCS(&accept_cond, &accept_mtx, INFINITE)) |
1604 | | error = 0; |
1605 | | else |
1606 | | error = GetLastError(); |
1607 | | #else |
1608 | 0 | error = pthread_cond_wait(&accept_cond, &accept_mtx); |
1609 | 0 | #endif |
1610 | 0 | if (error) { |
1611 | 0 | ACCEPT_UNLOCK(); |
1612 | 0 | goto noconnection; |
1613 | 0 | } |
1614 | 0 | } |
1615 | 0 | if (head->so_error) { |
1616 | 0 | error = head->so_error; |
1617 | 0 | head->so_error = 0; |
1618 | 0 | ACCEPT_UNLOCK(); |
1619 | 0 | goto noconnection; |
1620 | 0 | } |
1621 | 0 | so = TAILQ_FIRST(&head->so_comp); |
1622 | 0 | KASSERT(!(so->so_qstate & SQ_INCOMP), ("accept1: so SQ_INCOMP")); |
1623 | 0 | KASSERT(so->so_qstate & SQ_COMP, ("accept1: so not SQ_COMP")); |
1624 | | |
1625 | | /* |
1626 | | * Before changing the flags on the socket, we have to bump the |
1627 | | * reference count. Otherwise, if the protocol calls sofree(), |
1628 | | * the socket will be released due to a zero refcount. |
1629 | | */ |
1630 | 0 | SOCK_LOCK(so); /* soref() and so_state update */ |
1631 | 0 | soref(so); /* file descriptor reference */ |
1632 | | |
1633 | 0 | TAILQ_REMOVE(&head->so_comp, so, so_list); |
1634 | 0 | head->so_qlen--; |
1635 | 0 | so->so_state |= (head->so_state & SS_NBIO); |
1636 | 0 | so->so_qstate &= ~SQ_COMP; |
1637 | 0 | so->so_head = NULL; |
1638 | 0 | SOCK_UNLOCK(so); |
1639 | 0 | ACCEPT_UNLOCK(); |
1640 | | |
1641 | | |
1642 | | /* |
1643 | | * The original accept returns fd value via td->td_retval[0] = fd; |
1644 | | * we will return the socket for accepted connection. |
1645 | | */ |
1646 | | |
1647 | 0 | error = soaccept(so, &sa); |
1648 | 0 | if (error) { |
1649 | | /* |
1650 | | * return a namelen of zero for older code which might |
1651 | | * ignore the return value from accept. |
1652 | | */ |
1653 | 0 | if (name) |
1654 | 0 | *namelen = 0; |
1655 | 0 | goto noconnection; |
1656 | 0 | } |
1657 | 0 | if (sa == NULL) { |
1658 | 0 | if (name) |
1659 | 0 | *namelen = 0; |
1660 | 0 | goto done; |
1661 | 0 | } |
1662 | 0 | if (name) { |
1663 | | #ifdef HAVE_SA_LEN |
1664 | | /* check sa_len before it is destroyed */ |
1665 | | if (*namelen > sa->sa_len) { |
1666 | | *namelen = sa->sa_len; |
1667 | | } |
1668 | | #else |
1669 | 0 | socklen_t sa_len; |
1670 | |
|
1671 | 0 | switch (sa->sa_family) { |
1672 | 0 | #ifdef INET |
1673 | 0 | case AF_INET: |
1674 | 0 | sa_len = sizeof(struct sockaddr_in); |
1675 | 0 | break; |
1676 | 0 | #endif |
1677 | 0 | #ifdef INET6 |
1678 | 0 | case AF_INET6: |
1679 | 0 | sa_len = sizeof(struct sockaddr_in6); |
1680 | 0 | break; |
1681 | 0 | #endif |
1682 | 0 | case AF_CONN: |
1683 | 0 | sa_len = sizeof(struct sockaddr_conn); |
1684 | 0 | break; |
1685 | 0 | default: |
1686 | 0 | sa_len = 0; |
1687 | 0 | break; |
1688 | 0 | } |
1689 | 0 | if (*namelen > sa_len) { |
1690 | 0 | *namelen = sa_len; |
1691 | 0 | } |
1692 | 0 | #endif |
1693 | 0 | *name = sa; |
1694 | 0 | sa = NULL; |
1695 | 0 | } |
1696 | 0 | noconnection: |
1697 | 0 | if (sa) { |
1698 | 0 | FREE(sa, M_SONAME); |
1699 | 0 | } |
1700 | |
|
1701 | 0 | done: |
1702 | 0 | *ptr_accept_ret_sock = so; |
1703 | 0 | return (error); |
1704 | 0 | } |
1705 | | |
1706 | | |
1707 | | |
1708 | | /* Taken from /src/sys/kern/uipc_syscalls.c |
1709 | | * and modified for __Userspace__ |
1710 | | */ |
1711 | | /* |
1712 | | * accept1() |
1713 | | */ |
1714 | | static int |
1715 | | accept1(struct socket *so, struct sockaddr *aname, socklen_t *anamelen, struct socket **ptr_accept_ret_sock) |
1716 | 0 | { |
1717 | 0 | struct sockaddr *name; |
1718 | 0 | socklen_t namelen; |
1719 | 0 | int error; |
1720 | |
|
1721 | 0 | if (so == NULL) { |
1722 | 0 | return (EBADF); |
1723 | 0 | } |
1724 | 0 | if (aname == NULL) { |
1725 | 0 | return (user_accept(so, NULL, NULL, ptr_accept_ret_sock)); |
1726 | 0 | } |
1727 | | |
1728 | 0 | error = copyin(anamelen, &namelen, sizeof (namelen)); |
1729 | 0 | if (error) |
1730 | 0 | return (error); |
1731 | | |
1732 | 0 | error = user_accept(so, &name, &namelen, ptr_accept_ret_sock); |
1733 | | |
1734 | | /* |
1735 | | * return a namelen of zero for older code which might |
1736 | | * ignore the return value from accept. |
1737 | | */ |
1738 | 0 | if (error) { |
1739 | 0 | (void) copyout(&namelen, |
1740 | 0 | anamelen, sizeof(*anamelen)); |
1741 | 0 | return (error); |
1742 | 0 | } |
1743 | | |
1744 | 0 | if (error == 0 && name != NULL) { |
1745 | 0 | error = copyout(name, aname, namelen); |
1746 | 0 | } |
1747 | 0 | if (error == 0) { |
1748 | 0 | error = copyout(&namelen, anamelen, sizeof(namelen)); |
1749 | 0 | } |
1750 | |
|
1751 | 0 | if (name) { |
1752 | 0 | FREE(name, M_SONAME); |
1753 | 0 | } |
1754 | 0 | return (error); |
1755 | 0 | } |
1756 | | |
1757 | | struct socket * |
1758 | | usrsctp_accept(struct socket *so, struct sockaddr *aname, socklen_t *anamelen) |
1759 | 0 | { |
1760 | 0 | struct socket *accept_return_sock = NULL; |
1761 | |
|
1762 | 0 | errno = accept1(so, aname, anamelen, &accept_return_sock); |
1763 | 0 | if (errno) { |
1764 | 0 | return (NULL); |
1765 | 0 | } else { |
1766 | 0 | return (accept_return_sock); |
1767 | 0 | } |
1768 | 0 | } |
1769 | | |
1770 | | struct socket * |
1771 | | userspace_accept(struct socket *so, struct sockaddr *aname, socklen_t *anamelen) |
1772 | 0 | { |
1773 | 0 | return (usrsctp_accept(so, aname, anamelen)); |
1774 | 0 | } |
1775 | | |
1776 | | struct socket * |
1777 | | usrsctp_peeloff(struct socket *head, sctp_assoc_t id) |
1778 | 0 | { |
1779 | 0 | struct socket *so; |
1780 | |
|
1781 | 0 | if ((errno = sctp_can_peel_off(head, id)) != 0) { |
1782 | 0 | return (NULL); |
1783 | 0 | } |
1784 | 0 | if ((so = sonewconn(head, SS_ISCONNECTED)) == NULL) { |
1785 | 0 | return (NULL); |
1786 | 0 | } |
1787 | 0 | ACCEPT_LOCK(); |
1788 | 0 | SOCK_LOCK(so); |
1789 | 0 | soref(so); |
1790 | 0 | TAILQ_REMOVE(&head->so_comp, so, so_list); |
1791 | 0 | head->so_qlen--; |
1792 | 0 | so->so_state |= (head->so_state & SS_NBIO); |
1793 | 0 | so->so_qstate &= ~SQ_COMP; |
1794 | 0 | so->so_head = NULL; |
1795 | 0 | SOCK_UNLOCK(so); |
1796 | 0 | ACCEPT_UNLOCK(); |
1797 | 0 | if ((errno = sctp_do_peeloff(head, so, id)) != 0) { |
1798 | 0 | so->so_count = 0; |
1799 | 0 | sodealloc(so); |
1800 | 0 | return (NULL); |
1801 | 0 | } |
1802 | 0 | return (so); |
1803 | 0 | } |
1804 | | |
1805 | | int |
1806 | | sodisconnect(struct socket *so) |
1807 | 0 | { |
1808 | 0 | int error; |
1809 | |
|
1810 | 0 | if ((so->so_state & SS_ISCONNECTED) == 0) |
1811 | 0 | return (ENOTCONN); |
1812 | 0 | if (so->so_state & SS_ISDISCONNECTING) |
1813 | 0 | return (EALREADY); |
1814 | 0 | error = sctp_disconnect(so); |
1815 | 0 | return (error); |
1816 | 0 | } |
1817 | | |
1818 | | int |
1819 | | usrsctp_set_non_blocking(struct socket *so, int onoff) |
1820 | 13.0k | { |
1821 | 13.0k | if (so == NULL) { |
1822 | 0 | errno = EBADF; |
1823 | 0 | return (-1); |
1824 | 0 | } |
1825 | 13.0k | SOCK_LOCK(so); |
1826 | 13.0k | if (onoff != 0) { |
1827 | 13.0k | so->so_state |= SS_NBIO; |
1828 | 13.0k | } else { |
1829 | 0 | so->so_state &= ~SS_NBIO; |
1830 | 0 | } |
1831 | 13.0k | SOCK_UNLOCK(so); |
1832 | 13.0k | return (0); |
1833 | 13.0k | } |
1834 | | |
1835 | | int |
1836 | | usrsctp_get_non_blocking(struct socket *so) |
1837 | 0 | { |
1838 | 0 | int result; |
1839 | |
|
1840 | 0 | if (so == NULL) { |
1841 | 0 | errno = EBADF; |
1842 | 0 | return (-1); |
1843 | 0 | } |
1844 | 0 | SOCK_LOCK(so); |
1845 | 0 | if (so->so_state & SS_NBIO) { |
1846 | 0 | result = 1; |
1847 | 0 | } else { |
1848 | 0 | result = 0; |
1849 | 0 | } |
1850 | 0 | SOCK_UNLOCK(so); |
1851 | 0 | return (result); |
1852 | 0 | } |
1853 | | |
1854 | | int |
1855 | | soconnect(struct socket *so, struct sockaddr *nam) |
1856 | 13.0k | { |
1857 | 13.0k | int error; |
1858 | | |
1859 | 13.0k | if (so->so_options & SCTP_SO_ACCEPTCONN) |
1860 | 0 | return (EOPNOTSUPP); |
1861 | | /* |
1862 | | * If protocol is connection-based, can only connect once. |
1863 | | * Otherwise, if connected, try to disconnect first. This allows |
1864 | | * user to disconnect by connecting to, e.g., a null address. |
1865 | | */ |
1866 | 13.0k | if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) && (sodisconnect(so) != 0)) { |
1867 | 0 | error = EISCONN; |
1868 | 13.0k | } else { |
1869 | | /* |
1870 | | * Prevent accumulated error from previous connection from |
1871 | | * biting us. |
1872 | | */ |
1873 | 13.0k | so->so_error = 0; |
1874 | 13.0k | switch (nam->sa_family) { |
1875 | 0 | #if defined(INET) |
1876 | 0 | case AF_INET: |
1877 | 0 | error = sctp_connect(so, nam); |
1878 | 0 | break; |
1879 | 0 | #endif |
1880 | 0 | #if defined(INET6) |
1881 | 0 | case AF_INET6: |
1882 | 0 | error = sctp6_connect(so, nam); |
1883 | 0 | break; |
1884 | 0 | #endif |
1885 | 13.0k | case AF_CONN: |
1886 | 13.0k | error = sctpconn_connect(so, nam); |
1887 | 13.0k | break; |
1888 | 0 | default: |
1889 | 0 | error = EAFNOSUPPORT; |
1890 | 13.0k | } |
1891 | 13.0k | } |
1892 | | |
1893 | 13.0k | return (error); |
1894 | 13.0k | } |
1895 | | |
1896 | | |
1897 | | |
1898 | | int user_connect(struct socket *so, struct sockaddr *sa) |
1899 | 13.0k | { |
1900 | 13.0k | int error; |
1901 | 13.0k | int interrupted = 0; |
1902 | | |
1903 | 13.0k | if (so == NULL) { |
1904 | 0 | error = EBADF; |
1905 | 0 | goto done1; |
1906 | 0 | } |
1907 | 13.0k | if (so->so_state & SS_ISCONNECTING) { |
1908 | 0 | error = EALREADY; |
1909 | 0 | goto done1; |
1910 | 0 | } |
1911 | | |
1912 | 13.0k | error = soconnect(so, sa); |
1913 | 13.0k | if (error) { |
1914 | 0 | goto bad; |
1915 | 0 | } |
1916 | 13.0k | if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) { |
1917 | 13.0k | error = EINPROGRESS; |
1918 | 13.0k | goto done1; |
1919 | 13.0k | } |
1920 | | |
1921 | 0 | SOCK_LOCK(so); |
1922 | 0 | while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { |
1923 | | #if defined(_WIN32) |
1924 | | if (SleepConditionVariableCS(SOCK_COND(so), SOCK_MTX(so), INFINITE)) |
1925 | | error = 0; |
1926 | | else |
1927 | | error = -1; |
1928 | | #else |
1929 | 0 | error = pthread_cond_wait(SOCK_COND(so), SOCK_MTX(so)); |
1930 | 0 | #endif |
1931 | 0 | if (error) { |
1932 | | #if defined(__NetBSD__) |
1933 | | if (error == EINTR) { |
1934 | | #else |
1935 | 0 | if (error == EINTR || error == ERESTART) { |
1936 | 0 | #endif |
1937 | 0 | interrupted = 1; |
1938 | 0 | } |
1939 | 0 | break; |
1940 | 0 | } |
1941 | 0 | } |
1942 | 0 | if (error == 0) { |
1943 | 0 | error = so->so_error; |
1944 | 0 | so->so_error = 0; |
1945 | 0 | } |
1946 | 0 | SOCK_UNLOCK(so); |
1947 | | |
1948 | 0 | bad: |
1949 | 0 | if (!interrupted) { |
1950 | 0 | so->so_state &= ~SS_ISCONNECTING; |
1951 | 0 | } |
1952 | 0 | #if !defined(__NetBSD__) |
1953 | 0 | if (error == ERESTART) { |
1954 | 0 | error = EINTR; |
1955 | 0 | } |
1956 | 0 | #endif |
1957 | 13.0k | done1: |
1958 | 13.0k | return (error); |
1959 | 0 | } |
1960 | | |
1961 | | int usrsctp_connect(struct socket *so, struct sockaddr *name, int namelen) |
1962 | 13.0k | { |
1963 | 13.0k | struct sockaddr *sa = NULL; |
1964 | | |
1965 | 13.0k | errno = getsockaddr(&sa, (caddr_t)name, namelen); |
1966 | 13.0k | if (errno) |
1967 | 0 | return (-1); |
1968 | | |
1969 | 13.0k | errno = user_connect(so, sa); |
1970 | 13.0k | FREE(sa, M_SONAME); |
1971 | 13.0k | if (errno) { |
1972 | 13.0k | return (-1); |
1973 | 13.0k | } else { |
1974 | 0 | return (0); |
1975 | 0 | } |
1976 | 13.0k | } |
1977 | | |
1978 | | int userspace_connect(struct socket *so, struct sockaddr *name, int namelen) |
1979 | 0 | { |
1980 | 0 | return (usrsctp_connect(so, name, namelen)); |
1981 | 0 | } |
1982 | | |
1983 | 0 | #define SCTP_STACK_BUF_SIZE 2048 |
1984 | | |
1985 | | void |
1986 | 13.0k | usrsctp_close(struct socket *so) { |
1987 | 13.0k | if (so != NULL) { |
1988 | 13.0k | if (so->so_options & SCTP_SO_ACCEPTCONN) { |
1989 | 0 | struct socket *sp; |
1990 | |
|
1991 | 0 | ACCEPT_LOCK(); |
1992 | 0 | while ((sp = TAILQ_FIRST(&so->so_comp)) != NULL) { |
1993 | 0 | TAILQ_REMOVE(&so->so_comp, sp, so_list); |
1994 | 0 | so->so_qlen--; |
1995 | 0 | sp->so_qstate &= ~SQ_COMP; |
1996 | 0 | sp->so_head = NULL; |
1997 | 0 | ACCEPT_UNLOCK(); |
1998 | 0 | soabort(sp); |
1999 | 0 | ACCEPT_LOCK(); |
2000 | 0 | } |
2001 | 0 | ACCEPT_UNLOCK(); |
2002 | 0 | } |
2003 | 13.0k | ACCEPT_LOCK(); |
2004 | 13.0k | SOCK_LOCK(so); |
2005 | 13.0k | sorele(so); |
2006 | 13.0k | } |
2007 | 13.0k | } |
2008 | | |
2009 | | void |
2010 | | userspace_close(struct socket *so) |
2011 | 0 | { |
2012 | 0 | usrsctp_close(so); |
2013 | 0 | } |
2014 | | |
2015 | | int |
2016 | | usrsctp_shutdown(struct socket *so, int how) |
2017 | 0 | { |
2018 | 0 | if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) { |
2019 | 0 | errno = EINVAL; |
2020 | 0 | return (-1); |
2021 | 0 | } |
2022 | 0 | if (so == NULL) { |
2023 | 0 | errno = EBADF; |
2024 | 0 | return (-1); |
2025 | 0 | } |
2026 | 0 | sctp_flush(so, how); |
2027 | 0 | if (how != SHUT_WR) |
2028 | 0 | socantrcvmore(so); |
2029 | 0 | if (how != SHUT_RD) { |
2030 | 0 | errno = sctp_shutdown(so); |
2031 | 0 | if (errno) { |
2032 | 0 | return (-1); |
2033 | 0 | } else { |
2034 | 0 | return (0); |
2035 | 0 | } |
2036 | 0 | } |
2037 | 0 | return (0); |
2038 | 0 | } |
2039 | | |
2040 | | int |
2041 | | userspace_shutdown(struct socket *so, int how) |
2042 | 0 | { |
2043 | 0 | return (usrsctp_shutdown(so, how)); |
2044 | 0 | } |
2045 | | |
2046 | | int |
2047 | | usrsctp_finish(void) |
2048 | 0 | { |
2049 | 0 | if (SCTP_BASE_VAR(sctp_pcb_initialized) == 0) { |
2050 | 0 | return (0); |
2051 | 0 | } |
2052 | 0 | if (SCTP_INP_INFO_TRYLOCK()) { |
2053 | 0 | if (!LIST_EMPTY(&SCTP_BASE_INFO(listhead))) { |
2054 | 0 | SCTP_INP_INFO_RUNLOCK(); |
2055 | 0 | return (-1); |
2056 | 0 | } |
2057 | 0 | SCTP_INP_INFO_RUNLOCK(); |
2058 | 0 | } else { |
2059 | 0 | return (-1); |
2060 | 0 | } |
2061 | 0 | sctp_finish(); |
2062 | | #if defined(_WIN32) |
2063 | | DeleteConditionVariable(&accept_cond); |
2064 | | DeleteCriticalSection(&accept_mtx); |
2065 | | #if defined(INET) || defined(INET6) |
2066 | | WSACleanup(); |
2067 | | #endif |
2068 | | #else |
2069 | 0 | pthread_cond_destroy(&accept_cond); |
2070 | 0 | pthread_mutex_destroy(&accept_mtx); |
2071 | 0 | #endif |
2072 | 0 | return (0); |
2073 | 0 | } |
2074 | | |
2075 | | int |
2076 | | userspace_finish(void) |
2077 | 0 | { |
2078 | 0 | return (usrsctp_finish()); |
2079 | 0 | } |
2080 | | |
2081 | | /* needed from sctp_usrreq.c */ |
2082 | | int |
2083 | | sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, void *p); |
2084 | | |
2085 | | int |
2086 | | usrsctp_setsockopt(struct socket *so, int level, int option_name, |
2087 | | const void *option_value, socklen_t option_len) |
2088 | 275k | { |
2089 | 275k | if (so == NULL) { |
2090 | 0 | errno = EBADF; |
2091 | 0 | return (-1); |
2092 | 0 | } |
2093 | 275k | switch (level) { |
2094 | 13.0k | case SOL_SOCKET: |
2095 | 13.0k | { |
2096 | 13.0k | switch (option_name) { |
2097 | 0 | case SO_RCVBUF: |
2098 | 0 | if (option_len < (socklen_t)sizeof(int)) { |
2099 | 0 | errno = EINVAL; |
2100 | 0 | return (-1); |
2101 | 0 | } else { |
2102 | 0 | int *buf_size; |
2103 | |
|
2104 | 0 | buf_size = (int *)option_value; |
2105 | 0 | if (*buf_size < 1) { |
2106 | 0 | errno = EINVAL; |
2107 | 0 | return (-1); |
2108 | 0 | } |
2109 | 0 | sbreserve(&so->so_rcv, (u_long)*buf_size, so); |
2110 | 0 | return (0); |
2111 | 0 | } |
2112 | 0 | break; |
2113 | 0 | case SO_SNDBUF: |
2114 | 0 | if (option_len < (socklen_t)sizeof(int)) { |
2115 | 0 | errno = EINVAL; |
2116 | 0 | return (-1); |
2117 | 0 | } else { |
2118 | 0 | int *buf_size; |
2119 | |
|
2120 | 0 | buf_size = (int *)option_value; |
2121 | 0 | if (*buf_size < 1) { |
2122 | 0 | errno = EINVAL; |
2123 | 0 | return (-1); |
2124 | 0 | } |
2125 | 0 | sbreserve(&so->so_snd, (u_long)*buf_size, so); |
2126 | 0 | return (0); |
2127 | 0 | } |
2128 | 0 | break; |
2129 | 13.0k | case SO_LINGER: |
2130 | 13.0k | if (option_len < (socklen_t)sizeof(struct linger)) { |
2131 | 0 | errno = EINVAL; |
2132 | 0 | return (-1); |
2133 | 13.0k | } else { |
2134 | 13.0k | struct linger *l; |
2135 | | |
2136 | 13.0k | l = (struct linger *)option_value; |
2137 | 13.0k | so->so_linger = l->l_linger; |
2138 | 13.0k | if (l->l_onoff) { |
2139 | 13.0k | so->so_options |= SCTP_SO_LINGER; |
2140 | 13.0k | } else { |
2141 | 0 | so->so_options &= ~SCTP_SO_LINGER; |
2142 | 0 | } |
2143 | 13.0k | return (0); |
2144 | 13.0k | } |
2145 | 0 | default: |
2146 | 0 | errno = EINVAL; |
2147 | 0 | return (-1); |
2148 | 13.0k | } |
2149 | 13.0k | } |
2150 | 262k | case IPPROTO_SCTP: |
2151 | 262k | errno = sctp_setopt(so, option_name, (void *) option_value, (size_t)option_len, NULL); |
2152 | 262k | if (errno) { |
2153 | 0 | return (-1); |
2154 | 262k | } else { |
2155 | 262k | return (0); |
2156 | 262k | } |
2157 | 0 | default: |
2158 | 0 | errno = ENOPROTOOPT; |
2159 | 0 | return (-1); |
2160 | 275k | } |
2161 | 275k | } |
2162 | | |
2163 | | int |
2164 | | userspace_setsockopt(struct socket *so, int level, int option_name, |
2165 | | const void *option_value, socklen_t option_len) |
2166 | 0 | { |
2167 | 0 | return (usrsctp_setsockopt(so, level, option_name, option_value, option_len)); |
2168 | 0 | } |
2169 | | |
2170 | | /* needed from sctp_usrreq.c */ |
2171 | | int |
2172 | | sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize, |
2173 | | void *p); |
2174 | | |
2175 | | int |
2176 | | usrsctp_getsockopt(struct socket *so, int level, int option_name, |
2177 | | void *option_value, socklen_t *option_len) |
2178 | 0 | { |
2179 | 0 | if (so == NULL) { |
2180 | 0 | errno = EBADF; |
2181 | 0 | return (-1); |
2182 | 0 | } |
2183 | 0 | if (option_len == NULL) { |
2184 | 0 | errno = EFAULT; |
2185 | 0 | return (-1); |
2186 | 0 | } |
2187 | 0 | switch (level) { |
2188 | 0 | case SOL_SOCKET: |
2189 | 0 | switch (option_name) { |
2190 | 0 | case SO_RCVBUF: |
2191 | 0 | if (*option_len < (socklen_t)sizeof(int)) { |
2192 | 0 | errno = EINVAL; |
2193 | 0 | return (-1); |
2194 | 0 | } else { |
2195 | 0 | int *buf_size; |
2196 | |
|
2197 | 0 | buf_size = (int *)option_value; |
2198 | 0 | *buf_size = so->so_rcv.sb_hiwat; |
2199 | 0 | *option_len = (socklen_t)sizeof(int); |
2200 | 0 | return (0); |
2201 | 0 | } |
2202 | 0 | break; |
2203 | 0 | case SO_SNDBUF: |
2204 | 0 | if (*option_len < (socklen_t)sizeof(int)) { |
2205 | 0 | errno = EINVAL; |
2206 | 0 | return (-1); |
2207 | 0 | } else { |
2208 | 0 | int *buf_size; |
2209 | |
|
2210 | 0 | buf_size = (int *)option_value; |
2211 | 0 | *buf_size = so->so_snd.sb_hiwat; |
2212 | 0 | *option_len = (socklen_t)sizeof(int); |
2213 | 0 | return (0); |
2214 | 0 | } |
2215 | 0 | break; |
2216 | 0 | case SO_LINGER: |
2217 | 0 | if (*option_len < (socklen_t)sizeof(struct linger)) { |
2218 | 0 | errno = EINVAL; |
2219 | 0 | return (-1); |
2220 | 0 | } else { |
2221 | 0 | struct linger *l; |
2222 | |
|
2223 | 0 | l = (struct linger *)option_value; |
2224 | 0 | l->l_linger = so->so_linger; |
2225 | 0 | if (so->so_options & SCTP_SO_LINGER) { |
2226 | 0 | l->l_onoff = 1; |
2227 | 0 | } else { |
2228 | 0 | l->l_onoff = 0; |
2229 | 0 | } |
2230 | 0 | *option_len = (socklen_t)sizeof(struct linger); |
2231 | 0 | return (0); |
2232 | 0 | } |
2233 | 0 | break; |
2234 | 0 | case SO_ERROR: |
2235 | 0 | if (*option_len < (socklen_t)sizeof(int)) { |
2236 | 0 | errno = EINVAL; |
2237 | 0 | return (-1); |
2238 | 0 | } else { |
2239 | 0 | int *intval; |
2240 | |
|
2241 | 0 | intval = (int *)option_value; |
2242 | 0 | *intval = so->so_error; |
2243 | 0 | *option_len = (socklen_t)sizeof(int); |
2244 | 0 | return (0); |
2245 | 0 | } |
2246 | 0 | break; |
2247 | 0 | default: |
2248 | 0 | errno = EINVAL; |
2249 | 0 | return (-1); |
2250 | 0 | } |
2251 | 0 | case IPPROTO_SCTP: |
2252 | 0 | { |
2253 | 0 | size_t len; |
2254 | |
|
2255 | 0 | len = (size_t)*option_len; |
2256 | 0 | errno = sctp_getopt(so, option_name, option_value, &len, NULL); |
2257 | 0 | *option_len = (socklen_t)len; |
2258 | 0 | if (errno) { |
2259 | 0 | return (-1); |
2260 | 0 | } else { |
2261 | 0 | return (0); |
2262 | 0 | } |
2263 | 0 | } |
2264 | 0 | default: |
2265 | 0 | errno = ENOPROTOOPT; |
2266 | 0 | return (-1); |
2267 | 0 | } |
2268 | 0 | } |
2269 | | |
2270 | | int |
2271 | | userspace_getsockopt(struct socket *so, int level, int option_name, |
2272 | | void *option_value, socklen_t *option_len) |
2273 | 0 | { |
2274 | 0 | return (usrsctp_getsockopt(so, level, option_name, option_value, option_len)); |
2275 | 0 | } |
2276 | | |
2277 | | int |
2278 | | usrsctp_opt_info(struct socket *so, sctp_assoc_t id, int opt, void *arg, socklen_t *size) |
2279 | 0 | { |
2280 | 0 | if (arg == NULL) { |
2281 | 0 | errno = EINVAL; |
2282 | 0 | return (-1); |
2283 | 0 | } |
2284 | 0 | if ((id == SCTP_CURRENT_ASSOC) || |
2285 | 0 | (id == SCTP_ALL_ASSOC)) { |
2286 | 0 | errno = EINVAL; |
2287 | 0 | return (-1); |
2288 | 0 | } |
2289 | 0 | switch (opt) { |
2290 | 0 | case SCTP_RTOINFO: |
2291 | 0 | ((struct sctp_rtoinfo *)arg)->srto_assoc_id = id; |
2292 | 0 | break; |
2293 | 0 | case SCTP_ASSOCINFO: |
2294 | 0 | ((struct sctp_assocparams *)arg)->sasoc_assoc_id = id; |
2295 | 0 | break; |
2296 | 0 | case SCTP_DEFAULT_SEND_PARAM: |
2297 | 0 | ((struct sctp_assocparams *)arg)->sasoc_assoc_id = id; |
2298 | 0 | break; |
2299 | 0 | case SCTP_PRIMARY_ADDR: |
2300 | 0 | ((struct sctp_setprim *)arg)->ssp_assoc_id = id; |
2301 | 0 | break; |
2302 | 0 | case SCTP_PEER_ADDR_PARAMS: |
2303 | 0 | ((struct sctp_paddrparams *)arg)->spp_assoc_id = id; |
2304 | 0 | break; |
2305 | 0 | case SCTP_MAXSEG: |
2306 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2307 | 0 | break; |
2308 | 0 | case SCTP_AUTH_KEY: |
2309 | 0 | ((struct sctp_authkey *)arg)->sca_assoc_id = id; |
2310 | 0 | break; |
2311 | 0 | case SCTP_AUTH_ACTIVE_KEY: |
2312 | 0 | ((struct sctp_authkeyid *)arg)->scact_assoc_id = id; |
2313 | 0 | break; |
2314 | 0 | case SCTP_DELAYED_SACK: |
2315 | 0 | ((struct sctp_sack_info *)arg)->sack_assoc_id = id; |
2316 | 0 | break; |
2317 | 0 | case SCTP_CONTEXT: |
2318 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2319 | 0 | break; |
2320 | 0 | case SCTP_STATUS: |
2321 | 0 | ((struct sctp_status *)arg)->sstat_assoc_id = id; |
2322 | 0 | break; |
2323 | 0 | case SCTP_GET_PEER_ADDR_INFO: |
2324 | 0 | ((struct sctp_paddrinfo *)arg)->spinfo_assoc_id = id; |
2325 | 0 | break; |
2326 | 0 | case SCTP_PEER_AUTH_CHUNKS: |
2327 | 0 | ((struct sctp_authchunks *)arg)->gauth_assoc_id = id; |
2328 | 0 | break; |
2329 | 0 | case SCTP_LOCAL_AUTH_CHUNKS: |
2330 | 0 | ((struct sctp_authchunks *)arg)->gauth_assoc_id = id; |
2331 | 0 | break; |
2332 | 0 | case SCTP_TIMEOUTS: |
2333 | 0 | ((struct sctp_timeouts *)arg)->stimo_assoc_id = id; |
2334 | 0 | break; |
2335 | 0 | case SCTP_EVENT: |
2336 | 0 | ((struct sctp_event *)arg)->se_assoc_id = id; |
2337 | 0 | break; |
2338 | 0 | case SCTP_DEFAULT_SNDINFO: |
2339 | 0 | ((struct sctp_sndinfo *)arg)->snd_assoc_id = id; |
2340 | 0 | break; |
2341 | 0 | case SCTP_DEFAULT_PRINFO: |
2342 | 0 | ((struct sctp_default_prinfo *)arg)->pr_assoc_id = id; |
2343 | 0 | break; |
2344 | 0 | case SCTP_PEER_ADDR_THLDS: |
2345 | 0 | ((struct sctp_paddrthlds *)arg)->spt_assoc_id = id; |
2346 | 0 | break; |
2347 | 0 | case SCTP_REMOTE_UDP_ENCAPS_PORT: |
2348 | 0 | ((struct sctp_udpencaps *)arg)->sue_assoc_id = id; |
2349 | 0 | break; |
2350 | 0 | case SCTP_ECN_SUPPORTED: |
2351 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2352 | 0 | break; |
2353 | 0 | case SCTP_PR_SUPPORTED: |
2354 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2355 | 0 | break; |
2356 | 0 | case SCTP_AUTH_SUPPORTED: |
2357 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2358 | 0 | break; |
2359 | 0 | case SCTP_ASCONF_SUPPORTED: |
2360 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2361 | 0 | break; |
2362 | 0 | case SCTP_RECONFIG_SUPPORTED: |
2363 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2364 | 0 | break; |
2365 | 0 | case SCTP_NRSACK_SUPPORTED: |
2366 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2367 | 0 | break; |
2368 | 0 | case SCTP_PKTDROP_SUPPORTED: |
2369 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2370 | 0 | break; |
2371 | 0 | case SCTP_MAX_BURST: |
2372 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2373 | 0 | break; |
2374 | 0 | case SCTP_ENABLE_STREAM_RESET: |
2375 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2376 | 0 | break; |
2377 | 0 | case SCTP_PR_STREAM_STATUS: |
2378 | 0 | ((struct sctp_prstatus *)arg)->sprstat_assoc_id = id; |
2379 | 0 | break; |
2380 | 0 | case SCTP_PR_ASSOC_STATUS: |
2381 | 0 | ((struct sctp_prstatus *)arg)->sprstat_assoc_id = id; |
2382 | 0 | break; |
2383 | 0 | case SCTP_MAX_CWND: |
2384 | 0 | ((struct sctp_assoc_value *)arg)->assoc_id = id; |
2385 | 0 | break; |
2386 | 0 | default: |
2387 | 0 | break; |
2388 | 0 | } |
2389 | 0 | return (usrsctp_getsockopt(so, IPPROTO_SCTP, opt, arg, size)); |
2390 | 0 | } |
2391 | | |
2392 | | int |
2393 | | usrsctp_set_ulpinfo(struct socket *so, void *ulp_info) |
2394 | 0 | { |
2395 | 0 | return (register_ulp_info(so, ulp_info)); |
2396 | 0 | } |
2397 | | |
2398 | | |
2399 | | int |
2400 | | usrsctp_get_ulpinfo(struct socket *so, void **pulp_info) |
2401 | 0 | { |
2402 | 0 | return (retrieve_ulp_info(so, pulp_info)); |
2403 | 0 | } |
2404 | | |
2405 | | int |
2406 | | usrsctp_bindx(struct socket *so, struct sockaddr *addrs, int addrcnt, int flags) |
2407 | 0 | { |
2408 | 0 | struct sockaddr *sa; |
2409 | 0 | #ifdef INET |
2410 | 0 | struct sockaddr_in *sin; |
2411 | 0 | #endif |
2412 | 0 | #ifdef INET6 |
2413 | 0 | struct sockaddr_in6 *sin6; |
2414 | 0 | #endif |
2415 | 0 | int i; |
2416 | 0 | #if defined(INET) || defined(INET6) |
2417 | 0 | uint16_t sport; |
2418 | 0 | bool fix_port; |
2419 | 0 | #endif |
2420 | | |
2421 | | /* validate the flags */ |
2422 | 0 | if ((flags != SCTP_BINDX_ADD_ADDR) && |
2423 | 0 | (flags != SCTP_BINDX_REM_ADDR)) { |
2424 | 0 | errno = EFAULT; |
2425 | 0 | return (-1); |
2426 | 0 | } |
2427 | | /* validate the address count and list */ |
2428 | 0 | if ((addrcnt <= 0) || (addrs == NULL)) { |
2429 | 0 | errno = EINVAL; |
2430 | 0 | return (-1); |
2431 | 0 | } |
2432 | 0 | #if defined(INET) || defined(INET6) |
2433 | 0 | sport = 0; |
2434 | 0 | fix_port = false; |
2435 | 0 | #endif |
2436 | | /* First pre-screen the addresses */ |
2437 | 0 | sa = addrs; |
2438 | 0 | for (i = 0; i < addrcnt; i++) { |
2439 | 0 | switch (sa->sa_family) { |
2440 | 0 | #ifdef INET |
2441 | 0 | case AF_INET: |
2442 | | #ifdef HAVE_SA_LEN |
2443 | | if (sa->sa_len != sizeof(struct sockaddr_in)) { |
2444 | | errno = EINVAL; |
2445 | | return (-1); |
2446 | | } |
2447 | | #endif |
2448 | 0 | sin = (struct sockaddr_in *)sa; |
2449 | 0 | if (sin->sin_port) { |
2450 | | /* non-zero port, check or save */ |
2451 | 0 | if (sport) { |
2452 | | /* Check against our port */ |
2453 | 0 | if (sport != sin->sin_port) { |
2454 | 0 | errno = EINVAL; |
2455 | 0 | return (-1); |
2456 | 0 | } |
2457 | 0 | } else { |
2458 | | /* save off the port */ |
2459 | 0 | sport = sin->sin_port; |
2460 | 0 | fix_port = (i > 0); |
2461 | 0 | } |
2462 | 0 | } |
2463 | 0 | #ifndef HAVE_SA_LEN |
2464 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in)); |
2465 | 0 | #endif |
2466 | 0 | break; |
2467 | 0 | #endif |
2468 | 0 | #ifdef INET6 |
2469 | 0 | case AF_INET6: |
2470 | | #ifdef HAVE_SA_LEN |
2471 | | if (sa->sa_len != sizeof(struct sockaddr_in6)) { |
2472 | | errno = EINVAL; |
2473 | | return (-1); |
2474 | | } |
2475 | | #endif |
2476 | 0 | sin6 = (struct sockaddr_in6 *)sa; |
2477 | 0 | if (sin6->sin6_port) { |
2478 | | /* non-zero port, check or save */ |
2479 | 0 | if (sport) { |
2480 | | /* Check against our port */ |
2481 | 0 | if (sport != sin6->sin6_port) { |
2482 | 0 | errno = EINVAL; |
2483 | 0 | return (-1); |
2484 | 0 | } |
2485 | 0 | } else { |
2486 | | /* save off the port */ |
2487 | 0 | sport = sin6->sin6_port; |
2488 | 0 | fix_port = (i > 0); |
2489 | 0 | } |
2490 | 0 | } |
2491 | 0 | #ifndef HAVE_SA_LEN |
2492 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6)); |
2493 | 0 | #endif |
2494 | 0 | break; |
2495 | 0 | #endif |
2496 | 0 | default: |
2497 | | /* Invalid address family specified. */ |
2498 | 0 | errno = EAFNOSUPPORT; |
2499 | 0 | return (-1); |
2500 | 0 | } |
2501 | | #ifdef HAVE_SA_LEN |
2502 | | sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); |
2503 | | #endif |
2504 | 0 | } |
2505 | 0 | sa = addrs; |
2506 | 0 | for (i = 0; i < addrcnt; i++) { |
2507 | 0 | #ifndef HAVE_SA_LEN |
2508 | 0 | size_t sa_len; |
2509 | |
|
2510 | 0 | #endif |
2511 | | #ifdef HAVE_SA_LEN |
2512 | | #if defined(INET) || defined(INET6) |
2513 | | if (fix_port) { |
2514 | | switch (sa->sa_family) { |
2515 | | #ifdef INET |
2516 | | case AF_INET: |
2517 | | ((struct sockaddr_in *)sa)->sin_port = sport; |
2518 | | break; |
2519 | | #endif |
2520 | | #ifdef INET6 |
2521 | | case AF_INET6: |
2522 | | ((struct sockaddr_in6 *)sa)->sin6_port = sport; |
2523 | | break; |
2524 | | #endif |
2525 | | } |
2526 | | } |
2527 | | #endif |
2528 | | if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, sa->sa_len) != 0) { |
2529 | | return (-1); |
2530 | | } |
2531 | | sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); |
2532 | | #else |
2533 | 0 | switch (sa->sa_family) { |
2534 | 0 | #ifdef INET |
2535 | 0 | case AF_INET: |
2536 | 0 | sa_len = sizeof(struct sockaddr_in); |
2537 | 0 | break; |
2538 | 0 | #endif |
2539 | 0 | #ifdef INET6 |
2540 | 0 | case AF_INET6: |
2541 | 0 | sa_len = sizeof(struct sockaddr_in6); |
2542 | 0 | break; |
2543 | 0 | #endif |
2544 | 0 | default: |
2545 | 0 | sa_len = 0; |
2546 | 0 | break; |
2547 | 0 | } |
2548 | | /* |
2549 | | * Now, if there was a port mentioned, assure that the |
2550 | | * first address has that port to make sure it fails or |
2551 | | * succeeds correctly. |
2552 | | */ |
2553 | 0 | #if defined(INET) || defined(INET6) |
2554 | 0 | if (fix_port) { |
2555 | 0 | switch (sa->sa_family) { |
2556 | 0 | #ifdef INET |
2557 | 0 | case AF_INET: |
2558 | 0 | ((struct sockaddr_in *)sa)->sin_port = sport; |
2559 | 0 | break; |
2560 | 0 | #endif |
2561 | 0 | #ifdef INET6 |
2562 | 0 | case AF_INET6: |
2563 | 0 | ((struct sockaddr_in6 *)sa)->sin6_port = sport; |
2564 | 0 | break; |
2565 | 0 | #endif |
2566 | 0 | } |
2567 | 0 | } |
2568 | 0 | #endif |
2569 | 0 | if (usrsctp_setsockopt(so, IPPROTO_SCTP, flags, sa, (socklen_t)sa_len) != 0) { |
2570 | 0 | return (-1); |
2571 | 0 | } |
2572 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sa_len); |
2573 | 0 | #endif |
2574 | 0 | } |
2575 | 0 | return (0); |
2576 | 0 | } |
2577 | | |
2578 | | int |
2579 | | usrsctp_connectx(struct socket *so, |
2580 | | const struct sockaddr *addrs, int addrcnt, |
2581 | | sctp_assoc_t *id) |
2582 | 0 | { |
2583 | 0 | #if defined(INET) || defined(INET6) |
2584 | 0 | char buf[SCTP_STACK_BUF_SIZE]; |
2585 | 0 | int i, ret, cnt, *aa; |
2586 | 0 | char *cpto; |
2587 | 0 | const struct sockaddr *at; |
2588 | 0 | sctp_assoc_t *p_id; |
2589 | 0 | size_t len = sizeof(int); |
2590 | | |
2591 | | /* validate the address count and list */ |
2592 | 0 | if ((addrs == NULL) || (addrcnt <= 0)) { |
2593 | 0 | errno = EINVAL; |
2594 | 0 | return (-1); |
2595 | 0 | } |
2596 | 0 | at = addrs; |
2597 | 0 | cnt = 0; |
2598 | 0 | cpto = ((caddr_t)buf + sizeof(int)); |
2599 | | /* validate all the addresses and get the size */ |
2600 | 0 | for (i = 0; i < addrcnt; i++) { |
2601 | 0 | switch (at->sa_family) { |
2602 | 0 | #ifdef INET |
2603 | 0 | case AF_INET: |
2604 | | #ifdef HAVE_SA_LEN |
2605 | | if (at->sa_len != sizeof(struct sockaddr_in)) { |
2606 | | errno = EINVAL; |
2607 | | return (-1); |
2608 | | } |
2609 | | #endif |
2610 | 0 | len += sizeof(struct sockaddr_in); |
2611 | 0 | if (len > SCTP_STACK_BUF_SIZE) { |
2612 | 0 | errno = ENOMEM; |
2613 | 0 | return (-1); |
2614 | 0 | } |
2615 | 0 | memcpy(cpto, at, sizeof(struct sockaddr_in)); |
2616 | 0 | cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in)); |
2617 | 0 | at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in)); |
2618 | 0 | break; |
2619 | 0 | #endif |
2620 | 0 | #ifdef INET6 |
2621 | 0 | case AF_INET6: |
2622 | | #ifdef HAVE_SA_LEN |
2623 | | if (at->sa_len != sizeof(struct sockaddr_in6)) { |
2624 | | errno = EINVAL; |
2625 | | return (-1); |
2626 | | } |
2627 | | #endif |
2628 | 0 | #ifdef INET |
2629 | 0 | if (IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)at)->sin6_addr)) { |
2630 | 0 | len += sizeof(struct sockaddr_in); |
2631 | 0 | if (len > SCTP_STACK_BUF_SIZE) { |
2632 | 0 | errno = ENOMEM; |
2633 | 0 | return (-1); |
2634 | 0 | } |
2635 | 0 | in6_sin6_2_sin((struct sockaddr_in *)cpto, (struct sockaddr_in6 *)at); |
2636 | 0 | cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in)); |
2637 | 0 | } else { |
2638 | 0 | len += sizeof(struct sockaddr_in6); |
2639 | 0 | if (len > SCTP_STACK_BUF_SIZE) { |
2640 | 0 | errno = ENOMEM; |
2641 | 0 | return (-1); |
2642 | 0 | } |
2643 | 0 | memcpy(cpto, at, sizeof(struct sockaddr_in6)); |
2644 | 0 | cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6)); |
2645 | 0 | } |
2646 | | #else |
2647 | | len += sizeof(struct sockaddr_in6); |
2648 | | if (len > SCTP_STACK_BUF_SIZE) { |
2649 | | errno = ENOMEM; |
2650 | | return (-1); |
2651 | | } |
2652 | | memcpy(cpto, at, sizeof(struct sockaddr_in6)); |
2653 | | cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6)); |
2654 | | #endif |
2655 | 0 | at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in6)); |
2656 | 0 | break; |
2657 | 0 | #endif |
2658 | 0 | default: |
2659 | 0 | errno = EINVAL; |
2660 | 0 | return (-1); |
2661 | 0 | } |
2662 | 0 | cnt++; |
2663 | 0 | } |
2664 | 0 | aa = (int *)buf; |
2665 | 0 | *aa = cnt; |
2666 | 0 | ret = usrsctp_setsockopt(so, IPPROTO_SCTP, SCTP_CONNECT_X, (void *)buf, (socklen_t)len); |
2667 | 0 | if ((ret == 0) && id) { |
2668 | 0 | p_id = (sctp_assoc_t *)buf; |
2669 | 0 | *id = *p_id; |
2670 | 0 | } |
2671 | 0 | return (ret); |
2672 | | #else |
2673 | | errno = EINVAL; |
2674 | | return (-1); |
2675 | | #endif |
2676 | 0 | } |
2677 | | |
2678 | | int |
2679 | | usrsctp_getpaddrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs) |
2680 | 0 | { |
2681 | 0 | struct sctp_getaddresses *addrs; |
2682 | 0 | struct sockaddr *sa; |
2683 | 0 | caddr_t lim; |
2684 | 0 | socklen_t opt_len; |
2685 | 0 | uint32_t size_of_addresses; |
2686 | 0 | int cnt; |
2687 | |
|
2688 | 0 | if (raddrs == NULL) { |
2689 | 0 | errno = EFAULT; |
2690 | 0 | return (-1); |
2691 | 0 | } |
2692 | | /* When calling getsockopt(), the value contains the assoc_id. */ |
2693 | 0 | size_of_addresses = (uint32_t)id; |
2694 | 0 | opt_len = (socklen_t)sizeof(uint32_t); |
2695 | 0 | if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_REMOTE_ADDR_SIZE, &size_of_addresses, &opt_len) != 0) { |
2696 | 0 | if (errno == ENOENT) { |
2697 | 0 | return (0); |
2698 | 0 | } else { |
2699 | 0 | return (-1); |
2700 | 0 | } |
2701 | 0 | } |
2702 | 0 | opt_len = (socklen_t)((size_t)size_of_addresses + sizeof(struct sctp_getaddresses)); |
2703 | 0 | addrs = calloc(1, (size_t)opt_len); |
2704 | 0 | if (addrs == NULL) { |
2705 | 0 | errno = ENOMEM; |
2706 | 0 | return (-1); |
2707 | 0 | } |
2708 | 0 | addrs->sget_assoc_id = id; |
2709 | | /* Now lets get the array of addresses */ |
2710 | 0 | if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_PEER_ADDRESSES, addrs, &opt_len) != 0) { |
2711 | 0 | free(addrs); |
2712 | 0 | return (-1); |
2713 | 0 | } |
2714 | 0 | *raddrs = &addrs->addr[0].sa; |
2715 | 0 | cnt = 0; |
2716 | 0 | sa = &addrs->addr[0].sa; |
2717 | 0 | lim = (caddr_t)addrs + opt_len; |
2718 | | #ifdef HAVE_SA_LEN |
2719 | | while (((caddr_t)sa < lim) && (sa->sa_len > 0)) { |
2720 | | sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); |
2721 | | #else |
2722 | 0 | while ((caddr_t)sa < lim) { |
2723 | 0 | switch (sa->sa_family) { |
2724 | 0 | #ifdef INET |
2725 | 0 | case AF_INET: |
2726 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in)); |
2727 | 0 | break; |
2728 | 0 | #endif |
2729 | 0 | #ifdef INET6 |
2730 | 0 | case AF_INET6: |
2731 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6)); |
2732 | 0 | break; |
2733 | 0 | #endif |
2734 | 0 | case AF_CONN: |
2735 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_conn)); |
2736 | 0 | break; |
2737 | 0 | default: |
2738 | 0 | return (cnt); |
2739 | 0 | break; |
2740 | 0 | } |
2741 | 0 | #endif |
2742 | 0 | cnt++; |
2743 | 0 | } |
2744 | 0 | return (cnt); |
2745 | 0 | } |
2746 | | |
2747 | | void |
2748 | | usrsctp_freepaddrs(struct sockaddr *addrs) |
2749 | 0 | { |
2750 | | /* Take away the hidden association id */ |
2751 | 0 | void *fr_addr; |
2752 | |
|
2753 | 0 | fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr)); |
2754 | | /* Now free it */ |
2755 | 0 | free(fr_addr); |
2756 | 0 | } |
2757 | | |
2758 | | int |
2759 | | usrsctp_getladdrs(struct socket *so, sctp_assoc_t id, struct sockaddr **raddrs) |
2760 | 0 | { |
2761 | 0 | struct sctp_getaddresses *addrs; |
2762 | 0 | struct sockaddr *sa; |
2763 | 0 | caddr_t lim; |
2764 | 0 | socklen_t opt_len; |
2765 | 0 | uint32_t size_of_addresses; |
2766 | 0 | int cnt; |
2767 | |
|
2768 | 0 | if (raddrs == NULL) { |
2769 | 0 | errno = EFAULT; |
2770 | 0 | return (-1); |
2771 | 0 | } |
2772 | 0 | size_of_addresses = 0; |
2773 | 0 | opt_len = (socklen_t)sizeof(uint32_t); |
2774 | 0 | if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDR_SIZE, &size_of_addresses, &opt_len) != 0) { |
2775 | 0 | return (-1); |
2776 | 0 | } |
2777 | 0 | opt_len = (socklen_t)(size_of_addresses + sizeof(struct sctp_getaddresses)); |
2778 | 0 | addrs = calloc(1, (size_t)opt_len); |
2779 | 0 | if (addrs == NULL) { |
2780 | 0 | errno = ENOMEM; |
2781 | 0 | return (-1); |
2782 | 0 | } |
2783 | 0 | addrs->sget_assoc_id = id; |
2784 | | /* Now lets get the array of addresses */ |
2785 | 0 | if (usrsctp_getsockopt(so, IPPROTO_SCTP, SCTP_GET_LOCAL_ADDRESSES, addrs, &opt_len) != 0) { |
2786 | 0 | free(addrs); |
2787 | 0 | return (-1); |
2788 | 0 | } |
2789 | 0 | if (size_of_addresses == 0) { |
2790 | 0 | free(addrs); |
2791 | 0 | return (0); |
2792 | 0 | } |
2793 | 0 | *raddrs = &addrs->addr[0].sa; |
2794 | 0 | cnt = 0; |
2795 | 0 | sa = &addrs->addr[0].sa; |
2796 | 0 | lim = (caddr_t)addrs + opt_len; |
2797 | | #ifdef HAVE_SA_LEN |
2798 | | while (((caddr_t)sa < lim) && (sa->sa_len > 0)) { |
2799 | | sa = (struct sockaddr *)((caddr_t)sa + sa->sa_len); |
2800 | | #else |
2801 | 0 | while ((caddr_t)sa < lim) { |
2802 | 0 | switch (sa->sa_family) { |
2803 | 0 | #ifdef INET |
2804 | 0 | case AF_INET: |
2805 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in)); |
2806 | 0 | break; |
2807 | 0 | #endif |
2808 | 0 | #ifdef INET6 |
2809 | 0 | case AF_INET6: |
2810 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6)); |
2811 | 0 | break; |
2812 | 0 | #endif |
2813 | 0 | case AF_CONN: |
2814 | 0 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_conn)); |
2815 | 0 | break; |
2816 | 0 | default: |
2817 | 0 | return (cnt); |
2818 | 0 | break; |
2819 | 0 | } |
2820 | 0 | #endif |
2821 | 0 | cnt++; |
2822 | 0 | } |
2823 | 0 | return (cnt); |
2824 | 0 | } |
2825 | | |
2826 | | void |
2827 | | usrsctp_freeladdrs(struct sockaddr *addrs) |
2828 | 0 | { |
2829 | | /* Take away the hidden association id */ |
2830 | 0 | void *fr_addr; |
2831 | |
|
2832 | 0 | fr_addr = (void *)((caddr_t)addrs - offsetof(struct sctp_getaddresses, addr)); |
2833 | | /* Now free it */ |
2834 | 0 | free(fr_addr); |
2835 | 0 | } |
2836 | | |
2837 | | #ifdef INET |
2838 | | void |
2839 | | sctp_userspace_ip_output(int *result, struct mbuf *o_pak, |
2840 | | sctp_route_t *ro, void *inp, |
2841 | | uint32_t vrf_id) |
2842 | 0 | { |
2843 | 0 | struct mbuf *m; |
2844 | 0 | struct mbuf *m_orig; |
2845 | 0 | int iovcnt; |
2846 | 0 | int len; |
2847 | 0 | struct ip *ip; |
2848 | 0 | struct udphdr *udp; |
2849 | 0 | struct sockaddr_in dst; |
2850 | | #if defined(_WIN32) |
2851 | | WSAMSG win_msg_hdr; |
2852 | | DWORD win_sent_len; |
2853 | | WSABUF send_iovec[MAXLEN_MBUF_CHAIN]; |
2854 | | WSABUF winbuf; |
2855 | | #else |
2856 | 0 | struct iovec send_iovec[MAXLEN_MBUF_CHAIN]; |
2857 | 0 | struct msghdr msg_hdr; |
2858 | 0 | #endif |
2859 | 0 | int use_udp_tunneling; |
2860 | |
|
2861 | 0 | *result = 0; |
2862 | |
|
2863 | 0 | m = SCTP_HEADER_TO_CHAIN(o_pak); |
2864 | 0 | m_orig = m; |
2865 | |
|
2866 | 0 | len = sizeof(struct ip); |
2867 | 0 | if (SCTP_BUF_LEN(m) < len) { |
2868 | 0 | if ((m = m_pullup(m, len)) == 0) { |
2869 | 0 | SCTP_PRINTF("Can not get the IP header in the first mbuf.\n"); |
2870 | 0 | return; |
2871 | 0 | } |
2872 | 0 | } |
2873 | 0 | ip = mtod(m, struct ip *); |
2874 | 0 | use_udp_tunneling = (ip->ip_p == IPPROTO_UDP); |
2875 | |
|
2876 | 0 | if (use_udp_tunneling) { |
2877 | 0 | len = sizeof(struct ip) + sizeof(struct udphdr); |
2878 | 0 | if (SCTP_BUF_LEN(m) < len) { |
2879 | 0 | if ((m = m_pullup(m, len)) == 0) { |
2880 | 0 | SCTP_PRINTF("Can not get the UDP/IP header in the first mbuf.\n"); |
2881 | 0 | return; |
2882 | 0 | } |
2883 | 0 | ip = mtod(m, struct ip *); |
2884 | 0 | } |
2885 | 0 | udp = (struct udphdr *)(ip + 1); |
2886 | 0 | } else { |
2887 | 0 | udp = NULL; |
2888 | 0 | } |
2889 | | |
2890 | 0 | if (!use_udp_tunneling) { |
2891 | 0 | if (ip->ip_src.s_addr == INADDR_ANY) { |
2892 | | /* TODO get addr of outgoing interface */ |
2893 | 0 | SCTP_PRINTF("Why did the SCTP implementation did not choose a source address?\n"); |
2894 | 0 | } |
2895 | | /* TODO need to worry about ro->ro_dst as in ip_output? */ |
2896 | 0 | #if defined(__linux__) || defined(_WIN32) || (defined(__FreeBSD__) && (__FreeBSD_version >= 1100030)) |
2897 | | /* need to put certain fields into network order for Linux */ |
2898 | 0 | ip->ip_len = htons(ip->ip_len); |
2899 | 0 | #endif |
2900 | 0 | } |
2901 | |
|
2902 | 0 | memset((void *)&dst, 0, sizeof(struct sockaddr_in)); |
2903 | 0 | dst.sin_family = AF_INET; |
2904 | 0 | dst.sin_addr.s_addr = ip->ip_dst.s_addr; |
2905 | | #ifdef HAVE_SIN_LEN |
2906 | | dst.sin_len = sizeof(struct sockaddr_in); |
2907 | | #endif |
2908 | 0 | if (use_udp_tunneling) { |
2909 | 0 | dst.sin_port = udp->uh_dport; |
2910 | 0 | } else { |
2911 | 0 | dst.sin_port = 0; |
2912 | 0 | } |
2913 | | |
2914 | | /* tweak the mbuf chain */ |
2915 | 0 | if (use_udp_tunneling) { |
2916 | 0 | m_adj(m, sizeof(struct ip) + sizeof(struct udphdr)); |
2917 | 0 | } |
2918 | |
|
2919 | 0 | for (iovcnt = 0; m != NULL && iovcnt < MAXLEN_MBUF_CHAIN; m = m->m_next, iovcnt++) { |
2920 | 0 | #if !defined(_WIN32) |
2921 | 0 | send_iovec[iovcnt].iov_base = (caddr_t)m->m_data; |
2922 | 0 | send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m); |
2923 | | #else |
2924 | | send_iovec[iovcnt].buf = (caddr_t)m->m_data; |
2925 | | send_iovec[iovcnt].len = SCTP_BUF_LEN(m); |
2926 | | #endif |
2927 | 0 | } |
2928 | |
|
2929 | 0 | if (m != NULL) { |
2930 | 0 | SCTP_PRINTF("mbuf chain couldn't be copied completely\n"); |
2931 | 0 | goto free_mbuf; |
2932 | 0 | } |
2933 | | |
2934 | 0 | #if !defined(_WIN32) |
2935 | 0 | msg_hdr.msg_name = (struct sockaddr *) &dst; |
2936 | 0 | msg_hdr.msg_namelen = sizeof(struct sockaddr_in); |
2937 | 0 | msg_hdr.msg_iov = send_iovec; |
2938 | 0 | msg_hdr.msg_iovlen = iovcnt; |
2939 | 0 | msg_hdr.msg_control = NULL; |
2940 | 0 | msg_hdr.msg_controllen = 0; |
2941 | 0 | msg_hdr.msg_flags = 0; |
2942 | |
|
2943 | 0 | if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) { |
2944 | 0 | if (sendmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg_hdr, MSG_DONTWAIT) < 0) { |
2945 | 0 | *result = errno; |
2946 | 0 | } |
2947 | 0 | } |
2948 | 0 | if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) { |
2949 | 0 | if (sendmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg_hdr, MSG_DONTWAIT) < 0) { |
2950 | 0 | *result = errno; |
2951 | 0 | } |
2952 | 0 | } |
2953 | | #else |
2954 | | win_msg_hdr.name = (struct sockaddr *) &dst; |
2955 | | win_msg_hdr.namelen = sizeof(struct sockaddr_in); |
2956 | | win_msg_hdr.lpBuffers = (LPWSABUF)send_iovec; |
2957 | | win_msg_hdr.dwBufferCount = iovcnt; |
2958 | | winbuf.len = 0; |
2959 | | winbuf.buf = NULL; |
2960 | | win_msg_hdr.Control = winbuf; |
2961 | | win_msg_hdr.dwFlags = 0; |
2962 | | |
2963 | | if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp) != -1)) { |
2964 | | if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { |
2965 | | *result = WSAGetLastError(); |
2966 | | } |
2967 | | } |
2968 | | if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp) != -1)) { |
2969 | | if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { |
2970 | | *result = WSAGetLastError(); |
2971 | | } |
2972 | | } |
2973 | | #endif |
2974 | 0 | free_mbuf: |
2975 | 0 | sctp_m_freem(m_orig); |
2976 | 0 | } |
2977 | | #endif |
2978 | | |
2979 | | #if defined(INET6) |
2980 | | void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak, |
2981 | | struct route_in6 *ro, void *inp, |
2982 | | uint32_t vrf_id) |
2983 | 0 | { |
2984 | 0 | struct mbuf *m; |
2985 | 0 | struct mbuf *m_orig; |
2986 | 0 | int iovcnt; |
2987 | 0 | int len; |
2988 | 0 | struct ip6_hdr *ip6; |
2989 | 0 | struct udphdr *udp; |
2990 | 0 | struct sockaddr_in6 dst; |
2991 | | #if defined(_WIN32) |
2992 | | WSAMSG win_msg_hdr; |
2993 | | DWORD win_sent_len; |
2994 | | WSABUF send_iovec[MAXLEN_MBUF_CHAIN]; |
2995 | | WSABUF winbuf; |
2996 | | #else |
2997 | 0 | struct iovec send_iovec[MAXLEN_MBUF_CHAIN]; |
2998 | 0 | struct msghdr msg_hdr; |
2999 | 0 | #endif |
3000 | 0 | int use_udp_tunneling; |
3001 | |
|
3002 | 0 | *result = 0; |
3003 | |
|
3004 | 0 | m = SCTP_HEADER_TO_CHAIN(o_pak); |
3005 | 0 | m_orig = m; |
3006 | |
|
3007 | 0 | len = sizeof(struct ip6_hdr); |
3008 | |
|
3009 | 0 | if (SCTP_BUF_LEN(m) < len) { |
3010 | 0 | if ((m = m_pullup(m, len)) == 0) { |
3011 | 0 | SCTP_PRINTF("Can not get the IP header in the first mbuf.\n"); |
3012 | 0 | return; |
3013 | 0 | } |
3014 | 0 | } |
3015 | | |
3016 | 0 | ip6 = mtod(m, struct ip6_hdr *); |
3017 | 0 | use_udp_tunneling = (ip6->ip6_nxt == IPPROTO_UDP); |
3018 | |
|
3019 | 0 | if (use_udp_tunneling) { |
3020 | 0 | len = sizeof(struct ip6_hdr) + sizeof(struct udphdr); |
3021 | 0 | if (SCTP_BUF_LEN(m) < len) { |
3022 | 0 | if ((m = m_pullup(m, len)) == 0) { |
3023 | 0 | SCTP_PRINTF("Can not get the UDP/IP header in the first mbuf.\n"); |
3024 | 0 | return; |
3025 | 0 | } |
3026 | 0 | ip6 = mtod(m, struct ip6_hdr *); |
3027 | 0 | } |
3028 | 0 | udp = (struct udphdr *)(ip6 + 1); |
3029 | 0 | } else { |
3030 | 0 | udp = NULL; |
3031 | 0 | } |
3032 | | |
3033 | 0 | if (!use_udp_tunneling) { |
3034 | 0 | if (ip6->ip6_src.s6_addr == in6addr_any.s6_addr) { |
3035 | | /* TODO get addr of outgoing interface */ |
3036 | 0 | SCTP_PRINTF("Why did the SCTP implementation did not choose a source address?\n"); |
3037 | 0 | } |
3038 | | /* TODO need to worry about ro->ro_dst as in ip_output? */ |
3039 | 0 | } |
3040 | |
|
3041 | 0 | memset((void *)&dst, 0, sizeof(struct sockaddr_in6)); |
3042 | 0 | dst.sin6_family = AF_INET6; |
3043 | 0 | dst.sin6_addr = ip6->ip6_dst; |
3044 | | #ifdef HAVE_SIN6_LEN |
3045 | | dst.sin6_len = sizeof(struct sockaddr_in6); |
3046 | | #endif |
3047 | |
|
3048 | 0 | if (use_udp_tunneling) { |
3049 | 0 | dst.sin6_port = udp->uh_dport; |
3050 | 0 | } else { |
3051 | 0 | dst.sin6_port = 0; |
3052 | 0 | } |
3053 | | |
3054 | | /* tweak the mbuf chain */ |
3055 | 0 | if (use_udp_tunneling) { |
3056 | 0 | m_adj(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr)); |
3057 | 0 | } else { |
3058 | 0 | m_adj(m, sizeof(struct ip6_hdr)); |
3059 | 0 | } |
3060 | |
|
3061 | 0 | for (iovcnt = 0; m != NULL && iovcnt < MAXLEN_MBUF_CHAIN; m = m->m_next, iovcnt++) { |
3062 | 0 | #if !defined(_WIN32) |
3063 | 0 | send_iovec[iovcnt].iov_base = (caddr_t)m->m_data; |
3064 | 0 | send_iovec[iovcnt].iov_len = SCTP_BUF_LEN(m); |
3065 | | #else |
3066 | | send_iovec[iovcnt].buf = (caddr_t)m->m_data; |
3067 | | send_iovec[iovcnt].len = SCTP_BUF_LEN(m); |
3068 | | #endif |
3069 | 0 | } |
3070 | 0 | if (m != NULL) { |
3071 | 0 | SCTP_PRINTF("mbuf chain couldn't be copied completely\n"); |
3072 | 0 | goto free_mbuf; |
3073 | 0 | } |
3074 | | |
3075 | 0 | #if !defined(_WIN32) |
3076 | 0 | msg_hdr.msg_name = (struct sockaddr *) &dst; |
3077 | 0 | msg_hdr.msg_namelen = sizeof(struct sockaddr_in6); |
3078 | 0 | msg_hdr.msg_iov = send_iovec; |
3079 | 0 | msg_hdr.msg_iovlen = iovcnt; |
3080 | 0 | msg_hdr.msg_control = NULL; |
3081 | 0 | msg_hdr.msg_controllen = 0; |
3082 | 0 | msg_hdr.msg_flags = 0; |
3083 | |
|
3084 | 0 | if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) { |
3085 | 0 | if (sendmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg_hdr, MSG_DONTWAIT)< 0) { |
3086 | 0 | *result = errno; |
3087 | 0 | } |
3088 | 0 | } |
3089 | 0 | if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) { |
3090 | 0 | if (sendmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg_hdr, MSG_DONTWAIT) < 0) { |
3091 | 0 | *result = errno; |
3092 | 0 | } |
3093 | 0 | } |
3094 | | #else |
3095 | | win_msg_hdr.name = (struct sockaddr *) &dst; |
3096 | | win_msg_hdr.namelen = sizeof(struct sockaddr_in6); |
3097 | | win_msg_hdr.lpBuffers = (LPWSABUF)send_iovec; |
3098 | | win_msg_hdr.dwBufferCount = iovcnt; |
3099 | | winbuf.len = 0; |
3100 | | winbuf.buf = NULL; |
3101 | | win_msg_hdr.Control = winbuf; |
3102 | | win_msg_hdr.dwFlags = 0; |
3103 | | |
3104 | | if ((!use_udp_tunneling) && (SCTP_BASE_VAR(userspace_rawsctp6) != -1)) { |
3105 | | if (WSASendTo(SCTP_BASE_VAR(userspace_rawsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { |
3106 | | *result = WSAGetLastError(); |
3107 | | } |
3108 | | } |
3109 | | if ((use_udp_tunneling) && (SCTP_BASE_VAR(userspace_udpsctp6) != -1)) { |
3110 | | if (WSASendTo(SCTP_BASE_VAR(userspace_udpsctp6), (LPWSABUF) send_iovec, iovcnt, &win_sent_len, win_msg_hdr.dwFlags, win_msg_hdr.name, (int) win_msg_hdr.namelen, NULL, NULL) != 0) { |
3111 | | *result = WSAGetLastError(); |
3112 | | } |
3113 | | } |
3114 | | #endif |
3115 | 0 | free_mbuf: |
3116 | 0 | sctp_m_freem(m_orig); |
3117 | 0 | } |
3118 | | #endif |
3119 | | |
3120 | | void |
3121 | | usrsctp_register_address(void *addr) |
3122 | 3 | { |
3123 | 3 | struct sockaddr_conn sconn; |
3124 | | |
3125 | 3 | memset(&sconn, 0, sizeof(struct sockaddr_conn)); |
3126 | 3 | sconn.sconn_family = AF_CONN; |
3127 | | #ifdef HAVE_SCONN_LEN |
3128 | | sconn.sconn_len = sizeof(struct sockaddr_conn); |
3129 | | #endif |
3130 | 3 | sconn.sconn_port = 0; |
3131 | 3 | sconn.sconn_addr = addr; |
3132 | 3 | sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, |
3133 | 3 | NULL, |
3134 | 3 | 0xffffffff, |
3135 | 3 | 0, |
3136 | 3 | "conn", |
3137 | 3 | NULL, |
3138 | 3 | (struct sockaddr *)&sconn, |
3139 | 3 | 0, |
3140 | 3 | 0); |
3141 | 3 | } |
3142 | | |
3143 | | void |
3144 | | usrsctp_deregister_address(void *addr) |
3145 | 0 | { |
3146 | 0 | struct sockaddr_conn sconn; |
3147 | |
|
3148 | 0 | memset(&sconn, 0, sizeof(struct sockaddr_conn)); |
3149 | 0 | sconn.sconn_family = AF_CONN; |
3150 | | #ifdef HAVE_SCONN_LEN |
3151 | | sconn.sconn_len = sizeof(struct sockaddr_conn); |
3152 | | #endif |
3153 | 0 | sconn.sconn_port = 0; |
3154 | 0 | sconn.sconn_addr = addr; |
3155 | 0 | sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, |
3156 | 0 | (struct sockaddr *)&sconn, |
3157 | 0 | NULL, 0xffffffff); |
3158 | 0 | } |
3159 | | |
3160 | 0 | #define PREAMBLE_FORMAT "\n%c %02d:%02d:%02d.%06ld " |
3161 | 0 | #define PREAMBLE_LENGTH 19 |
3162 | 0 | #define HEADER "0000 " |
3163 | 0 | #define TRAILER "# SCTP_PACKET\n" |
3164 | | |
3165 | | char * |
3166 | | usrsctp_dumppacket(const void *buf, size_t len, int outbound) |
3167 | 0 | { |
3168 | 0 | size_t i, pos; |
3169 | 0 | char *dump_buf, *packet; |
3170 | 0 | struct tm t; |
3171 | | #ifdef _WIN32 |
3172 | | struct timeb tb; |
3173 | | #else |
3174 | 0 | struct timeval tv; |
3175 | 0 | time_t sec; |
3176 | 0 | #endif |
3177 | |
|
3178 | 0 | if ((len == 0) || (buf == NULL)) { |
3179 | 0 | return (NULL); |
3180 | 0 | } |
3181 | 0 | if ((dump_buf = malloc(PREAMBLE_LENGTH + strlen(HEADER) + 3 * len + strlen(TRAILER) + 1)) == NULL) { |
3182 | 0 | return (NULL); |
3183 | 0 | } |
3184 | 0 | pos = 0; |
3185 | | #ifdef _WIN32 |
3186 | | ftime(&tb); |
3187 | | localtime_s(&t, &tb.time); |
3188 | | #if defined(__MINGW32__) |
3189 | | if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, |
3190 | | outbound ? 'O' : 'I', |
3191 | | t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) { |
3192 | | free(dump_buf); |
3193 | | return (NULL); |
3194 | | } |
3195 | | #else |
3196 | | if (_snprintf_s(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_LENGTH, PREAMBLE_FORMAT, |
3197 | | outbound ? 'O' : 'I', |
3198 | | t.tm_hour, t.tm_min, t.tm_sec, (long)(1000 * tb.millitm)) < 0) { |
3199 | | free(dump_buf); |
3200 | | return (NULL); |
3201 | | } |
3202 | | #endif |
3203 | | #else |
3204 | 0 | gettimeofday(&tv, NULL); |
3205 | 0 | sec = (time_t)tv.tv_sec; |
3206 | 0 | localtime_r((const time_t *)&sec, &t); |
3207 | 0 | if (snprintf(dump_buf, PREAMBLE_LENGTH + 1, PREAMBLE_FORMAT, |
3208 | 0 | outbound ? 'O' : 'I', |
3209 | 0 | t.tm_hour, t.tm_min, t.tm_sec, (long)tv.tv_usec) < 0) { |
3210 | 0 | free(dump_buf); |
3211 | 0 | return (NULL); |
3212 | 0 | } |
3213 | 0 | #endif |
3214 | 0 | pos += PREAMBLE_LENGTH; |
3215 | | #if defined(_WIN32) && !defined(__MINGW32__) |
3216 | | strncpy_s(dump_buf + pos, strlen(HEADER) + 1, HEADER, strlen(HEADER)); |
3217 | | #else |
3218 | 0 | strcpy(dump_buf + pos, HEADER); |
3219 | 0 | #endif |
3220 | 0 | pos += strlen(HEADER); |
3221 | 0 | packet = (char *)buf; |
3222 | 0 | for (i = 0; i < len; i++) { |
3223 | 0 | uint8_t byte, low, high; |
3224 | |
|
3225 | 0 | byte = (uint8_t)packet[i]; |
3226 | 0 | high = byte / 16; |
3227 | 0 | low = byte % 16; |
3228 | 0 | dump_buf[pos++] = high < 10 ? '0' + high : 'a' + (high - 10); |
3229 | 0 | dump_buf[pos++] = low < 10 ? '0' + low : 'a' + (low - 10); |
3230 | 0 | dump_buf[pos++] = ' '; |
3231 | 0 | } |
3232 | | #if defined(_WIN32) && !defined(__MINGW32__) |
3233 | | strncpy_s(dump_buf + pos, strlen(TRAILER) + 1, TRAILER, strlen(TRAILER)); |
3234 | | #else |
3235 | 0 | strcpy(dump_buf + pos, TRAILER); |
3236 | 0 | #endif |
3237 | 0 | pos += strlen(TRAILER); |
3238 | 0 | dump_buf[pos++] = '\0'; |
3239 | 0 | return (dump_buf); |
3240 | 0 | } |
3241 | | |
3242 | | void |
3243 | | usrsctp_freedumpbuffer(char *buf) |
3244 | 0 | { |
3245 | 0 | free(buf); |
3246 | 0 | } |
3247 | | |
3248 | | void |
3249 | | usrsctp_enable_crc32c_offload(void) |
3250 | 3 | { |
3251 | 3 | SCTP_BASE_VAR(crc32c_offloaded) = 1; |
3252 | 3 | } |
3253 | | |
3254 | | void |
3255 | | usrsctp_disable_crc32c_offload(void) |
3256 | 0 | { |
3257 | 0 | SCTP_BASE_VAR(crc32c_offloaded) = 0; |
3258 | 0 | } |
3259 | | |
3260 | | /* Compute the CRC32C in network byte order */ |
3261 | | uint32_t |
3262 | | usrsctp_crc32c(void *buffer, size_t length) |
3263 | 0 | { |
3264 | 0 | uint32_t base = 0xffffffff; |
3265 | |
|
3266 | 0 | base = calculate_crc32c(0xffffffff, (unsigned char *)buffer, (unsigned int) length); |
3267 | 0 | base = sctp_finalize_crc32c(base); |
3268 | 0 | return (base); |
3269 | 0 | } |
3270 | | |
3271 | | void |
3272 | | usrsctp_conninput(void *addr, const void *buffer, size_t length, uint8_t ecn_bits) |
3273 | 7.66M | { |
3274 | 7.66M | struct sockaddr_conn src, dst; |
3275 | 7.66M | struct mbuf *m, *mm; |
3276 | 7.66M | struct sctphdr *sh; |
3277 | 7.66M | struct sctp_chunkhdr *ch; |
3278 | 7.66M | int remaining, offset; |
3279 | | |
3280 | 7.66M | SCTP_STAT_INCR(sctps_recvpackets); |
3281 | 7.66M | SCTP_STAT_INCR_COUNTER64(sctps_inpackets); |
3282 | 7.66M | memset(&src, 0, sizeof(struct sockaddr_conn)); |
3283 | 7.66M | src.sconn_family = AF_CONN; |
3284 | | #ifdef HAVE_SCONN_LEN |
3285 | | src.sconn_len = sizeof(struct sockaddr_conn); |
3286 | | #endif |
3287 | 7.66M | src.sconn_addr = addr; |
3288 | 7.66M | memset(&dst, 0, sizeof(struct sockaddr_conn)); |
3289 | 7.66M | dst.sconn_family = AF_CONN; |
3290 | | #ifdef HAVE_SCONN_LEN |
3291 | | dst.sconn_len = sizeof(struct sockaddr_conn); |
3292 | | #endif |
3293 | 7.66M | dst.sconn_addr = addr; |
3294 | 7.66M | if ((m = sctp_get_mbuf_for_msg((unsigned int)length, 1, M_NOWAIT, 0, MT_DATA)) == NULL) { |
3295 | 0 | return; |
3296 | 0 | } |
3297 | | /* Set the lengths fields of the mbuf chain. |
3298 | | * This is expected by m_copyback(). |
3299 | | */ |
3300 | 7.66M | remaining = (int)length; |
3301 | 15.3M | for (mm = m; mm != NULL; mm = mm->m_next) { |
3302 | 7.72M | mm->m_len = min((int)M_SIZE(mm), remaining); |
3303 | 7.72M | m->m_pkthdr.len += mm->m_len; |
3304 | 7.72M | remaining -= mm->m_len; |
3305 | 7.72M | } |
3306 | 7.66M | KASSERT(remaining == 0, ("usrsctp_conninput: %zu bytes left", remaining)); |
3307 | 7.66M | m_copyback(m, 0, (int)length, (caddr_t)buffer); |
3308 | 7.66M | offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr); |
3309 | 7.66M | if (SCTP_BUF_LEN(m) < offset) { |
3310 | 7.32M | if ((m = m_pullup(m, offset)) == NULL) { |
3311 | 7.32M | SCTP_STAT_INCR(sctps_hdrops); |
3312 | 7.32M | return; |
3313 | 7.32M | } |
3314 | 7.32M | } |
3315 | 338k | sh = mtod(m, struct sctphdr *); |
3316 | 338k | ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); |
3317 | 338k | offset -= sizeof(struct sctp_chunkhdr); |
3318 | 338k | src.sconn_port = sh->src_port; |
3319 | 338k | dst.sconn_port = sh->dest_port; |
3320 | 338k | sctp_common_input_processing(&m, 0, offset, (int)length, |
3321 | 338k | (struct sockaddr *)&src, |
3322 | 338k | (struct sockaddr *)&dst, |
3323 | 338k | sh, ch, |
3324 | 338k | SCTP_BASE_VAR(crc32c_offloaded) == 1 ? 0 : 1, |
3325 | 338k | ecn_bits, |
3326 | 338k | SCTP_DEFAULT_VRFID, 0); |
3327 | 338k | if (m) { |
3328 | 338k | sctp_m_freem(m); |
3329 | 338k | } |
3330 | 338k | return; |
3331 | 7.66M | } |
3332 | | |
3333 | | void usrsctp_handle_timers(uint32_t elapsed_milliseconds) |
3334 | 0 | { |
3335 | 0 | sctp_handle_tick(sctp_msecs_to_ticks(elapsed_milliseconds)); |
3336 | 0 | } |
3337 | | |
3338 | | int |
3339 | | usrsctp_get_events(struct socket *so) |
3340 | 574k | { |
3341 | 574k | int events = 0; |
3342 | | |
3343 | 574k | if (so == NULL) { |
3344 | 0 | errno = EBADF; |
3345 | 0 | return -1; |
3346 | 0 | } |
3347 | | |
3348 | 574k | SOCK_LOCK(so); |
3349 | 574k | if (soreadable(so)) { |
3350 | 546k | events |= SCTP_EVENT_READ; |
3351 | 546k | } |
3352 | 574k | if (sowriteable(so)) { |
3353 | 478k | events |= SCTP_EVENT_WRITE; |
3354 | 478k | } |
3355 | 574k | if (so->so_error) { |
3356 | 154k | events |= SCTP_EVENT_ERROR; |
3357 | 154k | } |
3358 | 574k | SOCK_UNLOCK(so); |
3359 | | |
3360 | 574k | return events; |
3361 | 574k | } |
3362 | | |
3363 | | int |
3364 | | usrsctp_set_upcall(struct socket *so, void (*upcall)(struct socket *, void *, int), void *arg) |
3365 | 13.0k | { |
3366 | 13.0k | if (so == NULL) { |
3367 | 0 | errno = EBADF; |
3368 | 0 | return (-1); |
3369 | 0 | } |
3370 | | |
3371 | 13.0k | SOCK_LOCK(so); |
3372 | 13.0k | so->so_upcall = upcall; |
3373 | 13.0k | so->so_upcallarg = arg; |
3374 | 13.0k | so->so_snd.sb_flags |= SB_UPCALL; |
3375 | 13.0k | so->so_rcv.sb_flags |= SB_UPCALL; |
3376 | 13.0k | SOCK_UNLOCK(so); |
3377 | | |
3378 | 13.0k | return (0); |
3379 | 13.0k | } |
3380 | | |
3381 | | #define USRSCTP_TUNABLE_SET_DEF(__field, __prefix) \ |
3382 | 0 | int usrsctp_tunable_set_ ## __field(uint32_t value) \ |
3383 | 0 | { \ |
3384 | 0 | if ((value < __prefix##_MIN) || \ |
3385 | 0 | (value > __prefix##_MAX)) { \ |
3386 | 0 | errno = EINVAL; \ |
3387 | 0 | return (-1); \ |
3388 | 0 | } else { \ |
3389 | 0 | SCTP_BASE_SYSCTL(__field) = value; \ |
3390 | 0 | return (0); \ |
3391 | 0 | } \ |
3392 | 0 | } Unexecuted instantiation: usrsctp_tunable_set_sctp_hashtblsize Unexecuted instantiation: usrsctp_tunable_set_sctp_pcbtblsize Unexecuted instantiation: usrsctp_tunable_set_sctp_chunkscale |
3393 | | |
3394 | | USRSCTP_TUNABLE_SET_DEF(sctp_hashtblsize, SCTPCTL_TCBHASHSIZE) |
3395 | | USRSCTP_TUNABLE_SET_DEF(sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE) |
3396 | | USRSCTP_TUNABLE_SET_DEF(sctp_chunkscale, SCTPCTL_CHUNKSCALE) |
3397 | | |
3398 | | #define USRSCTP_SYSCTL_SET_DEF(__field, __prefix) \ |
3399 | 4 | int usrsctp_sysctl_set_ ## __field(uint32_t value) \ |
3400 | 4 | { \ |
3401 | 4 | if ((value < __prefix##_MIN) || \ |
3402 | 4 | (value > __prefix##_MAX)) { \ |
3403 | 0 | errno = EINVAL; \ |
3404 | 0 | return (-1); \ |
3405 | 4 | } else { \ |
3406 | 4 | SCTP_BASE_SYSCTL(__field) = value; \ |
3407 | 4 | return (0); \ |
3408 | 4 | } \ |
3409 | 4 | } Unexecuted instantiation: usrsctp_sysctl_set_sctp_sendspace Unexecuted instantiation: usrsctp_sysctl_set_sctp_recvspace Unexecuted instantiation: usrsctp_sysctl_set_sctp_auto_asconf Unexecuted instantiation: usrsctp_sysctl_set_sctp_ecn_enable Unexecuted instantiation: usrsctp_sysctl_set_sctp_pr_enable Unexecuted instantiation: usrsctp_sysctl_set_sctp_auth_enable Unexecuted instantiation: usrsctp_sysctl_set_sctp_asconf_enable Unexecuted instantiation: usrsctp_sysctl_set_sctp_reconfig_enable usrsctp_sysctl_set_sctp_nrsack_enable Line | Count | Source | 3399 | 2 | int usrsctp_sysctl_set_ ## __field(uint32_t value) \ | 3400 | 2 | { \ | 3401 | 2 | if ((value < __prefix##_MIN) || \ | 3402 | 2 | (value > __prefix##_MAX)) { \ | 3403 | 0 | errno = EINVAL; \ | 3404 | 0 | return (-1); \ | 3405 | 2 | } else { \ | 3406 | 2 | SCTP_BASE_SYSCTL(__field) = value; \ | 3407 | 2 | return (0); \ | 3408 | 2 | } \ | 3409 | 2 | } |
usrsctp_sysctl_set_sctp_pktdrop_enable Line | Count | Source | 3399 | 2 | int usrsctp_sysctl_set_ ## __field(uint32_t value) \ | 3400 | 2 | { \ | 3401 | 2 | if ((value < __prefix##_MIN) || \ | 3402 | 2 | (value > __prefix##_MAX)) { \ | 3403 | 0 | errno = EINVAL; \ | 3404 | 0 | return (-1); \ | 3405 | 2 | } else { \ | 3406 | 2 | SCTP_BASE_SYSCTL(__field) = value; \ | 3407 | 2 | return (0); \ | 3408 | 2 | } \ | 3409 | 2 | } |
Unexecuted instantiation: usrsctp_sysctl_set_sctp_no_csum_on_loopback Unexecuted instantiation: usrsctp_sysctl_set_sctp_peer_chunk_oh Unexecuted instantiation: usrsctp_sysctl_set_sctp_max_burst_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_max_chunks_on_queue Unexecuted instantiation: usrsctp_sysctl_set_sctp_min_split_point Unexecuted instantiation: usrsctp_sysctl_set_sctp_delayed_sack_time_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_sack_freq_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_system_free_resc_limit Unexecuted instantiation: usrsctp_sysctl_set_sctp_asoc_free_resc_limit Unexecuted instantiation: usrsctp_sysctl_set_sctp_heartbeat_interval_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_pmtu_raise_time_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_shutdown_guard_time_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_secret_lifetime_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_rto_max_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_rto_min_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_rto_initial_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_init_rto_max_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_valid_cookie_life_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_init_rtx_max_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_assoc_rtx_max_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_path_rtx_max_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_add_more_threshold Unexecuted instantiation: usrsctp_sysctl_set_sctp_nr_incoming_streams_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_nr_outgoing_streams_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_cmt_on_off Unexecuted instantiation: usrsctp_sysctl_set_sctp_cmt_use_dac Unexecuted instantiation: usrsctp_sysctl_set_sctp_use_cwnd_based_maxburst Unexecuted instantiation: usrsctp_sysctl_set_sctp_nat_friendly Unexecuted instantiation: usrsctp_sysctl_set_sctp_L2_abc_variable Unexecuted instantiation: usrsctp_sysctl_set_sctp_mbuf_threshold_count Unexecuted instantiation: usrsctp_sysctl_set_sctp_do_drain Unexecuted instantiation: usrsctp_sysctl_set_sctp_hb_maxburst Unexecuted instantiation: usrsctp_sysctl_set_sctp_abort_if_one_2_one_hits_limit Unexecuted instantiation: usrsctp_sysctl_set_sctp_min_residual Unexecuted instantiation: usrsctp_sysctl_set_sctp_max_retran_chunk Unexecuted instantiation: usrsctp_sysctl_set_sctp_logging_level Unexecuted instantiation: usrsctp_sysctl_set_sctp_default_cc_module Unexecuted instantiation: usrsctp_sysctl_set_sctp_default_frag_interleave Unexecuted instantiation: usrsctp_sysctl_set_sctp_mobility_base Unexecuted instantiation: usrsctp_sysctl_set_sctp_mobility_fasthandoff Unexecuted instantiation: usrsctp_sysctl_set_sctp_inits_include_nat_friendly Unexecuted instantiation: usrsctp_sysctl_set_sctp_udp_tunneling_port Unexecuted instantiation: usrsctp_sysctl_set_sctp_enable_sack_immediately Unexecuted instantiation: usrsctp_sysctl_set_sctp_vtag_time_wait Unexecuted instantiation: usrsctp_sysctl_set_sctp_blackhole Unexecuted instantiation: usrsctp_sysctl_set_sctp_diag_info_code Unexecuted instantiation: usrsctp_sysctl_set_sctp_fr_max_burst_default Unexecuted instantiation: usrsctp_sysctl_set_sctp_path_pf_threshold Unexecuted instantiation: usrsctp_sysctl_set_sctp_default_ss_module Unexecuted instantiation: usrsctp_sysctl_set_sctp_rttvar_bw Unexecuted instantiation: usrsctp_sysctl_set_sctp_rttvar_rtt Unexecuted instantiation: usrsctp_sysctl_set_sctp_rttvar_eqret Unexecuted instantiation: usrsctp_sysctl_set_sctp_steady_step Unexecuted instantiation: usrsctp_sysctl_set_sctp_use_dccc_ecn Unexecuted instantiation: usrsctp_sysctl_set_sctp_buffer_splitting Unexecuted instantiation: usrsctp_sysctl_set_sctp_initial_cwnd Unexecuted instantiation: usrsctp_sysctl_set_sctp_ootb_with_zero_cksum |
3410 | | |
3411 | | #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__clang__) |
3412 | | #pragma GCC diagnostic push |
3413 | | #pragma GCC diagnostic ignored "-Wtype-limits" |
3414 | | #endif |
3415 | | USRSCTP_SYSCTL_SET_DEF(sctp_sendspace, SCTPCTL_MAXDGRAM) |
3416 | | USRSCTP_SYSCTL_SET_DEF(sctp_recvspace, SCTPCTL_RECVSPACE) |
3417 | | USRSCTP_SYSCTL_SET_DEF(sctp_auto_asconf, SCTPCTL_AUTOASCONF) |
3418 | | USRSCTP_SYSCTL_SET_DEF(sctp_ecn_enable, SCTPCTL_ECN_ENABLE) |
3419 | | USRSCTP_SYSCTL_SET_DEF(sctp_pr_enable, SCTPCTL_PR_ENABLE) |
3420 | | USRSCTP_SYSCTL_SET_DEF(sctp_auth_enable, SCTPCTL_AUTH_ENABLE) |
3421 | | USRSCTP_SYSCTL_SET_DEF(sctp_asconf_enable, SCTPCTL_ASCONF_ENABLE) |
3422 | | USRSCTP_SYSCTL_SET_DEF(sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE) |
3423 | | USRSCTP_SYSCTL_SET_DEF(sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE) |
3424 | | USRSCTP_SYSCTL_SET_DEF(sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE) |
3425 | | USRSCTP_SYSCTL_SET_DEF(sctp_no_csum_on_loopback, SCTPCTL_LOOPBACK_NOCSUM) |
3426 | | USRSCTP_SYSCTL_SET_DEF(sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH) |
3427 | | USRSCTP_SYSCTL_SET_DEF(sctp_max_burst_default, SCTPCTL_MAXBURST) |
3428 | | USRSCTP_SYSCTL_SET_DEF(sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS) |
3429 | | USRSCTP_SYSCTL_SET_DEF(sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT) |
3430 | | USRSCTP_SYSCTL_SET_DEF(sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME) |
3431 | | USRSCTP_SYSCTL_SET_DEF(sctp_sack_freq_default, SCTPCTL_SACK_FREQ) |
3432 | | USRSCTP_SYSCTL_SET_DEF(sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE) |
3433 | | USRSCTP_SYSCTL_SET_DEF(sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE) |
3434 | | USRSCTP_SYSCTL_SET_DEF(sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL) |
3435 | | USRSCTP_SYSCTL_SET_DEF(sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME) |
3436 | | USRSCTP_SYSCTL_SET_DEF(sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME) |
3437 | | USRSCTP_SYSCTL_SET_DEF(sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME) |
3438 | | USRSCTP_SYSCTL_SET_DEF(sctp_rto_max_default, SCTPCTL_RTO_MAX) |
3439 | | USRSCTP_SYSCTL_SET_DEF(sctp_rto_min_default, SCTPCTL_RTO_MIN) |
3440 | | USRSCTP_SYSCTL_SET_DEF(sctp_rto_initial_default, SCTPCTL_RTO_INITIAL) |
3441 | | USRSCTP_SYSCTL_SET_DEF(sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX) |
3442 | | USRSCTP_SYSCTL_SET_DEF(sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE) |
3443 | | USRSCTP_SYSCTL_SET_DEF(sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX) |
3444 | | USRSCTP_SYSCTL_SET_DEF(sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX) |
3445 | | USRSCTP_SYSCTL_SET_DEF(sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX) |
3446 | | USRSCTP_SYSCTL_SET_DEF(sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT) |
3447 | | USRSCTP_SYSCTL_SET_DEF(sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS) |
3448 | | USRSCTP_SYSCTL_SET_DEF(sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS) |
3449 | | USRSCTP_SYSCTL_SET_DEF(sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF) |
3450 | | USRSCTP_SYSCTL_SET_DEF(sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC) |
3451 | | USRSCTP_SYSCTL_SET_DEF(sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST) |
3452 | | USRSCTP_SYSCTL_SET_DEF(sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY) |
3453 | | USRSCTP_SYSCTL_SET_DEF(sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR) |
3454 | | USRSCTP_SYSCTL_SET_DEF(sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS) |
3455 | | USRSCTP_SYSCTL_SET_DEF(sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN) |
3456 | | USRSCTP_SYSCTL_SET_DEF(sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST) |
3457 | | USRSCTP_SYSCTL_SET_DEF(sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT) |
3458 | | USRSCTP_SYSCTL_SET_DEF(sctp_min_residual, SCTPCTL_MIN_RESIDUAL) |
3459 | | USRSCTP_SYSCTL_SET_DEF(sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK) |
3460 | | USRSCTP_SYSCTL_SET_DEF(sctp_logging_level, SCTPCTL_LOGGING_LEVEL) |
3461 | | USRSCTP_SYSCTL_SET_DEF(sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE) |
3462 | | USRSCTP_SYSCTL_SET_DEF(sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE) |
3463 | | USRSCTP_SYSCTL_SET_DEF(sctp_mobility_base, SCTPCTL_MOBILITY_BASE) |
3464 | | USRSCTP_SYSCTL_SET_DEF(sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF) |
3465 | | USRSCTP_SYSCTL_SET_DEF(sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS) |
3466 | | USRSCTP_SYSCTL_SET_DEF(sctp_udp_tunneling_port, SCTPCTL_UDP_TUNNELING_PORT) |
3467 | | USRSCTP_SYSCTL_SET_DEF(sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE) |
3468 | | USRSCTP_SYSCTL_SET_DEF(sctp_vtag_time_wait, SCTPCTL_TIME_WAIT) |
3469 | | USRSCTP_SYSCTL_SET_DEF(sctp_blackhole, SCTPCTL_BLACKHOLE) |
3470 | | USRSCTP_SYSCTL_SET_DEF(sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE) |
3471 | | USRSCTP_SYSCTL_SET_DEF(sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST) |
3472 | | USRSCTP_SYSCTL_SET_DEF(sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD) |
3473 | | USRSCTP_SYSCTL_SET_DEF(sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE) |
3474 | | USRSCTP_SYSCTL_SET_DEF(sctp_rttvar_bw, SCTPCTL_RTTVAR_BW) |
3475 | | USRSCTP_SYSCTL_SET_DEF(sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT) |
3476 | | USRSCTP_SYSCTL_SET_DEF(sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET) |
3477 | | USRSCTP_SYSCTL_SET_DEF(sctp_steady_step, SCTPCTL_RTTVAR_STEADYS) |
3478 | | USRSCTP_SYSCTL_SET_DEF(sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN) |
3479 | | USRSCTP_SYSCTL_SET_DEF(sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING) |
3480 | | USRSCTP_SYSCTL_SET_DEF(sctp_initial_cwnd, SCTPCTL_INITIAL_CWND) |
3481 | | USRSCTP_SYSCTL_SET_DEF(sctp_ootb_with_zero_cksum, SCTPCTL_OOTB_WITH_ZERO_CKSUM) |
3482 | | #ifdef SCTP_DEBUG |
3483 | | USRSCTP_SYSCTL_SET_DEF(sctp_debug_on, SCTPCTL_DEBUG) |
3484 | | #endif |
3485 | | #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__clang__) |
3486 | | #pragma GCC diagnostic pop |
3487 | | #endif |
3488 | | |
3489 | | #define USRSCTP_SYSCTL_GET_DEF(__field) \ |
3490 | 0 | uint32_t usrsctp_sysctl_get_ ## __field(void) { \ |
3491 | 0 | return SCTP_BASE_SYSCTL(__field); \ |
3492 | 0 | } Unexecuted instantiation: usrsctp_sysctl_get_sctp_sendspace Unexecuted instantiation: usrsctp_sysctl_get_sctp_recvspace Unexecuted instantiation: usrsctp_sysctl_get_sctp_auto_asconf Unexecuted instantiation: usrsctp_sysctl_get_sctp_multiple_asconfs Unexecuted instantiation: usrsctp_sysctl_get_sctp_ecn_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_pr_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_auth_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_asconf_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_reconfig_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_nrsack_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_pktdrop_enable Unexecuted instantiation: usrsctp_sysctl_get_sctp_no_csum_on_loopback Unexecuted instantiation: usrsctp_sysctl_get_sctp_peer_chunk_oh Unexecuted instantiation: usrsctp_sysctl_get_sctp_max_burst_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_max_chunks_on_queue Unexecuted instantiation: usrsctp_sysctl_get_sctp_hashtblsize Unexecuted instantiation: usrsctp_sysctl_get_sctp_pcbtblsize Unexecuted instantiation: usrsctp_sysctl_get_sctp_min_split_point Unexecuted instantiation: usrsctp_sysctl_get_sctp_chunkscale Unexecuted instantiation: usrsctp_sysctl_get_sctp_delayed_sack_time_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_sack_freq_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_system_free_resc_limit Unexecuted instantiation: usrsctp_sysctl_get_sctp_asoc_free_resc_limit Unexecuted instantiation: usrsctp_sysctl_get_sctp_heartbeat_interval_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_pmtu_raise_time_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_shutdown_guard_time_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_secret_lifetime_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_rto_max_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_rto_min_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_rto_initial_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_init_rto_max_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_valid_cookie_life_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_init_rtx_max_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_assoc_rtx_max_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_path_rtx_max_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_add_more_threshold Unexecuted instantiation: usrsctp_sysctl_get_sctp_nr_incoming_streams_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_nr_outgoing_streams_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_cmt_on_off Unexecuted instantiation: usrsctp_sysctl_get_sctp_cmt_use_dac Unexecuted instantiation: usrsctp_sysctl_get_sctp_use_cwnd_based_maxburst Unexecuted instantiation: usrsctp_sysctl_get_sctp_nat_friendly Unexecuted instantiation: usrsctp_sysctl_get_sctp_L2_abc_variable Unexecuted instantiation: usrsctp_sysctl_get_sctp_mbuf_threshold_count Unexecuted instantiation: usrsctp_sysctl_get_sctp_do_drain Unexecuted instantiation: usrsctp_sysctl_get_sctp_hb_maxburst Unexecuted instantiation: usrsctp_sysctl_get_sctp_abort_if_one_2_one_hits_limit Unexecuted instantiation: usrsctp_sysctl_get_sctp_min_residual Unexecuted instantiation: usrsctp_sysctl_get_sctp_max_retran_chunk Unexecuted instantiation: usrsctp_sysctl_get_sctp_logging_level Unexecuted instantiation: usrsctp_sysctl_get_sctp_default_cc_module Unexecuted instantiation: usrsctp_sysctl_get_sctp_default_frag_interleave Unexecuted instantiation: usrsctp_sysctl_get_sctp_mobility_base Unexecuted instantiation: usrsctp_sysctl_get_sctp_mobility_fasthandoff Unexecuted instantiation: usrsctp_sysctl_get_sctp_inits_include_nat_friendly Unexecuted instantiation: usrsctp_sysctl_get_sctp_udp_tunneling_port Unexecuted instantiation: usrsctp_sysctl_get_sctp_enable_sack_immediately Unexecuted instantiation: usrsctp_sysctl_get_sctp_vtag_time_wait Unexecuted instantiation: usrsctp_sysctl_get_sctp_blackhole Unexecuted instantiation: usrsctp_sysctl_get_sctp_diag_info_code Unexecuted instantiation: usrsctp_sysctl_get_sctp_fr_max_burst_default Unexecuted instantiation: usrsctp_sysctl_get_sctp_path_pf_threshold Unexecuted instantiation: usrsctp_sysctl_get_sctp_default_ss_module Unexecuted instantiation: usrsctp_sysctl_get_sctp_rttvar_bw Unexecuted instantiation: usrsctp_sysctl_get_sctp_rttvar_rtt Unexecuted instantiation: usrsctp_sysctl_get_sctp_rttvar_eqret Unexecuted instantiation: usrsctp_sysctl_get_sctp_steady_step Unexecuted instantiation: usrsctp_sysctl_get_sctp_use_dccc_ecn Unexecuted instantiation: usrsctp_sysctl_get_sctp_buffer_splitting Unexecuted instantiation: usrsctp_sysctl_get_sctp_initial_cwnd Unexecuted instantiation: usrsctp_sysctl_get_sctp_ootb_with_zero_cksum |
3493 | | |
3494 | | USRSCTP_SYSCTL_GET_DEF(sctp_sendspace) |
3495 | | USRSCTP_SYSCTL_GET_DEF(sctp_recvspace) |
3496 | | USRSCTP_SYSCTL_GET_DEF(sctp_auto_asconf) |
3497 | | USRSCTP_SYSCTL_GET_DEF(sctp_multiple_asconfs) |
3498 | | USRSCTP_SYSCTL_GET_DEF(sctp_ecn_enable) |
3499 | | USRSCTP_SYSCTL_GET_DEF(sctp_pr_enable) |
3500 | | USRSCTP_SYSCTL_GET_DEF(sctp_auth_enable) |
3501 | | USRSCTP_SYSCTL_GET_DEF(sctp_asconf_enable) |
3502 | | USRSCTP_SYSCTL_GET_DEF(sctp_reconfig_enable) |
3503 | | USRSCTP_SYSCTL_GET_DEF(sctp_nrsack_enable) |
3504 | | USRSCTP_SYSCTL_GET_DEF(sctp_pktdrop_enable) |
3505 | | USRSCTP_SYSCTL_GET_DEF(sctp_no_csum_on_loopback) |
3506 | | USRSCTP_SYSCTL_GET_DEF(sctp_peer_chunk_oh) |
3507 | | USRSCTP_SYSCTL_GET_DEF(sctp_max_burst_default) |
3508 | | USRSCTP_SYSCTL_GET_DEF(sctp_max_chunks_on_queue) |
3509 | | USRSCTP_SYSCTL_GET_DEF(sctp_hashtblsize) |
3510 | | USRSCTP_SYSCTL_GET_DEF(sctp_pcbtblsize) |
3511 | | USRSCTP_SYSCTL_GET_DEF(sctp_min_split_point) |
3512 | | USRSCTP_SYSCTL_GET_DEF(sctp_chunkscale) |
3513 | | USRSCTP_SYSCTL_GET_DEF(sctp_delayed_sack_time_default) |
3514 | | USRSCTP_SYSCTL_GET_DEF(sctp_sack_freq_default) |
3515 | | USRSCTP_SYSCTL_GET_DEF(sctp_system_free_resc_limit) |
3516 | | USRSCTP_SYSCTL_GET_DEF(sctp_asoc_free_resc_limit) |
3517 | | USRSCTP_SYSCTL_GET_DEF(sctp_heartbeat_interval_default) |
3518 | | USRSCTP_SYSCTL_GET_DEF(sctp_pmtu_raise_time_default) |
3519 | | USRSCTP_SYSCTL_GET_DEF(sctp_shutdown_guard_time_default) |
3520 | | USRSCTP_SYSCTL_GET_DEF(sctp_secret_lifetime_default) |
3521 | | USRSCTP_SYSCTL_GET_DEF(sctp_rto_max_default) |
3522 | | USRSCTP_SYSCTL_GET_DEF(sctp_rto_min_default) |
3523 | | USRSCTP_SYSCTL_GET_DEF(sctp_rto_initial_default) |
3524 | | USRSCTP_SYSCTL_GET_DEF(sctp_init_rto_max_default) |
3525 | | USRSCTP_SYSCTL_GET_DEF(sctp_valid_cookie_life_default) |
3526 | | USRSCTP_SYSCTL_GET_DEF(sctp_init_rtx_max_default) |
3527 | | USRSCTP_SYSCTL_GET_DEF(sctp_assoc_rtx_max_default) |
3528 | | USRSCTP_SYSCTL_GET_DEF(sctp_path_rtx_max_default) |
3529 | | USRSCTP_SYSCTL_GET_DEF(sctp_add_more_threshold) |
3530 | | USRSCTP_SYSCTL_GET_DEF(sctp_nr_incoming_streams_default) |
3531 | | USRSCTP_SYSCTL_GET_DEF(sctp_nr_outgoing_streams_default) |
3532 | | USRSCTP_SYSCTL_GET_DEF(sctp_cmt_on_off) |
3533 | | USRSCTP_SYSCTL_GET_DEF(sctp_cmt_use_dac) |
3534 | | USRSCTP_SYSCTL_GET_DEF(sctp_use_cwnd_based_maxburst) |
3535 | | USRSCTP_SYSCTL_GET_DEF(sctp_nat_friendly) |
3536 | | USRSCTP_SYSCTL_GET_DEF(sctp_L2_abc_variable) |
3537 | | USRSCTP_SYSCTL_GET_DEF(sctp_mbuf_threshold_count) |
3538 | | USRSCTP_SYSCTL_GET_DEF(sctp_do_drain) |
3539 | | USRSCTP_SYSCTL_GET_DEF(sctp_hb_maxburst) |
3540 | | USRSCTP_SYSCTL_GET_DEF(sctp_abort_if_one_2_one_hits_limit) |
3541 | | USRSCTP_SYSCTL_GET_DEF(sctp_min_residual) |
3542 | | USRSCTP_SYSCTL_GET_DEF(sctp_max_retran_chunk) |
3543 | | USRSCTP_SYSCTL_GET_DEF(sctp_logging_level) |
3544 | | USRSCTP_SYSCTL_GET_DEF(sctp_default_cc_module) |
3545 | | USRSCTP_SYSCTL_GET_DEF(sctp_default_frag_interleave) |
3546 | | USRSCTP_SYSCTL_GET_DEF(sctp_mobility_base) |
3547 | | USRSCTP_SYSCTL_GET_DEF(sctp_mobility_fasthandoff) |
3548 | | USRSCTP_SYSCTL_GET_DEF(sctp_inits_include_nat_friendly) |
3549 | | USRSCTP_SYSCTL_GET_DEF(sctp_udp_tunneling_port) |
3550 | | USRSCTP_SYSCTL_GET_DEF(sctp_enable_sack_immediately) |
3551 | | USRSCTP_SYSCTL_GET_DEF(sctp_vtag_time_wait) |
3552 | | USRSCTP_SYSCTL_GET_DEF(sctp_blackhole) |
3553 | | USRSCTP_SYSCTL_GET_DEF(sctp_diag_info_code) |
3554 | | USRSCTP_SYSCTL_GET_DEF(sctp_fr_max_burst_default) |
3555 | | USRSCTP_SYSCTL_GET_DEF(sctp_path_pf_threshold) |
3556 | | USRSCTP_SYSCTL_GET_DEF(sctp_default_ss_module) |
3557 | | USRSCTP_SYSCTL_GET_DEF(sctp_rttvar_bw) |
3558 | | USRSCTP_SYSCTL_GET_DEF(sctp_rttvar_rtt) |
3559 | | USRSCTP_SYSCTL_GET_DEF(sctp_rttvar_eqret) |
3560 | | USRSCTP_SYSCTL_GET_DEF(sctp_steady_step) |
3561 | | USRSCTP_SYSCTL_GET_DEF(sctp_use_dccc_ecn) |
3562 | | USRSCTP_SYSCTL_GET_DEF(sctp_buffer_splitting) |
3563 | | USRSCTP_SYSCTL_GET_DEF(sctp_initial_cwnd) |
3564 | | USRSCTP_SYSCTL_GET_DEF(sctp_ootb_with_zero_cksum) |
3565 | | #ifdef SCTP_DEBUG |
3566 | | USRSCTP_SYSCTL_GET_DEF(sctp_debug_on) |
3567 | | #endif |
3568 | | |
3569 | | void usrsctp_get_stat(struct sctpstat *stat) |
3570 | 0 | { |
3571 | 0 | *stat = SCTP_BASE_STATS; |
3572 | 0 | } |