sctp: implement make_datafrag for sctp_stream_interleave
To avoid hundreds of checks for the different process on I-DATA chunk, struct sctp_stream_interleave is defined as a group of functions used to replace the codes in some place where it needs to do different job according to if the asoc intl_enabled is set. With these ops, it only needs to initialize asoc->stream.si with sctp_stream_interleave_0 for normal data if asoc intl_enable is 0, or sctp_stream_interleave_1 for idata if asoc intl_enable is set in sctp_stream_init. After that, the members in asoc->stream.si can be used directly in some special places without checking asoc intl_enable. make_datafrag is the first member for sctp_stream_interleave, it's used to make data or idata frags, called in sctp_datamsg_from_user. The old function sctp_make_datafrag_empty needs to be adjust some to fit in this ops. Note that as idata and data chunks have different length, it also defines data_chunk_len for sctp_stream_interleave to describe the chunk size. Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
ad05a7a05e
commit
0c3f6f6554
@@ -199,10 +199,9 @@ struct sctp_chunk *sctp_make_cwr(const struct sctp_association *asoc,
|
||||
const struct sctp_chunk *chunk);
|
||||
struct sctp_chunk *sctp_make_idata(const struct sctp_association *asoc,
|
||||
__u8 flags, int paylen, gfp_t gfp);
|
||||
struct sctp_chunk *sctp_make_datafrag_empty(struct sctp_association *asoc,
|
||||
struct sctp_chunk *sctp_make_datafrag_empty(const struct sctp_association *asoc,
|
||||
const struct sctp_sndrcvinfo *sinfo,
|
||||
int len, const __u8 flags,
|
||||
__u16 ssn, gfp_t gfp);
|
||||
int len, __u8 flags, gfp_t gfp);
|
||||
struct sctp_chunk *sctp_make_ecne(const struct sctp_association *asoc,
|
||||
const __u32 lowest_tsn);
|
||||
struct sctp_chunk *sctp_make_sack(const struct sctp_association *asoc);
|
||||
|
44
include/net/sctp/stream_interleave.h
Normal file
44
include/net/sctp/stream_interleave.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/* SCTP kernel implementation
|
||||
* (C) Copyright Red Hat Inc. 2017
|
||||
*
|
||||
* These are definitions used by the stream schedulers, defined in RFC
|
||||
* draft ndata (https://tools.ietf.org/html/draft-ietf-tsvwg-sctp-ndata-11)
|
||||
*
|
||||
* This SCTP implementation is free software;
|
||||
* you can redistribute it and/or modify it under the terms of
|
||||
* the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This SCTP implementation is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* ************************
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNU CC; see the file COPYING. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Please send any bug reports or fixes you make to the
|
||||
* email addresses:
|
||||
* lksctp developers <linux-sctp@vger.kernel.org>
|
||||
*
|
||||
* Written or modified by:
|
||||
* Xin Long <lucien.xin@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __sctp_stream_interleave_h__
|
||||
#define __sctp_stream_interleave_h__
|
||||
|
||||
struct sctp_stream_interleave {
|
||||
__u16 data_chunk_len;
|
||||
/* (I-)DATA process */
|
||||
struct sctp_chunk *(*make_datafrag)(const struct sctp_association *asoc,
|
||||
const struct sctp_sndrcvinfo *sinfo,
|
||||
int len, __u8 flags, gfp_t gfp);
|
||||
};
|
||||
|
||||
void sctp_stream_interleave_init(struct sctp_stream *stream);
|
||||
|
||||
#endif /* __sctp_stream_interleave_h__ */
|
@@ -89,6 +89,7 @@ struct sctp_stream;
|
||||
#include <net/sctp/tsnmap.h>
|
||||
#include <net/sctp/ulpevent.h>
|
||||
#include <net/sctp/ulpqueue.h>
|
||||
#include <net/sctp/stream_interleave.h>
|
||||
|
||||
/* Structures useful for managing bind/connect. */
|
||||
|
||||
@@ -1389,11 +1390,22 @@ struct sctp_stream {
|
||||
struct sctp_stream_out_ext *rr_next;
|
||||
};
|
||||
};
|
||||
struct sctp_stream_interleave *si;
|
||||
};
|
||||
|
||||
#define SCTP_STREAM_CLOSED 0x00
|
||||
#define SCTP_STREAM_OPEN 0x01
|
||||
|
||||
static inline __u16 sctp_datachk_len(const struct sctp_stream *stream)
|
||||
{
|
||||
return stream->si->data_chunk_len;
|
||||
}
|
||||
|
||||
static inline __u16 sctp_datahdr_len(const struct sctp_stream *stream)
|
||||
{
|
||||
return stream->si->data_chunk_len - sizeof(struct sctp_chunkhdr);
|
||||
}
|
||||
|
||||
/* SCTP_GET_ASSOC_STATS counters */
|
||||
struct sctp_priv_assoc_stats {
|
||||
/* Maximum observed rto in the association during subsequent
|
||||
|
Reference in New Issue
Block a user