From patchwork Sat Jul 9 11:47:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 646671 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 3rmqPC5LSqz9sdg for ; Sat, 9 Jul 2016 21:48:15 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=gYorlGwh; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932945AbcGILsN (ORCPT ); Sat, 9 Jul 2016 07:48:13 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33148 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756754AbcGILsG (ORCPT ); Sat, 9 Jul 2016 07:48:06 -0400 Received: by mail-pf0-f196.google.com with SMTP id c74so10243992pfb.0; Sat, 09 Jul 2016 04:48:06 -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=vjGd5p4nM5eQHyRMEFAuyDGyKkRcn68RTJMfQgSTNHQ=; b=gYorlGwhJVgj6/qthXLFzKIvxJ+2Ia8LaO82GjEPCmB9MR4pZkCuw0KirrYsN6vQbh Moe7bJ2fBRHcXAi9z9KfJ3yd9dZfNLQtHHl+BbjWX7y2HowTw1mecLw78fqs253fFBfz PtMrX4LWwSbIo3mTloZecPs6GgCwiYPYScK3dNIrGdGIGZYYevAsw6p4QpWbrEvq8BaV l+Mj8fxWE6fw4NCG6j499CoEYaaLJ/oQtC2nxKSuMltJPS2iog7rGaWtrBvjE5QYeM3t GYiatoLA2xSKPXgJssEh+wM4x/VbiwPY6cl7SThcxigwzLvBHT/8C+KPUh19lzB05/Ms sqSQ== 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=vjGd5p4nM5eQHyRMEFAuyDGyKkRcn68RTJMfQgSTNHQ=; b=b82/iFkL4knL/qmVs7ctnhKDONZdzLaq1PL16DYtLoP+10m8NU1jfz7wPfNqItaW6t C+IMdqzQRimcyQX+sy800C+8bCd3DRhhy2tWis9L0OuTmMkDqcHlqjv/anvBz14Qty6y hyXYfZM0xb4XGrQJiQGWkthxSj+awyQgN8tR8tVKgvEvgID6dTG3visvImGPof1FaWYE R0H3Ltttl1Y4Fb9Oonyvs9jcfPV2pedTklt4IwKe2peJ+24uX7cI41H/3WdgvpSf9kiY hIGtJcKrE8vn3M2J8s1mDHrIREbw6E6XZbCDfpDiSyTu7kzEFqhbbQCojWBmaWBq23TJ Ikmw== X-Gm-Message-State: ALyK8tIN0ERLLjKvW68su08E7QkQp0zb3V4I8fMsYofkLOFs2PRwfV9T8MYM+mbHuhVnbA== X-Received: by 10.98.30.199 with SMTP id e190mr18137950pfe.146.1468064885910; Sat, 09 Jul 2016 04:48:05 -0700 (PDT) Received: from localhost (138.128.208.20.16clouds.com. [138.128.208.20]) by smtp.gmail.com with ESMTPSA id h4sm3571321pfk.47.2016.07.09.04.48.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jul 2016 04:48:05 -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 3/6] sctp: add SCTP_PR_ASSOC_STATUS on sctp sockopt Date: Sat, 9 Jul 2016 19:47:42 +0800 Message-Id: <63a9a850836134ba72b9377e8b99694d869e3fba.1468064737.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <2b9ceacb55912e29c2d970772d0267e465c33dff.1468064737.git.lucien.xin@gmail.com> References: <121aa41aceff56b3dda51c41b8f3c4d8662d65b7.1468064737.git.lucien.xin@gmail.com> <2b9ceacb55912e29c2d970772d0267e465c33dff.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 This patch adds SCTP_PR_ASSOC_STATUS to sctp sockopt, which is used to dump the prsctp statistics info from the asoc. The prsctp statistics includes abandoned_sent/unsent from the asoc. abandoned_sent is the count of the packets we drop packets from retransmit/transmited queue, and abandoned_unsent is the count of the packets we drop from out_queue according to the policy. Note: another option for prsctp statistics dump described in rfc is SCTP_PR_STREAM_STATUS, which is used to dump the prsctp statistics info from each stream. But by now, linux doesn't yet have per stream statistics info, it needs rfc6525 to be implemented. As the prsctp statistics for each stream has to be based on per stream statistics, we will delay it until rfc6525 is done in linux. Signed-off-by: Xin Long --- include/net/sctp/structs.h | 3 +++ include/uapi/linux/sctp.h | 12 +++++++++ net/sctp/socket.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h index 07115ca..d8e464a 100644 --- a/include/net/sctp/structs.h +++ b/include/net/sctp/structs.h @@ -1853,6 +1853,9 @@ struct sctp_association { prsctp_enable:1; struct sctp_priv_assoc_stats stats; + + __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1]; + __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1]; }; diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h index 984cf2e..d304f4c 100644 --- a/include/uapi/linux/sctp.h +++ b/include/uapi/linux/sctp.h @@ -114,6 +114,7 @@ typedef __s32 sctp_assoc_t; #define SCTP_GET_ASSOC_STATS 112 /* Read only */ #define SCTP_PR_SUPPORTED 113 #define SCTP_DEFAULT_PRINFO 114 +#define SCTP_PR_ASSOC_STATUS 115 /* PR-SCTP policies */ #define SCTP_PR_SCTP_NONE 0x0000 @@ -926,6 +927,17 @@ struct sctp_paddrthlds { __u16 spt_pathpfthld; }; +/* + * Socket Option for Getting the Association/Stream-Specific PR-SCTP Status + */ +struct sctp_prstatus { + sctp_assoc_t sprstat_assoc_id; + __u16 sprstat_sid; + __u16 sprstat_policy; + __u64 sprstat_abandoned_unsent; + __u64 sprstat_abandoned_sent; +}; + struct sctp_default_prinfo { sctp_assoc_t pr_assoc_id; __u32 pr_value; diff --git a/net/sctp/socket.c b/net/sctp/socket.c index c03fe1b..c3167c4 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -6330,6 +6330,64 @@ out: return retval; } +static int sctp_getsockopt_pr_assocstatus(struct sock *sk, int len, + char __user *optval, + int __user *optlen) +{ + struct sctp_prstatus params; + struct sctp_association *asoc; + int policy; + int retval = -EINVAL; + + if (len < sizeof(params)) + goto out; + + len = sizeof(params); + if (copy_from_user(¶ms, optval, len)) { + retval = -EFAULT; + goto out; + } + + policy = params.sprstat_policy; + if (policy & ~SCTP_PR_SCTP_MASK) + goto out; + + asoc = sctp_id2assoc(sk, params.sprstat_assoc_id); + if (!asoc) + goto out; + + if (policy == SCTP_PR_SCTP_NONE) { + params.sprstat_abandoned_unsent = 0; + params.sprstat_abandoned_sent = 0; + for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) { + params.sprstat_abandoned_unsent += + asoc->abandoned_unsent[policy]; + params.sprstat_abandoned_sent += + asoc->abandoned_sent[policy]; + } + } else { + params.sprstat_abandoned_unsent = + asoc->abandoned_unsent[__SCTP_PR_INDEX(policy)]; + params.sprstat_abandoned_sent = + asoc->abandoned_sent[__SCTP_PR_INDEX(policy)]; + } + + if (put_user(len, optlen)) { + retval = -EFAULT; + goto out; + } + + if (copy_to_user(optval, ¶ms, len)) { + retval = -EFAULT; + goto out; + } + + retval = 0; + +out: + return retval; +} + static int sctp_getsockopt(struct sock *sk, int level, int optname, char __user *optval, int __user *optlen) { @@ -6490,6 +6548,10 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname, retval = sctp_getsockopt_default_prinfo(sk, len, optval, optlen); break; + case SCTP_PR_ASSOC_STATUS: + retval = sctp_getsockopt_pr_assocstatus(sk, len, optval, + optlen); + break; default: retval = -ENOPROTOOPT; break;