From patchwork Thu Apr 26 19:58:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Ricardo Leitner X-Patchwork-Id: 905338 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="A+XsDH9m"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40X7FQ6ClJz9s02 for ; Fri, 27 Apr 2018 05:59:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755774AbeDZT7e (ORCPT ); Thu, 26 Apr 2018 15:59:34 -0400 Received: from mail-qt0-f196.google.com ([209.85.216.196]:45951 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755422AbeDZT71 (ORCPT ); Thu, 26 Apr 2018 15:59:27 -0400 Received: by mail-qt0-f196.google.com with SMTP id j42-v6so5304601qtj.12; Thu, 26 Apr 2018 12:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yFclKj7ZRLPyDXJxiXcBavwd8P13naX+rgXp5w6QQfY=; b=A+XsDH9mUQLC3Rh5jrhRKZIKTHRwk/9ZzdBxolmaxCKg/FZVB4D37lZhLiUbn8QKaI m9vhBHetEVQUXTIc5/DKVSblsP9L+urXAAS+FVwOuK13JlYC0dIRexcseT6bE1kWJrk3 j3qgyzc55M1NP9DNEw55T251/YGU6R3n7oQzfT3P9lBkFk0sA4ZE5lK4Um9X0EZD1666 qv4spR/gQIc8OxrudTb6TQI7YV02CmeMEo3yLa92+wGo4py+TlkdUHnfZXWIw0an12Kd alNPcVt45YPLmsjIc+Y9hDXnBl9B4AYuzN8oH+zGMoqeds7H89ePBLG7KfhuRjqQco0l kXZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yFclKj7ZRLPyDXJxiXcBavwd8P13naX+rgXp5w6QQfY=; b=aHvZ9D+tR/70GH5GkcyQpDYII2R6KoYGwMtIACFKFHzB1MMaWoVcczpVV7sk0eViu1 FqH1c3VpCMe1ECInkTqH0nn6LyrSrKIwEmL9f0TkjxQREqjjrHJM24JhYwO4CfasYhG8 FemlcC4MOA17JkWJHpiYhGzfaH7fFz5Q1bnVW1vnJ0m7asf0qwzVtVRJyx3EYufsrIcN /nyE04pNHjuIVbtmouCEYZU7QWicTGKJLOFoCkp5jNhumr5Dk1oi5lpuwWXiQD/oUJzc 4J80/i5Q0JfkOF7kwWlHb0WcR702G3xoixcXLev/SxfBIx4CpRw29r0LfYGsBN6JKrPq aVUg== X-Gm-Message-State: ALQs6tD403S+nPG4YUcGcZ24iaIzlc7sN/Cww+yGfWZhDMvEJd56AwN+ raybxDrbTMwDYZuLeEutk/4= X-Google-Smtp-Source: AB8JxZpPlDawXxxwqobL1LdkDa8tN2fq4NI1Z6PaEFsmtiDIMP9gZi7ggW1VIelQfrUDUrwI5eptwg== X-Received: by 2002:ac8:65d7:: with SMTP id t23-v6mr10160922qto.183.1524772766490; Thu, 26 Apr 2018 12:59:26 -0700 (PDT) Received: from localhost.localdomain ([177.10.56.95]) by smtp.gmail.com with ESMTPSA id d21sm5880784qkc.30.2018.04.26.12.59.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 26 Apr 2018 12:59:25 -0700 (PDT) Received: by localhost.localdomain (Postfix, from userid 1000) id CA202181110; Thu, 26 Apr 2018 16:59:18 -0300 (-03) From: Marcelo Ricardo Leitner To: netdev@vger.kernel.org Cc: linux-sctp@vger.kernel.org, Vlad Yasevich , Neil Horman , Xin Long Subject: [PATCH net-next 06/13] sctp: introduce sctp_assoc_update_frag_point Date: Thu, 26 Apr 2018 16:58:55 -0300 Message-Id: X-Mailer: git-send-email 2.14.3 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org and avoid the open-coded versions of it. Now sctp_datamsg_from_user can just re-use asoc->frag_point as it will always be updated. Signed-off-by: Marcelo Ricardo Leitner --- include/net/sctp/sctp.h | 20 -------------------- include/net/sctp/structs.h | 1 + net/sctp/associola.c | 24 +++++++++++++++++------- net/sctp/chunk.c | 12 +----------- net/sctp/socket.c | 2 +- 5 files changed, 20 insertions(+), 39 deletions(-) diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h index 0b98e4683f108670c65a0a7aceaf9a736d54bf29..350c65620a4eb35ba2af0d59fef70e2b8b461e44 100644 --- a/include/net/sctp/sctp.h +++ b/include/net/sctp/sctp.h @@ -428,26 +428,6 @@ static inline int sctp_list_single_entry(struct list_head *head) return (head->next != head) && (head->next == head->prev); } -/* Break down data chunks at this point. */ -static inline int sctp_frag_point(const struct sctp_association *asoc, int pmtu) -{ - struct sctp_sock *sp = sctp_sk(asoc->base.sk); - struct sctp_af *af = sp->pf->af; - int frag = pmtu; - - frag -= af->ip_options_len(asoc->base.sk); - frag -= af->net_header_len; - frag -= sizeof(struct sctphdr) + sctp_datachk_len(&asoc->stream); - - if (asoc->user_frag) - frag = min_t(int, frag, asoc->user_frag); - - frag = SCTP_TRUNC4(min_t(int, frag, SCTP_MAX_CHUNK_LEN - - sctp_datachk_len(&asoc->stream))); - - return frag; -} - static inline void sctp_assoc_pending_pmtu(struct sctp_association *asoc) { sctp_assoc_sync_pmtu(asoc); diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index c5e244be8f1ea99118cac9ada0cfce871cb15d3f..ebf809eed33add7905ddd13abf98712a833ae0e0 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -2097,6 +2097,7 @@ int sctp_assoc_update(struct sctp_association *old, __u32 sctp_association_get_next_tsn(struct sctp_association *); +void sctp_assoc_update_frag_point(struct sctp_association *asoc); void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu); void sctp_assoc_sync_pmtu(struct sctp_association *asoc); void sctp_assoc_rwnd_increase(struct sctp_association *, unsigned int); diff --git a/net/sctp/associola.c b/net/sctp/associola.c index 85b362324084e9ba139a39293a527ef06824e55b..a29025418b96015dd0240013b0a7c636194da67b 100644 --- a/net/sctp/associola.c +++ b/net/sctp/associola.c @@ -666,8 +666,6 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc, peer->pmtu_pending = 0; - asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu); - /* The asoc->peer.port might not be meaningful yet, but * initialize the packet structure anyway. */ @@ -1370,10 +1368,26 @@ sctp_assoc_choose_alter_transport(struct sctp_association *asoc, } } +void sctp_assoc_update_frag_point(struct sctp_association *asoc) +{ + int frag = sctp_mtu_payload(sctp_sk(asoc->base.sk), asoc->pathmtu, + sctp_datachk_len(&asoc->stream)); + + if (asoc->user_frag) + frag = min_t(int, frag, asoc->user_frag); + + frag = min_t(int, frag, SCTP_MAX_CHUNK_LEN - + sctp_datachk_len(&asoc->stream)); + + asoc->frag_point = SCTP_TRUNC4(frag); +} + void sctp_assoc_set_pmtu(struct sctp_association *asoc, __u32 pmtu) { - if (asoc->pathmtu != pmtu) + if (asoc->pathmtu != pmtu) { asoc->pathmtu = pmtu; + sctp_assoc_update_frag_point(asoc); + } pr_debug("%s: asoc:%p, pmtu:%d, frag_point:%d\n", __func__, asoc, asoc->pathmtu, asoc->frag_point); @@ -1403,10 +1417,6 @@ void sctp_assoc_sync_pmtu(struct sctp_association *asoc) } sctp_assoc_set_pmtu(asoc, pmtu); - asoc->frag_point = sctp_frag_point(asoc, pmtu); - - pr_debug("%s: asoc:%p, pmtu:%d, frag_point:%d\n", __func__, asoc, - asoc->pathmtu, asoc->frag_point); } /* Should we send a SACK to update our peer? */ diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c index be296d633e951c8df322d560150973b5b2bdce5b..79daa98208c391c780440144d69bc7be875c3476 100644 --- a/net/sctp/chunk.c +++ b/net/sctp/chunk.c @@ -172,8 +172,6 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, 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); @@ -192,12 +190,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, /* 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); + max_data = asoc->frag_point; /* If the the peer requested that we authenticate DATA chunks * we need to account for bundling of the AUTH chunks along with @@ -222,9 +215,6 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc, } } - /* 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; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index b9d14f57146b8e551c28379e379158231fb40ae7..21bf457be3ea321457107256c12ccb93e1fbab06 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -3251,7 +3251,7 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned sctp_datachk_len(&asoc->stream); } asoc->user_frag = val; - asoc->frag_point = sctp_frag_point(asoc, asoc->pathmtu); + sctp_assoc_update_frag_point(asoc); } else { if (params.assoc_id && sctp_style(sk, UDP)) return -EINVAL;