cregit-Linux how code gets into the kernel

Release 4.17 net/sctp/chunk.c

Directory: net/sctp
/* SCTP kernel implementation
 * (C) Copyright IBM Corp. 2003, 2004
 *
 * This file is part of the SCTP kernel implementation
 *
 * This file contains the code relating the chunk abstraction.
 *
 * This SCTP implementation is free software;
 * you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This SCTP implementation is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *                 ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * 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:
 *    Jon Grimm             <jgrimm@us.ibm.com>
 *    Sridhar Samudrala     <sri@us.ibm.com>
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/net.h>
#include <linux/inet.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <net/sctp/sctp.h>
#include <net/sctp/sm.h>

/* This file is mostly in anticipation of future work, but initially
 * populate with fragment tracking for an outbound message.
 */

/* Initialize datamsg from memory. */

static void sctp_datamsg_init(struct sctp_datamsg *msg) { refcount_set(&msg->refcnt, 1); msg->send_failed = 0; msg->send_error = 0; msg->can_delay = 1; msg->abandoned = 0; msg->expires_at = 0; INIT_LIST_HEAD(&msg->chunks); }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm4474.58%337.50%
Xin Long610.17%112.50%
Vladislav Yasevich610.17%112.50%
Sridhar Samudrala23.39%225.00%
Elena Reshetova11.69%112.50%
Total59100.00%8100.00%

/* Allocate and initialize datamsg. */
static struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp) { struct sctp_datamsg *msg; msg = kmalloc(sizeof(struct sctp_datamsg), gfp); if (msg) { sctp_datamsg_init(msg); SCTP_DBG_OBJCNT_INC(datamsg); } return msg; }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm4491.67%125.00%
Li Zefan24.17%125.00%
Daniel Borkmann12.08%125.00%
Al Viro12.08%125.00%
Total48100.00%4100.00%


void sctp_datamsg_free(struct sctp_datamsg *msg) { struct sctp_chunk *chunk; /* This doesn't have to be a _safe vairant because * sctp_chunk_free() only drops the refs. */ list_for_each_entry(chunk, &msg->chunks, frag_list) sctp_chunk_free(chunk); sctp_datamsg_put(msg); }

Contributors

PersonTokensPropCommitsCommitProp
Xin Long34100.00%1100.00%
Total34100.00%1100.00%

/* Final destructruction of datamsg memory. */
static void sctp_datamsg_destroy(struct sctp_datamsg *msg) { struct list_head *pos, *temp; struct sctp_chunk *chunk; struct sctp_sock *sp; struct sctp_ulpevent *ev; struct sctp_association *asoc = NULL; int error = 0, notify; /* If we failed, we may need to notify. */ notify = msg->send_failed ? -1 : 0; /* Release all references. */ list_for_each_safe(pos, temp, &msg->chunks) { list_del_init(pos); chunk = list_entry(pos, struct sctp_chunk, frag_list); /* Check whether we _really_ need to notify. */ if (notify < 0) { asoc = chunk->asoc; if (msg->send_error) error = msg->send_error; else error = asoc->outqueue.error; sp = sctp_sk(asoc->base.sk); notify = sctp_ulpevent_type_enabled(SCTP_SEND_FAILED, &sp->subscribe); } /* Generate a SEND FAILED event only if enabled. */ if (notify > 0) { int sent; if (chunk->has_tsn) sent = SCTP_DATA_SENT; else sent = SCTP_DATA_UNSENT; ev = sctp_ulpevent_make_send_failed(asoc, chunk, sent, error, GFP_ATOMIC); if (ev) asoc->stream.si->enqueue_event(&asoc->ulpq, ev); } sctp_chunk_put(chunk); } SCTP_DBG_OBJCNT_DEC(datamsg); kfree(msg); }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm21294.64%457.14%
Xin Long73.12%114.29%
Sridhar Samudrala41.79%114.29%
Arnaldo Carvalho de Melo10.45%114.29%
Total224100.00%7100.00%

/* Hold a reference. */
static void sctp_datamsg_hold(struct sctp_datamsg *msg) { refcount_inc(&msg->refcnt); }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm1789.47%133.33%
Elena Reshetova15.26%133.33%
Sridhar Samudrala15.26%133.33%
Total19100.00%3100.00%

/* Release a reference. */
void sctp_datamsg_put(struct sctp_datamsg *msg) { if (refcount_dec_and_test(&msg->refcnt)) sctp_datamsg_destroy(msg); }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm2496.00%150.00%
Elena Reshetova14.00%150.00%
Total25100.00%2100.00%

