Lines Matching +full:mixed +full:- +full:burst

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
1868 if ((scope->loopback_scope == 0) &&
1869 (ifa->ifn_p) && SCTP_IFN_IS_IFT_LOOP(ifa->ifn_p)) {
1875 switch (ifa->address.sa.sa_family) {
1878 if (scope->ipv4_addr_legal) {
1881 sin = &ifa->address.sin;
1882 if (sin->sin_addr.s_addr == 0) {
1886 if ((scope->ipv4_local_scope == 0) &&
1887 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
1898 if (scope->ipv6_addr_legal) {
1903 * IFA locks must now be applied HERE <->
1908 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1912 sin6 = &ifa->address.sin6;
1913 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1918 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
1921 if ((scope->site_scope == 0) &&
1922 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
1945 switch (ifa->address.sa.sa_family) {
1979 switch (ifa->address.sa.sa_family) {
1986 sin = &ifa->address.sin;
1988 paramh->param_type = htons(SCTP_IPV4_ADDRESS);
1989 paramh->param_length = htons(plen);
1990 ipv4p->addr = sin->sin_addr.s_addr;
2001 sin6 = &ifa->address.sin6;
2003 paramh->param_type = htons(SCTP_IPV6_ADDRESS);
2004 paramh->param_length = htons(plen);
2005 memcpy(ipv6p->addr, &sin6->sin6_addr,
2006 sizeof(ipv6p->addr));
2008 in6_clearscope((struct in6_addr *)ipv6p->addr);
2033 vrf_id = inp->def_vrf_id;
2040 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
2045 if (vrf->total_ifa_count > SCTP_COUNT_LIMIT) {
2050 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
2051 if ((scope->loopback_scope == 0) &&
2059 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
2061 if ((sctp_ifap->address.sa.sa_family == AF_INET) &&
2062 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2063 &sctp_ifap->address.sin.sin_addr) != 0)) {
2068 if ((sctp_ifap->address.sa.sa_family == AF_INET6) &&
2069 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2070 &sctp_ifap->address.sin6.sin6_addr) != 0)) {
2092 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
2094 if ((scope->loopback_scope == 0) &&
2102 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
2104 if ((sctp_ifap->address.sa.sa_family == AF_INET) &&
2105 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2106 &sctp_ifap->address.sin.sin_addr) != 0)) {
2111 if ((sctp_ifap->address.sa.sa_family == AF_INET6) &&
2112 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2113 &sctp_ifap->address.sin6.sin6_addr) != 0)) {
2156 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
2157 if (laddr->ifa == NULL) {
2160 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
2166 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
2173 if (sctp_is_address_in_scope(laddr->ifa,
2186 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
2187 if (laddr->ifa == NULL) {
2190 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
2193 if (sctp_is_address_in_scope(laddr->ifa,
2205 m_at = sctp_add_addr_to_mbuf(m_at, laddr->ifa, chunk_len);
2232 * -----------------------------------------
2234 * ----------------------------------------
2236 * -----------------------------------------
2237 * P | L | yes-v4 no-v6
2238 * -----------------------------------------
2239 * G | L | yes-v4 no-v6
2240 * -----------------------------------------
2242 * -----------------------------------------
2244 * -----------------------------------------
2246 * -----------------------------------------
2248 * -----------------------------------------
2250 * -----------------------------------------
2252 * -----------------------------------------
2255 if (ifa->address.sa.sa_family != fam) {
2256 /* forget mis-matched family */
2263 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ifa->address.sa);
2268 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2272 if (ifa->src_is_priv && !ifa->src_is_loop) {
2278 if (ifa->src_is_glob) {
2289 * straightforward and easier to validate :-)
2292 ifa->src_is_loop, ifa->src_is_priv, ifa->src_is_glob);
2296 if ((ifa->src_is_loop) && (dest_is_priv)) {
2300 if ((ifa->src_is_glob) && (dest_is_priv)) {
2304 if ((ifa->src_is_loop) && (dest_is_global)) {
2308 if ((ifa->src_is_priv) && (dest_is_global)) {
2332 * -----------------------------------------
2334 * -----------------------------------------
2336 * -----------------------------------------
2337 * P | L | yes-v4 no-v6
2338 * -----------------------------------------
2340 * -----------------------------------------
2342 * -----------------------------------------
2344 * -----------------------------------------
2345 * G | P | yes - May not work
2346 * -----------------------------------------
2348 * -----------------------------------------
2349 * P | G | yes - May not work
2350 * -----------------------------------------
2352 * -----------------------------------------
2355 if (ifa->address.sa.sa_family != fam) {
2358 ifa->address.sa.sa_family, fam);
2362 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, &ifa->address.sa);
2371 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2374 if (ifa->src_is_priv) {
2384 * straightforward and easier to validate :-)
2386 SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa->src_is_loop:%d dest_is_priv:%d\n",
2387 ifa->src_is_loop,
2389 if ((ifa->src_is_loop == 1) && (dest_is_priv)) {
2392 SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa->src_is_loop:%d dest_is_glob:%d\n",
2393 ifa->src_is_loop,
2395 if ((ifa->src_is_loop == 1) && (dest_is_global)) {
2409 /* There are no restrictions, no TCB :-) */
2412 LIST_FOREACH(laddr, &stcb->asoc.sctp_restricted_addrs, sctp_nxt_addr) {
2413 if (laddr->ifa == NULL) {
2418 if (laddr->ifa == ifa) {
2433 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
2434 if (laddr->ifa == NULL) {
2439 if ((laddr->ifa == ifa) && laddr->action == 0)
2477 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2479 if ((sctp_ifa->address.sa.sa_family == AF_INET) &&
2480 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2481 &sctp_ifa->address.sin.sin_addr) != 0)) {
2486 if ((sctp_ifa->address.sa.sa_family == AF_INET6) &&
2487 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2488 &sctp_ifa->address.sin6.sin6_addr) != 0)) {
2492 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
2501 atomic_add_int(&sifa->refcount, 1);
2512 starting_point = inp->next_addr_touse;
2514 if (inp->next_addr_touse == NULL) {
2515 inp->next_addr_touse = LIST_FIRST(&inp->sctp_addr_list);
2518 for (laddr = inp->next_addr_touse; laddr;
2520 if (laddr->ifa == NULL) {
2524 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
2528 sifa = sctp_is_ifa_addr_preferred(laddr->ifa, dest_is_loop,
2532 atomic_add_int(&sifa->refcount, 1);
2536 inp->next_addr_touse = NULL;
2540 inp->next_addr_touse = starting_point;
2543 if (inp->next_addr_touse == NULL) {
2544 inp->next_addr_touse = LIST_FIRST(&inp->sctp_addr_list);
2549 for (laddr = inp->next_addr_touse; laddr;
2551 if (laddr->ifa == NULL) {
2555 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
2559 sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop,
2563 atomic_add_int(&sifa->refcount, 1);
2567 inp->next_addr_touse = NULL;
2615 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2617 if ((sctp_ifa->address.sa.sa_family == AF_INET) &&
2618 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2619 &sctp_ifa->address.sin.sin_addr) != 0)) {
2624 if ((sctp_ifa->address.sa.sa_family == AF_INET6) &&
2625 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2626 &sctp_ifa->address.sin6.sin6_addr) != 0)) {
2630 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0))
2641 /* on the no-no list */
2644 atomic_add_int(&sifa->refcount, 1);
2649 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2651 if ((sctp_ifa->address.sa.sa_family == AF_INET) &&
2652 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2653 &sctp_ifa->address.sin.sin_addr) != 0)) {
2658 if ((sctp_ifa->address.sa.sa_family == AF_INET6) &&
2659 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2660 &sctp_ifa->address.sin6.sin6_addr) != 0)) {
2664 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0))
2675 /* on the no-no list */
2678 atomic_add_int(&sifa->refcount, 1);
2687 starting_point = stcb->asoc.last_used_address;
2689 if (stcb->asoc.last_used_address == NULL) {
2691 stcb->asoc.last_used_address = LIST_FIRST(&inp->sctp_addr_list);
2694 for (laddr = stcb->asoc.last_used_address; laddr;
2696 if (laddr->ifa == NULL) {
2700 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
2704 sifa = sctp_is_ifa_addr_preferred(laddr->ifa, dest_is_loop, dest_is_priv, fam);
2712 /* on the no-no list */
2715 stcb->asoc.last_used_address = laddr;
2716 atomic_add_int(&sifa->refcount, 1);
2720 stcb->asoc.last_used_address = NULL;
2724 stcb->asoc.last_used_address = starting_point;
2727 if (stcb->asoc.last_used_address == NULL) {
2729 stcb->asoc.last_used_address = LIST_FIRST(&inp->sctp_addr_list);
2732 for (laddr = stcb->asoc.last_used_address; laddr;
2734 if (laddr->ifa == NULL) {
2738 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
2742 sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop,
2751 /* on the no-no list */
2754 stcb->asoc.last_used_address = laddr;
2755 atomic_add_int(&sifa->refcount, 1);
2759 stcb->asoc.last_used_address = NULL;
2782 memcpy(&sin6, &ro->ro_dst, sizeof(struct sockaddr_in6));
2786 LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) {
2788 if ((ifa->address.sa.sa_family == AF_INET) &&
2789 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2790 &ifa->address.sin.sin_addr) != 0)) {
2795 if ((ifa->address.sa.sa_family == AF_INET6) &&
2796 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2797 &ifa->address.sin6.sin6_addr) != 0)) {
2801 if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
2811 sifa->src_is_loop && sifa->src_is_priv) {
2820 IN6_IS_ADDR_LINKLOCAL(&sifa->address.sin6.sin6_addr) &&
2823 * link-local <-> link-local must belong to the same
2826 memcpy(&lsa6, &sifa->address.sin6, sizeof(struct sockaddr_in6));
2835 * Check if the IPv6 address matches to next-hop. In the
2839 * next-hop. (by micchie)
2843 sctp_is_mobility_feature_on(stcb->sctp_ep, SCTP_MOBILITY_BASE)) {
2844 if (sctp_v6src_match_nexthop(&sifa->address.sin6, ro) == 0) {
2852 sctp_is_mobility_feature_on(stcb->sctp_ep, SCTP_MOBILITY_BASE)) {
2859 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2894 LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) {
2896 if ((ifa->address.sa.sa_family == AF_INET) &&
2897 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2898 &ifa->address.sin.sin_addr) != 0)) {
2903 if ((ifa->address.sa.sa_family == AF_INET6) &&
2905 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2906 &ifa->address.sin6.sin6_addr) != 0)) {
2910 if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
2920 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2961 /*-
2973 * abort :-<.
2989 ifn_index, sctp_ifn->ifn_name);
2992 cur_addr_num = net->indx_of_eligible_next_to_use;
3000 num_preferred, sctp_ifn->ifn_name);
3027 atomic_add_int(&sctp_ifa->refcount, 1);
3030 net->indx_of_eligible_next_to_use = cur_addr_num + 1;
3040 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3042 sctp_ifn->ifn_name);
3060 SCTPDBG(SCTP_DEBUG_OUTPUT2, "No preferred -- skipping to next\n");
3080 net->indx_of_eligible_next_to_use = cur_addr_num + 1;
3084 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa);
3086 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &net->ro._l_addr.sa);
3088 atomic_add_int(&sifa->refcount, 1);
3098 SCTPDBG(SCTP_DEBUG_OUTPUT2, "Jump to Plan D - no emit_ifn\n");
3101 LIST_FOREACH(sctp_ifa, &emit_ifn->ifalist, next_ifa) {
3104 if ((sctp_ifa->address.sa.sa_family == AF_INET) &&
3105 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
3106 &sctp_ifa->address.sin.sin_addr) != 0)) {
3112 if ((sctp_ifa->address.sa.sa_family == AF_INET6) &&
3113 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
3114 &sctp_ifa->address.sin6.sin6_addr) != 0)) {
3119 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
3131 if (sctp_is_address_in_scope(sifa, &stcb->asoc.scope, 0) == 0) {
3150 atomic_add_int(&sifa->refcount, 1);
3161 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3166 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3168 if ((sctp_ifa->address.sa.sa_family == AF_INET) &&
3169 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
3170 &sctp_ifa->address.sin.sin_addr) != 0)) {
3175 if ((sctp_ifa->address.sa.sa_family == AF_INET6) &&
3176 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
3177 &sctp_ifa->address.sin6.sin6_addr) != 0)) {
3181 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
3190 if (sctp_is_address_in_scope(sifa, &stcb->asoc.scope, 0) == 0) {
3212 if ((retried == 0) && (stcb->asoc.scope.ipv4_local_scope == 0)) {
3213 stcb->asoc.scope.ipv4_local_scope = 1;
3217 stcb->asoc.scope.ipv4_local_scope = 0;
3225 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3230 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3234 if ((sctp_ifa->address.sa.sa_family == AF_INET) &&
3235 (prison_check_ip4(inp->ip_inp.inp.inp_cred,
3236 &sctp_ifa->address.sin.sin_addr) != 0)) {
3241 if ((sctp_ifa->address.sa.sa_family == AF_INET6) &&
3242 (prison_check_ip6(inp->ip_inp.inp.inp_cred,
3243 &sctp_ifa->address.sin6.sin6_addr) != 0)) {
3247 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) &&
3261 &stcb->asoc.scope, 0) == 0) {
3278 if ((tmp_sifa->address.sin.sin_family == AF_INET) &&
3279 (IN4_ISPRIVATE_ADDRESS(&(tmp_sifa->address.sin.sin_addr)))) {
3285 atomic_add_int(&sifa->refcount, 1);
3303 struct sockaddr_in *to = (struct sockaddr_in *)&ro->ro_dst;
3306 struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&ro->ro_dst;
3311 * - Find the route if needed, cache if I can.
3312 * - Look at interface address in route, Is it in the bound list. If so we
3314 * - If not we must rotate amongst the addresses.
3323 * ------------------------------------------
3325 * -----------------------------------------
3327 * -----------------------------------------
3329 * -----------------------------------------
3331 * -----------------------------------------
3333 *------------------------------------------
3336 *------------------------------------------
3338 * -----------------------------------------
3340 * -----------------------------------------
3342 * -----------------------------------------
3344 * -----------------------------------------
3346 *------------------------------------------
3354 * one is best? And what about NAT's sending P->G may get you a NAT
3360 * - count the number of addresses on the interface.
3361 * - if it is one, no problem except case <c>.
3363 * - if there are more than one, then we need to worry about scope P
3364 * or G. We should prefer G -> G and P -> P if possible.
3365 * Then as a secondary fall back to mixed types G->P being a last
3367 * - The above all works for bound all, but bound specific we need to
3372 if (ro->ro_nh == NULL) {
3376 SCTP_RTALLOC(ro, vrf_id, inp->fibnum);
3378 if (ro->ro_nh == NULL) {
3381 fam = ro->ro_dst.sa_family;
3388 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3392 net->addr_is_local = 1;
3394 } else if ((IN4_ISPRIVATE_ADDRESS(&to->sin_addr))) {
3402 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr) ||
3413 net->addr_is_local = 1;
3415 } else if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3422 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)&ro->ro_dst);
3424 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3469 rem_len = tot_len - off;
3483 cmsg_data_len = (int)cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh));
3517 sndrcvinfo->sinfo_stream = sndinfo.snd_sid;
3518 sndrcvinfo->sinfo_flags = sndinfo.snd_flags;
3519 sndrcvinfo->sinfo_ppid = sndinfo.snd_ppid;
3520 sndrcvinfo->sinfo_context = sndinfo.snd_context;
3521 sndrcvinfo->sinfo_assoc_id = sndinfo.snd_assoc_id;
3529 sndrcvinfo->sinfo_timetolive = prinfo.pr_value;
3531 sndrcvinfo->sinfo_timetolive = 0;
3533 sndrcvinfo->sinfo_flags |= prinfo.pr_policy;
3540 sndrcvinfo->sinfo_keynumber_valid = 1;
3541 sndrcvinfo->sinfo_keynumber = authinfo.auth_keynumber;
3568 rem_len = tot_len - off;
3585 cmsg_data_len = (int)cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh));
3596 stcb->asoc.max_init_times = initmsg.sinit_max_attempts;
3598 stcb->asoc.pre_open_streams = initmsg.sinit_num_ostreams;
3600 stcb->asoc.max_inbound_streams = initmsg.sinit_max_instreams;
3602 stcb->asoc.initial_init_rto_max = initmsg.sinit_max_init_timeo;
3603 if (stcb->asoc.streamoutcnt < stcb->asoc.pre_open_streams) {
3612 stcb->asoc.streamoutcnt, stcb->asoc.pre_open_streams);
3616 (stcb->asoc.pre_open_streams * sizeof(struct sctp_stream_out)),
3620 SCTP_FREE(stcb->asoc.strmout, SCTP_M_STRMO);
3621 stcb->asoc.strmout = tmp_str;
3622 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt = stcb->asoc.pre_open_streams;
3624 stcb->asoc.pre_open_streams = stcb->asoc.streamoutcnt;
3626 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
3627 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
3628 stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], NULL);
3629 stcb->asoc.strmout[i].chunks_on_queues = 0;
3632 stcb->asoc.strmout[i].abandoned_sent[j] = 0;
3633 stcb->asoc.strmout[i].abandoned_unsent[j] = 0;
3636 stcb->asoc.strmout[i].abandoned_sent[0] = 0;
3637 stcb->asoc.strmout[i].abandoned_unsent[0] = 0;
3639 stcb->asoc.strmout[i].next_mid_ordered = 0;
3640 stcb->asoc.strmout[i].next_mid_unordered = 0;
3641 stcb->asoc.strmout[i].sid = i;
3642 stcb->asoc.strmout[i].last_msg_incomplete = 0;
3643 stcb->asoc.strmout[i].state = SCTP_STREAM_OPENING;
3656 sin.sin_port = stcb->rport;
3664 if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin, NULL, stcb->asoc.port,
3680 sin6.sin6_port = stcb->rport;
3696 if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin, NULL, stcb->asoc.port,
3703 if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin6, NULL, stcb->asoc.port,
3739 rem_len = tot_len - off;
3756 cmsg_data_len = (int)cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh));
3853 ph->param_type = htons(SCTP_STATE_COOKIE);
3854 ph->param_length = 0; /* fill in at the end */
3858 /* tack the INIT and then the INIT-ACK onto the chain */
3889 ph->param_length = htons(cookie_sz);
3898 if ((stcb != NULL) && (stcb->asoc.ecn_supported == 1)) {
3911 SCTPDBG(SCTP_DEBUG_OUTPUT1, "dropped packet - no valid source addr\n");
3915 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT1, &net->ro._l_addr.sa);
3916 if (net->dest_state & SCTP_ADDR_CONFIRMED) {
3917 if ((net->dest_state & SCTP_ADDR_REACHABLE) && stcb) {
3923 net->dest_state &= ~SCTP_ADDR_REACHABLE;
3924 net->dest_state &= ~SCTP_ADDR_PF;
3928 if (net == stcb->asoc.primary_destination) {
3934 if (stcb->asoc.alternate) {
3935 sctp_free_remote_addr(stcb->asoc.alternate);
3937 stcb->asoc.alternate = alt;
3938 atomic_add_int(&stcb->asoc.alternate->ref_count, 1);
3939 if (net->ro._s_addr) {
3940 sctp_free_ifa(net->ro._s_addr);
3941 net->ro._s_addr = NULL;
3943 net->src_addr_selected = 0;
3976 * - fill in the HMAC digest of any AUTH chunk in the packet.
3977 * - calculate and fill in the SCTP checksum.
3978 * - prepend an IP address header.
3979 * - if boundall use INADDR_ANY.
3980 * - if boundspecific do source address selection.
3981 * - set fragmentation option for ipV4.
3982 * - On return from IP output, check/adjust mtu size of output
4000 if ((net) && (net->dest_state & SCTP_ADDR_OUT_OF_SCOPE)) {
4007 vrf_id = stcb->asoc.vrf_id;
4009 vrf_id = inp->def_vrf_id;
4018 tos_value = net->dscp;
4020 tos_value = stcb->asoc.default_dscp;
4022 tos_value = inp->sctp_ep.default_dscp;
4025 switch (to->sa_family) {
4048 m->m_pkthdr.flowid = net->flowid;
4049 M_HASHTYPE_SET(m, net->flowtype);
4051 m->m_pkthdr.flowid = mflowid;
4056 ip->ip_v = IPVERSION;
4057 ip->ip_hl = (sizeof(struct ip) >> 2);
4064 tos_value = inp->ip_inp.inp.inp_ip_tos;
4071 ip->ip_off = htons(IP_DF);
4073 ip->ip_off = htons(0);
4078 ip->ip_ttl = inp->ip_inp.inp.inp_ip_ttl;
4079 ip->ip_len = htons(packet_length);
4080 ip->ip_tos = tos_value;
4082 ip->ip_p = IPPROTO_UDP;
4084 ip->ip_p = IPPROTO_SCTP;
4086 ip->ip_sum = 0;
4090 memcpy(&ro->ro_dst, to, to->sa_len);
4092 ro = (sctp_route_t *)&net->ro;
4095 ip->ip_dst.s_addr = ((struct sockaddr_in *)to)->sin_addr.s_addr;
4099 if (net->ro._s_addr && (net->ro._s_addr->localifa_flags & (SCTP_BEING_DELETED | SCTP_ADDR_IFA_UNUSEABLE))) {
4100 sctp_free_ifa(net->ro._s_addr);
4101 net->ro._s_addr = NULL;
4102 net->src_addr_selected = 0;
4105 if (net->src_addr_selected == 0) {
4107 net->ro._s_addr = sctp_source_address_selection(inp, stcb,
4110 net->src_addr_selected = 1;
4112 if (net->ro._s_addr == NULL) {
4114 net->src_addr_selected = 0;
4120 ip->ip_src = net->ro._s_addr->address.sin.sin_addr;
4135 ip->ip_src = _lsrc->address.sin.sin_addr;
4138 ip->ip_src = over_addr->sin.sin_addr;
4139 SCTP_RTALLOC(ro, vrf_id, inp->fibnum);
4150 udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
4151 udp->uh_dport = port;
4152 udp->uh_ulen = htons((uint16_t)(packet_length - sizeof(struct ip)));
4154 udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP));
4156 udp->uh_sum = 0;
4163 sctphdr->src_port = src_port;
4164 sctphdr->dest_port = dest_port;
4165 sctphdr->v_tag = v_tag;
4166 sctphdr->checksum = 0;
4175 if (ro->ro_nh == NULL) {
4190 (uint32_t)(ntohl(ip->ip_src.s_addr)));
4192 (uint32_t)(ntohl(ip->ip_dst.s_addr)));
4194 (void *)ro->ro_nh);
4207 sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip) + sizeof(struct udphdr));
4217 m->m_pkthdr.csum_flags = CSUM_SCTP;
4218 m->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum);
4242 if ((ro->ro_nh != NULL) && (net->ro._s_addr) &&
4243 ((net->dest_state & SCTP_ADDR_NO_PMTUD) == 0)) {
4246 mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, ro->ro_nh);
4248 if (net->port) {
4249 mtu -= sizeof(struct udphdr);
4251 if (mtu < net->mtu) {
4252 net->mtu = mtu;
4253 if ((stcb != NULL) && (stcb->asoc.smallest_mtu > mtu)) {
4258 } else if (ro->ro_nh == NULL) {
4260 if (net->ro._s_addr &&
4261 net->src_addr_selected) {
4262 sctp_free_ifa(net->ro._s_addr);
4263 net->ro._s_addr = NULL;
4265 net->src_addr_selected = 0;
4286 flowlabel = net->flowlabel;
4288 flowlabel = stcb->asoc.default_flowlabel;
4290 flowlabel = inp->sctp_ep.default_flowlabel;
4298 flowlabel = ntohl(((struct inpcb *)inp)->inp_flow);
4316 m->m_pkthdr.flowid = net->flowid;
4317 M_HASHTYPE_SET(m, net->flowtype);
4319 m->m_pkthdr.flowid = mflowid;
4339 memcpy(&ro->ro_dst, sin6, sin6->sin6_len);
4341 ro = (sctp_route_t *)&net->ro;
4353 tos_value = (ntohl(((struct inpcb *)inp)->inp_flow) >> 20) & 0xff;
4364 ip6h->ip6_flow = htonl(flowinfo);
4366 ip6h->ip6_nxt = IPPROTO_UDP;
4368 ip6h->ip6_nxt = IPPROTO_SCTP;
4370 ip6h->ip6_plen = htons((uint16_t)(packet_length - sizeof(struct ip6_hdr)));
4371 ip6h->ip6_dst = sin6->sin6_addr;
4375 * to a limited degree the kame src-addr-sel, since
4384 if (net->ro._s_addr && (net->ro._s_addr->localifa_flags & (SCTP_BEING_DELETED | SCTP_ADDR_IFA_UNUSEABLE))) {
4385 sctp_free_ifa(net->ro._s_addr);
4386 net->ro._s_addr = NULL;
4387 net->src_addr_selected = 0;
4390 if (net->src_addr_selected == 0) {
4391 sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
4399 net->ro._s_addr = sctp_source_address_selection(inp,
4406 net->src_addr_selected = 1;
4408 if (net->ro._s_addr == NULL) {
4410 net->src_addr_selected = 0;
4416 lsa6->sin6_addr = net->ro._s_addr->address.sin6.sin6_addr;
4418 sin6 = (struct sockaddr_in6 *)&ro->ro_dst;
4438 lsa6->sin6_addr = _lsrc->address.sin6.sin6_addr;
4441 lsa6->sin6_addr = over_addr->sin6.sin6_addr;
4442 SCTP_RTALLOC(ro, vrf_id, inp->fibnum);
4446 lsa6->sin6_port = inp->sctp_lport;
4448 if (ro->ro_nh == NULL) {
4461 * the non-SCOPEDROUTING case.
4466 lsa6_storage.sin6_addr = lsa6->sin6_addr;
4473 lsa6_storage.sin6_addr = lsa6->sin6_addr;
4474 lsa6_storage.sin6_port = inp->sctp_lport;
4476 ip6h->ip6_src = lsa6->sin6_addr;
4486 udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
4487 udp->uh_dport = port;
4488 udp->uh_ulen = htons((uint16_t)(packet_length - sizeof(struct ip6_hdr)));
4489 udp->uh_sum = 0;
4495 sctphdr->src_port = src_port;
4496 sctphdr->dest_port = dest_port;
4497 sctphdr->v_tag = v_tag;
4498 sctphdr->checksum = 0;
4504 ip6h->ip6_hlim = SCTP_GET_HLIM(inp, ro);
4509 sin6->sin6_addr = ip6h->ip6_dst;
4510 lsa6->sin6_addr = ip6h->ip6_src;
4519 sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
4524 prev_scope = sin6->sin6_scope_id;
4525 prev_port = sin6->sin6_port;
4536 sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr));
4538 if ((udp->uh_sum = in6_cksum(o_pak, IPPROTO_UDP, sizeof(struct ip6_hdr), packet_length - sizeof(struct ip6_hdr))) == 0) {
4539 udp->uh_sum = 0xffff;
4542 m->m_pkthdr.csum_flags = CSUM_SCTP_IPV6;
4543 m->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum);
4555 sin6->sin6_scope_id = prev_scope;
4556 sin6->sin6_port = prev_port;
4575 if (ro->ro_nh == NULL) {
4577 if (net->ro._s_addr &&
4578 net->src_addr_selected) {
4579 sctp_free_ifa(net->ro._s_addr);
4580 net->ro._s_addr = NULL;
4582 net->src_addr_selected = 0;
4584 if ((ro->ro_nh != NULL) && (net->ro._s_addr) &&
4585 ((net->dest_state & SCTP_ADDR_NO_PMTUD) == 0)) {
4588 mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, ro->ro_nh);
4590 if (net->port) {
4591 mtu -= sizeof(struct udphdr);
4593 if (mtu < net->mtu) {
4594 net->mtu = mtu;
4595 if ((stcb != NULL) && (stcb->asoc.smallest_mtu > mtu)) {
4601 if ((ND_IFINFO(ifp)->linkmtu > 0) &&
4602 (stcb->asoc.smallest_mtu > ND_IFINFO(ifp)->linkmtu)) {
4603 sctp_pathmtu_adjustment(stcb, ND_IFINFO(ifp)->linkmtu, false);
4612 ((struct sockaddr *)to)->sa_family);
4635 net = stcb->asoc.primary_destination;
4637 net = TAILQ_FIRST(&stcb->asoc.nets);
4643 net->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
4647 net->dest_state &= ~SCTP_ADDR_UNCONFIRMED;
4651 if (net->ro._l_addr.sa.sa_family == AF_INET6) {
4656 if (IN6_IS_ADDR_LINKLOCAL(&net->ro._l_addr.sin6.sin6_addr))
4660 if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
4662 SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - failed timer?\n");
4670 /* No memory, INIT timer will re-attempt. */
4671 SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - mbuf?\n");
4679 init->ch.chunk_type = SCTP_INITIATION;
4680 init->ch.chunk_flags = 0;
4682 init->ch.chunk_length = 0;
4684 init->init.initiate_tag = htonl(stcb->asoc.my_vtag);
4686 init->init.a_rwnd = htonl(max(inp->sctp_socket ? SCTP_SB_LIMIT_RCV(inp->sctp_socket) : 0,
4688 init->init.num_outbound_streams = htons(stcb->asoc.pre_open_streams);
4689 init->init.num_inbound_streams = htons(stcb->asoc.max_inbound_streams);
4690 init->init.initial_tsn = htonl(stcb->asoc.init_seq_number);
4693 if (inp->sctp_ep.adaptation_layer_indicator_provided) {
4696 ali->ph.param_type = htons(SCTP_ULP_ADAPTATION);
4697 ali->ph.param_length = htons(parameter_len);
4698 ali->indication = htonl(inp->sctp_ep.adaptation_layer_indicator);
4703 if (stcb->asoc.ecn_supported == 1) {
4706 ph->param_type = htons(SCTP_ECN_CAPABLE);
4707 ph->param_length = htons(parameter_len);
4711 /* PR-SCTP supported parameter */
4712 if (stcb->asoc.prsctp_supported == 1) {
4715 ph->param_type = htons(SCTP_PRSCTP_SUPPORTED);
4716 ph->param_length = htons(parameter_len);
4721 if (stcb->asoc.rcv_edmid != SCTP_EDMID_NONE) {
4724 zero_chksum->ph.param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE);
4725 zero_chksum->ph.param_length = htons(parameter_len);
4726 zero_chksum->edmid = htonl(stcb->asoc.rcv_edmid);
4734 ph->param_type = htons(SCTP_HAS_NAT_SUPPORT);
4735 ph->param_length = htons(parameter_len);
4742 if (stcb->asoc.prsctp_supported == 1) {
4743 pr_supported->chunk_types[num_ext++] = SCTP_FORWARD_CUM_TSN;
4744 if (stcb->asoc.idata_supported) {
4745 pr_supported->chunk_types[num_ext++] = SCTP_IFORWARD_CUM_TSN;
4748 if (stcb->asoc.auth_supported == 1) {
4749 pr_supported->chunk_types[num_ext++] = SCTP_AUTHENTICATION;
4751 if (stcb->asoc.asconf_supported == 1) {
4752 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF;
4753 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF_ACK;
4755 if (stcb->asoc.reconfig_supported == 1) {
4756 pr_supported->chunk_types[num_ext++] = SCTP_STREAM_RESET;
4758 if (stcb->asoc.idata_supported) {
4759 pr_supported->chunk_types[num_ext++] = SCTP_IDATA;
4761 if (stcb->asoc.nrsack_supported == 1) {
4762 pr_supported->chunk_types[num_ext++] = SCTP_NR_SELECTIVE_ACK;
4764 if (stcb->asoc.pktdrop_supported == 1) {
4765 pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED;
4769 pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT);
4770 pr_supported->ph.param_length = htons(parameter_len);
4771 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
4775 if (stcb->asoc.auth_supported) {
4777 if (stcb->asoc.authinfo.random != NULL) {
4786 parameter_len = (uint16_t)sizeof(struct sctp_auth_random) + stcb->asoc.authinfo.random_len;
4788 memcpy(randp, stcb->asoc.authinfo.random->key, parameter_len);
4789 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
4793 if (stcb->asoc.local_hmacs != NULL) {
4803 stcb->asoc.local_hmacs->num_algo * sizeof(uint16_t));
4804 hmacs->ph.param_type = htons(SCTP_HMAC_LIST);
4805 hmacs->ph.param_length = htons(parameter_len);
4806 sctp_serialize_hmaclist(stcb->asoc.local_hmacs, (uint8_t *)hmacs->hmac_ids);
4807 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
4811 if (stcb->asoc.local_auth_chunks != NULL) {
4821 sctp_auth_get_chklist_size(stcb->asoc.local_auth_chunks));
4822 chunks->ph.param_type = htons(SCTP_CHUNK_LIST);
4823 chunks->ph.param_length = htons(parameter_len);
4824 sctp_serialize_auth_chunks(stcb->asoc.local_auth_chunks, chunks->chunk_types);
4825 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
4831 if (stcb->asoc.cookie_preserve_req > 0) {
4841 cookie_preserve->ph.param_type = htons(SCTP_COOKIE_PRESERVE);
4842 cookie_preserve->ph.param_length = htons(parameter_len);
4843 cookie_preserve->time = htonl(stcb->asoc.cookie_preserve_req);
4844 stcb->asoc.cookie_preserve_req = 0;
4848 if (stcb->asoc.scope.ipv4_addr_legal || stcb->asoc.scope.ipv6_addr_legal) {
4857 if (stcb->asoc.scope.ipv4_addr_legal) {
4860 if (stcb->asoc.scope.ipv6_addr_legal) {
4864 sup_addr->ph.param_type = htons(SCTP_SUPPORTED_ADDRTYPE);
4865 sup_addr->ph.param_length = htons(parameter_len);
4867 if (stcb->asoc.scope.ipv4_addr_legal) {
4868 sup_addr->addr_type[i++] = htons(SCTP_IPV4_ADDRESS);
4870 if (stcb->asoc.scope.ipv6_addr_legal) {
4871 sup_addr->addr_type[i++] = htons(SCTP_IPV6_ADDRESS);
4873 padding_len = 4 - 2 * i;
4885 m_last = sctp_add_addresses_to_i_ia(inp, stcb, &stcb->asoc.scope,
4889 init->ch.chunk_length = htons(chunk_len);
4896 SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - calls lowlevel_output\n");
4898 (struct sockaddr *)&net->ro._l_addr,
4900 inp->sctp_lport, stcb->rport, htonl(0),
4901 net->port, NULL,
4906 stcb->asoc.ifp_had_enobuf = 1;
4910 stcb->asoc.ifp_had_enobuf = 0;
4913 (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time);
4925 * Given a mbuf containing an INIT or INIT-ACK with the param_offset
4934 * By having param_offset be pre-set to where parameters begin it is
4952 limit = ntohs(cp->chunk_length) - sizeof(struct sctp_init_chunk);
4960 ptype = ntohs(phdr->param_type);
4961 plen = ntohs(phdr->param_length);
4964 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error %d\n", plen);
4967 limit -= SCTP_SIZE32(plen);
4968 /*-
4973 * an operr.. to either incorporate (init-ack) or send.
4994 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error chklist %d\n", plen);
5001 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error supaddrtype %d\n", plen);
5008 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error checksum acceptable %d\n", plen);
5017 *edmid = ntohl(zero_chksum_p->edmid);
5024 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error random %d\n", plen);
5034 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error setprim %d\n", plen);
5042 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ipv4 addr %d\n", plen);
5049 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ipv6 addr %d\n", plen);
5056 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error cookie-preserve %d\n", plen);
5063 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error nat support %d\n", plen);
5071 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error prsctp %d\n", plen);
5078 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ecn %d\n", plen);
5085 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error adapatation %d\n", plen);
5092 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error success %d\n", plen);
5118 * Pre-reserve space for IP, SCTP,
5130 cause->code = htons(SCTP_CAUSE_UNRESOLVABLE_ADDR);
5131 cause->length = htons((uint16_t)(sizeof(struct sctp_gen_error_cause) + plen));
5201 param->param_type = htons(SCTP_UNRECOG_PARAM);
5202 param->param_length = htons((uint16_t)sizeof(struct sctp_paramhdr) + plen);
5216 pad_needed = 4 - (plen % 4);
5264 param->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION);
5265 param->param_length = htons(2 * sizeof(struct sctp_paramhdr));
5267 param->param_type = htons(ptype);
5268 param->param_length = htons(plen);
5313 switch (src->sa_family) {
5316 if (asoc->scope.ipv4_addr_legal) {
5323 if (asoc->scope.ipv6_addr_legal) {
5334 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
5335 sa = (struct sockaddr *)&net->ro._l_addr;
5336 if (sa->sa_family == src->sa_family) {
5338 if (sa->sa_family == AF_INET) {
5343 if (sa4->sin_addr.s_addr == src4->sin_addr.s_addr) {
5350 if (sa->sa_family == AF_INET6) {
5379 ptype = ntohs(phdr->param_type);
5380 plen = ntohs(phdr->param_length);
5405 if (asoc->scope.ipv4_addr_legal) {
5407 sin4.sin_addr.s_addr = p4->addr;
5428 if (asoc->scope.ipv6_addr_legal) {
5430 memcpy((caddr_t)&sin6.sin6_addr, p6->addr,
5431 sizeof(p6->addr));
5444 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
5445 sa = (struct sockaddr *)&net->ro._l_addr;
5446 if (sa->sa_family != sa_touse->sa_family) {
5450 if (sa->sa_family == AF_INET) {
5452 if (sa4->sin_addr.s_addr ==
5460 if (sa->sa_family == AF_INET6) {
5493 * INIT-ACK with COOKIE and send back. We assume that the in_initpkt has done
5541 asoc = &stcb->asoc;
5547 if (sctp_are_there_new_addresses(asoc, init_pkt, offset, offset + ntohs(init_chk->ch.chunk_length), src, &op_err)) {
5549 * new addresses, out of here in non-cookie-wait
5553 mflowtype, mflowid, inp->fibnum,
5557 if (src_net != NULL && (src_net->port != port)) {
5560 * in non-cookie-wait states
5569 mflowtype, mflowid, inp->fibnum,
5590 init_chk->init.initiate_tag, op_err,
5591 mflowtype, mflowid, inp->fibnum,
5597 /* No memory, INIT timer will re-attempt. */
5620 stc.tie_tag_my_vtag = asoc->my_vtag_nonce;
5621 stc.tie_tag_peer_vtag = asoc->peer_vtag_nonce;
5622 stc.cookie_life = asoc->cookie_life;
5623 net = asoc->primary_destination;
5628 stc.cookie_life = inp->sctp_ep.def_cookie_life;
5632 stc.myport = sh->dest_port;
5633 stc.peerport = sh->src_port;
5640 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
5654 switch (dst->sa_family) {
5659 stc.address[0] = src4->sin_addr.s_addr;
5665 stc.laddress[0] = dst4->sin_addr.s_addr;
5672 if ((IN4_ISPRIVATE_ADDRESS(&src4->sin_addr)) ||
5673 (IN4_ISPRIVATE_ADDRESS(&dst4->sin_addr))) {
5690 memcpy(&stc.address, &src6->sin6_addr, sizeof(struct in6_addr));
5691 stc.scope_id = ntohs(in6_getscope(&src6->sin6_addr));
5697 } else if (IN6_IS_ADDR_LINKLOCAL(&src6->sin6_addr) ||
5698 IN6_IS_ADDR_LINKLOCAL(&dst6->sin6_addr)) {
5724 } else if (IN6_IS_ADDR_SITELOCAL(&src6->sin6_addr) ||
5725 IN6_IS_ADDR_SITELOCAL(&dst6->sin6_addr)) {
5733 memcpy(&stc.laddress, &dst6->sin6_addr, sizeof(struct in6_addr));
5750 stc.loopback_scope = asoc->scope.loopback_scope;
5751 stc.ipv4_scope = asoc->scope.ipv4_local_scope;
5752 stc.site_scope = asoc->scope.site_scope;
5753 stc.local_scope = asoc->scope.local_scope;
5756 TAILQ_FOREACH(lnet, &asoc->nets, sctp_next) {
5757 if (lnet->ro._l_addr.sin6.sin6_family == AF_INET6) {
5758 if (IN6_IS_ADDR_LINKLOCAL(&lnet->ro._l_addr.sin6.sin6_addr)) {
5769 to = (struct sockaddr *)&net->ro._l_addr;
5770 switch (to->sa_family) {
5774 stc.address[0] = sin->sin_addr.s_addr;
5779 if (net->src_addr_selected == 0) {
5784 net->ro._s_addr = sctp_source_address_selection(inp,
5785 stcb, (sctp_route_t *)&net->ro,
5787 if (net->ro._s_addr == NULL) {
5793 net->src_addr_selected = 1;
5795 stc.laddress[0] = net->ro._s_addr->address.sin.sin_addr.s_addr;
5807 memcpy(&stc.address, &sin6->sin6_addr,
5810 stc.scope_id = sin6->sin6_scope_id;
5811 if (net->src_addr_selected == 0) {
5816 net->ro._s_addr = sctp_source_address_selection(inp,
5817 stcb, (sctp_route_t *)&net->ro,
5819 if (net->ro._s_addr == NULL) {
5825 net->src_addr_selected = 1;
5827 memcpy(&stc.laddress, &net->ro._s_addr->address.sin6.sin6_addr,
5835 stc.rcv_edmid = asoc->rcv_edmid;
5837 stc.rcv_edmid = inp->rcv_edmid;
5842 stc.peers_vtag = ntohl(init_chk->init.initiate_tag);
5848 initack->ch.chunk_type = SCTP_INITIATION_ACK;
5849 initack->ch.chunk_flags = 0;
5851 initack->ch.chunk_length = 0;
5857 /* re-use the v-tags and init-seq here */
5858 initack->init.initiate_tag = htonl(asoc->my_vtag);
5859 initack->init.initial_tsn = htonl(asoc->init_seq_number);
5864 atomic_add_int(&asoc->refcnt, 1);
5868 vtag = sctp_select_a_tag(inp, inp->sctp_lport, sh->src_port, 1);
5870 if ((asoc->peer_supports_nat) && (vtag == asoc->my_vtag)) {
5877 initack->init.initiate_tag = htonl(vtag);
5879 itsn = sctp_select_initial_TSN(&inp->sctp_ep);
5880 initack->init.initial_tsn = htonl(itsn);
5882 atomic_subtract_int(&asoc->refcnt, 1);
5887 vtag = sctp_select_a_tag(inp, inp->sctp_lport, sh->src_port, 1);
5889 initack->init.initiate_tag = htonl(vtag);
5891 initack->init.initial_tsn = htonl(sctp_select_initial_TSN(&inp->sctp_ep));
5897 stc.my_vtag = initack->init.initiate_tag;
5900 so = inp->sctp_socket;
5907 initack->init.a_rwnd = htonl(max(SCTP_SB_LIMIT_RCV(so), SCTP_MINIMAL_RWND));
5910 his_limit = ntohs(init_chk->init.num_inbound_streams);
5913 if (asoc->streamoutcnt > asoc->pre_open_streams) {
5914 i_want = asoc->streamoutcnt;
5916 i_want = asoc->pre_open_streams;
5919 i_want = inp->sctp_ep.pre_open_stream_count;
5923 initack->init.num_outbound_streams = init_chk->init.num_inbound_streams;
5926 initack->init.num_outbound_streams = htons(i_want);
5929 initack->init.num_inbound_streams =
5930 htons(inp->sctp_ep.max_open_streams_intome);
5933 if (inp->sctp_ep.adaptation_layer_indicator_provided) {
5936 ali->ph.param_type = htons(SCTP_ULP_ADAPTATION);
5937 ali->ph.param_length = htons(parameter_len);
5938 ali->indication = htonl(inp->sctp_ep.adaptation_layer_indicator);
5943 if (((asoc != NULL) && (asoc->ecn_supported == 1)) ||
5944 ((asoc == NULL) && (inp->ecn_supported == 1))) {
5947 ph->param_type = htons(SCTP_ECN_CAPABLE);
5948 ph->param_length = htons(parameter_len);
5952 /* PR-SCTP supported parameter */
5953 if (((asoc != NULL) && (asoc->prsctp_supported == 1)) ||
5954 ((asoc == NULL) && (inp->prsctp_supported == 1))) {
5957 ph->param_type = htons(SCTP_PRSCTP_SUPPORTED);
5958 ph->param_length = htons(parameter_len);
5963 if (((asoc != NULL) && (asoc->rcv_edmid != SCTP_EDMID_NONE)) ||
5964 ((asoc == NULL) && (inp->rcv_edmid != SCTP_EDMID_NONE))) {
5967 zero_chksum->ph.param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE);
5968 zero_chksum->ph.param_length = htons(parameter_len);
5970 zero_chksum->edmid = htonl(asoc->rcv_edmid);
5972 zero_chksum->edmid = htonl(inp->rcv_edmid);
5981 ph->param_type = htons(SCTP_HAS_NAT_SUPPORT);
5982 ph->param_length = htons(parameter_len);
5989 if (((asoc != NULL) && (asoc->prsctp_supported == 1)) ||
5990 ((asoc == NULL) && (inp->prsctp_supported == 1))) {
5991 pr_supported->chunk_types[num_ext++] = SCTP_FORWARD_CUM_TSN;
5992 if (((asoc != NULL) && (asoc->idata_supported == 1)) ||
5993 ((asoc == NULL) && (inp->idata_supported == 1))) {
5994 pr_supported->chunk_types[num_ext++] = SCTP_IFORWARD_CUM_TSN;
5997 if (((asoc != NULL) && (asoc->auth_supported == 1)) ||
5998 ((asoc == NULL) && (inp->auth_supported == 1))) {
5999 pr_supported->chunk_types[num_ext++] = SCTP_AUTHENTICATION;
6001 if (((asoc != NULL) && (asoc->asconf_supported == 1)) ||
6002 ((asoc == NULL) && (inp->asconf_supported == 1))) {
6003 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF;
6004 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF_ACK;
6006 if (((asoc != NULL) && (asoc->reconfig_supported == 1)) ||
6007 ((asoc == NULL) && (inp->reconfig_supported == 1))) {
6008 pr_supported->chunk_types[num_ext++] = SCTP_STREAM_RESET;
6010 if (((asoc != NULL) && (asoc->idata_supported == 1)) ||
6011 ((asoc == NULL) && (inp->idata_supported == 1))) {
6012 pr_supported->chunk_types[num_ext++] = SCTP_IDATA;
6014 if (((asoc != NULL) && (asoc->nrsack_supported == 1)) ||
6015 ((asoc == NULL) && (inp->nrsack_supported == 1))) {
6016 pr_supported->chunk_types[num_ext++] = SCTP_NR_SELECTIVE_ACK;
6018 if (((asoc != NULL) && (asoc->pktdrop_supported == 1)) ||
6019 ((asoc == NULL) && (inp->pktdrop_supported == 1))) {
6020 pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED;
6024 pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT);
6025 pr_supported->ph.param_length = htons(parameter_len);
6026 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
6031 if (((asoc != NULL) && (asoc->auth_supported == 1)) ||
6032 ((asoc == NULL) && (inp->auth_supported == 1))) {
6046 randp->ph.param_type = htons(SCTP_RANDOM);
6047 randp->ph.param_length = htons(parameter_len);
6048 SCTP_READ_RANDOM(randp->random_data, SCTP_AUTH_RANDOM_SIZE_DEFAULT);
6049 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
6060 sctp_serialize_hmaclist(inp->sctp_ep.local_hmacs,
6061 (uint8_t *)hmacs->hmac_ids);
6062 hmacs->ph.param_type = htons(SCTP_HMAC_LIST);
6063 hmacs->ph.param_length = htons(parameter_len);
6064 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
6075 sctp_serialize_auth_chunks(inp->sctp_ep.local_auth_chunks,
6076 chunks->chunk_types);
6077 chunks->ph.param_type = htons(SCTP_CHUNK_LIST);
6078 chunks->ph.param_length = htons(parameter_len);
6079 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
6114 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
6147 padding_len = SCTP_SIZE32(parameter_len) - parameter_len;
6152 * the INIT-ACK.
6154 initack->ch.chunk_length = htons(chunk_len);
6161 (uint8_t *)inp->sctp_ep.secret_key[(int)(inp->sctp_ep.current_secret_number)],
6181 use_zero_crc = (asoc->rcv_edmid != SCTP_EDMID_NONE) && (asoc->rcv_edmid == edmid);
6183 use_zero_crc = (inp->rcv_edmid != SCTP_EDMID_NONE) && (inp->rcv_edmid == edmid);
6188 inp->sctp_lport, sh->src_port, init_chk->init.initiate_tag,
6196 asoc->ifp_had_enobuf = 1;
6202 asoc->ifp_had_enobuf = 0;
6218 if ((asoc->prsctp_supported) &&
6219 (asoc->sent_queue_cnt_removeable > 0)) {
6220 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
6227 if (PR_SCTP_BUF_ENABLED(chk->flags)) {
6229 * This one is PR-SCTP AND buffer space
6232 if (chk->rec.data.timetodrop.tv_sec > (long)srcv->sinfo_timetolive) {
6240 if (chk->data) {
6248 if (chk->sent > SCTP_DATAGRAM_UNSENT)
6264 TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) {
6266 if (PR_SCTP_BUF_ENABLED(chk->flags)) {
6267 if (chk->rec.data.timetodrop.tv_sec > (long)srcv->sinfo_timetolive) {
6268 if (chk->data) {
6282 } /* end if chk->data */
6284 } /* end if chk pr-sctp */
6295 asoc = &stcb->asoc;
6297 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
6303 if (asoc->idata_supported) {
6305 if (sctp_auth_is_required_chunk(SCTP_IDATA, asoc->peer_auth_chunks)) {
6306 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
6310 if (sctp_auth_is_required_chunk(SCTP_DATA, asoc->peer_auth_chunks)) {
6311 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id);
6317 if (asoc->smallest_mtu % 4 > 0) {
6318 overhead += (asoc->smallest_mtu % 4);
6320 KASSERT(asoc->smallest_mtu > overhead,
6322 asoc->smallest_mtu, overhead));
6323 frag_point = asoc->smallest_mtu - overhead;
6327 if ((asoc->sctp_frag_point > 0) &&
6328 (asoc->sctp_frag_point < frag_point)) {
6329 frag_point = asoc->sctp_frag_point;
6341 if (PR_SCTP_ENABLED(sp->sinfo_flags)) {
6342 sp->act_flags |= PR_SCTP_POLICY(sp->sinfo_flags);
6343 } else if (sp->timetolive > 0) {
6344 sp->sinfo_flags |= SCTP_PR_SCTP_TTL;
6345 sp->act_flags |= PR_SCTP_POLICY(sp->sinfo_flags);
6349 switch (PR_SCTP_POLICY(sp->sinfo_flags)) {
6355 sp->ts.tv_sec = sp->timetolive;
6356 sp->ts.tv_usec = 0;
6362 (void)SCTP_GETTIME_TIMEVAL(&sp->ts);
6363 tv.tv_sec = sp->timetolive / 1000;
6364 tv.tv_usec = (sp->timetolive * 1000) % 1000000;
6369 timevaladd(&sp->ts, &tv);
6377 sp->ts.tv_sec = sp->timetolive;
6378 sp->ts.tv_usec = 0;
6383 PR_SCTP_POLICY(sp->sinfo_flags));
6405 if (srcv->sinfo_stream >= stcb->asoc.streamoutcnt) {
6411 if ((stcb->asoc.stream_locked) &&
6412 (stcb->asoc.stream_locked_on != srcv->sinfo_stream)) {
6417 if ((stcb->asoc.strmout[srcv->sinfo_stream].state != SCTP_STREAM_OPEN) &&
6418 (stcb->asoc.strmout[srcv->sinfo_stream].state != SCTP_STREAM_OPENING)) {
6422 if (stcb->asoc.strmout[srcv->sinfo_stream].state > SCTP_STREAM_OPEN) {
6433 (stcb->asoc.state & SCTP_STATE_SHUTDOWN_PENDING)) {
6445 sp->sinfo_flags = srcv->sinfo_flags;
6446 sp->timetolive = srcv->sinfo_timetolive;
6447 sp->ppid = srcv->sinfo_ppid;
6448 sp->context = srcv->sinfo_context;
6449 sp->fsn = 0;
6450 if (sp->sinfo_flags & SCTP_ADDR_OVER) {
6451 sp->net = net;
6452 atomic_add_int(&sp->net->ref_count, 1);
6454 sp->net = NULL;
6456 (void)SCTP_GETTIME_TIMEVAL(&sp->ts);
6457 sp->sid = srcv->sinfo_stream;
6458 sp->msg_is_complete = 1;
6459 sp->sender_all_done = 1;
6460 sp->some_taken = 0;
6461 sp->data = m;
6462 sp->tail_mbuf = NULL;
6469 sp->length = 0;
6472 sp->tail_mbuf = at;
6473 sp->length += SCTP_BUF_LEN(at);
6475 if (srcv->sinfo_keynumber_valid) {
6476 sp->auth_keyid = srcv->sinfo_keynumber;
6478 sp->auth_keyid = stcb->asoc.authinfo.active_keyid;
6480 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
6481 sctp_auth_key_acquire(stcb, sp->auth_keyid);
6482 sp->holds_key_ref = 1;
6484 strm = &stcb->asoc.strmout[srcv->sinfo_stream];
6485 sctp_snd_sb_alloc(stcb, sp->length);
6486 atomic_add_int(&stcb->asoc.stream_queue_cnt, 1);
6487 TAILQ_INSERT_TAIL(&strm->outqueue, sp, next);
6488 stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, strm, sp);
6521 (sizeofcpy <= (int)((((SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) - 1) * MLEN) + MHLEN)))) {
6580 sizeofcpy -= len;
6625 * save off the end and update the end-chain position
6637 /* save off the end and update the end-chain position */
6673 if (ca->m == NULL) {
6676 if (ca->inp != inp) {
6680 if (ca->sndlen > 0) {
6681 m = SCTP_M_COPYM(ca->m, 0, M_COPYALL, M_NOWAIT);
6684 ca->cnt_failed++;
6696 if (stcb->asoc.alternate) {
6697 net = stcb->asoc.alternate;
6699 net = stcb->asoc.primary_destination;
6701 if (ca->sndrcv.sinfo_flags & SCTP_ABORT) {
6716 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
6717 ph->param_length = htons((uint16_t)(sizeof(struct sctp_paramhdr) + ca->sndlen));
6720 * We add one here to keep the assoc from dis-appearing on
6723 atomic_add_int(&stcb->asoc.refcnt, 1);
6732 * stcb will return to us un-locked.. since free_asoc
6734 * relock.. to unlock in the iterator timer :-0
6737 atomic_subtract_int(&stcb->asoc.refcnt, 1);
6741 ret = sctp_msg_append(stcb, net, m, &ca->sndrcv);
6743 asoc = &stcb->asoc;
6744 if (ca->sndrcv.sinfo_flags & SCTP_EOF) {
6746 if (TAILQ_EMPTY(&asoc->send_queue) &&
6747 TAILQ_EMPTY(&asoc->sent_queue) &&
6749 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
6769 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb,
6771 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
6785 * and move to SHUTDOWN-PENDING
6790 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
6794 if (TAILQ_EMPTY(&asoc->send_queue) &&
6795 TAILQ_EMPTY(&asoc->sent_queue) &&
6796 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
6805 atomic_add_int(&stcb->asoc.refcnt, 1);
6806 sctp_abort_an_association(stcb->sctp_ep, stcb,
6808 atomic_subtract_int(&stcb->asoc.refcnt, 1);
6815 un_sent = ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) +
6816 (stcb->asoc.stream_queue_cnt * SCTP_DATA_CHUNK_OVERHEAD(stcb)));
6819 (stcb->asoc.total_flight > 0) &&
6820 (un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD))) {
6829 (void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out,
6836 ca->cnt_failed++;
6838 ca->cnt_sent++;
6854 * user you can't send the data :->
6858 if (ca->inp) {
6860 SCTP_INP_WLOCK(ca->inp);
6861 ca->inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP;
6862 SCTP_INP_WUNLOCK(ca->inp);
6864 sctp_m_freem(ca->m);
6895 left -= willcpy;
6920 sndlen = uio->uio_resid;
6939 ca->inp = inp;
6941 memcpy(&ca->sndrcv, srcv, sizeof(struct sctp_nonpad_sndrcvinfo));
6945 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SND_ITERATOR_UP) != 0) {
6951 inp->sctp_flags |= SCTP_PCB_FLAGS_SND_ITERATOR_UP;
6955 * this :-0
6957 ca->sndrcv.sinfo_flags &= ~SCTP_SENDALL;
6959 ca->sndlen = sndlen;
6961 ca->m = sctp_copy_out_all(uio, ca->sndlen);
6962 if (ca->m == NULL) {
6966 inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP;
6972 ca->m = m;
6981 inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP;
6995 TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) {
6996 if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) {
6997 TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next);
6998 asoc->ctrl_queue_cnt--;
6999 if (chk->data) {
7000 sctp_m_freem(chk->data);
7001 chk->data = NULL;
7015 asoc = &stcb->asoc;
7016 TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) {
7018 if (chk->rec.chunk_id.id == SCTP_ASCONF) {
7019 if (chk->data) {
7020 acp = mtod(chk->data, struct sctp_asconf_chunk *);
7021 if (SCTP_TSN_GT(ntohl(acp->serial_number), asoc->asconf_seq_out_acked)) {
7026 TAILQ_REMOVE(&asoc->asconf_send_queue, chk, sctp_next);
7027 asoc->ctrl_queue_cnt--;
7028 if (chk->data) {
7029 sctp_m_freem(chk->data);
7030 chk->data = NULL;
7049 TAILQ_REMOVE(&asoc->send_queue, data_list[i], sctp_next);
7050 asoc->send_queue_cnt--;
7057 data_list[i]->do_rtt = 0;
7060 data_list[i]->sent_rcv_time = net->last_sent_time;
7061 data_list[i]->rec.data.cwnd_at_send = net->cwnd;
7062 data_list[i]->rec.data.fast_retran_tsn = data_list[i]->rec.data.tsn;
7063 if (data_list[i]->whoTo == NULL) {
7064 data_list[i]->whoTo = net;
7065 atomic_add_int(&net->ref_count, 1);
7068 tp1 = TAILQ_LAST(&asoc->sent_queue, sctpchunk_listhead);
7069 if ((tp1) && SCTP_TSN_GT(tp1->rec.data.tsn, data_list[i]->rec.data.tsn)) {
7080 if (SCTP_TSN_GT(tp1->rec.data.tsn, data_list[i]->rec.data.tsn)) {
7083 TAILQ_INSERT_AFTER(&asoc->sent_queue, tp1, data_list[i], sctp_next);
7085 TAILQ_INSERT_TAIL(&asoc->sent_queue,
7090 /* This does not lower until the cum-ack passes it */
7091 asoc->sent_queue_cnt++;
7092 if ((asoc->peers_rwnd <= 0) &&
7093 (asoc->total_flight == 0) &&
7101 data_list[i]->sent = SCTP_DATAGRAM_SENT;
7102 data_list[i]->snd_count = 1;
7103 data_list[i]->rec.data.chunk_was_revoked = 0;
7106 data_list[i]->whoTo->flight_size,
7107 data_list[i]->book_size,
7108 (uint32_t)(uintptr_t)data_list[i]->whoTo,
7109 data_list[i]->rec.data.tsn);
7115 asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh));
7117 asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd,
7118 (uint32_t)(data_list[i]->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)));
7119 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
7121 asoc->peers_rwnd = 0;
7124 if (asoc->cc_functions.sctp_cwnd_update_packet_transmitted) {
7125 (*asoc->cc_functions.sctp_cwnd_update_packet_transmitted) (stcb, net);
7134 TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) {
7135 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) ||
7136 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK) || /* EY */
7137 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) ||
7138 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_ACK) ||
7139 (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) ||
7140 (chk->rec.chunk_id.id == SCTP_SHUTDOWN) ||
7141 (chk->rec.chunk_id.id == SCTP_SHUTDOWN_ACK) ||
7142 (chk->rec.chunk_id.id == SCTP_OPERATION_ERROR) ||
7143 (chk->rec.chunk_id.id == SCTP_PACKET_DROPPED) ||
7144 (chk->rec.chunk_id.id == SCTP_COOKIE_ACK) ||
7145 (chk->rec.chunk_id.id == SCTP_ECN_CWR) ||
7146 (chk->rec.chunk_id.id == SCTP_ASCONF_ACK)) {
7149 TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next);
7150 asoc->ctrl_queue_cnt--;
7151 if (chk->data) {
7152 sctp_m_freem(chk->data);
7153 chk->data = NULL;
7155 if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) {
7156 asoc->fwd_tsn_cnt--;
7159 } else if (chk->rec.chunk_id.id == SCTP_STREAM_RESET) {
7161 if (chk != asoc->str_reset) {
7183 /*-
7186 * arrives to transmit - wait for more data
7188 if (stcb->asoc.total_flight == 0) {
7202 /*-
7207 if (SCTP_SB_LIMIT_SND(stcb->sctp_socket) < frag_point) {
7211 ((length - space_left) < SCTP_BASE_SYSCTL(sctp_min_residual))) {
7212 /* Sub-optimal residual don't split in non-eeor mode. */
7250 asoc = &stcb->asoc;
7253 sp = TAILQ_FIRST(&strq->outqueue);
7255 sp = TAILQ_FIRST(&strq->outqueue);
7259 if ((sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_EXPLICIT_EOR) == 0) &&
7260 (stcb->asoc.idata_supported == 0) &&
7261 (strq->last_msg_incomplete)) {
7263 strq->sid,
7264 strq->last_msg_incomplete);
7265 strq->last_msg_incomplete = 0;
7270 if ((sp->msg_is_complete) && (sp->length == 0)) {
7271 if (sp->sender_all_done) {
7277 if ((sp->put_last_out == 0) && (sp->discard_rest == 0)) {
7278 SCTP_PRINTF("Gak, put out entire msg with NO end!-1\n");
7280 sp->sender_all_done,
7281 sp->length,
7282 sp->msg_is_complete,
7283 sp->put_last_out);
7285 atomic_subtract_int(&asoc->stream_queue_cnt, 1);
7286 TAILQ_REMOVE(&strq->outqueue, sp, next);
7287 stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp);
7288 if ((strq->state == SCTP_STREAM_RESET_PENDING) &&
7289 (strq->chunks_on_queues == 0) &&
7290 TAILQ_EMPTY(&strq->outqueue)) {
7291 stcb->asoc.trigger_reset = 1;
7293 if (sp->net) {
7294 sctp_free_remote_addr(sp->net);
7295 sp->net = NULL;
7297 if (sp->data) {
7298 sctp_m_freem(sp->data);
7299 sp->data = NULL;
7315 if (sp->length == 0) {
7320 } else if (sp->discard_rest) {
7322 atomic_subtract_int(&stcb->asoc.total_output_queue_size, sp->length);
7323 if ((stcb->sctp_socket != NULL) &&
7324 ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
7325 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
7326 SCTP_SB_DECR(&stcb->sctp_socket->so_snd, sp->length);
7328 if (sp->data) {
7329 sctp_m_freem(sp->data);
7330 sp->data = NULL;
7331 sp->tail_mbuf = NULL;
7333 sp->length = 0;
7334 sp->some_taken = 1;
7340 some_taken = sp->some_taken;
7341 length = sp->length;
7342 if (sp->msg_is_complete) {
7347 if (sp->some_taken) {
7352 sp->put_last_out = 1;
7353 if (sp->sinfo_flags & SCTP_SACK_IMMEDIATELY) {
7358 if (sp->some_taken == 0) {
7361 sp->some_taken = 1;
7369 if (sp->some_taken == 0) {
7371 sp->some_taken = 1;
7393 if (sp->sinfo_flags & SCTP_UNORDERED) {
7397 (sp->sinfo_flags & SCTP_EOF) == SCTP_EOF) {
7402 chk->rec.data.rcv_flags = rcv_flags;
7406 if (to_move < sp->length) {
7410 chk->data = sp->data;
7411 chk->last_mbuf = sp->tail_mbuf;
7413 sp->data = sp->tail_mbuf = NULL;
7418 chk->data = SCTP_M_COPYM(sp->data, 0, to_move, M_NOWAIT);
7419 chk->last_mbuf = NULL;
7420 if (chk->data == NULL) {
7421 sp->some_taken = some_taken;
7429 sctp_log_mbc(chk->data, SCTP_MBUF_ICOPY);
7433 m_adj(sp->data, to_move);
7435 m = sp->data;
7437 sp->data = SCTP_BUF_NEXT(m);
7439 if (sp->tail_mbuf == m) {
7440 /*-
7443 * than the sp->length.
7446 panic("Huh, freeing tail? - TSNH");
7448 SCTP_PRINTF("Huh, freeing tail? - TSNH\n");
7449 sp->tail_mbuf = sp->data = NULL;
7450 sp->length = 0;
7454 m = sp->data;
7457 if (SCTP_BUF_IS_EXTENDED(chk->data)) {
7458 chk->copy_by_ref = 1;
7460 chk->copy_by_ref = 0;
7466 if (chk->last_mbuf == NULL) {
7467 chk->last_mbuf = chk->data;
7468 while (SCTP_BUF_NEXT(chk->last_mbuf) != NULL) {
7469 chk->last_mbuf = SCTP_BUF_NEXT(chk->last_mbuf);
7474 /*- This should not happen either
7476 * of sp->length if its larger.
7482 sp->length = 0;
7485 atomic_subtract_int(&sp->length, to_move);
7488 if (M_LEADINGSPACE(chk->data) < leading) {
7499 if (sp->data == NULL) {
7501 sp->data = chk->data;
7502 sp->tail_mbuf = chk->last_mbuf;
7507 m_tmp = sp->data;
7508 sp->data = chk->data;
7509 SCTP_BUF_NEXT(chk->last_mbuf) = m_tmp;
7511 sp->some_taken = some_taken;
7512 atomic_add_int(&sp->length, to_move);
7513 chk->data = NULL;
7520 SCTP_BUF_NEXT(m) = chk->data;
7521 chk->data = m;
7522 M_ALIGN(chk->data, 4);
7525 SCTP_BUF_PREPEND(chk->data, SCTP_DATA_CHUNK_OVERHEAD(stcb), M_NOWAIT);
7526 if (chk->data == NULL) {
7539 chk->book_size = chk->send_size = (uint16_t)(to_move + SCTP_DATA_CHUNK_OVERHEAD(stcb));
7540 chk->book_size_scale = 0;
7541 chk->sent = SCTP_DATAGRAM_UNSENT;
7543 chk->flags = 0;
7544 chk->asoc = &stcb->asoc;
7545 chk->pad_inplace = 0;
7546 chk->no_fr_allowed = 0;
7547 if (stcb->asoc.idata_supported == 0) {
7550 chk->rec.data.mid = 0;
7552 chk->rec.data.mid = strq->next_mid_ordered;
7554 strq->next_mid_ordered++;
7559 chk->rec.data.mid = strq->next_mid_unordered;
7561 strq->next_mid_unordered++;
7564 chk->rec.data.mid = strq->next_mid_ordered;
7566 strq->next_mid_ordered++;
7570 chk->rec.data.sid = sp->sid;
7571 chk->rec.data.ppid = sp->ppid;
7572 chk->rec.data.context = sp->context;
7573 chk->rec.data.doing_fast_retransmit = 0;
7575 chk->rec.data.timetodrop = sp->ts;
7576 chk->flags = sp->act_flags;
7578 if (sp->net) {
7579 chk->whoTo = sp->net;
7580 atomic_add_int(&chk->whoTo->ref_count, 1);
7582 chk->whoTo = NULL;
7584 if (sp->holds_key_ref) {
7585 chk->auth_keyid = sp->auth_keyid;
7586 sctp_auth_key_acquire(stcb, chk->auth_keyid);
7587 chk->holds_key_ref = 1;
7589 stcb->asoc.ss_functions.sctp_ss_scheduled(stcb, net, asoc, strq, to_move);
7590 chk->rec.data.tsn = atomic_fetchadd_int(&asoc->sending_seq, 1);
7593 (uint32_t)(uintptr_t)stcb, sp->length,
7594 (uint32_t)((chk->rec.data.sid << 16) | (0x0000ffff & chk->rec.data.mid)),
7595 chk->rec.data.tsn);
7597 if (stcb->asoc.idata_supported == 0) {
7598 dchkh = mtod(chk->data, struct sctp_data_chunk *);
7600 ndchkh = mtod(chk->data, struct sctp_idata_chunk *);
7609 if (asoc->tsn_out_at >= SCTP_TSN_LOG_SIZE) {
7610 asoc->tsn_out_at = 0;
7611 asoc->tsn_out_wrapped = 1;
7613 asoc->out_tsnlog[asoc->tsn_out_at].tsn = chk->rec.data.tsn;
7614 asoc->out_tsnlog[asoc->tsn_out_at].strm = chk->rec.data.sid;
7615 asoc->out_tsnlog[asoc->tsn_out_at].seq = chk->rec.data.mid;
7616 asoc->out_tsnlog[asoc->tsn_out_at].sz = chk->send_size;
7617 asoc->out_tsnlog[asoc->tsn_out_at].flgs = chk->rec.data.rcv_flags;
7618 asoc->out_tsnlog[asoc->tsn_out_at].stcb = (void *)stcb;
7619 asoc->out_tsnlog[asoc->tsn_out_at].in_pos = asoc->tsn_out_at;
7620 asoc->out_tsnlog[asoc->tsn_out_at].in_out = 2;
7621 asoc->tsn_out_at++;
7623 if (stcb->asoc.idata_supported == 0) {
7624 dchkh->ch.chunk_type = SCTP_DATA;
7625 dchkh->ch.chunk_flags = chk->rec.data.rcv_flags;
7626 dchkh->dp.tsn = htonl(chk->rec.data.tsn);
7627 dchkh->dp.sid = htons(strq->sid);
7628 dchkh->dp.ssn = htons((uint16_t)chk->rec.data.mid);
7629 dchkh->dp.ppid = chk->rec.data.ppid;
7630 dchkh->ch.chunk_length = htons(chk->send_size);
7632 ndchkh->ch.chunk_type = SCTP_IDATA;
7633 ndchkh->ch.chunk_flags = chk->rec.data.rcv_flags;
7634 ndchkh->dp.tsn = htonl(chk->rec.data.tsn);
7635 ndchkh->dp.sid = htons(strq->sid);
7636 ndchkh->dp.reserved = htons(0);
7637 ndchkh->dp.mid = htonl(chk->rec.data.mid);
7638 if (sp->fsn == 0)
7639 ndchkh->dp.ppid_fsn.ppid = chk->rec.data.ppid;
7641 ndchkh->dp.ppid_fsn.fsn = htonl(sp->fsn);
7642 sp->fsn++;
7643 ndchkh->ch.chunk_length = htons(chk->send_size);
7645 /* Now advance the chk->send_size by the actual pad needed. */
7646 if (chk->send_size < SCTP_SIZE32(chk->book_size)) {
7651 pads = SCTP_SIZE32(chk->book_size) - chk->send_size;
7652 lm = sctp_pad_lastmbuf(chk->data, pads, chk->last_mbuf);
7654 chk->last_mbuf = lm;
7655 chk->pad_inplace = 1;
7657 chk->send_size += pads;
7659 if (PR_SCTP_ENABLED(chk->flags)) {
7660 asoc->pr_sctp_cnt++;
7662 if (sp->msg_is_complete && (sp->length == 0) && (sp->sender_all_done)) {
7664 if (sp->put_last_out == 0) {
7665 SCTP_PRINTF("Gak, put out entire msg with NO end!-2\n");
7667 sp->sender_all_done,
7668 sp->length,
7669 sp->msg_is_complete,
7670 sp->put_last_out);
7672 atomic_subtract_int(&asoc->stream_queue_cnt, 1);
7673 TAILQ_REMOVE(&strq->outqueue, sp, next);
7674 stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp);
7675 if ((strq->state == SCTP_STREAM_RESET_PENDING) &&
7676 (strq->chunks_on_queues == 0) &&
7677 TAILQ_EMPTY(&strq->outqueue)) {
7678 stcb->asoc.trigger_reset = 1;
7680 if (sp->net) {
7681 sctp_free_remote_addr(sp->net);
7682 sp->net = NULL;
7684 if (sp->data) {
7685 sctp_m_freem(sp->data);
7686 sp->data = NULL;
7690 asoc->chunks_on_out_queue++;
7691 strq->chunks_on_queues++;
7692 TAILQ_INSERT_TAIL(&asoc->send_queue, chk, sctp_next);
7693 asoc->send_queue_cnt++;
7709 asoc = &stcb->asoc;
7711 switch (net->ro._l_addr.sa.sa_family) {
7714 space_left = net->mtu - SCTP_MIN_V4_OVERHEAD;
7719 space_left = net->mtu - SCTP_MIN_OVERHEAD;
7724 space_left = net->mtu;
7728 space_left -= SCTP_DATA_CHUNK_OVERHEAD(stcb);
7732 strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc);
7742 strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc);
7745 space_left -= moved;
7750 space_left -= SCTP_DATA_CHUNK_OVERHEAD(stcb);
7759 stcb->asoc.ss_functions.sctp_ss_packet_done(stcb, net, asoc);
7762 if ((stcb->asoc.sctp_cmt_on_off == 0) &&
7763 (net == stcb->asoc.primary_destination)) {
7766 } else if (stcb->asoc.sctp_cmt_on_off > 0) {
7778 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
7779 if (chk->rec.chunk_id.id == SCTP_ECN_ECHO) {
7780 chk->sent = SCTP_DATAGRAM_UNSENT;
7796 asoc = &stcb->asoc;
7797 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
7798 TAILQ_FOREACH(sp, &stcb->asoc.strmout[i].outqueue, next) {
7799 if (sp->net == net) {
7800 sctp_free_remote_addr(sp->net);
7801 sp->net = NULL;
7805 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
7806 if (chk->whoTo == net) {
7807 sctp_free_remote_addr(chk->whoTo);
7808 chk->whoTo = NULL;
7826 * - Service the stream queue that is next, moving any
7830 * chunks its ok to not send the entire message ;-)
7831 * - Check to see if the cwnd/rwnd allows any output, if so we go ahead and
7856 * JRS 5/14/07 - Add flag for whether a heartbeat is sent to the
7864 auth_keyid = stcb->asoc.authinfo.active_keyid;
7865 if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
7889 if ((TAILQ_EMPTY(&asoc->control_send_queue) ||
7890 (asoc->ctrl_queue_cnt == stcb->asoc.ecn_echo_cnt_onq)) &&
7891 TAILQ_EMPTY(&asoc->asconf_send_queue) &&
7892 TAILQ_EMPTY(&asoc->send_queue) &&
7898 if (asoc->peers_rwnd == 0) {
7901 if (asoc->total_flight > 0) {
7906 if (stcb->asoc.ecn_echo_cnt_onq) {
7909 (asoc->ctrl_queue_cnt == stcb->asoc.ecn_echo_cnt_onq)) {
7910 /* Nothing but ECNe to send - we don't do that */
7913 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
7914 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) ||
7915 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) {
7916 sack_goes_to = chk->whoTo;
7921 max_rwnd_per_dest = ((asoc->peers_rwnd + asoc->total_flight) / asoc->numnets);
7922 if (stcb->sctp_socket)
7923 max_send_per_dest = SCTP_SB_LIMIT_SND(stcb->sctp_socket) / asoc->numnets;
7927 /* How many non-directed chunks are there? */
7928 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
7929 if (chk->whoTo == NULL) {
7931 * We already have non-directed chunks on
7932 * the queue, no need to do a fill-up.
7941 (!stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, asoc))) {
7942 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
7954 net->window_probe = 0;
7955 if ((net != stcb->asoc.alternate) &&
7956 ((net->dest_state & SCTP_ADDR_PF) ||
7957 ((net->dest_state & SCTP_ADDR_REACHABLE) == 0) ||
7958 (net->dest_state & SCTP_ADDR_UNCONFIRMED))) {
7965 if ((stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins) &&
7966 (net->flight_size == 0)) {
7967 (*stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins) (stcb, net);
7969 if (net->flight_size >= net->cwnd) {
7970 /* skip this network, no room - can't fill */
7990 if (TAILQ_EMPTY(&asoc->control_send_queue) &&
7991 TAILQ_EMPTY(&asoc->asconf_send_queue) &&
7992 TAILQ_EMPTY(&asoc->send_queue)) {
7997 if (asoc->sctp_cmt_on_off > 0) {
7999 start_at = asoc->last_net_cmt_send_started;
8002 start_at = TAILQ_FIRST(&asoc->nets);
8004 start_at = TAILQ_NEXT(asoc->last_net_cmt_send_started, sctp_next);
8006 start_at = TAILQ_FIRST(&asoc->nets);
8009 asoc->last_net_cmt_send_started = start_at;
8011 start_at = TAILQ_FIRST(&asoc->nets);
8013 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
8014 if (chk->whoTo == NULL) {
8015 if (asoc->alternate) {
8016 chk->whoTo = asoc->alternate;
8018 chk->whoTo = asoc->primary_destination;
8020 atomic_add_int(&chk->whoTo->ref_count, 1);
8033 if (TAILQ_EMPTY(&asoc->control_send_queue) &&
8034 TAILQ_EMPTY(&asoc->asconf_send_queue) &&
8035 (net->flight_size >= net->cwnd)) {
8048 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
8053 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
8056 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD;
8061 mtu = net->mtu - SCTP_MIN_OVERHEAD;
8066 mtu = net->mtu;
8071 if (mtu > asoc->peers_rwnd) {
8072 if (asoc->total_flight > 0) {
8074 r_mtu = asoc->peers_rwnd;
8088 TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) {
8089 if (chk->rec.chunk_id.id != SCTP_ASCONF) {
8092 if (chk->whoTo == NULL) {
8093 if (asoc->alternate == NULL) {
8094 if (asoc->primary_destination != net) {
8098 if (asoc->alternate != net) {
8103 if (chk->whoTo != net) {
8107 if (chk->data == NULL) {
8110 if (chk->sent != SCTP_DATAGRAM_UNSENT &&
8111 chk->sent != SCTP_DATAGRAM_RESEND) {
8123 sctp_auth_is_required_chunk(chk->rec.chunk_id.id,
8124 stcb->asoc.peer_auth_chunks)) {
8125 omtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
8129 if ((chk->send_size < (int)(mtu - omtu)) ||
8130 (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) {
8133 * from the chk->data for control but the
8146 (sctp_auth_is_required_chunk(chk->rec.chunk_id.id,
8147 stcb->asoc.peer_auth_chunks))) {
8153 chk->rec.chunk_id.id);
8156 outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain,
8157 (int)chk->rec.chunk_id.can_take_data,
8158 chk->send_size, chk->copy_by_ref);
8166 if (mtu > (chk->send_size + omtu))
8167 mtu -= (chk->send_size + omtu);
8170 to_out += (chk->send_size + omtu);
8172 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) {
8175 if (chk->rec.chunk_id.can_take_data)
8176 chk->data = NULL;
8188 chk->sent = SCTP_DATAGRAM_SENT;
8189 if (chk->whoTo == NULL) {
8190 chk->whoTo = net;
8191 atomic_add_int(&net->ref_count, 1);
8193 chk->snd_count++;
8211 net->last_sent_time = *now;
8214 (struct sockaddr *)&net->ro._l_addr,
8216 stcb->asoc.authinfo.active_keyid,
8218 inp->sctp_lport, stcb->rport,
8219 htonl(stcb->asoc.peer_vtag),
8220 net->port, NULL,
8232 asoc->ifp_had_enobuf = 1;
8248 asoc->ifp_had_enobuf = 0;
8262 switch (net->ro._l_addr.sa.sa_family) {
8265 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD;
8270 mtu = net->mtu - SCTP_MIN_OVERHEAD;
8275 mtu = net->mtu;
8291 TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) {
8293 (chk->rec.chunk_id.id == SCTP_ECN_ECHO) &&
8294 (chk->whoTo != sack_goes_to)) {
8300 if (chk->whoTo == net) {
8314 if (chk->whoTo == NULL) {
8315 if (asoc->alternate == NULL) {
8316 if (asoc->primary_destination != net) {
8320 if (asoc->alternate != net) {
8325 if (chk->whoTo != net) {
8330 if (chk->data == NULL) {
8333 if (chk->sent != SCTP_DATAGRAM_UNSENT) {
8350 sctp_auth_is_required_chunk(chk->rec.chunk_id.id,
8351 stcb->asoc.peer_auth_chunks)) {
8352 omtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
8356 if ((chk->send_size <= (int)(mtu - omtu)) ||
8357 (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) {
8360 * from the chk->data for control but the
8373 (sctp_auth_is_required_chunk(chk->rec.chunk_id.id,
8374 stcb->asoc.peer_auth_chunks))) {
8380 chk->rec.chunk_id.id);
8383 outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain,
8384 (int)chk->rec.chunk_id.can_take_data,
8385 chk->send_size, chk->copy_by_ref);
8393 if (mtu > (chk->send_size + omtu))
8394 mtu -= (chk->send_size + omtu);
8397 to_out += (chk->send_size + omtu);
8399 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) {
8402 if (chk->rec.chunk_id.can_take_data)
8403 chk->data = NULL;
8405 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) ||
8406 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK) || /* EY */
8407 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) ||
8408 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_ACK) ||
8409 (chk->rec.chunk_id.id == SCTP_SHUTDOWN) ||
8410 (chk->rec.chunk_id.id == SCTP_SHUTDOWN_ACK) ||
8411 (chk->rec.chunk_id.id == SCTP_OPERATION_ERROR) ||
8412 (chk->rec.chunk_id.id == SCTP_COOKIE_ACK) ||
8413 (chk->rec.chunk_id.id == SCTP_ECN_CWR) ||
8414 (chk->rec.chunk_id.id == SCTP_PACKET_DROPPED) ||
8415 (chk->rec.chunk_id.id == SCTP_ASCONF_ACK)) {
8416 if (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) {
8420 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) ||
8421 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) {
8423 if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
8438 if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) {
8441 } else if (chk->rec.chunk_id.id == SCTP_ECN_ECHO) {
8445 * over-zealous in our
8456 chk->sent = SCTP_DATAGRAM_SENT;
8457 if (chk->whoTo == NULL) {
8458 chk->whoTo = net;
8459 atomic_add_int(&net->ref_count, 1);
8461 chk->snd_count++;
8470 switch (asoc->snd_edmid) {
8499 net->last_sent_time = *now;
8503 (struct sockaddr *)&net->ro._l_addr,
8506 stcb->asoc.authinfo.active_keyid,
8508 inp->sctp_lport, stcb->rport,
8509 htonl(stcb->asoc.peer_vtag),
8510 net->port, NULL,
8522 asoc->ifp_had_enobuf = 1;
8537 asoc->ifp_had_enobuf = 0;
8551 switch (net->ro._l_addr.sa.sa_family) {
8554 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD;
8559 mtu = net->mtu - SCTP_MIN_OVERHEAD;
8564 mtu = net->mtu;
8577 if ((asoc->sctp_cmt_on_off > 0) &&
8578 (net != stcb->asoc.alternate) &&
8579 (net->dest_state & SCTP_ADDR_PF)) {
8582 if (net->flight_size >= net->cwnd) {
8585 if ((asoc->sctp_cmt_on_off > 0) &&
8587 (net->flight_size > max_rwnd_per_dest)) {
8596 if ((asoc->sctp_cmt_on_off > 0) &&
8599 (net->flight_size > max_send_per_dest)) {
8612 stcb->asoc.peer_auth_chunks);
8614 mtu -= sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
8617 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) {
8620 if (net->mtu > SCTP_MIN_V4_OVERHEAD)
8621 omtu = net->mtu - SCTP_MIN_V4_OVERHEAD;
8628 if (net->mtu > SCTP_MIN_OVERHEAD)
8629 omtu = net->mtu - SCTP_MIN_OVERHEAD;
8643 TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) {
8649 if (net->flight_size >= net->cwnd) {
8654 if ((chk->whoTo != NULL) &&
8655 (chk->whoTo != net)) {
8660 if (asoc->sctp_cmt_on_off == 0) {
8661 if ((asoc->alternate) &&
8662 (asoc->alternate != net) &&
8663 (chk->whoTo == NULL)) {
8665 } else if ((net != asoc->primary_destination) &&
8666 (asoc->alternate == NULL) &&
8667 (chk->whoTo == NULL)) {
8671 if ((chk->send_size > omtu) && ((chk->flags & CHUNK_FLAGS_FRAGMENT_OK) == 0)) {
8672 /*-
8685 chk->send_size, mtu);
8686 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
8689 (asoc->state & SCTP_STATE_SHUTDOWN_PENDING)) {
8692 dchkh = mtod(chk->data, struct sctp_data_chunk *);
8693 dchkh->ch.chunk_flags |= SCTP_DATA_SACK_IMMEDIATELY;
8695 if (((chk->send_size <= mtu) && (chk->send_size <= r_mtu)) ||
8696 ((chk->flags & CHUNK_FLAGS_FRAGMENT_OK) && (chk->send_size <= asoc->peers_rwnd))) {
8712 auth_keyid = chk->auth_keyid;
8720 auth_keyid = chk->auth_keyid;
8722 } else if (auth_keyid != chk->auth_keyid) {
8730 outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, 0,
8731 chk->send_size, chk->copy_by_ref);
8734 if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
8743 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) {
8747 if (mtu > chk->send_size)
8748 mtu -= chk->send_size;
8752 if (r_mtu > chk->send_size)
8753 r_mtu -= chk->send_size;
8757 to_out += chk->send_size;
8766 chk->window_probe = 0;
8771 if (chk->sent == SCTP_DATAGRAM_UNSENT) {
8772 if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
8777 if (((chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) &&
8778 ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0))
8791 if ((one_chunk) && (stcb->asoc.total_flight == 0)) {
8792 data_list[0]->window_probe = 1;
8793 net->window_probe = 1;
8809 switch (asoc->snd_edmid) {
8834 if (bundle_at && (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer))) {
8847 net->last_sent_time = *now;
8853 (struct sockaddr *)&net->ro._l_addr,
8861 inp->sctp_lport, stcb->rport,
8862 htonl(stcb->asoc.peer_vtag),
8863 net->port, NULL,
8873 asoc->ifp_had_enobuf = 1;
8885 /*-
8895 asoc->ifp_had_enobuf = 0;
8906 tsns_sent = data_list[0]->rec.data.tsn;
8909 (void)SCTP_GETTIME_TIMEVAL(&asoc->time_last_sent);
8911 *now = asoc->time_last_sent;
8913 asoc->time_last_sent = *now;
8915 if (net->rto_needed) {
8916 data_list[0]->do_rtt = 1;
8917 net->rto_needed = 0;
8932 start_at = TAILQ_FIRST(&asoc->nets);
8956 /*-
8985 padding_length = 4 - padding_length;
8999 chk->copy_by_ref = 0;
9000 chk->rec.chunk_id.id = SCTP_OPERATION_ERROR;
9001 chk->rec.chunk_id.can_take_data = 0;
9002 chk->flags = 0;
9003 chk->send_size = (uint16_t)chunk_length;
9004 chk->sent = SCTP_DATAGRAM_UNSENT;
9005 chk->snd_count = 0;
9006 chk->asoc = &stcb->asoc;
9007 chk->data = op_err;
9008 chk->whoTo = NULL;
9010 hdr->chunk_type = SCTP_OPERATION_ERROR;
9011 hdr->chunk_flags = 0;
9012 hdr->chunk_length = htons(chk->send_size);
9013 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
9014 chk->asoc->ctrl_queue_cnt++;
9023 /*-
9041 return (-3);
9043 ptype = ntohs(phdr->param_type);
9044 plen = ntohs(phdr->param_length);
9046 return (-6);
9053 return (-7);
9058 return (-2);
9061 pad = 4 - pad;
9065 return (-8);
9080 hdr->chunk_type = SCTP_COOKIE_ECHO;
9081 hdr->chunk_flags = 0;
9087 return (-5);
9089 chk->copy_by_ref = 0;
9090 chk->rec.chunk_id.id = SCTP_COOKIE_ECHO;
9091 chk->rec.chunk_id.can_take_data = 0;
9092 chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
9093 chk->send_size = SCTP_SIZE32(plen);
9094 chk->sent = SCTP_DATAGRAM_UNSENT;
9095 chk->snd_count = 0;
9096 chk->asoc = &stcb->asoc;
9097 chk->data = cookie;
9098 chk->whoTo = net;
9099 atomic_add_int(&chk->whoTo->ref_count, 1);
9100 TAILQ_INSERT_HEAD(&chk->asoc->control_send_queue, chk, sctp_next);
9101 chk->asoc->ctrl_queue_cnt++;
9134 chdr->chunk_type = SCTP_HEARTBEAT_ACK;
9135 chdr->chunk_flags = 0;
9137 sctp_pad_lastmbuf(outchain, 4 - (chk_length % 4), NULL);
9145 chk->copy_by_ref = 0;
9146 chk->rec.chunk_id.id = SCTP_HEARTBEAT_ACK;
9147 chk->rec.chunk_id.can_take_data = 1;
9148 chk->flags = 0;
9149 chk->send_size = chk_length;
9150 chk->sent = SCTP_DATAGRAM_UNSENT;
9151 chk->snd_count = 0;
9152 chk->asoc = &stcb->asoc;
9153 chk->data = outchain;
9154 chk->whoTo = net;
9155 atomic_add_int(&chk->whoTo->ref_count, 1);
9156 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
9157 chk->asoc->ctrl_queue_cnt++;
9163 /* formulate and queue a cookie-ack back to sender */
9182 chk->copy_by_ref = 0;
9183 chk->rec.chunk_id.id = SCTP_COOKIE_ACK;
9184 chk->rec.chunk_id.can_take_data = 1;
9185 chk->flags = 0;
9186 chk->send_size = sizeof(struct sctp_chunkhdr);
9187 chk->sent = SCTP_DATAGRAM_UNSENT;
9188 chk->snd_count = 0;
9189 chk->asoc = &stcb->asoc;
9190 chk->data = cookie_ack;
9191 if (chk->asoc->last_control_chunk_from != NULL) {
9192 chk->whoTo = chk->asoc->last_control_chunk_from;
9193 atomic_add_int(&chk->whoTo->ref_count, 1);
9195 chk->whoTo = NULL;
9198 hdr->chunk_type = SCTP_COOKIE_ACK;
9199 hdr->chunk_flags = 0;
9200 hdr->chunk_length = htons(chk->send_size);
9201 SCTP_BUF_LEN(cookie_ack) = chk->send_size;
9202 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
9203 chk->asoc->ctrl_queue_cnt++;
9210 /* formulate and queue a SHUTDOWN-ACK back to the sender */
9227 chk->copy_by_ref = 0;
9228 chk->rec.chunk_id.id = SCTP_SHUTDOWN_ACK;
9229 chk->rec.chunk_id.can_take_data = 1;
9230 chk->flags = 0;
9231 chk->send_size = sizeof(struct sctp_chunkhdr);
9232 chk->sent = SCTP_DATAGRAM_UNSENT;
9233 chk->snd_count = 0;
9234 chk->asoc = &stcb->asoc;
9235 chk->data = m_shutdown_ack;
9236 chk->whoTo = net;
9237 if (chk->whoTo) {
9238 atomic_add_int(&chk->whoTo->ref_count, 1);
9241 ack_cp->ch.chunk_type = SCTP_SHUTDOWN_ACK;
9242 ack_cp->ch.chunk_flags = 0;
9243 ack_cp->ch.chunk_length = htons(chk->send_size);
9244 SCTP_BUF_LEN(m_shutdown_ack) = chk->send_size;
9245 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
9246 chk->asoc->ctrl_queue_cnt++;
9258 TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) {
9259 if (chk->rec.chunk_id.id == SCTP_SHUTDOWN) {
9261 if (chk->whoTo) {
9262 sctp_free_remote_addr(chk->whoTo);
9263 chk->whoTo = NULL;
9281 chk->copy_by_ref = 0;
9282 chk->rec.chunk_id.id = SCTP_SHUTDOWN;
9283 chk->rec.chunk_id.can_take_data = 1;
9284 chk->flags = 0;
9285 chk->send_size = sizeof(struct sctp_shutdown_chunk);
9286 chk->sent = SCTP_DATAGRAM_UNSENT;
9287 chk->snd_count = 0;
9288 chk->asoc = &stcb->asoc;
9289 chk->data = m_shutdown;
9290 chk->whoTo = net;
9291 if (chk->whoTo) {
9292 atomic_add_int(&chk->whoTo->ref_count, 1);
9295 shutdown_cp->ch.chunk_type = SCTP_SHUTDOWN;
9296 shutdown_cp->ch.chunk_flags = 0;
9297 shutdown_cp->ch.chunk_length = htons(chk->send_size);
9298 shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn);
9299 SCTP_BUF_LEN(m_shutdown) = chk->send_size;
9300 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
9301 chk->asoc->ctrl_queue_cnt++;
9303 TAILQ_REMOVE(&stcb->asoc.control_send_queue, chk, sctp_next);
9304 chk->whoTo = net;
9305 if (chk->whoTo) {
9306 atomic_add_int(&chk->whoTo->ref_count, 1);
9308 shutdown_cp = mtod(chk->data, struct sctp_shutdown_chunk *);
9309 shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn);
9310 TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next);
9328 if ((!TAILQ_EMPTY(&stcb->asoc.asconf_send_queue)) &&
9329 (!sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_MULTIPLE_ASCONFS))) {
9347 chk->copy_by_ref = 0;
9348 chk->rec.chunk_id.id = SCTP_ASCONF;
9349 chk->rec.chunk_id.can_take_data = 0;
9350 chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
9351 chk->data = m_asconf;
9352 chk->send_size = len;
9353 chk->sent = SCTP_DATAGRAM_UNSENT;
9354 chk->snd_count = 0;
9355 chk->asoc = &stcb->asoc;
9356 chk->whoTo = net;
9357 if (chk->whoTo) {
9358 atomic_add_int(&chk->whoTo->ref_count, 1);
9360 TAILQ_INSERT_TAIL(&chk->asoc->asconf_send_queue, chk, sctp_next);
9361 chk->asoc->ctrl_queue_cnt++;
9369 * formulate and queue a asconf-ack back to sender. the asconf-ack
9378 /* Get the latest ASCONF-ACK */
9379 latest_ack = TAILQ_LAST(&stcb->asoc.asconf_ack_sent, sctp_asconf_ackhead);
9383 if (latest_ack->last_sent_to != NULL &&
9384 latest_ack->last_sent_to == stcb->asoc.last_control_chunk_from) {
9386 net = sctp_find_alternate_net(stcb, stcb->asoc.last_control_chunk_from, 0);
9389 if (stcb->asoc.last_control_chunk_from == NULL) {
9390 if (stcb->asoc.alternate) {
9391 net = stcb->asoc.alternate;
9393 net = stcb->asoc.primary_destination;
9396 net = stcb->asoc.last_control_chunk_from;
9401 if (stcb->asoc.last_control_chunk_from == NULL) {
9402 if (stcb->asoc.alternate) {
9403 net = stcb->asoc.alternate;
9405 net = stcb->asoc.primary_destination;
9408 net = stcb->asoc.last_control_chunk_from;
9411 latest_ack->last_sent_to = net;
9413 TAILQ_FOREACH(ack, &stcb->asoc.asconf_ack_sent, next) {
9414 if (ack->data == NULL) {
9419 m_ack = SCTP_M_COPYM(ack->data, 0, M_COPYALL, M_NOWAIT);
9437 chk->copy_by_ref = 0;
9438 chk->rec.chunk_id.id = SCTP_ASCONF_ACK;
9439 chk->rec.chunk_id.can_take_data = 1;
9440 chk->flags = CHUNK_FLAGS_FRAGMENT_OK;
9441 chk->whoTo = net;
9442 if (chk->whoTo) {
9443 atomic_add_int(&chk->whoTo->ref_count, 1);
9445 chk->data = m_ack;
9446 chk->send_size = ack->len;
9447 chk->sent = SCTP_DATAGRAM_UNSENT;
9448 chk->snd_count = 0;
9449 chk->asoc = &stcb->asoc;
9451 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next);
9452 chk->asoc->ctrl_queue_cnt++;
9463 /*-
9473 * or t3-timeout routines).
9498 auth_keyid = stcb->asoc.authinfo.active_keyid;
9502 if ((TAILQ_EMPTY(&asoc->sent_queue)) &&
9503 (TAILQ_EMPTY(&asoc->control_send_queue))) {
9505 asoc->sent_queue_retran_cnt);
9506 asoc->sent_queue_cnt = 0;
9507 asoc->sent_queue_cnt_removeable = 0;
9512 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
9513 if ((chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) ||
9514 (chk->rec.chunk_id.id == SCTP_STREAM_RESET) ||
9515 (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN)) {
9516 if (chk->sent != SCTP_DATAGRAM_RESEND) {
9519 if (chk->rec.chunk_id.id == SCTP_STREAM_RESET) {
9520 if (chk != asoc->str_reset) {
9529 if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) {
9537 (sctp_auth_is_required_chunk(chk->rec.chunk_id.id,
9538 stcb->asoc.peer_auth_chunks))) {
9542 chk->rec.chunk_id.id);
9545 m = sctp_copy_mbufchain(chk->data, m, &endofchain, 0, chk->send_size, chk->copy_by_ref);
9553 switch (asoc->snd_edmid) {
9561 if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) {
9562 sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, inp, stcb, chk->whoTo);
9564 } else if (chk->rec.chunk_id.id == SCTP_ASCONF) {
9566 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, stcb, chk->whoTo);
9569 chk->snd_count++; /* update our count */
9570 if ((error = sctp_lowlevel_chunk_output(inp, stcb, chk->whoTo,
9571 (struct sockaddr *)&chk->whoTo->ro._l_addr, m,
9572 auth_offset, auth, stcb->asoc.authinfo.active_keyid,
9574 inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag),
9575 chk->whoTo->port, NULL,
9581 asoc->ifp_had_enobuf = 1;
9586 asoc->ifp_had_enobuf = 0;
9592 * We don't want to mark the net->sent time here since this
9595 /* (void)SCTP_GETTIME_TIMEVAL(&chk->whoTo->last_sent_time); */
9597 chk->sent = SCTP_DATAGRAM_SENT;
9598 sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt);
9602 /* Clean up the fwd-tsn list */
9609 * fwd-tsn with it all.
9611 if (TAILQ_EMPTY(&asoc->sent_queue)) {
9622 data_auth_reqd = sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks);
9623 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
9624 if (chk->sent != SCTP_DATAGRAM_RESEND) {
9628 if (chk->data == NULL) {
9629 SCTP_PRINTF("TSN:%x chk->snd_count:%d chk->sent:%d can't retran - no data\n",
9630 chk->rec.data.tsn, chk->snd_count, chk->sent);
9634 (chk->snd_count >= SCTP_BASE_SYSCTL(sctp_max_retran_chunk))) {
9639 chk->rec.data.tsn, chk->snd_count);
9642 atomic_add_int(&stcb->asoc.refcnt, 1);
9643 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err,
9646 atomic_subtract_int(&stcb->asoc.refcnt, 1);
9650 net = chk->whoTo;
9651 switch (net->ro._l_addr.sa.sa_family) {
9654 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD;
9659 mtu = net->mtu - SCTP_MIN_OVERHEAD;
9664 mtu = net->mtu;
9668 if ((asoc->peers_rwnd < mtu) && (asoc->total_flight > 0)) {
9672 tsn = asoc->last_acked_seq + 1;
9673 if (tsn == chk->rec.data.tsn) {
9685 if (asoc->peers_rwnd < mtu) {
9687 if ((asoc->peers_rwnd == 0) &&
9688 (asoc->total_flight == 0)) {
9689 chk->window_probe = 1;
9690 chk->whoTo->window_probe = 1;
9698 net->fast_retran_ip = 0;
9699 if (chk->rec.data.doing_fast_retransmit == 0) {
9704 if (net->flight_size >= net->cwnd) {
9713 net->fast_retran_ip = 1;
9723 dmtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
9727 if ((chk->send_size <= (mtu - dmtu)) ||
9728 (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) {
9738 auth_keyid = chk->auth_keyid;
9742 auth_keyid = chk->auth_keyid;
9744 } else if (chk->auth_keyid != auth_keyid) {
9749 m = sctp_copy_mbufchain(chk->data, m, &endofchain, 0, chk->send_size, chk->copy_by_ref);
9755 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) {
9759 if (mtu > (chk->send_size + dmtu))
9760 mtu -= (chk->send_size + dmtu);
9764 if (one_chunk && (asoc->total_flight <= 0)) {
9774 if (fwd->sent != SCTP_DATAGRAM_RESEND) {
9778 if (fwd->whoTo != net) {
9783 dmtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
9786 if (fwd->send_size <= (mtu - dmtu)) {
9795 auth_keyid = fwd->auth_keyid;
9799 auth_keyid = fwd->auth_keyid;
9801 } else if (fwd->auth_keyid != auth_keyid) {
9809 m = sctp_copy_mbufchain(fwd->data, m, &endofchain, 0, fwd->send_size, fwd->copy_by_ref);
9815 if (fwd->flags & CHUNK_FLAGS_FRAGMENT_OK) {
9819 if (mtu > (fwd->send_size + dmtu))
9820 mtu -= (fwd->send_size + dmtu);
9837 * timer. A failure is like a lost IP packet :-)
9839 if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
9847 switch (asoc->snd_edmid) {
9857 (struct sockaddr *)&net->ro._l_addr, m,
9860 inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag),
9861 net->port, NULL,
9868 asoc->ifp_had_enobuf = 1;
9873 asoc->ifp_had_enobuf = 0;
9880 * We don't want to mark the net->sent time here
9884 /* (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); */
9886 /* For auto-close */
9888 (void)SCTP_GETTIME_TIMEVAL(&asoc->time_last_sent);
9889 *now = asoc->time_last_sent;
9892 asoc->time_last_sent = *now;
9899 tsns_sent = data_list[0]->rec.data.tsn;
9903 data_list[i]->sent = SCTP_DATAGRAM_SENT;
9910 if (data_list[i]->rec.data.chunk_was_revoked) {
9912 data_list[i]->whoTo->cwnd -= data_list[i]->book_size;
9913 data_list[i]->rec.data.chunk_was_revoked = 0;
9915 data_list[i]->snd_count++;
9916 sctp_ucount_decr(asoc->sent_queue_retran_cnt);
9918 data_list[i]->sent_rcv_time = asoc->time_last_sent;
9919 if (data_list[i]->book_size_scale) {
9924 data_list[i]->book_size_scale = 0;
9931 atomic_add_int(&((asoc)->total_output_queue_size), data_list[i]->book_size);
9932 data_list[i]->book_size *= 2;
9936 asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh));
9938 asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd,
9939 (uint32_t)(data_list[i]->send_size +
9944 data_list[i]->whoTo->flight_size,
9945 data_list[i]->book_size,
9946 (uint32_t)(uintptr_t)data_list[i]->whoTo,
9947 data_list[i]->rec.data.tsn);
9951 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
9953 asoc->peers_rwnd = 0;
9956 (data_list[i]->rec.data.doing_fast_retransmit)) {
9958 if ((data_list[i] == TAILQ_FIRST(&asoc->sent_queue)) &&
9960 /*-
9961 * ok we just fast-retrans'd
9967 * t3-expiring.
9985 if (asoc->sent_queue_retran_cnt <= 0) {
9987 asoc->sent_queue_retran_cnt = 0;
10008 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
10009 if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
10017 if (asoc->alternate) {
10018 sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->alternate);
10020 sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->primary_destination);
10031 /*-
10034 * - See if there are retransmits pending, if so we must
10036 * - Service the stream queue that is next, moving any
10040 * - Check to see if the cwnd/rwnd allows any output, if so we
10056 asoc = &stcb->asoc;
10070 un_sent = (stcb->asoc.total_output_queue_size - stcb->asoc.total_flight);
10073 (TAILQ_EMPTY(&asoc->control_send_queue)) &&
10074 (TAILQ_EMPTY(&asoc->asconf_send_queue)) &&
10075 (asoc->sent_queue_retran_cnt == 0) &&
10076 (asoc->trigger_reset == 0)) {
10082 * running, if so piggy-back the sack.
10084 if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
10086 sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, NULL,
10089 while (asoc->sent_queue_retran_cnt) {
10090 /*-
10095 /*-
10097 * by peer that carried data. Send cookie-ack only
10120 /*-
10121 * now lets push out control by calling med-level
10135 /*-
10157 if ((asoc->fr_max_burst > 0) && (tot_frs >= asoc->fr_max_burst)) {
10158 /* Hit FR burst limit */
10170 TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
10171 if ((net->dest_state & SCTP_ADDR_REACHABLE) == 0) {
10172 /*-
10179 if (net->ref_count > 1)
10182 /*-
10183 * if ((asoc->sat_network) || (net->addr_is_local))
10184 * { burst_limit = asoc->max_burst *
10187 if (asoc->max_burst > 0) {
10189 if ((net->flight_size + (asoc->max_burst * net->mtu)) < net->cwnd) {
10191 * JRS - Use the congestion
10195 asoc->cc_functions.sctp_cwnd_update_after_output(stcb, net, asoc->max_burst);
10197 sctp_log_maxburst(stcb, net, 0, asoc->max_burst, SCTP_MAX_BURST_APPLIED);
10201 net->fast_retran_ip = 0;
10203 if (net->flight_size == 0) {
10220 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Error %d was returned from med-c-op\n", error);
10222 sctp_log_maxburst(stcb, asoc->primary_destination, error, burst_cnt, SCTP_MAX_BURST_ERROR_STOP);
10230 SCTPDBG(SCTP_DEBUG_OUTPUT3, "m-c-o put out %d\n", num_out);
10247 un_sent = stcb->asoc.total_output_queue_size - stcb->asoc.total_flight;
10248 if ((un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD)) &&
10249 (stcb->asoc.total_flight > 0)) {
10254 if (TAILQ_EMPTY(&asoc->control_send_queue) &&
10255 TAILQ_EMPTY(&asoc->send_queue) &&
10260 if ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) <= 0) {
10265 ((asoc->max_burst == 0) ||
10267 (burst_cnt < asoc->max_burst)));
10270 if ((asoc->max_burst > 0) && (burst_cnt >= asoc->max_burst)) {
10272 asoc->burst_limit_applied = 1;
10274 sctp_log_maxburst(stcb, asoc->primary_destination, 0, burst_cnt, SCTP_MAX_BURST_APPLIED);
10277 asoc->burst_limit_applied = 0;
10286 /*-
10291 if (stcb->asoc.ecn_echo_cnt_onq)
10294 if (stcb->asoc.trigger_reset) {
10316 if (inp->sctp_socket == NULL) {
10320 return (sctp_sosend(inp->sctp_socket,
10343 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
10344 if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) {
10346 chk->sent = SCTP_DATAGRAM_UNSENT;
10347 chk->snd_count = 0;
10349 if (chk->whoTo) {
10350 sctp_free_remote_addr(chk->whoTo);
10351 chk->whoTo = NULL;
10361 asoc->fwd_tsn_cnt++;
10362 chk->copy_by_ref = 0;
10364 * We don't do the old thing here since this is used not for on-wire
10365 * but to tell if we are sending a fwd-tsn by the stack during
10366 * output. And if its a IFORWARD or a FORWARD it is a fwd-tsn.
10368 chk->rec.chunk_id.id = SCTP_FORWARD_CUM_TSN;
10369 chk->rec.chunk_id.can_take_data = 0;
10370 chk->flags = 0;
10371 chk->asoc = asoc;
10372 chk->whoTo = NULL;
10373 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
10374 if (chk->data == NULL) {
10378 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
10379 chk->sent = SCTP_DATAGRAM_UNSENT;
10380 chk->snd_count = 0;
10381 TAILQ_INSERT_TAIL(&asoc->control_send_queue, chk, sctp_next);
10382 asoc->ctrl_queue_cnt++;
10384 /*-
10388 SCTP_BUF_LEN(chk->data) = 0;
10389 TAILQ_FOREACH(at, &asoc->sent_queue, sctp_next) {
10390 if ((at->sent != SCTP_FORWARD_TSN_SKIP) &&
10391 (at->sent != SCTP_DATAGRAM_NR_ACKED)) {
10395 if (!asoc->idata_supported && (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED)) {
10401 if (asoc->idata_supported) {
10408 cnt_of_space = (unsigned int)M_TRAILINGSPACE(chk->data);
10410 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
10415 if (cnt_of_space > (asoc->smallest_mtu - ovh)) {
10417 cnt_of_space = asoc->smallest_mtu - ovh;
10422 asoc->advanced_peer_ack_point);
10424 advance_peer_ack_point = asoc->advanced_peer_ack_point;
10426 /*-
10435 cnt_of_skipped = cnt_of_space - sizeof(struct sctp_forward_tsn_chunk);
10436 if (asoc->idata_supported) {
10441 /*-
10445 at = TAILQ_FIRST(&asoc->sent_queue);
10457 0xff, cnt_of_skipped, at->rec.data.tsn,
10458 asoc->advanced_peer_ack_point);
10461 /*-
10466 advance_peer_ack_point = last->rec.data.tsn;
10468 if (asoc->idata_supported) {
10476 chk->send_size = space_needed;
10478 fwdtsn = mtod(chk->data, struct sctp_forward_tsn_chunk *);
10479 fwdtsn->ch.chunk_length = htons(chk->send_size);
10480 fwdtsn->ch.chunk_flags = 0;
10481 if (asoc->idata_supported) {
10482 fwdtsn->ch.chunk_type = SCTP_IFORWARD_CUM_TSN;
10484 fwdtsn->ch.chunk_type = SCTP_FORWARD_CUM_TSN;
10486 fwdtsn->new_cumulative_tsn = htonl(advance_peer_ack_point);
10487 SCTP_BUF_LEN(chk->data) = chk->send_size;
10489 /*-
10493 if (asoc->idata_supported) {
10500 /*-
10508 * one FWD-TSN. With a bit of work we can later FIX this to
10513 TAILQ_FOREACH(at, &asoc->sent_queue, sctp_next) {
10517 if (!asoc->idata_supported && (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED)) {
10521 if (at->rec.data.tsn == advance_peer_ack_point) {
10522 at->rec.data.fwd_tsn_cnt = 0;
10524 if (asoc->idata_supported) {
10525 strseq_m->sid = htons(at->rec.data.sid);
10526 if (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED) {
10527 strseq_m->flags = htons(PR_SCTP_UNORDERED_FLAG);
10529 strseq_m->flags = 0;
10531 strseq_m->mid = htonl(at->rec.data.mid);
10534 strseq->sid = htons(at->rec.data.sid);
10535 strseq->ssn = htons((uint16_t)at->rec.data.mid);
10546 /*-
10547 * Queue up a SACK or NR-SACK in the control queue.
10548 * We must first check to see if a SACK or NR-SACK is
10572 if (stcb->asoc.nrsack_supported == 1) {
10578 asoc = &stcb->asoc;
10580 if (asoc->last_data_chunk_from == NULL) {
10586 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
10587 if (chk->rec.chunk_id.id == type) {
10589 TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next);
10590 asoc->ctrl_queue_cnt--;
10592 if (a_chk->data) {
10593 sctp_m_freem(a_chk->data);
10594 a_chk->data = NULL;
10596 if (a_chk->whoTo) {
10597 sctp_free_remote_addr(a_chk->whoTo);
10598 a_chk->whoTo = NULL;
10607 if (stcb->asoc.delayed_ack) {
10609 stcb->sctp_ep, stcb, NULL,
10612 stcb->sctp_ep, stcb, NULL);
10614 stcb->asoc.send_sack = 1;
10618 a_chk->copy_by_ref = 0;
10619 a_chk->rec.chunk_id.id = type;
10620 a_chk->rec.chunk_id.can_take_data = 1;
10623 asoc->data_pkts_seen = 0;
10625 a_chk->flags = 0;
10626 a_chk->asoc = asoc;
10627 a_chk->snd_count = 0;
10628 a_chk->send_size = 0; /* fill in later */
10629 a_chk->sent = SCTP_DATAGRAM_UNSENT;
10630 a_chk->whoTo = NULL;
10632 if ((asoc->last_data_chunk_from->dest_state & SCTP_ADDR_REACHABLE) == 0) {
10633 /*-
10635 * we can select an alternate to asoc->last_data_chunk_from
10637 a_chk->whoTo = sctp_find_alternate_net(stcb, asoc->last_data_chunk_from, 0);
10638 if (a_chk->whoTo == NULL) {
10640 a_chk->whoTo = asoc->last_data_chunk_from;
10643 a_chk->whoTo = asoc->last_data_chunk_from;
10645 if (a_chk->whoTo) {
10646 atomic_add_int(&a_chk->whoTo->ref_count, 1);
10648 if (SCTP_TSN_GT(asoc->highest_tsn_inside_map, asoc->highest_tsn_inside_nr_map)) {
10649 highest_tsn = asoc->highest_tsn_inside_map;
10651 highest_tsn = asoc->highest_tsn_inside_nr_map;
10653 if (highest_tsn == asoc->cumulative_tsn) {
10665 a_chk->data = sctp_get_mbuf_for_msg(space_req, 0, M_NOWAIT, 1, MT_DATA);
10666 if ((a_chk->data == NULL) ||
10667 (a_chk->whoTo == NULL)) {
10669 if (a_chk->data) {
10671 sctp_m_freem(a_chk->data);
10672 a_chk->data = NULL;
10676 if (stcb->asoc.delayed_ack) {
10678 stcb->sctp_ep, stcb, NULL,
10681 stcb->sctp_ep, stcb, NULL);
10683 stcb->asoc.send_sack = 1;
10688 SCTP_BUF_RESV_UF(a_chk->data, SCTP_MIN_OVERHEAD);
10689 space = (unsigned int)M_TRAILINGSPACE(a_chk->data);
10690 if (space > (a_chk->whoTo->mtu - SCTP_MIN_OVERHEAD)) {
10691 space = (a_chk->whoTo->mtu - SCTP_MIN_OVERHEAD);
10693 limit = mtod(a_chk->data, caddr_t);
10698 if ((asoc->sctp_cmt_on_off > 0) &&
10700 /*-
10705 flags |= (asoc->cmt_dac_pkts_rcvd << 6);
10706 asoc->cmt_dac_pkts_rcvd = 0;
10709 stcb->asoc.cumack_logsnt[stcb->asoc.cumack_log_atsnt] = asoc->cumulative_tsn;
10710 stcb->asoc.cumack_log_atsnt++;
10711 if (stcb->asoc.cumack_log_atsnt >= SCTP_TSN_LOG_SIZE) {
10712 stcb->asoc.cumack_log_atsnt = 0;
10716 stcb->freed_by_sorcv_sincelast = 0;
10719 sack = mtod(a_chk->data, struct sctp_sack_chunk *);
10722 if (highest_tsn > asoc->mapping_array_base_tsn) {
10723 siz = (((highest_tsn - asoc->mapping_array_base_tsn) + 1) + 7) / 8;
10725 siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + highest_tsn + 7) / 8;
10729 nr_sack = mtod(a_chk->data, struct sctp_nr_sack_chunk *);
10731 if (asoc->highest_tsn_inside_map > asoc->mapping_array_base_tsn) {
10732 siz = (((asoc->highest_tsn_inside_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8;
10734 siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_map + 7) / 8;
10738 if (SCTP_TSN_GT(asoc->mapping_array_base_tsn, asoc->cumulative_tsn)) {
10741 offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn;
10744 SCTP_TSN_GT(highest_tsn, asoc->cumulative_tsn)) ||
10746 SCTP_TSN_GT(asoc->highest_tsn_inside_map, asoc->cumulative_tsn))) {
10749 tsn_map = asoc->mapping_array[i];
10751 tsn_map |= asoc->nr_mapping_array[i];
10758 tsn_map &= (~0U << (1 - offset));
10761 if (mergeable && selector->right_edge) {
10766 num_gap_blocks--;
10767 gap_descriptor--;
10769 if (selector->num_entries == 0)
10772 for (j = 0; j < selector->num_entries; j++) {
10773 if (mergeable && selector->right_edge) {
10785 gap_descriptor->start = htons((selector->gaps[j].start + offset));
10787 gap_descriptor->end = htons((selector->gaps[j].end + offset));
10796 if (selector->left_edge) {
10811 if (asoc->highest_tsn_inside_nr_map > asoc->mapping_array_base_tsn) {
10812 siz = (((asoc->highest_tsn_inside_nr_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8;
10814 siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_nr_map + 7) / 8;
10817 if (SCTP_TSN_GT(asoc->mapping_array_base_tsn, asoc->cumulative_tsn)) {
10820 offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn;
10822 if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->cumulative_tsn)) {
10825 tsn_map = asoc->nr_mapping_array[i];
10832 tsn_map &= (~0U << (1 - offset));
10835 if (mergeable && selector->right_edge) {
10840 num_nr_gap_blocks--;
10841 gap_descriptor--;
10843 if (selector->num_entries == 0)
10846 for (j = 0; j < selector->num_entries; j++) {
10847 if (mergeable && selector->right_edge) {
10860 gap_descriptor->start = htons((selector->gaps[j].start + offset));
10862 gap_descriptor->end = htons((selector->gaps[j].end + offset));
10871 if (selector->left_edge) {
10884 if ((limit_reached == 0) && (asoc->numduptsns)) {
10886 for (i = 0; i < asoc->numduptsns; i++) {
10887 *dup = htonl(asoc->dup_tsns[i]);
10895 asoc->numduptsns = 0;
10902 a_chk->send_size = (uint16_t)(sizeof(struct sctp_sack_chunk) +
10905 SCTP_BUF_LEN(a_chk->data) = a_chk->send_size;
10906 sack->sack.cum_tsn_ack = htonl(asoc->cumulative_tsn);
10907 sack->sack.a_rwnd = htonl(asoc->my_rwnd);
10908 sack->sack.num_gap_ack_blks = htons(num_gap_blocks);
10909 sack->sack.num_dup_tsns = htons(num_dups);
10910 sack->ch.chunk_type = type;
10911 sack->ch.chunk_flags = flags;
10912 sack->ch.chunk_length = htons(a_chk->send_size);
10914 a_chk->send_size = (uint16_t)(sizeof(struct sctp_nr_sack_chunk) +
10917 SCTP_BUF_LEN(a_chk->data) = a_chk->send_size;
10918 nr_sack->nr_sack.cum_tsn_ack = htonl(asoc->cumulative_tsn);
10919 nr_sack->nr_sack.a_rwnd = htonl(asoc->my_rwnd);
10920 nr_sack->nr_sack.num_gap_ack_blks = htons(num_gap_blocks);
10921 nr_sack->nr_sack.num_nr_gap_ack_blks = htons(num_nr_gap_blocks);
10922 nr_sack->nr_sack.num_dup_tsns = htons(num_dups);
10923 nr_sack->nr_sack.reserved = 0;
10924 nr_sack->ch.chunk_type = type;
10925 nr_sack->ch.chunk_flags = flags;
10926 nr_sack->ch.chunk_length = htons(a_chk->send_size);
10928 TAILQ_INSERT_TAIL(&asoc->control_send_queue, a_chk, sctp_next);
10929 asoc->my_last_reported_rwnd = asoc->my_rwnd;
10930 asoc->ctrl_queue_cnt++;
10931 asoc->send_sack = 0;
10951 /*-
10956 stcb->asoc.peer_auth_chunks)) {
10963 switch (stcb->asoc.snd_edmid) {
10993 padding_len = SCTP_SIZE32(chunk_len) - chunk_len;
11002 if (stcb->asoc.alternate) {
11003 net = stcb->asoc.alternate;
11005 net = stcb->asoc.primary_destination;
11009 abort->ch.chunk_type = SCTP_ABORT_ASSOCIATION;
11010 if (stcb->asoc.peer_vtag == 0) {
11011 /* This happens iff the assoc is in COOKIE-WAIT state. */
11012 vtag = stcb->asoc.my_vtag;
11013 abort->ch.chunk_flags = SCTP_HAD_NO_TCB;
11015 vtag = stcb->asoc.peer_vtag;
11016 abort->ch.chunk_flags = 0;
11018 abort->ch.chunk_length = htons(chunk_len);
11027 if ((error = sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net,
11028 (struct sockaddr *)&net->ro._l_addr,
11029 m_out, auth_offset, auth, stcb->asoc.authinfo.active_keyid, 1, 0, 0,
11030 stcb->sctp_ep->sctp_lport, stcb->rport, htonl(vtag),
11031 stcb->asoc.primary_destination->port, NULL,
11037 stcb->asoc.ifp_had_enobuf = 1;
11041 stcb->asoc.ifp_had_enobuf = 0;
11051 /* formulate and SEND a SHUTDOWN-COMPLETE */
11066 vtag = stcb->asoc.my_vtag;
11069 vtag = stcb->asoc.peer_vtag;
11071 switch (stcb->asoc.snd_edmid) {
11080 shutdown_complete->ch.chunk_type = SCTP_SHUTDOWN_COMPLETE;
11081 shutdown_complete->ch.chunk_flags = flags;
11082 shutdown_complete->ch.chunk_length = htons(sizeof(struct sctp_shutdown_complete_chunk));
11084 if ((error = sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net,
11085 (struct sockaddr *)&net->ro._l_addr,
11087 stcb->sctp_ep->sctp_lport, stcb->rport,
11089 net->port, NULL,
11095 stcb->asoc.ifp_had_enobuf = 1;
11099 stcb->asoc.ifp_had_enobuf = 0;
11141 padding_len = 4 - padding_len;
11154 switch (dst->sa_family) {
11184 mout->m_pkthdr.flowid = mflowid;
11192 switch (dst->sa_family) {
11198 ip->ip_v = IPVERSION;
11199 ip->ip_hl = (sizeof(struct ip) >> 2);
11200 ip->ip_tos = 0;
11201 ip->ip_off = htons(IP_DF);
11203 ip->ip_ttl = MODULE_GLOBAL(ip_defttl);
11205 ip->ip_p = IPPROTO_UDP;
11207 ip->ip_p = IPPROTO_SCTP;
11209 ip->ip_src.s_addr = dst_sin->sin_addr.s_addr;
11210 ip->ip_dst.s_addr = src_sin->sin_addr.s_addr;
11211 ip->ip_sum = 0;
11221 ip6->ip6_flow = htonl(0x60000000);
11223 ip6->ip6_flow |= (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK);
11225 ip6->ip6_hlim = MODULE_GLOBAL(ip6_defhlim);
11227 ip6->ip6_nxt = IPPROTO_UDP;
11229 ip6->ip6_nxt = IPPROTO_SCTP;
11231 ip6->ip6_src = dst_sin6->sin6_addr;
11232 ip6->ip6_dst = src_sin6->sin6_addr;
11249 udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
11250 udp->uh_dport = port;
11251 udp->uh_sum = 0;
11252 udp->uh_ulen = htons((uint16_t)(sizeof(struct udphdr) +
11262 shout->src_port = sh->dest_port;
11263 shout->dest_port = sh->src_port;
11264 shout->checksum = 0;
11266 shout->v_tag = htonl(vtag);
11268 shout->v_tag = sh->v_tag;
11272 ch->chunk_type = type;
11274 ch->chunk_flags = 0;
11276 ch->chunk_flags = SCTP_HAD_NO_TCB;
11278 ch->chunk_length = htons((uint16_t)(sizeof(struct sctp_chunkhdr) + cause_len));
11287 switch (dst->sa_family) {
11292 udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP));
11294 udp->uh_sum = 0;
11297 ip->ip_len = htons(len);
11299 shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip) + sizeof(struct udphdr));
11305 mout->m_pkthdr.csum_flags = CSUM_SCTP;
11306 mout->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum);
11320 ip6->ip6_plen = htons((uint16_t)(len - sizeof(struct ip6_hdr)));
11322 shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip6_hdr) + sizeof(struct udphdr));
11324 if ((udp->uh_sum = in6_cksum(o_pak, IPPROTO_UDP, sizeof(struct ip6_hdr), len - sizeof(struct ip6_hdr))) == 0) {
11325 udp->uh_sum = 0xffff;
11328 mout->m_pkthdr.csum_flags = CSUM_SCTP_IPV6;
11329 mout->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum);
11343 dst->sa_family);
11384 switch (net->ro._l_addr.sa.sa_family) {
11402 chk->copy_by_ref = 0;
11403 chk->rec.chunk_id.id = SCTP_HEARTBEAT_REQUEST;
11404 chk->rec.chunk_id.can_take_data = 1;
11405 chk->flags = 0;
11406 chk->asoc = &stcb->asoc;
11407 chk->send_size = sizeof(struct sctp_heartbeat_chunk);
11409 chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER);
11410 if (chk->data == NULL) {
11414 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
11415 SCTP_BUF_LEN(chk->data) = chk->send_size;
11416 chk->sent = SCTP_DATAGRAM_UNSENT;
11417 chk->snd_count = 0;
11418 chk->whoTo = net;
11419 atomic_add_int(&chk->whoTo->ref_count, 1);
11421 hb = mtod(chk->data, struct sctp_heartbeat_chunk *);
11424 hb->ch.chunk_type = SCTP_HEARTBEAT_REQUEST;
11425 hb->ch.chunk_flags = 0;
11426 hb->ch.chunk_length = htons(chk->send_size);
11428 hb->heartbeat.hb_info.ph.param_type = htons(SCTP_HEARTBEAT_INFO);
11429 hb->heartbeat.hb_info.ph.param_length = htons(sizeof(struct sctp_heartbeat_info_param));
11430 hb->heartbeat.hb_info.time_value_1 = now.tv_sec;
11431 hb->heartbeat.hb_info.time_value_2 = now.tv_usec;
11433 hb->heartbeat.hb_info.addr_family = (uint8_t)net->ro._l_addr.sa.sa_family;
11434 hb->heartbeat.hb_info.addr_len = net->ro._l_addr.sa.sa_len;
11435 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
11440 net->heartbeat_random1 = hb->heartbeat.hb_info.random_value1 = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep);
11441 net->heartbeat_random2 = hb->heartbeat.hb_info.random_value2 = sctp_select_initial_TSN(&stcb->sctp_ep->sctp_ep);
11443 net->heartbeat_random1 = hb->heartbeat.hb_info.random_value1 = 0;
11444 net->heartbeat_random2 = hb->heartbeat.hb_info.random_value2 = 0;
11446 switch (net->ro._l_addr.sa.sa_family) {
11449 memcpy(hb->heartbeat.hb_info.address,
11450 &net->ro._l_addr.sin.sin_addr,
11451 sizeof(net->ro._l_addr.sin.sin_addr));
11456 memcpy(hb->heartbeat.hb_info.address,
11457 &net->ro._l_addr.sin6.sin6_addr,
11458 sizeof(net->ro._l_addr.sin6.sin6_addr));
11462 if (chk->data) {
11463 sctp_m_freem(chk->data);
11464 chk->data = NULL;
11470 net->hb_responded = 0;
11471 TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next);
11472 stcb->asoc.ctrl_queue_cnt++;
11488 asoc = &stcb->asoc;
11490 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
11491 if ((chk->rec.chunk_id.id == SCTP_ECN_ECHO) && (net == chk->whoTo)) {
11495 ecne = mtod(chk->data, struct sctp_ecne_chunk *);
11496 ctsn = ntohl(ecne->tsn);
11498 ecne->tsn = htonl(high_tsn);
11501 cnt = ntohl(ecne->num_pkts_since_cwr);
11503 ecne->num_pkts_since_cwr = htonl(cnt);
11513 chk->copy_by_ref = 0;
11514 chk->rec.chunk_id.id = SCTP_ECN_ECHO;
11515 chk->rec.chunk_id.can_take_data = 0;
11516 chk->flags = 0;
11517 chk->asoc = &stcb->asoc;
11518 chk->send_size = sizeof(struct sctp_ecne_chunk);
11519 chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER);
11520 if (chk->data == NULL) {
11524 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
11525 SCTP_BUF_LEN(chk->data) = chk->send_size;
11526 chk->sent = SCTP_DATAGRAM_UNSENT;
11527 chk->snd_count = 0;
11528 chk->whoTo = net;
11529 atomic_add_int(&chk->whoTo->ref_count, 1);
11531 stcb->asoc.ecn_echo_cnt_onq++;
11532 ecne = mtod(chk->data, struct sctp_ecne_chunk *);
11533 ecne->ch.chunk_type = SCTP_ECN_ECHO;
11534 ecne->ch.chunk_flags = 0;
11535 ecne->ch.chunk_length = htons(sizeof(struct sctp_ecne_chunk));
11536 ecne->tsn = htonl(high_tsn);
11537 ecne->num_pkts_since_cwr = htonl(1);
11538 TAILQ_INSERT_HEAD(&stcb->asoc.control_send_queue, chk, sctp_next);
11539 asoc->ctrl_queue_cnt++;
11560 asoc = &stcb->asoc;
11562 if (asoc->pktdrop_supported == 0) {
11563 /*-
11568 if (stcb->sctp_socket == NULL) {
11575 chk->copy_by_ref = 0;
11576 chk->rec.chunk_id.id = SCTP_PACKET_DROPPED;
11577 chk->rec.chunk_id.can_take_data = 1;
11578 chk->flags = 0;
11579 len -= iphlen;
11580 chk->send_size = len;
11586 chk_length = ntohs(ch->chunk_length);
11591 switch (ch->chunk_type) {
11596 * We don't respond with an PKT-DROP to an ABORT
11597 * or PKT-DROP. We also do not respond to an
11598 * INIT-ACK, because we can't know if the initiation
11612 min(stcb->asoc.smallest_mtu, MCLBYTES)) {
11617 len = min(stcb->asoc.smallest_mtu, MCLBYTES) - SCTP_MAX_OVERHEAD;
11620 chk->asoc = &stcb->asoc;
11621 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
11622 if (chk->data == NULL) {
11627 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
11628 drp = mtod(chk->data, struct sctp_pktdrop_chunk *);
11630 sctp_m_freem(chk->data);
11631 chk->data = NULL;
11634 chk->book_size = SCTP_SIZE32((chk->send_size + sizeof(struct sctp_pktdrop_chunk) +
11636 chk->book_size_scale = 0;
11638 drp->ch.chunk_flags = SCTP_PACKET_TRUNCATED;
11639 drp->trunc_len = htons(fullsz);
11644 chk->send_size = (uint16_t)(len - sizeof(struct sctp_pktdrop_chunk));
11645 len = chk->send_size;
11648 drp->ch.chunk_flags = 0;
11649 drp->trunc_len = htons(0);
11652 drp->ch.chunk_flags |= SCTP_BADCRC;
11654 chk->send_size += sizeof(struct sctp_pktdrop_chunk);
11655 SCTP_BUF_LEN(chk->data) = chk->send_size;
11656 chk->sent = SCTP_DATAGRAM_UNSENT;
11657 chk->snd_count = 0;
11660 chk->whoTo = net;
11661 atomic_add_int(&chk->whoTo->ref_count, 1);
11663 chk->whoTo = NULL;
11665 drp->ch.chunk_type = SCTP_PACKET_DROPPED;
11666 drp->ch.chunk_length = htons(chk->send_size);
11667 spc = SCTP_SB_LIMIT_RCV(stcb->sctp_socket);
11671 drp->bottle_bw = htonl(spc);
11672 if (asoc->my_rwnd) {
11673 drp->current_onq = htonl(asoc->size_on_reasm_queue +
11674 asoc->size_on_all_streams +
11675 asoc->my_rwnd_control_len +
11676 SCTP_SBAVAIL(&stcb->sctp_socket->so_rcv));
11678 /*-
11682 drp->current_onq = htonl(spc);
11684 drp->reserved = 0;
11685 datap = drp->data;
11687 TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next);
11688 asoc->ctrl_queue_cnt++;
11702 asoc = &stcb->asoc;
11703 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) {
11704 if ((chk->rec.chunk_id.id == SCTP_ECN_CWR) && (net == chk->whoTo)) {
11711 cwr = mtod(chk->data, struct sctp_cwr_chunk *);
11712 ctsn = ntohl(cwr->tsn);
11714 cwr->tsn = htonl(high_tsn);
11718 cwr->ch.chunk_flags |= SCTP_CWR_REDUCE_OVERRIDE;
11727 chk->copy_by_ref = 0;
11728 chk->rec.chunk_id.id = SCTP_ECN_CWR;
11729 chk->rec.chunk_id.can_take_data = 1;
11730 chk->flags = 0;
11731 chk->asoc = asoc;
11732 chk->send_size = sizeof(struct sctp_cwr_chunk);
11733 chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER);
11734 if (chk->data == NULL) {
11738 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
11739 SCTP_BUF_LEN(chk->data) = chk->send_size;
11740 chk->sent = SCTP_DATAGRAM_UNSENT;
11741 chk->snd_count = 0;
11742 chk->whoTo = net;
11743 atomic_add_int(&chk->whoTo->ref_count, 1);
11744 cwr = mtod(chk->data, struct sctp_cwr_chunk *);
11745 cwr->ch.chunk_type = SCTP_ECN_CWR;
11746 cwr->ch.chunk_flags = override;
11747 cwr->ch.chunk_length = htons(sizeof(struct sctp_cwr_chunk));
11748 cwr->tsn = htonl(high_tsn);
11749 TAILQ_INSERT_TAIL(&asoc->control_send_queue, chk, sctp_next);
11750 asoc->ctrl_queue_cnt++;
11763 ch = mtod(chk->data, struct sctp_chunkhdr *);
11764 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
11768 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
11769 if ((stcb->asoc.strmout[i].state == SCTP_STREAM_RESET_PENDING) &&
11770 (stcb->asoc.strmout[i].chunks_on_queues == 0) &&
11771 TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
11778 if (number_entries == stcb->asoc.streamoutcnt) {
11785 req_out->ph.param_type = htons(SCTP_STR_RESET_OUT_REQUEST);
11786 req_out->ph.param_length = htons(len);
11787 req_out->request_seq = htonl(seq);
11788 req_out->response_seq = htonl(resp_seq);
11789 req_out->send_reset_at_tsn = htonl(last_sent);
11792 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
11793 if ((stcb->asoc.strmout[i].state == SCTP_STREAM_RESET_PENDING) &&
11794 (stcb->asoc.strmout[i].chunks_on_queues == 0) &&
11795 TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) {
11796 req_out->list_of_streams[at] = htons(i);
11798 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_IN_FLIGHT;
11805 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
11806 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_IN_FLIGHT;
11810 /*-
11815 req_out->list_of_streams[number_entries] = 0;
11818 ch->chunk_length = htons(len + old_len);
11819 chk->book_size = len + old_len;
11820 chk->book_size_scale = 0;
11821 chk->send_size = SCTP_SIZE32(chk->book_size);
11822 SCTP_BUF_LEN(chk->data) = chk->send_size;
11835 ch = mtod(chk->data, struct sctp_chunkhdr *);
11836 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
11842 req_in->ph.param_type = htons(SCTP_STR_RESET_IN_REQUEST);
11843 req_in->ph.param_length = htons(len);
11844 req_in->request_seq = htonl(seq);
11847 req_in->list_of_streams[i] = htons(list[i]);
11851 /*-
11856 req_in->list_of_streams[number_entries] = 0;
11859 ch->chunk_length = htons(len + old_len);
11860 chk->book_size = len + old_len;
11861 chk->book_size_scale = 0;
11862 chk->send_size = SCTP_SIZE32(chk->book_size);
11863 SCTP_BUF_LEN(chk->data) = chk->send_size;
11875 ch = mtod(chk->data, struct sctp_chunkhdr *);
11876 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
11882 req_tsn->ph.param_type = htons(SCTP_STR_RESET_TSN_REQUEST);
11883 req_tsn->ph.param_length = htons(len);
11884 req_tsn->request_seq = htonl(seq);
11887 ch->chunk_length = htons(len + old_len);
11888 chk->send_size = len + old_len;
11889 chk->book_size = SCTP_SIZE32(chk->send_size);
11890 chk->book_size_scale = 0;
11891 SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size);
11903 ch = mtod(chk->data, struct sctp_chunkhdr *);
11904 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
11910 resp->ph.param_type = htons(SCTP_STR_RESET_RESPONSE);
11911 resp->ph.param_length = htons(len);
11912 resp->response_seq = htonl(resp_seq);
11913 resp->result = ntohl(result);
11916 ch->chunk_length = htons(len + old_len);
11917 chk->book_size = len + old_len;
11918 chk->book_size_scale = 0;
11919 chk->send_size = SCTP_SIZE32(chk->book_size);
11920 SCTP_BUF_LEN(chk->data) = chk->send_size;
11933 asoc = &stcb->asoc;
11936 * Reset our last reset action to the new one IP -> response
11940 asoc->last_reset_action[0] = response;
11941 if (asoc->stream_reset_outstanding) {
11949 chk->copy_by_ref = 0;
11950 chk->rec.chunk_id.id = SCTP_STREAM_RESET;
11951 chk->rec.chunk_id.can_take_data = 0;
11952 chk->flags = 0;
11953 chk->asoc = &stcb->asoc;
11954 chk->book_size = sizeof(struct sctp_chunkhdr);
11955 chk->send_size = SCTP_SIZE32(chk->book_size);
11956 chk->book_size_scale = 0;
11957 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
11958 if (chk->data == NULL) {
11963 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
11965 chk->sent = SCTP_DATAGRAM_UNSENT;
11966 chk->snd_count = 0;
11967 if (stcb->asoc.alternate) {
11968 chk->whoTo = stcb->asoc.alternate;
11970 chk->whoTo = stcb->asoc.primary_destination;
11972 ch = mtod(chk->data, struct sctp_chunkhdr *);
11973 ch->chunk_type = SCTP_STREAM_RESET;
11974 ch->chunk_flags = 0;
11975 ch->chunk_length = htons(chk->book_size);
11976 atomic_add_int(&chk->whoTo->ref_count, 1);
11977 SCTP_BUF_LEN(chk->data) = chk->send_size;
11978 sctp_add_stream_reset_result(chk, ent->seq, response);
11980 TAILQ_INSERT_TAIL(&asoc->control_send_queue,
11983 asoc->ctrl_queue_cnt++;
11995 ch = mtod(chk->data, struct sctp_chunkhdr *);
11996 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
12002 resp->ph.param_type = htons(SCTP_STR_RESET_RESPONSE);
12003 resp->ph.param_length = htons(len);
12004 resp->response_seq = htonl(resp_seq);
12005 resp->result = htonl(result);
12006 resp->senders_next_tsn = htonl(send_una);
12007 resp->receivers_next_tsn = htonl(recv_next);
12010 ch->chunk_length = htons(len + old_len);
12011 chk->book_size = len + old_len;
12012 chk->send_size = SCTP_SIZE32(chk->book_size);
12013 chk->book_size_scale = 0;
12014 SCTP_BUF_LEN(chk->data) = chk->send_size;
12027 ch = mtod(chk->data, struct sctp_chunkhdr *);
12028 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
12036 addstr->ph.param_type = htons(SCTP_STR_RESET_ADD_OUT_STREAMS);
12037 addstr->ph.param_length = htons(len);
12038 addstr->request_seq = htonl(seq);
12039 addstr->number_of_streams = htons(adding);
12040 addstr->reserved = 0;
12043 ch->chunk_length = htons(len + old_len);
12044 chk->send_size = len + old_len;
12045 chk->book_size = SCTP_SIZE32(chk->send_size);
12046 chk->book_size_scale = 0;
12047 SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size);
12060 ch = mtod(chk->data, struct sctp_chunkhdr *);
12061 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length));
12068 addstr->ph.param_type = htons(SCTP_STR_RESET_ADD_IN_STREAMS);
12069 addstr->ph.param_length = htons(len);
12070 addstr->request_seq = htonl(seq);
12071 addstr->number_of_streams = htons(adding);
12072 addstr->reserved = 0;
12075 ch->chunk_length = htons(len + old_len);
12076 chk->send_size = len + old_len;
12077 chk->book_size = SCTP_SIZE32(chk->send_size);
12078 chk->book_size_scale = 0;
12079 SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size);
12091 asoc = &stcb->asoc;
12092 asoc->trigger_reset = 0;
12093 if (asoc->stream_reset_outstanding) {
12101 chk->copy_by_ref = 0;
12102 chk->rec.chunk_id.id = SCTP_STREAM_RESET;
12103 chk->rec.chunk_id.can_take_data = 0;
12104 chk->flags = 0;
12105 chk->asoc = &stcb->asoc;
12106 chk->book_size = sizeof(struct sctp_chunkhdr);
12107 chk->send_size = SCTP_SIZE32(chk->book_size);
12108 chk->book_size_scale = 0;
12109 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
12110 if (chk->data == NULL) {
12115 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
12118 chk->sent = SCTP_DATAGRAM_UNSENT;
12119 chk->snd_count = 0;
12120 if (stcb->asoc.alternate) {
12121 chk->whoTo = stcb->asoc.alternate;
12123 chk->whoTo = stcb->asoc.primary_destination;
12125 ch = mtod(chk->data, struct sctp_chunkhdr *);
12126 ch->chunk_type = SCTP_STREAM_RESET;
12127 ch->chunk_flags = 0;
12128 ch->chunk_length = htons(chk->book_size);
12129 atomic_add_int(&chk->whoTo->ref_count, 1);
12130 SCTP_BUF_LEN(chk->data) = chk->send_size;
12131 seq = stcb->asoc.str_reset_seq_out;
12132 if (sctp_add_stream_reset_out(stcb, chk, seq, (stcb->asoc.str_reset_seq_in - 1), (stcb->asoc.sending_seq - 1))) {
12134 asoc->stream_reset_outstanding++;
12136 m_freem(chk->data);
12137 chk->data = NULL;
12141 asoc->str_reset = chk;
12143 TAILQ_INSERT_TAIL(&asoc->control_send_queue,
12146 asoc->ctrl_queue_cnt++;
12148 if (stcb->asoc.send_sack) {
12151 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo);
12172 asoc = &stcb->asoc;
12173 if (asoc->stream_reset_outstanding) {
12174 /*-
12193 if (number_entries > (MCLBYTES -
12194 SCTP_MIN_OVERHEAD -
12195 sizeof(struct sctp_chunkhdr) -
12206 chk->copy_by_ref = 0;
12207 chk->rec.chunk_id.id = SCTP_STREAM_RESET;
12208 chk->rec.chunk_id.can_take_data = 0;
12209 chk->flags = 0;
12210 chk->asoc = &stcb->asoc;
12211 chk->book_size = sizeof(struct sctp_chunkhdr);
12212 chk->send_size = SCTP_SIZE32(chk->book_size);
12213 chk->book_size_scale = 0;
12214 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
12215 if (chk->data == NULL) {
12220 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD);
12223 chk->sent = SCTP_DATAGRAM_UNSENT;
12224 chk->snd_count = 0;
12225 if (stcb->asoc.alternate) {
12226 chk->whoTo = stcb->asoc.alternate;
12228 chk->whoTo = stcb->asoc.primary_destination;
12230 atomic_add_int(&chk->whoTo->ref_count, 1);
12231 ch = mtod(chk->data, struct sctp_chunkhdr *);
12232 ch->chunk_type = SCTP_STREAM_RESET;
12233 ch->chunk_flags = 0;
12234 ch->chunk_length = htons(chk->book_size);
12235 SCTP_BUF_LEN(chk->data) = chk->send_size;
12237 seq = stcb->asoc.str_reset_seq_out;
12241 ret = sctp_add_stream_reset_out(stcb, chk, seq, (stcb->asoc.str_reset_seq_in - 1), (stcb->asoc.sending_seq - 1));
12244 asoc->stream_reset_outstanding++;
12248 ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < adding_o)) {
12257 oldstream = stcb->asoc.strmout;
12259 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *,
12260 (stcb->asoc.streamoutcnt + adding_o) * sizeof(struct sctp_stream_out),
12262 if (stcb->asoc.strmout == NULL) {
12265 stcb->asoc.strmout = oldstream;
12275 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, false);
12276 for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
12277 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
12283 stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], &oldstream[i]);
12284 stcb->asoc.strmout[i].chunks_on_queues = oldstream[i].chunks_on_queues;
12287 stcb->asoc.strmout[i].abandoned_sent[j] = oldstream[i].abandoned_sent[j];
12288 stcb->asoc.strmout[i].abandoned_unsent[j] = oldstream[i].abandoned_unsent[j];
12291 stcb->asoc.strmout[i].abandoned_sent[0] = oldstream[i].abandoned_sent[0];
12292 stcb->asoc.strmout[i].abandoned_unsent[0] = oldstream[i].abandoned_unsent[0];
12294 stcb->asoc.strmout[i].next_mid_ordered = oldstream[i].next_mid_ordered;
12295 stcb->asoc.strmout[i].next_mid_unordered = oldstream[i].next_mid_unordered;
12296 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete;
12297 stcb->asoc.strmout[i].sid = i;
12298 stcb->asoc.strmout[i].state = oldstream[i].state;
12302 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next);
12306 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc);
12307 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + adding_o); i++) {
12308 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue);
12309 stcb->asoc.strmout[i].chunks_on_queues = 0;
12312 stcb->asoc.strmout[i].abandoned_sent[j] = 0;
12313 stcb->asoc.strmout[i].abandoned_unsent[j] = 0;
12316 stcb->asoc.strmout[i].abandoned_sent[0] = 0;
12317 stcb->asoc.strmout[i].abandoned_unsent[0] = 0;
12319 stcb->asoc.strmout[i].next_mid_ordered = 0;
12320 stcb->asoc.strmout[i].next_mid_unordered = 0;
12321 stcb->asoc.strmout[i].sid = i;
12322 stcb->asoc.strmout[i].last_msg_incomplete = 0;
12323 stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], NULL);
12324 stcb->asoc.strmout[i].state = SCTP_STREAM_CLOSED;
12326 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + adding_o;
12331 asoc->strm_pending_add_size = adding_o;
12332 asoc->peer_req_out = peer_asked;
12335 asoc->stream_reset_outstanding++;
12340 asoc->stream_reset_outstanding++;
12345 asoc->stream_reset_outstanding++;
12349 asoc->stream_reset_outstanding++;
12351 asoc->str_reset = chk;
12353 TAILQ_INSERT_TAIL(&asoc->control_send_queue,
12356 asoc->ctrl_queue_cnt++;
12357 if (stcb->asoc.send_sack) {
12360 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo);
12422 sp->data = m_uiotombuf(uio, M_WAITOK, sp->length, resv_upfront, 0);
12423 if (sp->data == NULL) {
12428 sp->tail_mbuf = m_last(sp->data);
12443 /*-
12460 sp->act_flags = 0;
12461 sp->sender_all_done = 0;
12462 sp->sinfo_flags = srcv->sinfo_flags;
12463 sp->timetolive = srcv->sinfo_timetolive;
12464 sp->ppid = srcv->sinfo_ppid;
12465 sp->context = srcv->sinfo_context;
12466 sp->fsn = 0;
12467 (void)SCTP_GETTIME_TIMEVAL(&sp->ts);
12468 sp->sid = srcv->sinfo_stream;
12469 sp->length = (uint32_t)min(uio->uio_resid, max_send_len);
12470 if ((sp->length == (uint32_t)uio->uio_resid) &&
12472 (srcv->sinfo_flags & SCTP_EOF) ||
12473 (user_marks_eor && (srcv->sinfo_flags & SCTP_EOR)))) {
12474 sp->msg_is_complete = 1;
12476 sp->msg_is_complete = 0;
12478 sp->sender_all_done = 0;
12479 sp->some_taken = 0;
12480 sp->put_last_out = 0;
12482 sp->data = sp->tail_mbuf = NULL;
12483 if (sp->length == 0) {
12486 if (srcv->sinfo_keynumber_valid) {
12487 sp->auth_keyid = srcv->sinfo_keynumber;
12489 sp->auth_keyid = stcb->asoc.authinfo.active_keyid;
12491 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) {
12492 sctp_auth_key_acquire(stcb, sp->auth_keyid);
12493 sp->holds_key_ref = 1;
12501 if (sp->sinfo_flags & SCTP_ADDR_OVER) {
12502 sp->net = net;
12503 atomic_add_int(&sp->net->ref_count, 1);
12505 sp->net = NULL;
12531 /* process cmsg snd/rcv info (maybe a assoc-id) */
12537 if ((addr != NULL) && (addr->sa_family == AF_INET6)) {
12540 if (addr->sa_len != sizeof(struct sockaddr_in6)) {
12545 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
12612 switch (raddr->sa.sa_family) {
12615 if (raddr->sin.sin_len != sizeof(struct sockaddr_in)) {
12619 port = raddr->sin.sin_port;
12624 if (raddr->sin6.sin6_len != sizeof(struct sockaddr_in6)) {
12628 port = raddr->sin6.sin6_port;
12639 if (uio->uio_resid < 0) {
12643 sndlen = uio->uio_resid;
12650 t_inp = inp = (struct sctp_inpcb *)so->so_pcb;
12657 /*-
12664 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
12670 atomic_add_int(&inp->total_sends, 1);
12674 sinfo_assoc_id = sndrcvninfo->sinfo_assoc_id;
12675 sinfo_flags = sndrcvninfo->sinfo_flags;
12686 sinfo_flags = inp->def_send.sinfo_flags;
12687 sinfo_assoc_id = inp->def_send.sinfo_assoc_id;
12701 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) {
12708 if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
12709 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
12710 stcb = LIST_FIRST(&inp->sctp_asoc_list);
12722 /*-
12751 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
12752 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE)) {
12756 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) &&
12757 (addr->sa_family == AF_INET6)) {
12798 /*-
12799 * User asks to abort a non-existent assoc,
12800 * or EOF a non-existent assoc with no data
12806 vrf_id = inp->def_vrf_id;
12809 inp->sctp_ep.pre_open_stream_count,
12810 inp->sctp_ep.port,
12827 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered);
12840 /*-
12853 asoc = &stcb->asoc;
12854 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
12855 (asoc->state & SCTP_STATE_WAS_ABORTED)) {
12856 if (asoc->state & SCTP_STATE_WAS_ABORTED) {
12869 atomic_add_int(&asoc->refcnt, 1);
12873 sndrcvninfo_buf = asoc->def_send;
12875 sinfo_flags = sndrcvninfo->sinfo_flags;
12920 max_out = asoc->smallest_mtu - sizeof(struct sctp_paramhdr);
12921 max_out -= sizeof(struct sctp_abort_msg);
12926 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT);
12927 ph->param_length = htons((uint16_t)(sizeof(struct sctp_paramhdr) + tot_out));
12934 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
12935 (asoc->state & SCTP_STATE_WAS_ABORTED)) {
12937 if (asoc->state & SCTP_STATE_WAS_ABORTED) {
12949 /*-
12952 * send the users note :-0
12963 atomic_subtract_int(&asoc->refcnt, 1);
12967 sctp_abort_an_association(stcb->sctp_ep, stcb, mm, false, SCTP_SO_LOCKED);
12983 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
12985 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
12995 ((port != 0) && (port != stcb->rport))) {
13000 if (asoc->alternate != NULL) {
13001 net = asoc->alternate;
13003 net = asoc->primary_destination;
13016 if (sndlen > (ssize_t)asoc->smallest_mtu) {
13021 sinfo_stream = sndrcvninfo->sinfo_stream;
13023 if (sinfo_stream >= asoc->streamoutcnt) {
13028 if ((asoc->strmout[sinfo_stream].state != SCTP_STREAM_OPEN) &&
13029 (asoc->strmout[sinfo_stream].state != SCTP_STREAM_OPENING)) {
13033 if (asoc->strmout[sinfo_stream].state > SCTP_STREAM_OPEN) {
13040 atomic_add_int(&stcb->total_sends, 1);
13047 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13053 if ((SCTP_SB_LIMIT_SND(so) < (amount + inqueue_bytes + asoc->sb_send_resv)) ||
13054 (asoc->chunks_on_out_queue >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) {
13064 atomic_add_int(&asoc->sb_send_resv, (int)sndlen);
13069 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13071 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13076 p->td_ru.ru_msgsnd++;
13079 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13081 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes;
13087 (sndlen > (ssize_t)SCTP_SB_LIMIT_SND(stcb->sctp_socket))) {
13095 /*-
13096 * For non-eeor the whole message must fit in
13106 ((asoc->chunks_on_out_queue + asoc->stream_queue_cnt) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) {
13108 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13109 SOCKBUF_LOCK(&so->so_snd);
13111 ((asoc->stream_queue_cnt + asoc->chunks_on_out_queue) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) {
13116 asoc->stream_queue_cnt,
13117 asoc->chunks_on_out_queue,
13123 stcb->block_entry = &be;
13127 if (so->so_error != 0) {
13128 error = so->so_error;
13134 SOCKBUF_UNLOCK(&so->so_snd);
13136 stcb->block_entry = NULL;
13140 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
13141 (asoc->state & SCTP_STATE_WAS_ABORTED)) {
13142 if (asoc->state & SCTP_STATE_WAS_ABORTED) {
13155 asoc, asoc->total_output_queue_size);
13157 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13158 SOCKBUF_LOCK(&so->so_snd);
13161 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes;
13165 SOCKBUF_UNLOCK(&so->so_snd);
13171 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13173 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13177 * sndlen covers for mbuf case uio_resid covers for the non-mbuf
13185 if ((asoc->stream_locked) &&
13186 (asoc->stream_locked_on != sinfo_stream)) {
13190 strm = &asoc->strmout[sinfo_stream];
13191 if (strm->last_msg_incomplete == 0) {
13196 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
13197 (asoc->state & SCTP_STATE_WAS_ABORTED)) {
13198 if (asoc->state & SCTP_STATE_WAS_ABORTED) {
13219 (asoc->state & SCTP_STATE_SHUTDOWN_PENDING)) {
13220 if (sp->data != 0) {
13221 sctp_m_freem(sp->data);
13222 sp->data = NULL;
13223 sp->tail_mbuf = NULL;
13224 sp->length = 0;
13226 if (sp->net != NULL) {
13227 sctp_free_remote_addr(sp->net);
13228 sp->net = NULL;
13235 strm = &asoc->strmout[sinfo_stream];
13236 if (sp->msg_is_complete) {
13237 strm->last_msg_incomplete = 0;
13238 asoc->stream_locked = 0;
13244 strm->last_msg_incomplete = 1;
13245 if (asoc->idata_supported == 0) {
13246 asoc->stream_locked = 1;
13247 asoc->stream_locked_on = sinfo_stream;
13249 sp->sender_all_done = 0;
13251 sctp_snd_sb_alloc(stcb, sp->length);
13252 atomic_add_int(&asoc->stream_queue_cnt, 1);
13256 sp->processing = 1;
13257 TAILQ_INSERT_TAIL(&strm->outqueue, sp, next);
13258 asoc->ss_functions.sctp_ss_add_to_stream(stcb, asoc, strm, sp);
13260 sp = TAILQ_LAST(&strm->outqueue, sctp_streamhead);
13267 strm->last_msg_incomplete = 0;
13271 if (sp->processing != 0) {
13275 sp->processing = 1;
13281 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13283 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13286 while (uio->uio_resid > 0) {
13290 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13292 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes;
13298 (uio->uio_resid <= max_len)) {
13304 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
13305 (asoc->state & SCTP_STATE_WAS_ABORTED)) {
13311 if (asoc->state & SCTP_STATE_WAS_ABORTED) {
13328 sp->processing = 0;
13333 if (sp->tail_mbuf != NULL) {
13335 SCTP_BUF_NEXT(sp->tail_mbuf) = mm;
13338 sp->data = mm;
13340 sp->tail_mbuf = new_tail;
13342 atomic_add_int(&sp->length, sndout);
13344 sp->sinfo_flags |= SCTP_SACK_IMMEDIATELY;
13348 if ((uio->uio_resid == 0) &&
13352 sp->msg_is_complete = 1;
13354 sp->msg_is_complete = 0;
13360 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13362 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13365 if (uio->uio_resid == 0) {
13369 /* PR-SCTP? */
13370 if ((asoc->prsctp_supported) && (asoc->sent_queue_cnt_removeable > 0)) {
13376 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13378 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes;
13387 /* Non-blocking io in place out */
13389 sp->processing = 0;
13406 if ((net->flight_size > net->cwnd) &&
13407 (asoc->sctp_cmt_on_off == 0)) {
13410 } else if (asoc->ifp_had_enobuf) {
13412 if (net->flight_size > (2 * net->mtu)) {
13415 asoc->ifp_had_enobuf = 0;
13417 un_sent = asoc->total_output_queue_size - asoc->total_flight;
13419 (asoc->total_flight > 0) &&
13420 (asoc->stream_queue_cnt < SCTP_MAX_DATA_BUNDLING) &&
13421 (un_sent < (int)(asoc->smallest_mtu - SCTP_MIN_OVERHEAD))) {
13422 /*-
13443 sctp_misc_ints(SCTP_CWNDLOG_PRESEND, asoc->total_output_queue_size,
13444 asoc->total_flight,
13445 asoc->chunks_on_out_queue, asoc->total_flight_count);
13451 /*-
13456 * and I don't need to start output :-D
13463 /*-
13472 * LOCK the so->so_snd to do the actual sowwakeup(). So
13477 inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERHEAD(stcb));
13478 SOCKBUF_LOCK(&so->so_snd);
13483 asoc, uio->uio_resid);
13486 stcb->block_entry = &be;
13490 if (so->so_error != 0)
13491 error = so->so_error;
13496 SOCKBUF_UNLOCK(&so->so_snd);
13498 stcb->block_entry = NULL;
13499 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
13500 (asoc->state & SCTP_STATE_WAS_ABORTED)) {
13501 if (asoc->state & SCTP_STATE_WAS_ABORTED) {
13515 sp->processing = 0;
13520 SOCKBUF_UNLOCK(&so->so_snd);
13524 asoc, asoc->total_output_queue_size);
13530 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13532 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13536 strm = &asoc->strmout[sinfo_stream];
13538 if (sp->msg_is_complete == 0) {
13539 strm->last_msg_incomplete = 1;
13540 if (asoc->idata_supported == 0) {
13541 asoc->stream_locked = 1;
13542 asoc->stream_locked_on = sinfo_stream;
13545 sp->sender_all_done = 1;
13546 strm->last_msg_incomplete = 0;
13547 asoc->stream_locked = 0;
13549 sp->processing = 0;
13552 strm->last_msg_incomplete = 0;
13553 asoc->stream_locked = 0;
13555 if (uio->uio_resid == 0) {
13572 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13574 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13581 if (TAILQ_EMPTY(&asoc->send_queue) &&
13582 TAILQ_EMPTY(&asoc->sent_queue) &&
13584 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
13599 if (asoc->alternate != NULL) {
13600 netp = asoc->alternate;
13602 netp = asoc->primary_destination;
13605 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb,
13607 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb,
13611 /*-
13615 /*-
13619 * SHUTDOWN-PENDING
13624 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) {
13628 if (TAILQ_EMPTY(&asoc->send_queue) &&
13629 TAILQ_EMPTY(&asoc->sent_queue) &&
13630 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
13636 atomic_subtract_int(&asoc->refcnt, 1);
13644 sctp_abort_an_association(stcb->sctp_ep, stcb,
13659 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13661 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13664 some_on_control = !TAILQ_EMPTY(&asoc->control_send_queue);
13680 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13682 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13685 if ((net->flight_size > net->cwnd) &&
13686 (asoc->sctp_cmt_on_off == 0)) {
13689 } else if (asoc->ifp_had_enobuf) {
13691 if (net->flight_size > (2 * net->mtu)) {
13694 asoc->ifp_had_enobuf = 0;
13696 un_sent = asoc->total_output_queue_size - asoc->total_flight;
13698 (asoc->total_flight > 0) &&
13699 (asoc->stream_queue_cnt < SCTP_MAX_DATA_BUNDLING) &&
13700 (un_sent < (int)(asoc->smallest_mtu - SCTP_MIN_OVERHEAD))) {
13701 /*-
13722 sctp_misc_ints(SCTP_CWNDLOG_PRESEND, asoc->total_output_queue_size,
13723 asoc->total_flight,
13724 asoc->chunks_on_out_queue, asoc->total_flight_count);
13729 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13731 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13735 if ((queue_only == 0) && (nagle_applies == 0) && (asoc->peers_rwnd && un_sent)) {
13738 (asoc->peers_rwnd == 0) &&
13739 (asoc->total_flight == 0)) {
13753 queue_only, asoc->peers_rwnd, un_sent,
13754 asoc->total_flight, asoc->chunks_on_out_queue,
13755 asoc->total_output_queue_size, error);
13759 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0,
13761 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0,
13771 atomic_subtract_int(&asoc->sb_send_resv, (int)sndlen);
13774 atomic_subtract_int(&asoc->refcnt, 1);
13805 if (stcb->asoc.auth_supported == 0) {
13809 if (!sctp_auth_is_required_chunk(chunk, stcb->asoc.peer_auth_chunks)) {
13823 auth->ch.chunk_type = SCTP_AUTHENTICATION;
13824 auth->ch.chunk_flags = 0;
13826 sctp_get_hmac_digest_len(stcb->asoc.peer_hmac_id);
13827 auth->ch.chunk_length = htons(chunk_len);
13828 auth->hmac_id = htons(stcb->asoc.peer_hmac_id);
13854 if (ro == NULL || ro->ro_nh == NULL || src6->sin6_family != AF_INET6)
13860 if (pfx->ndpr_stateflags & NDPRF_DETACHED)
13862 if (IN6_ARE_MASKED_ADDR_EQUAL(&pfx->ndpr_prefix.sin6_addr,
13863 &src6->sin6_addr, &pfx->ndpr_mask))
13878 LIST_FOREACH(pfxrtr, &pfx->ndpr_advrtrs, pfr_entry) {
13882 memcpy(&gw6.sin6_addr, &pfxrtr->router->rtaddr,
13887 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ro->ro_nh->gw_sa);
13888 if (sctp_cmpaddr((struct sockaddr *)&gw6, &ro->ro_nh->gw_sa)) {
13908 if (ro == NULL || ro->ro_nh == NULL ||
13909 sifa->address.sa.sa_family != AF_INET) {
13912 ifa = (struct ifaddr *)sifa->ifa;
13913 mask = (struct sockaddr_in *)(ifa->ifa_netmask);
13914 sin = &sifa->address.sin;
13915 srcnetaddr.s_addr = (sin->sin_addr.s_addr & mask->sin_addr.s_addr);
13917 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa);
13920 sin = &ro->ro_nh->gw4_sa;
13921 gwnetaddr.s_addr = (sin->sin_addr.s_addr & mask->sin_addr.s_addr);
13923 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ro->ro_nh->gw_sa);