Skip to content

Commit cc16f00

Browse files
lxindavem330
authored andcommitted
sctp: add support for generating stream reconf ssn reset request chunk
This patch is to add asoc strreset_outseq and strreset_inseq for saving the reconf request sequence, initialize them when create assoc and process init, and also to define Incoming and Outgoing SSN Reset Request Parameter described in rfc6525 section 4.1 and 4.2, As they can be in one same chunk as section rfc6525 3.1-3 describes, it makes them in one function. Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b16ed2b commit cc16f00

File tree

5 files changed

+156
-1
lines changed

5 files changed

+156
-1
lines changed

include/linux/sctp.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ typedef enum {
108108
/* Use hex, as defined in ADDIP sec. 3.1 */
109109
SCTP_CID_ASCONF = 0xC1,
110110
SCTP_CID_ASCONF_ACK = 0x80,
111+
SCTP_CID_RECONF = 0x82,
111112
} sctp_cid_t; /* enum */
112113

113114

@@ -199,6 +200,13 @@ typedef enum {
199200
SCTP_PARAM_SUCCESS_REPORT = cpu_to_be16(0xc005),
200201
SCTP_PARAM_ADAPTATION_LAYER_IND = cpu_to_be16(0xc006),
201202

203+
/* RE-CONFIG. Section 4 */
204+
SCTP_PARAM_RESET_OUT_REQUEST = cpu_to_be16(0x000d),
205+
SCTP_PARAM_RESET_IN_REQUEST = cpu_to_be16(0x000e),
206+
SCTP_PARAM_RESET_TSN_REQUEST = cpu_to_be16(0x000f),
207+
SCTP_PARAM_RESET_RESPONSE = cpu_to_be16(0x0010),
208+
SCTP_PARAM_RESET_ADD_OUT_STREAMS = cpu_to_be16(0x0011),
209+
SCTP_PARAM_RESET_ADD_IN_STREAMS = cpu_to_be16(0x0012),
202210
} sctp_param_t; /* enum */
203211

204212

@@ -710,4 +718,23 @@ struct sctp_infox {
710718
struct sctp_association *asoc;
711719
};
712720

721+
struct sctp_reconf_chunk {
722+
sctp_chunkhdr_t chunk_hdr;
723+
__u8 params[0];
724+
} __packed;
725+
726+
struct sctp_strreset_outreq {
727+
sctp_paramhdr_t param_hdr;
728+
__u32 request_seq;
729+
__u32 response_seq;
730+
__u32 send_reset_at_tsn;
731+
__u16 list_of_streams[0];
732+
} __packed;
733+
734+
struct sctp_strreset_inreq {
735+
sctp_paramhdr_t param_hdr;
736+
__u32 request_seq;
737+
__u16 list_of_streams[0];
738+
} __packed;
739+
713740
#endif /* __LINUX_SCTP_H__ */

include/net/sctp/sm.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
259259
__u32 new_cum_tsn, size_t nstreams,
260260
struct sctp_fwdtsn_skip *skiplist);
261261
struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc);
262-
262+
struct sctp_chunk *sctp_make_strreset_req(
263+
const struct sctp_association *asoc,
264+
__u16 stream_num, __u16 *stream_list,
265+
bool out, bool in);
263266
void sctp_chunk_assign_tsn(struct sctp_chunk *);
264267
void sctp_chunk_assign_ssn(struct sctp_chunk *);
265268

