aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/net/sctp/structs.h3
-rw-r--r--include/net/sctp/ulpevent.h5
-rw-r--r--include/uapi/linux/sctp.h32
-rw-r--r--net/sctp/socket.c49
-rw-r--r--net/sctp/ulpevent.c25
5 files changed, 105 insertions, 9 deletions
diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index 7af9a0f5d8ce..11d5df015370 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -207,7 +207,9 @@ struct sctp_sock {
207 struct sctp_paddrparams paddrparam; 207 struct sctp_paddrparams paddrparam;
208 struct sctp_event_subscribe subscribe; 208 struct sctp_event_subscribe subscribe;
209 struct sctp_assocparams assocparams; 209 struct sctp_assocparams assocparams;
210
210 int user_frag; 211 int user_frag;
212
211 __u32 autoclose; 213 __u32 autoclose;
212 __u8 nodelay; 214 __u8 nodelay;
213 __u8 disable_fragments; 215 __u8 disable_fragments;
@@ -215,6 +217,7 @@ struct sctp_sock {
215 __u8 frag_interleave; 217 __u8 frag_interleave;
216 __u32 adaptation_ind; 218 __u32 adaptation_ind;
217 __u32 pd_point; 219 __u32 pd_point;
220 __u8 recvrcvinfo;
218 221
219 atomic_t pd_mode; 222 atomic_t pd_mode;
220 /* Receive to here while partial delivery is in effect. */ 223 /* Receive to here while partial delivery is in effect. */
diff --git a/include/net/sctp/ulpevent.h b/include/net/sctp/ulpevent.h
index daacb32b55b5..e8095f973e94 100644
--- a/include/net/sctp/ulpevent.h
+++ b/include/net/sctp/ulpevent.h
@@ -129,7 +129,10 @@ struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
129 const struct sctp_association *asoc, gfp_t gfp); 129 const struct sctp_association *asoc, gfp_t gfp);
130 130
131void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event, 131void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
132 struct msghdr *); 132 struct msghdr *);
133void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event,
134 struct msghdr *);
135
133__u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event); 136__u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);
134 137
135/* Is this event type enabled? */ 138/* Is this event type enabled? */
diff --git a/include/uapi/linux/sctp.h b/include/uapi/linux/sctp.h
index a387761f7e02..29b81bbfc53d 100644
--- a/include/uapi/linux/sctp.h
+++ b/include/uapi/linux/sctp.h
@@ -95,6 +95,7 @@ typedef __s32 sctp_assoc_t;
95#define SCTP_GET_ASSOC_ID_LIST 29 /* Read only */ 95#define SCTP_GET_ASSOC_ID_LIST 29 /* Read only */
96#define SCTP_AUTO_ASCONF 30 96#define SCTP_AUTO_ASCONF 30
97#define SCTP_PEER_ADDR_THLDS 31 97#define SCTP_PEER_ADDR_THLDS 31
98#define SCTP_RECVRCVINFO 32
98 99
99/* Internal Socket Options. Some of the sctp library functions are 100/* Internal Socket Options. Some of the sctp library functions are
100 * implemented using these socket options. 101 * implemented using these socket options.
@@ -110,8 +111,7 @@ typedef __s32 sctp_assoc_t;
110#define SCTP_SOCKOPT_CONNECTX3 111 /* CONNECTX requests (updated) */ 111#define SCTP_SOCKOPT_CONNECTX3 111 /* CONNECTX requests (updated) */
111#define SCTP_GET_ASSOC_STATS 112 /* Read only */ 112#define SCTP_GET_ASSOC_STATS 112 /* Read only */
112 113
113/* 114/* 5.3.1 SCTP Initiation Structure (SCTP_INIT)
114 * 5.2.1 SCTP Initiation Structure (SCTP_INIT)
115 * 115 *
116 * This cmsghdr structure provides information for initializing new 116 * This cmsghdr structure provides information for initializing new
117 * SCTP associations with sendmsg(). The SCTP_INITMSG socket option 117 * SCTP associations with sendmsg(). The SCTP_INITMSG socket option
@@ -121,7 +121,6 @@ typedef __s32 sctp_assoc_t;
121 * cmsg_level cmsg_type cmsg_data[] 121 * cmsg_level cmsg_type cmsg_data[]
122 * ------------ ------------ ---------------------- 122 * ------------ ------------ ----------------------
123 * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg 123 * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg
124 *
125 */ 124 */
126struct sctp_initmsg { 125struct sctp_initmsg {
127 __u16 sinit_num_ostreams; 126 __u16 sinit_num_ostreams;
@@ -130,8 +129,7 @@ struct sctp_initmsg {
130 __u16 sinit_max_init_timeo; 129 __u16 sinit_max_init_timeo;
131}; 130};
132 131
133/* 132/* 5.3.2 SCTP Header Information Structure (SCTP_SNDRCV)
134 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
135 * 133 *
136 * This cmsghdr structure specifies SCTP options for sendmsg() and 134 * This cmsghdr structure specifies SCTP options for sendmsg() and
137 * describes SCTP header information about a received message through 135 * describes SCTP header information about a received message through
@@ -140,7 +138,6 @@ struct sctp_initmsg {
140 * cmsg_level cmsg_type cmsg_data[] 138 * cmsg_level cmsg_type cmsg_data[]
141 * ------------ ------------ ---------------------- 139 * ------------ ------------ ----------------------
142 * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo 140 * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo
143 *
144 */ 141 */
145struct sctp_sndrcvinfo { 142struct sctp_sndrcvinfo {
146 __u16 sinfo_stream; 143 __u16 sinfo_stream;
@@ -170,13 +167,32 @@ struct sctp_sndinfo {
170 sctp_assoc_t snd_assoc_id; 167 sctp_assoc_t snd_assoc_id;
171}; 168};
172 169
170/* 5.3.5 SCTP Receive Information Structure (SCTP_RCVINFO)
171 *
172 * This cmsghdr structure describes SCTP receive information
173 * about a received message through recvmsg().
174 *
175 * cmsg_level cmsg_type cmsg_data[]
176 * ------------ ------------ -------------------
177 * IPPROTO_SCTP SCTP_RCVINFO struct sctp_rcvinfo
178 */
179struct sctp_rcvinfo {
180 __u16 rcv_sid;
181 __u16 rcv_ssn;
182 __u16 rcv_flags;
183 __u32 rcv_ppid;
184 __u32 rcv_tsn;
185 __u32 rcv_cumtsn;
186 __u32 rcv_context;
187 sctp_assoc_t rcv_assoc_id;
188};
189
173/* 190/*
174 * sinfo_flags: 16 bits (unsigned integer) 191 * sinfo_flags: 16 bits (unsigned integer)
175 * 192 *
176 * This field may contain any of the following flags and is composed of 193 * This field may contain any of the following flags and is composed of
177 * a bitwise OR of these values. 194 * a bitwise OR of these values.
178 */ 195 */
179
180enum sctp_sinfo_flags { 196enum sctp_sinfo_flags {
181 SCTP_UNORDERED = 1, /* Send/receive message unordered. */ 197 SCTP_UNORDERED = 1, /* Send/receive message unordered. */
182 SCTP_ADDR_OVER = 2, /* Override the primary destination. */ 198 SCTP_ADDR_OVER = 2, /* Override the primary destination. */
@@ -199,6 +215,8 @@ typedef enum sctp_cmsg_type {
199#define SCTP_SNDRCV SCTP_SNDRCV 215#define SCTP_SNDRCV SCTP_SNDRCV
200 SCTP_SNDINFO, /* 5.3.4 SCTP Send Information Structure */ 216 SCTP_SNDINFO, /* 5.3.4 SCTP Send Information Structure */
201#define SCTP_SNDINFO SCTP_SNDINFO 217#define SCTP_SNDINFO SCTP_SNDINFO
218 SCTP_RCVINFO, /* 5.3.5 SCTP Receive Information Structure */
219#define SCTP_RCVINFO SCTP_RCVINFO
202} sctp_cmsg_t; 220} sctp_cmsg_t;
203 221
204/* 222/*
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index d61729e99856..9c193887c5cd 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2112,9 +2112,13 @@ static int sctp_recvmsg(struct kiocb *iocb, struct sock *sk,
2112 sp->pf->skb_msgname(skb, msg->msg_name, addr_len); 2112 sp->pf->skb_msgname(skb, msg->msg_name, addr_len);
2113 } 2113 }
2114 2114
2115 /* Check if we allow SCTP_RCVINFO. */
2116 if (sp->recvrcvinfo)
2117 sctp_ulpevent_read_rcvinfo(event, msg);
2115 /* Check if we allow SCTP_SNDRCVINFO. */ 2118 /* Check if we allow SCTP_SNDRCVINFO. */
2116 if (sp->subscribe.sctp_data_io_event) 2119 if (sp->subscribe.sctp_data_io_event)
2117 sctp_ulpevent_read_sndrcvinfo(event, msg); 2120 sctp_ulpevent_read_sndrcvinfo(event, msg);
2121
2118#if 0 2122#if 0
2119 /* FIXME: we should be calling IP/IPv6 layers. */ 2123 /* FIXME: we should be calling IP/IPv6 layers. */
2120 if (sk->sk_protinfo.af_inet.cmsg_flags) 2124 if (sk->sk_protinfo.af_inet.cmsg_flags)
@@ -3541,7 +3545,6 @@ static int sctp_setsockopt_auto_asconf(struct sock *sk, char __user *optval,
3541 return 0; 3545 return 0;
3542} 3546}
3543 3547
3544
3545/* 3548/*
3546 * SCTP_PEER_ADDR_THLDS 3549 * SCTP_PEER_ADDR_THLDS
3547 * 3550 *
@@ -3592,6 +3595,22 @@ static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
3592 return 0; 3595 return 0;
3593} 3596}
3594 3597
3598static int sctp_setsockopt_recvrcvinfo(struct sock *sk,
3599 char __user *optval,
3600 unsigned int optlen)
3601{
3602 int val;
3603
3604 if (optlen < sizeof(int))
3605 return -EINVAL;
3606 if (get_user(val, (int __user *) optval))
3607 return -EFAULT;
3608
3609 sctp_sk(sk)->recvrcvinfo = (val == 0) ? 0 : 1;
3610
3611 return 0;
3612}
3613
3595/* API 6.2 setsockopt(), getsockopt() 3614/* API 6.2 setsockopt(), getsockopt()
3596 * 3615 *
3597 * Applications use setsockopt() and getsockopt() to set or retrieve 3616 * Applications use setsockopt() and getsockopt() to set or retrieve
@@ -3743,6 +3762,9 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
3743 case SCTP_PEER_ADDR_THLDS: 3762 case SCTP_PEER_ADDR_THLDS:
3744 retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen); 3763 retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen);
3745 break; 3764 break;
3765 case SCTP_RECVRCVINFO:
3766 retval = sctp_setsockopt_recvrcvinfo(sk, optval, optlen);
3767 break;
3746 default: 3768 default:
3747 retval = -ENOPROTOOPT; 3769 retval = -ENOPROTOOPT;
3748 break; 3770 break;
@@ -3989,6 +4011,8 @@ static int sctp_init_sock(struct sock *sk)
3989 /* Enable Nagle algorithm by default. */ 4011 /* Enable Nagle algorithm by default. */
3990 sp->nodelay = 0; 4012 sp->nodelay = 0;
3991 4013
4014 sp->recvrcvinfo = 0;
4015
3992 /* Enable by default. */ 4016 /* Enable by default. */
3993 sp->v4mapped = 1; 4017 sp->v4mapped = 1;
3994 4018
@@ -5770,6 +5794,26 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
5770 return 0; 5794 return 0;
5771} 5795}
5772 5796
5797static int sctp_getsockopt_recvrcvinfo(struct sock *sk, int len,
5798 char __user *optval,
5799 int __user *optlen)
5800{
5801 int val = 0;
5802
5803 if (len < sizeof(int))
5804 return -EINVAL;
5805
5806 len = sizeof(int);
5807 if (sctp_sk(sk)->recvrcvinfo)
5808 val = 1;
5809 if (put_user(len, optlen))
5810 return -EFAULT;
5811 if (copy_to_user(optval, &val, len))
5812 return -EFAULT;
5813
5814 return 0;
5815}
5816
5773static int sctp_getsockopt(struct sock *sk, int level, int optname, 5817static int sctp_getsockopt(struct sock *sk, int level, int optname,
5774 char __user *optval, int __user *optlen) 5818 char __user *optval, int __user *optlen)
5775{ 5819{
@@ -5913,6 +5957,9 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
5913 case SCTP_GET_ASSOC_STATS: 5957 case SCTP_GET_ASSOC_STATS:
5914 retval = sctp_getsockopt_assoc_stats(sk, len, optval, optlen); 5958 retval = sctp_getsockopt_assoc_stats(sk, len, optval, optlen);
5915 break; 5959 break;
5960 case SCTP_RECVRCVINFO:
5961 retval = sctp_getsockopt_recvrcvinfo(sk, len, optval, optlen);
5962 break;
5916 default: 5963 default:
5917 retval = -ENOPROTOOPT; 5964 retval = -ENOPROTOOPT;
5918 break; 5965 break;
diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
index b6842fdb53d4..b31f365f18ab 100644
--- a/net/sctp/ulpevent.c
+++ b/net/sctp/ulpevent.c
@@ -886,6 +886,31 @@ void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
886 sizeof(sinfo), &sinfo); 886 sizeof(sinfo), &sinfo);
887} 887}
888 888
889/* RFC6458, Section 5.3.5 SCTP Receive Information Structure
890 * (SCTP_SNDRCV)
891 */
892void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event,
893 struct msghdr *msghdr)
894{
895 struct sctp_rcvinfo rinfo;
896
897 if (sctp_ulpevent_is_notification(event))
898 return;
899
900 memset(&rinfo, 0, sizeof(struct sctp_rcvinfo));
901 rinfo.rcv_sid = event->stream;
902 rinfo.rcv_ssn = event->ssn;
903 rinfo.rcv_ppid = event->ppid;
904 rinfo.rcv_flags = event->flags;
905 rinfo.rcv_tsn = event->tsn;
906 rinfo.rcv_cumtsn = event->cumtsn;
907 rinfo.rcv_assoc_id = sctp_assoc2id(event->asoc);
908 rinfo.rcv_context = event->asoc->default_rcv_context;
909
910 put_cmsg(msghdr, IPPROTO_SCTP, SCTP_RCVINFO,
911 sizeof(rinfo), &rinfo);
912}
913
889/* Do accounting for bytes received and hold a reference to the association 914/* Do accounting for bytes received and hold a reference to the association
890 * for each skb. 915 * for each skb.
891 */ 916 */