| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * a) Redistributions of source code must retain the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer. |
| 13 | * |
| 14 | * b) Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the distribution. |
| 17 | * |
| 18 | * c) Neither the name of Cisco Systems, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 24 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 32 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 |
| 35 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 36 | #include <sys/cdefs.h> |
| 37 | __FBSDID("$FreeBSD$"); |
| 38 | #endif |
| 39 |
| 40 | #include <netinet/sctp_os.h> |
| 41 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 42 | #include <sys/proc.h> |
| 43 | #endif |
| 44 | #include <netinet/sctp_pcb.h> |
| 45 | #include <netinet/sctp_header.h> |
| 46 | #include <netinet/sctp_var.h> |
| 47 | #ifdef INET6 |
| 48 | #include <netinet6/sctp6_var.h> |
| 49 | #endif |
| 50 | #include <netinet/sctp_sysctl.h> |
| 51 | #include <netinet/sctp_output.h> |
| 52 | #include <netinet/sctp_uio.h> |
| 53 | #include <netinet/sctp_asconf.h> |
| 54 | #include <netinet/sctputil.h> |
| 55 | #include <netinet/sctp_indata.h> |
| 56 | #include <netinet/sctp_timer.h> |
| 57 | #include <netinet/sctp_auth.h> |
| 58 | #include <netinet/sctp_bsd_addr.h> |
| 59 | #if defined(__Userspace__) |
| 60 | #include <netinet/sctp_callout.h> |
| 61 | #else |
| 62 | #include <netinet/udp.h> |
| 63 | #endif |
| 64 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 65 | #include <sys/eventhandler.h> |
| 66 | #endif |
| 67 | #if defined(HAVE_SCTP_PEELOFF_SOCKOPT) |
| 68 | #include <netinet/sctp_peeloff.h> |
| 69 | #endif /* HAVE_SCTP_PEELOFF_SOCKOPT */ |
| 70 |
| 71 | extern const struct sctp_cc_functions sctp_cc_functions[]; |
| 72 | extern const struct sctp_ss_functions sctp_ss_functions[]; |
| 73 |
| 74 | void |
| 75 | #if defined(__Userspace__) |
| 76 | sctp_init(uint16_t port, |
| 77 | int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df), |
| 78 | void (*debug_printf)(const char *format, ...), int start_threads) |
| 79 | #elif defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) &&!defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)) |
| 80 | sctp_init(struct protosw *pp SCTP_UNUSED, struct domain *dp SCTP_UNUSED) |
| 81 | #else |
| 82 | sctp_init(void) |
| 83 | #endif |
| 84 | { |
| 85 | #if !defined(__Userspace__) |
| 86 | u_long sb_max_adj; |
| 87 |
| 88 | #else |
| 89 | init_random(); |
| 90 | #endif |
| 91 | /* Initialize and modify the sysctled variables */ |
| 92 | sctp_init_sysctls(); |
| 93 | #if defined(__Userspace__) |
| 94 | SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = port; |
| 95 | #else |
| 96 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 97 | sb_max_adj = (u_long)((u_quad_t) (sb_max) * MCLBYTES / (MSIZE + MCLBYTES)); |
| 98 | SCTP_BASE_SYSCTL(sctp_sendspace) = sb_max_adj; |
| 99 | #else |
| 100 | if ((nmbclusters / 8) > SCTP_ASOC_MAX_CHUNKS_ON_QUEUE) |
| 101 | SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = (nmbclusters / 8); |
| 102 | /* |
| 103 | * Allow a user to take no more than 1/2 the number of clusters or |
| 104 | * the SB_MAX, whichever is smaller, for the send window. |
| 105 | */ |
| 106 | sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES)); |
| 107 | SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj, |
| 108 | (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT)); |
| 109 | #endif |
| 110 | /* |
| 111 | * Now for the recv window, should we take the same amount? or |
| 112 | * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For |
| 113 | * now I will just copy. |
| 114 | */ |
| 115 | SCTP_BASE_SYSCTL(sctp_recvspace) = SCTP_BASE_SYSCTL(sctp_sendspace); |
| 116 | #endif |
| 117 | SCTP_BASE_VAR(first_time) = 0; |
| 118 | SCTP_BASE_VAR(sctp_pcb_initialized) = 0; |
| 119 | #if defined(__Userspace__) |
| 120 | #if !defined(_WIN32) |
| 121 | #if defined(INET) || defined(INET6) |
| 122 | SCTP_BASE_VAR(userspace_route) = -1; |
| 123 | #endif |
| 124 | #endif |
| 125 | #ifdef INET |
| 126 | SCTP_BASE_VAR(userspace_rawsctp) = -1; |
| 127 | SCTP_BASE_VAR(userspace_udpsctp) = -1; |
| 128 | #endif |
| 129 | #ifdef INET6 |
| 130 | SCTP_BASE_VAR(userspace_rawsctp6) = -1; |
| 131 | SCTP_BASE_VAR(userspace_udpsctp6) = -1; |
| 132 | #endif |
| 133 | SCTP_BASE_VAR(timer_thread_should_exit) = 0; |
| 134 | SCTP_BASE_VAR(conn_output) = conn_output; |
| 135 | SCTP_BASE_VAR(debug_printf) = debug_printf; |
| 136 | SCTP_BASE_VAR(crc32c_offloaded) = 0; |
| 137 | SCTP_BASE_VAR(iterator_thread_started) = 0; |
| 138 | SCTP_BASE_VAR(timer_thread_started) = 0; |
| 139 | #endif |
| 140 | #if defined(__Userspace__) |
| 141 | sctp_pcb_init(start_threads); |
| 142 | if (start_threads) { |
| 143 | sctp_start_timer_thread(); |
| 144 | } |
| 145 | #else |
| 146 | sctp_pcb_init(); |
| 147 | #endif |
| 148 | #if defined(SCTP_PACKET_LOGGING) |
| 149 | SCTP_BASE_VAR(packet_log_writers) = 0; |
| 150 | SCTP_BASE_VAR(packet_log_end) = 0; |
| 151 | memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE); |
| 152 | #endif |
| 153 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 154 | SCTP_BASE_VAR(sctp_main_timer_ticks) = 0; |
| 155 | sctp_start_main_timer(); |
| 156 | timeout(sctp_delayed_startup, NULL, 1); |
| 157 | #endif |
| 158 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 159 | SCTP_BASE_VAR(eh_tag) = EVENTHANDLER_REGISTER(rt_addrmsg, |
| 160 | sctp_addr_change_event_handler, NULL, EVENTHANDLER_PRI_FIRST); |
| 161 | #endif |
| 162 | } |
| 163 |
| 164 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 165 | #ifdef VIMAGE |
| 166 | static void |
| 167 | sctp_finish(void *unused __unused) |
| 168 | { |
| 169 | EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag)); |
| 170 | sctp_pcb_finish(); |
| 171 | } |
| 172 | VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL); |
| 173 | #endif |
| 174 | #else |
| 175 | void |
| 176 | sctp_finish(void) |
| 177 | { |
| 178 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 179 | untimeout(sctp_delayed_startup, NULL); |
| 180 | sctp_over_udp_stop(); |
| 181 | sctp_address_monitor_stop(); |
| 182 | sctp_stop_main_timer(); |
| 183 | #endif |
| 184 | #if defined(__Userspace__) |
| 185 | #if defined(INET) || defined(INET6) |
| 186 | recv_thread_destroy(); |
| 187 | #endif |
| 188 | sctp_stop_timer_thread(); |
| 189 | #endif |
| 190 | sctp_pcb_finish(); |
| 191 | #if defined(_WIN32) && !defined(__Userspace__) |
| 192 | sctp_finish_sysctls(); |
| 193 | #endif |
| 194 | #if defined(__Userspace__) |
| 195 | finish_random(); |
| 196 | #endif |
| 197 | } |
| 198 | #endif |
| 199 |
| 200 | void |
| 201 | sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz) |
| 202 | { |
| 203 | struct sctp_tmit_chunk *chk; |
| 204 | uint16_t overhead; |
| 205 |
| 206 | /* Adjust that too */ |
| 207 | stcb->asoc.smallest_mtu = nxtsz; |
| 208 | /* now off to subtract IP_DF flag if needed */ |
| 209 | overhead = IP_HDR_SIZE + sizeof(struct sctphdr); |
| 210 | if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { |
| 211 | overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); |
| 212 | } |
| 213 | TAILQ_FOREACH(chk, &stcb->asoc.send_queue, sctp_next) { |
| 214 | if ((chk->send_size + overhead) > nxtsz) { |
| 215 | chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; |
| 216 | } |
| 217 | } |
| 218 | TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { |
| 219 | if ((chk->send_size + overhead) > nxtsz) { |
| 220 | /* |
| 221 | * For this guy we also mark for immediate resend |
| 222 | * since we sent to big of chunk |
| 223 | */ |
| 224 | chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; |
| 225 | if (chk->sent < SCTP_DATAGRAM_RESEND) { |
| 226 | sctp_flight_size_decrease(chk); |
| 227 | sctp_total_flight_decrease(stcb, chk); |
| 228 | chk->sent = SCTP_DATAGRAM_RESEND; |
| 229 | sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); |
| 230 | chk->rec.data.doing_fast_retransmit = 0; |
| 231 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { |
| 232 | sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU, |
| 233 | chk->whoTo->flight_size, |
| 234 | chk->book_size, |
| 235 | (uint32_t)(uintptr_t)chk->whoTo, |
| 236 | chk->rec.data.tsn); |
| 237 | } |
| 238 | /* Clear any time so NO RTT is being done */ |
| 239 | if (chk->do_rtt == 1) { |
| 240 | chk->do_rtt = 0; |
| 241 | chk->whoTo->rto_needed = 1; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 |
| 248 | #ifdef INET |
| 249 | #if !defined(__Userspace__) |
| 250 | void |
| 251 | sctp_notify(struct sctp_inpcb *inp, |
| 252 | struct sctp_tcb *stcb, |
| 253 | struct sctp_nets *net, |
| 254 | uint8_t icmp_type, |
| 255 | uint8_t icmp_code, |
| 256 | uint16_t ip_len, |
| 257 | uint32_t next_mtu) |
| 258 | { |
| 259 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 260 | struct socket *so; |
| 261 | #endif |
| 262 | int timer_stopped; |
| 263 |
| 264 | if (icmp_type != ICMP_UNREACH) { |
| 265 | /* We only care about unreachable */ |
| 266 | SCTP_TCB_UNLOCK(stcb); |
| 267 | return; |
| 268 | } |
| 269 | if ((icmp_code == ICMP_UNREACH_NET) || |
| 270 | (icmp_code == ICMP_UNREACH_HOST) || |
| 271 | (icmp_code == ICMP_UNREACH_NET_UNKNOWN) || |
| 272 | (icmp_code == ICMP_UNREACH_HOST_UNKNOWN) || |
| 273 | (icmp_code == ICMP_UNREACH_ISOLATED) || |
| 274 | (icmp_code == ICMP_UNREACH_NET_PROHIB) || |
| 275 | (icmp_code == ICMP_UNREACH_HOST_PROHIB) || |
| 276 | #if defined(__NetBSD__) |
| 277 | (icmp_code == ICMP_UNREACH_ADMIN_PROHIBIT)) { |
| 278 | #else |
| 279 | (icmp_code == ICMP_UNREACH_FILTER_PROHIB)) { |
| 280 | #endif |
| 281 | /* Mark the net unreachable. */ |
| 282 | if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 283 | /* OK, that destination is NOT reachable. */ |
| 284 | net->dest_state &= ~SCTP_ADDR_REACHABLE; |
| 285 | net->dest_state &= ~SCTP_ADDR_PF; |
| 286 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, |
| 287 | stcb, 0, |
| 288 | (void *)net, SCTP_SO_NOT_LOCKED); |
| 289 | } |
| 290 | SCTP_TCB_UNLOCK(stcb); |
| 291 | } else if ((icmp_code == ICMP_UNREACH_PROTOCOL) || |
| 292 | (icmp_code == ICMP_UNREACH_PORT)) { |
| 293 | /* Treat it like an ABORT. */ |
| 294 | sctp_abort_notification(stcb, true, false, 0, NULL, SCTP_SO_NOT_LOCKED); |
| 295 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 296 | so = SCTP_INP_SO(inp); |
| 297 | atomic_add_int(&stcb->asoc.refcnt, 1); |
| 298 | SCTP_TCB_UNLOCK(stcb); |
| 299 | SCTP_SOCKET_LOCK(so, 1); |
| 300 | SCTP_TCB_LOCK(stcb); |
| 301 | atomic_subtract_int(&stcb->asoc.refcnt, 1); |
| 302 | #endif |
| 303 | (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, |
| 304 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_2); |
| 305 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 306 | SCTP_SOCKET_UNLOCK(so, 1); |
| 307 | /* SCTP_TCB_UNLOCK(stcb); MT: I think this is not needed.*/ |
| 308 | #endif |
| 309 | /* no need to unlock here, since the TCB is gone */ |
| 310 | } else if (icmp_code == ICMP_UNREACH_NEEDFRAG) { |
| 311 | if (net->dest_state & SCTP_ADDR_NO_PMTUD) { |
| 312 | SCTP_TCB_UNLOCK(stcb); |
| 313 | return; |
| 314 | } |
| 315 | /* Find the next (smaller) MTU */ |
| 316 | if (next_mtu == 0) { |
| 317 | /* |
| 318 | * Old type router that does not tell us what the next |
| 319 | * MTU is. |
| 320 | * Rats we will have to guess (in a educated fashion |
| 321 | * of course). |
| 322 | */ |
| 323 | next_mtu = sctp_get_prev_mtu(ip_len); |
| 324 | } |
| 325 | /* Stop the PMTU timer. */ |
| 326 | if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { |
| 327 | timer_stopped = 1; |
| 328 | sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net, |
| 329 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_1); |
| 330 | } else { |
| 331 | timer_stopped = 0; |
| 332 | } |
| 333 | /* Update the path MTU. */ |
| 334 | if (net->port) { |
| 335 | next_mtu -= sizeof(struct udphdr); |
| 336 | } |
| 337 | if (net->mtu > next_mtu) { |
| 338 | net->mtu = next_mtu; |
| 339 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 340 | if (net->port) { |
| 341 | sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu + sizeof(struct udphdr)); |
| 342 | } else { |
| 343 | sctp_hc_set_mtu(&net->ro._l_addr, inp->fibnum, next_mtu); |
| 344 | } |
| 345 | #endif |
| 346 | } |
| 347 | /* Update the association MTU */ |
| 348 | if (stcb->asoc.smallest_mtu > next_mtu) { |
| 349 | sctp_pathmtu_adjustment(stcb, next_mtu); |
| 350 | } |
| 351 | /* Finally, start the PMTU timer if it was running before. */ |
| 352 | if (timer_stopped) { |
| 353 | sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); |
| 354 | } |
| 355 | SCTP_TCB_UNLOCK(stcb); |
| 356 | } else { |
| 357 | SCTP_TCB_UNLOCK(stcb); |
| 358 | } |
| 359 | } |
| 360 | #endif |
| 361 |
| 362 | #if !defined(__Userspace__) |
| 363 | void |
| 364 | #if defined(__APPLE__) && !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN) |
| 365 | sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip, struct ifnet *ifp SCTP_UNUSED) |
| 366 | #else |
| 367 | sctp_ctlinput(int cmd, struct sockaddr *sa, void *vip) |
| 368 | #endif |
| 369 | { |
| 370 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 371 | struct ip *outer_ip; |
| 372 | #endif |
| 373 | struct ip *inner_ip; |
| 374 | struct sctphdr *sh; |
| 375 | struct icmp *icmp; |
| 376 | struct sctp_inpcb *inp; |
| 377 | struct sctp_tcb *stcb; |
| 378 | struct sctp_nets *net; |
| 379 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 380 | struct sctp_init_chunk *ch; |
| 381 | #endif |
| 382 | struct sockaddr_in src, dst; |
| 383 |
| 384 | if (sa->sa_family != AF_INET || |
| 385 | ((struct sockaddr_in *)sa)->sin_addr.s_addr == INADDR_ANY) { |
| 386 | return; |
| 387 | } |
| 388 | if (PRC_IS_REDIRECT(cmd)) { |
| 389 | vip = NULL; |
| 390 | } else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0) { |
| 391 | return; |
| 392 | } |
| 393 | if (vip != NULL) { |
| 394 | inner_ip = (struct ip *)vip; |
| 395 | icmp = (struct icmp *)((caddr_t)inner_ip - |
| 396 | (sizeof(struct icmp) - sizeof(struct ip))); |
| 397 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 398 | outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip)); |
| 399 | #endif |
| 400 | sh = (struct sctphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2)); |
| 401 | memset(&src, 0, sizeof(struct sockaddr_in)); |
| 402 | src.sin_family = AF_INET; |
| 403 | #ifdef HAVE_SIN_LEN |
| 404 | src.sin_len = sizeof(struct sockaddr_in); |
| 405 | #endif |
| 406 | src.sin_port = sh->src_port; |
| 407 | src.sin_addr = inner_ip->ip_src; |
| 408 | memset(&dst, 0, sizeof(struct sockaddr_in)); |
| 409 | dst.sin_family = AF_INET; |
| 410 | #ifdef HAVE_SIN_LEN |
| 411 | dst.sin_len = sizeof(struct sockaddr_in); |
| 412 | #endif |
| 413 | dst.sin_port = sh->dest_port; |
| 414 | dst.sin_addr = inner_ip->ip_dst; |
| 415 | /* |
| 416 | * 'dst' holds the dest of the packet that failed to be sent. |
| 417 | * 'src' holds our local endpoint address. Thus we reverse |
| 418 | * the dst and the src in the lookup. |
| 419 | */ |
| 420 | inp = NULL; |
| 421 | net = NULL; |
| 422 | stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst, |
| 423 | (struct sockaddr *)&src, |
| 424 | &inp, &net, 1, |
| 425 | SCTP_DEFAULT_VRFID); |
| 426 | if ((stcb != NULL) && |
| 427 | (net != NULL) && |
| 428 | (inp != NULL)) { |
| 429 | /* Check the verification tag */ |
| 430 | if (ntohl(sh->v_tag) != 0) { |
| 431 | /* |
| 432 | * This must be the verification tag used for |
| 433 | * sending out packets. We don't consider |
| 434 | * packets reflecting the verification tag. |
| 435 | */ |
| 436 | if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) { |
| 437 | SCTP_TCB_UNLOCK(stcb); |
| 438 | return; |
| 439 | } |
| 440 | } else { |
| 441 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 442 | if (ntohs(outer_ip->ip_len) >= |
| 443 | sizeof(struct ip) + |
| 444 | 8 + (inner_ip->ip_hl << 2) + 20) { |
| 445 | /* |
| 446 | * In this case we can check if we |
| 447 | * got an INIT chunk and if the |
| 448 | * initiate tag matches. |
| 449 | */ |
| 450 | ch = (struct sctp_init_chunk *)(sh + 1); |
| 451 | if ((ch->ch.chunk_type != SCTP_INITIATION) || |
| 452 | (ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) { |
| 453 | SCTP_TCB_UNLOCK(stcb); |
| 454 | return; |
| 455 | } |
| 456 | } else { |
| 457 | SCTP_TCB_UNLOCK(stcb); |
| 458 | return; |
| 459 | } |
| 460 | #else |
| 461 | SCTP_TCB_UNLOCK(stcb); |
| 462 | return; |
| 463 | #endif |
| 464 | } |
| 465 | sctp_notify(inp, stcb, net, |
| 466 | icmp->icmp_type, |
| 467 | icmp->icmp_code, |
| 468 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 469 | ntohs(inner_ip->ip_len), |
| 470 | #else |
| 471 | inner_ip->ip_len, |
| 472 | #endif |
| 473 | (uint32_t)ntohs(icmp->icmp_nextmtu)); |
| 474 | #if defined(__Userspace__) |
| 475 | if (!(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) && |
| 476 | (stcb->sctp_socket != NULL)) { |
| 477 | struct socket *upcall_socket; |
| 478 |
| 479 | upcall_socket = stcb->sctp_socket; |
| 480 | SOCK_LOCK(upcall_socket); |
| 481 | soref(upcall_socket); |
| 482 | SOCK_UNLOCK(upcall_socket); |
| 483 | if ((upcall_socket->so_upcall != NULL) && |
| 484 | (upcall_socket->so_error != 0)) { |
| 485 | (*upcall_socket->so_upcall)(upcall_socket, upcall_socket->so_upcallarg, M_NOWAIT); |
| 486 | } |
| 487 | ACCEPT_LOCK(); |
| 488 | SOCK_LOCK(upcall_socket); |
| 489 | sorele(upcall_socket); |
| 490 | } |
| 491 | #endif |
| 492 | } else { |
| 493 | if ((stcb == NULL) && (inp != NULL)) { |
| 494 | /* reduce ref-count */ |
| 495 | SCTP_INP_WLOCK(inp); |
| 496 | SCTP_INP_DECR_REF(inp); |
| 497 | SCTP_INP_WUNLOCK(inp); |
| 498 | } |
| 499 | if (stcb) { |
| 500 | SCTP_TCB_UNLOCK(stcb); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | return; |
| 505 | } |
| 506 | #endif |
| 507 | #endif |
| 508 |
| 509 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 510 | static int |
| 511 | sctp_getcred(SYSCTL_HANDLER_ARGS) |
| 512 | { |
| 513 | struct xucred xuc; |
| 514 | struct sockaddr_in addrs[2]; |
| 515 | struct sctp_inpcb *inp; |
| 516 | struct sctp_nets *net; |
| 517 | struct sctp_tcb *stcb; |
| 518 | int error; |
| 519 | uint32_t vrf_id; |
| 520 |
| 521 | /* FIX, for non-bsd is this right? */ |
| 522 | vrf_id = SCTP_DEFAULT_VRFID; |
| 523 |
| 524 | error = priv_check(req->td, PRIV_NETINET_GETCRED); |
| 525 |
| 526 | if (error) |
| 527 | return (error); |
| 528 |
| 529 | error = SYSCTL_IN(req, addrs, sizeof(addrs)); |
| 530 | if (error) |
| 531 | return (error); |
| 532 |
| 533 | stcb = sctp_findassociation_addr_sa(sintosa(&addrs[1]), |
| 534 | sintosa(&addrs[0]), |
| 535 | &inp, &net, 1, vrf_id); |
| 536 | if (stcb == NULL || inp == NULL || inp->sctp_socket == NULL) { |
| 537 | if ((inp != NULL) && (stcb == NULL)) { |
| 538 | /* reduce ref-count */ |
| 539 | SCTP_INP_WLOCK(inp); |
| 540 | SCTP_INP_DECR_REF(inp); |
| 541 | goto cred_can_cont; |
| 542 | } |
| 543 |
| 544 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 545 | error = ENOENT; |
| 546 | goto out; |
| 547 | } |
| 548 | SCTP_TCB_UNLOCK(stcb); |
| 549 | /* We use the write lock here, only |
| 550 | * since in the error leg we need it. |
| 551 | * If we used RLOCK, then we would have |
| 552 | * to wlock/decr/unlock/rlock. Which |
| 553 | * in theory could create a hole. Better |
| 554 | * to use higher wlock. |
| 555 | */ |
| 556 | SCTP_INP_WLOCK(inp); |
| 557 | cred_can_cont: |
| 558 | error = cr_canseesocket(req->td->td_ucred, inp->sctp_socket); |
| 559 | if (error) { |
| 560 | SCTP_INP_WUNLOCK(inp); |
| 561 | goto out; |
| 562 | } |
| 563 | cru2x(inp->sctp_socket->so_cred, &xuc); |
| 564 | SCTP_INP_WUNLOCK(inp); |
| 565 | error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred)); |
| 566 | out: |
| 567 | return (error); |
| 568 | } |
| 569 |
| 570 | SYSCTL_PROC(_net_inet_sctp, OID_AUTO, getcred, |
| 571 | CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT, |
| 572 | 0, 0, sctp_getcred, "S,ucred", |
| 573 | "Get the ucred of a SCTP connection"); |
| 574 | #endif |
| 575 |
| 576 | #ifdef INET |
| 577 | #if defined(_WIN32) || defined(__Userspace__) |
| 578 | int |
| 579 | #elif defined(__FreeBSD__) |
| 580 | static void |
| 581 | #else |
| 582 | static int |
| 583 | #endif |
| 584 | sctp_abort(struct socket *so) |
| 585 | { |
| 586 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 587 | struct epoch_tracker et; |
| 588 | #endif |
| 589 | struct sctp_inpcb *inp; |
| 590 |
| 591 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 592 | if (inp == NULL) { |
| 593 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 594 | return; |
| 595 | #else |
| 596 | SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 597 | return (EINVAL); |
| 598 | #endif |
| 599 | } |
| 600 |
| 601 | SCTP_INP_WLOCK(inp); |
| 602 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 603 | NET_EPOCH_ENTER(et); |
| 604 | #endif |
| 605 | #ifdef SCTP_LOG_CLOSING |
| 606 | sctp_log_closing(inp, NULL, 17); |
| 607 | #endif |
| 608 | if (((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0)) { |
| 609 | inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP; |
| 610 | #ifdef SCTP_LOG_CLOSING |
| 611 | sctp_log_closing(inp, NULL, 16); |
| 612 | #endif |
| 613 | SCTP_INP_WUNLOCK(inp); |
| 614 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, |
| 615 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 616 | SOCK_LOCK(so); |
| 617 | SCTP_SB_CLEAR(so->so_snd); |
| 618 | /* same for the rcv ones, they are only |
| 619 | * here for the accounting/select. |
| 620 | */ |
| 621 | SCTP_SB_CLEAR(so->so_rcv); |
| 622 |
| 623 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 624 | so->so_usecount--; |
| 625 | #else |
| 626 | /* Now null out the reference, we are completely detached. */ |
| 627 | so->so_pcb = NULL; |
| 628 | #endif |
| 629 | SOCK_UNLOCK(so); |
| 630 | } else { |
| 631 | SCTP_INP_WUNLOCK(inp); |
| 632 | } |
| 633 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 634 | NET_EPOCH_EXIT(et); |
| 635 | #else |
| 636 | return (0); |
| 637 | #endif |
| 638 | } |
| 639 |
| 640 | #if defined(__Userspace__) |
| 641 | int |
| 642 | #else |
| 643 | static int |
| 644 | #endif |
| 645 | #if defined(__Userspace__) |
| 646 | sctp_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id) |
| 647 | #elif defined(__FreeBSD__) |
| 648 | sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct thread *p SCTP_UNUSED) |
| 649 | #elif defined(_WIN32) |
| 650 | sctp_attach(struct socket *so, int proto SCTP_UNUSED, PKTHREAD p SCTP_UNUSED) |
| 651 | #else |
| 652 | sctp_attach(struct socket *so, int proto SCTP_UNUSED, struct proc *p SCTP_UNUSED) |
| 653 | #endif |
| 654 | { |
| 655 | struct sctp_inpcb *inp; |
| 656 | struct inpcb *ip_inp; |
| 657 | int error; |
| 658 | #if !defined(__Userspace__) |
| 659 | uint32_t vrf_id = SCTP_DEFAULT_VRFID; |
| 660 | #endif |
| 661 |
| 662 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 663 | if (inp != NULL) { |
| 664 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 665 | return (EINVAL); |
| 666 | } |
| 667 | if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { |
| 668 | error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace)); |
| 669 | if (error) { |
| 670 | return (error); |
| 671 | } |
| 672 | } |
| 673 | error = sctp_inpcb_alloc(so, vrf_id); |
| 674 | if (error) { |
| 675 | return (error); |
| 676 | } |
| 677 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 678 | SCTP_INP_WLOCK(inp); |
| 679 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; /* I'm not v6! */ |
| 680 | ip_inp = &inp->ip_inp.inp; |
| 681 | ip_inp->inp_vflag |= INP_IPV4; |
| 682 | ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl); |
| 683 | SCTP_INP_WUNLOCK(inp); |
| 684 | return (0); |
| 685 | } |
| 686 |
| 687 | #if defined(__Userspace__) |
| 688 | int |
| 689 | sctp_bind(struct socket *so, struct sockaddr *addr) { |
| 690 | void *p = NULL; |
| 691 | #elif defined(__FreeBSD__) |
| 692 | static int |
| 693 | sctp_bind(struct socket *so, struct sockaddr *addr, struct thread *p) |
| 694 | { |
| 695 | #elif defined(__APPLE__) |
| 696 | static int |
| 697 | sctp_bind(struct socket *so, struct sockaddr *addr, struct proc *p) { |
| 698 | #elif defined(_WIN32) |
| 699 | static int |
| 700 | sctp_bind(struct socket *so, struct sockaddr *addr, PKTHREAD p) { |
| 701 | #else |
| 702 | static int |
| 703 | sctp_bind(struct socket *so, struct mbuf *nam, struct proc *p) |
| 704 | { |
| 705 | struct sockaddr *addr = nam ? mtod(nam, struct sockaddr *): NULL; |
| 706 |
| 707 | #endif |
| 708 | struct sctp_inpcb *inp; |
| 709 |
| 710 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 711 | if (inp == NULL) { |
| 712 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 713 | return (EINVAL); |
| 714 | } |
| 715 | if (addr != NULL) { |
| 716 | #ifdef HAVE_SA_LEN |
| 717 | if ((addr->sa_family != AF_INET) || |
| 718 | (addr->sa_len != sizeof(struct sockaddr_in))) { |
| 719 | #else |
| 720 | if (addr->sa_family != AF_INET) { |
| 721 | #endif |
| 722 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 723 | return (EINVAL); |
| 724 | } |
| 725 | } |
| 726 | return (sctp_inpcb_bind(so, addr, NULL, p)); |
| 727 | } |
| 728 |
| 729 | #endif |
| 730 | #if defined(__Userspace__) |
| 731 |
| 732 | int |
| 733 | sctpconn_attach(struct socket *so, int proto SCTP_UNUSED, uint32_t vrf_id) |
| 734 | { |
| 735 | struct sctp_inpcb *inp; |
| 736 | struct inpcb *ip_inp; |
| 737 | int error; |
| 738 |
| 739 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 740 | if (inp != NULL) { |
| 741 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 742 | return (EINVAL); |
| 743 | } |
| 744 | if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { |
| 745 | error = SCTP_SORESERVE(so, SCTP_BASE_SYSCTL(sctp_sendspace), SCTP_BASE_SYSCTL(sctp_recvspace)); |
| 746 | if (error) { |
| 747 | return (error); |
| 748 | } |
| 749 | } |
| 750 | error = sctp_inpcb_alloc(so, vrf_id); |
| 751 | if (error) { |
| 752 | return (error); |
| 753 | } |
| 754 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 755 | SCTP_INP_WLOCK(inp); |
| 756 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUND_V6; |
| 757 | inp->sctp_flags |= SCTP_PCB_FLAGS_BOUND_CONN; |
| 758 | ip_inp = &inp->ip_inp.inp; |
| 759 | ip_inp->inp_vflag |= INP_CONN; |
| 760 | ip_inp->inp_ip_ttl = MODULE_GLOBAL(ip_defttl); |
| 761 | SCTP_INP_WUNLOCK(inp); |
| 762 | return (0); |
| 763 | } |
| 764 |
| 765 | int |
| 766 | sctpconn_bind(struct socket *so, struct sockaddr *addr) |
| 767 | { |
| 768 | struct sctp_inpcb *inp; |
| 769 |
| 770 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 771 | if (inp == NULL) { |
| 772 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 773 | return (EINVAL); |
| 774 | } |
| 775 | if (addr != NULL) { |
| 776 | #ifdef HAVE_SA_LEN |
| 777 | if ((addr->sa_family != AF_CONN) || |
| 778 | (addr->sa_len != sizeof(struct sockaddr_conn))) { |
| 779 | #else |
| 780 | if (addr->sa_family != AF_CONN) { |
| 781 | #endif |
| 782 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 783 | return (EINVAL); |
| 784 | } |
| 785 | } |
| 786 | return (sctp_inpcb_bind(so, addr, NULL, NULL)); |
| 787 | } |
| 788 |
| 789 | #endif |
| 790 | #if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__) |
| 791 | void |
| 792 | sctp_close(struct socket *so) |
| 793 | { |
| 794 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 795 | struct epoch_tracker et; |
| 796 | #endif |
| 797 | struct sctp_inpcb *inp; |
| 798 |
| 799 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 800 | if (inp == NULL) |
| 801 | return; |
| 802 |
| 803 | /* Inform all the lower layer assoc that we |
| 804 | * are done. |
| 805 | */ |
| 806 | SCTP_INP_WLOCK(inp); |
| 807 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 808 | NET_EPOCH_ENTER(et); |
| 809 | #endif |
| 810 | #ifdef SCTP_LOG_CLOSING |
| 811 | sctp_log_closing(inp, NULL, 17); |
| 812 | #endif |
| 813 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { |
| 814 | inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP; |
| 815 | #if defined(__Userspace__) |
| 816 | if (((so->so_options & SCTP_SO_LINGER) && (so->so_linger == 0)) || |
| 817 | (so->so_rcv.sb_cc > 0)) { |
| 818 | #else |
| 819 | if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || |
| 820 | (so->so_rcv.sb_cc > 0)) { |
| 821 | #endif |
| 822 | #ifdef SCTP_LOG_CLOSING |
| 823 | sctp_log_closing(inp, NULL, 13); |
| 824 | #endif |
| 825 | SCTP_INP_WUNLOCK(inp); |
| 826 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, |
| 827 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 828 | } else { |
| 829 | #ifdef SCTP_LOG_CLOSING |
| 830 | sctp_log_closing(inp, NULL, 14); |
| 831 | #endif |
| 832 | SCTP_INP_WUNLOCK(inp); |
| 833 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE, |
| 834 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 835 | } |
| 836 | /* The socket is now detached, no matter what |
| 837 | * the state of the SCTP association. |
| 838 | */ |
| 839 | SOCK_LOCK(so); |
| 840 | SCTP_SB_CLEAR(so->so_snd); |
| 841 | /* same for the rcv ones, they are only |
| 842 | * here for the accounting/select. |
| 843 | */ |
| 844 | SCTP_SB_CLEAR(so->so_rcv); |
| 845 |
| 846 | #if !(defined(__APPLE__) && !defined(__Userspace__)) |
| 847 | /* Now null out the reference, we are completely detached. */ |
| 848 | so->so_pcb = NULL; |
| 849 | #endif |
| 850 | SOCK_UNLOCK(so); |
| 851 | } else { |
| 852 | SCTP_INP_WUNLOCK(inp); |
| 853 | } |
| 854 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 855 | NET_EPOCH_EXIT(et); |
| 856 | #endif |
| 857 | } |
| 858 | #else |
| 859 | int |
| 860 | sctp_detach(struct socket *so) |
| 861 | { |
| 862 | struct sctp_inpcb *inp; |
| 863 | uint32_t flags; |
| 864 |
| 865 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 866 | if (inp == NULL) { |
| 867 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 868 | return; |
| 869 | #else |
| 870 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 871 | return (EINVAL); |
| 872 | #endif |
| 873 | } |
| 874 | sctp_must_try_again: |
| 875 | flags = inp->sctp_flags; |
| 876 | #ifdef SCTP_LOG_CLOSING |
| 877 | sctp_log_closing(inp, NULL, 17); |
| 878 | #endif |
| 879 | if (((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && |
| 880 | (atomic_cmpset_int(&inp->sctp_flags, flags, (flags | SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_CLOSE_IP)))) { |
| 881 | #if defined(__Userspace__) |
| 882 | if (((so->so_options & SCTP_SO_LINGER) && (so->so_linger == 0)) || |
| 883 | (so->so_rcv.sb_cc > 0)) { |
| 884 | #else |
| 885 | if (((so->so_options & SO_LINGER) && (so->so_linger == 0)) || |
| 886 | (so->so_rcv.sb_cc > 0)) { |
| 887 | #endif |
| 888 | #ifdef SCTP_LOG_CLOSING |
| 889 | sctp_log_closing(inp, NULL, 13); |
| 890 | #endif |
| 891 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT, |
| 892 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 893 | } else { |
| 894 | #ifdef SCTP_LOG_CLOSING |
| 895 | sctp_log_closing(inp, NULL, 13); |
| 896 | #endif |
| 897 | sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE, |
| 898 | SCTP_CALLED_AFTER_CMPSET_OFCLOSE); |
| 899 | } |
| 900 | /* The socket is now detached, no matter what |
| 901 | * the state of the SCTP association. |
| 902 | */ |
| 903 | SCTP_SB_CLEAR(so->so_snd); |
| 904 | /* same for the rcv ones, they are only |
| 905 | * here for the accounting/select. |
| 906 | */ |
| 907 | SCTP_SB_CLEAR(so->so_rcv); |
| 908 | #if !(defined(__APPLE__) && !defined(__Userspace__)) |
| 909 | /* Now disconnect */ |
| 910 | so->so_pcb = NULL; |
| 911 | #endif |
| 912 | } else { |
| 913 | flags = inp->sctp_flags; |
| 914 | if ((flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) { |
| 915 | goto sctp_must_try_again; |
| 916 | } |
| 917 | } |
| 918 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 919 | return; |
| 920 | #else |
| 921 | return (0); |
| 922 | #endif |
| 923 | } |
| 924 | #endif |
| 925 |
| 926 | #if defined(__Userspace__) |
| 927 | /* __Userspace__ is not calling sctp_sendm */ |
| 928 | #endif |
| 929 | #if !(defined(_WIN32) && !defined(__Userspace__)) |
| 930 | int |
| 931 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 932 | sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, |
| 933 | struct mbuf *control, struct thread *p); |
| 934 |
| 935 | #else |
| 936 | sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, |
| 937 | struct mbuf *control, struct proc *p); |
| 938 |
| 939 | #endif |
| 940 | int |
| 941 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 942 | sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, |
| 943 | struct mbuf *control, struct thread *p) |
| 944 | { |
| 945 | #else |
| 946 | sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, |
| 947 | struct mbuf *control, struct proc *p) |
| 948 | { |
| 949 | #endif |
| 950 | struct sctp_inpcb *inp; |
| 951 | int error; |
| 952 |
| 953 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 954 | if (inp == NULL) { |
| 955 | if (control) { |
| 956 | sctp_m_freem(control); |
| 957 | control = NULL; |
| 958 | } |
| 959 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 960 | sctp_m_freem(m); |
| 961 | return (EINVAL); |
| 962 | } |
| 963 | /* Got to have an to address if we are NOT a connected socket */ |
| 964 | if ((addr == NULL) && |
| 965 | ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) || |
| 966 | (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) { |
| 967 | goto connected_type; |
| 968 | } |
| 969 |
| 970 | error = 0; |
| 971 | if (addr == NULL) { |
| 972 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ); |
| 973 | error = EDESTADDRREQ; |
| 974 | } else if (addr->sa_family != AF_INET) { |
| 975 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); |
| 976 | error = EAFNOSUPPORT; |
| 977 | #if defined(HAVE_SA_LEN) |
| 978 | } else if (addr->sa_len != sizeof(struct sockaddr_in)) { |
| 979 | SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 980 | error = EINVAL; |
| 981 | #endif |
| 982 | } |
| 983 | if (error != 0) { |
| 984 | sctp_m_freem(m); |
| 985 | if (control) { |
| 986 | sctp_m_freem(control); |
| 987 | control = NULL; |
| 988 | } |
| 989 | return (error); |
| 990 | } |
| 991 | connected_type: |
| 992 | /* now what about control */ |
| 993 | if (control) { |
| 994 | if (inp->control) { |
| 995 | sctp_m_freem(inp->control); |
| 996 | inp->control = NULL; |
| 997 | } |
| 998 | inp->control = control; |
| 999 | } |
| 1000 | /* Place the data */ |
| 1001 | if (inp->pkt) { |
| 1002 | SCTP_BUF_NEXT(inp->pkt_last) = m; |
| 1003 | inp->pkt_last = m; |
| 1004 | } else { |
| 1005 | inp->pkt_last = inp->pkt = m; |
| 1006 | } |
| 1007 | if ( |
| 1008 | #if (defined(__FreeBSD__) || defined(__APPLE__)) && !defined(__Userspace__) |
| 1009 | /* FreeBSD uses a flag passed */ |
| 1010 | ((flags & PRUS_MORETOCOME) == 0) |
| 1011 | #else |
| 1012 | 1 /* Open BSD does not have any "more to come" |
| 1013 | * indication */ |
| 1014 | #endif |
| 1015 | ) { |
| 1016 | /* |
| 1017 | * note with the current version this code will only be used |
| 1018 | * by OpenBSD-- NetBSD, FreeBSD, and MacOS have methods for |
| 1019 | * re-defining sosend to use the sctp_sosend. One can |
| 1020 | * optionally switch back to this code (by changing back the |
| 1021 | * definitions) but this is not advisable. This code is used |
| 1022 | * by FreeBSD when sending a file with sendfile() though. |
| 1023 | */ |
| 1024 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1025 | struct epoch_tracker et; |
| 1026 | #endif |
| 1027 | int ret; |
| 1028 |
| 1029 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1030 | NET_EPOCH_ENTER(et); |
| 1031 | #endif |
| 1032 | ret = sctp_output(inp, inp->pkt, addr, inp->control, p, flags); |
| 1033 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1034 | NET_EPOCH_EXIT(et); |
| 1035 | #endif |
| 1036 | inp->pkt = NULL; |
| 1037 | inp->control = NULL; |
| 1038 | return (ret); |
| 1039 | } else { |
| 1040 | return (0); |
| 1041 | } |
| 1042 | } |
| 1043 | #endif |
| 1044 |
| 1045 | int |
| 1046 | sctp_disconnect(struct socket *so) |
| 1047 | { |
| 1048 | struct sctp_inpcb *inp; |
| 1049 |
| 1050 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 1051 | if (inp == NULL) { |
| 1052 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); |
| 1053 | return (ENOTCONN); |
| 1054 | } |
| 1055 | SCTP_INP_RLOCK(inp); |
| 1056 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 1057 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 1058 | if (LIST_EMPTY(&inp->sctp_asoc_list)) { |
| 1059 | /* No connection */ |
| 1060 | SCTP_INP_RUNLOCK(inp); |
| 1061 | return (0); |
| 1062 | } else { |
| 1063 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1064 | struct epoch_tracker et; |
| 1065 | #endif |
| 1066 | struct sctp_association *asoc; |
| 1067 | struct sctp_tcb *stcb; |
| 1068 |
| 1069 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 1070 | if (stcb == NULL) { |
| 1071 | SCTP_INP_RUNLOCK(inp); |
| 1072 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 1073 | return (EINVAL); |
| 1074 | } |
| 1075 | SCTP_TCB_LOCK(stcb); |
| 1076 | asoc = &stcb->asoc; |
| 1077 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
| 1078 | /* We are about to be freed, out of here */ |
| 1079 | SCTP_TCB_UNLOCK(stcb); |
| 1080 | SCTP_INP_RUNLOCK(inp); |
| 1081 | return (0); |
| 1082 | } |
| 1083 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1084 | NET_EPOCH_ENTER(et); |
| 1085 | #endif |
| 1086 | #if defined(__Userspace__) |
| 1087 | if (((so->so_options & SCTP_SO_LINGER) && |
| 1088 | (so->so_linger == 0)) || |
| 1089 | (so->so_rcv.sb_cc > 0)) { |
| 1090 | #else |
| 1091 | if (((so->so_options & SO_LINGER) && |
| 1092 | (so->so_linger == 0)) || |
| 1093 | (so->so_rcv.sb_cc > 0)) { |
| 1094 | #endif |
| 1095 | if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) { |
| 1096 | /* Left with Data unread */ |
| 1097 | struct mbuf *op_err; |
| 1098 |
| 1099 | op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); |
| 1100 | sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED); |
| 1101 | SCTP_STAT_INCR_COUNTER32(sctps_aborted); |
| 1102 | } |
| 1103 | SCTP_INP_RUNLOCK(inp); |
| 1104 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || |
| 1105 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { |
| 1106 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
| 1107 | } |
| 1108 | (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, |
| 1109 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_3); |
| 1110 | /* No unlock tcb assoc is gone */ |
| 1111 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1112 | NET_EPOCH_EXIT(et); |
| 1113 | #endif |
| 1114 | return (0); |
| 1115 | } |
| 1116 | if (TAILQ_EMPTY(&asoc->send_queue) && |
| 1117 | TAILQ_EMPTY(&asoc->sent_queue) && |
| 1118 | (asoc->stream_queue_cnt == 0)) { |
| 1119 | /* there is nothing queued to send, so done */ |
| 1120 | if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc)) { |
| 1121 | goto abort_anyway; |
| 1122 | } |
| 1123 | if ((SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) && |
| 1124 | (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { |
| 1125 | /* only send SHUTDOWN 1st time thru */ |
| 1126 | struct sctp_nets *netp; |
| 1127 |
| 1128 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || |
| 1129 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { |
| 1130 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
| 1131 | } |
| 1132 | SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT); |
| 1133 | sctp_stop_timers_for_shutdown(stcb); |
| 1134 | if (stcb->asoc.alternate) { |
| 1135 | netp = stcb->asoc.alternate; |
| 1136 | } else { |
| 1137 | netp = stcb->asoc.primary_destination; |
| 1138 | } |
| 1139 | sctp_send_shutdown(stcb,netp); |
| 1140 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, |
| 1141 | stcb->sctp_ep, stcb, netp); |
| 1142 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, |
| 1143 | stcb->sctp_ep, stcb, NULL); |
| 1144 | sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_LOCKED); |
| 1145 | } |
| 1146 | } else { |
| 1147 | /* |
| 1148 | * we still got (or just got) data to send, |
| 1149 | * so set SHUTDOWN_PENDING |
| 1150 | */ |
| 1151 | /* |
| 1152 | * XXX sockets draft says that SCTP_EOF |
| 1153 | * should be sent with no data. currently, |
| 1154 | * we will allow user data to be sent first |
| 1155 | * and move to SHUTDOWN-PENDING |
| 1156 | */ |
| 1157 | SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING); |
| 1158 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL); |
| 1159 | if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc)) { |
| 1160 | SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT); |
| 1161 | } |
| 1162 | if (TAILQ_EMPTY(&asoc->send_queue) && |
| 1163 | TAILQ_EMPTY(&asoc->sent_queue) && |
| 1164 | (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { |
| 1165 | struct mbuf *op_err; |
| 1166 | abort_anyway: |
| 1167 | op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); |
| 1168 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_4; |
| 1169 | sctp_send_abort_tcb(stcb, op_err, SCTP_SO_LOCKED); |
| 1170 | SCTP_STAT_INCR_COUNTER32(sctps_aborted); |
| 1171 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) || |
| 1172 | (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) { |
| 1173 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
| 1174 | } |
| 1175 | SCTP_INP_RUNLOCK(inp); |
| 1176 | (void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, |
| 1177 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_5); |
| 1178 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1179 | NET_EPOCH_EXIT(et); |
| 1180 | #endif |
| 1181 | return (0); |
| 1182 | } else { |
| 1183 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED); |
| 1184 | } |
| 1185 | } |
| 1186 | soisdisconnecting(so); |
| 1187 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1188 | NET_EPOCH_EXIT(et); |
| 1189 | #endif |
| 1190 | SCTP_TCB_UNLOCK(stcb); |
| 1191 | SCTP_INP_RUNLOCK(inp); |
| 1192 | return (0); |
| 1193 | } |
| 1194 | /* not reached */ |
| 1195 | } else { |
| 1196 | /* UDP model does not support this */ |
| 1197 | SCTP_INP_RUNLOCK(inp); |
| 1198 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 1199 | return (EOPNOTSUPP); |
| 1200 | } |
| 1201 | } |
| 1202 |
| 1203 | #if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__) |
| 1204 | int |
| 1205 | sctp_flush(struct socket *so, int how) |
| 1206 | { |
| 1207 | /* |
| 1208 | * We will just clear out the values and let |
| 1209 | * subsequent close clear out the data, if any. |
| 1210 | * Note if the user did a shutdown(SHUT_RD) they |
| 1211 | * will not be able to read the data, the socket |
| 1212 | * will block that from happening. |
| 1213 | */ |
| 1214 | struct sctp_inpcb *inp; |
| 1215 |
| 1216 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 1217 | if (inp == NULL) { |
| 1218 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 1219 | return (EINVAL); |
| 1220 | } |
| 1221 | SCTP_INP_RLOCK(inp); |
| 1222 | /* For the 1 to many model this does nothing */ |
| 1223 | if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { |
| 1224 | SCTP_INP_RUNLOCK(inp); |
| 1225 | return (0); |
| 1226 | } |
| 1227 | SCTP_INP_RUNLOCK(inp); |
| 1228 | if ((how == PRU_FLUSH_RD) || (how == PRU_FLUSH_RDWR)) { |
| 1229 | /* First make sure the sb will be happy, we don't |
| 1230 | * use these except maybe the count |
| 1231 | */ |
| 1232 | SCTP_INP_WLOCK(inp); |
| 1233 | SCTP_INP_READ_LOCK(inp); |
| 1234 | inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_CANT_READ; |
| 1235 | SCTP_INP_READ_UNLOCK(inp); |
| 1236 | SCTP_INP_WUNLOCK(inp); |
| 1237 | so->so_rcv.sb_cc = 0; |
| 1238 | so->so_rcv.sb_mbcnt = 0; |
| 1239 | so->so_rcv.sb_mb = NULL; |
| 1240 | } |
| 1241 | if ((how == PRU_FLUSH_WR) || (how == PRU_FLUSH_RDWR)) { |
| 1242 | /* First make sure the sb will be happy, we don't |
| 1243 | * use these except maybe the count |
| 1244 | */ |
| 1245 | so->so_snd.sb_cc = 0; |
| 1246 | so->so_snd.sb_mbcnt = 0; |
| 1247 | so->so_snd.sb_mb = NULL; |
| 1248 | } |
| 1249 | return (0); |
| 1250 | } |
| 1251 | #endif |
| 1252 |
| 1253 | int |
| 1254 | sctp_shutdown(struct socket *so) |
| 1255 | { |
| 1256 | struct sctp_inpcb *inp; |
| 1257 |
| 1258 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 1259 | if (inp == NULL) { |
| 1260 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 1261 | return (EINVAL); |
| 1262 | } |
| 1263 | SCTP_INP_RLOCK(inp); |
| 1264 | /* For UDP model this is a invalid call */ |
| 1265 | if (!((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 1266 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { |
| 1267 | /* Restore the flags that the soshutdown took away. */ |
| 1268 | #if (defined(__FreeBSD__) || defined(_WIN32)) && !defined(__Userspace__) |
| 1269 | SOCKBUF_LOCK(&so->so_rcv); |
| 1270 | so->so_rcv.sb_state &= ~SBS_CANTRCVMORE; |
| 1271 | SOCKBUF_UNLOCK(&so->so_rcv); |
| 1272 | #else |
| 1273 | SOCK_LOCK(so); |
| 1274 | so->so_state &= ~SS_CANTRCVMORE; |
| 1275 | SOCK_UNLOCK(so); |
| 1276 | #endif |
| 1277 | /* This proc will wakeup for read and do nothing (I hope) */ |
| 1278 | SCTP_INP_RUNLOCK(inp); |
| 1279 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 1280 | return (EOPNOTSUPP); |
| 1281 | } else { |
| 1282 | /* |
| 1283 | * Ok, if we reach here its the TCP model and it is either |
| 1284 | * a SHUT_WR or SHUT_RDWR. |
| 1285 | * This means we put the shutdown flag against it. |
| 1286 | */ |
| 1287 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1288 | struct epoch_tracker et; |
| 1289 | #endif |
| 1290 | struct sctp_tcb *stcb; |
| 1291 | struct sctp_association *asoc; |
| 1292 | struct sctp_nets *netp; |
| 1293 |
| 1294 | if ((so->so_state & |
| 1295 | (SS_ISCONNECTED|SS_ISCONNECTING|SS_ISDISCONNECTING)) == 0) { |
| 1296 | SCTP_INP_RUNLOCK(inp); |
| 1297 | return (ENOTCONN); |
| 1298 | } |
| 1299 | socantsendmore(so); |
| 1300 |
| 1301 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 1302 | if (stcb == NULL) { |
| 1303 | /* |
| 1304 | * Ok, we hit the case that the shutdown call was |
| 1305 | * made after an abort or something. Nothing to do |
| 1306 | * now. |
| 1307 | */ |
| 1308 | SCTP_INP_RUNLOCK(inp); |
| 1309 | return (0); |
| 1310 | } |
| 1311 | SCTP_TCB_LOCK(stcb); |
| 1312 | asoc = &stcb->asoc; |
| 1313 | if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
| 1314 | SCTP_TCB_UNLOCK(stcb); |
| 1315 | SCTP_INP_RUNLOCK(inp); |
| 1316 | return (0); |
| 1317 | } |
| 1318 | if ((SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) && |
| 1319 | (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_ECHOED) && |
| 1320 | (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN)) { |
| 1321 | /* If we are not in or before ESTABLISHED, there is |
| 1322 | * no protocol action required. |
| 1323 | */ |
| 1324 | SCTP_TCB_UNLOCK(stcb); |
| 1325 | SCTP_INP_RUNLOCK(inp); |
| 1326 | return (0); |
| 1327 | } |
| 1328 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1329 | NET_EPOCH_ENTER(et); |
| 1330 | #endif |
| 1331 | if (stcb->asoc.alternate) { |
| 1332 | netp = stcb->asoc.alternate; |
| 1333 | } else { |
| 1334 | netp = stcb->asoc.primary_destination; |
| 1335 | } |
| 1336 | if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) && |
| 1337 | TAILQ_EMPTY(&asoc->send_queue) && |
| 1338 | TAILQ_EMPTY(&asoc->sent_queue) && |
| 1339 | (asoc->stream_queue_cnt == 0)) { |
| 1340 | if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc)) { |
| 1341 | goto abort_anyway; |
| 1342 | } |
| 1343 | /* there is nothing queued to send, so I'm done... */ |
| 1344 | SCTP_STAT_DECR_GAUGE32(sctps_currestab); |
| 1345 | SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT); |
| 1346 | sctp_stop_timers_for_shutdown(stcb); |
| 1347 | sctp_send_shutdown(stcb, netp); |
| 1348 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, |
| 1349 | stcb->sctp_ep, stcb, netp); |
| 1350 | } else { |
| 1351 | /* |
| 1352 | * We still got (or just got) data to send, so set |
| 1353 | * SHUTDOWN_PENDING. |
| 1354 | */ |
| 1355 | SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING); |
| 1356 | if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc)) { |
| 1357 | SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_PARTIAL_MSG_LEFT); |
| 1358 | } |
| 1359 | if (TAILQ_EMPTY(&asoc->send_queue) && |
| 1360 | TAILQ_EMPTY(&asoc->sent_queue) && |
| 1361 | (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { |
| 1362 | struct mbuf *op_err; |
| 1363 | abort_anyway: |
| 1364 | op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, ""); |
| 1365 | stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_USRREQ + SCTP_LOC_6; |
| 1366 | SCTP_INP_RUNLOCK(inp); |
| 1367 | sctp_abort_an_association(stcb->sctp_ep, stcb, |
| 1368 | op_err, false, SCTP_SO_LOCKED); |
| 1369 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1370 | NET_EPOCH_EXIT(et); |
| 1371 | #endif |
| 1372 | return (0); |
| 1373 | } |
| 1374 | } |
| 1375 | sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, NULL); |
| 1376 | /* XXX: Why do this in the case where we have still data queued? */ |
| 1377 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED); |
| 1378 | SCTP_TCB_UNLOCK(stcb); |
| 1379 | SCTP_INP_RUNLOCK(inp); |
| 1380 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1381 | NET_EPOCH_EXIT(et); |
| 1382 | #endif |
| 1383 | return (0); |
| 1384 | } |
| 1385 | } |
| 1386 |
| 1387 | /* |
| 1388 | * copies a "user" presentable address and removes embedded scope, etc. |
| 1389 | * returns 0 on success, 1 on error |
| 1390 | */ |
| 1391 | static uint32_t |
| 1392 | sctp_fill_user_address(struct sockaddr *dst, struct sockaddr *src) |
| 1393 | { |
| 1394 | #ifdef INET6 |
| 1395 | #if defined(SCTP_EMBEDDED_V6_SCOPE) |
| 1396 | struct sockaddr_in6 lsa6; |
| 1397 |
| 1398 | src = (struct sockaddr *)sctp_recover_scope((struct sockaddr_in6 *)src, |
| 1399 | &lsa6); |
| 1400 | #endif |
| 1401 | #endif |
| 1402 | #ifdef HAVE_SA_LEN |
| 1403 | memcpy(dst, src, src->sa_len); |
| 1404 | #else |
| 1405 | switch (src->sa_family) { |
| 1406 | #ifdef INET |
| 1407 | case AF_INET: |
| 1408 | memcpy(dst, src, sizeof(struct sockaddr_in)); |
| 1409 | break; |
| 1410 | #endif |
| 1411 | #ifdef INET6 |
| 1412 | case AF_INET6: |
| 1413 | memcpy(dst, src, sizeof(struct sockaddr_in6)); |
| 1414 | break; |
| 1415 | #endif |
| 1416 | #if defined(__Userspace__) |
| 1417 | case AF_CONN: |
| 1418 | memcpy(dst, src, sizeof(struct sockaddr_conn)); |
| 1419 | break; |
| 1420 | #endif |
| 1421 | default: |
| 1422 | /* TSNH */ |
| 1423 | break; |
| 1424 | } |
| 1425 | #endif |
| 1426 | return (0); |
| 1427 | } |
| 1428 |
| 1429 | static size_t |
| 1430 | sctp_fill_up_addresses_vrf(struct sctp_inpcb *inp, |
| 1431 | struct sctp_tcb *stcb, |
| 1432 | size_t limit, |
| 1433 | struct sockaddr *addr, |
| 1434 | uint32_t vrf_id) |
| 1435 | { |
| 1436 | struct sctp_ifn *sctp_ifn; |
| 1437 | struct sctp_ifa *sctp_ifa; |
| 1438 | size_t actual; |
| 1439 | int loopback_scope; |
| 1440 | #if defined(INET) |
| 1441 | int ipv4_local_scope, ipv4_addr_legal; |
| 1442 | #endif |
| 1443 | #if defined(INET6) |
| 1444 | int local_scope, site_scope, ipv6_addr_legal; |
| 1445 | #endif |
| 1446 | #if defined(__Userspace__) |
| 1447 | int conn_addr_legal; |
| 1448 | #endif |
| 1449 | struct sctp_vrf *vrf; |
| 1450 |
| 1451 | SCTP_IPI_ADDR_LOCK_ASSERT(); |
| 1452 | actual = 0; |
| 1453 | if (limit == 0) |
| 1454 | return (actual); |
| 1455 |
| 1456 | if (stcb) { |
| 1457 | /* Turn on all the appropriate scope */ |
| 1458 | loopback_scope = stcb->asoc.scope.loopback_scope; |
| 1459 | #if defined(INET) |
| 1460 | ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope; |
| 1461 | ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal; |
| 1462 | #endif |
| 1463 | #if defined(INET6) |
| 1464 | local_scope = stcb->asoc.scope.local_scope; |
| 1465 | site_scope = stcb->asoc.scope.site_scope; |
| 1466 | ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal; |
| 1467 | #endif |
| 1468 | #if defined(__Userspace__) |
| 1469 | conn_addr_legal = stcb->asoc.scope.conn_addr_legal; |
| 1470 | #endif |
| 1471 | } else { |
| 1472 | /* Use generic values for endpoints. */ |
| 1473 | loopback_scope = 1; |
| 1474 | #if defined(INET) |
| 1475 | ipv4_local_scope = 1; |
| 1476 | #endif |
| 1477 | #if defined(INET6) |
| 1478 | local_scope = 1; |
| 1479 | site_scope = 1; |
| 1480 | #endif |
| 1481 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
| 1482 | #if defined(INET6) |
| 1483 | ipv6_addr_legal = 1; |
| 1484 | #endif |
| 1485 | #if defined(INET) |
| 1486 | if (SCTP_IPV6_V6ONLY(inp)) { |
| 1487 | ipv4_addr_legal = 0; |
| 1488 | } else { |
| 1489 | ipv4_addr_legal = 1; |
| 1490 | } |
| 1491 | #endif |
| 1492 | #if defined(__Userspace__) |
| 1493 | conn_addr_legal = 0; |
| 1494 | #endif |
| 1495 | } else { |
| 1496 | #if defined(INET6) |
| 1497 | ipv6_addr_legal = 0; |
| 1498 | #endif |
| 1499 | #if defined(__Userspace__) |
| 1500 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) { |
| 1501 | conn_addr_legal = 1; |
| 1502 | #if defined(INET) |
| 1503 | ipv4_addr_legal = 0; |
| 1504 | #endif |
| 1505 | } else { |
| 1506 | conn_addr_legal = 0; |
| 1507 | #if defined(INET) |
| 1508 | ipv4_addr_legal = 1; |
| 1509 | #endif |
| 1510 | } |
| 1511 | #else |
| 1512 | #if defined(INET) |
| 1513 | ipv4_addr_legal = 1; |
| 1514 | #endif |
| 1515 | #endif |
| 1516 | } |
| 1517 | } |
| 1518 | vrf = sctp_find_vrf(vrf_id); |
| 1519 | if (vrf == NULL) { |
| 1520 | return (0); |
| 1521 | } |
| 1522 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
| 1523 | LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { |
| 1524 | if ((loopback_scope == 0) && |
| 1525 | SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { |
| 1526 | /* Skip loopback if loopback_scope not set */ |
| 1527 | continue; |
| 1528 | } |
| 1529 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
| 1530 | if (stcb) { |
| 1531 | /* |
| 1532 | * For the BOUND-ALL case, the list |
| 1533 | * associated with a TCB is Always |
| 1534 | * considered a reverse list.. i.e. |
| 1535 | * it lists addresses that are NOT |
| 1536 | * part of the association. If this |
| 1537 | * is one of those we must skip it. |
| 1538 | */ |
| 1539 | if (sctp_is_addr_restricted(stcb, |
| 1540 | sctp_ifa)) { |
| 1541 | continue; |
| 1542 | } |
| 1543 | } |
| 1544 | switch (sctp_ifa->address.sa.sa_family) { |
| 1545 | #ifdef INET |
| 1546 | case AF_INET: |
| 1547 | if (ipv4_addr_legal) { |
| 1548 | struct sockaddr_in *sin; |
| 1549 |
| 1550 | sin = &sctp_ifa->address.sin; |
| 1551 | if (sin->sin_addr.s_addr == 0) { |
| 1552 | /* |
| 1553 | * we skip unspecifed |
| 1554 | * addresses |
| 1555 | */ |
| 1556 | continue; |
| 1557 | } |
| 1558 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1559 | if (prison_check_ip4(inp->ip_inp.inp.inp_cred, |
| 1560 | &sin->sin_addr) != 0) { |
| 1561 | continue; |
| 1562 | } |
| 1563 | #endif |
| 1564 | if ((ipv4_local_scope == 0) && |
| 1565 | (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) { |
| 1566 | continue; |
| 1567 | } |
| 1568 | #ifdef INET6 |
| 1569 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { |
| 1570 | if (actual + sizeof(struct sockaddr_in6) > limit) { |
| 1571 | return (actual); |
| 1572 | } |
| 1573 | in6_sin_2_v4mapsin6(sin, (struct sockaddr_in6 *)addr); |
| 1574 | ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport; |
| 1575 | addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6)); |
| 1576 | actual += sizeof(struct sockaddr_in6); |
| 1577 | } else { |
| 1578 | #endif |
| 1579 | if (actual + sizeof(struct sockaddr_in) > limit) { |
| 1580 | return (actual); |
| 1581 | } |
| 1582 | memcpy(addr, sin, sizeof(struct sockaddr_in)); |
| 1583 | ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport; |
| 1584 | addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in)); |
| 1585 | actual += sizeof(struct sockaddr_in); |
| 1586 | #ifdef INET6 |
| 1587 | } |
| 1588 | #endif |
| 1589 | } else { |
| 1590 | continue; |
| 1591 | } |
| 1592 | break; |
| 1593 | #endif |
| 1594 | #ifdef INET6 |
| 1595 | case AF_INET6: |
| 1596 | if (ipv6_addr_legal) { |
| 1597 | struct sockaddr_in6 *sin6; |
| 1598 |
| 1599 | #if defined(SCTP_EMBEDDED_V6_SCOPE) && !defined(SCTP_KAME) |
| 1600 | struct sockaddr_in6 lsa6; |
| 1601 | #endif |
| 1602 | sin6 = &sctp_ifa->address.sin6; |
| 1603 | if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 1604 | /* |
| 1605 | * we skip unspecifed |
| 1606 | * addresses |
| 1607 | */ |
| 1608 | continue; |
| 1609 | } |
| 1610 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1611 | if (prison_check_ip6(inp->ip_inp.inp.inp_cred, |
| 1612 | &sin6->sin6_addr) != 0) { |
| 1613 | continue; |
| 1614 | } |
| 1615 | #endif |
| 1616 | if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { |
| 1617 | if (local_scope == 0) |
| 1618 | continue; |
| 1619 | #if defined(SCTP_EMBEDDED_V6_SCOPE) |
| 1620 | if (sin6->sin6_scope_id == 0) { |
| 1621 | #ifdef SCTP_KAME |
| 1622 | if (sa6_recoverscope(sin6) != 0) |
| 1623 | /* |
| 1624 | * bad link |
| 1625 | * local |
| 1626 | * address |
| 1627 | */ |
| 1628 | continue; |
| 1629 | #else |
| 1630 | lsa6 = *sin6; |
| 1631 | if (in6_recoverscope(&lsa6, |
| 1632 | &lsa6.sin6_addr, |
| 1633 | NULL)) |
| 1634 | /* |
| 1635 | * bad link |
| 1636 | * local |
| 1637 | * address |
| 1638 | */ |
| 1639 | continue; |
| 1640 | sin6 = &lsa6; |
| 1641 | #endif /* SCTP_KAME */ |
| 1642 | } |
| 1643 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
| 1644 | } |
| 1645 | if ((site_scope == 0) && |
| 1646 | (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) { |
| 1647 | continue; |
| 1648 | } |
| 1649 | if (actual + sizeof(struct sockaddr_in6) > limit) { |
| 1650 | return (actual); |
| 1651 | } |
| 1652 | memcpy(addr, sin6, sizeof(struct sockaddr_in6)); |
| 1653 | ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport; |
| 1654 | addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_in6)); |
| 1655 | actual += sizeof(struct sockaddr_in6); |
| 1656 | } else { |
| 1657 | continue; |
| 1658 | } |
| 1659 | break; |
| 1660 | #endif |
| 1661 | #if defined(__Userspace__) |
| 1662 | case AF_CONN: |
| 1663 | if (conn_addr_legal) { |
| 1664 | if (actual + sizeof(struct sockaddr_conn) > limit) { |
| 1665 | return (actual); |
| 1666 | } |
| 1667 | memcpy(addr, &sctp_ifa->address.sconn, sizeof(struct sockaddr_conn)); |
| 1668 | ((struct sockaddr_conn *)addr)->sconn_port = inp->sctp_lport; |
| 1669 | addr = (struct sockaddr *)((caddr_t)addr + sizeof(struct sockaddr_conn)); |
| 1670 | actual += sizeof(struct sockaddr_conn); |
| 1671 | } else { |
| 1672 | continue; |
| 1673 | } |
| 1674 | #endif |
| 1675 | default: |
| 1676 | /* TSNH */ |
| 1677 | break; |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | } else { |
| 1682 | struct sctp_laddr *laddr; |
| 1683 | size_t sa_len; |
| 1684 |
| 1685 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
| 1686 | if (stcb) { |
| 1687 | if (sctp_is_addr_restricted(stcb, laddr->ifa)) { |
| 1688 | continue; |
| 1689 | } |
| 1690 | } |
| 1691 | #ifdef HAVE_SA_LEN |
| 1692 | sa_len = laddr->ifa->address.sa.sa_len; |
| 1693 | #else |
| 1694 | switch (laddr->ifa->address.sa.sa_family) { |
| 1695 | #ifdef INET |
| 1696 | case AF_INET: |
| 1697 | sa_len = sizeof(struct sockaddr_in); |
| 1698 | break; |
| 1699 | #endif |
| 1700 | #ifdef INET6 |
| 1701 | case AF_INET6: |
| 1702 | sa_len = sizeof(struct sockaddr_in6); |
| 1703 | break; |
| 1704 | #endif |
| 1705 | #if defined(__Userspace__) |
| 1706 | case AF_CONN: |
| 1707 | sa_len = sizeof(struct sockaddr_conn); |
| 1708 | break; |
| 1709 | #endif |
| 1710 | default: |
| 1711 | /* TSNH */ |
| 1712 | sa_len = 0; |
| 1713 | break; |
| 1714 | } |
| 1715 | #endif |
| 1716 | if (actual + sa_len > limit) { |
| 1717 | return (actual); |
| 1718 | } |
| 1719 | if (sctp_fill_user_address(addr, &laddr->ifa->address.sa)) |
| 1720 | continue; |
| 1721 | switch (laddr->ifa->address.sa.sa_family) { |
| 1722 | #ifdef INET |
| 1723 | case AF_INET: |
| 1724 | ((struct sockaddr_in *)addr)->sin_port = inp->sctp_lport; |
| 1725 | break; |
| 1726 | #endif |
| 1727 | #ifdef INET6 |
| 1728 | case AF_INET6: |
| 1729 | ((struct sockaddr_in6 *)addr)->sin6_port = inp->sctp_lport; |
| 1730 | break; |
| 1731 | #endif |
| 1732 | #if defined(__Userspace__) |
| 1733 | case AF_CONN: |
| 1734 | ((struct sockaddr_conn *)addr)->sconn_port = inp->sctp_lport; |
| 1735 | break; |
| 1736 | #endif |
| 1737 | default: |
| 1738 | /* TSNH */ |
| 1739 | break; |
| 1740 | } |
| 1741 | addr = (struct sockaddr *)((caddr_t)addr + sa_len); |
| 1742 | actual += sa_len; |
| 1743 | } |
| 1744 | } |
| 1745 | return (actual); |
| 1746 | } |
| 1747 |
| 1748 | static size_t |
| 1749 | sctp_fill_up_addresses(struct sctp_inpcb *inp, |
| 1750 | struct sctp_tcb *stcb, |
| 1751 | size_t limit, |
| 1752 | struct sockaddr *addr) |
| 1753 | { |
| 1754 | size_t size = 0; |
| 1755 | #ifdef SCTP_MVRF |
| 1756 | uint32_t id; |
| 1757 | #endif |
| 1758 |
| 1759 | SCTP_IPI_ADDR_RLOCK(); |
| 1760 | #ifdef SCTP_MVRF |
| 1761 | /* |
| 1762 | * FIX ME: ?? this WILL report duplicate addresses if they appear |
| 1763 | * in more than one VRF. |
| 1764 | */ |
| 1765 | /* fill up addresses for all VRFs on the endpoint */ |
| 1766 | for (id = 0; (id < inp->num_vrfs) && (size < limit); id++) { |
| 1767 | size += sctp_fill_up_addresses_vrf(inp, stcb, limit, addr, |
| 1768 | inp->m_vrf_ids[id]); |
| 1769 | addr = (struct sockaddr *)((caddr_t)addr + size); |
| 1770 | } |
| 1771 | #else |
| 1772 | /* fill up addresses for the endpoint's default vrf */ |
| 1773 | size = sctp_fill_up_addresses_vrf(inp, stcb, limit, addr, |
| 1774 | inp->def_vrf_id); |
| 1775 | #endif |
| 1776 | SCTP_IPI_ADDR_RUNLOCK(); |
| 1777 | return (size); |
| 1778 | } |
| 1779 |
| 1780 | static int |
| 1781 | sctp_count_max_addresses_vrf(struct sctp_inpcb *inp, uint32_t vrf_id) |
| 1782 | { |
| 1783 | int cnt = 0; |
| 1784 | struct sctp_vrf *vrf = NULL; |
| 1785 |
| 1786 | /* |
| 1787 | * In both sub-set bound an bound_all cases we return the MAXIMUM |
| 1788 | * number of addresses that you COULD get. In reality the sub-set |
| 1789 | * bound may have an exclusion list for a given TCB OR in the |
| 1790 | * bound-all case a TCB may NOT include the loopback or other |
| 1791 | * addresses as well. |
| 1792 | */ |
| 1793 | SCTP_IPI_ADDR_LOCK_ASSERT(); |
| 1794 | vrf = sctp_find_vrf(vrf_id); |
| 1795 | if (vrf == NULL) { |
| 1796 | return (0); |
| 1797 | } |
| 1798 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
| 1799 | struct sctp_ifn *sctp_ifn; |
| 1800 | struct sctp_ifa *sctp_ifa; |
| 1801 |
| 1802 | LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { |
| 1803 | LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { |
| 1804 | /* Count them if they are the right type */ |
| 1805 | switch (sctp_ifa->address.sa.sa_family) { |
| 1806 | #ifdef INET |
| 1807 | case AF_INET: |
| 1808 | #ifdef INET6 |
| 1809 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) |
| 1810 | cnt += sizeof(struct sockaddr_in6); |
| 1811 | else |
| 1812 | cnt += sizeof(struct sockaddr_in); |
| 1813 | #else |
| 1814 | cnt += sizeof(struct sockaddr_in); |
| 1815 | #endif |
| 1816 | break; |
| 1817 | #endif |
| 1818 | #ifdef INET6 |
| 1819 | case AF_INET6: |
| 1820 | cnt += sizeof(struct sockaddr_in6); |
| 1821 | break; |
| 1822 | #endif |
| 1823 | #if defined(__Userspace__) |
| 1824 | case AF_CONN: |
| 1825 | cnt += sizeof(struct sockaddr_conn); |
| 1826 | break; |
| 1827 | #endif |
| 1828 | default: |
| 1829 | break; |
| 1830 | } |
| 1831 | } |
| 1832 | } |
| 1833 | } else { |
| 1834 | struct sctp_laddr *laddr; |
| 1835 |
| 1836 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
| 1837 | switch (laddr->ifa->address.sa.sa_family) { |
| 1838 | #ifdef INET |
| 1839 | case AF_INET: |
| 1840 | #ifdef INET6 |
| 1841 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) |
| 1842 | cnt += sizeof(struct sockaddr_in6); |
| 1843 | else |
| 1844 | cnt += sizeof(struct sockaddr_in); |
| 1845 | #else |
| 1846 | cnt += sizeof(struct sockaddr_in); |
| 1847 | #endif |
| 1848 | break; |
| 1849 | #endif |
| 1850 | #ifdef INET6 |
| 1851 | case AF_INET6: |
| 1852 | cnt += sizeof(struct sockaddr_in6); |
| 1853 | break; |
| 1854 | #endif |
| 1855 | #if defined(__Userspace__) |
| 1856 | case AF_CONN: |
| 1857 | cnt += sizeof(struct sockaddr_conn); |
| 1858 | break; |
| 1859 | #endif |
| 1860 | default: |
| 1861 | break; |
| 1862 | } |
| 1863 | } |
| 1864 | } |
| 1865 | return (cnt); |
| 1866 | } |
| 1867 |
| 1868 | static int |
| 1869 | sctp_count_max_addresses(struct sctp_inpcb *inp) |
| 1870 | { |
| 1871 | int cnt = 0; |
| 1872 | #ifdef SCTP_MVRF |
| 1873 | int id; |
| 1874 | #endif |
| 1875 |
| 1876 | SCTP_IPI_ADDR_RLOCK(); |
| 1877 | #ifdef SCTP_MVRF |
| 1878 | /* |
| 1879 | * FIX ME: ?? this WILL count duplicate addresses if they appear |
| 1880 | * in more than one VRF. |
| 1881 | */ |
| 1882 | /* count addresses for all VRFs on the endpoint */ |
| 1883 | for (id = 0; id < inp->num_vrfs; id++) { |
| 1884 | cnt += sctp_count_max_addresses_vrf(inp, inp->m_vrf_ids[id]); |
| 1885 | } |
| 1886 | #else |
| 1887 | /* count addresses for the endpoint's default VRF */ |
| 1888 | cnt = sctp_count_max_addresses_vrf(inp, inp->def_vrf_id); |
| 1889 | #endif |
| 1890 | SCTP_IPI_ADDR_RUNLOCK(); |
| 1891 | return (cnt); |
| 1892 | } |
| 1893 |
| 1894 | static int |
| 1895 | sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval, |
| 1896 | size_t optsize, void *p, int delay) |
| 1897 | { |
| 1898 | int error; |
| 1899 | int creat_lock_on = 0; |
| 1900 | struct sctp_tcb *stcb = NULL; |
| 1901 | struct sockaddr *sa; |
| 1902 | unsigned int num_v6 = 0, num_v4 = 0, *totaddrp, totaddr; |
| 1903 | uint32_t vrf_id; |
| 1904 | sctp_assoc_t *a_id; |
| 1905 |
| 1906 | SCTPDBG(SCTP_DEBUG_PCB1, "Connectx called\n"); |
| 1907 |
| 1908 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && |
| 1909 | (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { |
| 1910 | /* We are already connected AND the TCP model */ |
| 1911 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); |
| 1912 | return (EADDRINUSE); |
| 1913 | } |
| 1914 |
| 1915 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) && |
| 1916 | (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) { |
| 1917 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 1918 | return (EINVAL); |
| 1919 | } |
| 1920 |
| 1921 | if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { |
| 1922 | SCTP_INP_RLOCK(inp); |
| 1923 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 1924 | SCTP_INP_RUNLOCK(inp); |
| 1925 | } |
| 1926 | if (stcb) { |
| 1927 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 1928 | return (EALREADY); |
| 1929 | } |
| 1930 | SCTP_INP_INCR_REF(inp); |
| 1931 | SCTP_ASOC_CREATE_LOCK(inp); |
| 1932 | creat_lock_on = 1; |
| 1933 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || |
| 1934 | (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { |
| 1935 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT); |
| 1936 | error = EFAULT; |
| 1937 | goto out_now; |
| 1938 | } |
| 1939 | totaddrp = (unsigned int *)optval; |
| 1940 | totaddr = *totaddrp; |
| 1941 | sa = (struct sockaddr *)(totaddrp + 1); |
| 1942 | error = sctp_connectx_helper_find(inp, sa, totaddr, &num_v4, &num_v6, (unsigned int)(optsize - sizeof(int))); |
| 1943 | if (error != 0) { |
| 1944 | /* Already have or am bring up an association */ |
| 1945 | SCTP_ASOC_CREATE_UNLOCK(inp); |
| 1946 | creat_lock_on = 0; |
| 1947 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 1948 | goto out_now; |
| 1949 | } |
| 1950 | #ifdef INET6 |
| 1951 | if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && |
| 1952 | (num_v6 > 0)) { |
| 1953 | error = EINVAL; |
| 1954 | goto out_now; |
| 1955 | } |
| 1956 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && |
| 1957 | (num_v4 > 0)) { |
| 1958 | if (SCTP_IPV6_V6ONLY(inp)) { |
| 1959 | /* |
| 1960 | * if IPV6_V6ONLY flag, ignore connections destined |
| 1961 | * to a v4 addr or v4-mapped addr |
| 1962 | */ |
| 1963 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 1964 | error = EINVAL; |
| 1965 | goto out_now; |
| 1966 | } |
| 1967 | } |
| 1968 | #endif /* INET6 */ |
| 1969 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == |
| 1970 | SCTP_PCB_FLAGS_UNBOUND) { |
| 1971 | /* Bind a ephemeral port */ |
| 1972 | error = sctp_inpcb_bind(so, NULL, NULL, p); |
| 1973 | if (error) { |
| 1974 | goto out_now; |
| 1975 | } |
| 1976 | } |
| 1977 |
| 1978 | /* FIX ME: do we want to pass in a vrf on the connect call? */ |
| 1979 | vrf_id = inp->def_vrf_id; |
| 1980 |
| 1981 | /* We are GOOD to go */ |
| 1982 | stcb = sctp_aloc_assoc_connected(inp, sa, &error, 0, 0, vrf_id, |
| 1983 | inp->sctp_ep.pre_open_stream_count, |
| 1984 | inp->sctp_ep.port, |
| 1985 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 1986 | (struct thread *)p, |
| 1987 | #elif defined(_WIN32) && !defined(__Userspace__) |
| 1988 | (PKTHREAD)p, |
| 1989 | #else |
| 1990 | (struct proc *)p, |
| 1991 | #endif |
| 1992 | SCTP_INITIALIZE_AUTH_PARAMS); |
| 1993 | if (stcb == NULL) { |
| 1994 | /* Gak! no memory */ |
| 1995 | goto out_now; |
| 1996 | } |
| 1997 | SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT); |
| 1998 | /* move to second address */ |
| 1999 | switch (sa->sa_family) { |
| 2000 | #ifdef INET |
| 2001 | case AF_INET: |
| 2002 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in)); |
| 2003 | break; |
| 2004 | #endif |
| 2005 | #ifdef INET6 |
| 2006 | case AF_INET6: |
| 2007 | sa = (struct sockaddr *)((caddr_t)sa + sizeof(struct sockaddr_in6)); |
| 2008 | break; |
| 2009 | #endif |
| 2010 | default: |
| 2011 | break; |
| 2012 | } |
| 2013 |
| 2014 | error = 0; |
| 2015 | sctp_connectx_helper_add(stcb, sa, (totaddr-1), &error); |
| 2016 | /* Fill in the return id */ |
| 2017 | if (error) { |
| 2018 | goto out_now; |
| 2019 | } |
| 2020 | a_id = (sctp_assoc_t *)optval; |
| 2021 | *a_id = sctp_get_associd(stcb); |
| 2022 |
| 2023 | if (delay) { |
| 2024 | /* doing delayed connection */ |
| 2025 | stcb->asoc.delayed_connection = 1; |
| 2026 | sctp_timer_start(SCTP_TIMER_TYPE_INIT, inp, stcb, stcb->asoc.primary_destination); |
| 2027 | } else { |
| 2028 | (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); |
| 2029 | sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); |
| 2030 | } |
| 2031 | SCTP_TCB_UNLOCK(stcb); |
| 2032 | out_now: |
| 2033 | if (creat_lock_on) { |
| 2034 | SCTP_ASOC_CREATE_UNLOCK(inp); |
| 2035 | } |
| 2036 | SCTP_INP_DECR_REF(inp); |
| 2037 | return (error); |
| 2038 | } |
| 2039 |
| 2040 | #define SCTP_FIND_STCB(inp, stcb, assoc_id) { \ |
| 2041 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||\ |
| 2042 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { \ |
| 2043 | SCTP_INP_RLOCK(inp); \ |
| 2044 | stcb = LIST_FIRST(&inp->sctp_asoc_list); \ |
| 2045 | if (stcb) { \ |
| 2046 | SCTP_TCB_LOCK(stcb); \ |
| 2047 | } \ |
| 2048 | SCTP_INP_RUNLOCK(inp); \ |
| 2049 | } else if (assoc_id > SCTP_ALL_ASSOC) { \ |
| 2050 | stcb = sctp_findassociation_ep_asocid(inp, assoc_id, 1); \ |
| 2051 | if (stcb == NULL) { \ |
| 2052 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); \ |
| 2053 | error = ENOENT; \ |
| 2054 | break; \ |
| 2055 | } \ |
| 2056 | } else { \ |
| 2057 | stcb = NULL; \ |
| 2058 | } \ |
| 2059 | } |
| 2060 |
| 2061 | #define SCTP_CHECK_AND_CAST(destp, srcp, type, size) {\ |
| 2062 | if (size < sizeof(type)) { \ |
| 2063 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); \ |
| 2064 | error = EINVAL; \ |
| 2065 | break; \ |
| 2066 | } else { \ |
| 2067 | destp = (type *)srcp; \ |
| 2068 | } \ |
| 2069 | } |
| 2070 |
| 2071 | #if defined(__Userspace__) |
| 2072 | int |
| 2073 | #else |
| 2074 | static int |
| 2075 | #endif |
| 2076 | sctp_getopt(struct socket *so, int optname, void *optval, size_t *optsize, |
| 2077 | void *p) { |
| 2078 | struct sctp_inpcb *inp = NULL; |
| 2079 | int error, val = 0; |
| 2080 | struct sctp_tcb *stcb = NULL; |
| 2081 |
| 2082 | if (optval == NULL) { |
| 2083 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2084 | return (EINVAL); |
| 2085 | } |
| 2086 |
| 2087 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 2088 | if (inp == NULL) { |
| 2089 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2090 | return EINVAL; |
| 2091 | } |
| 2092 | error = 0; |
| 2093 |
| 2094 | switch (optname) { |
| 2095 | case SCTP_NODELAY: |
| 2096 | case SCTP_AUTOCLOSE: |
| 2097 | case SCTP_EXPLICIT_EOR: |
| 2098 | case SCTP_AUTO_ASCONF: |
| 2099 | case SCTP_DISABLE_FRAGMENTS: |
| 2100 | case SCTP_I_WANT_MAPPED_V4_ADDR: |
| 2101 | case SCTP_USE_EXT_RCVINFO: |
| 2102 | SCTP_INP_RLOCK(inp); |
| 2103 | switch (optname) { |
| 2104 | case SCTP_DISABLE_FRAGMENTS: |
| 2105 | val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NO_FRAGMENT); |
| 2106 | break; |
| 2107 | case SCTP_I_WANT_MAPPED_V4_ADDR: |
| 2108 | val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4); |
| 2109 | break; |
| 2110 | case SCTP_AUTO_ASCONF: |
| 2111 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
| 2112 | /* only valid for bound all sockets */ |
| 2113 | val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF); |
| 2114 | } else { |
| 2115 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2116 | error = EINVAL; |
| 2117 | goto flags_out; |
| 2118 | } |
| 2119 | break; |
| 2120 | case SCTP_EXPLICIT_EOR: |
| 2121 | val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR); |
| 2122 | break; |
| 2123 | case SCTP_NODELAY: |
| 2124 | val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NODELAY); |
| 2125 | break; |
| 2126 | case SCTP_USE_EXT_RCVINFO: |
| 2127 | val = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO); |
| 2128 | break; |
| 2129 | case SCTP_AUTOCLOSE: |
| 2130 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE)) |
| 2131 | val = sctp_ticks_to_secs(inp->sctp_ep.auto_close_time); |
| 2132 | else |
| 2133 | val = 0; |
| 2134 | break; |
| 2135 |
| 2136 | default: |
| 2137 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); |
| 2138 | error = ENOPROTOOPT; |
| 2139 | } /* end switch (sopt->sopt_name) */ |
| 2140 | if (*optsize < sizeof(val)) { |
| 2141 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2142 | error = EINVAL; |
| 2143 | } |
| 2144 | flags_out: |
| 2145 | SCTP_INP_RUNLOCK(inp); |
| 2146 | if (error == 0) { |
| 2147 | /* return the option value */ |
| 2148 | *(int *)optval = val; |
| 2149 | *optsize = sizeof(val); |
| 2150 | } |
| 2151 | break; |
| 2152 | case SCTP_GET_PACKET_LOG: |
| 2153 | { |
| 2154 | #ifdef SCTP_PACKET_LOGGING |
| 2155 | uint8_t *target; |
| 2156 | int ret; |
| 2157 |
| 2158 | SCTP_CHECK_AND_CAST(target, optval, uint8_t, *optsize); |
| 2159 | ret = sctp_copy_out_packet_log(target , (int)*optsize); |
| 2160 | *optsize = ret; |
| 2161 | #else |
| 2162 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 2163 | error = EOPNOTSUPP; |
| 2164 | #endif |
| 2165 | break; |
| 2166 | } |
| 2167 | case SCTP_REUSE_PORT: |
| 2168 | { |
| 2169 | uint32_t *value; |
| 2170 |
| 2171 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) { |
| 2172 | /* Can't do this for a 1-m socket */ |
| 2173 | error = EINVAL; |
| 2174 | break; |
| 2175 | } |
| 2176 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2177 | *value = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE); |
| 2178 | *optsize = sizeof(uint32_t); |
| 2179 | break; |
| 2180 | } |
| 2181 | case SCTP_PARTIAL_DELIVERY_POINT: |
| 2182 | { |
| 2183 | uint32_t *value; |
| 2184 |
| 2185 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2186 | *value = inp->partial_delivery_point; |
| 2187 | *optsize = sizeof(uint32_t); |
| 2188 | break; |
| 2189 | } |
| 2190 | case SCTP_FRAGMENT_INTERLEAVE: |
| 2191 | { |
| 2192 | uint32_t *value; |
| 2193 |
| 2194 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2195 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) { |
| 2196 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) { |
| 2197 | *value = SCTP_FRAG_LEVEL_2; |
| 2198 | } else { |
| 2199 | *value = SCTP_FRAG_LEVEL_1; |
| 2200 | } |
| 2201 | } else { |
| 2202 | *value = SCTP_FRAG_LEVEL_0; |
| 2203 | } |
| 2204 | *optsize = sizeof(uint32_t); |
| 2205 | break; |
| 2206 | } |
| 2207 | case SCTP_INTERLEAVING_SUPPORTED: |
| 2208 | { |
| 2209 | struct sctp_assoc_value *av; |
| 2210 |
| 2211 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2212 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2213 |
| 2214 | if (stcb) { |
| 2215 | av->assoc_value = stcb->asoc.idata_supported; |
| 2216 | SCTP_TCB_UNLOCK(stcb); |
| 2217 | } else { |
| 2218 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2219 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2220 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2221 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2222 | SCTP_INP_RLOCK(inp); |
| 2223 | if (inp->idata_supported) { |
| 2224 | av->assoc_value = 1; |
| 2225 | } else { |
| 2226 | av->assoc_value = 0; |
| 2227 | } |
| 2228 | SCTP_INP_RUNLOCK(inp); |
| 2229 | } else { |
| 2230 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2231 | error = EINVAL; |
| 2232 | } |
| 2233 | } |
| 2234 | if (error == 0) { |
| 2235 | *optsize = sizeof(struct sctp_assoc_value); |
| 2236 | } |
| 2237 | break; |
| 2238 | } |
| 2239 | case SCTP_CMT_ON_OFF: |
| 2240 | { |
| 2241 | struct sctp_assoc_value *av; |
| 2242 |
| 2243 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2244 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2245 | if (stcb) { |
| 2246 | av->assoc_value = stcb->asoc.sctp_cmt_on_off; |
| 2247 | SCTP_TCB_UNLOCK(stcb); |
| 2248 | } else { |
| 2249 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2250 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2251 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2252 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2253 | SCTP_INP_RLOCK(inp); |
| 2254 | av->assoc_value = inp->sctp_cmt_on_off; |
| 2255 | SCTP_INP_RUNLOCK(inp); |
| 2256 | } else { |
| 2257 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2258 | error = EINVAL; |
| 2259 | } |
| 2260 | } |
| 2261 | if (error == 0) { |
| 2262 | *optsize = sizeof(struct sctp_assoc_value); |
| 2263 | } |
| 2264 | break; |
| 2265 | } |
| 2266 | case SCTP_PLUGGABLE_CC: |
| 2267 | { |
| 2268 | struct sctp_assoc_value *av; |
| 2269 |
| 2270 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2271 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2272 | if (stcb) { |
| 2273 | av->assoc_value = stcb->asoc.congestion_control_module; |
| 2274 | SCTP_TCB_UNLOCK(stcb); |
| 2275 | } else { |
| 2276 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2277 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2278 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2279 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2280 | SCTP_INP_RLOCK(inp); |
| 2281 | av->assoc_value = inp->sctp_ep.sctp_default_cc_module; |
| 2282 | SCTP_INP_RUNLOCK(inp); |
| 2283 | } else { |
| 2284 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2285 | error = EINVAL; |
| 2286 | } |
| 2287 | } |
| 2288 | if (error == 0) { |
| 2289 | *optsize = sizeof(struct sctp_assoc_value); |
| 2290 | } |
| 2291 | break; |
| 2292 | } |
| 2293 | case SCTP_CC_OPTION: |
| 2294 | { |
| 2295 | struct sctp_cc_option *cc_opt; |
| 2296 |
| 2297 | SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, *optsize); |
| 2298 | SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id); |
| 2299 | if (stcb == NULL) { |
| 2300 | error = EINVAL; |
| 2301 | } else { |
| 2302 | if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) { |
| 2303 | error = ENOTSUP; |
| 2304 | } else { |
| 2305 | error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 0, cc_opt); |
| 2306 | *optsize = sizeof(struct sctp_cc_option); |
| 2307 | } |
| 2308 | SCTP_TCB_UNLOCK(stcb); |
| 2309 | } |
| 2310 | break; |
| 2311 | } |
| 2312 | case SCTP_PLUGGABLE_SS: |
| 2313 | { |
| 2314 | struct sctp_assoc_value *av; |
| 2315 |
| 2316 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2317 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2318 | if (stcb) { |
| 2319 | av->assoc_value = stcb->asoc.stream_scheduling_module; |
| 2320 | SCTP_TCB_UNLOCK(stcb); |
| 2321 | } else { |
| 2322 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2323 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2324 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2325 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2326 | SCTP_INP_RLOCK(inp); |
| 2327 | av->assoc_value = inp->sctp_ep.sctp_default_ss_module; |
| 2328 | SCTP_INP_RUNLOCK(inp); |
| 2329 | } else { |
| 2330 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2331 | error = EINVAL; |
| 2332 | } |
| 2333 | } |
| 2334 | if (error == 0) { |
| 2335 | *optsize = sizeof(struct sctp_assoc_value); |
| 2336 | } |
| 2337 | break; |
| 2338 | } |
| 2339 | case SCTP_SS_VALUE: |
| 2340 | { |
| 2341 | struct sctp_stream_value *av; |
| 2342 |
| 2343 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, *optsize); |
| 2344 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2345 | if (stcb) { |
| 2346 | if ((av->stream_id >= stcb->asoc.streamoutcnt) || |
| 2347 | (stcb->asoc.ss_functions.sctp_ss_get_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id], |
| 2348 | &av->stream_value) < 0)) { |
| 2349 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2350 | error = EINVAL; |
| 2351 | } else { |
| 2352 | *optsize = sizeof(struct sctp_stream_value); |
| 2353 | } |
| 2354 | SCTP_TCB_UNLOCK(stcb); |
| 2355 | } else { |
| 2356 | /* Can't get stream value without association */ |
| 2357 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2358 | error = EINVAL; |
| 2359 | } |
| 2360 | break; |
| 2361 | } |
| 2362 | case SCTP_GET_ADDR_LEN: |
| 2363 | { |
| 2364 | struct sctp_assoc_value *av; |
| 2365 |
| 2366 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2367 | error = EINVAL; |
| 2368 | #ifdef INET |
| 2369 | if (av->assoc_value == AF_INET) { |
| 2370 | av->assoc_value = sizeof(struct sockaddr_in); |
| 2371 | error = 0; |
| 2372 | } |
| 2373 | #endif |
| 2374 | #ifdef INET6 |
| 2375 | if (av->assoc_value == AF_INET6) { |
| 2376 | av->assoc_value = sizeof(struct sockaddr_in6); |
| 2377 | error = 0; |
| 2378 | } |
| 2379 | #endif |
| 2380 | #if defined(__Userspace__) |
| 2381 | if (av->assoc_value == AF_CONN) { |
| 2382 | av->assoc_value = sizeof(struct sockaddr_conn); |
| 2383 | error = 0; |
| 2384 | } |
| 2385 | #endif |
| 2386 | if (error) { |
| 2387 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2388 | } else { |
| 2389 | *optsize = sizeof(struct sctp_assoc_value); |
| 2390 | } |
| 2391 | break; |
| 2392 | } |
| 2393 | case SCTP_GET_ASSOC_NUMBER: |
| 2394 | { |
| 2395 | uint32_t *value, cnt; |
| 2396 |
| 2397 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2398 | SCTP_INP_RLOCK(inp); |
| 2399 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2400 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 2401 | /* Can't do this for a 1-1 socket */ |
| 2402 | error = EINVAL; |
| 2403 | SCTP_INP_RUNLOCK(inp); |
| 2404 | break; |
| 2405 | } |
| 2406 | cnt = 0; |
| 2407 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 2408 | cnt++; |
| 2409 | } |
| 2410 | SCTP_INP_RUNLOCK(inp); |
| 2411 | *value = cnt; |
| 2412 | *optsize = sizeof(uint32_t); |
| 2413 | break; |
| 2414 | } |
| 2415 | case SCTP_GET_ASSOC_ID_LIST: |
| 2416 | { |
| 2417 | struct sctp_assoc_ids *ids; |
| 2418 | uint32_t at; |
| 2419 | size_t limit; |
| 2420 |
| 2421 | SCTP_CHECK_AND_CAST(ids, optval, struct sctp_assoc_ids, *optsize); |
| 2422 | SCTP_INP_RLOCK(inp); |
| 2423 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2424 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 2425 | /* Can't do this for a 1-1 socket */ |
| 2426 | error = EINVAL; |
| 2427 | SCTP_INP_RUNLOCK(inp); |
| 2428 | break; |
| 2429 | } |
| 2430 | at = 0; |
| 2431 | limit = (*optsize - sizeof(uint32_t)) / sizeof(sctp_assoc_t); |
| 2432 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 2433 | if (at < limit) { |
| 2434 | ids->gaids_assoc_id[at++] = sctp_get_associd(stcb); |
| 2435 | if (at == 0) { |
| 2436 | error = EINVAL; |
| 2437 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2438 | break; |
| 2439 | } |
| 2440 | } else { |
| 2441 | error = EINVAL; |
| 2442 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2443 | break; |
| 2444 | } |
| 2445 | } |
| 2446 | SCTP_INP_RUNLOCK(inp); |
| 2447 | if (error == 0) { |
| 2448 | ids->gaids_number_of_ids = at; |
| 2449 | *optsize = ((at * sizeof(sctp_assoc_t)) + sizeof(uint32_t)); |
| 2450 | } |
| 2451 | break; |
| 2452 | } |
| 2453 | case SCTP_CONTEXT: |
| 2454 | { |
| 2455 | struct sctp_assoc_value *av; |
| 2456 |
| 2457 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2458 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2459 |
| 2460 | if (stcb) { |
| 2461 | av->assoc_value = stcb->asoc.context; |
| 2462 | SCTP_TCB_UNLOCK(stcb); |
| 2463 | } else { |
| 2464 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2465 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2466 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2467 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2468 | SCTP_INP_RLOCK(inp); |
| 2469 | av->assoc_value = inp->sctp_context; |
| 2470 | SCTP_INP_RUNLOCK(inp); |
| 2471 | } else { |
| 2472 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2473 | error = EINVAL; |
| 2474 | } |
| 2475 | } |
| 2476 | if (error == 0) { |
| 2477 | *optsize = sizeof(struct sctp_assoc_value); |
| 2478 | } |
| 2479 | break; |
| 2480 | } |
| 2481 | case SCTP_VRF_ID: |
| 2482 | { |
| 2483 | uint32_t *default_vrfid; |
| 2484 |
| 2485 | SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, *optsize); |
| 2486 | *default_vrfid = inp->def_vrf_id; |
| 2487 | *optsize = sizeof(uint32_t); |
| 2488 | break; |
| 2489 | } |
| 2490 | case SCTP_GET_ASOC_VRF: |
| 2491 | { |
| 2492 | struct sctp_assoc_value *id; |
| 2493 |
| 2494 | SCTP_CHECK_AND_CAST(id, optval, struct sctp_assoc_value, *optsize); |
| 2495 | SCTP_FIND_STCB(inp, stcb, id->assoc_id); |
| 2496 | if (stcb == NULL) { |
| 2497 | error = EINVAL; |
| 2498 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2499 | } else { |
| 2500 | id->assoc_value = stcb->asoc.vrf_id; |
| 2501 | SCTP_TCB_UNLOCK(stcb); |
| 2502 | *optsize = sizeof(struct sctp_assoc_value); |
| 2503 | } |
| 2504 | break; |
| 2505 | } |
| 2506 | case SCTP_GET_VRF_IDS: |
| 2507 | { |
| 2508 | #ifdef SCTP_MVRF |
| 2509 | int siz_needed; |
| 2510 | uint32_t *vrf_ids; |
| 2511 |
| 2512 | SCTP_CHECK_AND_CAST(vrf_ids, optval, uint32_t, *optsize); |
| 2513 | siz_needed = inp->num_vrfs * sizeof(uint32_t); |
| 2514 | if (*optsize < siz_needed) { |
| 2515 | error = EINVAL; |
| 2516 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2517 | } else { |
| 2518 | memcpy(vrf_ids, inp->m_vrf_ids, siz_needed); |
| 2519 | *optsize = siz_needed; |
| 2520 | } |
| 2521 | #else |
| 2522 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 2523 | error = EOPNOTSUPP; |
| 2524 | #endif |
| 2525 | break; |
| 2526 | } |
| 2527 | case SCTP_GET_NONCE_VALUES: |
| 2528 | { |
| 2529 | struct sctp_get_nonce_values *gnv; |
| 2530 |
| 2531 | SCTP_CHECK_AND_CAST(gnv, optval, struct sctp_get_nonce_values, *optsize); |
| 2532 | SCTP_FIND_STCB(inp, stcb, gnv->gn_assoc_id); |
| 2533 |
| 2534 | if (stcb) { |
| 2535 | gnv->gn_peers_tag = stcb->asoc.peer_vtag; |
| 2536 | gnv->gn_local_tag = stcb->asoc.my_vtag; |
| 2537 | SCTP_TCB_UNLOCK(stcb); |
| 2538 | *optsize = sizeof(struct sctp_get_nonce_values); |
| 2539 | } else { |
| 2540 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); |
| 2541 | error = ENOTCONN; |
| 2542 | } |
| 2543 | break; |
| 2544 | } |
| 2545 | case SCTP_DELAYED_SACK: |
| 2546 | { |
| 2547 | struct sctp_sack_info *sack; |
| 2548 |
| 2549 | SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, *optsize); |
| 2550 | SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id); |
| 2551 | if (stcb) { |
| 2552 | sack->sack_delay = stcb->asoc.delayed_ack; |
| 2553 | sack->sack_freq = stcb->asoc.sack_freq; |
| 2554 | SCTP_TCB_UNLOCK(stcb); |
| 2555 | } else { |
| 2556 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2557 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2558 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2559 | (sack->sack_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2560 | SCTP_INP_RLOCK(inp); |
| 2561 | sack->sack_delay = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]); |
| 2562 | sack->sack_freq = inp->sctp_ep.sctp_sack_freq; |
| 2563 | SCTP_INP_RUNLOCK(inp); |
| 2564 | } else { |
| 2565 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2566 | error = EINVAL; |
| 2567 | } |
| 2568 | } |
| 2569 | if (error == 0) { |
| 2570 | *optsize = sizeof(struct sctp_sack_info); |
| 2571 | } |
| 2572 | break; |
| 2573 | } |
| 2574 | case SCTP_GET_SNDBUF_USE: |
| 2575 | { |
| 2576 | struct sctp_sockstat *ss; |
| 2577 |
| 2578 | SCTP_CHECK_AND_CAST(ss, optval, struct sctp_sockstat, *optsize); |
| 2579 | SCTP_FIND_STCB(inp, stcb, ss->ss_assoc_id); |
| 2580 |
| 2581 | if (stcb) { |
| 2582 | ss->ss_total_sndbuf = stcb->asoc.total_output_queue_size; |
| 2583 | ss->ss_total_recv_buf = (stcb->asoc.size_on_reasm_queue + |
| 2584 | stcb->asoc.size_on_all_streams); |
| 2585 | SCTP_TCB_UNLOCK(stcb); |
| 2586 | *optsize = sizeof(struct sctp_sockstat); |
| 2587 | } else { |
| 2588 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); |
| 2589 | error = ENOTCONN; |
| 2590 | } |
| 2591 | break; |
| 2592 | } |
| 2593 | case SCTP_MAX_BURST: |
| 2594 | { |
| 2595 | struct sctp_assoc_value *av; |
| 2596 |
| 2597 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2598 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2599 |
| 2600 | if (stcb) { |
| 2601 | av->assoc_value = stcb->asoc.max_burst; |
| 2602 | SCTP_TCB_UNLOCK(stcb); |
| 2603 | } else { |
| 2604 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2605 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2606 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2607 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2608 | SCTP_INP_RLOCK(inp); |
| 2609 | av->assoc_value = inp->sctp_ep.max_burst; |
| 2610 | SCTP_INP_RUNLOCK(inp); |
| 2611 | } else { |
| 2612 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2613 | error = EINVAL; |
| 2614 | } |
| 2615 | } |
| 2616 | if (error == 0) { |
| 2617 | *optsize = sizeof(struct sctp_assoc_value); |
| 2618 | } |
| 2619 | break; |
| 2620 | } |
| 2621 | case SCTP_MAXSEG: |
| 2622 | { |
| 2623 | struct sctp_assoc_value *av; |
| 2624 | int ovh; |
| 2625 |
| 2626 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 2627 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 2628 |
| 2629 | if (stcb) { |
| 2630 | av->assoc_value = sctp_get_frag_point(stcb, &stcb->asoc); |
| 2631 | SCTP_TCB_UNLOCK(stcb); |
| 2632 | } else { |
| 2633 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 2634 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 2635 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 2636 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 2637 | SCTP_INP_RLOCK(inp); |
| 2638 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
| 2639 | ovh = SCTP_MED_OVERHEAD; |
| 2640 | } else { |
| 2641 | ovh = SCTP_MED_V4_OVERHEAD; |
| 2642 | } |
| 2643 | if (inp->sctp_frag_point >= SCTP_DEFAULT_MAXSEGMENT) |
| 2644 | av->assoc_value = 0; |
| 2645 | else |
| 2646 | av->assoc_value = inp->sctp_frag_point - ovh; |
| 2647 | SCTP_INP_RUNLOCK(inp); |
| 2648 | } else { |
| 2649 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 2650 | error = EINVAL; |
| 2651 | } |
| 2652 | } |
| 2653 | if (error == 0) { |
| 2654 | *optsize = sizeof(struct sctp_assoc_value); |
| 2655 | } |
| 2656 | break; |
| 2657 | } |
| 2658 | case SCTP_GET_STAT_LOG: |
| 2659 | error = sctp_fill_stat_log(optval, optsize); |
| 2660 | break; |
| 2661 | case SCTP_EVENTS: |
| 2662 | { |
| 2663 | struct sctp_event_subscribe *events; |
| 2664 |
| 2665 | SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, *optsize); |
| 2666 | memset(events, 0, sizeof(struct sctp_event_subscribe)); |
| 2667 | SCTP_INP_RLOCK(inp); |
| 2668 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) |
| 2669 | events->sctp_data_io_event = 1; |
| 2670 |
| 2671 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT)) |
| 2672 | events->sctp_association_event = 1; |
| 2673 |
| 2674 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT)) |
| 2675 | events->sctp_address_event = 1; |
| 2676 |
| 2677 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT)) |
| 2678 | events->sctp_send_failure_event = 1; |
| 2679 |
| 2680 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR)) |
| 2681 | events->sctp_peer_error_event = 1; |
| 2682 |
| 2683 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT)) |
| 2684 | events->sctp_shutdown_event = 1; |
| 2685 |
| 2686 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT)) |
| 2687 | events->sctp_partial_delivery_event = 1; |
| 2688 |
| 2689 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT)) |
| 2690 | events->sctp_adaptation_layer_event = 1; |
| 2691 |
| 2692 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT)) |
| 2693 | events->sctp_authentication_event = 1; |
| 2694 |
| 2695 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT)) |
| 2696 | events->sctp_sender_dry_event = 1; |
| 2697 |
| 2698 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT)) |
| 2699 | events->sctp_stream_reset_event = 1; |
| 2700 | SCTP_INP_RUNLOCK(inp); |
| 2701 | *optsize = sizeof(struct sctp_event_subscribe); |
| 2702 | break; |
| 2703 | } |
| 2704 | case SCTP_ADAPTATION_LAYER: |
| 2705 | { |
| 2706 | uint32_t *value; |
| 2707 |
| 2708 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2709 |
| 2710 | SCTP_INP_RLOCK(inp); |
| 2711 | *value = inp->sctp_ep.adaptation_layer_indicator; |
| 2712 | SCTP_INP_RUNLOCK(inp); |
| 2713 | *optsize = sizeof(uint32_t); |
| 2714 | break; |
| 2715 | } |
| 2716 | case SCTP_SET_INITIAL_DBG_SEQ: |
| 2717 | { |
| 2718 | uint32_t *value; |
| 2719 |
| 2720 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2721 | SCTP_INP_RLOCK(inp); |
| 2722 | *value = inp->sctp_ep.initial_sequence_debug; |
| 2723 | SCTP_INP_RUNLOCK(inp); |
| 2724 | *optsize = sizeof(uint32_t); |
| 2725 | break; |
| 2726 | } |
| 2727 | case SCTP_GET_LOCAL_ADDR_SIZE: |
| 2728 | { |
| 2729 | uint32_t *value; |
| 2730 |
| 2731 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2732 | SCTP_INP_RLOCK(inp); |
| 2733 | *value = sctp_count_max_addresses(inp); |
| 2734 | SCTP_INP_RUNLOCK(inp); |
| 2735 | *optsize = sizeof(uint32_t); |
| 2736 | break; |
| 2737 | } |
| 2738 | case SCTP_GET_REMOTE_ADDR_SIZE: |
| 2739 | { |
| 2740 | uint32_t *value; |
| 2741 | size_t size; |
| 2742 | struct sctp_nets *net; |
| 2743 |
| 2744 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); |
| 2745 | /* FIXME MT: change to sctp_assoc_value? */ |
| 2746 | SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) *value); |
| 2747 |
| 2748 | if (stcb) { |
| 2749 | size = 0; |
| 2750 | /* Count the sizes */ |
| 2751 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 2752 | switch (net->ro._l_addr.sa.sa_family) { |
| 2753 | #ifdef INET |
| 2754 | case AF_INET: |
| 2755 | #ifdef INET6 |
| 2756 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { |
| 2757 | size += sizeof(struct sockaddr_in6); |
| 2758 | } else { |
| 2759 | size += sizeof(struct sockaddr_in); |
| 2760 | } |
| 2761 | #else |
| 2762 | size += sizeof(struct sockaddr_in); |
| 2763 | #endif |
| 2764 | break; |
| 2765 | #endif |
| 2766 | #ifdef INET6 |
| 2767 | case AF_INET6: |
| 2768 | size += sizeof(struct sockaddr_in6); |
| 2769 | break; |
| 2770 | #endif |
| 2771 | #if defined(__Userspace__) |
| 2772 | case AF_CONN: |
| 2773 | size += sizeof(struct sockaddr_conn); |
| 2774 | break; |
| 2775 | #endif |
| 2776 | default: |
| 2777 | break; |
| 2778 | } |
| 2779 | } |
| 2780 | SCTP_TCB_UNLOCK(stcb); |
| 2781 | *value = (uint32_t) size; |
| 2782 | *optsize = sizeof(uint32_t); |
| 2783 | } else { |
| 2784 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); |
| 2785 | error = ENOTCONN; |
| 2786 | } |
| 2787 | break; |
| 2788 | } |
| 2789 | case SCTP_GET_PEER_ADDRESSES: |
| 2790 | /* |
| 2791 | * Get the address information, an array is passed in to |
| 2792 | * fill up we pack it. |
| 2793 | */ |
| 2794 | { |
| 2795 | size_t cpsz, left; |
| 2796 | struct sockaddr *addr; |
| 2797 | struct sctp_nets *net; |
| 2798 | struct sctp_getaddresses *saddr; |
| 2799 |
| 2800 | SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize); |
| 2801 | SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id); |
| 2802 |
| 2803 | if (stcb) { |
| 2804 | left = *optsize - offsetof(struct sctp_getaddresses, addr); |
| 2805 | *optsize = offsetof(struct sctp_getaddresses, addr); |
| 2806 | addr = &saddr->addr[0].sa; |
| 2807 |
| 2808 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 2809 | switch (net->ro._l_addr.sa.sa_family) { |
| 2810 | #ifdef INET |
| 2811 | case AF_INET: |
| 2812 | #ifdef INET6 |
| 2813 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { |
| 2814 | cpsz = sizeof(struct sockaddr_in6); |
| 2815 | } else { |
| 2816 | cpsz = sizeof(struct sockaddr_in); |
| 2817 | } |
| 2818 | #else |
| 2819 | cpsz = sizeof(struct sockaddr_in); |
| 2820 | #endif |
| 2821 | break; |
| 2822 | #endif |
| 2823 | #ifdef INET6 |
| 2824 | case AF_INET6: |
| 2825 | cpsz = sizeof(struct sockaddr_in6); |
| 2826 | break; |
| 2827 | #endif |
| 2828 | #if defined(__Userspace__) |
| 2829 | case AF_CONN: |
| 2830 | cpsz = sizeof(struct sockaddr_conn); |
| 2831 | break; |
| 2832 | #endif |
| 2833 | default: |
| 2834 | cpsz = 0; |
| 2835 | break; |
| 2836 | } |
| 2837 | if (cpsz == 0) { |
| 2838 | break; |
| 2839 | } |
| 2840 | if (left < cpsz) { |
| 2841 | /* not enough room. */ |
| 2842 | break; |
| 2843 | } |
| 2844 | #if defined(INET) && defined(INET6) |
| 2845 | if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) && |
| 2846 | (net->ro._l_addr.sa.sa_family == AF_INET)) { |
| 2847 | /* Must map the address */ |
| 2848 | in6_sin_2_v4mapsin6(&net->ro._l_addr.sin, |
| 2849 | (struct sockaddr_in6 *)addr); |
| 2850 | } else { |
| 2851 | memcpy(addr, &net->ro._l_addr, cpsz); |
| 2852 | } |
| 2853 | #else |
| 2854 | memcpy(addr, &net->ro._l_addr, cpsz); |
| 2855 | #endif |
| 2856 | ((struct sockaddr_in *)addr)->sin_port = stcb->rport; |
| 2857 |
| 2858 | addr = (struct sockaddr *)((caddr_t)addr + cpsz); |
| 2859 | left -= cpsz; |
| 2860 | *optsize += cpsz; |
| 2861 | } |
| 2862 | SCTP_TCB_UNLOCK(stcb); |
| 2863 | } else { |
| 2864 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 2865 | error = ENOENT; |
| 2866 | } |
| 2867 | break; |
| 2868 | } |
| 2869 | case SCTP_GET_LOCAL_ADDRESSES: |
| 2870 | { |
| 2871 | size_t limit, actual; |
| 2872 | struct sctp_getaddresses *saddr; |
| 2873 |
| 2874 | SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize); |
| 2875 | SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id); |
| 2876 |
| 2877 | limit = *optsize - offsetof(struct sctp_getaddresses, addr); |
| 2878 | actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa); |
| 2879 | if (stcb) { |
| 2880 | SCTP_TCB_UNLOCK(stcb); |
| 2881 | } |
| 2882 | *optsize = offsetof(struct sctp_getaddresses, addr) + actual; |
| 2883 | break; |
| 2884 | } |
| 2885 | case SCTP_PEER_ADDR_PARAMS: |
| 2886 | { |
| 2887 | struct sctp_paddrparams *paddrp; |
| 2888 | struct sctp_nets *net; |
| 2889 | struct sockaddr *addr; |
| 2890 | #if defined(INET) && defined(INET6) |
| 2891 | struct sockaddr_in sin_store; |
| 2892 | #endif |
| 2893 |
| 2894 | SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, *optsize); |
| 2895 | SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id); |
| 2896 |
| 2897 | #if defined(INET) && defined(INET6) |
| 2898 | if (paddrp->spp_address.ss_family == AF_INET6) { |
| 2899 | struct sockaddr_in6 *sin6; |
| 2900 |
| 2901 | sin6 = (struct sockaddr_in6 *)&paddrp->spp_address; |
| 2902 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 2903 | in6_sin6_2_sin(&sin_store, sin6); |
| 2904 | addr = (struct sockaddr *)&sin_store; |
| 2905 | } else { |
| 2906 | addr = (struct sockaddr *)&paddrp->spp_address; |
| 2907 | } |
| 2908 | } else { |
| 2909 | addr = (struct sockaddr *)&paddrp->spp_address; |
| 2910 | } |
| 2911 | #else |
| 2912 | addr = (struct sockaddr *)&paddrp->spp_address; |
| 2913 | #endif |
| 2914 | if (stcb != NULL) { |
| 2915 | net = sctp_findnet(stcb, addr); |
| 2916 | } else { |
| 2917 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 2918 | * do a decrement if it finds the stcb as long as the locked |
| 2919 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 2920 | */ |
| 2921 | net = NULL; |
| 2922 | SCTP_INP_INCR_REF(inp); |
| 2923 | stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL); |
| 2924 | if (stcb == NULL) { |
| 2925 | SCTP_INP_DECR_REF(inp); |
| 2926 | } |
| 2927 | } |
| 2928 | if ((stcb != NULL) && (net == NULL)) { |
| 2929 | #ifdef INET |
| 2930 | if (addr->sa_family == AF_INET) { |
| 2931 | struct sockaddr_in *sin; |
| 2932 |
| 2933 | sin = (struct sockaddr_in *)addr; |
| 2934 | if (sin->sin_addr.s_addr != INADDR_ANY) { |
| 2935 | error = EINVAL; |
| 2936 | SCTP_TCB_UNLOCK(stcb); |
| 2937 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2938 | break; |
| 2939 | } |
| 2940 | } else |
| 2941 | #endif |
| 2942 | #ifdef INET6 |
| 2943 | if (addr->sa_family == AF_INET6) { |
| 2944 | struct sockaddr_in6 *sin6; |
| 2945 |
| 2946 | sin6 = (struct sockaddr_in6 *)addr; |
| 2947 | if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 2948 | error = EINVAL; |
| 2949 | SCTP_TCB_UNLOCK(stcb); |
| 2950 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2951 | break; |
| 2952 | } |
| 2953 | } else |
| 2954 | #endif |
| 2955 | #if defined(__Userspace__) |
| 2956 | if (addr->sa_family == AF_CONN) { |
| 2957 | struct sockaddr_conn *sconn; |
| 2958 |
| 2959 | sconn = (struct sockaddr_conn *)addr; |
| 2960 | if (sconn->sconn_addr != NULL) { |
| 2961 | error = EINVAL; |
| 2962 | SCTP_TCB_UNLOCK(stcb); |
| 2963 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2964 | break; |
| 2965 | } |
| 2966 | } else |
| 2967 | #endif |
| 2968 | { |
| 2969 | error = EAFNOSUPPORT; |
| 2970 | SCTP_TCB_UNLOCK(stcb); |
| 2971 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 2972 | break; |
| 2973 | } |
| 2974 | } |
| 2975 |
| 2976 | if (stcb != NULL) { |
| 2977 | /* Applies to the specific association */ |
| 2978 | paddrp->spp_flags = 0; |
| 2979 | if (net != NULL) { |
| 2980 | paddrp->spp_hbinterval = net->heart_beat_delay; |
| 2981 | paddrp->spp_pathmaxrxt = net->failure_threshold; |
| 2982 | paddrp->spp_pathmtu = net->mtu; |
| 2983 | switch (net->ro._l_addr.sa.sa_family) { |
| 2984 | #ifdef INET |
| 2985 | case AF_INET: |
| 2986 | paddrp->spp_pathmtu -= SCTP_MIN_V4_OVERHEAD; |
| 2987 | break; |
| 2988 | #endif |
| 2989 | #ifdef INET6 |
| 2990 | case AF_INET6: |
| 2991 | paddrp->spp_pathmtu -= SCTP_MIN_OVERHEAD; |
| 2992 | break; |
| 2993 | #endif |
| 2994 | #if defined(__Userspace__) |
| 2995 | case AF_CONN: |
| 2996 | paddrp->spp_pathmtu -= sizeof(struct sctphdr); |
| 2997 | break; |
| 2998 | #endif |
| 2999 | default: |
| 3000 | break; |
| 3001 | } |
| 3002 | /* get flags for HB */ |
| 3003 | if (net->dest_state & SCTP_ADDR_NOHB) { |
| 3004 | paddrp->spp_flags |= SPP_HB_DISABLE; |
| 3005 | } else { |
| 3006 | paddrp->spp_flags |= SPP_HB_ENABLE; |
| 3007 | } |
| 3008 | /* get flags for PMTU */ |
| 3009 | if (net->dest_state & SCTP_ADDR_NO_PMTUD) { |
| 3010 | paddrp->spp_flags |= SPP_PMTUD_DISABLE; |
| 3011 | } else { |
| 3012 | paddrp->spp_flags |= SPP_PMTUD_ENABLE; |
| 3013 | } |
| 3014 | if (net->dscp & 0x01) { |
| 3015 | paddrp->spp_dscp = net->dscp & 0xfc; |
| 3016 | paddrp->spp_flags |= SPP_DSCP; |
| 3017 | } |
| 3018 | #ifdef INET6 |
| 3019 | if ((net->ro._l_addr.sa.sa_family == AF_INET6) && |
| 3020 | (net->flowlabel & 0x80000000)) { |
| 3021 | paddrp->spp_ipv6_flowlabel = net->flowlabel & 0x000fffff; |
| 3022 | paddrp->spp_flags |= SPP_IPV6_FLOWLABEL; |
| 3023 | } |
| 3024 | #endif |
| 3025 | } else { |
| 3026 | /* |
| 3027 | * No destination so return default |
| 3028 | * value |
| 3029 | */ |
| 3030 | paddrp->spp_pathmaxrxt = stcb->asoc.def_net_failure; |
| 3031 | paddrp->spp_pathmtu = stcb->asoc.default_mtu; |
| 3032 | if (stcb->asoc.default_dscp & 0x01) { |
| 3033 | paddrp->spp_dscp = stcb->asoc.default_dscp & 0xfc; |
| 3034 | paddrp->spp_flags |= SPP_DSCP; |
| 3035 | } |
| 3036 | #ifdef INET6 |
| 3037 | if (stcb->asoc.default_flowlabel & 0x80000000) { |
| 3038 | paddrp->spp_ipv6_flowlabel = stcb->asoc.default_flowlabel & 0x000fffff; |
| 3039 | paddrp->spp_flags |= SPP_IPV6_FLOWLABEL; |
| 3040 | } |
| 3041 | #endif |
| 3042 | /* default settings should be these */ |
| 3043 | if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) { |
| 3044 | paddrp->spp_flags |= SPP_HB_DISABLE; |
| 3045 | } else { |
| 3046 | paddrp->spp_flags |= SPP_HB_ENABLE; |
| 3047 | } |
| 3048 | if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) { |
| 3049 | paddrp->spp_flags |= SPP_PMTUD_DISABLE; |
| 3050 | } else { |
| 3051 | paddrp->spp_flags |= SPP_PMTUD_ENABLE; |
| 3052 | } |
| 3053 | paddrp->spp_hbinterval = stcb->asoc.heart_beat_delay; |
| 3054 | } |
| 3055 | paddrp->spp_assoc_id = sctp_get_associd(stcb); |
| 3056 | SCTP_TCB_UNLOCK(stcb); |
| 3057 | } else { |
| 3058 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3059 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3060 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3061 | (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3062 | /* Use endpoint defaults */ |
| 3063 | SCTP_INP_RLOCK(inp); |
| 3064 | paddrp->spp_pathmaxrxt = inp->sctp_ep.def_net_failure; |
| 3065 | paddrp->spp_hbinterval = sctp_ticks_to_msecs(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]); |
| 3066 | paddrp->spp_assoc_id = SCTP_FUTURE_ASSOC; |
| 3067 | /* get inp's default */ |
| 3068 | if (inp->sctp_ep.default_dscp & 0x01) { |
| 3069 | paddrp->spp_dscp = inp->sctp_ep.default_dscp & 0xfc; |
| 3070 | paddrp->spp_flags |= SPP_DSCP; |
| 3071 | } |
| 3072 | #ifdef INET6 |
| 3073 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && |
| 3074 | (inp->sctp_ep.default_flowlabel & 0x80000000)) { |
| 3075 | paddrp->spp_ipv6_flowlabel = inp->sctp_ep.default_flowlabel & 0x000fffff; |
| 3076 | paddrp->spp_flags |= SPP_IPV6_FLOWLABEL; |
| 3077 | } |
| 3078 | #endif |
| 3079 | paddrp->spp_pathmtu = inp->sctp_ep.default_mtu; |
| 3080 |
| 3081 | if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) { |
| 3082 | paddrp->spp_flags |= SPP_HB_ENABLE; |
| 3083 | } else { |
| 3084 | paddrp->spp_flags |= SPP_HB_DISABLE; |
| 3085 | } |
| 3086 | if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) { |
| 3087 | paddrp->spp_flags |= SPP_PMTUD_ENABLE; |
| 3088 | } else { |
| 3089 | paddrp->spp_flags |= SPP_PMTUD_DISABLE; |
| 3090 | } |
| 3091 | SCTP_INP_RUNLOCK(inp); |
| 3092 | } else { |
| 3093 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3094 | error = EINVAL; |
| 3095 | } |
| 3096 | } |
| 3097 | if (error == 0) { |
| 3098 | *optsize = sizeof(struct sctp_paddrparams); |
| 3099 | } |
| 3100 | break; |
| 3101 | } |
| 3102 | case SCTP_GET_PEER_ADDR_INFO: |
| 3103 | { |
| 3104 | struct sctp_paddrinfo *paddri; |
| 3105 | struct sctp_nets *net; |
| 3106 | struct sockaddr *addr; |
| 3107 | #if defined(INET) && defined(INET6) |
| 3108 | struct sockaddr_in sin_store; |
| 3109 | #endif |
| 3110 |
| 3111 | SCTP_CHECK_AND_CAST(paddri, optval, struct sctp_paddrinfo, *optsize); |
| 3112 | SCTP_FIND_STCB(inp, stcb, paddri->spinfo_assoc_id); |
| 3113 |
| 3114 | #if defined(INET) && defined(INET6) |
| 3115 | if (paddri->spinfo_address.ss_family == AF_INET6) { |
| 3116 | struct sockaddr_in6 *sin6; |
| 3117 |
| 3118 | sin6 = (struct sockaddr_in6 *)&paddri->spinfo_address; |
| 3119 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 3120 | in6_sin6_2_sin(&sin_store, sin6); |
| 3121 | addr = (struct sockaddr *)&sin_store; |
| 3122 | } else { |
| 3123 | addr = (struct sockaddr *)&paddri->spinfo_address; |
| 3124 | } |
| 3125 | } else { |
| 3126 | addr = (struct sockaddr *)&paddri->spinfo_address; |
| 3127 | } |
| 3128 | #else |
| 3129 | addr = (struct sockaddr *)&paddri->spinfo_address; |
| 3130 | #endif |
| 3131 | if (stcb != NULL) { |
| 3132 | net = sctp_findnet(stcb, addr); |
| 3133 | } else { |
| 3134 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 3135 | * do a decrement if it finds the stcb as long as the locked |
| 3136 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 3137 | */ |
| 3138 | net = NULL; |
| 3139 | SCTP_INP_INCR_REF(inp); |
| 3140 | stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL); |
| 3141 | if (stcb == NULL) { |
| 3142 | SCTP_INP_DECR_REF(inp); |
| 3143 | } |
| 3144 | } |
| 3145 |
| 3146 | if ((stcb != NULL) && (net != NULL)) { |
| 3147 | if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { |
| 3148 | /* It's unconfirmed */ |
| 3149 | paddri->spinfo_state = SCTP_UNCONFIRMED; |
| 3150 | } else if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 3151 | /* It's active */ |
| 3152 | paddri->spinfo_state = SCTP_ACTIVE; |
| 3153 | } else { |
| 3154 | /* It's inactive */ |
| 3155 | paddri->spinfo_state = SCTP_INACTIVE; |
| 3156 | } |
| 3157 | paddri->spinfo_cwnd = net->cwnd; |
| 3158 | paddri->spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT; |
| 3159 | paddri->spinfo_rto = net->RTO; |
| 3160 | paddri->spinfo_assoc_id = sctp_get_associd(stcb); |
| 3161 | paddri->spinfo_mtu = net->mtu; |
| 3162 | switch (addr->sa_family) { |
| 3163 | #if defined(INET) |
| 3164 | case AF_INET: |
| 3165 | paddri->spinfo_mtu -= SCTP_MIN_V4_OVERHEAD; |
| 3166 | break; |
| 3167 | #endif |
| 3168 | #if defined(INET6) |
| 3169 | case AF_INET6: |
| 3170 | paddri->spinfo_mtu -= SCTP_MIN_OVERHEAD; |
| 3171 | break; |
| 3172 | #endif |
| 3173 | #if defined(__Userspace__) |
| 3174 | case AF_CONN: |
| 3175 | paddri->spinfo_mtu -= sizeof(struct sctphdr); |
| 3176 | break; |
| 3177 | #endif |
| 3178 | default: |
| 3179 | break; |
| 3180 | } |
| 3181 | SCTP_TCB_UNLOCK(stcb); |
| 3182 | *optsize = sizeof(struct sctp_paddrinfo); |
| 3183 | } else { |
| 3184 | if (stcb != NULL) { |
| 3185 | SCTP_TCB_UNLOCK(stcb); |
| 3186 | } |
| 3187 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 3188 | error = ENOENT; |
| 3189 | } |
| 3190 | break; |
| 3191 | } |
| 3192 | case SCTP_PCB_STATUS: |
| 3193 | { |
| 3194 | struct sctp_pcbinfo *spcb; |
| 3195 |
| 3196 | SCTP_CHECK_AND_CAST(spcb, optval, struct sctp_pcbinfo, *optsize); |
| 3197 | sctp_fill_pcbinfo(spcb); |
| 3198 | *optsize = sizeof(struct sctp_pcbinfo); |
| 3199 | break; |
| 3200 | } |
| 3201 | case SCTP_STATUS: |
| 3202 | { |
| 3203 | struct sctp_nets *net; |
| 3204 | struct sctp_status *sstat; |
| 3205 |
| 3206 | SCTP_CHECK_AND_CAST(sstat, optval, struct sctp_status, *optsize); |
| 3207 | SCTP_FIND_STCB(inp, stcb, sstat->sstat_assoc_id); |
| 3208 |
| 3209 | if (stcb == NULL) { |
| 3210 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3211 | error = EINVAL; |
| 3212 | break; |
| 3213 | } |
| 3214 | sstat->sstat_state = sctp_map_assoc_state(stcb->asoc.state); |
| 3215 | sstat->sstat_assoc_id = sctp_get_associd(stcb); |
| 3216 | sstat->sstat_rwnd = stcb->asoc.peers_rwnd; |
| 3217 | sstat->sstat_unackdata = stcb->asoc.sent_queue_cnt; |
| 3218 | /* |
| 3219 | * We can't include chunks that have been passed to |
| 3220 | * the socket layer. Only things in queue. |
| 3221 | */ |
| 3222 | sstat->sstat_penddata = (stcb->asoc.cnt_on_reasm_queue + |
| 3223 | stcb->asoc.cnt_on_all_streams); |
| 3224 | sstat->sstat_instrms = stcb->asoc.streamincnt; |
| 3225 | sstat->sstat_outstrms = stcb->asoc.streamoutcnt; |
| 3226 | sstat->sstat_fragmentation_point = sctp_get_frag_point(stcb, &stcb->asoc); |
| 3227 | net = stcb->asoc.primary_destination; |
| 3228 | if (net != NULL) { |
| 3229 | #ifdef HAVE_SA_LEN |
| 3230 | memcpy(&sstat->sstat_primary.spinfo_address, |
| 3231 | &net->ro._l_addr, |
| 3232 | ((struct sockaddr *)(&net->ro._l_addr))->sa_len); |
| 3233 | #else |
| 3234 | switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) { |
| 3235 | #if defined(INET) |
| 3236 | case AF_INET: |
| 3237 | memcpy(&sstat->sstat_primary.spinfo_address, |
| 3238 | &net->ro._l_addr, |
| 3239 | sizeof(struct sockaddr_in)); |
| 3240 | break; |
| 3241 | #endif |
| 3242 | #if defined(INET6) |
| 3243 | case AF_INET6: |
| 3244 | memcpy(&sstat->sstat_primary.spinfo_address, |
| 3245 | &net->ro._l_addr, |
| 3246 | sizeof(struct sockaddr_in6)); |
| 3247 | break; |
| 3248 | #endif |
| 3249 | #if defined(__Userspace__) |
| 3250 | case AF_CONN: |
| 3251 | memcpy(&sstat->sstat_primary.spinfo_address, |
| 3252 | &net->ro._l_addr, |
| 3253 | sizeof(struct sockaddr_conn)); |
| 3254 | break; |
| 3255 | #endif |
| 3256 | default: |
| 3257 | break; |
| 3258 | } |
| 3259 | #endif |
| 3260 | ((struct sockaddr_in *)&sstat->sstat_primary.spinfo_address)->sin_port = stcb->rport; |
| 3261 | /* |
| 3262 | * Again the user can get info from sctp_constants.h |
| 3263 | * for what the state of the network is. |
| 3264 | */ |
| 3265 | if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { |
| 3266 | /* It's unconfirmed */ |
| 3267 | sstat->sstat_primary.spinfo_state = SCTP_UNCONFIRMED; |
| 3268 | } else if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 3269 | /* It's active */ |
| 3270 | sstat->sstat_primary.spinfo_state = SCTP_ACTIVE; |
| 3271 | } else { |
| 3272 | /* It's inactive */ |
| 3273 | sstat->sstat_primary.spinfo_state = SCTP_INACTIVE; |
| 3274 | } |
| 3275 | sstat->sstat_primary.spinfo_cwnd = net->cwnd; |
| 3276 | sstat->sstat_primary.spinfo_srtt = net->lastsa >> SCTP_RTT_SHIFT; |
| 3277 | sstat->sstat_primary.spinfo_rto = net->RTO; |
| 3278 | sstat->sstat_primary.spinfo_mtu = net->mtu; |
| 3279 | switch (stcb->asoc.primary_destination->ro._l_addr.sa.sa_family) { |
| 3280 | #if defined(INET) |
| 3281 | case AF_INET: |
| 3282 | sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_V4_OVERHEAD; |
| 3283 | break; |
| 3284 | #endif |
| 3285 | #if defined(INET6) |
| 3286 | case AF_INET6: |
| 3287 | sstat->sstat_primary.spinfo_mtu -= SCTP_MIN_OVERHEAD; |
| 3288 | break; |
| 3289 | #endif |
| 3290 | #if defined(__Userspace__) |
| 3291 | case AF_CONN: |
| 3292 | sstat->sstat_primary.spinfo_mtu -= sizeof(struct sctphdr); |
| 3293 | break; |
| 3294 | #endif |
| 3295 | default: |
| 3296 | break; |
| 3297 | } |
| 3298 | } else { |
| 3299 | memset(&sstat->sstat_primary, 0, sizeof(struct sctp_paddrinfo)); |
| 3300 | } |
| 3301 | sstat->sstat_primary.spinfo_assoc_id = sctp_get_associd(stcb); |
| 3302 | SCTP_TCB_UNLOCK(stcb); |
| 3303 | *optsize = sizeof(struct sctp_status); |
| 3304 | break; |
| 3305 | } |
| 3306 | case SCTP_RTOINFO: |
| 3307 | { |
| 3308 | struct sctp_rtoinfo *srto; |
| 3309 |
| 3310 | SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, *optsize); |
| 3311 | SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id); |
| 3312 |
| 3313 | if (stcb) { |
| 3314 | srto->srto_initial = stcb->asoc.initial_rto; |
| 3315 | srto->srto_max = stcb->asoc.maxrto; |
| 3316 | srto->srto_min = stcb->asoc.minrto; |
| 3317 | SCTP_TCB_UNLOCK(stcb); |
| 3318 | } else { |
| 3319 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3320 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3321 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3322 | (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3323 | SCTP_INP_RLOCK(inp); |
| 3324 | srto->srto_initial = inp->sctp_ep.initial_rto; |
| 3325 | srto->srto_max = inp->sctp_ep.sctp_maxrto; |
| 3326 | srto->srto_min = inp->sctp_ep.sctp_minrto; |
| 3327 | SCTP_INP_RUNLOCK(inp); |
| 3328 | } else { |
| 3329 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3330 | error = EINVAL; |
| 3331 | } |
| 3332 | } |
| 3333 | if (error == 0) { |
| 3334 | *optsize = sizeof(struct sctp_rtoinfo); |
| 3335 | } |
| 3336 | break; |
| 3337 | } |
| 3338 | case SCTP_TIMEOUTS: |
| 3339 | { |
| 3340 | struct sctp_timeouts *stimo; |
| 3341 |
| 3342 | SCTP_CHECK_AND_CAST(stimo, optval, struct sctp_timeouts, *optsize); |
| 3343 | SCTP_FIND_STCB(inp, stcb, stimo->stimo_assoc_id); |
| 3344 |
| 3345 | if (stcb) { |
| 3346 | stimo->stimo_init= stcb->asoc.timoinit; |
| 3347 | stimo->stimo_data= stcb->asoc.timodata; |
| 3348 | stimo->stimo_sack= stcb->asoc.timosack; |
| 3349 | stimo->stimo_shutdown= stcb->asoc.timoshutdown; |
| 3350 | stimo->stimo_heartbeat= stcb->asoc.timoheartbeat; |
| 3351 | stimo->stimo_cookie= stcb->asoc.timocookie; |
| 3352 | stimo->stimo_shutdownack= stcb->asoc.timoshutdownack; |
| 3353 | SCTP_TCB_UNLOCK(stcb); |
| 3354 | *optsize = sizeof(struct sctp_timeouts); |
| 3355 | } else { |
| 3356 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3357 | error = EINVAL; |
| 3358 | } |
| 3359 | break; |
| 3360 | } |
| 3361 | case SCTP_ASSOCINFO: |
| 3362 | { |
| 3363 | struct sctp_assocparams *sasoc; |
| 3364 |
| 3365 | SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, *optsize); |
| 3366 | SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id); |
| 3367 |
| 3368 | if (stcb) { |
| 3369 | sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(stcb->asoc.cookie_life); |
| 3370 | sasoc->sasoc_asocmaxrxt = stcb->asoc.max_send_times; |
| 3371 | sasoc->sasoc_number_peer_destinations = stcb->asoc.numnets; |
| 3372 | sasoc->sasoc_peer_rwnd = stcb->asoc.peers_rwnd; |
| 3373 | sasoc->sasoc_local_rwnd = stcb->asoc.my_rwnd; |
| 3374 | SCTP_TCB_UNLOCK(stcb); |
| 3375 | } else { |
| 3376 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3377 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3378 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3379 | (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3380 | SCTP_INP_RLOCK(inp); |
| 3381 | sasoc->sasoc_cookie_life = sctp_ticks_to_msecs(inp->sctp_ep.def_cookie_life); |
| 3382 | sasoc->sasoc_asocmaxrxt = inp->sctp_ep.max_send_times; |
| 3383 | sasoc->sasoc_number_peer_destinations = 0; |
| 3384 | sasoc->sasoc_peer_rwnd = 0; |
| 3385 | sasoc->sasoc_local_rwnd = (uint32_t)sbspace(&inp->sctp_socket->so_rcv); |
| 3386 | SCTP_INP_RUNLOCK(inp); |
| 3387 | } else { |
| 3388 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3389 | error = EINVAL; |
| 3390 | } |
| 3391 | } |
| 3392 | if (error == 0) { |
| 3393 | *optsize = sizeof(struct sctp_assocparams); |
| 3394 | } |
| 3395 | break; |
| 3396 | } |
| 3397 | case SCTP_DEFAULT_SEND_PARAM: |
| 3398 | { |
| 3399 | struct sctp_sndrcvinfo *s_info; |
| 3400 |
| 3401 | SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, *optsize); |
| 3402 | SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id); |
| 3403 |
| 3404 | if (stcb) { |
| 3405 | memcpy(s_info, &stcb->asoc.def_send, sizeof(stcb->asoc.def_send)); |
| 3406 | SCTP_TCB_UNLOCK(stcb); |
| 3407 | } else { |
| 3408 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3409 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3410 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3411 | (s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3412 | SCTP_INP_RLOCK(inp); |
| 3413 | memcpy(s_info, &inp->def_send, sizeof(inp->def_send)); |
| 3414 | SCTP_INP_RUNLOCK(inp); |
| 3415 | } else { |
| 3416 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3417 | error = EINVAL; |
| 3418 | } |
| 3419 | } |
| 3420 | if (error == 0) { |
| 3421 | *optsize = sizeof(struct sctp_sndrcvinfo); |
| 3422 | } |
| 3423 | break; |
| 3424 | } |
| 3425 | case SCTP_INITMSG: |
| 3426 | { |
| 3427 | struct sctp_initmsg *sinit; |
| 3428 |
| 3429 | SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, *optsize); |
| 3430 | SCTP_INP_RLOCK(inp); |
| 3431 | sinit->sinit_num_ostreams = inp->sctp_ep.pre_open_stream_count; |
| 3432 | sinit->sinit_max_instreams = inp->sctp_ep.max_open_streams_intome; |
| 3433 | sinit->sinit_max_attempts = inp->sctp_ep.max_init_times; |
| 3434 | sinit->sinit_max_init_timeo = inp->sctp_ep.initial_init_rto_max; |
| 3435 | SCTP_INP_RUNLOCK(inp); |
| 3436 | *optsize = sizeof(struct sctp_initmsg); |
| 3437 | break; |
| 3438 | } |
| 3439 | case SCTP_PRIMARY_ADDR: |
| 3440 | /* we allow a "get" operation on this */ |
| 3441 | { |
| 3442 | struct sctp_setprim *ssp; |
| 3443 |
| 3444 | SCTP_CHECK_AND_CAST(ssp, optval, struct sctp_setprim, *optsize); |
| 3445 | SCTP_FIND_STCB(inp, stcb, ssp->ssp_assoc_id); |
| 3446 |
| 3447 | if (stcb) { |
| 3448 | union sctp_sockstore *addr; |
| 3449 |
| 3450 | addr = &stcb->asoc.primary_destination->ro._l_addr; |
| 3451 | switch (addr->sa.sa_family) { |
| 3452 | #ifdef INET |
| 3453 | case AF_INET: |
| 3454 | #ifdef INET6 |
| 3455 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) { |
| 3456 | in6_sin_2_v4mapsin6(&addr->sin, |
| 3457 | (struct sockaddr_in6 *)&ssp->ssp_addr); |
| 3458 | } else { |
| 3459 | memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in)); |
| 3460 | } |
| 3461 | #else |
| 3462 | memcpy(&ssp->ssp_addr, &addr->sin, sizeof(struct sockaddr_in)); |
| 3463 | #endif |
| 3464 | break; |
| 3465 | #endif |
| 3466 | #ifdef INET6 |
| 3467 | case AF_INET6: |
| 3468 | memcpy(&ssp->ssp_addr, &addr->sin6, sizeof(struct sockaddr_in6)); |
| 3469 | break; |
| 3470 | #endif |
| 3471 | #if defined(__Userspace__) |
| 3472 | case AF_CONN: |
| 3473 | memcpy(&ssp->ssp_addr, &addr->sconn, sizeof(struct sockaddr_conn)); |
| 3474 | break; |
| 3475 | #endif |
| 3476 | default: |
| 3477 | break; |
| 3478 | } |
| 3479 | SCTP_TCB_UNLOCK(stcb); |
| 3480 | *optsize = sizeof(struct sctp_setprim); |
| 3481 | } else { |
| 3482 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3483 | error = EINVAL; |
| 3484 | } |
| 3485 | break; |
| 3486 | } |
| 3487 | case SCTP_HMAC_IDENT: |
| 3488 | { |
| 3489 | struct sctp_hmacalgo *shmac; |
| 3490 | sctp_hmaclist_t *hmaclist; |
| 3491 | size_t size; |
| 3492 | int i; |
| 3493 |
| 3494 | SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, *optsize); |
| 3495 |
| 3496 | SCTP_INP_RLOCK(inp); |
| 3497 | hmaclist = inp->sctp_ep.local_hmacs; |
| 3498 | if (hmaclist == NULL) { |
| 3499 | /* no HMACs to return */ |
| 3500 | *optsize = sizeof(*shmac); |
| 3501 | SCTP_INP_RUNLOCK(inp); |
| 3502 | break; |
| 3503 | } |
| 3504 | /* is there room for all of the hmac ids? */ |
| 3505 | size = sizeof(*shmac) + (hmaclist->num_algo * |
| 3506 | sizeof(shmac->shmac_idents[0])); |
| 3507 | if (*optsize < size) { |
| 3508 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3509 | error = EINVAL; |
| 3510 | SCTP_INP_RUNLOCK(inp); |
| 3511 | break; |
| 3512 | } |
| 3513 | /* copy in the list */ |
| 3514 | shmac->shmac_number_of_idents = hmaclist->num_algo; |
| 3515 | for (i = 0; i < hmaclist->num_algo; i++) { |
| 3516 | shmac->shmac_idents[i] = hmaclist->hmac[i]; |
| 3517 | } |
| 3518 | SCTP_INP_RUNLOCK(inp); |
| 3519 | *optsize = size; |
| 3520 | break; |
| 3521 | } |
| 3522 | case SCTP_AUTH_ACTIVE_KEY: |
| 3523 | { |
| 3524 | struct sctp_authkeyid *scact; |
| 3525 |
| 3526 | SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, *optsize); |
| 3527 | SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id); |
| 3528 |
| 3529 | if (stcb) { |
| 3530 | /* get the active key on the assoc */ |
| 3531 | scact->scact_keynumber = stcb->asoc.authinfo.active_keyid; |
| 3532 | SCTP_TCB_UNLOCK(stcb); |
| 3533 | } else { |
| 3534 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3535 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3536 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3537 | (scact->scact_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3538 | /* get the endpoint active key */ |
| 3539 | SCTP_INP_RLOCK(inp); |
| 3540 | scact->scact_keynumber = inp->sctp_ep.default_keyid; |
| 3541 | SCTP_INP_RUNLOCK(inp); |
| 3542 | } else { |
| 3543 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3544 | error = EINVAL; |
| 3545 | } |
| 3546 | } |
| 3547 | if (error == 0) { |
| 3548 | *optsize = sizeof(struct sctp_authkeyid); |
| 3549 | } |
| 3550 | break; |
| 3551 | } |
| 3552 | case SCTP_LOCAL_AUTH_CHUNKS: |
| 3553 | { |
| 3554 | struct sctp_authchunks *sac; |
| 3555 | sctp_auth_chklist_t *chklist = NULL; |
| 3556 | size_t size = 0; |
| 3557 |
| 3558 | SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize); |
| 3559 | SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id); |
| 3560 |
| 3561 | if (stcb) { |
| 3562 | /* get off the assoc */ |
| 3563 | chklist = stcb->asoc.local_auth_chunks; |
| 3564 | /* is there enough space? */ |
| 3565 | size = sctp_auth_get_chklist_size(chklist); |
| 3566 | if (*optsize < (sizeof(struct sctp_authchunks) + size)) { |
| 3567 | error = EINVAL; |
| 3568 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3569 | } else { |
| 3570 | /* copy in the chunks */ |
| 3571 | (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); |
| 3572 | sac->gauth_number_of_chunks = (uint32_t)size; |
| 3573 | *optsize = sizeof(struct sctp_authchunks) + size; |
| 3574 | } |
| 3575 | SCTP_TCB_UNLOCK(stcb); |
| 3576 | } else { |
| 3577 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3578 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3579 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3580 | (sac->gauth_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3581 | /* get off the endpoint */ |
| 3582 | SCTP_INP_RLOCK(inp); |
| 3583 | chklist = inp->sctp_ep.local_auth_chunks; |
| 3584 | /* is there enough space? */ |
| 3585 | size = sctp_auth_get_chklist_size(chklist); |
| 3586 | if (*optsize < (sizeof(struct sctp_authchunks) + size)) { |
| 3587 | error = EINVAL; |
| 3588 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3589 | } else { |
| 3590 | /* copy in the chunks */ |
| 3591 | (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); |
| 3592 | sac->gauth_number_of_chunks = (uint32_t)size; |
| 3593 | *optsize = sizeof(struct sctp_authchunks) + size; |
| 3594 | } |
| 3595 | SCTP_INP_RUNLOCK(inp); |
| 3596 | } else { |
| 3597 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3598 | error = EINVAL; |
| 3599 | } |
| 3600 | } |
| 3601 | break; |
| 3602 | } |
| 3603 | case SCTP_PEER_AUTH_CHUNKS: |
| 3604 | { |
| 3605 | struct sctp_authchunks *sac; |
| 3606 | sctp_auth_chklist_t *chklist = NULL; |
| 3607 | size_t size = 0; |
| 3608 |
| 3609 | SCTP_CHECK_AND_CAST(sac, optval, struct sctp_authchunks, *optsize); |
| 3610 | SCTP_FIND_STCB(inp, stcb, sac->gauth_assoc_id); |
| 3611 |
| 3612 | if (stcb) { |
| 3613 | /* get off the assoc */ |
| 3614 | chklist = stcb->asoc.peer_auth_chunks; |
| 3615 | /* is there enough space? */ |
| 3616 | size = sctp_auth_get_chklist_size(chklist); |
| 3617 | if (*optsize < (sizeof(struct sctp_authchunks) + size)) { |
| 3618 | error = EINVAL; |
| 3619 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3620 | } else { |
| 3621 | /* copy in the chunks */ |
| 3622 | (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); |
| 3623 | sac->gauth_number_of_chunks = (uint32_t)size; |
| 3624 | *optsize = sizeof(struct sctp_authchunks) + size; |
| 3625 | } |
| 3626 | SCTP_TCB_UNLOCK(stcb); |
| 3627 | } else { |
| 3628 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 3629 | error = ENOENT; |
| 3630 | } |
| 3631 | break; |
| 3632 | } |
| 3633 | #if defined(HAVE_SCTP_PEELOFF_SOCKOPT) |
| 3634 | case SCTP_PEELOFF: |
| 3635 | { |
| 3636 | struct sctp_peeloff_opt *peeloff; |
| 3637 |
| 3638 | SCTP_CHECK_AND_CAST(peeloff, optval, struct sctp_peeloff_opt, *optsize); |
| 3639 | /* do the peeloff */ |
| 3640 | error = sctp_peeloff_option(p, peeloff); |
| 3641 | if (error == 0) { |
| 3642 | *optsize = sizeof(struct sctp_peeloff_opt); |
| 3643 | } |
| 3644 | } |
| 3645 | break; |
| 3646 | #endif /* HAVE_SCTP_PEELOFF_SOCKOPT */ |
| 3647 | case SCTP_EVENT: |
| 3648 | { |
| 3649 | struct sctp_event *event; |
| 3650 | uint32_t event_type; |
| 3651 |
| 3652 | SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, *optsize); |
| 3653 | SCTP_FIND_STCB(inp, stcb, event->se_assoc_id); |
| 3654 |
| 3655 | switch (event->se_type) { |
| 3656 | case SCTP_ASSOC_CHANGE: |
| 3657 | event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT; |
| 3658 | break; |
| 3659 | case SCTP_PEER_ADDR_CHANGE: |
| 3660 | event_type = SCTP_PCB_FLAGS_RECVPADDREVNT; |
| 3661 | break; |
| 3662 | case SCTP_REMOTE_ERROR: |
| 3663 | event_type = SCTP_PCB_FLAGS_RECVPEERERR; |
| 3664 | break; |
| 3665 | case SCTP_SEND_FAILED: |
| 3666 | event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT; |
| 3667 | break; |
| 3668 | case SCTP_SHUTDOWN_EVENT: |
| 3669 | event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT; |
| 3670 | break; |
| 3671 | case SCTP_ADAPTATION_INDICATION: |
| 3672 | event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT; |
| 3673 | break; |
| 3674 | case SCTP_PARTIAL_DELIVERY_EVENT: |
| 3675 | event_type = SCTP_PCB_FLAGS_PDAPIEVNT; |
| 3676 | break; |
| 3677 | case SCTP_AUTHENTICATION_EVENT: |
| 3678 | event_type = SCTP_PCB_FLAGS_AUTHEVNT; |
| 3679 | break; |
| 3680 | case SCTP_STREAM_RESET_EVENT: |
| 3681 | event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT; |
| 3682 | break; |
| 3683 | case SCTP_SENDER_DRY_EVENT: |
| 3684 | event_type = SCTP_PCB_FLAGS_DRYEVNT; |
| 3685 | break; |
| 3686 | case SCTP_NOTIFICATIONS_STOPPED_EVENT: |
| 3687 | event_type = 0; |
| 3688 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP); |
| 3689 | error = ENOTSUP; |
| 3690 | break; |
| 3691 | case SCTP_ASSOC_RESET_EVENT: |
| 3692 | event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT; |
| 3693 | break; |
| 3694 | case SCTP_STREAM_CHANGE_EVENT: |
| 3695 | event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT; |
| 3696 | break; |
| 3697 | case SCTP_SEND_FAILED_EVENT: |
| 3698 | event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT; |
| 3699 | break; |
| 3700 | default: |
| 3701 | event_type = 0; |
| 3702 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3703 | error = EINVAL; |
| 3704 | break; |
| 3705 | } |
| 3706 | if (event_type > 0) { |
| 3707 | if (stcb) { |
| 3708 | event->se_on = sctp_stcb_is_feature_on(inp, stcb, event_type); |
| 3709 | } else { |
| 3710 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3711 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3712 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3713 | (event->se_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3714 | SCTP_INP_RLOCK(inp); |
| 3715 | event->se_on = sctp_is_feature_on(inp, event_type); |
| 3716 | SCTP_INP_RUNLOCK(inp); |
| 3717 | } else { |
| 3718 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3719 | error = EINVAL; |
| 3720 | } |
| 3721 | } |
| 3722 | } |
| 3723 | if (stcb != NULL) { |
| 3724 | SCTP_TCB_UNLOCK(stcb); |
| 3725 | } |
| 3726 | if (error == 0) { |
| 3727 | *optsize = sizeof(struct sctp_event); |
| 3728 | } |
| 3729 | break; |
| 3730 | } |
| 3731 | case SCTP_RECVRCVINFO: |
| 3732 | if (*optsize < sizeof(int)) { |
| 3733 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3734 | error = EINVAL; |
| 3735 | } else { |
| 3736 | SCTP_INP_RLOCK(inp); |
| 3737 | *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO); |
| 3738 | SCTP_INP_RUNLOCK(inp); |
| 3739 | *optsize = sizeof(int); |
| 3740 | } |
| 3741 | break; |
| 3742 | case SCTP_RECVNXTINFO: |
| 3743 | if (*optsize < sizeof(int)) { |
| 3744 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3745 | error = EINVAL; |
| 3746 | } else { |
| 3747 | SCTP_INP_RLOCK(inp); |
| 3748 | *(int *)optval = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO); |
| 3749 | SCTP_INP_RUNLOCK(inp); |
| 3750 | *optsize = sizeof(int); |
| 3751 | } |
| 3752 | break; |
| 3753 | case SCTP_DEFAULT_SNDINFO: |
| 3754 | { |
| 3755 | struct sctp_sndinfo *info; |
| 3756 |
| 3757 | SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, *optsize); |
| 3758 | SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id); |
| 3759 |
| 3760 | if (stcb) { |
| 3761 | info->snd_sid = stcb->asoc.def_send.sinfo_stream; |
| 3762 | info->snd_flags = stcb->asoc.def_send.sinfo_flags; |
| 3763 | info->snd_flags &= 0xfff0; |
| 3764 | info->snd_ppid = stcb->asoc.def_send.sinfo_ppid; |
| 3765 | info->snd_context = stcb->asoc.def_send.sinfo_context; |
| 3766 | SCTP_TCB_UNLOCK(stcb); |
| 3767 | } else { |
| 3768 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3769 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3770 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3771 | (info->snd_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3772 | SCTP_INP_RLOCK(inp); |
| 3773 | info->snd_sid = inp->def_send.sinfo_stream; |
| 3774 | info->snd_flags = inp->def_send.sinfo_flags; |
| 3775 | info->snd_flags &= 0xfff0; |
| 3776 | info->snd_ppid = inp->def_send.sinfo_ppid; |
| 3777 | info->snd_context = inp->def_send.sinfo_context; |
| 3778 | SCTP_INP_RUNLOCK(inp); |
| 3779 | } else { |
| 3780 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3781 | error = EINVAL; |
| 3782 | } |
| 3783 | } |
| 3784 | if (error == 0) { |
| 3785 | *optsize = sizeof(struct sctp_sndinfo); |
| 3786 | } |
| 3787 | break; |
| 3788 | } |
| 3789 | case SCTP_DEFAULT_PRINFO: |
| 3790 | { |
| 3791 | struct sctp_default_prinfo *info; |
| 3792 |
| 3793 | SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, *optsize); |
| 3794 | SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id); |
| 3795 |
| 3796 | if (stcb) { |
| 3797 | info->pr_policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags); |
| 3798 | info->pr_value = stcb->asoc.def_send.sinfo_timetolive; |
| 3799 | SCTP_TCB_UNLOCK(stcb); |
| 3800 | } else { |
| 3801 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3802 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3803 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3804 | (info->pr_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3805 | SCTP_INP_RLOCK(inp); |
| 3806 | info->pr_policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags); |
| 3807 | info->pr_value = inp->def_send.sinfo_timetolive; |
| 3808 | SCTP_INP_RUNLOCK(inp); |
| 3809 | } else { |
| 3810 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3811 | error = EINVAL; |
| 3812 | } |
| 3813 | } |
| 3814 | if (error == 0) { |
| 3815 | *optsize = sizeof(struct sctp_default_prinfo); |
| 3816 | } |
| 3817 | break; |
| 3818 | } |
| 3819 | case SCTP_PEER_ADDR_THLDS: |
| 3820 | { |
| 3821 | struct sctp_paddrthlds *thlds; |
| 3822 | struct sctp_nets *net; |
| 3823 | struct sockaddr *addr; |
| 3824 | #if defined(INET) && defined(INET6) |
| 3825 | struct sockaddr_in sin_store; |
| 3826 | #endif |
| 3827 |
| 3828 | SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, *optsize); |
| 3829 | SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id); |
| 3830 |
| 3831 | #if defined(INET) && defined(INET6) |
| 3832 | if (thlds->spt_address.ss_family == AF_INET6) { |
| 3833 | struct sockaddr_in6 *sin6; |
| 3834 |
| 3835 | sin6 = (struct sockaddr_in6 *)&thlds->spt_address; |
| 3836 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 3837 | in6_sin6_2_sin(&sin_store, sin6); |
| 3838 | addr = (struct sockaddr *)&sin_store; |
| 3839 | } else { |
| 3840 | addr = (struct sockaddr *)&thlds->spt_address; |
| 3841 | } |
| 3842 | } else { |
| 3843 | addr = (struct sockaddr *)&thlds->spt_address; |
| 3844 | } |
| 3845 | #else |
| 3846 | addr = (struct sockaddr *)&thlds->spt_address; |
| 3847 | #endif |
| 3848 | if (stcb != NULL) { |
| 3849 | net = sctp_findnet(stcb, addr); |
| 3850 | } else { |
| 3851 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 3852 | * do a decrement if it finds the stcb as long as the locked |
| 3853 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 3854 | */ |
| 3855 | net = NULL; |
| 3856 | SCTP_INP_INCR_REF(inp); |
| 3857 | stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL); |
| 3858 | if (stcb == NULL) { |
| 3859 | SCTP_INP_DECR_REF(inp); |
| 3860 | } |
| 3861 | } |
| 3862 | if ((stcb != NULL) && (net == NULL)) { |
| 3863 | #ifdef INET |
| 3864 | if (addr->sa_family == AF_INET) { |
| 3865 | struct sockaddr_in *sin; |
| 3866 |
| 3867 | sin = (struct sockaddr_in *)addr; |
| 3868 | if (sin->sin_addr.s_addr != INADDR_ANY) { |
| 3869 | error = EINVAL; |
| 3870 | SCTP_TCB_UNLOCK(stcb); |
| 3871 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3872 | break; |
| 3873 | } |
| 3874 | } else |
| 3875 | #endif |
| 3876 | #ifdef INET6 |
| 3877 | if (addr->sa_family == AF_INET6) { |
| 3878 | struct sockaddr_in6 *sin6; |
| 3879 |
| 3880 | sin6 = (struct sockaddr_in6 *)addr; |
| 3881 | if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 3882 | error = EINVAL; |
| 3883 | SCTP_TCB_UNLOCK(stcb); |
| 3884 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3885 | break; |
| 3886 | } |
| 3887 | } else |
| 3888 | #endif |
| 3889 | #if defined(__Userspace__) |
| 3890 | if (addr->sa_family == AF_CONN) { |
| 3891 | struct sockaddr_conn *sconn; |
| 3892 |
| 3893 | sconn = (struct sockaddr_conn *)addr; |
| 3894 | if (sconn->sconn_addr != NULL) { |
| 3895 | error = EINVAL; |
| 3896 | SCTP_TCB_UNLOCK(stcb); |
| 3897 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3898 | break; |
| 3899 | } |
| 3900 | } else |
| 3901 | #endif |
| 3902 | { |
| 3903 | error = EAFNOSUPPORT; |
| 3904 | SCTP_TCB_UNLOCK(stcb); |
| 3905 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3906 | break; |
| 3907 | } |
| 3908 | } |
| 3909 |
| 3910 | if (stcb != NULL) { |
| 3911 | if (net != NULL) { |
| 3912 | thlds->spt_pathmaxrxt = net->failure_threshold; |
| 3913 | thlds->spt_pathpfthld = net->pf_threshold; |
| 3914 | thlds->spt_pathcpthld = 0xffff; |
| 3915 | } else { |
| 3916 | thlds->spt_pathmaxrxt = stcb->asoc.def_net_failure; |
| 3917 | thlds->spt_pathpfthld = stcb->asoc.def_net_pf_threshold; |
| 3918 | thlds->spt_pathcpthld = 0xffff; |
| 3919 | } |
| 3920 | thlds->spt_assoc_id = sctp_get_associd(stcb); |
| 3921 | SCTP_TCB_UNLOCK(stcb); |
| 3922 | } else { |
| 3923 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 3924 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 3925 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 3926 | (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 3927 | /* Use endpoint defaults */ |
| 3928 | SCTP_INP_RLOCK(inp); |
| 3929 | thlds->spt_pathmaxrxt = inp->sctp_ep.def_net_failure; |
| 3930 | thlds->spt_pathpfthld = inp->sctp_ep.def_net_pf_threshold; |
| 3931 | thlds->spt_pathcpthld = 0xffff; |
| 3932 | SCTP_INP_RUNLOCK(inp); |
| 3933 | } else { |
| 3934 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 3935 | error = EINVAL; |
| 3936 | } |
| 3937 | } |
| 3938 | if (error == 0) { |
| 3939 | *optsize = sizeof(struct sctp_paddrthlds); |
| 3940 | } |
| 3941 | break; |
| 3942 | } |
| 3943 | case SCTP_REMOTE_UDP_ENCAPS_PORT: |
| 3944 | { |
| 3945 | struct sctp_udpencaps *encaps; |
| 3946 | struct sctp_nets *net; |
| 3947 | struct sockaddr *addr; |
| 3948 | #if defined(INET) && defined(INET6) |
| 3949 | struct sockaddr_in sin_store; |
| 3950 | #endif |
| 3951 |
| 3952 | SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, *optsize); |
| 3953 | SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id); |
| 3954 |
| 3955 | #if defined(INET) && defined(INET6) |
| 3956 | if (encaps->sue_address.ss_family == AF_INET6) { |
| 3957 | struct sockaddr_in6 *sin6; |
| 3958 |
| 3959 | sin6 = (struct sockaddr_in6 *)&encaps->sue_address; |
| 3960 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 3961 | in6_sin6_2_sin(&sin_store, sin6); |
| 3962 | addr = (struct sockaddr *)&sin_store; |
| 3963 | } else { |
| 3964 | addr = (struct sockaddr *)&encaps->sue_address; |
| 3965 | } |
| 3966 | } else { |
| 3967 | addr = (struct sockaddr *)&encaps->sue_address; |
| 3968 | } |
| 3969 | #else |
| 3970 | addr = (struct sockaddr *)&encaps->sue_address; |
| 3971 | #endif |
| 3972 | if (stcb) { |
| 3973 | net = sctp_findnet(stcb, addr); |
| 3974 | } else { |
| 3975 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 3976 | * do a decrement if it finds the stcb as long as the locked |
| 3977 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 3978 | */ |
| 3979 | net = NULL; |
| 3980 | SCTP_INP_INCR_REF(inp); |
| 3981 | stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL); |
| 3982 | if (stcb == NULL) { |
| 3983 | SCTP_INP_DECR_REF(inp); |
| 3984 | } |
| 3985 | } |
| 3986 | if ((stcb != NULL) && (net == NULL)) { |
| 3987 | #ifdef INET |
| 3988 | if (addr->sa_family == AF_INET) { |
| 3989 | struct sockaddr_in *sin; |
| 3990 |
| 3991 | sin = (struct sockaddr_in *)addr; |
| 3992 | if (sin->sin_addr.s_addr != INADDR_ANY) { |
| 3993 | error = EINVAL; |
| 3994 | SCTP_TCB_UNLOCK(stcb); |
| 3995 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 3996 | break; |
| 3997 | } |
| 3998 | } else |
| 3999 | #endif |
| 4000 | #ifdef INET6 |
| 4001 | if (addr->sa_family == AF_INET6) { |
| 4002 | struct sockaddr_in6 *sin6; |
| 4003 |
| 4004 | sin6 = (struct sockaddr_in6 *)addr; |
| 4005 | if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 4006 | error = EINVAL; |
| 4007 | SCTP_TCB_UNLOCK(stcb); |
| 4008 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 4009 | break; |
| 4010 | } |
| 4011 | } else |
| 4012 | #endif |
| 4013 | #if defined(__Userspace__) |
| 4014 | if (addr->sa_family == AF_CONN) { |
| 4015 | struct sockaddr_conn *sconn; |
| 4016 |
| 4017 | sconn = (struct sockaddr_conn *)addr; |
| 4018 | if (sconn->sconn_addr != NULL) { |
| 4019 | error = EINVAL; |
| 4020 | SCTP_TCB_UNLOCK(stcb); |
| 4021 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 4022 | break; |
| 4023 | } |
| 4024 | } else |
| 4025 | #endif |
| 4026 | { |
| 4027 | error = EAFNOSUPPORT; |
| 4028 | SCTP_TCB_UNLOCK(stcb); |
| 4029 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 4030 | break; |
| 4031 | } |
| 4032 | } |
| 4033 |
| 4034 | if (stcb != NULL) { |
| 4035 | if (net) { |
| 4036 | encaps->sue_port = net->port; |
| 4037 | } else { |
| 4038 | encaps->sue_port = stcb->asoc.port; |
| 4039 | } |
| 4040 | SCTP_TCB_UNLOCK(stcb); |
| 4041 | } else { |
| 4042 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4043 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4044 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4045 | (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4046 | SCTP_INP_RLOCK(inp); |
| 4047 | encaps->sue_port = inp->sctp_ep.port; |
| 4048 | SCTP_INP_RUNLOCK(inp); |
| 4049 | } else { |
| 4050 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4051 | error = EINVAL; |
| 4052 | } |
| 4053 | } |
| 4054 | if (error == 0) { |
| 4055 | *optsize = sizeof(struct sctp_udpencaps); |
| 4056 | } |
| 4057 | break; |
| 4058 | } |
| 4059 | case SCTP_ECN_SUPPORTED: |
| 4060 | { |
| 4061 | struct sctp_assoc_value *av; |
| 4062 |
| 4063 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4064 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4065 |
| 4066 | if (stcb) { |
| 4067 | av->assoc_value = stcb->asoc.ecn_supported; |
| 4068 | SCTP_TCB_UNLOCK(stcb); |
| 4069 | } else { |
| 4070 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4071 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4072 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4073 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4074 | SCTP_INP_RLOCK(inp); |
| 4075 | av->assoc_value = inp->ecn_supported; |
| 4076 | SCTP_INP_RUNLOCK(inp); |
| 4077 | } else { |
| 4078 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4079 | error = EINVAL; |
| 4080 | } |
| 4081 | } |
| 4082 | if (error == 0) { |
| 4083 | *optsize = sizeof(struct sctp_assoc_value); |
| 4084 | } |
| 4085 | break; |
| 4086 | } |
| 4087 | case SCTP_PR_SUPPORTED: |
| 4088 | { |
| 4089 | struct sctp_assoc_value *av; |
| 4090 |
| 4091 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4092 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4093 |
| 4094 | if (stcb) { |
| 4095 | av->assoc_value = stcb->asoc.prsctp_supported; |
| 4096 | SCTP_TCB_UNLOCK(stcb); |
| 4097 | } else { |
| 4098 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4099 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4100 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4101 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4102 | SCTP_INP_RLOCK(inp); |
| 4103 | av->assoc_value = inp->prsctp_supported; |
| 4104 | SCTP_INP_RUNLOCK(inp); |
| 4105 | } else { |
| 4106 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4107 | error = EINVAL; |
| 4108 | } |
| 4109 | } |
| 4110 | if (error == 0) { |
| 4111 | *optsize = sizeof(struct sctp_assoc_value); |
| 4112 | } |
| 4113 | break; |
| 4114 | } |
| 4115 | case SCTP_AUTH_SUPPORTED: |
| 4116 | { |
| 4117 | struct sctp_assoc_value *av; |
| 4118 |
| 4119 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4120 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4121 |
| 4122 | if (stcb) { |
| 4123 | av->assoc_value = stcb->asoc.auth_supported; |
| 4124 | SCTP_TCB_UNLOCK(stcb); |
| 4125 | } else { |
| 4126 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4127 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4128 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4129 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4130 | SCTP_INP_RLOCK(inp); |
| 4131 | av->assoc_value = inp->auth_supported; |
| 4132 | SCTP_INP_RUNLOCK(inp); |
| 4133 | } else { |
| 4134 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4135 | error = EINVAL; |
| 4136 | } |
| 4137 | } |
| 4138 | if (error == 0) { |
| 4139 | *optsize = sizeof(struct sctp_assoc_value); |
| 4140 | } |
| 4141 | break; |
| 4142 | } |
| 4143 | case SCTP_ASCONF_SUPPORTED: |
| 4144 | { |
| 4145 | struct sctp_assoc_value *av; |
| 4146 |
| 4147 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4148 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4149 |
| 4150 | if (stcb) { |
| 4151 | av->assoc_value = stcb->asoc.asconf_supported; |
| 4152 | SCTP_TCB_UNLOCK(stcb); |
| 4153 | } else { |
| 4154 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4155 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4156 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4157 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4158 | SCTP_INP_RLOCK(inp); |
| 4159 | av->assoc_value = inp->asconf_supported; |
| 4160 | SCTP_INP_RUNLOCK(inp); |
| 4161 | } else { |
| 4162 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4163 | error = EINVAL; |
| 4164 | } |
| 4165 | } |
| 4166 | if (error == 0) { |
| 4167 | *optsize = sizeof(struct sctp_assoc_value); |
| 4168 | } |
| 4169 | break; |
| 4170 | } |
| 4171 | case SCTP_RECONFIG_SUPPORTED: |
| 4172 | { |
| 4173 | struct sctp_assoc_value *av; |
| 4174 |
| 4175 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4176 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4177 |
| 4178 | if (stcb) { |
| 4179 | av->assoc_value = stcb->asoc.reconfig_supported; |
| 4180 | SCTP_TCB_UNLOCK(stcb); |
| 4181 | } else { |
| 4182 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4183 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4184 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4185 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4186 | SCTP_INP_RLOCK(inp); |
| 4187 | av->assoc_value = inp->reconfig_supported; |
| 4188 | SCTP_INP_RUNLOCK(inp); |
| 4189 | } else { |
| 4190 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4191 | error = EINVAL; |
| 4192 | } |
| 4193 | } |
| 4194 | if (error == 0) { |
| 4195 | *optsize = sizeof(struct sctp_assoc_value); |
| 4196 | } |
| 4197 | break; |
| 4198 | } |
| 4199 | case SCTP_NRSACK_SUPPORTED: |
| 4200 | { |
| 4201 | struct sctp_assoc_value *av; |
| 4202 |
| 4203 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4204 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4205 |
| 4206 | if (stcb) { |
| 4207 | av->assoc_value = stcb->asoc.nrsack_supported; |
| 4208 | SCTP_TCB_UNLOCK(stcb); |
| 4209 | } else { |
| 4210 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4211 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4212 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4213 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4214 | SCTP_INP_RLOCK(inp); |
| 4215 | av->assoc_value = inp->nrsack_supported; |
| 4216 | SCTP_INP_RUNLOCK(inp); |
| 4217 | } else { |
| 4218 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4219 | error = EINVAL; |
| 4220 | } |
| 4221 | } |
| 4222 | if (error == 0) { |
| 4223 | *optsize = sizeof(struct sctp_assoc_value); |
| 4224 | } |
| 4225 | break; |
| 4226 | } |
| 4227 | case SCTP_PKTDROP_SUPPORTED: |
| 4228 | { |
| 4229 | struct sctp_assoc_value *av; |
| 4230 |
| 4231 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4232 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4233 |
| 4234 | if (stcb) { |
| 4235 | av->assoc_value = stcb->asoc.pktdrop_supported; |
| 4236 | SCTP_TCB_UNLOCK(stcb); |
| 4237 | } else { |
| 4238 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4239 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4240 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4241 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4242 | SCTP_INP_RLOCK(inp); |
| 4243 | av->assoc_value = inp->pktdrop_supported; |
| 4244 | SCTP_INP_RUNLOCK(inp); |
| 4245 | } else { |
| 4246 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4247 | error = EINVAL; |
| 4248 | } |
| 4249 | } |
| 4250 | if (error == 0) { |
| 4251 | *optsize = sizeof(struct sctp_assoc_value); |
| 4252 | } |
| 4253 | break; |
| 4254 | } |
| 4255 | case SCTP_ENABLE_STREAM_RESET: |
| 4256 | { |
| 4257 | struct sctp_assoc_value *av; |
| 4258 |
| 4259 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4260 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4261 |
| 4262 | if (stcb) { |
| 4263 | av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support; |
| 4264 | SCTP_TCB_UNLOCK(stcb); |
| 4265 | } else { |
| 4266 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4267 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4268 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4269 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4270 | SCTP_INP_RLOCK(inp); |
| 4271 | av->assoc_value = (uint32_t)inp->local_strreset_support; |
| 4272 | SCTP_INP_RUNLOCK(inp); |
| 4273 | } else { |
| 4274 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4275 | error = EINVAL; |
| 4276 | } |
| 4277 | } |
| 4278 | if (error == 0) { |
| 4279 | *optsize = sizeof(struct sctp_assoc_value); |
| 4280 | } |
| 4281 | break; |
| 4282 | } |
| 4283 | case SCTP_PR_STREAM_STATUS: |
| 4284 | { |
| 4285 | struct sctp_prstatus *sprstat; |
| 4286 | uint16_t sid; |
| 4287 | uint16_t policy; |
| 4288 |
| 4289 | SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize); |
| 4290 | SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id); |
| 4291 |
| 4292 | sid = sprstat->sprstat_sid; |
| 4293 | policy = sprstat->sprstat_policy; |
| 4294 | #if defined(SCTP_DETAILED_STR_STATS) |
| 4295 | if ((stcb != NULL) && |
| 4296 | (sid < stcb->asoc.streamoutcnt) && |
| 4297 | (policy != SCTP_PR_SCTP_NONE) && |
| 4298 | ((policy <= SCTP_PR_SCTP_MAX) || |
| 4299 | (policy == SCTP_PR_SCTP_ALL))) { |
| 4300 | if (policy == SCTP_PR_SCTP_ALL) { |
| 4301 | sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0]; |
| 4302 | sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0]; |
| 4303 | } else { |
| 4304 | sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[policy]; |
| 4305 | sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[policy]; |
| 4306 | } |
| 4307 | #else |
| 4308 | if ((stcb != NULL) && |
| 4309 | (sid < stcb->asoc.streamoutcnt) && |
| 4310 | (policy == SCTP_PR_SCTP_ALL)) { |
| 4311 | sprstat->sprstat_abandoned_unsent = stcb->asoc.strmout[sid].abandoned_unsent[0]; |
| 4312 | sprstat->sprstat_abandoned_sent = stcb->asoc.strmout[sid].abandoned_sent[0]; |
| 4313 | #endif |
| 4314 | } else { |
| 4315 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4316 | error = EINVAL; |
| 4317 | } |
| 4318 | if (stcb != NULL) { |
| 4319 | SCTP_TCB_UNLOCK(stcb); |
| 4320 | } |
| 4321 | if (error == 0) { |
| 4322 | *optsize = sizeof(struct sctp_prstatus); |
| 4323 | } |
| 4324 | break; |
| 4325 | } |
| 4326 | case SCTP_PR_ASSOC_STATUS: |
| 4327 | { |
| 4328 | struct sctp_prstatus *sprstat; |
| 4329 | uint16_t policy; |
| 4330 |
| 4331 | SCTP_CHECK_AND_CAST(sprstat, optval, struct sctp_prstatus, *optsize); |
| 4332 | SCTP_FIND_STCB(inp, stcb, sprstat->sprstat_assoc_id); |
| 4333 |
| 4334 | policy = sprstat->sprstat_policy; |
| 4335 | if ((stcb != NULL) && |
| 4336 | (policy != SCTP_PR_SCTP_NONE) && |
| 4337 | ((policy <= SCTP_PR_SCTP_MAX) || |
| 4338 | (policy == SCTP_PR_SCTP_ALL))) { |
| 4339 | if (policy == SCTP_PR_SCTP_ALL) { |
| 4340 | sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[0]; |
| 4341 | sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[0]; |
| 4342 | } else { |
| 4343 | sprstat->sprstat_abandoned_unsent = stcb->asoc.abandoned_unsent[policy]; |
| 4344 | sprstat->sprstat_abandoned_sent = stcb->asoc.abandoned_sent[policy]; |
| 4345 | } |
| 4346 | } else { |
| 4347 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4348 | error = EINVAL; |
| 4349 | } |
| 4350 | if (stcb != NULL) { |
| 4351 | SCTP_TCB_UNLOCK(stcb); |
| 4352 | } |
| 4353 | if (error == 0) { |
| 4354 | *optsize = sizeof(struct sctp_prstatus); |
| 4355 | } |
| 4356 | break; |
| 4357 | } |
| 4358 | case SCTP_MAX_CWND: |
| 4359 | { |
| 4360 | struct sctp_assoc_value *av; |
| 4361 |
| 4362 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, *optsize); |
| 4363 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4364 |
| 4365 | if (stcb) { |
| 4366 | av->assoc_value = stcb->asoc.max_cwnd; |
| 4367 | SCTP_TCB_UNLOCK(stcb); |
| 4368 | } else { |
| 4369 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4370 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4371 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4372 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4373 | SCTP_INP_RLOCK(inp); |
| 4374 | av->assoc_value = inp->max_cwnd; |
| 4375 | SCTP_INP_RUNLOCK(inp); |
| 4376 | } else { |
| 4377 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4378 | error = EINVAL; |
| 4379 | } |
| 4380 | } |
| 4381 | if (error == 0) { |
| 4382 | *optsize = sizeof(struct sctp_assoc_value); |
| 4383 | } |
| 4384 | break; |
| 4385 | } |
| 4386 | default: |
| 4387 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); |
| 4388 | error = ENOPROTOOPT; |
| 4389 | break; |
| 4390 | } /* end switch (sopt->sopt_name) */ |
| 4391 | if (error) { |
| 4392 | *optsize = 0; |
| 4393 | } |
| 4394 | return (error); |
| 4395 | } |
| 4396 |
| 4397 | #if defined(__Userspace__) |
| 4398 | int |
| 4399 | #else |
| 4400 | static int |
| 4401 | #endif |
| 4402 | sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, |
| 4403 | void *p) |
| 4404 | { |
| 4405 | int error, set_opt; |
| 4406 | uint32_t *mopt; |
| 4407 | struct sctp_tcb *stcb = NULL; |
| 4408 | struct sctp_inpcb *inp = NULL; |
| 4409 | uint32_t vrf_id; |
| 4410 |
| 4411 | if (optval == NULL) { |
| 4412 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4413 | return (EINVAL); |
| 4414 | } |
| 4415 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 4416 | if (inp == NULL) { |
| 4417 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4418 | return (EINVAL); |
| 4419 | } |
| 4420 | vrf_id = inp->def_vrf_id; |
| 4421 |
| 4422 | error = 0; |
| 4423 | switch (optname) { |
| 4424 | case SCTP_NODELAY: |
| 4425 | case SCTP_AUTOCLOSE: |
| 4426 | case SCTP_AUTO_ASCONF: |
| 4427 | case SCTP_EXPLICIT_EOR: |
| 4428 | case SCTP_DISABLE_FRAGMENTS: |
| 4429 | case SCTP_USE_EXT_RCVINFO: |
| 4430 | case SCTP_I_WANT_MAPPED_V4_ADDR: |
| 4431 | /* copy in the option value */ |
| 4432 | SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize); |
| 4433 | set_opt = 0; |
| 4434 | if (error) |
| 4435 | break; |
| 4436 | switch (optname) { |
| 4437 | case SCTP_DISABLE_FRAGMENTS: |
| 4438 | set_opt = SCTP_PCB_FLAGS_NO_FRAGMENT; |
| 4439 | break; |
| 4440 | case SCTP_AUTO_ASCONF: |
| 4441 | /* |
| 4442 | * NOTE: we don't really support this flag |
| 4443 | */ |
| 4444 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
| 4445 | /* only valid for bound all sockets */ |
| 4446 | if ((SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) && |
| 4447 | (*mopt != 0)) { |
| 4448 | /* forbidden by admin */ |
| 4449 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EPERM); |
| 4450 | return (EPERM); |
| 4451 | } |
| 4452 | set_opt = SCTP_PCB_FLAGS_AUTO_ASCONF; |
| 4453 | } else { |
| 4454 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4455 | return (EINVAL); |
| 4456 | } |
| 4457 | break; |
| 4458 | case SCTP_EXPLICIT_EOR: |
| 4459 | set_opt = SCTP_PCB_FLAGS_EXPLICIT_EOR; |
| 4460 | break; |
| 4461 | case SCTP_USE_EXT_RCVINFO: |
| 4462 | set_opt = SCTP_PCB_FLAGS_EXT_RCVINFO; |
| 4463 | break; |
| 4464 | case SCTP_I_WANT_MAPPED_V4_ADDR: |
| 4465 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
| 4466 | set_opt = SCTP_PCB_FLAGS_NEEDS_MAPPED_V4; |
| 4467 | } else { |
| 4468 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4469 | return (EINVAL); |
| 4470 | } |
| 4471 | break; |
| 4472 | case SCTP_NODELAY: |
| 4473 | set_opt = SCTP_PCB_FLAGS_NODELAY; |
| 4474 | break; |
| 4475 | case SCTP_AUTOCLOSE: |
| 4476 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4477 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 4478 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4479 | return (EINVAL); |
| 4480 | } |
| 4481 | set_opt = SCTP_PCB_FLAGS_AUTOCLOSE; |
| 4482 | /* |
| 4483 | * The value is in ticks. Note this does not effect |
| 4484 | * old associations, only new ones. |
| 4485 | */ |
| 4486 | inp->sctp_ep.auto_close_time = sctp_secs_to_ticks(*mopt); |
| 4487 | break; |
| 4488 | } |
| 4489 | SCTP_INP_WLOCK(inp); |
| 4490 | if (*mopt != 0) { |
| 4491 | sctp_feature_on(inp, set_opt); |
| 4492 | } else { |
| 4493 | sctp_feature_off(inp, set_opt); |
| 4494 | } |
| 4495 | SCTP_INP_WUNLOCK(inp); |
| 4496 | break; |
| 4497 | case SCTP_REUSE_PORT: |
| 4498 | { |
| 4499 | SCTP_CHECK_AND_CAST(mopt, optval, uint32_t, optsize); |
| 4500 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) { |
| 4501 | /* Can't set it after we are bound */ |
| 4502 | error = EINVAL; |
| 4503 | break; |
| 4504 | } |
| 4505 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) { |
| 4506 | /* Can't do this for a 1-m socket */ |
| 4507 | error = EINVAL; |
| 4508 | break; |
| 4509 | } |
| 4510 | if (optval) |
| 4511 | sctp_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE); |
| 4512 | else |
| 4513 | sctp_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE); |
| 4514 | break; |
| 4515 | } |
| 4516 | case SCTP_PARTIAL_DELIVERY_POINT: |
| 4517 | { |
| 4518 | uint32_t *value; |
| 4519 |
| 4520 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize); |
| 4521 | if (*value > SCTP_SB_LIMIT_RCV(so)) { |
| 4522 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4523 | error = EINVAL; |
| 4524 | break; |
| 4525 | } |
| 4526 | inp->partial_delivery_point = *value; |
| 4527 | break; |
| 4528 | } |
| 4529 | case SCTP_FRAGMENT_INTERLEAVE: |
| 4530 | /* not yet until we re-write sctp_recvmsg() */ |
| 4531 | { |
| 4532 | uint32_t *level; |
| 4533 |
| 4534 | SCTP_CHECK_AND_CAST(level, optval, uint32_t, optsize); |
| 4535 | if (*level == SCTP_FRAG_LEVEL_2) { |
| 4536 | sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE); |
| 4537 | sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS); |
| 4538 | } else if (*level == SCTP_FRAG_LEVEL_1) { |
| 4539 | sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE); |
| 4540 | sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS); |
| 4541 | } else if (*level == SCTP_FRAG_LEVEL_0) { |
| 4542 | sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE); |
| 4543 | sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS); |
| 4544 |
| 4545 | } else { |
| 4546 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4547 | error = EINVAL; |
| 4548 | } |
| 4549 | break; |
| 4550 | } |
| 4551 | case SCTP_INTERLEAVING_SUPPORTED: |
| 4552 | { |
| 4553 | struct sctp_assoc_value *av; |
| 4554 |
| 4555 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 4556 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4557 |
| 4558 | if (stcb) { |
| 4559 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4560 | error = EINVAL; |
| 4561 | SCTP_TCB_UNLOCK(stcb); |
| 4562 | } else { |
| 4563 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4564 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4565 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4566 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 4567 | SCTP_INP_WLOCK(inp); |
| 4568 | if (av->assoc_value == 0) { |
| 4569 | inp->idata_supported = 0; |
| 4570 | } else { |
| 4571 | if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) && |
| 4572 | (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) { |
| 4573 | inp->idata_supported = 1; |
| 4574 | } else { |
| 4575 | /* Must have Frag interleave and stream interleave on */ |
| 4576 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4577 | error = EINVAL; |
| 4578 | } |
| 4579 | } |
| 4580 | SCTP_INP_WUNLOCK(inp); |
| 4581 | } else { |
| 4582 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4583 | error = EINVAL; |
| 4584 | } |
| 4585 | } |
| 4586 | break; |
| 4587 | } |
| 4588 | case SCTP_CMT_ON_OFF: |
| 4589 | if (SCTP_BASE_SYSCTL(sctp_cmt_on_off)) { |
| 4590 | struct sctp_assoc_value *av; |
| 4591 |
| 4592 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 4593 | if (av->assoc_value > SCTP_CMT_MAX) { |
| 4594 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4595 | error = EINVAL; |
| 4596 | break; |
| 4597 | } |
| 4598 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4599 | if (stcb) { |
| 4600 | stcb->asoc.sctp_cmt_on_off = av->assoc_value; |
| 4601 | SCTP_TCB_UNLOCK(stcb); |
| 4602 | } else { |
| 4603 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4604 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4605 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4606 | ((av->assoc_id == SCTP_FUTURE_ASSOC) || |
| 4607 | (av->assoc_id == SCTP_ALL_ASSOC)))) { |
| 4608 | SCTP_INP_WLOCK(inp); |
| 4609 | inp->sctp_cmt_on_off = av->assoc_value; |
| 4610 | SCTP_INP_WUNLOCK(inp); |
| 4611 | } |
| 4612 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4613 | ((av->assoc_id == SCTP_CURRENT_ASSOC) || |
| 4614 | (av->assoc_id == SCTP_ALL_ASSOC))) { |
| 4615 | SCTP_INP_RLOCK(inp); |
| 4616 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 4617 | SCTP_TCB_LOCK(stcb); |
| 4618 | stcb->asoc.sctp_cmt_on_off = av->assoc_value; |
| 4619 | SCTP_TCB_UNLOCK(stcb); |
| 4620 | } |
| 4621 | SCTP_INP_RUNLOCK(inp); |
| 4622 | } |
| 4623 | } |
| 4624 | } else { |
| 4625 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); |
| 4626 | error = ENOPROTOOPT; |
| 4627 | } |
| 4628 | break; |
| 4629 | case SCTP_PLUGGABLE_CC: |
| 4630 | { |
| 4631 | struct sctp_assoc_value *av; |
| 4632 | struct sctp_nets *net; |
| 4633 |
| 4634 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 4635 | if ((av->assoc_value != SCTP_CC_RFC2581) && |
| 4636 | (av->assoc_value != SCTP_CC_HSTCP) && |
| 4637 | (av->assoc_value != SCTP_CC_HTCP) && |
| 4638 | (av->assoc_value != SCTP_CC_RTCC)) { |
| 4639 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4640 | error = EINVAL; |
| 4641 | break; |
| 4642 | } |
| 4643 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4644 | if (stcb) { |
| 4645 | stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value]; |
| 4646 | stcb->asoc.congestion_control_module = av->assoc_value; |
| 4647 | if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) { |
| 4648 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 4649 | stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); |
| 4650 | } |
| 4651 | } |
| 4652 | SCTP_TCB_UNLOCK(stcb); |
| 4653 | } else { |
| 4654 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4655 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4656 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4657 | ((av->assoc_id == SCTP_FUTURE_ASSOC) || |
| 4658 | (av->assoc_id == SCTP_ALL_ASSOC)))) { |
| 4659 | SCTP_INP_WLOCK(inp); |
| 4660 | inp->sctp_ep.sctp_default_cc_module = av->assoc_value; |
| 4661 | SCTP_INP_WUNLOCK(inp); |
| 4662 | } |
| 4663 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4664 | ((av->assoc_id == SCTP_CURRENT_ASSOC) || |
| 4665 | (av->assoc_id == SCTP_ALL_ASSOC))) { |
| 4666 | SCTP_INP_RLOCK(inp); |
| 4667 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 4668 | SCTP_TCB_LOCK(stcb); |
| 4669 | stcb->asoc.cc_functions = sctp_cc_functions[av->assoc_value]; |
| 4670 | stcb->asoc.congestion_control_module = av->assoc_value; |
| 4671 | if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL) { |
| 4672 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 4673 | stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); |
| 4674 | } |
| 4675 | } |
| 4676 | SCTP_TCB_UNLOCK(stcb); |
| 4677 | } |
| 4678 | SCTP_INP_RUNLOCK(inp); |
| 4679 | } |
| 4680 | } |
| 4681 | break; |
| 4682 | } |
| 4683 | case SCTP_CC_OPTION: |
| 4684 | { |
| 4685 | struct sctp_cc_option *cc_opt; |
| 4686 |
| 4687 | SCTP_CHECK_AND_CAST(cc_opt, optval, struct sctp_cc_option, optsize); |
| 4688 | SCTP_FIND_STCB(inp, stcb, cc_opt->aid_value.assoc_id); |
| 4689 | if (stcb == NULL) { |
| 4690 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4691 | (cc_opt->aid_value.assoc_id == SCTP_CURRENT_ASSOC)) { |
| 4692 | SCTP_INP_RLOCK(inp); |
| 4693 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 4694 | SCTP_TCB_LOCK(stcb); |
| 4695 | if (stcb->asoc.cc_functions.sctp_cwnd_socket_option) { |
| 4696 | (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 1, cc_opt); |
| 4697 | } |
| 4698 | SCTP_TCB_UNLOCK(stcb); |
| 4699 | } |
| 4700 | SCTP_INP_RUNLOCK(inp); |
| 4701 | } else { |
| 4702 | error = EINVAL; |
| 4703 | } |
| 4704 | } else { |
| 4705 | if (stcb->asoc.cc_functions.sctp_cwnd_socket_option == NULL) { |
| 4706 | error = ENOTSUP; |
| 4707 | } else { |
| 4708 | error = (*stcb->asoc.cc_functions.sctp_cwnd_socket_option)(stcb, 1, |
| 4709 | cc_opt); |
| 4710 | } |
| 4711 | SCTP_TCB_UNLOCK(stcb); |
| 4712 | } |
| 4713 | break; |
| 4714 | } |
| 4715 | case SCTP_PLUGGABLE_SS: |
| 4716 | { |
| 4717 | struct sctp_assoc_value *av; |
| 4718 |
| 4719 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 4720 | if ((av->assoc_value != SCTP_SS_DEFAULT) && |
| 4721 | (av->assoc_value != SCTP_SS_ROUND_ROBIN) && |
| 4722 | (av->assoc_value != SCTP_SS_ROUND_ROBIN_PACKET) && |
| 4723 | (av->assoc_value != SCTP_SS_PRIORITY) && |
| 4724 | (av->assoc_value != SCTP_SS_FAIR_BANDWITH) && |
| 4725 | (av->assoc_value != SCTP_SS_FIRST_COME)) { |
| 4726 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4727 | error = EINVAL; |
| 4728 | break; |
| 4729 | } |
| 4730 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4731 | if (stcb) { |
| 4732 | SCTP_TCB_SEND_LOCK(stcb); |
| 4733 | stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1); |
| 4734 | stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value]; |
| 4735 | stcb->asoc.stream_scheduling_module = av->assoc_value; |
| 4736 | stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); |
| 4737 | SCTP_TCB_SEND_UNLOCK(stcb); |
| 4738 | SCTP_TCB_UNLOCK(stcb); |
| 4739 | } else { |
| 4740 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4741 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4742 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4743 | ((av->assoc_id == SCTP_FUTURE_ASSOC) || |
| 4744 | (av->assoc_id == SCTP_ALL_ASSOC)))) { |
| 4745 | SCTP_INP_WLOCK(inp); |
| 4746 | inp->sctp_ep.sctp_default_ss_module = av->assoc_value; |
| 4747 | SCTP_INP_WUNLOCK(inp); |
| 4748 | } |
| 4749 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4750 | ((av->assoc_id == SCTP_CURRENT_ASSOC) || |
| 4751 | (av->assoc_id == SCTP_ALL_ASSOC))) { |
| 4752 | SCTP_INP_RLOCK(inp); |
| 4753 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 4754 | SCTP_TCB_LOCK(stcb); |
| 4755 | SCTP_TCB_SEND_LOCK(stcb); |
| 4756 | stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1); |
| 4757 | stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value]; |
| 4758 | stcb->asoc.stream_scheduling_module = av->assoc_value; |
| 4759 | stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); |
| 4760 | SCTP_TCB_SEND_UNLOCK(stcb); |
| 4761 | SCTP_TCB_UNLOCK(stcb); |
| 4762 | } |
| 4763 | SCTP_INP_RUNLOCK(inp); |
| 4764 | } |
| 4765 | } |
| 4766 | break; |
| 4767 | } |
| 4768 | case SCTP_SS_VALUE: |
| 4769 | { |
| 4770 | struct sctp_stream_value *av; |
| 4771 |
| 4772 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_stream_value, optsize); |
| 4773 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4774 | if (stcb) { |
| 4775 | if ((av->stream_id >= stcb->asoc.streamoutcnt) || |
| 4776 | (stcb->asoc.ss_functions.sctp_ss_set_value(stcb, &stcb->asoc, &stcb->asoc.strmout[av->stream_id], |
| 4777 | av->stream_value) < 0)) { |
| 4778 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4779 | error = EINVAL; |
| 4780 | } |
| 4781 | SCTP_TCB_UNLOCK(stcb); |
| 4782 | } else { |
| 4783 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4784 | (av->assoc_id == SCTP_CURRENT_ASSOC)) { |
| 4785 | SCTP_INP_RLOCK(inp); |
| 4786 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 4787 | SCTP_TCB_LOCK(stcb); |
| 4788 | if (av->stream_id < stcb->asoc.streamoutcnt) { |
| 4789 | stcb->asoc.ss_functions.sctp_ss_set_value(stcb, |
| 4790 | &stcb->asoc, |
| 4791 | &stcb->asoc.strmout[av->stream_id], |
| 4792 | av->stream_value); |
| 4793 | } |
| 4794 | SCTP_TCB_UNLOCK(stcb); |
| 4795 | } |
| 4796 | SCTP_INP_RUNLOCK(inp); |
| 4797 | } else { |
| 4798 | /* Can't set stream value without association */ |
| 4799 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4800 | error = EINVAL; |
| 4801 | } |
| 4802 | } |
| 4803 | break; |
| 4804 | } |
| 4805 | case SCTP_CLR_STAT_LOG: |
| 4806 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 4807 | error = EOPNOTSUPP; |
| 4808 | break; |
| 4809 | case SCTP_CONTEXT: |
| 4810 | { |
| 4811 | struct sctp_assoc_value *av; |
| 4812 |
| 4813 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 4814 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 4815 |
| 4816 | if (stcb) { |
| 4817 | stcb->asoc.context = av->assoc_value; |
| 4818 | SCTP_TCB_UNLOCK(stcb); |
| 4819 | } else { |
| 4820 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 4821 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 4822 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4823 | ((av->assoc_id == SCTP_FUTURE_ASSOC) || |
| 4824 | (av->assoc_id == SCTP_ALL_ASSOC)))) { |
| 4825 | SCTP_INP_WLOCK(inp); |
| 4826 | inp->sctp_context = av->assoc_value; |
| 4827 | SCTP_INP_WUNLOCK(inp); |
| 4828 | } |
| 4829 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 4830 | ((av->assoc_id == SCTP_CURRENT_ASSOC) || |
| 4831 | (av->assoc_id == SCTP_ALL_ASSOC))) { |
| 4832 | SCTP_INP_RLOCK(inp); |
| 4833 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 4834 | SCTP_TCB_LOCK(stcb); |
| 4835 | stcb->asoc.context = av->assoc_value; |
| 4836 | SCTP_TCB_UNLOCK(stcb); |
| 4837 | } |
| 4838 | SCTP_INP_RUNLOCK(inp); |
| 4839 | } |
| 4840 | } |
| 4841 | break; |
| 4842 | } |
| 4843 | case SCTP_VRF_ID: |
| 4844 | { |
| 4845 | uint32_t *default_vrfid; |
| 4846 | #ifdef SCTP_MVRF |
| 4847 | int i; |
| 4848 | #endif |
| 4849 | SCTP_CHECK_AND_CAST(default_vrfid, optval, uint32_t, optsize); |
| 4850 | if (*default_vrfid > SCTP_MAX_VRF_ID) { |
| 4851 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4852 | error = EINVAL; |
| 4853 | break; |
| 4854 | } |
| 4855 | #ifdef SCTP_MVRF |
| 4856 | for (i = 0; i < inp->num_vrfs; i++) { |
| 4857 | /* The VRF must be in the VRF list */ |
| 4858 | if (*default_vrfid == inp->m_vrf_ids[i]) { |
| 4859 | SCTP_INP_WLOCK(inp); |
| 4860 | inp->def_vrf_id = *default_vrfid; |
| 4861 | SCTP_INP_WUNLOCK(inp); |
| 4862 | goto sctp_done; |
| 4863 | } |
| 4864 | } |
| 4865 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4866 | error = EINVAL; |
| 4867 | #else |
| 4868 | inp->def_vrf_id = *default_vrfid; |
| 4869 | #endif |
| 4870 | #ifdef SCTP_MVRF |
| 4871 | sctp_done: |
| 4872 | #endif |
| 4873 | break; |
| 4874 | } |
| 4875 | case SCTP_DEL_VRF_ID: |
| 4876 | { |
| 4877 | #ifdef SCTP_MVRF |
| 4878 | uint32_t *del_vrfid; |
| 4879 | int i, fnd = 0; |
| 4880 |
| 4881 | SCTP_CHECK_AND_CAST(del_vrfid, optval, uint32_t, optsize); |
| 4882 | if (*del_vrfid > SCTP_MAX_VRF_ID) { |
| 4883 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4884 | error = EINVAL; |
| 4885 | break; |
| 4886 | } |
| 4887 | if (inp->num_vrfs == 1) { |
| 4888 | /* Can't delete last one */ |
| 4889 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4890 | error = EINVAL; |
| 4891 | break; |
| 4892 | } |
| 4893 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) { |
| 4894 | /* Can't add more once you are bound */ |
| 4895 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4896 | error = EINVAL; |
| 4897 | break; |
| 4898 | } |
| 4899 | SCTP_INP_WLOCK(inp); |
| 4900 | for (i = 0; i < inp->num_vrfs; i++) { |
| 4901 | if (*del_vrfid == inp->m_vrf_ids[i]) { |
| 4902 | fnd = 1; |
| 4903 | break; |
| 4904 | } |
| 4905 | } |
| 4906 | if (!fnd) { |
| 4907 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4908 | error = EINVAL; |
| 4909 | break; |
| 4910 | } |
| 4911 | if (i != (inp->num_vrfs - 1)) { |
| 4912 | /* Take bottom one and move to this slot */ |
| 4913 | inp->m_vrf_ids[i] = inp->m_vrf_ids[(inp->num_vrfs-1)]; |
| 4914 | } |
| 4915 | if (*del_vrfid == inp->def_vrf_id) { |
| 4916 | /* Take the first one as the new default */ |
| 4917 | inp->def_vrf_id = inp->m_vrf_ids[0]; |
| 4918 | } |
| 4919 | /* Drop the number by one killing last one */ |
| 4920 | inp->num_vrfs--; |
| 4921 | #else |
| 4922 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 4923 | error = EOPNOTSUPP; |
| 4924 | #endif |
| 4925 | break; |
| 4926 | } |
| 4927 | case SCTP_ADD_VRF_ID: |
| 4928 | { |
| 4929 | #ifdef SCTP_MVRF |
| 4930 | uint32_t *add_vrfid; |
| 4931 | int i; |
| 4932 |
| 4933 | SCTP_CHECK_AND_CAST(add_vrfid, optval, uint32_t, optsize); |
| 4934 | if (*add_vrfid > SCTP_MAX_VRF_ID) { |
| 4935 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4936 | error = EINVAL; |
| 4937 | break; |
| 4938 | } |
| 4939 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) { |
| 4940 | /* Can't add more once you are bound */ |
| 4941 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 4942 | error = EINVAL; |
| 4943 | break; |
| 4944 | } |
| 4945 | SCTP_INP_WLOCK(inp); |
| 4946 | /* Verify its not already here */ |
| 4947 | for (i = 0; i < inp->num_vrfs; i++) { |
| 4948 | if (*add_vrfid == inp->m_vrf_ids[i]) { |
| 4949 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 4950 | error = EALREADY; |
| 4951 | SCTP_INP_WUNLOCK(inp); |
| 4952 | break; |
| 4953 | } |
| 4954 | } |
| 4955 | if ((inp->num_vrfs + 1) > inp->vrf_size) { |
| 4956 | /* need to grow array */ |
| 4957 | uint32_t *tarray; |
| 4958 | SCTP_MALLOC(tarray, uint32_t *, |
| 4959 | (sizeof(uint32_t) * (inp->vrf_size + SCTP_DEFAULT_VRF_SIZE)), |
| 4960 | SCTP_M_MVRF); |
| 4961 | if (tarray == NULL) { |
| 4962 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 4963 | error = ENOMEM; |
| 4964 | SCTP_INP_WUNLOCK(inp); |
| 4965 | break; |
| 4966 | } |
| 4967 | memcpy(tarray, inp->m_vrf_ids, (sizeof(uint32_t) * inp->vrf_size)); |
| 4968 | SCTP_FREE(inp->m_vrf_ids, SCTP_M_MVRF); |
| 4969 | inp->m_vrf_ids = tarray; |
| 4970 | inp->vrf_size += SCTP_DEFAULT_VRF_SIZE; |
| 4971 | } |
| 4972 | inp->m_vrf_ids[inp->num_vrfs] = *add_vrfid; |
| 4973 | inp->num_vrfs++; |
| 4974 | SCTP_INP_WUNLOCK(inp); |
| 4975 | #else |
| 4976 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 4977 | error = EOPNOTSUPP; |
| 4978 | #endif |
| 4979 | break; |
| 4980 | } |
| 4981 | case SCTP_DELAYED_SACK: |
| 4982 | { |
| 4983 | struct sctp_sack_info *sack; |
| 4984 |
| 4985 | SCTP_CHECK_AND_CAST(sack, optval, struct sctp_sack_info, optsize); |
| 4986 | SCTP_FIND_STCB(inp, stcb, sack->sack_assoc_id); |
| 4987 | if (sack->sack_delay) { |
| 4988 | if (sack->sack_delay > SCTP_MAX_SACK_DELAY) { |
| 4989 | error = EINVAL; |
| 4990 | if (stcb != NULL) { |
| 4991 | SCTP_TCB_UNLOCK(stcb); |
| 4992 | } |
| 4993 | break; |
| 4994 | } |
| 4995 | } |
| 4996 | if (stcb) { |
| 4997 | if (sack->sack_delay) { |
| 4998 | stcb->asoc.delayed_ack = sack->sack_delay; |
| 4999 | } |
| 5000 | if (sack->sack_freq) { |
| 5001 | stcb->asoc.sack_freq = sack->sack_freq; |
| 5002 | } |
| 5003 | SCTP_TCB_UNLOCK(stcb); |
| 5004 | } else { |
| 5005 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5006 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5007 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5008 | ((sack->sack_assoc_id == SCTP_FUTURE_ASSOC) || |
| 5009 | (sack->sack_assoc_id == SCTP_ALL_ASSOC)))) { |
| 5010 | SCTP_INP_WLOCK(inp); |
| 5011 | if (sack->sack_delay) { |
| 5012 | inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV] = sctp_msecs_to_ticks(sack->sack_delay); |
| 5013 | } |
| 5014 | if (sack->sack_freq) { |
| 5015 | inp->sctp_ep.sctp_sack_freq = sack->sack_freq; |
| 5016 | } |
| 5017 | SCTP_INP_WUNLOCK(inp); |
| 5018 | } |
| 5019 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5020 | ((sack->sack_assoc_id == SCTP_CURRENT_ASSOC) || |
| 5021 | (sack->sack_assoc_id == SCTP_ALL_ASSOC))) { |
| 5022 | SCTP_INP_RLOCK(inp); |
| 5023 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5024 | SCTP_TCB_LOCK(stcb); |
| 5025 | if (sack->sack_delay) { |
| 5026 | stcb->asoc.delayed_ack = sack->sack_delay; |
| 5027 | } |
| 5028 | if (sack->sack_freq) { |
| 5029 | stcb->asoc.sack_freq = sack->sack_freq; |
| 5030 | } |
| 5031 | SCTP_TCB_UNLOCK(stcb); |
| 5032 | } |
| 5033 | SCTP_INP_RUNLOCK(inp); |
| 5034 | } |
| 5035 | } |
| 5036 | break; |
| 5037 | } |
| 5038 | case SCTP_AUTH_CHUNK: |
| 5039 | { |
| 5040 | struct sctp_authchunk *sauth; |
| 5041 |
| 5042 | SCTP_CHECK_AND_CAST(sauth, optval, struct sctp_authchunk, optsize); |
| 5043 |
| 5044 | SCTP_INP_WLOCK(inp); |
| 5045 | if (sctp_auth_add_chunk(sauth->sauth_chunk, inp->sctp_ep.local_auth_chunks)) { |
| 5046 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5047 | error = EINVAL; |
| 5048 | } else { |
| 5049 | inp->auth_supported = 1; |
| 5050 | } |
| 5051 | SCTP_INP_WUNLOCK(inp); |
| 5052 | break; |
| 5053 | } |
| 5054 | case SCTP_AUTH_KEY: |
| 5055 | { |
| 5056 | struct sctp_authkey *sca; |
| 5057 | struct sctp_keyhead *shared_keys; |
| 5058 | sctp_sharedkey_t *shared_key; |
| 5059 | sctp_key_t *key = NULL; |
| 5060 | size_t size; |
| 5061 |
| 5062 | SCTP_CHECK_AND_CAST(sca, optval, struct sctp_authkey, optsize); |
| 5063 | if (sca->sca_keylength == 0) { |
| 5064 | size = optsize - sizeof(struct sctp_authkey); |
| 5065 | } else { |
| 5066 | if (sca->sca_keylength + sizeof(struct sctp_authkey) <= optsize) { |
| 5067 | size = sca->sca_keylength; |
| 5068 | } else { |
| 5069 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5070 | error = EINVAL; |
| 5071 | break; |
| 5072 | } |
| 5073 | } |
| 5074 | SCTP_FIND_STCB(inp, stcb, sca->sca_assoc_id); |
| 5075 |
| 5076 | if (stcb) { |
| 5077 | shared_keys = &stcb->asoc.shared_keys; |
| 5078 | /* clear the cached keys for this key id */ |
| 5079 | sctp_clear_cachedkeys(stcb, sca->sca_keynumber); |
| 5080 | /* |
| 5081 | * create the new shared key and |
| 5082 | * insert/replace it |
| 5083 | */ |
| 5084 | if (size > 0) { |
| 5085 | key = sctp_set_key(sca->sca_key, (uint32_t) size); |
| 5086 | if (key == NULL) { |
| 5087 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 5088 | error = ENOMEM; |
| 5089 | SCTP_TCB_UNLOCK(stcb); |
| 5090 | break; |
| 5091 | } |
| 5092 | } |
| 5093 | shared_key = sctp_alloc_sharedkey(); |
| 5094 | if (shared_key == NULL) { |
| 5095 | sctp_free_key(key); |
| 5096 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 5097 | error = ENOMEM; |
| 5098 | SCTP_TCB_UNLOCK(stcb); |
| 5099 | break; |
| 5100 | } |
| 5101 | shared_key->key = key; |
| 5102 | shared_key->keyid = sca->sca_keynumber; |
| 5103 | error = sctp_insert_sharedkey(shared_keys, shared_key); |
| 5104 | SCTP_TCB_UNLOCK(stcb); |
| 5105 | } else { |
| 5106 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5107 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5108 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5109 | ((sca->sca_assoc_id == SCTP_FUTURE_ASSOC) || |
| 5110 | (sca->sca_assoc_id == SCTP_ALL_ASSOC)))) { |
| 5111 | SCTP_INP_WLOCK(inp); |
| 5112 | shared_keys = &inp->sctp_ep.shared_keys; |
| 5113 | /* |
| 5114 | * clear the cached keys on all assocs for |
| 5115 | * this key id |
| 5116 | */ |
| 5117 | sctp_clear_cachedkeys_ep(inp, sca->sca_keynumber); |
| 5118 | /* |
| 5119 | * create the new shared key and |
| 5120 | * insert/replace it |
| 5121 | */ |
| 5122 | if (size > 0) { |
| 5123 | key = sctp_set_key(sca->sca_key, (uint32_t) size); |
| 5124 | if (key == NULL) { |
| 5125 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 5126 | error = ENOMEM; |
| 5127 | SCTP_INP_WUNLOCK(inp); |
| 5128 | break; |
| 5129 | } |
| 5130 | } |
| 5131 | shared_key = sctp_alloc_sharedkey(); |
| 5132 | if (shared_key == NULL) { |
| 5133 | sctp_free_key(key); |
| 5134 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 5135 | error = ENOMEM; |
| 5136 | SCTP_INP_WUNLOCK(inp); |
| 5137 | break; |
| 5138 | } |
| 5139 | shared_key->key = key; |
| 5140 | shared_key->keyid = sca->sca_keynumber; |
| 5141 | error = sctp_insert_sharedkey(shared_keys, shared_key); |
| 5142 | SCTP_INP_WUNLOCK(inp); |
| 5143 | } |
| 5144 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5145 | ((sca->sca_assoc_id == SCTP_CURRENT_ASSOC) || |
| 5146 | (sca->sca_assoc_id == SCTP_ALL_ASSOC))) { |
| 5147 | SCTP_INP_RLOCK(inp); |
| 5148 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5149 | SCTP_TCB_LOCK(stcb); |
| 5150 | shared_keys = &stcb->asoc.shared_keys; |
| 5151 | /* clear the cached keys for this key id */ |
| 5152 | sctp_clear_cachedkeys(stcb, sca->sca_keynumber); |
| 5153 | /* |
| 5154 | * create the new shared key and |
| 5155 | * insert/replace it |
| 5156 | */ |
| 5157 | if (size > 0) { |
| 5158 | key = sctp_set_key(sca->sca_key, (uint32_t) size); |
| 5159 | if (key == NULL) { |
| 5160 | SCTP_TCB_UNLOCK(stcb); |
| 5161 | continue; |
| 5162 | } |
| 5163 | } |
| 5164 | shared_key = sctp_alloc_sharedkey(); |
| 5165 | if (shared_key == NULL) { |
| 5166 | sctp_free_key(key); |
| 5167 | SCTP_TCB_UNLOCK(stcb); |
| 5168 | continue; |
| 5169 | } |
| 5170 | shared_key->key = key; |
| 5171 | shared_key->keyid = sca->sca_keynumber; |
| 5172 | error = sctp_insert_sharedkey(shared_keys, shared_key); |
| 5173 | SCTP_TCB_UNLOCK(stcb); |
| 5174 | } |
| 5175 | SCTP_INP_RUNLOCK(inp); |
| 5176 | } |
| 5177 | } |
| 5178 | break; |
| 5179 | } |
| 5180 | case SCTP_HMAC_IDENT: |
| 5181 | { |
| 5182 | struct sctp_hmacalgo *shmac; |
| 5183 | sctp_hmaclist_t *hmaclist; |
| 5184 | uint16_t hmacid; |
| 5185 | uint32_t i; |
| 5186 |
| 5187 | SCTP_CHECK_AND_CAST(shmac, optval, struct sctp_hmacalgo, optsize); |
| 5188 | if ((optsize < sizeof(struct sctp_hmacalgo) + shmac->shmac_number_of_idents * sizeof(uint16_t)) || |
| 5189 | (shmac->shmac_number_of_idents > 0xffff)) { |
| 5190 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5191 | error = EINVAL; |
| 5192 | break; |
| 5193 | } |
| 5194 |
| 5195 | hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents); |
| 5196 | if (hmaclist == NULL) { |
| 5197 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 5198 | error = ENOMEM; |
| 5199 | break; |
| 5200 | } |
| 5201 | for (i = 0; i < shmac->shmac_number_of_idents; i++) { |
| 5202 | hmacid = shmac->shmac_idents[i]; |
| 5203 | if (sctp_auth_add_hmacid(hmaclist, hmacid)) { |
| 5204 | /* invalid HMACs were found */; |
| 5205 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5206 | error = EINVAL; |
| 5207 | sctp_free_hmaclist(hmaclist); |
| 5208 | goto sctp_set_hmac_done; |
| 5209 | } |
| 5210 | } |
| 5211 | for (i = 0; i < hmaclist->num_algo; i++) { |
| 5212 | if (hmaclist->hmac[i] == SCTP_AUTH_HMAC_ID_SHA1) { |
| 5213 | /* already in list */ |
| 5214 | break; |
| 5215 | } |
| 5216 | } |
| 5217 | if (i == hmaclist->num_algo) { |
| 5218 | /* not found in list */ |
| 5219 | sctp_free_hmaclist(hmaclist); |
| 5220 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5221 | error = EINVAL; |
| 5222 | break; |
| 5223 | } |
| 5224 | /* set it on the endpoint */ |
| 5225 | SCTP_INP_WLOCK(inp); |
| 5226 | if (inp->sctp_ep.local_hmacs) |
| 5227 | sctp_free_hmaclist(inp->sctp_ep.local_hmacs); |
| 5228 | inp->sctp_ep.local_hmacs = hmaclist; |
| 5229 | SCTP_INP_WUNLOCK(inp); |
| 5230 | sctp_set_hmac_done: |
| 5231 | break; |
| 5232 | } |
| 5233 | case SCTP_AUTH_ACTIVE_KEY: |
| 5234 | { |
| 5235 | struct sctp_authkeyid *scact; |
| 5236 |
| 5237 | SCTP_CHECK_AND_CAST(scact, optval, struct sctp_authkeyid, optsize); |
| 5238 | SCTP_FIND_STCB(inp, stcb, scact->scact_assoc_id); |
| 5239 |
| 5240 | /* set the active key on the right place */ |
| 5241 | if (stcb) { |
| 5242 | /* set the active key on the assoc */ |
| 5243 | if (sctp_auth_setactivekey(stcb, |
| 5244 | scact->scact_keynumber)) { |
| 5245 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, |
| 5246 | SCTP_FROM_SCTP_USRREQ, |
| 5247 | EINVAL); |
| 5248 | error = EINVAL; |
| 5249 | } |
| 5250 | SCTP_TCB_UNLOCK(stcb); |
| 5251 | } else { |
| 5252 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5253 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5254 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5255 | ((scact->scact_assoc_id == SCTP_FUTURE_ASSOC) || |
| 5256 | (scact->scact_assoc_id == SCTP_ALL_ASSOC)))) { |
| 5257 | SCTP_INP_WLOCK(inp); |
| 5258 | if (sctp_auth_setactivekey_ep(inp, scact->scact_keynumber)) { |
| 5259 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5260 | error = EINVAL; |
| 5261 | } |
| 5262 | SCTP_INP_WUNLOCK(inp); |
| 5263 | } |
| 5264 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5265 | ((scact->scact_assoc_id == SCTP_CURRENT_ASSOC) || |
| 5266 | (scact->scact_assoc_id == SCTP_ALL_ASSOC))) { |
| 5267 | SCTP_INP_RLOCK(inp); |
| 5268 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5269 | SCTP_TCB_LOCK(stcb); |
| 5270 | sctp_auth_setactivekey(stcb, scact->scact_keynumber); |
| 5271 | SCTP_TCB_UNLOCK(stcb); |
| 5272 | } |
| 5273 | SCTP_INP_RUNLOCK(inp); |
| 5274 | } |
| 5275 | } |
| 5276 | break; |
| 5277 | } |
| 5278 | case SCTP_AUTH_DELETE_KEY: |
| 5279 | { |
| 5280 | struct sctp_authkeyid *scdel; |
| 5281 |
| 5282 | SCTP_CHECK_AND_CAST(scdel, optval, struct sctp_authkeyid, optsize); |
| 5283 | SCTP_FIND_STCB(inp, stcb, scdel->scact_assoc_id); |
| 5284 |
| 5285 | /* delete the key from the right place */ |
| 5286 | if (stcb) { |
| 5287 | if (sctp_delete_sharedkey(stcb, scdel->scact_keynumber)) { |
| 5288 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5289 | error = EINVAL; |
| 5290 | } |
| 5291 | SCTP_TCB_UNLOCK(stcb); |
| 5292 | } else { |
| 5293 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5294 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5295 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5296 | ((scdel->scact_assoc_id == SCTP_FUTURE_ASSOC) || |
| 5297 | (scdel->scact_assoc_id == SCTP_ALL_ASSOC)))) { |
| 5298 | SCTP_INP_WLOCK(inp); |
| 5299 | if (sctp_delete_sharedkey_ep(inp, scdel->scact_keynumber)) { |
| 5300 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5301 | error = EINVAL; |
| 5302 | } |
| 5303 | SCTP_INP_WUNLOCK(inp); |
| 5304 | } |
| 5305 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5306 | ((scdel->scact_assoc_id == SCTP_CURRENT_ASSOC) || |
| 5307 | (scdel->scact_assoc_id == SCTP_ALL_ASSOC))) { |
| 5308 | SCTP_INP_RLOCK(inp); |
| 5309 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5310 | SCTP_TCB_LOCK(stcb); |
| 5311 | sctp_delete_sharedkey(stcb, scdel->scact_keynumber); |
| 5312 | SCTP_TCB_UNLOCK(stcb); |
| 5313 | } |
| 5314 | SCTP_INP_RUNLOCK(inp); |
| 5315 | } |
| 5316 | } |
| 5317 | break; |
| 5318 | } |
| 5319 | case SCTP_AUTH_DEACTIVATE_KEY: |
| 5320 | { |
| 5321 | struct sctp_authkeyid *keyid; |
| 5322 |
| 5323 | SCTP_CHECK_AND_CAST(keyid, optval, struct sctp_authkeyid, optsize); |
| 5324 | SCTP_FIND_STCB(inp, stcb, keyid->scact_assoc_id); |
| 5325 |
| 5326 | /* deactivate the key from the right place */ |
| 5327 | if (stcb) { |
| 5328 | if (sctp_deact_sharedkey(stcb, keyid->scact_keynumber)) { |
| 5329 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5330 | error = EINVAL; |
| 5331 | } |
| 5332 | SCTP_TCB_UNLOCK(stcb); |
| 5333 | } else { |
| 5334 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5335 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5336 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5337 | ((keyid->scact_assoc_id == SCTP_FUTURE_ASSOC) || |
| 5338 | (keyid->scact_assoc_id == SCTP_ALL_ASSOC)))) { |
| 5339 | SCTP_INP_WLOCK(inp); |
| 5340 | if (sctp_deact_sharedkey_ep(inp, keyid->scact_keynumber)) { |
| 5341 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5342 | error = EINVAL; |
| 5343 | } |
| 5344 | SCTP_INP_WUNLOCK(inp); |
| 5345 | } |
| 5346 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5347 | ((keyid->scact_assoc_id == SCTP_CURRENT_ASSOC) || |
| 5348 | (keyid->scact_assoc_id == SCTP_ALL_ASSOC))) { |
| 5349 | SCTP_INP_RLOCK(inp); |
| 5350 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5351 | SCTP_TCB_LOCK(stcb); |
| 5352 | sctp_deact_sharedkey(stcb, keyid->scact_keynumber); |
| 5353 | SCTP_TCB_UNLOCK(stcb); |
| 5354 | } |
| 5355 | SCTP_INP_RUNLOCK(inp); |
| 5356 | } |
| 5357 | } |
| 5358 | break; |
| 5359 | } |
| 5360 | case SCTP_ENABLE_STREAM_RESET: |
| 5361 | { |
| 5362 | struct sctp_assoc_value *av; |
| 5363 |
| 5364 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 5365 | if (av->assoc_value & (~SCTP_ENABLE_VALUE_MASK)) { |
| 5366 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5367 | error = EINVAL; |
| 5368 | break; |
| 5369 | } |
| 5370 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 5371 | if (stcb) { |
| 5372 | stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value; |
| 5373 | SCTP_TCB_UNLOCK(stcb); |
| 5374 | } else { |
| 5375 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5376 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5377 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5378 | ((av->assoc_id == SCTP_FUTURE_ASSOC) || |
| 5379 | (av->assoc_id == SCTP_ALL_ASSOC)))) { |
| 5380 | SCTP_INP_WLOCK(inp); |
| 5381 | inp->local_strreset_support = (uint8_t)av->assoc_value; |
| 5382 | SCTP_INP_WUNLOCK(inp); |
| 5383 | } |
| 5384 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5385 | ((av->assoc_id == SCTP_CURRENT_ASSOC) || |
| 5386 | (av->assoc_id == SCTP_ALL_ASSOC))) { |
| 5387 | SCTP_INP_RLOCK(inp); |
| 5388 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5389 | SCTP_TCB_LOCK(stcb); |
| 5390 | stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value; |
| 5391 | SCTP_TCB_UNLOCK(stcb); |
| 5392 | } |
| 5393 | SCTP_INP_RUNLOCK(inp); |
| 5394 | } |
| 5395 | } |
| 5396 | break; |
| 5397 | } |
| 5398 | case SCTP_RESET_STREAMS: |
| 5399 | { |
| 5400 | struct sctp_reset_streams *strrst; |
| 5401 | int i, send_out = 0; |
| 5402 | int send_in = 0; |
| 5403 |
| 5404 | SCTP_CHECK_AND_CAST(strrst, optval, struct sctp_reset_streams, optsize); |
| 5405 | SCTP_FIND_STCB(inp, stcb, strrst->srs_assoc_id); |
| 5406 | if (stcb == NULL) { |
| 5407 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 5408 | error = ENOENT; |
| 5409 | break; |
| 5410 | } |
| 5411 | if (stcb->asoc.reconfig_supported == 0) { |
| 5412 | /* |
| 5413 | * Peer does not support the chunk type. |
| 5414 | */ |
| 5415 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 5416 | error = EOPNOTSUPP; |
| 5417 | SCTP_TCB_UNLOCK(stcb); |
| 5418 | break; |
| 5419 | } |
| 5420 | if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) { |
| 5421 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5422 | error = EINVAL; |
| 5423 | SCTP_TCB_UNLOCK(stcb); |
| 5424 | break; |
| 5425 | } |
| 5426 | if (sizeof(struct sctp_reset_streams) + |
| 5427 | strrst->srs_number_streams * sizeof(uint16_t) > optsize) { |
| 5428 | error = EINVAL; |
| 5429 | SCTP_TCB_UNLOCK(stcb); |
| 5430 | break; |
| 5431 | } |
| 5432 | if (strrst->srs_flags & SCTP_STREAM_RESET_INCOMING) { |
| 5433 | send_in = 1; |
| 5434 | if (stcb->asoc.stream_reset_outstanding) { |
| 5435 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 5436 | error = EALREADY; |
| 5437 | SCTP_TCB_UNLOCK(stcb); |
| 5438 | break; |
| 5439 | } |
| 5440 | } |
| 5441 | if (strrst->srs_flags & SCTP_STREAM_RESET_OUTGOING) { |
| 5442 | send_out = 1; |
| 5443 | } |
| 5444 | if ((strrst->srs_number_streams > SCTP_MAX_STREAMS_AT_ONCE_RESET) && send_in) { |
| 5445 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); |
| 5446 | error = ENOMEM; |
| 5447 | SCTP_TCB_UNLOCK(stcb); |
| 5448 | break; |
| 5449 | } |
| 5450 | if ((send_in == 0) && (send_out == 0)) { |
| 5451 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5452 | error = EINVAL; |
| 5453 | SCTP_TCB_UNLOCK(stcb); |
| 5454 | break; |
| 5455 | } |
| 5456 | for (i = 0; i < strrst->srs_number_streams; i++) { |
| 5457 | if ((send_in) && |
| 5458 | (strrst->srs_stream_list[i] >= stcb->asoc.streamincnt)) { |
| 5459 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5460 | error = EINVAL; |
| 5461 | break; |
| 5462 | } |
| 5463 | if ((send_out) && |
| 5464 | (strrst->srs_stream_list[i] >= stcb->asoc.streamoutcnt)) { |
| 5465 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5466 | error = EINVAL; |
| 5467 | break; |
| 5468 | } |
| 5469 | } |
| 5470 | if (error) { |
| 5471 | SCTP_TCB_UNLOCK(stcb); |
| 5472 | break; |
| 5473 | } |
| 5474 | if (send_out) { |
| 5475 | int cnt; |
| 5476 | uint16_t strm; |
| 5477 | if (strrst->srs_number_streams) { |
| 5478 | for (i = 0, cnt = 0; i < strrst->srs_number_streams; i++) { |
| 5479 | strm = strrst->srs_stream_list[i]; |
| 5480 | if (stcb->asoc.strmout[strm].state == SCTP_STREAM_OPEN) { |
| 5481 | stcb->asoc.strmout[strm].state = SCTP_STREAM_RESET_PENDING; |
| 5482 | cnt++; |
| 5483 | } |
| 5484 | } |
| 5485 | } else { |
| 5486 | /* Its all */ |
| 5487 | for (i = 0, cnt = 0; i < stcb->asoc.streamoutcnt; i++) { |
| 5488 | if (stcb->asoc.strmout[i].state == SCTP_STREAM_OPEN) { |
| 5489 | stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_PENDING; |
| 5490 | cnt++; |
| 5491 | } |
| 5492 | } |
| 5493 | } |
| 5494 | } |
| 5495 | if (send_in) { |
| 5496 | error = sctp_send_str_reset_req(stcb, strrst->srs_number_streams, |
| 5497 | strrst->srs_stream_list, |
| 5498 | send_in, 0, 0, 0, 0, 0); |
| 5499 | } else { |
| 5500 | error = sctp_send_stream_reset_out_if_possible(stcb, SCTP_SO_LOCKED); |
| 5501 | } |
| 5502 | if (error == 0) { |
| 5503 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED); |
| 5504 | } else { |
| 5505 | /* |
| 5506 | * For outgoing streams don't report any problems in |
| 5507 | * sending the request to the application. |
| 5508 | * XXX: Double check resetting incoming streams. |
| 5509 | */ |
| 5510 | error = 0; |
| 5511 | } |
| 5512 | SCTP_TCB_UNLOCK(stcb); |
| 5513 | break; |
| 5514 | } |
| 5515 | case SCTP_ADD_STREAMS: |
| 5516 | { |
| 5517 | struct sctp_add_streams *stradd; |
| 5518 | uint8_t addstream = 0; |
| 5519 | uint16_t add_o_strmcnt = 0; |
| 5520 | uint16_t add_i_strmcnt = 0; |
| 5521 |
| 5522 | SCTP_CHECK_AND_CAST(stradd, optval, struct sctp_add_streams, optsize); |
| 5523 | SCTP_FIND_STCB(inp, stcb, stradd->sas_assoc_id); |
| 5524 | if (stcb == NULL) { |
| 5525 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 5526 | error = ENOENT; |
| 5527 | break; |
| 5528 | } |
| 5529 | if (stcb->asoc.reconfig_supported == 0) { |
| 5530 | /* |
| 5531 | * Peer does not support the chunk type. |
| 5532 | */ |
| 5533 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 5534 | error = EOPNOTSUPP; |
| 5535 | SCTP_TCB_UNLOCK(stcb); |
| 5536 | break; |
| 5537 | } |
| 5538 | if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) { |
| 5539 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5540 | error = EINVAL; |
| 5541 | SCTP_TCB_UNLOCK(stcb); |
| 5542 | break; |
| 5543 | } |
| 5544 | if (stcb->asoc.stream_reset_outstanding) { |
| 5545 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 5546 | error = EALREADY; |
| 5547 | SCTP_TCB_UNLOCK(stcb); |
| 5548 | break; |
| 5549 | } |
| 5550 | if ((stradd->sas_outstrms == 0) && |
| 5551 | (stradd->sas_instrms == 0)) { |
| 5552 | error = EINVAL; |
| 5553 | goto skip_stuff; |
| 5554 | } |
| 5555 | if (stradd->sas_outstrms) { |
| 5556 | addstream = 1; |
| 5557 | /* We allocate here */ |
| 5558 | add_o_strmcnt = stradd->sas_outstrms; |
| 5559 | if ((((int)add_o_strmcnt) + ((int)stcb->asoc.streamoutcnt)) > 0x0000ffff) { |
| 5560 | /* You can't have more than 64k */ |
| 5561 | error = EINVAL; |
| 5562 | goto skip_stuff; |
| 5563 | } |
| 5564 | } |
| 5565 | if (stradd->sas_instrms) { |
| 5566 | int cnt; |
| 5567 |
| 5568 | addstream |= 2; |
| 5569 | /* We allocate inside sctp_send_str_reset_req() */ |
| 5570 | add_i_strmcnt = stradd->sas_instrms; |
| 5571 | cnt = add_i_strmcnt; |
| 5572 | cnt += stcb->asoc.streamincnt; |
| 5573 | if (cnt > 0x0000ffff) { |
| 5574 | /* You can't have more than 64k */ |
| 5575 | error = EINVAL; |
| 5576 | goto skip_stuff; |
| 5577 | } |
| 5578 | if (cnt > (int)stcb->asoc.max_inbound_streams) { |
| 5579 | /* More than you are allowed */ |
| 5580 | error = EINVAL; |
| 5581 | goto skip_stuff; |
| 5582 | } |
| 5583 | } |
| 5584 | error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 0, addstream, add_o_strmcnt, add_i_strmcnt, 0); |
| 5585 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED); |
| 5586 | skip_stuff: |
| 5587 | SCTP_TCB_UNLOCK(stcb); |
| 5588 | break; |
| 5589 | } |
| 5590 | case SCTP_RESET_ASSOC: |
| 5591 | { |
| 5592 | int i; |
| 5593 | uint32_t *value; |
| 5594 |
| 5595 | SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize); |
| 5596 | SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) *value); |
| 5597 | if (stcb == NULL) { |
| 5598 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 5599 | error = ENOENT; |
| 5600 | break; |
| 5601 | } |
| 5602 | if (stcb->asoc.reconfig_supported == 0) { |
| 5603 | /* |
| 5604 | * Peer does not support the chunk type. |
| 5605 | */ |
| 5606 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 5607 | error = EOPNOTSUPP; |
| 5608 | SCTP_TCB_UNLOCK(stcb); |
| 5609 | break; |
| 5610 | } |
| 5611 | if (SCTP_GET_STATE(stcb) != SCTP_STATE_OPEN) { |
| 5612 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5613 | error = EINVAL; |
| 5614 | SCTP_TCB_UNLOCK(stcb); |
| 5615 | break; |
| 5616 | } |
| 5617 | if (stcb->asoc.stream_reset_outstanding) { |
| 5618 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 5619 | error = EALREADY; |
| 5620 | SCTP_TCB_UNLOCK(stcb); |
| 5621 | break; |
| 5622 | } |
| 5623 | /* Is there any data pending in the send or sent queues? */ |
| 5624 | if (!TAILQ_EMPTY(&stcb->asoc.send_queue) || |
| 5625 | !TAILQ_EMPTY(&stcb->asoc.sent_queue)) { |
| 5626 | busy_out: |
| 5627 | error = EBUSY; |
| 5628 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 5629 | SCTP_TCB_UNLOCK(stcb); |
| 5630 | break; |
| 5631 | } |
| 5632 | /* Do any streams have data queued? */ |
| 5633 | for (i = 0; i < stcb->asoc.streamoutcnt; i++) { |
| 5634 | if (!TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) { |
| 5635 | goto busy_out; |
| 5636 | } |
| 5637 | } |
| 5638 | error = sctp_send_str_reset_req(stcb, 0, NULL, 0, 1, 0, 0, 0, 0); |
| 5639 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_REQ, SCTP_SO_LOCKED); |
| 5640 | SCTP_TCB_UNLOCK(stcb); |
| 5641 | break; |
| 5642 | } |
| 5643 | case SCTP_CONNECT_X: |
| 5644 | if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) { |
| 5645 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5646 | error = EINVAL; |
| 5647 | break; |
| 5648 | } |
| 5649 | error = sctp_do_connect_x(so, inp, optval, optsize, p, 0); |
| 5650 | break; |
| 5651 | case SCTP_CONNECT_X_DELAYED: |
| 5652 | if (optsize < (sizeof(int) + sizeof(struct sockaddr_in))) { |
| 5653 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5654 | error = EINVAL; |
| 5655 | break; |
| 5656 | } |
| 5657 | error = sctp_do_connect_x(so, inp, optval, optsize, p, 1); |
| 5658 | break; |
| 5659 | case SCTP_CONNECT_X_COMPLETE: |
| 5660 | { |
| 5661 | struct sockaddr *sa; |
| 5662 |
| 5663 | /* FIXME MT: check correct? */ |
| 5664 | SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize); |
| 5665 |
| 5666 | /* find tcb */ |
| 5667 | if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { |
| 5668 | SCTP_INP_RLOCK(inp); |
| 5669 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 5670 | if (stcb) { |
| 5671 | SCTP_TCB_LOCK(stcb); |
| 5672 | } |
| 5673 | SCTP_INP_RUNLOCK(inp); |
| 5674 | } else { |
| 5675 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 5676 | * do a decrement if it finds the stcb as long as the locked |
| 5677 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 5678 | */ |
| 5679 | SCTP_INP_INCR_REF(inp); |
| 5680 | stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL); |
| 5681 | if (stcb == NULL) { |
| 5682 | SCTP_INP_DECR_REF(inp); |
| 5683 | } |
| 5684 | } |
| 5685 |
| 5686 | if (stcb == NULL) { |
| 5687 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 5688 | error = ENOENT; |
| 5689 | break; |
| 5690 | } |
| 5691 | if (stcb->asoc.delayed_connection == 1) { |
| 5692 | stcb->asoc.delayed_connection = 0; |
| 5693 | (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); |
| 5694 | sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, |
| 5695 | stcb->asoc.primary_destination, |
| 5696 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_8); |
| 5697 | sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); |
| 5698 | } else { |
| 5699 | /* |
| 5700 | * already expired or did not use delayed |
| 5701 | * connectx |
| 5702 | */ |
| 5703 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 5704 | error = EALREADY; |
| 5705 | } |
| 5706 | SCTP_TCB_UNLOCK(stcb); |
| 5707 | break; |
| 5708 | } |
| 5709 | case SCTP_MAX_BURST: |
| 5710 | { |
| 5711 | struct sctp_assoc_value *av; |
| 5712 |
| 5713 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 5714 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 5715 |
| 5716 | if (stcb) { |
| 5717 | stcb->asoc.max_burst = av->assoc_value; |
| 5718 | SCTP_TCB_UNLOCK(stcb); |
| 5719 | } else { |
| 5720 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5721 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5722 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5723 | ((av->assoc_id == SCTP_FUTURE_ASSOC) || |
| 5724 | (av->assoc_id == SCTP_ALL_ASSOC)))) { |
| 5725 | SCTP_INP_WLOCK(inp); |
| 5726 | inp->sctp_ep.max_burst = av->assoc_value; |
| 5727 | SCTP_INP_WUNLOCK(inp); |
| 5728 | } |
| 5729 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5730 | ((av->assoc_id == SCTP_CURRENT_ASSOC) || |
| 5731 | (av->assoc_id == SCTP_ALL_ASSOC))) { |
| 5732 | SCTP_INP_RLOCK(inp); |
| 5733 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5734 | SCTP_TCB_LOCK(stcb); |
| 5735 | stcb->asoc.max_burst = av->assoc_value; |
| 5736 | SCTP_TCB_UNLOCK(stcb); |
| 5737 | } |
| 5738 | SCTP_INP_RUNLOCK(inp); |
| 5739 | } |
| 5740 | } |
| 5741 | break; |
| 5742 | } |
| 5743 | case SCTP_MAXSEG: |
| 5744 | { |
| 5745 | struct sctp_assoc_value *av; |
| 5746 | int ovh; |
| 5747 |
| 5748 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 5749 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 5750 |
| 5751 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
| 5752 | ovh = SCTP_MED_OVERHEAD; |
| 5753 | } else { |
| 5754 | ovh = SCTP_MED_V4_OVERHEAD; |
| 5755 | } |
| 5756 | if (stcb) { |
| 5757 | if (av->assoc_value) { |
| 5758 | stcb->asoc.sctp_frag_point = (av->assoc_value + ovh); |
| 5759 | } else { |
| 5760 | stcb->asoc.sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT; |
| 5761 | } |
| 5762 | SCTP_TCB_UNLOCK(stcb); |
| 5763 | } else { |
| 5764 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5765 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5766 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5767 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 5768 | SCTP_INP_WLOCK(inp); |
| 5769 | /* FIXME MT: I think this is not in tune with the API ID */ |
| 5770 | if (av->assoc_value) { |
| 5771 | inp->sctp_frag_point = (av->assoc_value + ovh); |
| 5772 | } else { |
| 5773 | inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT; |
| 5774 | } |
| 5775 | SCTP_INP_WUNLOCK(inp); |
| 5776 | } else { |
| 5777 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5778 | error = EINVAL; |
| 5779 | } |
| 5780 | } |
| 5781 | break; |
| 5782 | } |
| 5783 | case SCTP_EVENTS: |
| 5784 | { |
| 5785 | struct sctp_event_subscribe *events; |
| 5786 |
| 5787 | SCTP_CHECK_AND_CAST(events, optval, struct sctp_event_subscribe, optsize); |
| 5788 |
| 5789 | SCTP_INP_WLOCK(inp); |
| 5790 | if (events->sctp_data_io_event) { |
| 5791 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT); |
| 5792 | } else { |
| 5793 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT); |
| 5794 | } |
| 5795 |
| 5796 | if (events->sctp_association_event) { |
| 5797 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT); |
| 5798 | } else { |
| 5799 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVASSOCEVNT); |
| 5800 | } |
| 5801 |
| 5802 | if (events->sctp_address_event) { |
| 5803 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPADDREVNT); |
| 5804 | } else { |
| 5805 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPADDREVNT); |
| 5806 | } |
| 5807 |
| 5808 | if (events->sctp_send_failure_event) { |
| 5809 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); |
| 5810 | } else { |
| 5811 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); |
| 5812 | } |
| 5813 |
| 5814 | if (events->sctp_peer_error_event) { |
| 5815 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVPEERERR); |
| 5816 | } else { |
| 5817 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVPEERERR); |
| 5818 | } |
| 5819 |
| 5820 | if (events->sctp_shutdown_event) { |
| 5821 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); |
| 5822 | } else { |
| 5823 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); |
| 5824 | } |
| 5825 |
| 5826 | if (events->sctp_partial_delivery_event) { |
| 5827 | sctp_feature_on(inp, SCTP_PCB_FLAGS_PDAPIEVNT); |
| 5828 | } else { |
| 5829 | sctp_feature_off(inp, SCTP_PCB_FLAGS_PDAPIEVNT); |
| 5830 | } |
| 5831 |
| 5832 | if (events->sctp_adaptation_layer_event) { |
| 5833 | sctp_feature_on(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT); |
| 5834 | } else { |
| 5835 | sctp_feature_off(inp, SCTP_PCB_FLAGS_ADAPTATIONEVNT); |
| 5836 | } |
| 5837 |
| 5838 | if (events->sctp_authentication_event) { |
| 5839 | sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTHEVNT); |
| 5840 | } else { |
| 5841 | sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTHEVNT); |
| 5842 | } |
| 5843 |
| 5844 | if (events->sctp_sender_dry_event) { |
| 5845 | sctp_feature_on(inp, SCTP_PCB_FLAGS_DRYEVNT); |
| 5846 | } else { |
| 5847 | sctp_feature_off(inp, SCTP_PCB_FLAGS_DRYEVNT); |
| 5848 | } |
| 5849 |
| 5850 | if (events->sctp_stream_reset_event) { |
| 5851 | sctp_feature_on(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT); |
| 5852 | } else { |
| 5853 | sctp_feature_off(inp, SCTP_PCB_FLAGS_STREAM_RESETEVNT); |
| 5854 | } |
| 5855 | SCTP_INP_WUNLOCK(inp); |
| 5856 |
| 5857 | SCTP_INP_RLOCK(inp); |
| 5858 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5859 | SCTP_TCB_LOCK(stcb); |
| 5860 | if (events->sctp_association_event) { |
| 5861 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT); |
| 5862 | } else { |
| 5863 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT); |
| 5864 | } |
| 5865 | if (events->sctp_address_event) { |
| 5866 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT); |
| 5867 | } else { |
| 5868 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT); |
| 5869 | } |
| 5870 | if (events->sctp_send_failure_event) { |
| 5871 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); |
| 5872 | } else { |
| 5873 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT); |
| 5874 | } |
| 5875 | if (events->sctp_peer_error_event) { |
| 5876 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR); |
| 5877 | } else { |
| 5878 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVPEERERR); |
| 5879 | } |
| 5880 | if (events->sctp_shutdown_event) { |
| 5881 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); |
| 5882 | } else { |
| 5883 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT); |
| 5884 | } |
| 5885 | if (events->sctp_partial_delivery_event) { |
| 5886 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT); |
| 5887 | } else { |
| 5888 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT); |
| 5889 | } |
| 5890 | if (events->sctp_adaptation_layer_event) { |
| 5891 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT); |
| 5892 | } else { |
| 5893 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT); |
| 5894 | } |
| 5895 | if (events->sctp_authentication_event) { |
| 5896 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT); |
| 5897 | } else { |
| 5898 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_AUTHEVNT); |
| 5899 | } |
| 5900 | if (events->sctp_sender_dry_event) { |
| 5901 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT); |
| 5902 | } else { |
| 5903 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DRYEVNT); |
| 5904 | } |
| 5905 | if (events->sctp_stream_reset_event) { |
| 5906 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT); |
| 5907 | } else { |
| 5908 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT); |
| 5909 | } |
| 5910 | SCTP_TCB_UNLOCK(stcb); |
| 5911 | } |
| 5912 | /* Send up the sender dry event only for 1-to-1 style sockets. */ |
| 5913 | if (events->sctp_sender_dry_event) { |
| 5914 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5915 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 5916 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 5917 | if (stcb) { |
| 5918 | SCTP_TCB_LOCK(stcb); |
| 5919 | if (TAILQ_EMPTY(&stcb->asoc.send_queue) && |
| 5920 | TAILQ_EMPTY(&stcb->asoc.sent_queue) && |
| 5921 | (stcb->asoc.stream_queue_cnt == 0)) { |
| 5922 | sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED); |
| 5923 | } |
| 5924 | SCTP_TCB_UNLOCK(stcb); |
| 5925 | } |
| 5926 | } |
| 5927 | } |
| 5928 | SCTP_INP_RUNLOCK(inp); |
| 5929 | break; |
| 5930 | } |
| 5931 | case SCTP_ADAPTATION_LAYER: |
| 5932 | { |
| 5933 | struct sctp_setadaptation *adap_bits; |
| 5934 |
| 5935 | SCTP_CHECK_AND_CAST(adap_bits, optval, struct sctp_setadaptation, optsize); |
| 5936 | SCTP_INP_WLOCK(inp); |
| 5937 | inp->sctp_ep.adaptation_layer_indicator = adap_bits->ssb_adaptation_ind; |
| 5938 | inp->sctp_ep.adaptation_layer_indicator_provided = 1; |
| 5939 | SCTP_INP_WUNLOCK(inp); |
| 5940 | break; |
| 5941 | } |
| 5942 | #ifdef SCTP_DEBUG |
| 5943 | case SCTP_SET_INITIAL_DBG_SEQ: |
| 5944 | { |
| 5945 | uint32_t *vvv; |
| 5946 |
| 5947 | SCTP_CHECK_AND_CAST(vvv, optval, uint32_t, optsize); |
| 5948 | SCTP_INP_WLOCK(inp); |
| 5949 | inp->sctp_ep.initial_sequence_debug = *vvv; |
| 5950 | SCTP_INP_WUNLOCK(inp); |
| 5951 | break; |
| 5952 | } |
| 5953 | #endif |
| 5954 | case SCTP_DEFAULT_SEND_PARAM: |
| 5955 | { |
| 5956 | struct sctp_sndrcvinfo *s_info; |
| 5957 |
| 5958 | SCTP_CHECK_AND_CAST(s_info, optval, struct sctp_sndrcvinfo, optsize); |
| 5959 | SCTP_FIND_STCB(inp, stcb, s_info->sinfo_assoc_id); |
| 5960 |
| 5961 | if (stcb) { |
| 5962 | if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) { |
| 5963 | memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send))); |
| 5964 | } else { |
| 5965 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 5966 | error = EINVAL; |
| 5967 | } |
| 5968 | SCTP_TCB_UNLOCK(stcb); |
| 5969 | } else { |
| 5970 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 5971 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 5972 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5973 | ((s_info->sinfo_assoc_id == SCTP_FUTURE_ASSOC) || |
| 5974 | (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC)))) { |
| 5975 | SCTP_INP_WLOCK(inp); |
| 5976 | memcpy(&inp->def_send, s_info, min(optsize, sizeof(inp->def_send))); |
| 5977 | SCTP_INP_WUNLOCK(inp); |
| 5978 | } |
| 5979 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 5980 | ((s_info->sinfo_assoc_id == SCTP_CURRENT_ASSOC) || |
| 5981 | (s_info->sinfo_assoc_id == SCTP_ALL_ASSOC))) { |
| 5982 | SCTP_INP_RLOCK(inp); |
| 5983 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 5984 | SCTP_TCB_LOCK(stcb); |
| 5985 | if (s_info->sinfo_stream < stcb->asoc.streamoutcnt) { |
| 5986 | memcpy(&stcb->asoc.def_send, s_info, min(optsize, sizeof(stcb->asoc.def_send))); |
| 5987 | } |
| 5988 | SCTP_TCB_UNLOCK(stcb); |
| 5989 | } |
| 5990 | SCTP_INP_RUNLOCK(inp); |
| 5991 | } |
| 5992 | } |
| 5993 | break; |
| 5994 | } |
| 5995 | case SCTP_PEER_ADDR_PARAMS: |
| 5996 | { |
| 5997 | struct sctp_paddrparams *paddrp; |
| 5998 | struct sctp_nets *net; |
| 5999 | struct sockaddr *addr; |
| 6000 | #if defined(INET) && defined(INET6) |
| 6001 | struct sockaddr_in sin_store; |
| 6002 | #endif |
| 6003 |
| 6004 | SCTP_CHECK_AND_CAST(paddrp, optval, struct sctp_paddrparams, optsize); |
| 6005 | SCTP_FIND_STCB(inp, stcb, paddrp->spp_assoc_id); |
| 6006 |
| 6007 | #if defined(INET) && defined(INET6) |
| 6008 | if (paddrp->spp_address.ss_family == AF_INET6) { |
| 6009 | struct sockaddr_in6 *sin6; |
| 6010 |
| 6011 | sin6 = (struct sockaddr_in6 *)&paddrp->spp_address; |
| 6012 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 6013 | in6_sin6_2_sin(&sin_store, sin6); |
| 6014 | addr = (struct sockaddr *)&sin_store; |
| 6015 | } else { |
| 6016 | addr = (struct sockaddr *)&paddrp->spp_address; |
| 6017 | } |
| 6018 | } else { |
| 6019 | addr = (struct sockaddr *)&paddrp->spp_address; |
| 6020 | } |
| 6021 | #else |
| 6022 | addr = (struct sockaddr *)&paddrp->spp_address; |
| 6023 | #endif |
| 6024 | if (stcb != NULL) { |
| 6025 | net = sctp_findnet(stcb, addr); |
| 6026 | } else { |
| 6027 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 6028 | * do a decrement if it finds the stcb as long as the locked |
| 6029 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 6030 | */ |
| 6031 | net = NULL; |
| 6032 | SCTP_INP_INCR_REF(inp); |
| 6033 | stcb = sctp_findassociation_ep_addr(&inp, addr, |
| 6034 | &net, NULL, NULL); |
| 6035 | if (stcb == NULL) { |
| 6036 | SCTP_INP_DECR_REF(inp); |
| 6037 | } |
| 6038 | } |
| 6039 | if ((stcb != NULL) && (net == NULL)) { |
| 6040 | #ifdef INET |
| 6041 | if (addr->sa_family == AF_INET) { |
| 6042 | struct sockaddr_in *sin; |
| 6043 |
| 6044 | sin = (struct sockaddr_in *)addr; |
| 6045 | if (sin->sin_addr.s_addr != INADDR_ANY) { |
| 6046 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6047 | SCTP_TCB_UNLOCK(stcb); |
| 6048 | error = EINVAL; |
| 6049 | break; |
| 6050 | } |
| 6051 | } else |
| 6052 | #endif |
| 6053 | #ifdef INET6 |
| 6054 | if (addr->sa_family == AF_INET6) { |
| 6055 | struct sockaddr_in6 *sin6; |
| 6056 |
| 6057 | sin6 = (struct sockaddr_in6 *)addr; |
| 6058 | if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 6059 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6060 | SCTP_TCB_UNLOCK(stcb); |
| 6061 | error = EINVAL; |
| 6062 | break; |
| 6063 | } |
| 6064 | } else |
| 6065 | #endif |
| 6066 | #if defined(__Userspace__) |
| 6067 | if (addr->sa_family == AF_CONN) { |
| 6068 | struct sockaddr_conn *sconn; |
| 6069 |
| 6070 | sconn = (struct sockaddr_conn *)addr; |
| 6071 | if (sconn->sconn_addr != NULL) { |
| 6072 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6073 | SCTP_TCB_UNLOCK(stcb); |
| 6074 | error = EINVAL; |
| 6075 | break; |
| 6076 | } |
| 6077 | } else |
| 6078 | #endif |
| 6079 | { |
| 6080 | error = EAFNOSUPPORT; |
| 6081 | SCTP_TCB_UNLOCK(stcb); |
| 6082 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 6083 | break; |
| 6084 | } |
| 6085 | } |
| 6086 | /* sanity checks */ |
| 6087 | if ((paddrp->spp_flags & SPP_HB_ENABLE) && (paddrp->spp_flags & SPP_HB_DISABLE)) { |
| 6088 | if (stcb) |
| 6089 | SCTP_TCB_UNLOCK(stcb); |
| 6090 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6091 | return (EINVAL); |
| 6092 | } |
| 6093 |
| 6094 | if ((paddrp->spp_flags & SPP_PMTUD_ENABLE) && (paddrp->spp_flags & SPP_PMTUD_DISABLE)) { |
| 6095 | if (stcb) |
| 6096 | SCTP_TCB_UNLOCK(stcb); |
| 6097 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6098 | return (EINVAL); |
| 6099 | } |
| 6100 | if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && |
| 6101 | (paddrp->spp_pathmtu > 0) && |
| 6102 | ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) || |
| 6103 | (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) { |
| 6104 | if (stcb) |
| 6105 | SCTP_TCB_UNLOCK(stcb); |
| 6106 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6107 | return (EINVAL); |
| 6108 | } |
| 6109 |
| 6110 | if (stcb != NULL) { |
| 6111 | /************************TCB SPECIFIC SET ******************/ |
| 6112 | if (net != NULL) { |
| 6113 | /************************NET SPECIFIC SET ******************/ |
| 6114 | if (paddrp->spp_flags & SPP_HB_DISABLE) { |
| 6115 | if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) && |
| 6116 | !(net->dest_state & SCTP_ADDR_NOHB)) { |
| 6117 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, |
| 6118 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_9); |
| 6119 | } |
| 6120 | net->dest_state |= SCTP_ADDR_NOHB; |
| 6121 | } |
| 6122 | if (paddrp->spp_flags & SPP_HB_ENABLE) { |
| 6123 | if (paddrp->spp_hbinterval) { |
| 6124 | net->heart_beat_delay = paddrp->spp_hbinterval; |
| 6125 | } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { |
| 6126 | net->heart_beat_delay = 0; |
| 6127 | } |
| 6128 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, |
| 6129 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_10); |
| 6130 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); |
| 6131 | net->dest_state &= ~SCTP_ADDR_NOHB; |
| 6132 | } |
| 6133 | if (paddrp->spp_flags & SPP_HB_DEMAND) { |
| 6134 | if (SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) { |
| 6135 | sctp_send_hb(stcb, net, SCTP_SO_LOCKED); |
| 6136 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED); |
| 6137 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); |
| 6138 | } |
| 6139 | } |
| 6140 | if (paddrp->spp_flags & SPP_PMTUD_DISABLE) { |
| 6141 | if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { |
| 6142 | sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net, |
| 6143 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11); |
| 6144 | } |
| 6145 | net->dest_state |= SCTP_ADDR_NO_PMTUD; |
| 6146 | if (paddrp->spp_pathmtu > 0) { |
| 6147 | net->mtu = paddrp->spp_pathmtu; |
| 6148 | switch (net->ro._l_addr.sa.sa_family) { |
| 6149 | #ifdef INET |
| 6150 | case AF_INET: |
| 6151 | net->mtu += SCTP_MIN_V4_OVERHEAD; |
| 6152 | break; |
| 6153 | #endif |
| 6154 | #ifdef INET6 |
| 6155 | case AF_INET6: |
| 6156 | net->mtu += SCTP_MIN_OVERHEAD; |
| 6157 | break; |
| 6158 | #endif |
| 6159 | #if defined(__Userspace__) |
| 6160 | case AF_CONN: |
| 6161 | net->mtu += sizeof(struct sctphdr); |
| 6162 | break; |
| 6163 | #endif |
| 6164 | default: |
| 6165 | break; |
| 6166 | } |
| 6167 | if (net->mtu < stcb->asoc.smallest_mtu) { |
| 6168 | sctp_pathmtu_adjustment(stcb, net->mtu); |
| 6169 | } |
| 6170 | } |
| 6171 | } |
| 6172 | if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { |
| 6173 | if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { |
| 6174 | sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); |
| 6175 | } |
| 6176 | net->dest_state &= ~SCTP_ADDR_NO_PMTUD; |
| 6177 | } |
| 6178 | if (paddrp->spp_pathmaxrxt > 0) { |
| 6179 | if (net->dest_state & SCTP_ADDR_PF) { |
| 6180 | if (net->error_count > paddrp->spp_pathmaxrxt) { |
| 6181 | net->dest_state &= ~SCTP_ADDR_PF; |
| 6182 | } |
| 6183 | } else { |
| 6184 | if ((net->error_count <= paddrp->spp_pathmaxrxt) && |
| 6185 | (net->error_count > net->pf_threshold)) { |
| 6186 | net->dest_state |= SCTP_ADDR_PF; |
| 6187 | sctp_send_hb(stcb, net, SCTP_SO_LOCKED); |
| 6188 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 6189 | stcb->sctp_ep, stcb, net, |
| 6190 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_12); |
| 6191 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); |
| 6192 | } |
| 6193 | } |
| 6194 | if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 6195 | if (net->error_count > paddrp->spp_pathmaxrxt) { |
| 6196 | net->dest_state &= ~SCTP_ADDR_REACHABLE; |
| 6197 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); |
| 6198 | } |
| 6199 | } else { |
| 6200 | if (net->error_count <= paddrp->spp_pathmaxrxt) { |
| 6201 | net->dest_state |= SCTP_ADDR_REACHABLE; |
| 6202 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); |
| 6203 | } |
| 6204 | } |
| 6205 | net->failure_threshold = paddrp->spp_pathmaxrxt; |
| 6206 | } |
| 6207 | if (paddrp->spp_flags & SPP_DSCP) { |
| 6208 | net->dscp = paddrp->spp_dscp & 0xfc; |
| 6209 | net->dscp |= 0x01; |
| 6210 | } |
| 6211 | #ifdef INET6 |
| 6212 | if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) { |
| 6213 | if (net->ro._l_addr.sa.sa_family == AF_INET6) { |
| 6214 | net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; |
| 6215 | net->flowlabel |= 0x80000000; |
| 6216 | } |
| 6217 | } |
| 6218 | #endif |
| 6219 | } else { |
| 6220 | /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/ |
| 6221 | if (paddrp->spp_pathmaxrxt > 0) { |
| 6222 | stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt; |
| 6223 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6224 | if (net->dest_state & SCTP_ADDR_PF) { |
| 6225 | if (net->error_count > paddrp->spp_pathmaxrxt) { |
| 6226 | net->dest_state &= ~SCTP_ADDR_PF; |
| 6227 | } |
| 6228 | } else { |
| 6229 | if ((net->error_count <= paddrp->spp_pathmaxrxt) && |
| 6230 | (net->error_count > net->pf_threshold)) { |
| 6231 | net->dest_state |= SCTP_ADDR_PF; |
| 6232 | sctp_send_hb(stcb, net, SCTP_SO_LOCKED); |
| 6233 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 6234 | stcb->sctp_ep, stcb, net, |
| 6235 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_13); |
| 6236 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); |
| 6237 | } |
| 6238 | } |
| 6239 | if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 6240 | if (net->error_count > paddrp->spp_pathmaxrxt) { |
| 6241 | net->dest_state &= ~SCTP_ADDR_REACHABLE; |
| 6242 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); |
| 6243 | } |
| 6244 | } else { |
| 6245 | if (net->error_count <= paddrp->spp_pathmaxrxt) { |
| 6246 | net->dest_state |= SCTP_ADDR_REACHABLE; |
| 6247 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); |
| 6248 | } |
| 6249 | } |
| 6250 | net->failure_threshold = paddrp->spp_pathmaxrxt; |
| 6251 | } |
| 6252 | } |
| 6253 | if (paddrp->spp_flags & SPP_HB_ENABLE) { |
| 6254 | if (paddrp->spp_hbinterval != 0) { |
| 6255 | stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval; |
| 6256 | } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { |
| 6257 | stcb->asoc.heart_beat_delay = 0; |
| 6258 | } |
| 6259 | /* Turn back on the timer */ |
| 6260 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6261 | if (paddrp->spp_hbinterval != 0) { |
| 6262 | net->heart_beat_delay = paddrp->spp_hbinterval; |
| 6263 | } else if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { |
| 6264 | net->heart_beat_delay = 0; |
| 6265 | } |
| 6266 | if (net->dest_state & SCTP_ADDR_NOHB) { |
| 6267 | net->dest_state &= ~SCTP_ADDR_NOHB; |
| 6268 | } |
| 6269 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net, |
| 6270 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_14); |
| 6271 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net); |
| 6272 | } |
| 6273 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); |
| 6274 | } |
| 6275 | if (paddrp->spp_flags & SPP_HB_DISABLE) { |
| 6276 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6277 | if (!(net->dest_state & SCTP_ADDR_NOHB)) { |
| 6278 | net->dest_state |= SCTP_ADDR_NOHB; |
| 6279 | if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) { |
| 6280 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 6281 | inp, stcb, net, |
| 6282 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_15); |
| 6283 | } |
| 6284 | } |
| 6285 | } |
| 6286 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); |
| 6287 | } |
| 6288 | if (paddrp->spp_flags & SPP_PMTUD_DISABLE) { |
| 6289 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6290 | if (SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { |
| 6291 | sctp_timer_stop(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net, |
| 6292 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16); |
| 6293 | } |
| 6294 | net->dest_state |= SCTP_ADDR_NO_PMTUD; |
| 6295 | if (paddrp->spp_pathmtu > 0) { |
| 6296 | net->mtu = paddrp->spp_pathmtu; |
| 6297 | switch (net->ro._l_addr.sa.sa_family) { |
| 6298 | #ifdef INET |
| 6299 | case AF_INET: |
| 6300 | net->mtu += SCTP_MIN_V4_OVERHEAD; |
| 6301 | break; |
| 6302 | #endif |
| 6303 | #ifdef INET6 |
| 6304 | case AF_INET6: |
| 6305 | net->mtu += SCTP_MIN_OVERHEAD; |
| 6306 | break; |
| 6307 | #endif |
| 6308 | #if defined(__Userspace__) |
| 6309 | case AF_CONN: |
| 6310 | net->mtu += sizeof(struct sctphdr); |
| 6311 | break; |
| 6312 | #endif |
| 6313 | default: |
| 6314 | break; |
| 6315 | } |
| 6316 | if (net->mtu < stcb->asoc.smallest_mtu) { |
| 6317 | sctp_pathmtu_adjustment(stcb, net->mtu); |
| 6318 | } |
| 6319 | } |
| 6320 | } |
| 6321 | if (paddrp->spp_pathmtu > 0) { |
| 6322 | stcb->asoc.default_mtu = paddrp->spp_pathmtu; |
| 6323 | } |
| 6324 | sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD); |
| 6325 | } |
| 6326 | if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { |
| 6327 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6328 | if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { |
| 6329 | sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); |
| 6330 | } |
| 6331 | net->dest_state &= ~SCTP_ADDR_NO_PMTUD; |
| 6332 | } |
| 6333 | stcb->asoc.default_mtu = 0; |
| 6334 | sctp_stcb_feature_off(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD); |
| 6335 | } |
| 6336 | if (paddrp->spp_flags & SPP_DSCP) { |
| 6337 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6338 | net->dscp = paddrp->spp_dscp & 0xfc; |
| 6339 | net->dscp |= 0x01; |
| 6340 | } |
| 6341 | stcb->asoc.default_dscp = paddrp->spp_dscp & 0xfc; |
| 6342 | stcb->asoc.default_dscp |= 0x01; |
| 6343 | } |
| 6344 | #ifdef INET6 |
| 6345 | if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) { |
| 6346 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 6347 | if (net->ro._l_addr.sa.sa_family == AF_INET6) { |
| 6348 | net->flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; |
| 6349 | net->flowlabel |= 0x80000000; |
| 6350 | } |
| 6351 | } |
| 6352 | stcb->asoc.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; |
| 6353 | stcb->asoc.default_flowlabel |= 0x80000000; |
| 6354 | } |
| 6355 | #endif |
| 6356 | } |
| 6357 | SCTP_TCB_UNLOCK(stcb); |
| 6358 | } else { |
| 6359 | /************************NO TCB, SET TO default stuff ******************/ |
| 6360 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 6361 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 6362 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 6363 | (paddrp->spp_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 6364 | SCTP_INP_WLOCK(inp); |
| 6365 | /* |
| 6366 | * For the TOS/FLOWLABEL stuff you set it |
| 6367 | * with the options on the socket |
| 6368 | */ |
| 6369 | if (paddrp->spp_pathmaxrxt > 0) { |
| 6370 | inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt; |
| 6371 | } |
| 6372 |
| 6373 | if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) |
| 6374 | inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0; |
| 6375 | else if (paddrp->spp_hbinterval != 0) { |
| 6376 | if (paddrp->spp_hbinterval > SCTP_MAX_HB_INTERVAL) |
| 6377 | paddrp->spp_hbinterval= SCTP_MAX_HB_INTERVAL; |
| 6378 | inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval); |
| 6379 | } |
| 6380 |
| 6381 | if (paddrp->spp_flags & SPP_HB_ENABLE) { |
| 6382 | if (paddrp->spp_flags & SPP_HB_TIME_IS_ZERO) { |
| 6383 | inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = 0; |
| 6384 | } else if (paddrp->spp_hbinterval) { |
| 6385 | inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = sctp_msecs_to_ticks(paddrp->spp_hbinterval); |
| 6386 | } |
| 6387 | sctp_feature_off(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); |
| 6388 | } else if (paddrp->spp_flags & SPP_HB_DISABLE) { |
| 6389 | sctp_feature_on(inp, SCTP_PCB_FLAGS_DONOT_HEARTBEAT); |
| 6390 | } |
| 6391 | if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { |
| 6392 | inp->sctp_ep.default_mtu = 0; |
| 6393 | sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD); |
| 6394 | } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) { |
| 6395 | if (paddrp->spp_pathmtu > 0) { |
| 6396 | inp->sctp_ep.default_mtu = paddrp->spp_pathmtu; |
| 6397 | } |
| 6398 | sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD); |
| 6399 | } |
| 6400 | if (paddrp->spp_flags & SPP_DSCP) { |
| 6401 | inp->sctp_ep.default_dscp = paddrp->spp_dscp & 0xfc; |
| 6402 | inp->sctp_ep.default_dscp |= 0x01; |
| 6403 | } |
| 6404 | #ifdef INET6 |
| 6405 | if (paddrp->spp_flags & SPP_IPV6_FLOWLABEL) { |
| 6406 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
| 6407 | inp->sctp_ep.default_flowlabel = paddrp->spp_ipv6_flowlabel & 0x000fffff; |
| 6408 | inp->sctp_ep.default_flowlabel |= 0x80000000; |
| 6409 | } |
| 6410 | } |
| 6411 | #endif |
| 6412 | SCTP_INP_WUNLOCK(inp); |
| 6413 | } else { |
| 6414 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6415 | error = EINVAL; |
| 6416 | } |
| 6417 | } |
| 6418 | break; |
| 6419 | } |
| 6420 | case SCTP_RTOINFO: |
| 6421 | { |
| 6422 | struct sctp_rtoinfo *srto; |
| 6423 | uint32_t new_init, new_min, new_max; |
| 6424 |
| 6425 | SCTP_CHECK_AND_CAST(srto, optval, struct sctp_rtoinfo, optsize); |
| 6426 | SCTP_FIND_STCB(inp, stcb, srto->srto_assoc_id); |
| 6427 |
| 6428 | if (stcb) { |
| 6429 | if (srto->srto_initial) |
| 6430 | new_init = srto->srto_initial; |
| 6431 | else |
| 6432 | new_init = stcb->asoc.initial_rto; |
| 6433 | if (srto->srto_max) |
| 6434 | new_max = srto->srto_max; |
| 6435 | else |
| 6436 | new_max = stcb->asoc.maxrto; |
| 6437 | if (srto->srto_min) |
| 6438 | new_min = srto->srto_min; |
| 6439 | else |
| 6440 | new_min = stcb->asoc.minrto; |
| 6441 | if ((new_min <= new_init) && (new_init <= new_max)) { |
| 6442 | stcb->asoc.initial_rto = new_init; |
| 6443 | stcb->asoc.maxrto = new_max; |
| 6444 | stcb->asoc.minrto = new_min; |
| 6445 | } else { |
| 6446 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6447 | error = EINVAL; |
| 6448 | } |
| 6449 | SCTP_TCB_UNLOCK(stcb); |
| 6450 | } else { |
| 6451 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 6452 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 6453 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 6454 | (srto->srto_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 6455 | SCTP_INP_WLOCK(inp); |
| 6456 | if (srto->srto_initial) |
| 6457 | new_init = srto->srto_initial; |
| 6458 | else |
| 6459 | new_init = inp->sctp_ep.initial_rto; |
| 6460 | if (srto->srto_max) |
| 6461 | new_max = srto->srto_max; |
| 6462 | else |
| 6463 | new_max = inp->sctp_ep.sctp_maxrto; |
| 6464 | if (srto->srto_min) |
| 6465 | new_min = srto->srto_min; |
| 6466 | else |
| 6467 | new_min = inp->sctp_ep.sctp_minrto; |
| 6468 | if ((new_min <= new_init) && (new_init <= new_max)) { |
| 6469 | inp->sctp_ep.initial_rto = new_init; |
| 6470 | inp->sctp_ep.sctp_maxrto = new_max; |
| 6471 | inp->sctp_ep.sctp_minrto = new_min; |
| 6472 | } else { |
| 6473 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6474 | error = EINVAL; |
| 6475 | } |
| 6476 | SCTP_INP_WUNLOCK(inp); |
| 6477 | } else { |
| 6478 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6479 | error = EINVAL; |
| 6480 | } |
| 6481 | } |
| 6482 | break; |
| 6483 | } |
| 6484 | case SCTP_ASSOCINFO: |
| 6485 | { |
| 6486 | struct sctp_assocparams *sasoc; |
| 6487 |
| 6488 | SCTP_CHECK_AND_CAST(sasoc, optval, struct sctp_assocparams, optsize); |
| 6489 | SCTP_FIND_STCB(inp, stcb, sasoc->sasoc_assoc_id); |
| 6490 | if (sasoc->sasoc_cookie_life > 0) { |
| 6491 | /* boundary check the cookie life */ |
| 6492 | if (sasoc->sasoc_cookie_life < SCTP_MIN_COOKIE_LIFE) { |
| 6493 | sasoc->sasoc_cookie_life = SCTP_MIN_COOKIE_LIFE; |
| 6494 | } |
| 6495 | if (sasoc->sasoc_cookie_life > SCTP_MAX_COOKIE_LIFE) { |
| 6496 | sasoc->sasoc_cookie_life = SCTP_MAX_COOKIE_LIFE; |
| 6497 | } |
| 6498 | } |
| 6499 | if (stcb) { |
| 6500 | if (sasoc->sasoc_asocmaxrxt > 0) { |
| 6501 | stcb->asoc.max_send_times = sasoc->sasoc_asocmaxrxt; |
| 6502 | } |
| 6503 | if (sasoc->sasoc_cookie_life > 0) { |
| 6504 | stcb->asoc.cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life); |
| 6505 | } |
| 6506 | SCTP_TCB_UNLOCK(stcb); |
| 6507 | } else { |
| 6508 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 6509 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 6510 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 6511 | (sasoc->sasoc_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 6512 | SCTP_INP_WLOCK(inp); |
| 6513 | if (sasoc->sasoc_asocmaxrxt > 0) { |
| 6514 | inp->sctp_ep.max_send_times = sasoc->sasoc_asocmaxrxt; |
| 6515 | } |
| 6516 | if (sasoc->sasoc_cookie_life > 0) { |
| 6517 | inp->sctp_ep.def_cookie_life = sctp_msecs_to_ticks(sasoc->sasoc_cookie_life); |
| 6518 | } |
| 6519 | SCTP_INP_WUNLOCK(inp); |
| 6520 | } else { |
| 6521 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6522 | error = EINVAL; |
| 6523 | } |
| 6524 | } |
| 6525 | break; |
| 6526 | } |
| 6527 | case SCTP_INITMSG: |
| 6528 | { |
| 6529 | struct sctp_initmsg *sinit; |
| 6530 |
| 6531 | SCTP_CHECK_AND_CAST(sinit, optval, struct sctp_initmsg, optsize); |
| 6532 | SCTP_INP_WLOCK(inp); |
| 6533 | if (sinit->sinit_num_ostreams) |
| 6534 | inp->sctp_ep.pre_open_stream_count = sinit->sinit_num_ostreams; |
| 6535 |
| 6536 | if (sinit->sinit_max_instreams) |
| 6537 | inp->sctp_ep.max_open_streams_intome = sinit->sinit_max_instreams; |
| 6538 |
| 6539 | if (sinit->sinit_max_attempts) |
| 6540 | inp->sctp_ep.max_init_times = sinit->sinit_max_attempts; |
| 6541 |
| 6542 | if (sinit->sinit_max_init_timeo) |
| 6543 | inp->sctp_ep.initial_init_rto_max = sinit->sinit_max_init_timeo; |
| 6544 | SCTP_INP_WUNLOCK(inp); |
| 6545 | break; |
| 6546 | } |
| 6547 | case SCTP_PRIMARY_ADDR: |
| 6548 | { |
| 6549 | struct sctp_setprim *spa; |
| 6550 | struct sctp_nets *net; |
| 6551 | struct sockaddr *addr; |
| 6552 | #if defined(INET) && defined(INET6) |
| 6553 | struct sockaddr_in sin_store; |
| 6554 | #endif |
| 6555 |
| 6556 | SCTP_CHECK_AND_CAST(spa, optval, struct sctp_setprim, optsize); |
| 6557 | SCTP_FIND_STCB(inp, stcb, spa->ssp_assoc_id); |
| 6558 |
| 6559 | #if defined(INET) && defined(INET6) |
| 6560 | if (spa->ssp_addr.ss_family == AF_INET6) { |
| 6561 | struct sockaddr_in6 *sin6; |
| 6562 |
| 6563 | sin6 = (struct sockaddr_in6 *)&spa->ssp_addr; |
| 6564 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 6565 | in6_sin6_2_sin(&sin_store, sin6); |
| 6566 | addr = (struct sockaddr *)&sin_store; |
| 6567 | } else { |
| 6568 | addr = (struct sockaddr *)&spa->ssp_addr; |
| 6569 | } |
| 6570 | } else { |
| 6571 | addr = (struct sockaddr *)&spa->ssp_addr; |
| 6572 | } |
| 6573 | #else |
| 6574 | addr = (struct sockaddr *)&spa->ssp_addr; |
| 6575 | #endif |
| 6576 | if (stcb != NULL) { |
| 6577 | net = sctp_findnet(stcb, addr); |
| 6578 | } else { |
| 6579 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 6580 | * do a decrement if it finds the stcb as long as the locked |
| 6581 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 6582 | */ |
| 6583 | net = NULL; |
| 6584 | SCTP_INP_INCR_REF(inp); |
| 6585 | stcb = sctp_findassociation_ep_addr(&inp, addr, |
| 6586 | &net, NULL, NULL); |
| 6587 | if (stcb == NULL) { |
| 6588 | SCTP_INP_DECR_REF(inp); |
| 6589 | } |
| 6590 | } |
| 6591 |
| 6592 | if ((stcb != NULL) && (net != NULL)) { |
| 6593 | if (net != stcb->asoc.primary_destination) { |
| 6594 | if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) { |
| 6595 | /* Ok we need to set it */ |
| 6596 | if (sctp_set_primary_addr(stcb, (struct sockaddr *)NULL, net) == 0) { |
| 6597 | if ((stcb->asoc.alternate) && |
| 6598 | (!(net->dest_state & SCTP_ADDR_PF)) && |
| 6599 | (net->dest_state & SCTP_ADDR_REACHABLE)) { |
| 6600 | sctp_free_remote_addr(stcb->asoc.alternate); |
| 6601 | stcb->asoc.alternate = NULL; |
| 6602 | } |
| 6603 | } else { |
| 6604 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6605 | error = EINVAL; |
| 6606 | } |
| 6607 | } else { |
| 6608 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6609 | error = EINVAL; |
| 6610 | } |
| 6611 | } |
| 6612 | } else { |
| 6613 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6614 | error = EINVAL; |
| 6615 | } |
| 6616 | if (stcb != NULL) { |
| 6617 | SCTP_TCB_UNLOCK(stcb); |
| 6618 | } |
| 6619 | break; |
| 6620 | } |
| 6621 | case SCTP_SET_DYNAMIC_PRIMARY: |
| 6622 | { |
| 6623 | union sctp_sockstore *ss; |
| 6624 | #ifdef SCTP_MVRF |
| 6625 | int i, fnd = 0; |
| 6626 | #endif |
| 6627 | #if !defined(_WIN32) && !defined(__Userspace__) |
| 6628 | #if defined(__APPLE__) |
| 6629 | struct proc *proc; |
| 6630 | #endif |
| 6631 | #if defined(__FreeBSD__) |
| 6632 | error = priv_check(curthread, |
| 6633 | PRIV_NETINET_RESERVEDPORT); |
| 6634 | #elif defined(__APPLE__) |
| 6635 | proc = (struct proc *)p; |
| 6636 | if (p) { |
| 6637 | error = suser(proc->p_ucred, &proc->p_acflag); |
| 6638 | } else { |
| 6639 | break; |
| 6640 | } |
| 6641 | #else |
| 6642 | error = suser(p, 0); |
| 6643 | #endif |
| 6644 | if (error) |
| 6645 | break; |
| 6646 | #endif |
| 6647 |
| 6648 | SCTP_CHECK_AND_CAST(ss, optval, union sctp_sockstore, optsize); |
| 6649 | /* SUPER USER CHECK? */ |
| 6650 | #ifdef SCTP_MVRF |
| 6651 | for (i = 0; i < inp->num_vrfs; i++) { |
| 6652 | if (vrf_id == inp->m_vrf_ids[i]) { |
| 6653 | fnd = 1; |
| 6654 | break; |
| 6655 | } |
| 6656 | } |
| 6657 | if (!fnd) { |
| 6658 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6659 | error = EINVAL; |
| 6660 | break; |
| 6661 | } |
| 6662 | #endif |
| 6663 | error = sctp_dynamic_set_primary(&ss->sa, vrf_id); |
| 6664 | break; |
| 6665 | } |
| 6666 | case SCTP_SET_PEER_PRIMARY_ADDR: |
| 6667 | { |
| 6668 | struct sctp_setpeerprim *sspp; |
| 6669 | struct sockaddr *addr; |
| 6670 | #if defined(INET) && defined(INET6) |
| 6671 | struct sockaddr_in sin_store; |
| 6672 | #endif |
| 6673 |
| 6674 | SCTP_CHECK_AND_CAST(sspp, optval, struct sctp_setpeerprim, optsize); |
| 6675 | SCTP_FIND_STCB(inp, stcb, sspp->sspp_assoc_id); |
| 6676 | if (stcb != NULL) { |
| 6677 | struct sctp_ifa *ifa; |
| 6678 |
| 6679 | #if defined(INET) && defined(INET6) |
| 6680 | if (sspp->sspp_addr.ss_family == AF_INET6) { |
| 6681 | struct sockaddr_in6 *sin6; |
| 6682 |
| 6683 | sin6 = (struct sockaddr_in6 *)&sspp->sspp_addr; |
| 6684 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 6685 | in6_sin6_2_sin(&sin_store, sin6); |
| 6686 | addr = (struct sockaddr *)&sin_store; |
| 6687 | } else { |
| 6688 | addr = (struct sockaddr *)&sspp->sspp_addr; |
| 6689 | } |
| 6690 | } else { |
| 6691 | addr = (struct sockaddr *)&sspp->sspp_addr; |
| 6692 | } |
| 6693 | #else |
| 6694 | addr = (struct sockaddr *)&sspp->sspp_addr; |
| 6695 | #endif |
| 6696 | ifa = sctp_find_ifa_by_addr(addr, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED); |
| 6697 | if (ifa == NULL) { |
| 6698 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6699 | error = EINVAL; |
| 6700 | goto out_of_it; |
| 6701 | } |
| 6702 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { |
| 6703 | /* Must validate the ifa found is in our ep */ |
| 6704 | struct sctp_laddr *laddr; |
| 6705 | int found = 0; |
| 6706 |
| 6707 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
| 6708 | if (laddr->ifa == NULL) { |
| 6709 | SCTPDBG(SCTP_DEBUG_OUTPUT1, "%s: NULL ifa\n", |
| 6710 | __func__); |
| 6711 | continue; |
| 6712 | } |
| 6713 | if ((sctp_is_addr_restricted(stcb, laddr->ifa)) && |
| 6714 | (!sctp_is_addr_pending(stcb, laddr->ifa))) { |
| 6715 | continue; |
| 6716 | } |
| 6717 | if (laddr->ifa == ifa) { |
| 6718 | found = 1; |
| 6719 | break; |
| 6720 | } |
| 6721 | } |
| 6722 | if (!found) { |
| 6723 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6724 | error = EINVAL; |
| 6725 | goto out_of_it; |
| 6726 | } |
| 6727 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6728 | } else { |
| 6729 | switch (addr->sa_family) { |
| 6730 | #ifdef INET |
| 6731 | case AF_INET: |
| 6732 | { |
| 6733 | struct sockaddr_in *sin; |
| 6734 |
| 6735 | sin = (struct sockaddr_in *)addr; |
| 6736 | if (prison_check_ip4(inp->ip_inp.inp.inp_cred, |
| 6737 | &sin->sin_addr) != 0) { |
| 6738 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6739 | error = EINVAL; |
| 6740 | goto out_of_it; |
| 6741 | } |
| 6742 | break; |
| 6743 | } |
| 6744 | #endif |
| 6745 | #ifdef INET6 |
| 6746 | case AF_INET6: |
| 6747 | { |
| 6748 | struct sockaddr_in6 *sin6; |
| 6749 |
| 6750 | sin6 = (struct sockaddr_in6 *)addr; |
| 6751 | if (prison_check_ip6(inp->ip_inp.inp.inp_cred, |
| 6752 | &sin6->sin6_addr) != 0) { |
| 6753 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6754 | error = EINVAL; |
| 6755 | goto out_of_it; |
| 6756 | } |
| 6757 | break; |
| 6758 | } |
| 6759 | #endif |
| 6760 | default: |
| 6761 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6762 | error = EINVAL; |
| 6763 | goto out_of_it; |
| 6764 | } |
| 6765 | #endif |
| 6766 | } |
| 6767 | if (sctp_set_primary_ip_address_sa(stcb, addr) != 0) { |
| 6768 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6769 | error = EINVAL; |
| 6770 | } |
| 6771 | sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SOCKOPT, SCTP_SO_LOCKED); |
| 6772 | out_of_it: |
| 6773 | SCTP_TCB_UNLOCK(stcb); |
| 6774 | } else { |
| 6775 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6776 | error = EINVAL; |
| 6777 | } |
| 6778 | break; |
| 6779 | } |
| 6780 | case SCTP_BINDX_ADD_ADDR: |
| 6781 | { |
| 6782 | struct sockaddr *sa; |
| 6783 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6784 | struct thread *td; |
| 6785 |
| 6786 | td = (struct thread *)p; |
| 6787 | #endif |
| 6788 | SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize); |
| 6789 | #ifdef INET |
| 6790 | if (sa->sa_family == AF_INET) { |
| 6791 | if (optsize < sizeof(struct sockaddr_in)) { |
| 6792 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6793 | error = EINVAL; |
| 6794 | break; |
| 6795 | } |
| 6796 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6797 | if (td != NULL && |
| 6798 | (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) { |
| 6799 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 6800 | break; |
| 6801 | } |
| 6802 | #endif |
| 6803 | } else |
| 6804 | #endif |
| 6805 | #ifdef INET6 |
| 6806 | if (sa->sa_family == AF_INET6) { |
| 6807 | if (optsize < sizeof(struct sockaddr_in6)) { |
| 6808 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6809 | error = EINVAL; |
| 6810 | break; |
| 6811 | } |
| 6812 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6813 | if (td != NULL && |
| 6814 | (error = prison_local_ip6(td->td_ucred, |
| 6815 | &(((struct sockaddr_in6 *)sa)->sin6_addr), |
| 6816 | (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { |
| 6817 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 6818 | break; |
| 6819 | } |
| 6820 | #endif |
| 6821 | } else |
| 6822 | #endif |
| 6823 | { |
| 6824 | error = EAFNOSUPPORT; |
| 6825 | break; |
| 6826 | } |
| 6827 | sctp_bindx_add_address(so, inp, sa, vrf_id, &error, p); |
| 6828 | break; |
| 6829 | } |
| 6830 | case SCTP_BINDX_REM_ADDR: |
| 6831 | { |
| 6832 | struct sockaddr *sa; |
| 6833 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6834 | struct thread *td; |
| 6835 | td = (struct thread *)p; |
| 6836 |
| 6837 | #endif |
| 6838 | SCTP_CHECK_AND_CAST(sa, optval, struct sockaddr, optsize); |
| 6839 | #ifdef INET |
| 6840 | if (sa->sa_family == AF_INET) { |
| 6841 | if (optsize < sizeof(struct sockaddr_in)) { |
| 6842 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6843 | error = EINVAL; |
| 6844 | break; |
| 6845 | } |
| 6846 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6847 | if (td != NULL && |
| 6848 | (error = prison_local_ip4(td->td_ucred, &(((struct sockaddr_in *)sa)->sin_addr)))) { |
| 6849 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 6850 | break; |
| 6851 | } |
| 6852 | #endif |
| 6853 | } else |
| 6854 | #endif |
| 6855 | #ifdef INET6 |
| 6856 | if (sa->sa_family == AF_INET6) { |
| 6857 | if (optsize < sizeof(struct sockaddr_in6)) { |
| 6858 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6859 | error = EINVAL; |
| 6860 | break; |
| 6861 | } |
| 6862 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 6863 | if (td != NULL && |
| 6864 | (error = prison_local_ip6(td->td_ucred, |
| 6865 | &(((struct sockaddr_in6 *)sa)->sin6_addr), |
| 6866 | (SCTP_IPV6_V6ONLY(inp) != 0))) != 0) { |
| 6867 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 6868 | break; |
| 6869 | } |
| 6870 | #endif |
| 6871 | } else |
| 6872 | #endif |
| 6873 | { |
| 6874 | error = EAFNOSUPPORT; |
| 6875 | break; |
| 6876 | } |
| 6877 | sctp_bindx_delete_address(inp, sa, vrf_id, &error); |
| 6878 | break; |
| 6879 | } |
| 6880 | #if defined(__APPLE__) && !defined(__Userspace__) |
| 6881 | case SCTP_LISTEN_FIX: |
| 6882 | /* only applies to one-to-many sockets */ |
| 6883 | if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { |
| 6884 | /* make sure the ACCEPTCONN flag is OFF */ |
| 6885 | so->so_options &= ~SO_ACCEPTCONN; |
| 6886 | } else { |
| 6887 | /* otherwise, not allowed */ |
| 6888 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6889 | error = EINVAL; |
| 6890 | } |
| 6891 | break; |
| 6892 | #endif |
| 6893 | case SCTP_EVENT: |
| 6894 | { |
| 6895 | struct sctp_event *event; |
| 6896 | uint32_t event_type; |
| 6897 |
| 6898 | SCTP_CHECK_AND_CAST(event, optval, struct sctp_event, optsize); |
| 6899 | SCTP_FIND_STCB(inp, stcb, event->se_assoc_id); |
| 6900 | switch (event->se_type) { |
| 6901 | case SCTP_ASSOC_CHANGE: |
| 6902 | event_type = SCTP_PCB_FLAGS_RECVASSOCEVNT; |
| 6903 | break; |
| 6904 | case SCTP_PEER_ADDR_CHANGE: |
| 6905 | event_type = SCTP_PCB_FLAGS_RECVPADDREVNT; |
| 6906 | break; |
| 6907 | case SCTP_REMOTE_ERROR: |
| 6908 | event_type = SCTP_PCB_FLAGS_RECVPEERERR; |
| 6909 | break; |
| 6910 | case SCTP_SEND_FAILED: |
| 6911 | event_type = SCTP_PCB_FLAGS_RECVSENDFAILEVNT; |
| 6912 | break; |
| 6913 | case SCTP_SHUTDOWN_EVENT: |
| 6914 | event_type = SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT; |
| 6915 | break; |
| 6916 | case SCTP_ADAPTATION_INDICATION: |
| 6917 | event_type = SCTP_PCB_FLAGS_ADAPTATIONEVNT; |
| 6918 | break; |
| 6919 | case SCTP_PARTIAL_DELIVERY_EVENT: |
| 6920 | event_type = SCTP_PCB_FLAGS_PDAPIEVNT; |
| 6921 | break; |
| 6922 | case SCTP_AUTHENTICATION_EVENT: |
| 6923 | event_type = SCTP_PCB_FLAGS_AUTHEVNT; |
| 6924 | break; |
| 6925 | case SCTP_STREAM_RESET_EVENT: |
| 6926 | event_type = SCTP_PCB_FLAGS_STREAM_RESETEVNT; |
| 6927 | break; |
| 6928 | case SCTP_SENDER_DRY_EVENT: |
| 6929 | event_type = SCTP_PCB_FLAGS_DRYEVNT; |
| 6930 | break; |
| 6931 | case SCTP_NOTIFICATIONS_STOPPED_EVENT: |
| 6932 | event_type = 0; |
| 6933 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP); |
| 6934 | error = ENOTSUP; |
| 6935 | break; |
| 6936 | case SCTP_ASSOC_RESET_EVENT: |
| 6937 | event_type = SCTP_PCB_FLAGS_ASSOC_RESETEVNT; |
| 6938 | break; |
| 6939 | case SCTP_STREAM_CHANGE_EVENT: |
| 6940 | event_type = SCTP_PCB_FLAGS_STREAM_CHANGEEVNT; |
| 6941 | break; |
| 6942 | case SCTP_SEND_FAILED_EVENT: |
| 6943 | event_type = SCTP_PCB_FLAGS_RECVNSENDFAILEVNT; |
| 6944 | break; |
| 6945 | default: |
| 6946 | event_type = 0; |
| 6947 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 6948 | error = EINVAL; |
| 6949 | break; |
| 6950 | } |
| 6951 | if (event_type > 0) { |
| 6952 | if (stcb) { |
| 6953 | if (event->se_on) { |
| 6954 | sctp_stcb_feature_on(inp, stcb, event_type); |
| 6955 | if (event_type == SCTP_PCB_FLAGS_DRYEVNT) { |
| 6956 | if (TAILQ_EMPTY(&stcb->asoc.send_queue) && |
| 6957 | TAILQ_EMPTY(&stcb->asoc.sent_queue) && |
| 6958 | (stcb->asoc.stream_queue_cnt == 0)) { |
| 6959 | sctp_ulp_notify(SCTP_NOTIFY_SENDER_DRY, stcb, 0, NULL, SCTP_SO_LOCKED); |
| 6960 | } |
| 6961 | } |
| 6962 | } else { |
| 6963 | sctp_stcb_feature_off(inp, stcb, event_type); |
| 6964 | } |
| 6965 | SCTP_TCB_UNLOCK(stcb); |
| 6966 | } else { |
| 6967 | /* |
| 6968 | * We don't want to send up a storm of events, |
| 6969 | * so return an error for sender dry events |
| 6970 | */ |
| 6971 | if ((event_type == SCTP_PCB_FLAGS_DRYEVNT) && |
| 6972 | (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 6973 | ((event->se_assoc_id == SCTP_ALL_ASSOC) || |
| 6974 | (event->se_assoc_id == SCTP_CURRENT_ASSOC))) { |
| 6975 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTSUP); |
| 6976 | error = ENOTSUP; |
| 6977 | break; |
| 6978 | } |
| 6979 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 6980 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 6981 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 6982 | ((event->se_assoc_id == SCTP_FUTURE_ASSOC) || |
| 6983 | (event->se_assoc_id == SCTP_ALL_ASSOC)))) { |
| 6984 | SCTP_INP_WLOCK(inp); |
| 6985 | if (event->se_on) { |
| 6986 | sctp_feature_on(inp, event_type); |
| 6987 | } else { |
| 6988 | sctp_feature_off(inp, event_type); |
| 6989 | } |
| 6990 | SCTP_INP_WUNLOCK(inp); |
| 6991 | } |
| 6992 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 6993 | ((event->se_assoc_id == SCTP_CURRENT_ASSOC) || |
| 6994 | (event->se_assoc_id == SCTP_ALL_ASSOC))) { |
| 6995 | SCTP_INP_RLOCK(inp); |
| 6996 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 6997 | SCTP_TCB_LOCK(stcb); |
| 6998 | if (event->se_on) { |
| 6999 | sctp_stcb_feature_on(inp, stcb, event_type); |
| 7000 | } else { |
| 7001 | sctp_stcb_feature_off(inp, stcb, event_type); |
| 7002 | } |
| 7003 | SCTP_TCB_UNLOCK(stcb); |
| 7004 | } |
| 7005 | SCTP_INP_RUNLOCK(inp); |
| 7006 | } |
| 7007 | } |
| 7008 | } else { |
| 7009 | if (stcb) { |
| 7010 | SCTP_TCB_UNLOCK(stcb); |
| 7011 | } |
| 7012 | } |
| 7013 | break; |
| 7014 | } |
| 7015 | case SCTP_RECVRCVINFO: |
| 7016 | { |
| 7017 | int *onoff; |
| 7018 |
| 7019 | SCTP_CHECK_AND_CAST(onoff, optval, int, optsize); |
| 7020 | SCTP_INP_WLOCK(inp); |
| 7021 | if (*onoff != 0) { |
| 7022 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO); |
| 7023 | } else { |
| 7024 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO); |
| 7025 | } |
| 7026 | SCTP_INP_WUNLOCK(inp); |
| 7027 | break; |
| 7028 | } |
| 7029 | case SCTP_RECVNXTINFO: |
| 7030 | { |
| 7031 | int *onoff; |
| 7032 |
| 7033 | SCTP_CHECK_AND_CAST(onoff, optval, int, optsize); |
| 7034 | SCTP_INP_WLOCK(inp); |
| 7035 | if (*onoff != 0) { |
| 7036 | sctp_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO); |
| 7037 | } else { |
| 7038 | sctp_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO); |
| 7039 | } |
| 7040 | SCTP_INP_WUNLOCK(inp); |
| 7041 | break; |
| 7042 | } |
| 7043 | case SCTP_DEFAULT_SNDINFO: |
| 7044 | { |
| 7045 | struct sctp_sndinfo *info; |
| 7046 | uint16_t policy; |
| 7047 |
| 7048 | SCTP_CHECK_AND_CAST(info, optval, struct sctp_sndinfo, optsize); |
| 7049 | SCTP_FIND_STCB(inp, stcb, info->snd_assoc_id); |
| 7050 |
| 7051 | if (stcb) { |
| 7052 | if (info->snd_sid < stcb->asoc.streamoutcnt) { |
| 7053 | stcb->asoc.def_send.sinfo_stream = info->snd_sid; |
| 7054 | policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags); |
| 7055 | stcb->asoc.def_send.sinfo_flags = info->snd_flags; |
| 7056 | stcb->asoc.def_send.sinfo_flags |= policy; |
| 7057 | stcb->asoc.def_send.sinfo_ppid = info->snd_ppid; |
| 7058 | stcb->asoc.def_send.sinfo_context = info->snd_context; |
| 7059 | } else { |
| 7060 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7061 | error = EINVAL; |
| 7062 | } |
| 7063 | SCTP_TCB_UNLOCK(stcb); |
| 7064 | } else { |
| 7065 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7066 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7067 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7068 | ((info->snd_assoc_id == SCTP_FUTURE_ASSOC) || |
| 7069 | (info->snd_assoc_id == SCTP_ALL_ASSOC)))) { |
| 7070 | SCTP_INP_WLOCK(inp); |
| 7071 | inp->def_send.sinfo_stream = info->snd_sid; |
| 7072 | policy = PR_SCTP_POLICY(inp->def_send.sinfo_flags); |
| 7073 | inp->def_send.sinfo_flags = info->snd_flags; |
| 7074 | inp->def_send.sinfo_flags |= policy; |
| 7075 | inp->def_send.sinfo_ppid = info->snd_ppid; |
| 7076 | inp->def_send.sinfo_context = info->snd_context; |
| 7077 | SCTP_INP_WUNLOCK(inp); |
| 7078 | } |
| 7079 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7080 | ((info->snd_assoc_id == SCTP_CURRENT_ASSOC) || |
| 7081 | (info->snd_assoc_id == SCTP_ALL_ASSOC))) { |
| 7082 | SCTP_INP_RLOCK(inp); |
| 7083 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 7084 | SCTP_TCB_LOCK(stcb); |
| 7085 | if (info->snd_sid < stcb->asoc.streamoutcnt) { |
| 7086 | stcb->asoc.def_send.sinfo_stream = info->snd_sid; |
| 7087 | policy = PR_SCTP_POLICY(stcb->asoc.def_send.sinfo_flags); |
| 7088 | stcb->asoc.def_send.sinfo_flags = info->snd_flags; |
| 7089 | stcb->asoc.def_send.sinfo_flags |= policy; |
| 7090 | stcb->asoc.def_send.sinfo_ppid = info->snd_ppid; |
| 7091 | stcb->asoc.def_send.sinfo_context = info->snd_context; |
| 7092 | } |
| 7093 | SCTP_TCB_UNLOCK(stcb); |
| 7094 | } |
| 7095 | SCTP_INP_RUNLOCK(inp); |
| 7096 | } |
| 7097 | } |
| 7098 | break; |
| 7099 | } |
| 7100 | case SCTP_DEFAULT_PRINFO: |
| 7101 | { |
| 7102 | struct sctp_default_prinfo *info; |
| 7103 |
| 7104 | SCTP_CHECK_AND_CAST(info, optval, struct sctp_default_prinfo, optsize); |
| 7105 | SCTP_FIND_STCB(inp, stcb, info->pr_assoc_id); |
| 7106 |
| 7107 | if (info->pr_policy > SCTP_PR_SCTP_MAX) { |
| 7108 | if (stcb) { |
| 7109 | SCTP_TCB_UNLOCK(stcb); |
| 7110 | } |
| 7111 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7112 | error = EINVAL; |
| 7113 | break; |
| 7114 | } |
| 7115 | if (stcb) { |
| 7116 | stcb->asoc.def_send.sinfo_flags &= 0xfff0; |
| 7117 | stcb->asoc.def_send.sinfo_flags |= info->pr_policy; |
| 7118 | stcb->asoc.def_send.sinfo_timetolive = info->pr_value; |
| 7119 | SCTP_TCB_UNLOCK(stcb); |
| 7120 | } else { |
| 7121 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7122 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7123 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7124 | ((info->pr_assoc_id == SCTP_FUTURE_ASSOC) || |
| 7125 | (info->pr_assoc_id == SCTP_ALL_ASSOC)))) { |
| 7126 | SCTP_INP_WLOCK(inp); |
| 7127 | inp->def_send.sinfo_flags &= 0xfff0; |
| 7128 | inp->def_send.sinfo_flags |= info->pr_policy; |
| 7129 | inp->def_send.sinfo_timetolive = info->pr_value; |
| 7130 | SCTP_INP_WUNLOCK(inp); |
| 7131 | } |
| 7132 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7133 | ((info->pr_assoc_id == SCTP_CURRENT_ASSOC) || |
| 7134 | (info->pr_assoc_id == SCTP_ALL_ASSOC))) { |
| 7135 | SCTP_INP_RLOCK(inp); |
| 7136 | LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { |
| 7137 | SCTP_TCB_LOCK(stcb); |
| 7138 | stcb->asoc.def_send.sinfo_flags &= 0xfff0; |
| 7139 | stcb->asoc.def_send.sinfo_flags |= info->pr_policy; |
| 7140 | stcb->asoc.def_send.sinfo_timetolive = info->pr_value; |
| 7141 | SCTP_TCB_UNLOCK(stcb); |
| 7142 | } |
| 7143 | SCTP_INP_RUNLOCK(inp); |
| 7144 | } |
| 7145 | } |
| 7146 | break; |
| 7147 | } |
| 7148 | case SCTP_PEER_ADDR_THLDS: |
| 7149 | /* Applies to the specific association */ |
| 7150 | { |
| 7151 | struct sctp_paddrthlds *thlds; |
| 7152 | struct sctp_nets *net; |
| 7153 | struct sockaddr *addr; |
| 7154 | #if defined(INET) && defined(INET6) |
| 7155 | struct sockaddr_in sin_store; |
| 7156 | #endif |
| 7157 |
| 7158 | SCTP_CHECK_AND_CAST(thlds, optval, struct sctp_paddrthlds, optsize); |
| 7159 | SCTP_FIND_STCB(inp, stcb, thlds->spt_assoc_id); |
| 7160 |
| 7161 | #if defined(INET) && defined(INET6) |
| 7162 | if (thlds->spt_address.ss_family == AF_INET6) { |
| 7163 | struct sockaddr_in6 *sin6; |
| 7164 |
| 7165 | sin6 = (struct sockaddr_in6 *)&thlds->spt_address; |
| 7166 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 7167 | in6_sin6_2_sin(&sin_store, sin6); |
| 7168 | addr = (struct sockaddr *)&sin_store; |
| 7169 | } else { |
| 7170 | addr = (struct sockaddr *)&thlds->spt_address; |
| 7171 | } |
| 7172 | } else { |
| 7173 | addr = (struct sockaddr *)&thlds->spt_address; |
| 7174 | } |
| 7175 | #else |
| 7176 | addr = (struct sockaddr *)&thlds->spt_address; |
| 7177 | #endif |
| 7178 | if (stcb != NULL) { |
| 7179 | net = sctp_findnet(stcb, addr); |
| 7180 | } else { |
| 7181 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 7182 | * do a decrement if it finds the stcb as long as the locked |
| 7183 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 7184 | */ |
| 7185 | net = NULL; |
| 7186 | SCTP_INP_INCR_REF(inp); |
| 7187 | stcb = sctp_findassociation_ep_addr(&inp, addr, |
| 7188 | &net, NULL, NULL); |
| 7189 | if (stcb == NULL) { |
| 7190 | SCTP_INP_DECR_REF(inp); |
| 7191 | } |
| 7192 | } |
| 7193 | if ((stcb != NULL) && (net == NULL)) { |
| 7194 | #ifdef INET |
| 7195 | if (addr->sa_family == AF_INET) { |
| 7196 | struct sockaddr_in *sin; |
| 7197 |
| 7198 | sin = (struct sockaddr_in *)addr; |
| 7199 | if (sin->sin_addr.s_addr != INADDR_ANY) { |
| 7200 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7201 | SCTP_TCB_UNLOCK(stcb); |
| 7202 | error = EINVAL; |
| 7203 | break; |
| 7204 | } |
| 7205 | } else |
| 7206 | #endif |
| 7207 | #ifdef INET6 |
| 7208 | if (addr->sa_family == AF_INET6) { |
| 7209 | struct sockaddr_in6 *sin6; |
| 7210 |
| 7211 | sin6 = (struct sockaddr_in6 *)addr; |
| 7212 | if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 7213 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7214 | SCTP_TCB_UNLOCK(stcb); |
| 7215 | error = EINVAL; |
| 7216 | break; |
| 7217 | } |
| 7218 | } else |
| 7219 | #endif |
| 7220 | #if defined(__Userspace__) |
| 7221 | if (addr->sa_family == AF_CONN) { |
| 7222 | struct sockaddr_conn *sconn; |
| 7223 |
| 7224 | sconn = (struct sockaddr_conn *)addr; |
| 7225 | if (sconn->sconn_addr != NULL) { |
| 7226 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7227 | SCTP_TCB_UNLOCK(stcb); |
| 7228 | error = EINVAL; |
| 7229 | break; |
| 7230 | } |
| 7231 | } else |
| 7232 | #endif |
| 7233 | { |
| 7234 | error = EAFNOSUPPORT; |
| 7235 | SCTP_TCB_UNLOCK(stcb); |
| 7236 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 7237 | break; |
| 7238 | } |
| 7239 | } |
| 7240 | if (thlds->spt_pathcpthld != 0xffff) { |
| 7241 | if (stcb != NULL) { |
| 7242 | SCTP_TCB_UNLOCK(stcb); |
| 7243 | } |
| 7244 | error = EINVAL; |
| 7245 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 7246 | break; |
| 7247 | } |
| 7248 | if (stcb != NULL) { |
| 7249 | if (net != NULL) { |
| 7250 | net->failure_threshold = thlds->spt_pathmaxrxt; |
| 7251 | net->pf_threshold = thlds->spt_pathpfthld; |
| 7252 | if (net->dest_state & SCTP_ADDR_PF) { |
| 7253 | if ((net->error_count > net->failure_threshold) || |
| 7254 | (net->error_count <= net->pf_threshold)) { |
| 7255 | net->dest_state &= ~SCTP_ADDR_PF; |
| 7256 | } |
| 7257 | } else { |
| 7258 | if ((net->error_count > net->pf_threshold) && |
| 7259 | (net->error_count <= net->failure_threshold)) { |
| 7260 | net->dest_state |= SCTP_ADDR_PF; |
| 7261 | sctp_send_hb(stcb, net, SCTP_SO_LOCKED); |
| 7262 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 7263 | stcb->sctp_ep, stcb, net, |
| 7264 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_17); |
| 7265 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); |
| 7266 | } |
| 7267 | } |
| 7268 | if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 7269 | if (net->error_count > net->failure_threshold) { |
| 7270 | net->dest_state &= ~SCTP_ADDR_REACHABLE; |
| 7271 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); |
| 7272 | } |
| 7273 | } else { |
| 7274 | if (net->error_count <= net->failure_threshold) { |
| 7275 | net->dest_state |= SCTP_ADDR_REACHABLE; |
| 7276 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); |
| 7277 | } |
| 7278 | } |
| 7279 | } else { |
| 7280 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 7281 | net->failure_threshold = thlds->spt_pathmaxrxt; |
| 7282 | net->pf_threshold = thlds->spt_pathpfthld; |
| 7283 | if (net->dest_state & SCTP_ADDR_PF) { |
| 7284 | if ((net->error_count > net->failure_threshold) || |
| 7285 | (net->error_count <= net->pf_threshold)) { |
| 7286 | net->dest_state &= ~SCTP_ADDR_PF; |
| 7287 | } |
| 7288 | } else { |
| 7289 | if ((net->error_count > net->pf_threshold) && |
| 7290 | (net->error_count <= net->failure_threshold)) { |
| 7291 | net->dest_state |= SCTP_ADDR_PF; |
| 7292 | sctp_send_hb(stcb, net, SCTP_SO_LOCKED); |
| 7293 | sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, |
| 7294 | stcb->sctp_ep, stcb, net, |
| 7295 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_18); |
| 7296 | sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net); |
| 7297 | } |
| 7298 | } |
| 7299 | if (net->dest_state & SCTP_ADDR_REACHABLE) { |
| 7300 | if (net->error_count > net->failure_threshold) { |
| 7301 | net->dest_state &= ~SCTP_ADDR_REACHABLE; |
| 7302 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_DOWN, stcb, 0, net, SCTP_SO_LOCKED); |
| 7303 | } |
| 7304 | } else { |
| 7305 | if (net->error_count <= net->failure_threshold) { |
| 7306 | net->dest_state |= SCTP_ADDR_REACHABLE; |
| 7307 | sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_UP, stcb, 0, net, SCTP_SO_LOCKED); |
| 7308 | } |
| 7309 | } |
| 7310 | } |
| 7311 | stcb->asoc.def_net_failure = thlds->spt_pathmaxrxt; |
| 7312 | stcb->asoc.def_net_pf_threshold = thlds->spt_pathpfthld; |
| 7313 | } |
| 7314 | SCTP_TCB_UNLOCK(stcb); |
| 7315 | } else { |
| 7316 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7317 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7318 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7319 | (thlds->spt_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7320 | SCTP_INP_WLOCK(inp); |
| 7321 | inp->sctp_ep.def_net_failure = thlds->spt_pathmaxrxt; |
| 7322 | inp->sctp_ep.def_net_pf_threshold = thlds->spt_pathpfthld; |
| 7323 | SCTP_INP_WUNLOCK(inp); |
| 7324 | } else { |
| 7325 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7326 | error = EINVAL; |
| 7327 | } |
| 7328 | } |
| 7329 | break; |
| 7330 | } |
| 7331 | case SCTP_REMOTE_UDP_ENCAPS_PORT: |
| 7332 | { |
| 7333 | struct sctp_udpencaps *encaps; |
| 7334 | struct sctp_nets *net; |
| 7335 | struct sockaddr *addr; |
| 7336 | #if defined(INET) && defined(INET6) |
| 7337 | struct sockaddr_in sin_store; |
| 7338 | #endif |
| 7339 |
| 7340 | SCTP_CHECK_AND_CAST(encaps, optval, struct sctp_udpencaps, optsize); |
| 7341 | SCTP_FIND_STCB(inp, stcb, encaps->sue_assoc_id); |
| 7342 |
| 7343 | #if defined(INET) && defined(INET6) |
| 7344 | if (encaps->sue_address.ss_family == AF_INET6) { |
| 7345 | struct sockaddr_in6 *sin6; |
| 7346 |
| 7347 | sin6 = (struct sockaddr_in6 *)&encaps->sue_address; |
| 7348 | if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
| 7349 | in6_sin6_2_sin(&sin_store, sin6); |
| 7350 | addr = (struct sockaddr *)&sin_store; |
| 7351 | } else { |
| 7352 | addr = (struct sockaddr *)&encaps->sue_address; |
| 7353 | } |
| 7354 | } else { |
| 7355 | addr = (struct sockaddr *)&encaps->sue_address; |
| 7356 | } |
| 7357 | #else |
| 7358 | addr = (struct sockaddr *)&encaps->sue_address; |
| 7359 | #endif |
| 7360 | if (stcb != NULL) { |
| 7361 | net = sctp_findnet(stcb, addr); |
| 7362 | } else { |
| 7363 | /* We increment here since sctp_findassociation_ep_addr() wil |
| 7364 | * do a decrement if it finds the stcb as long as the locked |
| 7365 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 7366 | */ |
| 7367 | net = NULL; |
| 7368 | SCTP_INP_INCR_REF(inp); |
| 7369 | stcb = sctp_findassociation_ep_addr(&inp, addr, &net, NULL, NULL); |
| 7370 | if (stcb == NULL) { |
| 7371 | SCTP_INP_DECR_REF(inp); |
| 7372 | } |
| 7373 | } |
| 7374 | if ((stcb != NULL) && (net == NULL)) { |
| 7375 | #ifdef INET |
| 7376 | if (addr->sa_family == AF_INET) { |
| 7377 | struct sockaddr_in *sin; |
| 7378 |
| 7379 | sin = (struct sockaddr_in *)addr; |
| 7380 | if (sin->sin_addr.s_addr != INADDR_ANY) { |
| 7381 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7382 | SCTP_TCB_UNLOCK(stcb); |
| 7383 | error = EINVAL; |
| 7384 | break; |
| 7385 | } |
| 7386 | } else |
| 7387 | #endif |
| 7388 | #ifdef INET6 |
| 7389 | if (addr->sa_family == AF_INET6) { |
| 7390 | struct sockaddr_in6 *sin6; |
| 7391 |
| 7392 | sin6 = (struct sockaddr_in6 *)addr; |
| 7393 | if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 7394 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7395 | SCTP_TCB_UNLOCK(stcb); |
| 7396 | error = EINVAL; |
| 7397 | break; |
| 7398 | } |
| 7399 | } else |
| 7400 | #endif |
| 7401 | #if defined(__Userspace__) |
| 7402 | if (addr->sa_family == AF_CONN) { |
| 7403 | struct sockaddr_conn *sconn; |
| 7404 |
| 7405 | sconn = (struct sockaddr_conn *)addr; |
| 7406 | if (sconn->sconn_addr != NULL) { |
| 7407 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7408 | SCTP_TCB_UNLOCK(stcb); |
| 7409 | error = EINVAL; |
| 7410 | break; |
| 7411 | } |
| 7412 | } else |
| 7413 | #endif |
| 7414 | { |
| 7415 | error = EAFNOSUPPORT; |
| 7416 | SCTP_TCB_UNLOCK(stcb); |
| 7417 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 7418 | break; |
| 7419 | } |
| 7420 | } |
| 7421 |
| 7422 | if (stcb != NULL) { |
| 7423 | if (net != NULL) { |
| 7424 | net->port = encaps->sue_port; |
| 7425 | } else { |
| 7426 | stcb->asoc.port = encaps->sue_port; |
| 7427 | } |
| 7428 | SCTP_TCB_UNLOCK(stcb); |
| 7429 | } else { |
| 7430 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7431 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7432 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7433 | (encaps->sue_assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7434 | SCTP_INP_WLOCK(inp); |
| 7435 | inp->sctp_ep.port = encaps->sue_port; |
| 7436 | SCTP_INP_WUNLOCK(inp); |
| 7437 | } else { |
| 7438 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7439 | error = EINVAL; |
| 7440 | } |
| 7441 | } |
| 7442 | break; |
| 7443 | } |
| 7444 | case SCTP_ECN_SUPPORTED: |
| 7445 | { |
| 7446 | struct sctp_assoc_value *av; |
| 7447 |
| 7448 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7449 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7450 |
| 7451 | if (stcb) { |
| 7452 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7453 | error = EINVAL; |
| 7454 | SCTP_TCB_UNLOCK(stcb); |
| 7455 | } else { |
| 7456 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7457 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7458 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7459 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7460 | SCTP_INP_WLOCK(inp); |
| 7461 | if (av->assoc_value == 0) { |
| 7462 | inp->ecn_supported = 0; |
| 7463 | } else { |
| 7464 | inp->ecn_supported = 1; |
| 7465 | } |
| 7466 | SCTP_INP_WUNLOCK(inp); |
| 7467 | } else { |
| 7468 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7469 | error = EINVAL; |
| 7470 | } |
| 7471 | } |
| 7472 | break; |
| 7473 | } |
| 7474 | case SCTP_PR_SUPPORTED: |
| 7475 | { |
| 7476 | struct sctp_assoc_value *av; |
| 7477 |
| 7478 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7479 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7480 |
| 7481 | if (stcb) { |
| 7482 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7483 | error = EINVAL; |
| 7484 | SCTP_TCB_UNLOCK(stcb); |
| 7485 | } else { |
| 7486 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7487 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7488 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7489 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7490 | SCTP_INP_WLOCK(inp); |
| 7491 | if (av->assoc_value == 0) { |
| 7492 | inp->prsctp_supported = 0; |
| 7493 | } else { |
| 7494 | inp->prsctp_supported = 1; |
| 7495 | } |
| 7496 | SCTP_INP_WUNLOCK(inp); |
| 7497 | } else { |
| 7498 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7499 | error = EINVAL; |
| 7500 | } |
| 7501 | } |
| 7502 | break; |
| 7503 | } |
| 7504 | case SCTP_AUTH_SUPPORTED: |
| 7505 | { |
| 7506 | struct sctp_assoc_value *av; |
| 7507 |
| 7508 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7509 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7510 |
| 7511 | if (stcb) { |
| 7512 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7513 | error = EINVAL; |
| 7514 | SCTP_TCB_UNLOCK(stcb); |
| 7515 | } else { |
| 7516 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7517 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7518 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7519 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7520 | if ((av->assoc_value == 0) && |
| 7521 | (inp->asconf_supported == 1)) { |
| 7522 | /* AUTH is required for ASCONF */ |
| 7523 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7524 | error = EINVAL; |
| 7525 | } else { |
| 7526 | SCTP_INP_WLOCK(inp); |
| 7527 | if (av->assoc_value == 0) { |
| 7528 | inp->auth_supported = 0; |
| 7529 | } else { |
| 7530 | inp->auth_supported = 1; |
| 7531 | } |
| 7532 | SCTP_INP_WUNLOCK(inp); |
| 7533 | } |
| 7534 | } else { |
| 7535 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7536 | error = EINVAL; |
| 7537 | } |
| 7538 | } |
| 7539 | break; |
| 7540 | } |
| 7541 | case SCTP_ASCONF_SUPPORTED: |
| 7542 | { |
| 7543 | struct sctp_assoc_value *av; |
| 7544 |
| 7545 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7546 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7547 |
| 7548 | if (stcb) { |
| 7549 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7550 | error = EINVAL; |
| 7551 | SCTP_TCB_UNLOCK(stcb); |
| 7552 | } else { |
| 7553 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7554 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7555 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7556 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7557 | if ((av->assoc_value != 0) && |
| 7558 | (inp->auth_supported == 0)) { |
| 7559 | /* AUTH is required for ASCONF */ |
| 7560 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7561 | error = EINVAL; |
| 7562 | } else { |
| 7563 | SCTP_INP_WLOCK(inp); |
| 7564 | if (av->assoc_value == 0) { |
| 7565 | inp->asconf_supported = 0; |
| 7566 | sctp_auth_delete_chunk(SCTP_ASCONF, |
| 7567 | inp->sctp_ep.local_auth_chunks); |
| 7568 | sctp_auth_delete_chunk(SCTP_ASCONF_ACK, |
| 7569 | inp->sctp_ep.local_auth_chunks); |
| 7570 | } else { |
| 7571 | inp->asconf_supported = 1; |
| 7572 | sctp_auth_add_chunk(SCTP_ASCONF, |
| 7573 | inp->sctp_ep.local_auth_chunks); |
| 7574 | sctp_auth_add_chunk(SCTP_ASCONF_ACK, |
| 7575 | inp->sctp_ep.local_auth_chunks); |
| 7576 | } |
| 7577 | SCTP_INP_WUNLOCK(inp); |
| 7578 | } |
| 7579 | } else { |
| 7580 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7581 | error = EINVAL; |
| 7582 | } |
| 7583 | } |
| 7584 | break; |
| 7585 | } |
| 7586 | case SCTP_RECONFIG_SUPPORTED: |
| 7587 | { |
| 7588 | struct sctp_assoc_value *av; |
| 7589 |
| 7590 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7591 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7592 |
| 7593 | if (stcb) { |
| 7594 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7595 | error = EINVAL; |
| 7596 | SCTP_TCB_UNLOCK(stcb); |
| 7597 | } else { |
| 7598 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7599 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7600 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7601 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7602 | SCTP_INP_WLOCK(inp); |
| 7603 | if (av->assoc_value == 0) { |
| 7604 | inp->reconfig_supported = 0; |
| 7605 | } else { |
| 7606 | inp->reconfig_supported = 1; |
| 7607 | } |
| 7608 | SCTP_INP_WUNLOCK(inp); |
| 7609 | } else { |
| 7610 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7611 | error = EINVAL; |
| 7612 | } |
| 7613 | } |
| 7614 | break; |
| 7615 | } |
| 7616 | case SCTP_NRSACK_SUPPORTED: |
| 7617 | { |
| 7618 | struct sctp_assoc_value *av; |
| 7619 |
| 7620 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7621 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7622 |
| 7623 | if (stcb) { |
| 7624 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7625 | error = EINVAL; |
| 7626 | SCTP_TCB_UNLOCK(stcb); |
| 7627 | } else { |
| 7628 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7629 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7630 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7631 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7632 | SCTP_INP_WLOCK(inp); |
| 7633 | if (av->assoc_value == 0) { |
| 7634 | inp->nrsack_supported = 0; |
| 7635 | } else { |
| 7636 | inp->nrsack_supported = 1; |
| 7637 | } |
| 7638 | SCTP_INP_WUNLOCK(inp); |
| 7639 | } else { |
| 7640 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7641 | error = EINVAL; |
| 7642 | } |
| 7643 | } |
| 7644 | break; |
| 7645 | } |
| 7646 | case SCTP_PKTDROP_SUPPORTED: |
| 7647 | { |
| 7648 | struct sctp_assoc_value *av; |
| 7649 |
| 7650 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7651 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7652 |
| 7653 | if (stcb) { |
| 7654 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7655 | error = EINVAL; |
| 7656 | SCTP_TCB_UNLOCK(stcb); |
| 7657 | } else { |
| 7658 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7659 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7660 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7661 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7662 | SCTP_INP_WLOCK(inp); |
| 7663 | if (av->assoc_value == 0) { |
| 7664 | inp->pktdrop_supported = 0; |
| 7665 | } else { |
| 7666 | inp->pktdrop_supported = 1; |
| 7667 | } |
| 7668 | SCTP_INP_WUNLOCK(inp); |
| 7669 | } else { |
| 7670 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7671 | error = EINVAL; |
| 7672 | } |
| 7673 | } |
| 7674 | break; |
| 7675 | } |
| 7676 | case SCTP_MAX_CWND: |
| 7677 | { |
| 7678 | struct sctp_assoc_value *av; |
| 7679 | struct sctp_nets *net; |
| 7680 |
| 7681 | SCTP_CHECK_AND_CAST(av, optval, struct sctp_assoc_value, optsize); |
| 7682 | SCTP_FIND_STCB(inp, stcb, av->assoc_id); |
| 7683 |
| 7684 | if (stcb) { |
| 7685 | stcb->asoc.max_cwnd = av->assoc_value; |
| 7686 | if (stcb->asoc.max_cwnd > 0) { |
| 7687 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 7688 | if ((net->cwnd > stcb->asoc.max_cwnd) && |
| 7689 | (net->cwnd > (net->mtu - sizeof(struct sctphdr)))) { |
| 7690 | net->cwnd = stcb->asoc.max_cwnd; |
| 7691 | if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) { |
| 7692 | net->cwnd = net->mtu - sizeof(struct sctphdr); |
| 7693 | } |
| 7694 | } |
| 7695 | } |
| 7696 | } |
| 7697 | SCTP_TCB_UNLOCK(stcb); |
| 7698 | } else { |
| 7699 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || |
| 7700 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || |
| 7701 | ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) && |
| 7702 | (av->assoc_id == SCTP_FUTURE_ASSOC))) { |
| 7703 | SCTP_INP_WLOCK(inp); |
| 7704 | inp->max_cwnd = av->assoc_value; |
| 7705 | SCTP_INP_WUNLOCK(inp); |
| 7706 | } else { |
| 7707 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7708 | error = EINVAL; |
| 7709 | } |
| 7710 | } |
| 7711 | break; |
| 7712 | } |
| 7713 | default: |
| 7714 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOPROTOOPT); |
| 7715 | error = ENOPROTOOPT; |
| 7716 | break; |
| 7717 | } /* end switch (opt) */ |
| 7718 | return (error); |
| 7719 | } |
| 7720 |
| 7721 | #if !defined(__Userspace__) |
| 7722 | int |
| 7723 | sctp_ctloutput(struct socket *so, struct sockopt *sopt) |
| 7724 | { |
| 7725 | #if defined(__FreeBSD__) |
| 7726 | struct epoch_tracker et; |
| 7727 | struct sctp_inpcb *inp; |
| 7728 | #endif |
| 7729 | void *optval = NULL; |
| 7730 | void *p; |
| 7731 | size_t optsize = 0; |
| 7732 | int error = 0; |
| 7733 |
| 7734 | #if defined(__FreeBSD__) |
| 7735 | if ((sopt->sopt_level == SOL_SOCKET) && |
| 7736 | (sopt->sopt_name == SO_SETFIB)) { |
| 7737 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 7738 | if (inp == NULL) { |
| 7739 | SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS); |
| 7740 | return (EINVAL); |
| 7741 | } |
| 7742 | SCTP_INP_WLOCK(inp); |
| 7743 | inp->fibnum = so->so_fibnum; |
| 7744 | SCTP_INP_WUNLOCK(inp); |
| 7745 | return (0); |
| 7746 | } |
| 7747 | #endif |
| 7748 | if (sopt->sopt_level != IPPROTO_SCTP) { |
| 7749 | /* wrong proto level... send back up to IP */ |
| 7750 | #ifdef INET6 |
| 7751 | if (INP_CHECK_SOCKAF(so, AF_INET6)) |
| 7752 | error = ip6_ctloutput(so, sopt); |
| 7753 | #endif /* INET6 */ |
| 7754 | #if defined(INET) && defined(INET6) |
| 7755 | else |
| 7756 | #endif |
| 7757 | #ifdef INET |
| 7758 | error = ip_ctloutput(so, sopt); |
| 7759 | #endif |
| 7760 | return (error); |
| 7761 | } |
| 7762 | optsize = sopt->sopt_valsize; |
| 7763 | if (optsize > SCTP_SOCKET_OPTION_LIMIT) { |
| 7764 | SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS); |
| 7765 | return (ENOBUFS); |
| 7766 | } |
| 7767 | if (optsize) { |
| 7768 | SCTP_MALLOC(optval, void *, optsize, SCTP_M_SOCKOPT); |
| 7769 | if (optval == NULL) { |
| 7770 | SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS); |
| 7771 | return (ENOBUFS); |
| 7772 | } |
| 7773 | error = sooptcopyin(sopt, optval, optsize, optsize); |
| 7774 | if (error) { |
| 7775 | SCTP_FREE(optval, SCTP_M_SOCKOPT); |
| 7776 | goto out; |
| 7777 | } |
| 7778 | } |
| 7779 | #if defined(__FreeBSD__) || defined(_WIN32) |
| 7780 | p = (void *)sopt->sopt_td; |
| 7781 | #else |
| 7782 | p = (void *)sopt->sopt_p; |
| 7783 | #endif |
| 7784 | if (sopt->sopt_dir == SOPT_SET) { |
| 7785 | #if defined(__FreeBSD__) |
| 7786 | NET_EPOCH_ENTER(et); |
| 7787 | #endif |
| 7788 | error = sctp_setopt(so, sopt->sopt_name, optval, optsize, p); |
| 7789 | #if defined(__FreeBSD__) |
| 7790 | NET_EPOCH_EXIT(et); |
| 7791 | #endif |
| 7792 | } else if (sopt->sopt_dir == SOPT_GET) { |
| 7793 | error = sctp_getopt(so, sopt->sopt_name, optval, &optsize, p); |
| 7794 | } else { |
| 7795 | SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7796 | error = EINVAL; |
| 7797 | } |
| 7798 | if ((error == 0) && (optval != NULL)) { |
| 7799 | error = sooptcopyout(sopt, optval, optsize); |
| 7800 | SCTP_FREE(optval, SCTP_M_SOCKOPT); |
| 7801 | } else if (optval != NULL) { |
| 7802 | SCTP_FREE(optval, SCTP_M_SOCKOPT); |
| 7803 | } |
| 7804 | out: |
| 7805 | return (error); |
| 7806 | } |
| 7807 | #endif |
| 7808 |
| 7809 | #ifdef INET |
| 7810 | #if defined(__Userspace__) |
| 7811 | int |
| 7812 | sctp_connect(struct socket *so, struct sockaddr *addr) |
| 7813 | { |
| 7814 | void *p = NULL; |
| 7815 | #elif defined(__FreeBSD__) |
| 7816 | static int |
| 7817 | sctp_connect(struct socket *so, struct sockaddr *addr, struct thread *p) |
| 7818 | { |
| 7819 | #elif defined(__APPLE__) |
| 7820 | static int |
| 7821 | sctp_connect(struct socket *so, struct sockaddr *addr, struct proc *p) |
| 7822 | { |
| 7823 | #elif defined(_WIN32) |
| 7824 | static int |
| 7825 | sctp_connect(struct socket *so, struct sockaddr *addr, PKTHREAD p) |
| 7826 | { |
| 7827 | #else |
| 7828 | static int |
| 7829 | sctp_connect(struct socket *so, struct mbuf *nam, struct proc *p) |
| 7830 | { |
| 7831 | struct sockaddr *addr = mtod(nam, struct sockaddr *); |
| 7832 |
| 7833 | #endif |
| 7834 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 7835 | struct epoch_tracker et; |
| 7836 | #endif |
| 7837 | #ifdef SCTP_MVRF |
| 7838 | int i, fnd = 0; |
| 7839 | #endif |
| 7840 | int error = 0; |
| 7841 | int create_lock_on = 0; |
| 7842 | uint32_t vrf_id; |
| 7843 | struct sctp_inpcb *inp; |
| 7844 | struct sctp_tcb *stcb = NULL; |
| 7845 |
| 7846 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 7847 | if (inp == NULL) { |
| 7848 | /* I made the same as TCP since we are not setup? */ |
| 7849 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7850 | return (ECONNRESET); |
| 7851 | } |
| 7852 | if (addr == NULL) { |
| 7853 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7854 | return EINVAL; |
| 7855 | } |
| 7856 |
| 7857 | #if defined(__Userspace__) |
| 7858 | /* TODO __Userspace__ falls into this code for IPv6 stuff at the moment... */ |
| 7859 | #endif |
| 7860 | #if !defined(_WIN32) && !defined(__linux__) && !defined(__EMSCRIPTEN__) |
| 7861 | switch (addr->sa_family) { |
| 7862 | #ifdef INET6 |
| 7863 | case AF_INET6: |
| 7864 | { |
| 7865 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 7866 | struct sockaddr_in6 *sin6; |
| 7867 |
| 7868 | #endif |
| 7869 | if (addr->sa_len != sizeof(struct sockaddr_in6)) { |
| 7870 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7871 | return (EINVAL); |
| 7872 | } |
| 7873 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 7874 | sin6 = (struct sockaddr_in6 *)addr; |
| 7875 | if (p != NULL && (error = prison_remote_ip6(p->td_ucred, &sin6->sin6_addr)) != 0) { |
| 7876 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 7877 | return (error); |
| 7878 | } |
| 7879 | #endif |
| 7880 | break; |
| 7881 | } |
| 7882 | #endif |
| 7883 | #ifdef INET |
| 7884 | case AF_INET: |
| 7885 | { |
| 7886 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 7887 | struct sockaddr_in *sin; |
| 7888 |
| 7889 | #endif |
| 7890 | #if !defined(_WIN32) |
| 7891 | if (addr->sa_len != sizeof(struct sockaddr_in)) { |
| 7892 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7893 | return (EINVAL); |
| 7894 | } |
| 7895 | #endif |
| 7896 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 7897 | sin = (struct sockaddr_in *)addr; |
| 7898 | if (p != NULL && (error = prison_remote_ip4(p->td_ucred, &sin->sin_addr)) != 0) { |
| 7899 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 7900 | return (error); |
| 7901 | } |
| 7902 | #endif |
| 7903 | break; |
| 7904 | } |
| 7905 | #endif |
| 7906 | default: |
| 7907 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); |
| 7908 | return (EAFNOSUPPORT); |
| 7909 | } |
| 7910 | #endif |
| 7911 | SCTP_INP_INCR_REF(inp); |
| 7912 | SCTP_ASOC_CREATE_LOCK(inp); |
| 7913 | create_lock_on = 1; |
| 7914 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 7915 | NET_EPOCH_ENTER(et); |
| 7916 | #endif |
| 7917 |
| 7918 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || |
| 7919 | (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { |
| 7920 | /* Should I really unlock ? */ |
| 7921 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT); |
| 7922 | error = EFAULT; |
| 7923 | goto out_now; |
| 7924 | } |
| 7925 | #ifdef INET6 |
| 7926 | if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && |
| 7927 | (addr->sa_family == AF_INET6)) { |
| 7928 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7929 | error = EINVAL; |
| 7930 | goto out_now; |
| 7931 | } |
| 7932 | #endif |
| 7933 | #if defined(__Userspace__) |
| 7934 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) && |
| 7935 | (addr->sa_family != AF_CONN)) { |
| 7936 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7937 | error = EINVAL; |
| 7938 | goto out_now; |
| 7939 | } |
| 7940 | #endif |
| 7941 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == |
| 7942 | SCTP_PCB_FLAGS_UNBOUND) { |
| 7943 | /* Bind a ephemeral port */ |
| 7944 | error = sctp_inpcb_bind(so, NULL, NULL, p); |
| 7945 | if (error) { |
| 7946 | goto out_now; |
| 7947 | } |
| 7948 | } |
| 7949 | /* Now do we connect? */ |
| 7950 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) && |
| 7951 | (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) { |
| 7952 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7953 | error = EINVAL; |
| 7954 | goto out_now; |
| 7955 | } |
| 7956 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && |
| 7957 | (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { |
| 7958 | /* We are already connected AND the TCP model */ |
| 7959 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); |
| 7960 | error = EADDRINUSE; |
| 7961 | goto out_now; |
| 7962 | } |
| 7963 | if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { |
| 7964 | SCTP_INP_RLOCK(inp); |
| 7965 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 7966 | SCTP_INP_RUNLOCK(inp); |
| 7967 | } else { |
| 7968 | /* We increment here since sctp_findassociation_ep_addr() will |
| 7969 | * do a decrement if it finds the stcb as long as the locked |
| 7970 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 7971 | */ |
| 7972 | SCTP_INP_INCR_REF(inp); |
| 7973 | stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL); |
| 7974 | if (stcb == NULL) { |
| 7975 | SCTP_INP_DECR_REF(inp); |
| 7976 | } else { |
| 7977 | SCTP_TCB_UNLOCK(stcb); |
| 7978 | } |
| 7979 | } |
| 7980 | if (stcb != NULL) { |
| 7981 | /* Already have or am bring up an association */ |
| 7982 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 7983 | error = EALREADY; |
| 7984 | goto out_now; |
| 7985 | } |
| 7986 |
| 7987 | vrf_id = inp->def_vrf_id; |
| 7988 | #ifdef SCTP_MVRF |
| 7989 | for (i = 0; i < inp->num_vrfs; i++) { |
| 7990 | if (vrf_id == inp->m_vrf_ids[i]) { |
| 7991 | fnd = 1; |
| 7992 | break; |
| 7993 | } |
| 7994 | } |
| 7995 | if (!fnd) { |
| 7996 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 7997 | error = EINVAL; |
| 7998 | goto out_now; |
| 7999 | } |
| 8000 | #endif |
| 8001 | /* We are GOOD to go */ |
| 8002 | stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id, |
| 8003 | inp->sctp_ep.pre_open_stream_count, |
| 8004 | inp->sctp_ep.port, p, |
| 8005 | SCTP_INITIALIZE_AUTH_PARAMS); |
| 8006 | if (stcb == NULL) { |
| 8007 | /* Gak! no memory */ |
| 8008 | goto out_now; |
| 8009 | } |
| 8010 | SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT); |
| 8011 | (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); |
| 8012 |
| 8013 | sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); |
| 8014 | SCTP_TCB_UNLOCK(stcb); |
| 8015 | out_now: |
| 8016 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 8017 | NET_EPOCH_EXIT(et); |
| 8018 | #endif |
| 8019 | if (create_lock_on) { |
| 8020 | SCTP_ASOC_CREATE_UNLOCK(inp); |
| 8021 | } |
| 8022 | SCTP_INP_DECR_REF(inp); |
| 8023 | return (error); |
| 8024 | } |
| 8025 | #endif |
| 8026 |
| 8027 | #if defined(__Userspace__) |
| 8028 | int |
| 8029 | sctpconn_connect(struct socket *so, struct sockaddr *addr) |
| 8030 | { |
| 8031 | #ifdef SCTP_MVRF |
| 8032 | int i, fnd = 0; |
| 8033 | #endif |
| 8034 | void *p = NULL; |
| 8035 | int error = 0; |
| 8036 | int create_lock_on = 0; |
| 8037 | uint32_t vrf_id; |
| 8038 | struct sctp_inpcb *inp; |
| 8039 | struct sctp_tcb *stcb = NULL; |
| 8040 |
| 8041 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 8042 | if (inp == NULL) { |
| 8043 | /* I made the same as TCP since we are not setup? */ |
| 8044 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8045 | return (ECONNRESET); |
| 8046 | } |
| 8047 | if (addr == NULL) { |
| 8048 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8049 | return EINVAL; |
| 8050 | } |
| 8051 | switch (addr->sa_family) { |
| 8052 | #ifdef INET |
| 8053 | case AF_INET: |
| 8054 | #ifdef HAVE_SA_LEN |
| 8055 | if (addr->sa_len != sizeof(struct sockaddr_in)) { |
| 8056 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8057 | return (EINVAL); |
| 8058 | } |
| 8059 | #endif |
| 8060 | break; |
| 8061 | #endif |
| 8062 | #ifdef INET6 |
| 8063 | case AF_INET6: |
| 8064 | #ifdef HAVE_SA_LEN |
| 8065 | if (addr->sa_len != sizeof(struct sockaddr_in6)) { |
| 8066 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8067 | return (EINVAL); |
| 8068 | } |
| 8069 | #endif |
| 8070 | break; |
| 8071 | #endif |
| 8072 | case AF_CONN: |
| 8073 | #ifdef HAVE_SA_LEN |
| 8074 | if (addr->sa_len != sizeof(struct sockaddr_conn)) { |
| 8075 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8076 | return (EINVAL); |
| 8077 | } |
| 8078 | #endif |
| 8079 | break; |
| 8080 | default: |
| 8081 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); |
| 8082 | return (EAFNOSUPPORT); |
| 8083 | } |
| 8084 | SCTP_INP_INCR_REF(inp); |
| 8085 | SCTP_ASOC_CREATE_LOCK(inp); |
| 8086 | create_lock_on = 1; |
| 8087 |
| 8088 |
| 8089 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) || |
| 8090 | (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) { |
| 8091 | /* Should I really unlock ? */ |
| 8092 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EFAULT); |
| 8093 | error = EFAULT; |
| 8094 | goto out_now; |
| 8095 | } |
| 8096 | #ifdef INET6 |
| 8097 | if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && |
| 8098 | (addr->sa_family == AF_INET6)) { |
| 8099 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8100 | error = EINVAL; |
| 8101 | goto out_now; |
| 8102 | } |
| 8103 | #endif |
| 8104 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == SCTP_PCB_FLAGS_UNBOUND) { |
| 8105 | /* Bind a ephemeral port */ |
| 8106 | error = sctp_inpcb_bind(so, NULL, NULL, p); |
| 8107 | if (error) { |
| 8108 | goto out_now; |
| 8109 | } |
| 8110 | } |
| 8111 | /* Now do we connect? */ |
| 8112 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) && |
| 8113 | (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE))) { |
| 8114 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8115 | error = EINVAL; |
| 8116 | goto out_now; |
| 8117 | } |
| 8118 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && |
| 8119 | (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { |
| 8120 | /* We are already connected AND the TCP model */ |
| 8121 | SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_USRREQ, EADDRINUSE); |
| 8122 | error = EADDRINUSE; |
| 8123 | goto out_now; |
| 8124 | } |
| 8125 | if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { |
| 8126 | SCTP_INP_RLOCK(inp); |
| 8127 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 8128 | SCTP_INP_RUNLOCK(inp); |
| 8129 | } else { |
| 8130 | /* We increment here since sctp_findassociation_ep_addr() will |
| 8131 | * do a decrement if it finds the stcb as long as the locked |
| 8132 | * tcb (last argument) is NOT a TCB.. aka NULL. |
| 8133 | */ |
| 8134 | SCTP_INP_INCR_REF(inp); |
| 8135 | stcb = sctp_findassociation_ep_addr(&inp, addr, NULL, NULL, NULL); |
| 8136 | if (stcb == NULL) { |
| 8137 | SCTP_INP_DECR_REF(inp); |
| 8138 | } else { |
| 8139 | SCTP_TCB_UNLOCK(stcb); |
| 8140 | } |
| 8141 | } |
| 8142 | if (stcb != NULL) { |
| 8143 | /* Already have or am bring up an association */ |
| 8144 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EALREADY); |
| 8145 | error = EALREADY; |
| 8146 | goto out_now; |
| 8147 | } |
| 8148 |
| 8149 | vrf_id = inp->def_vrf_id; |
| 8150 | #ifdef SCTP_MVRF |
| 8151 | for (i = 0; i < inp->num_vrfs; i++) { |
| 8152 | if (vrf_id == inp->m_vrf_ids[i]) { |
| 8153 | fnd = 1; |
| 8154 | break; |
| 8155 | } |
| 8156 | } |
| 8157 | if (!fnd) { |
| 8158 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8159 | error = EINVAL; |
| 8160 | goto out_now; |
| 8161 | } |
| 8162 | #endif |
| 8163 | /* We are GOOD to go */ |
| 8164 | stcb = sctp_aloc_assoc_connected(inp, addr, &error, 0, 0, vrf_id, |
| 8165 | inp->sctp_ep.pre_open_stream_count, |
| 8166 | inp->sctp_ep.port, p, |
| 8167 | SCTP_INITIALIZE_AUTH_PARAMS); |
| 8168 | if (stcb == NULL) { |
| 8169 | /* Gak! no memory */ |
| 8170 | goto out_now; |
| 8171 | } |
| 8172 | SCTP_SET_STATE(stcb, SCTP_STATE_COOKIE_WAIT); |
| 8173 | (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); |
| 8174 |
| 8175 | sctp_send_initiate(inp, stcb, SCTP_SO_LOCKED); |
| 8176 | SCTP_TCB_UNLOCK(stcb); |
| 8177 | out_now: |
| 8178 | if (create_lock_on) { |
| 8179 | SCTP_ASOC_CREATE_UNLOCK(inp); |
| 8180 | } |
| 8181 |
| 8182 | SCTP_INP_DECR_REF(inp); |
| 8183 | return (error); |
| 8184 | } |
| 8185 | #endif |
| 8186 | int |
| 8187 | #if defined(__Userspace__) |
| 8188 | sctp_listen(struct socket *so, int backlog, struct proc *p) |
| 8189 | #elif defined(__FreeBSD__) |
| 8190 | sctp_listen(struct socket *so, int backlog, struct thread *p) |
| 8191 | #elif defined(_WIN32) |
| 8192 | sctp_listen(struct socket *so, int backlog, PKTHREAD p) |
| 8193 | #else |
| 8194 | sctp_listen(struct socket *so, struct proc *p) |
| 8195 | #endif |
| 8196 | { |
| 8197 | /* |
| 8198 | * Note this module depends on the protocol processing being called |
| 8199 | * AFTER any socket level flags and backlog are applied to the |
| 8200 | * socket. The traditional way that the socket flags are applied is |
| 8201 | * AFTER protocol processing. We have made a change to the |
| 8202 | * sys/kern/uipc_socket.c module to reverse this but this MUST be in |
| 8203 | * place if the socket API for SCTP is to work properly. |
| 8204 | */ |
| 8205 |
| 8206 | int error = 0; |
| 8207 | struct sctp_inpcb *inp; |
| 8208 |
| 8209 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 8210 | if (inp == NULL) { |
| 8211 | /* I made the same as TCP since we are not setup? */ |
| 8212 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8213 | return (ECONNRESET); |
| 8214 | } |
| 8215 | if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) { |
| 8216 | /* See if we have a listener */ |
| 8217 | struct sctp_inpcb *tinp; |
| 8218 | union sctp_sockstore store; |
| 8219 |
| 8220 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { |
| 8221 | /* not bound all */ |
| 8222 | struct sctp_laddr *laddr; |
| 8223 |
| 8224 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
| 8225 | memcpy(&store, &laddr->ifa->address, sizeof(store)); |
| 8226 | switch (store.sa.sa_family) { |
| 8227 | #ifdef INET |
| 8228 | case AF_INET: |
| 8229 | store.sin.sin_port = inp->sctp_lport; |
| 8230 | break; |
| 8231 | #endif |
| 8232 | #ifdef INET6 |
| 8233 | case AF_INET6: |
| 8234 | store.sin6.sin6_port = inp->sctp_lport; |
| 8235 | break; |
| 8236 | #endif |
| 8237 | #if defined(__Userspace__) |
| 8238 | case AF_CONN: |
| 8239 | store.sconn.sconn_port = inp->sctp_lport; |
| 8240 | break; |
| 8241 | #endif |
| 8242 | default: |
| 8243 | break; |
| 8244 | } |
| 8245 | tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id); |
| 8246 | if (tinp && (tinp != inp) && |
| 8247 | ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) && |
| 8248 | ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && |
| 8249 | (SCTP_IS_LISTENING(tinp))) { |
| 8250 | /* we have a listener already and its not this inp. */ |
| 8251 | SCTP_INP_DECR_REF(tinp); |
| 8252 | return (EADDRINUSE); |
| 8253 | } else if (tinp) { |
| 8254 | SCTP_INP_DECR_REF(tinp); |
| 8255 | } |
| 8256 | } |
| 8257 | } else { |
| 8258 | /* Setup a local addr bound all */ |
| 8259 | memset(&store, 0, sizeof(store)); |
| 8260 | #ifdef INET6 |
| 8261 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { |
| 8262 | store.sa.sa_family = AF_INET6; |
| 8263 | #ifdef HAVE_SA_LEN |
| 8264 | store.sa.sa_len = sizeof(struct sockaddr_in6); |
| 8265 | #endif |
| 8266 | } |
| 8267 | #endif |
| 8268 | #if defined(__Userspace__) |
| 8269 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) { |
| 8270 | store.sa.sa_family = AF_CONN; |
| 8271 | #ifdef HAVE_SA_LEN |
| 8272 | store.sa.sa_len = sizeof(struct sockaddr_conn); |
| 8273 | #endif |
| 8274 | } |
| 8275 | #endif |
| 8276 | #ifdef INET |
| 8277 | #if defined(__Userspace__) |
| 8278 | if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && |
| 8279 | ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) == 0)) { |
| 8280 | #else |
| 8281 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { |
| 8282 | #endif |
| 8283 | store.sa.sa_family = AF_INET; |
| 8284 | #ifdef HAVE_SA_LEN |
| 8285 | store.sa.sa_len = sizeof(struct sockaddr_in); |
| 8286 | #endif |
| 8287 | } |
| 8288 | #endif |
| 8289 | switch (store.sa.sa_family) { |
| 8290 | #ifdef INET |
| 8291 | case AF_INET: |
| 8292 | store.sin.sin_port = inp->sctp_lport; |
| 8293 | break; |
| 8294 | #endif |
| 8295 | #ifdef INET6 |
| 8296 | case AF_INET6: |
| 8297 | store.sin6.sin6_port = inp->sctp_lport; |
| 8298 | break; |
| 8299 | #endif |
| 8300 | #if defined(__Userspace__) |
| 8301 | case AF_CONN: |
| 8302 | store.sconn.sconn_port = inp->sctp_lport; |
| 8303 | break; |
| 8304 | #endif |
| 8305 | default: |
| 8306 | break; |
| 8307 | } |
| 8308 | tinp = sctp_pcb_findep(&store.sa, 0, 0, inp->def_vrf_id); |
| 8309 | if (tinp && (tinp != inp) && |
| 8310 | ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) && |
| 8311 | ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && |
| 8312 | (SCTP_IS_LISTENING(tinp))) { |
| 8313 | /* we have a listener already and its not this inp. */ |
| 8314 | SCTP_INP_DECR_REF(tinp); |
| 8315 | return (EADDRINUSE); |
| 8316 | } else if (tinp) { |
| 8317 | SCTP_INP_DECR_REF(tinp); |
| 8318 | } |
| 8319 | } |
| 8320 | } |
| 8321 | SCTP_INP_INFO_WLOCK(); |
| 8322 | SCTP_INP_WLOCK(inp); |
| 8323 | #ifdef SCTP_LOCK_LOGGING |
| 8324 | if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) { |
| 8325 | sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK); |
| 8326 | } |
| 8327 | #endif |
| 8328 | if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) && |
| 8329 | (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { |
| 8330 | /* The unlucky case |
| 8331 | * - We are in the tcp pool with this guy. |
| 8332 | * - Someone else is in the main inp slot. |
| 8333 | * - We must move this guy (the listener) to the main slot |
| 8334 | * - We must then move the guy that was listener to the TCP Pool. |
| 8335 | */ |
| 8336 | if (sctp_swap_inpcb_for_listen(inp)) { |
| 8337 | error = EADDRINUSE; |
| 8338 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 8339 | goto out; |
| 8340 | } |
| 8341 | } |
| 8342 | #if defined(__FreeBSD__) || defined(__Userspace__) |
| 8343 | SOCK_LOCK(so); |
| 8344 | error = solisten_proto_check(so); |
| 8345 | if (error) { |
| 8346 | SOCK_UNLOCK(so); |
| 8347 | goto out; |
| 8348 | } |
| 8349 | #endif |
| 8350 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && |
| 8351 | (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED)) { |
| 8352 | SOCK_UNLOCK(so); |
| 8353 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 8354 | solisten_proto_abort(so); |
| 8355 | #endif |
| 8356 | error = EADDRINUSE; |
| 8357 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error); |
| 8358 | goto out; |
| 8359 | } |
| 8360 | if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) { |
| 8361 | if ((error = sctp_inpcb_bind_locked(inp, NULL, NULL, p))) { |
| 8362 | SOCK_UNLOCK(so); |
| 8363 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 8364 | solisten_proto_abort(so); |
| 8365 | #endif |
| 8366 | /* bind error, probably perm */ |
| 8367 | goto out; |
| 8368 | } |
| 8369 | } |
| 8370 | #if defined(__FreeBSD__) && !defined(__Userspace__) |
| 8371 | if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) == 0) { |
| 8372 | solisten_proto(so, backlog); |
| 8373 | SOCK_UNLOCK(so); |
| 8374 | inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING; |
| 8375 | } else { |
| 8376 | solisten_proto_abort(so); |
| 8377 | SOCK_UNLOCK(so); |
| 8378 | if (backlog > 0) { |
| 8379 | inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING; |
| 8380 | } else { |
| 8381 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING; |
| 8382 | } |
| 8383 | } |
| 8384 | #elif defined(_WIN32) || defined(__Userspace__) |
| 8385 | solisten_proto(so, backlog); |
| 8386 | #endif |
| 8387 | #if !(defined(__FreeBSD__) && !defined(__Userspace__)) |
| 8388 | if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { |
| 8389 | /* remove the ACCEPTCONN flag for one-to-many sockets */ |
| 8390 | #if defined(__Userspace__) |
| 8391 | so->so_options &= ~SCTP_SO_ACCEPTCONN; |
| 8392 | #else |
| 8393 | so->so_options &= ~SO_ACCEPTCONN; |
| 8394 | #endif |
| 8395 | } |
| 8396 | SOCK_UNLOCK(so); |
| 8397 | if (backlog > 0) { |
| 8398 | inp->sctp_flags |= SCTP_PCB_FLAGS_ACCEPTING; |
| 8399 | } else { |
| 8400 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_ACCEPTING; |
| 8401 | } |
| 8402 | #endif |
| 8403 | out: |
| 8404 | SCTP_INP_WUNLOCK(inp); |
| 8405 | SCTP_INP_INFO_WUNLOCK(); |
| 8406 | return (error); |
| 8407 | } |
| 8408 |
| 8409 | static int sctp_defered_wakeup_cnt = 0; |
| 8410 |
| 8411 | int |
| 8412 | sctp_accept(struct socket *so, struct sockaddr **addr) |
| 8413 | { |
| 8414 | struct sctp_tcb *stcb; |
| 8415 | struct sctp_inpcb *inp; |
| 8416 | union sctp_sockstore store; |
| 8417 | #ifdef INET6 |
| 8418 | #if defined(SCTP_KAME) && defined(SCTP_EMBEDDED_V6_SCOPE) |
| 8419 | int error; |
| 8420 | #endif |
| 8421 | #endif |
| 8422 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 8423 |
| 8424 | if (inp == NULL) { |
| 8425 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8426 | return (ECONNRESET); |
| 8427 | } |
| 8428 | SCTP_INP_WLOCK(inp); |
| 8429 | if (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) { |
| 8430 | SCTP_INP_WUNLOCK(inp); |
| 8431 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EOPNOTSUPP); |
| 8432 | return (EOPNOTSUPP); |
| 8433 | } |
| 8434 | if (so->so_state & SS_ISDISCONNECTED) { |
| 8435 | SCTP_INP_WUNLOCK(inp); |
| 8436 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ECONNABORTED); |
| 8437 | return (ECONNABORTED); |
| 8438 | } |
| 8439 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 8440 | if (stcb == NULL) { |
| 8441 | SCTP_INP_WUNLOCK(inp); |
| 8442 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8443 | return (ECONNRESET); |
| 8444 | } |
| 8445 | SCTP_TCB_LOCK(stcb); |
| 8446 | store = stcb->asoc.primary_destination->ro._l_addr; |
| 8447 | SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_IN_ACCEPT_QUEUE); |
| 8448 | /* Wake any delayed sleep action */ |
| 8449 | if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { |
| 8450 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_DONT_WAKE; |
| 8451 | if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT) { |
| 8452 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT; |
| 8453 | SOCKBUF_LOCK(&inp->sctp_socket->so_snd); |
| 8454 | if (sowriteable(inp->sctp_socket)) { |
| 8455 | #if defined(__Userspace__) |
| 8456 | /*__Userspace__ calling sowwakup_locked because of SOCKBUF_LOCK above. */ |
| 8457 | #endif |
| 8458 | #if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__) |
| 8459 | sowwakeup_locked(inp->sctp_socket); |
| 8460 | #else |
| 8461 | #if defined(__APPLE__) |
| 8462 | /* socket is locked */ |
| 8463 | #endif |
| 8464 | sowwakeup(inp->sctp_socket); |
| 8465 | #endif |
| 8466 | } else { |
| 8467 | SOCKBUF_UNLOCK(&inp->sctp_socket->so_snd); |
| 8468 | } |
| 8469 | } |
| 8470 | if (inp->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT) { |
| 8471 | inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT; |
| 8472 | SOCKBUF_LOCK(&inp->sctp_socket->so_rcv); |
| 8473 | if (soreadable(inp->sctp_socket)) { |
| 8474 | sctp_defered_wakeup_cnt++; |
| 8475 | #if defined(__Userspace__) |
| 8476 | /*__Userspace__ calling sorwakup_locked because of SOCKBUF_LOCK above */ |
| 8477 | #endif |
| 8478 | #if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__) |
| 8479 | sorwakeup_locked(inp->sctp_socket); |
| 8480 | #else |
| 8481 | #if defined(__APPLE__) |
| 8482 | /* socket is locked */ |
| 8483 | #endif |
| 8484 | sorwakeup(inp->sctp_socket); |
| 8485 | #endif |
| 8486 | } else { |
| 8487 | SOCKBUF_UNLOCK(&inp->sctp_socket->so_rcv); |
| 8488 | } |
| 8489 | } |
| 8490 | } |
| 8491 | SCTP_INP_WUNLOCK(inp); |
| 8492 | if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { |
| 8493 | sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC, |
| 8494 | SCTP_FROM_SCTP_USRREQ + SCTP_LOC_19); |
| 8495 | } else { |
| 8496 | SCTP_TCB_UNLOCK(stcb); |
| 8497 | } |
| 8498 | switch (store.sa.sa_family) { |
| 8499 | #ifdef INET |
| 8500 | case AF_INET: |
| 8501 | { |
| 8502 | struct sockaddr_in *sin; |
| 8503 |
| 8504 | SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); |
| 8505 | if (sin == NULL) |
| 8506 | return (ENOMEM); |
| 8507 | sin->sin_family = AF_INET; |
| 8508 | #ifdef HAVE_SIN_LEN |
| 8509 | sin->sin_len = sizeof(*sin); |
| 8510 | #endif |
| 8511 | sin->sin_port = store.sin.sin_port; |
| 8512 | sin->sin_addr = store.sin.sin_addr; |
| 8513 | *addr = (struct sockaddr *)sin; |
| 8514 | break; |
| 8515 | } |
| 8516 | #endif |
| 8517 | #ifdef INET6 |
| 8518 | case AF_INET6: |
| 8519 | { |
| 8520 | struct sockaddr_in6 *sin6; |
| 8521 |
| 8522 | SCTP_MALLOC_SONAME(sin6, struct sockaddr_in6 *, sizeof *sin6); |
| 8523 | if (sin6 == NULL) |
| 8524 | return (ENOMEM); |
| 8525 | sin6->sin6_family = AF_INET6; |
| 8526 | #ifdef HAVE_SIN6_LEN |
| 8527 | sin6->sin6_len = sizeof(*sin6); |
| 8528 | #endif |
| 8529 | sin6->sin6_port = store.sin6.sin6_port; |
| 8530 | sin6->sin6_addr = store.sin6.sin6_addr; |
| 8531 | #if defined(SCTP_EMBEDDED_V6_SCOPE) |
| 8532 | #ifdef SCTP_KAME |
| 8533 | if ((error = sa6_recoverscope(sin6)) != 0) { |
| 8534 | SCTP_FREE_SONAME(sin6); |
| 8535 | return (error); |
| 8536 | } |
| 8537 | #else |
| 8538 | if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) |
| 8539 | /* |
| 8540 | * sin6->sin6_scope_id = |
| 8541 | * ntohs(sin6->sin6_addr.s6_addr16[1]); |
| 8542 | */ |
| 8543 | in6_recoverscope(sin6, &sin6->sin6_addr, NULL); /* skip ifp check */ |
| 8544 | else |
| 8545 | sin6->sin6_scope_id = 0; /* XXX */ |
| 8546 | #endif /* SCTP_KAME */ |
| 8547 | #endif /* SCTP_EMBEDDED_V6_SCOPE */ |
| 8548 | *addr = (struct sockaddr *)sin6; |
| 8549 | break; |
| 8550 | } |
| 8551 | #endif |
| 8552 | #if defined(__Userspace__) |
| 8553 | case AF_CONN: |
| 8554 | { |
| 8555 | struct sockaddr_conn *sconn; |
| 8556 |
| 8557 | SCTP_MALLOC_SONAME(sconn, struct sockaddr_conn *, sizeof(struct sockaddr_conn)); |
| 8558 | if (sconn == NULL) { |
| 8559 | return (ENOMEM); |
| 8560 | } |
| 8561 | sconn->sconn_family = AF_CONN; |
| 8562 | #ifdef HAVE_SCONN_LEN |
| 8563 | sconn->sconn_len = sizeof(struct sockaddr_conn); |
| 8564 | #endif |
| 8565 | sconn->sconn_port = store.sconn.sconn_port; |
| 8566 | sconn->sconn_addr = store.sconn.sconn_addr; |
| 8567 | *addr = (struct sockaddr *)sconn; |
| 8568 | break; |
| 8569 | } |
| 8570 | #endif |
| 8571 | default: |
| 8572 | /* TSNH */ |
| 8573 | break; |
| 8574 | } |
| 8575 | return (0); |
| 8576 | } |
| 8577 |
| 8578 | #ifdef INET |
| 8579 | int |
| 8580 | #if !defined(__Userspace__) |
| 8581 | sctp_ingetaddr(struct socket *so, struct sockaddr **addr) |
| 8582 | { |
| 8583 | struct sockaddr_in *sin; |
| 8584 | #else |
| 8585 | sctp_ingetaddr(struct socket *so, struct mbuf *nam) |
| 8586 | { |
| 8587 | struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *); |
| 8588 | #endif |
| 8589 | uint32_t vrf_id; |
| 8590 | struct sctp_inpcb *inp; |
| 8591 | struct sctp_ifa *sctp_ifa; |
| 8592 |
| 8593 | /* |
| 8594 | * Do the malloc first in case it blocks. |
| 8595 | */ |
| 8596 | #if !defined(__Userspace__) |
| 8597 | SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); |
| 8598 | if (sin == NULL) |
| 8599 | return (ENOMEM); |
| 8600 | #else |
| 8601 | SCTP_BUF_LEN(nam) = sizeof(*sin); |
| 8602 | memset(sin, 0, sizeof(*sin)); |
| 8603 | #endif |
| 8604 | sin->sin_family = AF_INET; |
| 8605 | #ifdef HAVE_SIN_LEN |
| 8606 | sin->sin_len = sizeof(*sin); |
| 8607 | #endif |
| 8608 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 8609 | if (!inp) { |
| 8610 | #if !defined(__Userspace__) |
| 8611 | SCTP_FREE_SONAME(sin); |
| 8612 | #endif |
| 8613 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8614 | return (ECONNRESET); |
| 8615 | } |
| 8616 | SCTP_INP_RLOCK(inp); |
| 8617 | sin->sin_port = inp->sctp_lport; |
| 8618 | if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { |
| 8619 | if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) { |
| 8620 | struct sctp_tcb *stcb; |
| 8621 | struct sockaddr_in *sin_a; |
| 8622 | struct sctp_nets *net; |
| 8623 | int fnd; |
| 8624 |
| 8625 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 8626 | if (stcb == NULL) { |
| 8627 | goto notConn; |
| 8628 | } |
| 8629 | fnd = 0; |
| 8630 | sin_a = NULL; |
| 8631 | SCTP_TCB_LOCK(stcb); |
| 8632 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 8633 | sin_a = (struct sockaddr_in *)&net->ro._l_addr; |
| 8634 | if (sin_a == NULL) |
| 8635 | /* this will make coverity happy */ |
| 8636 | continue; |
| 8637 |
| 8638 | if (sin_a->sin_family == AF_INET) { |
| 8639 | fnd = 1; |
| 8640 | break; |
| 8641 | } |
| 8642 | } |
| 8643 | if ((!fnd) || (sin_a == NULL)) { |
| 8644 | /* punt */ |
| 8645 | SCTP_TCB_UNLOCK(stcb); |
| 8646 | goto notConn; |
| 8647 | } |
| 8648 |
| 8649 | vrf_id = inp->def_vrf_id; |
| 8650 | sctp_ifa = sctp_source_address_selection(inp, |
| 8651 | stcb, |
| 8652 | (sctp_route_t *)&net->ro, |
| 8653 | net, 0, vrf_id); |
| 8654 | if (sctp_ifa) { |
| 8655 | sin->sin_addr = sctp_ifa->address.sin.sin_addr; |
| 8656 | sctp_free_ifa(sctp_ifa); |
| 8657 | } |
| 8658 | SCTP_TCB_UNLOCK(stcb); |
| 8659 | } else { |
| 8660 | /* For the bound all case you get back 0 */ |
| 8661 | notConn: |
| 8662 | sin->sin_addr.s_addr = 0; |
| 8663 | } |
| 8664 |
| 8665 | } else { |
| 8666 | /* Take the first IPv4 address in the list */ |
| 8667 | struct sctp_laddr *laddr; |
| 8668 | int fnd = 0; |
| 8669 |
| 8670 | LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { |
| 8671 | if (laddr->ifa->address.sa.sa_family == AF_INET) { |
| 8672 | struct sockaddr_in *sin_a; |
| 8673 |
| 8674 | sin_a = &laddr->ifa->address.sin; |
| 8675 | sin->sin_addr = sin_a->sin_addr; |
| 8676 | fnd = 1; |
| 8677 | break; |
| 8678 | } |
| 8679 | } |
| 8680 | if (!fnd) { |
| 8681 | #if !defined(__Userspace__) |
| 8682 | SCTP_FREE_SONAME(sin); |
| 8683 | #endif |
| 8684 | SCTP_INP_RUNLOCK(inp); |
| 8685 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 8686 | return (ENOENT); |
| 8687 | } |
| 8688 | } |
| 8689 | SCTP_INP_RUNLOCK(inp); |
| 8690 | #if !defined(__Userspace__) |
| 8691 | (*addr) = (struct sockaddr *)sin; |
| 8692 | #endif |
| 8693 | return (0); |
| 8694 | } |
| 8695 |
| 8696 | int |
| 8697 | #if !defined(__Userspace__) |
| 8698 | sctp_peeraddr(struct socket *so, struct sockaddr **addr) |
| 8699 | { |
| 8700 | struct sockaddr_in *sin; |
| 8701 | #else |
| 8702 | sctp_peeraddr(struct socket *so, struct mbuf *nam) |
| 8703 | { |
| 8704 | struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *); |
| 8705 |
| 8706 | #endif |
| 8707 | int fnd; |
| 8708 | struct sockaddr_in *sin_a; |
| 8709 | struct sctp_inpcb *inp; |
| 8710 | struct sctp_tcb *stcb; |
| 8711 | struct sctp_nets *net; |
| 8712 |
| 8713 | /* Do the malloc first in case it blocks. */ |
| 8714 | #if !defined(__Userspace__) |
| 8715 | SCTP_MALLOC_SONAME(sin, struct sockaddr_in *, sizeof *sin); |
| 8716 | if (sin == NULL) |
| 8717 | return (ENOMEM); |
| 8718 | #else |
| 8719 | SCTP_BUF_LEN(nam) = sizeof(*sin); |
| 8720 | memset(sin, 0, sizeof(*sin)); |
| 8721 | #endif |
| 8722 | sin->sin_family = AF_INET; |
| 8723 | #ifdef HAVE_SIN_LEN |
| 8724 | sin->sin_len = sizeof(*sin); |
| 8725 | #endif |
| 8726 |
| 8727 | inp = (struct sctp_inpcb *)so->so_pcb; |
| 8728 | if ((inp == NULL) || |
| 8729 | ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0)) { |
| 8730 | /* UDP type and listeners will drop out here */ |
| 8731 | #if !defined(__Userspace__) |
| 8732 | SCTP_FREE_SONAME(sin); |
| 8733 | #endif |
| 8734 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); |
| 8735 | return (ENOTCONN); |
| 8736 | } |
| 8737 | SCTP_INP_RLOCK(inp); |
| 8738 | stcb = LIST_FIRST(&inp->sctp_asoc_list); |
| 8739 | if (stcb) { |
| 8740 | SCTP_TCB_LOCK(stcb); |
| 8741 | } |
| 8742 | SCTP_INP_RUNLOCK(inp); |
| 8743 | if (stcb == NULL) { |
| 8744 | #if !defined(__Userspace__) |
| 8745 | SCTP_FREE_SONAME(sin); |
| 8746 | #endif |
| 8747 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8748 | return (ECONNRESET); |
| 8749 | } |
| 8750 | fnd = 0; |
| 8751 | TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { |
| 8752 | sin_a = (struct sockaddr_in *)&net->ro._l_addr; |
| 8753 | if (sin_a->sin_family == AF_INET) { |
| 8754 | fnd = 1; |
| 8755 | sin->sin_port = stcb->rport; |
| 8756 | sin->sin_addr = sin_a->sin_addr; |
| 8757 | break; |
| 8758 | } |
| 8759 | } |
| 8760 | SCTP_TCB_UNLOCK(stcb); |
| 8761 | if (!fnd) { |
| 8762 | /* No IPv4 address */ |
| 8763 | #if !defined(__Userspace__) |
| 8764 | SCTP_FREE_SONAME(sin); |
| 8765 | #endif |
| 8766 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); |
| 8767 | return (ENOENT); |
| 8768 | } |
| 8769 | #if !defined(__Userspace__) |
| 8770 | (*addr) = (struct sockaddr *)sin; |
| 8771 | #endif |
| 8772 | return (0); |
| 8773 | } |
| 8774 |
| 8775 | #if !defined(__Userspace__) |
| 8776 | struct pr_usrreqs sctp_usrreqs = { |
| 8777 | #if defined(__FreeBSD__) |
| 8778 | .pru_abort = sctp_abort, |
| 8779 | .pru_accept = sctp_accept, |
| 8780 | .pru_attach = sctp_attach, |
| 8781 | .pru_bind = sctp_bind, |
| 8782 | .pru_connect = sctp_connect, |
| 8783 | .pru_control = in_control, |
| 8784 | .pru_close = sctp_close, |
| 8785 | .pru_detach = sctp_close, |
| 8786 | .pru_sopoll = sopoll_generic, |
| 8787 | .pru_flush = sctp_flush, |
| 8788 | .pru_disconnect = sctp_disconnect, |
| 8789 | .pru_listen = sctp_listen, |
| 8790 | .pru_peeraddr = sctp_peeraddr, |
| 8791 | .pru_send = sctp_sendm, |
| 8792 | .pru_shutdown = sctp_shutdown, |
| 8793 | .pru_sockaddr = sctp_ingetaddr, |
| 8794 | .pru_sosend = sctp_sosend, |
| 8795 | .pru_soreceive = sctp_soreceive |
| 8796 | #elif defined(__APPLE__) |
| 8797 | .pru_abort = sctp_abort, |
| 8798 | .pru_accept = sctp_accept, |
| 8799 | .pru_attach = sctp_attach, |
| 8800 | .pru_bind = sctp_bind, |
| 8801 | .pru_connect = sctp_connect, |
| 8802 | .pru_connect2 = pru_connect2_notsupp, |
| 8803 | .pru_control = in_control, |
| 8804 | .pru_detach = sctp_detach, |
| 8805 | .pru_disconnect = sctp_disconnect, |
| 8806 | .pru_listen = sctp_listen, |
| 8807 | .pru_peeraddr = sctp_peeraddr, |
| 8808 | .pru_rcvd = NULL, |
| 8809 | .pru_rcvoob = pru_rcvoob_notsupp, |
| 8810 | .pru_send = sctp_sendm, |
| 8811 | .pru_sense = pru_sense_null, |
| 8812 | .pru_shutdown = sctp_shutdown, |
| 8813 | .pru_sockaddr = sctp_ingetaddr, |
| 8814 | .pru_sosend = sctp_sosend, |
| 8815 | .pru_soreceive = sctp_soreceive, |
| 8816 | .pru_sopoll = sopoll |
| 8817 | #elif defined(_WIN32) && !defined(__Userspace__) |
| 8818 | sctp_abort, |
| 8819 | sctp_accept, |
| 8820 | sctp_attach, |
| 8821 | sctp_bind, |
| 8822 | sctp_connect, |
| 8823 | pru_connect2_notsupp, |
| 8824 | NULL, |
| 8825 | NULL, |
| 8826 | sctp_disconnect, |
| 8827 | sctp_listen, |
| 8828 | sctp_peeraddr, |
| 8829 | NULL, |
| 8830 | pru_rcvoob_notsupp, |
| 8831 | NULL, |
| 8832 | pru_sense_null, |
| 8833 | sctp_shutdown, |
| 8834 | sctp_flush, |
| 8835 | sctp_ingetaddr, |
| 8836 | sctp_sosend, |
| 8837 | sctp_soreceive, |
| 8838 | sopoll_generic, |
| 8839 | NULL, |
| 8840 | sctp_close |
| 8841 | #endif |
| 8842 | }; |
| 8843 | #elif !defined(__Userspace__) |
| 8844 | int |
| 8845 | sctp_usrreq(so, req, m, nam, control) |
| 8846 | struct socket *so; |
| 8847 | int req; |
| 8848 | struct mbuf *m, *nam, *control; |
| 8849 | { |
| 8850 | struct proc *p = curproc; |
| 8851 | int error; |
| 8852 | int family; |
| 8853 | struct sctp_inpcb *inp = (struct sctp_inpcb *)so->so_pcb; |
| 8854 |
| 8855 | error = 0; |
| 8856 | family = so->so_proto->pr_domain->dom_family; |
| 8857 | if (req == PRU_CONTROL) { |
| 8858 | switch (family) { |
| 8859 | case PF_INET: |
| 8860 | error = in_control(so, (long)m, (caddr_t)nam, |
| 8861 | (struct ifnet *)control); |
| 8862 | break; |
| 8863 | #ifdef INET6 |
| 8864 | case PF_INET6: |
| 8865 | error = in6_control(so, (long)m, (caddr_t)nam, |
| 8866 | (struct ifnet *)control, p); |
| 8867 | break; |
| 8868 | #endif |
| 8869 | default: |
| 8870 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); |
| 8871 | error = EAFNOSUPPORT; |
| 8872 | } |
| 8873 | return (error); |
| 8874 | } |
| 8875 | switch (req) { |
| 8876 | case PRU_ATTACH: |
| 8877 | error = sctp_attach(so, family, p); |
| 8878 | break; |
| 8879 | case PRU_DETACH: |
| 8880 | error = sctp_detach(so); |
| 8881 | break; |
| 8882 | case PRU_BIND: |
| 8883 | if (nam == NULL) { |
| 8884 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8885 | return (EINVAL); |
| 8886 | } |
| 8887 | error = sctp_bind(so, nam, p); |
| 8888 | break; |
| 8889 | case PRU_LISTEN: |
| 8890 | error = sctp_listen(so, p); |
| 8891 | break; |
| 8892 | case PRU_CONNECT: |
| 8893 | if (nam == NULL) { |
| 8894 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8895 | return (EINVAL); |
| 8896 | } |
| 8897 | error = sctp_connect(so, nam, p); |
| 8898 | break; |
| 8899 | case PRU_DISCONNECT: |
| 8900 | error = sctp_disconnect(so); |
| 8901 | break; |
| 8902 | case PRU_ACCEPT: |
| 8903 | if (nam == NULL) { |
| 8904 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); |
| 8905 | return (EINVAL); |
| 8906 | } |
| 8907 | error = sctp_accept(so, nam); |
| 8908 | break; |
| 8909 | case PRU_SHUTDOWN: |
| 8910 | error = sctp_shutdown(so); |
| 8911 | break; |
| 8912 |
| 8913 | case PRU_RCVD: |
| 8914 | /* |
| 8915 | * For Open and Net BSD, this is real ugly. The mbuf *nam |
| 8916 | * that is passed (by soreceive()) is the int flags c ast as |
| 8917 | * a (mbuf *) yuck! |
| 8918 | */ |
| 8919 | break; |
| 8920 |
| 8921 | case PRU_SEND: |
| 8922 | /* Flags are ignored */ |
| 8923 | { |
| 8924 | struct sockaddr *addr; |
| 8925 |
| 8926 | if (nam == NULL) |
| 8927 | addr = NULL; |
| 8928 | else |
| 8929 | addr = mtod(nam, struct sockaddr *); |
| 8930 |
| 8931 | error = sctp_sendm(so, 0, m, addr, control, p); |
| 8932 | } |
| 8933 | break; |
| 8934 | case PRU_ABORT: |
| 8935 | error = sctp_abort(so); |
| 8936 | break; |
| 8937 |
| 8938 | case PRU_SENSE: |
| 8939 | error = 0; |
| 8940 | break; |
| 8941 | case PRU_RCVOOB: |
| 8942 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); |
| 8943 | error = EAFNOSUPPORT; |
| 8944 | break; |
| 8945 | case PRU_SENDOOB: |
| 8946 | SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT); |
| 8947 | error = EAFNOSUPPORT; |
| 8948 | break; |
| 8949 | case PRU_PEERADDR: |
| 8950 | error = sctp_peeraddr(so, nam); |
| 8951 | break; |
| 8952 | case PRU_SOCKADDR: |
| 8953 | error = sctp_ingetaddr(so, nam); |
| 8954 | break; |
| 8955 | case PRU_SLOWTIMO: |
| 8956 | error = 0; |
| 8957 | break; |
| 8958 | default: |
| 8959 | break; |
| 8960 | } |
| 8961 | return (error); |
| 8962 | } |
| 8963 |
| 8964 | #endif |
| 8965 | #endif |
| 8966 |
| 8967 | #if defined(__Userspace__) |
| 8968 | int |
| 8969 | register_recv_cb(struct socket *so, |
| 8970 | int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data, |
| 8971 | size_t datalen, struct sctp_rcvinfo, int flags, void *ulp_info)) |
| 8972 | { |
| 8973 | struct sctp_inpcb *inp; |
| 8974 |
| 8975 | inp = (struct sctp_inpcb *) so->so_pcb; |
| 8976 | if (inp == NULL) { |
| 8977 | return (0); |
| 8978 | } |
| 8979 | SCTP_INP_WLOCK(inp); |
| 8980 | inp->recv_callback = receive_cb; |
| 8981 | SCTP_INP_WUNLOCK(inp); |
| 8982 | return (1); |
| 8983 | } |
| 8984 |
| 8985 | int |
| 8986 | register_send_cb(struct socket *so, uint32_t sb_threshold, int (*send_cb)(struct socket *sock, uint32_t sb_free, void *ulp_info)) |
| 8987 | { |
| 8988 | struct sctp_inpcb *inp; |
| 8989 |
| 8990 | inp = (struct sctp_inpcb *) so->so_pcb; |
| 8991 | if (inp == NULL) { |
| 8992 | return (0); |
| 8993 | } |
| 8994 | SCTP_INP_WLOCK(inp); |
| 8995 | inp->send_callback = send_cb; |
| 8996 | inp->send_sb_threshold = sb_threshold; |
| 8997 | SCTP_INP_WUNLOCK(inp); |
| 8998 | /* FIXME change to current amount free. This will be the full buffer |
| 8999 | * the first time this is registered but it could be only a portion |
| 9000 | * of the send buffer if this is called a second time e.g. if the |
| 9001 | * threshold changes. |
| 9002 | */ |
| 9003 | return (1); |
| 9004 | } |
| 9005 |
| 9006 | int |
| 9007 | register_ulp_info (struct socket *so, void *ulp_info) |
| 9008 | { |
| 9009 | struct sctp_inpcb *inp; |
| 9010 |
| 9011 | inp = (struct sctp_inpcb *) so->so_pcb; |
| 9012 | if (inp == NULL) { |
| 9013 | return (0); |
| 9014 | } |
| 9015 | SCTP_INP_WLOCK(inp); |
| 9016 | inp->ulp_info = ulp_info; |
| 9017 | SCTP_INP_WUNLOCK(inp); |
| 9018 | return (1); |
| 9019 | } |
| 9020 |
| 9021 | int |
| 9022 | retrieve_ulp_info (struct socket *so, void **pulp_info) |
| 9023 | { |
| 9024 | struct sctp_inpcb *inp; |
| 9025 |
| 9026 | if (pulp_info == NULL) { |
| 9027 | return (0); |
| 9028 | } |
| 9029 |
| 9030 | inp = (struct sctp_inpcb *) so->so_pcb; |
| 9031 | if (inp == NULL) { |
| 9032 | return (0); |
| 9033 | } |
| 9034 | SCTP_INP_RLOCK(inp); |
| 9035 | *pulp_info = inp->ulp_info; |
| 9036 | SCTP_INP_RUNLOCK(inp); |
| 9037 | return (1); |
| 9038 | } |
| 9039 | #endif |
| 9040 |