From patchwork Sat Jul 9 11:47:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 646672 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rmqPJ0WV9z9sXx for ; Sat, 9 Jul 2016 21:48:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=sQ2OrYD+; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933007AbcGILsP (ORCPT ); Sat, 9 Jul 2016 07:48:15 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36532 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932850AbcGILsL (ORCPT ); Sat, 9 Jul 2016 07:48:11 -0400 Received: by mail-pf0-f195.google.com with SMTP id i123so10134050pfg.3; Sat, 09 Jul 2016 04:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=9C5DoR6FNoJtnvRXdwPdvVEyjQpTG08c0ofiJKlqr/k=; b=sQ2OrYD+htXW8MCsIqLa/PpdzmtzGFQifDY/FrtPmLkN3XyCSjvDc641emeNw8x0xe fOBE8o0rg18fsoU4PAovMIgUVN1irUHX231P0s1ZWb10YQ3FKxarClSJ0OuIf3mZRjwk O5wBsWJp3Y4Qy+G/DVgyqBXQtZCCPn6durV4lgzV8jYYyIzEAJQpTPyzYS+B9zx28JLO rdMWfGpxPBiuD15UUiT1vN5II1mGXDY7O9wVUNZsq2vtpRlajiqIICIBWl8ERMzmYIPa 1o2mJo/EcDwffOgyOfalyAKh5wwD6Oo2tmd92eV81TCM6YDjHN322pWhfdMUYH5IB1Ey VTMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=9C5DoR6FNoJtnvRXdwPdvVEyjQpTG08c0ofiJKlqr/k=; b=LNfjkvDuzlTtt3WXpqp15v7m3O0LdIZm+6PUciSgb7hqtq/MN+vVWoEPzZC9vPx/6i zBeF1V5HZFiA2gGUHhRhBoi8w0VCeEOmzXsfuj0ePMv9E8oGtSsz+D2qqpSusDWwtrz6 62eRas2IJDgC34QGvimCHD1OeZnovIgw0OaYZ2XyQMzuh9nq/x740eP0xaCioVEx1dry cVyvKjj5xEY1N8nEQ4yVrV4B5DZDjH7lUi90h1IR5pHFtD59mDu76bJlsK0OezTSPd9I uUhIx1HxSYZwaNJzYaWXmiKoMwBEW+W5jR1FVCKHOn0NawDYEp29dRmsBI8caVjAaTrk 5BJQ== X-Gm-Message-State: ALyK8tLtLpfcvGYjFDjn5XtdR5xH5L9kQhKIz4dwJxKQ9s8ZdJW6C/TFryA1C3AiVn07Pg== X-Received: by 10.98.83.68 with SMTP id h65mr17904582pfb.112.1468064889848; Sat, 09 Jul 2016 04:48:09 -0700 (PDT) Received: from localhost (138.128.208.20.16clouds.com. [138.128.208.20]) by smtp.gmail.com with ESMTPSA id 4sm4031933pav.33.2016.07.09.04.48.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jul 2016 04:48:09 -0700 (PDT) From: Xin Long To: network dev , linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Vlad Yasevich , daniel@iogearbox.net, davem@davemloft.net Subject: [PATCH net-next 4/6] sctp: implement prsctp TTL policy Date: Sat, 9 Jul 2016 19:47:43 +0800 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: <63a9a850836134ba72b9377e8b99694d869e3fba.1468064737.git.lucien.xin@gmail.com> References: <121aa41aceff56b3dda51c41b8f3c4d8662d65b7.1468064737.git.lucien.xin@gmail.com> <2b9ceacb55912e29c2d970772d0267e465c33dff.1468064737.git.lucien.xin@gmail.com> <63a9a850836134ba72b9377e8b99694d869e3fba.1468064737.git.lucien.xin@gmail.com> In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org prsctp TTL policy is a policy to abandon chunks when they expire at the specific time in local stack. It's similar with expires_at in struct sctp_datamsg. This patch uses sinfo->sinfo_timetolive to set the specific time for TTL policy. sinfo->sinfo_timetolive is also used for msg->expires_at. So if prsctp_enable or TTL policy is not enabled, msg->expires_at still works as before. Signed-off-by: Xin Long --- include/net/sctp/structs.h | 10 ++++++++++ net/sctp/chunk.c | 20 +++++++++++++++++--- net/sctp/output.c | 2 ++ net/sctp/sm_make_chunk.c | 12 ++++++++++++ net/sctp/socket.c | 4 ++-- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index d8e464a..6bcda71 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -602,6 +602,16 @@ struct sctp_chunk { /* This needs to be recoverable for SCTP_SEND_FAILED events. */ struct sctp_sndrcvinfo sinfo; + /* We use this field to record param for prsctp policies, + * for TTL policy, it is the time_to_drop of this chunk, + * for RTX policy, it is the max_sent_count of this chunk, + * for PRIO policy, it is the priority of this chunk. + */ + unsigned long prsctp_param; + + /* How many times this chunk have been sent, for prsctp RTX policy */ + int sent_count; + /* Which association does this belong to? */ struct sctp_association *asoc; diff --git a/net/sctp/chunk.c b/net/sctp/chunk.c index 1eb94bf..2698d12 100644 --- a/net/sctp/chunk.c +++ b/net/sctp/chunk.c @@ -335,13 +335,27 @@ errout: /* Check whether this message has expired. */ int sctp_chunk_abandoned(struct sctp_chunk *chunk) { - struct sctp_datamsg *msg = chunk->msg; + if (!chunk->asoc->prsctp_enable || + !SCTP_PR_POLICY(chunk->sinfo.sinfo_flags)) { + struct sctp_datamsg *msg = chunk->msg; + + if (!msg->can_abandon) + return 0; + + if (time_after(jiffies, msg->expires_at)) + return 1; - if (!msg->can_abandon) return 0; + } - if (time_after(jiffies, msg->expires_at)) + if (SCTP_PR_TTL_ENABLED(chunk->sinfo.sinfo_flags) && + time_after(jiffies, chunk->prsctp_param)) { + if (chunk->sent_count) + chunk->asoc->abandoned_sent[SCTP_PR_INDEX(TTL)]++; + else + chunk->asoc->abandoned_unsent[SCTP_PR_INDEX(TTL)]++; return 1; + } return 0; } diff --git a/net/sctp/output.c b/net/sctp/output.c index 2e9223b..7425f6c 100644 --- a/net/sctp/output.c +++ b/net/sctp/output.c @@ -316,6 +316,8 @@ static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet, packet->has_data = 1; /* timestamp the chunk for rtx purposes */ chunk->sent_at = jiffies; + /* Mainly used for prsctp RTX policy */ + chunk->sent_count++; break; case SCTP_CID_COOKIE_ECHO: packet->has_cookie_echo = 1; diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 0e3045e..2c431ee 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -711,6 +711,17 @@ nodata: return retval; } +static void sctp_set_prsctp_policy(struct sctp_chunk *chunk, + const struct sctp_sndrcvinfo *sinfo) +{ + if (!chunk->asoc->prsctp_enable) + return; + + if (SCTP_PR_TTL_ENABLED(sinfo->sinfo_flags)) + chunk->prsctp_param = + jiffies + msecs_to_jiffies(sinfo->sinfo_timetolive); +} + /* Make a DATA chunk for the given association from the provided * parameters. However, do not populate the data payload. */ @@ -744,6 +755,7 @@ struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc, retval->subh.data_hdr = sctp_addto_chunk(retval, sizeof(dp), &dp); memcpy(&retval->sinfo, sinfo, sizeof(struct sctp_sndrcvinfo)); + sctp_set_prsctp_policy(retval, sinfo); nodata: return retval; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index c3167c4..0861429 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -7099,7 +7099,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs) if (cmsgs->srinfo->sinfo_flags & ~(SCTP_UNORDERED | SCTP_ADDR_OVER | - SCTP_SACK_IMMEDIATELY | + SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF)) return -EINVAL; break; @@ -7123,7 +7123,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs) if (cmsgs->sinfo->snd_flags & ~(SCTP_UNORDERED | SCTP_ADDR_OVER | - SCTP_SACK_IMMEDIATELY | + SCTP_SACK_IMMEDIATELY | SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF)) return -EINVAL; break;