Commit 2cbf5b42 authored by David S. Miller's avatar David S. Miller

Merge branch 'sctp-sender-stream-reconf-reset-add-streams'

Xin Long says:

====================
sctp: add sender-side procedures for stream reconf asoc reset and add streams

Patch 4/6 is to implement sender-side procedures for the SSN/TSN Reset
Request Parameter described in rfc6525 section 5.1.4, patch 3/6 is
ahead of it to define a function to make the request chunk for it.

Patch 6/6 is to implement sender-side procedures for the Add Incoming
and Outgoing Streams Request Parameter Request Parameter described in
rfc6525 section 5.1.5 and 5.1.6, patch 5/6 is ahead of it to define a
function to make the request chunk for it.

Patch 2/6 is a fix to recover streams states when it fails to send
request and Patch 1/6 is to drop some unncessary __packed from some
old structures.

v1->v2:
  - put these into a smaller group.
  - rename some temporary variables in the codes.
  - rename the titles of the commits and improve some changelogs.
v2->v3:
  - re-split the patchset and make sure it has no dead codes for review.
  - move some codes into stream.c from socket.c.
v3->v4:
  - add one more patch to fix a send reset stream request issue.
  - doing actual work only when request is sent successfully.
  - reduce some indents in sctp_send_add_streams.
v4->v5:
  - close streams before sending request and recover them when sending
    fails in patch 1/5 and patch 3/5
v5->v6:
  - add patch 1/6 to drop some unncessary __packed from some old structures.
  - remove __packed from some new structures in patch 3/6 and 5/6.
  - define unsigned int outcnt and incnt to make codes smaller in patch 6/6.
  - use krealloc instead of kcalloc and remove ksize check in patch 6/6, as
    ksize check is acutally used in krealloc already.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents caa2858c 242bd2d5
