Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 1 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * (C) Copyright IBM Corp. 2001, 2004 |
| 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 5 | * Copyright (c) 2001 Intel Corp. |
| 6 | * Copyright (c) 2001 Nokia, Inc. |
| 7 | * Copyright (c) 2001 La Monte H.P. Yarroll |
| 8 | * |
| 9 | * These are the definitions needed for the sctp_ulpevent type. The |
| 10 | * sctp_ulpevent type is used to carry information from the state machine |
| 11 | * upwards to the ULP. |
| 12 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 13 | * This file is part of the SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 15 | * This SCTP implementation is free software; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * you can redistribute it and/or modify it under the terms of |
| 17 | * the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2, or (at your option) |
| 19 | * any later version. |
| 20 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 21 | * This SCTP implementation is distributed in the hope that it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 23 | * ************************ |
| 24 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 25 | * See the GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
Jeff Kirsher | 4b2f13a | 2013-12-06 06:28:48 -0800 | [diff] [blame] | 28 | * along with GNU CC; see the file COPYING. If not, see |
| 29 | * <http://www.gnu.org/licenses/>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
| 31 | * Please send any bug reports or fixes you make to the |
| 32 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 33 | * lksctp developers <linux-sctp@vger.kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * Written or modified by: |
| 36 | * Jon Grimm <jgrimm@us.ibm.com> |
| 37 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 38 | * Karl Knutson <karl@athena.chicago.il.us> |
| 39 | * Sridhar Samudrala <sri@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | */ |
| 41 | |
| 42 | #ifndef __sctp_ulpevent_h__ |
| 43 | #define __sctp_ulpevent_h__ |
| 44 | |
| 45 | /* A structure to carry information to the ULP (e.g. Sockets API) */ |
| 46 | /* Warning: This sits inside an skb.cb[] area. Be very careful of |
| 47 | * growing this structure as it is at the maximum limit now. |
| 48 | */ |
| 49 | struct sctp_ulpevent { |
| 50 | struct sctp_association *asoc; |
Marcelo Ricardo Leitner | 1f45f78 | 2016-07-13 15:08:57 -0300 | [diff] [blame] | 51 | struct sctp_chunk *chunk; |
Marcelo Ricardo Leitner | f5d258e | 2016-07-13 15:08:56 -0300 | [diff] [blame] | 52 | unsigned int rmem_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | __u32 ppid; |
| 54 | __u32 tsn; |
| 55 | __u32 cumtsn; |
Marcelo Ricardo Leitner | f5d258e | 2016-07-13 15:08:56 -0300 | [diff] [blame] | 56 | __u16 stream; |
| 57 | __u16 ssn; |
| 58 | __u16 flags; |
| 59 | __u16 msg_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /* Retrieve the skb this event sits inside of. */ |
Vlad Yasevich | ab38fb0 | 2008-04-12 18:40:06 -0700 | [diff] [blame] | 63 | static inline struct sk_buff *sctp_event2skb(const struct sctp_ulpevent *ev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | return container_of((void *)ev, struct sk_buff, cb); |
| 66 | } |
| 67 | |
| 68 | /* Retrieve & cast the event sitting inside the skb. */ |
| 69 | static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb) |
| 70 | { |
| 71 | return (struct sctp_ulpevent *)skb->cb; |
| 72 | } |
| 73 | |
| 74 | void sctp_ulpevent_free(struct sctp_ulpevent *); |
| 75 | int sctp_ulpevent_is_notification(const struct sctp_ulpevent *); |
Thomas Graf | cd4fcc7 | 2011-07-08 04:37:46 +0000 | [diff] [blame] | 76 | unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | struct sctp_ulpevent *sctp_ulpevent_make_assoc_change( |
| 79 | const struct sctp_association *asoc, |
| 80 | __u16 flags, |
| 81 | __u16 state, |
| 82 | __u16 error, |
| 83 | __u16 outbound, |
| 84 | __u16 inbound, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 85 | struct sctp_chunk *chunk, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 86 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change( |
| 89 | const struct sctp_association *asoc, |
| 90 | const struct sockaddr_storage *aaddr, |
| 91 | int flags, |
| 92 | int state, |
| 93 | int error, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 94 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | struct sctp_ulpevent *sctp_ulpevent_make_remote_error( |
| 97 | const struct sctp_association *asoc, |
| 98 | struct sctp_chunk *chunk, |
| 99 | __u16 flags, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 100 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | struct sctp_ulpevent *sctp_ulpevent_make_send_failed( |
| 102 | const struct sctp_association *asoc, |
| 103 | struct sctp_chunk *chunk, |
| 104 | __u16 flags, |
| 105 | __u32 error, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 106 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event( |
| 109 | const struct sctp_association *asoc, |
| 110 | __u16 flags, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 111 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | struct sctp_ulpevent *sctp_ulpevent_make_pdapi( |
| 114 | const struct sctp_association *asoc, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 115 | __u32 indication, gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 117 | struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication( |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 118 | const struct sctp_association *asoc, gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc, |
| 121 | struct sctp_chunk *chunk, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 122 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Vlad Yasevich | 65b07e5 | 2007-09-16 19:34:00 -0700 | [diff] [blame] | 124 | struct sctp_ulpevent *sctp_ulpevent_make_authkey( |
| 125 | const struct sctp_association *asoc, __u16 key_id, |
| 126 | __u32 indication, gfp_t gfp); |
| 127 | |
Wei Yongjun | e1cdd55 | 2011-04-17 17:29:03 +0000 | [diff] [blame] | 128 | struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event( |
| 129 | const struct sctp_association *asoc, gfp_t gfp); |
| 130 | |
Xin Long | 35ea82d | 2017-02-17 12:45:38 +0800 | [diff] [blame] | 131 | struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event( |
| 132 | const struct sctp_association *asoc, __u16 flags, |
| 133 | __u16 stream_num, __u16 *stream_list, gfp_t gfp); |
| 134 | |
Xin Long | c95129d | 2017-03-10 12:11:06 +0800 | [diff] [blame] | 135 | struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event( |
| 136 | const struct sctp_association *asoc, __u16 flags, |
| 137 | __u32 local_tsn, __u32 remote_tsn, gfp_t gfp); |
| 138 | |
Xin Long | b444153 | 2017-03-10 12:11:08 +0800 | [diff] [blame] | 139 | struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event( |
| 140 | const struct sctp_association *asoc, __u16 flags, |
| 141 | __u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp); |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event, |
Geir Ola Vaagland | 0d3a421 | 2014-07-12 20:30:37 +0200 | [diff] [blame] | 144 | struct msghdr *); |
| 145 | void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event, |
| 146 | struct msghdr *); |
Geir Ola Vaagland | 2347c80 | 2014-07-12 20:30:38 +0200 | [diff] [blame] | 147 | void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event, |
| 148 | struct msghdr *, struct sock *sk); |
Geir Ola Vaagland | 0d3a421 | 2014-07-12 20:30:37 +0200 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event); |
| 151 | |
| 152 | /* Is this event type enabled? */ |
| 153 | static inline int sctp_ulpevent_type_enabled(__u16 sn_type, |
| 154 | struct sctp_event_subscribe *mask) |
| 155 | { |
Dan Carpenter | fa5f7b5 | 2017-09-14 02:00:54 +0300 | [diff] [blame^] | 156 | int offset = sn_type - SCTP_SN_TYPE_BASE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | char *amask = (char *) mask; |
Dan Carpenter | fa5f7b5 | 2017-09-14 02:00:54 +0300 | [diff] [blame^] | 158 | |
| 159 | if (offset >= sizeof(struct sctp_event_subscribe)) |
| 160 | return 0; |
| 161 | return amask[offset]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* Given an event subscription, is this event enabled? */ |
| 165 | static inline int sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event, |
| 166 | struct sctp_event_subscribe *mask) |
| 167 | { |
| 168 | __u16 sn_type; |
| 169 | int enabled = 1; |
| 170 | |
| 171 | if (sctp_ulpevent_is_notification(event)) { |
| 172 | sn_type = sctp_ulpevent_get_notification_type(event); |
| 173 | enabled = sctp_ulpevent_type_enabled(sn_type, mask); |
| 174 | } |
| 175 | return enabled; |
| 176 | } |
| 177 | |
| 178 | #endif /* __sctp_ulpevent_h__ */ |