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 |
| 25 | * along with GNU CC; see the file COPYING. If not, write to |
| 26 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
| 27 | * Boston, MA 02111-1307, USA. |
| 28 | * |
| 29 | * Please send any bug reports or fixes you make to the |
| 30 | * email address(es): |
| 31 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
| 32 | * |
| 33 | * Or submit a bug report through the following website: |
| 34 | * http://www.sf.net/projects/lksctp |
| 35 | * |
| 36 | * Written or modified by: |
| 37 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 38 | * Karl Knutson <karl@athena.chicago.il.us> |
| 39 | * Mathew Kotowsky <kotowsky@sctp.org> |
| 40 | * Sridhar Samudrala <samudrala@us.ibm.com> |
| 41 | * Jon Grimm <jgrimm@us.ibm.com> |
| 42 | * Hui Huang <hui.huang@nokia.com> |
| 43 | * Dajiang Zhang <dajiang.zhang@nokia.com> |
| 44 | * Daisy Chang <daisyc@us.ibm.com> |
| 45 | * Ardelle Fan <ardelle.fan@intel.com> |
| 46 | * Ryan Layer <rmlayer@us.ibm.com> |
| 47 | * Kevin Gao <kevin.gao@intel.com> |
| 48 | * |
| 49 | * Any bugs reported given to us we will try to fix... any fixes shared will |
| 50 | * be incorporated into the next SCTP release. |
| 51 | */ |
| 52 | |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/kernel.h> |
| 55 | #include <linux/ip.h> |
| 56 | #include <linux/ipv6.h> |
| 57 | #include <linux/net.h> |
| 58 | #include <linux/inet.h> |
| 59 | #include <net/sock.h> |
| 60 | #include <net/inet_ecn.h> |
| 61 | #include <linux/skbuff.h> |
| 62 | #include <net/sctp/sctp.h> |
| 63 | #include <net/sctp/sm.h> |
| 64 | #include <net/sctp/structs.h> |
| 65 | |
| 66 | static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep, |
| 67 | const struct sctp_association *asoc, |
| 68 | struct sctp_chunk *chunk, |
| 69 | const void *payload, |
| 70 | size_t paylen); |
| 71 | static int sctp_eat_data(const struct sctp_association *asoc, |
| 72 | struct sctp_chunk *chunk, |
| 73 | sctp_cmd_seq_t *commands); |
| 74 | static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc, |
| 75 | const struct sctp_chunk *chunk); |
| 76 | static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep, |
| 77 | const struct sctp_association *asoc, |
| 78 | const struct sctp_chunk *chunk, |
| 79 | sctp_cmd_seq_t *commands, |
| 80 | struct sctp_chunk *err_chunk); |
| 81 | static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep, |
| 82 | const struct sctp_association *asoc, |
| 83 | const sctp_subtype_t type, |
| 84 | void *arg, |
| 85 | sctp_cmd_seq_t *commands); |
| 86 | static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep, |
| 87 | const struct sctp_association *asoc, |
| 88 | const sctp_subtype_t type, |
| 89 | void *arg, |
| 90 | sctp_cmd_seq_t *commands); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 91 | static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep, |
| 92 | const struct sctp_association *asoc, |
| 93 | const sctp_subtype_t type, |
| 94 | void *arg, |
| 95 | sctp_cmd_seq_t *commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk); |
| 97 | |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 98 | static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, |
Al Viro | f94c019 | 2006-11-20 17:00:25 -0800 | [diff] [blame] | 99 | __be16 error, int sk_err, |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 100 | const struct sctp_association *asoc, |
| 101 | struct sctp_transport *transport); |
| 102 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 103 | static sctp_disposition_t sctp_sf_abort_violation( |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 104 | const struct sctp_endpoint *ep, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 105 | const struct sctp_association *asoc, |
| 106 | void *arg, |
| 107 | sctp_cmd_seq_t *commands, |
| 108 | const __u8 *payload, |
| 109 | const size_t paylen); |
| 110 | |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 111 | static sctp_disposition_t sctp_sf_violation_chunklen( |
| 112 | const struct sctp_endpoint *ep, |
| 113 | const struct sctp_association *asoc, |
| 114 | const sctp_subtype_t type, |
| 115 | void *arg, |
| 116 | sctp_cmd_seq_t *commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 118 | static sctp_disposition_t sctp_sf_violation_paramlen( |
| 119 | const struct sctp_endpoint *ep, |
| 120 | const struct sctp_association *asoc, |
| 121 | const sctp_subtype_t type, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 122 | void *arg, void *ext, |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 123 | sctp_cmd_seq_t *commands); |
| 124 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 125 | static sctp_disposition_t sctp_sf_violation_ctsn( |
| 126 | const struct sctp_endpoint *ep, |
| 127 | const struct sctp_association *asoc, |
| 128 | const sctp_subtype_t type, |
| 129 | void *arg, |
| 130 | sctp_cmd_seq_t *commands); |
| 131 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 132 | static sctp_disposition_t sctp_sf_violation_chunk( |
| 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 | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 139 | static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep, |
| 140 | const struct sctp_association *asoc, |
| 141 | const sctp_subtype_t type, |
| 142 | struct sctp_chunk *chunk); |
| 143 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 144 | static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep, |
| 145 | const struct sctp_association *asoc, |
| 146 | const sctp_subtype_t type, |
| 147 | void *arg, |
| 148 | sctp_cmd_seq_t *commands); |
| 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | /* Small helper function that checks if the chunk length |
| 151 | * is of the appropriate length. The 'required_length' argument |
| 152 | * is set to be the size of a specific chunk we are testing. |
| 153 | * Return Values: 1 = Valid length |
| 154 | * 0 = Invalid length |
| 155 | * |
| 156 | */ |
| 157 | static inline int |
| 158 | sctp_chunk_length_valid(struct sctp_chunk *chunk, |
| 159 | __u16 required_length) |
| 160 | { |
| 161 | __u16 chunk_length = ntohs(chunk->chunk_hdr->length); |
| 162 | |
| 163 | if (unlikely(chunk_length < required_length)) |
| 164 | return 0; |
| 165 | |
| 166 | return 1; |
| 167 | } |
| 168 | |
| 169 | /********************************************************** |
| 170 | * These are the state functions for handling chunk events. |
| 171 | **********************************************************/ |
| 172 | |
| 173 | /* |
| 174 | * Process the final SHUTDOWN COMPLETE. |
| 175 | * |
| 176 | * Section: 4 (C) (diagram), 9.2 |
| 177 | * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify |
| 178 | * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be |
| 179 | * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint |
| 180 | * should stop the T2-shutdown timer and remove all knowledge of the |
| 181 | * association (and thus the association enters the CLOSED state). |
| 182 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 183 | * Verification Tag: 8.5.1(C), sctpimpguide 2.41. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | * C) Rules for packet carrying SHUTDOWN COMPLETE: |
| 185 | * ... |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 186 | * - The receiver of a SHUTDOWN COMPLETE shall accept the packet |
| 187 | * if the Verification Tag field of the packet matches its own tag and |
| 188 | * the T bit is not set |
| 189 | * OR |
| 190 | * it is set to its peer's tag and the T bit is set in the Chunk |
| 191 | * Flags. |
| 192 | * Otherwise, the receiver MUST silently discard the packet |
| 193 | * and take no further action. An endpoint MUST ignore the |
| 194 | * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | * |
| 196 | * Inputs |
| 197 | * (endpoint, asoc, chunk) |
| 198 | * |
| 199 | * Outputs |
| 200 | * (asoc, reply_msg, msg_up, timers, counters) |
| 201 | * |
| 202 | * The return value is the disposition of the chunk. |
| 203 | */ |
| 204 | sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep, |
| 205 | const struct sctp_association *asoc, |
| 206 | const sctp_subtype_t type, |
| 207 | void *arg, |
| 208 | sctp_cmd_seq_t *commands) |
| 209 | { |
| 210 | struct sctp_chunk *chunk = arg; |
| 211 | struct sctp_ulpevent *ev; |
| 212 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 213 | if (!sctp_vtag_verify_either(chunk, asoc)) |
| 214 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* RFC 2960 6.10 Bundling |
| 217 | * |
| 218 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 219 | * SHUTDOWN COMPLETE with any other chunks. |
| 220 | */ |
| 221 | if (!chunk->singleton) |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 222 | return sctp_sf_violation_chunk(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 224 | /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */ |
| 225 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 226 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 227 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | /* RFC 2960 10.2 SCTP-to-ULP |
| 230 | * |
| 231 | * H) SHUTDOWN COMPLETE notification |
| 232 | * |
| 233 | * When SCTP completes the shutdown procedures (section 9.2) this |
| 234 | * notification is passed to the upper layer. |
| 235 | */ |
| 236 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 237 | 0, 0, 0, NULL, GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 238 | if (ev) |
| 239 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 240 | SCTP_ULPEVENT(ev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint |
| 243 | * will verify that it is in SHUTDOWN-ACK-SENT state, if it is |
| 244 | * not the chunk should be discarded. If the endpoint is in |
| 245 | * the SHUTDOWN-ACK-SENT state the endpoint should stop the |
| 246 | * T2-shutdown timer and remove all knowledge of the |
| 247 | * association (and thus the association enters the CLOSED |
| 248 | * state). |
| 249 | */ |
| 250 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 251 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 252 | |
| 253 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 254 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 255 | |
| 256 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 257 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 258 | |
| 259 | SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); |
| 260 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 261 | |
| 262 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 263 | |
| 264 | return SCTP_DISPOSITION_DELETE_TCB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Respond to a normal INIT chunk. |
| 269 | * We are the side that is being asked for an association. |
| 270 | * |
| 271 | * Section: 5.1 Normal Establishment of an Association, B |
| 272 | * B) "Z" shall respond immediately with an INIT ACK chunk. The |
| 273 | * destination IP address of the INIT ACK MUST be set to the source |
| 274 | * IP address of the INIT to which this INIT ACK is responding. In |
| 275 | * the response, besides filling in other parameters, "Z" must set the |
| 276 | * Verification Tag field to Tag_A, and also provide its own |
| 277 | * Verification Tag (Tag_Z) in the Initiate Tag field. |
| 278 | * |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 279 | * Verification Tag: Must be 0. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | * |
| 281 | * Inputs |
| 282 | * (endpoint, asoc, chunk) |
| 283 | * |
| 284 | * Outputs |
| 285 | * (asoc, reply_msg, msg_up, timers, counters) |
| 286 | * |
| 287 | * The return value is the disposition of the chunk. |
| 288 | */ |
| 289 | sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep, |
| 290 | const struct sctp_association *asoc, |
| 291 | const sctp_subtype_t type, |
| 292 | void *arg, |
| 293 | sctp_cmd_seq_t *commands) |
| 294 | { |
| 295 | struct sctp_chunk *chunk = arg; |
| 296 | struct sctp_chunk *repl; |
| 297 | struct sctp_association *new_asoc; |
| 298 | struct sctp_chunk *err_chunk; |
| 299 | struct sctp_packet *packet; |
| 300 | sctp_unrecognized_param_t *unk_param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | int len; |
| 302 | |
| 303 | /* 6.10 Bundling |
| 304 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 305 | * SHUTDOWN COMPLETE with any other chunks. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 306 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | * IG Section 2.11.2 |
| 308 | * Furthermore, we require that the receiver of an INIT chunk MUST |
| 309 | * enforce these rules by silently discarding an arriving packet |
| 310 | * with an INIT chunk that is bundled with other chunks. |
| 311 | */ |
| 312 | if (!chunk->singleton) |
| 313 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 314 | |
| 315 | /* If the packet is an OOTB packet which is temporarily on the |
| 316 | * control endpoint, respond with an ABORT. |
| 317 | */ |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 318 | if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) { |
| 319 | SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | /* 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] | 324 | * Tag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | */ |
| 326 | if (chunk->sctp_hdr->vtag != 0) |
| 327 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
| 328 | |
| 329 | /* Make sure that the INIT chunk has a valid length. |
| 330 | * Normally, this would cause an ABORT with a Protocol Violation |
| 331 | * error, but since we don't have an association, we'll |
| 332 | * just discard the packet. |
| 333 | */ |
| 334 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t))) |
| 335 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 336 | |
Vlad Yasevich | bec9640 | 2009-07-30 18:08:28 -0400 | [diff] [blame] | 337 | /* If the INIT is coming toward a closing socket, we'll send back |
| 338 | * and ABORT. Essentially, this catches the race of INIT being |
| 339 | * backloged to the socket at the same time as the user isses close(). |
| 340 | * Since the socket and all its associations are going away, we |
| 341 | * can treat this OOTB |
| 342 | */ |
| 343 | if (sctp_sstate(ep->base.sk, CLOSING)) |
| 344 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
| 345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | /* Verify the INIT chunk before processing it. */ |
| 347 | err_chunk = NULL; |
| 348 | if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, |
| 349 | (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, |
| 350 | &err_chunk)) { |
| 351 | /* This chunk contains fatal error. It is to be discarded. |
| 352 | * Send an ABORT, with causes if there is any. |
| 353 | */ |
| 354 | if (err_chunk) { |
| 355 | packet = sctp_abort_pkt_new(ep, asoc, arg, |
| 356 | (__u8 *)(err_chunk->chunk_hdr) + |
| 357 | sizeof(sctp_chunkhdr_t), |
| 358 | ntohs(err_chunk->chunk_hdr->length) - |
| 359 | sizeof(sctp_chunkhdr_t)); |
| 360 | |
| 361 | sctp_chunk_free(err_chunk); |
| 362 | |
| 363 | if (packet) { |
| 364 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 365 | SCTP_PACKET(packet)); |
| 366 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 367 | return SCTP_DISPOSITION_CONSUME; |
| 368 | } else { |
| 369 | return SCTP_DISPOSITION_NOMEM; |
| 370 | } |
| 371 | } else { |
| 372 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, |
| 373 | commands); |
| 374 | } |
| 375 | } |
| 376 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 377 | /* Grab the INIT header. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data; |
| 379 | |
| 380 | /* Tag the variable length parameters. */ |
| 381 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); |
| 382 | |
| 383 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); |
| 384 | if (!new_asoc) |
| 385 | goto nomem; |
| 386 | |
| 387 | /* The call, sctp_process_init(), can fail on memory allocation. */ |
| 388 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, |
| 389 | sctp_source(chunk), |
| 390 | (sctp_init_chunk_t *)chunk->chunk_hdr, |
| 391 | GFP_ATOMIC)) |
| 392 | goto nomem_init; |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
| 395 | |
| 396 | /* If there are errors need to be reported for unknown parameters, |
| 397 | * make sure to reserve enough room in the INIT ACK for them. |
| 398 | */ |
| 399 | len = 0; |
| 400 | if (err_chunk) |
| 401 | len = ntohs(err_chunk->chunk_hdr->length) - |
| 402 | sizeof(sctp_chunkhdr_t); |
| 403 | |
| 404 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 405 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
| 407 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); |
| 408 | if (!repl) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 409 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* If there are errors need to be reported for unknown parameters, |
| 412 | * include them in the outgoing INIT ACK as "Unrecognized parameter" |
| 413 | * parameter. |
| 414 | */ |
| 415 | if (err_chunk) { |
| 416 | /* Get the "Unrecognized parameter" parameter(s) out of the |
| 417 | * ERROR chunk generated by sctp_verify_init(). Since the |
| 418 | * error cause code for "unknown parameter" and the |
| 419 | * "Unrecognized parameter" type is the same, we can |
| 420 | * construct the parameters in INIT ACK by copying the |
| 421 | * ERROR causes over. |
| 422 | */ |
| 423 | unk_param = (sctp_unrecognized_param_t *) |
| 424 | ((__u8 *)(err_chunk->chunk_hdr) + |
| 425 | sizeof(sctp_chunkhdr_t)); |
| 426 | /* Replace the cause code with the "Unrecognized parameter" |
| 427 | * parameter type. |
| 428 | */ |
| 429 | sctp_addto_chunk(repl, len, unk_param); |
| 430 | sctp_chunk_free(err_chunk); |
| 431 | } |
| 432 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 433 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 436 | |
| 437 | /* |
| 438 | * Note: After sending out INIT ACK with the State Cookie parameter, |
| 439 | * "Z" MUST NOT allocate any resources, nor keep any states for the |
| 440 | * new association. Otherwise, "Z" will be vulnerable to resource |
| 441 | * attacks. |
| 442 | */ |
| 443 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 444 | |
| 445 | return SCTP_DISPOSITION_DELETE_TCB; |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | nomem_init: |
| 448 | sctp_association_free(new_asoc); |
| 449 | nomem: |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 450 | if (err_chunk) |
| 451 | sctp_chunk_free(err_chunk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return SCTP_DISPOSITION_NOMEM; |
| 453 | } |
| 454 | |
| 455 | /* |
| 456 | * Respond to a normal INIT ACK chunk. |
| 457 | * We are the side that is initiating the association. |
| 458 | * |
| 459 | * Section: 5.1 Normal Establishment of an Association, C |
| 460 | * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init |
| 461 | * timer and leave COOKIE-WAIT state. "A" shall then send the State |
| 462 | * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start |
| 463 | * the T1-cookie timer, and enter the COOKIE-ECHOED state. |
| 464 | * |
| 465 | * Note: The COOKIE ECHO chunk can be bundled with any pending outbound |
| 466 | * DATA chunks, but it MUST be the first chunk in the packet and |
| 467 | * until the COOKIE ACK is returned the sender MUST NOT send any |
| 468 | * other packets to the peer. |
| 469 | * |
| 470 | * Verification Tag: 3.3.3 |
| 471 | * If the value of the Initiate Tag in a received INIT ACK chunk is |
| 472 | * found to be 0, the receiver MUST treat it as an error and close the |
| 473 | * association by transmitting an ABORT. |
| 474 | * |
| 475 | * Inputs |
| 476 | * (endpoint, asoc, chunk) |
| 477 | * |
| 478 | * Outputs |
| 479 | * (asoc, reply_msg, msg_up, timers, counters) |
| 480 | * |
| 481 | * The return value is the disposition of the chunk. |
| 482 | */ |
| 483 | sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep, |
| 484 | const struct sctp_association *asoc, |
| 485 | const sctp_subtype_t type, |
| 486 | void *arg, |
| 487 | sctp_cmd_seq_t *commands) |
| 488 | { |
| 489 | struct sctp_chunk *chunk = arg; |
| 490 | sctp_init_chunk_t *initchunk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | struct sctp_chunk *err_chunk; |
| 492 | struct sctp_packet *packet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | if (!sctp_vtag_verify(chunk, asoc)) |
| 495 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | /* 6.10 Bundling |
| 498 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 499 | * SHUTDOWN COMPLETE with any other chunks. |
| 500 | */ |
| 501 | if (!chunk->singleton) |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 502 | return sctp_sf_violation_chunk(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 504 | /* Make sure that the INIT-ACK chunk has a valid length */ |
| 505 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t))) |
| 506 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 507 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | /* Grab the INIT header. */ |
| 509 | chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data; |
| 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | /* Verify the INIT chunk before processing it. */ |
| 512 | err_chunk = NULL; |
| 513 | if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, |
| 514 | (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, |
| 515 | &err_chunk)) { |
| 516 | |
Vlad Yasevich | 853f4b5 | 2008-01-20 06:10:46 -0800 | [diff] [blame] | 517 | sctp_error_t error = SCTP_ERROR_NO_RESOURCE; |
| 518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | /* This chunk contains fatal error. It is to be discarded. |
Vlad Yasevich | d670119 | 2007-12-20 14:13:31 -0800 | [diff] [blame] | 520 | * Send an ABORT, with causes. If there are no causes, |
| 521 | * then there wasn't enough memory. Just terminate |
| 522 | * the association. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | */ |
| 524 | if (err_chunk) { |
| 525 | packet = sctp_abort_pkt_new(ep, asoc, arg, |
| 526 | (__u8 *)(err_chunk->chunk_hdr) + |
| 527 | sizeof(sctp_chunkhdr_t), |
| 528 | ntohs(err_chunk->chunk_hdr->length) - |
| 529 | sizeof(sctp_chunkhdr_t)); |
| 530 | |
| 531 | sctp_chunk_free(err_chunk); |
| 532 | |
| 533 | if (packet) { |
| 534 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 535 | SCTP_PACKET(packet)); |
| 536 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 537 | error = SCTP_ERROR_INV_PARAM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 540 | |
| 541 | /* SCTP-AUTH, Section 6.3: |
| 542 | * It should be noted that if the receiver wants to tear |
| 543 | * down an association in an authenticated way only, the |
| 544 | * handling of malformed packets should not result in |
| 545 | * tearing down the association. |
| 546 | * |
| 547 | * This means that if we only want to abort associations |
| 548 | * in an authenticated way (i.e AUTH+ABORT), then we |
Oliver Pinter | ac461a0 | 2008-02-03 17:52:41 +0200 | [diff] [blame] | 549 | * can't destroy this association just becuase the packet |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 550 | * was malformed. |
| 551 | */ |
| 552 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 553 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 554 | |
| 555 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 556 | return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, |
| 557 | asoc, chunk->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* Tag the variable length parameters. Note that we never |
| 561 | * convert the parameters in an INIT chunk. |
| 562 | */ |
| 563 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); |
| 564 | |
| 565 | initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr; |
| 566 | |
| 567 | sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT, |
| 568 | SCTP_PEER_INIT(initchunk)); |
| 569 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 570 | /* Reset init error count upon receipt of INIT-ACK. */ |
| 571 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
| 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* 5.1 C) "A" shall stop the T1-init timer and leave |
| 574 | * COOKIE-WAIT state. "A" shall then ... start the T1-cookie |
| 575 | * timer, and enter the COOKIE-ECHOED state. |
| 576 | */ |
| 577 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 578 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 579 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 580 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 581 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 582 | SCTP_STATE(SCTP_STATE_COOKIE_ECHOED)); |
| 583 | |
Vlad Yasevich | 730fc3d | 2007-09-16 19:32:11 -0700 | [diff] [blame] | 584 | /* SCTP-AUTH: genereate the assocition shared keys so that |
| 585 | * we can potentially signe the COOKIE-ECHO. |
| 586 | */ |
| 587 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL()); |
| 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | /* 5.1 C) "A" shall then send the State Cookie received in the |
| 590 | * INIT ACK chunk in a COOKIE ECHO chunk, ... |
| 591 | */ |
| 592 | /* If there is any errors to report, send the ERROR chunk generated |
| 593 | * for unknown parameters as well. |
| 594 | */ |
| 595 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO, |
| 596 | SCTP_CHUNK(err_chunk)); |
| 597 | |
| 598 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* |
| 602 | * Respond to a normal COOKIE ECHO chunk. |
| 603 | * We are the side that is being asked for an association. |
| 604 | * |
| 605 | * Section: 5.1 Normal Establishment of an Association, D |
| 606 | * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply |
| 607 | * with a COOKIE ACK chunk after building a TCB and moving to |
| 608 | * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with |
| 609 | * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK |
| 610 | * chunk MUST be the first chunk in the packet. |
| 611 | * |
| 612 | * IMPLEMENTATION NOTE: An implementation may choose to send the |
| 613 | * Communication Up notification to the SCTP user upon reception |
| 614 | * of a valid COOKIE ECHO chunk. |
| 615 | * |
| 616 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules |
| 617 | * D) Rules for packet carrying a COOKIE ECHO |
| 618 | * |
| 619 | * - When sending a COOKIE ECHO, the endpoint MUST use the value of the |
| 620 | * Initial Tag received in the INIT ACK. |
| 621 | * |
| 622 | * - The receiver of a COOKIE ECHO follows the procedures in Section 5. |
| 623 | * |
| 624 | * Inputs |
| 625 | * (endpoint, asoc, chunk) |
| 626 | * |
| 627 | * Outputs |
| 628 | * (asoc, reply_msg, msg_up, timers, counters) |
| 629 | * |
| 630 | * The return value is the disposition of the chunk. |
| 631 | */ |
| 632 | sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep, |
| 633 | const struct sctp_association *asoc, |
| 634 | const sctp_subtype_t type, void *arg, |
| 635 | sctp_cmd_seq_t *commands) |
| 636 | { |
| 637 | struct sctp_chunk *chunk = arg; |
| 638 | struct sctp_association *new_asoc; |
| 639 | sctp_init_chunk_t *peer_init; |
| 640 | struct sctp_chunk *repl; |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 641 | struct sctp_ulpevent *ev, *ai_ev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | int error = 0; |
| 643 | struct sctp_chunk *err_chk_p; |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 644 | struct sock *sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
| 646 | /* If the packet is an OOTB packet which is temporarily on the |
| 647 | * control endpoint, respond with an ABORT. |
| 648 | */ |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 649 | if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) { |
| 650 | SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES); |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 651 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | /* Make sure that the COOKIE_ECHO chunk has a valid length. |
| 655 | * In this case, we check that we have enough for at least a |
| 656 | * chunk header. More detailed verification is done |
| 657 | * in sctp_unpack_cookie(). |
| 658 | */ |
| 659 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 660 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 661 | |
Vlad Yasevich | 609ee46 | 2007-08-31 03:10:59 +0900 | [diff] [blame] | 662 | /* If the endpoint is not listening or if the number of associations |
| 663 | * on the TCP-style socket exceed the max backlog, respond with an |
| 664 | * ABORT. |
| 665 | */ |
| 666 | sk = ep->base.sk; |
| 667 | if (!sctp_sstate(sk, LISTENING) || |
| 668 | (sctp_style(sk, TCP) && sk_acceptq_is_full(sk))) |
| 669 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* "Decode" the chunk. We have no optional parameters so we |
| 672 | * are in good shape. |
| 673 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 674 | chunk->subh.cookie_hdr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | (struct sctp_signed_cookie *)chunk->skb->data; |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 676 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
| 677 | sizeof(sctp_chunkhdr_t))) |
| 678 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint |
| 681 | * "Z" will reply with a COOKIE ACK chunk after building a TCB |
| 682 | * and moving to the ESTABLISHED state. |
| 683 | */ |
| 684 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, |
| 685 | &err_chk_p); |
| 686 | |
| 687 | /* FIXME: |
| 688 | * If the re-build failed, what is the proper error path |
| 689 | * from here? |
| 690 | * |
| 691 | * [We should abort the association. --piggy] |
| 692 | */ |
| 693 | if (!new_asoc) { |
| 694 | /* FIXME: Several errors are possible. A bad cookie should |
| 695 | * be silently discarded, but think about logging it too. |
| 696 | */ |
| 697 | switch (error) { |
| 698 | case -SCTP_IERROR_NOMEM: |
| 699 | goto nomem; |
| 700 | |
| 701 | case -SCTP_IERROR_STALE_COOKIE: |
| 702 | sctp_send_stale_cookie_err(ep, asoc, chunk, commands, |
| 703 | err_chk_p); |
| 704 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 705 | |
| 706 | case -SCTP_IERROR_BAD_SIG: |
| 707 | default: |
| 708 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 709 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 713 | /* Delay state machine commands until later. |
| 714 | * |
| 715 | * Re-build the bind address for the association is done in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | * the sctp_unpack_cookie() already. |
| 717 | */ |
| 718 | /* This is a brand-new association, so these are not yet side |
| 719 | * effects--it is safe to run them here. |
| 720 | */ |
| 721 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 722 | |
| 723 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, |
Al Viro | 6a1e5f3 | 2006-11-20 17:12:25 -0800 | [diff] [blame] | 724 | &chunk->subh.cookie_hdr->c.peer_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | peer_init, GFP_ATOMIC)) |
| 726 | goto nomem_init; |
| 727 | |
Vlad Yasevich | 730fc3d | 2007-09-16 19:32:11 -0700 | [diff] [blame] | 728 | /* SCTP-AUTH: Now that we've populate required fields in |
| 729 | * sctp_process_init, set up the assocaition shared keys as |
| 730 | * necessary so that we can potentially authenticate the ACK |
| 731 | */ |
| 732 | error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC); |
| 733 | if (error) |
| 734 | goto nomem_init; |
| 735 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 736 | /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo |
| 737 | * is supposed to be authenticated and we have to do delayed |
| 738 | * authentication. We've just recreated the association using |
| 739 | * the information in the cookie and now it's much easier to |
| 740 | * do the authentication. |
| 741 | */ |
| 742 | if (chunk->auth_chunk) { |
| 743 | struct sctp_chunk auth; |
| 744 | sctp_ierror_t ret; |
| 745 | |
| 746 | /* set-up our fake chunk so that we can process it */ |
| 747 | auth.skb = chunk->auth_chunk; |
| 748 | auth.asoc = chunk->asoc; |
| 749 | auth.sctp_hdr = chunk->sctp_hdr; |
| 750 | auth.chunk_hdr = (sctp_chunkhdr_t *)skb_push(chunk->auth_chunk, |
| 751 | sizeof(sctp_chunkhdr_t)); |
| 752 | skb_pull(chunk->auth_chunk, sizeof(sctp_chunkhdr_t)); |
| 753 | auth.transport = chunk->transport; |
| 754 | |
| 755 | ret = sctp_sf_authenticate(ep, new_asoc, type, &auth); |
| 756 | |
| 757 | /* We can now safely free the auth_chunk clone */ |
| 758 | kfree_skb(chunk->auth_chunk); |
| 759 | |
| 760 | if (ret != SCTP_IERROR_NO_ERROR) { |
| 761 | sctp_association_free(new_asoc); |
| 762 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 763 | } |
| 764 | } |
| 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 767 | if (!repl) |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 768 | goto nomem_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 771 | * |
| 772 | * D) IMPLEMENTATION NOTE: An implementation may choose to |
| 773 | * send the Communication Up notification to the SCTP user |
| 774 | * upon reception of a valid COOKIE ECHO chunk. |
| 775 | */ |
| 776 | ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0, |
| 777 | new_asoc->c.sinit_num_ostreams, |
| 778 | new_asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 779 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | if (!ev) |
| 781 | goto nomem_ev; |
| 782 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 783 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 784 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 786 | * peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 788 | if (new_asoc->peer.adaptation_ind) { |
| 789 | ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 791 | if (!ai_ev) |
| 792 | goto nomem_aiev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 795 | /* Add all the state machine commands now since we've created |
| 796 | * everything. This way we don't introduce memory corruptions |
| 797 | * during side-effect processing and correclty count established |
| 798 | * associations. |
| 799 | */ |
| 800 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 801 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 802 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
| 803 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); |
| 804 | SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS); |
| 805 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 806 | |
| 807 | if (new_asoc->autoclose) |
| 808 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 809 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 810 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 811 | /* This will send the COOKIE ACK */ |
| 812 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 813 | |
| 814 | /* Queue the ASSOC_CHANGE event */ |
| 815 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 816 | |
| 817 | /* Send up the Adaptation Layer Indication event */ |
| 818 | if (ai_ev) |
| 819 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 820 | SCTP_ULPEVENT(ai_ev)); |
| 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | return SCTP_DISPOSITION_CONSUME; |
| 823 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 824 | nomem_aiev: |
| 825 | sctp_ulpevent_free(ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | nomem_ev: |
| 827 | sctp_chunk_free(repl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | nomem_init: |
| 829 | sctp_association_free(new_asoc); |
| 830 | nomem: |
| 831 | return SCTP_DISPOSITION_NOMEM; |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | * Respond to a normal COOKIE ACK chunk. |
| 836 | * We are the side that is being asked for an association. |
| 837 | * |
| 838 | * RFC 2960 5.1 Normal Establishment of an Association |
| 839 | * |
| 840 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the |
| 841 | * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie |
| 842 | * timer. It may also notify its ULP about the successful |
| 843 | * establishment of the association with a Communication Up |
| 844 | * notification (see Section 10). |
| 845 | * |
| 846 | * Verification Tag: |
| 847 | * Inputs |
| 848 | * (endpoint, asoc, chunk) |
| 849 | * |
| 850 | * Outputs |
| 851 | * (asoc, reply_msg, msg_up, timers, counters) |
| 852 | * |
| 853 | * The return value is the disposition of the chunk. |
| 854 | */ |
| 855 | sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep, |
| 856 | const struct sctp_association *asoc, |
| 857 | const sctp_subtype_t type, void *arg, |
| 858 | sctp_cmd_seq_t *commands) |
| 859 | { |
| 860 | struct sctp_chunk *chunk = arg; |
| 861 | struct sctp_ulpevent *ev; |
| 862 | |
| 863 | if (!sctp_vtag_verify(chunk, asoc)) |
| 864 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 865 | |
| 866 | /* Verify that the chunk length for the COOKIE-ACK is OK. |
| 867 | * If we don't do this, any bundled chunks may be junked. |
| 868 | */ |
| 869 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 870 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 871 | commands); |
| 872 | |
| 873 | /* Reset init error count upon receipt of COOKIE-ACK, |
| 874 | * to avoid problems with the managemement of this |
| 875 | * counter in stale cookie situations when a transition back |
| 876 | * from the COOKIE-ECHOED state to the COOKIE-WAIT |
| 877 | * state is performed. |
| 878 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 879 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 882 | * |
| 883 | * E) Upon reception of the COOKIE ACK, endpoint "A" will move |
| 884 | * from the COOKIE-ECHOED state to the ESTABLISHED state, |
| 885 | * stopping the T1-cookie timer. |
| 886 | */ |
| 887 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 888 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 889 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 890 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
| 891 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); |
| 892 | SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS); |
| 893 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 894 | if (asoc->autoclose) |
| 895 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 896 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | /* It may also notify its ULP about the successful |
| 899 | * establishment of the association with a Communication Up |
| 900 | * notification (see Section 10). |
| 901 | */ |
| 902 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, |
| 903 | 0, asoc->c.sinit_num_ostreams, |
| 904 | asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 905 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | if (!ev) |
| 908 | goto nomem; |
| 909 | |
| 910 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 911 | |
| 912 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 913 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 915 | * peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 917 | if (asoc->peer.adaptation_ind) { |
| 918 | ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | if (!ev) |
| 920 | goto nomem; |
| 921 | |
| 922 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 923 | SCTP_ULPEVENT(ev)); |
| 924 | } |
| 925 | |
| 926 | return SCTP_DISPOSITION_CONSUME; |
| 927 | nomem: |
| 928 | return SCTP_DISPOSITION_NOMEM; |
| 929 | } |
| 930 | |
| 931 | /* Generate and sendout a heartbeat packet. */ |
| 932 | static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep, |
| 933 | const struct sctp_association *asoc, |
| 934 | const sctp_subtype_t type, |
| 935 | void *arg, |
| 936 | sctp_cmd_seq_t *commands) |
| 937 | { |
| 938 | struct sctp_transport *transport = (struct sctp_transport *) arg; |
| 939 | struct sctp_chunk *reply; |
| 940 | sctp_sender_hb_info_t hbinfo; |
| 941 | size_t paylen = 0; |
| 942 | |
| 943 | hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO; |
| 944 | hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t)); |
Al Viro | 63de08f | 2006-11-20 17:07:25 -0800 | [diff] [blame] | 945 | hbinfo.daddr = transport->ipaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | hbinfo.sent_at = jiffies; |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 947 | hbinfo.hb_nonce = transport->hb_nonce; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| 949 | /* Send a heartbeat to our peer. */ |
| 950 | paylen = sizeof(sctp_sender_hb_info_t); |
| 951 | reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen); |
| 952 | if (!reply) |
| 953 | return SCTP_DISPOSITION_NOMEM; |
| 954 | |
| 955 | /* Set rto_pending indicating that an RTT measurement |
| 956 | * is started with this heartbeat chunk. |
| 957 | */ |
| 958 | sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING, |
| 959 | SCTP_TRANSPORT(transport)); |
| 960 | |
| 961 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 962 | return SCTP_DISPOSITION_CONSUME; |
| 963 | } |
| 964 | |
| 965 | /* Generate a HEARTBEAT packet on the given transport. */ |
| 966 | sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep, |
| 967 | const struct sctp_association *asoc, |
| 968 | const sctp_subtype_t type, |
| 969 | void *arg, |
| 970 | sctp_cmd_seq_t *commands) |
| 971 | { |
| 972 | struct sctp_transport *transport = (struct sctp_transport *) arg; |
| 973 | |
Vlad Yasevich | fd10279 | 2007-11-15 12:13:32 -0500 | [diff] [blame] | 974 | if (asoc->overall_error_count > asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 975 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 976 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 978 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 979 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 981 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 982 | return SCTP_DISPOSITION_DELETE_TCB; |
| 983 | } |
| 984 | |
| 985 | /* Section 3.3.5. |
| 986 | * The Sender-specific Heartbeat Info field should normally include |
| 987 | * information about the sender's current time when this HEARTBEAT |
| 988 | * chunk is sent and the destination transport address to which this |
| 989 | * HEARTBEAT is sent (see Section 8.3). |
| 990 | */ |
| 991 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 992 | if (transport->param_flags & SPP_HB_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | if (SCTP_DISPOSITION_NOMEM == |
| 994 | sctp_sf_heartbeat(ep, asoc, type, arg, |
| 995 | commands)) |
| 996 | return SCTP_DISPOSITION_NOMEM; |
| 997 | /* Set transport error counter and association error counter |
| 998 | * when sending heartbeat. |
| 999 | */ |
Vlad Yasevich | 7e99013 | 2009-03-02 09:46:14 +0000 | [diff] [blame] | 1000 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE, |
| 1001 | SCTP_TRANSPORT(transport)); |
| 1002 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | SCTP_TRANSPORT(transport)); |
| 1004 | } |
| 1005 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE, |
| 1006 | SCTP_TRANSPORT(transport)); |
| 1007 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1008 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * Process an heartbeat request. |
| 1013 | * |
| 1014 | * Section: 8.3 Path Heartbeat |
| 1015 | * The receiver of the HEARTBEAT should immediately respond with a |
| 1016 | * HEARTBEAT ACK that contains the Heartbeat Information field copied |
| 1017 | * from the received HEARTBEAT chunk. |
| 1018 | * |
| 1019 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 1020 | * When receiving an SCTP packet, the endpoint MUST ensure that the |
| 1021 | * value in the Verification Tag field of the received SCTP packet |
| 1022 | * matches its own Tag. If the received Verification Tag value does not |
| 1023 | * match the receiver's own tag value, the receiver shall silently |
| 1024 | * discard the packet and shall not process it any further except for |
| 1025 | * those cases listed in Section 8.5.1 below. |
| 1026 | * |
| 1027 | * Inputs |
| 1028 | * (endpoint, asoc, chunk) |
| 1029 | * |
| 1030 | * Outputs |
| 1031 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1032 | * |
| 1033 | * The return value is the disposition of the chunk. |
| 1034 | */ |
| 1035 | sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep, |
| 1036 | const struct sctp_association *asoc, |
| 1037 | const sctp_subtype_t type, |
| 1038 | void *arg, |
| 1039 | sctp_cmd_seq_t *commands) |
| 1040 | { |
| 1041 | struct sctp_chunk *chunk = arg; |
| 1042 | struct sctp_chunk *reply; |
| 1043 | size_t paylen = 0; |
| 1044 | |
| 1045 | if (!sctp_vtag_verify(chunk, asoc)) |
| 1046 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 1047 | |
| 1048 | /* Make sure that the HEARTBEAT chunk has a valid length. */ |
| 1049 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t))) |
| 1050 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 1051 | commands); |
| 1052 | |
| 1053 | /* 8.3 The receiver of the HEARTBEAT should immediately |
| 1054 | * respond with a HEARTBEAT ACK that contains the Heartbeat |
| 1055 | * Information field copied from the received HEARTBEAT chunk. |
| 1056 | */ |
| 1057 | chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data; |
| 1058 | paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t); |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 1059 | if (!pskb_pull(chunk->skb, paylen)) |
| 1060 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | |
| 1062 | reply = sctp_make_heartbeat_ack(asoc, chunk, |
| 1063 | chunk->subh.hb_hdr, paylen); |
| 1064 | if (!reply) |
| 1065 | goto nomem; |
| 1066 | |
| 1067 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 1068 | return SCTP_DISPOSITION_CONSUME; |
| 1069 | |
| 1070 | nomem: |
| 1071 | return SCTP_DISPOSITION_NOMEM; |
| 1072 | } |
| 1073 | |
| 1074 | /* |
| 1075 | * Process the returning HEARTBEAT ACK. |
| 1076 | * |
| 1077 | * Section: 8.3 Path Heartbeat |
| 1078 | * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT |
| 1079 | * should clear the error counter of the destination transport |
| 1080 | * address to which the HEARTBEAT was sent, and mark the destination |
| 1081 | * transport address as active if it is not so marked. The endpoint may |
| 1082 | * optionally report to the upper layer when an inactive destination |
| 1083 | * address is marked as active due to the reception of the latest |
| 1084 | * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also |
| 1085 | * clear the association overall error count as well (as defined |
| 1086 | * in section 8.1). |
| 1087 | * |
| 1088 | * The receiver of the HEARTBEAT ACK should also perform an RTT |
| 1089 | * measurement for that destination transport address using the time |
| 1090 | * value carried in the HEARTBEAT ACK chunk. |
| 1091 | * |
| 1092 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 1093 | * |
| 1094 | * Inputs |
| 1095 | * (endpoint, asoc, chunk) |
| 1096 | * |
| 1097 | * Outputs |
| 1098 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1099 | * |
| 1100 | * The return value is the disposition of the chunk. |
| 1101 | */ |
| 1102 | sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep, |
| 1103 | const struct sctp_association *asoc, |
| 1104 | const sctp_subtype_t type, |
| 1105 | void *arg, |
| 1106 | sctp_cmd_seq_t *commands) |
| 1107 | { |
| 1108 | struct sctp_chunk *chunk = arg; |
| 1109 | union sctp_addr from_addr; |
| 1110 | struct sctp_transport *link; |
| 1111 | sctp_sender_hb_info_t *hbinfo; |
| 1112 | unsigned long max_interval; |
| 1113 | |
| 1114 | if (!sctp_vtag_verify(chunk, asoc)) |
| 1115 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 1116 | |
| 1117 | /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */ |
| 1118 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t))) |
| 1119 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 1120 | commands); |
| 1121 | |
| 1122 | hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data; |
Vladislav Yasevich | a601266 | 2006-05-19 14:25:53 -0700 | [diff] [blame] | 1123 | /* Make sure that the length of the parameter is what we expect */ |
| 1124 | if (ntohs(hbinfo->param_hdr.length) != |
| 1125 | sizeof(sctp_sender_hb_info_t)) { |
| 1126 | return SCTP_DISPOSITION_DISCARD; |
| 1127 | } |
| 1128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | from_addr = hbinfo->daddr; |
Al Viro | 63de08f | 2006-11-20 17:07:25 -0800 | [diff] [blame] | 1130 | link = sctp_assoc_lookup_paddr(asoc, &from_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* This should never happen, but lets log it if so. */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1133 | if (unlikely(!link)) { |
| 1134 | if (from_addr.sa.sa_family == AF_INET6) { |
Wei Yongjun | d99fa42 | 2007-08-27 11:19:24 +0800 | [diff] [blame] | 1135 | if (net_ratelimit()) |
| 1136 | printk(KERN_WARNING |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 1137 | "%s association %p could not find address %pI6\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1138 | __func__, |
Wei Yongjun | d99fa42 | 2007-08-27 11:19:24 +0800 | [diff] [blame] | 1139 | asoc, |
Harvey Harrison | fdb46ee | 2008-10-28 16:10:17 -0700 | [diff] [blame] | 1140 | &from_addr.v6.sin6_addr); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1141 | } else { |
Wei Yongjun | d99fa42 | 2007-08-27 11:19:24 +0800 | [diff] [blame] | 1142 | if (net_ratelimit()) |
| 1143 | printk(KERN_WARNING |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 1144 | "%s association %p could not find address %pI4\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1145 | __func__, |
Wei Yongjun | d99fa42 | 2007-08-27 11:19:24 +0800 | [diff] [blame] | 1146 | asoc, |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 1147 | &from_addr.v4.sin_addr.s_addr); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 1148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | return SCTP_DISPOSITION_DISCARD; |
| 1150 | } |
| 1151 | |
Sridhar Samudrala | ad8fec1 | 2006-07-21 14:48:50 -0700 | [diff] [blame] | 1152 | /* Validate the 64-bit random nonce. */ |
| 1153 | if (hbinfo->hb_nonce != link->hb_nonce) |
| 1154 | return SCTP_DISPOSITION_DISCARD; |
| 1155 | |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 1156 | max_interval = link->hbinterval + link->rto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
| 1158 | /* Check if the timestamp looks valid. */ |
| 1159 | if (time_after(hbinfo->sent_at, jiffies) || |
| 1160 | time_after(jiffies, hbinfo->sent_at + max_interval)) { |
Joe Perches | 9ee46f1 | 2007-11-19 23:47:47 -0800 | [diff] [blame] | 1161 | SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | "received for transport: %p\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 1163 | __func__, link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | return SCTP_DISPOSITION_DISCARD; |
| 1165 | } |
| 1166 | |
| 1167 | /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of |
| 1168 | * the HEARTBEAT should clear the error counter of the |
| 1169 | * destination transport address to which the HEARTBEAT was |
| 1170 | * sent and mark the destination transport address as active if |
| 1171 | * it is not so marked. |
| 1172 | */ |
| 1173 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link)); |
| 1174 | |
| 1175 | return SCTP_DISPOSITION_CONSUME; |
| 1176 | } |
| 1177 | |
| 1178 | /* Helper function to send out an abort for the restart |
| 1179 | * condition. |
| 1180 | */ |
| 1181 | static int sctp_sf_send_restart_abort(union sctp_addr *ssa, |
| 1182 | struct sctp_chunk *init, |
| 1183 | sctp_cmd_seq_t *commands) |
| 1184 | { |
| 1185 | int len; |
| 1186 | struct sctp_packet *pkt; |
| 1187 | union sctp_addr_param *addrparm; |
| 1188 | struct sctp_errhdr *errhdr; |
| 1189 | struct sctp_endpoint *ep; |
| 1190 | char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)]; |
| 1191 | struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family); |
| 1192 | |
| 1193 | /* Build the error on the stack. We are way to malloc crazy |
| 1194 | * throughout the code today. |
| 1195 | */ |
| 1196 | errhdr = (struct sctp_errhdr *)buffer; |
| 1197 | addrparm = (union sctp_addr_param *)errhdr->variable; |
| 1198 | |
| 1199 | /* Copy into a parm format. */ |
| 1200 | len = af->to_addr_param(ssa, addrparm); |
| 1201 | len += sizeof(sctp_errhdr_t); |
| 1202 | |
| 1203 | errhdr->cause = SCTP_ERROR_RESTART; |
| 1204 | errhdr->length = htons(len); |
| 1205 | |
| 1206 | /* Assign to the control socket. */ |
| 1207 | ep = sctp_sk((sctp_get_ctl_sock()))->ep; |
| 1208 | |
| 1209 | /* Association is NULL since this may be a restart attack and we |
| 1210 | * want to send back the attacker's vtag. |
| 1211 | */ |
| 1212 | pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len); |
| 1213 | |
| 1214 | if (!pkt) |
| 1215 | goto out; |
| 1216 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt)); |
| 1217 | |
| 1218 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 1219 | |
| 1220 | /* Discard the rest of the inbound packet. */ |
| 1221 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
| 1222 | |
| 1223 | out: |
| 1224 | /* Even if there is no memory, treat as a failure so |
| 1225 | * the packet will get dropped. |
| 1226 | */ |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | /* A restart is occurring, check to make sure no new addresses |
| 1231 | * are being added as we may be under a takeover attack. |
| 1232 | */ |
| 1233 | static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc, |
| 1234 | const struct sctp_association *asoc, |
| 1235 | struct sctp_chunk *init, |
| 1236 | sctp_cmd_seq_t *commands) |
| 1237 | { |
| 1238 | struct sctp_transport *new_addr, *addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | int found; |
| 1240 | |
| 1241 | /* Implementor's Guide - Sectin 5.2.2 |
| 1242 | * ... |
| 1243 | * Before responding the endpoint MUST check to see if the |
| 1244 | * unexpected INIT adds new addresses to the association. If new |
| 1245 | * addresses are added to the association, the endpoint MUST respond |
| 1246 | * with an ABORT.. |
| 1247 | */ |
| 1248 | |
| 1249 | /* Search through all current addresses and make sure |
| 1250 | * we aren't adding any new ones. |
| 1251 | */ |
| 1252 | new_addr = NULL; |
| 1253 | found = 0; |
| 1254 | |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1255 | list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list, |
| 1256 | transports) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | found = 0; |
Robert P. J. Day | 9dbc15f | 2008-04-12 18:54:24 -0700 | [diff] [blame] | 1258 | list_for_each_entry(addr, &asoc->peer.transport_addr_list, |
| 1259 | transports) { |
Al Viro | 5f242a1 | 2006-11-20 17:05:23 -0800 | [diff] [blame] | 1260 | if (sctp_cmp_addr_exact(&new_addr->ipaddr, |
| 1261 | &addr->ipaddr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | found = 1; |
| 1263 | break; |
| 1264 | } |
| 1265 | } |
| 1266 | if (!found) |
| 1267 | break; |
| 1268 | } |
| 1269 | |
| 1270 | /* If a new address was added, ABORT the sender. */ |
| 1271 | if (!found && new_addr) { |
Al Viro | 7dd8a58 | 2006-11-20 17:23:25 -0800 | [diff] [blame] | 1272 | sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /* Return success if all addresses were found. */ |
| 1276 | return found; |
| 1277 | } |
| 1278 | |
| 1279 | /* Populate the verification/tie tags based on overlapping INIT |
| 1280 | * scenario. |
| 1281 | * |
| 1282 | * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state. |
| 1283 | */ |
| 1284 | static void sctp_tietags_populate(struct sctp_association *new_asoc, |
| 1285 | const struct sctp_association *asoc) |
| 1286 | { |
| 1287 | switch (asoc->state) { |
| 1288 | |
| 1289 | /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */ |
| 1290 | |
| 1291 | case SCTP_STATE_COOKIE_WAIT: |
| 1292 | new_asoc->c.my_vtag = asoc->c.my_vtag; |
| 1293 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1294 | new_asoc->c.peer_ttag = 0; |
| 1295 | break; |
| 1296 | |
| 1297 | case SCTP_STATE_COOKIE_ECHOED: |
| 1298 | new_asoc->c.my_vtag = asoc->c.my_vtag; |
| 1299 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1300 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; |
| 1301 | break; |
| 1302 | |
| 1303 | /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED, |
| 1304 | * COOKIE-WAIT and SHUTDOWN-ACK-SENT |
| 1305 | */ |
| 1306 | default: |
| 1307 | new_asoc->c.my_ttag = asoc->c.my_vtag; |
| 1308 | new_asoc->c.peer_ttag = asoc->c.peer_vtag; |
| 1309 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 1310 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
| 1312 | /* Other parameters for the endpoint SHOULD be copied from the |
| 1313 | * existing parameters of the association (e.g. number of |
| 1314 | * outbound streams) into the INIT ACK and cookie. |
| 1315 | */ |
| 1316 | new_asoc->rwnd = asoc->rwnd; |
| 1317 | new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams; |
| 1318 | new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams; |
| 1319 | new_asoc->c.initial_tsn = asoc->c.initial_tsn; |
| 1320 | } |
| 1321 | |
| 1322 | /* |
| 1323 | * Compare vtag/tietag values to determine unexpected COOKIE-ECHO |
| 1324 | * handling action. |
| 1325 | * |
| 1326 | * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists. |
| 1327 | * |
| 1328 | * Returns value representing action to be taken. These action values |
| 1329 | * correspond to Action/Description values in RFC 2960, Table 2. |
| 1330 | */ |
| 1331 | static char sctp_tietags_compare(struct sctp_association *new_asoc, |
| 1332 | const struct sctp_association *asoc) |
| 1333 | { |
| 1334 | /* In this case, the peer may have restarted. */ |
| 1335 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && |
| 1336 | (asoc->c.peer_vtag != new_asoc->c.peer_vtag) && |
| 1337 | (asoc->c.my_vtag == new_asoc->c.my_ttag) && |
| 1338 | (asoc->c.peer_vtag == new_asoc->c.peer_ttag)) |
| 1339 | return 'A'; |
| 1340 | |
| 1341 | /* Collision case B. */ |
| 1342 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && |
| 1343 | ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) || |
| 1344 | (0 == asoc->c.peer_vtag))) { |
| 1345 | return 'B'; |
| 1346 | } |
| 1347 | |
| 1348 | /* Collision case D. */ |
| 1349 | if ((asoc->c.my_vtag == new_asoc->c.my_vtag) && |
| 1350 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag)) |
| 1351 | return 'D'; |
| 1352 | |
| 1353 | /* Collision case C. */ |
| 1354 | if ((asoc->c.my_vtag != new_asoc->c.my_vtag) && |
| 1355 | (asoc->c.peer_vtag == new_asoc->c.peer_vtag) && |
| 1356 | (0 == new_asoc->c.my_ttag) && |
| 1357 | (0 == new_asoc->c.peer_ttag)) |
| 1358 | return 'C'; |
| 1359 | |
| 1360 | /* No match to any of the special cases; discard this packet. */ |
| 1361 | return 'E'; |
| 1362 | } |
| 1363 | |
| 1364 | /* Common helper routine for both duplicate and simulataneous INIT |
| 1365 | * chunk handling. |
| 1366 | */ |
| 1367 | static sctp_disposition_t sctp_sf_do_unexpected_init( |
| 1368 | const struct sctp_endpoint *ep, |
| 1369 | const struct sctp_association *asoc, |
| 1370 | const sctp_subtype_t type, |
| 1371 | void *arg, sctp_cmd_seq_t *commands) |
| 1372 | { |
| 1373 | sctp_disposition_t retval; |
| 1374 | struct sctp_chunk *chunk = arg; |
| 1375 | struct sctp_chunk *repl; |
| 1376 | struct sctp_association *new_asoc; |
| 1377 | struct sctp_chunk *err_chunk; |
| 1378 | struct sctp_packet *packet; |
| 1379 | sctp_unrecognized_param_t *unk_param; |
| 1380 | int len; |
| 1381 | |
| 1382 | /* 6.10 Bundling |
| 1383 | * An endpoint MUST NOT bundle INIT, INIT ACK or |
| 1384 | * SHUTDOWN COMPLETE with any other chunks. |
| 1385 | * |
| 1386 | * IG Section 2.11.2 |
| 1387 | * Furthermore, we require that the receiver of an INIT chunk MUST |
| 1388 | * enforce these rules by silently discarding an arriving packet |
| 1389 | * with an INIT chunk that is bundled with other chunks. |
| 1390 | */ |
| 1391 | if (!chunk->singleton) |
| 1392 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 1393 | |
| 1394 | /* 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] | 1395 | * Tag. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | */ |
| 1397 | if (chunk->sctp_hdr->vtag != 0) |
| 1398 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
| 1399 | |
| 1400 | /* Make sure that the INIT chunk has a valid length. |
| 1401 | * In this case, we generate a protocol violation since we have |
| 1402 | * an association established. |
| 1403 | */ |
| 1404 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t))) |
| 1405 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 1406 | commands); |
| 1407 | /* Grab the INIT header. */ |
| 1408 | chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data; |
| 1409 | |
| 1410 | /* Tag the variable length parameters. */ |
| 1411 | chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t)); |
| 1412 | |
| 1413 | /* Verify the INIT chunk before processing it. */ |
| 1414 | err_chunk = NULL; |
| 1415 | if (!sctp_verify_init(asoc, chunk->chunk_hdr->type, |
| 1416 | (sctp_init_chunk_t *)chunk->chunk_hdr, chunk, |
| 1417 | &err_chunk)) { |
| 1418 | /* This chunk contains fatal error. It is to be discarded. |
| 1419 | * Send an ABORT, with causes if there is any. |
| 1420 | */ |
| 1421 | if (err_chunk) { |
| 1422 | packet = sctp_abort_pkt_new(ep, asoc, arg, |
| 1423 | (__u8 *)(err_chunk->chunk_hdr) + |
| 1424 | sizeof(sctp_chunkhdr_t), |
| 1425 | ntohs(err_chunk->chunk_hdr->length) - |
| 1426 | sizeof(sctp_chunkhdr_t)); |
| 1427 | |
| 1428 | if (packet) { |
| 1429 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 1430 | SCTP_PACKET(packet)); |
| 1431 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 1432 | retval = SCTP_DISPOSITION_CONSUME; |
| 1433 | } else { |
| 1434 | retval = SCTP_DISPOSITION_NOMEM; |
| 1435 | } |
| 1436 | goto cleanup; |
| 1437 | } else { |
| 1438 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, |
| 1439 | commands); |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | /* |
| 1444 | * Other parameters for the endpoint SHOULD be copied from the |
| 1445 | * existing parameters of the association (e.g. number of |
| 1446 | * outbound streams) into the INIT ACK and cookie. |
| 1447 | * FIXME: We are copying parameters from the endpoint not the |
| 1448 | * association. |
| 1449 | */ |
| 1450 | new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC); |
| 1451 | if (!new_asoc) |
| 1452 | goto nomem; |
| 1453 | |
| 1454 | /* In the outbound INIT ACK the endpoint MUST copy its current |
| 1455 | * Verification Tag and Peers Verification tag into a reserved |
| 1456 | * place (local tie-tag and per tie-tag) within the state cookie. |
| 1457 | */ |
| 1458 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, |
| 1459 | sctp_source(chunk), |
| 1460 | (sctp_init_chunk_t *)chunk->chunk_hdr, |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1461 | GFP_ATOMIC)) |
| 1462 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
| 1464 | /* Make sure no new addresses are being added during the |
| 1465 | * restart. Do not do this check for COOKIE-WAIT state, |
| 1466 | * since there are no peer addresses to check against. |
| 1467 | * Upon return an ABORT will have been sent if needed. |
| 1468 | */ |
| 1469 | if (!sctp_state(asoc, COOKIE_WAIT)) { |
| 1470 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, |
| 1471 | commands)) { |
| 1472 | retval = SCTP_DISPOSITION_CONSUME; |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1473 | goto nomem_retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | } |
| 1475 | } |
| 1476 | |
| 1477 | sctp_tietags_populate(new_asoc, asoc); |
| 1478 | |
| 1479 | /* B) "Z" shall respond immediately with an INIT ACK chunk. */ |
| 1480 | |
| 1481 | /* If there are errors need to be reported for unknown parameters, |
| 1482 | * make sure to reserve enough room in the INIT ACK for them. |
| 1483 | */ |
| 1484 | len = 0; |
| 1485 | if (err_chunk) { |
| 1486 | len = ntohs(err_chunk->chunk_hdr->length) - |
| 1487 | sizeof(sctp_chunkhdr_t); |
| 1488 | } |
| 1489 | |
| 1490 | if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0) |
| 1491 | goto nomem; |
| 1492 | |
| 1493 | repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len); |
| 1494 | if (!repl) |
| 1495 | goto nomem; |
| 1496 | |
| 1497 | /* If there are errors need to be reported for unknown parameters, |
| 1498 | * include them in the outgoing INIT ACK as "Unrecognized parameter" |
| 1499 | * parameter. |
| 1500 | */ |
| 1501 | if (err_chunk) { |
| 1502 | /* Get the "Unrecognized parameter" parameter(s) out of the |
| 1503 | * ERROR chunk generated by sctp_verify_init(). Since the |
| 1504 | * error cause code for "unknown parameter" and the |
| 1505 | * "Unrecognized parameter" type is the same, we can |
| 1506 | * construct the parameters in INIT ACK by copying the |
| 1507 | * ERROR causes over. |
| 1508 | */ |
| 1509 | unk_param = (sctp_unrecognized_param_t *) |
| 1510 | ((__u8 *)(err_chunk->chunk_hdr) + |
| 1511 | sizeof(sctp_chunkhdr_t)); |
| 1512 | /* Replace the cause code with the "Unrecognized parameter" |
| 1513 | * parameter type. |
| 1514 | */ |
| 1515 | sctp_addto_chunk(repl, len, unk_param); |
| 1516 | } |
| 1517 | |
| 1518 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 1519 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1520 | |
| 1521 | /* |
| 1522 | * Note: After sending out INIT ACK with the State Cookie parameter, |
| 1523 | * "Z" MUST NOT allocate any resources for this new association. |
| 1524 | * Otherwise, "Z" will be vulnerable to resource attacks. |
| 1525 | */ |
| 1526 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 1527 | retval = SCTP_DISPOSITION_CONSUME; |
| 1528 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1529 | return retval; |
| 1530 | |
| 1531 | nomem: |
| 1532 | retval = SCTP_DISPOSITION_NOMEM; |
| 1533 | nomem_retval: |
| 1534 | if (new_asoc) |
| 1535 | sctp_association_free(new_asoc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | cleanup: |
| 1537 | if (err_chunk) |
| 1538 | sctp_chunk_free(err_chunk); |
| 1539 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /* |
| 1543 | * Handle simultanous INIT. |
| 1544 | * This means we started an INIT and then we got an INIT request from |
| 1545 | * our peer. |
| 1546 | * |
| 1547 | * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B) |
| 1548 | * This usually indicates an initialization collision, i.e., each |
| 1549 | * endpoint is attempting, at about the same time, to establish an |
| 1550 | * association with the other endpoint. |
| 1551 | * |
| 1552 | * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an |
| 1553 | * endpoint MUST respond with an INIT ACK using the same parameters it |
| 1554 | * sent in its original INIT chunk (including its Verification Tag, |
| 1555 | * unchanged). These original parameters are combined with those from the |
| 1556 | * newly received INIT chunk. The endpoint shall also generate a State |
| 1557 | * Cookie with the INIT ACK. The endpoint uses the parameters sent in its |
| 1558 | * INIT to calculate the State Cookie. |
| 1559 | * |
| 1560 | * After that, the endpoint MUST NOT change its state, the T1-init |
| 1561 | * timer shall be left running and the corresponding TCB MUST NOT be |
| 1562 | * destroyed. The normal procedures for handling State Cookies when |
| 1563 | * a TCB exists will resolve the duplicate INITs to a single association. |
| 1564 | * |
| 1565 | * For an endpoint that is in the COOKIE-ECHOED state it MUST populate |
| 1566 | * its Tie-Tags with the Tag information of itself and its peer (see |
| 1567 | * section 5.2.2 for a description of the Tie-Tags). |
| 1568 | * |
| 1569 | * Verification Tag: Not explicit, but an INIT can not have a valid |
| 1570 | * verification tag, so we skip the check. |
| 1571 | * |
| 1572 | * Inputs |
| 1573 | * (endpoint, asoc, chunk) |
| 1574 | * |
| 1575 | * Outputs |
| 1576 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1577 | * |
| 1578 | * The return value is the disposition of the chunk. |
| 1579 | */ |
| 1580 | sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep, |
| 1581 | const struct sctp_association *asoc, |
| 1582 | const sctp_subtype_t type, |
| 1583 | void *arg, |
| 1584 | sctp_cmd_seq_t *commands) |
| 1585 | { |
| 1586 | /* Call helper to do the real work for both simulataneous and |
| 1587 | * duplicate INIT chunk handling. |
| 1588 | */ |
| 1589 | return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands); |
| 1590 | } |
| 1591 | |
| 1592 | /* |
| 1593 | * Handle duplicated INIT messages. These are usually delayed |
| 1594 | * restransmissions. |
| 1595 | * |
| 1596 | * Section: 5.2.2 Unexpected INIT in States Other than CLOSED, |
| 1597 | * COOKIE-ECHOED and COOKIE-WAIT |
| 1598 | * |
| 1599 | * Unless otherwise stated, upon reception of an unexpected INIT for |
| 1600 | * this association, the endpoint shall generate an INIT ACK with a |
| 1601 | * State Cookie. In the outbound INIT ACK the endpoint MUST copy its |
| 1602 | * current Verification Tag and peer's Verification Tag into a reserved |
| 1603 | * place within the state cookie. We shall refer to these locations as |
| 1604 | * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet |
| 1605 | * containing this INIT ACK MUST carry a Verification Tag value equal to |
| 1606 | * the Initiation Tag found in the unexpected INIT. And the INIT ACK |
| 1607 | * MUST contain a new Initiation Tag (randomly generated see Section |
| 1608 | * 5.3.1). Other parameters for the endpoint SHOULD be copied from the |
| 1609 | * existing parameters of the association (e.g. number of outbound |
| 1610 | * streams) into the INIT ACK and cookie. |
| 1611 | * |
| 1612 | * After sending out the INIT ACK, the endpoint shall take no further |
| 1613 | * actions, i.e., the existing association, including its current state, |
| 1614 | * and the corresponding TCB MUST NOT be changed. |
| 1615 | * |
| 1616 | * Note: Only when a TCB exists and the association is not in a COOKIE- |
| 1617 | * WAIT state are the Tie-Tags populated. For a normal association INIT |
| 1618 | * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be |
| 1619 | * set to 0 (indicating that no previous TCB existed). The INIT ACK and |
| 1620 | * State Cookie are populated as specified in section 5.2.1. |
| 1621 | * |
| 1622 | * Verification Tag: Not specified, but an INIT has no way of knowing |
| 1623 | * what the verification tag could be, so we ignore it. |
| 1624 | * |
| 1625 | * Inputs |
| 1626 | * (endpoint, asoc, chunk) |
| 1627 | * |
| 1628 | * Outputs |
| 1629 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1630 | * |
| 1631 | * The return value is the disposition of the chunk. |
| 1632 | */ |
| 1633 | sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep, |
| 1634 | const struct sctp_association *asoc, |
| 1635 | const sctp_subtype_t type, |
| 1636 | void *arg, |
| 1637 | sctp_cmd_seq_t *commands) |
| 1638 | { |
| 1639 | /* Call helper to do the real work for both simulataneous and |
| 1640 | * duplicate INIT chunk handling. |
| 1641 | */ |
| 1642 | return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands); |
| 1643 | } |
| 1644 | |
| 1645 | |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1646 | /* |
| 1647 | * Unexpected INIT-ACK handler. |
| 1648 | * |
| 1649 | * Section 5.2.3 |
| 1650 | * If an INIT ACK received by an endpoint in any state other than the |
| 1651 | * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk. |
| 1652 | * An unexpected INIT ACK usually indicates the processing of an old or |
| 1653 | * duplicated INIT chunk. |
| 1654 | */ |
| 1655 | sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep, |
| 1656 | const struct sctp_association *asoc, |
| 1657 | const sctp_subtype_t type, |
| 1658 | void *arg, sctp_cmd_seq_t *commands) |
| 1659 | { |
| 1660 | /* Per the above section, we'll discard the chunk if we have an |
| 1661 | * endpoint. If this is an OOTB INIT-ACK, treat it as such. |
| 1662 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1663 | if (ep == sctp_sk((sctp_get_ctl_sock()))->ep) |
Vlad Yasevich | 610ab73 | 2007-01-15 19:18:30 -0800 | [diff] [blame] | 1664 | return sctp_sf_ootb(ep, asoc, type, arg, commands); |
| 1665 | else |
| 1666 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); |
| 1667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | |
| 1669 | /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A') |
| 1670 | * |
| 1671 | * Section 5.2.4 |
| 1672 | * A) In this case, the peer may have restarted. |
| 1673 | */ |
| 1674 | static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep, |
| 1675 | const struct sctp_association *asoc, |
| 1676 | struct sctp_chunk *chunk, |
| 1677 | sctp_cmd_seq_t *commands, |
| 1678 | struct sctp_association *new_asoc) |
| 1679 | { |
| 1680 | sctp_init_chunk_t *peer_init; |
| 1681 | struct sctp_ulpevent *ev; |
| 1682 | struct sctp_chunk *repl; |
| 1683 | struct sctp_chunk *err; |
| 1684 | sctp_disposition_t disposition; |
| 1685 | |
| 1686 | /* new_asoc is a brand-new association, so these are not yet |
| 1687 | * side effects--it is safe to run them here. |
| 1688 | */ |
| 1689 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 1690 | |
| 1691 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, |
| 1692 | sctp_source(chunk), peer_init, |
| 1693 | GFP_ATOMIC)) |
| 1694 | goto nomem; |
| 1695 | |
| 1696 | /* Make sure no new addresses are being added during the |
| 1697 | * restart. Though this is a pretty complicated attack |
| 1698 | * since you'd have to get inside the cookie. |
| 1699 | */ |
| 1700 | if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) { |
| 1701 | return SCTP_DISPOSITION_CONSUME; |
| 1702 | } |
| 1703 | |
| 1704 | /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes |
| 1705 | * the peer has restarted (Action A), it MUST NOT setup a new |
| 1706 | * association but instead resend the SHUTDOWN ACK and send an ERROR |
| 1707 | * chunk with a "Cookie Received while Shutting Down" error cause to |
| 1708 | * its peer. |
| 1709 | */ |
| 1710 | if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) { |
| 1711 | disposition = sctp_sf_do_9_2_reshutack(ep, asoc, |
| 1712 | SCTP_ST_CHUNK(chunk->chunk_hdr->type), |
| 1713 | chunk, commands); |
| 1714 | if (SCTP_DISPOSITION_NOMEM == disposition) |
| 1715 | goto nomem; |
| 1716 | |
| 1717 | err = sctp_make_op_error(asoc, chunk, |
| 1718 | SCTP_ERROR_COOKIE_IN_SHUTDOWN, |
| 1719 | NULL, 0); |
| 1720 | if (err) |
| 1721 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 1722 | SCTP_CHUNK(err)); |
| 1723 | |
| 1724 | return SCTP_DISPOSITION_CONSUME; |
| 1725 | } |
| 1726 | |
| 1727 | /* For now, fail any unsent/unacked data. Consider the optional |
| 1728 | * choice of resending of this data. |
| 1729 | */ |
| 1730 | sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL()); |
| 1731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1733 | if (!repl) |
| 1734 | goto nomem; |
| 1735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | /* Report association restart to upper layer. */ |
| 1737 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0, |
| 1738 | new_asoc->c.sinit_num_ostreams, |
| 1739 | new_asoc->c.sinit_max_instreams, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 1740 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | if (!ev) |
| 1742 | goto nomem_ev; |
| 1743 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1744 | /* Update the content of current association. */ |
| 1745 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); |
| 1746 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 1748 | return SCTP_DISPOSITION_CONSUME; |
| 1749 | |
| 1750 | nomem_ev: |
| 1751 | sctp_chunk_free(repl); |
| 1752 | nomem: |
| 1753 | return SCTP_DISPOSITION_NOMEM; |
| 1754 | } |
| 1755 | |
| 1756 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B') |
| 1757 | * |
| 1758 | * Section 5.2.4 |
| 1759 | * B) In this case, both sides may be attempting to start an association |
| 1760 | * at about the same time but the peer endpoint started its INIT |
| 1761 | * after responding to the local endpoint's INIT |
| 1762 | */ |
| 1763 | /* This case represents an initialization collision. */ |
| 1764 | static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep, |
| 1765 | const struct sctp_association *asoc, |
| 1766 | struct sctp_chunk *chunk, |
| 1767 | sctp_cmd_seq_t *commands, |
| 1768 | struct sctp_association *new_asoc) |
| 1769 | { |
| 1770 | sctp_init_chunk_t *peer_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | struct sctp_chunk *repl; |
| 1772 | |
| 1773 | /* new_asoc is a brand-new association, so these are not yet |
| 1774 | * side effects--it is safe to run them here. |
| 1775 | */ |
| 1776 | peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; |
| 1777 | if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type, |
| 1778 | sctp_source(chunk), peer_init, |
| 1779 | GFP_ATOMIC)) |
| 1780 | goto nomem; |
| 1781 | |
| 1782 | /* Update the content of current association. */ |
| 1783 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc)); |
| 1784 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1785 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
| 1786 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); |
| 1787 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL()); |
| 1788 | |
| 1789 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1790 | if (!repl) |
| 1791 | goto nomem; |
| 1792 | |
| 1793 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | |
| 1795 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 1796 | * |
| 1797 | * D) IMPLEMENTATION NOTE: An implementation may choose to |
| 1798 | * send the Communication Up notification to the SCTP user |
| 1799 | * upon reception of a valid COOKIE ECHO chunk. |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1800 | * |
| 1801 | * Sadly, this needs to be implemented as a side-effect, because |
| 1802 | * we are not guaranteed to have set the association id of the real |
| 1803 | * association and so these notifications need to be delayed until |
| 1804 | * the association id is allocated. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1807 | 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] | 1808 | |
| 1809 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1810 | * When a peer sends a Adaptation Layer Indication parameter , SCTP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | * delivers this notification to inform the application that of the |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1812 | * peers requested adaptation layer. |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1813 | * |
| 1814 | * This also needs to be done as a side effect for the same reason as |
| 1815 | * above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | */ |
Vlad Yasevich | 07d9396 | 2007-05-04 13:55:27 -0700 | [diff] [blame] | 1817 | if (asoc->peer.adaptation_ind) |
| 1818 | sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
| 1820 | return SCTP_DISPOSITION_CONSUME; |
| 1821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | nomem: |
| 1823 | return SCTP_DISPOSITION_NOMEM; |
| 1824 | } |
| 1825 | |
| 1826 | /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C') |
| 1827 | * |
| 1828 | * Section 5.2.4 |
| 1829 | * C) In this case, the local endpoint's cookie has arrived late. |
| 1830 | * Before it arrived, the local endpoint sent an INIT and received an |
| 1831 | * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag |
| 1832 | * but a new tag of its own. |
| 1833 | */ |
| 1834 | /* This case represents an initialization collision. */ |
| 1835 | static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep, |
| 1836 | const struct sctp_association *asoc, |
| 1837 | struct sctp_chunk *chunk, |
| 1838 | sctp_cmd_seq_t *commands, |
| 1839 | struct sctp_association *new_asoc) |
| 1840 | { |
| 1841 | /* The cookie should be silently discarded. |
| 1842 | * The endpoint SHOULD NOT change states and should leave |
| 1843 | * any timers running. |
| 1844 | */ |
| 1845 | return SCTP_DISPOSITION_DISCARD; |
| 1846 | } |
| 1847 | |
| 1848 | /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D') |
| 1849 | * |
| 1850 | * Section 5.2.4 |
| 1851 | * |
| 1852 | * D) When both local and remote tags match the endpoint should always |
| 1853 | * enter the ESTABLISHED state, if it has not already done so. |
| 1854 | */ |
| 1855 | /* This case represents an initialization collision. */ |
| 1856 | static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep, |
| 1857 | const struct sctp_association *asoc, |
| 1858 | struct sctp_chunk *chunk, |
| 1859 | sctp_cmd_seq_t *commands, |
| 1860 | struct sctp_association *new_asoc) |
| 1861 | { |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1862 | struct sctp_ulpevent *ev = NULL, *ai_ev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | struct sctp_chunk *repl; |
| 1864 | |
| 1865 | /* Clarification from Implementor's Guide: |
| 1866 | * D) When both local and remote tags match the endpoint should |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1867 | * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state. |
| 1868 | * It should stop any cookie timer that may be running and send |
| 1869 | * a COOKIE ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | */ |
| 1871 | |
| 1872 | /* Don't accidentally move back into established state. */ |
| 1873 | if (asoc->state < SCTP_STATE_ESTABLISHED) { |
| 1874 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 1875 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 1876 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 1877 | SCTP_STATE(SCTP_STATE_ESTABLISHED)); |
| 1878 | SCTP_INC_STATS(SCTP_MIB_CURRESTAB); |
| 1879 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, |
| 1880 | SCTP_NULL()); |
| 1881 | |
| 1882 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 1883 | * |
| 1884 | * D) IMPLEMENTATION NOTE: An implementation may choose |
| 1885 | * to send the Communication Up notification to the |
| 1886 | * SCTP user upon reception of a valid COOKIE |
| 1887 | * ECHO chunk. |
| 1888 | */ |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1889 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | SCTP_COMM_UP, 0, |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1891 | asoc->c.sinit_num_ostreams, |
| 1892 | asoc->c.sinit_max_instreams, |
YOSHIFUJI Hideaki | 9cbcbf4 | 2007-07-19 10:44:50 +0900 | [diff] [blame] | 1893 | NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | if (!ev) |
| 1895 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | |
| 1897 | /* Sockets API Draft Section 5.3.1.6 |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1898 | * When a peer sends a Adaptation Layer Indication parameter, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | * SCTP delivers this notification to inform the application |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1900 | * that of the peers requested adaptation layer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | */ |
Ivan Skytte Jorgensen | 0f3fffd | 2006-12-20 16:07:04 -0800 | [diff] [blame] | 1902 | if (asoc->peer.adaptation_ind) { |
| 1903 | ai_ev = sctp_ulpevent_make_adaptation_indication(asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | GFP_ATOMIC); |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1905 | if (!ai_ev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | goto nomem; |
| 1907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | } |
| 1909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
| 1911 | repl = sctp_make_cookie_ack(new_asoc, chunk); |
| 1912 | if (!repl) |
| 1913 | goto nomem; |
| 1914 | |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 1915 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 1916 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1917 | if (ev) |
| 1918 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 1919 | SCTP_ULPEVENT(ev)); |
| 1920 | if (ai_ev) |
| 1921 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 1922 | SCTP_ULPEVENT(ai_ev)); |
| 1923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | return SCTP_DISPOSITION_CONSUME; |
| 1925 | |
| 1926 | nomem: |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 1927 | if (ai_ev) |
| 1928 | sctp_ulpevent_free(ai_ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | if (ev) |
| 1930 | sctp_ulpevent_free(ev); |
| 1931 | return SCTP_DISPOSITION_NOMEM; |
| 1932 | } |
| 1933 | |
| 1934 | /* |
| 1935 | * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying |
| 1936 | * chunk was retransmitted and then delayed in the network. |
| 1937 | * |
| 1938 | * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists |
| 1939 | * |
| 1940 | * Verification Tag: None. Do cookie validation. |
| 1941 | * |
| 1942 | * Inputs |
| 1943 | * (endpoint, asoc, chunk) |
| 1944 | * |
| 1945 | * Outputs |
| 1946 | * (asoc, reply_msg, msg_up, timers, counters) |
| 1947 | * |
| 1948 | * The return value is the disposition of the chunk. |
| 1949 | */ |
| 1950 | sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep, |
| 1951 | const struct sctp_association *asoc, |
| 1952 | const sctp_subtype_t type, |
| 1953 | void *arg, |
| 1954 | sctp_cmd_seq_t *commands) |
| 1955 | { |
| 1956 | sctp_disposition_t retval; |
| 1957 | struct sctp_chunk *chunk = arg; |
| 1958 | struct sctp_association *new_asoc; |
| 1959 | int error = 0; |
| 1960 | char action; |
| 1961 | struct sctp_chunk *err_chk_p; |
| 1962 | |
| 1963 | /* Make sure that the chunk has a valid length from the protocol |
| 1964 | * perspective. In this case check to make sure we have at least |
| 1965 | * enough for the chunk header. Cookie length verification is |
| 1966 | * done later. |
| 1967 | */ |
| 1968 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 1969 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 1970 | commands); |
| 1971 | |
| 1972 | /* "Decode" the chunk. We have no optional parameters so we |
| 1973 | * are in good shape. |
| 1974 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 1975 | chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; |
Sridhar Samudrala | 62b0808 | 2006-05-05 17:04:43 -0700 | [diff] [blame] | 1976 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
| 1977 | sizeof(sctp_chunkhdr_t))) |
| 1978 | goto nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
| 1980 | /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie |
| 1981 | * of a duplicate COOKIE ECHO match the Verification Tags of the |
| 1982 | * current association, consider the State Cookie valid even if |
| 1983 | * the lifespan is exceeded. |
| 1984 | */ |
| 1985 | new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error, |
| 1986 | &err_chk_p); |
| 1987 | |
| 1988 | /* FIXME: |
| 1989 | * If the re-build failed, what is the proper error path |
| 1990 | * from here? |
| 1991 | * |
| 1992 | * [We should abort the association. --piggy] |
| 1993 | */ |
| 1994 | if (!new_asoc) { |
| 1995 | /* FIXME: Several errors are possible. A bad cookie should |
| 1996 | * be silently discarded, but think about logging it too. |
| 1997 | */ |
| 1998 | switch (error) { |
| 1999 | case -SCTP_IERROR_NOMEM: |
| 2000 | goto nomem; |
| 2001 | |
| 2002 | case -SCTP_IERROR_STALE_COOKIE: |
| 2003 | sctp_send_stale_cookie_err(ep, asoc, chunk, commands, |
| 2004 | err_chk_p); |
| 2005 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2006 | case -SCTP_IERROR_BAD_SIG: |
| 2007 | default: |
| 2008 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | /* Compare the tie_tag in cookie with the verification tag of |
| 2013 | * current association. |
| 2014 | */ |
| 2015 | action = sctp_tietags_compare(new_asoc, asoc); |
| 2016 | |
| 2017 | switch (action) { |
| 2018 | case 'A': /* Association restart. */ |
| 2019 | retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands, |
| 2020 | new_asoc); |
| 2021 | break; |
| 2022 | |
| 2023 | case 'B': /* Collision case B. */ |
| 2024 | retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands, |
| 2025 | new_asoc); |
| 2026 | break; |
| 2027 | |
| 2028 | case 'C': /* Collision case C. */ |
| 2029 | retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands, |
| 2030 | new_asoc); |
| 2031 | break; |
| 2032 | |
| 2033 | case 'D': /* Collision case D. */ |
| 2034 | retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands, |
| 2035 | new_asoc); |
| 2036 | break; |
| 2037 | |
| 2038 | default: /* Discard packet for all others. */ |
| 2039 | retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2040 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 2041 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | |
| 2043 | /* Delete the tempory new association. */ |
| 2044 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc)); |
| 2045 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 2046 | |
| 2047 | return retval; |
| 2048 | |
| 2049 | nomem: |
| 2050 | return SCTP_DISPOSITION_NOMEM; |
| 2051 | } |
| 2052 | |
| 2053 | /* |
| 2054 | * Process an ABORT. (SHUTDOWN-PENDING state) |
| 2055 | * |
| 2056 | * See sctp_sf_do_9_1_abort(). |
| 2057 | */ |
| 2058 | sctp_disposition_t sctp_sf_shutdown_pending_abort( |
| 2059 | const struct sctp_endpoint *ep, |
| 2060 | const struct sctp_association *asoc, |
| 2061 | const sctp_subtype_t type, |
| 2062 | void *arg, |
| 2063 | sctp_cmd_seq_t *commands) |
| 2064 | { |
| 2065 | struct sctp_chunk *chunk = arg; |
| 2066 | |
| 2067 | if (!sctp_vtag_verify_either(chunk, asoc)) |
| 2068 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2069 | |
| 2070 | /* Make sure that the ABORT chunk has a valid length. |
| 2071 | * Since this is an ABORT chunk, we have to discard it |
| 2072 | * because of the following text: |
| 2073 | * RFC 2960, Section 3.3.7 |
| 2074 | * If an endpoint receives an ABORT with a format error or for an |
| 2075 | * association that doesn't exist, it MUST silently discard it. |
| 2076 | * Becasue the length is "invalid", we can't really discard just |
| 2077 | * as we do not know its true length. So, to be safe, discard the |
| 2078 | * packet. |
| 2079 | */ |
| 2080 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) |
| 2081 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2082 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2083 | /* ADD-IP: Special case for ABORT chunks |
| 2084 | * F4) One special consideration is that ABORT Chunks arriving |
| 2085 | * destined to the IP address being deleted MUST be |
| 2086 | * ignored (see Section 5.3.1 for further details). |
| 2087 | */ |
| 2088 | if (SCTP_ADDR_DEL == |
| 2089 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
| 2090 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); |
| 2091 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2092 | return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | /* |
| 2096 | * Process an ABORT. (SHUTDOWN-SENT state) |
| 2097 | * |
| 2098 | * See sctp_sf_do_9_1_abort(). |
| 2099 | */ |
| 2100 | sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep, |
| 2101 | const struct sctp_association *asoc, |
| 2102 | const sctp_subtype_t type, |
| 2103 | void *arg, |
| 2104 | sctp_cmd_seq_t *commands) |
| 2105 | { |
| 2106 | struct sctp_chunk *chunk = arg; |
| 2107 | |
| 2108 | if (!sctp_vtag_verify_either(chunk, asoc)) |
| 2109 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2110 | |
| 2111 | /* Make sure that the ABORT chunk has a valid length. |
| 2112 | * Since this is an ABORT chunk, we have to discard it |
| 2113 | * because of the following text: |
| 2114 | * RFC 2960, Section 3.3.7 |
| 2115 | * If an endpoint receives an ABORT with a format error or for an |
| 2116 | * association that doesn't exist, it MUST silently discard it. |
| 2117 | * Becasue the length is "invalid", we can't really discard just |
| 2118 | * as we do not know its true length. So, to be safe, discard the |
| 2119 | * packet. |
| 2120 | */ |
| 2121 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) |
| 2122 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2123 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2124 | /* ADD-IP: Special case for ABORT chunks |
| 2125 | * F4) One special consideration is that ABORT Chunks arriving |
| 2126 | * destined to the IP address being deleted MUST be |
| 2127 | * ignored (see Section 5.3.1 for further details). |
| 2128 | */ |
| 2129 | if (SCTP_ADDR_DEL == |
| 2130 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
| 2131 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); |
| 2132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | /* Stop the T2-shutdown timer. */ |
| 2134 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2135 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 2136 | |
| 2137 | /* Stop the T5-shutdown guard timer. */ |
| 2138 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2139 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 2140 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2141 | return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | /* |
| 2145 | * Process an ABORT. (SHUTDOWN-ACK-SENT state) |
| 2146 | * |
| 2147 | * See sctp_sf_do_9_1_abort(). |
| 2148 | */ |
| 2149 | sctp_disposition_t sctp_sf_shutdown_ack_sent_abort( |
| 2150 | const struct sctp_endpoint *ep, |
| 2151 | const struct sctp_association *asoc, |
| 2152 | const sctp_subtype_t type, |
| 2153 | void *arg, |
| 2154 | sctp_cmd_seq_t *commands) |
| 2155 | { |
| 2156 | /* The same T2 timer, so we should be able to use |
| 2157 | * common function with the SHUTDOWN-SENT state. |
| 2158 | */ |
| 2159 | return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands); |
| 2160 | } |
| 2161 | |
| 2162 | /* |
| 2163 | * Handle an Error received in COOKIE_ECHOED state. |
| 2164 | * |
| 2165 | * Only handle the error type of stale COOKIE Error, the other errors will |
| 2166 | * be ignored. |
| 2167 | * |
| 2168 | * Inputs |
| 2169 | * (endpoint, asoc, chunk) |
| 2170 | * |
| 2171 | * Outputs |
| 2172 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2173 | * |
| 2174 | * The return value is the disposition of the chunk. |
| 2175 | */ |
| 2176 | sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep, |
| 2177 | const struct sctp_association *asoc, |
| 2178 | const sctp_subtype_t type, |
| 2179 | void *arg, |
| 2180 | sctp_cmd_seq_t *commands) |
| 2181 | { |
| 2182 | struct sctp_chunk *chunk = arg; |
| 2183 | sctp_errhdr_t *err; |
| 2184 | |
| 2185 | if (!sctp_vtag_verify(chunk, asoc)) |
| 2186 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2187 | |
| 2188 | /* Make sure that the ERROR chunk has a valid length. |
| 2189 | * The parameter walking depends on this as well. |
| 2190 | */ |
| 2191 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t))) |
| 2192 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2193 | commands); |
| 2194 | |
| 2195 | /* Process the error here */ |
| 2196 | /* FUTURE FIXME: When PR-SCTP related and other optional |
| 2197 | * parms are emitted, this will have to change to handle multiple |
| 2198 | * errors. |
| 2199 | */ |
| 2200 | sctp_walk_errors(err, chunk->chunk_hdr) { |
| 2201 | if (SCTP_ERROR_STALE_COOKIE == err->cause) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2202 | return sctp_sf_do_5_2_6_stale(ep, asoc, type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | arg, commands); |
| 2204 | } |
| 2205 | |
| 2206 | /* It is possible to have malformed error causes, and that |
| 2207 | * will cause us to end the walk early. However, since |
| 2208 | * we are discarding the packet, there should be no adverse |
| 2209 | * affects. |
| 2210 | */ |
| 2211 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2212 | } |
| 2213 | |
| 2214 | /* |
| 2215 | * Handle a Stale COOKIE Error |
| 2216 | * |
| 2217 | * Section: 5.2.6 Handle Stale COOKIE Error |
| 2218 | * If the association is in the COOKIE-ECHOED state, the endpoint may elect |
| 2219 | * one of the following three alternatives. |
| 2220 | * ... |
| 2221 | * 3) Send a new INIT chunk to the endpoint, adding a Cookie |
| 2222 | * Preservative parameter requesting an extension to the lifetime of |
| 2223 | * the State Cookie. When calculating the time extension, an |
| 2224 | * implementation SHOULD use the RTT information measured based on the |
| 2225 | * previous COOKIE ECHO / ERROR exchange, and should add no more |
| 2226 | * than 1 second beyond the measured RTT, due to long State Cookie |
| 2227 | * lifetimes making the endpoint more subject to a replay attack. |
| 2228 | * |
| 2229 | * Verification Tag: Not explicit, but safe to ignore. |
| 2230 | * |
| 2231 | * Inputs |
| 2232 | * (endpoint, asoc, chunk) |
| 2233 | * |
| 2234 | * Outputs |
| 2235 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2236 | * |
| 2237 | * The return value is the disposition of the chunk. |
| 2238 | */ |
| 2239 | static sctp_disposition_t sctp_sf_do_5_2_6_stale(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 | struct sctp_chunk *chunk = arg; |
| 2246 | time_t stale; |
| 2247 | sctp_cookie_preserve_param_t bht; |
| 2248 | sctp_errhdr_t *err; |
| 2249 | struct sctp_chunk *reply; |
| 2250 | struct sctp_bind_addr *bp; |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2251 | int attempts = asoc->init_err_counter + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 2253 | if (attempts > asoc->max_init_attempts) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2254 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 2255 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 2257 | SCTP_PERR(SCTP_ERROR_STALE_COOKIE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | return SCTP_DISPOSITION_DELETE_TCB; |
| 2259 | } |
| 2260 | |
| 2261 | err = (sctp_errhdr_t *)(chunk->skb->data); |
| 2262 | |
| 2263 | /* When calculating the time extension, an implementation |
| 2264 | * SHOULD use the RTT information measured based on the |
| 2265 | * previous COOKIE ECHO / ERROR exchange, and should add no |
| 2266 | * more than 1 second beyond the measured RTT, due to long |
| 2267 | * State Cookie lifetimes making the endpoint more subject to |
| 2268 | * a replay attack. |
| 2269 | * Measure of Staleness's unit is usec. (1/1000000 sec) |
| 2270 | * Suggested Cookie Life-span Increment's unit is msec. |
| 2271 | * (1/1000 sec) |
| 2272 | * In general, if you use the suggested cookie life, the value |
| 2273 | * found in the field of measure of staleness should be doubled |
| 2274 | * to give ample time to retransmit the new cookie and thus |
| 2275 | * yield a higher probability of success on the reattempt. |
| 2276 | */ |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2277 | stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | stale = (stale * 2) / 1000; |
| 2279 | |
| 2280 | bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE; |
| 2281 | bht.param_hdr.length = htons(sizeof(bht)); |
| 2282 | bht.lifespan_increment = htonl(stale); |
| 2283 | |
| 2284 | /* Build that new INIT chunk. */ |
| 2285 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
| 2286 | reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht)); |
| 2287 | if (!reply) |
| 2288 | goto nomem; |
| 2289 | |
| 2290 | sctp_addto_chunk(reply, sizeof(bht), &bht); |
| 2291 | |
| 2292 | /* Clear peer's init_tag cached in assoc as we are sending a new INIT */ |
| 2293 | sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL()); |
| 2294 | |
| 2295 | /* Stop pending T3-rtx and heartbeat timers */ |
| 2296 | sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL()); |
| 2297 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 2298 | |
| 2299 | /* Delete non-primary peer ip addresses since we are transitioning |
| 2300 | * back to the COOKIE-WAIT state |
| 2301 | */ |
| 2302 | sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL()); |
| 2303 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2304 | /* If we've sent any data bundled with COOKIE-ECHO we will need to |
| 2305 | * resend |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | */ |
Vlad Yasevich | b6157d8 | 2007-10-24 15:59:16 -0400 | [diff] [blame] | 2307 | sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | SCTP_TRANSPORT(asoc->peer.primary_path)); |
| 2309 | |
| 2310 | /* Cast away the const modifier, as we want to just |
| 2311 | * rerun it through as a sideffect. |
| 2312 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2313 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | |
| 2315 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2316 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 2317 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2318 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); |
| 2319 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 2320 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 2321 | |
| 2322 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 2323 | |
| 2324 | return SCTP_DISPOSITION_CONSUME; |
| 2325 | |
| 2326 | nomem: |
| 2327 | return SCTP_DISPOSITION_NOMEM; |
| 2328 | } |
| 2329 | |
| 2330 | /* |
| 2331 | * Process an ABORT. |
| 2332 | * |
| 2333 | * Section: 9.1 |
| 2334 | * After checking the Verification Tag, the receiving endpoint shall |
| 2335 | * remove the association from its record, and shall report the |
| 2336 | * termination to its upper layer. |
| 2337 | * |
| 2338 | * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules |
| 2339 | * B) Rules for packet carrying ABORT: |
| 2340 | * |
| 2341 | * - The endpoint shall always fill in the Verification Tag field of the |
| 2342 | * outbound packet with the destination endpoint's tag value if it |
| 2343 | * is known. |
| 2344 | * |
| 2345 | * - If the ABORT is sent in response to an OOTB packet, the endpoint |
| 2346 | * MUST follow the procedure described in Section 8.4. |
| 2347 | * |
| 2348 | * - The receiver MUST accept the packet if the Verification Tag |
| 2349 | * matches either its own tag, OR the tag of its peer. Otherwise, the |
| 2350 | * receiver MUST silently discard the packet and take no further |
| 2351 | * action. |
| 2352 | * |
| 2353 | * Inputs |
| 2354 | * (endpoint, asoc, chunk) |
| 2355 | * |
| 2356 | * Outputs |
| 2357 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2358 | * |
| 2359 | * The return value is the disposition of the chunk. |
| 2360 | */ |
| 2361 | sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep, |
| 2362 | const struct sctp_association *asoc, |
| 2363 | const sctp_subtype_t type, |
| 2364 | void *arg, |
| 2365 | sctp_cmd_seq_t *commands) |
| 2366 | { |
| 2367 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | |
| 2369 | if (!sctp_vtag_verify_either(chunk, asoc)) |
| 2370 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2371 | |
| 2372 | /* Make sure that the ABORT chunk has a valid length. |
| 2373 | * Since this is an ABORT chunk, we have to discard it |
| 2374 | * because of the following text: |
| 2375 | * RFC 2960, Section 3.3.7 |
| 2376 | * If an endpoint receives an ABORT with a format error or for an |
| 2377 | * association that doesn't exist, it MUST silently discard it. |
| 2378 | * Becasue the length is "invalid", we can't really discard just |
| 2379 | * as we do not know its true length. So, to be safe, discard the |
| 2380 | * packet. |
| 2381 | */ |
| 2382 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) |
| 2383 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2384 | |
Vlad Yasevich | 75205f4 | 2007-12-20 14:12:59 -0800 | [diff] [blame] | 2385 | /* ADD-IP: Special case for ABORT chunks |
| 2386 | * F4) One special consideration is that ABORT Chunks arriving |
| 2387 | * destined to the IP address being deleted MUST be |
| 2388 | * ignored (see Section 5.3.1 for further details). |
| 2389 | */ |
| 2390 | if (SCTP_ADDR_DEL == |
| 2391 | sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) |
| 2392 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); |
| 2393 | |
| 2394 | return __sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands); |
| 2395 | } |
| 2396 | |
| 2397 | static sctp_disposition_t __sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep, |
| 2398 | const struct sctp_association *asoc, |
| 2399 | const sctp_subtype_t type, |
| 2400 | void *arg, |
| 2401 | sctp_cmd_seq_t *commands) |
| 2402 | { |
| 2403 | struct sctp_chunk *chunk = arg; |
| 2404 | unsigned len; |
| 2405 | __be16 error = SCTP_ERROR_NO_ERROR; |
| 2406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | /* See if we have an error cause code in the chunk. */ |
| 2408 | len = ntohs(chunk->chunk_hdr->length); |
| 2409 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) |
| 2410 | error = ((sctp_errhdr_t *)chunk->skb->data)->cause; |
| 2411 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2412 | 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] | 2413 | /* ASSOC_FAILED will DELETE_TCB. */ |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 2414 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 2416 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 2417 | |
| 2418 | return SCTP_DISPOSITION_ABORT; |
| 2419 | } |
| 2420 | |
| 2421 | /* |
| 2422 | * Process an ABORT. (COOKIE-WAIT state) |
| 2423 | * |
| 2424 | * See sctp_sf_do_9_1_abort() above. |
| 2425 | */ |
| 2426 | sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep, |
| 2427 | const struct sctp_association *asoc, |
| 2428 | const sctp_subtype_t type, |
| 2429 | void *arg, |
| 2430 | sctp_cmd_seq_t *commands) |
| 2431 | { |
| 2432 | struct sctp_chunk *chunk = arg; |
| 2433 | unsigned len; |
Al Viro | f94c019 | 2006-11-20 17:00:25 -0800 | [diff] [blame] | 2434 | __be16 error = SCTP_ERROR_NO_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | |
| 2436 | if (!sctp_vtag_verify_either(chunk, asoc)) |
| 2437 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2438 | |
| 2439 | /* Make sure that the ABORT chunk has a valid length. |
| 2440 | * Since this is an ABORT chunk, we have to discard it |
| 2441 | * because of the following text: |
| 2442 | * RFC 2960, Section 3.3.7 |
| 2443 | * If an endpoint receives an ABORT with a format error or for an |
| 2444 | * association that doesn't exist, it MUST silently discard it. |
| 2445 | * Becasue the length is "invalid", we can't really discard just |
| 2446 | * as we do not know its true length. So, to be safe, discard the |
| 2447 | * packet. |
| 2448 | */ |
| 2449 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t))) |
| 2450 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2451 | |
| 2452 | /* See if we have an error cause code in the chunk. */ |
| 2453 | len = ntohs(chunk->chunk_hdr->length); |
| 2454 | if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) |
| 2455 | error = ((sctp_errhdr_t *)chunk->skb->data)->cause; |
| 2456 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2457 | return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc, |
| 2458 | chunk->transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | /* |
| 2462 | * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state) |
| 2463 | */ |
| 2464 | sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep, |
| 2465 | const struct sctp_association *asoc, |
| 2466 | const sctp_subtype_t type, |
| 2467 | void *arg, |
| 2468 | sctp_cmd_seq_t *commands) |
| 2469 | { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2470 | return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR, |
| 2471 | ENOPROTOOPT, asoc, |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2472 | (struct sctp_transport *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | /* |
| 2476 | * Process an ABORT. (COOKIE-ECHOED state) |
| 2477 | */ |
| 2478 | sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep, |
| 2479 | const struct sctp_association *asoc, |
| 2480 | const sctp_subtype_t type, |
| 2481 | void *arg, |
| 2482 | sctp_cmd_seq_t *commands) |
| 2483 | { |
| 2484 | /* There is a single T1 timer, so we should be able to use |
| 2485 | * common function with the COOKIE-WAIT state. |
| 2486 | */ |
| 2487 | return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands); |
| 2488 | } |
| 2489 | |
| 2490 | /* |
| 2491 | * Stop T1 timer and abort association with "INIT failed". |
| 2492 | * |
| 2493 | * This is common code called by several sctp_sf_*_abort() functions above. |
| 2494 | */ |
Adrian Bunk | 52c1da3 | 2005-06-23 22:05:33 -0700 | [diff] [blame] | 2495 | static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands, |
Al Viro | f94c019 | 2006-11-20 17:00:25 -0800 | [diff] [blame] | 2496 | __be16 error, int sk_err, |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2497 | const struct sctp_association *asoc, |
| 2498 | struct sctp_transport *transport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2500 | SCTP_DEBUG_PRINTK("ABORT received (INIT).\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2502 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 2503 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 2504 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 2505 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 2506 | 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] | 2507 | /* CMD_INIT_FAILED will DELETE_TCB. */ |
| 2508 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 2509 | SCTP_PERR(error)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 2510 | return SCTP_DISPOSITION_ABORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | /* |
| 2514 | * sctp_sf_do_9_2_shut |
| 2515 | * |
| 2516 | * Section: 9.2 |
| 2517 | * Upon the reception of the SHUTDOWN, the peer endpoint shall |
| 2518 | * - enter the SHUTDOWN-RECEIVED state, |
| 2519 | * |
| 2520 | * - stop accepting new data from its SCTP user |
| 2521 | * |
| 2522 | * - verify, by checking the Cumulative TSN Ack field of the chunk, |
| 2523 | * that all its outstanding DATA chunks have been received by the |
| 2524 | * SHUTDOWN sender. |
| 2525 | * |
| 2526 | * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT |
| 2527 | * send a SHUTDOWN in response to a ULP request. And should discard |
| 2528 | * subsequent SHUTDOWN chunks. |
| 2529 | * |
| 2530 | * If there are still outstanding DATA chunks left, the SHUTDOWN |
| 2531 | * receiver shall continue to follow normal data transmission |
| 2532 | * procedures defined in Section 6 until all outstanding DATA chunks |
| 2533 | * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept |
| 2534 | * new data from its SCTP user. |
| 2535 | * |
| 2536 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2537 | * |
| 2538 | * Inputs |
| 2539 | * (endpoint, asoc, chunk) |
| 2540 | * |
| 2541 | * Outputs |
| 2542 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2543 | * |
| 2544 | * The return value is the disposition of the chunk. |
| 2545 | */ |
| 2546 | sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep, |
| 2547 | const struct sctp_association *asoc, |
| 2548 | const sctp_subtype_t type, |
| 2549 | void *arg, |
| 2550 | sctp_cmd_seq_t *commands) |
| 2551 | { |
| 2552 | struct sctp_chunk *chunk = arg; |
| 2553 | sctp_shutdownhdr_t *sdh; |
| 2554 | sctp_disposition_t disposition; |
| 2555 | struct sctp_ulpevent *ev; |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2556 | __u32 ctsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | |
| 2558 | if (!sctp_vtag_verify(chunk, asoc)) |
| 2559 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2560 | |
| 2561 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
| 2562 | if (!sctp_chunk_length_valid(chunk, |
| 2563 | sizeof(struct sctp_shutdown_chunk_t))) |
| 2564 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2565 | commands); |
| 2566 | |
| 2567 | /* Convert the elaborate header. */ |
| 2568 | sdh = (sctp_shutdownhdr_t *)chunk->skb->data; |
| 2569 | skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t)); |
| 2570 | chunk->subh.shutdown_hdr = sdh; |
Wei Yongjun | df10eec | 2008-10-23 01:00:21 -0700 | [diff] [blame] | 2571 | ctsn = ntohl(sdh->cum_tsn_ack); |
| 2572 | |
| 2573 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 2574 | * send, terminating the association and respond to the |
| 2575 | * sender with an ABORT. |
| 2576 | */ |
| 2577 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
| 2578 | return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | |
Sridhar Samudrala | eb0e007 | 2005-09-22 23:48:38 -0700 | [diff] [blame] | 2580 | /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT |
| 2581 | * When a peer sends a SHUTDOWN, SCTP delivers this notification to |
| 2582 | * inform the application that it should cease sending data. |
| 2583 | */ |
| 2584 | ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC); |
| 2585 | if (!ev) { |
| 2586 | disposition = SCTP_DISPOSITION_NOMEM; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2587 | goto out; |
Sridhar Samudrala | eb0e007 | 2005-09-22 23:48:38 -0700 | [diff] [blame] | 2588 | } |
| 2589 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 2590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | /* Upon the reception of the SHUTDOWN, the peer endpoint shall |
| 2592 | * - enter the SHUTDOWN-RECEIVED state, |
| 2593 | * - stop accepting new data from its SCTP user |
| 2594 | * |
| 2595 | * [This is implicit in the new state.] |
| 2596 | */ |
| 2597 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 2598 | SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED)); |
| 2599 | disposition = SCTP_DISPOSITION_CONSUME; |
| 2600 | |
| 2601 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
| 2602 | disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type, |
| 2603 | arg, commands); |
| 2604 | } |
| 2605 | |
| 2606 | if (SCTP_DISPOSITION_NOMEM == disposition) |
| 2607 | goto out; |
| 2608 | |
| 2609 | /* - verify, by checking the Cumulative TSN Ack field of the |
| 2610 | * chunk, that all its outstanding DATA chunks have been |
| 2611 | * received by the SHUTDOWN sender. |
| 2612 | */ |
| 2613 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, |
Al Viro | 2178eda | 2006-11-20 17:26:53 -0800 | [diff] [blame] | 2614 | SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | out: |
| 2617 | return disposition; |
| 2618 | } |
| 2619 | |
Wei Yongjun | 2e3f92d | 2008-10-23 01:01:18 -0700 | [diff] [blame] | 2620 | /* |
| 2621 | * sctp_sf_do_9_2_shut_ctsn |
| 2622 | * |
| 2623 | * Once an endpoint has reached the SHUTDOWN-RECEIVED state, |
| 2624 | * it MUST NOT send a SHUTDOWN in response to a ULP request. |
| 2625 | * The Cumulative TSN Ack of the received SHUTDOWN chunk |
| 2626 | * MUST be processed. |
| 2627 | */ |
| 2628 | sctp_disposition_t sctp_sf_do_9_2_shut_ctsn(const struct sctp_endpoint *ep, |
| 2629 | const struct sctp_association *asoc, |
| 2630 | const sctp_subtype_t type, |
| 2631 | void *arg, |
| 2632 | sctp_cmd_seq_t *commands) |
| 2633 | { |
| 2634 | struct sctp_chunk *chunk = arg; |
| 2635 | sctp_shutdownhdr_t *sdh; |
| 2636 | |
| 2637 | if (!sctp_vtag_verify(chunk, asoc)) |
| 2638 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2639 | |
| 2640 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
| 2641 | if (!sctp_chunk_length_valid(chunk, |
| 2642 | sizeof(struct sctp_shutdown_chunk_t))) |
| 2643 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2644 | commands); |
| 2645 | |
| 2646 | sdh = (sctp_shutdownhdr_t *)chunk->skb->data; |
| 2647 | |
| 2648 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 2649 | * send, terminating the association and respond to the |
| 2650 | * sender with an ABORT. |
| 2651 | */ |
| 2652 | if (!TSN_lt(ntohl(sdh->cum_tsn_ack), asoc->next_tsn)) |
| 2653 | return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands); |
| 2654 | |
| 2655 | /* verify, by checking the Cumulative TSN Ack field of the |
| 2656 | * chunk, that all its outstanding DATA chunks have been |
| 2657 | * received by the SHUTDOWN sender. |
| 2658 | */ |
| 2659 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN, |
| 2660 | SCTP_BE32(sdh->cum_tsn_ack)); |
| 2661 | |
| 2662 | return SCTP_DISPOSITION_CONSUME; |
| 2663 | } |
| 2664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | /* RFC 2960 9.2 |
| 2666 | * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk |
| 2667 | * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination |
| 2668 | * transport addresses (either in the IP addresses or in the INIT chunk) |
| 2669 | * that belong to this association, it should discard the INIT chunk and |
| 2670 | * retransmit the SHUTDOWN ACK chunk. |
| 2671 | */ |
| 2672 | sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep, |
| 2673 | const struct sctp_association *asoc, |
| 2674 | const sctp_subtype_t type, |
| 2675 | void *arg, |
| 2676 | sctp_cmd_seq_t *commands) |
| 2677 | { |
| 2678 | struct sctp_chunk *chunk = (struct sctp_chunk *) arg; |
| 2679 | struct sctp_chunk *reply; |
| 2680 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 2681 | /* Make sure that the chunk has a valid length */ |
| 2682 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 2683 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2684 | commands); |
| 2685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | /* Since we are not going to really process this INIT, there |
| 2687 | * is no point in verifying chunk boundries. Just generate |
| 2688 | * the SHUTDOWN ACK. |
| 2689 | */ |
| 2690 | reply = sctp_make_shutdown_ack(asoc, chunk); |
| 2691 | if (NULL == reply) |
| 2692 | goto nomem; |
| 2693 | |
| 2694 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for |
| 2695 | * the T2-SHUTDOWN timer. |
| 2696 | */ |
| 2697 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 2698 | |
| 2699 | /* and restart the T2-shutdown timer. */ |
| 2700 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 2701 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 2702 | |
| 2703 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 2704 | |
| 2705 | return SCTP_DISPOSITION_CONSUME; |
| 2706 | nomem: |
| 2707 | return SCTP_DISPOSITION_NOMEM; |
| 2708 | } |
| 2709 | |
| 2710 | /* |
| 2711 | * sctp_sf_do_ecn_cwr |
| 2712 | * |
| 2713 | * Section: Appendix A: Explicit Congestion Notification |
| 2714 | * |
| 2715 | * CWR: |
| 2716 | * |
| 2717 | * RFC 2481 details a specific bit for a sender to send in the header of |
| 2718 | * its next outbound TCP segment to indicate to its peer that it has |
| 2719 | * reduced its congestion window. This is termed the CWR bit. For |
| 2720 | * SCTP the same indication is made by including the CWR chunk. |
| 2721 | * This chunk contains one data element, i.e. the TSN number that |
| 2722 | * was sent in the ECNE chunk. This element represents the lowest |
| 2723 | * TSN number in the datagram that was originally marked with the |
| 2724 | * CE bit. |
| 2725 | * |
| 2726 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2727 | * Inputs |
| 2728 | * (endpoint, asoc, chunk) |
| 2729 | * |
| 2730 | * Outputs |
| 2731 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2732 | * |
| 2733 | * The return value is the disposition of the chunk. |
| 2734 | */ |
| 2735 | sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep, |
| 2736 | const struct sctp_association *asoc, |
| 2737 | const sctp_subtype_t type, |
| 2738 | void *arg, |
| 2739 | sctp_cmd_seq_t *commands) |
| 2740 | { |
| 2741 | sctp_cwrhdr_t *cwr; |
| 2742 | struct sctp_chunk *chunk = arg; |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2743 | u32 lowest_tsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | |
| 2745 | if (!sctp_vtag_verify(chunk, asoc)) |
| 2746 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2747 | |
| 2748 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t))) |
| 2749 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2750 | commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | cwr = (sctp_cwrhdr_t *) chunk->skb->data; |
| 2753 | skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t)); |
| 2754 | |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2755 | lowest_tsn = ntohl(cwr->lowest_tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | |
| 2757 | /* Does this CWR ack the last sent congestion notification? */ |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2758 | if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | /* Stop sending ECNE. */ |
| 2760 | sctp_add_cmd_sf(commands, |
| 2761 | SCTP_CMD_ECN_CWR, |
Al Viro | 34bcca2 | 2006-11-20 17:27:15 -0800 | [diff] [blame] | 2762 | SCTP_U32(lowest_tsn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | } |
| 2764 | return SCTP_DISPOSITION_CONSUME; |
| 2765 | } |
| 2766 | |
| 2767 | /* |
| 2768 | * sctp_sf_do_ecne |
| 2769 | * |
| 2770 | * Section: Appendix A: Explicit Congestion Notification |
| 2771 | * |
| 2772 | * ECN-Echo |
| 2773 | * |
| 2774 | * RFC 2481 details a specific bit for a receiver to send back in its |
| 2775 | * TCP acknowledgements to notify the sender of the Congestion |
| 2776 | * Experienced (CE) bit having arrived from the network. For SCTP this |
| 2777 | * same indication is made by including the ECNE chunk. This chunk |
| 2778 | * contains one data element, i.e. the lowest TSN associated with the IP |
| 2779 | * datagram marked with the CE bit..... |
| 2780 | * |
| 2781 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2782 | * Inputs |
| 2783 | * (endpoint, asoc, chunk) |
| 2784 | * |
| 2785 | * Outputs |
| 2786 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2787 | * |
| 2788 | * The return value is the disposition of the chunk. |
| 2789 | */ |
| 2790 | sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep, |
| 2791 | const struct sctp_association *asoc, |
| 2792 | const sctp_subtype_t type, |
| 2793 | void *arg, |
| 2794 | sctp_cmd_seq_t *commands) |
| 2795 | { |
| 2796 | sctp_ecnehdr_t *ecne; |
| 2797 | struct sctp_chunk *chunk = arg; |
| 2798 | |
| 2799 | if (!sctp_vtag_verify(chunk, asoc)) |
| 2800 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2801 | |
| 2802 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t))) |
| 2803 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2804 | commands); |
| 2805 | |
| 2806 | ecne = (sctp_ecnehdr_t *) chunk->skb->data; |
| 2807 | skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t)); |
| 2808 | |
| 2809 | /* If this is a newer ECNE than the last CWR packet we sent out */ |
| 2810 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE, |
| 2811 | SCTP_U32(ntohl(ecne->lowest_tsn))); |
| 2812 | |
| 2813 | return SCTP_DISPOSITION_CONSUME; |
| 2814 | } |
| 2815 | |
| 2816 | /* |
| 2817 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks |
| 2818 | * |
| 2819 | * The SCTP endpoint MUST always acknowledge the reception of each valid |
| 2820 | * DATA chunk. |
| 2821 | * |
| 2822 | * The guidelines on delayed acknowledgement algorithm specified in |
| 2823 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an |
| 2824 | * acknowledgement SHOULD be generated for at least every second packet |
| 2825 | * (not every second DATA chunk) received, and SHOULD be generated within |
| 2826 | * 200 ms of the arrival of any unacknowledged DATA chunk. In some |
| 2827 | * situations it may be beneficial for an SCTP transmitter to be more |
| 2828 | * conservative than the algorithms detailed in this document allow. |
| 2829 | * However, an SCTP transmitter MUST NOT be more aggressive than the |
| 2830 | * following algorithms allow. |
| 2831 | * |
| 2832 | * A SCTP receiver MUST NOT generate more than one SACK for every |
| 2833 | * incoming packet, other than to update the offered window as the |
| 2834 | * receiving application consumes new data. |
| 2835 | * |
| 2836 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2837 | * |
| 2838 | * Inputs |
| 2839 | * (endpoint, asoc, chunk) |
| 2840 | * |
| 2841 | * Outputs |
| 2842 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2843 | * |
| 2844 | * The return value is the disposition of the chunk. |
| 2845 | */ |
| 2846 | sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep, |
| 2847 | const struct sctp_association *asoc, |
| 2848 | const sctp_subtype_t type, |
| 2849 | void *arg, |
| 2850 | sctp_cmd_seq_t *commands) |
| 2851 | { |
| 2852 | struct sctp_chunk *chunk = arg; |
| 2853 | int error; |
| 2854 | |
| 2855 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 2856 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 2857 | SCTP_NULL()); |
| 2858 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2859 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | |
| 2861 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t))) |
| 2862 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2863 | commands); |
| 2864 | |
| 2865 | error = sctp_eat_data(asoc, chunk, commands ); |
| 2866 | switch (error) { |
| 2867 | case SCTP_IERROR_NO_ERROR: |
| 2868 | break; |
| 2869 | case SCTP_IERROR_HIGH_TSN: |
| 2870 | case SCTP_IERROR_BAD_STREAM: |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 2871 | SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | goto discard_noforce; |
| 2873 | case SCTP_IERROR_DUP_TSN: |
| 2874 | case SCTP_IERROR_IGNORE_TSN: |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 2875 | SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | goto discard_force; |
| 2877 | case SCTP_IERROR_NO_DATA: |
| 2878 | goto consume; |
| 2879 | default: |
| 2880 | BUG(); |
| 2881 | } |
| 2882 | |
| 2883 | if (asoc->autoclose) { |
| 2884 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 2885 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 2886 | } |
| 2887 | |
| 2888 | /* If this is the last chunk in a packet, we need to count it |
| 2889 | * toward sack generation. Note that we need to SACK every |
| 2890 | * OTHER packet containing data chunks, EVEN IF WE DISCARD |
| 2891 | * THEM. We elect to NOT generate SACK's if the chunk fails |
| 2892 | * the verification tag test. |
| 2893 | * |
| 2894 | * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks |
| 2895 | * |
| 2896 | * The SCTP endpoint MUST always acknowledge the reception of |
| 2897 | * each valid DATA chunk. |
| 2898 | * |
| 2899 | * The guidelines on delayed acknowledgement algorithm |
| 2900 | * specified in Section 4.2 of [RFC2581] SHOULD be followed. |
| 2901 | * Specifically, an acknowledgement SHOULD be generated for at |
| 2902 | * least every second packet (not every second DATA chunk) |
| 2903 | * received, and SHOULD be generated within 200 ms of the |
| 2904 | * arrival of any unacknowledged DATA chunk. In some |
| 2905 | * situations it may be beneficial for an SCTP transmitter to |
| 2906 | * be more conservative than the algorithms detailed in this |
| 2907 | * document allow. However, an SCTP transmitter MUST NOT be |
| 2908 | * more aggressive than the following algorithms allow. |
| 2909 | */ |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 2910 | if (chunk->end_of_packet) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
| 2912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | return SCTP_DISPOSITION_CONSUME; |
| 2914 | |
| 2915 | discard_force: |
| 2916 | /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks |
| 2917 | * |
| 2918 | * When a packet arrives with duplicate DATA chunk(s) and with |
| 2919 | * no new DATA chunk(s), the endpoint MUST immediately send a |
| 2920 | * SACK with no delay. If a packet arrives with duplicate |
| 2921 | * DATA chunk(s) bundled with new DATA chunks, the endpoint |
| 2922 | * MAY immediately send a SACK. Normally receipt of duplicate |
| 2923 | * DATA chunks will occur when the original SACK chunk was lost |
| 2924 | * and the peer's RTO has expired. The duplicate TSN number(s) |
| 2925 | * SHOULD be reported in the SACK as duplicate. |
| 2926 | */ |
| 2927 | /* In our case, we split the MAY SACK advice up whether or not |
| 2928 | * the last chunk is a duplicate.' |
| 2929 | */ |
| 2930 | if (chunk->end_of_packet) |
| 2931 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 2932 | return SCTP_DISPOSITION_DISCARD; |
| 2933 | |
| 2934 | discard_noforce: |
Frank Filz | 52ccb8e | 2005-12-22 11:36:46 -0800 | [diff] [blame] | 2935 | if (chunk->end_of_packet) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
| 2937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | return SCTP_DISPOSITION_DISCARD; |
| 2939 | consume: |
| 2940 | return SCTP_DISPOSITION_CONSUME; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 2941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | /* |
| 2945 | * sctp_sf_eat_data_fast_4_4 |
| 2946 | * |
| 2947 | * Section: 4 (4) |
| 2948 | * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received |
| 2949 | * DATA chunks without delay. |
| 2950 | * |
| 2951 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 2952 | * Inputs |
| 2953 | * (endpoint, asoc, chunk) |
| 2954 | * |
| 2955 | * Outputs |
| 2956 | * (asoc, reply_msg, msg_up, timers, counters) |
| 2957 | * |
| 2958 | * The return value is the disposition of the chunk. |
| 2959 | */ |
| 2960 | sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep, |
| 2961 | const struct sctp_association *asoc, |
| 2962 | const sctp_subtype_t type, |
| 2963 | void *arg, |
| 2964 | sctp_cmd_seq_t *commands) |
| 2965 | { |
| 2966 | struct sctp_chunk *chunk = arg; |
| 2967 | int error; |
| 2968 | |
| 2969 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 2970 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 2971 | SCTP_NULL()); |
| 2972 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 2973 | } |
| 2974 | |
| 2975 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t))) |
| 2976 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 2977 | commands); |
| 2978 | |
| 2979 | error = sctp_eat_data(asoc, chunk, commands ); |
| 2980 | switch (error) { |
| 2981 | case SCTP_IERROR_NO_ERROR: |
| 2982 | case SCTP_IERROR_HIGH_TSN: |
| 2983 | case SCTP_IERROR_DUP_TSN: |
| 2984 | case SCTP_IERROR_IGNORE_TSN: |
| 2985 | case SCTP_IERROR_BAD_STREAM: |
| 2986 | break; |
| 2987 | case SCTP_IERROR_NO_DATA: |
| 2988 | goto consume; |
| 2989 | default: |
| 2990 | BUG(); |
| 2991 | } |
| 2992 | |
| 2993 | /* Go a head and force a SACK, since we are shutting down. */ |
| 2994 | |
| 2995 | /* Implementor's Guide. |
| 2996 | * |
| 2997 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately |
| 2998 | * respond to each received packet containing one or more DATA chunk(s) |
| 2999 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer |
| 3000 | */ |
| 3001 | if (chunk->end_of_packet) { |
| 3002 | /* We must delay the chunk creation since the cumulative |
| 3003 | * TSN has not been updated yet. |
| 3004 | */ |
| 3005 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); |
| 3006 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 3007 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3008 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3009 | } |
| 3010 | |
| 3011 | consume: |
| 3012 | return SCTP_DISPOSITION_CONSUME; |
| 3013 | } |
| 3014 | |
| 3015 | /* |
| 3016 | * Section: 6.2 Processing a Received SACK |
| 3017 | * D) Any time a SACK arrives, the endpoint performs the following: |
| 3018 | * |
| 3019 | * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point, |
| 3020 | * then drop the SACK. Since Cumulative TSN Ack is monotonically |
| 3021 | * increasing, a SACK whose Cumulative TSN Ack is less than the |
| 3022 | * Cumulative TSN Ack Point indicates an out-of-order SACK. |
| 3023 | * |
| 3024 | * ii) Set rwnd equal to the newly received a_rwnd minus the number |
| 3025 | * of bytes still outstanding after processing the Cumulative TSN Ack |
| 3026 | * and the Gap Ack Blocks. |
| 3027 | * |
| 3028 | * iii) If the SACK is missing a TSN that was previously |
| 3029 | * acknowledged via a Gap Ack Block (e.g., the data receiver |
| 3030 | * reneged on the data), then mark the corresponding DATA chunk |
| 3031 | * as available for retransmit: Mark it as missing for fast |
| 3032 | * retransmit as described in Section 7.2.4 and if no retransmit |
| 3033 | * timer is running for the destination address to which the DATA |
| 3034 | * chunk was originally transmitted, then T3-rtx is started for |
| 3035 | * that destination address. |
| 3036 | * |
| 3037 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3038 | * |
| 3039 | * Inputs |
| 3040 | * (endpoint, asoc, chunk) |
| 3041 | * |
| 3042 | * Outputs |
| 3043 | * (asoc, reply_msg, msg_up, timers, counters) |
| 3044 | * |
| 3045 | * The return value is the disposition of the chunk. |
| 3046 | */ |
| 3047 | sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep, |
| 3048 | const struct sctp_association *asoc, |
| 3049 | const sctp_subtype_t type, |
| 3050 | void *arg, |
| 3051 | sctp_cmd_seq_t *commands) |
| 3052 | { |
| 3053 | struct sctp_chunk *chunk = arg; |
| 3054 | sctp_sackhdr_t *sackh; |
| 3055 | __u32 ctsn; |
| 3056 | |
| 3057 | if (!sctp_vtag_verify(chunk, asoc)) |
| 3058 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3059 | |
| 3060 | /* Make sure that the SACK chunk has a valid length. */ |
| 3061 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t))) |
| 3062 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3063 | commands); |
| 3064 | |
| 3065 | /* Pull the SACK chunk from the data buffer */ |
| 3066 | sackh = sctp_sm_pull_sack(chunk); |
| 3067 | /* Was this a bogus SACK? */ |
| 3068 | if (!sackh) |
| 3069 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3070 | chunk->subh.sack_hdr = sackh; |
| 3071 | ctsn = ntohl(sackh->cum_tsn_ack); |
| 3072 | |
| 3073 | /* i) If Cumulative TSN Ack is less than the Cumulative TSN |
| 3074 | * Ack Point, then drop the SACK. Since Cumulative TSN |
| 3075 | * Ack is monotonically increasing, a SACK whose |
| 3076 | * Cumulative TSN Ack is less than the Cumulative TSN Ack |
| 3077 | * Point indicates an out-of-order SACK. |
| 3078 | */ |
| 3079 | if (TSN_lt(ctsn, asoc->ctsn_ack_point)) { |
| 3080 | SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn); |
| 3081 | SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point); |
| 3082 | return SCTP_DISPOSITION_DISCARD; |
| 3083 | } |
| 3084 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 3085 | /* If Cumulative TSN Ack beyond the max tsn currently |
| 3086 | * send, terminating the association and respond to the |
| 3087 | * sender with an ABORT. |
| 3088 | */ |
| 3089 | if (!TSN_lt(ctsn, asoc->next_tsn)) |
| 3090 | return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands); |
| 3091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | /* Return this SACK for further processing. */ |
| 3093 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh)); |
| 3094 | |
| 3095 | /* Note: We do the rest of the work on the PROCESS_SACK |
| 3096 | * sideeffect. |
| 3097 | */ |
| 3098 | return SCTP_DISPOSITION_CONSUME; |
| 3099 | } |
| 3100 | |
| 3101 | /* |
| 3102 | * Generate an ABORT in response to a packet. |
| 3103 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3104 | * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3105 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3106 | * 8) The receiver should respond to the sender of the OOTB packet with |
| 3107 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet |
| 3108 | * MUST fill in the Verification Tag field of the outbound packet |
| 3109 | * with the value found in the Verification Tag field of the OOTB |
| 3110 | * packet and set the T-bit in the Chunk Flags to indicate that the |
| 3111 | * Verification Tag is reflected. After sending this ABORT, the |
| 3112 | * receiver of the OOTB packet shall discard the OOTB packet and take |
| 3113 | * no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | * |
| 3115 | * Verification Tag: |
| 3116 | * |
| 3117 | * The return value is the disposition of the chunk. |
| 3118 | */ |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3119 | static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | const struct sctp_association *asoc, |
| 3121 | const sctp_subtype_t type, |
| 3122 | void *arg, |
| 3123 | sctp_cmd_seq_t *commands) |
| 3124 | { |
| 3125 | struct sctp_packet *packet = NULL; |
| 3126 | struct sctp_chunk *chunk = arg; |
| 3127 | struct sctp_chunk *abort; |
| 3128 | |
| 3129 | packet = sctp_ootb_pkt_new(asoc, chunk); |
| 3130 | |
| 3131 | if (packet) { |
| 3132 | /* Make an ABORT. The T bit will be set if the asoc |
| 3133 | * is NULL. |
| 3134 | */ |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3135 | abort = sctp_make_abort(asoc, chunk, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | if (!abort) { |
| 3137 | sctp_ootb_pkt_free(packet); |
| 3138 | return SCTP_DISPOSITION_NOMEM; |
| 3139 | } |
| 3140 | |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3141 | /* Reflect vtag if T-Bit is set */ |
| 3142 | if (sctp_test_T_bit(abort)) |
| 3143 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 3144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | /* Set the skb to the belonging sock for accounting. */ |
| 3146 | abort->skb->sk = ep->base.sk; |
| 3147 | |
| 3148 | sctp_packet_append_chunk(packet, abort); |
| 3149 | |
| 3150 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 3151 | SCTP_PACKET(packet)); |
| 3152 | |
| 3153 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 3154 | |
Vlad Yasevich | d3f2596 | 2007-09-07 11:47:45 -0400 | [diff] [blame] | 3155 | sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | return SCTP_DISPOSITION_CONSUME; |
| 3157 | } |
| 3158 | |
| 3159 | return SCTP_DISPOSITION_NOMEM; |
| 3160 | } |
| 3161 | |
| 3162 | /* |
| 3163 | * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR |
| 3164 | * event as ULP notification for each cause included in the chunk. |
| 3165 | * |
| 3166 | * API 5.3.1.3 - SCTP_REMOTE_ERROR |
| 3167 | * |
| 3168 | * The return value is the disposition of the chunk. |
| 3169 | */ |
| 3170 | sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep, |
| 3171 | const struct sctp_association *asoc, |
| 3172 | const sctp_subtype_t type, |
| 3173 | void *arg, |
| 3174 | sctp_cmd_seq_t *commands) |
| 3175 | { |
| 3176 | struct sctp_chunk *chunk = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | |
| 3178 | if (!sctp_vtag_verify(chunk, asoc)) |
| 3179 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3180 | |
| 3181 | /* Make sure that the ERROR chunk has a valid length. */ |
| 3182 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t))) |
| 3183 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3184 | commands); |
| 3185 | |
Wei Yongjun | 3df2678 | 2009-03-02 06:46:51 +0000 | [diff] [blame] | 3186 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR, |
| 3187 | SCTP_CHUNK(chunk)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | /* |
| 3193 | * Process an inbound SHUTDOWN ACK. |
| 3194 | * |
| 3195 | * From Section 9.2: |
| 3196 | * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall |
| 3197 | * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its |
| 3198 | * peer, and remove all record of the association. |
| 3199 | * |
| 3200 | * The return value is the disposition. |
| 3201 | */ |
| 3202 | sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep, |
| 3203 | const struct sctp_association *asoc, |
| 3204 | const sctp_subtype_t type, |
| 3205 | void *arg, |
| 3206 | sctp_cmd_seq_t *commands) |
| 3207 | { |
| 3208 | struct sctp_chunk *chunk = arg; |
| 3209 | struct sctp_chunk *reply; |
| 3210 | struct sctp_ulpevent *ev; |
| 3211 | |
| 3212 | if (!sctp_vtag_verify(chunk, asoc)) |
| 3213 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3214 | |
| 3215 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ |
| 3216 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 3217 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3218 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | /* 10.2 H) SHUTDOWN COMPLETE notification |
| 3220 | * |
| 3221 | * When SCTP completes the shutdown procedures (section 9.2) this |
| 3222 | * notification is passed to the upper layer. |
| 3223 | */ |
| 3224 | ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP, |
Vlad Yasevich | a5a35e7 | 2007-03-23 11:34:08 -0700 | [diff] [blame] | 3225 | 0, 0, 0, NULL, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | if (!ev) |
| 3227 | goto nomem; |
| 3228 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 3229 | /* ...send a SHUTDOWN COMPLETE chunk to its peer, */ |
| 3230 | reply = sctp_make_shutdown_complete(asoc, chunk); |
| 3231 | if (!reply) |
| 3232 | goto nomem_chunk; |
| 3233 | |
| 3234 | /* Do all the commands now (after allocation), so that we |
| 3235 | * have consistent state if memory allocation failes |
| 3236 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev)); |
| 3238 | |
| 3239 | /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall |
| 3240 | * stop the T2-shutdown timer, |
| 3241 | */ |
| 3242 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3243 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3244 | |
| 3245 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3246 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 3247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 3249 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 3250 | SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); |
| 3251 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 3252 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 3253 | |
| 3254 | /* ...and remove all record of the association. */ |
| 3255 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 3256 | return SCTP_DISPOSITION_DELETE_TCB; |
| 3257 | |
Vladislav Yasevich | df7deeb | 2006-08-22 00:19:51 -0700 | [diff] [blame] | 3258 | nomem_chunk: |
| 3259 | sctp_ulpevent_free(ev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | nomem: |
| 3261 | return SCTP_DISPOSITION_NOMEM; |
| 3262 | } |
| 3263 | |
| 3264 | /* |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3265 | * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41. |
| 3266 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
| 3268 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
| 3269 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB |
| 3270 | * packet must fill in the Verification Tag field of the outbound |
| 3271 | * packet with the Verification Tag received in the SHUTDOWN ACK and |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3272 | * set the T-bit in the Chunk Flags to indicate that the Verification |
| 3273 | * Tag is reflected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | * |
| 3275 | * 8) The receiver should respond to the sender of the OOTB packet with |
| 3276 | * an ABORT. When sending the ABORT, the receiver of the OOTB packet |
| 3277 | * MUST fill in the Verification Tag field of the outbound packet |
| 3278 | * with the value found in the Verification Tag field of the OOTB |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3279 | * packet and set the T-bit in the Chunk Flags to indicate that the |
| 3280 | * Verification Tag is reflected. After sending this ABORT, the |
| 3281 | * receiver of the OOTB packet shall discard the OOTB packet and take |
| 3282 | * no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | */ |
| 3284 | sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep, |
| 3285 | const struct sctp_association *asoc, |
| 3286 | const sctp_subtype_t type, |
| 3287 | void *arg, |
| 3288 | sctp_cmd_seq_t *commands) |
| 3289 | { |
| 3290 | struct sctp_chunk *chunk = arg; |
| 3291 | struct sk_buff *skb = chunk->skb; |
| 3292 | sctp_chunkhdr_t *ch; |
| 3293 | __u8 *ch_end; |
| 3294 | int ootb_shut_ack = 0; |
| 3295 | |
| 3296 | SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES); |
| 3297 | |
| 3298 | ch = (sctp_chunkhdr_t *) chunk->chunk_hdr; |
| 3299 | do { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3300 | /* Report violation if the chunk is less then minimal */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t)) |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3302 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3303 | commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3305 | /* Now that we know we at least have a chunk header, |
| 3306 | * do things that are type appropriate. |
| 3307 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | if (SCTP_CID_SHUTDOWN_ACK == ch->type) |
| 3309 | ootb_shut_ack = 1; |
| 3310 | |
| 3311 | /* RFC 2960, Section 3.3.7 |
| 3312 | * Moreover, under any circumstances, an endpoint that |
| 3313 | * receives an ABORT MUST NOT respond to that ABORT by |
| 3314 | * sending an ABORT of its own. |
| 3315 | */ |
| 3316 | if (SCTP_CID_ABORT == ch->type) |
| 3317 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3318 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3319 | /* Report violation if chunk len overflows */ |
| 3320 | ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); |
| 3321 | if (ch_end > skb_tail_pointer(skb)) |
| 3322 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3323 | commands); |
| 3324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | ch = (sctp_chunkhdr_t *) ch_end; |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 3326 | } while (ch_end < skb_tail_pointer(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | |
| 3328 | if (ootb_shut_ack) |
Vlad Yasevich | d3f2596 | 2007-09-07 11:47:45 -0400 | [diff] [blame] | 3329 | return sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | else |
Vlad Yasevich | d3f2596 | 2007-09-07 11:47:45 -0400 | [diff] [blame] | 3331 | return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | /* |
| 3335 | * Handle an "Out of the blue" SHUTDOWN ACK. |
| 3336 | * |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3337 | * Section: 8.4 5, sctpimpguide 2.41. |
| 3338 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3339 | * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3340 | * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE. |
| 3341 | * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB |
| 3342 | * packet must fill in the Verification Tag field of the outbound |
| 3343 | * packet with the Verification Tag received in the SHUTDOWN ACK and |
| 3344 | * set the T-bit in the Chunk Flags to indicate that the Verification |
| 3345 | * Tag is reflected. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | * |
| 3347 | * Inputs |
| 3348 | * (endpoint, asoc, type, arg, commands) |
| 3349 | * |
| 3350 | * Outputs |
| 3351 | * (sctp_disposition_t) |
| 3352 | * |
| 3353 | * The return value is the disposition of the chunk. |
| 3354 | */ |
| 3355 | static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep, |
| 3356 | const struct sctp_association *asoc, |
| 3357 | const sctp_subtype_t type, |
| 3358 | void *arg, |
| 3359 | sctp_cmd_seq_t *commands) |
| 3360 | { |
| 3361 | struct sctp_packet *packet = NULL; |
| 3362 | struct sctp_chunk *chunk = arg; |
| 3363 | struct sctp_chunk *shut; |
| 3364 | |
| 3365 | packet = sctp_ootb_pkt_new(asoc, chunk); |
| 3366 | |
| 3367 | if (packet) { |
| 3368 | /* Make an SHUTDOWN_COMPLETE. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3369 | * The T bit will be set if the asoc is NULL. |
| 3370 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3371 | shut = sctp_make_shutdown_complete(asoc, chunk); |
| 3372 | if (!shut) { |
| 3373 | sctp_ootb_pkt_free(packet); |
| 3374 | return SCTP_DISPOSITION_NOMEM; |
| 3375 | } |
| 3376 | |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 3377 | /* Reflect vtag if T-Bit is set */ |
| 3378 | if (sctp_test_T_bit(shut)) |
| 3379 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 3380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3381 | /* Set the skb to the belonging sock for accounting. */ |
| 3382 | shut->skb->sk = ep->base.sk; |
| 3383 | |
| 3384 | sctp_packet_append_chunk(packet, shut); |
| 3385 | |
| 3386 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 3387 | SCTP_PACKET(packet)); |
| 3388 | |
| 3389 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 3390 | |
| 3391 | /* If the chunk length is invalid, we don't want to process |
| 3392 | * the reset of the packet. |
| 3393 | */ |
| 3394 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 3395 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3396 | |
Vlad Yasevich | d3f2596 | 2007-09-07 11:47:45 -0400 | [diff] [blame] | 3397 | /* We need to discard the rest of the packet to prevent |
| 3398 | * potential bomming attacks from additional bundled chunks. |
| 3399 | * This is documented in SCTP Threats ID. |
| 3400 | */ |
| 3401 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | return SCTP_DISPOSITION_NOMEM; |
| 3405 | } |
| 3406 | |
| 3407 | /* |
| 3408 | * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state. |
| 3409 | * |
| 3410 | * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK |
| 3411 | * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the |
| 3412 | * procedures in section 8.4 SHOULD be followed, in other words it |
| 3413 | * should be treated as an Out Of The Blue packet. |
| 3414 | * [This means that we do NOT check the Verification Tag on these |
| 3415 | * chunks. --piggy ] |
| 3416 | * |
| 3417 | */ |
| 3418 | sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep, |
| 3419 | const struct sctp_association *asoc, |
| 3420 | const sctp_subtype_t type, |
| 3421 | void *arg, |
| 3422 | sctp_cmd_seq_t *commands) |
| 3423 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 3424 | struct sctp_chunk *chunk = arg; |
| 3425 | |
| 3426 | /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */ |
| 3427 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 3428 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3429 | commands); |
| 3430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | /* Although we do have an association in this case, it corresponds |
| 3432 | * to a restarted association. So the packet is treated as an OOTB |
| 3433 | * packet and the state function that handles OOTB SHUTDOWN_ACK is |
| 3434 | * called with a NULL association. |
| 3435 | */ |
Wei Yongjun | 8190f89 | 2008-09-08 12:13:55 +0800 | [diff] [blame] | 3436 | SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES); |
| 3437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands); |
| 3439 | } |
| 3440 | |
| 3441 | /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */ |
| 3442 | sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep, |
| 3443 | const struct sctp_association *asoc, |
| 3444 | const sctp_subtype_t type, void *arg, |
| 3445 | sctp_cmd_seq_t *commands) |
| 3446 | { |
| 3447 | struct sctp_chunk *chunk = arg; |
| 3448 | struct sctp_chunk *asconf_ack = NULL; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3449 | struct sctp_paramhdr *err_param = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | sctp_addiphdr_t *hdr; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3451 | union sctp_addr_param *addr_param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | __u32 serial; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3453 | int length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3454 | |
| 3455 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3456 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3457 | SCTP_NULL()); |
| 3458 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3459 | } |
| 3460 | |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3461 | /* ADD-IP: Section 4.1.1 |
| 3462 | * This chunk MUST be sent in an authenticated way by using |
| 3463 | * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk |
| 3464 | * is received unauthenticated it MUST be silently discarded as |
| 3465 | * described in [I-D.ietf-tsvwg-sctp-auth]. |
| 3466 | */ |
| 3467 | if (!sctp_addip_noauth && !chunk->auth) |
| 3468 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); |
| 3469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | /* Make sure that the ASCONF ADDIP chunk has a valid length. */ |
| 3471 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t))) |
| 3472 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3473 | commands); |
| 3474 | |
| 3475 | hdr = (sctp_addiphdr_t *)chunk->skb->data; |
| 3476 | serial = ntohl(hdr->serial); |
| 3477 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3478 | addr_param = (union sctp_addr_param *)hdr->params; |
| 3479 | length = ntohs(addr_param->p.length); |
| 3480 | if (length < sizeof(sctp_paramhdr_t)) |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3481 | return sctp_sf_violation_paramlen(ep, asoc, type, arg, |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3482 | (void *)addr_param, commands); |
| 3483 | |
| 3484 | /* Verify the ASCONF chunk before processing it. */ |
| 3485 | if (!sctp_verify_asconf(asoc, |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3486 | (sctp_paramhdr_t *)((void *)addr_param + length), |
| 3487 | (void *)chunk->chunk_end, |
| 3488 | &err_param)) |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3489 | return sctp_sf_violation_paramlen(ep, asoc, type, arg, |
| 3490 | (void *)err_param, commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3491 | |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3492 | /* 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] | 3493 | * the endpoint stored in a new association variable |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3494 | * 'Peer-Serial-Number'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | */ |
| 3496 | if (serial == asoc->peer.addip_serial + 1) { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3497 | /* If this is the first instance of ASCONF in the packet, |
| 3498 | * we can clean our old ASCONF-ACKs. |
| 3499 | */ |
| 3500 | if (!chunk->has_asconf) |
| 3501 | sctp_assoc_clean_asconf_ack_cache(asoc); |
| 3502 | |
| 3503 | /* ADDIP 5.2 E4) When the Sequence Number matches the next one |
| 3504 | * expected, process the ASCONF as described below and after |
| 3505 | * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to |
| 3506 | * the response packet and cache a copy of it (in the event it |
| 3507 | * later needs to be retransmitted). |
| 3508 | * |
| 3509 | * Essentially, do V1-V5. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3510 | */ |
| 3511 | asconf_ack = sctp_process_asconf((struct sctp_association *) |
| 3512 | asoc, chunk); |
| 3513 | if (!asconf_ack) |
| 3514 | return SCTP_DISPOSITION_NOMEM; |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3515 | } else if (serial < asoc->peer.addip_serial + 1) { |
| 3516 | /* ADDIP 5.2 E2) |
| 3517 | * If the value found in the Sequence Number is less than the |
| 3518 | * ('Peer- Sequence-Number' + 1), simply skip to the next |
| 3519 | * ASCONF, and include in the outbound response packet |
| 3520 | * any previously cached ASCONF-ACK response that was |
| 3521 | * sent and saved that matches the Sequence Number of the |
| 3522 | * ASCONF. Note: It is possible that no cached ASCONF-ACK |
| 3523 | * Chunk exists. This will occur when an older ASCONF |
| 3524 | * arrives out of order. In such a case, the receiver |
| 3525 | * should skip the ASCONF Chunk and not include ASCONF-ACK |
| 3526 | * Chunk for that chunk. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | */ |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3528 | asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial); |
| 3529 | if (!asconf_ack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | return SCTP_DISPOSITION_DISCARD; |
| 3531 | } else { |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3532 | /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3533 | * it must be either a stale packet or from an attacker. |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3534 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | return SCTP_DISPOSITION_DISCARD; |
| 3536 | } |
| 3537 | |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3538 | /* ADDIP 5.2 E6) The destination address of the SCTP packet |
| 3539 | * containing the ASCONF-ACK Chunks MUST be the source address of |
| 3540 | * the SCTP packet that held the ASCONF Chunks. |
| 3541 | * |
| 3542 | * To do this properly, we'll set the destination address of the chunk |
| 3543 | * and at the transmit time, will try look up the transport to use. |
| 3544 | * Since ASCONFs may be bundled, the correct transport may not be |
| 3545 | * created untill we process the entire packet, thus this workaround. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | */ |
Vlad Yasevich | a08de64 | 2007-12-20 14:11:47 -0800 | [diff] [blame] | 3547 | asconf_ack->dest = chunk->source; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | return SCTP_DISPOSITION_CONSUME; |
| 3551 | } |
| 3552 | |
| 3553 | /* |
| 3554 | * ADDIP Section 4.3 General rules for address manipulation |
| 3555 | * When building TLV parameters for the ASCONF Chunk that will add or |
| 3556 | * delete IP addresses the D0 to D13 rules should be applied: |
| 3557 | */ |
| 3558 | sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep, |
| 3559 | const struct sctp_association *asoc, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3560 | const sctp_subtype_t type, void *arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | sctp_cmd_seq_t *commands) |
| 3562 | { |
| 3563 | struct sctp_chunk *asconf_ack = arg; |
| 3564 | struct sctp_chunk *last_asconf = asoc->addip_last_asconf; |
| 3565 | struct sctp_chunk *abort; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3566 | struct sctp_paramhdr *err_param = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | sctp_addiphdr_t *addip_hdr; |
| 3568 | __u32 sent_serial, rcvd_serial; |
| 3569 | |
| 3570 | if (!sctp_vtag_verify(asconf_ack, asoc)) { |
| 3571 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3572 | SCTP_NULL()); |
| 3573 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3574 | } |
| 3575 | |
Vlad Yasevich | 6afd2e8 | 2007-12-20 14:08:04 -0800 | [diff] [blame] | 3576 | /* ADD-IP, Section 4.1.2: |
| 3577 | * This chunk MUST be sent in an authenticated way by using |
| 3578 | * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk |
| 3579 | * is received unauthenticated it MUST be silently discarded as |
| 3580 | * described in [I-D.ietf-tsvwg-sctp-auth]. |
| 3581 | */ |
| 3582 | if (!sctp_addip_noauth && !asconf_ack->auth) |
| 3583 | return sctp_sf_discard_chunk(ep, asoc, type, arg, commands); |
| 3584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | /* Make sure that the ADDIP chunk has a valid length. */ |
| 3586 | if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t))) |
| 3587 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3588 | commands); |
| 3589 | |
| 3590 | addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data; |
| 3591 | rcvd_serial = ntohl(addip_hdr->serial); |
| 3592 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3593 | /* Verify the ASCONF-ACK chunk before processing it. */ |
| 3594 | if (!sctp_verify_asconf(asoc, |
| 3595 | (sctp_paramhdr_t *)addip_hdr->params, |
| 3596 | (void *)asconf_ack->chunk_end, |
| 3597 | &err_param)) |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 3598 | return sctp_sf_violation_paramlen(ep, asoc, type, arg, |
| 3599 | (void *)err_param, commands); |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 3600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | if (last_asconf) { |
| 3602 | addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr; |
| 3603 | sent_serial = ntohl(addip_hdr->serial); |
| 3604 | } else { |
| 3605 | sent_serial = asoc->addip_serial - 1; |
| 3606 | } |
| 3607 | |
| 3608 | /* D0) If an endpoint receives an ASCONF-ACK that is greater than or |
| 3609 | * equal to the next serial number to be used but no ASCONF chunk is |
| 3610 | * outstanding the endpoint MUST ABORT the association. Note that a |
| 3611 | * sequence number is greater than if it is no more than 2^^31-1 |
| 3612 | * larger than the current sequence number (using serial arithmetic). |
| 3613 | */ |
| 3614 | if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) && |
| 3615 | !(asoc->addip_last_asconf)) { |
| 3616 | abort = sctp_make_abort(asoc, asconf_ack, |
| 3617 | sizeof(sctp_errhdr_t)); |
| 3618 | if (abort) { |
Wei Yongjun | 00f1c2d | 2007-08-21 15:50:01 +0800 | [diff] [blame] | 3619 | sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3621 | SCTP_CHUNK(abort)); |
| 3622 | } |
| 3623 | /* We are going to ABORT, so we might as well stop |
| 3624 | * processing the rest of the chunks in the packet. |
| 3625 | */ |
| 3626 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3627 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 3628 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 3629 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3630 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 3632 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3633 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 3634 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 3635 | return SCTP_DISPOSITION_ABORT; |
| 3636 | } |
| 3637 | |
| 3638 | if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) { |
| 3639 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 3640 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 3641 | |
| 3642 | if (!sctp_process_asconf_ack((struct sctp_association *)asoc, |
| 3643 | asconf_ack)) |
| 3644 | return SCTP_DISPOSITION_CONSUME; |
| 3645 | |
| 3646 | abort = sctp_make_abort(asoc, asconf_ack, |
| 3647 | sizeof(sctp_errhdr_t)); |
| 3648 | if (abort) { |
Wei Yongjun | 00f1c2d | 2007-08-21 15:50:01 +0800 | [diff] [blame] | 3649 | sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3651 | SCTP_CHUNK(abort)); |
| 3652 | } |
| 3653 | /* We are going to ABORT, so we might as well stop |
| 3654 | * processing the rest of the chunks in the packet. |
| 3655 | */ |
| 3656 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 3657 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3658 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 3660 | SCTP_PERR(SCTP_ERROR_ASCONF_ACK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 3662 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 3663 | return SCTP_DISPOSITION_ABORT; |
| 3664 | } |
| 3665 | |
| 3666 | return SCTP_DISPOSITION_DISCARD; |
| 3667 | } |
| 3668 | |
| 3669 | /* |
| 3670 | * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP |
| 3671 | * |
| 3672 | * When a FORWARD TSN chunk arrives, the data receiver MUST first update |
| 3673 | * its cumulative TSN point to the value carried in the FORWARD TSN |
| 3674 | * chunk, and then MUST further advance its cumulative TSN point locally |
| 3675 | * if possible. |
| 3676 | * After the above processing, the data receiver MUST stop reporting any |
| 3677 | * missing TSNs earlier than or equal to the new cumulative TSN point. |
| 3678 | * |
| 3679 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3680 | * |
| 3681 | * The return value is the disposition of the chunk. |
| 3682 | */ |
| 3683 | sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep, |
| 3684 | const struct sctp_association *asoc, |
| 3685 | const sctp_subtype_t type, |
| 3686 | void *arg, |
| 3687 | sctp_cmd_seq_t *commands) |
| 3688 | { |
| 3689 | struct sctp_chunk *chunk = arg; |
| 3690 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3691 | struct sctp_fwdtsn_skip *skip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | __u16 len; |
| 3693 | __u32 tsn; |
| 3694 | |
| 3695 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3696 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3697 | SCTP_NULL()); |
| 3698 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3699 | } |
| 3700 | |
| 3701 | /* Make sure that the FORWARD_TSN chunk has valid length. */ |
| 3702 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) |
| 3703 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3704 | commands); |
| 3705 | |
| 3706 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; |
| 3707 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; |
| 3708 | len = ntohs(chunk->chunk_hdr->length); |
| 3709 | len -= sizeof(struct sctp_chunkhdr); |
| 3710 | skb_pull(chunk->skb, len); |
| 3711 | |
| 3712 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 3713 | SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | |
| 3715 | /* The TSN is too high--silently discard the chunk and count on it |
| 3716 | * getting retransmitted later. |
| 3717 | */ |
| 3718 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) |
| 3719 | goto discard_noforce; |
| 3720 | |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3721 | /* Silently discard the chunk if stream-id is not valid */ |
| 3722 | sctp_walk_fwdtsn(skip, chunk) { |
| 3723 | if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams) |
| 3724 | goto discard_noforce; |
| 3725 | } |
| 3726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3727 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); |
| 3728 | if (len > sizeof(struct sctp_fwdtsn_hdr)) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3729 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | SCTP_CHUNK(chunk)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | /* Count this as receiving DATA. */ |
| 3733 | if (asoc->autoclose) { |
| 3734 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3735 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 3736 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | /* FIXME: For now send a SACK, but DATA processing may |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3739 | * send another. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | */ |
| 3741 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | |
| 3743 | return SCTP_DISPOSITION_CONSUME; |
| 3744 | |
| 3745 | discard_noforce: |
| 3746 | return SCTP_DISPOSITION_DISCARD; |
| 3747 | } |
| 3748 | |
| 3749 | sctp_disposition_t sctp_sf_eat_fwd_tsn_fast( |
| 3750 | const struct sctp_endpoint *ep, |
| 3751 | const struct sctp_association *asoc, |
| 3752 | const sctp_subtype_t type, |
| 3753 | void *arg, |
| 3754 | sctp_cmd_seq_t *commands) |
| 3755 | { |
| 3756 | struct sctp_chunk *chunk = arg; |
| 3757 | struct sctp_fwdtsn_hdr *fwdtsn_hdr; |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3758 | struct sctp_fwdtsn_skip *skip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | __u16 len; |
| 3760 | __u32 tsn; |
| 3761 | |
| 3762 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3763 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3764 | SCTP_NULL()); |
| 3765 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3766 | } |
| 3767 | |
| 3768 | /* Make sure that the FORWARD_TSN chunk has a valid length. */ |
| 3769 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk))) |
| 3770 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3771 | commands); |
| 3772 | |
| 3773 | fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data; |
| 3774 | chunk->subh.fwdtsn_hdr = fwdtsn_hdr; |
| 3775 | len = ntohs(chunk->chunk_hdr->length); |
| 3776 | len -= sizeof(struct sctp_chunkhdr); |
| 3777 | skb_pull(chunk->skb, len); |
| 3778 | |
| 3779 | tsn = ntohl(fwdtsn_hdr->new_cum_tsn); |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 3780 | SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__, tsn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
| 3782 | /* The TSN is too high--silently discard the chunk and count on it |
| 3783 | * getting retransmitted later. |
| 3784 | */ |
| 3785 | if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0) |
| 3786 | goto gen_shutdown; |
| 3787 | |
Wei Yongjun | 9fcb95a | 2008-12-25 16:58:11 -0800 | [diff] [blame] | 3788 | /* Silently discard the chunk if stream-id is not valid */ |
| 3789 | sctp_walk_fwdtsn(skip, chunk) { |
| 3790 | if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams) |
| 3791 | goto gen_shutdown; |
| 3792 | } |
| 3793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn)); |
| 3795 | if (len > sizeof(struct sctp_fwdtsn_hdr)) |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3796 | sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | SCTP_CHUNK(chunk)); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3799 | /* Go a head and force a SACK, since we are shutting down. */ |
| 3800 | gen_shutdown: |
| 3801 | /* Implementor's Guide. |
| 3802 | * |
| 3803 | * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately |
| 3804 | * respond to each received packet containing one or more DATA chunk(s) |
| 3805 | * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer |
| 3806 | */ |
| 3807 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL()); |
| 3808 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 3809 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 3810 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 3811 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 3812 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | /* |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 3816 | * SCTP-AUTH Section 6.3 Receving authenticated chukns |
| 3817 | * |
| 3818 | * The receiver MUST use the HMAC algorithm indicated in the HMAC |
| 3819 | * Identifier field. If this algorithm was not specified by the |
| 3820 | * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk |
| 3821 | * during association setup, the AUTH chunk and all chunks after it MUST |
| 3822 | * be discarded and an ERROR chunk SHOULD be sent with the error cause |
| 3823 | * defined in Section 4.1. |
| 3824 | * |
| 3825 | * If an endpoint with no shared key receives a Shared Key Identifier |
| 3826 | * other than 0, it MUST silently discard all authenticated chunks. If |
| 3827 | * the endpoint has at least one endpoint pair shared key for the peer, |
| 3828 | * it MUST use the key specified by the Shared Key Identifier if a |
| 3829 | * key has been configured for that Shared Key Identifier. If no |
| 3830 | * endpoint pair shared key has been configured for that Shared Key |
| 3831 | * Identifier, all authenticated chunks MUST be silently discarded. |
| 3832 | * |
| 3833 | * Verification Tag: 8.5 Verification Tag [Normal verification] |
| 3834 | * |
| 3835 | * The return value is the disposition of the chunk. |
| 3836 | */ |
| 3837 | static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep, |
| 3838 | const struct sctp_association *asoc, |
| 3839 | const sctp_subtype_t type, |
| 3840 | struct sctp_chunk *chunk) |
| 3841 | { |
| 3842 | struct sctp_authhdr *auth_hdr; |
| 3843 | struct sctp_hmac *hmac; |
| 3844 | unsigned int sig_len; |
| 3845 | __u16 key_id; |
| 3846 | __u8 *save_digest; |
| 3847 | __u8 *digest; |
| 3848 | |
| 3849 | /* Pull in the auth header, so we can do some more verification */ |
| 3850 | auth_hdr = (struct sctp_authhdr *)chunk->skb->data; |
| 3851 | chunk->subh.auth_hdr = auth_hdr; |
| 3852 | skb_pull(chunk->skb, sizeof(struct sctp_authhdr)); |
| 3853 | |
| 3854 | /* Make sure that we suport the HMAC algorithm from the auth |
| 3855 | * chunk. |
| 3856 | */ |
| 3857 | if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id)) |
| 3858 | return SCTP_IERROR_AUTH_BAD_HMAC; |
| 3859 | |
| 3860 | /* Make sure that the provided shared key identifier has been |
| 3861 | * configured |
| 3862 | */ |
| 3863 | key_id = ntohs(auth_hdr->shkey_id); |
| 3864 | if (key_id != asoc->active_key_id && !sctp_auth_get_shkey(asoc, key_id)) |
| 3865 | return SCTP_IERROR_AUTH_BAD_KEYID; |
| 3866 | |
| 3867 | |
| 3868 | /* Make sure that the length of the signature matches what |
| 3869 | * we expect. |
| 3870 | */ |
| 3871 | sig_len = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_auth_chunk_t); |
| 3872 | hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id)); |
| 3873 | if (sig_len != hmac->hmac_len) |
| 3874 | return SCTP_IERROR_PROTO_VIOLATION; |
| 3875 | |
| 3876 | /* Now that we've done validation checks, we can compute and |
| 3877 | * verify the hmac. The steps involved are: |
| 3878 | * 1. Save the digest from the chunk. |
| 3879 | * 2. Zero out the digest in the chunk. |
| 3880 | * 3. Compute the new digest |
| 3881 | * 4. Compare saved and new digests. |
| 3882 | */ |
| 3883 | digest = auth_hdr->hmac; |
| 3884 | skb_pull(chunk->skb, sig_len); |
| 3885 | |
| 3886 | save_digest = kmemdup(digest, sig_len, GFP_ATOMIC); |
| 3887 | if (!save_digest) |
| 3888 | goto nomem; |
| 3889 | |
| 3890 | memset(digest, 0, sig_len); |
| 3891 | |
| 3892 | sctp_auth_calculate_hmac(asoc, chunk->skb, |
| 3893 | (struct sctp_auth_chunk *)chunk->chunk_hdr, |
| 3894 | GFP_ATOMIC); |
| 3895 | |
| 3896 | /* Discard the packet if the digests do not match */ |
| 3897 | if (memcmp(save_digest, digest, sig_len)) { |
| 3898 | kfree(save_digest); |
| 3899 | return SCTP_IERROR_BAD_SIG; |
| 3900 | } |
| 3901 | |
| 3902 | kfree(save_digest); |
| 3903 | chunk->auth = 1; |
| 3904 | |
| 3905 | return SCTP_IERROR_NO_ERROR; |
| 3906 | nomem: |
| 3907 | return SCTP_IERROR_NOMEM; |
| 3908 | } |
| 3909 | |
| 3910 | sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep, |
| 3911 | const struct sctp_association *asoc, |
| 3912 | const sctp_subtype_t type, |
| 3913 | void *arg, |
| 3914 | sctp_cmd_seq_t *commands) |
| 3915 | { |
| 3916 | struct sctp_authhdr *auth_hdr; |
| 3917 | struct sctp_chunk *chunk = arg; |
| 3918 | struct sctp_chunk *err_chunk; |
| 3919 | sctp_ierror_t error; |
| 3920 | |
Wei Yongjun | d2f19fa | 2008-02-05 03:02:26 -0800 | [diff] [blame] | 3921 | /* Make sure that the peer has AUTH capable */ |
| 3922 | if (!asoc->peer.auth_capable) |
| 3923 | return sctp_sf_unk_chunk(ep, asoc, type, arg, commands); |
| 3924 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 3925 | if (!sctp_vtag_verify(chunk, asoc)) { |
| 3926 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG, |
| 3927 | SCTP_NULL()); |
| 3928 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3929 | } |
| 3930 | |
| 3931 | /* Make sure that the AUTH chunk has valid length. */ |
| 3932 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk))) |
| 3933 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3934 | commands); |
| 3935 | |
| 3936 | auth_hdr = (struct sctp_authhdr *)chunk->skb->data; |
| 3937 | error = sctp_sf_authenticate(ep, asoc, type, chunk); |
| 3938 | switch (error) { |
| 3939 | case SCTP_IERROR_AUTH_BAD_HMAC: |
| 3940 | /* Generate the ERROR chunk and discard the rest |
| 3941 | * of the packet |
| 3942 | */ |
| 3943 | err_chunk = sctp_make_op_error(asoc, chunk, |
| 3944 | SCTP_ERROR_UNSUP_HMAC, |
| 3945 | &auth_hdr->hmac_id, |
| 3946 | sizeof(__u16)); |
| 3947 | if (err_chunk) { |
| 3948 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 3949 | SCTP_CHUNK(err_chunk)); |
| 3950 | } |
| 3951 | /* Fall Through */ |
| 3952 | case SCTP_IERROR_AUTH_BAD_KEYID: |
| 3953 | case SCTP_IERROR_BAD_SIG: |
| 3954 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 3955 | break; |
| 3956 | case SCTP_IERROR_PROTO_VIOLATION: |
| 3957 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 3958 | commands); |
| 3959 | break; |
| 3960 | case SCTP_IERROR_NOMEM: |
| 3961 | return SCTP_DISPOSITION_NOMEM; |
| 3962 | default: |
| 3963 | break; |
| 3964 | } |
| 3965 | |
Vlad Yasevich | 65b07e5 | 2007-09-16 19:34:00 -0700 | [diff] [blame] | 3966 | if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) { |
| 3967 | struct sctp_ulpevent *ev; |
| 3968 | |
| 3969 | ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id), |
| 3970 | SCTP_AUTH_NEWKEY, GFP_ATOMIC); |
| 3971 | |
| 3972 | if (!ev) |
| 3973 | return -ENOMEM; |
| 3974 | |
| 3975 | sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, |
| 3976 | SCTP_ULPEVENT(ev)); |
| 3977 | } |
| 3978 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 3979 | return SCTP_DISPOSITION_CONSUME; |
| 3980 | } |
| 3981 | |
| 3982 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3983 | * Process an unknown chunk. |
| 3984 | * |
| 3985 | * Section: 3.2. Also, 2.1 in the implementor's guide. |
| 3986 | * |
| 3987 | * Chunk Types are encoded such that the highest-order two bits specify |
| 3988 | * the action that must be taken if the processing endpoint does not |
| 3989 | * recognize the Chunk Type. |
| 3990 | * |
| 3991 | * 00 - Stop processing this SCTP packet and discard it, do not process |
| 3992 | * any further chunks within it. |
| 3993 | * |
| 3994 | * 01 - Stop processing this SCTP packet and discard it, do not process |
| 3995 | * any further chunks within it, and report the unrecognized |
| 3996 | * chunk in an 'Unrecognized Chunk Type'. |
| 3997 | * |
| 3998 | * 10 - Skip this chunk and continue processing. |
| 3999 | * |
| 4000 | * 11 - Skip this chunk and continue processing, but report in an ERROR |
| 4001 | * Chunk using the 'Unrecognized Chunk Type' cause of error. |
| 4002 | * |
| 4003 | * The return value is the disposition of the chunk. |
| 4004 | */ |
| 4005 | sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep, |
| 4006 | const struct sctp_association *asoc, |
| 4007 | const sctp_subtype_t type, |
| 4008 | void *arg, |
| 4009 | sctp_cmd_seq_t *commands) |
| 4010 | { |
| 4011 | struct sctp_chunk *unk_chunk = arg; |
| 4012 | struct sctp_chunk *err_chunk; |
| 4013 | sctp_chunkhdr_t *hdr; |
| 4014 | |
| 4015 | SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk); |
| 4016 | |
| 4017 | if (!sctp_vtag_verify(unk_chunk, asoc)) |
| 4018 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 4019 | |
| 4020 | /* Make sure that the chunk has a valid length. |
| 4021 | * Since we don't know the chunk type, we use a general |
| 4022 | * chunkhdr structure to make a comparison. |
| 4023 | */ |
| 4024 | if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t))) |
| 4025 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 4026 | commands); |
| 4027 | |
| 4028 | switch (type.chunk & SCTP_CID_ACTION_MASK) { |
| 4029 | case SCTP_CID_ACTION_DISCARD: |
| 4030 | /* Discard the packet. */ |
| 4031 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 4032 | break; |
| 4033 | case SCTP_CID_ACTION_DISCARD_ERR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | /* Generate an ERROR chunk as response. */ |
| 4035 | hdr = unk_chunk->chunk_hdr; |
| 4036 | err_chunk = sctp_make_op_error(asoc, unk_chunk, |
| 4037 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, |
| 4038 | WORD_ROUND(ntohs(hdr->length))); |
| 4039 | if (err_chunk) { |
| 4040 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4041 | SCTP_CHUNK(err_chunk)); |
| 4042 | } |
Vlad Yasevich | 2e3216c | 2008-06-19 16:08:18 -0700 | [diff] [blame] | 4043 | |
| 4044 | /* Discard the packet. */ |
| 4045 | sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | return SCTP_DISPOSITION_CONSUME; |
| 4047 | break; |
| 4048 | case SCTP_CID_ACTION_SKIP: |
| 4049 | /* Skip the chunk. */ |
| 4050 | return SCTP_DISPOSITION_DISCARD; |
| 4051 | break; |
| 4052 | case SCTP_CID_ACTION_SKIP_ERR: |
| 4053 | /* Generate an ERROR chunk as response. */ |
| 4054 | hdr = unk_chunk->chunk_hdr; |
| 4055 | err_chunk = sctp_make_op_error(asoc, unk_chunk, |
| 4056 | SCTP_ERROR_UNKNOWN_CHUNK, hdr, |
| 4057 | WORD_ROUND(ntohs(hdr->length))); |
| 4058 | if (err_chunk) { |
| 4059 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 4060 | SCTP_CHUNK(err_chunk)); |
| 4061 | } |
| 4062 | /* Skip the chunk. */ |
| 4063 | return SCTP_DISPOSITION_CONSUME; |
| 4064 | break; |
| 4065 | default: |
| 4066 | break; |
| 4067 | } |
| 4068 | |
| 4069 | return SCTP_DISPOSITION_DISCARD; |
| 4070 | } |
| 4071 | |
| 4072 | /* |
| 4073 | * Discard the chunk. |
| 4074 | * |
| 4075 | * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2 |
| 4076 | * [Too numerous to mention...] |
| 4077 | * Verification Tag: No verification needed. |
| 4078 | * Inputs |
| 4079 | * (endpoint, asoc, chunk) |
| 4080 | * |
| 4081 | * Outputs |
| 4082 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4083 | * |
| 4084 | * The return value is the disposition of the chunk. |
| 4085 | */ |
| 4086 | sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep, |
| 4087 | const struct sctp_association *asoc, |
| 4088 | const sctp_subtype_t type, |
| 4089 | void *arg, |
| 4090 | sctp_cmd_seq_t *commands) |
| 4091 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4092 | struct sctp_chunk *chunk = arg; |
| 4093 | |
| 4094 | /* Make sure that the chunk has a valid length. |
| 4095 | * Since we don't know the chunk type, we use a general |
| 4096 | * chunkhdr structure to make a comparison. |
| 4097 | */ |
| 4098 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 4099 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 4100 | commands); |
| 4101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4102 | SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk); |
| 4103 | return SCTP_DISPOSITION_DISCARD; |
| 4104 | } |
| 4105 | |
| 4106 | /* |
| 4107 | * Discard the whole packet. |
| 4108 | * |
| 4109 | * Section: 8.4 2) |
| 4110 | * |
| 4111 | * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST |
| 4112 | * silently discard the OOTB packet and take no further action. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4113 | * |
| 4114 | * Verification Tag: No verification necessary |
| 4115 | * |
| 4116 | * Inputs |
| 4117 | * (endpoint, asoc, chunk) |
| 4118 | * |
| 4119 | * Outputs |
| 4120 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4121 | * |
| 4122 | * The return value is the disposition of the chunk. |
| 4123 | */ |
| 4124 | sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep, |
| 4125 | const struct sctp_association *asoc, |
| 4126 | const sctp_subtype_t type, |
| 4127 | void *arg, |
| 4128 | sctp_cmd_seq_t *commands) |
| 4129 | { |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 4130 | SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL()); |
| 4132 | |
| 4133 | return SCTP_DISPOSITION_CONSUME; |
| 4134 | } |
| 4135 | |
| 4136 | |
| 4137 | /* |
| 4138 | * The other end is violating protocol. |
| 4139 | * |
| 4140 | * Section: Not specified |
| 4141 | * Verification Tag: Not specified |
| 4142 | * Inputs |
| 4143 | * (endpoint, asoc, chunk) |
| 4144 | * |
| 4145 | * Outputs |
| 4146 | * (asoc, reply_msg, msg_up, timers, counters) |
| 4147 | * |
| 4148 | * We simply tag the chunk as a violation. The state machine will log |
| 4149 | * the violation and continue. |
| 4150 | */ |
| 4151 | sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep, |
| 4152 | const struct sctp_association *asoc, |
| 4153 | const sctp_subtype_t type, |
| 4154 | void *arg, |
| 4155 | sctp_cmd_seq_t *commands) |
| 4156 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4157 | struct sctp_chunk *chunk = arg; |
| 4158 | |
| 4159 | /* Make sure that the chunk has a valid length. */ |
| 4160 | if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t))) |
| 4161 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 4162 | commands); |
| 4163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | return SCTP_DISPOSITION_VIOLATION; |
| 4165 | } |
| 4166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4167 | /* |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4168 | * Common function to handle a protocol violation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | */ |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4170 | static sctp_disposition_t sctp_sf_abort_violation( |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4171 | const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | const struct sctp_association *asoc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | void *arg, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4174 | sctp_cmd_seq_t *commands, |
| 4175 | const __u8 *payload, |
| 4176 | const size_t paylen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4178 | struct sctp_packet *packet = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | struct sctp_chunk *chunk = arg; |
| 4180 | struct sctp_chunk *abort = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4182 | /* SCTP-AUTH, Section 6.3: |
| 4183 | * It should be noted that if the receiver wants to tear |
| 4184 | * down an association in an authenticated way only, the |
| 4185 | * handling of malformed packets should not result in |
| 4186 | * tearing down the association. |
| 4187 | * |
| 4188 | * This means that if we only want to abort associations |
| 4189 | * in an authenticated way (i.e AUTH+ABORT), then we |
Oliver Pinter | ac461a0 | 2008-02-03 17:52:41 +0200 | [diff] [blame] | 4190 | * can't destroy this association just becuase the packet |
Vlad Yasevich | bbd0d59 | 2007-10-03 17:51:34 -0700 | [diff] [blame] | 4191 | * was malformed. |
| 4192 | */ |
| 4193 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 4194 | goto discard; |
| 4195 | |
Jesper Juhl | 9abed24 | 2007-11-11 23:57:49 +0100 | [diff] [blame] | 4196 | /* Make the abort chunk. */ |
| 4197 | abort = sctp_make_abort_violation(asoc, chunk, payload, paylen); |
| 4198 | if (!abort) |
| 4199 | goto nomem; |
| 4200 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4201 | if (asoc) { |
Gui Jianfeng | f4ad85c | 2008-04-12 18:39:34 -0700 | [diff] [blame] | 4202 | /* Treat INIT-ACK as a special case during COOKIE-WAIT. */ |
| 4203 | if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK && |
| 4204 | !asoc->peer.i.init_tag) { |
| 4205 | sctp_initack_chunk_t *initack; |
| 4206 | |
| 4207 | initack = (sctp_initack_chunk_t *)chunk->chunk_hdr; |
| 4208 | if (!sctp_chunk_length_valid(chunk, |
| 4209 | sizeof(sctp_initack_chunk_t))) |
| 4210 | abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T; |
| 4211 | else { |
| 4212 | unsigned int inittag; |
| 4213 | |
| 4214 | inittag = ntohl(initack->init_hdr.init_tag); |
| 4215 | sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG, |
| 4216 | SCTP_U32(inittag)); |
| 4217 | } |
| 4218 | } |
| 4219 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4220 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
| 4221 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4223 | if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) { |
| 4224 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4225 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4226 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4227 | SCTP_ERROR(ECONNREFUSED)); |
| 4228 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
| 4229 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
| 4230 | } else { |
| 4231 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4232 | SCTP_ERROR(ECONNABORTED)); |
| 4233 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 4234 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
| 4235 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 4236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4237 | } else { |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4238 | packet = sctp_ootb_pkt_new(asoc, chunk); |
| 4239 | |
| 4240 | if (!packet) |
| 4241 | goto nomem_pkt; |
| 4242 | |
| 4243 | if (sctp_test_T_bit(abort)) |
| 4244 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 4245 | |
| 4246 | abort->skb->sk = ep->base.sk; |
| 4247 | |
| 4248 | sctp_packet_append_chunk(packet, abort); |
| 4249 | |
| 4250 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 4251 | SCTP_PACKET(packet)); |
| 4252 | |
| 4253 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 4257 | |
Vlad Yasevich | 56eb82b | 2008-10-09 14:33:01 -0700 | [diff] [blame] | 4258 | discard: |
| 4259 | sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | return SCTP_DISPOSITION_ABORT; |
| 4261 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4262 | nomem_pkt: |
| 4263 | sctp_chunk_free(abort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | nomem: |
| 4265 | return SCTP_DISPOSITION_NOMEM; |
| 4266 | } |
| 4267 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4268 | /* |
| 4269 | * Handle a protocol violation when the chunk length is invalid. |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4270 | * "Invalid" length is identified as smaller than the minimal length a |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4271 | * given chunk can be. For example, a SACK chunk has invalid length |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4272 | * if its length is set to be smaller than the size of sctp_sack_chunk_t. |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4273 | * |
| 4274 | * We inform the other end by sending an ABORT with a Protocol Violation |
| 4275 | * error code. |
| 4276 | * |
| 4277 | * Section: Not specified |
| 4278 | * Verification Tag: Nothing to do |
| 4279 | * Inputs |
| 4280 | * (endpoint, asoc, chunk) |
| 4281 | * |
| 4282 | * Outputs |
| 4283 | * (reply_msg, msg_up, counters) |
| 4284 | * |
| 4285 | * Generate an ABORT chunk and terminate the association. |
| 4286 | */ |
| 4287 | static sctp_disposition_t sctp_sf_violation_chunklen( |
| 4288 | const struct sctp_endpoint *ep, |
| 4289 | const struct sctp_association *asoc, |
| 4290 | const sctp_subtype_t type, |
| 4291 | void *arg, |
| 4292 | sctp_cmd_seq_t *commands) |
| 4293 | { |
Florian Westphal | 2444844 | 2008-03-23 22:46:34 -0700 | [diff] [blame] | 4294 | static const char err_str[]="The following chunk had invalid length:"; |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4295 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4296 | return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4297 | sizeof(err_str)); |
| 4298 | } |
| 4299 | |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4300 | /* |
| 4301 | * Handle a protocol violation when the parameter length is invalid. |
Frederik Schwarzer | 025dfda | 2008-10-16 19:02:37 +0200 | [diff] [blame] | 4302 | * "Invalid" length is identified as smaller than the minimal length a |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4303 | * given parameter can be. |
| 4304 | */ |
| 4305 | static sctp_disposition_t sctp_sf_violation_paramlen( |
| 4306 | const struct sctp_endpoint *ep, |
| 4307 | const struct sctp_association *asoc, |
| 4308 | const sctp_subtype_t type, |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4309 | void *arg, void *ext, |
| 4310 | sctp_cmd_seq_t *commands) |
| 4311 | { |
| 4312 | struct sctp_chunk *chunk = arg; |
| 4313 | struct sctp_paramhdr *param = ext; |
| 4314 | struct sctp_chunk *abort = NULL; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4315 | |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4316 | if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc)) |
| 4317 | goto discard; |
| 4318 | |
| 4319 | /* Make the abort chunk. */ |
| 4320 | abort = sctp_make_violation_paramlen(asoc, chunk, param); |
| 4321 | if (!abort) |
| 4322 | goto nomem; |
| 4323 | |
| 4324 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
| 4325 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 4326 | |
| 4327 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4328 | SCTP_ERROR(ECONNABORTED)); |
| 4329 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
| 4330 | SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION)); |
| 4331 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
Vlad Yasevich | 56eb82b | 2008-10-09 14:33:01 -0700 | [diff] [blame] | 4332 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4333 | |
| 4334 | discard: |
| 4335 | sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands); |
Wei Yongjun | ba01667 | 2008-09-30 05:32:24 -0700 | [diff] [blame] | 4336 | return SCTP_DISPOSITION_ABORT; |
| 4337 | nomem: |
| 4338 | return SCTP_DISPOSITION_NOMEM; |
Wei Yongjun | 6f4c618 | 2007-09-19 17:19:52 +0800 | [diff] [blame] | 4339 | } |
| 4340 | |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4341 | /* Handle a protocol violation when the peer trying to advance the |
| 4342 | * cumulative tsn ack to a point beyond the max tsn currently sent. |
| 4343 | * |
| 4344 | * We inform the other end by sending an ABORT with a Protocol Violation |
| 4345 | * error code. |
| 4346 | */ |
| 4347 | static sctp_disposition_t sctp_sf_violation_ctsn( |
| 4348 | const struct sctp_endpoint *ep, |
| 4349 | const struct sctp_association *asoc, |
| 4350 | const sctp_subtype_t type, |
| 4351 | void *arg, |
| 4352 | sctp_cmd_seq_t *commands) |
| 4353 | { |
Florian Westphal | 2444844 | 2008-03-23 22:46:34 -0700 | [diff] [blame] | 4354 | 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] | 4355 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4356 | return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str, |
Wei Yongjun | aecedea | 2007-08-02 16:57:44 +0800 | [diff] [blame] | 4357 | sizeof(err_str)); |
| 4358 | } |
| 4359 | |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4360 | /* Handle protocol violation of an invalid chunk bundling. For example, |
| 4361 | * when we have an association and we recieve bundled INIT-ACK, or |
| 4362 | * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle" |
| 4363 | * statement from the specs. Additinally, there might be an attacker |
| 4364 | * on the path and we may not want to continue this communication. |
| 4365 | */ |
| 4366 | static sctp_disposition_t sctp_sf_violation_chunk( |
| 4367 | const struct sctp_endpoint *ep, |
| 4368 | const struct sctp_association *asoc, |
| 4369 | const sctp_subtype_t type, |
| 4370 | void *arg, |
| 4371 | sctp_cmd_seq_t *commands) |
| 4372 | { |
Florian Westphal | 2444844 | 2008-03-23 22:46:34 -0700 | [diff] [blame] | 4373 | static const char err_str[]="The following chunk violates protocol:"; |
Vlad Yasevich | ece25df | 2007-09-07 16:30:54 -0400 | [diff] [blame] | 4374 | |
| 4375 | if (!asoc) |
| 4376 | return sctp_sf_violation(ep, asoc, type, arg, commands); |
| 4377 | |
| 4378 | return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str, |
| 4379 | sizeof(err_str)); |
| 4380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | /*************************************************************************** |
| 4382 | * These are the state functions for handling primitive (Section 10) events. |
| 4383 | ***************************************************************************/ |
| 4384 | /* |
| 4385 | * sctp_sf_do_prm_asoc |
| 4386 | * |
| 4387 | * Section: 10.1 ULP-to-SCTP |
| 4388 | * B) Associate |
| 4389 | * |
| 4390 | * Format: ASSOCIATE(local SCTP instance name, destination transport addr, |
| 4391 | * outbound stream count) |
| 4392 | * -> association id [,destination transport addr list] [,outbound stream |
| 4393 | * count] |
| 4394 | * |
| 4395 | * This primitive allows the upper layer to initiate an association to a |
| 4396 | * specific peer endpoint. |
| 4397 | * |
| 4398 | * The peer endpoint shall be specified by one of the transport addresses |
| 4399 | * which defines the endpoint (see Section 1.4). If the local SCTP |
| 4400 | * instance has not been initialized, the ASSOCIATE is considered an |
| 4401 | * error. |
| 4402 | * [This is not relevant for the kernel implementation since we do all |
| 4403 | * initialization at boot time. It we hadn't initialized we wouldn't |
| 4404 | * get anywhere near this code.] |
| 4405 | * |
| 4406 | * An association id, which is a local handle to the SCTP association, |
| 4407 | * will be returned on successful establishment of the association. If |
| 4408 | * SCTP is not able to open an SCTP association with the peer endpoint, |
| 4409 | * an error is returned. |
| 4410 | * [In the kernel implementation, the struct sctp_association needs to |
| 4411 | * be created BEFORE causing this primitive to run.] |
| 4412 | * |
| 4413 | * Other association parameters may be returned, including the |
| 4414 | * complete destination transport addresses of the peer as well as the |
| 4415 | * outbound stream count of the local endpoint. One of the transport |
| 4416 | * address from the returned destination addresses will be selected by |
| 4417 | * the local endpoint as default primary path for sending SCTP packets |
| 4418 | * to this peer. The returned "destination transport addr list" can |
| 4419 | * be used by the ULP to change the default primary path or to force |
| 4420 | * sending a packet to a specific transport address. [All of this |
| 4421 | * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING |
| 4422 | * function.] |
| 4423 | * |
| 4424 | * Mandatory attributes: |
| 4425 | * |
| 4426 | * o local SCTP instance name - obtained from the INITIALIZE operation. |
| 4427 | * [This is the argument asoc.] |
| 4428 | * o destination transport addr - specified as one of the transport |
| 4429 | * addresses of the peer endpoint with which the association is to be |
| 4430 | * established. |
| 4431 | * [This is asoc->peer.active_path.] |
| 4432 | * o outbound stream count - the number of outbound streams the ULP |
| 4433 | * would like to open towards this peer endpoint. |
| 4434 | * [BUG: This is not currently implemented.] |
| 4435 | * Optional attributes: |
| 4436 | * |
| 4437 | * None. |
| 4438 | * |
| 4439 | * The return value is a disposition. |
| 4440 | */ |
| 4441 | sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep, |
| 4442 | const struct sctp_association *asoc, |
| 4443 | const sctp_subtype_t type, |
| 4444 | void *arg, |
| 4445 | sctp_cmd_seq_t *commands) |
| 4446 | { |
| 4447 | struct sctp_chunk *repl; |
Vlad Yasevich | ab38fb0 | 2008-04-12 18:40:06 -0700 | [diff] [blame] | 4448 | struct sctp_association* my_asoc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | |
| 4450 | /* The comment below says that we enter COOKIE-WAIT AFTER |
| 4451 | * sending the INIT, but that doesn't actually work in our |
| 4452 | * implementation... |
| 4453 | */ |
| 4454 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4455 | SCTP_STATE(SCTP_STATE_COOKIE_WAIT)); |
| 4456 | |
| 4457 | /* RFC 2960 5.1 Normal Establishment of an Association |
| 4458 | * |
| 4459 | * A) "A" first sends an INIT chunk to "Z". In the INIT, "A" |
| 4460 | * must provide its Verification Tag (Tag_A) in the Initiate |
| 4461 | * Tag field. Tag_A SHOULD be a random number in the range of |
| 4462 | * 1 to 4294967295 (see 5.3.1 for Tag value selection). ... |
| 4463 | */ |
| 4464 | |
| 4465 | repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0); |
| 4466 | if (!repl) |
| 4467 | goto nomem; |
| 4468 | |
| 4469 | /* Cast away the const modifier, as we want to just |
| 4470 | * rerun it through as a sideffect. |
| 4471 | */ |
Vlad Yasevich | ab38fb0 | 2008-04-12 18:40:06 -0700 | [diff] [blame] | 4472 | my_asoc = (struct sctp_association *)asoc; |
| 4473 | 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] | 4474 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 4475 | /* Choose transport for INIT. */ |
| 4476 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 4477 | SCTP_CHUNK(repl)); |
| 4478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | /* After sending the INIT, "A" starts the T1-init timer and |
| 4480 | * enters the COOKIE-WAIT state. |
| 4481 | */ |
| 4482 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 4483 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4484 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 4485 | return SCTP_DISPOSITION_CONSUME; |
| 4486 | |
| 4487 | nomem: |
| 4488 | return SCTP_DISPOSITION_NOMEM; |
| 4489 | } |
| 4490 | |
| 4491 | /* |
| 4492 | * Process the SEND primitive. |
| 4493 | * |
| 4494 | * Section: 10.1 ULP-to-SCTP |
| 4495 | * E) Send |
| 4496 | * |
| 4497 | * Format: SEND(association id, buffer address, byte count [,context] |
| 4498 | * [,stream id] [,life time] [,destination transport address] |
| 4499 | * [,unorder flag] [,no-bundle flag] [,payload protocol-id] ) |
| 4500 | * -> result |
| 4501 | * |
| 4502 | * This is the main method to send user data via SCTP. |
| 4503 | * |
| 4504 | * Mandatory attributes: |
| 4505 | * |
| 4506 | * o association id - local handle to the SCTP association |
| 4507 | * |
| 4508 | * o buffer address - the location where the user message to be |
| 4509 | * transmitted is stored; |
| 4510 | * |
| 4511 | * o byte count - The size of the user data in number of bytes; |
| 4512 | * |
| 4513 | * Optional attributes: |
| 4514 | * |
| 4515 | * o context - an optional 32 bit integer that will be carried in the |
| 4516 | * sending failure notification to the ULP if the transportation of |
| 4517 | * this User Message fails. |
| 4518 | * |
| 4519 | * o stream id - to indicate which stream to send the data on. If not |
| 4520 | * specified, stream 0 will be used. |
| 4521 | * |
| 4522 | * o life time - specifies the life time of the user data. The user data |
| 4523 | * will not be sent by SCTP after the life time expires. This |
| 4524 | * parameter can be used to avoid efforts to transmit stale |
| 4525 | * user messages. SCTP notifies the ULP if the data cannot be |
| 4526 | * initiated to transport (i.e. sent to the destination via SCTP's |
| 4527 | * send primitive) within the life time variable. However, the |
| 4528 | * user data will be transmitted if SCTP has attempted to transmit a |
| 4529 | * chunk before the life time expired. |
| 4530 | * |
| 4531 | * o destination transport address - specified as one of the destination |
| 4532 | * transport addresses of the peer endpoint to which this packet |
| 4533 | * should be sent. Whenever possible, SCTP should use this destination |
| 4534 | * transport address for sending the packets, instead of the current |
| 4535 | * primary path. |
| 4536 | * |
| 4537 | * o unorder flag - this flag, if present, indicates that the user |
| 4538 | * would like the data delivered in an unordered fashion to the peer |
| 4539 | * (i.e., the U flag is set to 1 on all DATA chunks carrying this |
| 4540 | * message). |
| 4541 | * |
| 4542 | * o no-bundle flag - instructs SCTP not to bundle this user data with |
| 4543 | * other outbound DATA chunks. SCTP MAY still bundle even when |
| 4544 | * this flag is present, when faced with network congestion. |
| 4545 | * |
| 4546 | * o payload protocol-id - A 32 bit unsigned integer that is to be |
| 4547 | * passed to the peer indicating the type of payload protocol data |
| 4548 | * being transmitted. This value is passed as opaque data by SCTP. |
| 4549 | * |
| 4550 | * The return value is the disposition. |
| 4551 | */ |
| 4552 | sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep, |
| 4553 | const struct sctp_association *asoc, |
| 4554 | const sctp_subtype_t type, |
| 4555 | void *arg, |
| 4556 | sctp_cmd_seq_t *commands) |
| 4557 | { |
| 4558 | struct sctp_chunk *chunk = arg; |
| 4559 | |
| 4560 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); |
| 4561 | return SCTP_DISPOSITION_CONSUME; |
| 4562 | } |
| 4563 | |
| 4564 | /* |
| 4565 | * Process the SHUTDOWN primitive. |
| 4566 | * |
| 4567 | * Section: 10.1: |
| 4568 | * C) Shutdown |
| 4569 | * |
| 4570 | * Format: SHUTDOWN(association id) |
| 4571 | * -> result |
| 4572 | * |
| 4573 | * Gracefully closes an association. Any locally queued user data |
| 4574 | * will be delivered to the peer. The association will be terminated only |
| 4575 | * after the peer acknowledges all the SCTP packets sent. A success code |
| 4576 | * will be returned on successful termination of the association. If |
| 4577 | * attempting to terminate the association results in a failure, an error |
| 4578 | * code shall be returned. |
| 4579 | * |
| 4580 | * Mandatory attributes: |
| 4581 | * |
| 4582 | * o association id - local handle to the SCTP association |
| 4583 | * |
| 4584 | * Optional attributes: |
| 4585 | * |
| 4586 | * None. |
| 4587 | * |
| 4588 | * The return value is the disposition. |
| 4589 | */ |
| 4590 | sctp_disposition_t sctp_sf_do_9_2_prm_shutdown( |
| 4591 | const struct sctp_endpoint *ep, |
| 4592 | const struct sctp_association *asoc, |
| 4593 | const sctp_subtype_t type, |
| 4594 | void *arg, |
| 4595 | sctp_cmd_seq_t *commands) |
| 4596 | { |
| 4597 | int disposition; |
| 4598 | |
| 4599 | /* From 9.2 Shutdown of an Association |
| 4600 | * Upon receipt of the SHUTDOWN primitive from its upper |
| 4601 | * layer, the endpoint enters SHUTDOWN-PENDING state and |
| 4602 | * remains there until all outstanding data has been |
| 4603 | * acknowledged by its peer. The endpoint accepts no new data |
| 4604 | * from its upper layer, but retransmits data to the far end |
| 4605 | * if necessary to fill gaps. |
| 4606 | */ |
| 4607 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4608 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); |
| 4609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | disposition = SCTP_DISPOSITION_CONSUME; |
| 4611 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
| 4612 | disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type, |
| 4613 | arg, commands); |
| 4614 | } |
| 4615 | return disposition; |
| 4616 | } |
| 4617 | |
| 4618 | /* |
| 4619 | * Process the ABORT primitive. |
| 4620 | * |
| 4621 | * Section: 10.1: |
| 4622 | * C) Abort |
| 4623 | * |
| 4624 | * Format: Abort(association id [, cause code]) |
| 4625 | * -> result |
| 4626 | * |
| 4627 | * Ungracefully closes an association. Any locally queued user data |
| 4628 | * will be discarded and an ABORT chunk is sent to the peer. A success code |
| 4629 | * will be returned on successful abortion of the association. If |
| 4630 | * attempting to abort the association results in a failure, an error |
| 4631 | * code shall be returned. |
| 4632 | * |
| 4633 | * Mandatory attributes: |
| 4634 | * |
| 4635 | * o association id - local handle to the SCTP association |
| 4636 | * |
| 4637 | * Optional attributes: |
| 4638 | * |
| 4639 | * o cause code - reason of the abort to be passed to the peer |
| 4640 | * |
| 4641 | * None. |
| 4642 | * |
| 4643 | * The return value is the disposition. |
| 4644 | */ |
| 4645 | sctp_disposition_t sctp_sf_do_9_1_prm_abort( |
| 4646 | const struct sctp_endpoint *ep, |
| 4647 | const struct sctp_association *asoc, |
| 4648 | const sctp_subtype_t type, |
| 4649 | void *arg, |
| 4650 | sctp_cmd_seq_t *commands) |
| 4651 | { |
| 4652 | /* From 9.1 Abort of an Association |
| 4653 | * Upon receipt of the ABORT primitive from its upper |
| 4654 | * layer, the endpoint enters CLOSED state and |
| 4655 | * discard all outstanding data has been |
| 4656 | * acknowledged by its peer. The endpoint accepts no new data |
| 4657 | * from its upper layer, but retransmits data to the far end |
| 4658 | * if necessary to fill gaps. |
| 4659 | */ |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 4660 | struct sctp_chunk *abort = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4661 | sctp_disposition_t retval; |
| 4662 | |
| 4663 | retval = SCTP_DISPOSITION_CONSUME; |
| 4664 | |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 4665 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4666 | |
| 4667 | /* Even if we can't send the ABORT due to low memory delete the |
| 4668 | * TCB. This is a departure from our typical NOMEM handling. |
| 4669 | */ |
| 4670 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 4671 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4672 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4673 | /* Delete the established association. */ |
| 4674 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 4675 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | |
| 4677 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 4678 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 4679 | |
| 4680 | return retval; |
| 4681 | } |
| 4682 | |
| 4683 | /* We tried an illegal operation on an association which is closed. */ |
| 4684 | sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep, |
| 4685 | const struct sctp_association *asoc, |
| 4686 | const sctp_subtype_t type, |
| 4687 | void *arg, |
| 4688 | sctp_cmd_seq_t *commands) |
| 4689 | { |
| 4690 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL)); |
| 4691 | return SCTP_DISPOSITION_CONSUME; |
| 4692 | } |
| 4693 | |
| 4694 | /* We tried an illegal operation on an association which is shutting |
| 4695 | * down. |
| 4696 | */ |
| 4697 | sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep, |
| 4698 | const struct sctp_association *asoc, |
| 4699 | const sctp_subtype_t type, |
| 4700 | void *arg, |
| 4701 | sctp_cmd_seq_t *commands) |
| 4702 | { |
| 4703 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, |
| 4704 | SCTP_ERROR(-ESHUTDOWN)); |
| 4705 | return SCTP_DISPOSITION_CONSUME; |
| 4706 | } |
| 4707 | |
| 4708 | /* |
| 4709 | * sctp_cookie_wait_prm_shutdown |
| 4710 | * |
| 4711 | * Section: 4 Note: 2 |
| 4712 | * Verification Tag: |
| 4713 | * Inputs |
| 4714 | * (endpoint, asoc) |
| 4715 | * |
| 4716 | * The RFC does not explicitly address this issue, but is the route through the |
| 4717 | * state table when someone issues a shutdown while in COOKIE_WAIT state. |
| 4718 | * |
| 4719 | * Outputs |
| 4720 | * (timers) |
| 4721 | */ |
| 4722 | sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown( |
| 4723 | const struct sctp_endpoint *ep, |
| 4724 | const struct sctp_association *asoc, |
| 4725 | const sctp_subtype_t type, |
| 4726 | void *arg, |
| 4727 | sctp_cmd_seq_t *commands) |
| 4728 | { |
| 4729 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4730 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4731 | |
| 4732 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4733 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 4734 | |
| 4735 | SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS); |
| 4736 | |
| 4737 | sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL()); |
| 4738 | |
| 4739 | return SCTP_DISPOSITION_DELETE_TCB; |
| 4740 | } |
| 4741 | |
| 4742 | /* |
| 4743 | * sctp_cookie_echoed_prm_shutdown |
| 4744 | * |
| 4745 | * Section: 4 Note: 2 |
| 4746 | * Verification Tag: |
| 4747 | * Inputs |
| 4748 | * (endpoint, asoc) |
| 4749 | * |
| 4750 | * The RFC does not explcitly address this issue, but is the route through the |
| 4751 | * state table when someone issues a shutdown while in COOKIE_ECHOED state. |
| 4752 | * |
| 4753 | * Outputs |
| 4754 | * (timers) |
| 4755 | */ |
| 4756 | sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown( |
| 4757 | const struct sctp_endpoint *ep, |
| 4758 | const struct sctp_association *asoc, |
| 4759 | const sctp_subtype_t type, |
| 4760 | void *arg, sctp_cmd_seq_t *commands) |
| 4761 | { |
| 4762 | /* There is a single T1 timer, so we should be able to use |
| 4763 | * common function with the COOKIE-WAIT state. |
| 4764 | */ |
| 4765 | return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands); |
| 4766 | } |
| 4767 | |
| 4768 | /* |
| 4769 | * sctp_sf_cookie_wait_prm_abort |
| 4770 | * |
| 4771 | * Section: 4 Note: 2 |
| 4772 | * Verification Tag: |
| 4773 | * Inputs |
| 4774 | * (endpoint, asoc) |
| 4775 | * |
| 4776 | * The RFC does not explicitly address this issue, but is the route through the |
| 4777 | * state table when someone issues an abort while in COOKIE_WAIT state. |
| 4778 | * |
| 4779 | * Outputs |
| 4780 | * (timers) |
| 4781 | */ |
| 4782 | sctp_disposition_t sctp_sf_cookie_wait_prm_abort( |
| 4783 | const struct sctp_endpoint *ep, |
| 4784 | const struct sctp_association *asoc, |
| 4785 | const sctp_subtype_t type, |
| 4786 | void *arg, |
| 4787 | sctp_cmd_seq_t *commands) |
| 4788 | { |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 4789 | struct sctp_chunk *abort = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | sctp_disposition_t retval; |
| 4791 | |
| 4792 | /* Stop T1-init timer */ |
| 4793 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4794 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 4795 | retval = SCTP_DISPOSITION_CONSUME; |
| 4796 | |
Sridhar Samudrala | c164a9b | 2006-08-22 11:50:39 -0700 | [diff] [blame] | 4797 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | |
| 4799 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 4800 | SCTP_STATE(SCTP_STATE_CLOSED)); |
| 4801 | |
| 4802 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 4803 | |
| 4804 | /* Even if we can't send the ABORT due to low memory delete the |
| 4805 | * TCB. This is a departure from our typical NOMEM handling. |
| 4806 | */ |
| 4807 | |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 4808 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 4809 | SCTP_ERROR(ECONNREFUSED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | /* Delete the established association. */ |
| 4811 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 4812 | SCTP_PERR(SCTP_ERROR_USER_ABORT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4813 | |
| 4814 | return retval; |
| 4815 | } |
| 4816 | |
| 4817 | /* |
| 4818 | * sctp_sf_cookie_echoed_prm_abort |
| 4819 | * |
| 4820 | * Section: 4 Note: 3 |
| 4821 | * Verification Tag: |
| 4822 | * Inputs |
| 4823 | * (endpoint, asoc) |
| 4824 | * |
| 4825 | * The RFC does not explcitly address this issue, but is the route through the |
| 4826 | * state table when someone issues an abort while in COOKIE_ECHOED state. |
| 4827 | * |
| 4828 | * Outputs |
| 4829 | * (timers) |
| 4830 | */ |
| 4831 | sctp_disposition_t sctp_sf_cookie_echoed_prm_abort( |
| 4832 | const struct sctp_endpoint *ep, |
| 4833 | const struct sctp_association *asoc, |
| 4834 | const sctp_subtype_t type, |
| 4835 | void *arg, |
| 4836 | sctp_cmd_seq_t *commands) |
| 4837 | { |
| 4838 | /* There is a single T1 timer, so we should be able to use |
| 4839 | * common function with the COOKIE-WAIT state. |
| 4840 | */ |
| 4841 | return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands); |
| 4842 | } |
| 4843 | |
| 4844 | /* |
| 4845 | * sctp_sf_shutdown_pending_prm_abort |
| 4846 | * |
| 4847 | * Inputs |
| 4848 | * (endpoint, asoc) |
| 4849 | * |
| 4850 | * The RFC does not explicitly address this issue, but is the route through the |
| 4851 | * state table when someone issues an abort while in SHUTDOWN-PENDING state. |
| 4852 | * |
| 4853 | * Outputs |
| 4854 | * (timers) |
| 4855 | */ |
| 4856 | sctp_disposition_t sctp_sf_shutdown_pending_prm_abort( |
| 4857 | const struct sctp_endpoint *ep, |
| 4858 | const struct sctp_association *asoc, |
| 4859 | const sctp_subtype_t type, |
| 4860 | void *arg, |
| 4861 | sctp_cmd_seq_t *commands) |
| 4862 | { |
| 4863 | /* Stop the T5-shutdown guard timer. */ |
| 4864 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4865 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 4866 | |
| 4867 | return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands); |
| 4868 | } |
| 4869 | |
| 4870 | /* |
| 4871 | * sctp_sf_shutdown_sent_prm_abort |
| 4872 | * |
| 4873 | * Inputs |
| 4874 | * (endpoint, asoc) |
| 4875 | * |
| 4876 | * The RFC does not explicitly address this issue, but is the route through the |
| 4877 | * state table when someone issues an abort while in SHUTDOWN-SENT state. |
| 4878 | * |
| 4879 | * Outputs |
| 4880 | * (timers) |
| 4881 | */ |
| 4882 | sctp_disposition_t sctp_sf_shutdown_sent_prm_abort( |
| 4883 | const struct sctp_endpoint *ep, |
| 4884 | const struct sctp_association *asoc, |
| 4885 | const sctp_subtype_t type, |
| 4886 | void *arg, |
| 4887 | sctp_cmd_seq_t *commands) |
| 4888 | { |
| 4889 | /* Stop the T2-shutdown timer. */ |
| 4890 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4891 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 4892 | |
| 4893 | /* Stop the T5-shutdown guard timer. */ |
| 4894 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 4895 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 4896 | |
| 4897 | return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands); |
| 4898 | } |
| 4899 | |
| 4900 | /* |
| 4901 | * sctp_sf_cookie_echoed_prm_abort |
| 4902 | * |
| 4903 | * Inputs |
| 4904 | * (endpoint, asoc) |
| 4905 | * |
| 4906 | * The RFC does not explcitly address this issue, but is the route through the |
| 4907 | * state table when someone issues an abort while in COOKIE_ECHOED state. |
| 4908 | * |
| 4909 | * Outputs |
| 4910 | * (timers) |
| 4911 | */ |
| 4912 | sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort( |
| 4913 | const struct sctp_endpoint *ep, |
| 4914 | const struct sctp_association *asoc, |
| 4915 | const sctp_subtype_t type, |
| 4916 | void *arg, |
| 4917 | sctp_cmd_seq_t *commands) |
| 4918 | { |
| 4919 | /* The same T2 timer, so we should be able to use |
| 4920 | * common function with the SHUTDOWN-SENT state. |
| 4921 | */ |
| 4922 | return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands); |
| 4923 | } |
| 4924 | |
| 4925 | /* |
| 4926 | * Process the REQUESTHEARTBEAT primitive |
| 4927 | * |
| 4928 | * 10.1 ULP-to-SCTP |
| 4929 | * J) Request Heartbeat |
| 4930 | * |
| 4931 | * Format: REQUESTHEARTBEAT(association id, destination transport address) |
| 4932 | * |
| 4933 | * -> result |
| 4934 | * |
| 4935 | * Instructs the local endpoint to perform a HeartBeat on the specified |
| 4936 | * destination transport address of the given association. The returned |
| 4937 | * result should indicate whether the transmission of the HEARTBEAT |
| 4938 | * chunk to the destination address is successful. |
| 4939 | * |
| 4940 | * Mandatory attributes: |
| 4941 | * |
| 4942 | * o association id - local handle to the SCTP association |
| 4943 | * |
| 4944 | * o destination transport address - the transport address of the |
| 4945 | * association on which a heartbeat should be issued. |
| 4946 | */ |
| 4947 | sctp_disposition_t sctp_sf_do_prm_requestheartbeat( |
| 4948 | const struct sctp_endpoint *ep, |
| 4949 | const struct sctp_association *asoc, |
| 4950 | const sctp_subtype_t type, |
| 4951 | void *arg, |
| 4952 | sctp_cmd_seq_t *commands) |
| 4953 | { |
Vlad Yasevich | fb78525 | 2007-03-19 17:02:03 -0700 | [diff] [blame] | 4954 | if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type, |
| 4955 | (struct sctp_transport *)arg, commands)) |
| 4956 | return SCTP_DISPOSITION_NOMEM; |
| 4957 | |
| 4958 | /* |
| 4959 | * RFC 2960 (bis), section 8.3 |
| 4960 | * |
| 4961 | * D) Request an on-demand HEARTBEAT on a specific destination |
| 4962 | * transport address of a given association. |
| 4963 | * |
| 4964 | * The endpoint should increment the respective error counter of |
| 4965 | * the destination transport address each time a HEARTBEAT is sent |
| 4966 | * to that address and not acknowledged within one RTO. |
| 4967 | * |
| 4968 | */ |
Vlad Yasevich | 7e99013 | 2009-03-02 09:46:14 +0000 | [diff] [blame] | 4969 | sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT, |
Vlad Yasevich | fb78525 | 2007-03-19 17:02:03 -0700 | [diff] [blame] | 4970 | SCTP_TRANSPORT(arg)); |
| 4971 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | /* |
| 4975 | * ADDIP Section 4.1 ASCONF Chunk Procedures |
| 4976 | * When an endpoint has an ASCONF signaled change to be sent to the |
| 4977 | * remote endpoint it should do A1 to A9 |
| 4978 | */ |
| 4979 | sctp_disposition_t sctp_sf_do_prm_asconf(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 | struct sctp_chunk *chunk = arg; |
| 4986 | |
| 4987 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); |
| 4988 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 4989 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 4990 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk)); |
| 4991 | return SCTP_DISPOSITION_CONSUME; |
| 4992 | } |
| 4993 | |
| 4994 | /* |
| 4995 | * Ignore the primitive event |
| 4996 | * |
| 4997 | * The return value is the disposition of the primitive. |
| 4998 | */ |
| 4999 | sctp_disposition_t sctp_sf_ignore_primitive( |
| 5000 | const struct sctp_endpoint *ep, |
| 5001 | const struct sctp_association *asoc, |
| 5002 | const sctp_subtype_t type, |
| 5003 | void *arg, |
| 5004 | sctp_cmd_seq_t *commands) |
| 5005 | { |
| 5006 | SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive); |
| 5007 | return SCTP_DISPOSITION_DISCARD; |
| 5008 | } |
| 5009 | |
| 5010 | /*************************************************************************** |
| 5011 | * These are the state functions for the OTHER events. |
| 5012 | ***************************************************************************/ |
| 5013 | |
| 5014 | /* |
| 5015 | * Start the shutdown negotiation. |
| 5016 | * |
| 5017 | * From Section 9.2: |
| 5018 | * Once all its outstanding data has been acknowledged, the endpoint |
| 5019 | * shall send a SHUTDOWN chunk to its peer including in the Cumulative |
| 5020 | * TSN Ack field the last sequential TSN it has received from the peer. |
| 5021 | * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT |
| 5022 | * state. If the timer expires, the endpoint must re-send the SHUTDOWN |
| 5023 | * with the updated last sequential TSN received from its peer. |
| 5024 | * |
| 5025 | * The return value is the disposition. |
| 5026 | */ |
| 5027 | sctp_disposition_t sctp_sf_do_9_2_start_shutdown( |
| 5028 | const struct sctp_endpoint *ep, |
| 5029 | const struct sctp_association *asoc, |
| 5030 | const sctp_subtype_t type, |
| 5031 | void *arg, |
| 5032 | sctp_cmd_seq_t *commands) |
| 5033 | { |
| 5034 | struct sctp_chunk *reply; |
| 5035 | |
| 5036 | /* Once all its outstanding data has been acknowledged, the |
| 5037 | * endpoint shall send a SHUTDOWN chunk to its peer including |
| 5038 | * in the Cumulative TSN Ack field the last sequential TSN it |
| 5039 | * has received from the peer. |
| 5040 | */ |
| 5041 | reply = sctp_make_shutdown(asoc, NULL); |
| 5042 | if (!reply) |
| 5043 | goto nomem; |
| 5044 | |
| 5045 | /* Set the transport for the SHUTDOWN chunk and the timeout for the |
| 5046 | * T2-shutdown timer. |
| 5047 | */ |
| 5048 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5049 | |
| 5050 | /* It shall then start the T2-shutdown timer */ |
| 5051 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 5052 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5053 | |
Wei Yongjun | 536428a | 2008-09-05 08:55:26 +0800 | [diff] [blame] | 5054 | /* RFC 4960 Section 9.2 |
| 5055 | * The sender of the SHUTDOWN MAY also start an overall guard timer |
| 5056 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. |
| 5057 | */ |
| 5058 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START, |
| 5059 | SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD)); |
| 5060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | if (asoc->autoclose) |
| 5062 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5063 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 5064 | |
| 5065 | /* and enter the SHUTDOWN-SENT state. */ |
| 5066 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5067 | SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT)); |
| 5068 | |
| 5069 | /* sctp-implguide 2.10 Issues with Heartbeating and failover |
| 5070 | * |
| 5071 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5072 | * or SHUTDOWN-ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5073 | */ |
| 5074 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 5075 | |
| 5076 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5077 | |
| 5078 | return SCTP_DISPOSITION_CONSUME; |
| 5079 | |
| 5080 | nomem: |
| 5081 | return SCTP_DISPOSITION_NOMEM; |
| 5082 | } |
| 5083 | |
| 5084 | /* |
| 5085 | * Generate a SHUTDOWN ACK now that everything is SACK'd. |
| 5086 | * |
| 5087 | * From Section 9.2: |
| 5088 | * |
| 5089 | * If it has no more outstanding DATA chunks, the SHUTDOWN receiver |
| 5090 | * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own, |
| 5091 | * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the |
| 5092 | * endpoint must re-send the SHUTDOWN ACK. |
| 5093 | * |
| 5094 | * The return value is the disposition. |
| 5095 | */ |
| 5096 | sctp_disposition_t sctp_sf_do_9_2_shutdown_ack( |
| 5097 | const struct sctp_endpoint *ep, |
| 5098 | const struct sctp_association *asoc, |
| 5099 | const sctp_subtype_t type, |
| 5100 | void *arg, |
| 5101 | sctp_cmd_seq_t *commands) |
| 5102 | { |
| 5103 | struct sctp_chunk *chunk = (struct sctp_chunk *) arg; |
| 5104 | struct sctp_chunk *reply; |
| 5105 | |
| 5106 | /* There are 2 ways of getting here: |
| 5107 | * 1) called in response to a SHUTDOWN chunk |
| 5108 | * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued. |
| 5109 | * |
| 5110 | * For the case (2), the arg parameter is set to NULL. We need |
| 5111 | * to check that we have a chunk before accessing it's fields. |
| 5112 | */ |
| 5113 | if (chunk) { |
| 5114 | if (!sctp_vtag_verify(chunk, asoc)) |
| 5115 | return sctp_sf_pdiscard(ep, asoc, type, arg, commands); |
| 5116 | |
| 5117 | /* Make sure that the SHUTDOWN chunk has a valid length. */ |
| 5118 | if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t))) |
| 5119 | return sctp_sf_violation_chunklen(ep, asoc, type, arg, |
| 5120 | commands); |
| 5121 | } |
| 5122 | |
| 5123 | /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver |
| 5124 | * shall send a SHUTDOWN ACK ... |
| 5125 | */ |
| 5126 | reply = sctp_make_shutdown_ack(asoc, chunk); |
| 5127 | if (!reply) |
| 5128 | goto nomem; |
| 5129 | |
| 5130 | /* Set the transport for the SHUTDOWN ACK chunk and the timeout for |
| 5131 | * the T2-shutdown timer. |
| 5132 | */ |
| 5133 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5134 | |
| 5135 | /* and start/restart a T2-shutdown timer of its own, */ |
| 5136 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5137 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5138 | |
| 5139 | if (asoc->autoclose) |
| 5140 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5141 | SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE)); |
| 5142 | |
| 5143 | /* Enter the SHUTDOWN-ACK-SENT state. */ |
| 5144 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5145 | SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT)); |
| 5146 | |
| 5147 | /* sctp-implguide 2.10 Issues with Heartbeating and failover |
| 5148 | * |
| 5149 | * HEARTBEAT ... is discontinued after sending either SHUTDOWN |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5150 | * or SHUTDOWN-ACK. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | */ |
| 5152 | sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL()); |
| 5153 | |
| 5154 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5155 | |
| 5156 | return SCTP_DISPOSITION_CONSUME; |
| 5157 | |
| 5158 | nomem: |
| 5159 | return SCTP_DISPOSITION_NOMEM; |
| 5160 | } |
| 5161 | |
| 5162 | /* |
| 5163 | * Ignore the event defined as other |
| 5164 | * |
| 5165 | * The return value is the disposition of the event. |
| 5166 | */ |
| 5167 | sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep, |
| 5168 | const struct sctp_association *asoc, |
| 5169 | const sctp_subtype_t type, |
| 5170 | void *arg, |
| 5171 | sctp_cmd_seq_t *commands) |
| 5172 | { |
| 5173 | SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other); |
| 5174 | return SCTP_DISPOSITION_DISCARD; |
| 5175 | } |
| 5176 | |
| 5177 | /************************************************************ |
| 5178 | * These are the state functions for handling timeout events. |
| 5179 | ************************************************************/ |
| 5180 | |
| 5181 | /* |
| 5182 | * RTX Timeout |
| 5183 | * |
| 5184 | * Section: 6.3.3 Handle T3-rtx Expiration |
| 5185 | * |
| 5186 | * Whenever the retransmission timer T3-rtx expires for a destination |
| 5187 | * address, do the following: |
| 5188 | * [See below] |
| 5189 | * |
| 5190 | * The return value is the disposition of the chunk. |
| 5191 | */ |
| 5192 | sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep, |
| 5193 | const struct sctp_association *asoc, |
| 5194 | const sctp_subtype_t type, |
| 5195 | void *arg, |
| 5196 | sctp_cmd_seq_t *commands) |
| 5197 | { |
| 5198 | struct sctp_transport *transport = arg; |
| 5199 | |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5200 | SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS); |
| 5201 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | if (asoc->overall_error_count >= asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5203 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5204 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5205 | /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 5206 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5207 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 5209 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 5210 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5211 | } |
| 5212 | |
| 5213 | /* E1) For the destination address for which the timer |
| 5214 | * expires, adjust its ssthresh with rules defined in Section |
| 5215 | * 7.2.3 and set the cwnd <- MTU. |
| 5216 | */ |
| 5217 | |
| 5218 | /* E2) For the destination address for which the timer |
| 5219 | * expires, set RTO <- RTO * 2 ("back off the timer"). The |
| 5220 | * maximum value discussed in rule C7 above (RTO.max) may be |
| 5221 | * used to provide an upper bound to this doubling operation. |
| 5222 | */ |
| 5223 | |
| 5224 | /* E3) Determine how many of the earliest (i.e., lowest TSN) |
| 5225 | * outstanding DATA chunks for the address for which the |
| 5226 | * T3-rtx has expired will fit into a single packet, subject |
| 5227 | * to the MTU constraint for the path corresponding to the |
| 5228 | * destination transport address to which the retransmission |
| 5229 | * is being sent (this may be different from the address for |
| 5230 | * which the timer expires [see Section 6.4]). Call this |
| 5231 | * value K. Bundle and retransmit those K DATA chunks in a |
| 5232 | * single packet to the destination endpoint. |
| 5233 | * |
| 5234 | * Note: Any DATA chunks that were sent to the address for |
| 5235 | * which the T3-rtx timer expired but did not fit in one MTU |
| 5236 | * (rule E3 above), should be marked for retransmission and |
| 5237 | * sent as soon as cwnd allows (normally when a SACK arrives). |
| 5238 | */ |
| 5239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5240 | /* Do some failure management (Section 8.2). */ |
| 5241 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport)); |
| 5242 | |
Vlad Yasevich | 1845a57 | 2007-02-21 02:06:19 -0800 | [diff] [blame] | 5243 | /* NB: Rules E4 and F1 are implicit in R1. */ |
| 5244 | sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport)); |
| 5245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5246 | return SCTP_DISPOSITION_CONSUME; |
| 5247 | } |
| 5248 | |
| 5249 | /* |
| 5250 | * Generate delayed SACK on timeout |
| 5251 | * |
| 5252 | * Section: 6.2 Acknowledgement on Reception of DATA Chunks |
| 5253 | * |
| 5254 | * The guidelines on delayed acknowledgement algorithm specified in |
| 5255 | * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an |
| 5256 | * acknowledgement SHOULD be generated for at least every second packet |
| 5257 | * (not every second DATA chunk) received, and SHOULD be generated |
| 5258 | * within 200 ms of the arrival of any unacknowledged DATA chunk. In |
| 5259 | * some situations it may be beneficial for an SCTP transmitter to be |
| 5260 | * more conservative than the algorithms detailed in this document |
| 5261 | * allow. However, an SCTP transmitter MUST NOT be more aggressive than |
| 5262 | * the following algorithms allow. |
| 5263 | */ |
| 5264 | sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep, |
| 5265 | const struct sctp_association *asoc, |
| 5266 | const sctp_subtype_t type, |
| 5267 | void *arg, |
| 5268 | sctp_cmd_seq_t *commands) |
| 5269 | { |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5270 | SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5271 | sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE()); |
| 5272 | return SCTP_DISPOSITION_CONSUME; |
| 5273 | } |
| 5274 | |
| 5275 | /* |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5276 | * sctp_sf_t1_init_timer_expire |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5277 | * |
| 5278 | * Section: 4 Note: 2 |
| 5279 | * Verification Tag: |
| 5280 | * Inputs |
| 5281 | * (endpoint, asoc) |
| 5282 | * |
| 5283 | * RFC 2960 Section 4 Notes |
| 5284 | * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT |
| 5285 | * and re-start the T1-init timer without changing state. This MUST |
| 5286 | * be repeated up to 'Max.Init.Retransmits' times. After that, the |
| 5287 | * endpoint MUST abort the initialization process and report the |
| 5288 | * error to SCTP user. |
| 5289 | * |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5290 | * Outputs |
| 5291 | * (timers, events) |
| 5292 | * |
| 5293 | */ |
| 5294 | sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep, |
| 5295 | const struct sctp_association *asoc, |
| 5296 | const sctp_subtype_t type, |
| 5297 | void *arg, |
| 5298 | sctp_cmd_seq_t *commands) |
| 5299 | { |
| 5300 | struct sctp_chunk *repl = NULL; |
| 5301 | struct sctp_bind_addr *bp; |
| 5302 | int attempts = asoc->init_err_counter + 1; |
| 5303 | |
| 5304 | SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n"); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5305 | SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5306 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 5307 | if (attempts <= asoc->max_init_attempts) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5308 | bp = (struct sctp_bind_addr *) &asoc->base.bind_addr; |
| 5309 | repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0); |
| 5310 | if (!repl) |
| 5311 | return SCTP_DISPOSITION_NOMEM; |
| 5312 | |
| 5313 | /* Choose transport for INIT. */ |
| 5314 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 5315 | SCTP_CHUNK(repl)); |
| 5316 | |
| 5317 | /* Issue a sideeffect to do the needed accounting. */ |
| 5318 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART, |
| 5319 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT)); |
| 5320 | |
| 5321 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 5322 | } else { |
| 5323 | SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d" |
| 5324 | " max_init_attempts: %d\n", |
| 5325 | attempts, asoc->max_init_attempts); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5326 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5327 | SCTP_ERROR(ETIMEDOUT)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5328 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5329 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5330 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5331 | } |
| 5332 | |
| 5333 | return SCTP_DISPOSITION_CONSUME; |
| 5334 | } |
| 5335 | |
| 5336 | /* |
| 5337 | * sctp_sf_t1_cookie_timer_expire |
| 5338 | * |
| 5339 | * Section: 4 Note: 2 |
| 5340 | * Verification Tag: |
| 5341 | * Inputs |
| 5342 | * (endpoint, asoc) |
| 5343 | * |
| 5344 | * RFC 2960 Section 4 Notes |
| 5345 | * 3) If the T1-cookie timer expires, the endpoint MUST retransmit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5346 | * COOKIE ECHO and re-start the T1-cookie timer without changing |
| 5347 | * state. This MUST be repeated up to 'Max.Init.Retransmits' times. |
| 5348 | * After that, the endpoint MUST abort the initialization process and |
| 5349 | * report the error to SCTP user. |
| 5350 | * |
| 5351 | * Outputs |
| 5352 | * (timers, events) |
| 5353 | * |
| 5354 | */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5355 | sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | const struct sctp_association *asoc, |
| 5357 | const sctp_subtype_t type, |
| 5358 | void *arg, |
| 5359 | sctp_cmd_seq_t *commands) |
| 5360 | { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5361 | struct sctp_chunk *repl = NULL; |
| 5362 | int attempts = asoc->init_err_counter + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5364 | SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n"); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5365 | SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | |
Vlad Yasevich | 81845c2 | 2006-01-30 15:59:54 -0800 | [diff] [blame] | 5367 | if (attempts <= asoc->max_init_attempts) { |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5368 | repl = sctp_make_cookie_echo(asoc, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5369 | if (!repl) |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5370 | return SCTP_DISPOSITION_NOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | |
Vlad Yasevich | 96cd0d3 | 2008-09-08 14:00:26 -0400 | [diff] [blame] | 5372 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT, |
| 5373 | SCTP_CHUNK(repl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | /* Issue a sideeffect to do the needed accounting. */ |
Frank Filz | 3f7a87d | 2005-06-20 13:14:57 -0700 | [diff] [blame] | 5375 | sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART, |
| 5376 | SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE)); |
| 5377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl)); |
| 5379 | } else { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5380 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5381 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5382 | sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, |
Al Viro | dc251b2 | 2006-11-20 17:00:44 -0800 | [diff] [blame] | 5383 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5385 | } |
| 5386 | |
| 5387 | return SCTP_DISPOSITION_CONSUME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN |
| 5391 | * with the updated last sequential TSN received from its peer. |
| 5392 | * |
| 5393 | * An endpoint should limit the number of retransmissions of the |
| 5394 | * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'. |
| 5395 | * If this threshold is exceeded the endpoint should destroy the TCB and |
| 5396 | * MUST report the peer endpoint unreachable to the upper layer (and |
| 5397 | * thus the association enters the CLOSED state). The reception of any |
| 5398 | * packet from its peer (i.e. as the peer sends all of its queued DATA |
| 5399 | * chunks) should clear the endpoint's retransmission count and restart |
| 5400 | * the T2-Shutdown timer, giving its peer ample opportunity to transmit |
| 5401 | * all of its queued DATA chunks that have not yet been sent. |
| 5402 | */ |
| 5403 | sctp_disposition_t sctp_sf_t2_timer_expire(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 *reply = NULL; |
| 5410 | |
| 5411 | SCTP_DEBUG_PRINTK("Timer T2 expired.\n"); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5412 | SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS); |
| 5413 | |
Neil Horman | 58fbbed | 2008-02-29 11:40:56 -0800 | [diff] [blame] | 5414 | ((struct sctp_association *)asoc)->shutdown_retries++; |
| 5415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | if (asoc->overall_error_count >= asoc->max_retrans) { |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5417 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5418 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5419 | /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */ |
| 5420 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5421 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5422 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 5423 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 5424 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5425 | } |
| 5426 | |
| 5427 | switch (asoc->state) { |
| 5428 | case SCTP_STATE_SHUTDOWN_SENT: |
| 5429 | reply = sctp_make_shutdown(asoc, NULL); |
| 5430 | break; |
| 5431 | |
| 5432 | case SCTP_STATE_SHUTDOWN_ACK_SENT: |
| 5433 | reply = sctp_make_shutdown_ack(asoc, NULL); |
| 5434 | break; |
| 5435 | |
| 5436 | default: |
| 5437 | BUG(); |
| 5438 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 5439 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | |
| 5441 | if (!reply) |
| 5442 | goto nomem; |
| 5443 | |
Wei Yongjun | 6345b19 | 2009-04-26 23:13:35 +0800 | [diff] [blame] | 5444 | /* Do some failure management (Section 8.2). |
| 5445 | * If we remove the transport an SHUTDOWN was last sent to, don't |
| 5446 | * do failure management. |
| 5447 | */ |
| 5448 | if (asoc->shutdown_last_sent_to) |
| 5449 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, |
| 5450 | SCTP_TRANSPORT(asoc->shutdown_last_sent_to)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5451 | |
| 5452 | /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for |
| 5453 | * the T2-shutdown timer. |
| 5454 | */ |
| 5455 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply)); |
| 5456 | |
| 5457 | /* Restart the T2-shutdown timer. */ |
| 5458 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5459 | SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); |
| 5460 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
| 5461 | return SCTP_DISPOSITION_CONSUME; |
| 5462 | |
| 5463 | nomem: |
| 5464 | return SCTP_DISPOSITION_NOMEM; |
| 5465 | } |
| 5466 | |
| 5467 | /* |
| 5468 | * ADDIP Section 4.1 ASCONF CHunk Procedures |
| 5469 | * If the T4 RTO timer expires the endpoint should do B1 to B5 |
| 5470 | */ |
| 5471 | sctp_disposition_t sctp_sf_t4_timer_expire( |
| 5472 | const struct sctp_endpoint *ep, |
| 5473 | const struct sctp_association *asoc, |
| 5474 | const sctp_subtype_t type, |
| 5475 | void *arg, |
| 5476 | sctp_cmd_seq_t *commands) |
| 5477 | { |
| 5478 | struct sctp_chunk *chunk = asoc->addip_last_asconf; |
| 5479 | struct sctp_transport *transport = chunk->transport; |
| 5480 | |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5481 | SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS); |
| 5482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5483 | /* ADDIP 4.1 B1) Increment the error counters and perform path failure |
| 5484 | * detection on the appropriate destination address as defined in |
| 5485 | * RFC2960 [5] section 8.1 and 8.2. |
| 5486 | */ |
Wei Yongjun | 10a43ce | 2009-04-26 23:14:42 +0800 | [diff] [blame] | 5487 | if (transport) |
| 5488 | sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, |
| 5489 | SCTP_TRANSPORT(transport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | |
| 5491 | /* Reconfig T4 timer and transport. */ |
| 5492 | sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk)); |
| 5493 | |
| 5494 | /* ADDIP 4.1 B2) Increment the association error counters and perform |
| 5495 | * endpoint failure detection on the association as defined in |
| 5496 | * RFC2960 [5] section 8.1 and 8.2. |
| 5497 | * association error counter is incremented in SCTP_CMD_STRIKE. |
| 5498 | */ |
| 5499 | if (asoc->overall_error_count >= asoc->max_retrans) { |
| 5500 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, |
| 5501 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5502 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5503 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5504 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5505 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
Wei Yongjun | 3d5a019 | 2008-10-09 14:32:24 -0700 | [diff] [blame] | 5507 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | return SCTP_DISPOSITION_ABORT; |
| 5509 | } |
| 5510 | |
| 5511 | /* ADDIP 4.1 B3) Back-off the destination address RTO value to which |
| 5512 | * the ASCONF chunk was sent by doubling the RTO timer value. |
| 5513 | * This is done in SCTP_CMD_STRIKE. |
| 5514 | */ |
| 5515 | |
| 5516 | /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible |
| 5517 | * choose an alternate destination address (please refer to RFC2960 |
| 5518 | * [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] | 5519 | * 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] | 5520 | * ASCONF sent. |
| 5521 | */ |
| 5522 | sctp_chunk_hold(asoc->addip_last_asconf); |
| 5523 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 5524 | SCTP_CHUNK(asoc->addip_last_asconf)); |
| 5525 | |
| 5526 | /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different |
| 5527 | * destination is selected, then the RTO used will be that of the new |
| 5528 | * destination address. |
| 5529 | */ |
| 5530 | sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART, |
| 5531 | SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO)); |
| 5532 | |
| 5533 | return SCTP_DISPOSITION_CONSUME; |
| 5534 | } |
| 5535 | |
| 5536 | /* sctpimpguide-05 Section 2.12.2 |
| 5537 | * The sender of the SHUTDOWN MAY also start an overall guard timer |
| 5538 | * 'T5-shutdown-guard' to bound the overall time for shutdown sequence. |
| 5539 | * At the expiration of this timer the sender SHOULD abort the association |
| 5540 | * by sending an ABORT chunk. |
| 5541 | */ |
| 5542 | sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep, |
| 5543 | const struct sctp_association *asoc, |
| 5544 | const sctp_subtype_t type, |
| 5545 | void *arg, |
| 5546 | sctp_cmd_seq_t *commands) |
| 5547 | { |
| 5548 | struct sctp_chunk *reply = NULL; |
| 5549 | |
| 5550 | SCTP_DEBUG_PRINTK("Timer T5 expired.\n"); |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5551 | SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | |
| 5553 | reply = sctp_make_abort(asoc, NULL, 0); |
| 5554 | if (!reply) |
| 5555 | goto nomem; |
| 5556 | |
| 5557 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply)); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5558 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5559 | SCTP_ERROR(ETIMEDOUT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5560 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5561 | SCTP_PERR(SCTP_ERROR_NO_ERROR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5562 | |
Vlad Yasevich | a1080a8 | 2008-10-09 14:33:26 -0700 | [diff] [blame] | 5563 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 5564 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 5565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | return SCTP_DISPOSITION_DELETE_TCB; |
| 5567 | nomem: |
| 5568 | return SCTP_DISPOSITION_NOMEM; |
| 5569 | } |
| 5570 | |
| 5571 | /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires, |
| 5572 | * the association is automatically closed by starting the shutdown process. |
| 5573 | * The work that needs to be done is same as when SHUTDOWN is initiated by |
| 5574 | * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown(). |
| 5575 | */ |
| 5576 | sctp_disposition_t sctp_sf_autoclose_timer_expire( |
| 5577 | const struct sctp_endpoint *ep, |
| 5578 | const struct sctp_association *asoc, |
| 5579 | const sctp_subtype_t type, |
| 5580 | void *arg, |
| 5581 | sctp_cmd_seq_t *commands) |
| 5582 | { |
| 5583 | int disposition; |
| 5584 | |
Sridhar Samudrala | ac0b046 | 2006-08-22 00:15:33 -0700 | [diff] [blame] | 5585 | SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS); |
| 5586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5587 | /* From 9.2 Shutdown of an Association |
| 5588 | * Upon receipt of the SHUTDOWN primitive from its upper |
| 5589 | * layer, the endpoint enters SHUTDOWN-PENDING state and |
| 5590 | * remains there until all outstanding data has been |
| 5591 | * acknowledged by its peer. The endpoint accepts no new data |
| 5592 | * from its upper layer, but retransmits data to the far end |
| 5593 | * if necessary to fill gaps. |
| 5594 | */ |
| 5595 | sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE, |
| 5596 | SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING)); |
| 5597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | disposition = SCTP_DISPOSITION_CONSUME; |
| 5599 | if (sctp_outq_is_empty(&asoc->outqueue)) { |
| 5600 | disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type, |
| 5601 | arg, commands); |
| 5602 | } |
| 5603 | return disposition; |
| 5604 | } |
| 5605 | |
| 5606 | /***************************************************************************** |
| 5607 | * These are sa state functions which could apply to all types of events. |
| 5608 | ****************************************************************************/ |
| 5609 | |
| 5610 | /* |
| 5611 | * This table entry is not implemented. |
| 5612 | * |
| 5613 | * Inputs |
| 5614 | * (endpoint, asoc, chunk) |
| 5615 | * |
| 5616 | * The return value is the disposition of the chunk. |
| 5617 | */ |
| 5618 | sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep, |
| 5619 | const struct sctp_association *asoc, |
| 5620 | const sctp_subtype_t type, |
| 5621 | void *arg, |
| 5622 | sctp_cmd_seq_t *commands) |
| 5623 | { |
| 5624 | return SCTP_DISPOSITION_NOT_IMPL; |
| 5625 | } |
| 5626 | |
| 5627 | /* |
| 5628 | * This table entry represents a bug. |
| 5629 | * |
| 5630 | * Inputs |
| 5631 | * (endpoint, asoc, chunk) |
| 5632 | * |
| 5633 | * The return value is the disposition of the chunk. |
| 5634 | */ |
| 5635 | sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep, |
| 5636 | const struct sctp_association *asoc, |
| 5637 | const sctp_subtype_t type, |
| 5638 | void *arg, |
| 5639 | sctp_cmd_seq_t *commands) |
| 5640 | { |
| 5641 | return SCTP_DISPOSITION_BUG; |
| 5642 | } |
| 5643 | |
| 5644 | /* |
| 5645 | * This table entry represents the firing of a timer in the wrong state. |
| 5646 | * Since timer deletion cannot be guaranteed a timer 'may' end up firing |
| 5647 | * when the association is in the wrong state. This event should |
| 5648 | * be ignored, so as to prevent any rearming of the timer. |
| 5649 | * |
| 5650 | * Inputs |
| 5651 | * (endpoint, asoc, chunk) |
| 5652 | * |
| 5653 | * The return value is the disposition of the chunk. |
| 5654 | */ |
| 5655 | sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep, |
| 5656 | const struct sctp_association *asoc, |
| 5657 | const sctp_subtype_t type, |
| 5658 | void *arg, |
| 5659 | sctp_cmd_seq_t *commands) |
| 5660 | { |
| 5661 | SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk); |
| 5662 | return SCTP_DISPOSITION_CONSUME; |
| 5663 | } |
| 5664 | |
| 5665 | /******************************************************************** |
| 5666 | * 2nd Level Abstractions |
| 5667 | ********************************************************************/ |
| 5668 | |
| 5669 | /* Pull the SACK chunk based on the SACK header. */ |
| 5670 | static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk) |
| 5671 | { |
| 5672 | struct sctp_sackhdr *sack; |
| 5673 | unsigned int len; |
| 5674 | __u16 num_blocks; |
| 5675 | __u16 num_dup_tsns; |
| 5676 | |
| 5677 | /* Protect ourselves from reading too far into |
| 5678 | * the skb from a bogus sender. |
| 5679 | */ |
| 5680 | sack = (struct sctp_sackhdr *) chunk->skb->data; |
| 5681 | |
| 5682 | num_blocks = ntohs(sack->num_gap_ack_blocks); |
| 5683 | num_dup_tsns = ntohs(sack->num_dup_tsns); |
| 5684 | len = sizeof(struct sctp_sackhdr); |
| 5685 | len += (num_blocks + num_dup_tsns) * sizeof(__u32); |
| 5686 | if (len > chunk->skb->len) |
| 5687 | return NULL; |
| 5688 | |
| 5689 | skb_pull(chunk->skb, len); |
| 5690 | |
| 5691 | return sack; |
| 5692 | } |
| 5693 | |
| 5694 | /* Create an ABORT packet to be sent as a response, with the specified |
| 5695 | * error causes. |
| 5696 | */ |
| 5697 | static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep, |
| 5698 | const struct sctp_association *asoc, |
| 5699 | struct sctp_chunk *chunk, |
| 5700 | const void *payload, |
| 5701 | size_t paylen) |
| 5702 | { |
| 5703 | struct sctp_packet *packet; |
| 5704 | struct sctp_chunk *abort; |
| 5705 | |
| 5706 | packet = sctp_ootb_pkt_new(asoc, chunk); |
| 5707 | |
| 5708 | if (packet) { |
| 5709 | /* Make an ABORT. |
| 5710 | * The T bit will be set if the asoc is NULL. |
| 5711 | */ |
| 5712 | abort = sctp_make_abort(asoc, chunk, paylen); |
| 5713 | if (!abort) { |
| 5714 | sctp_ootb_pkt_free(packet); |
| 5715 | return NULL; |
| 5716 | } |
Jerome Forissier | 047a242 | 2005-04-28 11:58:43 -0700 | [diff] [blame] | 5717 | |
| 5718 | /* Reflect vtag if T-Bit is set */ |
| 5719 | if (sctp_test_T_bit(abort)) |
| 5720 | packet->vtag = ntohl(chunk->sctp_hdr->vtag); |
| 5721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | /* Add specified error causes, i.e., payload, to the |
| 5723 | * end of the chunk. |
| 5724 | */ |
| 5725 | sctp_addto_chunk(abort, paylen, payload); |
| 5726 | |
| 5727 | /* Set the skb to the belonging sock for accounting. */ |
| 5728 | abort->skb->sk = ep->base.sk; |
| 5729 | |
| 5730 | sctp_packet_append_chunk(packet, abort); |
| 5731 | |
| 5732 | } |
| 5733 | |
| 5734 | return packet; |
| 5735 | } |
| 5736 | |
| 5737 | /* Allocate a packet for responding in the OOTB conditions. */ |
| 5738 | static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc, |
| 5739 | const struct sctp_chunk *chunk) |
| 5740 | { |
| 5741 | struct sctp_packet *packet; |
| 5742 | struct sctp_transport *transport; |
| 5743 | __u16 sport; |
| 5744 | __u16 dport; |
| 5745 | __u32 vtag; |
| 5746 | |
| 5747 | /* Get the source and destination port from the inbound packet. */ |
| 5748 | sport = ntohs(chunk->sctp_hdr->dest); |
| 5749 | dport = ntohs(chunk->sctp_hdr->source); |
| 5750 | |
| 5751 | /* The V-tag is going to be the same as the inbound packet if no |
| 5752 | * association exists, otherwise, use the peer's vtag. |
| 5753 | */ |
| 5754 | if (asoc) { |
Wei Yongjun | 02c4e12 | 2007-08-31 10:03:58 +0800 | [diff] [blame] | 5755 | /* Special case the INIT-ACK as there is no peer's vtag |
| 5756 | * yet. |
| 5757 | */ |
| 5758 | switch(chunk->chunk_hdr->type) { |
| 5759 | case SCTP_CID_INIT_ACK: |
| 5760 | { |
| 5761 | sctp_initack_chunk_t *initack; |
| 5762 | |
| 5763 | initack = (sctp_initack_chunk_t *)chunk->chunk_hdr; |
| 5764 | vtag = ntohl(initack->init_hdr.init_tag); |
| 5765 | break; |
| 5766 | } |
| 5767 | default: |
| 5768 | vtag = asoc->peer.i.init_tag; |
| 5769 | break; |
| 5770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | } else { |
| 5772 | /* Special case the INIT and stale COOKIE_ECHO as there is no |
| 5773 | * vtag yet. |
| 5774 | */ |
| 5775 | switch(chunk->chunk_hdr->type) { |
| 5776 | case SCTP_CID_INIT: |
| 5777 | { |
| 5778 | sctp_init_chunk_t *init; |
| 5779 | |
| 5780 | init = (sctp_init_chunk_t *)chunk->chunk_hdr; |
| 5781 | vtag = ntohl(init->init_hdr.init_tag); |
| 5782 | break; |
| 5783 | } |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5784 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5785 | vtag = ntohl(chunk->sctp_hdr->vtag); |
| 5786 | break; |
| 5787 | } |
| 5788 | } |
| 5789 | |
| 5790 | /* Make a transport for the bucket, Eliza... */ |
Al Viro | 6a1e5f3 | 2006-11-20 17:12:25 -0800 | [diff] [blame] | 5791 | transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | if (!transport) |
| 5793 | goto nomem; |
| 5794 | |
| 5795 | /* Cache a route for the transport with the chunk's destination as |
| 5796 | * the source address. |
| 5797 | */ |
Al Viro | 16b0a03 | 2006-11-20 17:13:38 -0800 | [diff] [blame] | 5798 | sctp_transport_route(transport, (union sctp_addr *)&chunk->dest, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5799 | sctp_sk(sctp_get_ctl_sock())); |
| 5800 | |
| 5801 | packet = sctp_packet_init(&transport->packet, transport, sport, dport); |
| 5802 | packet = sctp_packet_config(packet, vtag, 0); |
| 5803 | |
| 5804 | return packet; |
| 5805 | |
| 5806 | nomem: |
| 5807 | return NULL; |
| 5808 | } |
| 5809 | |
| 5810 | /* Free the packet allocated earlier for responding in the OOTB condition. */ |
| 5811 | void sctp_ootb_pkt_free(struct sctp_packet *packet) |
| 5812 | { |
| 5813 | sctp_transport_free(packet->transport); |
| 5814 | } |
| 5815 | |
| 5816 | /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */ |
| 5817 | static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep, |
| 5818 | const struct sctp_association *asoc, |
| 5819 | const struct sctp_chunk *chunk, |
| 5820 | sctp_cmd_seq_t *commands, |
| 5821 | struct sctp_chunk *err_chunk) |
| 5822 | { |
| 5823 | struct sctp_packet *packet; |
| 5824 | |
| 5825 | if (err_chunk) { |
| 5826 | packet = sctp_ootb_pkt_new(asoc, chunk); |
| 5827 | if (packet) { |
| 5828 | struct sctp_signed_cookie *cookie; |
| 5829 | |
| 5830 | /* Override the OOTB vtag from the cookie. */ |
| 5831 | cookie = chunk->subh.cookie_hdr; |
| 5832 | packet->vtag = cookie->c.peer_vtag; |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5834 | /* Set the skb to the belonging sock for accounting. */ |
| 5835 | err_chunk->skb->sk = ep->base.sk; |
| 5836 | sctp_packet_append_chunk(packet, err_chunk); |
| 5837 | sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, |
| 5838 | SCTP_PACKET(packet)); |
| 5839 | SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS); |
| 5840 | } else |
| 5841 | sctp_chunk_free (err_chunk); |
| 5842 | } |
| 5843 | } |
| 5844 | |
| 5845 | |
| 5846 | /* Process a data chunk */ |
| 5847 | static int sctp_eat_data(const struct sctp_association *asoc, |
| 5848 | struct sctp_chunk *chunk, |
| 5849 | sctp_cmd_seq_t *commands) |
| 5850 | { |
| 5851 | sctp_datahdr_t *data_hdr; |
| 5852 | struct sctp_chunk *err; |
| 5853 | size_t datalen; |
| 5854 | sctp_verb_t deliver; |
| 5855 | int tmp; |
| 5856 | __u32 tsn; |
Neil Horman | 7c3ceb4f | 2006-05-05 17:02:09 -0700 | [diff] [blame] | 5857 | struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map; |
Neil Horman | 049b3ff | 2005-11-11 16:08:24 -0800 | [diff] [blame] | 5858 | struct sock *sk = asoc->base.sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | |
| 5860 | data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data; |
| 5861 | skb_pull(chunk->skb, sizeof(sctp_datahdr_t)); |
| 5862 | |
| 5863 | tsn = ntohl(data_hdr->tsn); |
| 5864 | SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn); |
| 5865 | |
| 5866 | /* ASSERT: Now skb->data is really the user data. */ |
| 5867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | /* Process ECN based congestion. |
| 5869 | * |
| 5870 | * Since the chunk structure is reused for all chunks within |
| 5871 | * a packet, we use ecn_ce_done to track if we've already |
| 5872 | * done CE processing for this packet. |
| 5873 | * |
| 5874 | * We need to do ECN processing even if we plan to discard the |
| 5875 | * chunk later. |
| 5876 | */ |
| 5877 | |
| 5878 | if (!chunk->ecn_ce_done) { |
| 5879 | struct sctp_af *af; |
| 5880 | chunk->ecn_ce_done = 1; |
| 5881 | |
| 5882 | af = sctp_get_af_specific( |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5883 | ipver2af(ip_hdr(chunk->skb)->version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5884 | |
| 5885 | if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) { |
| 5886 | /* Do real work as sideffect. */ |
| 5887 | sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE, |
| 5888 | SCTP_U32(tsn)); |
| 5889 | } |
| 5890 | } |
| 5891 | |
| 5892 | tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn); |
| 5893 | if (tmp < 0) { |
| 5894 | /* The TSN is too high--silently discard the chunk and |
| 5895 | * count on it getting retransmitted later. |
| 5896 | */ |
| 5897 | return SCTP_IERROR_HIGH_TSN; |
| 5898 | } else if (tmp > 0) { |
| 5899 | /* This is a duplicate. Record it. */ |
| 5900 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn)); |
| 5901 | return SCTP_IERROR_DUP_TSN; |
| 5902 | } |
| 5903 | |
| 5904 | /* This is a new TSN. */ |
| 5905 | |
| 5906 | /* Discard if there is no room in the receive window. |
| 5907 | * Actually, allow a little bit of overflow (up to a MTU). |
| 5908 | */ |
| 5909 | datalen = ntohs(chunk->chunk_hdr->length); |
| 5910 | datalen -= sizeof(sctp_data_chunk_t); |
| 5911 | |
| 5912 | deliver = SCTP_CMD_CHUNK_ULP; |
| 5913 | |
| 5914 | /* Think about partial delivery. */ |
| 5915 | if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { |
| 5916 | |
| 5917 | /* Even if we don't accept this chunk there is |
| 5918 | * memory pressure. |
| 5919 | */ |
| 5920 | sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL()); |
| 5921 | } |
| 5922 | |
YOSHIFUJI Hideaki | d808ad9 | 2007-02-09 23:25:18 +0900 | [diff] [blame] | 5923 | /* Spill over rwnd a little bit. Note: While allowed, this spill over |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | * seems a bit troublesome in that frag_point varies based on |
| 5925 | * PMTU. In cases, such as loopback, this might be a rather |
| 5926 | * large spill over. |
| 5927 | */ |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 5928 | if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over || |
| 5929 | (datalen > asoc->rwnd + asoc->frag_point))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5930 | |
| 5931 | /* If this is the next TSN, consider reneging to make |
| 5932 | * room. Note: Playing nice with a confused sender. A |
| 5933 | * malicious sender can still eat up all our buffer |
| 5934 | * space and in the future we may want to detect and |
| 5935 | * do more drastic reneging. |
| 5936 | */ |
Neil Horman | 7c3ceb4f | 2006-05-05 17:02:09 -0700 | [diff] [blame] | 5937 | if (sctp_tsnmap_has_gap(map) && |
| 5938 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5939 | SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn); |
| 5940 | deliver = SCTP_CMD_RENEGE; |
| 5941 | } else { |
| 5942 | SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, " |
| 5943 | "rwnd: %d\n", tsn, datalen, |
| 5944 | asoc->rwnd); |
| 5945 | return SCTP_IERROR_IGNORE_TSN; |
| 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | /* |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 5950 | * Also try to renege to limit our memory usage in the event that |
| 5951 | * we are under memory pressure |
Hideo Aoki | 3ab224b | 2007-12-31 00:11:19 -0800 | [diff] [blame] | 5952 | * 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] | 5953 | * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our |
| 5954 | * memory usage too much |
| 5955 | */ |
| 5956 | if (*sk->sk_prot_creator->memory_pressure) { |
| 5957 | if (sctp_tsnmap_has_gap(map) && |
| 5958 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
| 5959 | SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn); |
| 5960 | deliver = SCTP_CMD_RENEGE; |
| 5961 | } |
| 5962 | } |
| 5963 | |
| 5964 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5965 | * Section 3.3.10.9 No User Data (9) |
| 5966 | * |
| 5967 | * Cause of error |
| 5968 | * --------------- |
| 5969 | * No User Data: This error cause is returned to the originator of a |
| 5970 | * DATA chunk if a received DATA chunk has no user data. |
| 5971 | */ |
| 5972 | if (unlikely(0 == datalen)) { |
| 5973 | err = sctp_make_abort_no_data(asoc, chunk, tsn); |
| 5974 | if (err) { |
| 5975 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 5976 | SCTP_CHUNK(err)); |
| 5977 | } |
| 5978 | /* We are going to ABORT, so we might as well stop |
| 5979 | * processing the rest of the chunks in the packet. |
| 5980 | */ |
| 5981 | sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL()); |
Sridhar Samudrala | 8de8c87 | 2006-05-19 10:58:12 -0700 | [diff] [blame] | 5982 | sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, |
| 5983 | SCTP_ERROR(ECONNABORTED)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5984 | sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, |
Al Viro | 5be291f | 2006-11-20 17:01:06 -0800 | [diff] [blame] | 5985 | SCTP_PERR(SCTP_ERROR_NO_DATA)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5986 | SCTP_INC_STATS(SCTP_MIB_ABORTEDS); |
| 5987 | SCTP_DEC_STATS(SCTP_MIB_CURRESTAB); |
| 5988 | return SCTP_IERROR_NO_DATA; |
| 5989 | } |
| 5990 | |
Sridhar Samudrala | 9faa730 | 2006-07-21 14:49:07 -0700 | [diff] [blame] | 5991 | chunk->data_accepted = 1; |
| 5992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5993 | /* Note: Some chunks may get overcounted (if we drop) or overcounted |
| 5994 | * if we renege and the chunk arrives again. |
| 5995 | */ |
| 5996 | if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) |
| 5997 | SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS); |
| 5998 | else |
| 5999 | SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS); |
| 6000 | |
| 6001 | /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number |
| 6002 | * |
| 6003 | * If an endpoint receive a DATA chunk with an invalid stream |
| 6004 | * identifier, it shall acknowledge the reception of the DATA chunk |
| 6005 | * following the normal procedure, immediately send an ERROR chunk |
| 6006 | * with cause set to "Invalid Stream Identifier" (See Section 3.3.10) |
| 6007 | * and discard the DATA chunk. |
| 6008 | */ |
| 6009 | if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) { |
Vlad Yasevich | 3888e9e | 2008-07-08 02:28:39 -0700 | [diff] [blame] | 6010 | /* Mark tsn as received even though we drop it */ |
| 6011 | sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn)); |
| 6012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM, |
| 6014 | &data_hdr->stream, |
| 6015 | sizeof(data_hdr->stream)); |
| 6016 | if (err) |
| 6017 | sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, |
| 6018 | SCTP_CHUNK(err)); |
| 6019 | return SCTP_IERROR_BAD_STREAM; |
| 6020 | } |
| 6021 | |
| 6022 | /* Send the data up to the user. Note: Schedule the |
| 6023 | * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK |
| 6024 | * chunk needs the updated rwnd. |
| 6025 | */ |
| 6026 | sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk)); |
| 6027 | |
| 6028 | return SCTP_IERROR_NO_ERROR; |
| 6029 | } |