Skip to content

Commit

Permalink
sctp: introduce SCTP_FUTURE/CURRENT/ALL_ASSOC
Browse files Browse the repository at this point in the history
This patch is to add 3 constants SCTP_FUTURE_ASSOC,
SCTP_CURRENT_ASSOC and SCTP_ALL_ASSOC for reserved
assoc_ids, as defined in rfc6458#section-7.2.

And add the process for them when doing lookup and
inserting in sctp_id2assoc and sctp_assoc_set_id.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Xin Long authored and David S. Miller committed Jan 30, 2019
1 parent bde5272 commit 80df270
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/uapi/linux/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@

typedef __s32 sctp_assoc_t;

#define SCTP_FUTURE_ASSOC 0
#define SCTP_CURRENT_ASSOC 1
#define SCTP_ALL_ASSOC 2

/* The following symbols come from the Sockets API Extensions for
* SCTP <draft-ietf-tsvwg-sctpsocket-07.txt>.
*/
Expand Down
7 changes: 5 additions & 2 deletions net/sctp/associola.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,8 +1651,11 @@ int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp)
if (preload)
idr_preload(gfp);
spin_lock_bh(&sctp_assocs_id_lock);
/* 0 is not a valid assoc_id, must be >= 1 */
ret = idr_alloc_cyclic(&sctp_assocs_id, asoc, 1, 0, GFP_NOWAIT);
/* 0, 1, 2 are used as SCTP_FUTURE_ASSOC, SCTP_CURRENT_ASSOC and
* SCTP_ALL_ASSOC, so an available id must be > SCTP_ALL_ASSOC.
*/
ret = idr_alloc_cyclic(&sctp_assocs_id, asoc, SCTP_ALL_ASSOC + 1, 0,
GFP_NOWAIT);
spin_unlock_bh(&sctp_assocs_id_lock);
if (preload)
idr_preload_end();
Expand Down
2 changes: 1 addition & 1 deletion net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id)
}

/* Otherwise this is a UDP-style socket. */
if (!id || (id == (sctp_assoc_t)-1))
if (id <= SCTP_ALL_ASSOC)
return NULL;

spin_lock_bh(&sctp_assocs_id_lock);
Expand Down

0 comments on commit 80df270

Please sign in to comment.