/* Assign a chunk to this datamsg. */
static void sctp_datamsg_assign(struct sctp_datamsg *msg, struct sctp_chunk *chunk) { sctp_datamsg_hold(msg); chunk->msg = msg; }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm2696.30%150.00%
Sridhar Samudrala13.70%150.00%
Total27100.00%2100.00%

/* A data chunk can have a maximum payload of (2^16 - 20). Break * down any such message into smaller chunks. Opportunistically, fragment * the chunks down to the current MTU constraints. We may get refragmented * later if the PMTU changes, but it is _much better_ to fragment immediately * with a reasonable guess than always doing our fragmentation on the * soft-interrupt. */
struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, struct sctp_sndrcvinfo *sinfo, struct iov_iter *from) { size_t len, first_len, max_data, remaining; size_t msg_len = iov_iter_count(from); struct sctp_shared_key *shkey = NULL; struct list_head *pos, *temp; struct sctp_chunk *chunk; struct sctp_datamsg *msg; struct sctp_sock *sp; struct sctp_af *af; int err; msg = sctp_datamsg_new(GFP_KERNEL); if (!msg) return ERR_PTR(-ENOMEM); /* Note: Calculate this outside of the loop, so that all fragments * have the same expiration. */ if (asoc->peer.prsctp_capable && sinfo->sinfo_timetolive && (SCTP_PR_TTL_ENABLED(sinfo->sinfo_flags) || !SCTP_PR_POLICY(sinfo->sinfo_flags))) msg->expires_at = jiffies + msecs_to_jiffies(sinfo->sinfo_timetolive); /* This is the biggest possible DATA chunk that can fit into * the packet */ sp = sctp_sk(asoc->base.sk); af = sp->pf->af; max_data = asoc->pathmtu - af->net_header_len - sizeof(struct sctphdr) - sctp_datachk_len(&asoc->stream) - af->ip_options_len(asoc->base.sk); max_data = SCTP_TRUNC4(max_data); /* If the the peer requested that we authenticate DATA chunks * we need to account for bundling of the AUTH chunks along with * DATA. */ if (sctp_auth_send_cid(SCTP_CID_DATA, asoc)) { struct sctp_hmac *hmac_desc = sctp_auth_asoc_get_hmac(asoc); if (hmac_desc) max_data -= SCTP_PAD4(sizeof(struct sctp_auth_chunk) + hmac_desc->hmac_len); if (sinfo->sinfo_tsn && sinfo->sinfo_ssn != asoc->active_key_id) { shkey = sctp_auth_get_shkey(asoc, sinfo->sinfo_ssn); if (!shkey) { err = -EINVAL; goto errout; } } else { shkey = asoc->shkey; } } /* Check what's our max considering the above */ max_data = min_t(size_t, max_data, asoc->frag_point); /* Set first_len and then account for possible bundles on first frag */ first_len = max_data; /* Check to see if we have a pending SACK and try to let it be bundled * with this message. Do this if we don't have any data queued already. * To check that, look at out_qlen and retransmit list. * NOTE: we will not reduce to account for SACK, if the message would * not have been fragmented. */ if (timer_pending(&asoc->timers[SCTP_EVENT_TIMEOUT_SACK]) && asoc->outqueue.out_qlen == 0 && list_empty(&asoc->outqueue.retransmit) && msg_len > max_data) first_len -= SCTP_PAD4(sizeof(struct sctp_sack_chunk)); /* Encourage Cookie-ECHO bundling. */ if (asoc->state < SCTP_STATE_COOKIE_ECHOED) first_len -= SCTP_ARBITRARY_COOKIE_ECHO_LEN; /* Account for a different sized first fragment */ if (msg_len >= first_len) { msg->can_delay = 0; SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_FRAGUSRMSGS); } else { /* Which may be the only one... */ first_len = msg_len; } /* Create chunks for all DATA chunks. */ for (remaining = msg_len; remaining; remaining -= len) { u8 frag = SCTP_DATA_MIDDLE_FRAG; if (remaining == msg_len) { /* First frag, which may also be the last */ frag |= SCTP_DATA_FIRST_FRAG; len = first_len; } else { /* Middle frags */ len = max_data; } if (len >= remaining) { /* Last frag, which may also be the first */ len = remaining; frag |= SCTP_DATA_LAST_FRAG; /* The application requests to set the I-bit of the * last DATA chunk of a user message when providing * the user message to the SCTP implementation. */ if ((sinfo->sinfo_flags & SCTP_EOF) || (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY)) frag |= SCTP_DATA_SACK_IMM; } chunk = asoc->stream.si->make_datafrag(asoc, sinfo, len, frag, GFP_KERNEL); if (!chunk) { err = -ENOMEM; goto errout; } err = sctp_user_addto_chunk(chunk, len, from); if (err < 0) goto errout_chunk_free; chunk->shkey = shkey; /* Put the chunk->skb back into the form expected by send. */ __skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr - chunk->skb->data); sctp_datamsg_assign(msg, chunk); list_add_tail(&chunk->frag_list, &msg->chunks); } return msg; errout_chunk_free: sctp_chunk_free(chunk); errout: list_for_each_safe(pos, temp, &msg->chunks) { list_del_init(pos); chunk = list_entry(pos, struct sctp_chunk, frag_list); sctp_chunk_free(chunk); } sctp_datamsg_put(msg); return ERR_PTR(err); }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm21933.54%310.34%
Vladislav Yasevich12519.14%413.79%
Xin Long12018.38%827.59%
Marcelo Ricardo Leitner9013.78%413.79%
Richard Haines345.21%13.45%
Wei Yongjun253.83%13.45%
Tommi Rantala243.68%26.90%
Eric W. Biedermann91.38%13.45%
Al Viro30.46%13.45%
Wang Weidong10.15%13.45%
Florian Westphal10.15%13.45%
Hideaki Yoshifuji / 吉藤英明10.15%13.45%
Eric Dumazet10.15%13.45%
Total653100.00%29100.00%

