netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt
@ 2019-08-26  8:30 Xin Long
  2019-08-26  8:30 ` [PATCH net-next 1/3] sctp: make ecn flag per netns and endpoint Xin Long
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Xin Long @ 2019-08-26  8:30 UTC (permalink / raw)
  To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem

This patchset is to make ecn flag per netns and endpoint and then
add SCTP_ECN_SUPPORTED sockopt, as does for other feature flags.

Xin Long (3):
  sctp: make ecn flag per netns and endpoint
  sctp: allow users to set netns ecn flag with sysctl
  sctp: allow users to set ep ecn flag by sockopt

 include/net/netns/sctp.h   |  3 ++
 include/net/sctp/structs.h |  3 +-
 include/uapi/linux/sctp.h  |  1 +
 net/sctp/endpointola.c     |  1 +
 net/sctp/protocol.c        |  3 ++
 net/sctp/sm_make_chunk.c   | 16 +++++++---
 net/sctp/socket.c          | 73 ++++++++++++++++++++++++++++++++++++++++++++++
 net/sctp/sysctl.c          |  7 +++++
 8 files changed, 102 insertions(+), 5 deletions(-)

-- 
2.1.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/3] sctp: make ecn flag per netns and endpoint
  2019-08-26  8:30 [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Xin Long
@ 2019-08-26  8:30 ` Xin Long
  2019-08-26  8:30 ` [PATCH net-next 2/3] sctp: allow users to set netns ecn flag with sysctl Xin Long
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Xin Long @ 2019-08-26  8:30 UTC (permalink / raw)
  To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem

This patch is to add ecn flag for both netns_sctp and sctp_endpoint,
net->sctp.ecn_enable is set 1 by default, and ep->ecn_enable will
be initialized with net->sctp.ecn_enable.

asoc->peer.ecn_capable will be set during negotiation only when
ep->ecn_enable is set on both sides.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/net/netns/sctp.h   |  3 +++
 include/net/sctp/structs.h |  3 ++-
 net/sctp/endpointola.c     |  1 +
 net/sctp/protocol.c        |  3 +++
 net/sctp/sm_make_chunk.c   | 16 ++++++++++++----
 5 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/include/net/netns/sctp.h b/include/net/netns/sctp.h
index 0db7fb3..bdc0f27 100644
--- a/include/net/netns/sctp.h
+++ b/include/net/netns/sctp.h
@@ -128,6 +128,9 @@ struct netns_sctp {
 	/* Flag to indicate if stream interleave is enabled */
 	int intl_enable;
 
+	/* Flag to indicate if ecn is enabled */
+	int ecn_enable;
+
 	/*
 	 * Policy to control SCTP IPv4 address scoping
 	 * 0   - Disable IPv4 address scoping
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index daac1ef..503fbc3 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1322,7 +1322,8 @@ struct sctp_endpoint {
 	/* SCTP-AUTH: endpoint shared keys */
 	struct list_head endpoint_shared_keys;
 	__u16 active_key_id;
-	__u8  auth_enable:1,
+	__u8  ecn_enable:1,
+	      auth_enable:1,
 	      intl_enable:1,
 	      prsctp_enable:1,
 	      asconf_enable:1,
diff --git a/net/sctp/endpointola.c b/net/sctp/endpointola.c
index 75a407d..ea53049 100644
--- a/net/sctp/endpointola.c
+++ b/net/sctp/endpointola.c
@@ -106,6 +106,7 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
 	 */
 	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;
diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
index 2d47adc..b48ffe8 100644
--- a/net/sctp/protocol.c
+++ b/net/sctp/protocol.c
@@ -1254,6 +1254,9 @@ static int __net_init sctp_defaults_init(struct net *net)
 	/* Disable AUTH by default. */
 	net->sctp.auth_enable = 0;
 
+	/* Enable ECN by default. */
+	net->sctp.ecn_enable = 1;
+
 	/* Set SCOPE policy to enabled */
 	net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
 
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 338278f..e41ed2e 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -244,7 +244,9 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
 
 	chunksize = sizeof(init) + addrs_len;
 	chunksize += SCTP_PAD4(SCTP_SAT_LEN(num_types));
-	chunksize += sizeof(ecap_param);
+
+	if (asoc->ep->ecn_enable)
+		chunksize += sizeof(ecap_param);
 
 	if (asoc->ep->prsctp_enable)
 		chunksize += sizeof(prsctp_param);
@@ -335,7 +337,8 @@ struct sctp_chunk *sctp_make_init(const struct sctp_association *asoc,
 	sctp_addto_chunk(retval, sizeof(sat), &sat);
 	sctp_addto_chunk(retval, num_types * sizeof(__u16), &types);
 
-	sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
+	if (asoc->ep->ecn_enable)
+		sctp_addto_chunk(retval, sizeof(ecap_param), &ecap_param);
 
 	/* Add the supported extensions parameter.  Be nice and add this
 	 * fist before addiding the parameters for the extensions themselves
@@ -2597,8 +2600,13 @@ static int sctp_process_param(struct sctp_association *asoc,
 		break;
 
 	case SCTP_PARAM_ECN_CAPABLE:
-		asoc->peer.ecn_capable = 1;
-		break;
+		if (asoc->ep->ecn_enable) {
+			asoc->peer.ecn_capable = 1;
+			break;
+		}
+		/* Fall Through */
+		goto fall_through;
+
 
 	case SCTP_PARAM_ADAPTATION_LAYER_IND:
 		asoc->peer.adaptation_ind = ntohl(param.aind->adaptation_ind);
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/3] sctp: allow users to set netns ecn flag with sysctl
  2019-08-26  8:30 [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Xin Long
  2019-08-26  8:30 ` [PATCH net-next 1/3] sctp: make ecn flag per netns and endpoint Xin Long
@ 2019-08-26  8:30 ` Xin Long
  2019-08-26  8:30 ` [PATCH net-next 3/3] sctp: allow users to set ep ecn flag by sockopt Xin Long
  2019-08-26 11:02 ` [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Neil Horman
  3 siblings, 0 replies; 6+ messages in thread
From: Xin Long @ 2019-08-26  8:30 UTC (permalink / raw)
  To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem

sysctl net.sctp.ecn_enable is added in this patch. It will allow
users to change the default sctp ecn flag, net.sctp.ecn_enable.

This feature was also required on this thread:

  http://lkml.iu.edu/hypermail/linux/kernel/0812.1/01858.html

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/sctp/sysctl.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index 1250751..238cf17 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -278,6 +278,13 @@ static struct ctl_table sctp_net_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 	{
+		.procname	= "ecn_enable",
+		.data		= &init_net.sctp.ecn_enable,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
+	{
 		.procname	= "addr_scope_policy",
 		.data		= &init_net.sctp.scope_policy,
 		.maxlen		= sizeof(int),
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 3/3] sctp: allow users to set ep ecn flag by sockopt
  2019-08-26  8:30 [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Xin Long
  2019-08-26  8:30 ` [PATCH net-next 1/3] sctp: make ecn flag per netns and endpoint Xin Long
  2019-08-26  8:30 ` [PATCH net-next 2/3] sctp: allow users to set netns ecn flag with sysctl Xin Long
@ 2019-08-26  8:30 ` Xin Long
  2019-08-26 11:02 ` [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Neil Horman
  3 siblings, 0 replies; 6+ messages in thread
From: Xin Long @ 2019-08-26  8:30 UTC (permalink / raw)
  To: network dev, linux-sctp; +Cc: Marcelo Ricardo Leitner, Neil Horman, davem

SCTP_ECN_SUPPORTED sockopt will be added to allow users to change
ep ecn flag, and it's similar with other feature flags.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 include/uapi/linux/sctp.h |  1 +
 net/sctp/socket.c         | 73 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 62527ac..6d5b164 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -136,6 +136,7 @@ typedef __s32 sctp_assoc_t;
 #define SCTP_EVENT	127
 #define SCTP_ASCONF_SUPPORTED	128
 #define SCTP_AUTH_SUPPORTED	129
+#define SCTP_ECN_SUPPORTED	130
 
 /* PR-SCTP policies */
 #define SCTP_PR_SCTP_NONE	0x0000
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 82bc252..3e50a97 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -4560,6 +4560,34 @@ static int sctp_setsockopt_auth_supported(struct sock *sk,
 	return retval;
 }
 
+static int sctp_setsockopt_ecn_supported(struct sock *sk,
+					 char __user *optval,
+					 unsigned int optlen)
+{
+	struct sctp_assoc_value params;
+	struct sctp_association *asoc;
+	int retval = -EINVAL;
+
+	if (optlen != sizeof(params))
+		goto out;
+
+	if (copy_from_user(&params, optval, optlen)) {
+		retval = -EFAULT;
+		goto out;
+	}
+
+	asoc = sctp_id2assoc(sk, params.assoc_id);
+	if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+	    sctp_style(sk, UDP))
+		goto out;
+
+	sctp_sk(sk)->ep->ecn_enable = !!params.assoc_value;
+	retval = 0;
+
+out:
+	return retval;
+}
+
 /* API 6.2 setsockopt(), getsockopt()
  *
  * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -4766,6 +4794,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
 	case SCTP_AUTH_SUPPORTED:
 		retval = sctp_setsockopt_auth_supported(sk, optval, optlen);
 		break;
+	case SCTP_ECN_SUPPORTED:
+		retval = sctp_setsockopt_ecn_supported(sk, optval, optlen);
+		break;
 	default:
 		retval = -ENOPROTOOPT;
 		break;
@@ -7828,6 +7859,45 @@ static int sctp_getsockopt_auth_supported(struct sock *sk, int len,
 	return retval;
 }
 
+static int sctp_getsockopt_ecn_supported(struct sock *sk, int len,
+					 char __user *optval,
+					 int __user *optlen)
+{
+	struct sctp_assoc_value params;
+	struct sctp_association *asoc;
+	int retval = -EFAULT;
+
+	if (len < sizeof(params)) {
+		retval = -EINVAL;
+		goto out;
+	}
+
+	len = sizeof(params);
+	if (copy_from_user(&params, optval, len))
+		goto out;
+
+	asoc = sctp_id2assoc(sk, params.assoc_id);
+	if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
+	    sctp_style(sk, UDP)) {
+		retval = -EINVAL;
+		goto out;
+	}
+
+	params.assoc_value = asoc ? asoc->peer.ecn_capable
+				  : sctp_sk(sk)->ep->ecn_enable;
+
+	if (put_user(len, optlen))
+		goto out;
+
+	if (copy_to_user(optval, &params, len))
+		goto out;
+
+	retval = 0;
+
+out:
+	return retval;
+}
+
 static int sctp_getsockopt(struct sock *sk, int level, int optname,
 			   char __user *optval, int __user *optlen)
 {
@@ -8037,6 +8107,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
 		retval = sctp_getsockopt_auth_supported(sk, len, optval,
 							optlen);
 		break;
+	case SCTP_ECN_SUPPORTED:
+		retval = sctp_getsockopt_ecn_supported(sk, len, optval, optlen);
+		break;
 	default:
 		retval = -ENOPROTOOPT;
 		break;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt
  2019-08-26  8:30 [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Xin Long
                   ` (2 preceding siblings ...)
  2019-08-26  8:30 ` [PATCH net-next 3/3] sctp: allow users to set ep ecn flag by sockopt Xin Long
@ 2019-08-26 11:02 ` Neil Horman
  2019-08-28  3:55   ` David Miller
  3 siblings, 1 reply; 6+ messages in thread
From: Neil Horman @ 2019-08-26 11:02 UTC (permalink / raw)
  To: Xin Long; +Cc: network dev, linux-sctp, Marcelo Ricardo Leitner, davem

On Mon, Aug 26, 2019 at 04:30:01PM +0800, Xin Long wrote:
> This patchset is to make ecn flag per netns and endpoint and then
> add SCTP_ECN_SUPPORTED sockopt, as does for other feature flags.
> 
> Xin Long (3):
>   sctp: make ecn flag per netns and endpoint
>   sctp: allow users to set netns ecn flag with sysctl
>   sctp: allow users to set ep ecn flag by sockopt
> 
>  include/net/netns/sctp.h   |  3 ++
>  include/net/sctp/structs.h |  3 +-
>  include/uapi/linux/sctp.h  |  1 +
>  net/sctp/endpointola.c     |  1 +
>  net/sctp/protocol.c        |  3 ++
>  net/sctp/sm_make_chunk.c   | 16 +++++++---
>  net/sctp/socket.c          | 73 ++++++++++++++++++++++++++++++++++++++++++++++
>  net/sctp/sysctl.c          |  7 +++++
>  8 files changed, 102 insertions(+), 5 deletions(-)
> 
> -- 
> 2.1.0
> 
> 
Series
Acked-by: Neil Horman <nhorman@tuxdriver.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt
  2019-08-26 11:02 ` [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Neil Horman
@ 2019-08-28  3:55   ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2019-08-28  3:55 UTC (permalink / raw)
  To: nhorman; +Cc: lucien.xin, netdev, linux-sctp, marcelo.leitner

From: Neil Horman <nhorman@tuxdriver.com>
Date: Mon, 26 Aug 2019 07:02:21 -0400

> On Mon, Aug 26, 2019 at 04:30:01PM +0800, Xin Long wrote:
>> This patchset is to make ecn flag per netns and endpoint and then
>> add SCTP_ECN_SUPPORTED sockopt, as does for other feature flags.
>> 
>> Xin Long (3):
>>   sctp: make ecn flag per netns and endpoint
>>   sctp: allow users to set netns ecn flag with sysctl
>>   sctp: allow users to set ep ecn flag by sockopt
 ...
> Series
> Acked-by: Neil Horman <nhorman@tuxdriver.com>

Series applied to net-next, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-28  3:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-26  8:30 [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Xin Long
2019-08-26  8:30 ` [PATCH net-next 1/3] sctp: make ecn flag per netns and endpoint Xin Long
2019-08-26  8:30 ` [PATCH net-next 2/3] sctp: allow users to set netns ecn flag with sysctl Xin Long
2019-08-26  8:30 ` [PATCH net-next 3/3] sctp: allow users to set ep ecn flag by sockopt Xin Long
2019-08-26 11:02 ` [PATCH net-next 0/3] sctp: add SCTP_ECN_SUPPORTED sockopt Neil Horman
2019-08-28  3:55   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).