Lines Matching +full:rcv +full:- +full:sel
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) && in sctp_is_address_in_scope()
1869 (ifa->ifn_p) && SCTP_IFN_IS_IFT_LOOP(ifa->ifn_p)) { in sctp_is_address_in_scope()
1875 switch (ifa->address.sa.sa_family) { in sctp_is_address_in_scope()
1878 if (scope->ipv4_addr_legal) { in sctp_is_address_in_scope()
1881 sin = &ifa->address.sin; in sctp_is_address_in_scope()
1882 if (sin->sin_addr.s_addr == 0) { in sctp_is_address_in_scope()
1886 if ((scope->ipv4_local_scope == 0) && in sctp_is_address_in_scope()
1887 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) { in sctp_is_address_in_scope()
1898 if (scope->ipv6_addr_legal) { in sctp_is_address_in_scope()
1903 * IFA locks must now be applied HERE <-> in sctp_is_address_in_scope()
1908 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { in sctp_is_address_in_scope()
1912 sin6 = &ifa->address.sin6; in sctp_is_address_in_scope()
1913 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { in sctp_is_address_in_scope()
1918 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) { in sctp_is_address_in_scope()
1921 if ((scope->site_scope == 0) && in sctp_is_address_in_scope()
1922 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) { in sctp_is_address_in_scope()
1945 switch (ifa->address.sa.sa_family) { in sctp_add_addr_to_mbuf()
1979 switch (ifa->address.sa.sa_family) { in sctp_add_addr_to_mbuf()
1986 sin = &ifa->address.sin; in sctp_add_addr_to_mbuf()
1988 paramh->param_type = htons(SCTP_IPV4_ADDRESS); in sctp_add_addr_to_mbuf()
1989 paramh->param_length = htons(plen); in sctp_add_addr_to_mbuf()
1990 ipv4p->addr = sin->sin_addr.s_addr; in sctp_add_addr_to_mbuf()
2001 sin6 = &ifa->address.sin6; in sctp_add_addr_to_mbuf()
2003 paramh->param_type = htons(SCTP_IPV6_ADDRESS); in sctp_add_addr_to_mbuf()
2004 paramh->param_length = htons(plen); in sctp_add_addr_to_mbuf()
2005 memcpy(ipv6p->addr, &sin6->sin6_addr, in sctp_add_addr_to_mbuf()
2006 sizeof(ipv6p->addr)); in sctp_add_addr_to_mbuf()
2008 in6_clearscope((struct in6_addr *)ipv6p->addr); in sctp_add_addr_to_mbuf()
2033 vrf_id = inp->def_vrf_id; in sctp_add_addresses_to_i_ia()
2040 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { in sctp_add_addresses_to_i_ia()
2045 if (vrf->total_ifa_count > SCTP_COUNT_LIMIT) { in sctp_add_addresses_to_i_ia()
2050 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { in sctp_add_addresses_to_i_ia()
2051 if ((scope->loopback_scope == 0) && in sctp_add_addresses_to_i_ia()
2059 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { in sctp_add_addresses_to_i_ia()
2061 if ((sctp_ifap->address.sa.sa_family == AF_INET) && in sctp_add_addresses_to_i_ia()
2062 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_add_addresses_to_i_ia()
2063 &sctp_ifap->address.sin.sin_addr) != 0)) { in sctp_add_addresses_to_i_ia()
2068 if ((sctp_ifap->address.sa.sa_family == AF_INET6) && in sctp_add_addresses_to_i_ia()
2069 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_add_addresses_to_i_ia()
2070 &sctp_ifap->address.sin6.sin6_addr) != 0)) { in sctp_add_addresses_to_i_ia()
2092 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { in sctp_add_addresses_to_i_ia()
2094 if ((scope->loopback_scope == 0) && in sctp_add_addresses_to_i_ia()
2102 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { in sctp_add_addresses_to_i_ia()
2104 if ((sctp_ifap->address.sa.sa_family == AF_INET) && in sctp_add_addresses_to_i_ia()
2105 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_add_addresses_to_i_ia()
2106 &sctp_ifap->address.sin.sin_addr) != 0)) { in sctp_add_addresses_to_i_ia()
2111 if ((sctp_ifap->address.sa.sa_family == AF_INET6) && in sctp_add_addresses_to_i_ia()
2112 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_add_addresses_to_i_ia()
2113 &sctp_ifap->address.sin6.sin6_addr) != 0)) { in sctp_add_addresses_to_i_ia()
2156 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { in sctp_add_addresses_to_i_ia()
2157 if (laddr->ifa == NULL) { in sctp_add_addresses_to_i_ia()
2160 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) in sctp_add_addresses_to_i_ia()
2166 if (laddr->action == SCTP_DEL_IP_ADDRESS) { in sctp_add_addresses_to_i_ia()
2173 if (sctp_is_address_in_scope(laddr->ifa, in sctp_add_addresses_to_i_ia()
2186 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { in sctp_add_addresses_to_i_ia()
2187 if (laddr->ifa == NULL) { in sctp_add_addresses_to_i_ia()
2190 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) { in sctp_add_addresses_to_i_ia()
2193 if (sctp_is_address_in_scope(laddr->ifa, in sctp_add_addresses_to_i_ia()
2205 m_at = sctp_add_addr_to_mbuf(m_at, laddr->ifa, chunk_len); in sctp_add_addresses_to_i_ia()
2232 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2234 * ---------------------------------------- in sctp_is_ifa_addr_preferred()
2236 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2237 * P | L | yes-v4 no-v6 in sctp_is_ifa_addr_preferred()
2238 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2239 * G | L | yes-v4 no-v6 in sctp_is_ifa_addr_preferred()
2240 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2242 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2244 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2246 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2248 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2250 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2252 * ----------------------------------------- in sctp_is_ifa_addr_preferred()
2255 if (ifa->address.sa.sa_family != fam) { in sctp_is_ifa_addr_preferred()
2256 /* forget mis-matched family */ in sctp_is_ifa_addr_preferred()
2263 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ifa->address.sa); in sctp_is_ifa_addr_preferred()
2268 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { in sctp_is_ifa_addr_preferred()
2272 if (ifa->src_is_priv && !ifa->src_is_loop) { in sctp_is_ifa_addr_preferred()
2278 if (ifa->src_is_glob) { in sctp_is_ifa_addr_preferred()
2289 * straightforward and easier to validate :-) in sctp_is_ifa_addr_preferred()
2292 ifa->src_is_loop, ifa->src_is_priv, ifa->src_is_glob); in sctp_is_ifa_addr_preferred()
2296 if ((ifa->src_is_loop) && (dest_is_priv)) { in sctp_is_ifa_addr_preferred()
2300 if ((ifa->src_is_glob) && (dest_is_priv)) { in sctp_is_ifa_addr_preferred()
2304 if ((ifa->src_is_loop) && (dest_is_global)) { in sctp_is_ifa_addr_preferred()
2308 if ((ifa->src_is_priv) && (dest_is_global)) { in sctp_is_ifa_addr_preferred()
2332 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2334 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2336 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2337 * P | L | yes-v4 no-v6 in sctp_is_ifa_addr_acceptable()
2338 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2340 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2342 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2344 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2345 * G | P | yes - May not work in sctp_is_ifa_addr_acceptable()
2346 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2348 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2349 * P | G | yes - May not work in sctp_is_ifa_addr_acceptable()
2350 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2352 * ----------------------------------------- in sctp_is_ifa_addr_acceptable()
2355 if (ifa->address.sa.sa_family != fam) { in sctp_is_ifa_addr_acceptable()
2358 ifa->address.sa.sa_family, fam); in sctp_is_ifa_addr_acceptable()
2362 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, &ifa->address.sa); in sctp_is_ifa_addr_acceptable()
2371 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { in sctp_is_ifa_addr_acceptable()
2374 if (ifa->src_is_priv) { in sctp_is_ifa_addr_acceptable()
2384 * straightforward and easier to validate :-) in sctp_is_ifa_addr_acceptable()
2386 SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa->src_is_loop:%d dest_is_priv:%d\n", in sctp_is_ifa_addr_acceptable()
2387 ifa->src_is_loop, in sctp_is_ifa_addr_acceptable()
2389 if ((ifa->src_is_loop == 1) && (dest_is_priv)) { in sctp_is_ifa_addr_acceptable()
2392 SCTPDBG(SCTP_DEBUG_OUTPUT3, "ifa->src_is_loop:%d dest_is_glob:%d\n", in sctp_is_ifa_addr_acceptable()
2393 ifa->src_is_loop, in sctp_is_ifa_addr_acceptable()
2395 if ((ifa->src_is_loop == 1) && (dest_is_global)) { in sctp_is_ifa_addr_acceptable()
2409 /* There are no restrictions, no TCB :-) */ in sctp_is_addr_restricted()
2412 LIST_FOREACH(laddr, &stcb->asoc.sctp_restricted_addrs, sctp_nxt_addr) { in sctp_is_addr_restricted()
2413 if (laddr->ifa == NULL) { in sctp_is_addr_restricted()
2418 if (laddr->ifa == ifa) { in sctp_is_addr_restricted()
2433 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) { in sctp_is_addr_in_ep()
2434 if (laddr->ifa == NULL) { in sctp_is_addr_in_ep()
2439 if ((laddr->ifa == ifa) && laddr->action == 0) in sctp_is_addr_in_ep()
2477 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { in sctp_choose_boundspecific_inp()
2479 if ((sctp_ifa->address.sa.sa_family == AF_INET) && in sctp_choose_boundspecific_inp()
2480 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_choose_boundspecific_inp()
2481 &sctp_ifa->address.sin.sin_addr) != 0)) { in sctp_choose_boundspecific_inp()
2486 if ((sctp_ifa->address.sa.sa_family == AF_INET6) && in sctp_choose_boundspecific_inp()
2487 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_choose_boundspecific_inp()
2488 &sctp_ifa->address.sin6.sin6_addr) != 0)) { in sctp_choose_boundspecific_inp()
2492 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && in sctp_choose_boundspecific_inp()
2501 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_inp()
2512 starting_point = inp->next_addr_touse; in sctp_choose_boundspecific_inp()
2514 if (inp->next_addr_touse == NULL) { in sctp_choose_boundspecific_inp()
2515 inp->next_addr_touse = LIST_FIRST(&inp->sctp_addr_list); in sctp_choose_boundspecific_inp()
2518 for (laddr = inp->next_addr_touse; laddr; in sctp_choose_boundspecific_inp()
2520 if (laddr->ifa == NULL) { in sctp_choose_boundspecific_inp()
2524 if (laddr->action == SCTP_DEL_IP_ADDRESS) { in sctp_choose_boundspecific_inp()
2528 sifa = sctp_is_ifa_addr_preferred(laddr->ifa, dest_is_loop, in sctp_choose_boundspecific_inp()
2532 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_inp()
2536 inp->next_addr_touse = NULL; in sctp_choose_boundspecific_inp()
2540 inp->next_addr_touse = starting_point; in sctp_choose_boundspecific_inp()
2543 if (inp->next_addr_touse == NULL) { in sctp_choose_boundspecific_inp()
2544 inp->next_addr_touse = LIST_FIRST(&inp->sctp_addr_list); in sctp_choose_boundspecific_inp()
2549 for (laddr = inp->next_addr_touse; laddr; in sctp_choose_boundspecific_inp()
2551 if (laddr->ifa == NULL) { in sctp_choose_boundspecific_inp()
2555 if (laddr->action == SCTP_DEL_IP_ADDRESS) { in sctp_choose_boundspecific_inp()
2559 sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop, in sctp_choose_boundspecific_inp()
2563 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_inp()
2567 inp->next_addr_touse = NULL; in sctp_choose_boundspecific_inp()
2615 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { in sctp_choose_boundspecific_stcb()
2617 if ((sctp_ifa->address.sa.sa_family == AF_INET) && in sctp_choose_boundspecific_stcb()
2618 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_choose_boundspecific_stcb()
2619 &sctp_ifa->address.sin.sin_addr) != 0)) { in sctp_choose_boundspecific_stcb()
2624 if ((sctp_ifa->address.sa.sa_family == AF_INET6) && in sctp_choose_boundspecific_stcb()
2625 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_choose_boundspecific_stcb()
2626 &sctp_ifa->address.sin6.sin6_addr) != 0)) { in sctp_choose_boundspecific_stcb()
2630 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0)) in sctp_choose_boundspecific_stcb()
2641 /* on the no-no list */ in sctp_choose_boundspecific_stcb()
2644 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_stcb()
2649 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { in sctp_choose_boundspecific_stcb()
2651 if ((sctp_ifa->address.sa.sa_family == AF_INET) && in sctp_choose_boundspecific_stcb()
2652 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_choose_boundspecific_stcb()
2653 &sctp_ifa->address.sin.sin_addr) != 0)) { in sctp_choose_boundspecific_stcb()
2658 if ((sctp_ifa->address.sa.sa_family == AF_INET6) && in sctp_choose_boundspecific_stcb()
2659 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_choose_boundspecific_stcb()
2660 &sctp_ifa->address.sin6.sin6_addr) != 0)) { in sctp_choose_boundspecific_stcb()
2664 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && (non_asoc_addr_ok == 0)) in sctp_choose_boundspecific_stcb()
2675 /* on the no-no list */ in sctp_choose_boundspecific_stcb()
2678 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_stcb()
2687 starting_point = stcb->asoc.last_used_address; in sctp_choose_boundspecific_stcb()
2689 if (stcb->asoc.last_used_address == NULL) { in sctp_choose_boundspecific_stcb()
2691 stcb->asoc.last_used_address = LIST_FIRST(&inp->sctp_addr_list); in sctp_choose_boundspecific_stcb()
2694 for (laddr = stcb->asoc.last_used_address; laddr; in sctp_choose_boundspecific_stcb()
2696 if (laddr->ifa == NULL) { in sctp_choose_boundspecific_stcb()
2700 if (laddr->action == SCTP_DEL_IP_ADDRESS) { in sctp_choose_boundspecific_stcb()
2704 sifa = sctp_is_ifa_addr_preferred(laddr->ifa, dest_is_loop, dest_is_priv, fam); in sctp_choose_boundspecific_stcb()
2712 /* on the no-no list */ in sctp_choose_boundspecific_stcb()
2715 stcb->asoc.last_used_address = laddr; in sctp_choose_boundspecific_stcb()
2716 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_stcb()
2720 stcb->asoc.last_used_address = NULL; in sctp_choose_boundspecific_stcb()
2724 stcb->asoc.last_used_address = starting_point; in sctp_choose_boundspecific_stcb()
2727 if (stcb->asoc.last_used_address == NULL) { in sctp_choose_boundspecific_stcb()
2729 stcb->asoc.last_used_address = LIST_FIRST(&inp->sctp_addr_list); in sctp_choose_boundspecific_stcb()
2732 for (laddr = stcb->asoc.last_used_address; laddr; in sctp_choose_boundspecific_stcb()
2734 if (laddr->ifa == NULL) { in sctp_choose_boundspecific_stcb()
2738 if (laddr->action == SCTP_DEL_IP_ADDRESS) { in sctp_choose_boundspecific_stcb()
2742 sifa = sctp_is_ifa_addr_acceptable(laddr->ifa, dest_is_loop, in sctp_choose_boundspecific_stcb()
2751 /* on the no-no list */ in sctp_choose_boundspecific_stcb()
2754 stcb->asoc.last_used_address = laddr; in sctp_choose_boundspecific_stcb()
2755 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundspecific_stcb()
2759 stcb->asoc.last_used_address = NULL; in sctp_choose_boundspecific_stcb()
2782 memcpy(&sin6, &ro->ro_dst, sizeof(struct sockaddr_in6)); in sctp_select_nth_preferred_addr_from_ifn_boundall()
2786 LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2788 if ((ifa->address.sa.sa_family == AF_INET) && in sctp_select_nth_preferred_addr_from_ifn_boundall()
2789 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_select_nth_preferred_addr_from_ifn_boundall()
2790 &ifa->address.sin.sin_addr) != 0)) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2795 if ((ifa->address.sa.sa_family == AF_INET6) && in sctp_select_nth_preferred_addr_from_ifn_boundall()
2796 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_select_nth_preferred_addr_from_ifn_boundall()
2797 &ifa->address.sin6.sin6_addr) != 0)) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2801 if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && in sctp_select_nth_preferred_addr_from_ifn_boundall()
2811 sifa->src_is_loop && sifa->src_is_priv) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2820 IN6_IS_ADDR_LINKLOCAL(&sifa->address.sin6.sin6_addr) && in sctp_select_nth_preferred_addr_from_ifn_boundall()
2823 * link-local <-> link-local must belong to the same in sctp_select_nth_preferred_addr_from_ifn_boundall()
2826 memcpy(&lsa6, &sifa->address.sin6, sizeof(struct sockaddr_in6)); in sctp_select_nth_preferred_addr_from_ifn_boundall()
2835 * Check if the IPv6 address matches to next-hop. In the in sctp_select_nth_preferred_addr_from_ifn_boundall()
2839 * next-hop. (by micchie) in sctp_select_nth_preferred_addr_from_ifn_boundall()
2843 sctp_is_mobility_feature_on(stcb->sctp_ep, SCTP_MOBILITY_BASE)) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2844 if (sctp_v6src_match_nexthop(&sifa->address.sin6, ro) == 0) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2852 sctp_is_mobility_feature_on(stcb->sctp_ep, SCTP_MOBILITY_BASE)) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2859 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) { in sctp_select_nth_preferred_addr_from_ifn_boundall()
2894 LIST_FOREACH(ifa, &ifn->ifalist, next_ifa) { in sctp_count_num_preferred_boundall()
2896 if ((ifa->address.sa.sa_family == AF_INET) && in sctp_count_num_preferred_boundall()
2897 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_count_num_preferred_boundall()
2898 &ifa->address.sin.sin_addr) != 0)) { in sctp_count_num_preferred_boundall()
2903 if ((ifa->address.sa.sa_family == AF_INET6) && in sctp_count_num_preferred_boundall()
2905 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_count_num_preferred_boundall()
2906 &ifa->address.sin6.sin6_addr) != 0)) { in sctp_count_num_preferred_boundall()
2910 if ((ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && in sctp_count_num_preferred_boundall()
2920 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) { in sctp_count_num_preferred_boundall()
2961 /*- in sctp_choose_boundall()
2973 * abort :-<. in sctp_choose_boundall()
2989 ifn_index, sctp_ifn->ifn_name); in sctp_choose_boundall()
2992 cur_addr_num = net->indx_of_eligible_next_to_use; in sctp_choose_boundall()
3000 num_preferred, sctp_ifn->ifn_name); in sctp_choose_boundall()
3027 atomic_add_int(&sctp_ifa->refcount, 1); in sctp_choose_boundall()
3030 net->indx_of_eligible_next_to_use = cur_addr_num + 1; in sctp_choose_boundall()
3040 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { in sctp_choose_boundall()
3042 sctp_ifn->ifn_name); in sctp_choose_boundall()
3060 SCTPDBG(SCTP_DEBUG_OUTPUT2, "No preferred -- skipping to next\n"); in sctp_choose_boundall()
3080 net->indx_of_eligible_next_to_use = cur_addr_num + 1; in sctp_choose_boundall()
3084 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa); in sctp_choose_boundall()
3086 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &net->ro._l_addr.sa); in sctp_choose_boundall()
3088 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundall()
3098 SCTPDBG(SCTP_DEBUG_OUTPUT2, "Jump to Plan D - no emit_ifn\n"); in sctp_choose_boundall()
3101 LIST_FOREACH(sctp_ifa, &emit_ifn->ifalist, next_ifa) { in sctp_choose_boundall()
3104 if ((sctp_ifa->address.sa.sa_family == AF_INET) && in sctp_choose_boundall()
3105 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_choose_boundall()
3106 &sctp_ifa->address.sin.sin_addr) != 0)) { in sctp_choose_boundall()
3112 if ((sctp_ifa->address.sa.sa_family == AF_INET6) && in sctp_choose_boundall()
3113 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_choose_boundall()
3114 &sctp_ifa->address.sin6.sin6_addr) != 0)) { in sctp_choose_boundall()
3119 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && in sctp_choose_boundall()
3131 if (sctp_is_address_in_scope(sifa, &stcb->asoc.scope, 0) == 0) { in sctp_choose_boundall()
3150 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundall()
3161 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { in sctp_choose_boundall()
3166 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { in sctp_choose_boundall()
3168 if ((sctp_ifa->address.sa.sa_family == AF_INET) && in sctp_choose_boundall()
3169 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_choose_boundall()
3170 &sctp_ifa->address.sin.sin_addr) != 0)) { in sctp_choose_boundall()
3175 if ((sctp_ifa->address.sa.sa_family == AF_INET6) && in sctp_choose_boundall()
3176 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_choose_boundall()
3177 &sctp_ifa->address.sin6.sin6_addr) != 0)) { in sctp_choose_boundall()
3181 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && in sctp_choose_boundall()
3190 if (sctp_is_address_in_scope(sifa, &stcb->asoc.scope, 0) == 0) { in sctp_choose_boundall()
3212 if ((retried == 0) && (stcb->asoc.scope.ipv4_local_scope == 0)) { in sctp_choose_boundall()
3213 stcb->asoc.scope.ipv4_local_scope = 1; in sctp_choose_boundall()
3217 stcb->asoc.scope.ipv4_local_scope = 0; in sctp_choose_boundall()
3225 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { in sctp_choose_boundall()
3230 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { in sctp_choose_boundall()
3234 if ((sctp_ifa->address.sa.sa_family == AF_INET) && in sctp_choose_boundall()
3235 (prison_check_ip4(inp->ip_inp.inp.inp_cred, in sctp_choose_boundall()
3236 &sctp_ifa->address.sin.sin_addr) != 0)) { in sctp_choose_boundall()
3241 if ((sctp_ifa->address.sa.sa_family == AF_INET6) && in sctp_choose_boundall()
3242 (prison_check_ip6(inp->ip_inp.inp.inp_cred, in sctp_choose_boundall()
3243 &sctp_ifa->address.sin6.sin6_addr) != 0)) { in sctp_choose_boundall()
3247 if ((sctp_ifa->localifa_flags & SCTP_ADDR_DEFER_USE) && in sctp_choose_boundall()
3261 &stcb->asoc.scope, 0) == 0) { in sctp_choose_boundall()
3278 if ((tmp_sifa->address.sin.sin_family == AF_INET) && in sctp_choose_boundall()
3279 (IN4_ISPRIVATE_ADDRESS(&(tmp_sifa->address.sin.sin_addr)))) { in sctp_choose_boundall()
3285 atomic_add_int(&sifa->refcount, 1); in sctp_choose_boundall()
3303 struct sockaddr_in *to = (struct sockaddr_in *)&ro->ro_dst; in sctp_source_address_selection()
3306 struct sockaddr_in6 *to6 = (struct sockaddr_in6 *)&ro->ro_dst; in sctp_source_address_selection()
3311 * - Find the route if needed, cache if I can. in sctp_source_address_selection()
3312 * - Look at interface address in route, Is it in the bound list. If so we in sctp_source_address_selection()
3314 * - If not we must rotate amongst the addresses. in sctp_source_address_selection()
3323 * ------------------------------------------ in sctp_source_address_selection()
3325 * ----------------------------------------- in sctp_source_address_selection()
3327 * ----------------------------------------- in sctp_source_address_selection()
3329 * ----------------------------------------- in sctp_source_address_selection()
3331 * ----------------------------------------- in sctp_source_address_selection()
3333 *------------------------------------------ in sctp_source_address_selection()
3336 *------------------------------------------ in sctp_source_address_selection()
3338 * ----------------------------------------- in sctp_source_address_selection()
3340 * ----------------------------------------- in sctp_source_address_selection()
3342 * ----------------------------------------- in sctp_source_address_selection()
3344 * ----------------------------------------- in sctp_source_address_selection()
3346 *------------------------------------------ in sctp_source_address_selection()
3354 * one is best? And what about NAT's sending P->G may get you a NAT in sctp_source_address_selection()
3360 * - count the number of addresses on the interface. in sctp_source_address_selection()
3361 * - if it is one, no problem except case <c>. in sctp_source_address_selection()
3363 * - if there are more than one, then we need to worry about scope P in sctp_source_address_selection()
3364 * or G. We should prefer G -> G and P -> P if possible. in sctp_source_address_selection()
3365 * Then as a secondary fall back to mixed types G->P being a last in sctp_source_address_selection()
3367 * - The above all works for bound all, but bound specific we need to in sctp_source_address_selection()
3372 if (ro->ro_nh == NULL) { in sctp_source_address_selection()
3376 SCTP_RTALLOC(ro, vrf_id, inp->fibnum); in sctp_source_address_selection()
3378 if (ro->ro_nh == NULL) { in sctp_source_address_selection()
3381 fam = ro->ro_dst.sa_family; in sctp_source_address_selection()
3388 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { in sctp_source_address_selection()
3392 net->addr_is_local = 1; in sctp_source_address_selection()
3394 } else if ((IN4_ISPRIVATE_ADDRESS(&to->sin_addr))) { in sctp_source_address_selection()
3402 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr) || in sctp_source_address_selection()
3413 net->addr_is_local = 1; in sctp_source_address_selection()
3415 } else if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { in sctp_source_address_selection()
3422 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, (struct sockaddr *)&ro->ro_dst); in sctp_source_address_selection()
3424 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { in sctp_source_address_selection()
3469 rem_len = tot_len - off; in sctp_find_cmsg()
3483 cmsg_data_len = (int)cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh)); in sctp_find_cmsg()
3517 sndrcvinfo->sinfo_stream = sndinfo.snd_sid; in sctp_find_cmsg()
3518 sndrcvinfo->sinfo_flags = sndinfo.snd_flags; in sctp_find_cmsg()
3519 sndrcvinfo->sinfo_ppid = sndinfo.snd_ppid; in sctp_find_cmsg()
3520 sndrcvinfo->sinfo_context = sndinfo.snd_context; in sctp_find_cmsg()
3521 sndrcvinfo->sinfo_assoc_id = sndinfo.snd_assoc_id; in sctp_find_cmsg()
3529 sndrcvinfo->sinfo_timetolive = prinfo.pr_value; in sctp_find_cmsg()
3531 sndrcvinfo->sinfo_timetolive = 0; in sctp_find_cmsg()
3533 sndrcvinfo->sinfo_flags |= prinfo.pr_policy; in sctp_find_cmsg()
3540 sndrcvinfo->sinfo_keynumber_valid = 1; in sctp_find_cmsg()
3541 sndrcvinfo->sinfo_keynumber = authinfo.auth_keynumber; in sctp_find_cmsg()
3568 rem_len = tot_len - off; in sctp_process_cmsgs_for_init()
3585 cmsg_data_len = (int)cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh)); in sctp_process_cmsgs_for_init()
3596 stcb->asoc.max_init_times = initmsg.sinit_max_attempts; in sctp_process_cmsgs_for_init()
3598 stcb->asoc.pre_open_streams = initmsg.sinit_num_ostreams; in sctp_process_cmsgs_for_init()
3600 stcb->asoc.max_inbound_streams = initmsg.sinit_max_instreams; in sctp_process_cmsgs_for_init()
3602 stcb->asoc.initial_init_rto_max = initmsg.sinit_max_init_timeo; in sctp_process_cmsgs_for_init()
3603 if (stcb->asoc.streamoutcnt < stcb->asoc.pre_open_streams) { in sctp_process_cmsgs_for_init()
3612 stcb->asoc.streamoutcnt, stcb->asoc.pre_open_streams); in sctp_process_cmsgs_for_init()
3616 (stcb->asoc.pre_open_streams * sizeof(struct sctp_stream_out)), in sctp_process_cmsgs_for_init()
3620 SCTP_FREE(stcb->asoc.strmout, SCTP_M_STRMO); in sctp_process_cmsgs_for_init()
3621 stcb->asoc.strmout = tmp_str; in sctp_process_cmsgs_for_init()
3622 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt = stcb->asoc.pre_open_streams; in sctp_process_cmsgs_for_init()
3624 stcb->asoc.pre_open_streams = stcb->asoc.streamoutcnt; in sctp_process_cmsgs_for_init()
3626 for (i = 0; i < stcb->asoc.streamoutcnt; i++) { in sctp_process_cmsgs_for_init()
3627 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); in sctp_process_cmsgs_for_init()
3628 stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], NULL); in sctp_process_cmsgs_for_init()
3629 stcb->asoc.strmout[i].chunks_on_queues = 0; in sctp_process_cmsgs_for_init()
3632 stcb->asoc.strmout[i].abandoned_sent[j] = 0; in sctp_process_cmsgs_for_init()
3633 stcb->asoc.strmout[i].abandoned_unsent[j] = 0; in sctp_process_cmsgs_for_init()
3636 stcb->asoc.strmout[i].abandoned_sent[0] = 0; in sctp_process_cmsgs_for_init()
3637 stcb->asoc.strmout[i].abandoned_unsent[0] = 0; in sctp_process_cmsgs_for_init()
3639 stcb->asoc.strmout[i].next_mid_ordered = 0; in sctp_process_cmsgs_for_init()
3640 stcb->asoc.strmout[i].next_mid_unordered = 0; in sctp_process_cmsgs_for_init()
3641 stcb->asoc.strmout[i].sid = i; in sctp_process_cmsgs_for_init()
3642 stcb->asoc.strmout[i].last_msg_incomplete = 0; in sctp_process_cmsgs_for_init()
3643 stcb->asoc.strmout[i].state = SCTP_STREAM_OPENING; in sctp_process_cmsgs_for_init()
3656 sin.sin_port = stcb->rport; in sctp_process_cmsgs_for_init()
3663 if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin, NULL, stcb->asoc.port, in sctp_process_cmsgs_for_init()
3679 sin6.sin6_port = stcb->rport; in sctp_process_cmsgs_for_init()
3694 if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin, NULL, stcb->asoc.port, in sctp_process_cmsgs_for_init()
3701 if (sctp_add_remote_addr(stcb, (struct sockaddr *)&sin6, NULL, stcb->asoc.port, in sctp_process_cmsgs_for_init()
3737 rem_len = tot_len - off; in sctp_findassociation_cmsgs()
3754 cmsg_data_len = (int)cmh.cmsg_len - CMSG_ALIGN(sizeof(cmh)); in sctp_findassociation_cmsgs()
3851 ph->param_type = htons(SCTP_STATE_COOKIE); in sctp_add_cookie()
3852 ph->param_length = 0; /* fill in at the end */ in sctp_add_cookie()
3856 /* tack the INIT and then the INIT-ACK onto the chain */ in sctp_add_cookie()
3887 ph->param_length = htons(cookie_sz); in sctp_add_cookie()
3896 if ((stcb != NULL) && (stcb->asoc.ecn_supported == 1)) { in sctp_get_ect()
3909 SCTPDBG(SCTP_DEBUG_OUTPUT1, "dropped packet - no valid source addr\n"); in sctp_handle_no_route()
3913 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT1, &net->ro._l_addr.sa); in sctp_handle_no_route()
3914 if (net->dest_state & SCTP_ADDR_CONFIRMED) { in sctp_handle_no_route()
3915 if ((net->dest_state & SCTP_ADDR_REACHABLE) && stcb) { in sctp_handle_no_route()
3921 net->dest_state &= ~SCTP_ADDR_REACHABLE; in sctp_handle_no_route()
3922 net->dest_state &= ~SCTP_ADDR_PF; in sctp_handle_no_route()
3926 if (net == stcb->asoc.primary_destination) { in sctp_handle_no_route()
3932 if (stcb->asoc.alternate) { in sctp_handle_no_route()
3933 sctp_free_remote_addr(stcb->asoc.alternate); in sctp_handle_no_route()
3935 stcb->asoc.alternate = alt; in sctp_handle_no_route()
3936 atomic_add_int(&stcb->asoc.alternate->ref_count, 1); in sctp_handle_no_route()
3937 if (net->ro._s_addr) { in sctp_handle_no_route()
3938 sctp_free_ifa(net->ro._s_addr); in sctp_handle_no_route()
3939 net->ro._s_addr = NULL; in sctp_handle_no_route()
3941 net->src_addr_selected = 0; in sctp_handle_no_route()
3974 * - fill in the HMAC digest of any AUTH chunk in the packet. in sctp_lowlevel_chunk_output()
3975 * - calculate and fill in the SCTP checksum. in sctp_lowlevel_chunk_output()
3976 * - prepend an IP address header. in sctp_lowlevel_chunk_output()
3977 * - if boundall use INADDR_ANY. in sctp_lowlevel_chunk_output()
3978 * - if boundspecific do source address selection. in sctp_lowlevel_chunk_output()
3979 * - set fragmentation option for ipV4. in sctp_lowlevel_chunk_output()
3980 * - On return from IP output, check/adjust mtu size of output in sctp_lowlevel_chunk_output()
3998 if ((net) && (net->dest_state & SCTP_ADDR_OUT_OF_SCOPE)) { in sctp_lowlevel_chunk_output()
4005 vrf_id = stcb->asoc.vrf_id; in sctp_lowlevel_chunk_output()
4007 vrf_id = inp->def_vrf_id; in sctp_lowlevel_chunk_output()
4016 tos_value = net->dscp; in sctp_lowlevel_chunk_output()
4018 tos_value = stcb->asoc.default_dscp; in sctp_lowlevel_chunk_output()
4020 tos_value = inp->sctp_ep.default_dscp; in sctp_lowlevel_chunk_output()
4023 switch (to->sa_family) { in sctp_lowlevel_chunk_output()
4046 m->m_pkthdr.flowid = net->flowid; in sctp_lowlevel_chunk_output()
4047 M_HASHTYPE_SET(m, net->flowtype); in sctp_lowlevel_chunk_output()
4049 m->m_pkthdr.flowid = mflowid; in sctp_lowlevel_chunk_output()
4054 ip->ip_v = IPVERSION; in sctp_lowlevel_chunk_output()
4055 ip->ip_hl = (sizeof(struct ip) >> 2); in sctp_lowlevel_chunk_output()
4062 tos_value = inp->ip_inp.inp.inp_ip_tos; in sctp_lowlevel_chunk_output()
4069 ip->ip_off = htons(IP_DF); in sctp_lowlevel_chunk_output()
4071 ip->ip_off = htons(0); in sctp_lowlevel_chunk_output()
4076 ip->ip_ttl = inp->ip_inp.inp.inp_ip_ttl; in sctp_lowlevel_chunk_output()
4077 ip->ip_len = htons(packet_length); in sctp_lowlevel_chunk_output()
4078 ip->ip_tos = tos_value; in sctp_lowlevel_chunk_output()
4080 ip->ip_p = IPPROTO_UDP; in sctp_lowlevel_chunk_output()
4082 ip->ip_p = IPPROTO_SCTP; in sctp_lowlevel_chunk_output()
4084 ip->ip_sum = 0; in sctp_lowlevel_chunk_output()
4088 memcpy(&ro->ro_dst, to, to->sa_len); in sctp_lowlevel_chunk_output()
4090 ro = (sctp_route_t *)&net->ro; in sctp_lowlevel_chunk_output()
4093 ip->ip_dst.s_addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; in sctp_lowlevel_chunk_output()
4097 …if (net->ro._s_addr && (net->ro._s_addr->localifa_flags & (SCTP_BEING_DELETED | SCTP_ADDR_IFA_UNUS… in sctp_lowlevel_chunk_output()
4098 sctp_free_ifa(net->ro._s_addr); in sctp_lowlevel_chunk_output()
4099 net->ro._s_addr = NULL; in sctp_lowlevel_chunk_output()
4100 net->src_addr_selected = 0; in sctp_lowlevel_chunk_output()
4103 if (net->src_addr_selected == 0) { in sctp_lowlevel_chunk_output()
4105 net->ro._s_addr = sctp_source_address_selection(inp, stcb, in sctp_lowlevel_chunk_output()
4108 net->src_addr_selected = 1; in sctp_lowlevel_chunk_output()
4110 if (net->ro._s_addr == NULL) { in sctp_lowlevel_chunk_output()
4112 net->src_addr_selected = 0; in sctp_lowlevel_chunk_output()
4118 ip->ip_src = net->ro._s_addr->address.sin.sin_addr; in sctp_lowlevel_chunk_output()
4133 ip->ip_src = _lsrc->address.sin.sin_addr; in sctp_lowlevel_chunk_output()
4136 ip->ip_src = over_addr->sin.sin_addr; in sctp_lowlevel_chunk_output()
4137 SCTP_RTALLOC(ro, vrf_id, inp->fibnum); in sctp_lowlevel_chunk_output()
4148 udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); in sctp_lowlevel_chunk_output()
4149 udp->uh_dport = port; in sctp_lowlevel_chunk_output()
4150 udp->uh_ulen = htons((uint16_t)(packet_length - sizeof(struct ip))); in sctp_lowlevel_chunk_output()
4152 … udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); in sctp_lowlevel_chunk_output()
4154 udp->uh_sum = 0; in sctp_lowlevel_chunk_output()
4161 sctphdr->src_port = src_port; in sctp_lowlevel_chunk_output()
4162 sctphdr->dest_port = dest_port; in sctp_lowlevel_chunk_output()
4163 sctphdr->v_tag = v_tag; in sctp_lowlevel_chunk_output()
4164 sctphdr->checksum = 0; in sctp_lowlevel_chunk_output()
4173 if (ro->ro_nh == NULL) { in sctp_lowlevel_chunk_output()
4188 (uint32_t)(ntohl(ip->ip_src.s_addr))); in sctp_lowlevel_chunk_output()
4190 (uint32_t)(ntohl(ip->ip_dst.s_addr))); in sctp_lowlevel_chunk_output()
4192 (void *)ro->ro_nh); in sctp_lowlevel_chunk_output()
4205 sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip) + sizeof(struct udphdr)); in sctp_lowlevel_chunk_output()
4215 m->m_pkthdr.csum_flags = CSUM_SCTP; in sctp_lowlevel_chunk_output()
4216 m->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum); in sctp_lowlevel_chunk_output()
4240 if ((ro->ro_nh != NULL) && (net->ro._s_addr) && in sctp_lowlevel_chunk_output()
4241 ((net->dest_state & SCTP_ADDR_NO_PMTUD) == 0)) { in sctp_lowlevel_chunk_output()
4244 mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, ro->ro_nh); in sctp_lowlevel_chunk_output()
4246 if (net->port) { in sctp_lowlevel_chunk_output()
4247 mtu -= sizeof(struct udphdr); in sctp_lowlevel_chunk_output()
4249 if (mtu < net->mtu) { in sctp_lowlevel_chunk_output()
4250 net->mtu = mtu; in sctp_lowlevel_chunk_output()
4251 if ((stcb != NULL) && (stcb->asoc.smallest_mtu > mtu)) { in sctp_lowlevel_chunk_output()
4256 } else if (ro->ro_nh == NULL) { in sctp_lowlevel_chunk_output()
4258 if (net->ro._s_addr && in sctp_lowlevel_chunk_output()
4259 net->src_addr_selected) { in sctp_lowlevel_chunk_output()
4260 sctp_free_ifa(net->ro._s_addr); in sctp_lowlevel_chunk_output()
4261 net->ro._s_addr = NULL; in sctp_lowlevel_chunk_output()
4263 net->src_addr_selected = 0; in sctp_lowlevel_chunk_output()
4284 flowlabel = net->flowlabel; in sctp_lowlevel_chunk_output()
4286 flowlabel = stcb->asoc.default_flowlabel; in sctp_lowlevel_chunk_output()
4288 flowlabel = inp->sctp_ep.default_flowlabel; in sctp_lowlevel_chunk_output()
4296 flowlabel = ntohl(((struct inpcb *)inp)->inp_flow); in sctp_lowlevel_chunk_output()
4314 m->m_pkthdr.flowid = net->flowid; in sctp_lowlevel_chunk_output()
4315 M_HASHTYPE_SET(m, net->flowtype); in sctp_lowlevel_chunk_output()
4317 m->m_pkthdr.flowid = mflowid; in sctp_lowlevel_chunk_output()
4337 memcpy(&ro->ro_dst, sin6, sin6->sin6_len); in sctp_lowlevel_chunk_output()
4339 ro = (sctp_route_t *)&net->ro; in sctp_lowlevel_chunk_output()
4351 tos_value = (ntohl(((struct inpcb *)inp)->inp_flow) >> 20) & 0xff; in sctp_lowlevel_chunk_output()
4362 ip6h->ip6_flow = htonl(flowinfo); in sctp_lowlevel_chunk_output()
4364 ip6h->ip6_nxt = IPPROTO_UDP; in sctp_lowlevel_chunk_output()
4366 ip6h->ip6_nxt = IPPROTO_SCTP; in sctp_lowlevel_chunk_output()
4368 ip6h->ip6_plen = htons((uint16_t)(packet_length - sizeof(struct ip6_hdr))); in sctp_lowlevel_chunk_output()
4369 ip6h->ip6_dst = sin6->sin6_addr; in sctp_lowlevel_chunk_output()
4373 * to a limited degree the kame src-addr-sel, since in sctp_lowlevel_chunk_output()
4382 …if (net->ro._s_addr && (net->ro._s_addr->localifa_flags & (SCTP_BEING_DELETED | SCTP_ADDR_IFA_UNUS… in sctp_lowlevel_chunk_output()
4383 sctp_free_ifa(net->ro._s_addr); in sctp_lowlevel_chunk_output()
4384 net->ro._s_addr = NULL; in sctp_lowlevel_chunk_output()
4385 net->src_addr_selected = 0; in sctp_lowlevel_chunk_output()
4388 if (net->src_addr_selected == 0) { in sctp_lowlevel_chunk_output()
4389 sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; in sctp_lowlevel_chunk_output()
4397 net->ro._s_addr = sctp_source_address_selection(inp, in sctp_lowlevel_chunk_output()
4404 net->src_addr_selected = 1; in sctp_lowlevel_chunk_output()
4406 if (net->ro._s_addr == NULL) { in sctp_lowlevel_chunk_output()
4408 net->src_addr_selected = 0; in sctp_lowlevel_chunk_output()
4414 lsa6->sin6_addr = net->ro._s_addr->address.sin6.sin6_addr; in sctp_lowlevel_chunk_output()
4416 sin6 = (struct sockaddr_in6 *)&ro->ro_dst; in sctp_lowlevel_chunk_output()
4436 lsa6->sin6_addr = _lsrc->address.sin6.sin6_addr; in sctp_lowlevel_chunk_output()
4439 lsa6->sin6_addr = over_addr->sin6.sin6_addr; in sctp_lowlevel_chunk_output()
4440 SCTP_RTALLOC(ro, vrf_id, inp->fibnum); in sctp_lowlevel_chunk_output()
4444 lsa6->sin6_port = inp->sctp_lport; in sctp_lowlevel_chunk_output()
4446 if (ro->ro_nh == NULL) { in sctp_lowlevel_chunk_output()
4459 * the non-SCOPEDROUTING case. in sctp_lowlevel_chunk_output()
4464 lsa6_storage.sin6_addr = lsa6->sin6_addr; in sctp_lowlevel_chunk_output()
4471 lsa6_storage.sin6_addr = lsa6->sin6_addr; in sctp_lowlevel_chunk_output()
4472 lsa6_storage.sin6_port = inp->sctp_lport; in sctp_lowlevel_chunk_output()
4474 ip6h->ip6_src = lsa6->sin6_addr; in sctp_lowlevel_chunk_output()
4484 udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); in sctp_lowlevel_chunk_output()
4485 udp->uh_dport = port; in sctp_lowlevel_chunk_output()
4486 udp->uh_ulen = htons((uint16_t)(packet_length - sizeof(struct ip6_hdr))); in sctp_lowlevel_chunk_output()
4487 udp->uh_sum = 0; in sctp_lowlevel_chunk_output()
4493 sctphdr->src_port = src_port; in sctp_lowlevel_chunk_output()
4494 sctphdr->dest_port = dest_port; in sctp_lowlevel_chunk_output()
4495 sctphdr->v_tag = v_tag; in sctp_lowlevel_chunk_output()
4496 sctphdr->checksum = 0; in sctp_lowlevel_chunk_output()
4502 ip6h->ip6_hlim = SCTP_GET_HLIM(inp, ro); in sctp_lowlevel_chunk_output()
4507 sin6->sin6_addr = ip6h->ip6_dst; in sctp_lowlevel_chunk_output()
4508 lsa6->sin6_addr = ip6h->ip6_src; in sctp_lowlevel_chunk_output()
4517 sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; in sctp_lowlevel_chunk_output()
4522 prev_scope = sin6->sin6_scope_id; in sctp_lowlevel_chunk_output()
4523 prev_port = sin6->sin6_port; in sctp_lowlevel_chunk_output()
4534 sctphdr->checksum = sctp_calculate_cksum(m, sizeof(struct ip6_hdr) + sizeof(struct udphdr)); in sctp_lowlevel_chunk_output()
4536 …if ((udp->uh_sum = in6_cksum(o_pak, IPPROTO_UDP, sizeof(struct ip6_hdr), packet_length - sizeof(st… in sctp_lowlevel_chunk_output()
4537 udp->uh_sum = 0xffff; in sctp_lowlevel_chunk_output()
4540 m->m_pkthdr.csum_flags = CSUM_SCTP_IPV6; in sctp_lowlevel_chunk_output()
4541 m->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum); in sctp_lowlevel_chunk_output()
4553 sin6->sin6_scope_id = prev_scope; in sctp_lowlevel_chunk_output()
4554 sin6->sin6_port = prev_port; in sctp_lowlevel_chunk_output()
4573 if (ro->ro_nh == NULL) { in sctp_lowlevel_chunk_output()
4575 if (net->ro._s_addr && in sctp_lowlevel_chunk_output()
4576 net->src_addr_selected) { in sctp_lowlevel_chunk_output()
4577 sctp_free_ifa(net->ro._s_addr); in sctp_lowlevel_chunk_output()
4578 net->ro._s_addr = NULL; in sctp_lowlevel_chunk_output()
4580 net->src_addr_selected = 0; in sctp_lowlevel_chunk_output()
4582 if ((ro->ro_nh != NULL) && (net->ro._s_addr) && in sctp_lowlevel_chunk_output()
4583 ((net->dest_state & SCTP_ADDR_NO_PMTUD) == 0)) { in sctp_lowlevel_chunk_output()
4586 mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, ro->ro_nh); in sctp_lowlevel_chunk_output()
4588 if (net->port) { in sctp_lowlevel_chunk_output()
4589 mtu -= sizeof(struct udphdr); in sctp_lowlevel_chunk_output()
4591 if (mtu < net->mtu) { in sctp_lowlevel_chunk_output()
4592 net->mtu = mtu; in sctp_lowlevel_chunk_output()
4593 if ((stcb != NULL) && (stcb->asoc.smallest_mtu > mtu)) { in sctp_lowlevel_chunk_output()
4599 if ((ND_IFINFO(ifp)->linkmtu > 0) && in sctp_lowlevel_chunk_output()
4600 (stcb->asoc.smallest_mtu > ND_IFINFO(ifp)->linkmtu)) { in sctp_lowlevel_chunk_output()
4601 sctp_pathmtu_adjustment(stcb, ND_IFINFO(ifp)->linkmtu, false); in sctp_lowlevel_chunk_output()
4610 ((struct sockaddr *)to)->sa_family); in sctp_lowlevel_chunk_output()
4633 net = stcb->asoc.primary_destination; in sctp_send_initiate()
4635 net = TAILQ_FIRST(&stcb->asoc.nets); in sctp_send_initiate()
4641 net->dest_state &= ~SCTP_ADDR_UNCONFIRMED; in sctp_send_initiate()
4645 net->dest_state &= ~SCTP_ADDR_UNCONFIRMED; in sctp_send_initiate()
4649 if (net->ro._l_addr.sa.sa_family == AF_INET6) { in sctp_send_initiate()
4654 if (IN6_IS_ADDR_LINKLOCAL(&net->ro._l_addr.sin6.sin6_addr)) in sctp_send_initiate()
4658 if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { in sctp_send_initiate()
4660 SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - failed timer?\n"); in sctp_send_initiate()
4668 /* No memory, INIT timer will re-attempt. */ in sctp_send_initiate()
4669 SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - mbuf?\n"); in sctp_send_initiate()
4677 init->ch.chunk_type = SCTP_INITIATION; in sctp_send_initiate()
4678 init->ch.chunk_flags = 0; in sctp_send_initiate()
4680 init->ch.chunk_length = 0; in sctp_send_initiate()
4682 init->init.initiate_tag = htonl(stcb->asoc.my_vtag); in sctp_send_initiate()
4684 init->init.a_rwnd = htonl(max(inp->sctp_socket ? SCTP_SB_LIMIT_RCV(inp->sctp_socket) : 0, in sctp_send_initiate()
4686 init->init.num_outbound_streams = htons(stcb->asoc.pre_open_streams); in sctp_send_initiate()
4687 init->init.num_inbound_streams = htons(stcb->asoc.max_inbound_streams); in sctp_send_initiate()
4688 init->init.initial_tsn = htonl(stcb->asoc.init_seq_number); in sctp_send_initiate()
4691 if (inp->sctp_ep.adaptation_layer_indicator_provided) { in sctp_send_initiate()
4694 ali->ph.param_type = htons(SCTP_ULP_ADAPTATION); in sctp_send_initiate()
4695 ali->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4696 ali->indication = htonl(inp->sctp_ep.adaptation_layer_indicator); in sctp_send_initiate()
4701 if (stcb->asoc.ecn_supported == 1) { in sctp_send_initiate()
4704 ph->param_type = htons(SCTP_ECN_CAPABLE); in sctp_send_initiate()
4705 ph->param_length = htons(parameter_len); in sctp_send_initiate()
4709 /* PR-SCTP supported parameter */ in sctp_send_initiate()
4710 if (stcb->asoc.prsctp_supported == 1) { in sctp_send_initiate()
4713 ph->param_type = htons(SCTP_PRSCTP_SUPPORTED); in sctp_send_initiate()
4714 ph->param_length = htons(parameter_len); in sctp_send_initiate()
4719 if (stcb->asoc.rcv_edmid != SCTP_EDMID_NONE) { in sctp_send_initiate()
4722 zero_chksum->ph.param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE); in sctp_send_initiate()
4723 zero_chksum->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4724 zero_chksum->edmid = htonl(stcb->asoc.rcv_edmid); in sctp_send_initiate()
4732 ph->param_type = htons(SCTP_HAS_NAT_SUPPORT); in sctp_send_initiate()
4733 ph->param_length = htons(parameter_len); in sctp_send_initiate()
4740 if (stcb->asoc.prsctp_supported == 1) { in sctp_send_initiate()
4741 pr_supported->chunk_types[num_ext++] = SCTP_FORWARD_CUM_TSN; in sctp_send_initiate()
4742 if (stcb->asoc.idata_supported) { in sctp_send_initiate()
4743 pr_supported->chunk_types[num_ext++] = SCTP_IFORWARD_CUM_TSN; in sctp_send_initiate()
4746 if (stcb->asoc.auth_supported == 1) { in sctp_send_initiate()
4747 pr_supported->chunk_types[num_ext++] = SCTP_AUTHENTICATION; in sctp_send_initiate()
4749 if (stcb->asoc.asconf_supported == 1) { in sctp_send_initiate()
4750 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF; in sctp_send_initiate()
4751 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF_ACK; in sctp_send_initiate()
4753 if (stcb->asoc.reconfig_supported == 1) { in sctp_send_initiate()
4754 pr_supported->chunk_types[num_ext++] = SCTP_STREAM_RESET; in sctp_send_initiate()
4756 if (stcb->asoc.idata_supported) { in sctp_send_initiate()
4757 pr_supported->chunk_types[num_ext++] = SCTP_IDATA; in sctp_send_initiate()
4759 if (stcb->asoc.nrsack_supported == 1) { in sctp_send_initiate()
4760 pr_supported->chunk_types[num_ext++] = SCTP_NR_SELECTIVE_ACK; in sctp_send_initiate()
4762 if (stcb->asoc.pktdrop_supported == 1) { in sctp_send_initiate()
4763 pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED; in sctp_send_initiate()
4767 pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT); in sctp_send_initiate()
4768 pr_supported->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4769 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate()
4773 if (stcb->asoc.auth_supported) { in sctp_send_initiate()
4775 if (stcb->asoc.authinfo.random != NULL) { in sctp_send_initiate()
4784 parameter_len = (uint16_t)sizeof(struct sctp_auth_random) + stcb->asoc.authinfo.random_len; in sctp_send_initiate()
4786 memcpy(randp, stcb->asoc.authinfo.random->key, parameter_len); in sctp_send_initiate()
4787 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate()
4791 if (stcb->asoc.local_hmacs != NULL) { in sctp_send_initiate()
4801 stcb->asoc.local_hmacs->num_algo * sizeof(uint16_t)); in sctp_send_initiate()
4802 hmacs->ph.param_type = htons(SCTP_HMAC_LIST); in sctp_send_initiate()
4803 hmacs->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4804 sctp_serialize_hmaclist(stcb->asoc.local_hmacs, (uint8_t *)hmacs->hmac_ids); in sctp_send_initiate()
4805 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate()
4809 if (stcb->asoc.local_auth_chunks != NULL) { in sctp_send_initiate()
4819 sctp_auth_get_chklist_size(stcb->asoc.local_auth_chunks)); in sctp_send_initiate()
4820 chunks->ph.param_type = htons(SCTP_CHUNK_LIST); in sctp_send_initiate()
4821 chunks->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4822 sctp_serialize_auth_chunks(stcb->asoc.local_auth_chunks, chunks->chunk_types); in sctp_send_initiate()
4823 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate()
4829 if (stcb->asoc.cookie_preserve_req > 0) { in sctp_send_initiate()
4839 cookie_preserve->ph.param_type = htons(SCTP_COOKIE_PRESERVE); in sctp_send_initiate()
4840 cookie_preserve->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4841 cookie_preserve->time = htonl(stcb->asoc.cookie_preserve_req); in sctp_send_initiate()
4842 stcb->asoc.cookie_preserve_req = 0; in sctp_send_initiate()
4846 if (stcb->asoc.scope.ipv4_addr_legal || stcb->asoc.scope.ipv6_addr_legal) { in sctp_send_initiate()
4855 if (stcb->asoc.scope.ipv4_addr_legal) { in sctp_send_initiate()
4858 if (stcb->asoc.scope.ipv6_addr_legal) { in sctp_send_initiate()
4862 sup_addr->ph.param_type = htons(SCTP_SUPPORTED_ADDRTYPE); in sctp_send_initiate()
4863 sup_addr->ph.param_length = htons(parameter_len); in sctp_send_initiate()
4865 if (stcb->asoc.scope.ipv4_addr_legal) { in sctp_send_initiate()
4866 sup_addr->addr_type[i++] = htons(SCTP_IPV4_ADDRESS); in sctp_send_initiate()
4868 if (stcb->asoc.scope.ipv6_addr_legal) { in sctp_send_initiate()
4869 sup_addr->addr_type[i++] = htons(SCTP_IPV6_ADDRESS); in sctp_send_initiate()
4871 padding_len = 4 - 2 * i; in sctp_send_initiate()
4883 m_last = sctp_add_addresses_to_i_ia(inp, stcb, &stcb->asoc.scope, in sctp_send_initiate()
4887 init->ch.chunk_length = htons(chunk_len); in sctp_send_initiate()
4894 SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - calls lowlevel_output\n"); in sctp_send_initiate()
4896 (struct sockaddr *)&net->ro._l_addr, in sctp_send_initiate()
4898 inp->sctp_lport, stcb->rport, htonl(0), in sctp_send_initiate()
4899 net->port, NULL, in sctp_send_initiate()
4904 stcb->asoc.ifp_had_enobuf = 1; in sctp_send_initiate()
4908 stcb->asoc.ifp_had_enobuf = 0; in sctp_send_initiate()
4911 (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); in sctp_send_initiate()
4923 * Given a mbuf containing an INIT or INIT-ACK with the param_offset in sctp_arethere_unrecognized_parameters()
4932 * By having param_offset be pre-set to where parameters begin it is in sctp_arethere_unrecognized_parameters()
4950 limit = ntohs(cp->chunk_length) - sizeof(struct sctp_init_chunk); in sctp_arethere_unrecognized_parameters()
4958 ptype = ntohs(phdr->param_type); in sctp_arethere_unrecognized_parameters()
4959 plen = ntohs(phdr->param_length); in sctp_arethere_unrecognized_parameters()
4962 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error %d\n", plen); in sctp_arethere_unrecognized_parameters()
4965 limit -= SCTP_SIZE32(plen); in sctp_arethere_unrecognized_parameters()
4966 /*- in sctp_arethere_unrecognized_parameters()
4971 * an operr.. to either incorporate (init-ack) or send. in sctp_arethere_unrecognized_parameters()
4992 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error chklist %d\n", plen); in sctp_arethere_unrecognized_parameters()
4999 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error supaddrtype %d\n", plen); in sctp_arethere_unrecognized_parameters()
5006 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error checksum acceptable %d\n", plen); in sctp_arethere_unrecognized_parameters()
5015 *edmid = ntohl(zero_chksum_p->edmid); in sctp_arethere_unrecognized_parameters()
5022 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error random %d\n", plen); in sctp_arethere_unrecognized_parameters()
5032 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error setprim %d\n", plen); in sctp_arethere_unrecognized_parameters()
5040 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ipv4 addr %d\n", plen); in sctp_arethere_unrecognized_parameters()
5047 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ipv6 addr %d\n", plen); in sctp_arethere_unrecognized_parameters()
5054 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error cookie-preserve %d\n", plen); in sctp_arethere_unrecognized_parameters()
5061 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error nat support %d\n", plen); in sctp_arethere_unrecognized_parameters()
5069 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error prsctp %d\n", plen); in sctp_arethere_unrecognized_parameters()
5076 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error ecn %d\n", plen); in sctp_arethere_unrecognized_parameters()
5083 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error adapatation %d\n", plen); in sctp_arethere_unrecognized_parameters()
5090 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Invalid size - error success %d\n", plen); in sctp_arethere_unrecognized_parameters()
5116 * Pre-reserve space for IP, SCTP, in sctp_arethere_unrecognized_parameters()
5128 cause->code = htons(SCTP_CAUSE_UNRESOLVABLE_ADDR); in sctp_arethere_unrecognized_parameters()
5129 cause->length = htons((uint16_t)(sizeof(struct sctp_gen_error_cause) + plen)); in sctp_arethere_unrecognized_parameters()
5199 param->param_type = htons(SCTP_UNRECOG_PARAM); in sctp_arethere_unrecognized_parameters()
5200 param->param_length = htons((uint16_t)sizeof(struct sctp_paramhdr) + plen); in sctp_arethere_unrecognized_parameters()
5214 pad_needed = 4 - (plen % 4); in sctp_arethere_unrecognized_parameters()
5262 param->param_type = htons(SCTP_CAUSE_PROTOCOL_VIOLATION); in sctp_arethere_unrecognized_parameters()
5263 param->param_length = htons(2 * sizeof(struct sctp_paramhdr)); in sctp_arethere_unrecognized_parameters()
5265 param->param_type = htons(ptype); in sctp_arethere_unrecognized_parameters()
5266 param->param_length = htons(plen); in sctp_arethere_unrecognized_parameters()
5311 switch (src->sa_family) { in sctp_are_there_new_addresses()
5314 if (asoc->scope.ipv4_addr_legal) { in sctp_are_there_new_addresses()
5321 if (asoc->scope.ipv6_addr_legal) { in sctp_are_there_new_addresses()
5332 TAILQ_FOREACH(net, &asoc->nets, sctp_next) { in sctp_are_there_new_addresses()
5333 sa = (struct sockaddr *)&net->ro._l_addr; in sctp_are_there_new_addresses()
5334 if (sa->sa_family == src->sa_family) { in sctp_are_there_new_addresses()
5336 if (sa->sa_family == AF_INET) { in sctp_are_there_new_addresses()
5341 if (sa4->sin_addr.s_addr == src4->sin_addr.s_addr) { in sctp_are_there_new_addresses()
5348 if (sa->sa_family == AF_INET6) { in sctp_are_there_new_addresses()
5377 ptype = ntohs(phdr->param_type); in sctp_are_there_new_addresses()
5378 plen = ntohs(phdr->param_length); in sctp_are_there_new_addresses()
5403 if (asoc->scope.ipv4_addr_legal) { in sctp_are_there_new_addresses()
5405 sin4.sin_addr.s_addr = p4->addr; in sctp_are_there_new_addresses()
5426 if (asoc->scope.ipv6_addr_legal) { in sctp_are_there_new_addresses()
5428 memcpy((caddr_t)&sin6.sin6_addr, p6->addr, in sctp_are_there_new_addresses()
5429 sizeof(p6->addr)); in sctp_are_there_new_addresses()
5442 TAILQ_FOREACH(net, &asoc->nets, sctp_next) { in sctp_are_there_new_addresses()
5443 sa = (struct sockaddr *)&net->ro._l_addr; in sctp_are_there_new_addresses()
5444 if (sa->sa_family != sa_touse->sa_family) { in sctp_are_there_new_addresses()
5448 if (sa->sa_family == AF_INET) { in sctp_are_there_new_addresses()
5450 if (sa4->sin_addr.s_addr == in sctp_are_there_new_addresses()
5458 if (sa->sa_family == AF_INET6) { in sctp_are_there_new_addresses()
5491 * INIT-ACK with COOKIE and send back. We assume that the in_initpkt has done
5539 asoc = &stcb->asoc; in sctp_send_initiate_ack()
5545 …if (sctp_are_there_new_addresses(asoc, init_pkt, offset, offset + ntohs(init_chk->ch.chunk_length)… in sctp_send_initiate_ack()
5547 * new addresses, out of here in non-cookie-wait in sctp_send_initiate_ack()
5551 mflowtype, mflowid, inp->fibnum, in sctp_send_initiate_ack()
5555 if (src_net != NULL && (src_net->port != port)) { in sctp_send_initiate_ack()
5558 * in non-cookie-wait states in sctp_send_initiate_ack()
5567 mflowtype, mflowid, inp->fibnum, in sctp_send_initiate_ack()
5588 init_chk->init.initiate_tag, op_err, in sctp_send_initiate_ack()
5589 mflowtype, mflowid, inp->fibnum, in sctp_send_initiate_ack()
5595 /* No memory, INIT timer will re-attempt. */ in sctp_send_initiate_ack()
5618 stc.tie_tag_my_vtag = asoc->my_vtag_nonce; in sctp_send_initiate_ack()
5619 stc.tie_tag_peer_vtag = asoc->peer_vtag_nonce; in sctp_send_initiate_ack()
5620 stc.cookie_life = asoc->cookie_life; in sctp_send_initiate_ack()
5621 net = asoc->primary_destination; in sctp_send_initiate_ack()
5626 stc.cookie_life = inp->sctp_ep.def_cookie_life; in sctp_send_initiate_ack()
5630 stc.myport = sh->dest_port; in sctp_send_initiate_ack()
5631 stc.peerport = sh->src_port; in sctp_send_initiate_ack()
5638 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { in sctp_send_initiate_ack()
5652 switch (dst->sa_family) { in sctp_send_initiate_ack()
5657 stc.address[0] = src4->sin_addr.s_addr; in sctp_send_initiate_ack()
5663 stc.laddress[0] = dst4->sin_addr.s_addr; in sctp_send_initiate_ack()
5670 if ((IN4_ISPRIVATE_ADDRESS(&src4->sin_addr)) || in sctp_send_initiate_ack()
5671 (IN4_ISPRIVATE_ADDRESS(&dst4->sin_addr))) { in sctp_send_initiate_ack()
5688 memcpy(&stc.address, &src6->sin6_addr, sizeof(struct in6_addr)); in sctp_send_initiate_ack()
5689 stc.scope_id = ntohs(in6_getscope(&src6->sin6_addr)); in sctp_send_initiate_ack()
5695 } else if (IN6_IS_ADDR_LINKLOCAL(&src6->sin6_addr) || in sctp_send_initiate_ack()
5696 IN6_IS_ADDR_LINKLOCAL(&dst6->sin6_addr)) { in sctp_send_initiate_ack()
5722 } else if (IN6_IS_ADDR_SITELOCAL(&src6->sin6_addr) || in sctp_send_initiate_ack()
5723 IN6_IS_ADDR_SITELOCAL(&dst6->sin6_addr)) { in sctp_send_initiate_ack()
5731 memcpy(&stc.laddress, &dst6->sin6_addr, sizeof(struct in6_addr)); in sctp_send_initiate_ack()
5748 stc.loopback_scope = asoc->scope.loopback_scope; in sctp_send_initiate_ack()
5749 stc.ipv4_scope = asoc->scope.ipv4_local_scope; in sctp_send_initiate_ack()
5750 stc.site_scope = asoc->scope.site_scope; in sctp_send_initiate_ack()
5751 stc.local_scope = asoc->scope.local_scope; in sctp_send_initiate_ack()
5754 TAILQ_FOREACH(lnet, &asoc->nets, sctp_next) { in sctp_send_initiate_ack()
5755 if (lnet->ro._l_addr.sin6.sin6_family == AF_INET6) { in sctp_send_initiate_ack()
5756 if (IN6_IS_ADDR_LINKLOCAL(&lnet->ro._l_addr.sin6.sin6_addr)) { in sctp_send_initiate_ack()
5767 to = (struct sockaddr *)&net->ro._l_addr; in sctp_send_initiate_ack()
5768 switch (to->sa_family) { in sctp_send_initiate_ack()
5772 stc.address[0] = sin->sin_addr.s_addr; in sctp_send_initiate_ack()
5777 if (net->src_addr_selected == 0) { in sctp_send_initiate_ack()
5782 net->ro._s_addr = sctp_source_address_selection(inp, in sctp_send_initiate_ack()
5783 stcb, (sctp_route_t *)&net->ro, in sctp_send_initiate_ack()
5785 if (net->ro._s_addr == NULL) { in sctp_send_initiate_ack()
5791 net->src_addr_selected = 1; in sctp_send_initiate_ack()
5793 stc.laddress[0] = net->ro._s_addr->address.sin.sin_addr.s_addr; in sctp_send_initiate_ack()
5805 memcpy(&stc.address, &sin6->sin6_addr, in sctp_send_initiate_ack()
5808 stc.scope_id = sin6->sin6_scope_id; in sctp_send_initiate_ack()
5809 if (net->src_addr_selected == 0) { in sctp_send_initiate_ack()
5814 net->ro._s_addr = sctp_source_address_selection(inp, in sctp_send_initiate_ack()
5815 stcb, (sctp_route_t *)&net->ro, in sctp_send_initiate_ack()
5817 if (net->ro._s_addr == NULL) { in sctp_send_initiate_ack()
5823 net->src_addr_selected = 1; in sctp_send_initiate_ack()
5825 memcpy(&stc.laddress, &net->ro._s_addr->address.sin6.sin6_addr, in sctp_send_initiate_ack()
5833 stc.rcv_edmid = asoc->rcv_edmid; in sctp_send_initiate_ack()
5835 stc.rcv_edmid = inp->rcv_edmid; in sctp_send_initiate_ack()
5840 stc.peers_vtag = ntohl(init_chk->init.initiate_tag); in sctp_send_initiate_ack()
5846 initack->ch.chunk_type = SCTP_INITIATION_ACK; in sctp_send_initiate_ack()
5847 initack->ch.chunk_flags = 0; in sctp_send_initiate_ack()
5849 initack->ch.chunk_length = 0; in sctp_send_initiate_ack()
5855 /* re-use the v-tags and init-seq here */ in sctp_send_initiate_ack()
5856 initack->init.initiate_tag = htonl(asoc->my_vtag); in sctp_send_initiate_ack()
5857 initack->init.initial_tsn = htonl(asoc->init_seq_number); in sctp_send_initiate_ack()
5862 atomic_add_int(&asoc->refcnt, 1); in sctp_send_initiate_ack()
5866 vtag = sctp_select_a_tag(inp, inp->sctp_lport, sh->src_port, 1); in sctp_send_initiate_ack()
5868 if ((asoc->peer_supports_nat) && (vtag == asoc->my_vtag)) { in sctp_send_initiate_ack()
5875 initack->init.initiate_tag = htonl(vtag); in sctp_send_initiate_ack()
5877 itsn = sctp_select_initial_TSN(&inp->sctp_ep); in sctp_send_initiate_ack()
5878 initack->init.initial_tsn = htonl(itsn); in sctp_send_initiate_ack()
5880 atomic_subtract_int(&asoc->refcnt, 1); in sctp_send_initiate_ack()
5885 vtag = sctp_select_a_tag(inp, inp->sctp_lport, sh->src_port, 1); in sctp_send_initiate_ack()
5887 initack->init.initiate_tag = htonl(vtag); in sctp_send_initiate_ack()
5889 initack->init.initial_tsn = htonl(sctp_select_initial_TSN(&inp->sctp_ep)); in sctp_send_initiate_ack()
5895 stc.my_vtag = initack->init.initiate_tag; in sctp_send_initiate_ack()
5898 so = inp->sctp_socket; in sctp_send_initiate_ack()
5905 initack->init.a_rwnd = htonl(max(SCTP_SB_LIMIT_RCV(so), SCTP_MINIMAL_RWND)); in sctp_send_initiate_ack()
5908 his_limit = ntohs(init_chk->init.num_inbound_streams); in sctp_send_initiate_ack()
5911 if (asoc->streamoutcnt > asoc->pre_open_streams) { in sctp_send_initiate_ack()
5912 i_want = asoc->streamoutcnt; in sctp_send_initiate_ack()
5914 i_want = asoc->pre_open_streams; in sctp_send_initiate_ack()
5917 i_want = inp->sctp_ep.pre_open_stream_count; in sctp_send_initiate_ack()
5921 initack->init.num_outbound_streams = init_chk->init.num_inbound_streams; in sctp_send_initiate_ack()
5924 initack->init.num_outbound_streams = htons(i_want); in sctp_send_initiate_ack()
5927 initack->init.num_inbound_streams = in sctp_send_initiate_ack()
5928 htons(inp->sctp_ep.max_open_streams_intome); in sctp_send_initiate_ack()
5931 if (inp->sctp_ep.adaptation_layer_indicator_provided) { in sctp_send_initiate_ack()
5934 ali->ph.param_type = htons(SCTP_ULP_ADAPTATION); in sctp_send_initiate_ack()
5935 ali->ph.param_length = htons(parameter_len); in sctp_send_initiate_ack()
5936 ali->indication = htonl(inp->sctp_ep.adaptation_layer_indicator); in sctp_send_initiate_ack()
5941 if (((asoc != NULL) && (asoc->ecn_supported == 1)) || in sctp_send_initiate_ack()
5942 ((asoc == NULL) && (inp->ecn_supported == 1))) { in sctp_send_initiate_ack()
5945 ph->param_type = htons(SCTP_ECN_CAPABLE); in sctp_send_initiate_ack()
5946 ph->param_length = htons(parameter_len); in sctp_send_initiate_ack()
5950 /* PR-SCTP supported parameter */ in sctp_send_initiate_ack()
5951 if (((asoc != NULL) && (asoc->prsctp_supported == 1)) || in sctp_send_initiate_ack()
5952 ((asoc == NULL) && (inp->prsctp_supported == 1))) { in sctp_send_initiate_ack()
5955 ph->param_type = htons(SCTP_PRSCTP_SUPPORTED); in sctp_send_initiate_ack()
5956 ph->param_length = htons(parameter_len); in sctp_send_initiate_ack()
5961 if (((asoc != NULL) && (asoc->rcv_edmid != SCTP_EDMID_NONE)) || in sctp_send_initiate_ack()
5962 ((asoc == NULL) && (inp->rcv_edmid != SCTP_EDMID_NONE))) { in sctp_send_initiate_ack()
5965 zero_chksum->ph.param_type = htons(SCTP_ZERO_CHECKSUM_ACCEPTABLE); in sctp_send_initiate_ack()
5966 zero_chksum->ph.param_length = htons(parameter_len); in sctp_send_initiate_ack()
5968 zero_chksum->edmid = htonl(asoc->rcv_edmid); in sctp_send_initiate_ack()
5970 zero_chksum->edmid = htonl(inp->rcv_edmid); in sctp_send_initiate_ack()
5979 ph->param_type = htons(SCTP_HAS_NAT_SUPPORT); in sctp_send_initiate_ack()
5980 ph->param_length = htons(parameter_len); in sctp_send_initiate_ack()
5987 if (((asoc != NULL) && (asoc->prsctp_supported == 1)) || in sctp_send_initiate_ack()
5988 ((asoc == NULL) && (inp->prsctp_supported == 1))) { in sctp_send_initiate_ack()
5989 pr_supported->chunk_types[num_ext++] = SCTP_FORWARD_CUM_TSN; in sctp_send_initiate_ack()
5990 if (((asoc != NULL) && (asoc->idata_supported == 1)) || in sctp_send_initiate_ack()
5991 ((asoc == NULL) && (inp->idata_supported == 1))) { in sctp_send_initiate_ack()
5992 pr_supported->chunk_types[num_ext++] = SCTP_IFORWARD_CUM_TSN; in sctp_send_initiate_ack()
5995 if (((asoc != NULL) && (asoc->auth_supported == 1)) || in sctp_send_initiate_ack()
5996 ((asoc == NULL) && (inp->auth_supported == 1))) { in sctp_send_initiate_ack()
5997 pr_supported->chunk_types[num_ext++] = SCTP_AUTHENTICATION; in sctp_send_initiate_ack()
5999 if (((asoc != NULL) && (asoc->asconf_supported == 1)) || in sctp_send_initiate_ack()
6000 ((asoc == NULL) && (inp->asconf_supported == 1))) { in sctp_send_initiate_ack()
6001 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF; in sctp_send_initiate_ack()
6002 pr_supported->chunk_types[num_ext++] = SCTP_ASCONF_ACK; in sctp_send_initiate_ack()
6004 if (((asoc != NULL) && (asoc->reconfig_supported == 1)) || in sctp_send_initiate_ack()
6005 ((asoc == NULL) && (inp->reconfig_supported == 1))) { in sctp_send_initiate_ack()
6006 pr_supported->chunk_types[num_ext++] = SCTP_STREAM_RESET; in sctp_send_initiate_ack()
6008 if (((asoc != NULL) && (asoc->idata_supported == 1)) || in sctp_send_initiate_ack()
6009 ((asoc == NULL) && (inp->idata_supported == 1))) { in sctp_send_initiate_ack()
6010 pr_supported->chunk_types[num_ext++] = SCTP_IDATA; in sctp_send_initiate_ack()
6012 if (((asoc != NULL) && (asoc->nrsack_supported == 1)) || in sctp_send_initiate_ack()
6013 ((asoc == NULL) && (inp->nrsack_supported == 1))) { in sctp_send_initiate_ack()
6014 pr_supported->chunk_types[num_ext++] = SCTP_NR_SELECTIVE_ACK; in sctp_send_initiate_ack()
6016 if (((asoc != NULL) && (asoc->pktdrop_supported == 1)) || in sctp_send_initiate_ack()
6017 ((asoc == NULL) && (inp->pktdrop_supported == 1))) { in sctp_send_initiate_ack()
6018 pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED; in sctp_send_initiate_ack()
6022 pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT); in sctp_send_initiate_ack()
6023 pr_supported->ph.param_length = htons(parameter_len); in sctp_send_initiate_ack()
6024 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate_ack()
6029 if (((asoc != NULL) && (asoc->auth_supported == 1)) || in sctp_send_initiate_ack()
6030 ((asoc == NULL) && (inp->auth_supported == 1))) { in sctp_send_initiate_ack()
6044 randp->ph.param_type = htons(SCTP_RANDOM); in sctp_send_initiate_ack()
6045 randp->ph.param_length = htons(parameter_len); in sctp_send_initiate_ack()
6046 SCTP_READ_RANDOM(randp->random_data, SCTP_AUTH_RANDOM_SIZE_DEFAULT); in sctp_send_initiate_ack()
6047 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate_ack()
6058 sctp_serialize_hmaclist(inp->sctp_ep.local_hmacs, in sctp_send_initiate_ack()
6059 (uint8_t *)hmacs->hmac_ids); in sctp_send_initiate_ack()
6060 hmacs->ph.param_type = htons(SCTP_HMAC_LIST); in sctp_send_initiate_ack()
6061 hmacs->ph.param_length = htons(parameter_len); in sctp_send_initiate_ack()
6062 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate_ack()
6073 sctp_serialize_auth_chunks(inp->sctp_ep.local_auth_chunks, in sctp_send_initiate_ack()
6074 chunks->chunk_types); in sctp_send_initiate_ack()
6075 chunks->ph.param_type = htons(SCTP_CHUNK_LIST); in sctp_send_initiate_ack()
6076 chunks->ph.param_length = htons(parameter_len); in sctp_send_initiate_ack()
6077 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate_ack()
6112 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate_ack()
6145 padding_len = SCTP_SIZE32(parameter_len) - parameter_len; in sctp_send_initiate_ack()
6150 * the INIT-ACK. in sctp_send_initiate_ack()
6152 initack->ch.chunk_length = htons(chunk_len); in sctp_send_initiate_ack()
6159 (uint8_t *)inp->sctp_ep.secret_key[(int)(inp->sctp_ep.current_secret_number)], in sctp_send_initiate_ack()
6179 use_zero_crc = (asoc->rcv_edmid != SCTP_EDMID_NONE) && (asoc->rcv_edmid == edmid); in sctp_send_initiate_ack()
6181 use_zero_crc = (inp->rcv_edmid != SCTP_EDMID_NONE) && (inp->rcv_edmid == edmid); in sctp_send_initiate_ack()
6186 inp->sctp_lport, sh->src_port, init_chk->init.initiate_tag, in sctp_send_initiate_ack()
6194 asoc->ifp_had_enobuf = 1; in sctp_send_initiate_ack()
6200 asoc->ifp_had_enobuf = 0; in sctp_send_initiate_ack()
6216 if ((asoc->prsctp_supported) && in sctp_prune_prsctp()
6217 (asoc->sent_queue_cnt_removeable > 0)) { in sctp_prune_prsctp()
6218 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { in sctp_prune_prsctp()
6225 if (PR_SCTP_BUF_ENABLED(chk->flags)) { in sctp_prune_prsctp()
6227 * This one is PR-SCTP AND buffer space in sctp_prune_prsctp()
6230 if (chk->rec.data.timetodrop.tv_sec > (long)srcv->sinfo_timetolive) { in sctp_prune_prsctp()
6238 if (chk->data) { in sctp_prune_prsctp()
6246 if (chk->sent > SCTP_DATAGRAM_UNSENT) in sctp_prune_prsctp()
6262 TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) { in sctp_prune_prsctp()
6264 if (PR_SCTP_BUF_ENABLED(chk->flags)) { in sctp_prune_prsctp()
6265 if (chk->rec.data.timetodrop.tv_sec > (long)srcv->sinfo_timetolive) { in sctp_prune_prsctp()
6266 if (chk->data) { in sctp_prune_prsctp()
6280 } /* end if chk->data */ in sctp_prune_prsctp()
6282 } /* end if chk pr-sctp */ in sctp_prune_prsctp()
6293 asoc = &stcb->asoc; in sctp_get_frag_point()
6295 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { in sctp_get_frag_point()
6301 if (asoc->idata_supported) { in sctp_get_frag_point()
6303 if (sctp_auth_is_required_chunk(SCTP_IDATA, asoc->peer_auth_chunks)) { in sctp_get_frag_point()
6304 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id); in sctp_get_frag_point()
6308 if (sctp_auth_is_required_chunk(SCTP_DATA, asoc->peer_auth_chunks)) { in sctp_get_frag_point()
6309 overhead += sctp_get_auth_chunk_len(asoc->peer_hmac_id); in sctp_get_frag_point()
6315 if (asoc->smallest_mtu % 4 > 0) { in sctp_get_frag_point()
6316 overhead += (asoc->smallest_mtu % 4); in sctp_get_frag_point()
6318 KASSERT(asoc->smallest_mtu > overhead, in sctp_get_frag_point()
6320 asoc->smallest_mtu, overhead)); in sctp_get_frag_point()
6321 frag_point = asoc->smallest_mtu - overhead; in sctp_get_frag_point()
6325 if ((asoc->sctp_frag_point > 0) && in sctp_get_frag_point()
6326 (asoc->sctp_frag_point < frag_point)) { in sctp_get_frag_point()
6327 frag_point = asoc->sctp_frag_point; in sctp_get_frag_point()
6339 if (PR_SCTP_ENABLED(sp->sinfo_flags)) { in sctp_set_prsctp_policy()
6340 sp->act_flags |= PR_SCTP_POLICY(sp->sinfo_flags); in sctp_set_prsctp_policy()
6341 } else if (sp->timetolive > 0) { in sctp_set_prsctp_policy()
6342 sp->sinfo_flags |= SCTP_PR_SCTP_TTL; in sctp_set_prsctp_policy()
6343 sp->act_flags |= PR_SCTP_POLICY(sp->sinfo_flags); in sctp_set_prsctp_policy()
6347 switch (PR_SCTP_POLICY(sp->sinfo_flags)) { in sctp_set_prsctp_policy()
6353 sp->ts.tv_sec = sp->timetolive; in sctp_set_prsctp_policy()
6354 sp->ts.tv_usec = 0; in sctp_set_prsctp_policy()
6360 (void)SCTP_GETTIME_TIMEVAL(&sp->ts); in sctp_set_prsctp_policy()
6361 tv.tv_sec = sp->timetolive / 1000; in sctp_set_prsctp_policy()
6362 tv.tv_usec = (sp->timetolive * 1000) % 1000000; in sctp_set_prsctp_policy()
6367 timevaladd(&sp->ts, &tv); in sctp_set_prsctp_policy()
6375 sp->ts.tv_sec = sp->timetolive; in sctp_set_prsctp_policy()
6376 sp->ts.tv_usec = 0; in sctp_set_prsctp_policy()
6381 PR_SCTP_POLICY(sp->sinfo_flags)); in sctp_set_prsctp_policy()
6403 if (srcv->sinfo_stream >= stcb->asoc.streamoutcnt) { in sctp_msg_append()
6409 if ((stcb->asoc.stream_locked) && in sctp_msg_append()
6410 (stcb->asoc.stream_locked_on != srcv->sinfo_stream)) { in sctp_msg_append()
6415 if ((stcb->asoc.strmout[srcv->sinfo_stream].state != SCTP_STREAM_OPEN) && in sctp_msg_append()
6416 (stcb->asoc.strmout[srcv->sinfo_stream].state != SCTP_STREAM_OPENING)) { in sctp_msg_append()
6420 if (stcb->asoc.strmout[srcv->sinfo_stream].state > SCTP_STREAM_OPEN) { in sctp_msg_append()
6431 (stcb->asoc.state & SCTP_STATE_SHUTDOWN_PENDING)) { in sctp_msg_append()
6443 sp->sinfo_flags = srcv->sinfo_flags; in sctp_msg_append()
6444 sp->timetolive = srcv->sinfo_timetolive; in sctp_msg_append()
6445 sp->ppid = srcv->sinfo_ppid; in sctp_msg_append()
6446 sp->context = srcv->sinfo_context; in sctp_msg_append()
6447 sp->fsn = 0; in sctp_msg_append()
6448 if (sp->sinfo_flags & SCTP_ADDR_OVER) { in sctp_msg_append()
6449 sp->net = net; in sctp_msg_append()
6450 atomic_add_int(&sp->net->ref_count, 1); in sctp_msg_append()
6452 sp->net = NULL; in sctp_msg_append()
6454 (void)SCTP_GETTIME_TIMEVAL(&sp->ts); in sctp_msg_append()
6455 sp->sid = srcv->sinfo_stream; in sctp_msg_append()
6456 sp->msg_is_complete = 1; in sctp_msg_append()
6457 sp->sender_all_done = 1; in sctp_msg_append()
6458 sp->some_taken = 0; in sctp_msg_append()
6459 sp->data = m; in sctp_msg_append()
6460 sp->tail_mbuf = NULL; in sctp_msg_append()
6467 sp->length = 0; in sctp_msg_append()
6470 sp->tail_mbuf = at; in sctp_msg_append()
6471 sp->length += SCTP_BUF_LEN(at); in sctp_msg_append()
6473 if (srcv->sinfo_keynumber_valid) { in sctp_msg_append()
6474 sp->auth_keyid = srcv->sinfo_keynumber; in sctp_msg_append()
6476 sp->auth_keyid = stcb->asoc.authinfo.active_keyid; in sctp_msg_append()
6478 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { in sctp_msg_append()
6479 sctp_auth_key_acquire(stcb, sp->auth_keyid); in sctp_msg_append()
6480 sp->holds_key_ref = 1; in sctp_msg_append()
6482 strm = &stcb->asoc.strmout[srcv->sinfo_stream]; in sctp_msg_append()
6483 sctp_snd_sb_alloc(stcb, sp->length); in sctp_msg_append()
6484 atomic_add_int(&stcb->asoc.stream_queue_cnt, 1); in sctp_msg_append()
6485 TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); in sctp_msg_append()
6486 stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, strm, sp); in sctp_msg_append()
6519 (sizeofcpy <= (int)((((SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) - 1) * MLEN) + MHLEN)))) { in sctp_copy_mbufchain()
6578 sizeofcpy -= len; in sctp_copy_mbufchain()
6623 * save off the end and update the end-chain position in sctp_copy_mbufchain()
6635 /* save off the end and update the end-chain position */ in sctp_copy_mbufchain()
6671 if (ca->m == NULL) { in sctp_sendall_iterator()
6674 if (ca->inp != inp) { in sctp_sendall_iterator()
6678 if (ca->sndlen > 0) { in sctp_sendall_iterator()
6679 m = SCTP_M_COPYM(ca->m, 0, M_COPYALL, M_NOWAIT); in sctp_sendall_iterator()
6682 ca->cnt_failed++; in sctp_sendall_iterator()
6694 if (stcb->asoc.alternate) { in sctp_sendall_iterator()
6695 net = stcb->asoc.alternate; in sctp_sendall_iterator()
6697 net = stcb->asoc.primary_destination; in sctp_sendall_iterator()
6699 if (ca->sndrcv.sinfo_flags & SCTP_ABORT) { in sctp_sendall_iterator()
6714 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); in sctp_sendall_iterator()
6715 ph->param_length = htons((uint16_t)(sizeof(struct sctp_paramhdr) + ca->sndlen)); in sctp_sendall_iterator()
6718 * We add one here to keep the assoc from dis-appearing on in sctp_sendall_iterator()
6721 atomic_add_int(&stcb->asoc.refcnt, 1); in sctp_sendall_iterator()
6730 * stcb will return to us un-locked.. since free_asoc in sctp_sendall_iterator()
6732 * relock.. to unlock in the iterator timer :-0 in sctp_sendall_iterator()
6735 atomic_subtract_int(&stcb->asoc.refcnt, 1); in sctp_sendall_iterator()
6739 ret = sctp_msg_append(stcb, net, m, &ca->sndrcv); in sctp_sendall_iterator()
6741 asoc = &stcb->asoc; in sctp_sendall_iterator()
6742 if (ca->sndrcv.sinfo_flags & SCTP_EOF) { in sctp_sendall_iterator()
6744 if (TAILQ_EMPTY(&asoc->send_queue) && in sctp_sendall_iterator()
6745 TAILQ_EMPTY(&asoc->sent_queue) && in sctp_sendall_iterator()
6747 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) { in sctp_sendall_iterator()
6767 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, in sctp_sendall_iterator()
6769 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, in sctp_sendall_iterator()
6783 * and move to SHUTDOWN-PENDING in sctp_sendall_iterator()
6788 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) { in sctp_sendall_iterator()
6792 if (TAILQ_EMPTY(&asoc->send_queue) && in sctp_sendall_iterator()
6793 TAILQ_EMPTY(&asoc->sent_queue) && in sctp_sendall_iterator()
6794 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { in sctp_sendall_iterator()
6803 atomic_add_int(&stcb->asoc.refcnt, 1); in sctp_sendall_iterator()
6804 sctp_abort_an_association(stcb->sctp_ep, stcb, in sctp_sendall_iterator()
6806 atomic_subtract_int(&stcb->asoc.refcnt, 1); in sctp_sendall_iterator()
6813 un_sent = ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) + in sctp_sendall_iterator()
6814 (stcb->asoc.stream_queue_cnt * SCTP_DATA_CHUNK_OVERHEAD(stcb))); in sctp_sendall_iterator()
6817 (stcb->asoc.total_flight > 0) && in sctp_sendall_iterator()
6818 (un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD))) { in sctp_sendall_iterator()
6827 (void)sctp_med_chunk_output(inp, stcb, &stcb->asoc, &num_out, in sctp_sendall_iterator()
6834 ca->cnt_failed++; in sctp_sendall_iterator()
6836 ca->cnt_sent++; in sctp_sendall_iterator()
6852 * user you can't send the data :-> in sctp_sendall_completes()
6856 if (ca->inp) { in sctp_sendall_completes()
6858 SCTP_INP_WLOCK(ca->inp); in sctp_sendall_completes()
6859 ca->inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP; in sctp_sendall_completes()
6860 SCTP_INP_WUNLOCK(ca->inp); in sctp_sendall_completes()
6862 sctp_m_freem(ca->m); in sctp_sendall_completes()
6893 left -= willcpy; in sctp_copy_out_all()
6918 sndlen = uio->uio_resid; in sctp_sendall()
6937 ca->inp = inp; in sctp_sendall()
6939 memcpy(&ca->sndrcv, srcv, sizeof(struct sctp_nonpad_sndrcvinfo)); in sctp_sendall()
6943 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SND_ITERATOR_UP) != 0) { in sctp_sendall()
6949 inp->sctp_flags |= SCTP_PCB_FLAGS_SND_ITERATOR_UP; in sctp_sendall()
6953 * this :-0 in sctp_sendall()
6955 ca->sndrcv.sinfo_flags &= ~SCTP_SENDALL; in sctp_sendall()
6957 ca->sndlen = sndlen; in sctp_sendall()
6959 ca->m = sctp_copy_out_all(uio, ca->sndlen); in sctp_sendall()
6960 if (ca->m == NULL) { in sctp_sendall()
6964 inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP; in sctp_sendall()
6970 ca->m = m; in sctp_sendall()
6979 inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP; in sctp_sendall()
6993 TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) { in sctp_toss_old_cookies()
6994 if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) { in sctp_toss_old_cookies()
6995 TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next); in sctp_toss_old_cookies()
6996 asoc->ctrl_queue_cnt--; in sctp_toss_old_cookies()
6997 if (chk->data) { in sctp_toss_old_cookies()
6998 sctp_m_freem(chk->data); in sctp_toss_old_cookies()
6999 chk->data = NULL; in sctp_toss_old_cookies()
7013 asoc = &stcb->asoc; in sctp_toss_old_asconf()
7014 TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) { in sctp_toss_old_asconf()
7016 if (chk->rec.chunk_id.id == SCTP_ASCONF) { in sctp_toss_old_asconf()
7017 if (chk->data) { in sctp_toss_old_asconf()
7018 acp = mtod(chk->data, struct sctp_asconf_chunk *); in sctp_toss_old_asconf()
7019 if (SCTP_TSN_GT(ntohl(acp->serial_number), asoc->asconf_seq_out_acked)) { in sctp_toss_old_asconf()
7024 TAILQ_REMOVE(&asoc->asconf_send_queue, chk, sctp_next); in sctp_toss_old_asconf()
7025 asoc->ctrl_queue_cnt--; in sctp_toss_old_asconf()
7026 if (chk->data) { in sctp_toss_old_asconf()
7027 sctp_m_freem(chk->data); in sctp_toss_old_asconf()
7028 chk->data = NULL; in sctp_toss_old_asconf()
7047 TAILQ_REMOVE(&asoc->send_queue, data_list[i], sctp_next); in sctp_clean_up_datalist()
7048 asoc->send_queue_cnt--; in sctp_clean_up_datalist()
7055 data_list[i]->do_rtt = 0; in sctp_clean_up_datalist()
7058 data_list[i]->sent_rcv_time = net->last_sent_time; in sctp_clean_up_datalist()
7059 data_list[i]->rec.data.cwnd_at_send = net->cwnd; in sctp_clean_up_datalist()
7060 data_list[i]->rec.data.fast_retran_tsn = data_list[i]->rec.data.tsn; in sctp_clean_up_datalist()
7061 if (data_list[i]->whoTo == NULL) { in sctp_clean_up_datalist()
7062 data_list[i]->whoTo = net; in sctp_clean_up_datalist()
7063 atomic_add_int(&net->ref_count, 1); in sctp_clean_up_datalist()
7066 tp1 = TAILQ_LAST(&asoc->sent_queue, sctpchunk_listhead); in sctp_clean_up_datalist()
7067 if ((tp1) && SCTP_TSN_GT(tp1->rec.data.tsn, data_list[i]->rec.data.tsn)) { in sctp_clean_up_datalist()
7078 if (SCTP_TSN_GT(tp1->rec.data.tsn, data_list[i]->rec.data.tsn)) { in sctp_clean_up_datalist()
7081 TAILQ_INSERT_AFTER(&asoc->sent_queue, tp1, data_list[i], sctp_next); in sctp_clean_up_datalist()
7083 TAILQ_INSERT_TAIL(&asoc->sent_queue, in sctp_clean_up_datalist()
7088 /* This does not lower until the cum-ack passes it */ in sctp_clean_up_datalist()
7089 asoc->sent_queue_cnt++; in sctp_clean_up_datalist()
7090 if ((asoc->peers_rwnd <= 0) && in sctp_clean_up_datalist()
7091 (asoc->total_flight == 0) && in sctp_clean_up_datalist()
7099 data_list[i]->sent = SCTP_DATAGRAM_SENT; in sctp_clean_up_datalist()
7100 data_list[i]->snd_count = 1; in sctp_clean_up_datalist()
7101 data_list[i]->rec.data.chunk_was_revoked = 0; in sctp_clean_up_datalist()
7104 data_list[i]->whoTo->flight_size, in sctp_clean_up_datalist()
7105 data_list[i]->book_size, in sctp_clean_up_datalist()
7106 (uint32_t)(uintptr_t)data_list[i]->whoTo, in sctp_clean_up_datalist()
7107 data_list[i]->rec.data.tsn); in sctp_clean_up_datalist()
7113 asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); in sctp_clean_up_datalist()
7115 asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd, in sctp_clean_up_datalist()
7116 (uint32_t)(data_list[i]->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh))); in sctp_clean_up_datalist()
7117 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { in sctp_clean_up_datalist()
7119 asoc->peers_rwnd = 0; in sctp_clean_up_datalist()
7122 if (asoc->cc_functions.sctp_cwnd_update_packet_transmitted) { in sctp_clean_up_datalist()
7123 (*asoc->cc_functions.sctp_cwnd_update_packet_transmitted) (stcb, net); in sctp_clean_up_datalist()
7132 TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) { in sctp_clean_up_ctl()
7133 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || in sctp_clean_up_ctl()
7134 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK) || /* EY */ in sctp_clean_up_ctl()
7135 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) || in sctp_clean_up_ctl()
7136 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_ACK) || in sctp_clean_up_ctl()
7137 (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) || in sctp_clean_up_ctl()
7138 (chk->rec.chunk_id.id == SCTP_SHUTDOWN) || in sctp_clean_up_ctl()
7139 (chk->rec.chunk_id.id == SCTP_SHUTDOWN_ACK) || in sctp_clean_up_ctl()
7140 (chk->rec.chunk_id.id == SCTP_OPERATION_ERROR) || in sctp_clean_up_ctl()
7141 (chk->rec.chunk_id.id == SCTP_PACKET_DROPPED) || in sctp_clean_up_ctl()
7142 (chk->rec.chunk_id.id == SCTP_COOKIE_ACK) || in sctp_clean_up_ctl()
7143 (chk->rec.chunk_id.id == SCTP_ECN_CWR) || in sctp_clean_up_ctl()
7144 (chk->rec.chunk_id.id == SCTP_ASCONF_ACK)) { in sctp_clean_up_ctl()
7147 TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next); in sctp_clean_up_ctl()
7148 asoc->ctrl_queue_cnt--; in sctp_clean_up_ctl()
7149 if (chk->data) { in sctp_clean_up_ctl()
7150 sctp_m_freem(chk->data); in sctp_clean_up_ctl()
7151 chk->data = NULL; in sctp_clean_up_ctl()
7153 if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) { in sctp_clean_up_ctl()
7154 asoc->fwd_tsn_cnt--; in sctp_clean_up_ctl()
7157 } else if (chk->rec.chunk_id.id == SCTP_STREAM_RESET) { in sctp_clean_up_ctl()
7159 if (chk != asoc->str_reset) { in sctp_clean_up_ctl()
7181 /*- in sctp_can_we_split_this()
7184 * arrives to transmit - wait for more data in sctp_can_we_split_this()
7186 if (stcb->asoc.total_flight == 0) { in sctp_can_we_split_this()
7200 /*- in sctp_can_we_split_this()
7205 if (SCTP_SB_LIMIT_SND(stcb->sctp_socket) < frag_point) { in sctp_can_we_split_this()
7209 ((length - space_left) < SCTP_BASE_SYSCTL(sctp_min_residual))) { in sctp_can_we_split_this()
7210 /* Sub-optimal residual don't split in non-eeor mode. */ in sctp_can_we_split_this()
7248 asoc = &stcb->asoc; in sctp_move_to_outqueue()
7251 sp = TAILQ_FIRST(&strq->outqueue); in sctp_move_to_outqueue()
7253 sp = TAILQ_FIRST(&strq->outqueue); in sctp_move_to_outqueue()
7257 if ((sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_EXPLICIT_EOR) == 0) && in sctp_move_to_outqueue()
7258 (stcb->asoc.idata_supported == 0) && in sctp_move_to_outqueue()
7259 (strq->last_msg_incomplete)) { in sctp_move_to_outqueue()
7261 strq->sid, in sctp_move_to_outqueue()
7262 strq->last_msg_incomplete); in sctp_move_to_outqueue()
7263 strq->last_msg_incomplete = 0; in sctp_move_to_outqueue()
7268 if ((sp->msg_is_complete) && (sp->length == 0)) { in sctp_move_to_outqueue()
7269 if (sp->sender_all_done) { in sctp_move_to_outqueue()
7275 if ((sp->put_last_out == 0) && (sp->discard_rest == 0)) { in sctp_move_to_outqueue()
7276 SCTP_PRINTF("Gak, put out entire msg with NO end!-1\n"); in sctp_move_to_outqueue()
7278 sp->sender_all_done, in sctp_move_to_outqueue()
7279 sp->length, in sctp_move_to_outqueue()
7280 sp->msg_is_complete, in sctp_move_to_outqueue()
7281 sp->put_last_out); in sctp_move_to_outqueue()
7283 atomic_subtract_int(&asoc->stream_queue_cnt, 1); in sctp_move_to_outqueue()
7284 TAILQ_REMOVE(&strq->outqueue, sp, next); in sctp_move_to_outqueue()
7285 stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp); in sctp_move_to_outqueue()
7286 if ((strq->state == SCTP_STREAM_RESET_PENDING) && in sctp_move_to_outqueue()
7287 (strq->chunks_on_queues == 0) && in sctp_move_to_outqueue()
7288 TAILQ_EMPTY(&strq->outqueue)) { in sctp_move_to_outqueue()
7289 stcb->asoc.trigger_reset = 1; in sctp_move_to_outqueue()
7291 if (sp->net) { in sctp_move_to_outqueue()
7292 sctp_free_remote_addr(sp->net); in sctp_move_to_outqueue()
7293 sp->net = NULL; in sctp_move_to_outqueue()
7295 if (sp->data) { in sctp_move_to_outqueue()
7296 sctp_m_freem(sp->data); in sctp_move_to_outqueue()
7297 sp->data = NULL; in sctp_move_to_outqueue()
7313 if (sp->length == 0) { in sctp_move_to_outqueue()
7318 } else if (sp->discard_rest) { in sctp_move_to_outqueue()
7320 atomic_subtract_int(&stcb->asoc.total_output_queue_size, sp->length); in sctp_move_to_outqueue()
7321 if ((stcb->sctp_socket != NULL) && in sctp_move_to_outqueue()
7322 ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || in sctp_move_to_outqueue()
7323 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { in sctp_move_to_outqueue()
7324 SCTP_SB_DECR(&stcb->sctp_socket->so_snd, sp->length); in sctp_move_to_outqueue()
7326 if (sp->data) { in sctp_move_to_outqueue()
7327 sctp_m_freem(sp->data); in sctp_move_to_outqueue()
7328 sp->data = NULL; in sctp_move_to_outqueue()
7329 sp->tail_mbuf = NULL; in sctp_move_to_outqueue()
7331 sp->length = 0; in sctp_move_to_outqueue()
7332 sp->some_taken = 1; in sctp_move_to_outqueue()
7338 some_taken = sp->some_taken; in sctp_move_to_outqueue()
7339 length = sp->length; in sctp_move_to_outqueue()
7340 if (sp->msg_is_complete) { in sctp_move_to_outqueue()
7345 if (sp->some_taken) { in sctp_move_to_outqueue()
7350 sp->put_last_out = 1; in sctp_move_to_outqueue()
7351 if (sp->sinfo_flags & SCTP_SACK_IMMEDIATELY) { in sctp_move_to_outqueue()
7356 if (sp->some_taken == 0) { in sctp_move_to_outqueue()
7359 sp->some_taken = 1; in sctp_move_to_outqueue()
7367 if (sp->some_taken == 0) { in sctp_move_to_outqueue()
7369 sp->some_taken = 1; in sctp_move_to_outqueue()
7391 if (sp->sinfo_flags & SCTP_UNORDERED) { in sctp_move_to_outqueue()
7395 (sp->sinfo_flags & SCTP_EOF) == SCTP_EOF) { in sctp_move_to_outqueue()
7400 chk->rec.data.rcv_flags = rcv_flags; in sctp_move_to_outqueue()
7404 if (to_move < sp->length) { in sctp_move_to_outqueue()
7408 chk->data = sp->data; in sctp_move_to_outqueue()
7409 chk->last_mbuf = sp->tail_mbuf; in sctp_move_to_outqueue()
7411 sp->data = sp->tail_mbuf = NULL; in sctp_move_to_outqueue()
7416 chk->data = SCTP_M_COPYM(sp->data, 0, to_move, M_NOWAIT); in sctp_move_to_outqueue()
7417 chk->last_mbuf = NULL; in sctp_move_to_outqueue()
7418 if (chk->data == NULL) { in sctp_move_to_outqueue()
7419 sp->some_taken = some_taken; in sctp_move_to_outqueue()
7427 sctp_log_mbc(chk->data, SCTP_MBUF_ICOPY); in sctp_move_to_outqueue()
7431 m_adj(sp->data, to_move); in sctp_move_to_outqueue()
7433 m = sp->data; in sctp_move_to_outqueue()
7435 sp->data = SCTP_BUF_NEXT(m); in sctp_move_to_outqueue()
7437 if (sp->tail_mbuf == m) { in sctp_move_to_outqueue()
7438 /*- in sctp_move_to_outqueue()
7441 * than the sp->length. in sctp_move_to_outqueue()
7444 panic("Huh, freeing tail? - TSNH"); in sctp_move_to_outqueue()
7446 SCTP_PRINTF("Huh, freeing tail? - TSNH\n"); in sctp_move_to_outqueue()
7447 sp->tail_mbuf = sp->data = NULL; in sctp_move_to_outqueue()
7448 sp->length = 0; in sctp_move_to_outqueue()
7452 m = sp->data; in sctp_move_to_outqueue()
7455 if (SCTP_BUF_IS_EXTENDED(chk->data)) { in sctp_move_to_outqueue()
7456 chk->copy_by_ref = 1; in sctp_move_to_outqueue()
7458 chk->copy_by_ref = 0; in sctp_move_to_outqueue()
7464 if (chk->last_mbuf == NULL) { in sctp_move_to_outqueue()
7465 chk->last_mbuf = chk->data; in sctp_move_to_outqueue()
7466 while (SCTP_BUF_NEXT(chk->last_mbuf) != NULL) { in sctp_move_to_outqueue()
7467 chk->last_mbuf = SCTP_BUF_NEXT(chk->last_mbuf); in sctp_move_to_outqueue()
7472 /*- This should not happen either in sctp_move_to_outqueue()
7474 * of sp->length if its larger. in sctp_move_to_outqueue()
7480 sp->length = 0; in sctp_move_to_outqueue()
7483 atomic_subtract_int(&sp->length, to_move); in sctp_move_to_outqueue()
7486 if (M_LEADINGSPACE(chk->data) < leading) { in sctp_move_to_outqueue()
7497 if (sp->data == NULL) { in sctp_move_to_outqueue()
7499 sp->data = chk->data; in sctp_move_to_outqueue()
7500 sp->tail_mbuf = chk->last_mbuf; in sctp_move_to_outqueue()
7505 m_tmp = sp->data; in sctp_move_to_outqueue()
7506 sp->data = chk->data; in sctp_move_to_outqueue()
7507 SCTP_BUF_NEXT(chk->last_mbuf) = m_tmp; in sctp_move_to_outqueue()
7509 sp->some_taken = some_taken; in sctp_move_to_outqueue()
7510 atomic_add_int(&sp->length, to_move); in sctp_move_to_outqueue()
7511 chk->data = NULL; in sctp_move_to_outqueue()
7518 SCTP_BUF_NEXT(m) = chk->data; in sctp_move_to_outqueue()
7519 chk->data = m; in sctp_move_to_outqueue()
7520 M_ALIGN(chk->data, 4); in sctp_move_to_outqueue()
7523 SCTP_BUF_PREPEND(chk->data, SCTP_DATA_CHUNK_OVERHEAD(stcb), M_NOWAIT); in sctp_move_to_outqueue()
7524 if (chk->data == NULL) { in sctp_move_to_outqueue()
7537 chk->book_size = chk->send_size = (uint16_t)(to_move + SCTP_DATA_CHUNK_OVERHEAD(stcb)); in sctp_move_to_outqueue()
7538 chk->book_size_scale = 0; in sctp_move_to_outqueue()
7539 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_move_to_outqueue()
7541 chk->flags = 0; in sctp_move_to_outqueue()
7542 chk->asoc = &stcb->asoc; in sctp_move_to_outqueue()
7543 chk->pad_inplace = 0; in sctp_move_to_outqueue()
7544 chk->no_fr_allowed = 0; in sctp_move_to_outqueue()
7545 if (stcb->asoc.idata_supported == 0) { in sctp_move_to_outqueue()
7548 chk->rec.data.mid = 0; in sctp_move_to_outqueue()
7550 chk->rec.data.mid = strq->next_mid_ordered; in sctp_move_to_outqueue()
7552 strq->next_mid_ordered++; in sctp_move_to_outqueue()
7557 chk->rec.data.mid = strq->next_mid_unordered; in sctp_move_to_outqueue()
7559 strq->next_mid_unordered++; in sctp_move_to_outqueue()
7562 chk->rec.data.mid = strq->next_mid_ordered; in sctp_move_to_outqueue()
7564 strq->next_mid_ordered++; in sctp_move_to_outqueue()
7568 chk->rec.data.sid = sp->sid; in sctp_move_to_outqueue()
7569 chk->rec.data.ppid = sp->ppid; in sctp_move_to_outqueue()
7570 chk->rec.data.context = sp->context; in sctp_move_to_outqueue()
7571 chk->rec.data.doing_fast_retransmit = 0; in sctp_move_to_outqueue()
7573 chk->rec.data.timetodrop = sp->ts; in sctp_move_to_outqueue()
7574 chk->flags = sp->act_flags; in sctp_move_to_outqueue()
7576 if (sp->net) { in sctp_move_to_outqueue()
7577 chk->whoTo = sp->net; in sctp_move_to_outqueue()
7578 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_move_to_outqueue()
7580 chk->whoTo = NULL; in sctp_move_to_outqueue()
7582 if (sp->holds_key_ref) { in sctp_move_to_outqueue()
7583 chk->auth_keyid = sp->auth_keyid; in sctp_move_to_outqueue()
7584 sctp_auth_key_acquire(stcb, chk->auth_keyid); in sctp_move_to_outqueue()
7585 chk->holds_key_ref = 1; in sctp_move_to_outqueue()
7587 stcb->asoc.ss_functions.sctp_ss_scheduled(stcb, net, asoc, strq, to_move); in sctp_move_to_outqueue()
7588 chk->rec.data.tsn = atomic_fetchadd_int(&asoc->sending_seq, 1); in sctp_move_to_outqueue()
7591 (uint32_t)(uintptr_t)stcb, sp->length, in sctp_move_to_outqueue()
7592 (uint32_t)((chk->rec.data.sid << 16) | (0x0000ffff & chk->rec.data.mid)), in sctp_move_to_outqueue()
7593 chk->rec.data.tsn); in sctp_move_to_outqueue()
7595 if (stcb->asoc.idata_supported == 0) { in sctp_move_to_outqueue()
7596 dchkh = mtod(chk->data, struct sctp_data_chunk *); in sctp_move_to_outqueue()
7598 ndchkh = mtod(chk->data, struct sctp_idata_chunk *); in sctp_move_to_outqueue()
7607 if (asoc->tsn_out_at >= SCTP_TSN_LOG_SIZE) { in sctp_move_to_outqueue()
7608 asoc->tsn_out_at = 0; in sctp_move_to_outqueue()
7609 asoc->tsn_out_wrapped = 1; in sctp_move_to_outqueue()
7611 asoc->out_tsnlog[asoc->tsn_out_at].tsn = chk->rec.data.tsn; in sctp_move_to_outqueue()
7612 asoc->out_tsnlog[asoc->tsn_out_at].strm = chk->rec.data.sid; in sctp_move_to_outqueue()
7613 asoc->out_tsnlog[asoc->tsn_out_at].seq = chk->rec.data.mid; in sctp_move_to_outqueue()
7614 asoc->out_tsnlog[asoc->tsn_out_at].sz = chk->send_size; in sctp_move_to_outqueue()
7615 asoc->out_tsnlog[asoc->tsn_out_at].flgs = chk->rec.data.rcv_flags; in sctp_move_to_outqueue()
7616 asoc->out_tsnlog[asoc->tsn_out_at].stcb = (void *)stcb; in sctp_move_to_outqueue()
7617 asoc->out_tsnlog[asoc->tsn_out_at].in_pos = asoc->tsn_out_at; in sctp_move_to_outqueue()
7618 asoc->out_tsnlog[asoc->tsn_out_at].in_out = 2; in sctp_move_to_outqueue()
7619 asoc->tsn_out_at++; in sctp_move_to_outqueue()
7621 if (stcb->asoc.idata_supported == 0) { in sctp_move_to_outqueue()
7622 dchkh->ch.chunk_type = SCTP_DATA; in sctp_move_to_outqueue()
7623 dchkh->ch.chunk_flags = chk->rec.data.rcv_flags; in sctp_move_to_outqueue()
7624 dchkh->dp.tsn = htonl(chk->rec.data.tsn); in sctp_move_to_outqueue()
7625 dchkh->dp.sid = htons(strq->sid); in sctp_move_to_outqueue()
7626 dchkh->dp.ssn = htons((uint16_t)chk->rec.data.mid); in sctp_move_to_outqueue()
7627 dchkh->dp.ppid = chk->rec.data.ppid; in sctp_move_to_outqueue()
7628 dchkh->ch.chunk_length = htons(chk->send_size); in sctp_move_to_outqueue()
7630 ndchkh->ch.chunk_type = SCTP_IDATA; in sctp_move_to_outqueue()
7631 ndchkh->ch.chunk_flags = chk->rec.data.rcv_flags; in sctp_move_to_outqueue()
7632 ndchkh->dp.tsn = htonl(chk->rec.data.tsn); in sctp_move_to_outqueue()
7633 ndchkh->dp.sid = htons(strq->sid); in sctp_move_to_outqueue()
7634 ndchkh->dp.reserved = htons(0); in sctp_move_to_outqueue()
7635 ndchkh->dp.mid = htonl(chk->rec.data.mid); in sctp_move_to_outqueue()
7636 if (sp->fsn == 0) in sctp_move_to_outqueue()
7637 ndchkh->dp.ppid_fsn.ppid = chk->rec.data.ppid; in sctp_move_to_outqueue()
7639 ndchkh->dp.ppid_fsn.fsn = htonl(sp->fsn); in sctp_move_to_outqueue()
7640 sp->fsn++; in sctp_move_to_outqueue()
7641 ndchkh->ch.chunk_length = htons(chk->send_size); in sctp_move_to_outqueue()
7643 /* Now advance the chk->send_size by the actual pad needed. */ in sctp_move_to_outqueue()
7644 if (chk->send_size < SCTP_SIZE32(chk->book_size)) { in sctp_move_to_outqueue()
7649 pads = SCTP_SIZE32(chk->book_size) - chk->send_size; in sctp_move_to_outqueue()
7650 lm = sctp_pad_lastmbuf(chk->data, pads, chk->last_mbuf); in sctp_move_to_outqueue()
7652 chk->last_mbuf = lm; in sctp_move_to_outqueue()
7653 chk->pad_inplace = 1; in sctp_move_to_outqueue()
7655 chk->send_size += pads; in sctp_move_to_outqueue()
7657 if (PR_SCTP_ENABLED(chk->flags)) { in sctp_move_to_outqueue()
7658 asoc->pr_sctp_cnt++; in sctp_move_to_outqueue()
7660 if (sp->msg_is_complete && (sp->length == 0) && (sp->sender_all_done)) { in sctp_move_to_outqueue()
7662 if (sp->put_last_out == 0) { in sctp_move_to_outqueue()
7663 SCTP_PRINTF("Gak, put out entire msg with NO end!-2\n"); in sctp_move_to_outqueue()
7665 sp->sender_all_done, in sctp_move_to_outqueue()
7666 sp->length, in sctp_move_to_outqueue()
7667 sp->msg_is_complete, in sctp_move_to_outqueue()
7668 sp->put_last_out); in sctp_move_to_outqueue()
7670 atomic_subtract_int(&asoc->stream_queue_cnt, 1); in sctp_move_to_outqueue()
7671 TAILQ_REMOVE(&strq->outqueue, sp, next); in sctp_move_to_outqueue()
7672 stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp); in sctp_move_to_outqueue()
7673 if ((strq->state == SCTP_STREAM_RESET_PENDING) && in sctp_move_to_outqueue()
7674 (strq->chunks_on_queues == 0) && in sctp_move_to_outqueue()
7675 TAILQ_EMPTY(&strq->outqueue)) { in sctp_move_to_outqueue()
7676 stcb->asoc.trigger_reset = 1; in sctp_move_to_outqueue()
7678 if (sp->net) { in sctp_move_to_outqueue()
7679 sctp_free_remote_addr(sp->net); in sctp_move_to_outqueue()
7680 sp->net = NULL; in sctp_move_to_outqueue()
7682 if (sp->data) { in sctp_move_to_outqueue()
7683 sctp_m_freem(sp->data); in sctp_move_to_outqueue()
7684 sp->data = NULL; in sctp_move_to_outqueue()
7688 asoc->chunks_on_out_queue++; in sctp_move_to_outqueue()
7689 strq->chunks_on_queues++; in sctp_move_to_outqueue()
7690 TAILQ_INSERT_TAIL(&asoc->send_queue, chk, sctp_next); in sctp_move_to_outqueue()
7691 asoc->send_queue_cnt++; in sctp_move_to_outqueue()
7707 asoc = &stcb->asoc; in sctp_fill_outqueue()
7709 switch (net->ro._l_addr.sa.sa_family) { in sctp_fill_outqueue()
7712 space_left = net->mtu - SCTP_MIN_V4_OVERHEAD; in sctp_fill_outqueue()
7717 space_left = net->mtu - SCTP_MIN_OVERHEAD; in sctp_fill_outqueue()
7722 space_left = net->mtu; in sctp_fill_outqueue()
7726 space_left -= SCTP_DATA_CHUNK_OVERHEAD(stcb); in sctp_fill_outqueue()
7730 strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc); in sctp_fill_outqueue()
7740 strq = stcb->asoc.ss_functions.sctp_ss_select_stream(stcb, net, asoc); in sctp_fill_outqueue()
7743 space_left -= moved; in sctp_fill_outqueue()
7748 space_left -= SCTP_DATA_CHUNK_OVERHEAD(stcb); in sctp_fill_outqueue()
7757 stcb->asoc.ss_functions.sctp_ss_packet_done(stcb, net, asoc); in sctp_fill_outqueue()
7760 if ((stcb->asoc.sctp_cmt_on_off == 0) && in sctp_fill_outqueue()
7761 (net == stcb->asoc.primary_destination)) { in sctp_fill_outqueue()
7764 } else if (stcb->asoc.sctp_cmt_on_off > 0) { in sctp_fill_outqueue()
7776 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_fix_ecn_echo()
7777 if (chk->rec.chunk_id.id == SCTP_ECN_ECHO) { in sctp_fix_ecn_echo()
7778 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_fix_ecn_echo()
7794 asoc = &stcb->asoc; in sctp_move_chunks_from_net()
7795 for (i = 0; i < stcb->asoc.streamoutcnt; i++) { in sctp_move_chunks_from_net()
7796 TAILQ_FOREACH(sp, &stcb->asoc.strmout[i].outqueue, next) { in sctp_move_chunks_from_net()
7797 if (sp->net == net) { in sctp_move_chunks_from_net()
7798 sctp_free_remote_addr(sp->net); in sctp_move_chunks_from_net()
7799 sp->net = NULL; in sctp_move_chunks_from_net()
7803 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) { in sctp_move_chunks_from_net()
7804 if (chk->whoTo == net) { in sctp_move_chunks_from_net()
7805 sctp_free_remote_addr(chk->whoTo); in sctp_move_chunks_from_net()
7806 chk->whoTo = NULL; in sctp_move_chunks_from_net()
7824 * - Service the stream queue that is next, moving any in sctp_med_chunk_output()
7828 * chunks its ok to not send the entire message ;-) in sctp_med_chunk_output()
7829 * - Check to see if the cwnd/rwnd allows any output, if so we go ahead and in sctp_med_chunk_output()
7854 * JRS 5/14/07 - Add flag for whether a heartbeat is sent to the in sctp_med_chunk_output()
7862 auth_keyid = stcb->asoc.authinfo.active_keyid; in sctp_med_chunk_output()
7863 if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) || in sctp_med_chunk_output()
7887 if ((TAILQ_EMPTY(&asoc->control_send_queue) || in sctp_med_chunk_output()
7888 (asoc->ctrl_queue_cnt == stcb->asoc.ecn_echo_cnt_onq)) && in sctp_med_chunk_output()
7889 TAILQ_EMPTY(&asoc->asconf_send_queue) && in sctp_med_chunk_output()
7890 TAILQ_EMPTY(&asoc->send_queue) && in sctp_med_chunk_output()
7896 if (asoc->peers_rwnd == 0) { in sctp_med_chunk_output()
7899 if (asoc->total_flight > 0) { in sctp_med_chunk_output()
7904 if (stcb->asoc.ecn_echo_cnt_onq) { in sctp_med_chunk_output()
7907 (asoc->ctrl_queue_cnt == stcb->asoc.ecn_echo_cnt_onq)) { in sctp_med_chunk_output()
7908 /* Nothing but ECNe to send - we don't do that */ in sctp_med_chunk_output()
7911 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_med_chunk_output()
7912 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || in sctp_med_chunk_output()
7913 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) { in sctp_med_chunk_output()
7914 sack_goes_to = chk->whoTo; in sctp_med_chunk_output()
7919 max_rwnd_per_dest = ((asoc->peers_rwnd + asoc->total_flight) / asoc->numnets); in sctp_med_chunk_output()
7920 if (stcb->sctp_socket) in sctp_med_chunk_output()
7921 max_send_per_dest = SCTP_SB_LIMIT_SND(stcb->sctp_socket) / asoc->numnets; in sctp_med_chunk_output()
7925 /* How many non-directed chunks are there? */ in sctp_med_chunk_output()
7926 TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) { in sctp_med_chunk_output()
7927 if (chk->whoTo == NULL) { in sctp_med_chunk_output()
7929 * We already have non-directed chunks on in sctp_med_chunk_output()
7930 * the queue, no need to do a fill-up. in sctp_med_chunk_output()
7939 (!stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, asoc))) { in sctp_med_chunk_output()
7940 TAILQ_FOREACH(net, &asoc->nets, sctp_next) { in sctp_med_chunk_output()
7952 net->window_probe = 0; in sctp_med_chunk_output()
7953 if ((net != stcb->asoc.alternate) && in sctp_med_chunk_output()
7954 ((net->dest_state & SCTP_ADDR_PF) || in sctp_med_chunk_output()
7955 ((net->dest_state & SCTP_ADDR_REACHABLE) == 0) || in sctp_med_chunk_output()
7956 (net->dest_state & SCTP_ADDR_UNCONFIRMED))) { in sctp_med_chunk_output()
7963 if ((stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins) && in sctp_med_chunk_output()
7964 (net->flight_size == 0)) { in sctp_med_chunk_output()
7965 (*stcb->asoc.cc_functions.sctp_cwnd_new_transmission_begins) (stcb, net); in sctp_med_chunk_output()
7967 if (net->flight_size >= net->cwnd) { in sctp_med_chunk_output()
7968 /* skip this network, no room - can't fill */ in sctp_med_chunk_output()
7988 if (TAILQ_EMPTY(&asoc->control_send_queue) && in sctp_med_chunk_output()
7989 TAILQ_EMPTY(&asoc->asconf_send_queue) && in sctp_med_chunk_output()
7990 TAILQ_EMPTY(&asoc->send_queue)) { in sctp_med_chunk_output()
7995 if (asoc->sctp_cmt_on_off > 0) { in sctp_med_chunk_output()
7997 start_at = asoc->last_net_cmt_send_started; in sctp_med_chunk_output()
8000 start_at = TAILQ_FIRST(&asoc->nets); in sctp_med_chunk_output()
8002 start_at = TAILQ_NEXT(asoc->last_net_cmt_send_started, sctp_next); in sctp_med_chunk_output()
8004 start_at = TAILQ_FIRST(&asoc->nets); in sctp_med_chunk_output()
8007 asoc->last_net_cmt_send_started = start_at; in sctp_med_chunk_output()
8009 start_at = TAILQ_FIRST(&asoc->nets); in sctp_med_chunk_output()
8011 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_med_chunk_output()
8012 if (chk->whoTo == NULL) { in sctp_med_chunk_output()
8013 if (asoc->alternate) { in sctp_med_chunk_output()
8014 chk->whoTo = asoc->alternate; in sctp_med_chunk_output()
8016 chk->whoTo = asoc->primary_destination; in sctp_med_chunk_output()
8018 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_med_chunk_output()
8031 if (TAILQ_EMPTY(&asoc->control_send_queue) && in sctp_med_chunk_output()
8032 TAILQ_EMPTY(&asoc->asconf_send_queue) && in sctp_med_chunk_output()
8033 (net->flight_size >= net->cwnd)) { in sctp_med_chunk_output()
8046 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { in sctp_med_chunk_output()
8051 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) { in sctp_med_chunk_output()
8054 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; in sctp_med_chunk_output()
8059 mtu = net->mtu - SCTP_MIN_OVERHEAD; in sctp_med_chunk_output()
8064 mtu = net->mtu; in sctp_med_chunk_output()
8069 if (mtu > asoc->peers_rwnd) { in sctp_med_chunk_output()
8070 if (asoc->total_flight > 0) { in sctp_med_chunk_output()
8072 r_mtu = asoc->peers_rwnd; in sctp_med_chunk_output()
8086 TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) { in sctp_med_chunk_output()
8087 if (chk->rec.chunk_id.id != SCTP_ASCONF) { in sctp_med_chunk_output()
8090 if (chk->whoTo == NULL) { in sctp_med_chunk_output()
8091 if (asoc->alternate == NULL) { in sctp_med_chunk_output()
8092 if (asoc->primary_destination != net) { in sctp_med_chunk_output()
8096 if (asoc->alternate != net) { in sctp_med_chunk_output()
8101 if (chk->whoTo != net) { in sctp_med_chunk_output()
8105 if (chk->data == NULL) { in sctp_med_chunk_output()
8108 if (chk->sent != SCTP_DATAGRAM_UNSENT && in sctp_med_chunk_output()
8109 chk->sent != SCTP_DATAGRAM_RESEND) { in sctp_med_chunk_output()
8121 sctp_auth_is_required_chunk(chk->rec.chunk_id.id, in sctp_med_chunk_output()
8122 stcb->asoc.peer_auth_chunks)) { in sctp_med_chunk_output()
8123 omtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); in sctp_med_chunk_output()
8127 if ((chk->send_size < (int)(mtu - omtu)) || in sctp_med_chunk_output()
8128 (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) { in sctp_med_chunk_output()
8131 * from the chk->data for control but the in sctp_med_chunk_output()
8144 (sctp_auth_is_required_chunk(chk->rec.chunk_id.id, in sctp_med_chunk_output()
8145 stcb->asoc.peer_auth_chunks))) { in sctp_med_chunk_output()
8151 chk->rec.chunk_id.id); in sctp_med_chunk_output()
8154 outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, in sctp_med_chunk_output()
8155 (int)chk->rec.chunk_id.can_take_data, in sctp_med_chunk_output()
8156 chk->send_size, chk->copy_by_ref); in sctp_med_chunk_output()
8164 if (mtu > (chk->send_size + omtu)) in sctp_med_chunk_output()
8165 mtu -= (chk->send_size + omtu); in sctp_med_chunk_output()
8168 to_out += (chk->send_size + omtu); in sctp_med_chunk_output()
8170 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { in sctp_med_chunk_output()
8173 if (chk->rec.chunk_id.can_take_data) in sctp_med_chunk_output()
8174 chk->data = NULL; in sctp_med_chunk_output()
8186 chk->sent = SCTP_DATAGRAM_SENT; in sctp_med_chunk_output()
8187 if (chk->whoTo == NULL) { in sctp_med_chunk_output()
8188 chk->whoTo = net; in sctp_med_chunk_output()
8189 atomic_add_int(&net->ref_count, 1); in sctp_med_chunk_output()
8191 chk->snd_count++; in sctp_med_chunk_output()
8209 net->last_sent_time = *now; in sctp_med_chunk_output()
8212 (struct sockaddr *)&net->ro._l_addr, in sctp_med_chunk_output()
8214 stcb->asoc.authinfo.active_keyid, in sctp_med_chunk_output()
8216 inp->sctp_lport, stcb->rport, in sctp_med_chunk_output()
8217 htonl(stcb->asoc.peer_vtag), in sctp_med_chunk_output()
8218 net->port, NULL, in sctp_med_chunk_output()
8230 asoc->ifp_had_enobuf = 1; in sctp_med_chunk_output()
8246 asoc->ifp_had_enobuf = 0; in sctp_med_chunk_output()
8260 switch (net->ro._l_addr.sa.sa_family) { in sctp_med_chunk_output()
8263 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; in sctp_med_chunk_output()
8268 mtu = net->mtu - SCTP_MIN_OVERHEAD; in sctp_med_chunk_output()
8273 mtu = net->mtu; in sctp_med_chunk_output()
8289 TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) { in sctp_med_chunk_output()
8291 (chk->rec.chunk_id.id == SCTP_ECN_ECHO) && in sctp_med_chunk_output()
8292 (chk->whoTo != sack_goes_to)) { in sctp_med_chunk_output()
8298 if (chk->whoTo == net) { in sctp_med_chunk_output()
8312 if (chk->whoTo == NULL) { in sctp_med_chunk_output()
8313 if (asoc->alternate == NULL) { in sctp_med_chunk_output()
8314 if (asoc->primary_destination != net) { in sctp_med_chunk_output()
8318 if (asoc->alternate != net) { in sctp_med_chunk_output()
8323 if (chk->whoTo != net) { in sctp_med_chunk_output()
8328 if (chk->data == NULL) { in sctp_med_chunk_output()
8331 if (chk->sent != SCTP_DATAGRAM_UNSENT) { in sctp_med_chunk_output()
8348 sctp_auth_is_required_chunk(chk->rec.chunk_id.id, in sctp_med_chunk_output()
8349 stcb->asoc.peer_auth_chunks)) { in sctp_med_chunk_output()
8350 omtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); in sctp_med_chunk_output()
8354 if ((chk->send_size <= (int)(mtu - omtu)) || in sctp_med_chunk_output()
8355 (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) { in sctp_med_chunk_output()
8358 * from the chk->data for control but the in sctp_med_chunk_output()
8371 (sctp_auth_is_required_chunk(chk->rec.chunk_id.id, in sctp_med_chunk_output()
8372 stcb->asoc.peer_auth_chunks))) { in sctp_med_chunk_output()
8378 chk->rec.chunk_id.id); in sctp_med_chunk_output()
8381 outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, in sctp_med_chunk_output()
8382 (int)chk->rec.chunk_id.can_take_data, in sctp_med_chunk_output()
8383 chk->send_size, chk->copy_by_ref); in sctp_med_chunk_output()
8391 if (mtu > (chk->send_size + omtu)) in sctp_med_chunk_output()
8392 mtu -= (chk->send_size + omtu); in sctp_med_chunk_output()
8395 to_out += (chk->send_size + omtu); in sctp_med_chunk_output()
8397 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { in sctp_med_chunk_output()
8400 if (chk->rec.chunk_id.can_take_data) in sctp_med_chunk_output()
8401 chk->data = NULL; in sctp_med_chunk_output()
8403 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || in sctp_med_chunk_output()
8404 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK) || /* EY */ in sctp_med_chunk_output()
8405 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) || in sctp_med_chunk_output()
8406 (chk->rec.chunk_id.id == SCTP_HEARTBEAT_ACK) || in sctp_med_chunk_output()
8407 (chk->rec.chunk_id.id == SCTP_SHUTDOWN) || in sctp_med_chunk_output()
8408 (chk->rec.chunk_id.id == SCTP_SHUTDOWN_ACK) || in sctp_med_chunk_output()
8409 (chk->rec.chunk_id.id == SCTP_OPERATION_ERROR) || in sctp_med_chunk_output()
8410 (chk->rec.chunk_id.id == SCTP_COOKIE_ACK) || in sctp_med_chunk_output()
8411 (chk->rec.chunk_id.id == SCTP_ECN_CWR) || in sctp_med_chunk_output()
8412 (chk->rec.chunk_id.id == SCTP_PACKET_DROPPED) || in sctp_med_chunk_output()
8413 (chk->rec.chunk_id.id == SCTP_ASCONF_ACK)) { in sctp_med_chunk_output()
8414 if (chk->rec.chunk_id.id == SCTP_HEARTBEAT_REQUEST) { in sctp_med_chunk_output()
8418 if ((chk->rec.chunk_id.id == SCTP_SELECTIVE_ACK) || in sctp_med_chunk_output()
8419 (chk->rec.chunk_id.id == SCTP_NR_SELECTIVE_ACK)) { in sctp_med_chunk_output()
8421 if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { in sctp_med_chunk_output()
8436 if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) { in sctp_med_chunk_output()
8439 } else if (chk->rec.chunk_id.id == SCTP_ECN_ECHO) { in sctp_med_chunk_output()
8443 * over-zealous in our in sctp_med_chunk_output()
8454 chk->sent = SCTP_DATAGRAM_SENT; in sctp_med_chunk_output()
8455 if (chk->whoTo == NULL) { in sctp_med_chunk_output()
8456 chk->whoTo = net; in sctp_med_chunk_output()
8457 atomic_add_int(&net->ref_count, 1); in sctp_med_chunk_output()
8459 chk->snd_count++; in sctp_med_chunk_output()
8468 switch (asoc->snd_edmid) { in sctp_med_chunk_output()
8497 net->last_sent_time = *now; in sctp_med_chunk_output()
8501 (struct sockaddr *)&net->ro._l_addr, in sctp_med_chunk_output()
8504 stcb->asoc.authinfo.active_keyid, in sctp_med_chunk_output()
8506 inp->sctp_lport, stcb->rport, in sctp_med_chunk_output()
8507 htonl(stcb->asoc.peer_vtag), in sctp_med_chunk_output()
8508 net->port, NULL, in sctp_med_chunk_output()
8520 asoc->ifp_had_enobuf = 1; in sctp_med_chunk_output()
8535 asoc->ifp_had_enobuf = 0; in sctp_med_chunk_output()
8549 switch (net->ro._l_addr.sa.sa_family) { in sctp_med_chunk_output()
8552 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; in sctp_med_chunk_output()
8557 mtu = net->mtu - SCTP_MIN_OVERHEAD; in sctp_med_chunk_output()
8562 mtu = net->mtu; in sctp_med_chunk_output()
8575 if ((asoc->sctp_cmt_on_off > 0) && in sctp_med_chunk_output()
8576 (net != stcb->asoc.alternate) && in sctp_med_chunk_output()
8577 (net->dest_state & SCTP_ADDR_PF)) { in sctp_med_chunk_output()
8580 if (net->flight_size >= net->cwnd) { in sctp_med_chunk_output()
8583 if ((asoc->sctp_cmt_on_off > 0) && in sctp_med_chunk_output()
8585 (net->flight_size > max_rwnd_per_dest)) { in sctp_med_chunk_output()
8594 if ((asoc->sctp_cmt_on_off > 0) && in sctp_med_chunk_output()
8597 (net->flight_size > max_send_per_dest)) { in sctp_med_chunk_output()
8610 stcb->asoc.peer_auth_chunks); in sctp_med_chunk_output()
8612 mtu -= sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); in sctp_med_chunk_output()
8615 switch (((struct sockaddr *)&net->ro._l_addr)->sa_family) { in sctp_med_chunk_output()
8618 if (net->mtu > SCTP_MIN_V4_OVERHEAD) in sctp_med_chunk_output()
8619 omtu = net->mtu - SCTP_MIN_V4_OVERHEAD; in sctp_med_chunk_output()
8626 if (net->mtu > SCTP_MIN_OVERHEAD) in sctp_med_chunk_output()
8627 omtu = net->mtu - SCTP_MIN_OVERHEAD; in sctp_med_chunk_output()
8641 TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) { in sctp_med_chunk_output()
8647 if (net->flight_size >= net->cwnd) { in sctp_med_chunk_output()
8652 if ((chk->whoTo != NULL) && in sctp_med_chunk_output()
8653 (chk->whoTo != net)) { in sctp_med_chunk_output()
8658 if (asoc->sctp_cmt_on_off == 0) { in sctp_med_chunk_output()
8659 if ((asoc->alternate) && in sctp_med_chunk_output()
8660 (asoc->alternate != net) && in sctp_med_chunk_output()
8661 (chk->whoTo == NULL)) { in sctp_med_chunk_output()
8663 } else if ((net != asoc->primary_destination) && in sctp_med_chunk_output()
8664 (asoc->alternate == NULL) && in sctp_med_chunk_output()
8665 (chk->whoTo == NULL)) { in sctp_med_chunk_output()
8669 if ((chk->send_size > omtu) && ((chk->flags & CHUNK_FLAGS_FRAGMENT_OK) == 0)) { in sctp_med_chunk_output()
8670 /*- in sctp_med_chunk_output()
8683 chk->send_size, mtu); in sctp_med_chunk_output()
8684 chk->flags |= CHUNK_FLAGS_FRAGMENT_OK; in sctp_med_chunk_output()
8687 (asoc->state & SCTP_STATE_SHUTDOWN_PENDING)) { in sctp_med_chunk_output()
8690 dchkh = mtod(chk->data, struct sctp_data_chunk *); in sctp_med_chunk_output()
8691 dchkh->ch.chunk_flags |= SCTP_DATA_SACK_IMMEDIATELY; in sctp_med_chunk_output()
8693 if (((chk->send_size <= mtu) && (chk->send_size <= r_mtu)) || in sctp_med_chunk_output()
8694 ((chk->flags & CHUNK_FLAGS_FRAGMENT_OK) && (chk->send_size <= asoc->peers_rwnd))) { in sctp_med_chunk_output()
8710 auth_keyid = chk->auth_keyid; in sctp_med_chunk_output()
8718 auth_keyid = chk->auth_keyid; in sctp_med_chunk_output()
8720 } else if (auth_keyid != chk->auth_keyid) { in sctp_med_chunk_output()
8728 outchain = sctp_copy_mbufchain(chk->data, outchain, &endoutchain, 0, in sctp_med_chunk_output()
8729 chk->send_size, chk->copy_by_ref); in sctp_med_chunk_output()
8732 if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { in sctp_med_chunk_output()
8741 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { in sctp_med_chunk_output()
8745 if (mtu > chk->send_size) in sctp_med_chunk_output()
8746 mtu -= chk->send_size; in sctp_med_chunk_output()
8750 if (r_mtu > chk->send_size) in sctp_med_chunk_output()
8751 r_mtu -= chk->send_size; in sctp_med_chunk_output()
8755 to_out += chk->send_size; in sctp_med_chunk_output()
8764 chk->window_probe = 0; in sctp_med_chunk_output()
8769 if (chk->sent == SCTP_DATAGRAM_UNSENT) { in sctp_med_chunk_output()
8770 if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) { in sctp_med_chunk_output()
8775 if (((chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) && in sctp_med_chunk_output()
8776 ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0)) in sctp_med_chunk_output()
8789 if ((one_chunk) && (stcb->asoc.total_flight == 0)) { in sctp_med_chunk_output()
8790 data_list[0]->window_probe = 1; in sctp_med_chunk_output()
8791 net->window_probe = 1; in sctp_med_chunk_output()
8807 switch (asoc->snd_edmid) { in sctp_med_chunk_output()
8832 if (bundle_at && (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer))) { in sctp_med_chunk_output()
8845 net->last_sent_time = *now; in sctp_med_chunk_output()
8851 (struct sockaddr *)&net->ro._l_addr, in sctp_med_chunk_output()
8859 inp->sctp_lport, stcb->rport, in sctp_med_chunk_output()
8860 htonl(stcb->asoc.peer_vtag), in sctp_med_chunk_output()
8861 net->port, NULL, in sctp_med_chunk_output()
8871 asoc->ifp_had_enobuf = 1; in sctp_med_chunk_output()
8883 /*- in sctp_med_chunk_output()
8893 asoc->ifp_had_enobuf = 0; in sctp_med_chunk_output()
8904 tsns_sent = data_list[0]->rec.data.tsn; in sctp_med_chunk_output()
8907 (void)SCTP_GETTIME_TIMEVAL(&asoc->time_last_sent); in sctp_med_chunk_output()
8909 *now = asoc->time_last_sent; in sctp_med_chunk_output()
8911 asoc->time_last_sent = *now; in sctp_med_chunk_output()
8913 if (net->rto_needed) { in sctp_med_chunk_output()
8914 data_list[0]->do_rtt = 1; in sctp_med_chunk_output()
8915 net->rto_needed = 0; in sctp_med_chunk_output()
8930 start_at = TAILQ_FIRST(&asoc->nets); in sctp_med_chunk_output()
8954 /*- in sctp_queue_op_err()
8983 padding_length = 4 - padding_length; in sctp_queue_op_err()
8997 chk->copy_by_ref = 0; in sctp_queue_op_err()
8998 chk->rec.chunk_id.id = SCTP_OPERATION_ERROR; in sctp_queue_op_err()
8999 chk->rec.chunk_id.can_take_data = 0; in sctp_queue_op_err()
9000 chk->flags = 0; in sctp_queue_op_err()
9001 chk->send_size = (uint16_t)chunk_length; in sctp_queue_op_err()
9002 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_queue_op_err()
9003 chk->snd_count = 0; in sctp_queue_op_err()
9004 chk->asoc = &stcb->asoc; in sctp_queue_op_err()
9005 chk->data = op_err; in sctp_queue_op_err()
9006 chk->whoTo = NULL; in sctp_queue_op_err()
9008 hdr->chunk_type = SCTP_OPERATION_ERROR; in sctp_queue_op_err()
9009 hdr->chunk_flags = 0; in sctp_queue_op_err()
9010 hdr->chunk_length = htons(chk->send_size); in sctp_queue_op_err()
9011 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_queue_op_err()
9012 chk->asoc->ctrl_queue_cnt++; in sctp_queue_op_err()
9021 /*- in sctp_send_cookie_echo()
9039 return (-3); in sctp_send_cookie_echo()
9041 ptype = ntohs(phdr->param_type); in sctp_send_cookie_echo()
9042 plen = ntohs(phdr->param_length); in sctp_send_cookie_echo()
9044 return (-6); in sctp_send_cookie_echo()
9051 return (-7); in sctp_send_cookie_echo()
9056 return (-2); in sctp_send_cookie_echo()
9059 pad = 4 - pad; in sctp_send_cookie_echo()
9063 return (-8); in sctp_send_cookie_echo()
9078 hdr->chunk_type = SCTP_COOKIE_ECHO; in sctp_send_cookie_echo()
9079 hdr->chunk_flags = 0; in sctp_send_cookie_echo()
9085 return (-5); in sctp_send_cookie_echo()
9087 chk->copy_by_ref = 0; in sctp_send_cookie_echo()
9088 chk->rec.chunk_id.id = SCTP_COOKIE_ECHO; in sctp_send_cookie_echo()
9089 chk->rec.chunk_id.can_take_data = 0; in sctp_send_cookie_echo()
9090 chk->flags = CHUNK_FLAGS_FRAGMENT_OK; in sctp_send_cookie_echo()
9091 chk->send_size = SCTP_SIZE32(plen); in sctp_send_cookie_echo()
9092 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_cookie_echo()
9093 chk->snd_count = 0; in sctp_send_cookie_echo()
9094 chk->asoc = &stcb->asoc; in sctp_send_cookie_echo()
9095 chk->data = cookie; in sctp_send_cookie_echo()
9096 chk->whoTo = net; in sctp_send_cookie_echo()
9097 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_cookie_echo()
9098 TAILQ_INSERT_HEAD(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_send_cookie_echo()
9099 chk->asoc->ctrl_queue_cnt++; in sctp_send_cookie_echo()
9132 chdr->chunk_type = SCTP_HEARTBEAT_ACK; in sctp_send_heartbeat_ack()
9133 chdr->chunk_flags = 0; in sctp_send_heartbeat_ack()
9135 sctp_pad_lastmbuf(outchain, 4 - (chk_length % 4), NULL); in sctp_send_heartbeat_ack()
9143 chk->copy_by_ref = 0; in sctp_send_heartbeat_ack()
9144 chk->rec.chunk_id.id = SCTP_HEARTBEAT_ACK; in sctp_send_heartbeat_ack()
9145 chk->rec.chunk_id.can_take_data = 1; in sctp_send_heartbeat_ack()
9146 chk->flags = 0; in sctp_send_heartbeat_ack()
9147 chk->send_size = chk_length; in sctp_send_heartbeat_ack()
9148 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_heartbeat_ack()
9149 chk->snd_count = 0; in sctp_send_heartbeat_ack()
9150 chk->asoc = &stcb->asoc; in sctp_send_heartbeat_ack()
9151 chk->data = outchain; in sctp_send_heartbeat_ack()
9152 chk->whoTo = net; in sctp_send_heartbeat_ack()
9153 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_heartbeat_ack()
9154 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_send_heartbeat_ack()
9155 chk->asoc->ctrl_queue_cnt++; in sctp_send_heartbeat_ack()
9161 /* formulate and queue a cookie-ack back to sender */ in sctp_send_cookie_ack()
9180 chk->copy_by_ref = 0; in sctp_send_cookie_ack()
9181 chk->rec.chunk_id.id = SCTP_COOKIE_ACK; in sctp_send_cookie_ack()
9182 chk->rec.chunk_id.can_take_data = 1; in sctp_send_cookie_ack()
9183 chk->flags = 0; in sctp_send_cookie_ack()
9184 chk->send_size = sizeof(struct sctp_chunkhdr); in sctp_send_cookie_ack()
9185 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_cookie_ack()
9186 chk->snd_count = 0; in sctp_send_cookie_ack()
9187 chk->asoc = &stcb->asoc; in sctp_send_cookie_ack()
9188 chk->data = cookie_ack; in sctp_send_cookie_ack()
9189 if (chk->asoc->last_control_chunk_from != NULL) { in sctp_send_cookie_ack()
9190 chk->whoTo = chk->asoc->last_control_chunk_from; in sctp_send_cookie_ack()
9191 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_cookie_ack()
9193 chk->whoTo = NULL; in sctp_send_cookie_ack()
9196 hdr->chunk_type = SCTP_COOKIE_ACK; in sctp_send_cookie_ack()
9197 hdr->chunk_flags = 0; in sctp_send_cookie_ack()
9198 hdr->chunk_length = htons(chk->send_size); in sctp_send_cookie_ack()
9199 SCTP_BUF_LEN(cookie_ack) = chk->send_size; in sctp_send_cookie_ack()
9200 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_send_cookie_ack()
9201 chk->asoc->ctrl_queue_cnt++; in sctp_send_cookie_ack()
9208 /* formulate and queue a SHUTDOWN-ACK back to the sender */ in sctp_send_shutdown_ack()
9225 chk->copy_by_ref = 0; in sctp_send_shutdown_ack()
9226 chk->rec.chunk_id.id = SCTP_SHUTDOWN_ACK; in sctp_send_shutdown_ack()
9227 chk->rec.chunk_id.can_take_data = 1; in sctp_send_shutdown_ack()
9228 chk->flags = 0; in sctp_send_shutdown_ack()
9229 chk->send_size = sizeof(struct sctp_chunkhdr); in sctp_send_shutdown_ack()
9230 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_shutdown_ack()
9231 chk->snd_count = 0; in sctp_send_shutdown_ack()
9232 chk->asoc = &stcb->asoc; in sctp_send_shutdown_ack()
9233 chk->data = m_shutdown_ack; in sctp_send_shutdown_ack()
9234 chk->whoTo = net; in sctp_send_shutdown_ack()
9235 if (chk->whoTo) { in sctp_send_shutdown_ack()
9236 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_shutdown_ack()
9239 ack_cp->ch.chunk_type = SCTP_SHUTDOWN_ACK; in sctp_send_shutdown_ack()
9240 ack_cp->ch.chunk_flags = 0; in sctp_send_shutdown_ack()
9241 ack_cp->ch.chunk_length = htons(chk->send_size); in sctp_send_shutdown_ack()
9242 SCTP_BUF_LEN(m_shutdown_ack) = chk->send_size; in sctp_send_shutdown_ack()
9243 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_send_shutdown_ack()
9244 chk->asoc->ctrl_queue_cnt++; in sctp_send_shutdown_ack()
9256 TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) { in sctp_send_shutdown()
9257 if (chk->rec.chunk_id.id == SCTP_SHUTDOWN) { in sctp_send_shutdown()
9259 if (chk->whoTo) { in sctp_send_shutdown()
9260 sctp_free_remote_addr(chk->whoTo); in sctp_send_shutdown()
9261 chk->whoTo = NULL; in sctp_send_shutdown()
9279 chk->copy_by_ref = 0; in sctp_send_shutdown()
9280 chk->rec.chunk_id.id = SCTP_SHUTDOWN; in sctp_send_shutdown()
9281 chk->rec.chunk_id.can_take_data = 1; in sctp_send_shutdown()
9282 chk->flags = 0; in sctp_send_shutdown()
9283 chk->send_size = sizeof(struct sctp_shutdown_chunk); in sctp_send_shutdown()
9284 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_shutdown()
9285 chk->snd_count = 0; in sctp_send_shutdown()
9286 chk->asoc = &stcb->asoc; in sctp_send_shutdown()
9287 chk->data = m_shutdown; in sctp_send_shutdown()
9288 chk->whoTo = net; in sctp_send_shutdown()
9289 if (chk->whoTo) { in sctp_send_shutdown()
9290 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_shutdown()
9293 shutdown_cp->ch.chunk_type = SCTP_SHUTDOWN; in sctp_send_shutdown()
9294 shutdown_cp->ch.chunk_flags = 0; in sctp_send_shutdown()
9295 shutdown_cp->ch.chunk_length = htons(chk->send_size); in sctp_send_shutdown()
9296 shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn); in sctp_send_shutdown()
9297 SCTP_BUF_LEN(m_shutdown) = chk->send_size; in sctp_send_shutdown()
9298 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_send_shutdown()
9299 chk->asoc->ctrl_queue_cnt++; in sctp_send_shutdown()
9301 TAILQ_REMOVE(&stcb->asoc.control_send_queue, chk, sctp_next); in sctp_send_shutdown()
9302 chk->whoTo = net; in sctp_send_shutdown()
9303 if (chk->whoTo) { in sctp_send_shutdown()
9304 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_shutdown()
9306 shutdown_cp = mtod(chk->data, struct sctp_shutdown_chunk *); in sctp_send_shutdown()
9307 shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn); in sctp_send_shutdown()
9308 TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); in sctp_send_shutdown()
9326 if ((!TAILQ_EMPTY(&stcb->asoc.asconf_send_queue)) && in sctp_send_asconf()
9327 (!sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_MULTIPLE_ASCONFS))) { in sctp_send_asconf()
9345 chk->copy_by_ref = 0; in sctp_send_asconf()
9346 chk->rec.chunk_id.id = SCTP_ASCONF; in sctp_send_asconf()
9347 chk->rec.chunk_id.can_take_data = 0; in sctp_send_asconf()
9348 chk->flags = CHUNK_FLAGS_FRAGMENT_OK; in sctp_send_asconf()
9349 chk->data = m_asconf; in sctp_send_asconf()
9350 chk->send_size = len; in sctp_send_asconf()
9351 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_asconf()
9352 chk->snd_count = 0; in sctp_send_asconf()
9353 chk->asoc = &stcb->asoc; in sctp_send_asconf()
9354 chk->whoTo = net; in sctp_send_asconf()
9355 if (chk->whoTo) { in sctp_send_asconf()
9356 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_asconf()
9358 TAILQ_INSERT_TAIL(&chk->asoc->asconf_send_queue, chk, sctp_next); in sctp_send_asconf()
9359 chk->asoc->ctrl_queue_cnt++; in sctp_send_asconf()
9367 * formulate and queue a asconf-ack back to sender. the asconf-ack in sctp_send_asconf_ack()
9376 /* Get the latest ASCONF-ACK */ in sctp_send_asconf_ack()
9377 latest_ack = TAILQ_LAST(&stcb->asoc.asconf_ack_sent, sctp_asconf_ackhead); in sctp_send_asconf_ack()
9381 if (latest_ack->last_sent_to != NULL && in sctp_send_asconf_ack()
9382 latest_ack->last_sent_to == stcb->asoc.last_control_chunk_from) { in sctp_send_asconf_ack()
9384 net = sctp_find_alternate_net(stcb, stcb->asoc.last_control_chunk_from, 0); in sctp_send_asconf_ack()
9387 if (stcb->asoc.last_control_chunk_from == NULL) { in sctp_send_asconf_ack()
9388 if (stcb->asoc.alternate) { in sctp_send_asconf_ack()
9389 net = stcb->asoc.alternate; in sctp_send_asconf_ack()
9391 net = stcb->asoc.primary_destination; in sctp_send_asconf_ack()
9394 net = stcb->asoc.last_control_chunk_from; in sctp_send_asconf_ack()
9399 if (stcb->asoc.last_control_chunk_from == NULL) { in sctp_send_asconf_ack()
9400 if (stcb->asoc.alternate) { in sctp_send_asconf_ack()
9401 net = stcb->asoc.alternate; in sctp_send_asconf_ack()
9403 net = stcb->asoc.primary_destination; in sctp_send_asconf_ack()
9406 net = stcb->asoc.last_control_chunk_from; in sctp_send_asconf_ack()
9409 latest_ack->last_sent_to = net; in sctp_send_asconf_ack()
9411 TAILQ_FOREACH(ack, &stcb->asoc.asconf_ack_sent, next) { in sctp_send_asconf_ack()
9412 if (ack->data == NULL) { in sctp_send_asconf_ack()
9417 m_ack = SCTP_M_COPYM(ack->data, 0, M_COPYALL, M_NOWAIT); in sctp_send_asconf_ack()
9435 chk->copy_by_ref = 0; in sctp_send_asconf_ack()
9436 chk->rec.chunk_id.id = SCTP_ASCONF_ACK; in sctp_send_asconf_ack()
9437 chk->rec.chunk_id.can_take_data = 1; in sctp_send_asconf_ack()
9438 chk->flags = CHUNK_FLAGS_FRAGMENT_OK; in sctp_send_asconf_ack()
9439 chk->whoTo = net; in sctp_send_asconf_ack()
9440 if (chk->whoTo) { in sctp_send_asconf_ack()
9441 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_asconf_ack()
9443 chk->data = m_ack; in sctp_send_asconf_ack()
9444 chk->send_size = ack->len; in sctp_send_asconf_ack()
9445 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_asconf_ack()
9446 chk->snd_count = 0; in sctp_send_asconf_ack()
9447 chk->asoc = &stcb->asoc; in sctp_send_asconf_ack()
9449 TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); in sctp_send_asconf_ack()
9450 chk->asoc->ctrl_queue_cnt++; in sctp_send_asconf_ack()
9461 /*- in sctp_chunk_retransmission()
9471 * or t3-timeout routines). in sctp_chunk_retransmission()
9496 auth_keyid = stcb->asoc.authinfo.active_keyid; in sctp_chunk_retransmission()
9500 if ((TAILQ_EMPTY(&asoc->sent_queue)) && in sctp_chunk_retransmission()
9501 (TAILQ_EMPTY(&asoc->control_send_queue))) { in sctp_chunk_retransmission()
9503 asoc->sent_queue_retran_cnt); in sctp_chunk_retransmission()
9504 asoc->sent_queue_cnt = 0; in sctp_chunk_retransmission()
9505 asoc->sent_queue_cnt_removeable = 0; in sctp_chunk_retransmission()
9510 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_chunk_retransmission()
9511 if ((chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) || in sctp_chunk_retransmission()
9512 (chk->rec.chunk_id.id == SCTP_STREAM_RESET) || in sctp_chunk_retransmission()
9513 (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN)) { in sctp_chunk_retransmission()
9514 if (chk->sent != SCTP_DATAGRAM_RESEND) { in sctp_chunk_retransmission()
9517 if (chk->rec.chunk_id.id == SCTP_STREAM_RESET) { in sctp_chunk_retransmission()
9518 if (chk != asoc->str_reset) { in sctp_chunk_retransmission()
9527 if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) { in sctp_chunk_retransmission()
9535 (sctp_auth_is_required_chunk(chk->rec.chunk_id.id, in sctp_chunk_retransmission()
9536 stcb->asoc.peer_auth_chunks))) { in sctp_chunk_retransmission()
9540 chk->rec.chunk_id.id); in sctp_chunk_retransmission()
9543 m = sctp_copy_mbufchain(chk->data, m, &endofchain, 0, chk->send_size, chk->copy_by_ref); in sctp_chunk_retransmission()
9551 switch (asoc->snd_edmid) { in sctp_chunk_retransmission()
9559 if (chk->rec.chunk_id.id == SCTP_COOKIE_ECHO) { in sctp_chunk_retransmission()
9560 sctp_timer_start(SCTP_TIMER_TYPE_COOKIE, inp, stcb, chk->whoTo); in sctp_chunk_retransmission()
9562 } else if (chk->rec.chunk_id.id == SCTP_ASCONF) { in sctp_chunk_retransmission()
9564 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, stcb, chk->whoTo); in sctp_chunk_retransmission()
9567 chk->snd_count++; /* update our count */ in sctp_chunk_retransmission()
9568 if ((error = sctp_lowlevel_chunk_output(inp, stcb, chk->whoTo, in sctp_chunk_retransmission()
9569 (struct sockaddr *)&chk->whoTo->ro._l_addr, m, in sctp_chunk_retransmission()
9570 auth_offset, auth, stcb->asoc.authinfo.active_keyid, in sctp_chunk_retransmission()
9572 inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag), in sctp_chunk_retransmission()
9573 chk->whoTo->port, NULL, in sctp_chunk_retransmission()
9579 asoc->ifp_had_enobuf = 1; in sctp_chunk_retransmission()
9584 asoc->ifp_had_enobuf = 0; in sctp_chunk_retransmission()
9590 * We don't want to mark the net->sent time here since this in sctp_chunk_retransmission()
9593 /* (void)SCTP_GETTIME_TIMEVAL(&chk->whoTo->last_sent_time); */ in sctp_chunk_retransmission()
9595 chk->sent = SCTP_DATAGRAM_SENT; in sctp_chunk_retransmission()
9596 sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt); in sctp_chunk_retransmission()
9600 /* Clean up the fwd-tsn list */ in sctp_chunk_retransmission()
9607 * fwd-tsn with it all. in sctp_chunk_retransmission()
9609 if (TAILQ_EMPTY(&asoc->sent_queue)) { in sctp_chunk_retransmission()
9620 data_auth_reqd = sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks); in sctp_chunk_retransmission()
9621 TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) { in sctp_chunk_retransmission()
9622 if (chk->sent != SCTP_DATAGRAM_RESEND) { in sctp_chunk_retransmission()
9626 if (chk->data == NULL) { in sctp_chunk_retransmission()
9627 SCTP_PRINTF("TSN:%x chk->snd_count:%d chk->sent:%d can't retran - no data\n", in sctp_chunk_retransmission()
9628 chk->rec.data.tsn, chk->snd_count, chk->sent); in sctp_chunk_retransmission()
9632 (chk->snd_count >= SCTP_BASE_SYSCTL(sctp_max_retran_chunk))) { in sctp_chunk_retransmission()
9637 chk->rec.data.tsn, chk->snd_count); in sctp_chunk_retransmission()
9640 atomic_add_int(&stcb->asoc.refcnt, 1); in sctp_chunk_retransmission()
9641 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, in sctp_chunk_retransmission()
9644 atomic_subtract_int(&stcb->asoc.refcnt, 1); in sctp_chunk_retransmission()
9648 net = chk->whoTo; in sctp_chunk_retransmission()
9649 switch (net->ro._l_addr.sa.sa_family) { in sctp_chunk_retransmission()
9652 mtu = net->mtu - SCTP_MIN_V4_OVERHEAD; in sctp_chunk_retransmission()
9657 mtu = net->mtu - SCTP_MIN_OVERHEAD; in sctp_chunk_retransmission()
9662 mtu = net->mtu; in sctp_chunk_retransmission()
9666 if ((asoc->peers_rwnd < mtu) && (asoc->total_flight > 0)) { in sctp_chunk_retransmission()
9670 tsn = asoc->last_acked_seq + 1; in sctp_chunk_retransmission()
9671 if (tsn == chk->rec.data.tsn) { in sctp_chunk_retransmission()
9683 if (asoc->peers_rwnd < mtu) { in sctp_chunk_retransmission()
9685 if ((asoc->peers_rwnd == 0) && in sctp_chunk_retransmission()
9686 (asoc->total_flight == 0)) { in sctp_chunk_retransmission()
9687 chk->window_probe = 1; in sctp_chunk_retransmission()
9688 chk->whoTo->window_probe = 1; in sctp_chunk_retransmission()
9696 net->fast_retran_ip = 0; in sctp_chunk_retransmission()
9697 if (chk->rec.data.doing_fast_retransmit == 0) { in sctp_chunk_retransmission()
9702 if (net->flight_size >= net->cwnd) { in sctp_chunk_retransmission()
9711 net->fast_retran_ip = 1; in sctp_chunk_retransmission()
9721 dmtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); in sctp_chunk_retransmission()
9725 if ((chk->send_size <= (mtu - dmtu)) || in sctp_chunk_retransmission()
9726 (chk->flags & CHUNK_FLAGS_FRAGMENT_OK)) { in sctp_chunk_retransmission()
9736 auth_keyid = chk->auth_keyid; in sctp_chunk_retransmission()
9740 auth_keyid = chk->auth_keyid; in sctp_chunk_retransmission()
9742 } else if (chk->auth_keyid != auth_keyid) { in sctp_chunk_retransmission()
9747 m = sctp_copy_mbufchain(chk->data, m, &endofchain, 0, chk->send_size, chk->copy_by_ref); in sctp_chunk_retransmission()
9753 if (chk->flags & CHUNK_FLAGS_FRAGMENT_OK) { in sctp_chunk_retransmission()
9757 if (mtu > (chk->send_size + dmtu)) in sctp_chunk_retransmission()
9758 mtu -= (chk->send_size + dmtu); in sctp_chunk_retransmission()
9762 if (one_chunk && (asoc->total_flight <= 0)) { in sctp_chunk_retransmission()
9772 if (fwd->sent != SCTP_DATAGRAM_RESEND) { in sctp_chunk_retransmission()
9776 if (fwd->whoTo != net) { in sctp_chunk_retransmission()
9781 dmtu = sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id); in sctp_chunk_retransmission()
9784 if (fwd->send_size <= (mtu - dmtu)) { in sctp_chunk_retransmission()
9793 auth_keyid = fwd->auth_keyid; in sctp_chunk_retransmission()
9797 auth_keyid = fwd->auth_keyid; in sctp_chunk_retransmission()
9799 } else if (fwd->auth_keyid != auth_keyid) { in sctp_chunk_retransmission()
9807 m = sctp_copy_mbufchain(fwd->data, m, &endofchain, 0, fwd->send_size, fwd->copy_by_ref); in sctp_chunk_retransmission()
9813 if (fwd->flags & CHUNK_FLAGS_FRAGMENT_OK) { in sctp_chunk_retransmission()
9817 if (mtu > (fwd->send_size + dmtu)) in sctp_chunk_retransmission()
9818 mtu -= (fwd->send_size + dmtu); in sctp_chunk_retransmission()
9835 * timer. A failure is like a lost IP packet :-) in sctp_chunk_retransmission()
9837 if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { in sctp_chunk_retransmission()
9845 switch (asoc->snd_edmid) { in sctp_chunk_retransmission()
9855 (struct sockaddr *)&net->ro._l_addr, m, in sctp_chunk_retransmission()
9858 inp->sctp_lport, stcb->rport, htonl(stcb->asoc.peer_vtag), in sctp_chunk_retransmission()
9859 net->port, NULL, in sctp_chunk_retransmission()
9866 asoc->ifp_had_enobuf = 1; in sctp_chunk_retransmission()
9871 asoc->ifp_had_enobuf = 0; in sctp_chunk_retransmission()
9878 * We don't want to mark the net->sent time here in sctp_chunk_retransmission()
9882 /* (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); */ in sctp_chunk_retransmission()
9884 /* For auto-close */ in sctp_chunk_retransmission()
9886 (void)SCTP_GETTIME_TIMEVAL(&asoc->time_last_sent); in sctp_chunk_retransmission()
9887 *now = asoc->time_last_sent; in sctp_chunk_retransmission()
9890 asoc->time_last_sent = *now; in sctp_chunk_retransmission()
9897 tsns_sent = data_list[0]->rec.data.tsn; in sctp_chunk_retransmission()
9901 data_list[i]->sent = SCTP_DATAGRAM_SENT; in sctp_chunk_retransmission()
9908 if (data_list[i]->rec.data.chunk_was_revoked) { in sctp_chunk_retransmission()
9910 data_list[i]->whoTo->cwnd -= data_list[i]->book_size; in sctp_chunk_retransmission()
9911 data_list[i]->rec.data.chunk_was_revoked = 0; in sctp_chunk_retransmission()
9913 data_list[i]->snd_count++; in sctp_chunk_retransmission()
9914 sctp_ucount_decr(asoc->sent_queue_retran_cnt); in sctp_chunk_retransmission()
9916 data_list[i]->sent_rcv_time = asoc->time_last_sent; in sctp_chunk_retransmission()
9917 if (data_list[i]->book_size_scale) { in sctp_chunk_retransmission()
9922 data_list[i]->book_size_scale = 0; in sctp_chunk_retransmission()
9929 atomic_add_int(&((asoc)->total_output_queue_size), data_list[i]->book_size); in sctp_chunk_retransmission()
9930 data_list[i]->book_size *= 2; in sctp_chunk_retransmission()
9934 asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); in sctp_chunk_retransmission()
9936 asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd, in sctp_chunk_retransmission()
9937 (uint32_t)(data_list[i]->send_size + in sctp_chunk_retransmission()
9942 data_list[i]->whoTo->flight_size, in sctp_chunk_retransmission()
9943 data_list[i]->book_size, in sctp_chunk_retransmission()
9944 (uint32_t)(uintptr_t)data_list[i]->whoTo, in sctp_chunk_retransmission()
9945 data_list[i]->rec.data.tsn); in sctp_chunk_retransmission()
9949 if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { in sctp_chunk_retransmission()
9951 asoc->peers_rwnd = 0; in sctp_chunk_retransmission()
9954 (data_list[i]->rec.data.doing_fast_retransmit)) { in sctp_chunk_retransmission()
9956 if ((data_list[i] == TAILQ_FIRST(&asoc->sent_queue)) && in sctp_chunk_retransmission()
9958 /*- in sctp_chunk_retransmission()
9959 * ok we just fast-retrans'd in sctp_chunk_retransmission()
9965 * t3-expiring. in sctp_chunk_retransmission()
9983 if (asoc->sent_queue_retran_cnt <= 0) { in sctp_chunk_retransmission()
9985 asoc->sent_queue_retran_cnt = 0; in sctp_chunk_retransmission()
10006 TAILQ_FOREACH(net, &asoc->nets, sctp_next) { in sctp_timer_validation()
10007 if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { in sctp_timer_validation()
10015 if (asoc->alternate) { in sctp_timer_validation()
10016 sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->alternate); in sctp_timer_validation()
10018 sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb, asoc->primary_destination); in sctp_timer_validation()
10029 /*- in sctp_chunk_output()
10032 * - See if there are retransmits pending, if so we must in sctp_chunk_output()
10034 * - Service the stream queue that is next, moving any in sctp_chunk_output()
10038 * - Check to see if the cwnd/rwnd allows any output, if so we in sctp_chunk_output()
10054 asoc = &stcb->asoc; in sctp_chunk_output()
10068 un_sent = (stcb->asoc.total_output_queue_size - stcb->asoc.total_flight); in sctp_chunk_output()
10071 (TAILQ_EMPTY(&asoc->control_send_queue)) && in sctp_chunk_output()
10072 (TAILQ_EMPTY(&asoc->asconf_send_queue)) && in sctp_chunk_output()
10073 (asoc->sent_queue_retran_cnt == 0) && in sctp_chunk_output()
10074 (asoc->trigger_reset == 0)) { in sctp_chunk_output()
10080 * running, if so piggy-back the sack. in sctp_chunk_output()
10082 if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) { in sctp_chunk_output()
10084 sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, NULL, in sctp_chunk_output()
10087 while (asoc->sent_queue_retran_cnt) { in sctp_chunk_output()
10088 /*- in sctp_chunk_output()
10093 /*- in sctp_chunk_output()
10095 * by peer that carried data. Send cookie-ack only in sctp_chunk_output()
10118 /*- in sctp_chunk_output()
10119 * now lets push out control by calling med-level in sctp_chunk_output()
10133 /*- in sctp_chunk_output()
10155 if ((asoc->fr_max_burst > 0) && (tot_frs >= asoc->fr_max_burst)) { in sctp_chunk_output()
10168 TAILQ_FOREACH(net, &asoc->nets, sctp_next) { in sctp_chunk_output()
10169 if ((net->dest_state & SCTP_ADDR_REACHABLE) == 0) { in sctp_chunk_output()
10170 /*- in sctp_chunk_output()
10177 if (net->ref_count > 1) in sctp_chunk_output()
10180 /*- in sctp_chunk_output()
10181 * if ((asoc->sat_network) || (net->addr_is_local)) in sctp_chunk_output()
10182 * { burst_limit = asoc->max_burst * in sctp_chunk_output()
10185 if (asoc->max_burst > 0) { in sctp_chunk_output()
10187 if ((net->flight_size + (asoc->max_burst * net->mtu)) < net->cwnd) { in sctp_chunk_output()
10189 * JRS - Use the congestion in sctp_chunk_output()
10193 asoc->cc_functions.sctp_cwnd_update_after_output(stcb, net, asoc->max_burst); in sctp_chunk_output()
10195 sctp_log_maxburst(stcb, net, 0, asoc->max_burst, SCTP_MAX_BURST_APPLIED); in sctp_chunk_output()
10199 net->fast_retran_ip = 0; in sctp_chunk_output()
10201 if (net->flight_size == 0) { in sctp_chunk_output()
10218 SCTPDBG(SCTP_DEBUG_OUTPUT1, "Error %d was returned from med-c-op\n", error); in sctp_chunk_output()
10220 sctp_log_maxburst(stcb, asoc->primary_destination, error, burst_cnt, SCTP_MAX_BURST_ERROR_STOP); in sctp_chunk_output()
10228 SCTPDBG(SCTP_DEBUG_OUTPUT3, "m-c-o put out %d\n", num_out); in sctp_chunk_output()
10245 un_sent = stcb->asoc.total_output_queue_size - stcb->asoc.total_flight; in sctp_chunk_output()
10246 if ((un_sent < (int)(stcb->asoc.smallest_mtu - SCTP_MIN_OVERHEAD)) && in sctp_chunk_output()
10247 (stcb->asoc.total_flight > 0)) { in sctp_chunk_output()
10252 if (TAILQ_EMPTY(&asoc->control_send_queue) && in sctp_chunk_output()
10253 TAILQ_EMPTY(&asoc->send_queue) && in sctp_chunk_output()
10258 if ((stcb->asoc.total_output_queue_size - stcb->asoc.total_flight) <= 0) { in sctp_chunk_output()
10263 ((asoc->max_burst == 0) || in sctp_chunk_output()
10265 (burst_cnt < asoc->max_burst))); in sctp_chunk_output()
10268 if ((asoc->max_burst > 0) && (burst_cnt >= asoc->max_burst)) { in sctp_chunk_output()
10270 asoc->burst_limit_applied = 1; in sctp_chunk_output()
10272 sctp_log_maxburst(stcb, asoc->primary_destination, 0, burst_cnt, SCTP_MAX_BURST_APPLIED); in sctp_chunk_output()
10275 asoc->burst_limit_applied = 0; in sctp_chunk_output()
10284 /*- in sctp_chunk_output()
10289 if (stcb->asoc.ecn_echo_cnt_onq) in sctp_chunk_output()
10292 if (stcb->asoc.trigger_reset) { in sctp_chunk_output()
10314 if (inp->sctp_socket == NULL) { in sctp_output()
10318 return (sctp_sosend(inp->sctp_socket, in sctp_output()
10341 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in send_forward_tsn()
10342 if (chk->rec.chunk_id.id == SCTP_FORWARD_CUM_TSN) { in send_forward_tsn()
10344 chk->sent = SCTP_DATAGRAM_UNSENT; in send_forward_tsn()
10345 chk->snd_count = 0; in send_forward_tsn()
10347 if (chk->whoTo) { in send_forward_tsn()
10348 sctp_free_remote_addr(chk->whoTo); in send_forward_tsn()
10349 chk->whoTo = NULL; in send_forward_tsn()
10359 asoc->fwd_tsn_cnt++; in send_forward_tsn()
10360 chk->copy_by_ref = 0; in send_forward_tsn()
10362 * We don't do the old thing here since this is used not for on-wire in send_forward_tsn()
10363 * but to tell if we are sending a fwd-tsn by the stack during in send_forward_tsn()
10364 * output. And if its a IFORWARD or a FORWARD it is a fwd-tsn. in send_forward_tsn()
10366 chk->rec.chunk_id.id = SCTP_FORWARD_CUM_TSN; in send_forward_tsn()
10367 chk->rec.chunk_id.can_take_data = 0; in send_forward_tsn()
10368 chk->flags = 0; in send_forward_tsn()
10369 chk->asoc = asoc; in send_forward_tsn()
10370 chk->whoTo = NULL; in send_forward_tsn()
10371 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); in send_forward_tsn()
10372 if (chk->data == NULL) { in send_forward_tsn()
10376 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in send_forward_tsn()
10377 chk->sent = SCTP_DATAGRAM_UNSENT; in send_forward_tsn()
10378 chk->snd_count = 0; in send_forward_tsn()
10379 TAILQ_INSERT_TAIL(&asoc->control_send_queue, chk, sctp_next); in send_forward_tsn()
10380 asoc->ctrl_queue_cnt++; in send_forward_tsn()
10382 /*- in send_forward_tsn()
10386 SCTP_BUF_LEN(chk->data) = 0; in send_forward_tsn()
10387 TAILQ_FOREACH(at, &asoc->sent_queue, sctp_next) { in send_forward_tsn()
10388 if ((at->sent != SCTP_FORWARD_TSN_SKIP) && in send_forward_tsn()
10389 (at->sent != SCTP_DATAGRAM_NR_ACKED)) { in send_forward_tsn()
10393 if (!asoc->idata_supported && (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED)) { in send_forward_tsn()
10399 if (asoc->idata_supported) { in send_forward_tsn()
10406 cnt_of_space = (unsigned int)M_TRAILINGSPACE(chk->data); in send_forward_tsn()
10408 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) { in send_forward_tsn()
10413 if (cnt_of_space > (asoc->smallest_mtu - ovh)) { in send_forward_tsn()
10415 cnt_of_space = asoc->smallest_mtu - ovh; in send_forward_tsn()
10420 asoc->advanced_peer_ack_point); in send_forward_tsn()
10422 advance_peer_ack_point = asoc->advanced_peer_ack_point; in send_forward_tsn()
10424 /*- in send_forward_tsn()
10433 cnt_of_skipped = cnt_of_space - sizeof(struct sctp_forward_tsn_chunk); in send_forward_tsn()
10434 if (asoc->idata_supported) { in send_forward_tsn()
10439 /*- in send_forward_tsn()
10443 at = TAILQ_FIRST(&asoc->sent_queue); in send_forward_tsn()
10455 0xff, cnt_of_skipped, at->rec.data.tsn, in send_forward_tsn()
10456 asoc->advanced_peer_ack_point); in send_forward_tsn()
10459 /*- in send_forward_tsn()
10464 advance_peer_ack_point = last->rec.data.tsn; in send_forward_tsn()
10466 if (asoc->idata_supported) { in send_forward_tsn()
10474 chk->send_size = space_needed; in send_forward_tsn()
10476 fwdtsn = mtod(chk->data, struct sctp_forward_tsn_chunk *); in send_forward_tsn()
10477 fwdtsn->ch.chunk_length = htons(chk->send_size); in send_forward_tsn()
10478 fwdtsn->ch.chunk_flags = 0; in send_forward_tsn()
10479 if (asoc->idata_supported) { in send_forward_tsn()
10480 fwdtsn->ch.chunk_type = SCTP_IFORWARD_CUM_TSN; in send_forward_tsn()
10482 fwdtsn->ch.chunk_type = SCTP_FORWARD_CUM_TSN; in send_forward_tsn()
10484 fwdtsn->new_cumulative_tsn = htonl(advance_peer_ack_point); in send_forward_tsn()
10485 SCTP_BUF_LEN(chk->data) = chk->send_size; in send_forward_tsn()
10487 /*- in send_forward_tsn()
10491 if (asoc->idata_supported) { in send_forward_tsn()
10498 /*- in send_forward_tsn()
10506 * one FWD-TSN. With a bit of work we can later FIX this to in send_forward_tsn()
10511 TAILQ_FOREACH(at, &asoc->sent_queue, sctp_next) { in send_forward_tsn()
10515 if (!asoc->idata_supported && (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED)) { in send_forward_tsn()
10519 if (at->rec.data.tsn == advance_peer_ack_point) { in send_forward_tsn()
10520 at->rec.data.fwd_tsn_cnt = 0; in send_forward_tsn()
10522 if (asoc->idata_supported) { in send_forward_tsn()
10523 strseq_m->sid = htons(at->rec.data.sid); in send_forward_tsn()
10524 if (at->rec.data.rcv_flags & SCTP_DATA_UNORDERED) { in send_forward_tsn()
10525 strseq_m->flags = htons(PR_SCTP_UNORDERED_FLAG); in send_forward_tsn()
10527 strseq_m->flags = 0; in send_forward_tsn()
10529 strseq_m->mid = htonl(at->rec.data.mid); in send_forward_tsn()
10532 strseq->sid = htons(at->rec.data.sid); in send_forward_tsn()
10533 strseq->ssn = htons((uint16_t)at->rec.data.mid); in send_forward_tsn()
10544 /*- in sctp_send_sack()
10545 * Queue up a SACK or NR-SACK in the control queue. in sctp_send_sack()
10546 * We must first check to see if a SACK or NR-SACK is in sctp_send_sack()
10570 if (stcb->asoc.nrsack_supported == 1) { in sctp_send_sack()
10576 asoc = &stcb->asoc; in sctp_send_sack()
10578 if (asoc->last_data_chunk_from == NULL) { in sctp_send_sack()
10584 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_send_sack()
10585 if (chk->rec.chunk_id.id == type) { in sctp_send_sack()
10587 TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next); in sctp_send_sack()
10588 asoc->ctrl_queue_cnt--; in sctp_send_sack()
10590 if (a_chk->data) { in sctp_send_sack()
10591 sctp_m_freem(a_chk->data); in sctp_send_sack()
10592 a_chk->data = NULL; in sctp_send_sack()
10594 if (a_chk->whoTo) { in sctp_send_sack()
10595 sctp_free_remote_addr(a_chk->whoTo); in sctp_send_sack()
10596 a_chk->whoTo = NULL; in sctp_send_sack()
10605 if (stcb->asoc.delayed_ack) { in sctp_send_sack()
10607 stcb->sctp_ep, stcb, NULL, in sctp_send_sack()
10610 stcb->sctp_ep, stcb, NULL); in sctp_send_sack()
10612 stcb->asoc.send_sack = 1; in sctp_send_sack()
10616 a_chk->copy_by_ref = 0; in sctp_send_sack()
10617 a_chk->rec.chunk_id.id = type; in sctp_send_sack()
10618 a_chk->rec.chunk_id.can_take_data = 1; in sctp_send_sack()
10621 asoc->data_pkts_seen = 0; in sctp_send_sack()
10623 a_chk->flags = 0; in sctp_send_sack()
10624 a_chk->asoc = asoc; in sctp_send_sack()
10625 a_chk->snd_count = 0; in sctp_send_sack()
10626 a_chk->send_size = 0; /* fill in later */ in sctp_send_sack()
10627 a_chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_sack()
10628 a_chk->whoTo = NULL; in sctp_send_sack()
10630 if ((asoc->last_data_chunk_from->dest_state & SCTP_ADDR_REACHABLE) == 0) { in sctp_send_sack()
10631 /*- in sctp_send_sack()
10633 * we can select an alternate to asoc->last_data_chunk_from in sctp_send_sack()
10635 a_chk->whoTo = sctp_find_alternate_net(stcb, asoc->last_data_chunk_from, 0); in sctp_send_sack()
10636 if (a_chk->whoTo == NULL) { in sctp_send_sack()
10638 a_chk->whoTo = asoc->last_data_chunk_from; in sctp_send_sack()
10641 a_chk->whoTo = asoc->last_data_chunk_from; in sctp_send_sack()
10643 if (a_chk->whoTo) { in sctp_send_sack()
10644 atomic_add_int(&a_chk->whoTo->ref_count, 1); in sctp_send_sack()
10646 if (SCTP_TSN_GT(asoc->highest_tsn_inside_map, asoc->highest_tsn_inside_nr_map)) { in sctp_send_sack()
10647 highest_tsn = asoc->highest_tsn_inside_map; in sctp_send_sack()
10649 highest_tsn = asoc->highest_tsn_inside_nr_map; in sctp_send_sack()
10651 if (highest_tsn == asoc->cumulative_tsn) { in sctp_send_sack()
10663 a_chk->data = sctp_get_mbuf_for_msg(space_req, 0, M_NOWAIT, 1, MT_DATA); in sctp_send_sack()
10664 if ((a_chk->data == NULL) || in sctp_send_sack()
10665 (a_chk->whoTo == NULL)) { in sctp_send_sack()
10667 if (a_chk->data) { in sctp_send_sack()
10669 sctp_m_freem(a_chk->data); in sctp_send_sack()
10670 a_chk->data = NULL; in sctp_send_sack()
10674 if (stcb->asoc.delayed_ack) { in sctp_send_sack()
10676 stcb->sctp_ep, stcb, NULL, in sctp_send_sack()
10679 stcb->sctp_ep, stcb, NULL); in sctp_send_sack()
10681 stcb->asoc.send_sack = 1; in sctp_send_sack()
10686 SCTP_BUF_RESV_UF(a_chk->data, SCTP_MIN_OVERHEAD); in sctp_send_sack()
10687 space = (unsigned int)M_TRAILINGSPACE(a_chk->data); in sctp_send_sack()
10688 if (space > (a_chk->whoTo->mtu - SCTP_MIN_OVERHEAD)) { in sctp_send_sack()
10689 space = (a_chk->whoTo->mtu - SCTP_MIN_OVERHEAD); in sctp_send_sack()
10691 limit = mtod(a_chk->data, caddr_t); in sctp_send_sack()
10696 if ((asoc->sctp_cmt_on_off > 0) && in sctp_send_sack()
10698 /*- in sctp_send_sack()
10703 flags |= (asoc->cmt_dac_pkts_rcvd << 6); in sctp_send_sack()
10704 asoc->cmt_dac_pkts_rcvd = 0; in sctp_send_sack()
10707 stcb->asoc.cumack_logsnt[stcb->asoc.cumack_log_atsnt] = asoc->cumulative_tsn; in sctp_send_sack()
10708 stcb->asoc.cumack_log_atsnt++; in sctp_send_sack()
10709 if (stcb->asoc.cumack_log_atsnt >= SCTP_TSN_LOG_SIZE) { in sctp_send_sack()
10710 stcb->asoc.cumack_log_atsnt = 0; in sctp_send_sack()
10714 stcb->freed_by_sorcv_sincelast = 0; in sctp_send_sack()
10717 sack = mtod(a_chk->data, struct sctp_sack_chunk *); in sctp_send_sack()
10720 if (highest_tsn > asoc->mapping_array_base_tsn) { in sctp_send_sack()
10721 siz = (((highest_tsn - asoc->mapping_array_base_tsn) + 1) + 7) / 8; in sctp_send_sack()
10723 siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + highest_tsn + 7) / 8; in sctp_send_sack()
10727 nr_sack = mtod(a_chk->data, struct sctp_nr_sack_chunk *); in sctp_send_sack()
10729 if (asoc->highest_tsn_inside_map > asoc->mapping_array_base_tsn) { in sctp_send_sack()
10730 siz = (((asoc->highest_tsn_inside_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8; in sctp_send_sack()
10732 siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_map + 7) / 8; in sctp_send_sack()
10736 if (SCTP_TSN_GT(asoc->mapping_array_base_tsn, asoc->cumulative_tsn)) { in sctp_send_sack()
10739 offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn; in sctp_send_sack()
10742 SCTP_TSN_GT(highest_tsn, asoc->cumulative_tsn)) || in sctp_send_sack()
10744 SCTP_TSN_GT(asoc->highest_tsn_inside_map, asoc->cumulative_tsn))) { in sctp_send_sack()
10747 tsn_map = asoc->mapping_array[i]; in sctp_send_sack()
10749 tsn_map |= asoc->nr_mapping_array[i]; in sctp_send_sack()
10756 tsn_map &= (~0U << (1 - offset)); in sctp_send_sack()
10759 if (mergeable && selector->right_edge) { in sctp_send_sack()
10764 num_gap_blocks--; in sctp_send_sack()
10765 gap_descriptor--; in sctp_send_sack()
10767 if (selector->num_entries == 0) in sctp_send_sack()
10770 for (j = 0; j < selector->num_entries; j++) { in sctp_send_sack()
10771 if (mergeable && selector->right_edge) { in sctp_send_sack()
10783 gap_descriptor->start = htons((selector->gaps[j].start + offset)); in sctp_send_sack()
10785 gap_descriptor->end = htons((selector->gaps[j].end + offset)); in sctp_send_sack()
10794 if (selector->left_edge) { in sctp_send_sack()
10809 if (asoc->highest_tsn_inside_nr_map > asoc->mapping_array_base_tsn) { in sctp_send_sack()
10810 siz = (((asoc->highest_tsn_inside_nr_map - asoc->mapping_array_base_tsn) + 1) + 7) / 8; in sctp_send_sack()
10812 siz = (((MAX_TSN - asoc->mapping_array_base_tsn) + 1) + asoc->highest_tsn_inside_nr_map + 7) / 8; in sctp_send_sack()
10815 if (SCTP_TSN_GT(asoc->mapping_array_base_tsn, asoc->cumulative_tsn)) { in sctp_send_sack()
10818 offset = asoc->mapping_array_base_tsn - asoc->cumulative_tsn; in sctp_send_sack()
10820 if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->cumulative_tsn)) { in sctp_send_sack()
10823 tsn_map = asoc->nr_mapping_array[i]; in sctp_send_sack()
10830 tsn_map &= (~0U << (1 - offset)); in sctp_send_sack()
10833 if (mergeable && selector->right_edge) { in sctp_send_sack()
10838 num_nr_gap_blocks--; in sctp_send_sack()
10839 gap_descriptor--; in sctp_send_sack()
10841 if (selector->num_entries == 0) in sctp_send_sack()
10844 for (j = 0; j < selector->num_entries; j++) { in sctp_send_sack()
10845 if (mergeable && selector->right_edge) { in sctp_send_sack()
10858 gap_descriptor->start = htons((selector->gaps[j].start + offset)); in sctp_send_sack()
10860 gap_descriptor->end = htons((selector->gaps[j].end + offset)); in sctp_send_sack()
10869 if (selector->left_edge) { in sctp_send_sack()
10882 if ((limit_reached == 0) && (asoc->numduptsns)) { in sctp_send_sack()
10884 for (i = 0; i < asoc->numduptsns; i++) { in sctp_send_sack()
10885 *dup = htonl(asoc->dup_tsns[i]); in sctp_send_sack()
10893 asoc->numduptsns = 0; in sctp_send_sack()
10900 a_chk->send_size = (uint16_t)(sizeof(struct sctp_sack_chunk) + in sctp_send_sack()
10903 SCTP_BUF_LEN(a_chk->data) = a_chk->send_size; in sctp_send_sack()
10904 sack->sack.cum_tsn_ack = htonl(asoc->cumulative_tsn); in sctp_send_sack()
10905 sack->sack.a_rwnd = htonl(asoc->my_rwnd); in sctp_send_sack()
10906 sack->sack.num_gap_ack_blks = htons(num_gap_blocks); in sctp_send_sack()
10907 sack->sack.num_dup_tsns = htons(num_dups); in sctp_send_sack()
10908 sack->ch.chunk_type = type; in sctp_send_sack()
10909 sack->ch.chunk_flags = flags; in sctp_send_sack()
10910 sack->ch.chunk_length = htons(a_chk->send_size); in sctp_send_sack()
10912 a_chk->send_size = (uint16_t)(sizeof(struct sctp_nr_sack_chunk) + in sctp_send_sack()
10915 SCTP_BUF_LEN(a_chk->data) = a_chk->send_size; in sctp_send_sack()
10916 nr_sack->nr_sack.cum_tsn_ack = htonl(asoc->cumulative_tsn); in sctp_send_sack()
10917 nr_sack->nr_sack.a_rwnd = htonl(asoc->my_rwnd); in sctp_send_sack()
10918 nr_sack->nr_sack.num_gap_ack_blks = htons(num_gap_blocks); in sctp_send_sack()
10919 nr_sack->nr_sack.num_nr_gap_ack_blks = htons(num_nr_gap_blocks); in sctp_send_sack()
10920 nr_sack->nr_sack.num_dup_tsns = htons(num_dups); in sctp_send_sack()
10921 nr_sack->nr_sack.reserved = 0; in sctp_send_sack()
10922 nr_sack->ch.chunk_type = type; in sctp_send_sack()
10923 nr_sack->ch.chunk_flags = flags; in sctp_send_sack()
10924 nr_sack->ch.chunk_length = htons(a_chk->send_size); in sctp_send_sack()
10926 TAILQ_INSERT_TAIL(&asoc->control_send_queue, a_chk, sctp_next); in sctp_send_sack()
10927 asoc->my_last_reported_rwnd = asoc->my_rwnd; in sctp_send_sack()
10928 asoc->ctrl_queue_cnt++; in sctp_send_sack()
10929 asoc->send_sack = 0; in sctp_send_sack()
10949 /*- in sctp_send_abort_tcb()
10954 stcb->asoc.peer_auth_chunks)) { in sctp_send_abort_tcb()
10961 switch (stcb->asoc.snd_edmid) { in sctp_send_abort_tcb()
10991 padding_len = SCTP_SIZE32(chunk_len) - chunk_len; in sctp_send_abort_tcb()
11000 if (stcb->asoc.alternate) { in sctp_send_abort_tcb()
11001 net = stcb->asoc.alternate; in sctp_send_abort_tcb()
11003 net = stcb->asoc.primary_destination; in sctp_send_abort_tcb()
11007 abort->ch.chunk_type = SCTP_ABORT_ASSOCIATION; in sctp_send_abort_tcb()
11008 if (stcb->asoc.peer_vtag == 0) { in sctp_send_abort_tcb()
11009 /* This happens iff the assoc is in COOKIE-WAIT state. */ in sctp_send_abort_tcb()
11010 vtag = stcb->asoc.my_vtag; in sctp_send_abort_tcb()
11011 abort->ch.chunk_flags = SCTP_HAD_NO_TCB; in sctp_send_abort_tcb()
11013 vtag = stcb->asoc.peer_vtag; in sctp_send_abort_tcb()
11014 abort->ch.chunk_flags = 0; in sctp_send_abort_tcb()
11016 abort->ch.chunk_length = htons(chunk_len); in sctp_send_abort_tcb()
11025 if ((error = sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, in sctp_send_abort_tcb()
11026 (struct sockaddr *)&net->ro._l_addr, in sctp_send_abort_tcb()
11027 m_out, auth_offset, auth, stcb->asoc.authinfo.active_keyid, 1, 0, 0, in sctp_send_abort_tcb()
11028 stcb->sctp_ep->sctp_lport, stcb->rport, htonl(vtag), in sctp_send_abort_tcb()
11029 stcb->asoc.primary_destination->port, NULL, in sctp_send_abort_tcb()
11035 stcb->asoc.ifp_had_enobuf = 1; in sctp_send_abort_tcb()
11039 stcb->asoc.ifp_had_enobuf = 0; in sctp_send_abort_tcb()
11049 /* formulate and SEND a SHUTDOWN-COMPLETE */ in sctp_send_shutdown_complete()
11064 vtag = stcb->asoc.my_vtag; in sctp_send_shutdown_complete()
11067 vtag = stcb->asoc.peer_vtag; in sctp_send_shutdown_complete()
11069 switch (stcb->asoc.snd_edmid) { in sctp_send_shutdown_complete()
11078 shutdown_complete->ch.chunk_type = SCTP_SHUTDOWN_COMPLETE; in sctp_send_shutdown_complete()
11079 shutdown_complete->ch.chunk_flags = flags; in sctp_send_shutdown_complete()
11080 shutdown_complete->ch.chunk_length = htons(sizeof(struct sctp_shutdown_complete_chunk)); in sctp_send_shutdown_complete()
11082 if ((error = sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, in sctp_send_shutdown_complete()
11083 (struct sockaddr *)&net->ro._l_addr, in sctp_send_shutdown_complete()
11085 stcb->sctp_ep->sctp_lport, stcb->rport, in sctp_send_shutdown_complete()
11087 net->port, NULL, in sctp_send_shutdown_complete()
11093 stcb->asoc.ifp_had_enobuf = 1; in sctp_send_shutdown_complete()
11097 stcb->asoc.ifp_had_enobuf = 0; in sctp_send_shutdown_complete()
11139 padding_len = 4 - padding_len; in sctp_send_resp_msg()
11152 switch (dst->sa_family) { in sctp_send_resp_msg()
11182 mout->m_pkthdr.flowid = mflowid; in sctp_send_resp_msg()
11190 switch (dst->sa_family) { in sctp_send_resp_msg()
11196 ip->ip_v = IPVERSION; in sctp_send_resp_msg()
11197 ip->ip_hl = (sizeof(struct ip) >> 2); in sctp_send_resp_msg()
11198 ip->ip_tos = 0; in sctp_send_resp_msg()
11199 ip->ip_off = htons(IP_DF); in sctp_send_resp_msg()
11201 ip->ip_ttl = MODULE_GLOBAL(ip_defttl); in sctp_send_resp_msg()
11203 ip->ip_p = IPPROTO_UDP; in sctp_send_resp_msg()
11205 ip->ip_p = IPPROTO_SCTP; in sctp_send_resp_msg()
11207 ip->ip_src.s_addr = dst_sin->sin_addr.s_addr; in sctp_send_resp_msg()
11208 ip->ip_dst.s_addr = src_sin->sin_addr.s_addr; in sctp_send_resp_msg()
11209 ip->ip_sum = 0; in sctp_send_resp_msg()
11219 ip6->ip6_flow = htonl(0x60000000); in sctp_send_resp_msg()
11221 ip6->ip6_flow |= (htonl(ip6_randomflowlabel()) & IPV6_FLOWLABEL_MASK); in sctp_send_resp_msg()
11223 ip6->ip6_hlim = MODULE_GLOBAL(ip6_defhlim); in sctp_send_resp_msg()
11225 ip6->ip6_nxt = IPPROTO_UDP; in sctp_send_resp_msg()
11227 ip6->ip6_nxt = IPPROTO_SCTP; in sctp_send_resp_msg()
11229 ip6->ip6_src = dst_sin6->sin6_addr; in sctp_send_resp_msg()
11230 ip6->ip6_dst = src_sin6->sin6_addr; in sctp_send_resp_msg()
11247 udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); in sctp_send_resp_msg()
11248 udp->uh_dport = port; in sctp_send_resp_msg()
11249 udp->uh_sum = 0; in sctp_send_resp_msg()
11250 udp->uh_ulen = htons((uint16_t)(sizeof(struct udphdr) + in sctp_send_resp_msg()
11260 shout->src_port = sh->dest_port; in sctp_send_resp_msg()
11261 shout->dest_port = sh->src_port; in sctp_send_resp_msg()
11262 shout->checksum = 0; in sctp_send_resp_msg()
11264 shout->v_tag = htonl(vtag); in sctp_send_resp_msg()
11266 shout->v_tag = sh->v_tag; in sctp_send_resp_msg()
11270 ch->chunk_type = type; in sctp_send_resp_msg()
11272 ch->chunk_flags = 0; in sctp_send_resp_msg()
11274 ch->chunk_flags = SCTP_HAD_NO_TCB; in sctp_send_resp_msg()
11276 ch->chunk_length = htons((uint16_t)(sizeof(struct sctp_chunkhdr) + cause_len)); in sctp_send_resp_msg()
11285 switch (dst->sa_family) { in sctp_send_resp_msg()
11290 … udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); in sctp_send_resp_msg()
11292 udp->uh_sum = 0; in sctp_send_resp_msg()
11295 ip->ip_len = htons(len); in sctp_send_resp_msg()
11297 shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip) + sizeof(struct udphdr)); in sctp_send_resp_msg()
11303 mout->m_pkthdr.csum_flags = CSUM_SCTP; in sctp_send_resp_msg()
11304 mout->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum); in sctp_send_resp_msg()
11318 ip6->ip6_plen = htons((uint16_t)(len - sizeof(struct ip6_hdr))); in sctp_send_resp_msg()
11320 shout->checksum = sctp_calculate_cksum(mout, sizeof(struct ip6_hdr) + sizeof(struct udphdr)); in sctp_send_resp_msg()
11322 …if ((udp->uh_sum = in6_cksum(o_pak, IPPROTO_UDP, sizeof(struct ip6_hdr), len - sizeof(struct ip6_h… in sctp_send_resp_msg()
11323 udp->uh_sum = 0xffff; in sctp_send_resp_msg()
11326 mout->m_pkthdr.csum_flags = CSUM_SCTP_IPV6; in sctp_send_resp_msg()
11327 mout->m_pkthdr.csum_data = offsetof(struct sctphdr, checksum); in sctp_send_resp_msg()
11341 dst->sa_family); in sctp_send_resp_msg()
11382 switch (net->ro._l_addr.sa.sa_family) { in sctp_send_hb()
11400 chk->copy_by_ref = 0; in sctp_send_hb()
11401 chk->rec.chunk_id.id = SCTP_HEARTBEAT_REQUEST; in sctp_send_hb()
11402 chk->rec.chunk_id.can_take_data = 1; in sctp_send_hb()
11403 chk->flags = 0; in sctp_send_hb()
11404 chk->asoc = &stcb->asoc; in sctp_send_hb()
11405 chk->send_size = sizeof(struct sctp_heartbeat_chunk); in sctp_send_hb()
11407 chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER); in sctp_send_hb()
11408 if (chk->data == NULL) { in sctp_send_hb()
11412 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_hb()
11413 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_hb()
11414 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_hb()
11415 chk->snd_count = 0; in sctp_send_hb()
11416 chk->whoTo = net; in sctp_send_hb()
11417 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_hb()
11419 hb = mtod(chk->data, struct sctp_heartbeat_chunk *); in sctp_send_hb()
11422 hb->ch.chunk_type = SCTP_HEARTBEAT_REQUEST; in sctp_send_hb()
11423 hb->ch.chunk_flags = 0; in sctp_send_hb()
11424 hb->ch.chunk_length = htons(chk->send_size); in sctp_send_hb()
11426 hb->heartbeat.hb_info.ph.param_type = htons(SCTP_HEARTBEAT_INFO); in sctp_send_hb()
11427 hb->heartbeat.hb_info.ph.param_length = htons(sizeof(struct sctp_heartbeat_info_param)); in sctp_send_hb()
11428 hb->heartbeat.hb_info.time_value_1 = now.tv_sec; in sctp_send_hb()
11429 hb->heartbeat.hb_info.time_value_2 = now.tv_usec; in sctp_send_hb()
11431 hb->heartbeat.hb_info.addr_family = (uint8_t)net->ro._l_addr.sa.sa_family; in sctp_send_hb()
11432 hb->heartbeat.hb_info.addr_len = net->ro._l_addr.sa.sa_len; in sctp_send_hb()
11433 if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { in sctp_send_hb()
11438 …net->heartbeat_random1 = hb->heartbeat.hb_info.random_value1 = sctp_select_initial_TSN(&stcb->sctp… in sctp_send_hb()
11439 …net->heartbeat_random2 = hb->heartbeat.hb_info.random_value2 = sctp_select_initial_TSN(&stcb->sctp… in sctp_send_hb()
11441 net->heartbeat_random1 = hb->heartbeat.hb_info.random_value1 = 0; in sctp_send_hb()
11442 net->heartbeat_random2 = hb->heartbeat.hb_info.random_value2 = 0; in sctp_send_hb()
11444 switch (net->ro._l_addr.sa.sa_family) { in sctp_send_hb()
11447 memcpy(hb->heartbeat.hb_info.address, in sctp_send_hb()
11448 &net->ro._l_addr.sin.sin_addr, in sctp_send_hb()
11449 sizeof(net->ro._l_addr.sin.sin_addr)); in sctp_send_hb()
11454 memcpy(hb->heartbeat.hb_info.address, in sctp_send_hb()
11455 &net->ro._l_addr.sin6.sin6_addr, in sctp_send_hb()
11456 sizeof(net->ro._l_addr.sin6.sin6_addr)); in sctp_send_hb()
11460 if (chk->data) { in sctp_send_hb()
11461 sctp_m_freem(chk->data); in sctp_send_hb()
11462 chk->data = NULL; in sctp_send_hb()
11468 net->hb_responded = 0; in sctp_send_hb()
11469 TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); in sctp_send_hb()
11470 stcb->asoc.ctrl_queue_cnt++; in sctp_send_hb()
11486 asoc = &stcb->asoc; in sctp_send_ecn_echo()
11488 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_send_ecn_echo()
11489 if ((chk->rec.chunk_id.id == SCTP_ECN_ECHO) && (net == chk->whoTo)) { in sctp_send_ecn_echo()
11493 ecne = mtod(chk->data, struct sctp_ecne_chunk *); in sctp_send_ecn_echo()
11494 ctsn = ntohl(ecne->tsn); in sctp_send_ecn_echo()
11496 ecne->tsn = htonl(high_tsn); in sctp_send_ecn_echo()
11499 cnt = ntohl(ecne->num_pkts_since_cwr); in sctp_send_ecn_echo()
11501 ecne->num_pkts_since_cwr = htonl(cnt); in sctp_send_ecn_echo()
11511 chk->copy_by_ref = 0; in sctp_send_ecn_echo()
11512 chk->rec.chunk_id.id = SCTP_ECN_ECHO; in sctp_send_ecn_echo()
11513 chk->rec.chunk_id.can_take_data = 0; in sctp_send_ecn_echo()
11514 chk->flags = 0; in sctp_send_ecn_echo()
11515 chk->asoc = &stcb->asoc; in sctp_send_ecn_echo()
11516 chk->send_size = sizeof(struct sctp_ecne_chunk); in sctp_send_ecn_echo()
11517 chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER); in sctp_send_ecn_echo()
11518 if (chk->data == NULL) { in sctp_send_ecn_echo()
11522 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_ecn_echo()
11523 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_ecn_echo()
11524 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_ecn_echo()
11525 chk->snd_count = 0; in sctp_send_ecn_echo()
11526 chk->whoTo = net; in sctp_send_ecn_echo()
11527 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_ecn_echo()
11529 stcb->asoc.ecn_echo_cnt_onq++; in sctp_send_ecn_echo()
11530 ecne = mtod(chk->data, struct sctp_ecne_chunk *); in sctp_send_ecn_echo()
11531 ecne->ch.chunk_type = SCTP_ECN_ECHO; in sctp_send_ecn_echo()
11532 ecne->ch.chunk_flags = 0; in sctp_send_ecn_echo()
11533 ecne->ch.chunk_length = htons(sizeof(struct sctp_ecne_chunk)); in sctp_send_ecn_echo()
11534 ecne->tsn = htonl(high_tsn); in sctp_send_ecn_echo()
11535 ecne->num_pkts_since_cwr = htonl(1); in sctp_send_ecn_echo()
11536 TAILQ_INSERT_HEAD(&stcb->asoc.control_send_queue, chk, sctp_next); in sctp_send_ecn_echo()
11537 asoc->ctrl_queue_cnt++; in sctp_send_ecn_echo()
11558 asoc = &stcb->asoc; in sctp_send_packet_dropped()
11560 if (asoc->pktdrop_supported == 0) { in sctp_send_packet_dropped()
11561 /*- in sctp_send_packet_dropped()
11566 if (stcb->sctp_socket == NULL) { in sctp_send_packet_dropped()
11573 chk->copy_by_ref = 0; in sctp_send_packet_dropped()
11574 chk->rec.chunk_id.id = SCTP_PACKET_DROPPED; in sctp_send_packet_dropped()
11575 chk->rec.chunk_id.can_take_data = 1; in sctp_send_packet_dropped()
11576 chk->flags = 0; in sctp_send_packet_dropped()
11577 len -= iphlen; in sctp_send_packet_dropped()
11578 chk->send_size = len; in sctp_send_packet_dropped()
11584 chk_length = ntohs(ch->chunk_length); in sctp_send_packet_dropped()
11589 switch (ch->chunk_type) { in sctp_send_packet_dropped()
11594 * We don't respond with an PKT-DROP to an ABORT in sctp_send_packet_dropped()
11595 * or PKT-DROP. We also do not respond to an in sctp_send_packet_dropped()
11596 * INIT-ACK, because we can't know if the initiation in sctp_send_packet_dropped()
11610 min(stcb->asoc.smallest_mtu, MCLBYTES)) { in sctp_send_packet_dropped()
11615 len = min(stcb->asoc.smallest_mtu, MCLBYTES) - SCTP_MAX_OVERHEAD; in sctp_send_packet_dropped()
11618 chk->asoc = &stcb->asoc; in sctp_send_packet_dropped()
11619 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); in sctp_send_packet_dropped()
11620 if (chk->data == NULL) { in sctp_send_packet_dropped()
11625 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_packet_dropped()
11626 drp = mtod(chk->data, struct sctp_pktdrop_chunk *); in sctp_send_packet_dropped()
11628 sctp_m_freem(chk->data); in sctp_send_packet_dropped()
11629 chk->data = NULL; in sctp_send_packet_dropped()
11632 chk->book_size = SCTP_SIZE32((chk->send_size + sizeof(struct sctp_pktdrop_chunk) + in sctp_send_packet_dropped()
11634 chk->book_size_scale = 0; in sctp_send_packet_dropped()
11636 drp->ch.chunk_flags = SCTP_PACKET_TRUNCATED; in sctp_send_packet_dropped()
11637 drp->trunc_len = htons(fullsz); in sctp_send_packet_dropped()
11642 chk->send_size = (uint16_t)(len - sizeof(struct sctp_pktdrop_chunk)); in sctp_send_packet_dropped()
11643 len = chk->send_size; in sctp_send_packet_dropped()
11646 drp->ch.chunk_flags = 0; in sctp_send_packet_dropped()
11647 drp->trunc_len = htons(0); in sctp_send_packet_dropped()
11650 drp->ch.chunk_flags |= SCTP_BADCRC; in sctp_send_packet_dropped()
11652 chk->send_size += sizeof(struct sctp_pktdrop_chunk); in sctp_send_packet_dropped()
11653 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_packet_dropped()
11654 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_packet_dropped()
11655 chk->snd_count = 0; in sctp_send_packet_dropped()
11658 chk->whoTo = net; in sctp_send_packet_dropped()
11659 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_packet_dropped()
11661 chk->whoTo = NULL; in sctp_send_packet_dropped()
11663 drp->ch.chunk_type = SCTP_PACKET_DROPPED; in sctp_send_packet_dropped()
11664 drp->ch.chunk_length = htons(chk->send_size); in sctp_send_packet_dropped()
11665 spc = SCTP_SB_LIMIT_RCV(stcb->sctp_socket); in sctp_send_packet_dropped()
11669 drp->bottle_bw = htonl(spc); in sctp_send_packet_dropped()
11670 if (asoc->my_rwnd) { in sctp_send_packet_dropped()
11671 drp->current_onq = htonl(asoc->size_on_reasm_queue + in sctp_send_packet_dropped()
11672 asoc->size_on_all_streams + in sctp_send_packet_dropped()
11673 asoc->my_rwnd_control_len + in sctp_send_packet_dropped()
11674 SCTP_SBAVAIL(&stcb->sctp_socket->so_rcv)); in sctp_send_packet_dropped()
11676 /*- in sctp_send_packet_dropped()
11680 drp->current_onq = htonl(spc); in sctp_send_packet_dropped()
11682 drp->reserved = 0; in sctp_send_packet_dropped()
11683 datap = drp->data; in sctp_send_packet_dropped()
11685 TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); in sctp_send_packet_dropped()
11686 asoc->ctrl_queue_cnt++; in sctp_send_packet_dropped()
11700 asoc = &stcb->asoc; in sctp_send_cwr()
11701 TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { in sctp_send_cwr()
11702 if ((chk->rec.chunk_id.id == SCTP_ECN_CWR) && (net == chk->whoTo)) { in sctp_send_cwr()
11709 cwr = mtod(chk->data, struct sctp_cwr_chunk *); in sctp_send_cwr()
11710 ctsn = ntohl(cwr->tsn); in sctp_send_cwr()
11712 cwr->tsn = htonl(high_tsn); in sctp_send_cwr()
11716 cwr->ch.chunk_flags |= SCTP_CWR_REDUCE_OVERRIDE; in sctp_send_cwr()
11725 chk->copy_by_ref = 0; in sctp_send_cwr()
11726 chk->rec.chunk_id.id = SCTP_ECN_CWR; in sctp_send_cwr()
11727 chk->rec.chunk_id.can_take_data = 1; in sctp_send_cwr()
11728 chk->flags = 0; in sctp_send_cwr()
11729 chk->asoc = asoc; in sctp_send_cwr()
11730 chk->send_size = sizeof(struct sctp_cwr_chunk); in sctp_send_cwr()
11731 chk->data = sctp_get_mbuf_for_msg(chk->send_size, 0, M_NOWAIT, 1, MT_HEADER); in sctp_send_cwr()
11732 if (chk->data == NULL) { in sctp_send_cwr()
11736 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_cwr()
11737 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_cwr()
11738 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_cwr()
11739 chk->snd_count = 0; in sctp_send_cwr()
11740 chk->whoTo = net; in sctp_send_cwr()
11741 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_cwr()
11742 cwr = mtod(chk->data, struct sctp_cwr_chunk *); in sctp_send_cwr()
11743 cwr->ch.chunk_type = SCTP_ECN_CWR; in sctp_send_cwr()
11744 cwr->ch.chunk_flags = override; in sctp_send_cwr()
11745 cwr->ch.chunk_length = htons(sizeof(struct sctp_cwr_chunk)); in sctp_send_cwr()
11746 cwr->tsn = htonl(high_tsn); in sctp_send_cwr()
11747 TAILQ_INSERT_TAIL(&asoc->control_send_queue, chk, sctp_next); in sctp_send_cwr()
11748 asoc->ctrl_queue_cnt++; in sctp_send_cwr()
11761 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_stream_reset_out()
11762 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_stream_reset_out()
11766 for (i = 0; i < stcb->asoc.streamoutcnt; i++) { in sctp_add_stream_reset_out()
11767 if ((stcb->asoc.strmout[i].state == SCTP_STREAM_RESET_PENDING) && in sctp_add_stream_reset_out()
11768 (stcb->asoc.strmout[i].chunks_on_queues == 0) && in sctp_add_stream_reset_out()
11769 TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) { in sctp_add_stream_reset_out()
11776 if (number_entries == stcb->asoc.streamoutcnt) { in sctp_add_stream_reset_out()
11783 req_out->ph.param_type = htons(SCTP_STR_RESET_OUT_REQUEST); in sctp_add_stream_reset_out()
11784 req_out->ph.param_length = htons(len); in sctp_add_stream_reset_out()
11785 req_out->request_seq = htonl(seq); in sctp_add_stream_reset_out()
11786 req_out->response_seq = htonl(resp_seq); in sctp_add_stream_reset_out()
11787 req_out->send_reset_at_tsn = htonl(last_sent); in sctp_add_stream_reset_out()
11790 for (i = 0; i < stcb->asoc.streamoutcnt; i++) { in sctp_add_stream_reset_out()
11791 if ((stcb->asoc.strmout[i].state == SCTP_STREAM_RESET_PENDING) && in sctp_add_stream_reset_out()
11792 (stcb->asoc.strmout[i].chunks_on_queues == 0) && in sctp_add_stream_reset_out()
11793 TAILQ_EMPTY(&stcb->asoc.strmout[i].outqueue)) { in sctp_add_stream_reset_out()
11794 req_out->list_of_streams[at] = htons(i); in sctp_add_stream_reset_out()
11796 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_IN_FLIGHT; in sctp_add_stream_reset_out()
11803 for (i = 0; i < stcb->asoc.streamoutcnt; i++) { in sctp_add_stream_reset_out()
11804 stcb->asoc.strmout[i].state = SCTP_STREAM_RESET_IN_FLIGHT; in sctp_add_stream_reset_out()
11808 /*- in sctp_add_stream_reset_out()
11813 req_out->list_of_streams[number_entries] = 0; in sctp_add_stream_reset_out()
11816 ch->chunk_length = htons(len + old_len); in sctp_add_stream_reset_out()
11817 chk->book_size = len + old_len; in sctp_add_stream_reset_out()
11818 chk->book_size_scale = 0; in sctp_add_stream_reset_out()
11819 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_add_stream_reset_out()
11820 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_add_stream_reset_out()
11833 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_stream_reset_in()
11834 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_stream_reset_in()
11840 req_in->ph.param_type = htons(SCTP_STR_RESET_IN_REQUEST); in sctp_add_stream_reset_in()
11841 req_in->ph.param_length = htons(len); in sctp_add_stream_reset_in()
11842 req_in->request_seq = htonl(seq); in sctp_add_stream_reset_in()
11845 req_in->list_of_streams[i] = htons(list[i]); in sctp_add_stream_reset_in()
11849 /*- in sctp_add_stream_reset_in()
11854 req_in->list_of_streams[number_entries] = 0; in sctp_add_stream_reset_in()
11857 ch->chunk_length = htons(len + old_len); in sctp_add_stream_reset_in()
11858 chk->book_size = len + old_len; in sctp_add_stream_reset_in()
11859 chk->book_size_scale = 0; in sctp_add_stream_reset_in()
11860 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_add_stream_reset_in()
11861 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_add_stream_reset_in()
11873 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_stream_reset_tsn()
11874 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_stream_reset_tsn()
11880 req_tsn->ph.param_type = htons(SCTP_STR_RESET_TSN_REQUEST); in sctp_add_stream_reset_tsn()
11881 req_tsn->ph.param_length = htons(len); in sctp_add_stream_reset_tsn()
11882 req_tsn->request_seq = htonl(seq); in sctp_add_stream_reset_tsn()
11885 ch->chunk_length = htons(len + old_len); in sctp_add_stream_reset_tsn()
11886 chk->send_size = len + old_len; in sctp_add_stream_reset_tsn()
11887 chk->book_size = SCTP_SIZE32(chk->send_size); in sctp_add_stream_reset_tsn()
11888 chk->book_size_scale = 0; in sctp_add_stream_reset_tsn()
11889 SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); in sctp_add_stream_reset_tsn()
11901 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_stream_reset_result()
11902 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_stream_reset_result()
11908 resp->ph.param_type = htons(SCTP_STR_RESET_RESPONSE); in sctp_add_stream_reset_result()
11909 resp->ph.param_length = htons(len); in sctp_add_stream_reset_result()
11910 resp->response_seq = htonl(resp_seq); in sctp_add_stream_reset_result()
11911 resp->result = ntohl(result); in sctp_add_stream_reset_result()
11914 ch->chunk_length = htons(len + old_len); in sctp_add_stream_reset_result()
11915 chk->book_size = len + old_len; in sctp_add_stream_reset_result()
11916 chk->book_size_scale = 0; in sctp_add_stream_reset_result()
11917 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_add_stream_reset_result()
11918 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_add_stream_reset_result()
11931 asoc = &stcb->asoc; in sctp_send_deferred_reset_response()
11934 * Reset our last reset action to the new one IP -> response in sctp_send_deferred_reset_response()
11938 asoc->last_reset_action[0] = response; in sctp_send_deferred_reset_response()
11939 if (asoc->stream_reset_outstanding) { in sctp_send_deferred_reset_response()
11947 chk->copy_by_ref = 0; in sctp_send_deferred_reset_response()
11948 chk->rec.chunk_id.id = SCTP_STREAM_RESET; in sctp_send_deferred_reset_response()
11949 chk->rec.chunk_id.can_take_data = 0; in sctp_send_deferred_reset_response()
11950 chk->flags = 0; in sctp_send_deferred_reset_response()
11951 chk->asoc = &stcb->asoc; in sctp_send_deferred_reset_response()
11952 chk->book_size = sizeof(struct sctp_chunkhdr); in sctp_send_deferred_reset_response()
11953 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_send_deferred_reset_response()
11954 chk->book_size_scale = 0; in sctp_send_deferred_reset_response()
11955 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); in sctp_send_deferred_reset_response()
11956 if (chk->data == NULL) { in sctp_send_deferred_reset_response()
11961 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_deferred_reset_response()
11963 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_deferred_reset_response()
11964 chk->snd_count = 0; in sctp_send_deferred_reset_response()
11965 if (stcb->asoc.alternate) { in sctp_send_deferred_reset_response()
11966 chk->whoTo = stcb->asoc.alternate; in sctp_send_deferred_reset_response()
11968 chk->whoTo = stcb->asoc.primary_destination; in sctp_send_deferred_reset_response()
11970 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_send_deferred_reset_response()
11971 ch->chunk_type = SCTP_STREAM_RESET; in sctp_send_deferred_reset_response()
11972 ch->chunk_flags = 0; in sctp_send_deferred_reset_response()
11973 ch->chunk_length = htons(chk->book_size); in sctp_send_deferred_reset_response()
11974 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_deferred_reset_response()
11975 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_deferred_reset_response()
11976 sctp_add_stream_reset_result(chk, ent->seq, response); in sctp_send_deferred_reset_response()
11978 TAILQ_INSERT_TAIL(&asoc->control_send_queue, in sctp_send_deferred_reset_response()
11981 asoc->ctrl_queue_cnt++; in sctp_send_deferred_reset_response()
11993 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_stream_reset_result_tsn()
11994 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_stream_reset_result_tsn()
12000 resp->ph.param_type = htons(SCTP_STR_RESET_RESPONSE); in sctp_add_stream_reset_result_tsn()
12001 resp->ph.param_length = htons(len); in sctp_add_stream_reset_result_tsn()
12002 resp->response_seq = htonl(resp_seq); in sctp_add_stream_reset_result_tsn()
12003 resp->result = htonl(result); in sctp_add_stream_reset_result_tsn()
12004 resp->senders_next_tsn = htonl(send_una); in sctp_add_stream_reset_result_tsn()
12005 resp->receivers_next_tsn = htonl(recv_next); in sctp_add_stream_reset_result_tsn()
12008 ch->chunk_length = htons(len + old_len); in sctp_add_stream_reset_result_tsn()
12009 chk->book_size = len + old_len; in sctp_add_stream_reset_result_tsn()
12010 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_add_stream_reset_result_tsn()
12011 chk->book_size_scale = 0; in sctp_add_stream_reset_result_tsn()
12012 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_add_stream_reset_result_tsn()
12025 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_an_out_stream()
12026 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_an_out_stream()
12034 addstr->ph.param_type = htons(SCTP_STR_RESET_ADD_OUT_STREAMS); in sctp_add_an_out_stream()
12035 addstr->ph.param_length = htons(len); in sctp_add_an_out_stream()
12036 addstr->request_seq = htonl(seq); in sctp_add_an_out_stream()
12037 addstr->number_of_streams = htons(adding); in sctp_add_an_out_stream()
12038 addstr->reserved = 0; in sctp_add_an_out_stream()
12041 ch->chunk_length = htons(len + old_len); in sctp_add_an_out_stream()
12042 chk->send_size = len + old_len; in sctp_add_an_out_stream()
12043 chk->book_size = SCTP_SIZE32(chk->send_size); in sctp_add_an_out_stream()
12044 chk->book_size_scale = 0; in sctp_add_an_out_stream()
12045 SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); in sctp_add_an_out_stream()
12058 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_add_an_in_stream()
12059 old_len = len = SCTP_SIZE32(ntohs(ch->chunk_length)); in sctp_add_an_in_stream()
12066 addstr->ph.param_type = htons(SCTP_STR_RESET_ADD_IN_STREAMS); in sctp_add_an_in_stream()
12067 addstr->ph.param_length = htons(len); in sctp_add_an_in_stream()
12068 addstr->request_seq = htonl(seq); in sctp_add_an_in_stream()
12069 addstr->number_of_streams = htons(adding); in sctp_add_an_in_stream()
12070 addstr->reserved = 0; in sctp_add_an_in_stream()
12073 ch->chunk_length = htons(len + old_len); in sctp_add_an_in_stream()
12074 chk->send_size = len + old_len; in sctp_add_an_in_stream()
12075 chk->book_size = SCTP_SIZE32(chk->send_size); in sctp_add_an_in_stream()
12076 chk->book_size_scale = 0; in sctp_add_an_in_stream()
12077 SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); in sctp_add_an_in_stream()
12089 asoc = &stcb->asoc; in sctp_send_stream_reset_out_if_possible()
12090 asoc->trigger_reset = 0; in sctp_send_stream_reset_out_if_possible()
12091 if (asoc->stream_reset_outstanding) { in sctp_send_stream_reset_out_if_possible()
12099 chk->copy_by_ref = 0; in sctp_send_stream_reset_out_if_possible()
12100 chk->rec.chunk_id.id = SCTP_STREAM_RESET; in sctp_send_stream_reset_out_if_possible()
12101 chk->rec.chunk_id.can_take_data = 0; in sctp_send_stream_reset_out_if_possible()
12102 chk->flags = 0; in sctp_send_stream_reset_out_if_possible()
12103 chk->asoc = &stcb->asoc; in sctp_send_stream_reset_out_if_possible()
12104 chk->book_size = sizeof(struct sctp_chunkhdr); in sctp_send_stream_reset_out_if_possible()
12105 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_send_stream_reset_out_if_possible()
12106 chk->book_size_scale = 0; in sctp_send_stream_reset_out_if_possible()
12107 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); in sctp_send_stream_reset_out_if_possible()
12108 if (chk->data == NULL) { in sctp_send_stream_reset_out_if_possible()
12113 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_stream_reset_out_if_possible()
12116 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_stream_reset_out_if_possible()
12117 chk->snd_count = 0; in sctp_send_stream_reset_out_if_possible()
12118 if (stcb->asoc.alternate) { in sctp_send_stream_reset_out_if_possible()
12119 chk->whoTo = stcb->asoc.alternate; in sctp_send_stream_reset_out_if_possible()
12121 chk->whoTo = stcb->asoc.primary_destination; in sctp_send_stream_reset_out_if_possible()
12123 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_send_stream_reset_out_if_possible()
12124 ch->chunk_type = SCTP_STREAM_RESET; in sctp_send_stream_reset_out_if_possible()
12125 ch->chunk_flags = 0; in sctp_send_stream_reset_out_if_possible()
12126 ch->chunk_length = htons(chk->book_size); in sctp_send_stream_reset_out_if_possible()
12127 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_stream_reset_out_if_possible()
12128 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_stream_reset_out_if_possible()
12129 seq = stcb->asoc.str_reset_seq_out; in sctp_send_stream_reset_out_if_possible()
12130 … (sctp_add_stream_reset_out(stcb, chk, seq, (stcb->asoc.str_reset_seq_in - 1), (stcb->asoc.sending… in sctp_send_stream_reset_out_if_possible()
12132 asoc->stream_reset_outstanding++; in sctp_send_stream_reset_out_if_possible()
12134 m_freem(chk->data); in sctp_send_stream_reset_out_if_possible()
12135 chk->data = NULL; in sctp_send_stream_reset_out_if_possible()
12139 asoc->str_reset = chk; in sctp_send_stream_reset_out_if_possible()
12141 TAILQ_INSERT_TAIL(&asoc->control_send_queue, in sctp_send_stream_reset_out_if_possible()
12144 asoc->ctrl_queue_cnt++; in sctp_send_stream_reset_out_if_possible()
12146 if (stcb->asoc.send_sack) { in sctp_send_stream_reset_out_if_possible()
12149 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo); in sctp_send_stream_reset_out_if_possible()
12170 asoc = &stcb->asoc; in sctp_send_str_reset_req()
12171 if (asoc->stream_reset_outstanding) { in sctp_send_str_reset_req()
12172 /*- in sctp_send_str_reset_req()
12191 if (number_entries > (MCLBYTES - in sctp_send_str_reset_req()
12192 SCTP_MIN_OVERHEAD - in sctp_send_str_reset_req()
12193 sizeof(struct sctp_chunkhdr) - in sctp_send_str_reset_req()
12204 chk->copy_by_ref = 0; in sctp_send_str_reset_req()
12205 chk->rec.chunk_id.id = SCTP_STREAM_RESET; in sctp_send_str_reset_req()
12206 chk->rec.chunk_id.can_take_data = 0; in sctp_send_str_reset_req()
12207 chk->flags = 0; in sctp_send_str_reset_req()
12208 chk->asoc = &stcb->asoc; in sctp_send_str_reset_req()
12209 chk->book_size = sizeof(struct sctp_chunkhdr); in sctp_send_str_reset_req()
12210 chk->send_size = SCTP_SIZE32(chk->book_size); in sctp_send_str_reset_req()
12211 chk->book_size_scale = 0; in sctp_send_str_reset_req()
12212 chk->data = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); in sctp_send_str_reset_req()
12213 if (chk->data == NULL) { in sctp_send_str_reset_req()
12218 SCTP_BUF_RESV_UF(chk->data, SCTP_MIN_OVERHEAD); in sctp_send_str_reset_req()
12221 chk->sent = SCTP_DATAGRAM_UNSENT; in sctp_send_str_reset_req()
12222 chk->snd_count = 0; in sctp_send_str_reset_req()
12223 if (stcb->asoc.alternate) { in sctp_send_str_reset_req()
12224 chk->whoTo = stcb->asoc.alternate; in sctp_send_str_reset_req()
12226 chk->whoTo = stcb->asoc.primary_destination; in sctp_send_str_reset_req()
12228 atomic_add_int(&chk->whoTo->ref_count, 1); in sctp_send_str_reset_req()
12229 ch = mtod(chk->data, struct sctp_chunkhdr *); in sctp_send_str_reset_req()
12230 ch->chunk_type = SCTP_STREAM_RESET; in sctp_send_str_reset_req()
12231 ch->chunk_flags = 0; in sctp_send_str_reset_req()
12232 ch->chunk_length = htons(chk->book_size); in sctp_send_str_reset_req()
12233 SCTP_BUF_LEN(chk->data) = chk->send_size; in sctp_send_str_reset_req()
12235 seq = stcb->asoc.str_reset_seq_out; in sctp_send_str_reset_req()
12239 …= sctp_add_stream_reset_out(stcb, chk, seq, (stcb->asoc.str_reset_seq_in - 1), (stcb->asoc.sending… in sctp_send_str_reset_req()
12242 asoc->stream_reset_outstanding++; in sctp_send_str_reset_req()
12246 ((stcb->asoc.strm_realoutsize - stcb->asoc.streamoutcnt) < adding_o)) { in sctp_send_str_reset_req()
12255 oldstream = stcb->asoc.strmout; in sctp_send_str_reset_req()
12257 SCTP_MALLOC(stcb->asoc.strmout, struct sctp_stream_out *, in sctp_send_str_reset_req()
12258 (stcb->asoc.streamoutcnt + adding_o) * sizeof(struct sctp_stream_out), in sctp_send_str_reset_req()
12260 if (stcb->asoc.strmout == NULL) { in sctp_send_str_reset_req()
12263 stcb->asoc.strmout = oldstream; in sctp_send_str_reset_req()
12273 stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, false); in sctp_send_str_reset_req()
12274 for (i = 0; i < stcb->asoc.streamoutcnt; i++) { in sctp_send_str_reset_req()
12275 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); in sctp_send_str_reset_req()
12281 stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], &oldstream[i]); in sctp_send_str_reset_req()
12282 stcb->asoc.strmout[i].chunks_on_queues = oldstream[i].chunks_on_queues; in sctp_send_str_reset_req()
12285 stcb->asoc.strmout[i].abandoned_sent[j] = oldstream[i].abandoned_sent[j]; in sctp_send_str_reset_req()
12286 stcb->asoc.strmout[i].abandoned_unsent[j] = oldstream[i].abandoned_unsent[j]; in sctp_send_str_reset_req()
12289 stcb->asoc.strmout[i].abandoned_sent[0] = oldstream[i].abandoned_sent[0]; in sctp_send_str_reset_req()
12290 stcb->asoc.strmout[i].abandoned_unsent[0] = oldstream[i].abandoned_unsent[0]; in sctp_send_str_reset_req()
12292 stcb->asoc.strmout[i].next_mid_ordered = oldstream[i].next_mid_ordered; in sctp_send_str_reset_req()
12293 stcb->asoc.strmout[i].next_mid_unordered = oldstream[i].next_mid_unordered; in sctp_send_str_reset_req()
12294 stcb->asoc.strmout[i].last_msg_incomplete = oldstream[i].last_msg_incomplete; in sctp_send_str_reset_req()
12295 stcb->asoc.strmout[i].sid = i; in sctp_send_str_reset_req()
12296 stcb->asoc.strmout[i].state = oldstream[i].state; in sctp_send_str_reset_req()
12300 TAILQ_INSERT_TAIL(&stcb->asoc.strmout[i].outqueue, sp, next); in sctp_send_str_reset_req()
12304 stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc); in sctp_send_str_reset_req()
12305 for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + adding_o); i++) { in sctp_send_str_reset_req()
12306 TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); in sctp_send_str_reset_req()
12307 stcb->asoc.strmout[i].chunks_on_queues = 0; in sctp_send_str_reset_req()
12310 stcb->asoc.strmout[i].abandoned_sent[j] = 0; in sctp_send_str_reset_req()
12311 stcb->asoc.strmout[i].abandoned_unsent[j] = 0; in sctp_send_str_reset_req()
12314 stcb->asoc.strmout[i].abandoned_sent[0] = 0; in sctp_send_str_reset_req()
12315 stcb->asoc.strmout[i].abandoned_unsent[0] = 0; in sctp_send_str_reset_req()
12317 stcb->asoc.strmout[i].next_mid_ordered = 0; in sctp_send_str_reset_req()
12318 stcb->asoc.strmout[i].next_mid_unordered = 0; in sctp_send_str_reset_req()
12319 stcb->asoc.strmout[i].sid = i; in sctp_send_str_reset_req()
12320 stcb->asoc.strmout[i].last_msg_incomplete = 0; in sctp_send_str_reset_req()
12321 stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], NULL); in sctp_send_str_reset_req()
12322 stcb->asoc.strmout[i].state = SCTP_STREAM_CLOSED; in sctp_send_str_reset_req()
12324 stcb->asoc.strm_realoutsize = stcb->asoc.streamoutcnt + adding_o; in sctp_send_str_reset_req()
12329 asoc->strm_pending_add_size = adding_o; in sctp_send_str_reset_req()
12330 asoc->peer_req_out = peer_asked; in sctp_send_str_reset_req()
12333 asoc->stream_reset_outstanding++; in sctp_send_str_reset_req()
12338 asoc->stream_reset_outstanding++; in sctp_send_str_reset_req()
12343 asoc->stream_reset_outstanding++; in sctp_send_str_reset_req()
12347 asoc->stream_reset_outstanding++; in sctp_send_str_reset_req()
12349 asoc->str_reset = chk; in sctp_send_str_reset_req()
12351 TAILQ_INSERT_TAIL(&asoc->control_send_queue, in sctp_send_str_reset_req()
12354 asoc->ctrl_queue_cnt++; in sctp_send_str_reset_req()
12355 if (stcb->asoc.send_sack) { in sctp_send_str_reset_req()
12358 sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, stcb->sctp_ep, stcb, chk->whoTo); in sctp_send_str_reset_req()
12420 sp->data = m_uiotombuf(uio, M_WAITOK, sp->length, resv_upfront, 0); in sctp_copy_one()
12421 if (sp->data == NULL) { in sctp_copy_one()
12426 sp->tail_mbuf = m_last(sp->data); in sctp_copy_one()
12441 /*- in sctp_copy_it_in()
12458 sp->act_flags = 0; in sctp_copy_it_in()
12459 sp->sender_all_done = 0; in sctp_copy_it_in()
12460 sp->sinfo_flags = srcv->sinfo_flags; in sctp_copy_it_in()
12461 sp->timetolive = srcv->sinfo_timetolive; in sctp_copy_it_in()
12462 sp->ppid = srcv->sinfo_ppid; in sctp_copy_it_in()
12463 sp->context = srcv->sinfo_context; in sctp_copy_it_in()
12464 sp->fsn = 0; in sctp_copy_it_in()
12465 (void)SCTP_GETTIME_TIMEVAL(&sp->ts); in sctp_copy_it_in()
12466 sp->sid = srcv->sinfo_stream; in sctp_copy_it_in()
12467 sp->length = (uint32_t)min(uio->uio_resid, max_send_len); in sctp_copy_it_in()
12468 if ((sp->length == (uint32_t)uio->uio_resid) && in sctp_copy_it_in()
12470 (srcv->sinfo_flags & SCTP_EOF) || in sctp_copy_it_in()
12471 (user_marks_eor && (srcv->sinfo_flags & SCTP_EOR)))) { in sctp_copy_it_in()
12472 sp->msg_is_complete = 1; in sctp_copy_it_in()
12474 sp->msg_is_complete = 0; in sctp_copy_it_in()
12476 sp->sender_all_done = 0; in sctp_copy_it_in()
12477 sp->some_taken = 0; in sctp_copy_it_in()
12478 sp->put_last_out = 0; in sctp_copy_it_in()
12480 sp->data = sp->tail_mbuf = NULL; in sctp_copy_it_in()
12481 if (sp->length == 0) { in sctp_copy_it_in()
12484 if (srcv->sinfo_keynumber_valid) { in sctp_copy_it_in()
12485 sp->auth_keyid = srcv->sinfo_keynumber; in sctp_copy_it_in()
12487 sp->auth_keyid = stcb->asoc.authinfo.active_keyid; in sctp_copy_it_in()
12489 if (sctp_auth_is_required_chunk(SCTP_DATA, stcb->asoc.peer_auth_chunks)) { in sctp_copy_it_in()
12490 sctp_auth_key_acquire(stcb, sp->auth_keyid); in sctp_copy_it_in()
12491 sp->holds_key_ref = 1; in sctp_copy_it_in()
12499 if (sp->sinfo_flags & SCTP_ADDR_OVER) { in sctp_copy_it_in()
12500 sp->net = net; in sctp_copy_it_in()
12501 atomic_add_int(&sp->net->ref_count, 1); in sctp_copy_it_in()
12503 sp->net = NULL; in sctp_copy_it_in()
12529 /* process cmsg snd/rcv info (maybe a assoc-id) */ in sctp_sosend()
12535 if ((addr != NULL) && (addr->sa_family == AF_INET6)) { in sctp_sosend()
12538 if (addr->sa_len != sizeof(struct sockaddr_in6)) { in sctp_sosend()
12543 if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { in sctp_sosend()
12610 switch (raddr->sa.sa_family) { in sctp_lower_sosend()
12613 if (raddr->sin.sin_len != sizeof(struct sockaddr_in)) { in sctp_lower_sosend()
12617 port = raddr->sin.sin_port; in sctp_lower_sosend()
12622 if (raddr->sin6.sin6_len != sizeof(struct sockaddr_in6)) { in sctp_lower_sosend()
12626 port = raddr->sin6.sin6_port; in sctp_lower_sosend()
12637 if (uio->uio_resid < 0) { in sctp_lower_sosend()
12641 sndlen = uio->uio_resid; in sctp_lower_sosend()
12648 t_inp = inp = (struct sctp_inpcb *)so->so_pcb; in sctp_lower_sosend()
12655 /*- in sctp_lower_sosend()
12662 if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) && in sctp_lower_sosend()
12668 atomic_add_int(&inp->total_sends, 1); in sctp_lower_sosend()
12672 sinfo_assoc_id = sndrcvninfo->sinfo_assoc_id; in sctp_lower_sosend()
12673 sinfo_flags = sndrcvninfo->sinfo_flags; in sctp_lower_sosend()
12684 sinfo_flags = inp->def_send.sinfo_flags; in sctp_lower_sosend()
12685 sinfo_assoc_id = inp->def_send.sinfo_assoc_id; in sctp_lower_sosend()
12699 (inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE)) { in sctp_lower_sosend()
12706 if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) || in sctp_lower_sosend()
12707 (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { in sctp_lower_sosend()
12708 stcb = LIST_FIRST(&inp->sctp_asoc_list); in sctp_lower_sosend()
12720 /*- in sctp_lower_sosend()
12749 if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) || in sctp_lower_sosend()
12750 (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE)) { in sctp_lower_sosend()
12754 if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) && in sctp_lower_sosend()
12755 (addr->sa_family == AF_INET6)) { in sctp_lower_sosend()
12796 /*- in sctp_lower_sosend()
12797 * User asks to abort a non-existent assoc, in sctp_lower_sosend()
12798 * or EOF a non-existent assoc with no data in sctp_lower_sosend()
12804 vrf_id = inp->def_vrf_id; in sctp_lower_sosend()
12807 inp->sctp_ep.pre_open_stream_count, in sctp_lower_sosend()
12808 inp->sctp_ep.port, in sctp_lower_sosend()
12825 (void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_entered); in sctp_lower_sosend()
12838 /*- in sctp_lower_sosend()
12851 asoc = &stcb->asoc; in sctp_lower_sosend()
12852 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) || in sctp_lower_sosend()
12853 (asoc->state & SCTP_STATE_WAS_ABORTED)) { in sctp_lower_sosend()
12854 if (asoc->state & SCTP_STATE_WAS_ABORTED) { in sctp_lower_sosend()
12867 atomic_add_int(&asoc->refcnt, 1); in sctp_lower_sosend()
12871 sndrcvninfo_buf = asoc->def_send; in sctp_lower_sosend()
12873 sinfo_flags = sndrcvninfo->sinfo_flags; in sctp_lower_sosend()
12918 max_out = asoc->smallest_mtu - sizeof(struct sctp_paramhdr); in sctp_lower_sosend()
12919 max_out -= sizeof(struct sctp_abort_msg); in sctp_lower_sosend()
12924 ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); in sctp_lower_sosend()
12925 ph->param_length = htons((uint16_t)(sizeof(struct sctp_paramhdr) + tot_out)); in sctp_lower_sosend()
12932 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) || in sctp_lower_sosend()
12933 (asoc->state & SCTP_STATE_WAS_ABORTED)) { in sctp_lower_sosend()
12935 if (asoc->state & SCTP_STATE_WAS_ABORTED) { in sctp_lower_sosend()
12947 /*- in sctp_lower_sosend()
12950 * send the users note :-0 in sctp_lower_sosend()
12961 atomic_subtract_int(&asoc->refcnt, 1); in sctp_lower_sosend()
12965 sctp_abort_an_association(stcb->sctp_ep, stcb, mm, false, SCTP_SO_LOCKED); in sctp_lower_sosend()
12981 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
12983 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
12993 ((port != 0) && (port != stcb->rport))) { in sctp_lower_sosend()
12998 if (asoc->alternate != NULL) { in sctp_lower_sosend()
12999 net = asoc->alternate; in sctp_lower_sosend()
13001 net = asoc->primary_destination; in sctp_lower_sosend()
13014 if (sndlen > (ssize_t)asoc->smallest_mtu) { in sctp_lower_sosend()
13019 sinfo_stream = sndrcvninfo->sinfo_stream; in sctp_lower_sosend()
13021 if (sinfo_stream >= asoc->streamoutcnt) { in sctp_lower_sosend()
13026 if ((asoc->strmout[sinfo_stream].state != SCTP_STREAM_OPEN) && in sctp_lower_sosend()
13027 (asoc->strmout[sinfo_stream].state != SCTP_STREAM_OPENING)) { in sctp_lower_sosend()
13031 if (asoc->strmout[sinfo_stream].state > SCTP_STREAM_OPEN) { in sctp_lower_sosend()
13038 atomic_add_int(&stcb->total_sends, 1); in sctp_lower_sosend()
13045 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13051 if ((SCTP_SB_LIMIT_SND(so) < (amount + inqueue_bytes + asoc->sb_send_resv)) || in sctp_lower_sosend()
13052 (asoc->chunks_on_out_queue >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue))) { in sctp_lower_sosend()
13062 atomic_add_int(&asoc->sb_send_resv, (int)sndlen); in sctp_lower_sosend()
13067 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13069 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13074 p->td_ru.ru_msgsnd++; in sctp_lower_sosend()
13077 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13079 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; in sctp_lower_sosend()
13085 (sndlen > (ssize_t)SCTP_SB_LIMIT_SND(stcb->sctp_socket))) { in sctp_lower_sosend()
13093 /*- in sctp_lower_sosend()
13094 * For non-eeor the whole message must fit in in sctp_lower_sosend()
13104 …((asoc->chunks_on_out_queue + asoc->stream_queue_cnt) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue… in sctp_lower_sosend()
13106 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13107 SOCKBUF_LOCK(&so->so_snd); in sctp_lower_sosend()
13109 …((asoc->stream_queue_cnt + asoc->chunks_on_out_queue) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue… in sctp_lower_sosend()
13114 asoc->stream_queue_cnt, in sctp_lower_sosend()
13115 asoc->chunks_on_out_queue, in sctp_lower_sosend()
13121 stcb->block_entry = &be; in sctp_lower_sosend()
13125 if (so->so_error != 0) { in sctp_lower_sosend()
13126 error = so->so_error; in sctp_lower_sosend()
13132 SOCKBUF_UNLOCK(&so->so_snd); in sctp_lower_sosend()
13134 stcb->block_entry = NULL; in sctp_lower_sosend()
13138 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) || in sctp_lower_sosend()
13139 (asoc->state & SCTP_STATE_WAS_ABORTED)) { in sctp_lower_sosend()
13140 if (asoc->state & SCTP_STATE_WAS_ABORTED) { in sctp_lower_sosend()
13153 asoc, asoc->total_output_queue_size); in sctp_lower_sosend()
13155 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13156 SOCKBUF_LOCK(&so->so_snd); in sctp_lower_sosend()
13159 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; in sctp_lower_sosend()
13163 SOCKBUF_UNLOCK(&so->so_snd); in sctp_lower_sosend()
13169 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13171 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13175 * sndlen covers for mbuf case uio_resid covers for the non-mbuf in sctp_lower_sosend()
13183 if ((asoc->stream_locked) && in sctp_lower_sosend()
13184 (asoc->stream_locked_on != sinfo_stream)) { in sctp_lower_sosend()
13188 strm = &asoc->strmout[sinfo_stream]; in sctp_lower_sosend()
13189 if (strm->last_msg_incomplete == 0) { in sctp_lower_sosend()
13194 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) || in sctp_lower_sosend()
13195 (asoc->state & SCTP_STATE_WAS_ABORTED)) { in sctp_lower_sosend()
13196 if (asoc->state & SCTP_STATE_WAS_ABORTED) { in sctp_lower_sosend()
13217 (asoc->state & SCTP_STATE_SHUTDOWN_PENDING)) { in sctp_lower_sosend()
13218 if (sp->data != 0) { in sctp_lower_sosend()
13219 sctp_m_freem(sp->data); in sctp_lower_sosend()
13220 sp->data = NULL; in sctp_lower_sosend()
13221 sp->tail_mbuf = NULL; in sctp_lower_sosend()
13222 sp->length = 0; in sctp_lower_sosend()
13224 if (sp->net != NULL) { in sctp_lower_sosend()
13225 sctp_free_remote_addr(sp->net); in sctp_lower_sosend()
13226 sp->net = NULL; in sctp_lower_sosend()
13233 strm = &asoc->strmout[sinfo_stream]; in sctp_lower_sosend()
13234 if (sp->msg_is_complete) { in sctp_lower_sosend()
13235 strm->last_msg_incomplete = 0; in sctp_lower_sosend()
13236 asoc->stream_locked = 0; in sctp_lower_sosend()
13242 strm->last_msg_incomplete = 1; in sctp_lower_sosend()
13243 if (asoc->idata_supported == 0) { in sctp_lower_sosend()
13244 asoc->stream_locked = 1; in sctp_lower_sosend()
13245 asoc->stream_locked_on = sinfo_stream; in sctp_lower_sosend()
13247 sp->sender_all_done = 0; in sctp_lower_sosend()
13249 sctp_snd_sb_alloc(stcb, sp->length); in sctp_lower_sosend()
13250 atomic_add_int(&asoc->stream_queue_cnt, 1); in sctp_lower_sosend()
13254 sp->processing = 1; in sctp_lower_sosend()
13255 TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); in sctp_lower_sosend()
13256 asoc->ss_functions.sctp_ss_add_to_stream(stcb, asoc, strm, sp); in sctp_lower_sosend()
13258 sp = TAILQ_LAST(&strm->outqueue, sctp_streamhead); in sctp_lower_sosend()
13265 strm->last_msg_incomplete = 0; in sctp_lower_sosend()
13269 if (sp->processing != 0) { in sctp_lower_sosend()
13273 sp->processing = 1; in sctp_lower_sosend()
13279 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13281 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13284 while (uio->uio_resid > 0) { in sctp_lower_sosend()
13288 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13290 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; in sctp_lower_sosend()
13296 (uio->uio_resid <= max_len)) { in sctp_lower_sosend()
13302 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) || in sctp_lower_sosend()
13303 (asoc->state & SCTP_STATE_WAS_ABORTED)) { in sctp_lower_sosend()
13309 if (asoc->state & SCTP_STATE_WAS_ABORTED) { in sctp_lower_sosend()
13326 sp->processing = 0; in sctp_lower_sosend()
13331 if (sp->tail_mbuf != NULL) { in sctp_lower_sosend()
13333 SCTP_BUF_NEXT(sp->tail_mbuf) = mm; in sctp_lower_sosend()
13336 sp->data = mm; in sctp_lower_sosend()
13338 sp->tail_mbuf = new_tail; in sctp_lower_sosend()
13340 atomic_add_int(&sp->length, sndout); in sctp_lower_sosend()
13342 sp->sinfo_flags |= SCTP_SACK_IMMEDIATELY; in sctp_lower_sosend()
13346 if ((uio->uio_resid == 0) && in sctp_lower_sosend()
13350 sp->msg_is_complete = 1; in sctp_lower_sosend()
13352 sp->msg_is_complete = 0; in sctp_lower_sosend()
13358 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13360 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13363 if (uio->uio_resid == 0) { in sctp_lower_sosend()
13367 /* PR-SCTP? */ in sctp_lower_sosend()
13368 if ((asoc->prsctp_supported) && (asoc->sent_queue_cnt_removeable > 0)) { in sctp_lower_sosend()
13374 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13376 max_len = SCTP_SB_LIMIT_SND(so) - inqueue_bytes; in sctp_lower_sosend()
13385 /* Non-blocking io in place out */ in sctp_lower_sosend()
13387 sp->processing = 0; in sctp_lower_sosend()
13404 if ((net->flight_size > net->cwnd) && in sctp_lower_sosend()
13405 (asoc->sctp_cmt_on_off == 0)) { in sctp_lower_sosend()
13408 } else if (asoc->ifp_had_enobuf) { in sctp_lower_sosend()
13410 if (net->flight_size > (2 * net->mtu)) { in sctp_lower_sosend()
13413 asoc->ifp_had_enobuf = 0; in sctp_lower_sosend()
13415 un_sent = asoc->total_output_queue_size - asoc->total_flight; in sctp_lower_sosend()
13417 (asoc->total_flight > 0) && in sctp_lower_sosend()
13418 (asoc->stream_queue_cnt < SCTP_MAX_DATA_BUNDLING) && in sctp_lower_sosend()
13419 (un_sent < (int)(asoc->smallest_mtu - SCTP_MIN_OVERHEAD))) { in sctp_lower_sosend()
13420 /*- in sctp_lower_sosend()
13441 sctp_misc_ints(SCTP_CWNDLOG_PRESEND, asoc->total_output_queue_size, in sctp_lower_sosend()
13442 asoc->total_flight, in sctp_lower_sosend()
13443 asoc->chunks_on_out_queue, asoc->total_flight_count); in sctp_lower_sosend()
13449 /*- in sctp_lower_sosend()
13454 * and I don't need to start output :-D in sctp_lower_sosend()
13461 /*- in sctp_lower_sosend()
13470 * LOCK the so->so_snd to do the actual sowwakeup(). So in sctp_lower_sosend()
13475 …inqueue_bytes = asoc->total_output_queue_size - (asoc->chunks_on_out_queue * SCTP_DATA_CHUNK_OVERH… in sctp_lower_sosend()
13476 SOCKBUF_LOCK(&so->so_snd); in sctp_lower_sosend()
13481 asoc, uio->uio_resid); in sctp_lower_sosend()
13484 stcb->block_entry = &be; in sctp_lower_sosend()
13488 if (so->so_error != 0) in sctp_lower_sosend()
13489 error = so->so_error; in sctp_lower_sosend()
13494 SOCKBUF_UNLOCK(&so->so_snd); in sctp_lower_sosend()
13496 stcb->block_entry = NULL; in sctp_lower_sosend()
13497 if ((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) || in sctp_lower_sosend()
13498 (asoc->state & SCTP_STATE_WAS_ABORTED)) { in sctp_lower_sosend()
13499 if (asoc->state & SCTP_STATE_WAS_ABORTED) { in sctp_lower_sosend()
13513 sp->processing = 0; in sctp_lower_sosend()
13518 SOCKBUF_UNLOCK(&so->so_snd); in sctp_lower_sosend()
13522 asoc, asoc->total_output_queue_size); in sctp_lower_sosend()
13528 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13530 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13534 strm = &asoc->strmout[sinfo_stream]; in sctp_lower_sosend()
13536 if (sp->msg_is_complete == 0) { in sctp_lower_sosend()
13537 strm->last_msg_incomplete = 1; in sctp_lower_sosend()
13538 if (asoc->idata_supported == 0) { in sctp_lower_sosend()
13539 asoc->stream_locked = 1; in sctp_lower_sosend()
13540 asoc->stream_locked_on = sinfo_stream; in sctp_lower_sosend()
13543 sp->sender_all_done = 1; in sctp_lower_sosend()
13544 strm->last_msg_incomplete = 0; in sctp_lower_sosend()
13545 asoc->stream_locked = 0; in sctp_lower_sosend()
13547 sp->processing = 0; in sctp_lower_sosend()
13550 strm->last_msg_incomplete = 0; in sctp_lower_sosend()
13551 asoc->stream_locked = 0; in sctp_lower_sosend()
13553 if (uio->uio_resid == 0) { in sctp_lower_sosend()
13570 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13572 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13579 if (TAILQ_EMPTY(&asoc->send_queue) && in sctp_lower_sosend()
13580 TAILQ_EMPTY(&asoc->sent_queue) && in sctp_lower_sosend()
13582 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) { in sctp_lower_sosend()
13597 if (asoc->alternate != NULL) { in sctp_lower_sosend()
13598 netp = asoc->alternate; in sctp_lower_sosend()
13600 netp = asoc->primary_destination; in sctp_lower_sosend()
13603 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, stcb->sctp_ep, stcb, in sctp_lower_sosend()
13605 sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, in sctp_lower_sosend()
13609 /*- in sctp_lower_sosend()
13613 /*- in sctp_lower_sosend()
13617 * SHUTDOWN-PENDING in sctp_lower_sosend()
13622 if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) { in sctp_lower_sosend()
13626 if (TAILQ_EMPTY(&asoc->send_queue) && in sctp_lower_sosend()
13627 TAILQ_EMPTY(&asoc->sent_queue) && in sctp_lower_sosend()
13628 (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) { in sctp_lower_sosend()
13634 atomic_subtract_int(&asoc->refcnt, 1); in sctp_lower_sosend()
13642 sctp_abort_an_association(stcb->sctp_ep, stcb, in sctp_lower_sosend()
13657 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13659 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13662 some_on_control = !TAILQ_EMPTY(&asoc->control_send_queue); in sctp_lower_sosend()
13678 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13680 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13683 if ((net->flight_size > net->cwnd) && in sctp_lower_sosend()
13684 (asoc->sctp_cmt_on_off == 0)) { in sctp_lower_sosend()
13687 } else if (asoc->ifp_had_enobuf) { in sctp_lower_sosend()
13689 if (net->flight_size > (2 * net->mtu)) { in sctp_lower_sosend()
13692 asoc->ifp_had_enobuf = 0; in sctp_lower_sosend()
13694 un_sent = asoc->total_output_queue_size - asoc->total_flight; in sctp_lower_sosend()
13696 (asoc->total_flight > 0) && in sctp_lower_sosend()
13697 (asoc->stream_queue_cnt < SCTP_MAX_DATA_BUNDLING) && in sctp_lower_sosend()
13698 (un_sent < (int)(asoc->smallest_mtu - SCTP_MIN_OVERHEAD))) { in sctp_lower_sosend()
13699 /*- in sctp_lower_sosend()
13720 sctp_misc_ints(SCTP_CWNDLOG_PRESEND, asoc->total_output_queue_size, in sctp_lower_sosend()
13721 asoc->total_flight, in sctp_lower_sosend()
13722 asoc->chunks_on_out_queue, asoc->total_flight_count); in sctp_lower_sosend()
13727 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13729 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13733 if ((queue_only == 0) && (nagle_applies == 0) && (asoc->peers_rwnd && un_sent)) { in sctp_lower_sosend()
13736 (asoc->peers_rwnd == 0) && in sctp_lower_sosend()
13737 (asoc->total_flight == 0)) { in sctp_lower_sosend()
13751 queue_only, asoc->peers_rwnd, un_sent, in sctp_lower_sosend()
13752 asoc->total_flight, asoc->chunks_on_out_queue, in sctp_lower_sosend()
13753 asoc->total_output_queue_size, error); in sctp_lower_sosend()
13757 KASSERT((asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0, in sctp_lower_sosend()
13759 KASSERT((asoc->state & SCTP_STATE_WAS_ABORTED) == 0, in sctp_lower_sosend()
13769 atomic_subtract_int(&asoc->sb_send_resv, (int)sndlen); in sctp_lower_sosend()
13772 atomic_subtract_int(&asoc->refcnt, 1); in sctp_lower_sosend()
13803 if (stcb->asoc.auth_supported == 0) { in sctp_add_auth_chunk()
13807 if (!sctp_auth_is_required_chunk(chunk, stcb->asoc.peer_auth_chunks)) { in sctp_add_auth_chunk()
13821 auth->ch.chunk_type = SCTP_AUTHENTICATION; in sctp_add_auth_chunk()
13822 auth->ch.chunk_flags = 0; in sctp_add_auth_chunk()
13824 sctp_get_hmac_digest_len(stcb->asoc.peer_hmac_id); in sctp_add_auth_chunk()
13825 auth->ch.chunk_length = htons(chunk_len); in sctp_add_auth_chunk()
13826 auth->hmac_id = htons(stcb->asoc.peer_hmac_id); in sctp_add_auth_chunk()
13852 if (ro == NULL || ro->ro_nh == NULL || src6->sin6_family != AF_INET6) in sctp_v6src_match_nexthop()
13858 if (pfx->ndpr_stateflags & NDPRF_DETACHED) in sctp_v6src_match_nexthop()
13860 if (IN6_ARE_MASKED_ADDR_EQUAL(&pfx->ndpr_prefix.sin6_addr, in sctp_v6src_match_nexthop()
13861 &src6->sin6_addr, &pfx->ndpr_mask)) in sctp_v6src_match_nexthop()
13876 LIST_FOREACH(pfxrtr, &pfx->ndpr_advrtrs, pfr_entry) { in sctp_v6src_match_nexthop()
13880 memcpy(&gw6.sin6_addr, &pfxrtr->router->rtaddr, in sctp_v6src_match_nexthop()
13885 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ro->ro_nh->gw_sa); in sctp_v6src_match_nexthop()
13886 if (sctp_cmpaddr((struct sockaddr *)&gw6, &ro->ro_nh->gw_sa)) { in sctp_v6src_match_nexthop()
13906 if (ro == NULL || ro->ro_nh == NULL || in sctp_v4src_match_nexthop()
13907 sifa->address.sa.sa_family != AF_INET) { in sctp_v4src_match_nexthop()
13910 ifa = (struct ifaddr *)sifa->ifa; in sctp_v4src_match_nexthop()
13911 mask = (struct sockaddr_in *)(ifa->ifa_netmask); in sctp_v4src_match_nexthop()
13912 sin = &sifa->address.sin; in sctp_v4src_match_nexthop()
13913 srcnetaddr.s_addr = (sin->sin_addr.s_addr & mask->sin_addr.s_addr); in sctp_v4src_match_nexthop()
13915 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &sifa->address.sa); in sctp_v4src_match_nexthop()
13918 sin = &ro->ro_nh->gw4_sa; in sctp_v4src_match_nexthop()
13919 gwnetaddr.s_addr = (sin->sin_addr.s_addr & mask->sin_addr.s_addr); in sctp_v4src_match_nexthop()
13921 SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT2, &ro->ro_nh->gw_sa); in sctp_v4src_match_nexthop()