netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geir Ola Vaagland <geirola@gmail.com>
To: netdev@vger.kernel.org
Cc: linux-sctp@vger.kernel.org, Vlad Yasevich <vyasevich@gmail.com>
Subject: [PATCH net-next 6/6] Support for SCTP_DEFAULT_SNDINFO socket option
Date: Tue, 17 Jun 2014 13:57:53 +0200	[thread overview]
Message-ID: <1403006273-27859-7-git-send-email-geirola@gmail.com> (raw)
In-Reply-To: <1403006273-27859-1-git-send-email-geirola@gmail.com>

CC: Vlad Yasevich <vyasevich@gmail.com>
Signed-off-by: Geir Ola Vaagland <geirola@gmail.com>
---
 include/uapi/linux/sctp.h |  1 +
 net/sctp/socket.c         | 94 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+)

diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index 986563e..133df4e 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -99,6 +99,7 @@ typedef __s32 sctp_assoc_t;
 
 #define SCTP_RECVRCVINFO 32
 #define SCTP_RECVNXTINFO 33
+#define SCTP_DEFAULT_SNDINFO 34
 
 /* Internal Socket Options. Some of the sctp library functions are
  * implemented using these socket options.
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 57106e8..a725376 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2801,6 +2801,55 @@ static int sctp_setsockopt_default_send_param(struct sock *sk,
 
 	return 0;
 }
+/*
+ * 8.1.31. Set Default Send Parameters (SCTP_DEFAULT_SNDINFO)
+ *
+ *   Applications that wish to use the sendto() system call may wish to
+ *   specify a default set of parameters that would normally be supplied
+ *   through the inclusion of ancillary data.  This socket option allows
+ *   such an application to set the default sctp_sndinfo structure.  The
+ *   application that wishes to use this socket option simply passes the
+ *   sctp_sndinfo structure (defined in Section 5.3.4) to this call.  The
+ *   input parameters accepted by this call include snd_sid, snd_flags,
+ *   snd_ppid, and snd_context.  The snd_flags parameter is composed of a
+ *   bitwise OR of SCTP_UNORDERED, SCTP_EOF, and SCTP_SENDALL.  The
+ *   snd_assoc_id field specifies the association to which to apply the
+ *   parameters.  For a one-to-many style socket, any of the predefined
+ *   constants are also allowed in this field.  The field is ignored for
+ *   one-to-one style sockets.
+ */
+static int sctp_setsockopt_default_sndinfo(struct sock *sk,
+		char __user *optval,
+		unsigned int optlen){
+	struct sctp_sndinfo info;
+	struct sctp_association *asoc;
+	struct sctp_sock *sp = sctp_sk(sk);
+
+	if (optlen != sizeof(struct sctp_sndinfo))
+		return -EINVAL;
+	if (copy_from_user(&info, optval, optlen))
+		return -EFAULT;
+
+	asoc = sctp_id2assoc(sk, info.snd_assoc_id);
+	if (!asoc && info.snd_assoc_id && sctp_style(sk, UDP))
+		return -EINVAL;
+
+	/* Note! asoc->default_timetolive is not set in this way anymore.
+	 * The PR-SCTP extension needs to be implemented.  */
+	if (asoc) {
+		asoc->default_stream = info.snd_sid;
+		asoc->default_flags = info.snd_flags;
+		asoc->default_ppid = info.snd_ppid;
+		asoc->default_context = info.snd_context;
+	} else {
+		sp->default_stream = info.snd_sid;
+		sp->default_flags = info.snd_flags;
+		sp->default_ppid = info.snd_ppid;
+		sp->default_context = info.snd_context;
+	}
+	return 0;
+}
+
 
 /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
  *
@@ -3724,6 +3773,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
 		retval = sctp_setsockopt_default_send_param(sk, optval,
 							    optlen);
 		break;
+	case SCTP_DEFAULT_SNDINFO:
+		retval = sctp_setsockopt_default_sndinfo(sk, optval, optlen);
+		break;
 	case SCTP_PRIMARY_ADDR:
 		retval = sctp_setsockopt_primary_addr(sk, optval, optlen);
 		break;
