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-2002 Intel Corp. |
| 6 | * Copyright (c) 2002 Nokia Corp. |
| 7 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 8 | * This is part of the SCTP Linux Kernel Implementation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * These are the state functions for the state machine. |
| 11 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 12 | * This SCTP implementation is free software; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * you can redistribute it and/or modify it under the terms of |
| 14 | * the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2, or (at your option) |
| 16 | * any later version. |
| 17 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 18 | * This SCTP implementation is distributed in the hope that it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 20 | * ************************ |
| 21 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 22 | * See the GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
Jeff Kirsher | 4b2f13a | 2013-12-06 06:28:48 -0800 | [diff] [blame] | 25 | * along with GNU CC; see the file COPYING. If not, see |
| 26 | * <http://www.gnu.org/licenses/>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * |
| 28 | * Please send any bug reports or fixes you make to the |
| 29 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 30 | * lksctp developers <linux-sctp@vger.kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | * Written or modified by: |
| 33 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 34 | * Karl Knutson <karl@athena.chicago.il.us> |
| 35 | * Mathew Kotowsky <kotowsky@sctp.org> |
| 36 | * Sridhar Samudrala <samudrala@us.ibm.com> |
| 37 | * Jon Grimm <jgrimm@us.ibm.com> |
| 38 | * Hui Huang <hui.huang@nokia.com> |
| 39 | * Dajiang Zhang <dajiang.zhang@nokia.com> |
| 40 | * Daisy Chang <daisyc@us.ibm.com> |
| 41 | * Ardelle Fan <ardelle.fan@intel.com> |
| 42 | * Ryan Layer <rmlayer@us.ibm.com> |
| 43 | * Kevin Gao <kevin.gao@intel.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | */ |
| 45 | |
Joe Perches | 145ce50 | 2010-08-24 13:21:08 +0000 | [diff] [blame] | 46 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/types.h> |
| 49 | #include <linux/kernel.h> |
| 50 | #include <linux/ip.h> |
| 51 | #include <linux/ipv6.h> |
| 52 | #include <linux/net.h> |
| 53 | #include <linux/inet.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 54 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <net/sock.h> |
| 56 | #include <net/inet_ecn.h> |
| 57 | #include <linux/skbuff.h> |
| 58 | #include <net/sctp/sctp.h> |
| 59 | #include <net/sctp/sm.h> |
| 60 | #include <net/sctp/structs.h> |
| 61 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 62 | static struct sctp_packet *sctp_abort_pkt_new(struct net *net, |
| 63 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | const struct sctp_association *asoc, |
| 65 | struct sctp_chunk *chunk, |
| 66 | const void *payload, |
| 67 | size_t paylen); |
| 68 | static int sctp_eat_data(const struct sctp_association *asoc, |
| 69 | struct sctp_chunk *chunk, |
| 70 | sctp_cmd_seq_t *commands); |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 71 | static struct sctp_packet *sctp_ootb_pkt_new(struct net *net, |
| 72 | const struct sctp_association *asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | const struct sctp_chunk *chunk); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 74 | static void sctp_send_stale_cookie_err(struct net *net, |
| 75 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | const struct sctp_association *asoc, |
| 77 | const struct sctp_chunk *chunk, |
| 78 | sctp_cmd_seq_t *commands, |
| 79 | struct sctp_chunk *err_chunk); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 80 | static sctp_disposition_t sctp_sf_do_5_2_6_stale(struct net *net, |
| 81 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | const struct sctp_association *asoc, |
| 83 | const sctp_subtype_t type, |
| 84 | void *arg, |
| 85 | sctp_cmd_seq_t *commands); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 86 | static sctp_disposition_t sctp_sf_shut_8_4_5(struct net *net, |
| 87 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | const struct sctp_association *asoc, |
| 89 | const sctp_subtype_t type, |
| 90 | void *arg, |
| 91 | sctp_cmd_seq_t *commands); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 92 | static sctp_disposition_t sctp_sf_tabort_8_4_8(struct net *net, |
| 93 | const struct sctp_endpoint *ep, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 94 | const struct sctp_association *asoc, |
| 95 | const sctp_subtype_t type, |
| 96 | void *arg, |
| 97 | sctp_cmd_seq_t *commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk); |
| 99 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 100 | static sctp_disposition_t sctp_stop_t1_and_abort(struct net *net, |
| 101 | sctp_cmd_seq_t *commands, |
Al Viro | f94c019 | 2006-11-20 17:00:25 -0800 | [diff] [blame] | 102 | __be16 error, int sk_err, |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 103 | const struct sctp_association *asoc, |
| 104 | struct sctp_transport *transport); |
| 105 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 106 | static sctp_disposition_t sctp_sf_abort_violation( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 107 | struct net *net, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 108 | const struct sctp_endpoint *ep, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 109 | const struct sctp_association *asoc, |
| 110 | void *arg, |
| 111 | sctp_cmd_seq_t *commands, |
| 112 | const __u8 *payload, |
| 113 | const size_t paylen); |
| 114 | |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 115 | static sctp_disposition_t sctp_sf_violation_chunklen( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 116 | struct net *net, |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 117 | const struct sctp_endpoint *ep, |
| 118 | const struct sctp_association *asoc, |
| 119 | const sctp_subtype_t type, |
| 120 | void *arg, |
| 121 | sctp_cmd_seq_t *commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 123 | static sctp_disposition_t sctp_sf_violation_paramlen( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 124 | struct net *net, |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 125 | const struct sctp_endpoint *ep, |
| 126 | const struct sctp_association *asoc, |
| 127 | const sctp_subtype_t type, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 128 | void *arg, void *ext, |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 129 | sctp_cmd_seq_t *commands); |
| 130 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 131 | static sctp_disposition_t sctp_sf_violation_ctsn( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 132 | struct net *net, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 133 | const struct sctp_endpoint *ep, |
| 134 | const struct sctp_association *asoc, |
| 135 | const sctp_subtype_t type, |
| 136 | void *arg, |
| 137 | sctp_cmd_seq_t *commands); |
| 138 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 139 | static sctp_disposition_t sctp_sf_violation_chunk( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 140 | struct net *net, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 141 | const struct sctp_endpoint *ep, |
| 142 | const struct sctp_association *asoc, |
| 143 | const sctp_subtype_t type, |
| 144 | void *arg, |
| 145 | sctp_cmd_seq_t *commands); |
| 146 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 147 | static sctp_ierror_t sctp_sf_authenticate(struct net *net, |
| 148 | const struct sctp_endpoint *ep, |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 149 | const struct sctp_association *asoc, |
| 150 | const sctp_subtype_t type, |
| 151 | struct sctp_chunk *chunk); |
| 152 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 153 | static sctp_disposition_t __sctp_sf_do_9_1_abort(struct net *net, |
| 154 | const struct sctp_endpoint *ep, |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 155 | const struct sctp_association *asoc, |
| 156 | const sctp_subtype_t type, |
| 157 | void *arg, |
| 158 | sctp_cmd_seq_t *commands); |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* Small helper function that checks if the chunk length |
| 161 | * is of the appropriate length. The 'required_length' argument |
| 162 | * is set to be the size of a specific chunk we are testing. |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 163 | * Return Values: true = Valid length |
| 164 | * false = Invalid length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | * |
| 166 | */ |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 167 | static inline bool |
| 168 | sctp_chunk_length_valid(struct sctp_chunk *chunk, __u16 required_length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { |
| 170 | __u16 chunk_length = ntohs(chunk->chunk_hdr->length); |
| 171 | |
Daniel Borkmann | 26b87c7 | 2014-10-09 22:55:33 +0200 | [diff] [blame] | 172 | /* Previously already marked? */ |
| 173 | if (unlikely(chunk->pdiscard)) |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 174 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | if (unlikely(chunk_length < required_length)) |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 176 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Marcelo Ricardo Leitner | 509e7a3 | 2016-12-28 09:26:35 -0200 | [diff] [blame] | 178 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /********************************************************** |
| 182 | * These are the state functions for handling chunk events. |
| 183 | **********************************************************/ |
| 184 | |
| 185 | /* |
| 186 | * Process the final SHUTDOWN COMPLETE. |
| 187 | * |
| 188 | * Section: 4 (C) (diagram), 9.2 |
| 189 | * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify |
| 190 | * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be |
| 191 | * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint |
| 192 | * should stop the T2-shutdown timer and remove all knowledge of the |
| 193 | * association (and thus the association enters the CLOSED state). |
| 194 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 195 | * Verification Tag: 8.5.1(C), sctpimpguide 2.41. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * C) Rules for packet carrying SHUTDOWN COMPLETE: |
| 197 | * ... |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 198 | * - The receiver of a SHUTDOWN COMPLETE shall accept the packet |
| 199 | * if the Verification Tag field of the packet matches its own tag and |
| 200 | * the T bit is not set |
| 201 | * OR |
| 202 | * it is set to its peer's tag and the T bit is set in the Chunk |
| 203 | * Flags. |
| 204 | * Otherwise, the receiver MUST silently discard the packet |
| 205 | * and take no further action. An endpoint MUST ignore the |
| 206 | * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | * |
| 208 | * Inputs |
| 209 | * (endpoint, asoc, chunk) |
| 210 | * |
| 211 | * Outputs |
| 212 | * (asoc, reply_msg, msg_up, timers, counters) |
| 213 | * |
| 214 | * The return value is the disposition of the chunk. |
| 215 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 216 | sctp_disposition_t sctp_sf_do_4_C(struct net *net, |
| 217 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | const struct sctp_association *asoc, |
| 219 | const sctp_subtype_t type, |
| 220 | void *arg, |
| 221 | sctp_cmd_seq_t *commands) |
| 222 | { |
| 223 | struct sctp_chunk *chunk = arg; |
| 224 | struct sctp_ulpevent *ev; |
| 225 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 226 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 227 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | /* RFC 2960 6.10 Bundling |
| 230 | * |
| 231 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 232 | * SHUTDOWN COMPLETE with any other chunks. |
| 233 | */ |
| 234 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 235 | return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 237 | /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 238 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 239 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 240 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* RFC 2960 10.2 SCTP-to-ULP |
| 243 | * |
| 244 | * H) SHUTDOWN COMPLETE notification |
| 245 | * |
| 246 | * When SCTP completes the shutdown procedures (section 9.2) this |
| 247 | * notification is passed to the upper layer. |
| 248 | */ |
| 249 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 250 | 0, 0, 0, NULL, GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 251 | if (ev) |
| 252 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 253 | SCTP_ULPEVENT(ev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint |
| 256 | * will verify that it is in SHUTDOWN-ACK-SENT state, if it is |
| 257 | * not the chunk should be discarded. If the endpoint is in |
| 258 | * the SHUTDOWN-ACK-SENT state the endpoint should stop the |
| 259 | * T2-shutdown timer and remove all knowledge of the |
| 260 | * association (and thus the association enters the CLOSED |
| 261 | * state). |
| 262 | */ |
| 263 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 264 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 265 | |
| 266 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 267 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 268 | |
| 269 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 270 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 271 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 272 | SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS); |
| 273 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 276 | |
| 277 | return SCTP_DISPOSITION_DELETE_TCB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | /* |
| 281 | * Respond to a normal INIT chunk. |
| 282 | * We are the side that is being asked for an association. |
| 283 | * |
| 284 | * Section: 5.1 Normal Establishment of an Association, B |
| 285 | * B) "Z" shall respond immediately with an INIT ACK chunk. The |
| 286 | * destination IP address of the INIT ACK MUST be set to the source |
| 287 | * IP address of the INIT to which this INIT ACK is responding. In |
| 288 | * the response, besides filling in other parameters, "Z" must set the |
| 289 | * Verification Tag field to Tag_A, and also provide its own |
| 290 | * Verification Tag (Tag_Z) in the Initiate Tag field. |
| 291 | * |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 292 | * Verification Tag: Must be 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | * |
| 294 | * Inputs |
| 295 | * (endpoint, asoc, chunk) |
| 296 | * |
| 297 | * Outputs |
| 298 | * (asoc, reply_msg, msg_up, timers, counters) |
| 299 | * |
| 300 | * The return value is the disposition of the chunk. |
| 301 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 302 | sctp_disposition_t sctp_sf_do_5_1B_init(struct net *net, |
| 303 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | const struct sctp_association *asoc, |
| 305 | const sctp_subtype_t type, |
| 306 | void *arg, |
| 307 | sctp_cmd_seq_t *commands) |
| 308 | { |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 309 | struct sctp_chunk *chunk = arg, *repl, *err_chunk; |
| 310 | struct sctp_unrecognized_param *unk_param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | struct sctp_association *new_asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct sctp_packet *packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | int len; |
| 314 | |
| 315 | /* 6.10 Bundling |
| 316 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 317 | * SHUTDOWN COMPLETE with any other chunks. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 318 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | * IG Section 2.11.2 |
| 320 | * Furthermore, we require that the receiver of an INIT chunk MUST |
| 321 | * enforce these rules by silently discarding an arriving packet |
| 322 | * with an INIT chunk that is bundled with other chunks. |
| 323 | */ |
| 324 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 325 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | /* If the packet is an OOTB packet which is temporarily on the |
| 328 | * control endpoint, respond with an ABORT. |
| 329 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 330 | if (ep == sctp_sk(net->sctp.ctl_sock)->ep) { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 331 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 332 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* 3.1 A packet containing an INIT chunk MUST have a zero Verification |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 336 | * Tag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | */ |
| 338 | if (chunk->sctp_hdr->vtag != 0) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 339 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | /* Make sure that the INIT chunk has a valid length. |
| 342 | * Normally, this would cause an ABORT with a Protocol Violation |
| 343 | * error, but since we don't have an association, we'll |
| 344 | * just discard the packet. |
| 345 | */ |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 346 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 347 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Vlad Yasevich | bec9640 | 2009-07-30 18:08:28 -0400 | [diff] [blame] | 349 | /* If the INIT is coming toward a closing socket, we'll send back |
| 350 | * and ABORT. Essentially, this catches the race of INIT being |
| 351 | * backloged to the socket at the same time as the user isses close(). |
| 352 | * Since the socket and all its associations are going away, we |
| 353 | * can treat this OOTB |
| 354 | */ |
| 355 | if (sctp_sstate(ep->base.sk, CLOSING)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 356 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bec9640 | 2009-07-30 18:08:28 -0400 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | /* Verify the INIT chunk before processing it. */ |
| 359 | err_chunk = NULL; |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 360 | if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type, |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 361 | (struct sctp_init_chunk *)chunk->chunk_hdr, chunk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | &err_chunk)) { |
| 363 | /* This chunk contains fatal error. It is to be discarded. |
| 364 | * Send an ABORT, with causes if there is any. |
| 365 | */ |
| 366 | if (err_chunk) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 367 | packet = sctp_abort_pkt_new(net, ep, asoc, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | (__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 369 | sizeof(struct sctp_chunkhdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 371 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | sctp_chunk_free(err_chunk); |
| 374 | |
| 375 | if (packet) { |
| 376 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 377 | SCTP_PACKET(packet)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 378 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | return SCTP_DISPOSITION_CONSUME; |
| 380 | } else { |
| 381 | return SCTP_DISPOSITION_NOMEM; |
| 382 | } |
| 383 | } else { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 384 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | commands); |
| 386 | } |
| 387 | } |
| 388 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 389 | /* Grab the INIT header. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 390 | chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | /* Tag the variable length parameters. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 393 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); |
| 396 | if (!new_asoc) |
| 397 | goto nomem; |
| 398 | |
Vlad Yasevich | 409b95a | 2009-11-10 08:57:34 +0000 | [diff] [blame] | 399 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, |
| 400 | sctp_scope(sctp_source(chunk)), |
| 401 | GFP_ATOMIC) < 0) |
| 402 | goto nomem_init; |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | /* The call, sctp_process_init(), can fail on memory allocation. */ |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 405 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 406 | (struct sctp_init_chunk *)chunk->chunk_hdr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | GFP_ATOMIC)) |
| 408 | goto nomem_init; |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
| 411 | |
| 412 | /* If there are errors need to be reported for unknown parameters, |
| 413 | * make sure to reserve enough room in the INIT ACK for them. |
| 414 | */ |
| 415 | len = 0; |
| 416 | if (err_chunk) |
| 417 | len = ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 418 | sizeof(struct sctp_chunkhdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); |
| 421 | if (!repl) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 422 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | /* If there are errors need to be reported for unknown parameters, |
| 425 | * include them in the outgoing INIT ACK as "Unrecognized parameter" |
| 426 | * parameter. |
| 427 | */ |
| 428 | if (err_chunk) { |
| 429 | /* Get the "Unrecognized parameter" parameter(s) out of the |
| 430 | * ERROR chunk generated by sctp_verify_init(). Since the |
| 431 | * error cause code for "unknown parameter" and the |
| 432 | * "Unrecognized parameter" type is the same, we can |
| 433 | * construct the parameters in INIT ACK by copying the |
| 434 | * ERROR causes over. |
| 435 | */ |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 436 | unk_param = (struct sctp_unrecognized_param *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | ((__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 438 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | /* Replace the cause code with the "Unrecognized parameter" |
| 440 | * parameter type. |
| 441 | */ |
| 442 | sctp_addto_chunk(repl, len, unk_param); |
| 443 | sctp_chunk_free(err_chunk); |
| 444 | } |
| 445 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 446 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 449 | |
| 450 | /* |
| 451 | * Note: After sending out INIT ACK with the State Cookie parameter, |
| 452 | * "Z" MUST NOT allocate any resources, nor keep any states for the |
| 453 | * new association. Otherwise, "Z" will be vulnerable to resource |
| 454 | * attacks. |
| 455 | */ |
| 456 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 457 | |
| 458 | return SCTP_DISPOSITION_DELETE_TCB; |
| 459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | nomem_init: |
| 461 | sctp_association_free(new_asoc); |
| 462 | nomem: |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 463 | if (err_chunk) |
| 464 | sctp_chunk_free(err_chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | return SCTP_DISPOSITION_NOMEM; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * Respond to a normal INIT ACK chunk. |
| 470 | * We are the side that is initiating the association. |
| 471 | * |
| 472 | * Section: 5.1 Normal Establishment of an Association, C |
| 473 | * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init |
| 474 | * timer and leave COOKIE-WAIT state. "A" shall then send the State |
| 475 | * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start |
| 476 | * the T1-cookie timer, and enter the COOKIE-ECHOED state. |
| 477 | * |
| 478 | * Note: The COOKIE ECHO chunk can be bundled with any pending outbound |
| 479 | * DATA chunks, but it MUST be the first chunk in the packet and |
| 480 | * until the COOKIE ACK is returned the sender MUST NOT send any |
| 481 | * other packets to the peer. |
| 482 | * |
| 483 | * Verification Tag: 3.3.3 |
| 484 | * If the value of the Initiate Tag in a received INIT ACK chunk is |
| 485 | * found to be 0, the receiver MUST treat it as an error and close the |
| 486 | * association by transmitting an ABORT. |
| 487 | * |
| 488 | * Inputs |
| 489 | * (endpoint, asoc, chunk) |
| 490 | * |
| 491 | * Outputs |
| 492 | * (asoc, reply_msg, msg_up, timers, counters) |
| 493 | * |
| 494 | * The return value is the disposition of the chunk. |
| 495 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 496 | sctp_disposition_t sctp_sf_do_5_1C_ack(struct net *net, |
| 497 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | const struct sctp_association *asoc, |
| 499 | const sctp_subtype_t type, |
| 500 | void *arg, |
| 501 | sctp_cmd_seq_t *commands) |
| 502 | { |
| 503 | struct sctp_chunk *chunk = arg; |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 504 | struct sctp_init_chunk *initchunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | struct sctp_chunk *err_chunk; |
| 506 | struct sctp_packet *packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 509 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | /* 6.10 Bundling |
| 512 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 513 | * SHUTDOWN COMPLETE with any other chunks. |
| 514 | */ |
| 515 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 516 | return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 518 | /* Make sure that the INIT-ACK chunk has a valid length */ |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 519 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 520 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 521 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* Grab the INIT header. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 523 | chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | /* Verify the INIT chunk before processing it. */ |
| 526 | err_chunk = NULL; |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 527 | if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type, |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 528 | (struct sctp_init_chunk *)chunk->chunk_hdr, chunk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | &err_chunk)) { |
| 530 | |
Xin Long | 2a49321 | 2017-08-03 15:42:13 +0800 | [diff] [blame] | 531 | enum sctp_error error = SCTP_ERROR_NO_RESOURCE; |
Vlad Yasevich | 853f4b5 | 2008-01-20 06:10:46 -0800 | [diff] [blame] | 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | /* This chunk contains fatal error. It is to be discarded. |
Vlad Yasevich | d670119 | 2007-12-20 14:13:31 -0800 | [diff] [blame] | 534 | * Send an ABORT, with causes. If there are no causes, |
| 535 | * then there wasn't enough memory. Just terminate |
| 536 | * the association. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | */ |
| 538 | if (err_chunk) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 539 | packet = sctp_abort_pkt_new(net, ep, asoc, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | (__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 541 | sizeof(struct sctp_chunkhdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 543 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | sctp_chunk_free(err_chunk); |
| 546 | |
| 547 | if (packet) { |
| 548 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 549 | SCTP_PACKET(packet)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 550 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 551 | error = SCTP_ERROR_INV_PARAM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 554 | |
| 555 | /* SCTP-AUTH, Section 6.3: |
| 556 | * It should be noted that if the receiver wants to tear |
| 557 | * down an association in an authenticated way only, the |
| 558 | * handling of malformed packets should not result in |
| 559 | * tearing down the association. |
| 560 | * |
| 561 | * This means that if we only want to abort associations |
| 562 | * in an authenticated way (i.e AUTH+ABORT), then we |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 563 | * can't destroy this association just because the packet |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 564 | * was malformed. |
| 565 | */ |
| 566 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 567 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 568 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 569 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 570 | return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 571 | asoc, chunk->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /* Tag the variable length parameters. Note that we never |
| 575 | * convert the parameters in an INIT chunk. |
| 576 | */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 577 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 579 | initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT, |
| 582 | SCTP_PEER_INIT(initchunk)); |
| 583 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 584 | /* Reset init error count upon receipt of INIT-ACK. */ |
| 585 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
| 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | /* 5.1 C) "A" shall stop the T1-init timer and leave |
| 588 | * COOKIE-WAIT state. "A" shall then ... start the T1-cookie |
| 589 | * timer, and enter the COOKIE-ECHOED state. |
| 590 | */ |
| 591 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 592 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 593 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 594 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 595 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 596 | SCTP_STATE(SCTP_STATE_COOKIE_ECHOED)); |
| 597 | |
Vlad Yasevich | 730fc3d | 2007-09-16 19:32:11 -0700 | [diff] [blame] | 598 | /* SCTP-AUTH: genereate the assocition shared keys so that |
| 599 | * we can potentially signe the COOKIE-ECHO. |
| 600 | */ |
| 601 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL()); |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | /* 5.1 C) "A" shall then send the State Cookie received in the |
| 604 | * INIT ACK chunk in a COOKIE ECHO chunk, ... |
| 605 | */ |
| 606 | /* If there is any errors to report, send the ERROR chunk generated |
| 607 | * for unknown parameters as well. |
| 608 | */ |
| 609 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO, |
| 610 | SCTP_CHUNK(err_chunk)); |
| 611 | |
| 612 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* |
| 616 | * Respond to a normal COOKIE ECHO chunk. |
| 617 | * We are the side that is being asked for an association. |
| 618 | * |
| 619 | * Section: 5.1 Normal Establishment of an Association, D |
| 620 | * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply |
| 621 | * with a COOKIE ACK chunk after building a TCB and moving to |
| 622 | * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with |
| 623 | * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK |
| 624 | * chunk MUST be the first chunk in the packet. |
| 625 | * |
| 626 | * IMPLEMENTATION NOTE: An implementation may choose to send the |
| 627 | * Communication Up notification to the SCTP user upon reception |
| 628 | * of a valid COOKIE ECHO chunk. |
| 629 | * |
| 630 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules |
| 631 | * D) Rules for packet carrying a COOKIE ECHO |
| 632 | * |
| 633 | * - When sending a COOKIE ECHO, the endpoint MUST use the value of the |
| 634 | * Initial Tag received in the INIT ACK. |
| 635 | * |
| 636 | * - The receiver of a COOKIE ECHO follows the procedures in Section 5. |
| 637 | * |
| 638 | * Inputs |
| 639 | * (endpoint, asoc, chunk) |
| 640 | * |
| 641 | * Outputs |
| 642 | * (asoc, reply_msg, msg_up, timers, counters) |
| 643 | * |
| 644 | * The return value is the disposition of the chunk. |
| 645 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 646 | sctp_disposition_t sctp_sf_do_5_1D_ce(struct net *net, |
| 647 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | const struct sctp_association *asoc, |
| 649 | const sctp_subtype_t type, void *arg, |
| 650 | sctp_cmd_seq_t *commands) |
| 651 | { |
| 652 | struct sctp_chunk *chunk = arg; |
| 653 | struct sctp_association *new_asoc; |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 654 | struct sctp_init_chunk *peer_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | struct sctp_chunk *repl; |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 656 | struct sctp_ulpevent *ev, *ai_ev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | int error = 0; |
| 658 | struct sctp_chunk *err_chk_p; |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 659 | struct sock *sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | /* If the packet is an OOTB packet which is temporarily on the |
| 662 | * control endpoint, respond with an ABORT. |
| 663 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 664 | if (ep == sctp_sk(net->sctp.ctl_sock)->ep) { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 665 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 666 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | |
| 669 | /* Make sure that the COOKIE_ECHO chunk has a valid length. |
| 670 | * In this case, we check that we have enough for at least a |
| 671 | * chunk header. More detailed verification is done |
| 672 | * in sctp_unpack_cookie(). |
| 673 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 674 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 675 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 677 | /* If the endpoint is not listening or if the number of associations |
| 678 | * on the TCP-style socket exceed the max backlog, respond with an |
| 679 | * ABORT. |
| 680 | */ |
| 681 | sk = ep->base.sk; |
| 682 | if (!sctp_sstate(sk, LISTENING) || |
| 683 | (sctp_style(sk, TCP) && sk_acceptq_is_full(sk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 684 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | /* "Decode" the chunk. We have no optional parameters so we |
| 687 | * are in good shape. |
| 688 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 689 | chunk->subh.cookie_hdr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | (struct sctp_signed_cookie *)chunk->skb->data; |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 691 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 692 | sizeof(struct sctp_chunkhdr))) |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 693 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint |
| 696 | * "Z" will reply with a COOKIE ACK chunk after building a TCB |
| 697 | * and moving to the ESTABLISHED state. |
| 698 | */ |
| 699 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, |
| 700 | &err_chk_p); |
| 701 | |
| 702 | /* FIXME: |
| 703 | * If the re-build failed, what is the proper error path |
| 704 | * from here? |
| 705 | * |
| 706 | * [We should abort the association. --piggy] |
| 707 | */ |
| 708 | if (!new_asoc) { |
| 709 | /* FIXME: Several errors are possible. A bad cookie should |
| 710 | * be silently discarded, but think about logging it too. |
| 711 | */ |
| 712 | switch (error) { |
| 713 | case -SCTP_IERROR_NOMEM: |
| 714 | goto nomem; |
| 715 | |
| 716 | case -SCTP_IERROR_STALE_COOKIE: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 717 | sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | err_chk_p); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 719 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
| 721 | case -SCTP_IERROR_BAD_SIG: |
| 722 | default: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 723 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 728 | /* Delay state machine commands until later. |
| 729 | * |
| 730 | * Re-build the bind address for the association is done in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | * the sctp_unpack_cookie() already. |
| 732 | */ |
| 733 | /* This is a brand-new association, so these are not yet side |
| 734 | * effects--it is safe to run them here. |
| 735 | */ |
| 736 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 737 | |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 738 | if (!sctp_process_init(new_asoc, chunk, |
Al Viro | 6a1e5f3 | 2006-11-20 17:12:25 -0800 | [diff] [blame] | 739 | &chunk->subh.cookie_hdr->c.peer_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | peer_init, GFP_ATOMIC)) |
| 741 | goto nomem_init; |
| 742 | |
Vlad Yasevich | 730fc3d | 2007-09-16 19:32:11 -0700 | [diff] [blame] | 743 | /* SCTP-AUTH: Now that we've populate required fields in |
| 744 | * sctp_process_init, set up the assocaition shared keys as |
| 745 | * necessary so that we can potentially authenticate the ACK |
| 746 | */ |
| 747 | error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC); |
| 748 | if (error) |
| 749 | goto nomem_init; |
| 750 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 751 | /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo |
| 752 | * is supposed to be authenticated and we have to do delayed |
| 753 | * authentication. We've just recreated the association using |
| 754 | * the information in the cookie and now it's much easier to |
| 755 | * do the authentication. |
| 756 | */ |
| 757 | if (chunk->auth_chunk) { |
| 758 | struct sctp_chunk auth; |
| 759 | sctp_ierror_t ret; |
| 760 | |
Daniel Borkmann | ec0223e | 2014-03-03 17:23:04 +0100 | [diff] [blame] | 761 | /* Make sure that we and the peer are AUTH capable */ |
| 762 | if (!net->sctp.auth_enable || !new_asoc->peer.auth_capable) { |
Daniel Borkmann | ec0223e | 2014-03-03 17:23:04 +0100 | [diff] [blame] | 763 | sctp_association_free(new_asoc); |
| 764 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 765 | } |
| 766 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 767 | /* set-up our fake chunk so that we can process it */ |
| 768 | auth.skb = chunk->auth_chunk; |
| 769 | auth.asoc = chunk->asoc; |
| 770 | auth.sctp_hdr = chunk->sctp_hdr; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 771 | auth.chunk_hdr = (struct sctp_chunkhdr *) |
| 772 | skb_push(chunk->auth_chunk, |
| 773 | sizeof(struct sctp_chunkhdr)); |
| 774 | skb_pull(chunk->auth_chunk, sizeof(struct sctp_chunkhdr)); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 775 | auth.transport = chunk->transport; |
| 776 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 777 | ret = sctp_sf_authenticate(net, ep, new_asoc, type, &auth); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 778 | if (ret != SCTP_IERROR_NO_ERROR) { |
| 779 | sctp_association_free(new_asoc); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 780 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 785 | if (!repl) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 786 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 789 | * |
| 790 | * D) IMPLEMENTATION NOTE: An implementation may choose to |
| 791 | * send the Communication Up notification to the SCTP user |
| 792 | * upon reception of a valid COOKIE ECHO chunk. |
| 793 | */ |
| 794 | ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0, |
| 795 | new_asoc->c.sinit_num_ostreams, |
| 796 | new_asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 797 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (!ev) |
| 799 | goto nomem_ev; |
| 800 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 801 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 802 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 804 | * peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 806 | if (new_asoc->peer.adaptation_ind) { |
| 807 | ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 809 | if (!ai_ev) |
| 810 | goto nomem_aiev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 813 | /* Add all the state machine commands now since we've created |
| 814 | * everything. This way we don't introduce memory corruptions |
| 815 | * during side-effect processing and correclty count established |
| 816 | * associations. |
| 817 | */ |
| 818 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 819 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 820 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 821 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
| 822 | SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 823 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 824 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 825 | if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 826 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 827 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 828 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 829 | /* This will send the COOKIE ACK */ |
| 830 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 831 | |
| 832 | /* Queue the ASSOC_CHANGE event */ |
| 833 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 834 | |
| 835 | /* Send up the Adaptation Layer Indication event */ |
| 836 | if (ai_ev) |
| 837 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 838 | SCTP_ULPEVENT(ai_ev)); |
| 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | return SCTP_DISPOSITION_CONSUME; |
| 841 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 842 | nomem_aiev: |
| 843 | sctp_ulpevent_free(ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | nomem_ev: |
| 845 | sctp_chunk_free(repl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | nomem_init: |
| 847 | sctp_association_free(new_asoc); |
| 848 | nomem: |
| 849 | return SCTP_DISPOSITION_NOMEM; |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Respond to a normal COOKIE ACK chunk. |
Marcelo Ricardo Leitner | b52effd | 2015-07-17 13:50:21 -0300 | [diff] [blame] | 854 | * We are the side that is asking for an association. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | * |
| 856 | * RFC 2960 5.1 Normal Establishment of an Association |
| 857 | * |
| 858 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the |
| 859 | * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie |
| 860 | * timer. It may also notify its ULP about the successful |
| 861 | * establishment of the association with a Communication Up |
| 862 | * notification (see Section 10). |
| 863 | * |
| 864 | * Verification Tag: |
| 865 | * Inputs |
| 866 | * (endpoint, asoc, chunk) |
| 867 | * |
| 868 | * Outputs |
| 869 | * (asoc, reply_msg, msg_up, timers, counters) |
| 870 | * |
| 871 | * The return value is the disposition of the chunk. |
| 872 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 873 | sctp_disposition_t sctp_sf_do_5_1E_ca(struct net *net, |
| 874 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | const struct sctp_association *asoc, |
| 876 | const sctp_subtype_t type, void *arg, |
| 877 | sctp_cmd_seq_t *commands) |
| 878 | { |
| 879 | struct sctp_chunk *chunk = arg; |
| 880 | struct sctp_ulpevent *ev; |
| 881 | |
| 882 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 883 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
| 885 | /* Verify that the chunk length for the COOKIE-ACK is OK. |
| 886 | * If we don't do this, any bundled chunks may be junked. |
| 887 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 888 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 889 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | commands); |
| 891 | |
| 892 | /* Reset init error count upon receipt of COOKIE-ACK, |
| 893 | * to avoid problems with the managemement of this |
| 894 | * counter in stale cookie situations when a transition back |
| 895 | * from the COOKIE-ECHOED state to the COOKIE-WAIT |
| 896 | * state is performed. |
| 897 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 898 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 901 | * |
| 902 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move |
| 903 | * from the COOKIE-ECHOED state to the ESTABLISHED state, |
| 904 | * stopping the T1-cookie timer. |
| 905 | */ |
| 906 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 907 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 908 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 909 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 910 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
| 911 | SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 913 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 915 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | /* It may also notify its ULP about the successful |
| 918 | * establishment of the association with a Communication Up |
| 919 | * notification (see Section 10). |
| 920 | */ |
| 921 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, |
| 922 | 0, asoc->c.sinit_num_ostreams, |
| 923 | asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 924 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | if (!ev) |
| 927 | goto nomem; |
| 928 | |
| 929 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 930 | |
| 931 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 932 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 934 | * peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 936 | if (asoc->peer.adaptation_ind) { |
| 937 | ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | if (!ev) |
| 939 | goto nomem; |
| 940 | |
| 941 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 942 | SCTP_ULPEVENT(ev)); |
| 943 | } |
| 944 | |
| 945 | return SCTP_DISPOSITION_CONSUME; |
| 946 | nomem: |
| 947 | return SCTP_DISPOSITION_NOMEM; |
| 948 | } |
| 949 | |
| 950 | /* Generate and sendout a heartbeat packet. */ |
| 951 | static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep, |
| 952 | const struct sctp_association *asoc, |
| 953 | const sctp_subtype_t type, |
| 954 | void *arg, |
| 955 | sctp_cmd_seq_t *commands) |
| 956 | { |
| 957 | struct sctp_transport *transport = (struct sctp_transport *) arg; |
| 958 | struct sctp_chunk *reply; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | |
| 960 | /* Send a heartbeat to our peer. */ |
Wei Yongjun | 92c73af | 2011-04-19 21:31:47 +0000 | [diff] [blame] | 961 | reply = sctp_make_heartbeat(asoc, transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | if (!reply) |
| 963 | return SCTP_DISPOSITION_NOMEM; |
| 964 | |
| 965 | /* Set rto_pending indicating that an RTT measurement |
| 966 | * is started with this heartbeat chunk. |
| 967 | */ |
| 968 | sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING, |
| 969 | SCTP_TRANSPORT(transport)); |
| 970 | |
| 971 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 972 | return SCTP_DISPOSITION_CONSUME; |
| 973 | } |
| 974 | |
| 975 | /* Generate a HEARTBEAT packet on the given transport. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 976 | sctp_disposition_t sctp_sf_sendbeat_8_3(struct net *net, |
| 977 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | const struct sctp_association *asoc, |
| 979 | const sctp_subtype_t type, |
| 980 | void *arg, |
| 981 | sctp_cmd_seq_t *commands) |
| 982 | { |
| 983 | struct sctp_transport *transport = (struct sctp_transport *) arg; |
| 984 | |
Vlad Yasevich | b9f8478 | 2009-08-26 09:36:25 -0400 | [diff] [blame] | 985 | if (asoc->overall_error_count >= asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 986 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 987 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 989 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 990 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 991 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 992 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | return SCTP_DISPOSITION_DELETE_TCB; |
| 994 | } |
| 995 | |
| 996 | /* Section 3.3.5. |
| 997 | * The Sender-specific Heartbeat Info field should normally include |
| 998 | * information about the sender's current time when this HEARTBEAT |
| 999 | * chunk is sent and the destination transport address to which this |
| 1000 | * HEARTBEAT is sent (see Section 8.3). |
| 1001 | */ |
| 1002 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 1003 | if (transport->param_flags & SPP_HB_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | if (SCTP_DISPOSITION_NOMEM == |
| 1005 | sctp_sf_heartbeat(ep, asoc, type, arg, |
| 1006 | commands)) |
| 1007 | return SCTP_DISPOSITION_NOMEM; |
Vlad Yasevich | 245cba7 | 2009-11-23 15:53:58 -0500 | [diff] [blame] | 1008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | /* Set transport error counter and association error counter |
| 1010 | * when sending heartbeat. |
| 1011 | */ |
Vlad Yasevich | 7e99013 | 2009-03-02 09:46:14 +0000 | [diff] [blame] | 1012 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | SCTP_TRANSPORT(transport)); |
| 1014 | } |
Vlad Yasevich | 245cba7 | 2009-11-23 15:53:58 -0500 | [diff] [blame] | 1015 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE, |
| 1016 | SCTP_TRANSPORT(transport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE, |
| 1018 | SCTP_TRANSPORT(transport)); |
| 1019 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1020 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Xin Long | 7b9438d | 2017-01-18 00:44:43 +0800 | [diff] [blame] | 1023 | /* resend asoc strreset_chunk. */ |
| 1024 | sctp_disposition_t sctp_sf_send_reconf(struct net *net, |
| 1025 | const struct sctp_endpoint *ep, |
| 1026 | const struct sctp_association *asoc, |
| 1027 | const sctp_subtype_t type, void *arg, |
| 1028 | sctp_cmd_seq_t *commands) |
| 1029 | { |
| 1030 | struct sctp_transport *transport = arg; |
| 1031 | |
| 1032 | if (asoc->overall_error_count >= asoc->max_retrans) { |
| 1033 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 1034 | SCTP_ERROR(ETIMEDOUT)); |
| 1035 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 1036 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 1037 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
| 1038 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 1039 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
| 1040 | return SCTP_DISPOSITION_DELETE_TCB; |
| 1041 | } |
| 1042 | |
| 1043 | sctp_chunk_hold(asoc->strreset_chunk); |
| 1044 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 1045 | SCTP_CHUNK(asoc->strreset_chunk)); |
| 1046 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); |
| 1047 | |
| 1048 | return SCTP_DISPOSITION_CONSUME; |
| 1049 | } |
| 1050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | /* |
| 1052 | * Process an heartbeat request. |
| 1053 | * |
| 1054 | * Section: 8.3 Path Heartbeat |
| 1055 | * The receiver of the HEARTBEAT should immediately respond with a |
| 1056 | * HEARTBEAT ACK that contains the Heartbeat Information field copied |
| 1057 | * from the received HEARTBEAT chunk. |
| 1058 | * |
| 1059 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 1060 | * When receiving an SCTP packet, the endpoint MUST ensure that the |
| 1061 | * value in the Verification Tag field of the received SCTP packet |
| 1062 | * matches its own Tag. If the received Verification Tag value does not |
| 1063 | * match the receiver's own tag value, the receiver shall silently |
| 1064 | * discard the packet and shall not process it any further except for |
| 1065 | * those cases listed in Section 8.5.1 below. |
| 1066 | * |
| 1067 | * Inputs |
| 1068 | * (endpoint, asoc, chunk) |
| 1069 | * |
| 1070 | * Outputs |
| 1071 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1072 | * |
| 1073 | * The return value is the disposition of the chunk. |
| 1074 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1075 | sctp_disposition_t sctp_sf_beat_8_3(struct net *net, |
| 1076 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | const struct sctp_association *asoc, |
| 1078 | const sctp_subtype_t type, |
| 1079 | void *arg, |
| 1080 | sctp_cmd_seq_t *commands) |
| 1081 | { |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 1082 | struct sctp_paramhdr *param_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | struct sctp_chunk *chunk = arg; |
| 1084 | struct sctp_chunk *reply; |
| 1085 | size_t paylen = 0; |
| 1086 | |
| 1087 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1088 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | /* Make sure that the HEARTBEAT chunk has a valid length. */ |
Xin Long | 38c00f7 | 2017-07-23 09:34:35 +0800 | [diff] [blame] | 1091 | if (!sctp_chunk_length_valid(chunk, |
| 1092 | sizeof(struct sctp_heartbeat_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1093 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | commands); |
| 1095 | |
| 1096 | /* 8.3 The receiver of the HEARTBEAT should immediately |
| 1097 | * respond with a HEARTBEAT ACK that contains the Heartbeat |
| 1098 | * Information field copied from the received HEARTBEAT chunk. |
| 1099 | */ |
Xin Long | 4d2dcdf | 2017-07-23 09:34:34 +0800 | [diff] [blame] | 1100 | chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data; |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 1101 | param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1102 | paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr); |
Thomas Graf | 06a31e2 | 2012-11-30 02:16:27 +0000 | [diff] [blame] | 1103 | |
| 1104 | if (ntohs(param_hdr->length) > paylen) |
| 1105 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
| 1106 | param_hdr, commands); |
| 1107 | |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 1108 | if (!pskb_pull(chunk->skb, paylen)) |
| 1109 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
Thomas Graf | 06a31e2 | 2012-11-30 02:16:27 +0000 | [diff] [blame] | 1111 | reply = sctp_make_heartbeat_ack(asoc, chunk, param_hdr, paylen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | if (!reply) |
| 1113 | goto nomem; |
| 1114 | |
| 1115 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 1116 | return SCTP_DISPOSITION_CONSUME; |
| 1117 | |
| 1118 | nomem: |
| 1119 | return SCTP_DISPOSITION_NOMEM; |
| 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * Process the returning HEARTBEAT ACK. |
| 1124 | * |
| 1125 | * Section: 8.3 Path Heartbeat |
| 1126 | * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT |
| 1127 | * should clear the error counter of the destination transport |
| 1128 | * address to which the HEARTBEAT was sent, and mark the destination |
| 1129 | * transport address as active if it is not so marked. The endpoint may |
| 1130 | * optionally report to the upper layer when an inactive destination |
| 1131 | * address is marked as active due to the reception of the latest |
| 1132 | * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also |
| 1133 | * clear the association overall error count as well (as defined |
| 1134 | * in section 8.1). |
| 1135 | * |
| 1136 | * The receiver of the HEARTBEAT ACK should also perform an RTT |
| 1137 | * measurement for that destination transport address using the time |
| 1138 | * value carried in the HEARTBEAT ACK chunk. |
| 1139 | * |
| 1140 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 1141 | * |
| 1142 | * Inputs |
| 1143 | * (endpoint, asoc, chunk) |
| 1144 | * |
| 1145 | * Outputs |
| 1146 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1147 | * |
| 1148 | * The return value is the disposition of the chunk. |
| 1149 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1150 | sctp_disposition_t sctp_sf_backbeat_8_3(struct net *net, |
| 1151 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | const struct sctp_association *asoc, |
| 1153 | const sctp_subtype_t type, |
| 1154 | void *arg, |
| 1155 | sctp_cmd_seq_t *commands) |
| 1156 | { |
| 1157 | struct sctp_chunk *chunk = arg; |
| 1158 | union sctp_addr from_addr; |
| 1159 | struct sctp_transport *link; |
| 1160 | sctp_sender_hb_info_t *hbinfo; |
| 1161 | unsigned long max_interval; |
| 1162 | |
| 1163 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1164 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
| 1166 | /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1167 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr) + |
Wei Yongjun | dadb50c | 2009-08-22 11:27:37 +0800 | [diff] [blame] | 1168 | sizeof(sctp_sender_hb_info_t))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1169 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | commands); |
| 1171 | |
| 1172 | hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data; |
Vladislav Yasevich | a601266 | 2006-05-19 14:25:53 -0700 | [diff] [blame] | 1173 | /* Make sure that the length of the parameter is what we expect */ |
| 1174 | if (ntohs(hbinfo->param_hdr.length) != |
| 1175 | sizeof(sctp_sender_hb_info_t)) { |
| 1176 | return SCTP_DISPOSITION_DISCARD; |
| 1177 | } |
| 1178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | from_addr = hbinfo->daddr; |
Al Viro | 63de08f | 2006-11-20 17:07:25 -0800 | [diff] [blame] | 1180 | link = sctp_assoc_lookup_paddr(asoc, &from_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
| 1182 | /* This should never happen, but lets log it if so. */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1183 | if (unlikely(!link)) { |
| 1184 | if (from_addr.sa.sa_family == AF_INET6) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1185 | net_warn_ratelimited("%s association %p could not find address %pI6\n", |
| 1186 | __func__, |
| 1187 | asoc, |
| 1188 | &from_addr.v6.sin6_addr); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1189 | } else { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1190 | net_warn_ratelimited("%s association %p could not find address %pI4\n", |
| 1191 | __func__, |
| 1192 | asoc, |
| 1193 | &from_addr.v4.sin_addr.s_addr); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | return SCTP_DISPOSITION_DISCARD; |
| 1196 | } |
| 1197 | |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 1198 | /* Validate the 64-bit random nonce. */ |
| 1199 | if (hbinfo->hb_nonce != link->hb_nonce) |
| 1200 | return SCTP_DISPOSITION_DISCARD; |
| 1201 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 1202 | max_interval = link->hbinterval + link->rto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | /* Check if the timestamp looks valid. */ |
| 1205 | if (time_after(hbinfo->sent_at, jiffies) || |
| 1206 | time_after(jiffies, hbinfo->sent_at + max_interval)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 1207 | pr_debug("%s: HEARTBEAT ACK with invalid timestamp received " |
| 1208 | "for transport:%p\n", __func__, link); |
| 1209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | return SCTP_DISPOSITION_DISCARD; |
| 1211 | } |
| 1212 | |
| 1213 | /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of |
| 1214 | * the HEARTBEAT should clear the error counter of the |
| 1215 | * destination transport address to which the HEARTBEAT was |
| 1216 | * sent and mark the destination transport address as active if |
| 1217 | * it is not so marked. |
| 1218 | */ |
| 1219 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link)); |
| 1220 | |
| 1221 | return SCTP_DISPOSITION_CONSUME; |
| 1222 | } |
| 1223 | |
| 1224 | /* Helper function to send out an abort for the restart |
| 1225 | * condition. |
| 1226 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1227 | static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | struct sctp_chunk *init, |
| 1229 | sctp_cmd_seq_t *commands) |
| 1230 | { |
| 1231 | int len; |
| 1232 | struct sctp_packet *pkt; |
| 1233 | union sctp_addr_param *addrparm; |
| 1234 | struct sctp_errhdr *errhdr; |
| 1235 | struct sctp_endpoint *ep; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 1236 | char buffer[sizeof(*errhdr) + sizeof(*addrparm)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family); |
| 1238 | |
| 1239 | /* Build the error on the stack. We are way to malloc crazy |
| 1240 | * throughout the code today. |
| 1241 | */ |
| 1242 | errhdr = (struct sctp_errhdr *)buffer; |
| 1243 | addrparm = (union sctp_addr_param *)errhdr->variable; |
| 1244 | |
| 1245 | /* Copy into a parm format. */ |
| 1246 | len = af->to_addr_param(ssa, addrparm); |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 1247 | len += sizeof(*errhdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | |
| 1249 | errhdr->cause = SCTP_ERROR_RESTART; |
| 1250 | errhdr->length = htons(len); |
| 1251 | |
| 1252 | /* Assign to the control socket. */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1253 | ep = sctp_sk(net->sctp.ctl_sock)->ep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
| 1255 | /* Association is NULL since this may be a restart attack and we |
| 1256 | * want to send back the attacker's vtag. |
| 1257 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1258 | pkt = sctp_abort_pkt_new(net, ep, NULL, init, errhdr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
| 1260 | if (!pkt) |
| 1261 | goto out; |
| 1262 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt)); |
| 1263 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 1264 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | |
| 1266 | /* Discard the rest of the inbound packet. */ |
| 1267 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
| 1268 | |
| 1269 | out: |
| 1270 | /* Even if there is no memory, treat as a failure so |
| 1271 | * the packet will get dropped. |
| 1272 | */ |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1276 | static bool list_has_sctp_addr(const struct list_head *list, |
| 1277 | union sctp_addr *ipaddr) |
| 1278 | { |
| 1279 | struct sctp_transport *addr; |
| 1280 | |
| 1281 | list_for_each_entry(addr, list, transports) { |
| 1282 | if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr)) |
| 1283 | return true; |
| 1284 | } |
| 1285 | |
| 1286 | return false; |
| 1287 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | /* A restart is occurring, check to make sure no new addresses |
| 1289 | * are being added as we may be under a takeover attack. |
| 1290 | */ |
| 1291 | static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, |
| 1292 | const struct sctp_association *asoc, |
| 1293 | struct sctp_chunk *init, |
| 1294 | sctp_cmd_seq_t *commands) |
| 1295 | { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1296 | struct net *net = sock_net(new_asoc->base.sk); |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1297 | struct sctp_transport *new_addr; |
| 1298 | int ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1300 | /* Implementor's Guide - Section 5.2.2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | * ... |
| 1302 | * Before responding the endpoint MUST check to see if the |
| 1303 | * unexpected INIT adds new addresses to the association. If new |
| 1304 | * addresses are added to the association, the endpoint MUST respond |
| 1305 | * with an ABORT.. |
| 1306 | */ |
| 1307 | |
| 1308 | /* Search through all current addresses and make sure |
| 1309 | * we aren't adding any new ones. |
| 1310 | */ |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1311 | list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list, |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1312 | transports) { |
| 1313 | if (!list_has_sctp_addr(&asoc->peer.transport_addr_list, |
| 1314 | &new_addr->ipaddr)) { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1315 | sctp_sf_send_restart_abort(net, &new_addr->ipaddr, init, |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1316 | commands); |
| 1317 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | break; |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1319 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /* Return success if all addresses were found. */ |
Joe Perches | 123031c | 2010-09-08 11:04:21 +0000 | [diff] [blame] | 1323 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | /* Populate the verification/tie tags based on overlapping INIT |
| 1327 | * scenario. |
| 1328 | * |
| 1329 | * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state. |
| 1330 | */ |
| 1331 | static void sctp_tietags_populate(struct sctp_association *new_asoc, |
| 1332 | const struct sctp_association *asoc) |
| 1333 | { |
| 1334 | switch (asoc->state) { |
| 1335 | |
| 1336 | /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */ |
| 1337 | |
| 1338 | case SCTP_STATE_COOKIE_WAIT: |
| 1339 | new_asoc->c.my_vtag = asoc->c.my_vtag; |
| 1340 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1341 | new_asoc->c.peer_ttag = 0; |
| 1342 | break; |
| 1343 | |
| 1344 | case SCTP_STATE_COOKIE_ECHOED: |
| 1345 | new_asoc->c.my_vtag = asoc->c.my_vtag; |
| 1346 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1347 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; |
| 1348 | break; |
| 1349 | |
| 1350 | /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED, |
| 1351 | * COOKIE-WAIT and SHUTDOWN-ACK-SENT |
| 1352 | */ |
| 1353 | default: |
| 1354 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1355 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; |
| 1356 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
| 1359 | /* Other parameters for the endpoint SHOULD be copied from the |
| 1360 | * existing parameters of the association (e.g. number of |
| 1361 | * outbound streams) into the INIT ACK and cookie. |
| 1362 | */ |
| 1363 | new_asoc->rwnd = asoc->rwnd; |
| 1364 | new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams; |
| 1365 | new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams; |
| 1366 | new_asoc->c.initial_tsn = asoc->c.initial_tsn; |
| 1367 | } |
| 1368 | |
| 1369 | /* |
| 1370 | * Compare vtag/tietag values to determine unexpected COOKIE-ECHO |
| 1371 | * handling action. |
| 1372 | * |
| 1373 | * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists. |
| 1374 | * |
| 1375 | * Returns value representing action to be taken. These action values |
| 1376 | * correspond to Action/Description values in RFC 2960, Table 2. |
| 1377 | */ |
| 1378 | static char sctp_tietags_compare(struct sctp_association *new_asoc, |
| 1379 | const struct sctp_association *asoc) |
| 1380 | { |
| 1381 | /* In this case, the peer may have restarted. */ |
| 1382 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && |
| 1383 | (asoc->c.peer_vtag != new_asoc->c.peer_vtag) && |
| 1384 | (asoc->c.my_vtag == new_asoc->c.my_ttag) && |
| 1385 | (asoc->c.peer_vtag == new_asoc->c.peer_ttag)) |
| 1386 | return 'A'; |
| 1387 | |
| 1388 | /* Collision case B. */ |
| 1389 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && |
| 1390 | ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) || |
| 1391 | (0 == asoc->c.peer_vtag))) { |
| 1392 | return 'B'; |
| 1393 | } |
| 1394 | |
| 1395 | /* Collision case D. */ |
| 1396 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && |
| 1397 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag)) |
| 1398 | return 'D'; |
| 1399 | |
| 1400 | /* Collision case C. */ |
| 1401 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && |
| 1402 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag) && |
| 1403 | (0 == new_asoc->c.my_ttag) && |
| 1404 | (0 == new_asoc->c.peer_ttag)) |
| 1405 | return 'C'; |
| 1406 | |
| 1407 | /* No match to any of the special cases; discard this packet. */ |
| 1408 | return 'E'; |
| 1409 | } |
| 1410 | |
| 1411 | /* Common helper routine for both duplicate and simulataneous INIT |
| 1412 | * chunk handling. |
| 1413 | */ |
| 1414 | static sctp_disposition_t sctp_sf_do_unexpected_init( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1415 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | const struct sctp_endpoint *ep, |
| 1417 | const struct sctp_association *asoc, |
| 1418 | const sctp_subtype_t type, |
| 1419 | void *arg, sctp_cmd_seq_t *commands) |
| 1420 | { |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 1421 | struct sctp_chunk *chunk = arg, *repl, *err_chunk; |
| 1422 | struct sctp_unrecognized_param *unk_param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | struct sctp_association *new_asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | struct sctp_packet *packet; |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 1425 | sctp_disposition_t retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | int len; |
| 1427 | |
| 1428 | /* 6.10 Bundling |
| 1429 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 1430 | * SHUTDOWN COMPLETE with any other chunks. |
| 1431 | * |
| 1432 | * IG Section 2.11.2 |
| 1433 | * Furthermore, we require that the receiver of an INIT chunk MUST |
| 1434 | * enforce these rules by silently discarding an arriving packet |
| 1435 | * with an INIT chunk that is bundled with other chunks. |
| 1436 | */ |
| 1437 | if (!chunk->singleton) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1438 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
| 1440 | /* 3.1 A packet containing an INIT chunk MUST have a zero Verification |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1441 | * Tag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | */ |
| 1443 | if (chunk->sctp_hdr->vtag != 0) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1444 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | |
| 1446 | /* Make sure that the INIT chunk has a valid length. |
| 1447 | * In this case, we generate a protocol violation since we have |
| 1448 | * an association established. |
| 1449 | */ |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1450 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1451 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | commands); |
| 1453 | /* Grab the INIT header. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 1454 | chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
| 1456 | /* Tag the variable length parameters. */ |
Xin Long | 4ae70c0 | 2017-06-30 11:52:21 +0800 | [diff] [blame] | 1457 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
| 1459 | /* Verify the INIT chunk before processing it. */ |
| 1460 | err_chunk = NULL; |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 1461 | if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type, |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1462 | (struct sctp_init_chunk *)chunk->chunk_hdr, chunk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | &err_chunk)) { |
| 1464 | /* This chunk contains fatal error. It is to be discarded. |
| 1465 | * Send an ABORT, with causes if there is any. |
| 1466 | */ |
| 1467 | if (err_chunk) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1468 | packet = sctp_abort_pkt_new(net, ep, asoc, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | (__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1470 | sizeof(struct sctp_chunkhdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1472 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | |
| 1474 | if (packet) { |
| 1475 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 1476 | SCTP_PACKET(packet)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1477 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | retval = SCTP_DISPOSITION_CONSUME; |
| 1479 | } else { |
| 1480 | retval = SCTP_DISPOSITION_NOMEM; |
| 1481 | } |
| 1482 | goto cleanup; |
| 1483 | } else { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1484 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | commands); |
| 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | /* |
| 1490 | * Other parameters for the endpoint SHOULD be copied from the |
| 1491 | * existing parameters of the association (e.g. number of |
| 1492 | * outbound streams) into the INIT ACK and cookie. |
| 1493 | * FIXME: We are copying parameters from the endpoint not the |
| 1494 | * association. |
| 1495 | */ |
| 1496 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); |
| 1497 | if (!new_asoc) |
| 1498 | goto nomem; |
| 1499 | |
Vlad Yasevich | 409b95a | 2009-11-10 08:57:34 +0000 | [diff] [blame] | 1500 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, |
| 1501 | sctp_scope(sctp_source(chunk)), GFP_ATOMIC) < 0) |
| 1502 | goto nomem; |
| 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | /* In the outbound INIT ACK the endpoint MUST copy its current |
| 1505 | * Verification Tag and Peers Verification tag into a reserved |
| 1506 | * place (local tie-tag and per tie-tag) within the state cookie. |
| 1507 | */ |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 1508 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1509 | (struct sctp_init_chunk *)chunk->chunk_hdr, |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1510 | GFP_ATOMIC)) |
| 1511 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | |
| 1513 | /* Make sure no new addresses are being added during the |
| 1514 | * restart. Do not do this check for COOKIE-WAIT state, |
| 1515 | * since there are no peer addresses to check against. |
| 1516 | * Upon return an ABORT will have been sent if needed. |
| 1517 | */ |
| 1518 | if (!sctp_state(asoc, COOKIE_WAIT)) { |
| 1519 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, |
| 1520 | commands)) { |
| 1521 | retval = SCTP_DISPOSITION_CONSUME; |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1522 | goto nomem_retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | |
| 1526 | sctp_tietags_populate(new_asoc, asoc); |
| 1527 | |
| 1528 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
| 1529 | |
| 1530 | /* If there are errors need to be reported for unknown parameters, |
| 1531 | * make sure to reserve enough room in the INIT ACK for them. |
| 1532 | */ |
| 1533 | len = 0; |
| 1534 | if (err_chunk) { |
| 1535 | len = ntohs(err_chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1536 | sizeof(struct sctp_chunkhdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); |
| 1540 | if (!repl) |
| 1541 | goto nomem; |
| 1542 | |
| 1543 | /* If there are errors need to be reported for unknown parameters, |
| 1544 | * include them in the outgoing INIT ACK as "Unrecognized parameter" |
| 1545 | * parameter. |
| 1546 | */ |
| 1547 | if (err_chunk) { |
| 1548 | /* Get the "Unrecognized parameter" parameter(s) out of the |
| 1549 | * ERROR chunk generated by sctp_verify_init(). Since the |
| 1550 | * error cause code for "unknown parameter" and the |
| 1551 | * "Unrecognized parameter" type is the same, we can |
| 1552 | * construct the parameters in INIT ACK by copying the |
| 1553 | * ERROR causes over. |
| 1554 | */ |
Xin Long | 62e6b7e | 2017-07-23 09:34:28 +0800 | [diff] [blame] | 1555 | unk_param = (struct sctp_unrecognized_param *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | ((__u8 *)(err_chunk->chunk_hdr) + |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 1557 | sizeof(struct sctp_chunkhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | /* Replace the cause code with the "Unrecognized parameter" |
| 1559 | * parameter type. |
| 1560 | */ |
| 1561 | sctp_addto_chunk(repl, len, unk_param); |
| 1562 | } |
| 1563 | |
| 1564 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 1565 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1566 | |
| 1567 | /* |
| 1568 | * Note: After sending out INIT ACK with the State Cookie parameter, |
| 1569 | * "Z" MUST NOT allocate any resources for this new association. |
| 1570 | * Otherwise, "Z" will be vulnerable to resource attacks. |
| 1571 | */ |
| 1572 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 1573 | retval = SCTP_DISPOSITION_CONSUME; |
| 1574 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1575 | return retval; |
| 1576 | |
| 1577 | nomem: |
| 1578 | retval = SCTP_DISPOSITION_NOMEM; |
| 1579 | nomem_retval: |
| 1580 | if (new_asoc) |
| 1581 | sctp_association_free(new_asoc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | cleanup: |
| 1583 | if (err_chunk) |
| 1584 | sctp_chunk_free(err_chunk); |
| 1585 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1589 | * Handle simultaneous INIT. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | * This means we started an INIT and then we got an INIT request from |
| 1591 | * our peer. |
| 1592 | * |
| 1593 | * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B) |
| 1594 | * This usually indicates an initialization collision, i.e., each |
| 1595 | * endpoint is attempting, at about the same time, to establish an |
| 1596 | * association with the other endpoint. |
| 1597 | * |
| 1598 | * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an |
| 1599 | * endpoint MUST respond with an INIT ACK using the same parameters it |
| 1600 | * sent in its original INIT chunk (including its Verification Tag, |
| 1601 | * unchanged). These original parameters are combined with those from the |
| 1602 | * newly received INIT chunk. The endpoint shall also generate a State |
| 1603 | * Cookie with the INIT ACK. The endpoint uses the parameters sent in its |
| 1604 | * INIT to calculate the State Cookie. |
| 1605 | * |
| 1606 | * After that, the endpoint MUST NOT change its state, the T1-init |
| 1607 | * timer shall be left running and the corresponding TCB MUST NOT be |
| 1608 | * destroyed. The normal procedures for handling State Cookies when |
| 1609 | * a TCB exists will resolve the duplicate INITs to a single association. |
| 1610 | * |
| 1611 | * For an endpoint that is in the COOKIE-ECHOED state it MUST populate |
| 1612 | * its Tie-Tags with the Tag information of itself and its peer (see |
| 1613 | * section 5.2.2 for a description of the Tie-Tags). |
| 1614 | * |
| 1615 | * Verification Tag: Not explicit, but an INIT can not have a valid |
| 1616 | * verification tag, so we skip the check. |
| 1617 | * |
| 1618 | * Inputs |
| 1619 | * (endpoint, asoc, chunk) |
| 1620 | * |
| 1621 | * Outputs |
| 1622 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1623 | * |
| 1624 | * The return value is the disposition of the chunk. |
| 1625 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1626 | sctp_disposition_t sctp_sf_do_5_2_1_siminit(struct net *net, |
| 1627 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | const struct sctp_association *asoc, |
| 1629 | const sctp_subtype_t type, |
| 1630 | void *arg, |
| 1631 | sctp_cmd_seq_t *commands) |
| 1632 | { |
| 1633 | /* Call helper to do the real work for both simulataneous and |
| 1634 | * duplicate INIT chunk handling. |
| 1635 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1636 | return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | /* |
| 1640 | * Handle duplicated INIT messages. These are usually delayed |
| 1641 | * restransmissions. |
| 1642 | * |
| 1643 | * Section: 5.2.2 Unexpected INIT in States Other than CLOSED, |
| 1644 | * COOKIE-ECHOED and COOKIE-WAIT |
| 1645 | * |
| 1646 | * Unless otherwise stated, upon reception of an unexpected INIT for |
| 1647 | * this association, the endpoint shall generate an INIT ACK with a |
| 1648 | * State Cookie. In the outbound INIT ACK the endpoint MUST copy its |
| 1649 | * current Verification Tag and peer's Verification Tag into a reserved |
| 1650 | * place within the state cookie. We shall refer to these locations as |
| 1651 | * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet |
| 1652 | * containing this INIT ACK MUST carry a Verification Tag value equal to |
| 1653 | * the Initiation Tag found in the unexpected INIT. And the INIT ACK |
| 1654 | * MUST contain a new Initiation Tag (randomly generated see Section |
| 1655 | * 5.3.1). Other parameters for the endpoint SHOULD be copied from the |
| 1656 | * existing parameters of the association (e.g. number of outbound |
| 1657 | * streams) into the INIT ACK and cookie. |
| 1658 | * |
| 1659 | * After sending out the INIT ACK, the endpoint shall take no further |
| 1660 | * actions, i.e., the existing association, including its current state, |
| 1661 | * and the corresponding TCB MUST NOT be changed. |
| 1662 | * |
| 1663 | * Note: Only when a TCB exists and the association is not in a COOKIE- |
| 1664 | * WAIT state are the Tie-Tags populated. For a normal association INIT |
| 1665 | * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be |
| 1666 | * set to 0 (indicating that no previous TCB existed). The INIT ACK and |
| 1667 | * State Cookie are populated as specified in section 5.2.1. |
| 1668 | * |
| 1669 | * Verification Tag: Not specified, but an INIT has no way of knowing |
| 1670 | * what the verification tag could be, so we ignore it. |
| 1671 | * |
| 1672 | * Inputs |
| 1673 | * (endpoint, asoc, chunk) |
| 1674 | * |
| 1675 | * Outputs |
| 1676 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1677 | * |
| 1678 | * The return value is the disposition of the chunk. |
| 1679 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1680 | sctp_disposition_t sctp_sf_do_5_2_2_dupinit(struct net *net, |
| 1681 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | const struct sctp_association *asoc, |
| 1683 | const sctp_subtype_t type, |
| 1684 | void *arg, |
| 1685 | sctp_cmd_seq_t *commands) |
| 1686 | { |
| 1687 | /* Call helper to do the real work for both simulataneous and |
| 1688 | * duplicate INIT chunk handling. |
| 1689 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1690 | return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1694 | /* |
| 1695 | * Unexpected INIT-ACK handler. |
| 1696 | * |
| 1697 | * Section 5.2.3 |
| 1698 | * If an INIT ACK received by an endpoint in any state other than the |
| 1699 | * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk. |
| 1700 | * An unexpected INIT ACK usually indicates the processing of an old or |
| 1701 | * duplicated INIT chunk. |
| 1702 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1703 | sctp_disposition_t sctp_sf_do_5_2_3_initack(struct net *net, |
| 1704 | const struct sctp_endpoint *ep, |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1705 | const struct sctp_association *asoc, |
| 1706 | const sctp_subtype_t type, |
| 1707 | void *arg, sctp_cmd_seq_t *commands) |
| 1708 | { |
| 1709 | /* Per the above section, we'll discard the chunk if we have an |
| 1710 | * endpoint. If this is an OOTB INIT-ACK, treat it as such. |
| 1711 | */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 1712 | if (ep == sctp_sk(net->sctp.ctl_sock)->ep) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1713 | return sctp_sf_ootb(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1714 | else |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1715 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1716 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | |
| 1718 | /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A') |
| 1719 | * |
| 1720 | * Section 5.2.4 |
| 1721 | * A) In this case, the peer may have restarted. |
| 1722 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1723 | static sctp_disposition_t sctp_sf_do_dupcook_a(struct net *net, |
| 1724 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | const struct sctp_association *asoc, |
| 1726 | struct sctp_chunk *chunk, |
| 1727 | sctp_cmd_seq_t *commands, |
| 1728 | struct sctp_association *new_asoc) |
| 1729 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1730 | struct sctp_init_chunk *peer_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | struct sctp_ulpevent *ev; |
| 1732 | struct sctp_chunk *repl; |
| 1733 | struct sctp_chunk *err; |
| 1734 | sctp_disposition_t disposition; |
| 1735 | |
| 1736 | /* new_asoc is a brand-new association, so these are not yet |
| 1737 | * side effects--it is safe to run them here. |
| 1738 | */ |
| 1739 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 1740 | |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 1741 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | GFP_ATOMIC)) |
| 1743 | goto nomem; |
| 1744 | |
| 1745 | /* Make sure no new addresses are being added during the |
| 1746 | * restart. Though this is a pretty complicated attack |
| 1747 | * since you'd have to get inside the cookie. |
| 1748 | */ |
| 1749 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) { |
| 1750 | return SCTP_DISPOSITION_CONSUME; |
| 1751 | } |
| 1752 | |
| 1753 | /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes |
| 1754 | * the peer has restarted (Action A), it MUST NOT setup a new |
| 1755 | * association but instead resend the SHUTDOWN ACK and send an ERROR |
| 1756 | * chunk with a "Cookie Received while Shutting Down" error cause to |
| 1757 | * its peer. |
| 1758 | */ |
| 1759 | if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1760 | disposition = sctp_sf_do_9_2_reshutack(net, ep, asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | SCTP_ST_CHUNK(chunk->chunk_hdr->type), |
| 1762 | chunk, commands); |
| 1763 | if (SCTP_DISPOSITION_NOMEM == disposition) |
| 1764 | goto nomem; |
| 1765 | |
| 1766 | err = sctp_make_op_error(asoc, chunk, |
| 1767 | SCTP_ERROR_COOKIE_IN_SHUTDOWN, |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 1768 | NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | if (err) |
| 1770 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 1771 | SCTP_CHUNK(err)); |
| 1772 | |
| 1773 | return SCTP_DISPOSITION_CONSUME; |
| 1774 | } |
| 1775 | |
Wei Yongjun | a000c01 | 2011-05-29 23:23:36 +0000 | [diff] [blame] | 1776 | /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked |
| 1777 | * data. Consider the optional choice of resending of this data. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | */ |
Wei Yongjun | a000c01 | 2011-05-29 23:23:36 +0000 | [diff] [blame] | 1779 | sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); |
| 1780 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 1781 | SCTP_TO(SCTP_EVENT_TIMEOUT_SACK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL()); |
| 1783 | |
Wei Yongjun | a000c01 | 2011-05-29 23:23:36 +0000 | [diff] [blame] | 1784 | /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue |
| 1785 | * and ASCONF-ACK cache. |
| 1786 | */ |
| 1787 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 1788 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 1789 | sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_ASCONF_QUEUE, SCTP_NULL()); |
| 1790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1792 | if (!repl) |
| 1793 | goto nomem; |
| 1794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | /* Report association restart to upper layer. */ |
| 1796 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0, |
| 1797 | new_asoc->c.sinit_num_ostreams, |
| 1798 | new_asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 1799 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | if (!ev) |
| 1801 | goto nomem_ev; |
| 1802 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1803 | /* Update the content of current association. */ |
| 1804 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
Vlad Yasevich | bdf6fa5 | 2014-10-03 18:16:20 -0400 | [diff] [blame] | 1806 | if (sctp_state(asoc, SHUTDOWN_PENDING) && |
| 1807 | (sctp_sstate(asoc->base.sk, CLOSING) || |
| 1808 | sock_flag(asoc->base.sk, SOCK_DEAD))) { |
| 1809 | /* if were currently in SHUTDOWN_PENDING, but the socket |
| 1810 | * has been closed by user, don't transition to ESTABLISHED. |
| 1811 | * Instead trigger SHUTDOWN bundled with COOKIE_ACK. |
| 1812 | */ |
| 1813 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1814 | return sctp_sf_do_9_2_start_shutdown(net, ep, asoc, |
| 1815 | SCTP_ST_CHUNK(0), NULL, |
| 1816 | commands); |
| 1817 | } else { |
| 1818 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1819 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
| 1820 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | return SCTP_DISPOSITION_CONSUME; |
| 1823 | |
| 1824 | nomem_ev: |
| 1825 | sctp_chunk_free(repl); |
| 1826 | nomem: |
| 1827 | return SCTP_DISPOSITION_NOMEM; |
| 1828 | } |
| 1829 | |
| 1830 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B') |
| 1831 | * |
| 1832 | * Section 5.2.4 |
| 1833 | * B) In this case, both sides may be attempting to start an association |
| 1834 | * at about the same time but the peer endpoint started its INIT |
| 1835 | * after responding to the local endpoint's INIT |
| 1836 | */ |
| 1837 | /* This case represents an initialization collision. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1838 | static sctp_disposition_t sctp_sf_do_dupcook_b(struct net *net, |
| 1839 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | const struct sctp_association *asoc, |
| 1841 | struct sctp_chunk *chunk, |
| 1842 | sctp_cmd_seq_t *commands, |
| 1843 | struct sctp_association *new_asoc) |
| 1844 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 1845 | struct sctp_init_chunk *peer_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | struct sctp_chunk *repl; |
| 1847 | |
| 1848 | /* new_asoc is a brand-new association, so these are not yet |
| 1849 | * side effects--it is safe to run them here. |
| 1850 | */ |
| 1851 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
Wei Yongjun | de6becdc0 | 2011-04-19 21:30:51 +0000 | [diff] [blame] | 1852 | if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | GFP_ATOMIC)) |
| 1854 | goto nomem; |
| 1855 | |
| 1856 | /* Update the content of current association. */ |
| 1857 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); |
| 1858 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1859 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1860 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 1862 | |
| 1863 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1864 | if (!repl) |
| 1865 | goto nomem; |
| 1866 | |
| 1867 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | |
| 1869 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 1870 | * |
| 1871 | * D) IMPLEMENTATION NOTE: An implementation may choose to |
| 1872 | * send the Communication Up notification to the SCTP user |
| 1873 | * upon reception of a valid COOKIE ECHO chunk. |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1874 | * |
| 1875 | * Sadly, this needs to be implemented as a side-effect, because |
| 1876 | * we are not guaranteed to have set the association id of the real |
| 1877 | * association and so these notifications need to be delayed until |
| 1878 | * the association id is allocated. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1881 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
| 1883 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1884 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1886 | * peers requested adaptation layer. |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1887 | * |
| 1888 | * This also needs to be done as a side effect for the same reason as |
| 1889 | * above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | */ |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1891 | if (asoc->peer.adaptation_ind) |
| 1892 | sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
| 1894 | return SCTP_DISPOSITION_CONSUME; |
| 1895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | nomem: |
| 1897 | return SCTP_DISPOSITION_NOMEM; |
| 1898 | } |
| 1899 | |
| 1900 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C') |
| 1901 | * |
| 1902 | * Section 5.2.4 |
| 1903 | * C) In this case, the local endpoint's cookie has arrived late. |
| 1904 | * Before it arrived, the local endpoint sent an INIT and received an |
| 1905 | * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag |
| 1906 | * but a new tag of its own. |
| 1907 | */ |
| 1908 | /* This case represents an initialization collision. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1909 | static sctp_disposition_t sctp_sf_do_dupcook_c(struct net *net, |
| 1910 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | const struct sctp_association *asoc, |
| 1912 | struct sctp_chunk *chunk, |
| 1913 | sctp_cmd_seq_t *commands, |
| 1914 | struct sctp_association *new_asoc) |
| 1915 | { |
| 1916 | /* The cookie should be silently discarded. |
| 1917 | * The endpoint SHOULD NOT change states and should leave |
| 1918 | * any timers running. |
| 1919 | */ |
| 1920 | return SCTP_DISPOSITION_DISCARD; |
| 1921 | } |
| 1922 | |
| 1923 | /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D') |
| 1924 | * |
| 1925 | * Section 5.2.4 |
| 1926 | * |
| 1927 | * D) When both local and remote tags match the endpoint should always |
| 1928 | * enter the ESTABLISHED state, if it has not already done so. |
| 1929 | */ |
| 1930 | /* This case represents an initialization collision. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1931 | static sctp_disposition_t sctp_sf_do_dupcook_d(struct net *net, |
| 1932 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | const struct sctp_association *asoc, |
| 1934 | struct sctp_chunk *chunk, |
| 1935 | sctp_cmd_seq_t *commands, |
| 1936 | struct sctp_association *new_asoc) |
| 1937 | { |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1938 | struct sctp_ulpevent *ev = NULL, *ai_ev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | struct sctp_chunk *repl; |
| 1940 | |
| 1941 | /* Clarification from Implementor's Guide: |
| 1942 | * D) When both local and remote tags match the endpoint should |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1943 | * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state. |
| 1944 | * It should stop any cookie timer that may be running and send |
| 1945 | * a COOKIE ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | */ |
| 1947 | |
| 1948 | /* Don't accidentally move back into established state. */ |
| 1949 | if (asoc->state < SCTP_STATE_ESTABLISHED) { |
| 1950 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 1951 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 1952 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1953 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 1954 | SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, |
| 1956 | SCTP_NULL()); |
| 1957 | |
| 1958 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 1959 | * |
| 1960 | * D) IMPLEMENTATION NOTE: An implementation may choose |
| 1961 | * to send the Communication Up notification to the |
| 1962 | * SCTP user upon reception of a valid COOKIE |
| 1963 | * ECHO chunk. |
| 1964 | */ |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1965 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | SCTP_COMM_UP, 0, |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1967 | asoc->c.sinit_num_ostreams, |
| 1968 | asoc->c.sinit_max_instreams, |
YOSHIFUJI Hideaki | 9cbcbf4 | 2007-07-19 10:44:50 +0900 | [diff] [blame] | 1969 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | if (!ev) |
| 1971 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
| 1973 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1974 | * When a peer sends a Adaptation Layer Indication parameter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | * SCTP delivers this notification to inform the application |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1976 | * that of the peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1978 | if (asoc->peer.adaptation_ind) { |
| 1979 | ai_ev = sctp_ulpevent_make_adaptation_indication(asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1981 | if (!ai_ev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | goto nomem; |
| 1983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | } |
| 1985 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | |
| 1987 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1988 | if (!repl) |
| 1989 | goto nomem; |
| 1990 | |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 1991 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1992 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1993 | if (ev) |
| 1994 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 1995 | SCTP_ULPEVENT(ev)); |
| 1996 | if (ai_ev) |
| 1997 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 1998 | SCTP_ULPEVENT(ai_ev)); |
| 1999 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | return SCTP_DISPOSITION_CONSUME; |
| 2001 | |
| 2002 | nomem: |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 2003 | if (ai_ev) |
| 2004 | sctp_ulpevent_free(ai_ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | if (ev) |
| 2006 | sctp_ulpevent_free(ev); |
| 2007 | return SCTP_DISPOSITION_NOMEM; |
| 2008 | } |
| 2009 | |
| 2010 | /* |
| 2011 | * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying |
| 2012 | * chunk was retransmitted and then delayed in the network. |
| 2013 | * |
| 2014 | * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists |
| 2015 | * |
| 2016 | * Verification Tag: None. Do cookie validation. |
| 2017 | * |
| 2018 | * Inputs |
| 2019 | * (endpoint, asoc, chunk) |
| 2020 | * |
| 2021 | * Outputs |
| 2022 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2023 | * |
| 2024 | * The return value is the disposition of the chunk. |
| 2025 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2026 | sctp_disposition_t sctp_sf_do_5_2_4_dupcook(struct net *net, |
| 2027 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | const struct sctp_association *asoc, |
| 2029 | const sctp_subtype_t type, |
| 2030 | void *arg, |
| 2031 | sctp_cmd_seq_t *commands) |
| 2032 | { |
| 2033 | sctp_disposition_t retval; |
| 2034 | struct sctp_chunk *chunk = arg; |
| 2035 | struct sctp_association *new_asoc; |
| 2036 | int error = 0; |
| 2037 | char action; |
| 2038 | struct sctp_chunk *err_chk_p; |
| 2039 | |
| 2040 | /* Make sure that the chunk has a valid length from the protocol |
| 2041 | * perspective. In this case check to make sure we have at least |
| 2042 | * enough for the chunk header. Cookie length verification is |
| 2043 | * done later. |
| 2044 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 2045 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2046 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | commands); |
| 2048 | |
| 2049 | /* "Decode" the chunk. We have no optional parameters so we |
| 2050 | * are in good shape. |
| 2051 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2052 | chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 2053 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 2054 | sizeof(struct sctp_chunkhdr))) |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 2055 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
| 2057 | /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie |
| 2058 | * of a duplicate COOKIE ECHO match the Verification Tags of the |
| 2059 | * current association, consider the State Cookie valid even if |
| 2060 | * the lifespan is exceeded. |
| 2061 | */ |
| 2062 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, |
| 2063 | &err_chk_p); |
| 2064 | |
| 2065 | /* FIXME: |
| 2066 | * If the re-build failed, what is the proper error path |
| 2067 | * from here? |
| 2068 | * |
| 2069 | * [We should abort the association. --piggy] |
| 2070 | */ |
| 2071 | if (!new_asoc) { |
| 2072 | /* FIXME: Several errors are possible. A bad cookie should |
| 2073 | * be silently discarded, but think about logging it too. |
| 2074 | */ |
| 2075 | switch (error) { |
| 2076 | case -SCTP_IERROR_NOMEM: |
| 2077 | goto nomem; |
| 2078 | |
| 2079 | case -SCTP_IERROR_STALE_COOKIE: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2080 | sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | err_chk_p); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2082 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | case -SCTP_IERROR_BAD_SIG: |
| 2084 | default: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2085 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2086 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | } |
| 2088 | |
Xin Long | 7e06297 | 2017-05-23 13:28:55 +0800 | [diff] [blame] | 2089 | /* Set temp so that it won't be added into hashtable */ |
| 2090 | new_asoc->temp = 1; |
| 2091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | /* Compare the tie_tag in cookie with the verification tag of |
| 2093 | * current association. |
| 2094 | */ |
| 2095 | action = sctp_tietags_compare(new_asoc, asoc); |
| 2096 | |
| 2097 | switch (action) { |
| 2098 | case 'A': /* Association restart. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2099 | retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | new_asoc); |
| 2101 | break; |
| 2102 | |
| 2103 | case 'B': /* Collision case B. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2104 | retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | new_asoc); |
| 2106 | break; |
| 2107 | |
| 2108 | case 'C': /* Collision case C. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2109 | retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | new_asoc); |
| 2111 | break; |
| 2112 | |
| 2113 | case 'D': /* Collision case D. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2114 | retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | new_asoc); |
| 2116 | break; |
| 2117 | |
| 2118 | default: /* Discard packet for all others. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2119 | retval = sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | |
| 2123 | /* Delete the tempory new association. */ |
Vlad Yasevich | f281563 | 2013-03-12 15:53:23 +0000 | [diff] [blame] | 2124 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, SCTP_ASOC(new_asoc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 2126 | |
Max Matveev | d5ccd49 | 2011-08-29 21:02:24 +0000 | [diff] [blame] | 2127 | /* Restore association pointer to provide SCTP command interpeter |
| 2128 | * with a valid context in case it needs to manipulate |
| 2129 | * the queues */ |
| 2130 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, |
| 2131 | SCTP_ASOC((struct sctp_association *)asoc)); |
| 2132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | return retval; |
| 2134 | |
| 2135 | nomem: |
| 2136 | return SCTP_DISPOSITION_NOMEM; |
| 2137 | } |
| 2138 | |
| 2139 | /* |
| 2140 | * Process an ABORT. (SHUTDOWN-PENDING state) |
| 2141 | * |
| 2142 | * See sctp_sf_do_9_1_abort(). |
| 2143 | */ |
| 2144 | sctp_disposition_t sctp_sf_shutdown_pending_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2145 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | const struct sctp_endpoint *ep, |
| 2147 | const struct sctp_association *asoc, |
| 2148 | const sctp_subtype_t type, |
| 2149 | void *arg, |
| 2150 | sctp_cmd_seq_t *commands) |
| 2151 | { |
| 2152 | struct sctp_chunk *chunk = arg; |
| 2153 | |
| 2154 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2155 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
| 2157 | /* Make sure that the ABORT chunk has a valid length. |
| 2158 | * Since this is an ABORT chunk, we have to discard it |
| 2159 | * because of the following text: |
| 2160 | * RFC 2960, Section 3.3.7 |
| 2161 | * If an endpoint receives an ABORT with a format error or for an |
| 2162 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2163 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | * as we do not know its true length. So, to be safe, discard the |
| 2165 | * packet. |
| 2166 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2167 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2168 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2170 | /* ADD-IP: Special case for ABORT chunks |
| 2171 | * F4) One special consideration is that ABORT Chunks arriving |
| 2172 | * destined to the IP address being deleted MUST be |
| 2173 | * ignored (see Section 5.3.1 for further details). |
| 2174 | */ |
| 2175 | if (SCTP_ADDR_DEL == |
| 2176 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2177 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2178 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2179 | return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /* |
| 2183 | * Process an ABORT. (SHUTDOWN-SENT state) |
| 2184 | * |
| 2185 | * See sctp_sf_do_9_1_abort(). |
| 2186 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2187 | sctp_disposition_t sctp_sf_shutdown_sent_abort(struct net *net, |
| 2188 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | const struct sctp_association *asoc, |
| 2190 | const sctp_subtype_t type, |
| 2191 | void *arg, |
| 2192 | sctp_cmd_seq_t *commands) |
| 2193 | { |
| 2194 | struct sctp_chunk *chunk = arg; |
| 2195 | |
| 2196 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2197 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
| 2199 | /* Make sure that the ABORT chunk has a valid length. |
| 2200 | * Since this is an ABORT chunk, we have to discard it |
| 2201 | * because of the following text: |
| 2202 | * RFC 2960, Section 3.3.7 |
| 2203 | * If an endpoint receives an ABORT with a format error or for an |
| 2204 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2205 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | * as we do not know its true length. So, to be safe, discard the |
| 2207 | * packet. |
| 2208 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2209 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2210 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2212 | /* ADD-IP: Special case for ABORT chunks |
| 2213 | * F4) One special consideration is that ABORT Chunks arriving |
| 2214 | * destined to the IP address being deleted MUST be |
| 2215 | * ignored (see Section 5.3.1 for further details). |
| 2216 | */ |
| 2217 | if (SCTP_ADDR_DEL == |
| 2218 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2219 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | /* Stop the T2-shutdown timer. */ |
| 2222 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2223 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 2224 | |
| 2225 | /* Stop the T5-shutdown guard timer. */ |
| 2226 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2227 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 2228 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2229 | return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /* |
| 2233 | * Process an ABORT. (SHUTDOWN-ACK-SENT state) |
| 2234 | * |
| 2235 | * See sctp_sf_do_9_1_abort(). |
| 2236 | */ |
| 2237 | sctp_disposition_t sctp_sf_shutdown_ack_sent_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2238 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | const struct sctp_endpoint *ep, |
| 2240 | const struct sctp_association *asoc, |
| 2241 | const sctp_subtype_t type, |
| 2242 | void *arg, |
| 2243 | sctp_cmd_seq_t *commands) |
| 2244 | { |
| 2245 | /* The same T2 timer, so we should be able to use |
| 2246 | * common function with the SHUTDOWN-SENT state. |
| 2247 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2248 | return sctp_sf_shutdown_sent_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | /* |
| 2252 | * Handle an Error received in COOKIE_ECHOED state. |
| 2253 | * |
| 2254 | * Only handle the error type of stale COOKIE Error, the other errors will |
| 2255 | * be ignored. |
| 2256 | * |
| 2257 | * Inputs |
| 2258 | * (endpoint, asoc, chunk) |
| 2259 | * |
| 2260 | * Outputs |
| 2261 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2262 | * |
| 2263 | * The return value is the disposition of the chunk. |
| 2264 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2265 | sctp_disposition_t sctp_sf_cookie_echoed_err(struct net *net, |
| 2266 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | const struct sctp_association *asoc, |
| 2268 | const sctp_subtype_t type, |
| 2269 | void *arg, |
| 2270 | sctp_cmd_seq_t *commands) |
| 2271 | { |
| 2272 | struct sctp_chunk *chunk = arg; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2273 | struct sctp_errhdr *err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | |
| 2275 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2276 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | |
| 2278 | /* Make sure that the ERROR chunk has a valid length. |
| 2279 | * The parameter walking depends on this as well. |
| 2280 | */ |
Xin Long | 87caeba | 2017-08-03 15:42:12 +0800 | [diff] [blame] | 2281 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2282 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | commands); |
| 2284 | |
| 2285 | /* Process the error here */ |
| 2286 | /* FUTURE FIXME: When PR-SCTP related and other optional |
| 2287 | * parms are emitted, this will have to change to handle multiple |
| 2288 | * errors. |
| 2289 | */ |
| 2290 | sctp_walk_errors(err, chunk->chunk_hdr) { |
| 2291 | if (SCTP_ERROR_STALE_COOKIE == err->cause) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2292 | return sctp_sf_do_5_2_6_stale(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | arg, commands); |
| 2294 | } |
| 2295 | |
| 2296 | /* It is possible to have malformed error causes, and that |
| 2297 | * will cause us to end the walk early. However, since |
| 2298 | * we are discarding the packet, there should be no adverse |
| 2299 | * affects. |
| 2300 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2301 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | /* |
| 2305 | * Handle a Stale COOKIE Error |
| 2306 | * |
| 2307 | * Section: 5.2.6 Handle Stale COOKIE Error |
| 2308 | * If the association is in the COOKIE-ECHOED state, the endpoint may elect |
| 2309 | * one of the following three alternatives. |
| 2310 | * ... |
| 2311 | * 3) Send a new INIT chunk to the endpoint, adding a Cookie |
| 2312 | * Preservative parameter requesting an extension to the lifetime of |
| 2313 | * the State Cookie. When calculating the time extension, an |
| 2314 | * implementation SHOULD use the RTT information measured based on the |
| 2315 | * previous COOKIE ECHO / ERROR exchange, and should add no more |
| 2316 | * than 1 second beyond the measured RTT, due to long State Cookie |
| 2317 | * lifetimes making the endpoint more subject to a replay attack. |
| 2318 | * |
| 2319 | * Verification Tag: Not explicit, but safe to ignore. |
| 2320 | * |
| 2321 | * Inputs |
| 2322 | * (endpoint, asoc, chunk) |
| 2323 | * |
| 2324 | * Outputs |
| 2325 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2326 | * |
| 2327 | * The return value is the disposition of the chunk. |
| 2328 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2329 | static sctp_disposition_t sctp_sf_do_5_2_6_stale(struct net *net, |
| 2330 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | const struct sctp_association *asoc, |
| 2332 | const sctp_subtype_t type, |
| 2333 | void *arg, |
| 2334 | sctp_cmd_seq_t *commands) |
| 2335 | { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2336 | int attempts = asoc->init_err_counter + 1; |
Xin Long | 365ddb6 | 2017-07-17 11:29:51 +0800 | [diff] [blame] | 2337 | struct sctp_chunk *chunk = arg, *reply; |
| 2338 | struct sctp_cookie_preserve_param bht; |
| 2339 | struct sctp_bind_addr *bp; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2340 | struct sctp_errhdr *err; |
Xin Long | 365ddb6 | 2017-07-17 11:29:51 +0800 | [diff] [blame] | 2341 | u32 stale; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 2343 | if (attempts > asoc->max_init_attempts) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2344 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 2345 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 2347 | SCTP_PERR(SCTP_ERROR_STALE_COOKIE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | return SCTP_DISPOSITION_DELETE_TCB; |
| 2349 | } |
| 2350 | |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2351 | err = (struct sctp_errhdr *)(chunk->skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
| 2353 | /* When calculating the time extension, an implementation |
| 2354 | * SHOULD use the RTT information measured based on the |
| 2355 | * previous COOKIE ECHO / ERROR exchange, and should add no |
| 2356 | * more than 1 second beyond the measured RTT, due to long |
| 2357 | * State Cookie lifetimes making the endpoint more subject to |
| 2358 | * a replay attack. |
| 2359 | * Measure of Staleness's unit is usec. (1/1000000 sec) |
| 2360 | * Suggested Cookie Life-span Increment's unit is msec. |
| 2361 | * (1/1000 sec) |
| 2362 | * In general, if you use the suggested cookie life, the value |
| 2363 | * found in the field of measure of staleness should be doubled |
| 2364 | * to give ample time to retransmit the new cookie and thus |
| 2365 | * yield a higher probability of success on the reattempt. |
| 2366 | */ |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2367 | stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | stale = (stale * 2) / 1000; |
| 2369 | |
| 2370 | bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE; |
| 2371 | bht.param_hdr.length = htons(sizeof(bht)); |
| 2372 | bht.lifespan_increment = htonl(stale); |
| 2373 | |
| 2374 | /* Build that new INIT chunk. */ |
| 2375 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
| 2376 | reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht)); |
| 2377 | if (!reply) |
| 2378 | goto nomem; |
| 2379 | |
| 2380 | sctp_addto_chunk(reply, sizeof(bht), &bht); |
| 2381 | |
| 2382 | /* Clear peer's init_tag cached in assoc as we are sending a new INIT */ |
| 2383 | sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL()); |
| 2384 | |
| 2385 | /* Stop pending T3-rtx and heartbeat timers */ |
| 2386 | sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); |
| 2387 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 2388 | |
| 2389 | /* Delete non-primary peer ip addresses since we are transitioning |
| 2390 | * back to the COOKIE-WAIT state |
| 2391 | */ |
| 2392 | sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL()); |
| 2393 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2394 | /* If we've sent any data bundled with COOKIE-ECHO we will need to |
| 2395 | * resend |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | */ |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 2397 | sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | SCTP_TRANSPORT(asoc->peer.primary_path)); |
| 2399 | |
| 2400 | /* Cast away the const modifier, as we want to just |
| 2401 | * rerun it through as a sideffect. |
| 2402 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2403 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | |
| 2405 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2406 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 2407 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2408 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); |
| 2409 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 2410 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 2411 | |
| 2412 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 2413 | |
| 2414 | return SCTP_DISPOSITION_CONSUME; |
| 2415 | |
| 2416 | nomem: |
| 2417 | return SCTP_DISPOSITION_NOMEM; |
| 2418 | } |
| 2419 | |
| 2420 | /* |
| 2421 | * Process an ABORT. |
| 2422 | * |
| 2423 | * Section: 9.1 |
| 2424 | * After checking the Verification Tag, the receiving endpoint shall |
| 2425 | * remove the association from its record, and shall report the |
| 2426 | * termination to its upper layer. |
| 2427 | * |
| 2428 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules |
| 2429 | * B) Rules for packet carrying ABORT: |
| 2430 | * |
| 2431 | * - The endpoint shall always fill in the Verification Tag field of the |
| 2432 | * outbound packet with the destination endpoint's tag value if it |
| 2433 | * is known. |
| 2434 | * |
| 2435 | * - If the ABORT is sent in response to an OOTB packet, the endpoint |
| 2436 | * MUST follow the procedure described in Section 8.4. |
| 2437 | * |
| 2438 | * - The receiver MUST accept the packet if the Verification Tag |
| 2439 | * matches either its own tag, OR the tag of its peer. Otherwise, the |
| 2440 | * receiver MUST silently discard the packet and take no further |
| 2441 | * action. |
| 2442 | * |
| 2443 | * Inputs |
| 2444 | * (endpoint, asoc, chunk) |
| 2445 | * |
| 2446 | * Outputs |
| 2447 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2448 | * |
| 2449 | * The return value is the disposition of the chunk. |
| 2450 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2451 | sctp_disposition_t sctp_sf_do_9_1_abort(struct net *net, |
| 2452 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | const struct sctp_association *asoc, |
| 2454 | const sctp_subtype_t type, |
| 2455 | void *arg, |
| 2456 | sctp_cmd_seq_t *commands) |
| 2457 | { |
| 2458 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | |
| 2460 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2461 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
| 2463 | /* Make sure that the ABORT chunk has a valid length. |
| 2464 | * Since this is an ABORT chunk, we have to discard it |
| 2465 | * because of the following text: |
| 2466 | * RFC 2960, Section 3.3.7 |
| 2467 | * If an endpoint receives an ABORT with a format error or for an |
| 2468 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2469 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | * as we do not know its true length. So, to be safe, discard the |
| 2471 | * packet. |
| 2472 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2473 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2474 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2476 | /* ADD-IP: Special case for ABORT chunks |
| 2477 | * F4) One special consideration is that ABORT Chunks arriving |
| 2478 | * destined to the IP address being deleted MUST be |
| 2479 | * ignored (see Section 5.3.1 for further details). |
| 2480 | */ |
| 2481 | if (SCTP_ADDR_DEL == |
| 2482 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2483 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2484 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2485 | return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2488 | static sctp_disposition_t __sctp_sf_do_9_1_abort(struct net *net, |
| 2489 | const struct sctp_endpoint *ep, |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2490 | const struct sctp_association *asoc, |
| 2491 | const sctp_subtype_t type, |
| 2492 | void *arg, |
| 2493 | sctp_cmd_seq_t *commands) |
| 2494 | { |
| 2495 | struct sctp_chunk *chunk = arg; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 2496 | unsigned int len; |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2497 | __be16 error = SCTP_ERROR_NO_ERROR; |
| 2498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | /* See if we have an error cause code in the chunk. */ |
| 2500 | len = ntohs(chunk->chunk_hdr->length); |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2501 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) { |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2502 | struct sctp_errhdr *err; |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2503 | |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2504 | sctp_walk_errors(err, chunk->chunk_hdr); |
| 2505 | if ((void *)err != (void *)chunk->chunk_end) |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2506 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, |
| 2507 | commands); |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2508 | |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2509 | error = ((struct sctp_errhdr *)chunk->skb->data)->cause; |
Shan Wei | 96ca468 | 2011-04-19 21:26:26 +0000 | [diff] [blame] | 2510 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2512 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2513 | /* ASSOC_FAILED will DELETE_TCB. */ |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 2514 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 2515 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 2516 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | |
| 2518 | return SCTP_DISPOSITION_ABORT; |
| 2519 | } |
| 2520 | |
| 2521 | /* |
| 2522 | * Process an ABORT. (COOKIE-WAIT state) |
| 2523 | * |
| 2524 | * See sctp_sf_do_9_1_abort() above. |
| 2525 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2526 | sctp_disposition_t sctp_sf_cookie_wait_abort(struct net *net, |
| 2527 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | const struct sctp_association *asoc, |
| 2529 | const sctp_subtype_t type, |
| 2530 | void *arg, |
| 2531 | sctp_cmd_seq_t *commands) |
| 2532 | { |
| 2533 | struct sctp_chunk *chunk = arg; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 2534 | unsigned int len; |
Al Viro | f94c019 | 2006-11-20 17:00:25 -0800 | [diff] [blame] | 2535 | __be16 error = SCTP_ERROR_NO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | |
| 2537 | if (!sctp_vtag_verify_either(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2538 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
| 2540 | /* Make sure that the ABORT chunk has a valid length. |
| 2541 | * Since this is an ABORT chunk, we have to discard it |
| 2542 | * because of the following text: |
| 2543 | * RFC 2960, Section 3.3.7 |
| 2544 | * If an endpoint receives an ABORT with a format error or for an |
| 2545 | * association that doesn't exist, it MUST silently discard it. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2546 | * Because the length is "invalid", we can't really discard just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | * as we do not know its true length. So, to be safe, discard the |
| 2548 | * packet. |
| 2549 | */ |
Xin Long | 441ae65 | 2017-07-23 09:34:36 +0800 | [diff] [blame] | 2550 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2551 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | |
| 2553 | /* See if we have an error cause code in the chunk. */ |
| 2554 | len = ntohs(chunk->chunk_hdr->length); |
| 2555 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 2556 | error = ((struct sctp_errhdr *)chunk->skb->data)->cause; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2558 | return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, asoc, |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2559 | chunk->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | /* |
| 2563 | * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state) |
| 2564 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2565 | sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(struct net *net, |
| 2566 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | const struct sctp_association *asoc, |
| 2568 | const sctp_subtype_t type, |
| 2569 | void *arg, |
| 2570 | sctp_cmd_seq_t *commands) |
| 2571 | { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2572 | return sctp_stop_t1_and_abort(net, commands, SCTP_ERROR_NO_ERROR, |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2573 | ENOPROTOOPT, asoc, |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2574 | (struct sctp_transport *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | /* |
| 2578 | * Process an ABORT. (COOKIE-ECHOED state) |
| 2579 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2580 | sctp_disposition_t sctp_sf_cookie_echoed_abort(struct net *net, |
| 2581 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2582 | const struct sctp_association *asoc, |
| 2583 | const sctp_subtype_t type, |
| 2584 | void *arg, |
| 2585 | sctp_cmd_seq_t *commands) |
| 2586 | { |
| 2587 | /* There is a single T1 timer, so we should be able to use |
| 2588 | * common function with the COOKIE-WAIT state. |
| 2589 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2590 | return sctp_sf_cookie_wait_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | /* |
| 2594 | * Stop T1 timer and abort association with "INIT failed". |
| 2595 | * |
| 2596 | * This is common code called by several sctp_sf_*_abort() functions above. |
| 2597 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2598 | static sctp_disposition_t sctp_stop_t1_and_abort(struct net *net, |
| 2599 | sctp_cmd_seq_t *commands, |
Al Viro | f94c019 | 2006-11-20 17:00:25 -0800 | [diff] [blame] | 2600 | __be16 error, int sk_err, |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2601 | const struct sctp_association *asoc, |
| 2602 | struct sctp_transport *transport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2604 | pr_debug("%s: ABORT received (INIT)\n", __func__); |
| 2605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2607 | SCTP_STATE(SCTP_STATE_CLOSED)); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2608 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2610 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2611 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | /* CMD_INIT_FAILED will DELETE_TCB. */ |
| 2613 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 2614 | SCTP_PERR(error)); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2615 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2616 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | /* |
| 2620 | * sctp_sf_do_9_2_shut |
| 2621 | * |
| 2622 | * Section: 9.2 |
| 2623 | * Upon the reception of the SHUTDOWN, the peer endpoint shall |
| 2624 | * - enter the SHUTDOWN-RECEIVED state, |
| 2625 | * |
| 2626 | * - stop accepting new data from its SCTP user |
| 2627 | * |
| 2628 | * - verify, by checking the Cumulative TSN Ack field of the chunk, |
| 2629 | * that all its outstanding DATA chunks have been received by the |
| 2630 | * SHUTDOWN sender. |
| 2631 | * |
| 2632 | * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT |
| 2633 | * send a SHUTDOWN in response to a ULP request. And should discard |
| 2634 | * subsequent SHUTDOWN chunks. |
| 2635 | * |
| 2636 | * If there are still outstanding DATA chunks left, the SHUTDOWN |
| 2637 | * receiver shall continue to follow normal data transmission |
| 2638 | * procedures defined in Section 6 until all outstanding DATA chunks |
| 2639 | * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept |
| 2640 | * new data from its SCTP user. |
| 2641 | * |
| 2642 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2643 | * |
| 2644 | * Inputs |
| 2645 | * (endpoint, asoc, chunk) |
| 2646 | * |
| 2647 | * Outputs |
| 2648 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2649 | * |
| 2650 | * The return value is the disposition of the chunk. |
| 2651 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2652 | sctp_disposition_t sctp_sf_do_9_2_shutdown(struct net *net, |
| 2653 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2654 | const struct sctp_association *asoc, |
| 2655 | const sctp_subtype_t type, |
| 2656 | void *arg, |
| 2657 | sctp_cmd_seq_t *commands) |
| 2658 | { |
| 2659 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | sctp_disposition_t disposition; |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2661 | struct sctp_shutdownhdr *sdh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | struct sctp_ulpevent *ev; |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2663 | __u32 ctsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
| 2665 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2666 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | |
| 2668 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 2669 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2670 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2671 | commands); |
| 2672 | |
| 2673 | /* Convert the elaborate header. */ |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2674 | sdh = (struct sctp_shutdownhdr *)chunk->skb->data; |
| 2675 | skb_pull(chunk->skb, sizeof(*sdh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | chunk->subh.shutdown_hdr = sdh; |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2677 | ctsn = ntohl(sdh->cum_tsn_ack); |
| 2678 | |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2679 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2680 | pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn, |
| 2681 | asoc->ctsn_ack_point); |
| 2682 | |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2683 | return SCTP_DISPOSITION_DISCARD; |
| 2684 | } |
| 2685 | |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2686 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 2687 | * send, terminating the association and respond to the |
| 2688 | * sender with an ABORT. |
| 2689 | */ |
| 2690 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2691 | return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
Sridhar Samudrala | eb0e007 | 2005-09-22 23:48:38 -0700 | [diff] [blame] | 2693 | /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT |
| 2694 | * When a peer sends a SHUTDOWN, SCTP delivers this notification to |
| 2695 | * inform the application that it should cease sending data. |
| 2696 | */ |
| 2697 | ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC); |
| 2698 | if (!ev) { |
| 2699 | disposition = SCTP_DISPOSITION_NOMEM; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2700 | goto out; |
Sridhar Samudrala | eb0e007 | 2005-09-22 23:48:38 -0700 | [diff] [blame] | 2701 | } |
| 2702 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 2703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | /* Upon the reception of the SHUTDOWN, the peer endpoint shall |
| 2705 | * - enter the SHUTDOWN-RECEIVED state, |
| 2706 | * - stop accepting new data from its SCTP user |
| 2707 | * |
| 2708 | * [This is implicit in the new state.] |
| 2709 | */ |
| 2710 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2711 | SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED)); |
| 2712 | disposition = SCTP_DISPOSITION_CONSUME; |
| 2713 | |
| 2714 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2715 | disposition = sctp_sf_do_9_2_shutdown_ack(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | arg, commands); |
| 2717 | } |
| 2718 | |
| 2719 | if (SCTP_DISPOSITION_NOMEM == disposition) |
| 2720 | goto out; |
| 2721 | |
| 2722 | /* - verify, by checking the Cumulative TSN Ack field of the |
| 2723 | * chunk, that all its outstanding DATA chunks have been |
| 2724 | * received by the SHUTDOWN sender. |
| 2725 | */ |
| 2726 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, |
Al Viro | 2178eda | 2006-11-20 17:26:53 -0800 | [diff] [blame] | 2727 | SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | out: |
| 2730 | return disposition; |
| 2731 | } |
| 2732 | |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2733 | /* |
| 2734 | * sctp_sf_do_9_2_shut_ctsn |
| 2735 | * |
| 2736 | * Once an endpoint has reached the SHUTDOWN-RECEIVED state, |
| 2737 | * it MUST NOT send a SHUTDOWN in response to a ULP request. |
| 2738 | * The Cumulative TSN Ack of the received SHUTDOWN chunk |
| 2739 | * MUST be processed. |
| 2740 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2741 | sctp_disposition_t sctp_sf_do_9_2_shut_ctsn(struct net *net, |
| 2742 | const struct sctp_endpoint *ep, |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2743 | const struct sctp_association *asoc, |
| 2744 | const sctp_subtype_t type, |
| 2745 | void *arg, |
| 2746 | sctp_cmd_seq_t *commands) |
| 2747 | { |
| 2748 | struct sctp_chunk *chunk = arg; |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2749 | struct sctp_shutdownhdr *sdh; |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2750 | __u32 ctsn; |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2751 | |
| 2752 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2753 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2754 | |
| 2755 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 2756 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2757 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2758 | commands); |
| 2759 | |
Xin Long | e61e405 | 2017-08-03 15:42:09 +0800 | [diff] [blame] | 2760 | sdh = (struct sctp_shutdownhdr *)chunk->skb->data; |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2761 | ctsn = ntohl(sdh->cum_tsn_ack); |
| 2762 | |
| 2763 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 2764 | pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn, |
| 2765 | asoc->ctsn_ack_point); |
| 2766 | |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2767 | return SCTP_DISPOSITION_DISCARD; |
| 2768 | } |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2769 | |
| 2770 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 2771 | * send, terminating the association and respond to the |
| 2772 | * sender with an ABORT. |
| 2773 | */ |
Wei Yongjun | a2f36ee | 2009-08-22 11:24:00 +0800 | [diff] [blame] | 2774 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2775 | return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands); |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2776 | |
| 2777 | /* verify, by checking the Cumulative TSN Ack field of the |
| 2778 | * chunk, that all its outstanding DATA chunks have been |
| 2779 | * received by the SHUTDOWN sender. |
| 2780 | */ |
| 2781 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, |
| 2782 | SCTP_BE32(sdh->cum_tsn_ack)); |
| 2783 | |
| 2784 | return SCTP_DISPOSITION_CONSUME; |
| 2785 | } |
| 2786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | /* RFC 2960 9.2 |
| 2788 | * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk |
| 2789 | * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination |
| 2790 | * transport addresses (either in the IP addresses or in the INIT chunk) |
| 2791 | * that belong to this association, it should discard the INIT chunk and |
| 2792 | * retransmit the SHUTDOWN ACK chunk. |
| 2793 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2794 | sctp_disposition_t sctp_sf_do_9_2_reshutack(struct net *net, |
| 2795 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | const struct sctp_association *asoc, |
| 2797 | const sctp_subtype_t type, |
| 2798 | void *arg, |
| 2799 | sctp_cmd_seq_t *commands) |
| 2800 | { |
| 2801 | struct sctp_chunk *chunk = (struct sctp_chunk *) arg; |
| 2802 | struct sctp_chunk *reply; |
| 2803 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 2804 | /* Make sure that the chunk has a valid length */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 2805 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2806 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 2807 | commands); |
| 2808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | /* Since we are not going to really process this INIT, there |
| 2810 | * is no point in verifying chunk boundries. Just generate |
| 2811 | * the SHUTDOWN ACK. |
| 2812 | */ |
| 2813 | reply = sctp_make_shutdown_ack(asoc, chunk); |
| 2814 | if (NULL == reply) |
| 2815 | goto nomem; |
| 2816 | |
| 2817 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for |
| 2818 | * the T2-SHUTDOWN timer. |
| 2819 | */ |
| 2820 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 2821 | |
| 2822 | /* and restart the T2-shutdown timer. */ |
| 2823 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 2824 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 2825 | |
| 2826 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 2827 | |
| 2828 | return SCTP_DISPOSITION_CONSUME; |
| 2829 | nomem: |
| 2830 | return SCTP_DISPOSITION_NOMEM; |
| 2831 | } |
| 2832 | |
| 2833 | /* |
| 2834 | * sctp_sf_do_ecn_cwr |
| 2835 | * |
| 2836 | * Section: Appendix A: Explicit Congestion Notification |
| 2837 | * |
| 2838 | * CWR: |
| 2839 | * |
| 2840 | * RFC 2481 details a specific bit for a sender to send in the header of |
| 2841 | * its next outbound TCP segment to indicate to its peer that it has |
| 2842 | * reduced its congestion window. This is termed the CWR bit. For |
| 2843 | * SCTP the same indication is made by including the CWR chunk. |
| 2844 | * This chunk contains one data element, i.e. the TSN number that |
| 2845 | * was sent in the ECNE chunk. This element represents the lowest |
| 2846 | * TSN number in the datagram that was originally marked with the |
| 2847 | * CE bit. |
| 2848 | * |
| 2849 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2850 | * Inputs |
| 2851 | * (endpoint, asoc, chunk) |
| 2852 | * |
| 2853 | * Outputs |
| 2854 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2855 | * |
| 2856 | * The return value is the disposition of the chunk. |
| 2857 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2858 | sctp_disposition_t sctp_sf_do_ecn_cwr(struct net *net, |
| 2859 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | const struct sctp_association *asoc, |
| 2861 | const sctp_subtype_t type, |
| 2862 | void *arg, |
| 2863 | sctp_cmd_seq_t *commands) |
| 2864 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | struct sctp_chunk *chunk = arg; |
Xin Long | 65f7710 | 2017-08-03 15:42:16 +0800 | [diff] [blame^] | 2866 | struct sctp_cwrhdr *cwr; |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2867 | u32 lowest_tsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | |
| 2869 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2870 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | |
Xin Long | b515fd2 | 2017-08-03 15:42:15 +0800 | [diff] [blame] | 2872 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2873 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2875 | |
Xin Long | 65f7710 | 2017-08-03 15:42:16 +0800 | [diff] [blame^] | 2876 | cwr = (struct sctp_cwrhdr *)chunk->skb->data; |
| 2877 | skb_pull(chunk->skb, sizeof(*cwr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2879 | lowest_tsn = ntohl(cwr->lowest_tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | |
| 2881 | /* Does this CWR ack the last sent congestion notification? */ |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2882 | if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2883 | /* Stop sending ECNE. */ |
| 2884 | sctp_add_cmd_sf(commands, |
| 2885 | SCTP_CMD_ECN_CWR, |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2886 | SCTP_U32(lowest_tsn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | } |
| 2888 | return SCTP_DISPOSITION_CONSUME; |
| 2889 | } |
| 2890 | |
| 2891 | /* |
| 2892 | * sctp_sf_do_ecne |
| 2893 | * |
| 2894 | * Section: Appendix A: Explicit Congestion Notification |
| 2895 | * |
| 2896 | * ECN-Echo |
| 2897 | * |
| 2898 | * RFC 2481 details a specific bit for a receiver to send back in its |
| 2899 | * TCP acknowledgements to notify the sender of the Congestion |
| 2900 | * Experienced (CE) bit having arrived from the network. For SCTP this |
| 2901 | * same indication is made by including the ECNE chunk. This chunk |
| 2902 | * contains one data element, i.e. the lowest TSN associated with the IP |
| 2903 | * datagram marked with the CE bit..... |
| 2904 | * |
| 2905 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2906 | * Inputs |
| 2907 | * (endpoint, asoc, chunk) |
| 2908 | * |
| 2909 | * Outputs |
| 2910 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2911 | * |
| 2912 | * The return value is the disposition of the chunk. |
| 2913 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2914 | sctp_disposition_t sctp_sf_do_ecne(struct net *net, |
| 2915 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | const struct sctp_association *asoc, |
| 2917 | const sctp_subtype_t type, |
| 2918 | void *arg, |
| 2919 | sctp_cmd_seq_t *commands) |
| 2920 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | struct sctp_chunk *chunk = arg; |
Xin Long | 1fb6d83 | 2017-08-03 15:42:14 +0800 | [diff] [blame] | 2922 | struct sctp_ecnehdr *ecne; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | |
| 2924 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2925 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | |
Xin Long | b515fd2 | 2017-08-03 15:42:15 +0800 | [diff] [blame] | 2927 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2928 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | commands); |
| 2930 | |
Xin Long | 1fb6d83 | 2017-08-03 15:42:14 +0800 | [diff] [blame] | 2931 | ecne = (struct sctp_ecnehdr *)chunk->skb->data; |
| 2932 | skb_pull(chunk->skb, sizeof(*ecne)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
| 2934 | /* If this is a newer ECNE than the last CWR packet we sent out */ |
| 2935 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE, |
| 2936 | SCTP_U32(ntohl(ecne->lowest_tsn))); |
| 2937 | |
| 2938 | return SCTP_DISPOSITION_CONSUME; |
| 2939 | } |
| 2940 | |
| 2941 | /* |
| 2942 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks |
| 2943 | * |
| 2944 | * The SCTP endpoint MUST always acknowledge the reception of each valid |
| 2945 | * DATA chunk. |
| 2946 | * |
| 2947 | * The guidelines on delayed acknowledgement algorithm specified in |
| 2948 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an |
| 2949 | * acknowledgement SHOULD be generated for at least every second packet |
| 2950 | * (not every second DATA chunk) received, and SHOULD be generated within |
| 2951 | * 200 ms of the arrival of any unacknowledged DATA chunk. In some |
| 2952 | * situations it may be beneficial for an SCTP transmitter to be more |
| 2953 | * conservative than the algorithms detailed in this document allow. |
| 2954 | * However, an SCTP transmitter MUST NOT be more aggressive than the |
| 2955 | * following algorithms allow. |
| 2956 | * |
| 2957 | * A SCTP receiver MUST NOT generate more than one SACK for every |
| 2958 | * incoming packet, other than to update the offered window as the |
| 2959 | * receiving application consumes new data. |
| 2960 | * |
| 2961 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2962 | * |
| 2963 | * Inputs |
| 2964 | * (endpoint, asoc, chunk) |
| 2965 | * |
| 2966 | * Outputs |
| 2967 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2968 | * |
| 2969 | * The return value is the disposition of the chunk. |
| 2970 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2971 | sctp_disposition_t sctp_sf_eat_data_6_2(struct net *net, |
| 2972 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | const struct sctp_association *asoc, |
| 2974 | const sctp_subtype_t type, |
| 2975 | void *arg, |
| 2976 | sctp_cmd_seq_t *commands) |
| 2977 | { |
| 2978 | struct sctp_chunk *chunk = arg; |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 2979 | sctp_arg_t force = SCTP_NOFORCE(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | int error; |
| 2981 | |
| 2982 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 2983 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 2984 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2985 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2986 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | |
Xin Long | 9f8d314 | 2017-06-30 11:52:20 +0800 | [diff] [blame] | 2988 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_data_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2989 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2990 | commands); |
| 2991 | |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 2992 | error = sctp_eat_data(asoc, chunk, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2993 | switch (error) { |
| 2994 | case SCTP_IERROR_NO_ERROR: |
| 2995 | break; |
| 2996 | case SCTP_IERROR_HIGH_TSN: |
| 2997 | case SCTP_IERROR_BAD_STREAM: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 2998 | SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | goto discard_noforce; |
| 3000 | case SCTP_IERROR_DUP_TSN: |
| 3001 | case SCTP_IERROR_IGNORE_TSN: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3002 | SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | goto discard_force; |
| 3004 | case SCTP_IERROR_NO_DATA: |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 3005 | return SCTP_DISPOSITION_ABORT; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 3006 | case SCTP_IERROR_PROTO_VIOLATION: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3007 | return sctp_sf_abort_violation(net, ep, asoc, chunk, commands, |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 3008 | (u8 *)chunk->subh.data_hdr, |
| 3009 | sizeof(struct sctp_datahdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | default: |
| 3011 | BUG(); |
| 3012 | } |
| 3013 | |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 3014 | if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM) |
| 3015 | force = SCTP_FORCE(); |
| 3016 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 3017 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3019 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 3020 | } |
| 3021 | |
| 3022 | /* If this is the last chunk in a packet, we need to count it |
| 3023 | * toward sack generation. Note that we need to SACK every |
| 3024 | * OTHER packet containing data chunks, EVEN IF WE DISCARD |
| 3025 | * THEM. We elect to NOT generate SACK's if the chunk fails |
| 3026 | * the verification tag test. |
| 3027 | * |
| 3028 | * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks |
| 3029 | * |
| 3030 | * The SCTP endpoint MUST always acknowledge the reception of |
| 3031 | * each valid DATA chunk. |
| 3032 | * |
| 3033 | * The guidelines on delayed acknowledgement algorithm |
| 3034 | * specified in Section 4.2 of [RFC2581] SHOULD be followed. |
| 3035 | * Specifically, an acknowledgement SHOULD be generated for at |
| 3036 | * least every second packet (not every second DATA chunk) |
| 3037 | * received, and SHOULD be generated within 200 ms of the |
| 3038 | * arrival of any unacknowledged DATA chunk. In some |
| 3039 | * situations it may be beneficial for an SCTP transmitter to |
| 3040 | * be more conservative than the algorithms detailed in this |
| 3041 | * document allow. However, an SCTP transmitter MUST NOT be |
| 3042 | * more aggressive than the following algorithms allow. |
| 3043 | */ |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 3044 | if (chunk->end_of_packet) |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 3045 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | return SCTP_DISPOSITION_CONSUME; |
| 3048 | |
| 3049 | discard_force: |
| 3050 | /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks |
| 3051 | * |
| 3052 | * When a packet arrives with duplicate DATA chunk(s) and with |
| 3053 | * no new DATA chunk(s), the endpoint MUST immediately send a |
| 3054 | * SACK with no delay. If a packet arrives with duplicate |
| 3055 | * DATA chunk(s) bundled with new DATA chunks, the endpoint |
| 3056 | * MAY immediately send a SACK. Normally receipt of duplicate |
| 3057 | * DATA chunks will occur when the original SACK chunk was lost |
| 3058 | * and the peer's RTO has expired. The duplicate TSN number(s) |
| 3059 | * SHOULD be reported in the SACK as duplicate. |
| 3060 | */ |
| 3061 | /* In our case, we split the MAY SACK advice up whether or not |
| 3062 | * the last chunk is a duplicate.' |
| 3063 | */ |
| 3064 | if (chunk->end_of_packet) |
| 3065 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 3066 | return SCTP_DISPOSITION_DISCARD; |
| 3067 | |
| 3068 | discard_noforce: |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 3069 | if (chunk->end_of_packet) |
Wei Yongjun | 6dc7694 | 2009-11-23 15:53:53 -0500 | [diff] [blame] | 3070 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | return SCTP_DISPOSITION_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
| 3075 | /* |
| 3076 | * sctp_sf_eat_data_fast_4_4 |
| 3077 | * |
| 3078 | * Section: 4 (4) |
| 3079 | * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received |
| 3080 | * DATA chunks without delay. |
| 3081 | * |
| 3082 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3083 | * Inputs |
| 3084 | * (endpoint, asoc, chunk) |
| 3085 | * |
| 3086 | * Outputs |
| 3087 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3088 | * |
| 3089 | * The return value is the disposition of the chunk. |
| 3090 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3091 | sctp_disposition_t sctp_sf_eat_data_fast_4_4(struct net *net, |
| 3092 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | const struct sctp_association *asoc, |
| 3094 | const sctp_subtype_t type, |
| 3095 | void *arg, |
| 3096 | sctp_cmd_seq_t *commands) |
| 3097 | { |
| 3098 | struct sctp_chunk *chunk = arg; |
| 3099 | int error; |
| 3100 | |
| 3101 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3102 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3103 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3104 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Xin Long | 9f8d314 | 2017-06-30 11:52:20 +0800 | [diff] [blame] | 3107 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_data_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3108 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | commands); |
| 3110 | |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3111 | error = sctp_eat_data(asoc, chunk, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | switch (error) { |
| 3113 | case SCTP_IERROR_NO_ERROR: |
| 3114 | case SCTP_IERROR_HIGH_TSN: |
| 3115 | case SCTP_IERROR_DUP_TSN: |
| 3116 | case SCTP_IERROR_IGNORE_TSN: |
| 3117 | case SCTP_IERROR_BAD_STREAM: |
| 3118 | break; |
| 3119 | case SCTP_IERROR_NO_DATA: |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 3120 | return SCTP_DISPOSITION_ABORT; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 3121 | case SCTP_IERROR_PROTO_VIOLATION: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3122 | return sctp_sf_abort_violation(net, ep, asoc, chunk, commands, |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 3123 | (u8 *)chunk->subh.data_hdr, |
| 3124 | sizeof(struct sctp_datahdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | default: |
| 3126 | BUG(); |
| 3127 | } |
| 3128 | |
| 3129 | /* Go a head and force a SACK, since we are shutting down. */ |
| 3130 | |
| 3131 | /* Implementor's Guide. |
| 3132 | * |
| 3133 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately |
| 3134 | * respond to each received packet containing one or more DATA chunk(s) |
| 3135 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer |
| 3136 | */ |
| 3137 | if (chunk->end_of_packet) { |
| 3138 | /* We must delay the chunk creation since the cumulative |
| 3139 | * TSN has not been updated yet. |
| 3140 | */ |
| 3141 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); |
| 3142 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 3143 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3144 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3145 | } |
| 3146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3147 | return SCTP_DISPOSITION_CONSUME; |
| 3148 | } |
| 3149 | |
| 3150 | /* |
| 3151 | * Section: 6.2 Processing a Received SACK |
| 3152 | * D) Any time a SACK arrives, the endpoint performs the following: |
| 3153 | * |
| 3154 | * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point, |
| 3155 | * then drop the SACK. Since Cumulative TSN Ack is monotonically |
| 3156 | * increasing, a SACK whose Cumulative TSN Ack is less than the |
| 3157 | * Cumulative TSN Ack Point indicates an out-of-order SACK. |
| 3158 | * |
| 3159 | * ii) Set rwnd equal to the newly received a_rwnd minus the number |
| 3160 | * of bytes still outstanding after processing the Cumulative TSN Ack |
| 3161 | * and the Gap Ack Blocks. |
| 3162 | * |
| 3163 | * iii) If the SACK is missing a TSN that was previously |
| 3164 | * acknowledged via a Gap Ack Block (e.g., the data receiver |
| 3165 | * reneged on the data), then mark the corresponding DATA chunk |
| 3166 | * as available for retransmit: Mark it as missing for fast |
| 3167 | * retransmit as described in Section 7.2.4 and if no retransmit |
| 3168 | * timer is running for the destination address to which the DATA |
| 3169 | * chunk was originally transmitted, then T3-rtx is started for |
| 3170 | * that destination address. |
| 3171 | * |
| 3172 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3173 | * |
| 3174 | * Inputs |
| 3175 | * (endpoint, asoc, chunk) |
| 3176 | * |
| 3177 | * Outputs |
| 3178 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3179 | * |
| 3180 | * The return value is the disposition of the chunk. |
| 3181 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3182 | sctp_disposition_t sctp_sf_eat_sack_6_2(struct net *net, |
| 3183 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | const struct sctp_association *asoc, |
| 3185 | const sctp_subtype_t type, |
| 3186 | void *arg, |
| 3187 | sctp_cmd_seq_t *commands) |
| 3188 | { |
| 3189 | struct sctp_chunk *chunk = arg; |
Xin Long | 7873108 | 2017-07-23 09:34:32 +0800 | [diff] [blame] | 3190 | struct sctp_sackhdr *sackh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | __u32 ctsn; |
| 3192 | |
| 3193 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3194 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | |
| 3196 | /* Make sure that the SACK chunk has a valid length. */ |
Xin Long | d4d6c61 | 2017-07-23 09:34:33 +0800 | [diff] [blame] | 3197 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3198 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | commands); |
| 3200 | |
| 3201 | /* Pull the SACK chunk from the data buffer */ |
| 3202 | sackh = sctp_sm_pull_sack(chunk); |
| 3203 | /* Was this a bogus SACK? */ |
| 3204 | if (!sackh) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3205 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | chunk->subh.sack_hdr = sackh; |
| 3207 | ctsn = ntohl(sackh->cum_tsn_ack); |
| 3208 | |
| 3209 | /* i) If Cumulative TSN Ack is less than the Cumulative TSN |
| 3210 | * Ack Point, then drop the SACK. Since Cumulative TSN |
| 3211 | * Ack is monotonically increasing, a SACK whose |
| 3212 | * Cumulative TSN Ack is less than the Cumulative TSN Ack |
| 3213 | * Point indicates an out-of-order SACK. |
| 3214 | */ |
| 3215 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 3216 | pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn, |
| 3217 | asoc->ctsn_ack_point); |
| 3218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | return SCTP_DISPOSITION_DISCARD; |
| 3220 | } |
| 3221 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 3222 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 3223 | * send, terminating the association and respond to the |
| 3224 | * sender with an ABORT. |
| 3225 | */ |
| 3226 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3227 | return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands); |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 3228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | /* Return this SACK for further processing. */ |
Nicolas Dichtel | edfee03 | 2012-10-03 05:43:22 +0000 | [diff] [blame] | 3230 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | |
| 3232 | /* Note: We do the rest of the work on the PROCESS_SACK |
| 3233 | * sideeffect. |
| 3234 | */ |
| 3235 | return SCTP_DISPOSITION_CONSUME; |
| 3236 | } |
| 3237 | |
| 3238 | /* |
| 3239 | * Generate an ABORT in response to a packet. |
| 3240 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3241 | * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3243 | * 8) The receiver should respond to the sender of the OOTB packet with |
| 3244 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet |
| 3245 | * MUST fill in the Verification Tag field of the outbound packet |
| 3246 | * with the value found in the Verification Tag field of the OOTB |
| 3247 | * packet and set the T-bit in the Chunk Flags to indicate that the |
| 3248 | * Verification Tag is reflected. After sending this ABORT, the |
| 3249 | * receiver of the OOTB packet shall discard the OOTB packet and take |
| 3250 | * no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | * |
| 3252 | * Verification Tag: |
| 3253 | * |
| 3254 | * The return value is the disposition of the chunk. |
| 3255 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3256 | static sctp_disposition_t sctp_sf_tabort_8_4_8(struct net *net, |
| 3257 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3258 | const struct sctp_association *asoc, |
| 3259 | const sctp_subtype_t type, |
| 3260 | void *arg, |
| 3261 | sctp_cmd_seq_t *commands) |
| 3262 | { |
| 3263 | struct sctp_packet *packet = NULL; |
| 3264 | struct sctp_chunk *chunk = arg; |
| 3265 | struct sctp_chunk *abort; |
| 3266 | |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 3267 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Marcelo Ricardo Leitner | eab5907 | 2016-12-28 09:26:31 -0200 | [diff] [blame] | 3268 | if (!packet) |
| 3269 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | |
Marcelo Ricardo Leitner | eab5907 | 2016-12-28 09:26:31 -0200 | [diff] [blame] | 3271 | /* Make an ABORT. The T bit will be set if the asoc |
| 3272 | * is NULL. |
| 3273 | */ |
| 3274 | abort = sctp_make_abort(asoc, chunk, 0); |
| 3275 | if (!abort) { |
| 3276 | sctp_ootb_pkt_free(packet); |
| 3277 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Marcelo Ricardo Leitner | eab5907 | 2016-12-28 09:26:31 -0200 | [diff] [blame] | 3280 | /* Reflect vtag if T-Bit is set */ |
| 3281 | if (sctp_test_T_bit(abort)) |
| 3282 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 3283 | |
| 3284 | /* Set the skb to the belonging sock for accounting. */ |
| 3285 | abort->skb->sk = ep->base.sk; |
| 3286 | |
| 3287 | sctp_packet_append_chunk(packet, abort); |
| 3288 | |
| 3289 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 3290 | SCTP_PACKET(packet)); |
| 3291 | |
| 3292 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
| 3293 | |
| 3294 | sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 3295 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | /* |
| 3299 | * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR |
| 3300 | * event as ULP notification for each cause included in the chunk. |
| 3301 | * |
| 3302 | * API 5.3.1.3 - SCTP_REMOTE_ERROR |
| 3303 | * |
| 3304 | * The return value is the disposition of the chunk. |
| 3305 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3306 | sctp_disposition_t sctp_sf_operr_notify(struct net *net, |
| 3307 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | const struct sctp_association *asoc, |
| 3309 | const sctp_subtype_t type, |
| 3310 | void *arg, |
| 3311 | sctp_cmd_seq_t *commands) |
| 3312 | { |
| 3313 | struct sctp_chunk *chunk = arg; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3314 | struct sctp_errhdr *err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | |
| 3316 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3317 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | |
| 3319 | /* Make sure that the ERROR chunk has a valid length. */ |
Xin Long | 87caeba | 2017-08-03 15:42:12 +0800 | [diff] [blame] | 3320 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3321 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | commands); |
Shan Wei | 8a00be1 | 2011-04-19 21:25:40 +0000 | [diff] [blame] | 3323 | sctp_walk_errors(err, chunk->chunk_hdr); |
| 3324 | if ((void *)err != (void *)chunk->chunk_end) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3325 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
Shan Wei | 8a00be1 | 2011-04-19 21:25:40 +0000 | [diff] [blame] | 3326 | (void *)err, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | |
Wei Yongjun | 3df26787 | 2009-03-02 06:46:51 +0000 | [diff] [blame] | 3328 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR, |
| 3329 | SCTP_CHUNK(chunk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | /* |
| 3335 | * Process an inbound SHUTDOWN ACK. |
| 3336 | * |
| 3337 | * From Section 9.2: |
| 3338 | * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall |
| 3339 | * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its |
| 3340 | * peer, and remove all record of the association. |
| 3341 | * |
| 3342 | * The return value is the disposition. |
| 3343 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3344 | sctp_disposition_t sctp_sf_do_9_2_final(struct net *net, |
| 3345 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | const struct sctp_association *asoc, |
| 3347 | const sctp_subtype_t type, |
| 3348 | void *arg, |
| 3349 | sctp_cmd_seq_t *commands) |
| 3350 | { |
| 3351 | struct sctp_chunk *chunk = arg; |
| 3352 | struct sctp_chunk *reply; |
| 3353 | struct sctp_ulpevent *ev; |
| 3354 | |
| 3355 | if (!sctp_vtag_verify(chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3356 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3357 | |
| 3358 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3359 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3360 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | /* 10.2 H) SHUTDOWN COMPLETE notification |
| 3363 | * |
| 3364 | * When SCTP completes the shutdown procedures (section 9.2) this |
| 3365 | * notification is passed to the upper layer. |
| 3366 | */ |
| 3367 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 3368 | 0, 0, 0, NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | if (!ev) |
| 3370 | goto nomem; |
| 3371 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 3372 | /* ...send a SHUTDOWN COMPLETE chunk to its peer, */ |
| 3373 | reply = sctp_make_shutdown_complete(asoc, chunk); |
| 3374 | if (!reply) |
| 3375 | goto nomem_chunk; |
| 3376 | |
| 3377 | /* Do all the commands now (after allocation), so that we |
| 3378 | * have consistent state if memory allocation failes |
| 3379 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 3381 | |
| 3382 | /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall |
| 3383 | * stop the T2-shutdown timer, |
| 3384 | */ |
| 3385 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3386 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3387 | |
| 3388 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3389 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 3390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 3392 | SCTP_STATE(SCTP_STATE_CLOSED)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3393 | SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS); |
| 3394 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 3396 | |
| 3397 | /* ...and remove all record of the association. */ |
| 3398 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 3399 | return SCTP_DISPOSITION_DELETE_TCB; |
| 3400 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 3401 | nomem_chunk: |
| 3402 | sctp_ulpevent_free(ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | nomem: |
| 3404 | return SCTP_DISPOSITION_NOMEM; |
| 3405 | } |
| 3406 | |
| 3407 | /* |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3408 | * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41. |
| 3409 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
| 3411 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
| 3412 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB |
| 3413 | * packet must fill in the Verification Tag field of the outbound |
| 3414 | * packet with the Verification Tag received in the SHUTDOWN ACK and |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3415 | * set the T-bit in the Chunk Flags to indicate that the Verification |
| 3416 | * Tag is reflected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | * |
| 3418 | * 8) The receiver should respond to the sender of the OOTB packet with |
| 3419 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet |
| 3420 | * MUST fill in the Verification Tag field of the outbound packet |
| 3421 | * with the value found in the Verification Tag field of the OOTB |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3422 | * packet and set the T-bit in the Chunk Flags to indicate that the |
| 3423 | * Verification Tag is reflected. After sending this ABORT, the |
| 3424 | * receiver of the OOTB packet shall discard the OOTB packet and take |
| 3425 | * no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3427 | sctp_disposition_t sctp_sf_ootb(struct net *net, |
| 3428 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | const struct sctp_association *asoc, |
| 3430 | const sctp_subtype_t type, |
| 3431 | void *arg, |
| 3432 | sctp_cmd_seq_t *commands) |
| 3433 | { |
| 3434 | struct sctp_chunk *chunk = arg; |
| 3435 | struct sk_buff *skb = chunk->skb; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3436 | struct sctp_chunkhdr *ch; |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3437 | struct sctp_errhdr *err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | __u8 *ch_end; |
| 3439 | int ootb_shut_ack = 0; |
Shan Wei | 85c5ed4 | 2011-04-19 21:30:01 +0000 | [diff] [blame] | 3440 | int ootb_cookie_ack = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3442 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3444 | ch = (struct sctp_chunkhdr *)chunk->chunk_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | do { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3446 | /* Report violation if the chunk is less then minimal */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3447 | if (ntohs(ch->length) < sizeof(*ch)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3448 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3449 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Marcelo Ricardo Leitner | bf911e9 | 2016-10-25 14:27:39 -0200 | [diff] [blame] | 3451 | /* Report violation if chunk len overflows */ |
| 3452 | ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length)); |
| 3453 | if (ch_end > skb_tail_pointer(skb)) |
| 3454 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
| 3455 | commands); |
| 3456 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3457 | /* Now that we know we at least have a chunk header, |
| 3458 | * do things that are type appropriate. |
| 3459 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | if (SCTP_CID_SHUTDOWN_ACK == ch->type) |
| 3461 | ootb_shut_ack = 1; |
| 3462 | |
| 3463 | /* RFC 2960, Section 3.3.7 |
| 3464 | * Moreover, under any circumstances, an endpoint that |
| 3465 | * receives an ABORT MUST NOT respond to that ABORT by |
| 3466 | * sending an ABORT of its own. |
| 3467 | */ |
| 3468 | if (SCTP_CID_ABORT == ch->type) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3469 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3470 | |
Shan Wei | 85c5ed4 | 2011-04-19 21:30:01 +0000 | [diff] [blame] | 3471 | /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR |
| 3472 | * or a COOKIE ACK the SCTP Packet should be silently |
| 3473 | * discarded. |
| 3474 | */ |
| 3475 | |
| 3476 | if (SCTP_CID_COOKIE_ACK == ch->type) |
| 3477 | ootb_cookie_ack = 1; |
| 3478 | |
| 3479 | if (SCTP_CID_ERROR == ch->type) { |
| 3480 | sctp_walk_errors(err, ch) { |
| 3481 | if (SCTP_ERROR_STALE_COOKIE == err->cause) { |
| 3482 | ootb_cookie_ack = 1; |
| 3483 | break; |
| 3484 | } |
| 3485 | } |
| 3486 | } |
| 3487 | |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3488 | ch = (struct sctp_chunkhdr *)ch_end; |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3489 | } while (ch_end < skb_tail_pointer(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | |
| 3491 | if (ootb_shut_ack) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3492 | return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands); |
Shan Wei | 85c5ed4 | 2011-04-19 21:30:01 +0000 | [diff] [blame] | 3493 | else if (ootb_cookie_ack) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3494 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | else |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3496 | return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | /* |
| 3500 | * Handle an "Out of the blue" SHUTDOWN ACK. |
| 3501 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3502 | * Section: 8.4 5, sctpimpguide 2.41. |
| 3503 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3505 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
| 3506 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB |
| 3507 | * packet must fill in the Verification Tag field of the outbound |
| 3508 | * packet with the Verification Tag received in the SHUTDOWN ACK and |
| 3509 | * set the T-bit in the Chunk Flags to indicate that the Verification |
| 3510 | * Tag is reflected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | * |
| 3512 | * Inputs |
| 3513 | * (endpoint, asoc, type, arg, commands) |
| 3514 | * |
| 3515 | * Outputs |
| 3516 | * (sctp_disposition_t) |
| 3517 | * |
| 3518 | * The return value is the disposition of the chunk. |
| 3519 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3520 | static sctp_disposition_t sctp_sf_shut_8_4_5(struct net *net, |
| 3521 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | const struct sctp_association *asoc, |
| 3523 | const sctp_subtype_t type, |
| 3524 | void *arg, |
| 3525 | sctp_cmd_seq_t *commands) |
| 3526 | { |
| 3527 | struct sctp_packet *packet = NULL; |
| 3528 | struct sctp_chunk *chunk = arg; |
| 3529 | struct sctp_chunk *shut; |
| 3530 | |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 3531 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3532 | if (!packet) |
| 3533 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3535 | /* Make an SHUTDOWN_COMPLETE. |
| 3536 | * The T bit will be set if the asoc is NULL. |
| 3537 | */ |
| 3538 | shut = sctp_make_shutdown_complete(asoc, chunk); |
| 3539 | if (!shut) { |
| 3540 | sctp_ootb_pkt_free(packet); |
| 3541 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3542 | } |
| 3543 | |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3544 | /* Reflect vtag if T-Bit is set */ |
| 3545 | if (sctp_test_T_bit(shut)) |
| 3546 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 3547 | |
| 3548 | /* Set the skb to the belonging sock for accounting. */ |
| 3549 | shut->skb->sk = ep->base.sk; |
| 3550 | |
| 3551 | sctp_packet_append_chunk(packet, shut); |
| 3552 | |
| 3553 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 3554 | SCTP_PACKET(packet)); |
| 3555 | |
| 3556 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
| 3557 | |
| 3558 | /* If the chunk length is invalid, we don't want to process |
| 3559 | * the reset of the packet. |
| 3560 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3561 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Marcelo Ricardo Leitner | 1ff0156 | 2016-12-28 09:26:32 -0200 | [diff] [blame] | 3562 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 3563 | |
| 3564 | /* We need to discard the rest of the packet to prevent |
| 3565 | * potential bomming attacks from additional bundled chunks. |
| 3566 | * This is documented in SCTP Threats ID. |
| 3567 | */ |
| 3568 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | } |
| 3570 | |
| 3571 | /* |
| 3572 | * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state. |
| 3573 | * |
| 3574 | * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK |
| 3575 | * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the |
| 3576 | * procedures in section 8.4 SHOULD be followed, in other words it |
| 3577 | * should be treated as an Out Of The Blue packet. |
| 3578 | * [This means that we do NOT check the Verification Tag on these |
| 3579 | * chunks. --piggy ] |
| 3580 | * |
| 3581 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3582 | sctp_disposition_t sctp_sf_do_8_5_1_E_sa(struct net *net, |
| 3583 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | const struct sctp_association *asoc, |
| 3585 | const sctp_subtype_t type, |
| 3586 | void *arg, |
| 3587 | sctp_cmd_seq_t *commands) |
| 3588 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3589 | struct sctp_chunk *chunk = arg; |
| 3590 | |
| 3591 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 3592 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3593 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3594 | commands); |
| 3595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | /* Although we do have an association in this case, it corresponds |
| 3597 | * to a restarted association. So the packet is treated as an OOTB |
| 3598 | * packet and the state function that handles OOTB SHUTDOWN_ACK is |
| 3599 | * called with a NULL association. |
| 3600 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3601 | SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 3602 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3603 | return sctp_sf_shut_8_4_5(net, ep, NULL, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3607 | sctp_disposition_t sctp_sf_do_asconf(struct net *net, |
| 3608 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | const struct sctp_association *asoc, |
| 3610 | const sctp_subtype_t type, void *arg, |
| 3611 | sctp_cmd_seq_t *commands) |
| 3612 | { |
| 3613 | struct sctp_chunk *chunk = arg; |
| 3614 | struct sctp_chunk *asconf_ack = NULL; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3615 | struct sctp_paramhdr *err_param = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | sctp_addiphdr_t *hdr; |
| 3617 | __u32 serial; |
| 3618 | |
| 3619 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3620 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3621 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3622 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3625 | /* ADD-IP: Section 4.1.1 |
| 3626 | * This chunk MUST be sent in an authenticated way by using |
| 3627 | * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk |
| 3628 | * is received unauthenticated it MUST be silently discarded as |
| 3629 | * described in [I-D.ietf-tsvwg-sctp-auth]. |
| 3630 | */ |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 3631 | if (!net->sctp.addip_noauth && !chunk->auth) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3632 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | /* Make sure that the ASCONF ADDIP chunk has a valid length. */ |
| 3635 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3636 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | commands); |
| 3638 | |
| 3639 | hdr = (sctp_addiphdr_t *)chunk->skb->data; |
| 3640 | serial = ntohl(hdr->serial); |
| 3641 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3642 | /* Verify the ASCONF chunk before processing it. */ |
Daniel Borkmann | 9de7922 | 2014-10-09 22:55:31 +0200 | [diff] [blame] | 3643 | if (!sctp_verify_asconf(asoc, chunk, true, &err_param)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3644 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3645 | (void *)err_param, commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3646 | |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3647 | /* ADDIP 5.2 E1) Compare the value of the serial number to the value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | * the endpoint stored in a new association variable |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3649 | * 'Peer-Serial-Number'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | */ |
| 3651 | if (serial == asoc->peer.addip_serial + 1) { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3652 | /* If this is the first instance of ASCONF in the packet, |
| 3653 | * we can clean our old ASCONF-ACKs. |
| 3654 | */ |
| 3655 | if (!chunk->has_asconf) |
| 3656 | sctp_assoc_clean_asconf_ack_cache(asoc); |
| 3657 | |
| 3658 | /* ADDIP 5.2 E4) When the Sequence Number matches the next one |
| 3659 | * expected, process the ASCONF as described below and after |
| 3660 | * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to |
| 3661 | * the response packet and cache a copy of it (in the event it |
| 3662 | * later needs to be retransmitted). |
| 3663 | * |
| 3664 | * Essentially, do V1-V5. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | */ |
| 3666 | asconf_ack = sctp_process_asconf((struct sctp_association *) |
| 3667 | asoc, chunk); |
| 3668 | if (!asconf_ack) |
| 3669 | return SCTP_DISPOSITION_NOMEM; |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3670 | } else if (serial < asoc->peer.addip_serial + 1) { |
| 3671 | /* ADDIP 5.2 E2) |
| 3672 | * If the value found in the Sequence Number is less than the |
| 3673 | * ('Peer- Sequence-Number' + 1), simply skip to the next |
| 3674 | * ASCONF, and include in the outbound response packet |
| 3675 | * any previously cached ASCONF-ACK response that was |
| 3676 | * sent and saved that matches the Sequence Number of the |
| 3677 | * ASCONF. Note: It is possible that no cached ASCONF-ACK |
| 3678 | * Chunk exists. This will occur when an older ASCONF |
| 3679 | * arrives out of order. In such a case, the receiver |
| 3680 | * should skip the ASCONF Chunk and not include ASCONF-ACK |
| 3681 | * Chunk for that chunk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | */ |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3683 | asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial); |
| 3684 | if (!asconf_ack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | return SCTP_DISPOSITION_DISCARD; |
Vlad Yasevich | 31b02e1 | 2009-09-04 18:21:00 -0400 | [diff] [blame] | 3686 | |
| 3687 | /* Reset the transport so that we select the correct one |
| 3688 | * this time around. This is to make sure that we don't |
| 3689 | * accidentally use a stale transport that's been removed. |
| 3690 | */ |
| 3691 | asconf_ack->transport = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | } else { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3693 | /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | * it must be either a stale packet or from an attacker. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3695 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | return SCTP_DISPOSITION_DISCARD; |
| 3697 | } |
| 3698 | |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3699 | /* ADDIP 5.2 E6) The destination address of the SCTP packet |
| 3700 | * containing the ASCONF-ACK Chunks MUST be the source address of |
| 3701 | * the SCTP packet that held the ASCONF Chunks. |
| 3702 | * |
| 3703 | * To do this properly, we'll set the destination address of the chunk |
| 3704 | * and at the transmit time, will try look up the transport to use. |
| 3705 | * Since ASCONFs may be bundled, the correct transport may not be |
Thadeu Lima de Souza Cascardo | 94e2bd6 | 2009-10-16 15:20:49 +0200 | [diff] [blame] | 3706 | * created until we process the entire packet, thus this workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | */ |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3708 | asconf_ack->dest = chunk->source; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); |
Michio Honda | 6af29cc | 2011-06-16 17:14:34 +0900 | [diff] [blame] | 3710 | if (asoc->new_transport) { |
wangweidong | f7010e6 | 2013-12-23 12:16:52 +0800 | [diff] [blame] | 3711 | sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands); |
Michio Honda | 6af29cc | 2011-06-16 17:14:34 +0900 | [diff] [blame] | 3712 | ((struct sctp_association *)asoc)->new_transport = NULL; |
| 3713 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | return SCTP_DISPOSITION_CONSUME; |
| 3716 | } |
| 3717 | |
| 3718 | /* |
| 3719 | * ADDIP Section 4.3 General rules for address manipulation |
| 3720 | * When building TLV parameters for the ASCONF Chunk that will add or |
| 3721 | * delete IP addresses the D0 to D13 rules should be applied: |
| 3722 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3723 | sctp_disposition_t sctp_sf_do_asconf_ack(struct net *net, |
| 3724 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | const struct sctp_association *asoc, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3726 | const sctp_subtype_t type, void *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | sctp_cmd_seq_t *commands) |
| 3728 | { |
| 3729 | struct sctp_chunk *asconf_ack = arg; |
| 3730 | struct sctp_chunk *last_asconf = asoc->addip_last_asconf; |
| 3731 | struct sctp_chunk *abort; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3732 | struct sctp_paramhdr *err_param = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | sctp_addiphdr_t *addip_hdr; |
| 3734 | __u32 sent_serial, rcvd_serial; |
| 3735 | |
| 3736 | if (!sctp_vtag_verify(asconf_ack, asoc)) { |
| 3737 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3738 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3739 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3742 | /* ADD-IP, Section 4.1.2: |
| 3743 | * This chunk MUST be sent in an authenticated way by using |
| 3744 | * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk |
| 3745 | * is received unauthenticated it MUST be silently discarded as |
| 3746 | * described in [I-D.ietf-tsvwg-sctp-auth]. |
| 3747 | */ |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 3748 | if (!net->sctp.addip_noauth && !asconf_ack->auth) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3749 | return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | /* Make sure that the ADDIP chunk has a valid length. */ |
| 3752 | if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3753 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | commands); |
| 3755 | |
| 3756 | addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data; |
| 3757 | rcvd_serial = ntohl(addip_hdr->serial); |
| 3758 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3759 | /* Verify the ASCONF-ACK chunk before processing it. */ |
Daniel Borkmann | 9de7922 | 2014-10-09 22:55:31 +0200 | [diff] [blame] | 3760 | if (!sctp_verify_asconf(asoc, asconf_ack, false, &err_param)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3761 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3762 | (void *)err_param, commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3763 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | if (last_asconf) { |
| 3765 | addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr; |
| 3766 | sent_serial = ntohl(addip_hdr->serial); |
| 3767 | } else { |
| 3768 | sent_serial = asoc->addip_serial - 1; |
| 3769 | } |
| 3770 | |
| 3771 | /* D0) If an endpoint receives an ASCONF-ACK that is greater than or |
| 3772 | * equal to the next serial number to be used but no ASCONF chunk is |
| 3773 | * outstanding the endpoint MUST ABORT the association. Note that a |
| 3774 | * sequence number is greater than if it is no more than 2^^31-1 |
| 3775 | * larger than the current sequence number (using serial arithmetic). |
| 3776 | */ |
| 3777 | if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) && |
| 3778 | !(asoc->addip_last_asconf)) { |
| 3779 | abort = sctp_make_abort(asoc, asconf_ack, |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3780 | sizeof(struct sctp_errhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | if (abort) { |
Wei Yongjun | 00f1c2d | 2007-08-21 15:50:01 +0800 | [diff] [blame] | 3782 | sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3783 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3784 | SCTP_CHUNK(abort)); |
| 3785 | } |
| 3786 | /* We are going to ABORT, so we might as well stop |
| 3787 | * processing the rest of the chunks in the packet. |
| 3788 | */ |
| 3789 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3790 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3791 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 3792 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3793 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 3795 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3796 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 3797 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | return SCTP_DISPOSITION_ABORT; |
| 3799 | } |
| 3800 | |
| 3801 | if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) { |
| 3802 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3803 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 3804 | |
| 3805 | if (!sctp_process_asconf_ack((struct sctp_association *)asoc, |
Vlad Yasevich | c078669 | 2010-04-28 08:47:22 +0000 | [diff] [blame] | 3806 | asconf_ack)) { |
| 3807 | /* Successfully processed ASCONF_ACK. We can |
| 3808 | * release the next asconf if we have one. |
| 3809 | */ |
| 3810 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_NEXT_ASCONF, |
| 3811 | SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | return SCTP_DISPOSITION_CONSUME; |
Vlad Yasevich | c078669 | 2010-04-28 08:47:22 +0000 | [diff] [blame] | 3813 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
| 3815 | abort = sctp_make_abort(asoc, asconf_ack, |
Xin Long | d8238d9 | 2017-08-03 15:42:11 +0800 | [diff] [blame] | 3816 | sizeof(struct sctp_errhdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | if (abort) { |
Wei Yongjun | 00f1c2d | 2007-08-21 15:50:01 +0800 | [diff] [blame] | 3818 | sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3820 | SCTP_CHUNK(abort)); |
| 3821 | } |
| 3822 | /* We are going to ABORT, so we might as well stop |
| 3823 | * processing the rest of the chunks in the packet. |
| 3824 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 3825 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 3826 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3827 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 3829 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 3830 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 3831 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | return SCTP_DISPOSITION_ABORT; |
| 3833 | } |
| 3834 | |
| 3835 | return SCTP_DISPOSITION_DISCARD; |
| 3836 | } |
| 3837 | |
Xin Long | 2040d3d | 2017-02-17 12:45:42 +0800 | [diff] [blame] | 3838 | /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */ |
| 3839 | sctp_disposition_t sctp_sf_do_reconf(struct net *net, |
| 3840 | const struct sctp_endpoint *ep, |
| 3841 | const struct sctp_association *asoc, |
| 3842 | const sctp_subtype_t type, void *arg, |
| 3843 | sctp_cmd_seq_t *commands) |
| 3844 | { |
| 3845 | struct sctp_paramhdr *err_param = NULL; |
| 3846 | struct sctp_chunk *chunk = arg; |
| 3847 | struct sctp_reconf_chunk *hdr; |
| 3848 | union sctp_params param; |
| 3849 | |
| 3850 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3851 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3852 | SCTP_NULL()); |
| 3853 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
| 3854 | } |
| 3855 | |
| 3856 | /* Make sure that the RECONF chunk has a valid length. */ |
| 3857 | if (!sctp_chunk_length_valid(chunk, sizeof(*hdr))) |
| 3858 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
| 3859 | commands); |
| 3860 | |
| 3861 | if (!sctp_verify_reconf(asoc, chunk, &err_param)) |
| 3862 | return sctp_sf_violation_paramlen(net, ep, asoc, type, arg, |
| 3863 | (void *)err_param, commands); |
| 3864 | |
| 3865 | hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr; |
| 3866 | sctp_walk_params(param, hdr, params) { |
| 3867 | struct sctp_chunk *reply = NULL; |
| 3868 | struct sctp_ulpevent *ev = NULL; |
| 3869 | |
| 3870 | if (param.p->type == SCTP_PARAM_RESET_OUT_REQUEST) |
| 3871 | reply = sctp_process_strreset_outreq( |
| 3872 | (struct sctp_association *)asoc, param, &ev); |
| 3873 | else if (param.p->type == SCTP_PARAM_RESET_IN_REQUEST) |
| 3874 | reply = sctp_process_strreset_inreq( |
| 3875 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 3876 | else if (param.p->type == SCTP_PARAM_RESET_TSN_REQUEST) |
| 3877 | reply = sctp_process_strreset_tsnreq( |
| 3878 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 3879 | else if (param.p->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) |
| 3880 | reply = sctp_process_strreset_addstrm_out( |
| 3881 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 3882 | else if (param.p->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) |
| 3883 | reply = sctp_process_strreset_addstrm_in( |
| 3884 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 3885 | else if (param.p->type == SCTP_PARAM_RESET_RESPONSE) |
| 3886 | reply = sctp_process_strreset_resp( |
| 3887 | (struct sctp_association *)asoc, param, &ev); |
Xin Long | 2040d3d | 2017-02-17 12:45:42 +0800 | [diff] [blame] | 3888 | |
| 3889 | if (ev) |
| 3890 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 3891 | SCTP_ULPEVENT(ev)); |
| 3892 | |
| 3893 | if (reply) |
| 3894 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3895 | SCTP_CHUNK(reply)); |
| 3896 | } |
| 3897 | |
| 3898 | return SCTP_DISPOSITION_CONSUME; |
| 3899 | } |
| 3900 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | /* |
| 3902 | * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP |
| 3903 | * |
| 3904 | * When a FORWARD TSN chunk arrives, the data receiver MUST first update |
| 3905 | * its cumulative TSN point to the value carried in the FORWARD TSN |
| 3906 | * chunk, and then MUST further advance its cumulative TSN point locally |
| 3907 | * if possible. |
| 3908 | * After the above processing, the data receiver MUST stop reporting any |
| 3909 | * missing TSNs earlier than or equal to the new cumulative TSN point. |
| 3910 | * |
| 3911 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3912 | * |
| 3913 | * The return value is the disposition of the chunk. |
| 3914 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3915 | sctp_disposition_t sctp_sf_eat_fwd_tsn(struct net *net, |
| 3916 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | const struct sctp_association *asoc, |
| 3918 | const sctp_subtype_t type, |
| 3919 | void *arg, |
| 3920 | sctp_cmd_seq_t *commands) |
| 3921 | { |
| 3922 | struct sctp_chunk *chunk = arg; |
| 3923 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3924 | struct sctp_fwdtsn_skip *skip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | __u16 len; |
| 3926 | __u32 tsn; |
| 3927 | |
| 3928 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3929 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3930 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3931 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | } |
| 3933 | |
Xin Long | d15c9ed | 2017-02-03 17:37:06 +0800 | [diff] [blame] | 3934 | if (!asoc->peer.prsctp_capable) |
| 3935 | return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands); |
| 3936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | /* Make sure that the FORWARD_TSN chunk has valid length. */ |
| 3938 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3939 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | commands); |
| 3941 | |
| 3942 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; |
| 3943 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; |
| 3944 | len = ntohs(chunk->chunk_hdr->length); |
| 3945 | len -= sizeof(struct sctp_chunkhdr); |
| 3946 | skb_pull(chunk->skb, len); |
| 3947 | |
| 3948 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 3949 | pr_debug("%s: TSN 0x%x\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | |
| 3951 | /* The TSN is too high--silently discard the chunk and count on it |
| 3952 | * getting retransmitted later. |
| 3953 | */ |
| 3954 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) |
| 3955 | goto discard_noforce; |
| 3956 | |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3957 | /* Silently discard the chunk if stream-id is not valid */ |
| 3958 | sctp_walk_fwdtsn(skip, chunk) { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 3959 | if (ntohs(skip->stream) >= asoc->stream.incnt) |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3960 | goto discard_noforce; |
| 3961 | } |
| 3962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); |
| 3964 | if (len > sizeof(struct sctp_fwdtsn_hdr)) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3965 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | SCTP_CHUNK(chunk)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3968 | /* Count this as receiving DATA. */ |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 3969 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3971 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 3972 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | /* FIXME: For now send a SACK, but DATA processing may |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3975 | * send another. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3976 | */ |
| 3977 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | |
| 3979 | return SCTP_DISPOSITION_CONSUME; |
| 3980 | |
| 3981 | discard_noforce: |
| 3982 | return SCTP_DISPOSITION_DISCARD; |
| 3983 | } |
| 3984 | |
| 3985 | sctp_disposition_t sctp_sf_eat_fwd_tsn_fast( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 3986 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | const struct sctp_endpoint *ep, |
| 3988 | const struct sctp_association *asoc, |
| 3989 | const sctp_subtype_t type, |
| 3990 | void *arg, |
| 3991 | sctp_cmd_seq_t *commands) |
| 3992 | { |
| 3993 | struct sctp_chunk *chunk = arg; |
| 3994 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3995 | struct sctp_fwdtsn_skip *skip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | __u16 len; |
| 3997 | __u32 tsn; |
| 3998 | |
| 3999 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 4000 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 4001 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4002 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | } |
| 4004 | |
Xin Long | d15c9ed | 2017-02-03 17:37:06 +0800 | [diff] [blame] | 4005 | if (!asoc->peer.prsctp_capable) |
| 4006 | return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands); |
| 4007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | /* Make sure that the FORWARD_TSN chunk has a valid length. */ |
| 4009 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4010 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | commands); |
| 4012 | |
| 4013 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; |
| 4014 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; |
| 4015 | len = ntohs(chunk->chunk_hdr->length); |
| 4016 | len -= sizeof(struct sctp_chunkhdr); |
| 4017 | skb_pull(chunk->skb, len); |
| 4018 | |
| 4019 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4020 | pr_debug("%s: TSN 0x%x\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | |
| 4022 | /* The TSN is too high--silently discard the chunk and count on it |
| 4023 | * getting retransmitted later. |
| 4024 | */ |
| 4025 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) |
| 4026 | goto gen_shutdown; |
| 4027 | |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 4028 | /* Silently discard the chunk if stream-id is not valid */ |
| 4029 | sctp_walk_fwdtsn(skip, chunk) { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 4030 | if (ntohs(skip->stream) >= asoc->stream.incnt) |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 4031 | goto gen_shutdown; |
| 4032 | } |
| 4033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); |
| 4035 | if (len > sizeof(struct sctp_fwdtsn_hdr)) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4036 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | SCTP_CHUNK(chunk)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | /* Go a head and force a SACK, since we are shutting down. */ |
| 4040 | gen_shutdown: |
| 4041 | /* Implementor's Guide. |
| 4042 | * |
| 4043 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately |
| 4044 | * respond to each received packet containing one or more DATA chunk(s) |
| 4045 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer |
| 4046 | */ |
| 4047 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); |
| 4048 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 4049 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 4050 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 4051 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4052 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4056 | * SCTP-AUTH Section 6.3 Receiving authenticated chukns |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4057 | * |
| 4058 | * The receiver MUST use the HMAC algorithm indicated in the HMAC |
| 4059 | * Identifier field. If this algorithm was not specified by the |
| 4060 | * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk |
| 4061 | * during association setup, the AUTH chunk and all chunks after it MUST |
| 4062 | * be discarded and an ERROR chunk SHOULD be sent with the error cause |
| 4063 | * defined in Section 4.1. |
| 4064 | * |
| 4065 | * If an endpoint with no shared key receives a Shared Key Identifier |
| 4066 | * other than 0, it MUST silently discard all authenticated chunks. If |
| 4067 | * the endpoint has at least one endpoint pair shared key for the peer, |
| 4068 | * it MUST use the key specified by the Shared Key Identifier if a |
| 4069 | * key has been configured for that Shared Key Identifier. If no |
| 4070 | * endpoint pair shared key has been configured for that Shared Key |
| 4071 | * Identifier, all authenticated chunks MUST be silently discarded. |
| 4072 | * |
| 4073 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 4074 | * |
| 4075 | * The return value is the disposition of the chunk. |
| 4076 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4077 | static sctp_ierror_t sctp_sf_authenticate(struct net *net, |
| 4078 | const struct sctp_endpoint *ep, |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4079 | const struct sctp_association *asoc, |
| 4080 | const sctp_subtype_t type, |
| 4081 | struct sctp_chunk *chunk) |
| 4082 | { |
| 4083 | struct sctp_authhdr *auth_hdr; |
| 4084 | struct sctp_hmac *hmac; |
| 4085 | unsigned int sig_len; |
| 4086 | __u16 key_id; |
| 4087 | __u8 *save_digest; |
| 4088 | __u8 *digest; |
| 4089 | |
| 4090 | /* Pull in the auth header, so we can do some more verification */ |
| 4091 | auth_hdr = (struct sctp_authhdr *)chunk->skb->data; |
| 4092 | chunk->subh.auth_hdr = auth_hdr; |
| 4093 | skb_pull(chunk->skb, sizeof(struct sctp_authhdr)); |
| 4094 | |
Masanari Iida | 02582e9 | 2012-08-22 19:11:26 +0900 | [diff] [blame] | 4095 | /* Make sure that we support the HMAC algorithm from the auth |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4096 | * chunk. |
| 4097 | */ |
| 4098 | if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id)) |
| 4099 | return SCTP_IERROR_AUTH_BAD_HMAC; |
| 4100 | |
| 4101 | /* Make sure that the provided shared key identifier has been |
| 4102 | * configured |
| 4103 | */ |
| 4104 | key_id = ntohs(auth_hdr->shkey_id); |
| 4105 | if (key_id != asoc->active_key_id && !sctp_auth_get_shkey(asoc, key_id)) |
| 4106 | return SCTP_IERROR_AUTH_BAD_KEYID; |
| 4107 | |
| 4108 | |
| 4109 | /* Make sure that the length of the signature matches what |
| 4110 | * we expect. |
| 4111 | */ |
| 4112 | sig_len = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_auth_chunk_t); |
| 4113 | hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id)); |
| 4114 | if (sig_len != hmac->hmac_len) |
| 4115 | return SCTP_IERROR_PROTO_VIOLATION; |
| 4116 | |
| 4117 | /* Now that we've done validation checks, we can compute and |
| 4118 | * verify the hmac. The steps involved are: |
| 4119 | * 1. Save the digest from the chunk. |
| 4120 | * 2. Zero out the digest in the chunk. |
| 4121 | * 3. Compute the new digest |
| 4122 | * 4. Compare saved and new digests. |
| 4123 | */ |
| 4124 | digest = auth_hdr->hmac; |
| 4125 | skb_pull(chunk->skb, sig_len); |
| 4126 | |
| 4127 | save_digest = kmemdup(digest, sig_len, GFP_ATOMIC); |
| 4128 | if (!save_digest) |
| 4129 | goto nomem; |
| 4130 | |
| 4131 | memset(digest, 0, sig_len); |
| 4132 | |
| 4133 | sctp_auth_calculate_hmac(asoc, chunk->skb, |
| 4134 | (struct sctp_auth_chunk *)chunk->chunk_hdr, |
| 4135 | GFP_ATOMIC); |
| 4136 | |
| 4137 | /* Discard the packet if the digests do not match */ |
| 4138 | if (memcmp(save_digest, digest, sig_len)) { |
| 4139 | kfree(save_digest); |
| 4140 | return SCTP_IERROR_BAD_SIG; |
| 4141 | } |
| 4142 | |
| 4143 | kfree(save_digest); |
| 4144 | chunk->auth = 1; |
| 4145 | |
| 4146 | return SCTP_IERROR_NO_ERROR; |
| 4147 | nomem: |
| 4148 | return SCTP_IERROR_NOMEM; |
| 4149 | } |
| 4150 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4151 | sctp_disposition_t sctp_sf_eat_auth(struct net *net, |
| 4152 | const struct sctp_endpoint *ep, |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4153 | const struct sctp_association *asoc, |
| 4154 | const sctp_subtype_t type, |
| 4155 | void *arg, |
| 4156 | sctp_cmd_seq_t *commands) |
| 4157 | { |
| 4158 | struct sctp_authhdr *auth_hdr; |
| 4159 | struct sctp_chunk *chunk = arg; |
| 4160 | struct sctp_chunk *err_chunk; |
| 4161 | sctp_ierror_t error; |
| 4162 | |
Wei Yongjun | d2f19fa | 2008-02-05 03:02:26 -0800 | [diff] [blame] | 4163 | /* Make sure that the peer has AUTH capable */ |
| 4164 | if (!asoc->peer.auth_capable) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4165 | return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands); |
Wei Yongjun | d2f19fa | 2008-02-05 03:02:26 -0800 | [diff] [blame] | 4166 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4167 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 4168 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 4169 | SCTP_NULL()); |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4170 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | /* Make sure that the AUTH chunk has valid length. */ |
| 4174 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4175 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4176 | commands); |
| 4177 | |
| 4178 | auth_hdr = (struct sctp_authhdr *)chunk->skb->data; |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4179 | error = sctp_sf_authenticate(net, ep, asoc, type, chunk); |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4180 | switch (error) { |
Joe Perches | 7fd71b1 | 2011-07-01 09:43:11 +0000 | [diff] [blame] | 4181 | case SCTP_IERROR_AUTH_BAD_HMAC: |
| 4182 | /* Generate the ERROR chunk and discard the rest |
| 4183 | * of the packet |
| 4184 | */ |
| 4185 | err_chunk = sctp_make_op_error(asoc, chunk, |
| 4186 | SCTP_ERROR_UNSUP_HMAC, |
| 4187 | &auth_hdr->hmac_id, |
| 4188 | sizeof(__u16), 0); |
| 4189 | if (err_chunk) { |
| 4190 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4191 | SCTP_CHUNK(err_chunk)); |
| 4192 | } |
| 4193 | /* Fall Through */ |
| 4194 | case SCTP_IERROR_AUTH_BAD_KEYID: |
| 4195 | case SCTP_IERROR_BAD_SIG: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4196 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Joe Perches | 7fd71b1 | 2011-07-01 09:43:11 +0000 | [diff] [blame] | 4197 | |
| 4198 | case SCTP_IERROR_PROTO_VIOLATION: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4199 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Joe Perches | 7fd71b1 | 2011-07-01 09:43:11 +0000 | [diff] [blame] | 4200 | commands); |
| 4201 | |
| 4202 | case SCTP_IERROR_NOMEM: |
| 4203 | return SCTP_DISPOSITION_NOMEM; |
| 4204 | |
| 4205 | default: /* Prevent gcc warnings */ |
| 4206 | break; |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
Vlad Yasevich | 65b07e5 | 2007-09-16 19:34:00 -0700 | [diff] [blame] | 4209 | if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) { |
| 4210 | struct sctp_ulpevent *ev; |
| 4211 | |
| 4212 | ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id), |
| 4213 | SCTP_AUTH_NEWKEY, GFP_ATOMIC); |
| 4214 | |
| 4215 | if (!ev) |
| 4216 | return -ENOMEM; |
| 4217 | |
| 4218 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 4219 | SCTP_ULPEVENT(ev)); |
| 4220 | } |
| 4221 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4222 | return SCTP_DISPOSITION_CONSUME; |
| 4223 | } |
| 4224 | |
| 4225 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | * Process an unknown chunk. |
| 4227 | * |
| 4228 | * Section: 3.2. Also, 2.1 in the implementor's guide. |
| 4229 | * |
| 4230 | * Chunk Types are encoded such that the highest-order two bits specify |
| 4231 | * the action that must be taken if the processing endpoint does not |
| 4232 | * recognize the Chunk Type. |
| 4233 | * |
| 4234 | * 00 - Stop processing this SCTP packet and discard it, do not process |
| 4235 | * any further chunks within it. |
| 4236 | * |
| 4237 | * 01 - Stop processing this SCTP packet and discard it, do not process |
| 4238 | * any further chunks within it, and report the unrecognized |
| 4239 | * chunk in an 'Unrecognized Chunk Type'. |
| 4240 | * |
| 4241 | * 10 - Skip this chunk and continue processing. |
| 4242 | * |
| 4243 | * 11 - Skip this chunk and continue processing, but report in an ERROR |
| 4244 | * Chunk using the 'Unrecognized Chunk Type' cause of error. |
| 4245 | * |
| 4246 | * The return value is the disposition of the chunk. |
| 4247 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4248 | sctp_disposition_t sctp_sf_unk_chunk(struct net *net, |
| 4249 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4250 | const struct sctp_association *asoc, |
| 4251 | const sctp_subtype_t type, |
| 4252 | void *arg, |
| 4253 | sctp_cmd_seq_t *commands) |
| 4254 | { |
| 4255 | struct sctp_chunk *unk_chunk = arg; |
| 4256 | struct sctp_chunk *err_chunk; |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4257 | struct sctp_chunkhdr *hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4259 | pr_debug("%s: processing unknown chunk id:%d\n", __func__, type.chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
| 4261 | if (!sctp_vtag_verify(unk_chunk, asoc)) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4262 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | |
| 4264 | /* Make sure that the chunk has a valid length. |
| 4265 | * Since we don't know the chunk type, we use a general |
| 4266 | * chunkhdr structure to make a comparison. |
| 4267 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4268 | if (!sctp_chunk_length_valid(unk_chunk, sizeof(*hdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4269 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4270 | commands); |
| 4271 | |
| 4272 | switch (type.chunk & SCTP_CID_ACTION_MASK) { |
| 4273 | case SCTP_CID_ACTION_DISCARD: |
| 4274 | /* Discard the packet. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4275 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | case SCTP_CID_ACTION_DISCARD_ERR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | /* Generate an ERROR chunk as response. */ |
| 4278 | hdr = unk_chunk->chunk_hdr; |
| 4279 | err_chunk = sctp_make_op_error(asoc, unk_chunk, |
| 4280 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, |
Marcelo Ricardo Leitner | e2f036a | 2016-09-21 08:45:55 -0300 | [diff] [blame] | 4281 | SCTP_PAD4(ntohs(hdr->length)), |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 4282 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4283 | if (err_chunk) { |
| 4284 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4285 | SCTP_CHUNK(err_chunk)); |
| 4286 | } |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 4287 | |
| 4288 | /* Discard the packet. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4289 | sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | case SCTP_CID_ACTION_SKIP: |
| 4292 | /* Skip the chunk. */ |
| 4293 | return SCTP_DISPOSITION_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | case SCTP_CID_ACTION_SKIP_ERR: |
| 4295 | /* Generate an ERROR chunk as response. */ |
| 4296 | hdr = unk_chunk->chunk_hdr; |
| 4297 | err_chunk = sctp_make_op_error(asoc, unk_chunk, |
| 4298 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, |
Marcelo Ricardo Leitner | e2f036a | 2016-09-21 08:45:55 -0300 | [diff] [blame] | 4299 | SCTP_PAD4(ntohs(hdr->length)), |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 4300 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | if (err_chunk) { |
| 4302 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4303 | SCTP_CHUNK(err_chunk)); |
| 4304 | } |
| 4305 | /* Skip the chunk. */ |
| 4306 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | default: |
| 4308 | break; |
| 4309 | } |
| 4310 | |
| 4311 | return SCTP_DISPOSITION_DISCARD; |
| 4312 | } |
| 4313 | |
| 4314 | /* |
| 4315 | * Discard the chunk. |
| 4316 | * |
| 4317 | * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2 |
| 4318 | * [Too numerous to mention...] |
| 4319 | * Verification Tag: No verification needed. |
| 4320 | * Inputs |
| 4321 | * (endpoint, asoc, chunk) |
| 4322 | * |
| 4323 | * Outputs |
| 4324 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4325 | * |
| 4326 | * The return value is the disposition of the chunk. |
| 4327 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4328 | sctp_disposition_t sctp_sf_discard_chunk(struct net *net, |
| 4329 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4330 | const struct sctp_association *asoc, |
| 4331 | const sctp_subtype_t type, |
| 4332 | void *arg, |
| 4333 | sctp_cmd_seq_t *commands) |
| 4334 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4335 | struct sctp_chunk *chunk = arg; |
| 4336 | |
| 4337 | /* Make sure that the chunk has a valid length. |
| 4338 | * Since we don't know the chunk type, we use a general |
| 4339 | * chunkhdr structure to make a comparison. |
| 4340 | */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4341 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4342 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4343 | commands); |
| 4344 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 4345 | pr_debug("%s: chunk:%d is discarded\n", __func__, type.chunk); |
| 4346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | return SCTP_DISPOSITION_DISCARD; |
| 4348 | } |
| 4349 | |
| 4350 | /* |
| 4351 | * Discard the whole packet. |
| 4352 | * |
| 4353 | * Section: 8.4 2) |
| 4354 | * |
| 4355 | * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST |
| 4356 | * silently discard the OOTB packet and take no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | * |
| 4358 | * Verification Tag: No verification necessary |
| 4359 | * |
| 4360 | * Inputs |
| 4361 | * (endpoint, asoc, chunk) |
| 4362 | * |
| 4363 | * Outputs |
| 4364 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4365 | * |
| 4366 | * The return value is the disposition of the chunk. |
| 4367 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4368 | sctp_disposition_t sctp_sf_pdiscard(struct net *net, |
| 4369 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | const struct sctp_association *asoc, |
| 4371 | const sctp_subtype_t type, |
| 4372 | void *arg, |
| 4373 | sctp_cmd_seq_t *commands) |
| 4374 | { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4375 | SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
| 4377 | |
| 4378 | return SCTP_DISPOSITION_CONSUME; |
| 4379 | } |
| 4380 | |
| 4381 | |
| 4382 | /* |
| 4383 | * The other end is violating protocol. |
| 4384 | * |
| 4385 | * Section: Not specified |
| 4386 | * Verification Tag: Not specified |
| 4387 | * Inputs |
| 4388 | * (endpoint, asoc, chunk) |
| 4389 | * |
| 4390 | * Outputs |
| 4391 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4392 | * |
| 4393 | * We simply tag the chunk as a violation. The state machine will log |
| 4394 | * the violation and continue. |
| 4395 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4396 | sctp_disposition_t sctp_sf_violation(struct net *net, |
| 4397 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | const struct sctp_association *asoc, |
| 4399 | const sctp_subtype_t type, |
| 4400 | void *arg, |
| 4401 | sctp_cmd_seq_t *commands) |
| 4402 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4403 | struct sctp_chunk *chunk = arg; |
| 4404 | |
| 4405 | /* Make sure that the chunk has a valid length. */ |
Xin Long | 922dbc5 | 2017-06-30 11:52:13 +0800 | [diff] [blame] | 4406 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4407 | return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4408 | commands); |
| 4409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | return SCTP_DISPOSITION_VIOLATION; |
| 4411 | } |
| 4412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | /* |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4414 | * Common function to handle a protocol violation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | */ |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4416 | static sctp_disposition_t sctp_sf_abort_violation( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4417 | struct net *net, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4418 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4419 | const struct sctp_association *asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | void *arg, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4421 | sctp_cmd_seq_t *commands, |
| 4422 | const __u8 *payload, |
| 4423 | const size_t paylen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4425 | struct sctp_packet *packet = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | struct sctp_chunk *chunk = arg; |
| 4427 | struct sctp_chunk *abort = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4429 | /* SCTP-AUTH, Section 6.3: |
| 4430 | * It should be noted that if the receiver wants to tear |
| 4431 | * down an association in an authenticated way only, the |
| 4432 | * handling of malformed packets should not result in |
| 4433 | * tearing down the association. |
| 4434 | * |
| 4435 | * This means that if we only want to abort associations |
| 4436 | * in an authenticated way (i.e AUTH+ABORT), then we |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4437 | * can't destroy this association just because the packet |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4438 | * was malformed. |
| 4439 | */ |
| 4440 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 4441 | goto discard; |
| 4442 | |
Jesper Juhl | 9abed24 | 2007-11-11 23:57:49 +0100 | [diff] [blame] | 4443 | /* Make the abort chunk. */ |
| 4444 | abort = sctp_make_abort_violation(asoc, chunk, payload, paylen); |
| 4445 | if (!abort) |
| 4446 | goto nomem; |
| 4447 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4448 | if (asoc) { |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4449 | /* Treat INIT-ACK as a special case during COOKIE-WAIT. */ |
| 4450 | if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK && |
| 4451 | !asoc->peer.i.init_tag) { |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 4452 | struct sctp_initack_chunk *initack; |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4453 | |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 4454 | initack = (struct sctp_initack_chunk *)chunk->chunk_hdr; |
| 4455 | if (!sctp_chunk_length_valid(chunk, sizeof(*initack))) |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4456 | abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T; |
| 4457 | else { |
| 4458 | unsigned int inittag; |
| 4459 | |
| 4460 | inittag = ntohl(initack->init_hdr.init_tag); |
| 4461 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG, |
| 4462 | SCTP_U32(inittag)); |
| 4463 | } |
| 4464 | } |
| 4465 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4466 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4467 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4469 | if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) { |
| 4470 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4471 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4472 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4473 | SCTP_ERROR(ECONNREFUSED)); |
| 4474 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
| 4475 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
| 4476 | } else { |
| 4477 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4478 | SCTP_ERROR(ECONNABORTED)); |
| 4479 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 4480 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4481 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4482 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | } else { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 4484 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4485 | |
| 4486 | if (!packet) |
| 4487 | goto nomem_pkt; |
| 4488 | |
| 4489 | if (sctp_test_T_bit(abort)) |
| 4490 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 4491 | |
| 4492 | abort->skb->sk = ep->base.sk; |
| 4493 | |
| 4494 | sctp_packet_append_chunk(packet, abort); |
| 4495 | |
| 4496 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 4497 | SCTP_PACKET(packet)); |
| 4498 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4499 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4502 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4503 | |
Vlad Yasevich | 56eb82b | 2008-10-09 14:33:01 -0700 | [diff] [blame] | 4504 | discard: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4505 | sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | return SCTP_DISPOSITION_ABORT; |
| 4507 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4508 | nomem_pkt: |
| 4509 | sctp_chunk_free(abort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | nomem: |
| 4511 | return SCTP_DISPOSITION_NOMEM; |
| 4512 | } |
| 4513 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4514 | /* |
| 4515 | * Handle a protocol violation when the chunk length is invalid. |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4516 | * "Invalid" length is identified as smaller than the minimal length a |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4517 | * given chunk can be. For example, a SACK chunk has invalid length |
Xin Long | d4d6c61 | 2017-07-23 09:34:33 +0800 | [diff] [blame] | 4518 | * if its length is set to be smaller than the size of struct sctp_sack_chunk. |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4519 | * |
| 4520 | * We inform the other end by sending an ABORT with a Protocol Violation |
| 4521 | * error code. |
| 4522 | * |
| 4523 | * Section: Not specified |
| 4524 | * Verification Tag: Nothing to do |
| 4525 | * Inputs |
| 4526 | * (endpoint, asoc, chunk) |
| 4527 | * |
| 4528 | * Outputs |
| 4529 | * (reply_msg, msg_up, counters) |
| 4530 | * |
| 4531 | * Generate an ABORT chunk and terminate the association. |
| 4532 | */ |
| 4533 | static sctp_disposition_t sctp_sf_violation_chunklen( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4534 | struct net *net, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4535 | const struct sctp_endpoint *ep, |
| 4536 | const struct sctp_association *asoc, |
| 4537 | const sctp_subtype_t type, |
| 4538 | void *arg, |
| 4539 | sctp_cmd_seq_t *commands) |
| 4540 | { |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 4541 | static const char err_str[] = "The following chunk had invalid length:"; |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4542 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4543 | return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4544 | sizeof(err_str)); |
| 4545 | } |
| 4546 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4547 | /* |
| 4548 | * Handle a protocol violation when the parameter length is invalid. |
Shan Wei | 33c7cfd | 2011-04-18 19:11:01 +0000 | [diff] [blame] | 4549 | * If the length is smaller than the minimum length of a given parameter, |
| 4550 | * or accumulated length in multi parameters exceeds the end of the chunk, |
| 4551 | * the length is considered as invalid. |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4552 | */ |
| 4553 | static sctp_disposition_t sctp_sf_violation_paramlen( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4554 | struct net *net, |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4555 | const struct sctp_endpoint *ep, |
| 4556 | const struct sctp_association *asoc, |
| 4557 | const sctp_subtype_t type, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4558 | void *arg, void *ext, |
| 4559 | sctp_cmd_seq_t *commands) |
| 4560 | { |
| 4561 | struct sctp_chunk *chunk = arg; |
| 4562 | struct sctp_paramhdr *param = ext; |
| 4563 | struct sctp_chunk *abort = NULL; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4564 | |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4565 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 4566 | goto discard; |
| 4567 | |
| 4568 | /* Make the abort chunk. */ |
| 4569 | abort = sctp_make_violation_paramlen(asoc, chunk, param); |
| 4570 | if (!abort) |
| 4571 | goto nomem; |
| 4572 | |
| 4573 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4574 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4575 | |
| 4576 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4577 | SCTP_ERROR(ECONNABORTED)); |
| 4578 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 4579 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4580 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
| 4581 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4582 | |
| 4583 | discard: |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4584 | sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4585 | return SCTP_DISPOSITION_ABORT; |
| 4586 | nomem: |
| 4587 | return SCTP_DISPOSITION_NOMEM; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4588 | } |
| 4589 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4590 | /* Handle a protocol violation when the peer trying to advance the |
| 4591 | * cumulative tsn ack to a point beyond the max tsn currently sent. |
| 4592 | * |
| 4593 | * We inform the other end by sending an ABORT with a Protocol Violation |
| 4594 | * error code. |
| 4595 | */ |
| 4596 | static sctp_disposition_t sctp_sf_violation_ctsn( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4597 | struct net *net, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4598 | const struct sctp_endpoint *ep, |
| 4599 | const struct sctp_association *asoc, |
| 4600 | const sctp_subtype_t type, |
| 4601 | void *arg, |
| 4602 | sctp_cmd_seq_t *commands) |
| 4603 | { |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 4604 | static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:"; |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4605 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4606 | return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4607 | sizeof(err_str)); |
| 4608 | } |
| 4609 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4610 | /* Handle protocol violation of an invalid chunk bundling. For example, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4611 | * when we have an association and we receive bundled INIT-ACK, or |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4612 | * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle" |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4613 | * statement from the specs. Additionally, there might be an attacker |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4614 | * on the path and we may not want to continue this communication. |
| 4615 | */ |
| 4616 | static sctp_disposition_t sctp_sf_violation_chunk( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4617 | struct net *net, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4618 | const struct sctp_endpoint *ep, |
| 4619 | const struct sctp_association *asoc, |
| 4620 | const sctp_subtype_t type, |
| 4621 | void *arg, |
| 4622 | sctp_cmd_seq_t *commands) |
| 4623 | { |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 4624 | static const char err_str[] = "The following chunk violates protocol:"; |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4625 | |
| 4626 | if (!asoc) |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4627 | return sctp_sf_violation(net, ep, asoc, type, arg, commands); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4628 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4629 | return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str, |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4630 | sizeof(err_str)); |
| 4631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | /*************************************************************************** |
| 4633 | * These are the state functions for handling primitive (Section 10) events. |
| 4634 | ***************************************************************************/ |
| 4635 | /* |
| 4636 | * sctp_sf_do_prm_asoc |
| 4637 | * |
| 4638 | * Section: 10.1 ULP-to-SCTP |
| 4639 | * B) Associate |
| 4640 | * |
| 4641 | * Format: ASSOCIATE(local SCTP instance name, destination transport addr, |
| 4642 | * outbound stream count) |
| 4643 | * -> association id [,destination transport addr list] [,outbound stream |
| 4644 | * count] |
| 4645 | * |
| 4646 | * This primitive allows the upper layer to initiate an association to a |
| 4647 | * specific peer endpoint. |
| 4648 | * |
| 4649 | * The peer endpoint shall be specified by one of the transport addresses |
| 4650 | * which defines the endpoint (see Section 1.4). If the local SCTP |
| 4651 | * instance has not been initialized, the ASSOCIATE is considered an |
| 4652 | * error. |
| 4653 | * [This is not relevant for the kernel implementation since we do all |
| 4654 | * initialization at boot time. It we hadn't initialized we wouldn't |
| 4655 | * get anywhere near this code.] |
| 4656 | * |
| 4657 | * An association id, which is a local handle to the SCTP association, |
| 4658 | * will be returned on successful establishment of the association. If |
| 4659 | * SCTP is not able to open an SCTP association with the peer endpoint, |
| 4660 | * an error is returned. |
| 4661 | * [In the kernel implementation, the struct sctp_association needs to |
| 4662 | * be created BEFORE causing this primitive to run.] |
| 4663 | * |
| 4664 | * Other association parameters may be returned, including the |
| 4665 | * complete destination transport addresses of the peer as well as the |
| 4666 | * outbound stream count of the local endpoint. One of the transport |
| 4667 | * address from the returned destination addresses will be selected by |
| 4668 | * the local endpoint as default primary path for sending SCTP packets |
| 4669 | * to this peer. The returned "destination transport addr list" can |
| 4670 | * be used by the ULP to change the default primary path or to force |
| 4671 | * sending a packet to a specific transport address. [All of this |
| 4672 | * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING |
| 4673 | * function.] |
| 4674 | * |
| 4675 | * Mandatory attributes: |
| 4676 | * |
| 4677 | * o local SCTP instance name - obtained from the INITIALIZE operation. |
| 4678 | * [This is the argument asoc.] |
| 4679 | * o destination transport addr - specified as one of the transport |
| 4680 | * addresses of the peer endpoint with which the association is to be |
| 4681 | * established. |
| 4682 | * [This is asoc->peer.active_path.] |
| 4683 | * o outbound stream count - the number of outbound streams the ULP |
| 4684 | * would like to open towards this peer endpoint. |
| 4685 | * [BUG: This is not currently implemented.] |
| 4686 | * Optional attributes: |
| 4687 | * |
| 4688 | * None. |
| 4689 | * |
| 4690 | * The return value is a disposition. |
| 4691 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4692 | sctp_disposition_t sctp_sf_do_prm_asoc(struct net *net, |
| 4693 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | const struct sctp_association *asoc, |
| 4695 | const sctp_subtype_t type, |
| 4696 | void *arg, |
| 4697 | sctp_cmd_seq_t *commands) |
| 4698 | { |
| 4699 | struct sctp_chunk *repl; |
wangweidong | 26ac8e5 | 2013-12-23 12:16:51 +0800 | [diff] [blame] | 4700 | struct sctp_association *my_asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4701 | |
| 4702 | /* The comment below says that we enter COOKIE-WAIT AFTER |
| 4703 | * sending the INIT, but that doesn't actually work in our |
| 4704 | * implementation... |
| 4705 | */ |
| 4706 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4707 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); |
| 4708 | |
| 4709 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 4710 | * |
| 4711 | * A) "A" first sends an INIT chunk to "Z". In the INIT, "A" |
| 4712 | * must provide its Verification Tag (Tag_A) in the Initiate |
| 4713 | * Tag field. Tag_A SHOULD be a random number in the range of |
| 4714 | * 1 to 4294967295 (see 5.3.1 for Tag value selection). ... |
| 4715 | */ |
| 4716 | |
| 4717 | repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0); |
| 4718 | if (!repl) |
| 4719 | goto nomem; |
| 4720 | |
Daniel Borkmann | 405426f | 2013-06-14 18:24:05 +0200 | [diff] [blame] | 4721 | /* Choose transport for INIT. */ |
| 4722 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 4723 | SCTP_CHUNK(repl)); |
| 4724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4725 | /* Cast away the const modifier, as we want to just |
| 4726 | * rerun it through as a sideffect. |
| 4727 | */ |
Vlad Yasevich | ab38fb0 | 2008-04-12 18:40:06 -0700 | [diff] [blame] | 4728 | my_asoc = (struct sctp_association *)asoc; |
| 4729 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | |
| 4731 | /* After sending the INIT, "A" starts the T1-init timer and |
| 4732 | * enters the COOKIE-WAIT state. |
| 4733 | */ |
| 4734 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 4735 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4736 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 4737 | return SCTP_DISPOSITION_CONSUME; |
| 4738 | |
| 4739 | nomem: |
| 4740 | return SCTP_DISPOSITION_NOMEM; |
| 4741 | } |
| 4742 | |
| 4743 | /* |
| 4744 | * Process the SEND primitive. |
| 4745 | * |
| 4746 | * Section: 10.1 ULP-to-SCTP |
| 4747 | * E) Send |
| 4748 | * |
| 4749 | * Format: SEND(association id, buffer address, byte count [,context] |
| 4750 | * [,stream id] [,life time] [,destination transport address] |
| 4751 | * [,unorder flag] [,no-bundle flag] [,payload protocol-id] ) |
| 4752 | * -> result |
| 4753 | * |
| 4754 | * This is the main method to send user data via SCTP. |
| 4755 | * |
| 4756 | * Mandatory attributes: |
| 4757 | * |
| 4758 | * o association id - local handle to the SCTP association |
| 4759 | * |
| 4760 | * o buffer address - the location where the user message to be |
| 4761 | * transmitted is stored; |
| 4762 | * |
| 4763 | * o byte count - The size of the user data in number of bytes; |
| 4764 | * |
| 4765 | * Optional attributes: |
| 4766 | * |
| 4767 | * o context - an optional 32 bit integer that will be carried in the |
| 4768 | * sending failure notification to the ULP if the transportation of |
| 4769 | * this User Message fails. |
| 4770 | * |
| 4771 | * o stream id - to indicate which stream to send the data on. If not |
| 4772 | * specified, stream 0 will be used. |
| 4773 | * |
| 4774 | * o life time - specifies the life time of the user data. The user data |
| 4775 | * will not be sent by SCTP after the life time expires. This |
| 4776 | * parameter can be used to avoid efforts to transmit stale |
| 4777 | * user messages. SCTP notifies the ULP if the data cannot be |
| 4778 | * initiated to transport (i.e. sent to the destination via SCTP's |
| 4779 | * send primitive) within the life time variable. However, the |
| 4780 | * user data will be transmitted if SCTP has attempted to transmit a |
| 4781 | * chunk before the life time expired. |
| 4782 | * |
| 4783 | * o destination transport address - specified as one of the destination |
| 4784 | * transport addresses of the peer endpoint to which this packet |
| 4785 | * should be sent. Whenever possible, SCTP should use this destination |
| 4786 | * transport address for sending the packets, instead of the current |
| 4787 | * primary path. |
| 4788 | * |
| 4789 | * o unorder flag - this flag, if present, indicates that the user |
| 4790 | * would like the data delivered in an unordered fashion to the peer |
| 4791 | * (i.e., the U flag is set to 1 on all DATA chunks carrying this |
| 4792 | * message). |
| 4793 | * |
| 4794 | * o no-bundle flag - instructs SCTP not to bundle this user data with |
| 4795 | * other outbound DATA chunks. SCTP MAY still bundle even when |
| 4796 | * this flag is present, when faced with network congestion. |
| 4797 | * |
| 4798 | * o payload protocol-id - A 32 bit unsigned integer that is to be |
| 4799 | * passed to the peer indicating the type of payload protocol data |
| 4800 | * being transmitted. This value is passed as opaque data by SCTP. |
| 4801 | * |
| 4802 | * The return value is the disposition. |
| 4803 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4804 | sctp_disposition_t sctp_sf_do_prm_send(struct net *net, |
| 4805 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4806 | const struct sctp_association *asoc, |
| 4807 | const sctp_subtype_t type, |
| 4808 | void *arg, |
| 4809 | sctp_cmd_seq_t *commands) |
| 4810 | { |
Vlad Yasevich | 9c5c62b | 2009-08-10 13:51:03 -0400 | [diff] [blame] | 4811 | struct sctp_datamsg *msg = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | |
Vlad Yasevich | 9c5c62b | 2009-08-10 13:51:03 -0400 | [diff] [blame] | 4813 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_MSG, SCTP_DATAMSG(msg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | return SCTP_DISPOSITION_CONSUME; |
| 4815 | } |
| 4816 | |
| 4817 | /* |
| 4818 | * Process the SHUTDOWN primitive. |
| 4819 | * |
| 4820 | * Section: 10.1: |
| 4821 | * C) Shutdown |
| 4822 | * |
| 4823 | * Format: SHUTDOWN(association id) |
| 4824 | * -> result |
| 4825 | * |
| 4826 | * Gracefully closes an association. Any locally queued user data |
| 4827 | * will be delivered to the peer. The association will be terminated only |
| 4828 | * after the peer acknowledges all the SCTP packets sent. A success code |
| 4829 | * will be returned on successful termination of the association. If |
| 4830 | * attempting to terminate the association results in a failure, an error |
| 4831 | * code shall be returned. |
| 4832 | * |
| 4833 | * Mandatory attributes: |
| 4834 | * |
| 4835 | * o association id - local handle to the SCTP association |
| 4836 | * |
| 4837 | * Optional attributes: |
| 4838 | * |
| 4839 | * None. |
| 4840 | * |
| 4841 | * The return value is the disposition. |
| 4842 | */ |
| 4843 | sctp_disposition_t sctp_sf_do_9_2_prm_shutdown( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4844 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | const struct sctp_endpoint *ep, |
| 4846 | const struct sctp_association *asoc, |
| 4847 | const sctp_subtype_t type, |
| 4848 | void *arg, |
| 4849 | sctp_cmd_seq_t *commands) |
| 4850 | { |
| 4851 | int disposition; |
| 4852 | |
| 4853 | /* From 9.2 Shutdown of an Association |
| 4854 | * Upon receipt of the SHUTDOWN primitive from its upper |
| 4855 | * layer, the endpoint enters SHUTDOWN-PENDING state and |
| 4856 | * remains there until all outstanding data has been |
| 4857 | * acknowledged by its peer. The endpoint accepts no new data |
| 4858 | * from its upper layer, but retransmits data to the far end |
| 4859 | * if necessary to fill gaps. |
| 4860 | */ |
| 4861 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4862 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); |
| 4863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | disposition = SCTP_DISPOSITION_CONSUME; |
| 4865 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4866 | disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | arg, commands); |
| 4868 | } |
| 4869 | return disposition; |
| 4870 | } |
| 4871 | |
| 4872 | /* |
| 4873 | * Process the ABORT primitive. |
| 4874 | * |
| 4875 | * Section: 10.1: |
| 4876 | * C) Abort |
| 4877 | * |
| 4878 | * Format: Abort(association id [, cause code]) |
| 4879 | * -> result |
| 4880 | * |
| 4881 | * Ungracefully closes an association. Any locally queued user data |
| 4882 | * will be discarded and an ABORT chunk is sent to the peer. A success code |
| 4883 | * will be returned on successful abortion of the association. If |
| 4884 | * attempting to abort the association results in a failure, an error |
| 4885 | * code shall be returned. |
| 4886 | * |
| 4887 | * Mandatory attributes: |
| 4888 | * |
| 4889 | * o association id - local handle to the SCTP association |
| 4890 | * |
| 4891 | * Optional attributes: |
| 4892 | * |
| 4893 | * o cause code - reason of the abort to be passed to the peer |
| 4894 | * |
| 4895 | * None. |
| 4896 | * |
| 4897 | * The return value is the disposition. |
| 4898 | */ |
| 4899 | sctp_disposition_t sctp_sf_do_9_1_prm_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4900 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | const struct sctp_endpoint *ep, |
| 4902 | const struct sctp_association *asoc, |
| 4903 | const sctp_subtype_t type, |
| 4904 | void *arg, |
| 4905 | sctp_cmd_seq_t *commands) |
| 4906 | { |
| 4907 | /* From 9.1 Abort of an Association |
| 4908 | * Upon receipt of the ABORT primitive from its upper |
| 4909 | * layer, the endpoint enters CLOSED state and |
| 4910 | * discard all outstanding data has been |
| 4911 | * acknowledged by its peer. The endpoint accepts no new data |
| 4912 | * from its upper layer, but retransmits data to the far end |
| 4913 | * if necessary to fill gaps. |
| 4914 | */ |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 4915 | struct sctp_chunk *abort = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | |
Xin Long | 068d8bd | 2015-12-29 17:49:25 +0800 | [diff] [blame] | 4917 | if (abort) |
| 4918 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | |
| 4920 | /* Even if we can't send the ABORT due to low memory delete the |
| 4921 | * TCB. This is a departure from our typical NOMEM handling. |
| 4922 | */ |
| 4923 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 4924 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4925 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | /* Delete the established association. */ |
| 4927 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 4928 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4930 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 4931 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 4933 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | /* We tried an illegal operation on an association which is closed. */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4937 | sctp_disposition_t sctp_sf_error_closed(struct net *net, |
| 4938 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | const struct sctp_association *asoc, |
| 4940 | const sctp_subtype_t type, |
| 4941 | void *arg, |
| 4942 | sctp_cmd_seq_t *commands) |
| 4943 | { |
| 4944 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL)); |
| 4945 | return SCTP_DISPOSITION_CONSUME; |
| 4946 | } |
| 4947 | |
| 4948 | /* We tried an illegal operation on an association which is shutting |
| 4949 | * down. |
| 4950 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4951 | sctp_disposition_t sctp_sf_error_shutdown(struct net *net, |
| 4952 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | const struct sctp_association *asoc, |
| 4954 | const sctp_subtype_t type, |
| 4955 | void *arg, |
| 4956 | sctp_cmd_seq_t *commands) |
| 4957 | { |
| 4958 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, |
| 4959 | SCTP_ERROR(-ESHUTDOWN)); |
| 4960 | return SCTP_DISPOSITION_CONSUME; |
| 4961 | } |
| 4962 | |
| 4963 | /* |
| 4964 | * sctp_cookie_wait_prm_shutdown |
| 4965 | * |
| 4966 | * Section: 4 Note: 2 |
| 4967 | * Verification Tag: |
| 4968 | * Inputs |
| 4969 | * (endpoint, asoc) |
| 4970 | * |
| 4971 | * The RFC does not explicitly address this issue, but is the route through the |
| 4972 | * state table when someone issues a shutdown while in COOKIE_WAIT state. |
| 4973 | * |
| 4974 | * Outputs |
| 4975 | * (timers) |
| 4976 | */ |
| 4977 | sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 4978 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4979 | const struct sctp_endpoint *ep, |
| 4980 | const struct sctp_association *asoc, |
| 4981 | const sctp_subtype_t type, |
| 4982 | void *arg, |
| 4983 | sctp_cmd_seq_t *commands) |
| 4984 | { |
| 4985 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4986 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4987 | |
| 4988 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4989 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 4990 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 4991 | SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | |
| 4993 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 4994 | |
| 4995 | return SCTP_DISPOSITION_DELETE_TCB; |
| 4996 | } |
| 4997 | |
| 4998 | /* |
| 4999 | * sctp_cookie_echoed_prm_shutdown |
| 5000 | * |
| 5001 | * Section: 4 Note: 2 |
| 5002 | * Verification Tag: |
| 5003 | * Inputs |
| 5004 | * (endpoint, asoc) |
| 5005 | * |
| 5006 | * The RFC does not explcitly address this issue, but is the route through the |
| 5007 | * state table when someone issues a shutdown while in COOKIE_ECHOED state. |
| 5008 | * |
| 5009 | * Outputs |
| 5010 | * (timers) |
| 5011 | */ |
| 5012 | sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5013 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | const struct sctp_endpoint *ep, |
| 5015 | const struct sctp_association *asoc, |
| 5016 | const sctp_subtype_t type, |
| 5017 | void *arg, sctp_cmd_seq_t *commands) |
| 5018 | { |
| 5019 | /* There is a single T1 timer, so we should be able to use |
| 5020 | * common function with the COOKIE-WAIT state. |
| 5021 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5022 | return sctp_sf_cookie_wait_prm_shutdown(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | /* |
| 5026 | * sctp_sf_cookie_wait_prm_abort |
| 5027 | * |
| 5028 | * Section: 4 Note: 2 |
| 5029 | * Verification Tag: |
| 5030 | * Inputs |
| 5031 | * (endpoint, asoc) |
| 5032 | * |
| 5033 | * The RFC does not explicitly address this issue, but is the route through the |
| 5034 | * state table when someone issues an abort while in COOKIE_WAIT state. |
| 5035 | * |
| 5036 | * Outputs |
| 5037 | * (timers) |
| 5038 | */ |
| 5039 | sctp_disposition_t sctp_sf_cookie_wait_prm_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5040 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5041 | const struct sctp_endpoint *ep, |
| 5042 | const struct sctp_association *asoc, |
| 5043 | const sctp_subtype_t type, |
| 5044 | void *arg, |
| 5045 | sctp_cmd_seq_t *commands) |
| 5046 | { |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 5047 | struct sctp_chunk *abort = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | |
| 5049 | /* Stop T1-init timer */ |
| 5050 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5051 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5052 | |
Xin Long | 068d8bd | 2015-12-29 17:49:25 +0800 | [diff] [blame] | 5053 | if (abort) |
| 5054 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5055 | |
| 5056 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5057 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 5058 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5059 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | |
| 5061 | /* Even if we can't send the ABORT due to low memory delete the |
| 5062 | * TCB. This is a departure from our typical NOMEM handling. |
| 5063 | */ |
| 5064 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5065 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5066 | SCTP_ERROR(ECONNREFUSED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | /* Delete the established association. */ |
| 5068 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5069 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | |
Marcelo Ricardo Leitner | 649621e | 2016-01-08 11:00:54 -0200 | [diff] [blame] | 5071 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | /* |
| 5075 | * sctp_sf_cookie_echoed_prm_abort |
| 5076 | * |
| 5077 | * Section: 4 Note: 3 |
| 5078 | * Verification Tag: |
| 5079 | * Inputs |
| 5080 | * (endpoint, asoc) |
| 5081 | * |
| 5082 | * The RFC does not explcitly address this issue, but is the route through the |
| 5083 | * state table when someone issues an abort while in COOKIE_ECHOED state. |
| 5084 | * |
| 5085 | * Outputs |
| 5086 | * (timers) |
| 5087 | */ |
| 5088 | sctp_disposition_t sctp_sf_cookie_echoed_prm_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5089 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | const struct sctp_endpoint *ep, |
| 5091 | const struct sctp_association *asoc, |
| 5092 | const sctp_subtype_t type, |
| 5093 | void *arg, |
| 5094 | sctp_cmd_seq_t *commands) |
| 5095 | { |
| 5096 | /* There is a single T1 timer, so we should be able to use |
| 5097 | * common function with the COOKIE-WAIT state. |
| 5098 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5099 | return sctp_sf_cookie_wait_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | /* |
| 5103 | * sctp_sf_shutdown_pending_prm_abort |
| 5104 | * |
| 5105 | * Inputs |
| 5106 | * (endpoint, asoc) |
| 5107 | * |
| 5108 | * The RFC does not explicitly address this issue, but is the route through the |
| 5109 | * state table when someone issues an abort while in SHUTDOWN-PENDING state. |
| 5110 | * |
| 5111 | * Outputs |
| 5112 | * (timers) |
| 5113 | */ |
| 5114 | sctp_disposition_t sctp_sf_shutdown_pending_prm_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5115 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5116 | const struct sctp_endpoint *ep, |
| 5117 | const struct sctp_association *asoc, |
| 5118 | const sctp_subtype_t type, |
| 5119 | void *arg, |
| 5120 | sctp_cmd_seq_t *commands) |
| 5121 | { |
| 5122 | /* Stop the T5-shutdown guard timer. */ |
| 5123 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5124 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5125 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5126 | return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | /* |
| 5130 | * sctp_sf_shutdown_sent_prm_abort |
| 5131 | * |
| 5132 | * Inputs |
| 5133 | * (endpoint, asoc) |
| 5134 | * |
| 5135 | * The RFC does not explicitly address this issue, but is the route through the |
| 5136 | * state table when someone issues an abort while in SHUTDOWN-SENT state. |
| 5137 | * |
| 5138 | * Outputs |
| 5139 | * (timers) |
| 5140 | */ |
| 5141 | sctp_disposition_t sctp_sf_shutdown_sent_prm_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5142 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5143 | const struct sctp_endpoint *ep, |
| 5144 | const struct sctp_association *asoc, |
| 5145 | const sctp_subtype_t type, |
| 5146 | void *arg, |
| 5147 | sctp_cmd_seq_t *commands) |
| 5148 | { |
| 5149 | /* Stop the T2-shutdown timer. */ |
| 5150 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5151 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5152 | |
| 5153 | /* Stop the T5-shutdown guard timer. */ |
| 5154 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5155 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5156 | |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5157 | return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | /* |
| 5161 | * sctp_sf_cookie_echoed_prm_abort |
| 5162 | * |
| 5163 | * Inputs |
| 5164 | * (endpoint, asoc) |
| 5165 | * |
| 5166 | * The RFC does not explcitly address this issue, but is the route through the |
| 5167 | * state table when someone issues an abort while in COOKIE_ECHOED state. |
| 5168 | * |
| 5169 | * Outputs |
| 5170 | * (timers) |
| 5171 | */ |
| 5172 | sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5173 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | const struct sctp_endpoint *ep, |
| 5175 | const struct sctp_association *asoc, |
| 5176 | const sctp_subtype_t type, |
| 5177 | void *arg, |
| 5178 | sctp_cmd_seq_t *commands) |
| 5179 | { |
| 5180 | /* The same T2 timer, so we should be able to use |
| 5181 | * common function with the SHUTDOWN-SENT state. |
| 5182 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5183 | return sctp_sf_shutdown_sent_prm_abort(net, ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | /* |
| 5187 | * Process the REQUESTHEARTBEAT primitive |
| 5188 | * |
| 5189 | * 10.1 ULP-to-SCTP |
| 5190 | * J) Request Heartbeat |
| 5191 | * |
| 5192 | * Format: REQUESTHEARTBEAT(association id, destination transport address) |
| 5193 | * |
| 5194 | * -> result |
| 5195 | * |
| 5196 | * Instructs the local endpoint to perform a HeartBeat on the specified |
| 5197 | * destination transport address of the given association. The returned |
| 5198 | * result should indicate whether the transmission of the HEARTBEAT |
| 5199 | * chunk to the destination address is successful. |
| 5200 | * |
| 5201 | * Mandatory attributes: |
| 5202 | * |
| 5203 | * o association id - local handle to the SCTP association |
| 5204 | * |
| 5205 | * o destination transport address - the transport address of the |
| 5206 | * association on which a heartbeat should be issued. |
| 5207 | */ |
| 5208 | sctp_disposition_t sctp_sf_do_prm_requestheartbeat( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5209 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5210 | const struct sctp_endpoint *ep, |
| 5211 | const struct sctp_association *asoc, |
| 5212 | const sctp_subtype_t type, |
| 5213 | void *arg, |
| 5214 | sctp_cmd_seq_t *commands) |
| 5215 | { |
Vlad Yasevich | fb78525 | 2007-03-19 17:02:03 -0700 | [diff] [blame] | 5216 | if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type, |
| 5217 | (struct sctp_transport *)arg, commands)) |
| 5218 | return SCTP_DISPOSITION_NOMEM; |
| 5219 | |
| 5220 | /* |
| 5221 | * RFC 2960 (bis), section 8.3 |
| 5222 | * |
| 5223 | * D) Request an on-demand HEARTBEAT on a specific destination |
| 5224 | * transport address of a given association. |
| 5225 | * |
| 5226 | * The endpoint should increment the respective error counter of |
| 5227 | * the destination transport address each time a HEARTBEAT is sent |
| 5228 | * to that address and not acknowledged within one RTO. |
| 5229 | * |
| 5230 | */ |
Vlad Yasevich | 7e99013 | 2009-03-02 09:46:14 +0000 | [diff] [blame] | 5231 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, |
Vlad Yasevich | fb78525 | 2007-03-19 17:02:03 -0700 | [diff] [blame] | 5232 | SCTP_TRANSPORT(arg)); |
| 5233 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | /* |
| 5237 | * ADDIP Section 4.1 ASCONF Chunk Procedures |
| 5238 | * When an endpoint has an ASCONF signaled change to be sent to the |
| 5239 | * remote endpoint it should do A1 to A9 |
| 5240 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5241 | sctp_disposition_t sctp_sf_do_prm_asconf(struct net *net, |
| 5242 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | const struct sctp_association *asoc, |
| 5244 | const sctp_subtype_t type, |
| 5245 | void *arg, |
| 5246 | sctp_cmd_seq_t *commands) |
| 5247 | { |
| 5248 | struct sctp_chunk *chunk = arg; |
| 5249 | |
| 5250 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); |
| 5251 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 5252 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 5253 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); |
| 5254 | return SCTP_DISPOSITION_CONSUME; |
| 5255 | } |
| 5256 | |
Xin Long | 7a090b0 | 2017-01-18 00:44:44 +0800 | [diff] [blame] | 5257 | /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */ |
| 5258 | sctp_disposition_t sctp_sf_do_prm_reconf(struct net *net, |
| 5259 | const struct sctp_endpoint *ep, |
| 5260 | const struct sctp_association *asoc, |
| 5261 | const sctp_subtype_t type, |
| 5262 | void *arg, sctp_cmd_seq_t *commands) |
| 5263 | { |
| 5264 | struct sctp_chunk *chunk = arg; |
| 5265 | |
| 5266 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); |
| 5267 | return SCTP_DISPOSITION_CONSUME; |
| 5268 | } |
| 5269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5270 | /* |
| 5271 | * Ignore the primitive event |
| 5272 | * |
| 5273 | * The return value is the disposition of the primitive. |
| 5274 | */ |
| 5275 | sctp_disposition_t sctp_sf_ignore_primitive( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5276 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | const struct sctp_endpoint *ep, |
| 5278 | const struct sctp_association *asoc, |
| 5279 | const sctp_subtype_t type, |
| 5280 | void *arg, |
| 5281 | sctp_cmd_seq_t *commands) |
| 5282 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5283 | pr_debug("%s: primitive type:%d is ignored\n", __func__, |
| 5284 | type.primitive); |
| 5285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | return SCTP_DISPOSITION_DISCARD; |
| 5287 | } |
| 5288 | |
| 5289 | /*************************************************************************** |
| 5290 | * These are the state functions for the OTHER events. |
| 5291 | ***************************************************************************/ |
| 5292 | |
| 5293 | /* |
Wei Yongjun | e1cdd55 | 2011-04-17 17:29:03 +0000 | [diff] [blame] | 5294 | * When the SCTP stack has no more user data to send or retransmit, this |
| 5295 | * notification is given to the user. Also, at the time when a user app |
| 5296 | * subscribes to this event, if there is no data to be sent or |
| 5297 | * retransmit, the stack will immediately send up this notification. |
| 5298 | */ |
| 5299 | sctp_disposition_t sctp_sf_do_no_pending_tsn( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5300 | struct net *net, |
Wei Yongjun | e1cdd55 | 2011-04-17 17:29:03 +0000 | [diff] [blame] | 5301 | const struct sctp_endpoint *ep, |
| 5302 | const struct sctp_association *asoc, |
| 5303 | const sctp_subtype_t type, |
| 5304 | void *arg, |
| 5305 | sctp_cmd_seq_t *commands) |
| 5306 | { |
| 5307 | struct sctp_ulpevent *event; |
| 5308 | |
| 5309 | event = sctp_ulpevent_make_sender_dry_event(asoc, GFP_ATOMIC); |
| 5310 | if (!event) |
| 5311 | return SCTP_DISPOSITION_NOMEM; |
| 5312 | |
| 5313 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(event)); |
| 5314 | |
| 5315 | return SCTP_DISPOSITION_CONSUME; |
| 5316 | } |
| 5317 | |
| 5318 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5319 | * Start the shutdown negotiation. |
| 5320 | * |
| 5321 | * From Section 9.2: |
| 5322 | * Once all its outstanding data has been acknowledged, the endpoint |
| 5323 | * shall send a SHUTDOWN chunk to its peer including in the Cumulative |
| 5324 | * TSN Ack field the last sequential TSN it has received from the peer. |
| 5325 | * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT |
| 5326 | * state. If the timer expires, the endpoint must re-send the SHUTDOWN |
| 5327 | * with the updated last sequential TSN received from its peer. |
| 5328 | * |
| 5329 | * The return value is the disposition. |
| 5330 | */ |
| 5331 | sctp_disposition_t sctp_sf_do_9_2_start_shutdown( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5332 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5333 | const struct sctp_endpoint *ep, |
| 5334 | const struct sctp_association *asoc, |
| 5335 | const sctp_subtype_t type, |
| 5336 | void *arg, |
| 5337 | sctp_cmd_seq_t *commands) |
| 5338 | { |
| 5339 | struct sctp_chunk *reply; |
| 5340 | |
| 5341 | /* Once all its outstanding data has been acknowledged, the |
| 5342 | * endpoint shall send a SHUTDOWN chunk to its peer including |
| 5343 | * in the Cumulative TSN Ack field the last sequential TSN it |
| 5344 | * has received from the peer. |
| 5345 | */ |
| 5346 | reply = sctp_make_shutdown(asoc, NULL); |
| 5347 | if (!reply) |
| 5348 | goto nomem; |
| 5349 | |
| 5350 | /* Set the transport for the SHUTDOWN chunk and the timeout for the |
| 5351 | * T2-shutdown timer. |
| 5352 | */ |
| 5353 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5354 | |
| 5355 | /* It shall then start the T2-shutdown timer */ |
| 5356 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 5357 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5358 | |
Wei Yongjun | 536428a | 2008-09-05 08:55:26 +0800 | [diff] [blame] | 5359 | /* RFC 4960 Section 9.2 |
| 5360 | * The sender of the SHUTDOWN MAY also start an overall guard timer |
| 5361 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. |
| 5362 | */ |
Thomas Graf | f8d9605 | 2011-07-07 00:28:35 +0000 | [diff] [blame] | 5363 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
Wei Yongjun | 536428a | 2008-09-05 08:55:26 +0800 | [diff] [blame] | 5364 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5365 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 5366 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5367 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5368 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 5369 | |
| 5370 | /* and enter the SHUTDOWN-SENT state. */ |
| 5371 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5372 | SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT)); |
| 5373 | |
| 5374 | /* sctp-implguide 2.10 Issues with Heartbeating and failover |
| 5375 | * |
| 5376 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5377 | * or SHUTDOWN-ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | */ |
| 5379 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 5380 | |
| 5381 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5382 | |
| 5383 | return SCTP_DISPOSITION_CONSUME; |
| 5384 | |
| 5385 | nomem: |
| 5386 | return SCTP_DISPOSITION_NOMEM; |
| 5387 | } |
| 5388 | |
| 5389 | /* |
| 5390 | * Generate a SHUTDOWN ACK now that everything is SACK'd. |
| 5391 | * |
| 5392 | * From Section 9.2: |
| 5393 | * |
| 5394 | * If it has no more outstanding DATA chunks, the SHUTDOWN receiver |
| 5395 | * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own, |
| 5396 | * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the |
| 5397 | * endpoint must re-send the SHUTDOWN ACK. |
| 5398 | * |
| 5399 | * The return value is the disposition. |
| 5400 | */ |
| 5401 | sctp_disposition_t sctp_sf_do_9_2_shutdown_ack( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5402 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5403 | const struct sctp_endpoint *ep, |
| 5404 | const struct sctp_association *asoc, |
| 5405 | const sctp_subtype_t type, |
| 5406 | void *arg, |
| 5407 | sctp_cmd_seq_t *commands) |
| 5408 | { |
| 5409 | struct sctp_chunk *chunk = (struct sctp_chunk *) arg; |
| 5410 | struct sctp_chunk *reply; |
| 5411 | |
| 5412 | /* There are 2 ways of getting here: |
| 5413 | * 1) called in response to a SHUTDOWN chunk |
| 5414 | * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued. |
| 5415 | * |
| 5416 | * For the case (2), the arg parameter is set to NULL. We need |
| 5417 | * to check that we have a chunk before accessing it's fields. |
| 5418 | */ |
| 5419 | if (chunk) { |
| 5420 | if (!sctp_vtag_verify(chunk, asoc)) |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 5421 | return sctp_sf_pdiscard(net, ep, asoc, type, arg, |
| 5422 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | |
| 5424 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
Xin Long | ac23e68 | 2017-08-03 15:42:10 +0800 | [diff] [blame] | 5425 | if (!sctp_chunk_length_valid( |
| 5426 | chunk, sizeof(struct sctp_shutdown_chunk))) |
| 5427 | return sctp_sf_violation_chunklen(net, ep, asoc, type, |
| 5428 | arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver |
| 5432 | * shall send a SHUTDOWN ACK ... |
| 5433 | */ |
| 5434 | reply = sctp_make_shutdown_ack(asoc, chunk); |
| 5435 | if (!reply) |
| 5436 | goto nomem; |
| 5437 | |
| 5438 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for |
| 5439 | * the T2-shutdown timer. |
| 5440 | */ |
| 5441 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5442 | |
| 5443 | /* and start/restart a T2-shutdown timer of its own, */ |
| 5444 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5445 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5446 | |
Neil Horman | 9f70f46 | 2013-12-10 06:48:15 -0500 | [diff] [blame] | 5447 | if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5449 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 5450 | |
| 5451 | /* Enter the SHUTDOWN-ACK-SENT state. */ |
| 5452 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5453 | SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT)); |
| 5454 | |
| 5455 | /* sctp-implguide 2.10 Issues with Heartbeating and failover |
| 5456 | * |
| 5457 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5458 | * or SHUTDOWN-ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5459 | */ |
| 5460 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 5461 | |
| 5462 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5463 | |
| 5464 | return SCTP_DISPOSITION_CONSUME; |
| 5465 | |
| 5466 | nomem: |
| 5467 | return SCTP_DISPOSITION_NOMEM; |
| 5468 | } |
| 5469 | |
| 5470 | /* |
| 5471 | * Ignore the event defined as other |
| 5472 | * |
| 5473 | * The return value is the disposition of the event. |
| 5474 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5475 | sctp_disposition_t sctp_sf_ignore_other(struct net *net, |
| 5476 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | const struct sctp_association *asoc, |
| 5478 | const sctp_subtype_t type, |
| 5479 | void *arg, |
| 5480 | sctp_cmd_seq_t *commands) |
| 5481 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5482 | pr_debug("%s: the event other type:%d is ignored\n", |
| 5483 | __func__, type.other); |
| 5484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | return SCTP_DISPOSITION_DISCARD; |
| 5486 | } |
| 5487 | |
| 5488 | /************************************************************ |
| 5489 | * These are the state functions for handling timeout events. |
| 5490 | ************************************************************/ |
| 5491 | |
| 5492 | /* |
| 5493 | * RTX Timeout |
| 5494 | * |
| 5495 | * Section: 6.3.3 Handle T3-rtx Expiration |
| 5496 | * |
| 5497 | * Whenever the retransmission timer T3-rtx expires for a destination |
| 5498 | * address, do the following: |
| 5499 | * [See below] |
| 5500 | * |
| 5501 | * The return value is the disposition of the chunk. |
| 5502 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5503 | sctp_disposition_t sctp_sf_do_6_3_3_rtx(struct net *net, |
| 5504 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | const struct sctp_association *asoc, |
| 5506 | const sctp_subtype_t type, |
| 5507 | void *arg, |
| 5508 | sctp_cmd_seq_t *commands) |
| 5509 | { |
| 5510 | struct sctp_transport *transport = arg; |
| 5511 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5512 | SCTP_INC_STATS(net, SCTP_MIB_T3_RTX_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | if (asoc->overall_error_count >= asoc->max_retrans) { |
lucien | 8a0d19c | 2015-12-05 15:35:36 +0800 | [diff] [blame] | 5515 | if (asoc->peer.zero_window_announced && |
| 5516 | asoc->state == SCTP_STATE_SHUTDOWN_PENDING) { |
Thomas Graf | f8d9605 | 2011-07-07 00:28:35 +0000 | [diff] [blame] | 5517 | /* |
| 5518 | * We are here likely because the receiver had its rwnd |
| 5519 | * closed for a while and we have not been able to |
| 5520 | * transmit the locally queued data within the maximum |
| 5521 | * retransmission attempts limit. Start the T5 |
| 5522 | * shutdown guard timer to give the receiver one last |
| 5523 | * chance and some additional time to recover before |
| 5524 | * aborting. |
| 5525 | */ |
| 5526 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START_ONCE, |
| 5527 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5528 | } else { |
| 5529 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5530 | SCTP_ERROR(ETIMEDOUT)); |
| 5531 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 5532 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 5533 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5534 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5535 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Thomas Graf | f8d9605 | 2011-07-07 00:28:35 +0000 | [diff] [blame] | 5536 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | /* E1) For the destination address for which the timer |
| 5541 | * expires, adjust its ssthresh with rules defined in Section |
| 5542 | * 7.2.3 and set the cwnd <- MTU. |
| 5543 | */ |
| 5544 | |
| 5545 | /* E2) For the destination address for which the timer |
| 5546 | * expires, set RTO <- RTO * 2 ("back off the timer"). The |
| 5547 | * maximum value discussed in rule C7 above (RTO.max) may be |
| 5548 | * used to provide an upper bound to this doubling operation. |
| 5549 | */ |
| 5550 | |
| 5551 | /* E3) Determine how many of the earliest (i.e., lowest TSN) |
| 5552 | * outstanding DATA chunks for the address for which the |
| 5553 | * T3-rtx has expired will fit into a single packet, subject |
| 5554 | * to the MTU constraint for the path corresponding to the |
| 5555 | * destination transport address to which the retransmission |
| 5556 | * is being sent (this may be different from the address for |
| 5557 | * which the timer expires [see Section 6.4]). Call this |
| 5558 | * value K. Bundle and retransmit those K DATA chunks in a |
| 5559 | * single packet to the destination endpoint. |
| 5560 | * |
| 5561 | * Note: Any DATA chunks that were sent to the address for |
| 5562 | * which the T3-rtx timer expired but did not fit in one MTU |
| 5563 | * (rule E3 above), should be marked for retransmission and |
| 5564 | * sent as soon as cwnd allows (normally when a SACK arrives). |
| 5565 | */ |
| 5566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | /* Do some failure management (Section 8.2). */ |
| 5568 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); |
| 5569 | |
Vlad Yasevich | 1845a57 | 2007-02-21 02:06:19 -0800 | [diff] [blame] | 5570 | /* NB: Rules E4 and F1 are implicit in R1. */ |
| 5571 | sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport)); |
| 5572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | return SCTP_DISPOSITION_CONSUME; |
| 5574 | } |
| 5575 | |
| 5576 | /* |
| 5577 | * Generate delayed SACK on timeout |
| 5578 | * |
| 5579 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks |
| 5580 | * |
| 5581 | * The guidelines on delayed acknowledgement algorithm specified in |
| 5582 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an |
| 5583 | * acknowledgement SHOULD be generated for at least every second packet |
| 5584 | * (not every second DATA chunk) received, and SHOULD be generated |
| 5585 | * within 200 ms of the arrival of any unacknowledged DATA chunk. In |
| 5586 | * some situations it may be beneficial for an SCTP transmitter to be |
| 5587 | * more conservative than the algorithms detailed in this document |
| 5588 | * allow. However, an SCTP transmitter MUST NOT be more aggressive than |
| 5589 | * the following algorithms allow. |
| 5590 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5591 | sctp_disposition_t sctp_sf_do_6_2_sack(struct net *net, |
| 5592 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5593 | const struct sctp_association *asoc, |
| 5594 | const sctp_subtype_t type, |
| 5595 | void *arg, |
| 5596 | sctp_cmd_seq_t *commands) |
| 5597 | { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5598 | SCTP_INC_STATS(net, SCTP_MIB_DELAY_SACK_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5599 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 5600 | return SCTP_DISPOSITION_CONSUME; |
| 5601 | } |
| 5602 | |
| 5603 | /* |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5604 | * sctp_sf_t1_init_timer_expire |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5605 | * |
| 5606 | * Section: 4 Note: 2 |
| 5607 | * Verification Tag: |
| 5608 | * Inputs |
| 5609 | * (endpoint, asoc) |
| 5610 | * |
| 5611 | * RFC 2960 Section 4 Notes |
| 5612 | * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT |
| 5613 | * and re-start the T1-init timer without changing state. This MUST |
| 5614 | * be repeated up to 'Max.Init.Retransmits' times. After that, the |
| 5615 | * endpoint MUST abort the initialization process and report the |
| 5616 | * error to SCTP user. |
| 5617 | * |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5618 | * Outputs |
| 5619 | * (timers, events) |
| 5620 | * |
| 5621 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5622 | sctp_disposition_t sctp_sf_t1_init_timer_expire(struct net *net, |
| 5623 | const struct sctp_endpoint *ep, |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5624 | const struct sctp_association *asoc, |
| 5625 | const sctp_subtype_t type, |
| 5626 | void *arg, |
| 5627 | sctp_cmd_seq_t *commands) |
| 5628 | { |
| 5629 | struct sctp_chunk *repl = NULL; |
| 5630 | struct sctp_bind_addr *bp; |
| 5631 | int attempts = asoc->init_err_counter + 1; |
| 5632 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5633 | pr_debug("%s: timer T1 expired (INIT)\n", __func__); |
| 5634 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5635 | SCTP_INC_STATS(net, SCTP_MIB_T1_INIT_EXPIREDS); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5636 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 5637 | if (attempts <= asoc->max_init_attempts) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5638 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
| 5639 | repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); |
| 5640 | if (!repl) |
| 5641 | return SCTP_DISPOSITION_NOMEM; |
| 5642 | |
| 5643 | /* Choose transport for INIT. */ |
| 5644 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 5645 | SCTP_CHUNK(repl)); |
| 5646 | |
| 5647 | /* Issue a sideeffect to do the needed accounting. */ |
| 5648 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, |
| 5649 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 5650 | |
| 5651 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 5652 | } else { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5653 | pr_debug("%s: giving up on INIT, attempts:%d " |
| 5654 | "max_init_attempts:%d\n", __func__, attempts, |
| 5655 | asoc->max_init_attempts); |
| 5656 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5657 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5658 | SCTP_ERROR(ETIMEDOUT)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5659 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5660 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5661 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5662 | } |
| 5663 | |
| 5664 | return SCTP_DISPOSITION_CONSUME; |
| 5665 | } |
| 5666 | |
| 5667 | /* |
| 5668 | * sctp_sf_t1_cookie_timer_expire |
| 5669 | * |
| 5670 | * Section: 4 Note: 2 |
| 5671 | * Verification Tag: |
| 5672 | * Inputs |
| 5673 | * (endpoint, asoc) |
| 5674 | * |
| 5675 | * RFC 2960 Section 4 Notes |
| 5676 | * 3) If the T1-cookie timer expires, the endpoint MUST retransmit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | * COOKIE ECHO and re-start the T1-cookie timer without changing |
| 5678 | * state. This MUST be repeated up to 'Max.Init.Retransmits' times. |
| 5679 | * After that, the endpoint MUST abort the initialization process and |
| 5680 | * report the error to SCTP user. |
| 5681 | * |
| 5682 | * Outputs |
| 5683 | * (timers, events) |
| 5684 | * |
| 5685 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5686 | sctp_disposition_t sctp_sf_t1_cookie_timer_expire(struct net *net, |
| 5687 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | const struct sctp_association *asoc, |
| 5689 | const sctp_subtype_t type, |
| 5690 | void *arg, |
| 5691 | sctp_cmd_seq_t *commands) |
| 5692 | { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5693 | struct sctp_chunk *repl = NULL; |
| 5694 | int attempts = asoc->init_err_counter + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5696 | pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__); |
| 5697 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5698 | SCTP_INC_STATS(net, SCTP_MIB_T1_COOKIE_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5699 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 5700 | if (attempts <= asoc->max_init_attempts) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5701 | repl = sctp_make_cookie_echo(asoc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | if (!repl) |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5703 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | |
Vlad Yasevich | 96cd0d3 | 2008-09-08 14:00:26 -0400 | [diff] [blame] | 5705 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 5706 | SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5707 | /* Issue a sideeffect to do the needed accounting. */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5708 | sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART, |
| 5709 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 5710 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 5712 | } else { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5713 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5714 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5716 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5718 | } |
| 5719 | |
| 5720 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN |
| 5724 | * with the updated last sequential TSN received from its peer. |
| 5725 | * |
| 5726 | * An endpoint should limit the number of retransmissions of the |
| 5727 | * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'. |
| 5728 | * If this threshold is exceeded the endpoint should destroy the TCB and |
| 5729 | * MUST report the peer endpoint unreachable to the upper layer (and |
| 5730 | * thus the association enters the CLOSED state). The reception of any |
| 5731 | * packet from its peer (i.e. as the peer sends all of its queued DATA |
| 5732 | * chunks) should clear the endpoint's retransmission count and restart |
| 5733 | * the T2-Shutdown timer, giving its peer ample opportunity to transmit |
| 5734 | * all of its queued DATA chunks that have not yet been sent. |
| 5735 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5736 | sctp_disposition_t sctp_sf_t2_timer_expire(struct net *net, |
| 5737 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | const struct sctp_association *asoc, |
| 5739 | const sctp_subtype_t type, |
| 5740 | void *arg, |
| 5741 | sctp_cmd_seq_t *commands) |
| 5742 | { |
| 5743 | struct sctp_chunk *reply = NULL; |
| 5744 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5745 | pr_debug("%s: timer T2 expired\n", __func__); |
| 5746 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5747 | SCTP_INC_STATS(net, SCTP_MIB_T2_SHUTDOWN_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5748 | |
Neil Horman | 58fbbed | 2008-02-29 11:40:56 -0800 | [diff] [blame] | 5749 | ((struct sctp_association *)asoc)->shutdown_retries++; |
| 5750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | if (asoc->overall_error_count >= asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5752 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5753 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5754 | /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 5755 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5756 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5757 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5758 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5760 | } |
| 5761 | |
| 5762 | switch (asoc->state) { |
| 5763 | case SCTP_STATE_SHUTDOWN_SENT: |
| 5764 | reply = sctp_make_shutdown(asoc, NULL); |
| 5765 | break; |
| 5766 | |
| 5767 | case SCTP_STATE_SHUTDOWN_ACK_SENT: |
| 5768 | reply = sctp_make_shutdown_ack(asoc, NULL); |
| 5769 | break; |
| 5770 | |
| 5771 | default: |
| 5772 | BUG(); |
| 5773 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 5774 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5775 | |
| 5776 | if (!reply) |
| 5777 | goto nomem; |
| 5778 | |
Wei Yongjun | 6345b19 | 2009-04-26 23:13:35 +0800 | [diff] [blame] | 5779 | /* Do some failure management (Section 8.2). |
| 5780 | * If we remove the transport an SHUTDOWN was last sent to, don't |
| 5781 | * do failure management. |
| 5782 | */ |
| 5783 | if (asoc->shutdown_last_sent_to) |
| 5784 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, |
| 5785 | SCTP_TRANSPORT(asoc->shutdown_last_sent_to)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | |
| 5787 | /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for |
| 5788 | * the T2-shutdown timer. |
| 5789 | */ |
| 5790 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5791 | |
| 5792 | /* Restart the T2-shutdown timer. */ |
| 5793 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5794 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5795 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5796 | return SCTP_DISPOSITION_CONSUME; |
| 5797 | |
| 5798 | nomem: |
| 5799 | return SCTP_DISPOSITION_NOMEM; |
| 5800 | } |
| 5801 | |
| 5802 | /* |
| 5803 | * ADDIP Section 4.1 ASCONF CHunk Procedures |
| 5804 | * If the T4 RTO timer expires the endpoint should do B1 to B5 |
| 5805 | */ |
| 5806 | sctp_disposition_t sctp_sf_t4_timer_expire( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5807 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | const struct sctp_endpoint *ep, |
| 5809 | const struct sctp_association *asoc, |
| 5810 | const sctp_subtype_t type, |
| 5811 | void *arg, |
| 5812 | sctp_cmd_seq_t *commands) |
| 5813 | { |
| 5814 | struct sctp_chunk *chunk = asoc->addip_last_asconf; |
| 5815 | struct sctp_transport *transport = chunk->transport; |
| 5816 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5817 | SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | /* ADDIP 4.1 B1) Increment the error counters and perform path failure |
| 5820 | * detection on the appropriate destination address as defined in |
| 5821 | * RFC2960 [5] section 8.1 and 8.2. |
| 5822 | */ |
Wei Yongjun | 10a43ce | 2009-04-26 23:14:42 +0800 | [diff] [blame] | 5823 | if (transport) |
| 5824 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, |
| 5825 | SCTP_TRANSPORT(transport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | |
| 5827 | /* Reconfig T4 timer and transport. */ |
| 5828 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); |
| 5829 | |
| 5830 | /* ADDIP 4.1 B2) Increment the association error counters and perform |
| 5831 | * endpoint failure detection on the association as defined in |
| 5832 | * RFC2960 [5] section 8.1 and 8.2. |
| 5833 | * association error counter is incremented in SCTP_CMD_STRIKE. |
| 5834 | */ |
| 5835 | if (asoc->overall_error_count >= asoc->max_retrans) { |
| 5836 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5837 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5838 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5839 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5840 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5841 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5842 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5843 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5844 | return SCTP_DISPOSITION_ABORT; |
| 5845 | } |
| 5846 | |
| 5847 | /* ADDIP 4.1 B3) Back-off the destination address RTO value to which |
| 5848 | * the ASCONF chunk was sent by doubling the RTO timer value. |
| 5849 | * This is done in SCTP_CMD_STRIKE. |
| 5850 | */ |
| 5851 | |
| 5852 | /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible |
| 5853 | * choose an alternate destination address (please refer to RFC2960 |
| 5854 | * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5855 | * chunk, it MUST be the same (including its serial number) as the last |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5856 | * ASCONF sent. |
| 5857 | */ |
| 5858 | sctp_chunk_hold(asoc->addip_last_asconf); |
| 5859 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 5860 | SCTP_CHUNK(asoc->addip_last_asconf)); |
| 5861 | |
| 5862 | /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different |
| 5863 | * destination is selected, then the RTO used will be that of the new |
| 5864 | * destination address. |
| 5865 | */ |
| 5866 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5867 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 5868 | |
| 5869 | return SCTP_DISPOSITION_CONSUME; |
| 5870 | } |
| 5871 | |
| 5872 | /* sctpimpguide-05 Section 2.12.2 |
| 5873 | * The sender of the SHUTDOWN MAY also start an overall guard timer |
| 5874 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. |
| 5875 | * At the expiration of this timer the sender SHOULD abort the association |
| 5876 | * by sending an ABORT chunk. |
| 5877 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5878 | sctp_disposition_t sctp_sf_t5_timer_expire(struct net *net, |
| 5879 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5880 | const struct sctp_association *asoc, |
| 5881 | const sctp_subtype_t type, |
| 5882 | void *arg, |
| 5883 | sctp_cmd_seq_t *commands) |
| 5884 | { |
| 5885 | struct sctp_chunk *reply = NULL; |
| 5886 | |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 5887 | pr_debug("%s: timer T5 expired\n", __func__); |
| 5888 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5889 | SCTP_INC_STATS(net, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5890 | |
| 5891 | reply = sctp_make_abort(asoc, NULL, 0); |
| 5892 | if (!reply) |
| 5893 | goto nomem; |
| 5894 | |
| 5895 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5896 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5897 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5898 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5899 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5900 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5901 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 5902 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Vlad Yasevich | a1080a8 | 2008-10-09 14:33:26 -0700 | [diff] [blame] | 5903 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5905 | nomem: |
| 5906 | return SCTP_DISPOSITION_NOMEM; |
| 5907 | } |
| 5908 | |
| 5909 | /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires, |
| 5910 | * the association is automatically closed by starting the shutdown process. |
| 5911 | * The work that needs to be done is same as when SHUTDOWN is initiated by |
| 5912 | * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown(). |
| 5913 | */ |
| 5914 | sctp_disposition_t sctp_sf_autoclose_timer_expire( |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5915 | struct net *net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5916 | const struct sctp_endpoint *ep, |
| 5917 | const struct sctp_association *asoc, |
| 5918 | const sctp_subtype_t type, |
| 5919 | void *arg, |
| 5920 | sctp_cmd_seq_t *commands) |
| 5921 | { |
| 5922 | int disposition; |
| 5923 | |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 5924 | SCTP_INC_STATS(net, SCTP_MIB_AUTOCLOSE_EXPIREDS); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | /* From 9.2 Shutdown of an Association |
| 5927 | * Upon receipt of the SHUTDOWN primitive from its upper |
| 5928 | * layer, the endpoint enters SHUTDOWN-PENDING state and |
| 5929 | * remains there until all outstanding data has been |
| 5930 | * acknowledged by its peer. The endpoint accepts no new data |
| 5931 | * from its upper layer, but retransmits data to the far end |
| 5932 | * if necessary to fill gaps. |
| 5933 | */ |
| 5934 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5935 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); |
| 5936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5937 | disposition = SCTP_DISPOSITION_CONSUME; |
| 5938 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5939 | disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5940 | arg, commands); |
| 5941 | } |
| 5942 | return disposition; |
| 5943 | } |
| 5944 | |
| 5945 | /***************************************************************************** |
| 5946 | * These are sa state functions which could apply to all types of events. |
| 5947 | ****************************************************************************/ |
| 5948 | |
| 5949 | /* |
| 5950 | * This table entry is not implemented. |
| 5951 | * |
| 5952 | * Inputs |
| 5953 | * (endpoint, asoc, chunk) |
| 5954 | * |
| 5955 | * The return value is the disposition of the chunk. |
| 5956 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5957 | sctp_disposition_t sctp_sf_not_impl(struct net *net, |
| 5958 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5959 | const struct sctp_association *asoc, |
| 5960 | const sctp_subtype_t type, |
| 5961 | void *arg, |
| 5962 | sctp_cmd_seq_t *commands) |
| 5963 | { |
| 5964 | return SCTP_DISPOSITION_NOT_IMPL; |
| 5965 | } |
| 5966 | |
| 5967 | /* |
| 5968 | * This table entry represents a bug. |
| 5969 | * |
| 5970 | * Inputs |
| 5971 | * (endpoint, asoc, chunk) |
| 5972 | * |
| 5973 | * The return value is the disposition of the chunk. |
| 5974 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5975 | sctp_disposition_t sctp_sf_bug(struct net *net, |
| 5976 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | const struct sctp_association *asoc, |
| 5978 | const sctp_subtype_t type, |
| 5979 | void *arg, |
| 5980 | sctp_cmd_seq_t *commands) |
| 5981 | { |
| 5982 | return SCTP_DISPOSITION_BUG; |
| 5983 | } |
| 5984 | |
| 5985 | /* |
| 5986 | * This table entry represents the firing of a timer in the wrong state. |
| 5987 | * Since timer deletion cannot be guaranteed a timer 'may' end up firing |
| 5988 | * when the association is in the wrong state. This event should |
| 5989 | * be ignored, so as to prevent any rearming of the timer. |
| 5990 | * |
| 5991 | * Inputs |
| 5992 | * (endpoint, asoc, chunk) |
| 5993 | * |
| 5994 | * The return value is the disposition of the chunk. |
| 5995 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 5996 | sctp_disposition_t sctp_sf_timer_ignore(struct net *net, |
| 5997 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5998 | const struct sctp_association *asoc, |
| 5999 | const sctp_subtype_t type, |
| 6000 | void *arg, |
| 6001 | sctp_cmd_seq_t *commands) |
| 6002 | { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6003 | pr_debug("%s: timer %d ignored\n", __func__, type.chunk); |
| 6004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6005 | return SCTP_DISPOSITION_CONSUME; |
| 6006 | } |
| 6007 | |
| 6008 | /******************************************************************** |
| 6009 | * 2nd Level Abstractions |
| 6010 | ********************************************************************/ |
| 6011 | |
| 6012 | /* Pull the SACK chunk based on the SACK header. */ |
| 6013 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk) |
| 6014 | { |
| 6015 | struct sctp_sackhdr *sack; |
| 6016 | unsigned int len; |
| 6017 | __u16 num_blocks; |
| 6018 | __u16 num_dup_tsns; |
| 6019 | |
| 6020 | /* Protect ourselves from reading too far into |
| 6021 | * the skb from a bogus sender. |
| 6022 | */ |
| 6023 | sack = (struct sctp_sackhdr *) chunk->skb->data; |
| 6024 | |
| 6025 | num_blocks = ntohs(sack->num_gap_ack_blocks); |
| 6026 | num_dup_tsns = ntohs(sack->num_dup_tsns); |
| 6027 | len = sizeof(struct sctp_sackhdr); |
| 6028 | len += (num_blocks + num_dup_tsns) * sizeof(__u32); |
| 6029 | if (len > chunk->skb->len) |
| 6030 | return NULL; |
| 6031 | |
| 6032 | skb_pull(chunk->skb, len); |
| 6033 | |
| 6034 | return sack; |
| 6035 | } |
| 6036 | |
| 6037 | /* Create an ABORT packet to be sent as a response, with the specified |
| 6038 | * error causes. |
| 6039 | */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 6040 | static struct sctp_packet *sctp_abort_pkt_new(struct net *net, |
| 6041 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6042 | const struct sctp_association *asoc, |
| 6043 | struct sctp_chunk *chunk, |
| 6044 | const void *payload, |
| 6045 | size_t paylen) |
| 6046 | { |
| 6047 | struct sctp_packet *packet; |
| 6048 | struct sctp_chunk *abort; |
| 6049 | |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6050 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | |
| 6052 | if (packet) { |
| 6053 | /* Make an ABORT. |
| 6054 | * The T bit will be set if the asoc is NULL. |
| 6055 | */ |
| 6056 | abort = sctp_make_abort(asoc, chunk, paylen); |
| 6057 | if (!abort) { |
| 6058 | sctp_ootb_pkt_free(packet); |
| 6059 | return NULL; |
| 6060 | } |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 6061 | |
| 6062 | /* Reflect vtag if T-Bit is set */ |
| 6063 | if (sctp_test_T_bit(abort)) |
| 6064 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 6065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6066 | /* Add specified error causes, i.e., payload, to the |
| 6067 | * end of the chunk. |
| 6068 | */ |
| 6069 | sctp_addto_chunk(abort, paylen, payload); |
| 6070 | |
| 6071 | /* Set the skb to the belonging sock for accounting. */ |
| 6072 | abort->skb->sk = ep->base.sk; |
| 6073 | |
| 6074 | sctp_packet_append_chunk(packet, abort); |
| 6075 | |
| 6076 | } |
| 6077 | |
| 6078 | return packet; |
| 6079 | } |
| 6080 | |
| 6081 | /* Allocate a packet for responding in the OOTB conditions. */ |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6082 | static struct sctp_packet *sctp_ootb_pkt_new(struct net *net, |
| 6083 | const struct sctp_association *asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6084 | const struct sctp_chunk *chunk) |
| 6085 | { |
| 6086 | struct sctp_packet *packet; |
| 6087 | struct sctp_transport *transport; |
| 6088 | __u16 sport; |
| 6089 | __u16 dport; |
| 6090 | __u32 vtag; |
| 6091 | |
| 6092 | /* Get the source and destination port from the inbound packet. */ |
| 6093 | sport = ntohs(chunk->sctp_hdr->dest); |
| 6094 | dport = ntohs(chunk->sctp_hdr->source); |
| 6095 | |
| 6096 | /* The V-tag is going to be the same as the inbound packet if no |
| 6097 | * association exists, otherwise, use the peer's vtag. |
| 6098 | */ |
| 6099 | if (asoc) { |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6100 | /* Special case the INIT-ACK as there is no peer's vtag |
| 6101 | * yet. |
| 6102 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 6103 | switch (chunk->chunk_hdr->type) { |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6104 | case SCTP_CID_INIT_ACK: |
| 6105 | { |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 6106 | struct sctp_initack_chunk *initack; |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6107 | |
Xin Long | cb1844c | 2017-07-23 09:34:26 +0800 | [diff] [blame] | 6108 | initack = (struct sctp_initack_chunk *)chunk->chunk_hdr; |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 6109 | vtag = ntohl(initack->init_hdr.init_tag); |
| 6110 | break; |
| 6111 | } |
| 6112 | default: |
| 6113 | vtag = asoc->peer.i.init_tag; |
| 6114 | break; |
| 6115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6116 | } else { |
| 6117 | /* Special case the INIT and stale COOKIE_ECHO as there is no |
| 6118 | * vtag yet. |
| 6119 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 6120 | switch (chunk->chunk_hdr->type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | case SCTP_CID_INIT: |
| 6122 | { |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 6123 | struct sctp_init_chunk *init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | |
Xin Long | 01a992b | 2017-06-30 11:52:22 +0800 | [diff] [blame] | 6125 | init = (struct sctp_init_chunk *)chunk->chunk_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6126 | vtag = ntohl(init->init_hdr.init_tag); |
| 6127 | break; |
| 6128 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6129 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6130 | vtag = ntohl(chunk->sctp_hdr->vtag); |
| 6131 | break; |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | /* Make a transport for the bucket, Eliza... */ |
Eric W. Biederman | 89bf345 | 2012-08-07 07:26:14 +0000 | [diff] [blame] | 6136 | transport = sctp_transport_new(net, sctp_source(chunk), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | if (!transport) |
| 6138 | goto nomem; |
| 6139 | |
| 6140 | /* Cache a route for the transport with the chunk's destination as |
| 6141 | * the source address. |
| 6142 | */ |
Al Viro | 16b0a03 | 2006-11-20 17:13:38 -0800 | [diff] [blame] | 6143 | sctp_transport_route(transport, (union sctp_addr *)&chunk->dest, |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6144 | sctp_sk(net->sctp.ctl_sock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6145 | |
Marcelo Ricardo Leitner | 66b91d2 | 2016-12-28 09:26:34 -0200 | [diff] [blame] | 6146 | packet = &transport->packet; |
| 6147 | sctp_packet_init(packet, transport, sport, dport); |
| 6148 | sctp_packet_config(packet, vtag, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6149 | |
| 6150 | return packet; |
| 6151 | |
| 6152 | nomem: |
| 6153 | return NULL; |
| 6154 | } |
| 6155 | |
| 6156 | /* Free the packet allocated earlier for responding in the OOTB condition. */ |
| 6157 | void sctp_ootb_pkt_free(struct sctp_packet *packet) |
| 6158 | { |
| 6159 | sctp_transport_free(packet->transport); |
| 6160 | } |
| 6161 | |
| 6162 | /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */ |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 6163 | static void sctp_send_stale_cookie_err(struct net *net, |
| 6164 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6165 | const struct sctp_association *asoc, |
| 6166 | const struct sctp_chunk *chunk, |
| 6167 | sctp_cmd_seq_t *commands, |
| 6168 | struct sctp_chunk *err_chunk) |
| 6169 | { |
| 6170 | struct sctp_packet *packet; |
| 6171 | |
| 6172 | if (err_chunk) { |
Eric W. Biederman | 2ce9550 | 2012-08-06 08:43:06 +0000 | [diff] [blame] | 6173 | packet = sctp_ootb_pkt_new(net, asoc, chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6174 | if (packet) { |
| 6175 | struct sctp_signed_cookie *cookie; |
| 6176 | |
| 6177 | /* Override the OOTB vtag from the cookie. */ |
| 6178 | cookie = chunk->subh.cookie_hdr; |
| 6179 | packet->vtag = cookie->c.peer_vtag; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | /* Set the skb to the belonging sock for accounting. */ |
| 6182 | err_chunk->skb->sk = ep->base.sk; |
| 6183 | sctp_packet_append_chunk(packet, err_chunk); |
| 6184 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 6185 | SCTP_PACKET(packet)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6186 | SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6187 | } else |
| 6188 | sctp_chunk_free (err_chunk); |
| 6189 | } |
| 6190 | } |
| 6191 | |
| 6192 | |
| 6193 | /* Process a data chunk */ |
| 6194 | static int sctp_eat_data(const struct sctp_association *asoc, |
| 6195 | struct sctp_chunk *chunk, |
| 6196 | sctp_cmd_seq_t *commands) |
| 6197 | { |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 6198 | struct sctp_datahdr *data_hdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | struct sctp_chunk *err; |
| 6200 | size_t datalen; |
| 6201 | sctp_verb_t deliver; |
| 6202 | int tmp; |
| 6203 | __u32 tsn; |
Neil Horman | 7c3ceb4f | 2006-05-05 17:02:09 -0700 | [diff] [blame] | 6204 | struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map; |
Neil Horman | 049b3ff | 2005-11-11 16:08:24 -0800 | [diff] [blame] | 6205 | struct sock *sk = asoc->base.sk; |
Eric W. Biederman | 24cb81a | 2012-08-07 07:28:09 +0000 | [diff] [blame] | 6206 | struct net *net = sock_net(sk); |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6207 | u16 ssn; |
| 6208 | u16 sid; |
| 6209 | u8 ordered = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | |
Xin Long | 3583df1 | 2017-06-30 11:52:19 +0800 | [diff] [blame] | 6211 | data_hdr = (struct sctp_datahdr *)chunk->skb->data; |
| 6212 | chunk->subh.data_hdr = data_hdr; |
| 6213 | skb_pull(chunk->skb, sizeof(*data_hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6214 | |
| 6215 | tsn = ntohl(data_hdr->tsn); |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6216 | pr_debug("%s: TSN 0x%x\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | |
| 6218 | /* ASSERT: Now skb->data is really the user data. */ |
| 6219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | /* Process ECN based congestion. |
| 6221 | * |
| 6222 | * Since the chunk structure is reused for all chunks within |
| 6223 | * a packet, we use ecn_ce_done to track if we've already |
| 6224 | * done CE processing for this packet. |
| 6225 | * |
| 6226 | * We need to do ECN processing even if we plan to discard the |
| 6227 | * chunk later. |
| 6228 | */ |
| 6229 | |
Marcelo Ricardo Leitner | 2d47fd1 | 2016-07-13 15:09:00 -0300 | [diff] [blame] | 6230 | if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) { |
Marcelo Ricardo Leitner | e7487c8 | 2016-07-13 15:08:58 -0300 | [diff] [blame] | 6231 | struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6232 | chunk->ecn_ce_done = 1; |
| 6233 | |
Marcelo Ricardo Leitner | 2d47fd1 | 2016-07-13 15:09:00 -0300 | [diff] [blame] | 6234 | if (af->is_ce(sctp_gso_headskb(chunk->skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6235 | /* Do real work as sideffect. */ |
| 6236 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE, |
| 6237 | SCTP_U32(tsn)); |
| 6238 | } |
| 6239 | } |
| 6240 | |
| 6241 | tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn); |
| 6242 | if (tmp < 0) { |
| 6243 | /* The TSN is too high--silently discard the chunk and |
| 6244 | * count on it getting retransmitted later. |
| 6245 | */ |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6246 | if (chunk->asoc) |
| 6247 | chunk->asoc->stats.outofseqtsns++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6248 | return SCTP_IERROR_HIGH_TSN; |
| 6249 | } else if (tmp > 0) { |
| 6250 | /* This is a duplicate. Record it. */ |
| 6251 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn)); |
| 6252 | return SCTP_IERROR_DUP_TSN; |
| 6253 | } |
| 6254 | |
| 6255 | /* This is a new TSN. */ |
| 6256 | |
| 6257 | /* Discard if there is no room in the receive window. |
| 6258 | * Actually, allow a little bit of overflow (up to a MTU). |
| 6259 | */ |
| 6260 | datalen = ntohs(chunk->chunk_hdr->length); |
Xin Long | 9f8d314 | 2017-06-30 11:52:20 +0800 | [diff] [blame] | 6261 | datalen -= sizeof(struct sctp_data_chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | |
| 6263 | deliver = SCTP_CMD_CHUNK_ULP; |
| 6264 | |
| 6265 | /* Think about partial delivery. */ |
| 6266 | if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { |
| 6267 | |
| 6268 | /* Even if we don't accept this chunk there is |
| 6269 | * memory pressure. |
| 6270 | */ |
| 6271 | sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL()); |
| 6272 | } |
| 6273 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 6274 | /* Spill over rwnd a little bit. Note: While allowed, this spill over |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6275 | * seems a bit troublesome in that frag_point varies based on |
| 6276 | * PMTU. In cases, such as loopback, this might be a rather |
| 6277 | * large spill over. |
| 6278 | */ |
Daniel Borkmann | 362d520 | 2014-04-14 21:45:17 +0200 | [diff] [blame] | 6279 | if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over || |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6280 | (datalen > asoc->rwnd + asoc->frag_point))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6281 | |
| 6282 | /* If this is the next TSN, consider reneging to make |
| 6283 | * room. Note: Playing nice with a confused sender. A |
| 6284 | * malicious sender can still eat up all our buffer |
| 6285 | * space and in the future we may want to detect and |
| 6286 | * do more drastic reneging. |
| 6287 | */ |
Neil Horman | 7c3ceb4f | 2006-05-05 17:02:09 -0700 | [diff] [blame] | 6288 | if (sctp_tsnmap_has_gap(map) && |
| 6289 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6290 | pr_debug("%s: reneging for tsn:%u\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | deliver = SCTP_CMD_RENEGE; |
| 6292 | } else { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6293 | pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n", |
| 6294 | __func__, tsn, datalen, asoc->rwnd); |
| 6295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6296 | return SCTP_IERROR_IGNORE_TSN; |
| 6297 | } |
| 6298 | } |
| 6299 | |
| 6300 | /* |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6301 | * Also try to renege to limit our memory usage in the event that |
| 6302 | * we are under memory pressure |
Hideo Aoki | 3ab224b | 2007-12-31 00:11:19 -0800 | [diff] [blame] | 6303 | * If we can't renege, don't worry about it, the sk_rmem_schedule |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6304 | * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our |
| 6305 | * memory usage too much |
| 6306 | */ |
| 6307 | if (*sk->sk_prot_creator->memory_pressure) { |
| 6308 | if (sctp_tsnmap_has_gap(map) && |
wangweidong | f7010e6 | 2013-12-23 12:16:52 +0800 | [diff] [blame] | 6309 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
Daniel Borkmann | bb33381 | 2013-06-28 19:49:40 +0200 | [diff] [blame] | 6310 | pr_debug("%s: under pressure, reneging for tsn:%u\n", |
| 6311 | __func__, tsn); |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 6312 | deliver = SCTP_CMD_RENEGE; |
| 6313 | } |
| 6314 | } |
| 6315 | |
| 6316 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | * Section 3.3.10.9 No User Data (9) |
| 6318 | * |
| 6319 | * Cause of error |
| 6320 | * --------------- |
| 6321 | * No User Data: This error cause is returned to the originator of a |
| 6322 | * DATA chunk if a received DATA chunk has no user data. |
| 6323 | */ |
| 6324 | if (unlikely(0 == datalen)) { |
| 6325 | err = sctp_make_abort_no_data(asoc, chunk, tsn); |
| 6326 | if (err) { |
| 6327 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 6328 | SCTP_CHUNK(err)); |
| 6329 | } |
| 6330 | /* We are going to ABORT, so we might as well stop |
| 6331 | * processing the rest of the chunks in the packet. |
| 6332 | */ |
wangweidong | cb3f837 | 2013-12-23 12:16:50 +0800 | [diff] [blame] | 6333 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 6334 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 6335 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6336 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 6337 | SCTP_PERR(SCTP_ERROR_NO_DATA)); |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6338 | SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS); |
| 6339 | SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6340 | return SCTP_IERROR_NO_DATA; |
| 6341 | } |
| 6342 | |
Sridhar Samudrala | 9faa730 | 2006-07-21 14:49:07 -0700 | [diff] [blame] | 6343 | chunk->data_accepted = 1; |
| 6344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | /* Note: Some chunks may get overcounted (if we drop) or overcounted |
| 6346 | * if we renege and the chunk arrives again. |
| 6347 | */ |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6348 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6349 | SCTP_INC_STATS(net, SCTP_MIB_INUNORDERCHUNKS); |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6350 | if (chunk->asoc) |
| 6351 | chunk->asoc->stats.iuodchunks++; |
| 6352 | } else { |
Eric W. Biederman | b01a240 | 2012-08-06 08:47:55 +0000 | [diff] [blame] | 6353 | SCTP_INC_STATS(net, SCTP_MIB_INORDERCHUNKS); |
Michele Baldessari | 196d675 | 2012-12-01 04:49:42 +0000 | [diff] [blame] | 6354 | if (chunk->asoc) |
| 6355 | chunk->asoc->stats.iodchunks++; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6356 | ordered = 1; |
| 6357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | |
| 6359 | /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number |
| 6360 | * |
| 6361 | * If an endpoint receive a DATA chunk with an invalid stream |
| 6362 | * identifier, it shall acknowledge the reception of the DATA chunk |
| 6363 | * following the normal procedure, immediately send an ERROR chunk |
| 6364 | * with cause set to "Invalid Stream Identifier" (See Section 3.3.10) |
| 6365 | * and discard the DATA chunk. |
| 6366 | */ |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6367 | sid = ntohs(data_hdr->stream); |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 6368 | if (sid >= asoc->stream.incnt) { |
Vlad Yasevich | 3888e9e | 2008-07-08 02:28:39 -0700 | [diff] [blame] | 6369 | /* Mark tsn as received even though we drop it */ |
| 6370 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn)); |
| 6371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM, |
| 6373 | &data_hdr->stream, |
Vlad Yasevich | 6383cfb | 2009-11-23 15:53:56 -0500 | [diff] [blame] | 6374 | sizeof(data_hdr->stream), |
| 6375 | sizeof(u16)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | if (err) |
| 6377 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 6378 | SCTP_CHUNK(err)); |
| 6379 | return SCTP_IERROR_BAD_STREAM; |
| 6380 | } |
| 6381 | |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6382 | /* Check to see if the SSN is possible for this TSN. |
| 6383 | * The biggest gap we can record is 4K wide. Since SSNs wrap |
| 6384 | * at an unsigned short, there is no way that an SSN can |
| 6385 | * wrap and for a valid TSN. We can simply check if the current |
| 6386 | * SSN is smaller then the next expected one. If it is, it wrapped |
| 6387 | * and is invalid. |
| 6388 | */ |
| 6389 | ssn = ntohs(data_hdr->ssn); |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 6390 | if (ordered && SSN_lt(ssn, sctp_ssn_peek(&asoc->stream, in, sid))) |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6391 | return SCTP_IERROR_PROTO_VIOLATION; |
Vlad Yasevich | f1751c5 | 2009-09-04 18:21:03 -0400 | [diff] [blame] | 6392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6393 | /* Send the data up to the user. Note: Schedule the |
| 6394 | * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK |
| 6395 | * chunk needs the updated rwnd. |
| 6396 | */ |
| 6397 | sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk)); |
| 6398 | |
| 6399 | return SCTP_IERROR_NO_ERROR; |
| 6400 | } |