/* Set the association max_retrans and RTO values from the *socketvalues.
*/
asoc->max_retrans = sp->assocparams.sasoc_asocmaxrxt;
asoc->pf_retrans = sp->pf_retrans;
asoc->ps_retrans = sp->ps_retrans;
asoc->pf_expose = sp->pf_expose;
/* Initialize the association's heartbeat interval based on the *sockconfiguredvalue.
*/
asoc->hbinterval = msecs_to_jiffies(sp->hbinterval);
asoc->probe_interval = msecs_to_jiffies(sp->probe_interval);
asoc->encap_port = sp->encap_port;
/* Initialize path max retrans value. */
asoc->pathmaxrxt = sp->pathmaxrxt;
/* Initializes the timers */ for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i)
timer_setup(&asoc->timers[i], sctp_timer_events[i], 0);
/* Set the local window size for receive. *Thisisalsothercvbufspaceperassociation. *RFC6-ASCTPreceiverMUSTbeabletoreceiveaminimumof *1500bytesinoneSCTPpacket.
*/ if ((sk->sk_rcvbuf/2) < SCTP_DEFAULT_MINWINDOW)
asoc->rwnd = SCTP_DEFAULT_MINWINDOW; else
asoc->rwnd = sk->sk_rcvbuf/2;
asoc->a_rwnd = asoc->rwnd;
/* Use my own max window until I learn something better. */
asoc->peer.rwnd = SCTP_DEFAULT_MAXWINDOW;
/* Initialize the receive memory counter */
atomic_set(&asoc->rmem_alloc, 0);
/* Assume that peer would support both address types unless we are *toldotherwise.
*/
asoc->peer.ipv4_address = 1; if (asoc->base.sk->sk_family == PF_INET6)
asoc->peer.ipv6_address = 1;
INIT_LIST_HEAD(&asoc->asocs);
/* Save the hmacs and chunks list into this association */ if (ep->auth_hmacs_list)
memcpy(asoc->c.auth_hmacs, ep->auth_hmacs_list,
ntohs(ep->auth_hmacs_list->param_hdr.length)); if (ep->auth_chunk_list)
memcpy(asoc->c.auth_chunks, ep->auth_chunk_list,
ntohs(ep->auth_chunk_list->param_hdr.length));
/* Get the AUTH random number for this association */
p = (struct sctp_paramhdr *)asoc->c.auth_random;
p->type = SCTP_PARAM_RANDOM;
p->length = htons(sizeof(*p) + SCTP_AUTH_RANDOM_LENGTH);
get_random_bytes(p+1, SCTP_AUTH_RANDOM_LENGTH);
/* Allocate and initialize a new association */ struct sctp_association *sctp_association_new(conststruct sctp_endpoint *ep, conststruct sock *sk, enum sctp_scope scope, gfp_t gfp)
{ struct sctp_association *asoc;
asoc = kzalloc(sizeof(*asoc), gfp); if (!asoc) goto fail;
if (!sctp_association_init(asoc, ep, sk, scope, gfp)) goto fail_init;
SCTP_DBG_OBJCNT_INC(assoc);
pr_debug("Created asoc %p\n", asoc);
return asoc;
fail_init:
kfree(asoc);
fail: return NULL;
}
/* Free this association if possible. There may still be users, so *theactualdeallocationmaybedelayed.
*/ void sctp_association_free(struct sctp_association *asoc)
{ struct sock *sk = asoc->base.sk; struct sctp_transport *transport; struct list_head *pos, *temp; int i;
/* Only real associations count against the endpoint, so *don'tbotherforifthisisatemporaryassociation.
*/ if (!list_empty(&asoc->asocs)) {
list_del(&asoc->asocs);
/* Decrement the backlog value for a TCP-style listening *socket.
*/ if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
sk_acceptq_removed(sk);
}
/* Mark as dead, so other users can know this structure is *goingaway.
*/
asoc->base.dead = true;
/* Dispose of any data lying around in the outqueue. */
sctp_outq_free(&asoc->outqueue);
/* Dispose of any pending messages for the upper layer. */
sctp_ulpq_free(&asoc->ulpq);
/* Dispose of any pending chunks on the inqueue. */
sctp_inq_free(&asoc->base.inqueue);
if (asoc->strreset_chunk)
sctp_chunk_free(asoc->strreset_chunk);
/* Clean up the bound address list. */
sctp_bind_addr_free(&asoc->base.bind_addr);
/* Do we need to go through all of our timers and *deletethem?Tobesafewewilltrytodeleteall,butwe *shouldbeabletogothroughandmakeaguessbased *onourstate.
*/ for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i) { if (timer_delete(&asoc->timers[i]))
sctp_association_put(asoc);
}
/* Release the transport structures. */
list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
transport = list_entry(pos, struct sctp_transport, transports);
list_del_rcu(pos);
sctp_unhash_transport(transport);
sctp_transport_free(transport);
}
asoc->peer.transport_count = 0;
sctp_asconf_queue_teardown(asoc);
/* Free pending address space being deleted */
kfree(asoc->asconf_addr_del_pending);
/* AUTH - Free the endpoint shared keys */
sctp_auth_destroy_keys(&asoc->endpoint_shared_keys);
/* AUTH - Free the association shared key */
sctp_auth_key_put(asoc->asoc_shared_key);
sctp_association_put(asoc);
}
/* Cleanup and free up an association. */ staticvoid sctp_association_destroy(struct sctp_association *asoc)
{ if (unlikely(!asoc->base.dead)) {
WARN(1, "Attempt to destroy undead association %p!\n", asoc); return;
}
/* Change the primary destination address for the peer. */ void sctp_assoc_set_primary(struct sctp_association *asoc, struct sctp_transport *transport)
{ int changeover = 0;
/* it's a changeover only if we already have a primary path *thatwearechanging
*/ if (asoc->peer.primary_path != NULL &&
asoc->peer.primary_path != transport)
changeover = 1 ;
/* Set a default msg_name for events. */
memcpy(&asoc->peer.primary_addr, &transport->ipaddr, sizeof(union sctp_addr));
/* If the primary path is changing, assume that the *userwantstousethisnewpath.
*/ if ((transport->state == SCTP_ACTIVE) ||
(transport->state == SCTP_UNKNOWN))
asoc->peer.active_path = transport;
/* If we are to remove the current retran_path, update it *tothenextpeerbeforeremovingthispeerfromthelist.
*/ if (asoc->peer.retran_path == peer)
sctp_assoc_update_retran_path(asoc);
/* Remove this peer from the list. */
list_del_rcu(&peer->transports); /* Remove this peer from the transport hashtable */
sctp_unhash_transport(peer);
/* Get the first transport of asoc. */
pos = asoc->peer.transport_addr_list.next;
transport = list_entry(pos, struct sctp_transport, transports);
/* Update any entries that match the peer to be deleted. */ if (asoc->peer.primary_path == peer)
sctp_assoc_set_primary(asoc, transport); if (asoc->peer.active_path == peer)
asoc->peer.active_path = transport; if (asoc->peer.retran_path == peer)
asoc->peer.retran_path = transport; if (asoc->peer.last_data_from == peer)
asoc->peer.last_data_from = transport;
/* If we remove the transport an INIT was last sent to, set it to *NULL.Combinedwiththeupdateoftheretranpathabove,this *willcausethenextINITtobesenttothenextavailable *transport,maintainingthecycle.
*/ if (asoc->init_last_sent_to == peer)
asoc->init_last_sent_to = NULL;
/* If we remove the transport an SHUTDOWN was last sent to, set it *toNULL.Combinedwiththeupdateoftheretranpathabove,this *willcausethenextSHUTDOWNtobesenttothenextavailable *transport,maintainingthecycle.
*/ if (asoc->shutdown_last_sent_to == peer)
asoc->shutdown_last_sent_to = NULL;
/* If we remove the transport an ASCONF was last sent to, set it to *NULL.
*/ if (asoc->addip_last_asconf &&
asoc->addip_last_asconf->transport == peer)
asoc->addip_last_asconf->transport = NULL;
/* If we have something on the transmitted list, we have to *saveitoff.Thebestplaceistheactivepath.
*/ if (!list_empty(&peer->transmitted)) { struct sctp_transport *active = asoc->peer.active_path;
/* Reset the transport of each chunk on this list */
list_for_each_entry(ch, &peer->transmitted,
transmitted_list) {
ch->transport = NULL;
ch->rtt_in_progress = 0;
}
/* Start a T3 timer here in case it wasn't running so *thatthesemigratedpacketshaveachancetoget *retransmitted.
*/ if (!timer_pending(&active->T3_rtx_timer)) if (!mod_timer(&active->T3_rtx_timer,
jiffies + active->rto))
sctp_transport_hold(active);
}
list_for_each_entry(ch, &asoc->outqueue.out_chunk_list, list) if (ch->transport == peer)
ch->transport = NULL;
/* Set the port if it has not been set yet. */ if (0 == asoc->peer.port)
asoc->peer.port = port;
/* Check to see if this is a duplicate. */
peer = sctp_assoc_lookup_paddr(asoc, addr); if (peer) { /* An UNKNOWN state is only set on transports added by *userinsctp_connectx()call.Suchtransportsshouldbe *consideredCONFIRMEDperRFC4960,Section5.4.
*/ if (peer->state == SCTP_UNKNOWN) {
peer->state = SCTP_ACTIVE;
} return peer;
}
peer = sctp_transport_new(asoc->base.net, addr, gfp); if (!peer) return NULL;
sctp_transport_set_owner(peer, asoc);
/* Initialize the peer's heartbeat interval based on the *associationconfiguredvalue.
*/
peer->hbinterval = asoc->hbinterval;
peer->probe_interval = asoc->probe_interval;
peer->encap_port = asoc->encap_port;
/* Set the path max_retrans. */
peer->pathmaxrxt = asoc->pathmaxrxt;
/* And the partial failure retrans threshold */
peer->pf_retrans = asoc->pf_retrans; /* And the primary path switchover retrans threshold */
peer->ps_retrans = asoc->ps_retrans;
/* Initialize the peer's SACK delay timeout based on the *associationconfiguredvalue.
*/
peer->sackdelay = asoc->sackdelay;
peer->sackfreq = asoc->sackfreq;
if (addr->sa.sa_family == AF_INET6) {
__be32 info = addr->v6.sin6_flowinfo;
/* Enable/disable heartbeat, SACK delay, and path MTU discovery *basedonassociationsetting.
*/
peer->param_flags = asoc->param_flags;
/* Initialize the pmtu of the transport. */
sctp_transport_route(peer, NULL, sp);
/* If this is the first transport addr on this association, *initializetheassociationPMTUtothepeer'sPMTU. *IfnotandthecurrentassociationPMTUishigherthanthenew *peer'sPMTU,resettheassociationPMTUtothenewpeer'sPMTU.
*/
sctp_assoc_set_pmtu(asoc, asoc->pathmtu ?
min_t(int, peer->pathmtu, asoc->pathmtu) :
peer->pathmtu);
peer->pmtu_pending = 0;
/* The asoc->peer.port might not be meaningful yet, but *initializethepacketstructureanyway.
*/
sctp_packet_init(&peer->packet, peer, asoc->base.bind_addr.port,
asoc->peer.port);
/* At this point, we may not have the receiver's advertised window, *soinitializessthreshtothedefaultvalueanditwillbeset *laterwhenweprocesstheINIT.
*/
peer->ssthresh = SCTP_DEFAULT_MAXWINDOW;
/* If we do not yet have a primary path, set one. */ if (!asoc->peer.primary_path) {
sctp_assoc_set_primary(asoc, peer);
asoc->peer.retran_path = peer;
}
/* Lookup a transport by address. */ struct sctp_transport *sctp_assoc_lookup_paddr( conststruct sctp_association *asoc, constunion sctp_addr *address)
{ struct sctp_transport *t;
/* Cycle through all transports searching for a peer address. */
list_for_each_entry(t, &asoc->peer.transport_addr_list,
transports) { if (sctp_cmp_addr_exact(address, &t->ipaddr)) return t;
}
return NULL;
}
/* Remove all transports except a give one */ void sctp_assoc_del_nonprimary_peers(struct sctp_association *asoc, struct sctp_transport *primary)
{ struct sctp_transport *temp; struct sctp_transport *t;
list_for_each_entry_safe(t, temp, &asoc->peer.transport_addr_list,
transports) { /* if the current transport is not the primary one, delete it */ if (t != primary)
sctp_assoc_rm_peer(asoc, t);
}
}
/* Engage in transport control operations. *Markthetransportupordownandsendanotificationtotheuser. *Selectandupdatethenewactiveandretranpaths.
*/ void sctp_assoc_control_transport(struct sctp_association *asoc, struct sctp_transport *transport, enum sctp_transport_cmd command,
sctp_sn_error_t error)
{ int spc_state = SCTP_ADDR_AVAILABLE; bool ulp_notify = true;
/* Record the transition on the transport. */ switch (command) { case SCTP_TRANSPORT_UP: /* If we are moving from UNCONFIRMED state due *toheartbeatsuccess,reporttheSCTP_ADDR_CONFIRMED *statetotheuser,otherwisereportSCTP_ADDR_AVAILABLE.
*/ if (transport->state == SCTP_PF &&
asoc->pf_expose != SCTP_PF_EXPOSE_ENABLE)
ulp_notify = false; elseif (transport->state == SCTP_UNCONFIRMED &&
error == SCTP_HEARTBEAT_SUCCESS)
spc_state = SCTP_ADDR_CONFIRMED;
case SCTP_TRANSPORT_DOWN: /* If the transport was never confirmed, do not transition it *toinactivestate.Also,releasethecachedroutesince *theremaybeabetterroutenexttime.
*/ if (transport->state != SCTP_UNCONFIRMED) {
transport->state = SCTP_INACTIVE;
sctp_transport_pl_reset(transport);
spc_state = SCTP_ADDR_UNREACHABLE;
} else {
sctp_transport_dst_release(transport);
ulp_notify = false;
} break;
case SCTP_TRANSPORT_PF:
transport->state = SCTP_PF; if (asoc->pf_expose != SCTP_PF_EXPOSE_ENABLE)
ulp_notify = false; else
spc_state = SCTP_ADDR_POTENTIALLY_FAILED; break;
default: return;
}
/* Generate and send a SCTP_PEER_ADDR_CHANGE notification *totheuser.
*/ if (ulp_notify)
sctp_ulpevent_notify_peer_addr_change(transport,
spc_state, error);
/* Select new active and retran paths. */
sctp_select_active_and_retran_path(asoc);
}
/* Hold a reference to an association. */ void sctp_association_hold(struct sctp_association *asoc)
{
refcount_inc(&asoc->base.refcnt);
}
/* Release a reference to an association and cleanup *iftherearenomorereferences.
*/ void sctp_association_put(struct sctp_association *asoc)
{ if (refcount_dec_and_test(&asoc->base.refcnt))
sctp_association_destroy(asoc);
}
/* Allocate the next TSN, Transmission Sequence Number, for the given *association.
*/
__u32 sctp_association_get_next_tsn(struct sctp_association *asoc)
{ /* From Section 1.6 Serial Number Arithmetic: *TransmissionSequenceNumberswraparoundwhentheyreach *2**32-1.Thatis,thenextTSNaDATAchunkMUSTuse *aftertransmittingTSN=2*32-1isTSN=0.
*/
__u32 retval = asoc->next_tsn;
asoc->next_tsn++;
asoc->unack_data++;
return retval;
}
/* Compare two addresses to see if they match. Wildcard addresses *onlymatchthemselves.
*/ int sctp_cmp_addr_exact(constunion sctp_addr *ss1, constunion sctp_addr *ss2)
{ struct sctp_af *af;
af = sctp_get_af_specific(ss1->sa.sa_family); if (unlikely(!af)) return0;
return af->cmp_addr(ss1, ss2);
}
/* Return an ecne chunk to get prepended to a packet. *Note:Weareslyandreturnashared,preallocedchunk.FIXME: *Nowedon't,butwecould/should.
*/ struct sctp_chunk *sctp_get_ecne_prepend(struct sctp_association *asoc)
{ if (!asoc->need_ecne) return NULL;
if (key == chunk->subh.data_hdr->tsn) {
match = active; goto out;
}
}
/* If not found, go search all the other transports. */
list_for_each_entry(transport, &asoc->peer.transport_addr_list,
transports) {
if (transport == active) continue;
list_for_each_entry(chunk, &transport->transmitted,
transmitted_list) { if (key == chunk->subh.data_hdr->tsn) {
match = transport; goto out;
}
}
}
out: return match;
}
/* Do delayed input processing. This is scheduled by sctp_rcv(). */ staticvoid sctp_assoc_bh_rcv(struct work_struct *work)
{ struct sctp_association *asoc =
container_of(work, struct sctp_association,
base.inqueue.immediate); struct net *net = asoc->base.net; union sctp_subtype subtype; struct sctp_endpoint *ep; struct sctp_chunk *chunk; struct sctp_inq *inqueue; int first_time = 1; /* is this the first time through the loop */ int error = 0; int state;
/* The association should be held so we should be safe. */
ep = asoc->ep;
inqueue = &asoc->base.inqueue;
sctp_association_hold(asoc); while (NULL != (chunk = sctp_inq_pop(inqueue))) {
state = asoc->state;
subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type);
/* If the first chunk in the packet is AUTH, do special *processingspecifiedinSection6.3ofSCTP-AUTHspec
*/ if (first_time && subtype.chunk == SCTP_CID_AUTH) { struct sctp_chunkhdr *next_hdr;
next_hdr = sctp_inq_peek(inqueue); if (!next_hdr) goto normal;
/* If the next chunk is COOKIE-ECHO, skip the AUTH *chunkwhilesavingapointertoitsowecando *Authenticationlater(duringcookie-echo *processing).
*/ if (next_hdr->type == SCTP_CID_COOKIE_ECHO) {
chunk->auth_chunk = skb_clone(chunk->skb,
GFP_ATOMIC);
chunk->auth = 1; continue;
}
}
/* Remember where the last DATA chunk came from so we *knowwheretosendtheSACK.
*/ if (sctp_chunk_is_data(chunk))
asoc->peer.last_data_from = chunk->transport; else {
SCTP_INC_STATS(net, SCTP_MIB_INCTRLCHUNKS);
asoc->stats.ictrlchunks++; if (chunk->chunk_hdr->type == SCTP_CID_SACK)
asoc->stats.isacks++;
}
if (chunk->transport)
chunk->transport->last_time_heard = ktime_get();
/* Run through the state machine. */
error = sctp_do_sm(net, SCTP_EVENT_T_CHUNK, subtype,
state, ep, asoc, chunk, GFP_ATOMIC);
/* Check to see if the association is freed in response to *theincomingchunk.Ifso,getoutofthewhileloop.
*/ if (asoc->base.dead) break;
/* If there is an error on chunk, discard this packet. */ if (error && chunk)
chunk->pdiscard = 1;
if (first_time)
first_time = 0;
}
sctp_association_put(asoc);
}
/* This routine moves an association from its old sk to a new sk. */ void sctp_assoc_migrate(struct sctp_association *assoc, struct sock *newsk)
{ struct sctp_sock *newsp = sctp_sk(newsk); struct sock *oldsk = assoc->base.sk;
/* Delete the association from the old endpoint's list of *associations.
*/
list_del_init(&assoc->asocs);
/* Decrement the backlog value for a TCP-style socket. */ if (sctp_style(oldsk, TCP))
sk_acceptq_removed(oldsk);
/* Release references to the old endpoint and the sock. */
sctp_endpoint_put(assoc->ep);
sock_put(assoc->base.sk);
/* Get a reference to the new endpoint. */
assoc->ep = newsp->ep;
sctp_endpoint_hold(assoc->ep);
/* Get a reference to the new sock. */
assoc->base.sk = newsk;
sock_hold(assoc->base.sk);
/* Add the association to the new endpoint's list of associations. */
sctp_endpoint_add_asoc(newsp->ep, assoc);
}
/* Update an association (possibly from unexpected COOKIE-ECHO processing). */ int sctp_assoc_update(struct sctp_association *asoc, struct sctp_association *new)
{ struct sctp_transport *trans; struct list_head *pos, *temp;
/* Copy in new parameters of peer. */
asoc->c = new->c;
asoc->peer.rwnd = new->peer.rwnd;
asoc->peer.sack_needed = new->peer.sack_needed;
asoc->peer.auth_capable = new->peer.auth_capable;
asoc->peer.i = new->peer.i;
if (!sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
asoc->peer.i.initial_tsn, GFP_ATOMIC)) return -ENOMEM;
/* Remove any peer addresses not present in the new association. */
list_for_each_safe(pos, temp, &asoc->peer.transport_addr_list) {
trans = list_entry(pos, struct sctp_transport, transports); if (!sctp_assoc_lookup_paddr(new, &trans->ipaddr)) {
sctp_assoc_rm_peer(asoc, trans); continue;
}
if (asoc->state >= SCTP_STATE_ESTABLISHED)
sctp_transport_reset(trans);
}
/* If the case is A (association restart), use *initial_tsnasnext_tsn.IfthecaseisB,use *currentnext_tsnincasedatasenttopeer *hasbeendiscardedandneedsretransmission.
*/ if (asoc->state >= SCTP_STATE_ESTABLISHED) {
asoc->next_tsn = new->next_tsn;
asoc->ctsn_ack_point = new->ctsn_ack_point;
asoc->adv_peer_ack_point = new->adv_peer_ack_point;
/* Reinitialize SSN for both local streams *andpeer'sstreams.
*/
sctp_stream_clear(&asoc->stream);
/* Flush the ULP reassembly and ordered queue. *Anydatatherewillnowbestaleandwill *causeproblems.
*/
sctp_ulpq_flush(&asoc->ulpq);
/* reset the overall association error count so *thattherestartedassociationdoesn'tgettorn *downonthenextretransmissiontimer.
*/
asoc->overall_error_count = 0;
} else { /* Add any peer addresses from the new association. */
list_for_each_entry(trans, &new->peer.transport_addr_list,
transports) if (!sctp_assoc_add_peer(asoc, &trans->ipaddr,
GFP_ATOMIC, trans->state)) return -ENOMEM;
if (sctp_state(asoc, COOKIE_WAIT))
sctp_stream_update(&asoc->stream, &new->stream);
/* get a new assoc id if we don't have one yet. */ if (sctp_assoc_set_id(asoc, GFP_ATOMIC)) return -ENOMEM;
}
/* SCTP-AUTH: Save the peer parameters from the new associations *andalsomovetheassociationsharedkeysover
*/
kfree(asoc->peer.peer_random);
asoc->peer.peer_random = new->peer.peer_random; new->peer.peer_random = NULL;
/* First, try a score-based selection if both transport states *differ.Ifwe'reinatie,letstrytomakeamoreclever *decisionherebasedonerrorcountsandlasttimeheard.
*/ if (score_curr > score_best) return curr; elseif (score_curr == score_best) return sctp_trans_elect_tie(best, curr); else return best;
}
/* We're done as we only have the one and only path. */ if (asoc->peer.transport_count == 1) return; /* If active_path and retran_path are the same and active, *thenthisistheonlyactivepath.Useit.
*/ if (asoc->peer.active_path == asoc->peer.retran_path &&
asoc->peer.active_path->state == SCTP_ACTIVE) return;
/* Iterate from retran_path's successor back to retran_path. */ for (trans = list_next_entry(trans, transports); 1;
trans = list_next_entry(trans, transports)) { /* Manually skip the head element. */ if (&trans->transports == &asoc->peer.transport_addr_list) continue; if (trans->state == SCTP_UNCONFIRMED) continue;
trans_next = sctp_trans_elect_best(trans, trans_next); /* Active is good enough for immediate return. */ if (trans_next->state == SCTP_ACTIVE) break; /* We've reached the end, time to update path. */ if (trans == asoc->peer.retran_path) break;
}
asoc->peer.retran_path = trans_next;
pr_debug("%s: association:%p updated new path to addr:%pISpc\n",
__func__, asoc, &asoc->peer.retran_path->ipaddr.sa);
}
/* Look for the two most recently used active transports. */
list_for_each_entry(trans, &asoc->peer.transport_addr_list,
transports) { /* Skip uninteresting transports. */ if (trans->state == SCTP_INACTIVE ||
trans->state == SCTP_UNCONFIRMED) continue; /* Keep track of the best PF transport from our *listincasewedon'tfindanactiveone.
*/ if (trans->state == SCTP_PF) {
trans_pf = sctp_trans_elect_best(trans, trans_pf); continue;
} /* For active transports, pick the most recent ones. */ if (trans_pri == NULL ||
ktime_after(trans->last_time_heard,
trans_pri->last_time_heard)) {
trans_sec = trans_pri;
trans_pri = trans;
} elseif (trans_sec == NULL ||
ktime_after(trans->last_time_heard,
trans_sec->last_time_heard)) {
trans_sec = trans;
}
}
/* We did not find anything useful for a possible retransmission *path;eitherprimarypaththatwefoundisthesameas *thecurrentone,orwedidn'tgenerallyfindanactiveone.
*/ if (trans_sec == NULL)
trans_sec = trans_pri;
/* If we failed to find a usable transport, just camp on the *activeorpickaPFiffit'sthebetterchoice.
*/ if (trans_pri == NULL) {
trans_pri = sctp_trans_elect_best(asoc->peer.active_path, trans_pf);
trans_sec = trans_pri;
}
/* Set the active and retran transports. */
asoc->peer.active_path = trans_pri;
asoc->peer.retran_path = trans_sec;
}
struct sctp_transport *
sctp_assoc_choose_alter_transport(struct sctp_association *asoc, struct sctp_transport *last_sent_to)
{ /* If this is the first time packet is sent, use the active path, *elseusetheretranpath.Ifthelastpacketwassentoverthe *retranpath,updatetheretranpathanduseit.
*/ if (last_sent_to == NULL) { return asoc->peer.active_path;
} else { if (last_sent_to == asoc->peer.retran_path)
sctp_assoc_update_retran_path(asoc);
/* Update the association's pmtu and frag_point by going through all the *transports.Thisroutineiscalledwhenatransport'sPMTUhaschanged.
*/ void sctp_assoc_sync_pmtu(struct sctp_association *asoc)
{ struct sctp_transport *t;
__u32 pmtu = 0;
if (!asoc) return;
/* Get the lowest pmtu of all the transports. */
list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) { if (t->pmtu_pending && t->dst) {
sctp_transport_update_pmtu(t,
atomic_read(&t->mtu_info));
t->pmtu_pending = 0;
} if (!pmtu || (t->pathmtu < pmtu))
pmtu = t->pathmtu;
}
sctp_assoc_set_pmtu(asoc, pmtu);
}
/* Should we send a SACK to update our peer? */ staticinlinebool sctp_peer_needs_update(struct sctp_association *asoc)
{ struct net *net = asoc->base.net;
switch (asoc->state) { case SCTP_STATE_ESTABLISHED: case SCTP_STATE_SHUTDOWN_PENDING: case SCTP_STATE_SHUTDOWN_RECEIVED: case SCTP_STATE_SHUTDOWN_SENT: if ((asoc->rwnd > asoc->a_rwnd) &&
((asoc->rwnd - asoc->a_rwnd) >= max_t(__u32,
(asoc->base.sk->sk_rcvbuf >> net->sctp.rwnd_upd_shift),
asoc->pathmtu))) returntrue; break; default: break;
} returnfalse;
}
/* Increase asoc's rwnd by len and send any window update SACK if needed. */ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsignedint len)
{ struct sctp_chunk *sack; struct timer_list *timer;
/* If we had window pressure, start recovering it *onceourrwndhadreachedtheaccumulatedpressure *threshold.Theideaistorecoverslowly,butup *totheinitialadvertisedwindow.
*/ if (asoc->rwnd_press) { int change = min(asoc->pathmtu, asoc->rwnd_press);
asoc->rwnd += change;
asoc->rwnd_press -= change;
}
pr_debug("%s: asoc:%p rwnd increased by %d to (%u, %u) - %u\n",
__func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
asoc->a_rwnd);
/* Send a window update SACK if the rwnd has increased by at least the *minimumoftheassociation'sPMTUandhalfofthereceivebuffer. *Thealgorithmusedissimilartotheonedescribedin *Section4.2.3.3ofRFC1122.
*/ if (sctp_peer_needs_update(asoc)) {
asoc->a_rwnd = asoc->rwnd;
/* Stop the SACK timer. */
timer = &asoc->timers[SCTP_EVENT_TIMEOUT_SACK]; if (timer_delete(timer))
sctp_association_put(asoc);
}
}
/* Decrease asoc's rwnd by len. */ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsignedint len)
{ int rx_count; int over = 0;
if (unlikely(!asoc->rwnd || asoc->rwnd_over))
pr_debug("%s: association:%p has asoc->rwnd:%u, " "asoc->rwnd_over:%u!\n", __func__, asoc,
asoc->rwnd, asoc->rwnd_over);
if (asoc->ep->rcvbuf_policy)
rx_count = atomic_read(&asoc->rmem_alloc); else
rx_count = atomic_read(&asoc->base.sk->sk_rmem_alloc);
/* If we've reached or overflowed our receive buffer, announce *a0rwndifrwndwouldstillbepositive.Storethe *potentialpressureoverflowsothatthewindowcanberestored *backtooriginalvalue.
*/ if (rx_count >= asoc->base.sk->sk_rcvbuf)
over = 1;
if (asoc->rwnd >= len) {
asoc->rwnd -= len; if (over) {
asoc->rwnd_press += asoc->rwnd;
asoc->rwnd = 0;
}
} else {
asoc->rwnd_over += len - asoc->rwnd;
asoc->rwnd = 0;
}
pr_debug("%s: asoc:%p rwnd decreased by %d to (%u, %u, %u)\n",
__func__, asoc, len, asoc->rwnd, asoc->rwnd_over,
asoc->rwnd_press);
}
/* Build the bind address list for the association based on info from the *localendpointandtheremotepeer.
*/ int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc, enum sctp_scope scope, gfp_t gfp)
{ struct sock *sk = asoc->base.sk; int flags;
/* Use scoping rules to determine the subset of addresses from *theendpoint.
*/
flags = (PF_INET6 == sk->sk_family) ? SCTP_ADDR6_ALLOWED : 0; if (!inet_v6_ipv6only(sk))
flags |= SCTP_ADDR4_ALLOWED; if (asoc->peer.ipv4_address)
flags |= SCTP_ADDR4_PEERSUPP; if (asoc->peer.ipv6_address)
flags |= SCTP_ADDR6_PEERSUPP;
/* Lookup laddr in the bind address list of an association. */ int sctp_assoc_lookup_laddr(struct sctp_association *asoc, constunion sctp_addr *laddr)
{ int found = 0;
if ((asoc->base.bind_addr.port == ntohs(laddr->v4.sin_port)) &&
sctp_bind_addr_match(&asoc->base.bind_addr, laddr,
sctp_sk(asoc->base.sk)))
found = 1;
return found;
}
/* Set an association id for a given association */ int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp)
{ bool preload = gfpflags_allow_blocking(gfp); int ret;
/* If the id is already assigned, keep it. */ if (asoc->assoc_id) return0;
if (preload)
idr_preload(gfp);
spin_lock_bh(&sctp_assocs_id_lock); /* 0, 1, 2 are used as SCTP_FUTURE_ASSOC, SCTP_CURRENT_ASSOC and *SCTP_ALL_ASSOC,soanavailableidmustbe>SCTP_ALL_ASSOC.
*/
ret = idr_alloc_cyclic(&sctp_assocs_id, asoc, SCTP_ALL_ASSOC + 1, 0,
GFP_NOWAIT);
spin_unlock_bh(&sctp_assocs_id_lock); if (preload)
idr_preload_end(); if (ret < 0) return ret;
/* Clean up the ASCONF_ACK queue */ void sctp_assoc_clean_asconf_ack_cache(conststruct sctp_association *asoc)
{ struct sctp_chunk *ack; struct sctp_chunk *tmp;
/* We can remove all the entries from the queue up to *the"Peer-Sequence-Number".
*/
list_for_each_entry_safe(ack, tmp, &asoc->asconf_ack_list,
transmitted_list) { if (ack->subh.addip_hdr->serial ==
htonl(asoc->peer.addip_serial)) break;
/* Find the ASCONF_ACK whose serial number matches ASCONF */ struct sctp_chunk *sctp_assoc_lookup_asconf_ack( conststruct sctp_association *asoc,
__be32 serial)
{ struct sctp_chunk *ack;
/* Walk through the list of cached ASCONF-ACKs and find the *ackchunkwhoseserialnumbermatchesthatoftherequest.
*/
list_for_each_entry(ack, &asoc->asconf_ack_list, transmitted_list) { if (sctp_chunk_pending(ack)) continue; if (ack->subh.addip_hdr->serial == serial) {
sctp_chunk_hold(ack); return ack;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.