Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfc6731d authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'sctp-add-subscribe-per-asoc-and-sockopt-SCTP_EVENT'



Xin Long says:

====================
sctp: add subscribe per asoc and sockopt SCTP_EVENT

This patchset mainly adds the Event Subscription sockopt described in
rfc6525#section-6.2:

"Subscribing to events as described in [RFC6458] uses a setsockopt()
call with the SCTP_EVENT socket option.  This option takes the
following structure, which specifies the association, the event type
(using the same value found in the event type field), and an on/off
boolean.

  struct sctp_event {
    sctp_assoc_t se_assoc_id;
    uint16_t     se_type;
    uint8_t      se_on;
  };

The user fills in the se_type field with the same value found in the
strreset_type field, i.e., SCTP_STREAM_RESET_EVENT.  The user will
also fill in the se_assoc_id field with either the association to set
this event on (this field is ignored for one-to-one style sockets) or
one of the reserved constant values defined in [RFC6458].  Finally,
the se_on field is set with a 1 to enable the event or a 0 to disable
the event."

As for the old SCTP_EVENTS Option with struct sctp_event_subscribe,
it's being DEPRECATED.

v1->v2:
  - fix some key word in changelog that triggerred the filters at
    vger.kernel.org.
v2->v3:
  - fix an array out of bounds noticed by Neil in patch 1/4.
====================

Acked-by: default avatarNeil Horman <nhorman@tuxdriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents f2be6d71 480ba9c1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ enum { SCTP_DEFAULT_INSTREAMS = SCTP_MAX_STREAM };
					 SCTP_NUM_AUTH_CHUNK_TYPES)

/* These are the different flavours of event.  */
enum sctp_event {
enum sctp_event_type {
	SCTP_EVENT_T_CHUNK = 1,
	SCTP_EVENT_T_TIMEOUT,
	SCTP_EVENT_T_OTHER,
+2 −2
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ sctp_state_fn_t sctp_sf_autoclose_timer_expire;
__u8 sctp_get_chunk_type(struct sctp_chunk *chunk);
const struct sctp_sm_table_entry *sctp_sm_lookup_event(
					struct net *net,
					enum sctp_event event_type,
					enum sctp_event_type event_type,
					enum sctp_state state,
					union sctp_subtype event_subtype);
int sctp_chunk_iif(const struct sctp_chunk *);
@@ -313,7 +313,7 @@ struct sctp_chunk *sctp_process_strreset_resp(

/* Prototypes for statetable processing. */

int sctp_do_sm(struct net *net, enum sctp_event event_type,
int sctp_do_sm(struct net *net, enum sctp_event_type event_type,
	       union sctp_subtype subtype, enum sctp_state state,
	       struct sctp_endpoint *ep, struct sctp_association *asoc,
	       void *event_arg, gfp_t gfp);
+3 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ struct sctp_sock {
	 * These two structures must be grouped together for the usercopy
	 * whitelist region.
	 */
	struct sctp_event_subscribe subscribe;
	__u16 subscribe;
	struct sctp_initmsg initmsg;

	int user_frag;
@@ -2077,6 +2077,8 @@ struct sctp_association {

	int sent_cnt_removable;

	__u16 subscribe;

	__u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1];
	__u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1];
};
+24 −15
Original line number Diff line number Diff line
@@ -164,30 +164,39 @@ void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,

__u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event);

static inline void sctp_ulpevent_type_set(__u16 *subscribe,
					  __u16 sn_type, __u8 on)
{
	if (sn_type > SCTP_SN_TYPE_MAX)
		return;

	if (on)
		*subscribe |=  (1 << (sn_type - SCTP_SN_TYPE_BASE));
	else
		*subscribe &= ~(1 << (sn_type - SCTP_SN_TYPE_BASE));
}

/* Is this event type enabled? */
static inline int sctp_ulpevent_type_enabled(__u16 sn_type,
					     struct sctp_event_subscribe *mask)
static inline bool sctp_ulpevent_type_enabled(__u16 subscribe, __u16 sn_type)
{
	int offset = sn_type - SCTP_SN_TYPE_BASE;
	char *amask = (char *) mask;
	if (sn_type > SCTP_SN_TYPE_MAX)
		return false;

	if (offset >= sizeof(struct sctp_event_subscribe))
		return 0;
	return amask[offset];
	return subscribe & (1 << (sn_type - SCTP_SN_TYPE_BASE));
}

/* Given an event subscription, is this event enabled? */
static inline int sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
					   struct sctp_event_subscribe *mask)
static inline bool sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event,
					    __u16 subscribe)
{
	__u16 sn_type;
	int enabled = 1;

	if (sctp_ulpevent_is_notification(event)) {
	if (!sctp_ulpevent_is_notification(event))
		return true;

	sn_type = sctp_ulpevent_get_notification_type(event);
		enabled = sctp_ulpevent_type_enabled(sn_type, mask);
	}
	return enabled;

	return sctp_ulpevent_type_enabled(subscribe, sn_type);
}

#endif /* __sctp_ulpevent_h__ */
+12 −1
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ typedef __s32 sctp_assoc_t;
#define SCTP_STREAM_SCHEDULER_VALUE	124
#define SCTP_INTERLEAVING_SUPPORTED	125
#define SCTP_SENDMSG_CONNECT	126
#define SCTP_EVENT	127

/* PR-SCTP policies */
#define SCTP_PR_SCTP_NONE	0x0000
@@ -633,6 +634,8 @@ union sctp_notification {

enum sctp_sn_type {
	SCTP_SN_TYPE_BASE	= (1<<15),
	SCTP_DATA_IO_EVENT	= SCTP_SN_TYPE_BASE,
#define SCTP_DATA_IO_EVENT		SCTP_DATA_IO_EVENT
	SCTP_ASSOC_CHANGE,
#define SCTP_ASSOC_CHANGE		SCTP_ASSOC_CHANGE
	SCTP_PEER_ADDR_CHANGE,
@@ -657,6 +660,8 @@ enum sctp_sn_type {
#define SCTP_ASSOC_RESET_EVENT		SCTP_ASSOC_RESET_EVENT
	SCTP_STREAM_CHANGE_EVENT,
#define SCTP_STREAM_CHANGE_EVENT	SCTP_STREAM_CHANGE_EVENT
	SCTP_SN_TYPE_MAX	= SCTP_STREAM_CHANGE_EVENT,
#define SCTP_SN_TYPE_MAX		SCTP_SN_TYPE_MAX
};

/* Notification error codes used to fill up the error fields in some
@@ -1150,6 +1155,12 @@ struct sctp_add_streams {
	uint16_t sas_outstrms;
};

struct sctp_event {
	sctp_assoc_t se_assoc_id;
	uint16_t se_type;
	uint8_t se_on;
};

/* SCTP Stream schedulers */
enum sctp_sched_type {
	SCTP_SS_FCFS,
Loading