Lines Matching +full:assoc +full:- +full:select

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 1999-2000 Cisco, Inc.
5 * Copyright (c) 1999-2001 Motorola, Inc.
15 * lksctp developers <linux-sctp@vger.kernel.org>
65 asoc->ep = (struct sctp_endpoint *)ep; in sctp_association_init()
66 asoc->base.sk = (struct sock *)sk; in sctp_association_init()
67 asoc->base.net = sock_net(sk); in sctp_association_init()
69 sctp_endpoint_hold(asoc->ep); in sctp_association_init()
70 sock_hold(asoc->base.sk); in sctp_association_init()
73 asoc->base.type = SCTP_EP_TYPE_ASSOCIATION; in sctp_association_init()
76 refcount_set(&asoc->base.refcnt, 1); in sctp_association_init()
79 sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port); in sctp_association_init()
81 asoc->state = SCTP_STATE_CLOSED; in sctp_association_init()
82 asoc->cookie_life = ms_to_ktime(sp->assocparams.sasoc_cookie_life); in sctp_association_init()
83 asoc->user_frag = sp->user_frag; in sctp_association_init()
88 asoc->max_retrans = sp->assocparams.sasoc_asocmaxrxt; in sctp_association_init()
89 asoc->pf_retrans = sp->pf_retrans; in sctp_association_init()
90 asoc->ps_retrans = sp->ps_retrans; in sctp_association_init()
91 asoc->pf_expose = sp->pf_expose; in sctp_association_init()
93 asoc->rto_initial = msecs_to_jiffies(sp->rtoinfo.srto_initial); in sctp_association_init()
94 asoc->rto_max = msecs_to_jiffies(sp->rtoinfo.srto_max); in sctp_association_init()
95 asoc->rto_min = msecs_to_jiffies(sp->rtoinfo.srto_min); in sctp_association_init()
100 asoc->hbinterval = msecs_to_jiffies(sp->hbinterval); in sctp_association_init()
103 asoc->pathmaxrxt = sp->pathmaxrxt; in sctp_association_init()
105 asoc->flowlabel = sp->flowlabel; in sctp_association_init()
106 asoc->dscp = sp->dscp; in sctp_association_init()
109 asoc->sackdelay = msecs_to_jiffies(sp->sackdelay); in sctp_association_init()
110 asoc->sackfreq = sp->sackfreq; in sctp_association_init()
115 asoc->param_flags = sp->param_flags; in sctp_association_init()
120 asoc->max_burst = sp->max_burst; in sctp_association_init()
122 asoc->subscribe = sp->subscribe; in sctp_association_init()
125 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial; in sctp_association_init()
126 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = asoc->rto_initial; in sctp_association_init()
127 asoc->timeouts[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = asoc->rto_initial; in sctp_association_init()
130 * If the 'T5-shutdown-guard' timer is used, it SHOULD be set to the in sctp_association_init()
133 asoc->timeouts[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD] in sctp_association_init()
134 = 5 * asoc->rto_max; in sctp_association_init()
136 asoc->timeouts[SCTP_EVENT_TIMEOUT_SACK] = asoc->sackdelay; in sctp_association_init()
137 asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = sp->autoclose * HZ; in sctp_association_init()
141 timer_setup(&asoc->timers[i], sctp_timer_events[i], 0); in sctp_association_init()
147 asoc->c.sinit_max_instreams = sp->initmsg.sinit_max_instreams; in sctp_association_init()
148 asoc->c.sinit_num_ostreams = sp->initmsg.sinit_num_ostreams; in sctp_association_init()
149 asoc->max_init_attempts = sp->initmsg.sinit_max_attempts; in sctp_association_init()
151 asoc->max_init_timeo = in sctp_association_init()
152 msecs_to_jiffies(sp->initmsg.sinit_max_init_timeo); in sctp_association_init()
156 * RFC 6 - A SCTP receiver MUST be able to receive a minimum of in sctp_association_init()
159 if ((sk->sk_rcvbuf/2) < SCTP_DEFAULT_MINWINDOW) in sctp_association_init()
160 asoc->rwnd = SCTP_DEFAULT_MINWINDOW; in sctp_association_init()
162 asoc->rwnd = sk->sk_rcvbuf/2; in sctp_association_init()
164 asoc->a_rwnd = asoc->rwnd; in sctp_association_init()
167 asoc->peer.rwnd = SCTP_DEFAULT_MAXWINDOW; in sctp_association_init()
170 atomic_set(&asoc->rmem_alloc, 0); in sctp_association_init()
172 init_waitqueue_head(&asoc->wait); in sctp_association_init()
174 asoc->c.my_vtag = sctp_generate_tag(ep); in sctp_association_init()
175 asoc->c.my_port = ep->base.bind_addr.port; in sctp_association_init()
177 asoc->c.initial_tsn = sctp_generate_tsn(ep); in sctp_association_init()
179 asoc->next_tsn = asoc->c.initial_tsn; in sctp_association_init()
181 asoc->ctsn_ack_point = asoc->next_tsn - 1; in sctp_association_init()
182 asoc->adv_peer_ack_point = asoc->ctsn_ack_point; in sctp_association_init()
183 asoc->highest_sacked = asoc->ctsn_ack_point; in sctp_association_init()
184 asoc->last_cwr_tsn = asoc->ctsn_ack_point; in sctp_association_init()
196 asoc->addip_serial = asoc->c.initial_tsn; in sctp_association_init()
197 asoc->strreset_outseq = asoc->c.initial_tsn; in sctp_association_init()
199 INIT_LIST_HEAD(&asoc->addip_chunk_list); in sctp_association_init()
200 INIT_LIST_HEAD(&asoc->asconf_ack_list); in sctp_association_init()
203 INIT_LIST_HEAD(&asoc->peer.transport_addr_list); in sctp_association_init()
216 asoc->peer.sack_needed = 1; in sctp_association_init()
217 asoc->peer.sack_generation = 1; in sctp_association_init()
220 sctp_inq_init(&asoc->base.inqueue); in sctp_association_init()
221 sctp_inq_set_th_handler(&asoc->base.inqueue, sctp_assoc_bh_rcv); in sctp_association_init()
224 sctp_outq_init(asoc, &asoc->outqueue); in sctp_association_init()
226 if (!sctp_ulpq_init(&asoc->ulpq, asoc)) in sctp_association_init()
229 if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams, in sctp_association_init()
234 asoc->pathmtu = sp->pathmtu; in sctp_association_init()
240 asoc->peer.ipv4_address = 1; in sctp_association_init()
241 if (asoc->base.sk->sk_family == PF_INET6) in sctp_association_init()
242 asoc->peer.ipv6_address = 1; in sctp_association_init()
243 INIT_LIST_HEAD(&asoc->asocs); in sctp_association_init()
245 asoc->default_stream = sp->default_stream; in sctp_association_init()
246 asoc->default_ppid = sp->default_ppid; in sctp_association_init()
247 asoc->default_flags = sp->default_flags; in sctp_association_init()
248 asoc->default_context = sp->default_context; in sctp_association_init()
249 asoc->default_timetolive = sp->default_timetolive; in sctp_association_init()
250 asoc->default_rcv_context = sp->default_rcv_context; in sctp_association_init()
253 INIT_LIST_HEAD(&asoc->endpoint_shared_keys); in sctp_association_init()
257 asoc->active_key_id = ep->active_key_id; in sctp_association_init()
258 asoc->strreset_enable = ep->strreset_enable; in sctp_association_init()
261 if (ep->auth_hmacs_list) in sctp_association_init()
262 memcpy(asoc->c.auth_hmacs, ep->auth_hmacs_list, in sctp_association_init()
263 ntohs(ep->auth_hmacs_list->param_hdr.length)); in sctp_association_init()
264 if (ep->auth_chunk_list) in sctp_association_init()
265 memcpy(asoc->c.auth_chunks, ep->auth_chunk_list, in sctp_association_init()
266 ntohs(ep->auth_chunk_list->param_hdr.length)); in sctp_association_init()
269 p = (struct sctp_paramhdr *)asoc->c.auth_random; in sctp_association_init()
270 p->type = SCTP_PARAM_RANDOM; in sctp_association_init()
271 p->length = htons(sizeof(*p) + SCTP_AUTH_RANDOM_LENGTH); in sctp_association_init()
277 sctp_stream_free(&asoc->stream); in sctp_association_init()
279 sock_put(asoc->base.sk); in sctp_association_init()
280 sctp_endpoint_put(asoc->ep); in sctp_association_init()
298 SCTP_DBG_OBJCNT_INC(assoc); in sctp_association_new()
315 struct sock *sk = asoc->base.sk; in sctp_association_free()
323 if (!list_empty(&asoc->asocs)) { in sctp_association_free()
324 list_del(&asoc->asocs); in sctp_association_free()
326 /* Decrement the backlog value for a TCP-style listening in sctp_association_free()
336 asoc->base.dead = true; in sctp_association_free()
339 sctp_outq_free(&asoc->outqueue); in sctp_association_free()
342 sctp_ulpq_free(&asoc->ulpq); in sctp_association_free()
345 sctp_inq_free(&asoc->base.inqueue); in sctp_association_free()
347 sctp_tsnmap_free(&asoc->peer.tsn_map); in sctp_association_free()
350 sctp_stream_free(&asoc->stream); in sctp_association_free()
352 if (asoc->strreset_chunk) in sctp_association_free()
353 sctp_chunk_free(asoc->strreset_chunk); in sctp_association_free()
356 sctp_bind_addr_free(&asoc->base.bind_addr); in sctp_association_free()
364 if (del_timer(&asoc->timers[i])) in sctp_association_free()
369 kfree(asoc->peer.cookie); in sctp_association_free()
370 kfree(asoc->peer.peer_random); in sctp_association_free()
371 kfree(asoc->peer.peer_chunks); in sctp_association_free()
372 kfree(asoc->peer.peer_hmacs); in sctp_association_free()
375 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { in sctp_association_free()
382 asoc->peer.transport_count = 0; in sctp_association_free()
387 kfree(asoc->asconf_addr_del_pending); in sctp_association_free()
389 /* AUTH - Free the endpoint shared keys */ in sctp_association_free()
390 sctp_auth_destroy_keys(&asoc->endpoint_shared_keys); in sctp_association_free()
392 /* AUTH - Free the association shared key */ in sctp_association_free()
393 sctp_auth_key_put(asoc->asoc_shared_key); in sctp_association_free()
401 if (unlikely(!asoc->base.dead)) { in sctp_association_destroy()
406 sctp_endpoint_put(asoc->ep); in sctp_association_destroy()
407 sock_put(asoc->base.sk); in sctp_association_destroy()
409 if (asoc->assoc_id != 0) { in sctp_association_destroy()
411 idr_remove(&sctp_assocs_id, asoc->assoc_id); in sctp_association_destroy()
415 WARN_ON(atomic_read(&asoc->rmem_alloc)); in sctp_association_destroy()
418 SCTP_DBG_OBJCNT_DEC(assoc); in sctp_association_destroy()
430 if (asoc->peer.primary_path != NULL && in sctp_assoc_set_primary()
431 asoc->peer.primary_path != transport) in sctp_assoc_set_primary()
434 asoc->peer.primary_path = transport; in sctp_assoc_set_primary()
439 memcpy(&asoc->peer.primary_addr, &transport->ipaddr, in sctp_assoc_set_primary()
445 if ((transport->state == SCTP_ACTIVE) || in sctp_assoc_set_primary()
446 (transport->state == SCTP_UNKNOWN)) in sctp_assoc_set_primary()
447 asoc->peer.active_path = transport; in sctp_assoc_set_primary()
450 * SFR-CACC algorithm: in sctp_assoc_set_primary()
463 if (!asoc->outqueue.outstanding_bytes && !asoc->outqueue.out_qlen) in sctp_assoc_set_primary()
466 if (transport->cacc.changeover_active) in sctp_assoc_set_primary()
467 transport->cacc.cycling_changeover = changeover; in sctp_assoc_set_primary()
472 transport->cacc.changeover_active = changeover; in sctp_assoc_set_primary()
477 transport->cacc.next_tsn_at_change = asoc->next_tsn; in sctp_assoc_set_primary()
489 __func__, asoc, &peer->ipaddr.sa); in sctp_assoc_rm_peer()
494 if (asoc->peer.retran_path == peer) in sctp_assoc_rm_peer()
498 list_del_rcu(&peer->transports); in sctp_assoc_rm_peer()
503 pos = asoc->peer.transport_addr_list.next; in sctp_assoc_rm_peer()
507 if (asoc->peer.primary_path == peer) in sctp_assoc_rm_peer()
509 if (asoc->peer.active_path == peer) in sctp_assoc_rm_peer()
510 asoc->peer.active_path = transport; in sctp_assoc_rm_peer()
511 if (asoc->peer.retran_path == peer) in sctp_assoc_rm_peer()
512 asoc->peer.retran_path = transport; in sctp_assoc_rm_peer()
513 if (asoc->peer.last_data_from == peer) in sctp_assoc_rm_peer()
514 asoc->peer.last_data_from = transport; in sctp_assoc_rm_peer()
516 if (asoc->strreset_chunk && in sctp_assoc_rm_peer()
517 asoc->strreset_chunk->transport == peer) { in sctp_assoc_rm_peer()
518 asoc->strreset_chunk->transport = transport; in sctp_assoc_rm_peer()
527 if (asoc->init_last_sent_to == peer) in sctp_assoc_rm_peer()
528 asoc->init_last_sent_to = NULL; in sctp_assoc_rm_peer()
535 if (asoc->shutdown_last_sent_to == peer) in sctp_assoc_rm_peer()
536 asoc->shutdown_last_sent_to = NULL; in sctp_assoc_rm_peer()
541 if (asoc->addip_last_asconf && in sctp_assoc_rm_peer()
542 asoc->addip_last_asconf->transport == peer) in sctp_assoc_rm_peer()
543 asoc->addip_last_asconf->transport = NULL; in sctp_assoc_rm_peer()
548 if (!list_empty(&peer->transmitted)) { in sctp_assoc_rm_peer()
549 struct sctp_transport *active = asoc->peer.active_path; in sctp_assoc_rm_peer()
552 list_for_each_entry(ch, &peer->transmitted, in sctp_assoc_rm_peer()
554 ch->transport = NULL; in sctp_assoc_rm_peer()
555 ch->rtt_in_progress = 0; in sctp_assoc_rm_peer()
558 list_splice_tail_init(&peer->transmitted, in sctp_assoc_rm_peer()
559 &active->transmitted); in sctp_assoc_rm_peer()
565 if (!timer_pending(&active->T3_rtx_timer)) in sctp_assoc_rm_peer()
566 if (!mod_timer(&active->T3_rtx_timer, in sctp_assoc_rm_peer()
567 jiffies + active->rto)) in sctp_assoc_rm_peer()
571 list_for_each_entry(ch, &asoc->outqueue.out_chunk_list, list) in sctp_assoc_rm_peer()
572 if (ch->transport == peer) in sctp_assoc_rm_peer()
573 ch->transport = NULL; in sctp_assoc_rm_peer()
575 asoc->peer.transport_count--; in sctp_assoc_rm_peer()
591 sp = sctp_sk(asoc->base.sk); in sctp_assoc_add_peer()
594 port = ntohs(addr->v4.sin_port); in sctp_assoc_add_peer()
597 asoc, &addr->sa, peer_state); in sctp_assoc_add_peer()
600 if (0 == asoc->peer.port) in sctp_assoc_add_peer()
601 asoc->peer.port = port; in sctp_assoc_add_peer()
610 if (peer->state == SCTP_UNKNOWN) { in sctp_assoc_add_peer()
611 peer->state = SCTP_ACTIVE; in sctp_assoc_add_peer()
616 peer = sctp_transport_new(asoc->base.net, addr, gfp); in sctp_assoc_add_peer()
625 peer->hbinterval = asoc->hbinterval; in sctp_assoc_add_peer()
628 peer->pathmaxrxt = asoc->pathmaxrxt; in sctp_assoc_add_peer()
631 peer->pf_retrans = asoc->pf_retrans; in sctp_assoc_add_peer()
633 peer->ps_retrans = asoc->ps_retrans; in sctp_assoc_add_peer()
638 peer->sackdelay = asoc->sackdelay; in sctp_assoc_add_peer()
639 peer->sackfreq = asoc->sackfreq; in sctp_assoc_add_peer()
641 if (addr->sa.sa_family == AF_INET6) { in sctp_assoc_add_peer()
642 __be32 info = addr->v6.sin6_flowinfo; in sctp_assoc_add_peer()
645 peer->flowlabel = ntohl(info & IPV6_FLOWLABEL_MASK); in sctp_assoc_add_peer()
646 peer->flowlabel |= SCTP_FLOWLABEL_SET_MASK; in sctp_assoc_add_peer()
648 peer->flowlabel = asoc->flowlabel; in sctp_assoc_add_peer()
651 peer->dscp = asoc->dscp; in sctp_assoc_add_peer()
656 peer->param_flags = asoc->param_flags; in sctp_assoc_add_peer()
666 sctp_assoc_set_pmtu(asoc, asoc->pathmtu ? in sctp_assoc_add_peer()
667 min_t(int, peer->pathmtu, asoc->pathmtu) : in sctp_assoc_add_peer()
668 peer->pathmtu); in sctp_assoc_add_peer()
670 peer->pmtu_pending = 0; in sctp_assoc_add_peer()
672 /* The asoc->peer.port might not be meaningful yet, but in sctp_assoc_add_peer()
675 sctp_packet_init(&peer->packet, peer, asoc->base.bind_addr.port, in sctp_assoc_add_peer()
676 asoc->peer.port); in sctp_assoc_add_peer()
678 /* 7.2.1 Slow-Start in sctp_assoc_add_peer()
688 peer->cwnd = min(4*asoc->pathmtu, max_t(__u32, 2*asoc->pathmtu, 4380)); in sctp_assoc_add_peer()
694 peer->ssthresh = SCTP_DEFAULT_MAXWINDOW; in sctp_assoc_add_peer()
696 peer->partial_bytes_acked = 0; in sctp_assoc_add_peer()
697 peer->flight_size = 0; in sctp_assoc_add_peer()
698 peer->burst_limited = 0; in sctp_assoc_add_peer()
701 peer->rto = asoc->rto_initial; in sctp_assoc_add_peer()
705 peer->state = peer_state; in sctp_assoc_add_peer()
714 list_add_tail_rcu(&peer->transports, &asoc->peer.transport_addr_list); in sctp_assoc_add_peer()
715 asoc->peer.transport_count++; in sctp_assoc_add_peer()
720 if (!asoc->peer.primary_path) { in sctp_assoc_add_peer()
722 asoc->peer.retran_path = peer; in sctp_assoc_add_peer()
725 if (asoc->peer.active_path == asoc->peer.retran_path && in sctp_assoc_add_peer()
726 peer->state != SCTP_UNCONFIRMED) { in sctp_assoc_add_peer()
727 asoc->peer.retran_path = peer; in sctp_assoc_add_peer()
741 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { in sctp_assoc_del_peer()
743 if (sctp_cmp_addr_exact(addr, &transport->ipaddr)) { in sctp_assoc_del_peer()
760 list_for_each_entry(t, &asoc->peer.transport_addr_list, in sctp_assoc_lookup_paddr()
762 if (sctp_cmp_addr_exact(address, &t->ipaddr)) in sctp_assoc_lookup_paddr()
776 list_for_each_entry_safe(t, temp, &asoc->peer.transport_addr_list, in sctp_assoc_del_nonprimary_peers()
786 * Select and update the new active and retran paths.
803 if (transport->state == SCTP_PF && in sctp_assoc_control_transport()
804 asoc->pf_expose != SCTP_PF_EXPOSE_ENABLE) in sctp_assoc_control_transport()
806 else if (transport->state == SCTP_UNCONFIRMED && in sctp_assoc_control_transport()
810 transport->state = SCTP_ACTIVE; in sctp_assoc_control_transport()
818 if (transport->state != SCTP_UNCONFIRMED) { in sctp_assoc_control_transport()
819 transport->state = SCTP_INACTIVE; in sctp_assoc_control_transport()
828 transport->state = SCTP_PF; in sctp_assoc_control_transport()
829 if (asoc->pf_expose != SCTP_PF_EXPOSE_ENABLE) in sctp_assoc_control_transport()
846 /* Select new active and retran paths. */ in sctp_assoc_control_transport()
853 refcount_inc(&asoc->base.refcnt); in sctp_association_hold()
861 if (refcount_dec_and_test(&asoc->base.refcnt)) in sctp_association_put()
872 * 2**32 - 1. That is, the next TSN a DATA chunk MUST use in sctp_association_get_next_tsn()
873 * after transmitting TSN = 2*32 - 1 is TSN = 0. in sctp_association_get_next_tsn()
875 __u32 retval = asoc->next_tsn; in sctp_association_get_next_tsn()
876 asoc->next_tsn++; in sctp_association_get_next_tsn()
877 asoc->unack_data++; in sctp_association_get_next_tsn()
890 af = sctp_get_af_specific(ss1->sa.sa_family); in sctp_cmp_addr_exact()
894 return af->cmp_addr(ss1, ss2); in sctp_cmp_addr_exact()
903 if (!asoc->need_ecne) in sctp_get_ecne_prepend()
909 return sctp_make_ecne(asoc, asoc->last_ecne_tsn); in sctp_get_ecne_prepend()
941 active = asoc->peer.active_path; in sctp_assoc_lookup_tsn()
943 list_for_each_entry(chunk, &active->transmitted, in sctp_assoc_lookup_tsn()
946 if (key == chunk->subh.data_hdr->tsn) { in sctp_assoc_lookup_tsn()
953 list_for_each_entry(transport, &asoc->peer.transport_addr_list, in sctp_assoc_lookup_tsn()
958 list_for_each_entry(chunk, &transport->transmitted, in sctp_assoc_lookup_tsn()
960 if (key == chunk->subh.data_hdr->tsn) { in sctp_assoc_lookup_tsn()
976 struct net *net = asoc->base.net; in sctp_assoc_bh_rcv()
986 ep = asoc->ep; in sctp_assoc_bh_rcv()
988 inqueue = &asoc->base.inqueue; in sctp_assoc_bh_rcv()
991 state = asoc->state; in sctp_assoc_bh_rcv()
992 subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type); in sctp_assoc_bh_rcv()
995 * processing specified in Section 6.3 of SCTP-AUTH spec in sctp_assoc_bh_rcv()
1004 /* If the next chunk is COOKIE-ECHO, skip the AUTH in sctp_assoc_bh_rcv()
1006 * Authentication later (during cookie-echo in sctp_assoc_bh_rcv()
1009 if (next_hdr->type == SCTP_CID_COOKIE_ECHO) { in sctp_assoc_bh_rcv()
1010 chunk->auth_chunk = skb_clone(chunk->skb, in sctp_assoc_bh_rcv()
1012 chunk->auth = 1; in sctp_assoc_bh_rcv()
1018 /* SCTP-AUTH, Section 6.3: in sctp_assoc_bh_rcv()
1020 * to be received only after an AUTH-chunk. This list has in sctp_assoc_bh_rcv()
1025 if (sctp_auth_recv_cid(subtype.chunk, asoc) && !chunk->auth) in sctp_assoc_bh_rcv()
1032 asoc->peer.last_data_from = chunk->transport; in sctp_assoc_bh_rcv()
1035 asoc->stats.ictrlchunks++; in sctp_assoc_bh_rcv()
1036 if (chunk->chunk_hdr->type == SCTP_CID_SACK) in sctp_assoc_bh_rcv()
1037 asoc->stats.isacks++; in sctp_assoc_bh_rcv()
1040 if (chunk->transport) in sctp_assoc_bh_rcv()
1041 chunk->transport->last_time_heard = ktime_get(); in sctp_assoc_bh_rcv()
1050 if (asoc->base.dead) in sctp_assoc_bh_rcv()
1055 chunk->pdiscard = 1; in sctp_assoc_bh_rcv()
1064 void sctp_assoc_migrate(struct sctp_association *assoc, struct sock *newsk) in sctp_assoc_migrate() argument
1067 struct sock *oldsk = assoc->base.sk; in sctp_assoc_migrate()
1072 list_del_init(&assoc->asocs); in sctp_assoc_migrate()
1074 /* Decrement the backlog value for a TCP-style socket. */ in sctp_assoc_migrate()
1079 sctp_endpoint_put(assoc->ep); in sctp_assoc_migrate()
1080 sock_put(assoc->base.sk); in sctp_assoc_migrate()
1083 assoc->ep = newsp->ep; in sctp_assoc_migrate()
1084 sctp_endpoint_hold(assoc->ep); in sctp_assoc_migrate()
1087 assoc->base.sk = newsk; in sctp_assoc_migrate()
1088 sock_hold(assoc->base.sk); in sctp_assoc_migrate()
1091 sctp_endpoint_add_asoc(newsp->ep, assoc); in sctp_assoc_migrate()
1094 /* Update an association (possibly from unexpected COOKIE-ECHO processing). */
1102 asoc->c = new->c; in sctp_assoc_update()
1103 asoc->peer.rwnd = new->peer.rwnd; in sctp_assoc_update()
1104 asoc->peer.sack_needed = new->peer.sack_needed; in sctp_assoc_update()
1105 asoc->peer.auth_capable = new->peer.auth_capable; in sctp_assoc_update()
1106 asoc->peer.i = new->peer.i; in sctp_assoc_update()
1108 if (!sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL, in sctp_assoc_update()
1109 asoc->peer.i.initial_tsn, GFP_ATOMIC)) in sctp_assoc_update()
1110 return -ENOMEM; in sctp_assoc_update()
1113 list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) { in sctp_assoc_update()
1115 if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr)) { in sctp_assoc_update()
1120 if (asoc->state >= SCTP_STATE_ESTABLISHED) in sctp_assoc_update()
1129 if (asoc->state >= SCTP_STATE_ESTABLISHED) { in sctp_assoc_update()
1130 asoc->next_tsn = new->next_tsn; in sctp_assoc_update()
1131 asoc->ctsn_ack_point = new->ctsn_ack_point; in sctp_assoc_update()
1132 asoc->adv_peer_ack_point = new->adv_peer_ack_point; in sctp_assoc_update()
1137 sctp_stream_clear(&asoc->stream); in sctp_assoc_update()
1143 sctp_ulpq_flush(&asoc->ulpq); in sctp_assoc_update()
1149 asoc->overall_error_count = 0; in sctp_assoc_update()
1153 list_for_each_entry(trans, &new->peer.transport_addr_list, in sctp_assoc_update()
1155 if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr) && in sctp_assoc_update()
1156 !sctp_assoc_add_peer(asoc, &trans->ipaddr, in sctp_assoc_update()
1157 GFP_ATOMIC, trans->state)) in sctp_assoc_update()
1158 return -ENOMEM; in sctp_assoc_update()
1160 asoc->ctsn_ack_point = asoc->next_tsn - 1; in sctp_assoc_update()
1161 asoc->adv_peer_ack_point = asoc->ctsn_ack_point; in sctp_assoc_update()
1164 sctp_stream_update(&asoc->stream, &new->stream); in sctp_assoc_update()
1166 /* get a new assoc id if we don't have one yet. */ in sctp_assoc_update()
1168 return -ENOMEM; in sctp_assoc_update()
1171 /* SCTP-AUTH: Save the peer parameters from the new associations in sctp_assoc_update()
1174 kfree(asoc->peer.peer_random); in sctp_assoc_update()
1175 asoc->peer.peer_random = new->peer.peer_random; in sctp_assoc_update()
1176 new->peer.peer_random = NULL; in sctp_assoc_update()
1178 kfree(asoc->peer.peer_chunks); in sctp_assoc_update()
1179 asoc->peer.peer_chunks = new->peer.peer_chunks; in sctp_assoc_update()
1180 new->peer.peer_chunks = NULL; in sctp_assoc_update()
1182 kfree(asoc->peer.peer_hmacs); in sctp_assoc_update()
1183 asoc->peer.peer_hmacs = new->peer.peer_hmacs; in sctp_assoc_update()
1184 new->peer.peer_hmacs = NULL; in sctp_assoc_update()
1190 * See also RFC4960, 6.4. Multi-Homed SCTP Endpoints:
1201 * is multihomed, it should consider each source-destination
1203 * When retransmitting timed-out data, the endpoint should
1204 * attempt to pick the most divergent source-destination
1205 * pair from the original source-destination pair to which
1208 * Note: Rules for picking the most divergent source-destination
1212 * Our basic strategy is to round-robin transports in priorities
1214 * transport with state SCTP_ACTIVE exists, round-robin through
1219 switch (trans->state) { in sctp_trans_score()
1234 if (trans1->error_count > trans2->error_count) { in sctp_trans_elect_tie()
1236 } else if (trans1->error_count == trans2->error_count && in sctp_trans_elect_tie()
1237 ktime_after(trans2->last_time_heard, in sctp_trans_elect_tie()
1238 trans1->last_time_heard)) { in sctp_trans_elect_tie()
1256 /* First, try a score-based selection if both transport states in sctp_trans_elect_best()
1270 struct sctp_transport *trans = asoc->peer.retran_path; in sctp_assoc_update_retran_path()
1274 if (asoc->peer.transport_count == 1) in sctp_assoc_update_retran_path()
1279 if (asoc->peer.active_path == asoc->peer.retran_path && in sctp_assoc_update_retran_path()
1280 asoc->peer.active_path->state == SCTP_ACTIVE) in sctp_assoc_update_retran_path()
1287 if (&trans->transports == &asoc->peer.transport_addr_list) in sctp_assoc_update_retran_path()
1289 if (trans->state == SCTP_UNCONFIRMED) in sctp_assoc_update_retran_path()
1293 if (trans_next->state == SCTP_ACTIVE) in sctp_assoc_update_retran_path()
1296 if (trans == asoc->peer.retran_path) in sctp_assoc_update_retran_path()
1300 asoc->peer.retran_path = trans_next; in sctp_assoc_update_retran_path()
1303 __func__, asoc, &asoc->peer.retran_path->ipaddr.sa); in sctp_assoc_update_retran_path()
1312 list_for_each_entry(trans, &asoc->peer.transport_addr_list, in sctp_select_active_and_retran_path()
1315 if (trans->state == SCTP_INACTIVE || in sctp_select_active_and_retran_path()
1316 trans->state == SCTP_UNCONFIRMED) in sctp_select_active_and_retran_path()
1321 if (trans->state == SCTP_PF) { in sctp_select_active_and_retran_path()
1327 ktime_after(trans->last_time_heard, in sctp_select_active_and_retran_path()
1328 trans_pri->last_time_heard)) { in sctp_select_active_and_retran_path()
1332 ktime_after(trans->last_time_heard, in sctp_select_active_and_retran_path()
1333 trans_sec->last_time_heard)) { in sctp_select_active_and_retran_path()
1338 /* RFC 2960 6.4 Multi-Homed SCTP Endpoints in sctp_select_active_and_retran_path()
1346 if ((asoc->peer.primary_path->state == SCTP_ACTIVE || in sctp_select_active_and_retran_path()
1347 asoc->peer.primary_path->state == SCTP_UNKNOWN) && in sctp_select_active_and_retran_path()
1348 asoc->peer.primary_path != trans_pri) { in sctp_select_active_and_retran_path()
1350 trans_pri = asoc->peer.primary_path; in sctp_select_active_and_retran_path()
1364 trans_pri = sctp_trans_elect_best(asoc->peer.active_path, trans_pf); in sctp_select_active_and_retran_path()
1369 asoc->peer.active_path = trans_pri; in sctp_select_active_and_retran_path()
1370 asoc->peer.retran_path = trans_sec; in sctp_select_active_and_retran_path()
1382 return asoc->peer.active_path; in sctp_assoc_choose_alter_transport()
1384 if (last_sent_to == asoc->peer.retran_path) in sctp_assoc_choose_alter_transport()
1387 return asoc->peer.retran_path; in sctp_assoc_choose_alter_transport()
1393 int frag = sctp_mtu_payload(sctp_sk(asoc->base.sk), asoc->pathmtu, in sctp_assoc_update_frag_point()
1394 sctp_datachk_len(&asoc->stream)); in sctp_assoc_update_frag_point()
1396 if (asoc->user_frag) in sctp_assoc_update_frag_point()
1397 frag = min_t(int, frag, asoc->user_frag); in sctp_assoc_update_frag_point()
1399 frag = min_t(int, frag, SCTP_MAX_CHUNK_LEN - in sctp_assoc_update_frag_point()
1400 sctp_datachk_len(&asoc->stream)); in sctp_assoc_update_frag_point()
1402 asoc->frag_point = SCTP_TRUNC4(frag); in sctp_assoc_update_frag_point()
1407 if (asoc->pathmtu != pmtu) { in sctp_assoc_set_pmtu()
1408 asoc->pathmtu = pmtu; in sctp_assoc_set_pmtu()
1413 asoc->pathmtu, asoc->frag_point); in sctp_assoc_set_pmtu()
1428 list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) { in sctp_assoc_sync_pmtu()
1429 if (t->pmtu_pending && t->dst) { in sctp_assoc_sync_pmtu()
1431 atomic_read(&t->mtu_info)); in sctp_assoc_sync_pmtu()
1432 t->pmtu_pending = 0; in sctp_assoc_sync_pmtu()
1434 if (!pmtu || (t->pathmtu < pmtu)) in sctp_assoc_sync_pmtu()
1435 pmtu = t->pathmtu; in sctp_assoc_sync_pmtu()
1444 struct net *net = asoc->base.net; in sctp_peer_needs_update()
1446 switch (asoc->state) { in sctp_peer_needs_update()
1451 if ((asoc->rwnd > asoc->a_rwnd) && in sctp_peer_needs_update()
1452 ((asoc->rwnd - asoc->a_rwnd) >= max_t(__u32, in sctp_peer_needs_update()
1453 (asoc->base.sk->sk_rcvbuf >> net->sctp.rwnd_upd_shift), in sctp_peer_needs_update()
1454 asoc->pathmtu))) in sctp_peer_needs_update()
1469 if (asoc->rwnd_over) { in sctp_assoc_rwnd_increase()
1470 if (asoc->rwnd_over >= len) { in sctp_assoc_rwnd_increase()
1471 asoc->rwnd_over -= len; in sctp_assoc_rwnd_increase()
1473 asoc->rwnd += (len - asoc->rwnd_over); in sctp_assoc_rwnd_increase()
1474 asoc->rwnd_over = 0; in sctp_assoc_rwnd_increase()
1477 asoc->rwnd += len; in sctp_assoc_rwnd_increase()
1485 if (asoc->rwnd_press) { in sctp_assoc_rwnd_increase()
1486 int change = min(asoc->pathmtu, asoc->rwnd_press); in sctp_assoc_rwnd_increase()
1487 asoc->rwnd += change; in sctp_assoc_rwnd_increase()
1488 asoc->rwnd_press -= change; in sctp_assoc_rwnd_increase()
1491 pr_debug("%s: asoc:%p rwnd increased by %d to (%u, %u) - %u\n", in sctp_assoc_rwnd_increase()
1492 __func__, asoc, len, asoc->rwnd, asoc->rwnd_over, in sctp_assoc_rwnd_increase()
1493 asoc->a_rwnd); in sctp_assoc_rwnd_increase()
1501 asoc->a_rwnd = asoc->rwnd; in sctp_assoc_rwnd_increase()
1503 pr_debug("%s: sending window update SACK- asoc:%p rwnd:%u " in sctp_assoc_rwnd_increase()
1504 "a_rwnd:%u\n", __func__, asoc, asoc->rwnd, in sctp_assoc_rwnd_increase()
1505 asoc->a_rwnd); in sctp_assoc_rwnd_increase()
1511 asoc->peer.sack_needed = 0; in sctp_assoc_rwnd_increase()
1513 sctp_outq_tail(&asoc->outqueue, sack, GFP_ATOMIC); in sctp_assoc_rwnd_increase()
1516 timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK]; in sctp_assoc_rwnd_increase()
1528 if (unlikely(!asoc->rwnd || asoc->rwnd_over)) in sctp_assoc_rwnd_decrease()
1529 pr_debug("%s: association:%p has asoc->rwnd:%u, " in sctp_assoc_rwnd_decrease()
1530 "asoc->rwnd_over:%u!\n", __func__, asoc, in sctp_assoc_rwnd_decrease()
1531 asoc->rwnd, asoc->rwnd_over); in sctp_assoc_rwnd_decrease()
1533 if (asoc->ep->rcvbuf_policy) in sctp_assoc_rwnd_decrease()
1534 rx_count = atomic_read(&asoc->rmem_alloc); in sctp_assoc_rwnd_decrease()
1536 rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc); in sctp_assoc_rwnd_decrease()
1543 if (rx_count >= asoc->base.sk->sk_rcvbuf) in sctp_assoc_rwnd_decrease()
1546 if (asoc->rwnd >= len) { in sctp_assoc_rwnd_decrease()
1547 asoc->rwnd -= len; in sctp_assoc_rwnd_decrease()
1549 asoc->rwnd_press += asoc->rwnd; in sctp_assoc_rwnd_decrease()
1550 asoc->rwnd = 0; in sctp_assoc_rwnd_decrease()
1553 asoc->rwnd_over += len - asoc->rwnd; in sctp_assoc_rwnd_decrease()
1554 asoc->rwnd = 0; in sctp_assoc_rwnd_decrease()
1558 __func__, asoc, len, asoc->rwnd, asoc->rwnd_over, in sctp_assoc_rwnd_decrease()
1559 asoc->rwnd_press); in sctp_assoc_rwnd_decrease()
1568 struct sock *sk = asoc->base.sk; in sctp_assoc_set_bind_addr_from_ep()
1574 flags = (PF_INET6 == sk->sk_family) ? SCTP_ADDR6_ALLOWED : 0; in sctp_assoc_set_bind_addr_from_ep()
1577 if (asoc->peer.ipv4_address) in sctp_assoc_set_bind_addr_from_ep()
1579 if (asoc->peer.ipv6_address) in sctp_assoc_set_bind_addr_from_ep()
1582 return sctp_bind_addr_copy(asoc->base.net, in sctp_assoc_set_bind_addr_from_ep()
1583 &asoc->base.bind_addr, in sctp_assoc_set_bind_addr_from_ep()
1584 &asoc->ep->base.bind_addr, in sctp_assoc_set_bind_addr_from_ep()
1593 int var_size2 = ntohs(cookie->peer_init->chunk_hdr.length); in sctp_assoc_set_bind_addr_from_cookie()
1594 int var_size3 = cookie->raw_addr_list_len; in sctp_assoc_set_bind_addr_from_cookie()
1595 __u8 *raw = (__u8 *)cookie->peer_init + var_size2; in sctp_assoc_set_bind_addr_from_cookie()
1597 return sctp_raw_to_bind_addrs(&asoc->base.bind_addr, raw, var_size3, in sctp_assoc_set_bind_addr_from_cookie()
1598 asoc->ep->base.bind_addr.port, gfp); in sctp_assoc_set_bind_addr_from_cookie()
1607 if ((asoc->base.bind_addr.port == ntohs(laddr->v4.sin_port)) && in sctp_assoc_lookup_laddr()
1608 sctp_bind_addr_match(&asoc->base.bind_addr, laddr, in sctp_assoc_lookup_laddr()
1609 sctp_sk(asoc->base.sk))) in sctp_assoc_lookup_laddr()
1622 if (asoc->assoc_id) in sctp_assoc_set_id()
1639 asoc->assoc_id = (sctp_assoc_t)ret; in sctp_assoc_set_id()
1649 list_for_each_entry_safe(asconf, tmp, &asoc->addip_chunk_list, list) { in sctp_assoc_free_asconf_queue()
1650 list_del_init(&asconf->list); in sctp_assoc_free_asconf_queue()
1661 list_for_each_entry_safe(ack, tmp, &asoc->asconf_ack_list, in sctp_assoc_free_asconf_acks()
1663 list_del_init(&ack->transmitted_list); in sctp_assoc_free_asconf_acks()
1675 * the "Peer-Sequence-Number". in sctp_assoc_clean_asconf_ack_cache()
1677 list_for_each_entry_safe(ack, tmp, &asoc->asconf_ack_list, in sctp_assoc_clean_asconf_ack_cache()
1679 if (ack->subh.addip_hdr->serial == in sctp_assoc_clean_asconf_ack_cache()
1680 htonl(asoc->peer.addip_serial)) in sctp_assoc_clean_asconf_ack_cache()
1683 list_del_init(&ack->transmitted_list); in sctp_assoc_clean_asconf_ack_cache()
1695 /* Walk through the list of cached ASCONF-ACKs and find the in sctp_assoc_lookup_asconf_ack()
1698 list_for_each_entry(ack, &asoc->asconf_ack_list, transmitted_list) { in sctp_assoc_lookup_asconf_ack()
1701 if (ack->subh.addip_hdr->serial == serial) { in sctp_assoc_lookup_asconf_ack()
1719 if (asoc->addip_last_asconf) in sctp_asconf_queue_teardown()
1720 sctp_chunk_free(asoc->addip_last_asconf); in sctp_asconf_queue_teardown()