...@@ -721,7 +721,7 @@ struct sctp_infox { ...@@ -721,7 +721,7 @@ struct sctp_infox {
struct sctp_reconf_chunk { struct sctp_reconf_chunk {
sctp_chunkhdr_t chunk_hdr; sctp_chunkhdr_t chunk_hdr;
__u8 params[0]; __u8 params[0];
} __packed; };
struct sctp_strreset_outreq { struct sctp_strreset_outreq {
sctp_paramhdr_t param_hdr; sctp_paramhdr_t param_hdr;
...@@ -729,12 +729,24 @@ struct sctp_strreset_outreq { ...@@ -729,12 +729,24 @@ struct sctp_strreset_outreq {
__u32 response_seq; __u32 response_seq;
__u32 send_reset_at_tsn; __u32 send_reset_at_tsn;
__u16 list_of_streams[0]; __u16 list_of_streams[0];
} __packed; };
struct sctp_strreset_inreq { struct sctp_strreset_inreq {
sctp_paramhdr_t param_hdr; sctp_paramhdr_t param_hdr;
__u32 request_seq; __u32 request_seq;
__u16 list_of_streams[0]; __u16 list_of_streams[0];
} __packed; };
struct sctp_strreset_tsnreq {
sctp_paramhdr_t param_hdr;
__u32 request_seq;
};
struct sctp_strreset_addstrm {
sctp_paramhdr_t param_hdr;
__u32 request_seq;
__u16 number_of_streams;
__u16 reserved;
};
#endif /* __LINUX_SCTP_H__ */ #endif /* __LINUX_SCTP_H__ */
...@@ -198,6 +198,9 @@ int sctp_offload_init(void); ...@@ -198,6 +198,9 @@ int sctp_offload_init(void);
*/ */
int sctp_send_reset_streams(struct sctp_association *asoc, int sctp_send_reset_streams(struct sctp_association *asoc,
struct sctp_reset_streams *params); struct sctp_reset_streams *params);
int sctp_send_reset_assoc(struct sctp_association *asoc);
int sctp_send_add_streams(struct sctp_association *asoc,
struct sctp_add_streams *params);
/* /*
* Module global variables * Module global variables
......
...@@ -265,6 +265,11 @@ struct sctp_chunk *sctp_make_strreset_req( ...@@ -265,6 +265,11 @@ struct sctp_chunk *sctp_make_strreset_req(
const struct sctp_association *asoc, const struct sctp_association *asoc,
__u16 stream_num, __u16 *stream_list, __u16 stream_num, __u16 *stream_list,
bool out, bool in); bool out, bool in);
struct sctp_chunk *sctp_make_strreset_tsnreq(
const struct sctp_association *asoc);
struct sctp_chunk *sctp_make_strreset_addstrm(
const struct sctp_association *asoc,
__u16 out, __u16 in);
void sctp_chunk_assign_tsn(struct sctp_chunk *); void sctp_chunk_assign_tsn(struct sctp_chunk *);
void sctp_chunk_assign_ssn(struct sctp_chunk *); void sctp_chunk_assign_ssn(struct sctp_chunk *);
......
...@@ -117,6 +117,8 @@ typedef __s32 sctp_assoc_t; ...@@ -117,6 +117,8 @@ typedef __s32 sctp_assoc_t;
#define SCTP_PR_ASSOC_STATUS 115 #define SCTP_PR_ASSOC_STATUS 115
#define SCTP_ENABLE_STREAM_RESET 118 #define SCTP_ENABLE_STREAM_RESET 118
#define SCTP_RESET_STREAMS 119 #define SCTP_RESET_STREAMS 119
#define SCTP_RESET_ASSOC 120
#define SCTP_ADD_STREAMS 121
/* PR-SCTP policies */ /* PR-SCTP policies */
#define SCTP_PR_SCTP_NONE 0x0000 #define SCTP_PR_SCTP_NONE 0x0000
...@@ -1026,4 +1028,10 @@ struct sctp_reset_streams { ...@@ -1026,4 +1028,10 @@ struct sctp_reset_streams {
uint16_t srs_stream_list[]; /* list if srs_num_streams is not 0 */ uint16_t srs_stream_list[]; /* list if srs_num_streams is not 0 */
}; };
struct sctp_add_streams {
sctp_assoc_t sas_assoc_id;
uint16_t sas_instrms;
uint16_t sas_outstrms;
};
#endif /* _UAPI_SCTP_H */ #endif /* _UAPI_SCTP_H */
...@@ -3658,3 +3658,78 @@ struct sctp_chunk *sctp_make_strreset_req( ...@@ -3658,3 +3658,78 @@ struct sctp_chunk *sctp_make_strreset_req(
return retval; return retval;
} }
/* RE-CONFIG 4.3 (SSN/TSN RESET ALL)
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Parameter Type = 15 | Parameter Length = 8 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Re-configuration Request Sequence Number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct sctp_chunk *sctp_make_strreset_tsnreq(
const struct sctp_association *asoc)
{
struct sctp_strreset_tsnreq tsnreq;
__u16 length = sizeof(tsnreq);
struct sctp_chunk *retval;
retval = sctp_make_reconf(asoc, length);
if (!retval)
return NULL;
tsnreq.param_hdr.type = SCTP_PARAM_RESET_TSN_REQUEST;
tsnreq.param_hdr.length = htons(length);
tsnreq.request_seq = htonl(asoc->strreset_outseq);
sctp_addto_chunk(retval, sizeof(tsnreq), &tsnreq);
return retval;
}
/* RE-CONFIG 4.5/4.6 (ADD STREAM)
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Parameter Type = 17 | Parameter Length = 12 |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Re-configuration Request Sequence Number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Number of new streams | Reserved |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
struct sctp_chunk *sctp_make_strreset_addstrm(
const struct sctp_association *asoc,
__u16 out, __u16 in)
{
struct sctp_strreset_addstrm addstrm;
__u16 size = sizeof(addstrm);
struct sctp_chunk *retval;
retval = sctp_make_reconf(asoc, (!!out + !!in) * size);
if (!retval)
return NULL;
if (out) {
addstrm.param_hdr.type = SCTP_PARAM_RESET_ADD_OUT_STREAMS;
addstrm.param_hdr.length = htons(size);
addstrm.number_of_streams = htons(out);
addstrm.request_seq = htonl(asoc->strreset_outseq);
addstrm.reserved = 0;
sctp_addto_chunk(retval, size, &addstrm);
}
if (in) {
addstrm.param_hdr.type = SCTP_PARAM_RESET_ADD_IN_STREAMS;
addstrm.param_hdr.length = htons(size);
addstrm.number_of_streams = htons(in);
addstrm.request_seq = htonl(asoc->strreset_outseq + !!out);
addstrm.reserved = 0;
sctp_addto_chunk(retval, size, &addstrm);
}
return retval;
}
...@@ -3818,6 +3818,58 @@ static int sctp_setsockopt_reset_streams(struct sock *sk, ...@@ -3818,6 +3818,58 @@ static int sctp_setsockopt_reset_streams(struct sock *sk,
return retval; return retval;
} }
static int sctp_setsockopt_reset_assoc(struct sock *sk,
char __user *optval,
unsigned int optlen)
{
struct sctp_association *asoc;
sctp_assoc_t associd;
int retval = -EINVAL;
if (optlen != sizeof(associd))
goto out;
if (copy_from_user(&associd, optval, optlen)) {
retval = -EFAULT;
goto out;
}
asoc = sctp_id2assoc(sk, associd);
if (!asoc)
goto out;
retval = sctp_send_reset_assoc(asoc);
out:
return retval;
}
static int sctp_setsockopt_add_streams(struct sock *sk,
char __user *optval,
unsigned int optlen)
{
struct sctp_association *asoc;
struct sctp_add_streams params;
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.sas_assoc_id);
if (!asoc)
goto out;
retval = sctp_send_add_streams(asoc, &params);
out:
return retval;
}
/* API 6.2 setsockopt(), getsockopt() /* API 6.2 setsockopt(), getsockopt()
* *
* Applications use setsockopt() and getsockopt() to set or retrieve * Applications use setsockopt() and getsockopt() to set or retrieve
...@@ -3990,6 +4042,12 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, ...@@ -3990,6 +4042,12 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
case SCTP_RESET_STREAMS: case SCTP_RESET_STREAMS:
retval = sctp_setsockopt_reset_streams(sk, optval, optlen); retval = sctp_setsockopt_reset_streams(sk, optval, optlen);
break; break;
case SCTP_RESET_ASSOC:
retval = sctp_setsockopt_reset_assoc(sk, optval, optlen);
break;
case SCTP_ADD_STREAMS:
retval = sctp_setsockopt_add_streams(sk, optval, optlen);
break;
default: default:
retval = -ENOPROTOOPT; retval = -ENOPROTOOPT;
break; break;
......
...@@ -136,8 +136,10 @@ int sctp_send_reset_streams(struct sctp_association *asoc, ...@@ -136,8 +136,10 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
goto out; goto out;
chunk = sctp_make_strreset_req(asoc, str_nums, str_list, out, in); chunk = sctp_make_strreset_req(asoc, str_nums, str_list, out, in);
if (!chunk) if (!chunk) {
retval = -ENOMEM;
goto out; goto out;
}
if (out) { if (out) {
if (str_nums) if (str_nums)
...@@ -149,7 +151,54 @@ int sctp_send_reset_streams(struct sctp_association *asoc, ...@@ -149,7 +151,54 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
stream->out[i].state = SCTP_STREAM_CLOSED; stream->out[i].state = SCTP_STREAM_CLOSED;
} }
asoc->strreset_chunk = chunk;
sctp_chunk_hold(asoc->strreset_chunk);
retval = sctp_send_reconf(asoc, chunk);
if (retval) {
sctp_chunk_put(asoc->strreset_chunk);
asoc->strreset_chunk = NULL;
if (!out)
goto out;
if (str_nums)
for (i = 0; i < str_nums; i++)
stream->out[str_list[i]].state =
SCTP_STREAM_OPEN;
else
for (i = 0; i < stream->outcnt; i++)
stream->out[i].state = SCTP_STREAM_OPEN;
goto out;
}
asoc->strreset_outstanding = out + in; asoc->strreset_outstanding = out + in;
out:
return retval;
}
int sctp_send_reset_assoc(struct sctp_association *asoc)
{
struct sctp_chunk *chunk = NULL;
int retval;
__u16 i;
if (!asoc->peer.reconf_capable ||
!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
return -ENOPROTOOPT;
if (asoc->strreset_outstanding)
return -EINPROGRESS;
chunk = sctp_make_strreset_tsnreq(asoc);
if (!chunk)
return -ENOMEM;
/* Block further xmit of data until this request is completed */
for (i = 0; i < asoc->stream->outcnt; i++)
asoc->stream->out[i].state = SCTP_STREAM_CLOSED;
asoc->strreset_chunk = chunk; asoc->strreset_chunk = chunk;
sctp_chunk_hold(asoc->strreset_chunk); sctp_chunk_hold(asoc->strreset_chunk);
...@@ -157,8 +206,91 @@ int sctp_send_reset_streams(struct sctp_association *asoc, ...@@ -157,8 +206,91 @@ int sctp_send_reset_streams(struct sctp_association *asoc,
if (retval) { if (retval) {
sctp_chunk_put(asoc->strreset_chunk); sctp_chunk_put(asoc->strreset_chunk);
asoc->strreset_chunk = NULL; asoc->strreset_chunk = NULL;
for (i = 0; i < asoc->stream->outcnt; i++)
asoc->stream->out[i].state = SCTP_STREAM_OPEN;
return retval;
} }
asoc->strreset_outstanding = 1;
return 0;
}
int sctp_send_add_streams(struct sctp_association *asoc,
struct sctp_add_streams *params)
{
struct sctp_stream *stream = asoc->stream;
struct sctp_chunk *chunk = NULL;
int retval = -ENOMEM;
__u32 outcnt, incnt;
__u16 out, in;
if (!asoc->peer.reconf_capable ||
!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) {
retval = -ENOPROTOOPT;
goto out;
}
if (asoc->strreset_outstanding) {
retval = -EINPROGRESS;
goto out;
}
out = params->sas_outstrms;
in = params->sas_instrms;
outcnt = stream->outcnt + out;
incnt = stream->incnt + in;
if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM ||
(!out && !in)) {
retval = -EINVAL;
goto out;
}
if (out) {
struct sctp_stream_out *streamout;
streamout = krealloc(stream->out, outcnt * sizeof(*streamout),
GFP_KERNEL);
if (!streamout)
goto out;
memset(streamout + stream->outcnt, 0, out * sizeof(*streamout));
stream->out = streamout;
}
if (in) {
struct sctp_stream_in *streamin;
streamin = krealloc(stream->in, incnt * sizeof(*streamin),
GFP_KERNEL);
if (!streamin)
goto out;
memset(streamin + stream->incnt, 0, in * sizeof(*streamin));
stream->in = streamin;
}
chunk = sctp_make_strreset_addstrm(asoc, out, in);
if (!chunk)
goto out;
asoc->strreset_chunk = chunk;
sctp_chunk_hold(asoc->strreset_chunk);
retval = sctp_send_reconf(asoc, chunk);
if (retval) {
sctp_chunk_put(asoc->strreset_chunk);
asoc->strreset_chunk = NULL;
goto out;
}
stream->incnt = incnt;
stream->outcnt = outcnt;
asoc->strreset_outstanding = !!out + !!in;
out: out:
return retval; return retval;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment