1 /* SCTP kernel reference Implementation
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.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
69 const struct sctp_association *asoc,
70 struct sctp_chunk *chunk,
73 static int sctp_eat_data(const struct sctp_association *asoc,
74 struct sctp_chunk *chunk,
75 sctp_cmd_seq_t *commands);
76 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
77 const struct sctp_chunk *chunk);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
79 const struct sctp_association *asoc,
80 const struct sctp_chunk *chunk,
81 sctp_cmd_seq_t *commands,
82 struct sctp_chunk *err_chunk);
83 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
84 const struct sctp_association *asoc,
85 const sctp_subtype_t type,
87 sctp_cmd_seq_t *commands);
88 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
89 const struct sctp_association *asoc,
90 const sctp_subtype_t type,
92 sctp_cmd_seq_t *commands);
93 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
94 const struct sctp_association *asoc,
95 const sctp_subtype_t type,
97 sctp_cmd_seq_t *commands);
98 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
100 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
101 __be16 error, int sk_err,
102 const struct sctp_association *asoc,
103 struct sctp_transport *transport);
105 static sctp_disposition_t sctp_sf_abort_violation(
106 const struct sctp_endpoint *ep,
107 const struct sctp_association *asoc,
109 sctp_cmd_seq_t *commands,
111 const size_t paylen);
113 static sctp_disposition_t sctp_sf_violation_chunklen(
114 const struct sctp_endpoint *ep,
115 const struct sctp_association *asoc,
116 const sctp_subtype_t type,
118 sctp_cmd_seq_t *commands);
120 static sctp_disposition_t sctp_sf_violation_paramlen(
121 const struct sctp_endpoint *ep,
122 const struct sctp_association *asoc,
123 const sctp_subtype_t type,
125 sctp_cmd_seq_t *commands);
127 static sctp_disposition_t sctp_sf_violation_ctsn(
128 const struct sctp_endpoint *ep,
129 const struct sctp_association *asoc,
130 const sctp_subtype_t type,
132 sctp_cmd_seq_t *commands);
134 static sctp_disposition_t sctp_sf_violation_chunk(
135 const struct sctp_endpoint *ep,
136 const struct sctp_association *asoc,
137 const sctp_subtype_t type,
139 sctp_cmd_seq_t *commands);
141 /* Small helper function that checks if the chunk length
142 * is of the appropriate length. The 'required_length' argument
143 * is set to be the size of a specific chunk we are testing.
144 * Return Values: 1 = Valid length
149 sctp_chunk_length_valid(struct sctp_chunk *chunk,
150 __u16 required_length)
152 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
154 if (unlikely(chunk_length < required_length))
160 /**********************************************************
161 * These are the state functions for handling chunk events.
162 **********************************************************/
165 * Process the final SHUTDOWN COMPLETE.
167 * Section: 4 (C) (diagram), 9.2
168 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
169 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
170 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
171 * should stop the T2-shutdown timer and remove all knowledge of the
172 * association (and thus the association enters the CLOSED state).
174 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
175 * C) Rules for packet carrying SHUTDOWN COMPLETE:
177 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
178 * if the Verification Tag field of the packet matches its own tag and
179 * the T bit is not set
181 * it is set to its peer's tag and the T bit is set in the Chunk
183 * Otherwise, the receiver MUST silently discard the packet
184 * and take no further action. An endpoint MUST ignore the
185 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
188 * (endpoint, asoc, chunk)
191 * (asoc, reply_msg, msg_up, timers, counters)
193 * The return value is the disposition of the chunk.
195 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
196 const struct sctp_association *asoc,
197 const sctp_subtype_t type,
199 sctp_cmd_seq_t *commands)
201 struct sctp_chunk *chunk = arg;
202 struct sctp_ulpevent *ev;
204 if (!sctp_vtag_verify_either(chunk, asoc))
205 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
207 /* RFC 2960 6.10 Bundling
209 * An endpoint MUST NOT bundle INIT, INIT ACK or
210 * SHUTDOWN COMPLETE with any other chunks.
212 if (!chunk->singleton)
213 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
215 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
216 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
217 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
220 /* RFC 2960 10.2 SCTP-to-ULP
222 * H) SHUTDOWN COMPLETE notification
224 * When SCTP completes the shutdown procedures (section 9.2) this
225 * notification is passed to the upper layer.
227 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
228 0, 0, 0, NULL, GFP_ATOMIC);
230 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
233 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
234 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
235 * not the chunk should be discarded. If the endpoint is in
236 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
237 * T2-shutdown timer and remove all knowledge of the
238 * association (and thus the association enters the CLOSED
241 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
242 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
244 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
245 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
247 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
248 SCTP_STATE(SCTP_STATE_CLOSED));
250 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
251 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
253 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
255 return SCTP_DISPOSITION_DELETE_TCB;
259 * Respond to a normal INIT chunk.
260 * We are the side that is being asked for an association.
262 * Section: 5.1 Normal Establishment of an Association, B
263 * B) "Z" shall respond immediately with an INIT ACK chunk. The
264 * destination IP address of the INIT ACK MUST be set to the source
265 * IP address of the INIT to which this INIT ACK is responding. In
266 * the response, besides filling in other parameters, "Z" must set the
267 * Verification Tag field to Tag_A, and also provide its own
268 * Verification Tag (Tag_Z) in the Initiate Tag field.
270 * Verification Tag: Must be 0.
273 * (endpoint, asoc, chunk)
276 * (asoc, reply_msg, msg_up, timers, counters)
278 * The return value is the disposition of the chunk.
280 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
281 const struct sctp_association *asoc,
282 const sctp_subtype_t type,
284 sctp_cmd_seq_t *commands)
286 struct sctp_chunk *chunk = arg;
287 struct sctp_chunk *repl;
288 struct sctp_association *new_asoc;
289 struct sctp_chunk *err_chunk;
290 struct sctp_packet *packet;
291 sctp_unrecognized_param_t *unk_param;
295 * An endpoint MUST NOT bundle INIT, INIT ACK or
296 * SHUTDOWN COMPLETE with any other chunks.
299 * Furthermore, we require that the receiver of an INIT chunk MUST
300 * enforce these rules by silently discarding an arriving packet
301 * with an INIT chunk that is bundled with other chunks.
303 if (!chunk->singleton)
304 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
306 /* If the packet is an OOTB packet which is temporarily on the
307 * control endpoint, respond with an ABORT.
309 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
310 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
312 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
315 if (chunk->sctp_hdr->vtag != 0)
316 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
318 /* Make sure that the INIT chunk has a valid length.
319 * Normally, this would cause an ABORT with a Protocol Violation
320 * error, but since we don't have an association, we'll
321 * just discard the packet.
323 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
324 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
326 /* Verify the INIT chunk before processing it. */
328 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
329 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
331 /* This chunk contains fatal error. It is to be discarded.
332 * Send an ABORT, with causes if there is any.
335 packet = sctp_abort_pkt_new(ep, asoc, arg,
336 (__u8 *)(err_chunk->chunk_hdr) +
337 sizeof(sctp_chunkhdr_t),
338 ntohs(err_chunk->chunk_hdr->length) -
339 sizeof(sctp_chunkhdr_t));
341 sctp_chunk_free(err_chunk);
344 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
345 SCTP_PACKET(packet));
346 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
347 return SCTP_DISPOSITION_CONSUME;
349 return SCTP_DISPOSITION_NOMEM;
352 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
357 /* Grab the INIT header. */
358 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
360 /* Tag the variable length parameters. */
361 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
363 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
367 /* The call, sctp_process_init(), can fail on memory allocation. */
368 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
370 (sctp_init_chunk_t *)chunk->chunk_hdr,
374 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
376 /* If there are errors need to be reported for unknown parameters,
377 * make sure to reserve enough room in the INIT ACK for them.
381 len = ntohs(err_chunk->chunk_hdr->length) -
382 sizeof(sctp_chunkhdr_t);
384 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
387 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
391 /* If there are errors need to be reported for unknown parameters,
392 * include them in the outgoing INIT ACK as "Unrecognized parameter"
396 /* Get the "Unrecognized parameter" parameter(s) out of the
397 * ERROR chunk generated by sctp_verify_init(). Since the
398 * error cause code for "unknown parameter" and the
399 * "Unrecognized parameter" type is the same, we can
400 * construct the parameters in INIT ACK by copying the
403 unk_param = (sctp_unrecognized_param_t *)
404 ((__u8 *)(err_chunk->chunk_hdr) +
405 sizeof(sctp_chunkhdr_t));
406 /* Replace the cause code with the "Unrecognized parameter"
409 sctp_addto_chunk(repl, len, unk_param);
410 sctp_chunk_free(err_chunk);
413 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
415 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
418 * Note: After sending out INIT ACK with the State Cookie parameter,
419 * "Z" MUST NOT allocate any resources, nor keep any states for the
420 * new association. Otherwise, "Z" will be vulnerable to resource
423 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
425 return SCTP_DISPOSITION_DELETE_TCB;
428 sctp_association_free(new_asoc);
431 sctp_chunk_free(err_chunk);
432 return SCTP_DISPOSITION_NOMEM;
436 * Respond to a normal INIT ACK chunk.
437 * We are the side that is initiating the association.
439 * Section: 5.1 Normal Establishment of an Association, C
440 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
441 * timer and leave COOKIE-WAIT state. "A" shall then send the State
442 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
443 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
445 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
446 * DATA chunks, but it MUST be the first chunk in the packet and
447 * until the COOKIE ACK is returned the sender MUST NOT send any
448 * other packets to the peer.
450 * Verification Tag: 3.3.3
451 * If the value of the Initiate Tag in a received INIT ACK chunk is
452 * found to be 0, the receiver MUST treat it as an error and close the
453 * association by transmitting an ABORT.
456 * (endpoint, asoc, chunk)
459 * (asoc, reply_msg, msg_up, timers, counters)
461 * The return value is the disposition of the chunk.
463 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
464 const struct sctp_association *asoc,
465 const sctp_subtype_t type,
467 sctp_cmd_seq_t *commands)
469 struct sctp_chunk *chunk = arg;
470 sctp_init_chunk_t *initchunk;
471 struct sctp_chunk *err_chunk;
472 struct sctp_packet *packet;
475 if (!sctp_vtag_verify(chunk, asoc))
476 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
479 * An endpoint MUST NOT bundle INIT, INIT ACK or
480 * SHUTDOWN COMPLETE with any other chunks.
482 if (!chunk->singleton)
483 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
485 /* Make sure that the INIT-ACK chunk has a valid length */
486 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
487 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
489 /* Grab the INIT header. */
490 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
492 /* Verify the INIT chunk before processing it. */
494 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
495 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
498 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
500 /* This chunk contains fatal error. It is to be discarded.
501 * Send an ABORT, with causes if there is any.
504 packet = sctp_abort_pkt_new(ep, asoc, arg,
505 (__u8 *)(err_chunk->chunk_hdr) +
506 sizeof(sctp_chunkhdr_t),
507 ntohs(err_chunk->chunk_hdr->length) -
508 sizeof(sctp_chunkhdr_t));
510 sctp_chunk_free(err_chunk);
513 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
514 SCTP_PACKET(packet));
515 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
516 error = SCTP_ERROR_INV_PARAM;
518 error = SCTP_ERROR_NO_RESOURCE;
521 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
522 error = SCTP_ERROR_INV_PARAM;
524 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
525 asoc, chunk->transport);
528 /* Tag the variable length parameters. Note that we never
529 * convert the parameters in an INIT chunk.
531 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
533 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
535 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
536 SCTP_PEER_INIT(initchunk));
538 /* Reset init error count upon receipt of INIT-ACK. */
539 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
541 /* 5.1 C) "A" shall stop the T1-init timer and leave
542 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
543 * timer, and enter the COOKIE-ECHOED state.
545 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
546 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
547 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
548 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
549 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
550 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
552 /* SCTP-AUTH: genereate the assocition shared keys so that
553 * we can potentially signe the COOKIE-ECHO.
555 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
557 /* 5.1 C) "A" shall then send the State Cookie received in the
558 * INIT ACK chunk in a COOKIE ECHO chunk, ...
560 /* If there is any errors to report, send the ERROR chunk generated
561 * for unknown parameters as well.
563 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
564 SCTP_CHUNK(err_chunk));
566 return SCTP_DISPOSITION_CONSUME;
570 * Respond to a normal COOKIE ECHO chunk.
571 * We are the side that is being asked for an association.
573 * Section: 5.1 Normal Establishment of an Association, D
574 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
575 * with a COOKIE ACK chunk after building a TCB and moving to
576 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
577 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
578 * chunk MUST be the first chunk in the packet.
580 * IMPLEMENTATION NOTE: An implementation may choose to send the
581 * Communication Up notification to the SCTP user upon reception
582 * of a valid COOKIE ECHO chunk.
584 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
585 * D) Rules for packet carrying a COOKIE ECHO
587 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
588 * Initial Tag received in the INIT ACK.
590 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
593 * (endpoint, asoc, chunk)
596 * (asoc, reply_msg, msg_up, timers, counters)
598 * The return value is the disposition of the chunk.
600 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
601 const struct sctp_association *asoc,
602 const sctp_subtype_t type, void *arg,
603 sctp_cmd_seq_t *commands)
605 struct sctp_chunk *chunk = arg;
606 struct sctp_association *new_asoc;
607 sctp_init_chunk_t *peer_init;
608 struct sctp_chunk *repl;
609 struct sctp_ulpevent *ev, *ai_ev = NULL;
611 struct sctp_chunk *err_chk_p;
614 /* If the packet is an OOTB packet which is temporarily on the
615 * control endpoint, respond with an ABORT.
617 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
618 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
620 /* Make sure that the COOKIE_ECHO chunk has a valid length.
621 * In this case, we check that we have enough for at least a
622 * chunk header. More detailed verification is done
623 * in sctp_unpack_cookie().
625 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
626 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
628 /* If the endpoint is not listening or if the number of associations
629 * on the TCP-style socket exceed the max backlog, respond with an
633 if (!sctp_sstate(sk, LISTENING) ||
634 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
635 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
637 /* "Decode" the chunk. We have no optional parameters so we
640 chunk->subh.cookie_hdr =
641 (struct sctp_signed_cookie *)chunk->skb->data;
642 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
643 sizeof(sctp_chunkhdr_t)))
646 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
647 * "Z" will reply with a COOKIE ACK chunk after building a TCB
648 * and moving to the ESTABLISHED state.
650 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
654 * If the re-build failed, what is the proper error path
657 * [We should abort the association. --piggy]
660 /* FIXME: Several errors are possible. A bad cookie should
661 * be silently discarded, but think about logging it too.
664 case -SCTP_IERROR_NOMEM:
667 case -SCTP_IERROR_STALE_COOKIE:
668 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
670 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
672 case -SCTP_IERROR_BAD_SIG:
674 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
679 /* Delay state machine commands until later.
681 * Re-build the bind address for the association is done in
682 * the sctp_unpack_cookie() already.
684 /* This is a brand-new association, so these are not yet side
685 * effects--it is safe to run them here.
687 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
689 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
690 &chunk->subh.cookie_hdr->c.peer_addr,
691 peer_init, GFP_ATOMIC))
694 /* SCTP-AUTH: Now that we've populate required fields in
695 * sctp_process_init, set up the assocaition shared keys as
696 * necessary so that we can potentially authenticate the ACK
698 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
702 repl = sctp_make_cookie_ack(new_asoc, chunk);
706 /* RFC 2960 5.1 Normal Establishment of an Association
708 * D) IMPLEMENTATION NOTE: An implementation may choose to
709 * send the Communication Up notification to the SCTP user
710 * upon reception of a valid COOKIE ECHO chunk.
712 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
713 new_asoc->c.sinit_num_ostreams,
714 new_asoc->c.sinit_max_instreams,
719 /* Sockets API Draft Section 5.3.1.6
720 * When a peer sends a Adaptation Layer Indication parameter , SCTP
721 * delivers this notification to inform the application that of the
722 * peers requested adaptation layer.
724 if (new_asoc->peer.adaptation_ind) {
725 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
731 /* Add all the state machine commands now since we've created
732 * everything. This way we don't introduce memory corruptions
733 * during side-effect processing and correclty count established
736 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
737 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
738 SCTP_STATE(SCTP_STATE_ESTABLISHED));
739 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
740 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
741 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
743 if (new_asoc->autoclose)
744 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
745 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
747 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
749 /* This will send the COOKIE ACK */
750 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
752 /* Queue the ASSOC_CHANGE event */
753 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
755 /* Send up the Adaptation Layer Indication event */
757 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
758 SCTP_ULPEVENT(ai_ev));
760 return SCTP_DISPOSITION_CONSUME;
763 sctp_ulpevent_free(ev);
765 sctp_chunk_free(repl);
767 sctp_association_free(new_asoc);
769 return SCTP_DISPOSITION_NOMEM;
773 * Respond to a normal COOKIE ACK chunk.
774 * We are the side that is being asked for an association.
776 * RFC 2960 5.1 Normal Establishment of an Association
778 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
779 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
780 * timer. It may also notify its ULP about the successful
781 * establishment of the association with a Communication Up
782 * notification (see Section 10).
786 * (endpoint, asoc, chunk)
789 * (asoc, reply_msg, msg_up, timers, counters)
791 * The return value is the disposition of the chunk.
793 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
794 const struct sctp_association *asoc,
795 const sctp_subtype_t type, void *arg,
796 sctp_cmd_seq_t *commands)
798 struct sctp_chunk *chunk = arg;
799 struct sctp_ulpevent *ev;
801 if (!sctp_vtag_verify(chunk, asoc))
802 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
804 /* Verify that the chunk length for the COOKIE-ACK is OK.
805 * If we don't do this, any bundled chunks may be junked.
807 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
808 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
811 /* Reset init error count upon receipt of COOKIE-ACK,
812 * to avoid problems with the managemement of this
813 * counter in stale cookie situations when a transition back
814 * from the COOKIE-ECHOED state to the COOKIE-WAIT
815 * state is performed.
817 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
819 /* RFC 2960 5.1 Normal Establishment of an Association
821 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
822 * from the COOKIE-ECHOED state to the ESTABLISHED state,
823 * stopping the T1-cookie timer.
825 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
826 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
827 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
828 SCTP_STATE(SCTP_STATE_ESTABLISHED));
829 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
830 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
831 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
833 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
834 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
835 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
837 /* It may also notify its ULP about the successful
838 * establishment of the association with a Communication Up
839 * notification (see Section 10).
841 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
842 0, asoc->c.sinit_num_ostreams,
843 asoc->c.sinit_max_instreams,
849 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
851 /* Sockets API Draft Section 5.3.1.6
852 * When a peer sends a Adaptation Layer Indication parameter , SCTP
853 * delivers this notification to inform the application that of the
854 * peers requested adaptation layer.
856 if (asoc->peer.adaptation_ind) {
857 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
861 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
865 return SCTP_DISPOSITION_CONSUME;
867 return SCTP_DISPOSITION_NOMEM;
870 /* Generate and sendout a heartbeat packet. */
871 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
872 const struct sctp_association *asoc,
873 const sctp_subtype_t type,
875 sctp_cmd_seq_t *commands)
877 struct sctp_transport *transport = (struct sctp_transport *) arg;
878 struct sctp_chunk *reply;
879 sctp_sender_hb_info_t hbinfo;
882 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
883 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
884 hbinfo.daddr = transport->ipaddr;
885 hbinfo.sent_at = jiffies;
886 hbinfo.hb_nonce = transport->hb_nonce;
888 /* Send a heartbeat to our peer. */
889 paylen = sizeof(sctp_sender_hb_info_t);
890 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
892 return SCTP_DISPOSITION_NOMEM;
894 /* Set rto_pending indicating that an RTT measurement
895 * is started with this heartbeat chunk.
897 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
898 SCTP_TRANSPORT(transport));
900 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
901 return SCTP_DISPOSITION_CONSUME;
904 /* Generate a HEARTBEAT packet on the given transport. */
905 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
906 const struct sctp_association *asoc,
907 const sctp_subtype_t type,
909 sctp_cmd_seq_t *commands)
911 struct sctp_transport *transport = (struct sctp_transport *) arg;
913 if (asoc->overall_error_count >= asoc->max_retrans) {
914 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
915 SCTP_ERROR(ETIMEDOUT));
916 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
917 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
918 SCTP_PERR(SCTP_ERROR_NO_ERROR));
919 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
920 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
921 return SCTP_DISPOSITION_DELETE_TCB;
925 * The Sender-specific Heartbeat Info field should normally include
926 * information about the sender's current time when this HEARTBEAT
927 * chunk is sent and the destination transport address to which this
928 * HEARTBEAT is sent (see Section 8.3).
931 if (transport->param_flags & SPP_HB_ENABLE) {
932 if (SCTP_DISPOSITION_NOMEM ==
933 sctp_sf_heartbeat(ep, asoc, type, arg,
935 return SCTP_DISPOSITION_NOMEM;
936 /* Set transport error counter and association error counter
937 * when sending heartbeat.
939 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
940 SCTP_TRANSPORT(transport));
942 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
943 SCTP_TRANSPORT(transport));
945 return SCTP_DISPOSITION_CONSUME;
949 * Process an heartbeat request.
951 * Section: 8.3 Path Heartbeat
952 * The receiver of the HEARTBEAT should immediately respond with a
953 * HEARTBEAT ACK that contains the Heartbeat Information field copied
954 * from the received HEARTBEAT chunk.
956 * Verification Tag: 8.5 Verification Tag [Normal verification]
957 * When receiving an SCTP packet, the endpoint MUST ensure that the
958 * value in the Verification Tag field of the received SCTP packet
959 * matches its own Tag. If the received Verification Tag value does not
960 * match the receiver's own tag value, the receiver shall silently
961 * discard the packet and shall not process it any further except for
962 * those cases listed in Section 8.5.1 below.
965 * (endpoint, asoc, chunk)
968 * (asoc, reply_msg, msg_up, timers, counters)
970 * The return value is the disposition of the chunk.
972 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
973 const struct sctp_association *asoc,
974 const sctp_subtype_t type,
976 sctp_cmd_seq_t *commands)
978 struct sctp_chunk *chunk = arg;
979 struct sctp_chunk *reply;
982 if (!sctp_vtag_verify(chunk, asoc))
983 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
985 /* Make sure that the HEARTBEAT chunk has a valid length. */
986 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
987 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
990 /* 8.3 The receiver of the HEARTBEAT should immediately
991 * respond with a HEARTBEAT ACK that contains the Heartbeat
992 * Information field copied from the received HEARTBEAT chunk.
994 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
995 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
996 if (!pskb_pull(chunk->skb, paylen))
999 reply = sctp_make_heartbeat_ack(asoc, chunk,
1000 chunk->subh.hb_hdr, paylen);
1004 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1005 return SCTP_DISPOSITION_CONSUME;
1008 return SCTP_DISPOSITION_NOMEM;
1012 * Process the returning HEARTBEAT ACK.
1014 * Section: 8.3 Path Heartbeat
1015 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1016 * should clear the error counter of the destination transport
1017 * address to which the HEARTBEAT was sent, and mark the destination
1018 * transport address as active if it is not so marked. The endpoint may
1019 * optionally report to the upper layer when an inactive destination
1020 * address is marked as active due to the reception of the latest
1021 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1022 * clear the association overall error count as well (as defined
1025 * The receiver of the HEARTBEAT ACK should also perform an RTT
1026 * measurement for that destination transport address using the time
1027 * value carried in the HEARTBEAT ACK chunk.
1029 * Verification Tag: 8.5 Verification Tag [Normal verification]
1032 * (endpoint, asoc, chunk)
1035 * (asoc, reply_msg, msg_up, timers, counters)
1037 * The return value is the disposition of the chunk.
1039 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1040 const struct sctp_association *asoc,
1041 const sctp_subtype_t type,
1043 sctp_cmd_seq_t *commands)
1045 struct sctp_chunk *chunk = arg;
1046 union sctp_addr from_addr;
1047 struct sctp_transport *link;
1048 sctp_sender_hb_info_t *hbinfo;
1049 unsigned long max_interval;
1051 if (!sctp_vtag_verify(chunk, asoc))
1052 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1054 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1055 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1056 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1059 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1060 /* Make sure that the length of the parameter is what we expect */
1061 if (ntohs(hbinfo->param_hdr.length) !=
1062 sizeof(sctp_sender_hb_info_t)) {
1063 return SCTP_DISPOSITION_DISCARD;
1066 from_addr = hbinfo->daddr;
1067 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1069 /* This should never happen, but lets log it if so. */
1070 if (unlikely(!link)) {
1071 if (from_addr.sa.sa_family == AF_INET6) {
1072 if (net_ratelimit())
1074 "%s association %p could not find address "
1078 NIP6(from_addr.v6.sin6_addr));
1080 if (net_ratelimit())
1082 "%s association %p could not find address "
1086 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1088 return SCTP_DISPOSITION_DISCARD;
1091 /* Validate the 64-bit random nonce. */
1092 if (hbinfo->hb_nonce != link->hb_nonce)
1093 return SCTP_DISPOSITION_DISCARD;
1095 max_interval = link->hbinterval + link->rto;
1097 /* Check if the timestamp looks valid. */
1098 if (time_after(hbinfo->sent_at, jiffies) ||
1099 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1100 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1101 "received for transport: %p\n",
1102 __FUNCTION__, link);
1103 return SCTP_DISPOSITION_DISCARD;
1106 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1107 * the HEARTBEAT should clear the error counter of the
1108 * destination transport address to which the HEARTBEAT was
1109 * sent and mark the destination transport address as active if
1110 * it is not so marked.
1112 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1114 return SCTP_DISPOSITION_CONSUME;
1117 /* Helper function to send out an abort for the restart
1120 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1121 struct sctp_chunk *init,
1122 sctp_cmd_seq_t *commands)
1125 struct sctp_packet *pkt;
1126 union sctp_addr_param *addrparm;
1127 struct sctp_errhdr *errhdr;
1128 struct sctp_endpoint *ep;
1129 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1130 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1132 /* Build the error on the stack. We are way to malloc crazy
1133 * throughout the code today.
1135 errhdr = (struct sctp_errhdr *)buffer;
1136 addrparm = (union sctp_addr_param *)errhdr->variable;
1138 /* Copy into a parm format. */
1139 len = af->to_addr_param(ssa, addrparm);
1140 len += sizeof(sctp_errhdr_t);
1142 errhdr->cause = SCTP_ERROR_RESTART;
1143 errhdr->length = htons(len);
1145 /* Assign to the control socket. */
1146 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1148 /* Association is NULL since this may be a restart attack and we
1149 * want to send back the attacker's vtag.
1151 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1155 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1157 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1159 /* Discard the rest of the inbound packet. */
1160 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1163 /* Even if there is no memory, treat as a failure so
1164 * the packet will get dropped.
1169 /* A restart is occurring, check to make sure no new addresses
1170 * are being added as we may be under a takeover attack.
1172 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1173 const struct sctp_association *asoc,
1174 struct sctp_chunk *init,
1175 sctp_cmd_seq_t *commands)
1177 struct sctp_transport *new_addr, *addr;
1178 struct list_head *pos, *pos2;
1181 /* Implementor's Guide - Sectin 5.2.2
1183 * Before responding the endpoint MUST check to see if the
1184 * unexpected INIT adds new addresses to the association. If new
1185 * addresses are added to the association, the endpoint MUST respond
1189 /* Search through all current addresses and make sure
1190 * we aren't adding any new ones.
1195 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1196 new_addr = list_entry(pos, struct sctp_transport, transports);
1198 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1199 addr = list_entry(pos2, struct sctp_transport,
1201 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1211 /* If a new address was added, ABORT the sender. */
1212 if (!found && new_addr) {
1213 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1216 /* Return success if all addresses were found. */
1220 /* Populate the verification/tie tags based on overlapping INIT
1223 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1225 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1226 const struct sctp_association *asoc)
1228 switch (asoc->state) {
1230 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1232 case SCTP_STATE_COOKIE_WAIT:
1233 new_asoc->c.my_vtag = asoc->c.my_vtag;
1234 new_asoc->c.my_ttag = asoc->c.my_vtag;
1235 new_asoc->c.peer_ttag = 0;
1238 case SCTP_STATE_COOKIE_ECHOED:
1239 new_asoc->c.my_vtag = asoc->c.my_vtag;
1240 new_asoc->c.my_ttag = asoc->c.my_vtag;
1241 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1244 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1245 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1248 new_asoc->c.my_ttag = asoc->c.my_vtag;
1249 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1253 /* Other parameters for the endpoint SHOULD be copied from the
1254 * existing parameters of the association (e.g. number of
1255 * outbound streams) into the INIT ACK and cookie.
1257 new_asoc->rwnd = asoc->rwnd;
1258 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1259 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1260 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1263 static void sctp_auth_params_populate(struct sctp_association *new_asoc,
1264 const struct sctp_association *asoc)
1266 /* Only perform this if AUTH extension is enabled */
1267 if (!sctp_auth_enable)
1270 /* We need to provide the same parameter information as
1271 * was in the original INIT. This means that we need to copy
1272 * the HMACS, CHUNKS, and RANDOM parameter from the original
1275 memcpy(new_asoc->c.auth_random, asoc->c.auth_random,
1276 sizeof(asoc->c.auth_random));
1277 memcpy(new_asoc->c.auth_hmacs, asoc->c.auth_hmacs,
1278 sizeof(asoc->c.auth_hmacs));
1279 memcpy(new_asoc->c.auth_chunks, asoc->c.auth_chunks,
1280 sizeof(asoc->c.auth_chunks));
1284 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1287 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1289 * Returns value representing action to be taken. These action values
1290 * correspond to Action/Description values in RFC 2960, Table 2.
1292 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1293 const struct sctp_association *asoc)
1295 /* In this case, the peer may have restarted. */
1296 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1297 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1298 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1299 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1302 /* Collision case B. */
1303 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1304 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1305 (0 == asoc->c.peer_vtag))) {
1309 /* Collision case D. */
1310 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1311 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1314 /* Collision case C. */
1315 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1316 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1317 (0 == new_asoc->c.my_ttag) &&
1318 (0 == new_asoc->c.peer_ttag))
1321 /* No match to any of the special cases; discard this packet. */
1325 /* Common helper routine for both duplicate and simulataneous INIT
1328 static sctp_disposition_t sctp_sf_do_unexpected_init(
1329 const struct sctp_endpoint *ep,
1330 const struct sctp_association *asoc,
1331 const sctp_subtype_t type,
1332 void *arg, sctp_cmd_seq_t *commands)
1334 sctp_disposition_t retval;
1335 struct sctp_chunk *chunk = arg;
1336 struct sctp_chunk *repl;
1337 struct sctp_association *new_asoc;
1338 struct sctp_chunk *err_chunk;
1339 struct sctp_packet *packet;
1340 sctp_unrecognized_param_t *unk_param;
1344 * An endpoint MUST NOT bundle INIT, INIT ACK or
1345 * SHUTDOWN COMPLETE with any other chunks.
1348 * Furthermore, we require that the receiver of an INIT chunk MUST
1349 * enforce these rules by silently discarding an arriving packet
1350 * with an INIT chunk that is bundled with other chunks.
1352 if (!chunk->singleton)
1353 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1355 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1358 if (chunk->sctp_hdr->vtag != 0)
1359 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1361 /* Make sure that the INIT chunk has a valid length.
1362 * In this case, we generate a protocol violation since we have
1363 * an association established.
1365 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1366 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1368 /* Grab the INIT header. */
1369 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1371 /* Tag the variable length parameters. */
1372 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1374 /* Verify the INIT chunk before processing it. */
1376 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1377 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1379 /* This chunk contains fatal error. It is to be discarded.
1380 * Send an ABORT, with causes if there is any.
1383 packet = sctp_abort_pkt_new(ep, asoc, arg,
1384 (__u8 *)(err_chunk->chunk_hdr) +
1385 sizeof(sctp_chunkhdr_t),
1386 ntohs(err_chunk->chunk_hdr->length) -
1387 sizeof(sctp_chunkhdr_t));
1390 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1391 SCTP_PACKET(packet));
1392 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1393 retval = SCTP_DISPOSITION_CONSUME;
1395 retval = SCTP_DISPOSITION_NOMEM;
1399 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1405 * Other parameters for the endpoint SHOULD be copied from the
1406 * existing parameters of the association (e.g. number of
1407 * outbound streams) into the INIT ACK and cookie.
1408 * FIXME: We are copying parameters from the endpoint not the
1411 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1415 /* In the outbound INIT ACK the endpoint MUST copy its current
1416 * Verification Tag and Peers Verification tag into a reserved
1417 * place (local tie-tag and per tie-tag) within the state cookie.
1419 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1421 (sctp_init_chunk_t *)chunk->chunk_hdr,
1425 /* Make sure no new addresses are being added during the
1426 * restart. Do not do this check for COOKIE-WAIT state,
1427 * since there are no peer addresses to check against.
1428 * Upon return an ABORT will have been sent if needed.
1430 if (!sctp_state(asoc, COOKIE_WAIT)) {
1431 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1433 retval = SCTP_DISPOSITION_CONSUME;
1438 sctp_tietags_populate(new_asoc, asoc);
1440 sctp_auth_params_populate(new_asoc, asoc);
1442 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1444 /* If there are errors need to be reported for unknown parameters,
1445 * make sure to reserve enough room in the INIT ACK for them.
1449 len = ntohs(err_chunk->chunk_hdr->length) -
1450 sizeof(sctp_chunkhdr_t);
1453 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1456 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1460 /* If there are errors need to be reported for unknown parameters,
1461 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1465 /* Get the "Unrecognized parameter" parameter(s) out of the
1466 * ERROR chunk generated by sctp_verify_init(). Since the
1467 * error cause code for "unknown parameter" and the
1468 * "Unrecognized parameter" type is the same, we can
1469 * construct the parameters in INIT ACK by copying the
1470 * ERROR causes over.
1472 unk_param = (sctp_unrecognized_param_t *)
1473 ((__u8 *)(err_chunk->chunk_hdr) +
1474 sizeof(sctp_chunkhdr_t));
1475 /* Replace the cause code with the "Unrecognized parameter"
1478 sctp_addto_chunk(repl, len, unk_param);
1481 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1482 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1485 * Note: After sending out INIT ACK with the State Cookie parameter,
1486 * "Z" MUST NOT allocate any resources for this new association.
1487 * Otherwise, "Z" will be vulnerable to resource attacks.
1489 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1490 retval = SCTP_DISPOSITION_CONSUME;
1495 retval = SCTP_DISPOSITION_NOMEM;
1498 sctp_association_free(new_asoc);
1501 sctp_chunk_free(err_chunk);
1506 * Handle simultanous INIT.
1507 * This means we started an INIT and then we got an INIT request from
1510 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1511 * This usually indicates an initialization collision, i.e., each
1512 * endpoint is attempting, at about the same time, to establish an
1513 * association with the other endpoint.
1515 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1516 * endpoint MUST respond with an INIT ACK using the same parameters it
1517 * sent in its original INIT chunk (including its Verification Tag,
1518 * unchanged). These original parameters are combined with those from the
1519 * newly received INIT chunk. The endpoint shall also generate a State
1520 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1521 * INIT to calculate the State Cookie.
1523 * After that, the endpoint MUST NOT change its state, the T1-init
1524 * timer shall be left running and the corresponding TCB MUST NOT be
1525 * destroyed. The normal procedures for handling State Cookies when
1526 * a TCB exists will resolve the duplicate INITs to a single association.
1528 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1529 * its Tie-Tags with the Tag information of itself and its peer (see
1530 * section 5.2.2 for a description of the Tie-Tags).
1532 * Verification Tag: Not explicit, but an INIT can not have a valid
1533 * verification tag, so we skip the check.
1536 * (endpoint, asoc, chunk)
1539 * (asoc, reply_msg, msg_up, timers, counters)
1541 * The return value is the disposition of the chunk.
1543 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1544 const struct sctp_association *asoc,
1545 const sctp_subtype_t type,
1547 sctp_cmd_seq_t *commands)
1549 /* Call helper to do the real work for both simulataneous and
1550 * duplicate INIT chunk handling.
1552 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1556 * Handle duplicated INIT messages. These are usually delayed
1559 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1560 * COOKIE-ECHOED and COOKIE-WAIT
1562 * Unless otherwise stated, upon reception of an unexpected INIT for
1563 * this association, the endpoint shall generate an INIT ACK with a
1564 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1565 * current Verification Tag and peer's Verification Tag into a reserved
1566 * place within the state cookie. We shall refer to these locations as
1567 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1568 * containing this INIT ACK MUST carry a Verification Tag value equal to
1569 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1570 * MUST contain a new Initiation Tag (randomly generated see Section
1571 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1572 * existing parameters of the association (e.g. number of outbound
1573 * streams) into the INIT ACK and cookie.
1575 * After sending out the INIT ACK, the endpoint shall take no further
1576 * actions, i.e., the existing association, including its current state,
1577 * and the corresponding TCB MUST NOT be changed.
1579 * Note: Only when a TCB exists and the association is not in a COOKIE-
1580 * WAIT state are the Tie-Tags populated. For a normal association INIT
1581 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1582 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1583 * State Cookie are populated as specified in section 5.2.1.
1585 * Verification Tag: Not specified, but an INIT has no way of knowing
1586 * what the verification tag could be, so we ignore it.
1589 * (endpoint, asoc, chunk)
1592 * (asoc, reply_msg, msg_up, timers, counters)
1594 * The return value is the disposition of the chunk.
1596 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1597 const struct sctp_association *asoc,
1598 const sctp_subtype_t type,
1600 sctp_cmd_seq_t *commands)
1602 /* Call helper to do the real work for both simulataneous and
1603 * duplicate INIT chunk handling.
1605 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1610 * Unexpected INIT-ACK handler.
1613 * If an INIT ACK received by an endpoint in any state other than the
1614 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1615 * An unexpected INIT ACK usually indicates the processing of an old or
1616 * duplicated INIT chunk.
1618 sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1619 const struct sctp_association *asoc,
1620 const sctp_subtype_t type,
1621 void *arg, sctp_cmd_seq_t *commands)
1623 /* Per the above section, we'll discard the chunk if we have an
1624 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1626 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1627 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1629 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1632 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1635 * A) In this case, the peer may have restarted.
1637 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1638 const struct sctp_association *asoc,
1639 struct sctp_chunk *chunk,
1640 sctp_cmd_seq_t *commands,
1641 struct sctp_association *new_asoc)
1643 sctp_init_chunk_t *peer_init;
1644 struct sctp_ulpevent *ev;
1645 struct sctp_chunk *repl;
1646 struct sctp_chunk *err;
1647 sctp_disposition_t disposition;
1649 /* new_asoc is a brand-new association, so these are not yet
1650 * side effects--it is safe to run them here.
1652 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1654 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1655 sctp_source(chunk), peer_init,
1659 /* Make sure no new addresses are being added during the
1660 * restart. Though this is a pretty complicated attack
1661 * since you'd have to get inside the cookie.
1663 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1664 return SCTP_DISPOSITION_CONSUME;
1667 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1668 * the peer has restarted (Action A), it MUST NOT setup a new
1669 * association but instead resend the SHUTDOWN ACK and send an ERROR
1670 * chunk with a "Cookie Received while Shutting Down" error cause to
1673 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1674 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1675 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1677 if (SCTP_DISPOSITION_NOMEM == disposition)
1680 err = sctp_make_op_error(asoc, chunk,
1681 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1684 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1687 return SCTP_DISPOSITION_CONSUME;
1690 /* For now, fail any unsent/unacked data. Consider the optional
1691 * choice of resending of this data.
1693 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1695 repl = sctp_make_cookie_ack(new_asoc, chunk);
1699 /* Report association restart to upper layer. */
1700 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1701 new_asoc->c.sinit_num_ostreams,
1702 new_asoc->c.sinit_max_instreams,
1707 /* Update the content of current association. */
1708 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1709 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1710 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1711 return SCTP_DISPOSITION_CONSUME;
1714 sctp_chunk_free(repl);
1716 return SCTP_DISPOSITION_NOMEM;
1719 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1722 * B) In this case, both sides may be attempting to start an association
1723 * at about the same time but the peer endpoint started its INIT
1724 * after responding to the local endpoint's INIT
1726 /* This case represents an initialization collision. */
1727 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1728 const struct sctp_association *asoc,
1729 struct sctp_chunk *chunk,
1730 sctp_cmd_seq_t *commands,
1731 struct sctp_association *new_asoc)
1733 sctp_init_chunk_t *peer_init;
1734 struct sctp_chunk *repl;
1736 /* new_asoc is a brand-new association, so these are not yet
1737 * side effects--it is safe to run them here.
1739 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1740 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1741 sctp_source(chunk), peer_init,
1745 /* Update the content of current association. */
1746 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1747 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1748 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1749 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1750 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1752 repl = sctp_make_cookie_ack(new_asoc, chunk);
1756 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1757 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1759 /* RFC 2960 5.1 Normal Establishment of an Association
1761 * D) IMPLEMENTATION NOTE: An implementation may choose to
1762 * send the Communication Up notification to the SCTP user
1763 * upon reception of a valid COOKIE ECHO chunk.
1765 * Sadly, this needs to be implemented as a side-effect, because
1766 * we are not guaranteed to have set the association id of the real
1767 * association and so these notifications need to be delayed until
1768 * the association id is allocated.
1771 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1773 /* Sockets API Draft Section 5.3.1.6
1774 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1775 * delivers this notification to inform the application that of the
1776 * peers requested adaptation layer.
1778 * This also needs to be done as a side effect for the same reason as
1781 if (asoc->peer.adaptation_ind)
1782 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1784 return SCTP_DISPOSITION_CONSUME;
1787 return SCTP_DISPOSITION_NOMEM;
1790 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1793 * C) In this case, the local endpoint's cookie has arrived late.
1794 * Before it arrived, the local endpoint sent an INIT and received an
1795 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1796 * but a new tag of its own.
1798 /* This case represents an initialization collision. */
1799 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1800 const struct sctp_association *asoc,
1801 struct sctp_chunk *chunk,
1802 sctp_cmd_seq_t *commands,
1803 struct sctp_association *new_asoc)
1805 /* The cookie should be silently discarded.
1806 * The endpoint SHOULD NOT change states and should leave
1807 * any timers running.
1809 return SCTP_DISPOSITION_DISCARD;
1812 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1816 * D) When both local and remote tags match the endpoint should always
1817 * enter the ESTABLISHED state, if it has not already done so.
1819 /* This case represents an initialization collision. */
1820 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1821 const struct sctp_association *asoc,
1822 struct sctp_chunk *chunk,
1823 sctp_cmd_seq_t *commands,
1824 struct sctp_association *new_asoc)
1826 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1827 struct sctp_chunk *repl;
1829 /* Clarification from Implementor's Guide:
1830 * D) When both local and remote tags match the endpoint should
1831 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1832 * It should stop any cookie timer that may be running and send
1836 /* Don't accidentally move back into established state. */
1837 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1838 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1839 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1840 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1841 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1842 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1843 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1846 /* RFC 2960 5.1 Normal Establishment of an Association
1848 * D) IMPLEMENTATION NOTE: An implementation may choose
1849 * to send the Communication Up notification to the
1850 * SCTP user upon reception of a valid COOKIE
1853 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1855 asoc->c.sinit_num_ostreams,
1856 asoc->c.sinit_max_instreams,
1861 /* Sockets API Draft Section 5.3.1.6
1862 * When a peer sends a Adaptation Layer Indication parameter,
1863 * SCTP delivers this notification to inform the application
1864 * that of the peers requested adaptation layer.
1866 if (asoc->peer.adaptation_ind) {
1867 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1874 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1876 repl = sctp_make_cookie_ack(new_asoc, chunk);
1881 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1884 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1885 SCTP_ULPEVENT(ai_ev));
1887 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1888 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1890 return SCTP_DISPOSITION_CONSUME;
1894 sctp_ulpevent_free(ai_ev);
1896 sctp_ulpevent_free(ev);
1897 return SCTP_DISPOSITION_NOMEM;
1901 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1902 * chunk was retransmitted and then delayed in the network.
1904 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1906 * Verification Tag: None. Do cookie validation.
1909 * (endpoint, asoc, chunk)
1912 * (asoc, reply_msg, msg_up, timers, counters)
1914 * The return value is the disposition of the chunk.
1916 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1917 const struct sctp_association *asoc,
1918 const sctp_subtype_t type,
1920 sctp_cmd_seq_t *commands)
1922 sctp_disposition_t retval;
1923 struct sctp_chunk *chunk = arg;
1924 struct sctp_association *new_asoc;
1927 struct sctp_chunk *err_chk_p;
1929 /* Make sure that the chunk has a valid length from the protocol
1930 * perspective. In this case check to make sure we have at least
1931 * enough for the chunk header. Cookie length verification is
1934 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1935 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1938 /* "Decode" the chunk. We have no optional parameters so we
1939 * are in good shape.
1941 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1942 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1943 sizeof(sctp_chunkhdr_t)))
1946 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1947 * of a duplicate COOKIE ECHO match the Verification Tags of the
1948 * current association, consider the State Cookie valid even if
1949 * the lifespan is exceeded.
1951 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1955 * If the re-build failed, what is the proper error path
1958 * [We should abort the association. --piggy]
1961 /* FIXME: Several errors are possible. A bad cookie should
1962 * be silently discarded, but think about logging it too.
1965 case -SCTP_IERROR_NOMEM:
1968 case -SCTP_IERROR_STALE_COOKIE:
1969 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1971 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1972 case -SCTP_IERROR_BAD_SIG:
1974 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1978 /* Compare the tie_tag in cookie with the verification tag of
1979 * current association.
1981 action = sctp_tietags_compare(new_asoc, asoc);
1984 case 'A': /* Association restart. */
1985 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1989 case 'B': /* Collision case B. */
1990 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1994 case 'C': /* Collision case C. */
1995 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1999 case 'D': /* Collision case D. */
2000 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
2004 default: /* Discard packet for all others. */
2005 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2009 /* Delete the tempory new association. */
2010 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
2011 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2016 return SCTP_DISPOSITION_NOMEM;
2020 * Process an ABORT. (SHUTDOWN-PENDING state)
2022 * See sctp_sf_do_9_1_abort().
2024 sctp_disposition_t sctp_sf_shutdown_pending_abort(
2025 const struct sctp_endpoint *ep,
2026 const struct sctp_association *asoc,
2027 const sctp_subtype_t type,
2029 sctp_cmd_seq_t *commands)
2031 struct sctp_chunk *chunk = arg;
2033 if (!sctp_vtag_verify_either(chunk, asoc))
2034 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2036 /* Make sure that the ABORT chunk has a valid length.
2037 * Since this is an ABORT chunk, we have to discard it
2038 * because of the following text:
2039 * RFC 2960, Section 3.3.7
2040 * If an endpoint receives an ABORT with a format error or for an
2041 * association that doesn't exist, it MUST silently discard it.
2042 * Becasue the length is "invalid", we can't really discard just
2043 * as we do not know its true length. So, to be safe, discard the
2046 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2047 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2049 /* Stop the T5-shutdown guard timer. */
2050 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2051 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2053 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2057 * Process an ABORT. (SHUTDOWN-SENT state)
2059 * See sctp_sf_do_9_1_abort().
2061 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2062 const struct sctp_association *asoc,
2063 const sctp_subtype_t type,
2065 sctp_cmd_seq_t *commands)
2067 struct sctp_chunk *chunk = arg;
2069 if (!sctp_vtag_verify_either(chunk, asoc))
2070 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2072 /* Make sure that the ABORT chunk has a valid length.
2073 * Since this is an ABORT chunk, we have to discard it
2074 * because of the following text:
2075 * RFC 2960, Section 3.3.7
2076 * If an endpoint receives an ABORT with a format error or for an
2077 * association that doesn't exist, it MUST silently discard it.
2078 * Becasue the length is "invalid", we can't really discard just
2079 * as we do not know its true length. So, to be safe, discard the
2082 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2083 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2085 /* Stop the T2-shutdown timer. */
2086 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2087 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2089 /* Stop the T5-shutdown guard timer. */
2090 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2091 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2093 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2097 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2099 * See sctp_sf_do_9_1_abort().
2101 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2102 const struct sctp_endpoint *ep,
2103 const struct sctp_association *asoc,
2104 const sctp_subtype_t type,
2106 sctp_cmd_seq_t *commands)
2108 /* The same T2 timer, so we should be able to use
2109 * common function with the SHUTDOWN-SENT state.
2111 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2115 * Handle an Error received in COOKIE_ECHOED state.
2117 * Only handle the error type of stale COOKIE Error, the other errors will
2121 * (endpoint, asoc, chunk)
2124 * (asoc, reply_msg, msg_up, timers, counters)
2126 * The return value is the disposition of the chunk.
2128 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2129 const struct sctp_association *asoc,
2130 const sctp_subtype_t type,
2132 sctp_cmd_seq_t *commands)
2134 struct sctp_chunk *chunk = arg;
2137 if (!sctp_vtag_verify(chunk, asoc))
2138 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2140 /* Make sure that the ERROR chunk has a valid length.
2141 * The parameter walking depends on this as well.
2143 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2144 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2147 /* Process the error here */
2148 /* FUTURE FIXME: When PR-SCTP related and other optional
2149 * parms are emitted, this will have to change to handle multiple
2152 sctp_walk_errors(err, chunk->chunk_hdr) {
2153 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2154 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2158 /* It is possible to have malformed error causes, and that
2159 * will cause us to end the walk early. However, since
2160 * we are discarding the packet, there should be no adverse
2163 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2167 * Handle a Stale COOKIE Error
2169 * Section: 5.2.6 Handle Stale COOKIE Error
2170 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2171 * one of the following three alternatives.
2173 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2174 * Preservative parameter requesting an extension to the lifetime of
2175 * the State Cookie. When calculating the time extension, an
2176 * implementation SHOULD use the RTT information measured based on the
2177 * previous COOKIE ECHO / ERROR exchange, and should add no more
2178 * than 1 second beyond the measured RTT, due to long State Cookie
2179 * lifetimes making the endpoint more subject to a replay attack.
2181 * Verification Tag: Not explicit, but safe to ignore.
2184 * (endpoint, asoc, chunk)
2187 * (asoc, reply_msg, msg_up, timers, counters)
2189 * The return value is the disposition of the chunk.
2191 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2192 const struct sctp_association *asoc,
2193 const sctp_subtype_t type,
2195 sctp_cmd_seq_t *commands)
2197 struct sctp_chunk *chunk = arg;
2199 sctp_cookie_preserve_param_t bht;
2201 struct sctp_chunk *reply;
2202 struct sctp_bind_addr *bp;
2203 int attempts = asoc->init_err_counter + 1;
2205 if (attempts > asoc->max_init_attempts) {
2206 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2207 SCTP_ERROR(ETIMEDOUT));
2208 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2209 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2210 return SCTP_DISPOSITION_DELETE_TCB;
2213 err = (sctp_errhdr_t *)(chunk->skb->data);
2215 /* When calculating the time extension, an implementation
2216 * SHOULD use the RTT information measured based on the
2217 * previous COOKIE ECHO / ERROR exchange, and should add no
2218 * more than 1 second beyond the measured RTT, due to long
2219 * State Cookie lifetimes making the endpoint more subject to
2221 * Measure of Staleness's unit is usec. (1/1000000 sec)
2222 * Suggested Cookie Life-span Increment's unit is msec.
2224 * In general, if you use the suggested cookie life, the value
2225 * found in the field of measure of staleness should be doubled
2226 * to give ample time to retransmit the new cookie and thus
2227 * yield a higher probability of success on the reattempt.
2229 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2230 stale = (stale * 2) / 1000;
2232 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2233 bht.param_hdr.length = htons(sizeof(bht));
2234 bht.lifespan_increment = htonl(stale);
2236 /* Build that new INIT chunk. */
2237 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2238 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2242 sctp_addto_chunk(reply, sizeof(bht), &bht);
2244 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2245 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2247 /* Stop pending T3-rtx and heartbeat timers */
2248 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2249 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2251 /* Delete non-primary peer ip addresses since we are transitioning
2252 * back to the COOKIE-WAIT state
2254 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2256 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2259 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN,
2260 SCTP_TRANSPORT(asoc->peer.primary_path));
2262 /* Cast away the const modifier, as we want to just
2263 * rerun it through as a sideffect.
2265 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2267 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2268 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2269 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2270 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2271 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2272 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2274 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2276 return SCTP_DISPOSITION_CONSUME;
2279 return SCTP_DISPOSITION_NOMEM;
2286 * After checking the Verification Tag, the receiving endpoint shall
2287 * remove the association from its record, and shall report the
2288 * termination to its upper layer.
2290 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2291 * B) Rules for packet carrying ABORT:
2293 * - The endpoint shall always fill in the Verification Tag field of the
2294 * outbound packet with the destination endpoint's tag value if it
2297 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2298 * MUST follow the procedure described in Section 8.4.
2300 * - The receiver MUST accept the packet if the Verification Tag
2301 * matches either its own tag, OR the tag of its peer. Otherwise, the
2302 * receiver MUST silently discard the packet and take no further
2306 * (endpoint, asoc, chunk)
2309 * (asoc, reply_msg, msg_up, timers, counters)
2311 * The return value is the disposition of the chunk.
2313 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2314 const struct sctp_association *asoc,
2315 const sctp_subtype_t type,
2317 sctp_cmd_seq_t *commands)
2319 struct sctp_chunk *chunk = arg;
2321 __be16 error = SCTP_ERROR_NO_ERROR;
2323 if (!sctp_vtag_verify_either(chunk, asoc))
2324 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2326 /* Make sure that the ABORT chunk has a valid length.
2327 * Since this is an ABORT chunk, we have to discard it
2328 * because of the following text:
2329 * RFC 2960, Section 3.3.7
2330 * If an endpoint receives an ABORT with a format error or for an
2331 * association that doesn't exist, it MUST silently discard it.
2332 * Becasue the length is "invalid", we can't really discard just
2333 * as we do not know its true length. So, to be safe, discard the
2336 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2337 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2339 /* See if we have an error cause code in the chunk. */
2340 len = ntohs(chunk->chunk_hdr->length);
2341 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2342 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2344 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2345 /* ASSOC_FAILED will DELETE_TCB. */
2346 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2347 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2348 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2350 return SCTP_DISPOSITION_ABORT;
2354 * Process an ABORT. (COOKIE-WAIT state)
2356 * See sctp_sf_do_9_1_abort() above.
2358 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2359 const struct sctp_association *asoc,
2360 const sctp_subtype_t type,
2362 sctp_cmd_seq_t *commands)
2364 struct sctp_chunk *chunk = arg;
2366 __be16 error = SCTP_ERROR_NO_ERROR;
2368 if (!sctp_vtag_verify_either(chunk, asoc))
2369 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2371 /* Make sure that the ABORT chunk has a valid length.
2372 * Since this is an ABORT chunk, we have to discard it
2373 * because of the following text:
2374 * RFC 2960, Section 3.3.7
2375 * If an endpoint receives an ABORT with a format error or for an
2376 * association that doesn't exist, it MUST silently discard it.
2377 * Becasue the length is "invalid", we can't really discard just
2378 * as we do not know its true length. So, to be safe, discard the
2381 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2382 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2384 /* See if we have an error cause code in the chunk. */
2385 len = ntohs(chunk->chunk_hdr->length);
2386 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2387 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2389 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2394 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2396 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2397 const struct sctp_association *asoc,
2398 const sctp_subtype_t type,
2400 sctp_cmd_seq_t *commands)
2402 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2404 (struct sctp_transport *)arg);
2408 * Process an ABORT. (COOKIE-ECHOED state)
2410 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2411 const struct sctp_association *asoc,
2412 const sctp_subtype_t type,
2414 sctp_cmd_seq_t *commands)
2416 /* There is a single T1 timer, so we should be able to use
2417 * common function with the COOKIE-WAIT state.
2419 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2423 * Stop T1 timer and abort association with "INIT failed".
2425 * This is common code called by several sctp_sf_*_abort() functions above.
2427 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2428 __be16 error, int sk_err,
2429 const struct sctp_association *asoc,
2430 struct sctp_transport *transport)
2432 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2433 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2434 SCTP_STATE(SCTP_STATE_CLOSED));
2435 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2436 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2437 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2438 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2439 /* CMD_INIT_FAILED will DELETE_TCB. */
2440 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2442 return SCTP_DISPOSITION_ABORT;
2446 * sctp_sf_do_9_2_shut
2449 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2450 * - enter the SHUTDOWN-RECEIVED state,
2452 * - stop accepting new data from its SCTP user
2454 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2455 * that all its outstanding DATA chunks have been received by the
2458 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2459 * send a SHUTDOWN in response to a ULP request. And should discard
2460 * subsequent SHUTDOWN chunks.
2462 * If there are still outstanding DATA chunks left, the SHUTDOWN
2463 * receiver shall continue to follow normal data transmission
2464 * procedures defined in Section 6 until all outstanding DATA chunks
2465 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2466 * new data from its SCTP user.
2468 * Verification Tag: 8.5 Verification Tag [Normal verification]
2471 * (endpoint, asoc, chunk)
2474 * (asoc, reply_msg, msg_up, timers, counters)
2476 * The return value is the disposition of the chunk.
2478 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2479 const struct sctp_association *asoc,
2480 const sctp_subtype_t type,
2482 sctp_cmd_seq_t *commands)
2484 struct sctp_chunk *chunk = arg;
2485 sctp_shutdownhdr_t *sdh;
2486 sctp_disposition_t disposition;
2487 struct sctp_ulpevent *ev;
2489 if (!sctp_vtag_verify(chunk, asoc))
2490 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2492 /* Make sure that the SHUTDOWN chunk has a valid length. */
2493 if (!sctp_chunk_length_valid(chunk,
2494 sizeof(struct sctp_shutdown_chunk_t)))
2495 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2498 /* Convert the elaborate header. */
2499 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2500 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2501 chunk->subh.shutdown_hdr = sdh;
2503 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2504 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2505 * inform the application that it should cease sending data.
2507 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2509 disposition = SCTP_DISPOSITION_NOMEM;
2512 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2514 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2515 * - enter the SHUTDOWN-RECEIVED state,
2516 * - stop accepting new data from its SCTP user
2518 * [This is implicit in the new state.]
2520 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2521 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2522 disposition = SCTP_DISPOSITION_CONSUME;
2524 if (sctp_outq_is_empty(&asoc->outqueue)) {
2525 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2529 if (SCTP_DISPOSITION_NOMEM == disposition)
2532 /* - verify, by checking the Cumulative TSN Ack field of the
2533 * chunk, that all its outstanding DATA chunks have been
2534 * received by the SHUTDOWN sender.
2536 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2537 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2544 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2545 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2546 * transport addresses (either in the IP addresses or in the INIT chunk)
2547 * that belong to this association, it should discard the INIT chunk and
2548 * retransmit the SHUTDOWN ACK chunk.
2550 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2551 const struct sctp_association *asoc,
2552 const sctp_subtype_t type,
2554 sctp_cmd_seq_t *commands)
2556 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2557 struct sctp_chunk *reply;
2559 /* Make sure that the chunk has a valid length */
2560 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
2561 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2564 /* Since we are not going to really process this INIT, there
2565 * is no point in verifying chunk boundries. Just generate
2568 reply = sctp_make_shutdown_ack(asoc, chunk);
2572 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2573 * the T2-SHUTDOWN timer.
2575 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2577 /* and restart the T2-shutdown timer. */
2578 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2579 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2581 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2583 return SCTP_DISPOSITION_CONSUME;
2585 return SCTP_DISPOSITION_NOMEM;
2589 * sctp_sf_do_ecn_cwr
2591 * Section: Appendix A: Explicit Congestion Notification
2595 * RFC 2481 details a specific bit for a sender to send in the header of
2596 * its next outbound TCP segment to indicate to its peer that it has
2597 * reduced its congestion window. This is termed the CWR bit. For
2598 * SCTP the same indication is made by including the CWR chunk.
2599 * This chunk contains one data element, i.e. the TSN number that
2600 * was sent in the ECNE chunk. This element represents the lowest
2601 * TSN number in the datagram that was originally marked with the
2604 * Verification Tag: 8.5 Verification Tag [Normal verification]
2606 * (endpoint, asoc, chunk)
2609 * (asoc, reply_msg, msg_up, timers, counters)
2611 * The return value is the disposition of the chunk.
2613 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2614 const struct sctp_association *asoc,
2615 const sctp_subtype_t type,
2617 sctp_cmd_seq_t *commands)
2620 struct sctp_chunk *chunk = arg;
2623 if (!sctp_vtag_verify(chunk, asoc))
2624 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2626 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2627 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2630 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2631 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2633 lowest_tsn = ntohl(cwr->lowest_tsn);
2635 /* Does this CWR ack the last sent congestion notification? */
2636 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2637 /* Stop sending ECNE. */
2638 sctp_add_cmd_sf(commands,
2640 SCTP_U32(lowest_tsn));
2642 return SCTP_DISPOSITION_CONSUME;
2648 * Section: Appendix A: Explicit Congestion Notification
2652 * RFC 2481 details a specific bit for a receiver to send back in its
2653 * TCP acknowledgements to notify the sender of the Congestion
2654 * Experienced (CE) bit having arrived from the network. For SCTP this
2655 * same indication is made by including the ECNE chunk. This chunk
2656 * contains one data element, i.e. the lowest TSN associated with the IP
2657 * datagram marked with the CE bit.....
2659 * Verification Tag: 8.5 Verification Tag [Normal verification]
2661 * (endpoint, asoc, chunk)
2664 * (asoc, reply_msg, msg_up, timers, counters)
2666 * The return value is the disposition of the chunk.
2668 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2669 const struct sctp_association *asoc,
2670 const sctp_subtype_t type,
2672 sctp_cmd_seq_t *commands)
2674 sctp_ecnehdr_t *ecne;
2675 struct sctp_chunk *chunk = arg;
2677 if (!sctp_vtag_verify(chunk, asoc))
2678 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2680 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2681 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2684 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2685 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2687 /* If this is a newer ECNE than the last CWR packet we sent out */
2688 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2689 SCTP_U32(ntohl(ecne->lowest_tsn)));
2691 return SCTP_DISPOSITION_CONSUME;
2695 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2697 * The SCTP endpoint MUST always acknowledge the reception of each valid
2700 * The guidelines on delayed acknowledgement algorithm specified in
2701 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2702 * acknowledgement SHOULD be generated for at least every second packet
2703 * (not every second DATA chunk) received, and SHOULD be generated within
2704 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2705 * situations it may be beneficial for an SCTP transmitter to be more
2706 * conservative than the algorithms detailed in this document allow.
2707 * However, an SCTP transmitter MUST NOT be more aggressive than the
2708 * following algorithms allow.
2710 * A SCTP receiver MUST NOT generate more than one SACK for every
2711 * incoming packet, other than to update the offered window as the
2712 * receiving application consumes new data.
2714 * Verification Tag: 8.5 Verification Tag [Normal verification]
2717 * (endpoint, asoc, chunk)
2720 * (asoc, reply_msg, msg_up, timers, counters)
2722 * The return value is the disposition of the chunk.
2724 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2725 const struct sctp_association *asoc,
2726 const sctp_subtype_t type,
2728 sctp_cmd_seq_t *commands)
2730 struct sctp_chunk *chunk = arg;
2733 if (!sctp_vtag_verify(chunk, asoc)) {
2734 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2736 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2739 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2740 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2743 error = sctp_eat_data(asoc, chunk, commands );
2745 case SCTP_IERROR_NO_ERROR:
2747 case SCTP_IERROR_HIGH_TSN:
2748 case SCTP_IERROR_BAD_STREAM:
2749 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2750 goto discard_noforce;
2751 case SCTP_IERROR_DUP_TSN:
2752 case SCTP_IERROR_IGNORE_TSN:
2753 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2755 case SCTP_IERROR_NO_DATA:
2761 if (asoc->autoclose) {
2762 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2763 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2766 /* If this is the last chunk in a packet, we need to count it
2767 * toward sack generation. Note that we need to SACK every
2768 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2769 * THEM. We elect to NOT generate SACK's if the chunk fails
2770 * the verification tag test.
2772 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2774 * The SCTP endpoint MUST always acknowledge the reception of
2775 * each valid DATA chunk.
2777 * The guidelines on delayed acknowledgement algorithm
2778 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2779 * Specifically, an acknowledgement SHOULD be generated for at
2780 * least every second packet (not every second DATA chunk)
2781 * received, and SHOULD be generated within 200 ms of the
2782 * arrival of any unacknowledged DATA chunk. In some
2783 * situations it may be beneficial for an SCTP transmitter to
2784 * be more conservative than the algorithms detailed in this
2785 * document allow. However, an SCTP transmitter MUST NOT be
2786 * more aggressive than the following algorithms allow.
2788 if (chunk->end_of_packet)
2789 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2791 return SCTP_DISPOSITION_CONSUME;
2794 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2796 * When a packet arrives with duplicate DATA chunk(s) and with
2797 * no new DATA chunk(s), the endpoint MUST immediately send a
2798 * SACK with no delay. If a packet arrives with duplicate
2799 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2800 * MAY immediately send a SACK. Normally receipt of duplicate
2801 * DATA chunks will occur when the original SACK chunk was lost
2802 * and the peer's RTO has expired. The duplicate TSN number(s)
2803 * SHOULD be reported in the SACK as duplicate.
2805 /* In our case, we split the MAY SACK advice up whether or not
2806 * the last chunk is a duplicate.'
2808 if (chunk->end_of_packet)
2809 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2810 return SCTP_DISPOSITION_DISCARD;
2813 if (chunk->end_of_packet)
2814 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2816 return SCTP_DISPOSITION_DISCARD;
2818 return SCTP_DISPOSITION_CONSUME;
2823 * sctp_sf_eat_data_fast_4_4
2826 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2827 * DATA chunks without delay.
2829 * Verification Tag: 8.5 Verification Tag [Normal verification]
2831 * (endpoint, asoc, chunk)
2834 * (asoc, reply_msg, msg_up, timers, counters)
2836 * The return value is the disposition of the chunk.
2838 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2839 const struct sctp_association *asoc,
2840 const sctp_subtype_t type,
2842 sctp_cmd_seq_t *commands)
2844 struct sctp_chunk *chunk = arg;
2847 if (!sctp_vtag_verify(chunk, asoc)) {
2848 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2850 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2853 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2854 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2857 error = sctp_eat_data(asoc, chunk, commands );
2859 case SCTP_IERROR_NO_ERROR:
2860 case SCTP_IERROR_HIGH_TSN:
2861 case SCTP_IERROR_DUP_TSN:
2862 case SCTP_IERROR_IGNORE_TSN:
2863 case SCTP_IERROR_BAD_STREAM:
2865 case SCTP_IERROR_NO_DATA:
2871 /* Go a head and force a SACK, since we are shutting down. */
2873 /* Implementor's Guide.
2875 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2876 * respond to each received packet containing one or more DATA chunk(s)
2877 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2879 if (chunk->end_of_packet) {
2880 /* We must delay the chunk creation since the cumulative
2881 * TSN has not been updated yet.
2883 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2884 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2885 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2886 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2890 return SCTP_DISPOSITION_CONSUME;
2894 * Section: 6.2 Processing a Received SACK
2895 * D) Any time a SACK arrives, the endpoint performs the following:
2897 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2898 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2899 * increasing, a SACK whose Cumulative TSN Ack is less than the
2900 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2902 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2903 * of bytes still outstanding after processing the Cumulative TSN Ack
2904 * and the Gap Ack Blocks.
2906 * iii) If the SACK is missing a TSN that was previously
2907 * acknowledged via a Gap Ack Block (e.g., the data receiver
2908 * reneged on the data), then mark the corresponding DATA chunk
2909 * as available for retransmit: Mark it as missing for fast
2910 * retransmit as described in Section 7.2.4 and if no retransmit
2911 * timer is running for the destination address to which the DATA
2912 * chunk was originally transmitted, then T3-rtx is started for
2913 * that destination address.
2915 * Verification Tag: 8.5 Verification Tag [Normal verification]
2918 * (endpoint, asoc, chunk)
2921 * (asoc, reply_msg, msg_up, timers, counters)
2923 * The return value is the disposition of the chunk.
2925 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2926 const struct sctp_association *asoc,
2927 const sctp_subtype_t type,
2929 sctp_cmd_seq_t *commands)
2931 struct sctp_chunk *chunk = arg;
2932 sctp_sackhdr_t *sackh;
2935 if (!sctp_vtag_verify(chunk, asoc))
2936 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2938 /* Make sure that the SACK chunk has a valid length. */
2939 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
2940 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2943 /* Pull the SACK chunk from the data buffer */
2944 sackh = sctp_sm_pull_sack(chunk);
2945 /* Was this a bogus SACK? */
2947 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2948 chunk->subh.sack_hdr = sackh;
2949 ctsn = ntohl(sackh->cum_tsn_ack);
2951 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2952 * Ack Point, then drop the SACK. Since Cumulative TSN
2953 * Ack is monotonically increasing, a SACK whose
2954 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2955 * Point indicates an out-of-order SACK.
2957 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2958 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2959 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2960 return SCTP_DISPOSITION_DISCARD;
2963 /* If Cumulative TSN Ack beyond the max tsn currently
2964 * send, terminating the association and respond to the
2965 * sender with an ABORT.
2967 if (!TSN_lt(ctsn, asoc->next_tsn))
2968 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
2970 /* Return this SACK for further processing. */
2971 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2973 /* Note: We do the rest of the work on the PROCESS_SACK
2976 return SCTP_DISPOSITION_CONSUME;
2980 * Generate an ABORT in response to a packet.
2982 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2984 * 8) The receiver should respond to the sender of the OOTB packet with
2985 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2986 * MUST fill in the Verification Tag field of the outbound packet
2987 * with the value found in the Verification Tag field of the OOTB
2988 * packet and set the T-bit in the Chunk Flags to indicate that the
2989 * Verification Tag is reflected. After sending this ABORT, the
2990 * receiver of the OOTB packet shall discard the OOTB packet and take
2991 * no further action.
2995 * The return value is the disposition of the chunk.
2997 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2998 const struct sctp_association *asoc,
2999 const sctp_subtype_t type,
3001 sctp_cmd_seq_t *commands)
3003 struct sctp_packet *packet = NULL;
3004 struct sctp_chunk *chunk = arg;
3005 struct sctp_chunk *abort;
3007 packet = sctp_ootb_pkt_new(asoc, chunk);
3010 /* Make an ABORT. The T bit will be set if the asoc
3013 abort = sctp_make_abort(asoc, chunk, 0);
3015 sctp_ootb_pkt_free(packet);
3016 return SCTP_DISPOSITION_NOMEM;
3019 /* Reflect vtag if T-Bit is set */
3020 if (sctp_test_T_bit(abort))
3021 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3023 /* Set the skb to the belonging sock for accounting. */
3024 abort->skb->sk = ep->base.sk;
3026 sctp_packet_append_chunk(packet, abort);
3028 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3029 SCTP_PACKET(packet));
3031 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3033 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3034 return SCTP_DISPOSITION_CONSUME;
3037 return SCTP_DISPOSITION_NOMEM;
3041 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3042 * event as ULP notification for each cause included in the chunk.
3044 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3046 * The return value is the disposition of the chunk.
3048 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
3049 const struct sctp_association *asoc,
3050 const sctp_subtype_t type,
3052 sctp_cmd_seq_t *commands)
3054 struct sctp_chunk *chunk = arg;
3055 struct sctp_ulpevent *ev;
3057 if (!sctp_vtag_verify(chunk, asoc))
3058 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3060 /* Make sure that the ERROR chunk has a valid length. */
3061 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
3062 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3065 while (chunk->chunk_end > chunk->skb->data) {
3066 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
3071 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
3072 SCTP_ULPEVENT(ev))) {
3073 sctp_ulpevent_free(ev);
3077 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3080 return SCTP_DISPOSITION_CONSUME;
3083 return SCTP_DISPOSITION_NOMEM;
3087 * Process an inbound SHUTDOWN ACK.
3090 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3091 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3092 * peer, and remove all record of the association.
3094 * The return value is the disposition.
3096 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3097 const struct sctp_association *asoc,
3098 const sctp_subtype_t type,
3100 sctp_cmd_seq_t *commands)
3102 struct sctp_chunk *chunk = arg;
3103 struct sctp_chunk *reply;
3104 struct sctp_ulpevent *ev;
3106 if (!sctp_vtag_verify(chunk, asoc))
3107 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3109 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3110 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3111 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3113 /* 10.2 H) SHUTDOWN COMPLETE notification
3115 * When SCTP completes the shutdown procedures (section 9.2) this
3116 * notification is passed to the upper layer.
3118 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3119 0, 0, 0, NULL, GFP_ATOMIC);
3123 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3124 reply = sctp_make_shutdown_complete(asoc, chunk);
3128 /* Do all the commands now (after allocation), so that we
3129 * have consistent state if memory allocation failes
3131 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3133 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3134 * stop the T2-shutdown timer,
3136 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3137 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3139 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3140 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3142 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3143 SCTP_STATE(SCTP_STATE_CLOSED));
3144 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3145 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3146 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3148 /* ...and remove all record of the association. */
3149 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3150 return SCTP_DISPOSITION_DELETE_TCB;
3153 sctp_ulpevent_free(ev);
3155 return SCTP_DISPOSITION_NOMEM;
3159 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3161 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3162 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3163 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3164 * packet must fill in the Verification Tag field of the outbound
3165 * packet with the Verification Tag received in the SHUTDOWN ACK and
3166 * set the T-bit in the Chunk Flags to indicate that the Verification
3169 * 8) The receiver should respond to the sender of the OOTB packet with
3170 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3171 * MUST fill in the Verification Tag field of the outbound packet
3172 * with the value found in the Verification Tag field of the OOTB
3173 * packet and set the T-bit in the Chunk Flags to indicate that the
3174 * Verification Tag is reflected. After sending this ABORT, the
3175 * receiver of the OOTB packet shall discard the OOTB packet and take
3176 * no further action.
3178 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3179 const struct sctp_association *asoc,
3180 const sctp_subtype_t type,
3182 sctp_cmd_seq_t *commands)
3184 struct sctp_chunk *chunk = arg;
3185 struct sk_buff *skb = chunk->skb;
3186 sctp_chunkhdr_t *ch;
3188 int ootb_shut_ack = 0;
3190 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3192 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3194 /* Report violation if the chunk is less then minimal */
3195 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3196 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3199 /* Now that we know we at least have a chunk header,
3200 * do things that are type appropriate.
3202 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3205 /* RFC 2960, Section 3.3.7
3206 * Moreover, under any circumstances, an endpoint that
3207 * receives an ABORT MUST NOT respond to that ABORT by
3208 * sending an ABORT of its own.
3210 if (SCTP_CID_ABORT == ch->type)
3211 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3213 /* Report violation if chunk len overflows */
3214 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3215 if (ch_end > skb_tail_pointer(skb))
3216 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3219 ch = (sctp_chunkhdr_t *) ch_end;
3220 } while (ch_end < skb_tail_pointer(skb));
3223 return sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3225 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3229 * Handle an "Out of the blue" SHUTDOWN ACK.
3231 * Section: 8.4 5, sctpimpguide 2.41.
3233 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3234 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3235 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3236 * packet must fill in the Verification Tag field of the outbound
3237 * packet with the Verification Tag received in the SHUTDOWN ACK and
3238 * set the T-bit in the Chunk Flags to indicate that the Verification
3242 * (endpoint, asoc, type, arg, commands)
3245 * (sctp_disposition_t)
3247 * The return value is the disposition of the chunk.
3249 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3250 const struct sctp_association *asoc,
3251 const sctp_subtype_t type,
3253 sctp_cmd_seq_t *commands)
3255 struct sctp_packet *packet = NULL;
3256 struct sctp_chunk *chunk = arg;
3257 struct sctp_chunk *shut;
3259 packet = sctp_ootb_pkt_new(asoc, chunk);
3262 /* Make an SHUTDOWN_COMPLETE.
3263 * The T bit will be set if the asoc is NULL.
3265 shut = sctp_make_shutdown_complete(asoc, chunk);
3267 sctp_ootb_pkt_free(packet);
3268 return SCTP_DISPOSITION_NOMEM;
3271 /* Reflect vtag if T-Bit is set */
3272 if (sctp_test_T_bit(shut))
3273 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3275 /* Set the skb to the belonging sock for accounting. */
3276 shut->skb->sk = ep->base.sk;
3278 sctp_packet_append_chunk(packet, shut);
3280 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3281 SCTP_PACKET(packet));
3283 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3285 /* If the chunk length is invalid, we don't want to process
3286 * the reset of the packet.
3288 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3289 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3291 /* We need to discard the rest of the packet to prevent
3292 * potential bomming attacks from additional bundled chunks.
3293 * This is documented in SCTP Threats ID.
3295 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3298 return SCTP_DISPOSITION_NOMEM;
3302 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3304 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3305 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3306 * procedures in section 8.4 SHOULD be followed, in other words it
3307 * should be treated as an Out Of The Blue packet.
3308 * [This means that we do NOT check the Verification Tag on these
3312 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3313 const struct sctp_association *asoc,
3314 const sctp_subtype_t type,
3316 sctp_cmd_seq_t *commands)
3318 struct sctp_chunk *chunk = arg;
3320 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3321 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3322 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3325 /* Although we do have an association in this case, it corresponds
3326 * to a restarted association. So the packet is treated as an OOTB
3327 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3328 * called with a NULL association.
3330 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3333 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3334 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3335 const struct sctp_association *asoc,
3336 const sctp_subtype_t type, void *arg,
3337 sctp_cmd_seq_t *commands)
3339 struct sctp_chunk *chunk = arg;
3340 struct sctp_chunk *asconf_ack = NULL;
3341 struct sctp_paramhdr *err_param = NULL;
3342 sctp_addiphdr_t *hdr;
3343 union sctp_addr_param *addr_param;
3347 if (!sctp_vtag_verify(chunk, asoc)) {
3348 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3350 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3353 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3354 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3355 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3358 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3359 serial = ntohl(hdr->serial);
3361 addr_param = (union sctp_addr_param *)hdr->params;
3362 length = ntohs(addr_param->p.length);
3363 if (length < sizeof(sctp_paramhdr_t))
3364 return sctp_sf_violation_paramlen(ep, asoc, type,
3365 (void *)addr_param, commands);
3367 /* Verify the ASCONF chunk before processing it. */
3368 if (!sctp_verify_asconf(asoc,
3369 (sctp_paramhdr_t *)((void *)addr_param + length),
3370 (void *)chunk->chunk_end,
3372 return sctp_sf_violation_paramlen(ep, asoc, type,
3373 (void *)&err_param, commands);
3375 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3376 * the endpoint stored in a new association variable
3377 * 'Peer-Serial-Number'.
3379 if (serial == asoc->peer.addip_serial + 1) {
3380 /* ADDIP 4.2 C2) If the value found in the serial number is
3381 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3384 asconf_ack = sctp_process_asconf((struct sctp_association *)
3387 return SCTP_DISPOSITION_NOMEM;
3388 } else if (serial == asoc->peer.addip_serial) {
3389 /* ADDIP 4.2 C3) If the value found in the serial number is
3390 * equal to the value stored in the 'Peer-Serial-Number'
3391 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3392 * to save the last ASCONF-ACK for some predetermined period of
3393 * time and instead of re-processing the ASCONF (with the same
3394 * serial number) it may just re-transmit the ASCONF-ACK.
3396 if (asoc->addip_last_asconf_ack)
3397 asconf_ack = asoc->addip_last_asconf_ack;
3399 return SCTP_DISPOSITION_DISCARD;
3401 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3402 * it must be either a stale packet or from an attacker.
3404 return SCTP_DISPOSITION_DISCARD;
3407 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3408 * back to the source address contained in the IP header of the ASCONF
3409 * being responded to.
3411 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3413 return SCTP_DISPOSITION_CONSUME;
3417 * ADDIP Section 4.3 General rules for address manipulation
3418 * When building TLV parameters for the ASCONF Chunk that will add or
3419 * delete IP addresses the D0 to D13 rules should be applied:
3421 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3422 const struct sctp_association *asoc,
3423 const sctp_subtype_t type, void *arg,
3424 sctp_cmd_seq_t *commands)
3426 struct sctp_chunk *asconf_ack = arg;
3427 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3428 struct sctp_chunk *abort;
3429 struct sctp_paramhdr *err_param = NULL;
3430 sctp_addiphdr_t *addip_hdr;
3431 __u32 sent_serial, rcvd_serial;
3433 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3434 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3436 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3439 /* Make sure that the ADDIP chunk has a valid length. */
3440 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3441 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3444 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3445 rcvd_serial = ntohl(addip_hdr->serial);
3447 /* Verify the ASCONF-ACK chunk before processing it. */
3448 if (!sctp_verify_asconf(asoc,
3449 (sctp_paramhdr_t *)addip_hdr->params,
3450 (void *)asconf_ack->chunk_end,
3452 return sctp_sf_violation_paramlen(ep, asoc, type,
3453 (void *)&err_param, commands);
3456 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3457 sent_serial = ntohl(addip_hdr->serial);
3459 sent_serial = asoc->addip_serial - 1;
3462 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3463 * equal to the next serial number to be used but no ASCONF chunk is
3464 * outstanding the endpoint MUST ABORT the association. Note that a
3465 * sequence number is greater than if it is no more than 2^^31-1
3466 * larger than the current sequence number (using serial arithmetic).
3468 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3469 !(asoc->addip_last_asconf)) {
3470 abort = sctp_make_abort(asoc, asconf_ack,
3471 sizeof(sctp_errhdr_t));
3473 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
3474 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3477 /* We are going to ABORT, so we might as well stop
3478 * processing the rest of the chunks in the packet.
3480 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3481 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3482 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3483 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3484 SCTP_ERROR(ECONNABORTED));
3485 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3486 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3487 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3488 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3489 return SCTP_DISPOSITION_ABORT;
3492 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3493 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3494 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3496 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3498 return SCTP_DISPOSITION_CONSUME;
3500 abort = sctp_make_abort(asoc, asconf_ack,
3501 sizeof(sctp_errhdr_t));
3503 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
3504 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3507 /* We are going to ABORT, so we might as well stop
3508 * processing the rest of the chunks in the packet.
3510 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3511 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3512 SCTP_ERROR(ECONNABORTED));
3513 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3514 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3515 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3516 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3517 return SCTP_DISPOSITION_ABORT;
3520 return SCTP_DISPOSITION_DISCARD;
3524 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3526 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3527 * its cumulative TSN point to the value carried in the FORWARD TSN
3528 * chunk, and then MUST further advance its cumulative TSN point locally
3530 * After the above processing, the data receiver MUST stop reporting any
3531 * missing TSNs earlier than or equal to the new cumulative TSN point.
3533 * Verification Tag: 8.5 Verification Tag [Normal verification]
3535 * The return value is the disposition of the chunk.
3537 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3538 const struct sctp_association *asoc,
3539 const sctp_subtype_t type,
3541 sctp_cmd_seq_t *commands)
3543 struct sctp_chunk *chunk = arg;
3544 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3548 if (!sctp_vtag_verify(chunk, asoc)) {
3549 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3551 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3554 /* Make sure that the FORWARD_TSN chunk has valid length. */
3555 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3556 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3559 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3560 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3561 len = ntohs(chunk->chunk_hdr->length);
3562 len -= sizeof(struct sctp_chunkhdr);
3563 skb_pull(chunk->skb, len);
3565 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3566 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3568 /* The TSN is too high--silently discard the chunk and count on it
3569 * getting retransmitted later.
3571 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3572 goto discard_noforce;
3574 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3575 if (len > sizeof(struct sctp_fwdtsn_hdr))
3576 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3579 /* Count this as receiving DATA. */
3580 if (asoc->autoclose) {
3581 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3582 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3585 /* FIXME: For now send a SACK, but DATA processing may
3588 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3590 return SCTP_DISPOSITION_CONSUME;
3593 return SCTP_DISPOSITION_DISCARD;
3596 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3597 const struct sctp_endpoint *ep,
3598 const struct sctp_association *asoc,
3599 const sctp_subtype_t type,
3601 sctp_cmd_seq_t *commands)
3603 struct sctp_chunk *chunk = arg;
3604 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3608 if (!sctp_vtag_verify(chunk, asoc)) {
3609 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3611 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3614 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3615 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3616 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3619 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3620 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3621 len = ntohs(chunk->chunk_hdr->length);
3622 len -= sizeof(struct sctp_chunkhdr);
3623 skb_pull(chunk->skb, len);
3625 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3626 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3628 /* The TSN is too high--silently discard the chunk and count on it
3629 * getting retransmitted later.
3631 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3634 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3635 if (len > sizeof(struct sctp_fwdtsn_hdr))
3636 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3639 /* Go a head and force a SACK, since we are shutting down. */
3641 /* Implementor's Guide.
3643 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3644 * respond to each received packet containing one or more DATA chunk(s)
3645 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3647 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3648 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3649 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3650 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3652 return SCTP_DISPOSITION_CONSUME;
3656 * Process an unknown chunk.
3658 * Section: 3.2. Also, 2.1 in the implementor's guide.
3660 * Chunk Types are encoded such that the highest-order two bits specify
3661 * the action that must be taken if the processing endpoint does not
3662 * recognize the Chunk Type.
3664 * 00 - Stop processing this SCTP packet and discard it, do not process
3665 * any further chunks within it.
3667 * 01 - Stop processing this SCTP packet and discard it, do not process
3668 * any further chunks within it, and report the unrecognized
3669 * chunk in an 'Unrecognized Chunk Type'.
3671 * 10 - Skip this chunk and continue processing.
3673 * 11 - Skip this chunk and continue processing, but report in an ERROR
3674 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3676 * The return value is the disposition of the chunk.
3678 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3679 const struct sctp_association *asoc,
3680 const sctp_subtype_t type,
3682 sctp_cmd_seq_t *commands)
3684 struct sctp_chunk *unk_chunk = arg;
3685 struct sctp_chunk *err_chunk;
3686 sctp_chunkhdr_t *hdr;
3688 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3690 if (!sctp_vtag_verify(unk_chunk, asoc))
3691 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3693 /* Make sure that the chunk has a valid length.
3694 * Since we don't know the chunk type, we use a general
3695 * chunkhdr structure to make a comparison.
3697 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3698 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3701 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3702 case SCTP_CID_ACTION_DISCARD:
3703 /* Discard the packet. */
3704 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3706 case SCTP_CID_ACTION_DISCARD_ERR:
3707 /* Discard the packet. */
3708 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3710 /* Generate an ERROR chunk as response. */
3711 hdr = unk_chunk->chunk_hdr;
3712 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3713 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3714 WORD_ROUND(ntohs(hdr->length)));
3716 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3717 SCTP_CHUNK(err_chunk));
3719 return SCTP_DISPOSITION_CONSUME;
3721 case SCTP_CID_ACTION_SKIP:
3722 /* Skip the chunk. */
3723 return SCTP_DISPOSITION_DISCARD;
3725 case SCTP_CID_ACTION_SKIP_ERR:
3726 /* Generate an ERROR chunk as response. */
3727 hdr = unk_chunk->chunk_hdr;
3728 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3729 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3730 WORD_ROUND(ntohs(hdr->length)));
3732 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3733 SCTP_CHUNK(err_chunk));
3735 /* Skip the chunk. */
3736 return SCTP_DISPOSITION_CONSUME;
3742 return SCTP_DISPOSITION_DISCARD;
3746 * Discard the chunk.
3748 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3749 * [Too numerous to mention...]
3750 * Verification Tag: No verification needed.
3752 * (endpoint, asoc, chunk)
3755 * (asoc, reply_msg, msg_up, timers, counters)
3757 * The return value is the disposition of the chunk.
3759 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3760 const struct sctp_association *asoc,
3761 const sctp_subtype_t type,
3763 sctp_cmd_seq_t *commands)
3765 struct sctp_chunk *chunk = arg;
3767 /* Make sure that the chunk has a valid length.
3768 * Since we don't know the chunk type, we use a general
3769 * chunkhdr structure to make a comparison.
3771 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3772 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3775 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3776 return SCTP_DISPOSITION_DISCARD;
3780 * Discard the whole packet.
3784 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3785 * silently discard the OOTB packet and take no further action.
3787 * Verification Tag: No verification necessary
3790 * (endpoint, asoc, chunk)
3793 * (asoc, reply_msg, msg_up, timers, counters)
3795 * The return value is the disposition of the chunk.
3797 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3798 const struct sctp_association *asoc,
3799 const sctp_subtype_t type,
3801 sctp_cmd_seq_t *commands)
3803 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
3804 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3806 return SCTP_DISPOSITION_CONSUME;
3811 * The other end is violating protocol.
3813 * Section: Not specified
3814 * Verification Tag: Not specified
3816 * (endpoint, asoc, chunk)
3819 * (asoc, reply_msg, msg_up, timers, counters)
3821 * We simply tag the chunk as a violation. The state machine will log
3822 * the violation and continue.
3824 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3825 const struct sctp_association *asoc,
3826 const sctp_subtype_t type,
3828 sctp_cmd_seq_t *commands)
3830 struct sctp_chunk *chunk = arg;
3832 /* Make sure that the chunk has a valid length. */
3833 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3834 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3837 return SCTP_DISPOSITION_VIOLATION;
3841 * Common function to handle a protocol violation.
3843 static sctp_disposition_t sctp_sf_abort_violation(
3844 const struct sctp_endpoint *ep,
3845 const struct sctp_association *asoc,
3847 sctp_cmd_seq_t *commands,
3848 const __u8 *payload,
3849 const size_t paylen)
3851 struct sctp_packet *packet = NULL;
3852 struct sctp_chunk *chunk = arg;
3853 struct sctp_chunk *abort = NULL;
3855 /* Make the abort chunk. */
3856 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
3861 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3862 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3864 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
3865 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3866 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3867 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3868 SCTP_ERROR(ECONNREFUSED));
3869 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3870 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
3872 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3873 SCTP_ERROR(ECONNABORTED));
3874 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3875 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
3876 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3879 packet = sctp_ootb_pkt_new(asoc, chunk);
3884 if (sctp_test_T_bit(abort))
3885 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3887 abort->skb->sk = ep->base.sk;
3889 sctp_packet_append_chunk(packet, abort);
3891 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3892 SCTP_PACKET(packet));
3894 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3897 sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
3899 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3901 return SCTP_DISPOSITION_ABORT;
3904 sctp_chunk_free(abort);
3906 return SCTP_DISPOSITION_NOMEM;
3910 * Handle a protocol violation when the chunk length is invalid.
3911 * "Invalid" length is identified as smaller then the minimal length a
3912 * given chunk can be. For example, a SACK chunk has invalid length
3913 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3915 * We inform the other end by sending an ABORT with a Protocol Violation
3918 * Section: Not specified
3919 * Verification Tag: Nothing to do
3921 * (endpoint, asoc, chunk)
3924 * (reply_msg, msg_up, counters)
3926 * Generate an ABORT chunk and terminate the association.
3928 static sctp_disposition_t sctp_sf_violation_chunklen(
3929 const struct sctp_endpoint *ep,
3930 const struct sctp_association *asoc,
3931 const sctp_subtype_t type,
3933 sctp_cmd_seq_t *commands)
3935 char err_str[]="The following chunk had invalid length:";
3937 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
3942 * Handle a protocol violation when the parameter length is invalid.
3943 * "Invalid" length is identified as smaller then the minimal length a
3944 * given parameter can be.
3946 static sctp_disposition_t sctp_sf_violation_paramlen(
3947 const struct sctp_endpoint *ep,
3948 const struct sctp_association *asoc,
3949 const sctp_subtype_t type,
3951 sctp_cmd_seq_t *commands) {
3952 char err_str[] = "The following parameter had invalid length:";
3954 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
3958 /* Handle a protocol violation when the peer trying to advance the
3959 * cumulative tsn ack to a point beyond the max tsn currently sent.
3961 * We inform the other end by sending an ABORT with a Protocol Violation
3964 static sctp_disposition_t sctp_sf_violation_ctsn(
3965 const struct sctp_endpoint *ep,
3966 const struct sctp_association *asoc,
3967 const sctp_subtype_t type,
3969 sctp_cmd_seq_t *commands)
3971 char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:";
3973 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
3977 /* Handle protocol violation of an invalid chunk bundling. For example,
3978 * when we have an association and we recieve bundled INIT-ACK, or
3979 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
3980 * statement from the specs. Additinally, there might be an attacker
3981 * on the path and we may not want to continue this communication.
3983 static sctp_disposition_t sctp_sf_violation_chunk(
3984 const struct sctp_endpoint *ep,
3985 const struct sctp_association *asoc,
3986 const sctp_subtype_t type,
3988 sctp_cmd_seq_t *commands)
3990 char err_str[]="The following chunk violates protocol:";
3993 return sctp_sf_violation(ep, asoc, type, arg, commands);
3995 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
3998 /***************************************************************************
3999 * These are the state functions for handling primitive (Section 10) events.
4000 ***************************************************************************/
4002 * sctp_sf_do_prm_asoc
4004 * Section: 10.1 ULP-to-SCTP
4007 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4008 * outbound stream count)
4009 * -> association id [,destination transport addr list] [,outbound stream
4012 * This primitive allows the upper layer to initiate an association to a
4013 * specific peer endpoint.
4015 * The peer endpoint shall be specified by one of the transport addresses
4016 * which defines the endpoint (see Section 1.4). If the local SCTP
4017 * instance has not been initialized, the ASSOCIATE is considered an
4019 * [This is not relevant for the kernel implementation since we do all
4020 * initialization at boot time. It we hadn't initialized we wouldn't
4021 * get anywhere near this code.]
4023 * An association id, which is a local handle to the SCTP association,
4024 * will be returned on successful establishment of the association. If
4025 * SCTP is not able to open an SCTP association with the peer endpoint,
4026 * an error is returned.
4027 * [In the kernel implementation, the struct sctp_association needs to
4028 * be created BEFORE causing this primitive to run.]
4030 * Other association parameters may be returned, including the
4031 * complete destination transport addresses of the peer as well as the
4032 * outbound stream count of the local endpoint. One of the transport
4033 * address from the returned destination addresses will be selected by
4034 * the local endpoint as default primary path for sending SCTP packets
4035 * to this peer. The returned "destination transport addr list" can
4036 * be used by the ULP to change the default primary path or to force
4037 * sending a packet to a specific transport address. [All of this
4038 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4041 * Mandatory attributes:
4043 * o local SCTP instance name - obtained from the INITIALIZE operation.
4044 * [This is the argument asoc.]
4045 * o destination transport addr - specified as one of the transport
4046 * addresses of the peer endpoint with which the association is to be
4048 * [This is asoc->peer.active_path.]
4049 * o outbound stream count - the number of outbound streams the ULP
4050 * would like to open towards this peer endpoint.
4051 * [BUG: This is not currently implemented.]
4052 * Optional attributes:
4056 * The return value is a disposition.
4058 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
4059 const struct sctp_association *asoc,
4060 const sctp_subtype_t type,
4062 sctp_cmd_seq_t *commands)
4064 struct sctp_chunk *repl;
4066 /* The comment below says that we enter COOKIE-WAIT AFTER
4067 * sending the INIT, but that doesn't actually work in our
4070 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4071 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4073 /* RFC 2960 5.1 Normal Establishment of an Association
4075 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4076 * must provide its Verification Tag (Tag_A) in the Initiate
4077 * Tag field. Tag_A SHOULD be a random number in the range of
4078 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4081 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4085 /* Cast away the const modifier, as we want to just
4086 * rerun it through as a sideffect.
4088 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
4089 SCTP_ASOC((struct sctp_association *) asoc));
4091 /* Choose transport for INIT. */
4092 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4095 /* After sending the INIT, "A" starts the T1-init timer and
4096 * enters the COOKIE-WAIT state.
4098 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4099 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4100 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4101 return SCTP_DISPOSITION_CONSUME;
4104 return SCTP_DISPOSITION_NOMEM;
4108 * Process the SEND primitive.
4110 * Section: 10.1 ULP-to-SCTP
4113 * Format: SEND(association id, buffer address, byte count [,context]
4114 * [,stream id] [,life time] [,destination transport address]
4115 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4118 * This is the main method to send user data via SCTP.
4120 * Mandatory attributes:
4122 * o association id - local handle to the SCTP association
4124 * o buffer address - the location where the user message to be
4125 * transmitted is stored;
4127 * o byte count - The size of the user data in number of bytes;
4129 * Optional attributes:
4131 * o context - an optional 32 bit integer that will be carried in the
4132 * sending failure notification to the ULP if the transportation of
4133 * this User Message fails.
4135 * o stream id - to indicate which stream to send the data on. If not
4136 * specified, stream 0 will be used.
4138 * o life time - specifies the life time of the user data. The user data
4139 * will not be sent by SCTP after the life time expires. This
4140 * parameter can be used to avoid efforts to transmit stale
4141 * user messages. SCTP notifies the ULP if the data cannot be
4142 * initiated to transport (i.e. sent to the destination via SCTP's
4143 * send primitive) within the life time variable. However, the
4144 * user data will be transmitted if SCTP has attempted to transmit a
4145 * chunk before the life time expired.
4147 * o destination transport address - specified as one of the destination
4148 * transport addresses of the peer endpoint to which this packet
4149 * should be sent. Whenever possible, SCTP should use this destination
4150 * transport address for sending the packets, instead of the current
4153 * o unorder flag - this flag, if present, indicates that the user
4154 * would like the data delivered in an unordered fashion to the peer
4155 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4158 * o no-bundle flag - instructs SCTP not to bundle this user data with
4159 * other outbound DATA chunks. SCTP MAY still bundle even when
4160 * this flag is present, when faced with network congestion.
4162 * o payload protocol-id - A 32 bit unsigned integer that is to be
4163 * passed to the peer indicating the type of payload protocol data
4164 * being transmitted. This value is passed as opaque data by SCTP.
4166 * The return value is the disposition.
4168 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
4169 const struct sctp_association *asoc,
4170 const sctp_subtype_t type,
4172 sctp_cmd_seq_t *commands)
4174 struct sctp_chunk *chunk = arg;
4176 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4177 return SCTP_DISPOSITION_CONSUME;
4181 * Process the SHUTDOWN primitive.
4186 * Format: SHUTDOWN(association id)
4189 * Gracefully closes an association. Any locally queued user data
4190 * will be delivered to the peer. The association will be terminated only
4191 * after the peer acknowledges all the SCTP packets sent. A success code
4192 * will be returned on successful termination of the association. If
4193 * attempting to terminate the association results in a failure, an error
4194 * code shall be returned.
4196 * Mandatory attributes:
4198 * o association id - local handle to the SCTP association
4200 * Optional attributes:
4204 * The return value is the disposition.
4206 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
4207 const struct sctp_endpoint *ep,
4208 const struct sctp_association *asoc,
4209 const sctp_subtype_t type,
4211 sctp_cmd_seq_t *commands)
4215 /* From 9.2 Shutdown of an Association
4216 * Upon receipt of the SHUTDOWN primitive from its upper
4217 * layer, the endpoint enters SHUTDOWN-PENDING state and
4218 * remains there until all outstanding data has been
4219 * acknowledged by its peer. The endpoint accepts no new data
4220 * from its upper layer, but retransmits data to the far end
4221 * if necessary to fill gaps.
4223 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4224 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4226 /* sctpimpguide-05 Section 2.12.2
4227 * The sender of the SHUTDOWN MAY also start an overall guard timer
4228 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4230 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4231 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4233 disposition = SCTP_DISPOSITION_CONSUME;
4234 if (sctp_outq_is_empty(&asoc->outqueue)) {
4235 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4242 * Process the ABORT primitive.
4247 * Format: Abort(association id [, cause code])
4250 * Ungracefully closes an association. Any locally queued user data
4251 * will be discarded and an ABORT chunk is sent to the peer. A success code
4252 * will be returned on successful abortion of the association. If
4253 * attempting to abort the association results in a failure, an error
4254 * code shall be returned.
4256 * Mandatory attributes:
4258 * o association id - local handle to the SCTP association
4260 * Optional attributes:
4262 * o cause code - reason of the abort to be passed to the peer
4266 * The return value is the disposition.
4268 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4269 const struct sctp_endpoint *ep,
4270 const struct sctp_association *asoc,
4271 const sctp_subtype_t type,
4273 sctp_cmd_seq_t *commands)
4275 /* From 9.1 Abort of an Association
4276 * Upon receipt of the ABORT primitive from its upper
4277 * layer, the endpoint enters CLOSED state and
4278 * discard all outstanding data has been
4279 * acknowledged by its peer. The endpoint accepts no new data
4280 * from its upper layer, but retransmits data to the far end
4281 * if necessary to fill gaps.
4283 struct sctp_chunk *abort = arg;
4284 sctp_disposition_t retval;
4286 retval = SCTP_DISPOSITION_CONSUME;
4288 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4290 /* Even if we can't send the ABORT due to low memory delete the
4291 * TCB. This is a departure from our typical NOMEM handling.
4294 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4295 SCTP_ERROR(ECONNABORTED));
4296 /* Delete the established association. */
4297 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4298 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4300 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4301 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4306 /* We tried an illegal operation on an association which is closed. */
4307 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4308 const struct sctp_association *asoc,
4309 const sctp_subtype_t type,
4311 sctp_cmd_seq_t *commands)
4313 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4314 return SCTP_DISPOSITION_CONSUME;
4317 /* We tried an illegal operation on an association which is shutting
4320 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4321 const struct sctp_association *asoc,
4322 const sctp_subtype_t type,
4324 sctp_cmd_seq_t *commands)
4326 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4327 SCTP_ERROR(-ESHUTDOWN));
4328 return SCTP_DISPOSITION_CONSUME;
4332 * sctp_cookie_wait_prm_shutdown
4334 * Section: 4 Note: 2
4339 * The RFC does not explicitly address this issue, but is the route through the
4340 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4345 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4346 const struct sctp_endpoint *ep,
4347 const struct sctp_association *asoc,
4348 const sctp_subtype_t type,
4350 sctp_cmd_seq_t *commands)
4352 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4353 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4355 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4356 SCTP_STATE(SCTP_STATE_CLOSED));
4358 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4360 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4362 return SCTP_DISPOSITION_DELETE_TCB;
4366 * sctp_cookie_echoed_prm_shutdown
4368 * Section: 4 Note: 2
4373 * The RFC does not explcitly address this issue, but is the route through the
4374 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4379 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4380 const struct sctp_endpoint *ep,
4381 const struct sctp_association *asoc,
4382 const sctp_subtype_t type,
4383 void *arg, sctp_cmd_seq_t *commands)
4385 /* There is a single T1 timer, so we should be able to use
4386 * common function with the COOKIE-WAIT state.
4388 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4392 * sctp_sf_cookie_wait_prm_abort
4394 * Section: 4 Note: 2
4399 * The RFC does not explicitly address this issue, but is the route through the
4400 * state table when someone issues an abort while in COOKIE_WAIT state.
4405 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4406 const struct sctp_endpoint *ep,
4407 const struct sctp_association *asoc,
4408 const sctp_subtype_t type,
4410 sctp_cmd_seq_t *commands)
4412 struct sctp_chunk *abort = arg;
4413 sctp_disposition_t retval;
4415 /* Stop T1-init timer */
4416 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4417 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4418 retval = SCTP_DISPOSITION_CONSUME;
4420 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4422 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4423 SCTP_STATE(SCTP_STATE_CLOSED));
4425 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4427 /* Even if we can't send the ABORT due to low memory delete the
4428 * TCB. This is a departure from our typical NOMEM handling.
4431 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4432 SCTP_ERROR(ECONNREFUSED));
4433 /* Delete the established association. */
4434 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4435 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4441 * sctp_sf_cookie_echoed_prm_abort
4443 * Section: 4 Note: 3
4448 * The RFC does not explcitly address this issue, but is the route through the
4449 * state table when someone issues an abort while in COOKIE_ECHOED state.
4454 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4455 const struct sctp_endpoint *ep,
4456 const struct sctp_association *asoc,
4457 const sctp_subtype_t type,
4459 sctp_cmd_seq_t *commands)
4461 /* There is a single T1 timer, so we should be able to use
4462 * common function with the COOKIE-WAIT state.
4464 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4468 * sctp_sf_shutdown_pending_prm_abort
4473 * The RFC does not explicitly address this issue, but is the route through the
4474 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4479 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4480 const struct sctp_endpoint *ep,
4481 const struct sctp_association *asoc,
4482 const sctp_subtype_t type,
4484 sctp_cmd_seq_t *commands)
4486 /* Stop the T5-shutdown guard timer. */
4487 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4488 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4490 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4494 * sctp_sf_shutdown_sent_prm_abort
4499 * The RFC does not explicitly address this issue, but is the route through the
4500 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4505 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4506 const struct sctp_endpoint *ep,
4507 const struct sctp_association *asoc,
4508 const sctp_subtype_t type,
4510 sctp_cmd_seq_t *commands)
4512 /* Stop the T2-shutdown timer. */
4513 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4514 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4516 /* Stop the T5-shutdown guard timer. */
4517 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4518 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4520 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4524 * sctp_sf_cookie_echoed_prm_abort
4529 * The RFC does not explcitly address this issue, but is the route through the
4530 * state table when someone issues an abort while in COOKIE_ECHOED state.
4535 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4536 const struct sctp_endpoint *ep,
4537 const struct sctp_association *asoc,
4538 const sctp_subtype_t type,
4540 sctp_cmd_seq_t *commands)
4542 /* The same T2 timer, so we should be able to use
4543 * common function with the SHUTDOWN-SENT state.
4545 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4549 * Process the REQUESTHEARTBEAT primitive
4552 * J) Request Heartbeat
4554 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4558 * Instructs the local endpoint to perform a HeartBeat on the specified
4559 * destination transport address of the given association. The returned
4560 * result should indicate whether the transmission of the HEARTBEAT
4561 * chunk to the destination address is successful.
4563 * Mandatory attributes:
4565 * o association id - local handle to the SCTP association
4567 * o destination transport address - the transport address of the
4568 * association on which a heartbeat should be issued.
4570 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4571 const struct sctp_endpoint *ep,
4572 const struct sctp_association *asoc,
4573 const sctp_subtype_t type,
4575 sctp_cmd_seq_t *commands)
4577 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
4578 (struct sctp_transport *)arg, commands))
4579 return SCTP_DISPOSITION_NOMEM;
4582 * RFC 2960 (bis), section 8.3
4584 * D) Request an on-demand HEARTBEAT on a specific destination
4585 * transport address of a given association.
4587 * The endpoint should increment the respective error counter of
4588 * the destination transport address each time a HEARTBEAT is sent
4589 * to that address and not acknowledged within one RTO.
4592 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
4593 SCTP_TRANSPORT(arg));
4594 return SCTP_DISPOSITION_CONSUME;
4598 * ADDIP Section 4.1 ASCONF Chunk Procedures
4599 * When an endpoint has an ASCONF signaled change to be sent to the
4600 * remote endpoint it should do A1 to A9
4602 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4603 const struct sctp_association *asoc,
4604 const sctp_subtype_t type,
4606 sctp_cmd_seq_t *commands)
4608 struct sctp_chunk *chunk = arg;
4610 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4611 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4612 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4613 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4614 return SCTP_DISPOSITION_CONSUME;
4618 * Ignore the primitive event
4620 * The return value is the disposition of the primitive.
4622 sctp_disposition_t sctp_sf_ignore_primitive(
4623 const struct sctp_endpoint *ep,
4624 const struct sctp_association *asoc,
4625 const sctp_subtype_t type,
4627 sctp_cmd_seq_t *commands)
4629 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4630 return SCTP_DISPOSITION_DISCARD;
4633 /***************************************************************************
4634 * These are the state functions for the OTHER events.
4635 ***************************************************************************/
4638 * Start the shutdown negotiation.
4641 * Once all its outstanding data has been acknowledged, the endpoint
4642 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4643 * TSN Ack field the last sequential TSN it has received from the peer.
4644 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4645 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4646 * with the updated last sequential TSN received from its peer.
4648 * The return value is the disposition.
4650 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4651 const struct sctp_endpoint *ep,
4652 const struct sctp_association *asoc,
4653 const sctp_subtype_t type,
4655 sctp_cmd_seq_t *commands)
4657 struct sctp_chunk *reply;
4659 /* Once all its outstanding data has been acknowledged, the
4660 * endpoint shall send a SHUTDOWN chunk to its peer including
4661 * in the Cumulative TSN Ack field the last sequential TSN it
4662 * has received from the peer.
4664 reply = sctp_make_shutdown(asoc, NULL);
4668 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4669 * T2-shutdown timer.
4671 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4673 /* It shall then start the T2-shutdown timer */
4674 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4675 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4677 if (asoc->autoclose)
4678 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4679 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4681 /* and enter the SHUTDOWN-SENT state. */
4682 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4683 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4685 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4687 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4690 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4692 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4694 return SCTP_DISPOSITION_CONSUME;
4697 return SCTP_DISPOSITION_NOMEM;
4701 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4705 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4706 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4707 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4708 * endpoint must re-send the SHUTDOWN ACK.
4710 * The return value is the disposition.
4712 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4713 const struct sctp_endpoint *ep,
4714 const struct sctp_association *asoc,
4715 const sctp_subtype_t type,
4717 sctp_cmd_seq_t *commands)
4719 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4720 struct sctp_chunk *reply;
4722 /* There are 2 ways of getting here:
4723 * 1) called in response to a SHUTDOWN chunk
4724 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4726 * For the case (2), the arg parameter is set to NULL. We need
4727 * to check that we have a chunk before accessing it's fields.
4730 if (!sctp_vtag_verify(chunk, asoc))
4731 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4733 /* Make sure that the SHUTDOWN chunk has a valid length. */
4734 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
4735 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4739 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4740 * shall send a SHUTDOWN ACK ...
4742 reply = sctp_make_shutdown_ack(asoc, chunk);
4746 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4747 * the T2-shutdown timer.
4749 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4751 /* and start/restart a T2-shutdown timer of its own, */
4752 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4753 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4755 if (asoc->autoclose)
4756 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4757 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4759 /* Enter the SHUTDOWN-ACK-SENT state. */
4760 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4761 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4763 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4765 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4768 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4770 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4772 return SCTP_DISPOSITION_CONSUME;
4775 return SCTP_DISPOSITION_NOMEM;
4779 * Ignore the event defined as other
4781 * The return value is the disposition of the event.
4783 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4784 const struct sctp_association *asoc,
4785 const sctp_subtype_t type,
4787 sctp_cmd_seq_t *commands)
4789 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4790 return SCTP_DISPOSITION_DISCARD;
4793 /************************************************************
4794 * These are the state functions for handling timeout events.
4795 ************************************************************/
4800 * Section: 6.3.3 Handle T3-rtx Expiration
4802 * Whenever the retransmission timer T3-rtx expires for a destination
4803 * address, do the following:
4806 * The return value is the disposition of the chunk.
4808 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
4809 const struct sctp_association *asoc,
4810 const sctp_subtype_t type,
4812 sctp_cmd_seq_t *commands)
4814 struct sctp_transport *transport = arg;
4816 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS);
4818 if (asoc->overall_error_count >= asoc->max_retrans) {
4819 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4820 SCTP_ERROR(ETIMEDOUT));
4821 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4822 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4823 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4824 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4825 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4826 return SCTP_DISPOSITION_DELETE_TCB;
4829 /* E1) For the destination address for which the timer
4830 * expires, adjust its ssthresh with rules defined in Section
4831 * 7.2.3 and set the cwnd <- MTU.
4834 /* E2) For the destination address for which the timer
4835 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4836 * maximum value discussed in rule C7 above (RTO.max) may be
4837 * used to provide an upper bound to this doubling operation.
4840 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4841 * outstanding DATA chunks for the address for which the
4842 * T3-rtx has expired will fit into a single packet, subject
4843 * to the MTU constraint for the path corresponding to the
4844 * destination transport address to which the retransmission
4845 * is being sent (this may be different from the address for
4846 * which the timer expires [see Section 6.4]). Call this
4847 * value K. Bundle and retransmit those K DATA chunks in a
4848 * single packet to the destination endpoint.
4850 * Note: Any DATA chunks that were sent to the address for
4851 * which the T3-rtx timer expired but did not fit in one MTU
4852 * (rule E3 above), should be marked for retransmission and
4853 * sent as soon as cwnd allows (normally when a SACK arrives).
4856 /* Do some failure management (Section 8.2). */
4857 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4859 /* NB: Rules E4 and F1 are implicit in R1. */
4860 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4862 return SCTP_DISPOSITION_CONSUME;
4866 * Generate delayed SACK on timeout
4868 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4870 * The guidelines on delayed acknowledgement algorithm specified in
4871 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4872 * acknowledgement SHOULD be generated for at least every second packet
4873 * (not every second DATA chunk) received, and SHOULD be generated
4874 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4875 * some situations it may be beneficial for an SCTP transmitter to be
4876 * more conservative than the algorithms detailed in this document
4877 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4878 * the following algorithms allow.
4880 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4881 const struct sctp_association *asoc,
4882 const sctp_subtype_t type,
4884 sctp_cmd_seq_t *commands)
4886 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS);
4887 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4888 return SCTP_DISPOSITION_CONSUME;
4892 * sctp_sf_t1_init_timer_expire
4894 * Section: 4 Note: 2
4899 * RFC 2960 Section 4 Notes
4900 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4901 * and re-start the T1-init timer without changing state. This MUST
4902 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4903 * endpoint MUST abort the initialization process and report the
4904 * error to SCTP user.
4910 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
4911 const struct sctp_association *asoc,
4912 const sctp_subtype_t type,
4914 sctp_cmd_seq_t *commands)
4916 struct sctp_chunk *repl = NULL;
4917 struct sctp_bind_addr *bp;
4918 int attempts = asoc->init_err_counter + 1;
4920 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4921 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS);
4923 if (attempts <= asoc->max_init_attempts) {
4924 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4925 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4927 return SCTP_DISPOSITION_NOMEM;
4929 /* Choose transport for INIT. */
4930 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4933 /* Issue a sideeffect to do the needed accounting. */
4934 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4935 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4937 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4939 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4940 " max_init_attempts: %d\n",
4941 attempts, asoc->max_init_attempts);
4942 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4943 SCTP_ERROR(ETIMEDOUT));
4944 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4945 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4946 return SCTP_DISPOSITION_DELETE_TCB;
4949 return SCTP_DISPOSITION_CONSUME;
4953 * sctp_sf_t1_cookie_timer_expire
4955 * Section: 4 Note: 2
4960 * RFC 2960 Section 4 Notes
4961 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4962 * COOKIE ECHO and re-start the T1-cookie timer without changing
4963 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4964 * After that, the endpoint MUST abort the initialization process and
4965 * report the error to SCTP user.
4971 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
4972 const struct sctp_association *asoc,
4973 const sctp_subtype_t type,
4975 sctp_cmd_seq_t *commands)
4977 struct sctp_chunk *repl = NULL;
4978 int attempts = asoc->init_err_counter + 1;
4980 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4981 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS);
4983 if (attempts <= asoc->max_init_attempts) {
4984 repl = sctp_make_cookie_echo(asoc, NULL);
4986 return SCTP_DISPOSITION_NOMEM;
4988 /* Issue a sideeffect to do the needed accounting. */
4989 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
4990 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
4992 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4994 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4995 SCTP_ERROR(ETIMEDOUT));
4996 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4997 SCTP_PERR(SCTP_ERROR_NO_ERROR));
4998 return SCTP_DISPOSITION_DELETE_TCB;
5001 return SCTP_DISPOSITION_CONSUME;
5004 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5005 * with the updated last sequential TSN received from its peer.
5007 * An endpoint should limit the number of retransmissions of the
5008 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5009 * If this threshold is exceeded the endpoint should destroy the TCB and
5010 * MUST report the peer endpoint unreachable to the upper layer (and
5011 * thus the association enters the CLOSED state). The reception of any
5012 * packet from its peer (i.e. as the peer sends all of its queued DATA
5013 * chunks) should clear the endpoint's retransmission count and restart
5014 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5015 * all of its queued DATA chunks that have not yet been sent.
5017 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
5018 const struct sctp_association *asoc,
5019 const sctp_subtype_t type,
5021 sctp_cmd_seq_t *commands)
5023 struct sctp_chunk *reply = NULL;
5025 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5026 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
5028 if (asoc->overall_error_count >= asoc->max_retrans) {
5029 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5030 SCTP_ERROR(ETIMEDOUT));
5031 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5032 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5033 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5034 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5035 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5036 return SCTP_DISPOSITION_DELETE_TCB;
5039 switch (asoc->state) {
5040 case SCTP_STATE_SHUTDOWN_SENT:
5041 reply = sctp_make_shutdown(asoc, NULL);
5044 case SCTP_STATE_SHUTDOWN_ACK_SENT:
5045 reply = sctp_make_shutdown_ack(asoc, NULL);
5056 /* Do some failure management (Section 8.2). */
5057 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
5058 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
5060 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5061 * the T2-shutdown timer.
5063 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5065 /* Restart the T2-shutdown timer. */
5066 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5067 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5068 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5069 return SCTP_DISPOSITION_CONSUME;
5072 return SCTP_DISPOSITION_NOMEM;
5076 * ADDIP Section 4.1 ASCONF CHunk Procedures
5077 * If the T4 RTO timer expires the endpoint should do B1 to B5
5079 sctp_disposition_t sctp_sf_t4_timer_expire(
5080 const struct sctp_endpoint *ep,
5081 const struct sctp_association *asoc,
5082 const sctp_subtype_t type,
5084 sctp_cmd_seq_t *commands)
5086 struct sctp_chunk *chunk = asoc->addip_last_asconf;
5087 struct sctp_transport *transport = chunk->transport;
5089 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS);
5091 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5092 * detection on the appropriate destination address as defined in
5093 * RFC2960 [5] section 8.1 and 8.2.
5095 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5097 /* Reconfig T4 timer and transport. */
5098 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5100 /* ADDIP 4.1 B2) Increment the association error counters and perform
5101 * endpoint failure detection on the association as defined in
5102 * RFC2960 [5] section 8.1 and 8.2.
5103 * association error counter is incremented in SCTP_CMD_STRIKE.
5105 if (asoc->overall_error_count >= asoc->max_retrans) {
5106 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5107 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5108 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5109 SCTP_ERROR(ETIMEDOUT));
5110 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5111 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5112 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5113 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
5114 return SCTP_DISPOSITION_ABORT;
5117 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5118 * the ASCONF chunk was sent by doubling the RTO timer value.
5119 * This is done in SCTP_CMD_STRIKE.
5122 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5123 * choose an alternate destination address (please refer to RFC2960
5124 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5125 * chunk, it MUST be the same (including its serial number) as the last
5128 sctp_chunk_hold(asoc->addip_last_asconf);
5129 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5130 SCTP_CHUNK(asoc->addip_last_asconf));
5132 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5133 * destination is selected, then the RTO used will be that of the new
5134 * destination address.
5136 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5137 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5139 return SCTP_DISPOSITION_CONSUME;
5142 /* sctpimpguide-05 Section 2.12.2
5143 * The sender of the SHUTDOWN MAY also start an overall guard timer
5144 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5145 * At the expiration of this timer the sender SHOULD abort the association
5146 * by sending an ABORT chunk.
5148 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
5149 const struct sctp_association *asoc,
5150 const sctp_subtype_t type,
5152 sctp_cmd_seq_t *commands)
5154 struct sctp_chunk *reply = NULL;
5156 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5157 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
5159 reply = sctp_make_abort(asoc, NULL, 0);
5163 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5164 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5165 SCTP_ERROR(ETIMEDOUT));
5166 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5167 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5169 return SCTP_DISPOSITION_DELETE_TCB;
5171 return SCTP_DISPOSITION_NOMEM;
5174 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5175 * the association is automatically closed by starting the shutdown process.
5176 * The work that needs to be done is same as when SHUTDOWN is initiated by
5177 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5179 sctp_disposition_t sctp_sf_autoclose_timer_expire(
5180 const struct sctp_endpoint *ep,
5181 const struct sctp_association *asoc,
5182 const sctp_subtype_t type,
5184 sctp_cmd_seq_t *commands)
5188 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS);
5190 /* From 9.2 Shutdown of an Association
5191 * Upon receipt of the SHUTDOWN primitive from its upper
5192 * layer, the endpoint enters SHUTDOWN-PENDING state and
5193 * remains there until all outstanding data has been
5194 * acknowledged by its peer. The endpoint accepts no new data
5195 * from its upper layer, but retransmits data to the far end
5196 * if necessary to fill gaps.
5198 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5199 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5201 /* sctpimpguide-05 Section 2.12.2
5202 * The sender of the SHUTDOWN MAY also start an overall guard timer
5203 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5205 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5206 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5207 disposition = SCTP_DISPOSITION_CONSUME;
5208 if (sctp_outq_is_empty(&asoc->outqueue)) {
5209 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
5215 /*****************************************************************************
5216 * These are sa state functions which could apply to all types of events.
5217 ****************************************************************************/
5220 * This table entry is not implemented.
5223 * (endpoint, asoc, chunk)
5225 * The return value is the disposition of the chunk.
5227 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
5228 const struct sctp_association *asoc,
5229 const sctp_subtype_t type,
5231 sctp_cmd_seq_t *commands)
5233 return SCTP_DISPOSITION_NOT_IMPL;
5237 * This table entry represents a bug.
5240 * (endpoint, asoc, chunk)
5242 * The return value is the disposition of the chunk.
5244 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
5245 const struct sctp_association *asoc,
5246 const sctp_subtype_t type,
5248 sctp_cmd_seq_t *commands)
5250 return SCTP_DISPOSITION_BUG;
5254 * This table entry represents the firing of a timer in the wrong state.
5255 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5256 * when the association is in the wrong state. This event should
5257 * be ignored, so as to prevent any rearming of the timer.
5260 * (endpoint, asoc, chunk)
5262 * The return value is the disposition of the chunk.
5264 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
5265 const struct sctp_association *asoc,
5266 const sctp_subtype_t type,
5268 sctp_cmd_seq_t *commands)
5270 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
5271 return SCTP_DISPOSITION_CONSUME;
5274 /********************************************************************
5275 * 2nd Level Abstractions
5276 ********************************************************************/
5278 /* Pull the SACK chunk based on the SACK header. */
5279 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
5281 struct sctp_sackhdr *sack;
5286 /* Protect ourselves from reading too far into
5287 * the skb from a bogus sender.
5289 sack = (struct sctp_sackhdr *) chunk->skb->data;
5291 num_blocks = ntohs(sack->num_gap_ack_blocks);
5292 num_dup_tsns = ntohs(sack->num_dup_tsns);
5293 len = sizeof(struct sctp_sackhdr);
5294 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
5295 if (len > chunk->skb->len)
5298 skb_pull(chunk->skb, len);
5303 /* Create an ABORT packet to be sent as a response, with the specified
5306 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5307 const struct sctp_association *asoc,
5308 struct sctp_chunk *chunk,
5309 const void *payload,
5312 struct sctp_packet *packet;
5313 struct sctp_chunk *abort;
5315 packet = sctp_ootb_pkt_new(asoc, chunk);
5319 * The T bit will be set if the asoc is NULL.
5321 abort = sctp_make_abort(asoc, chunk, paylen);
5323 sctp_ootb_pkt_free(packet);
5327 /* Reflect vtag if T-Bit is set */
5328 if (sctp_test_T_bit(abort))
5329 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5331 /* Add specified error causes, i.e., payload, to the
5334 sctp_addto_chunk(abort, paylen, payload);
5336 /* Set the skb to the belonging sock for accounting. */
5337 abort->skb->sk = ep->base.sk;
5339 sctp_packet_append_chunk(packet, abort);
5346 /* Allocate a packet for responding in the OOTB conditions. */
5347 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5348 const struct sctp_chunk *chunk)
5350 struct sctp_packet *packet;
5351 struct sctp_transport *transport;
5356 /* Get the source and destination port from the inbound packet. */
5357 sport = ntohs(chunk->sctp_hdr->dest);
5358 dport = ntohs(chunk->sctp_hdr->source);
5360 /* The V-tag is going to be the same as the inbound packet if no
5361 * association exists, otherwise, use the peer's vtag.
5364 /* Special case the INIT-ACK as there is no peer's vtag
5367 switch(chunk->chunk_hdr->type) {
5368 case SCTP_CID_INIT_ACK:
5370 sctp_initack_chunk_t *initack;
5372 initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
5373 vtag = ntohl(initack->init_hdr.init_tag);
5377 vtag = asoc->peer.i.init_tag;
5381 /* Special case the INIT and stale COOKIE_ECHO as there is no
5384 switch(chunk->chunk_hdr->type) {
5387 sctp_init_chunk_t *init;
5389 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5390 vtag = ntohl(init->init_hdr.init_tag);
5394 vtag = ntohl(chunk->sctp_hdr->vtag);
5399 /* Make a transport for the bucket, Eliza... */
5400 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5404 /* Cache a route for the transport with the chunk's destination as
5405 * the source address.
5407 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5408 sctp_sk(sctp_get_ctl_sock()));
5410 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5411 packet = sctp_packet_config(packet, vtag, 0);
5419 /* Free the packet allocated earlier for responding in the OOTB condition. */
5420 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5422 sctp_transport_free(packet->transport);
5425 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5426 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5427 const struct sctp_association *asoc,
5428 const struct sctp_chunk *chunk,
5429 sctp_cmd_seq_t *commands,
5430 struct sctp_chunk *err_chunk)
5432 struct sctp_packet *packet;
5435 packet = sctp_ootb_pkt_new(asoc, chunk);
5437 struct sctp_signed_cookie *cookie;
5439 /* Override the OOTB vtag from the cookie. */
5440 cookie = chunk->subh.cookie_hdr;
5441 packet->vtag = cookie->c.peer_vtag;
5443 /* Set the skb to the belonging sock for accounting. */
5444 err_chunk->skb->sk = ep->base.sk;
5445 sctp_packet_append_chunk(packet, err_chunk);
5446 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5447 SCTP_PACKET(packet));
5448 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5450 sctp_chunk_free (err_chunk);
5455 /* Process a data chunk */
5456 static int sctp_eat_data(const struct sctp_association *asoc,
5457 struct sctp_chunk *chunk,
5458 sctp_cmd_seq_t *commands)
5460 sctp_datahdr_t *data_hdr;
5461 struct sctp_chunk *err;
5463 sctp_verb_t deliver;
5466 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5467 struct sock *sk = asoc->base.sk;
5469 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5470 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5472 tsn = ntohl(data_hdr->tsn);
5473 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5475 /* ASSERT: Now skb->data is really the user data. */
5477 /* Process ECN based congestion.
5479 * Since the chunk structure is reused for all chunks within
5480 * a packet, we use ecn_ce_done to track if we've already
5481 * done CE processing for this packet.
5483 * We need to do ECN processing even if we plan to discard the
5487 if (!chunk->ecn_ce_done) {
5489 chunk->ecn_ce_done = 1;
5491 af = sctp_get_af_specific(
5492 ipver2af(ip_hdr(chunk->skb)->version));
5494 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5495 /* Do real work as sideffect. */
5496 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5501 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5503 /* The TSN is too high--silently discard the chunk and
5504 * count on it getting retransmitted later.
5506 return SCTP_IERROR_HIGH_TSN;
5507 } else if (tmp > 0) {
5508 /* This is a duplicate. Record it. */
5509 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5510 return SCTP_IERROR_DUP_TSN;
5513 /* This is a new TSN. */
5515 /* Discard if there is no room in the receive window.
5516 * Actually, allow a little bit of overflow (up to a MTU).
5518 datalen = ntohs(chunk->chunk_hdr->length);
5519 datalen -= sizeof(sctp_data_chunk_t);
5521 deliver = SCTP_CMD_CHUNK_ULP;
5523 /* Think about partial delivery. */
5524 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5526 /* Even if we don't accept this chunk there is
5529 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5532 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5533 * seems a bit troublesome in that frag_point varies based on
5534 * PMTU. In cases, such as loopback, this might be a rather
5537 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
5538 (datalen > asoc->rwnd + asoc->frag_point))) {
5540 /* If this is the next TSN, consider reneging to make
5541 * room. Note: Playing nice with a confused sender. A
5542 * malicious sender can still eat up all our buffer
5543 * space and in the future we may want to detect and
5544 * do more drastic reneging.
5546 if (sctp_tsnmap_has_gap(map) &&
5547 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5548 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5549 deliver = SCTP_CMD_RENEGE;
5551 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5552 "rwnd: %d\n", tsn, datalen,
5554 return SCTP_IERROR_IGNORE_TSN;
5559 * Also try to renege to limit our memory usage in the event that
5560 * we are under memory pressure
5561 * If we can't renege, don't worry about it, the sk_stream_rmem_schedule
5562 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5563 * memory usage too much
5565 if (*sk->sk_prot_creator->memory_pressure) {
5566 if (sctp_tsnmap_has_gap(map) &&
5567 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5568 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn);
5569 deliver = SCTP_CMD_RENEGE;
5574 * Section 3.3.10.9 No User Data (9)
5578 * No User Data: This error cause is returned to the originator of a
5579 * DATA chunk if a received DATA chunk has no user data.
5581 if (unlikely(0 == datalen)) {
5582 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5584 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5587 /* We are going to ABORT, so we might as well stop
5588 * processing the rest of the chunks in the packet.
5590 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5591 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5592 SCTP_ERROR(ECONNABORTED));
5593 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5594 SCTP_PERR(SCTP_ERROR_NO_DATA));
5595 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5596 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5597 return SCTP_IERROR_NO_DATA;
5600 /* If definately accepting the DATA chunk, record its TSN, otherwise
5601 * wait for renege processing.
5603 if (SCTP_CMD_CHUNK_ULP == deliver)
5604 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5606 chunk->data_accepted = 1;
5608 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5609 * if we renege and the chunk arrives again.
5611 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5612 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5614 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5616 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5618 * If an endpoint receive a DATA chunk with an invalid stream
5619 * identifier, it shall acknowledge the reception of the DATA chunk
5620 * following the normal procedure, immediately send an ERROR chunk
5621 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5622 * and discard the DATA chunk.
5624 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5625 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5627 sizeof(data_hdr->stream));
5629 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5631 return SCTP_IERROR_BAD_STREAM;
5634 /* Send the data up to the user. Note: Schedule the
5635 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5636 * chunk needs the updated rwnd.
5638 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5640 return SCTP_IERROR_NO_ERROR;