/* Check whether this message has expired. */
int sctp_chunk_abandoned(struct sctp_chunk *chunk) { if (!chunk->asoc->peer.prsctp_capable) return 0; if (chunk->msg->abandoned) return 1; if (!chunk->has_tsn && !(chunk->chunk_hdr->flags & SCTP_DATA_FIRST_FRAG)) return 0; if (SCTP_PR_TTL_ENABLED(chunk->sinfo.sinfo_flags) && time_after(jiffies, chunk->msg->expires_at)) { struct sctp_stream_out *streamout = &chunk->asoc->stream.out[chunk->sinfo.sinfo_stream]; if (chunk->sent_count) { chunk->asoc->abandoned_sent[SCTP_PR_INDEX(TTL)]++; streamout->ext->abandoned_sent[SCTP_PR_INDEX(TTL)]++; } else { chunk->asoc->abandoned_unsent[SCTP_PR_INDEX(TTL)]++; streamout->ext->abandoned_unsent[SCTP_PR_INDEX(TTL)]++; } chunk->msg->abandoned = 1; return 1; } else if (SCTP_PR_RTX_ENABLED(chunk->sinfo.sinfo_flags) && chunk->sent_count > chunk->sinfo.sinfo_timetolive) { struct sctp_stream_out *streamout = &chunk->asoc->stream.out[chunk->sinfo.sinfo_stream]; chunk->asoc->abandoned_sent[SCTP_PR_INDEX(RTX)]++; streamout->ext->abandoned_sent[SCTP_PR_INDEX(RTX)]++; chunk->msg->abandoned = 1; return 1; } else if (!SCTP_PR_POLICY(chunk->sinfo.sinfo_flags) && chunk->msg->expires_at && time_after(jiffies, chunk->msg->expires_at)) { chunk->msg->abandoned = 1; return 1; } /* PRIO policy is processed by sendmsg, not here */ return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Xin Long28593.75%1076.92%
Jon Grimm123.95%17.69%
Marcelo Ricardo Leitner61.97%17.69%
Sridhar Samudrala10.33%17.69%
Total304100.00%13100.00%

/* This chunk (and consequently entire message) has failed in its sending. */
void sctp_chunk_fail(struct sctp_chunk *chunk, int error) { chunk->msg->send_failed = 1; chunk->msg->send_error = error; }

Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm2896.55%150.00%
Sridhar Samudrala13.45%150.00%
Total29100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Jon Grimm66044.99%47.84%
Xin Long45230.81%1733.33%
Vladislav Yasevich1318.93%47.84%
Marcelo Ricardo Leitner966.54%59.80%
Richard Haines342.32%11.96%
Wei Yongjun251.70%11.96%
Tommi Rantala241.64%23.92%
Sridhar Samudrala100.68%35.88%
Eric W. Biedermann90.61%11.96%
Joe Perches70.48%11.96%
Al Viro40.27%23.92%
Tejun Heo30.20%11.96%
Elena Reshetova30.20%11.96%
Li Zefan20.14%11.96%
Arnaldo Carvalho de Melo10.07%11.96%
Daniel Borkmann10.07%11.96%
Wang Weidong10.07%11.96%
Florian Westphal10.07%11.96%
Jeff Kirsher10.07%11.96%
Eric Dumazet10.07%11.96%
Hideaki Yoshifuji / 吉藤英明10.07%11.96%
Total1467100.00%51100.00%
Directory: net/sctp
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.