Skip to content

Commit

Permalink
Merge branch 'sctp-add-subscribe-per-asoc-and-sockopt-SCTP_EVENT'
Browse files Browse the repository at this point in the history
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: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Nov 19, 2018
2 parents f2be6d7 + 480ba9c commit cfc6731
Showing 13 changed files with 183 additions and 50 deletions.
2 changes: 1 addition & 1 deletion include/net/sctp/constants.h
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 2 additions & 2 deletions include/net/sctp/sm.h
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 3 additions & 1 deletion include/net/sctp/structs.h
Original file line number Diff line number Diff line change
@@ -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];
};
39 changes: 24 additions & 15 deletions include/net/sctp/ulpevent.h
Original file line number Diff line number Diff line change
@@ -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)) {
sn_type = sctp_ulpevent_get_notification_type(event);
enabled = sctp_ulpevent_type_enabled(sn_type, mask);
}
return enabled;
if (!sctp_ulpevent_is_notification(event))
return true;

sn_type = sctp_ulpevent_get_notification_type(event);

return sctp_ulpevent_type_enabled(subscribe, sn_type);
}

#endif /* __sctp_ulpevent_h__ */
13 changes: 12 additions & 1 deletion include/uapi/linux/sctp.h
Original file line number Diff line number Diff line change
@@ -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
@@ -632,7 +633,9 @@ union sctp_notification {
*/

enum sctp_sn_type {
SCTP_SN_TYPE_BASE = (1<<15),
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,
2 changes: 2 additions & 0 deletions net/sctp/associola.c
Original file line number Diff line number Diff line change
@@ -135,6 +135,8 @@ static struct sctp_association *sctp_association_init(
*/
asoc->max_burst = sp->max_burst;

asoc->subscribe = sp->subscribe;

/* initialize association timers */
asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial;
asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_INIT] = asoc->rto_initial;
8 changes: 3 additions & 5 deletions net/sctp/chunk.c
Original file line number Diff line number Diff line change
@@ -86,11 +86,10 @@ void sctp_datamsg_free(struct sctp_datamsg *msg)
/* Final destructruction of datamsg memory. */
static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
{
struct sctp_association *asoc = NULL;
struct list_head *pos, *temp;
struct sctp_chunk *chunk;
struct sctp_sock *sp;
struct sctp_ulpevent *ev;
struct sctp_association *asoc = NULL;
int error = 0, notify;

/* If we failed, we may need to notify. */
@@ -108,9 +107,8 @@ static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
else
error = asoc->outqueue.error;

sp = sctp_sk(asoc->base.sk);
notify = sctp_ulpevent_type_enabled(SCTP_SEND_FAILED,
&sp->subscribe);
notify = sctp_ulpevent_type_enabled(asoc->subscribe,
SCTP_SEND_FAILED);
}

/* Generate a SEND FAILED event only if enabled. */
2 changes: 1 addition & 1 deletion net/sctp/primitive.c
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@
int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
void *arg) { \
int error = 0; \
enum sctp_event event_type; union sctp_subtype subtype; \
enum sctp_event_type event_type; union sctp_subtype subtype; \
enum sctp_state state; \
struct sctp_endpoint *ep; \
\
12 changes: 6 additions & 6 deletions net/sctp/sm_sideeffect.c
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
#include <net/sctp/sm.h>
#include <net/sctp/stream_sched.h>

static int sctp_cmd_interpreter(enum sctp_event event_type,
static int sctp_cmd_interpreter(enum sctp_event_type event_type,
union sctp_subtype subtype,
enum sctp_state state,
struct sctp_endpoint *ep,
@@ -61,7 +61,7 @@ static int sctp_cmd_interpreter(enum sctp_event event_type,
enum sctp_disposition status,
struct sctp_cmd_seq *commands,
gfp_t gfp);
static int sctp_side_effects(enum sctp_event event_type,
static int sctp_side_effects(enum sctp_event_type event_type,
union sctp_subtype subtype,
enum sctp_state state,
struct sctp_endpoint *ep,
@@ -623,7 +623,7 @@ static void sctp_cmd_init_failed(struct sctp_cmd_seq *commands,
/* Worker routine to handle SCTP_CMD_ASSOC_FAILED. */
static void sctp_cmd_assoc_failed(struct sctp_cmd_seq *commands,
struct sctp_association *asoc,
enum sctp_event event_type,
enum sctp_event_type event_type,
union sctp_subtype subtype,
struct sctp_chunk *chunk,
unsigned int error)
@@ -1162,7 +1162,7 @@ static void sctp_cmd_send_asconf(struct sctp_association *asoc)
* If you want to understand all of lksctp, this is a
* good place to start.
*/
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)
@@ -1199,7 +1199,7 @@ int sctp_do_sm(struct net *net, enum sctp_event event_type,
/*****************************************************************
* This the master state function side effect processing function.
*****************************************************************/
static int sctp_side_effects(enum sctp_event event_type,
static int sctp_side_effects(enum sctp_event_type event_type,
union sctp_subtype subtype,
enum sctp_state state,
struct sctp_endpoint *ep,
@@ -1285,7 +1285,7 @@ static int sctp_side_effects(enum sctp_event event_type,
********************************************************************/

/* This is the side-effect interpreter. */
static int sctp_cmd_interpreter(enum sctp_event event_type,
static int sctp_cmd_interpreter(enum sctp_event_type event_type,
union sctp_subtype subtype,
enum sctp_state state,
struct sctp_endpoint *ep,
2 changes: 1 addition & 1 deletion net/sctp/sm_statetable.c
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ static const struct sctp_sm_table_entry bug = {

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)
{
Loading

0 comments on commit cfc6731

Please sign in to comment.