// SPDX-License-Identifier: GPL-2.0-or-later /* SCTP kernel implementation * Copyright (c) 1999-2000 Cisco, Inc. * Copyright (c) 1999-2001 Motorola, Inc. * Copyright (c) 2001-2002 International Business Machines, Corp. * Copyright (c) 2001 Intel Corp. * Copyright (c) 2001 Nokia, Inc. * Copyright (c) 2001 La Monte H.P. Yarroll * * This file is part of the SCTP kernel implementation * * This abstraction represents an SCTP endpoint. * * Please send any bug reports or fixes you make to the * email address(es): * lksctp developers <linux-sctp@vger.kernel.org> * * Written or modified by: * La Monte H.P. Yarroll <piggy@acm.org> * Karl Knutson <karl@athena.chicago.il.us> * Jon Grimm <jgrimm@austin.ibm.com> * Daisy Chang <daisyc@us.ibm.com> * Dajiang Zhang <dajiang.zhang@nokia.com>
*/
/* Add the null key to the endpoint shared keys list and * set the hmcas and chunks pointers.
*/
ep->prsctp_enable = net->sctp.prsctp_enable;
ep->reconf_enable = net->sctp.reconf_enable;
ep->ecn_enable = net->sctp.ecn_enable;
/* Remember who we are attached to. */
ep->base.sk = sk;
ep->base.net = sock_net(sk);
sock_hold(ep->base.sk);
/* Create a sctp_endpoint with all that boring stuff initialized. * Returns NULL if there isn't enough memory.
*/ struct sctp_endpoint *sctp_endpoint_new(struct sock *sk, gfp_t gfp)
{ struct sctp_endpoint *ep;
/* Build a local endpoint. */
ep = kzalloc(sizeof(*ep), gfp); if (!ep) goto fail;
if (!sctp_endpoint_init(ep, sk, gfp)) goto fail_init;
SCTP_DBG_OBJCNT_INC(ep); return ep;
fail_init:
kfree(ep);
fail: return NULL;
}
/* Add an association to an endpoint. */ void sctp_endpoint_add_asoc(struct sctp_endpoint *ep, struct sctp_association *asoc)
{ struct sock *sk = ep->base.sk;
/* If this is a temporary association, don't bother * since we'll be removing it shortly and don't * want anyone to find it anyway.
*/ if (asoc->temp) return;
/* Now just add it to our list of asocs */
list_add_tail(&asoc->asocs, &ep->asocs);
/* Increment the backlog value for a TCP-style listening socket. */ if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
sk_acceptq_added(sk);
}
/* Free the endpoint structure. Delay cleanup until * all users have released their reference count on this structure.
*/ void sctp_endpoint_free(struct sctp_endpoint *ep)
{
ep->base.dead = true;
inet_sk_set_state(ep->base.sk, SCTP_SS_CLOSED);
/* Unlink this endpoint, so we can't find it again! */
sctp_unhash_endpoint(ep);
if (unlikely(!ep->base.dead)) {
WARN(1, "Attempt to destroy undead endpoint %p!\n", ep); return;
}
/* Free the digest buffer */
kfree(ep->digest);
/* SCTP-AUTH: Free up AUTH releated data such as shared keys * chunks and hmacs arrays that were allocated
*/
sctp_auth_destroy_keys(&ep->endpoint_shared_keys);
sctp_auth_free(ep);
sk = ep->base.sk; /* Remove and free the port */ if (sctp_sk(sk)->bind_hash)
sctp_put_port(sk);
call_rcu(&ep->rcu, sctp_endpoint_destroy_rcu);
}
/* Hold a reference to an endpoint. */ int sctp_endpoint_hold(struct sctp_endpoint *ep)
{ return refcount_inc_not_zero(&ep->base.refcnt);
}
/* Release a reference to an endpoint and clean up if there are * no more references.
*/ void sctp_endpoint_put(struct sctp_endpoint *ep)
{ if (refcount_dec_and_test(&ep->base.refcnt))
sctp_endpoint_destroy(ep);
}
/* Is this the endpoint we are looking for? */ struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *ep, struct net *net, constunion sctp_addr *laddr, int dif, int sdif)
{ int bound_dev_if = READ_ONCE(ep->base.sk->sk_bound_dev_if); struct sctp_endpoint *retval = NULL;
/* Find the association that goes with this chunk. * We lookup the transport from hashtable at first, then get association * through t->assoc.
*/ struct sctp_association *sctp_endpoint_lookup_assoc( conststruct sctp_endpoint *ep, constunion sctp_addr *paddr, struct sctp_transport **transport)
{ struct sctp_association *asoc = NULL; struct sctp_transport *t;
*transport = NULL;
/* If the local port is not set, there can't be any associations * on this endpoint.
*/ if (!ep->base.bind_addr.port) return NULL;
rcu_read_lock();
t = sctp_epaddr_lookup_transport(ep, paddr); if (!t) goto out;
/* Look for any peeled off association from the endpoint that matches the * given peer address.
*/ bool sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep, constunion sctp_addr *paddr)
{ int bound_dev_if = READ_ONCE(ep->base.sk->sk_bound_dev_if); struct sctp_sockaddr_entry *addr; struct net *net = ep->base.net; struct sctp_bind_addr *bp;
bp = &ep->base.bind_addr; /* This function is called with the socket lock held, * so the address_list can not change.
*/
list_for_each_entry(addr, &bp->address_list, list) { if (sctp_has_association(net, &addr->a, paddr,
bound_dev_if, bound_dev_if)) returntrue;
}
returnfalse;
}
/* Do delayed input processing. This is scheduled by sctp_rcv(). * This may be called on BH or task time.
*/ staticvoid sctp_endpoint_bh_rcv(struct work_struct *work)
{ struct sctp_endpoint *ep =
container_of(work, struct sctp_endpoint,
base.inqueue.immediate); struct sctp_association *asoc; struct sock *sk; struct net *net; struct sctp_transport *transport; struct sctp_chunk *chunk; struct sctp_inq *inqueue; union sctp_subtype subtype; enum sctp_state state; int error = 0; int first_time = 1; /* is this the first time through the loop */
if (ep->base.dead) return;
asoc = NULL;
inqueue = &ep->base.inqueue;
sk = ep->base.sk;
net = sock_net(sk);
while (NULL != (chunk = sctp_inq_pop(inqueue))) {
subtype = SCTP_ST_CHUNK(chunk->chunk_hdr->type);
/* If the first chunk in the packet is AUTH, do special * processing specified in Section 6.3 of SCTP-AUTH spec
*/ 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 * chunk while saving a pointer to it so we can do * Authentication later (during cookie-echo * processing).
*/ if (next_hdr->type == SCTP_CID_COOKIE_ECHO) {
chunk->auth_chunk = skb_clone(chunk->skb,
GFP_ATOMIC);
chunk->auth = 1; continue;
}
}
normal: /* We might have grown an association since last we * looked, so try again. * * This happens when we've just processed our * COOKIE-ECHO chunk.
*/ if (NULL == chunk->asoc) {
asoc = sctp_endpoint_lookup_assoc(ep,
sctp_source(chunk),
&transport);
chunk->asoc = asoc;
chunk->transport = transport;
}
state = asoc ? asoc->state : SCTP_STATE_CLOSED; if (sctp_auth_recv_cid(subtype.chunk, asoc) && !chunk->auth) continue;
/* Remember where the last DATA chunk came from so we * know where to send the SACK.
*/ if (asoc && sctp_chunk_is_data(chunk))
asoc->peer.last_data_from = chunk->transport; else {
SCTP_INC_STATS(ep->base.net, SCTP_MIB_INCTRLCHUNKS); if (asoc)
asoc->stats.ictrlchunks++;
}
if (chunk->transport)
chunk->transport->last_time_heard = ktime_get();
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.