sctp: implement sender-side procedures for SSN Reset Request Parameter
This patch is to implement sender-side procedures for the Outgoing and Incoming SSN Reset Request Parameter described in rfc6525 section 5.1.2 and 5.1.3. It is also add sockopt SCTP_RESET_STREAMS in rfc6525 section 6.3.2 for users. Note that the new asoc member strreset_outstanding is to make sure only one reconf request chunk on the fly as rfc6525 section 5.1.1 demands. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
9fb657aec0
commit
7f9d68ac94
@@ -33,6 +33,7 @@
|
||||
*/
|
||||
|
||||
#include <net/sctp/sctp.h>
|
||||
#include <net/sctp/sm.h>
|
||||
|
||||
struct sctp_stream *sctp_stream_new(__u16 incnt, __u16 outcnt, gfp_t gfp)
|
||||
{
|
||||
@@ -83,3 +84,81 @@ void sctp_stream_clear(struct sctp_stream *stream)
|
||||
for (i = 0; i < stream->incnt; i++)
|
||||
stream->in[i].ssn = 0;
|
||||
}
|
||||
|
||||
static int sctp_send_reconf(struct sctp_association *asoc,
|
||||
struct sctp_chunk *chunk)
|
||||
{
|
||||
struct net *net = sock_net(asoc->base.sk);
|
||||
int retval = 0;
|
||||
|
||||
retval = sctp_primitive_RECONF(net, asoc, chunk);
|
||||
if (retval)
|
||||
sctp_chunk_free(chunk);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int sctp_send_reset_streams(struct sctp_association *asoc,
|
||||
struct sctp_reset_streams *params)
|
||||
{
|
||||
struct sctp_stream *stream = asoc->stream;
|
||||
__u16 i, str_nums, *str_list;
|
||||
struct sctp_chunk *chunk;
|
||||
int retval = -EINVAL;
|
||||
bool out, in;
|
||||
|
||||
if (!asoc->peer.reconf_capable ||
|
||||
!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) {
|
||||
retval = -ENOPROTOOPT;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (asoc->strreset_outstanding) {
|
||||
retval = -EINPROGRESS;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING;
|
||||
in = params->srs_flags & SCTP_STREAM_RESET_INCOMING;
|
||||
if (!out && !in)
|
||||
goto out;
|
||||
|
||||
str_nums = params->srs_number_streams;
|
||||
str_list = params->srs_stream_list;
|
||||
if (out && str_nums)
|
||||
for (i = 0; i < str_nums; i++)
|
||||
if (str_list[i] >= stream->outcnt)
|
||||
goto out;
|
||||
|
||||
if (in && str_nums)
|
||||
for (i = 0; i < str_nums; i++)
|
||||
if (str_list[i] >= stream->incnt)
|
||||
goto out;
|
||||
|
||||
chunk = sctp_make_strreset_req(asoc, str_nums, str_list, out, in);
|
||||
if (!chunk)
|
||||
goto out;
|
||||
|
||||
if (out) {
|
||||
if (str_nums)
|
||||
for (i = 0; i < str_nums; i++)
|
||||
stream->out[str_list[i]].state =
|
||||
SCTP_STREAM_CLOSED;
|
||||
else
|
||||
for (i = 0; i < stream->outcnt; i++)
|
||||
stream->out[i].state = SCTP_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
asoc->strreset_outstanding = out + in;
|
||||
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;
|
||||
}
|
||||
|
||||
out:
|
||||
return retval;
|
||||
}
|
||||
|
Reference in New Issue
Block a user