@@ -5063,6 +5115,45 @@ static int sctp_getsockopt_default_send_param(struct sock *sk,
 
 	return 0;
 }
+static int sctp_getsockopt_default_sndinfo(struct sock *sk,
+		int len, char __user *optval,
+		int __user *optlen)
+{
+	struct sctp_sndinfo info;
+	struct sctp_association *asoc;
+	struct sctp_sock *sp = sctp_sk(sk);
+
+	if (len < sizeof(struct sctp_sndinfo))
+		return -EINVAL;
+
+	len = sizeof(struct sctp_sndinfo);
+
+	if (copy_from_user(&info, optval, len))
+		return -EFAULT;
+
+	asoc = sctp_id2assoc(sk, info.snd_assoc_id);
+	if (!asoc && info.snd_assoc_id && sctp_style(sk, UDP))
+		return -EINVAL;
+
+	if (asoc) {
+		info.snd_sid = asoc->default_stream;
+		info.snd_flags = asoc->default_flags;
+		info.snd_ppid = asoc->default_ppid;
+		info.snd_context = asoc->default_context;
+	} else {
+		info.snd_sid = sp->default_stream;
+		info.snd_flags = sp->default_flags;
+		info.snd_ppid = sp->default_ppid;
+		info.snd_context = sp->default_context;
+	}
+
+	if (put_user(len, optlen))
+		return -EFAULT;
+	if (copy_to_user(optval, &info, len))
+		return -EFAULT;
+
+	return 0;
+}
 
 /*
  *
@@ -5917,6 +6008,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
 		retval = sctp_getsockopt_default_send_param(sk, len,
 							    optval, optlen);
 		break;
+	case SCTP_DEFAULT_SNDINFO:
+		retval = sctp_getsockopt_default_sndinfo(sk, len, optval, optlen);
+		break;
 	case SCTP_PRIMARY_ADDR:
 		retval = sctp_getsockopt_primary_addr(sk, len, optval, optlen);
 		break;

  parent reply	other threads:[~2014-06-17 11:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-17 11:57 [PATCH net-next 0/6] A step closer to RFC 6458 compliancy Geir Ola Vaagland
2014-06-17 11:57 ` [PATCH net-next 1/6] Support for SCTP_RECVRCVINFO socket option Geir Ola Vaagland
2014-06-17 12:35   ` David Laight
2014-06-17 13:57   ` Vlad Yasevich
2014-06-17 11:57 ` [PATCH net-next 2/6] Support for SCTP_RCVINFO ancillary data Geir Ola Vaagland
2014-06-17 12:36   ` David Laight
2014-06-17 14:07   ` Vlad Yasevich
2014-06-17 11:57 ` [PATCH net-next 3/6] Support for SCTP_SNDINFO " Geir Ola Vaagland
2014-06-17 12:38   ` David Laight
2014-06-17 14:29     ` Vlad Yasevich
2014-06-17 14:42       ` David Laight
2014-06-17 11:57 ` [PATCH net-next 4/6] Support for SCTP_NXTINFO socket option Geir Ola Vaagland
2014-06-17 11:57 ` [PATCH net-next 5/6] Support for receiving SCTP_NXTINFO ancillary data Geir Ola Vaagland
2014-06-17 11:57 ` Geir Ola Vaagland [this message]
2014-06-17 12:32 ` [PATCH net-next 0/6] A step closer to RFC 6458 compliancy David Laight
2014-06-17 13:40 ` Vlad Yasevich
  -- strict thread matches above, loose matches on Subject: below --
2014-06-17 15:01 Geir Ola Vaagland
2014-06-17 15:01 ` [PATCH net-next 6/6] Support for SCTP_DEFAULT_SNDINFO socket option Geir Ola Vaagland
2014-06-18 23:33   ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403006273-27859-7-git-send-email-geirola@gmail.com \
    --to=geirola@gmail.com \
    --cc=linux-sctp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vyasevich@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).