Thomas Gleixner | 47505b8 | 2019-05-23 11:14:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 2 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * (C) Copyright IBM Corp. 2001, 2004 |
| 4 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 5 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 6 | * Copyright (c) 2001 Intel Corp. |
| 7 | * Copyright (c) 2001 Nokia, Inc. |
| 8 | * Copyright (c) 2001 La Monte H.P. Yarroll |
| 9 | * |
| 10 | * These are the definitions needed for the sctp_ulpevent type. The |
| 11 | * sctp_ulpevent type is used to carry information from the state machine |
| 12 | * upwards to the ULP. |
| 13 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 14 | * This file is part of the SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * Please send any bug reports or fixes you make to the |
| 17 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 18 | * lksctp developers <linux-sctp@vger.kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * Written or modified by: |
| 21 | * Jon Grimm <jgrimm@us.ibm.com> |
| 22 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 23 | * Karl Knutson <karl@athena.chicago.il.us> |
| 24 | * Sridhar Samudrala <sri@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #ifndef __sctp_ulpevent_h__ |
| 28 | #define __sctp_ulpevent_h__ |
| 29 | |
| 30 | /* A structure to carry information to the ULP (e.g. Sockets API) */ |
| 31 | /* Warning: This sits inside an skb.cb[] area. Be very careful of |
| 32 | * growing this structure as it is at the maximum limit now. |
Xin Long | bd4d627 | 2017-12-08 21:04:04 +0800 | [diff] [blame] | 33 | * |
| 34 | * sctp_ulpevent is saved in sk->cb(48 bytes), whose last 4 bytes |
| 35 | * have been taken by sock_skb_cb, So here it has to use 'packed' |
| 36 | * to make sctp_ulpevent fit into the rest 44 bytes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | struct sctp_ulpevent { |
| 39 | struct sctp_association *asoc; |
Marcelo Ricardo Leitner | 1f45f78 | 2016-07-13 15:08:57 -0300 | [diff] [blame] | 40 | struct sctp_chunk *chunk; |
Marcelo Ricardo Leitner | f5d258e | 2016-07-13 15:08:56 -0300 | [diff] [blame] | 41 | unsigned int rmem_len; |
Xin Long | bd4d627 | 2017-12-08 21:04:04 +0800 | [diff] [blame] | 42 | union { |
| 43 | __u32 mid; |
| 44 | __u16 ssn; |
| 45 | }; |
| 46 | union { |
| 47 | __u32 ppid; |
| 48 | __u32 fsn; |
| 49 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | __u32 tsn; |
| 51 | __u32 cumtsn; |
Marcelo Ricardo Leitner | f5d258e | 2016-07-13 15:08:56 -0300 | [diff] [blame] | 52 | __u16 stream; |
Marcelo Ricardo Leitner | f5d258e | 2016-07-13 15:08:56 -0300 | [diff] [blame] | 53 | __u16 flags; |
| 54 | __u16 msg_flags; |
Xin Long | bd4d627 | 2017-12-08 21:04:04 +0800 | [diff] [blame] | 55 | } __packed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /* Retrieve the skb this event sits inside of. */ |
Vlad Yasevich | ab38fb0 | 2008-04-12 18:40:06 -0700 | [diff] [blame] | 58 | static inline struct sk_buff *sctp_event2skb(const struct sctp_ulpevent *ev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | return container_of((void *)ev, struct sk_buff, cb); |
| 61 | } |
| 62 | |
| 63 | /* Retrieve & cast the event sitting inside the skb. */ |
| 64 | static inline struct sctp_ulpevent *sctp_skb2event(struct sk_buff *skb) |
| 65 | { |
| 66 | return (struct sctp_ulpevent *)skb->cb; |
| 67 | } |
| 68 | |
| 69 | void sctp_ulpevent_free(struct sctp_ulpevent *); |
| 70 | int sctp_ulpevent_is_notification(const struct sctp_ulpevent *); |
Thomas Graf | cd4fcc7 | 2011-07-08 04:37:46 +0000 | [diff] [blame] | 71 | unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | struct sctp_ulpevent *sctp_ulpevent_make_assoc_change( |
| 74 | const struct sctp_association *asoc, |
| 75 | __u16 flags, |
| 76 | __u16 state, |
| 77 | __u16 error, |
| 78 | __u16 outbound, |
| 79 | __u16 inbound, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 80 | struct sctp_chunk *chunk, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 81 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Jonas Falkevik | 50ce4c0 | 2020-05-27 11:59:43 +0200 | [diff] [blame] | 83 | void sctp_ulpevent_notify_peer_addr_change(struct sctp_transport *transport, |
Xin Long | 4b77403 | 2019-10-08 19:27:33 +0800 | [diff] [blame] | 84 | int state, int error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | struct sctp_ulpevent *sctp_ulpevent_make_remote_error( |
| 87 | const struct sctp_association *asoc, |
| 88 | struct sctp_chunk *chunk, |
| 89 | __u16 flags, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 90 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | struct sctp_ulpevent *sctp_ulpevent_make_send_failed( |
| 92 | const struct sctp_association *asoc, |
| 93 | struct sctp_chunk *chunk, |
| 94 | __u16 flags, |
| 95 | __u32 error, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 96 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Xin Long | b6e6b5f | 2019-10-08 19:27:36 +0800 | [diff] [blame] | 98 | struct sctp_ulpevent *sctp_ulpevent_make_send_failed_event( |
| 99 | const struct sctp_association *asoc, |
| 100 | struct sctp_chunk *chunk, |
| 101 | __u16 flags, |
| 102 | __u32 error, |
| 103 | gfp_t gfp); |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event( |
| 106 | const struct sctp_association *asoc, |
| 107 | __u16 flags, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 108 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | struct sctp_ulpevent *sctp_ulpevent_make_pdapi( |
| 111 | const struct sctp_association *asoc, |
Xin Long | 65f5e35 | 2017-12-08 21:04:08 +0800 | [diff] [blame] | 112 | __u32 indication, __u32 sid, __u32 seq, |
| 113 | __u32 flags, gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 115 | struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication( |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 116 | const struct sctp_association *asoc, gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc, |
| 119 | struct sctp_chunk *chunk, |
Al Viro | dd0fc66 | 2005-10-07 07:46:04 +0100 | [diff] [blame] | 120 | gfp_t gfp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Vlad Yasevich | 65b07e5 | 2007-09-16 19:34:00 -0700 | [diff] [blame] | 122 | struct sctp_ulpevent *sctp_ulpevent_make_authkey( |
| 123 | const struct sctp_association *asoc, __u16 key_id, |
| 124 | __u32 indication, gfp_t gfp); |
| 125 | |
Wei Yongjun | e1cdd55 | 2011-04-17 17:29:03 +0000 | [diff] [blame] | 126 | struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event( |
| 127 | const struct sctp_association *asoc, gfp_t gfp); |
| 128 | |
Xin Long | 35ea82d | 2017-02-17 12:45:38 +0800 | [diff] [blame] | 129 | struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event( |
| 130 | const struct sctp_association *asoc, __u16 flags, |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 131 | __u16 stream_num, __be16 *stream_list, gfp_t gfp); |
Xin Long | 35ea82d | 2017-02-17 12:45:38 +0800 | [diff] [blame] | 132 | |
Xin Long | c95129d | 2017-03-10 12:11:06 +0800 | [diff] [blame] | 133 | struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event( |
| 134 | const struct sctp_association *asoc, __u16 flags, |
| 135 | __u32 local_tsn, __u32 remote_tsn, gfp_t gfp); |
| 136 | |
Xin Long | b444153 | 2017-03-10 12:11:08 +0800 | [diff] [blame] | 137 | struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event( |
| 138 | const struct sctp_association *asoc, __u16 flags, |
| 139 | __u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp); |
| 140 | |
Xin Long | bd4d627 | 2017-12-08 21:04:04 +0800 | [diff] [blame] | 141 | struct sctp_ulpevent *sctp_make_reassembled_event( |
| 142 | struct net *net, struct sk_buff_head *queue, |
| 143 | struct sk_buff *f_frag, struct sk_buff *l_frag); |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event, |
Geir Ola Vaagland | 0d3a421 | 2014-07-12 20:30:37 +0200 | [diff] [blame] | 146 | struct msghdr *); |
| 147 | void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event, |
| 148 | struct msghdr *); |
Geir Ola Vaagland | 2347c80 | 2014-07-12 20:30:38 +0200 | [diff] [blame] | 149 | void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event, |
| 150 | struct msghdr *, struct sock *sk); |
Geir Ola Vaagland | 0d3a421 | 2014-07-12 20:30:37 +0200 | [diff] [blame] | 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event); |
| 153 | |
Xin Long | 2cc0eeb | 2018-11-18 16:08:51 +0800 | [diff] [blame] | 154 | static inline void sctp_ulpevent_type_set(__u16 *subscribe, |
| 155 | __u16 sn_type, __u8 on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Xin Long | 2cc0eeb | 2018-11-18 16:08:51 +0800 | [diff] [blame] | 157 | if (sn_type > SCTP_SN_TYPE_MAX) |
| 158 | return; |
Dan Carpenter | fa5f7b5 | 2017-09-14 02:00:54 +0300 | [diff] [blame] | 159 | |
Xin Long | 2cc0eeb | 2018-11-18 16:08:51 +0800 | [diff] [blame] | 160 | if (on) |
| 161 | *subscribe |= (1 << (sn_type - SCTP_SN_TYPE_BASE)); |
| 162 | else |
| 163 | *subscribe &= ~(1 << (sn_type - SCTP_SN_TYPE_BASE)); |
| 164 | } |
| 165 | |
| 166 | /* Is this event type enabled? */ |
| 167 | static inline bool sctp_ulpevent_type_enabled(__u16 subscribe, __u16 sn_type) |
| 168 | { |
| 169 | if (sn_type > SCTP_SN_TYPE_MAX) |
| 170 | return false; |
| 171 | |
| 172 | return subscribe & (1 << (sn_type - SCTP_SN_TYPE_BASE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /* Given an event subscription, is this event enabled? */ |
Xin Long | 2cc0eeb | 2018-11-18 16:08:51 +0800 | [diff] [blame] | 176 | static inline bool sctp_ulpevent_is_enabled(const struct sctp_ulpevent *event, |
| 177 | __u16 subscribe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
| 179 | __u16 sn_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Xin Long | 2cc0eeb | 2018-11-18 16:08:51 +0800 | [diff] [blame] | 181 | if (!sctp_ulpevent_is_notification(event)) |
| 182 | return true; |
| 183 | |
| 184 | sn_type = sctp_ulpevent_get_notification_type(event); |
| 185 | |
| 186 | return sctp_ulpevent_type_enabled(subscribe, sn_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | #endif /* __sctp_ulpevent_h__ */ |