include/net/sctp/structs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,9 @@ struct sctp_association {
18651865
temp:1, /* Is it a temporary association? */
18661866
prsctp_enable:1;
18671867

1868+
__u32 strreset_outseq; /* Update after receiving response */
1869+
__u32 strreset_inseq; /* Update after receiving request */
1870+
18681871
struct sctp_priv_assoc_stats stats;
18691872

18701873
int sent_cnt_removable;

net/sctp/associola.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
207207
* association to the same value as the initial TSN.
208208
*/
209209
asoc->addip_serial = asoc->c.initial_tsn;
210+
asoc->strreset_outseq = asoc->c.initial_tsn;
210211

211212
INIT_LIST_HEAD(&asoc->addip_chunk_list);
212213
INIT_LIST_HEAD(&asoc->asconf_ack_list);

net/sctp/sm_make_chunk.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,7 @@ struct sctp_association *sctp_unpack_cookie(
18441844
retval->next_tsn = retval->c.initial_tsn;
18451845
retval->ctsn_ack_point = retval->next_tsn - 1;
18461846
retval->addip_serial = retval->c.initial_tsn;
1847+
retval->strreset_outseq = retval->c.initial_tsn;
18471848
retval->adv_peer_ack_point = retval->ctsn_ack_point;
18481849
retval->peer.prsctp_capable = retval->c.prsctp_capable;
18491850
retval->peer.adaptation_ind = retval->c.adaptation_ind;
@@ -2387,6 +2388,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
23872388
asoc->peer.i.initial_tsn =
23882389
ntohl(peer_init->init_hdr.initial_tsn);
23892390

2391+
asoc->strreset_inseq = asoc->peer.i.initial_tsn;
2392+
23902393
/* Apply the upper bounds for output streams based on peer's
23912394
* number of inbound streams.
23922395
*/
@@ -3524,3 +3527,121 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
35243527

35253528
return retval;
35263529
}
3530+
3531+
/* RE-CONFIG 3.1 (RE-CONFIG chunk)
3532+
* 0 1 2 3
3533+
* 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
3534+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3535+
* | Type = 130 | Chunk Flags | Chunk Length |
3536+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3537+
* \ \
3538+
* / Re-configuration Parameter /
3539+
* \ \
3540+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3541+
* \ \
3542+
* / Re-configuration Parameter (optional) /
3543+
* \ \
3544+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3545+
*/
3546+
static struct sctp_chunk *sctp_make_reconf(
3547+
const struct sctp_association *asoc,
3548+
int length)
3549+
{
3550+
struct sctp_reconf_chunk *reconf;
3551+
struct sctp_chunk *retval;
3552+
3553+
retval = sctp_make_control(asoc, SCTP_CID_RECONF, 0, length,
3554+
GFP_ATOMIC);
3555+
if (!retval)
3556+
return NULL;
3557+
3558+
reconf = (struct sctp_reconf_chunk *)retval->chunk_hdr;
3559+
retval->param_hdr.v = reconf->params;
3560+
3561+
return retval;
3562+
}
3563+
3564+
/* RE-CONFIG 4.1 (STREAM OUT RESET)
3565+
* 0 1 2 3
3566+
* 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
3567+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3568+
* | Parameter Type = 13 | Parameter Length = 16 + 2 * N |
3569+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3570+
* | Re-configuration Request Sequence Number |
3571+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3572+
* | Re-configuration Response Sequence Number |
3573+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3574+
* | Sender's Last Assigned TSN |
3575+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3576+
* | Stream Number 1 (optional) | Stream Number 2 (optional) |
3577+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3578+
* / ...... /
3579+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3580+
* | Stream Number N-1 (optional) | Stream Number N (optional) |
3581+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3582+
*
3583+
* RE-CONFIG 4.2 (STREAM IN RESET)
3584+
* 0 1 2 3
3585+
* 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
3586+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3587+
* | Parameter Type = 14 | Parameter Length = 8 + 2 * N |
3588+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3589+
* | Re-configuration Request Sequence Number |
3590+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3591+
* | Stream Number 1 (optional) | Stream Number 2 (optional) |
3592+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3593+
* / ...... /
3594+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3595+
* | Stream Number N-1 (optional) | Stream Number N (optional) |
3596+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
3597+
*/
3598+
struct sctp_chunk *sctp_make_strreset_req(
3599+
const struct sctp_association *asoc,
3600+
__u16 stream_num, __u16 *stream_list,
3601+
bool out, bool in)
3602+
{
3603+
struct sctp_strreset_outreq outreq;
3604+
__u16 stream_len = stream_num * 2;
3605+
struct sctp_strreset_inreq inreq;
3606+
struct sctp_chunk *retval;
3607+
__u16 outlen, inlen, i;
3608+
3609+
outlen = (sizeof(outreq) + stream_len) * out;
3610+
inlen = (sizeof(inreq) + stream_len) * in;
3611+
3612+
retval = sctp_make_reconf(asoc, outlen + inlen);
3613+
if (!retval)
3614+
return NULL;
3615+
3616+
for (i = 0; i < stream_num; i++)
3617+
stream_list[i] = htons(stream_list[i]);
3618+
3619+
if (outlen) {
3620+
outreq.param_hdr.type = SCTP_PARAM_RESET_OUT_REQUEST;
3621+
outreq.param_hdr.length = htons(outlen);
3622+
outreq.request_seq = htonl(asoc->strreset_outseq);
3623+
outreq.response_seq = htonl(asoc->strreset_inseq - 1);
3624+
outreq.send_reset_at_tsn = htonl(asoc->next_tsn - 1);
3625+
3626+
sctp_addto_chunk(retval, sizeof(outreq), &outreq);
3627+
3628+
if (stream_len)
3629+
sctp_addto_chunk(retval, stream_len, stream_list);
3630+
}
3631+
3632+
if (inlen) {
3633+
inreq.param_hdr.type = SCTP_PARAM_RESET_IN_REQUEST;
3634+
inreq.param_hdr.length = htons(inlen);
3635+
inreq.request_seq = htonl(asoc->strreset_outseq + out);
3636+
3637+
sctp_addto_chunk(retval, sizeof(inreq), &inreq);
3638+
3639+
if (stream_len)
3640+
sctp_addto_chunk(retval, stream_len, stream_list);
3641+
}
3642+
3643+
for (i = 0; i < stream_num; i++)
3644+
stream_list[i] = ntohs(stream_list[i]);
3645+
3646+
return retval;
3647+
}

0 commit comments

Comments
 (0)