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