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 static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
142 const struct sctp_association *asoc,
143 const sctp_subtype_t type,
144 struct sctp_chunk *chunk);
146 /* Small helper function that checks if the chunk length
147 * is of the appropriate length. The 'required_length' argument
148 * is set to be the size of a specific chunk we are testing.
149 * Return Values: 1 = Valid length
154 sctp_chunk_length_valid(struct sctp_chunk *chunk,
155 __u16 required_length)
157 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
159 if (unlikely(chunk_length < required_length))
165 /**********************************************************
166 * These are the state functions for handling chunk events.
167 **********************************************************/
170 * Process the final SHUTDOWN COMPLETE.
172 * Section: 4 (C) (diagram), 9.2
173 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
174 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
175 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
176 * should stop the T2-shutdown timer and remove all knowledge of the
177 * association (and thus the association enters the CLOSED state).
179 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
180 * C) Rules for packet carrying SHUTDOWN COMPLETE:
182 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
183 * if the Verification Tag field of the packet matches its own tag and
184 * the T bit is not set
186 * it is set to its peer's tag and the T bit is set in the Chunk
188 * Otherwise, the receiver MUST silently discard the packet
189 * and take no further action. An endpoint MUST ignore the
190 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
193 * (endpoint, asoc, chunk)
196 * (asoc, reply_msg, msg_up, timers, counters)
198 * The return value is the disposition of the chunk.
200 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
201 const struct sctp_association *asoc,
202 const sctp_subtype_t type,
204 sctp_cmd_seq_t *commands)
206 struct sctp_chunk *chunk = arg;
207 struct sctp_ulpevent *ev;
209 if (!sctp_vtag_verify_either(chunk, asoc))
210 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
212 /* RFC 2960 6.10 Bundling
214 * An endpoint MUST NOT bundle INIT, INIT ACK or
215 * SHUTDOWN COMPLETE with any other chunks.
217 if (!chunk->singleton)
218 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
220 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
221 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
222 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
225 /* RFC 2960 10.2 SCTP-to-ULP
227 * H) SHUTDOWN COMPLETE notification
229 * When SCTP completes the shutdown procedures (section 9.2) this
230 * notification is passed to the upper layer.
232 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
233 0, 0, 0, NULL, GFP_ATOMIC);
235 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
238 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
239 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
240 * not the chunk should be discarded. If the endpoint is in
241 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
242 * T2-shutdown timer and remove all knowledge of the
243 * association (and thus the association enters the CLOSED
246 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
247 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
249 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
250 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
252 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
253 SCTP_STATE(SCTP_STATE_CLOSED));
255 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
256 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
258 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
260 return SCTP_DISPOSITION_DELETE_TCB;
264 * Respond to a normal INIT chunk.
265 * We are the side that is being asked for an association.
267 * Section: 5.1 Normal Establishment of an Association, B
268 * B) "Z" shall respond immediately with an INIT ACK chunk. The
269 * destination IP address of the INIT ACK MUST be set to the source
270 * IP address of the INIT to which this INIT ACK is responding. In
271 * the response, besides filling in other parameters, "Z" must set the
272 * Verification Tag field to Tag_A, and also provide its own
273 * Verification Tag (Tag_Z) in the Initiate Tag field.
275 * Verification Tag: Must be 0.
278 * (endpoint, asoc, chunk)
281 * (asoc, reply_msg, msg_up, timers, counters)
283 * The return value is the disposition of the chunk.
285 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
286 const struct sctp_association *asoc,
287 const sctp_subtype_t type,
289 sctp_cmd_seq_t *commands)
291 struct sctp_chunk *chunk = arg;
292 struct sctp_chunk *repl;
293 struct sctp_association *new_asoc;
294 struct sctp_chunk *err_chunk;
295 struct sctp_packet *packet;
296 sctp_unrecognized_param_t *unk_param;
300 * An endpoint MUST NOT bundle INIT, INIT ACK or
301 * SHUTDOWN COMPLETE with any other chunks.
304 * Furthermore, we require that the receiver of an INIT chunk MUST
305 * enforce these rules by silently discarding an arriving packet
306 * with an INIT chunk that is bundled with other chunks.
308 if (!chunk->singleton)
309 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
311 /* If the packet is an OOTB packet which is temporarily on the
312 * control endpoint, respond with an ABORT.
314 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
315 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
317 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
320 if (chunk->sctp_hdr->vtag != 0)
321 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
323 /* Make sure that the INIT chunk has a valid length.
324 * Normally, this would cause an ABORT with a Protocol Violation
325 * error, but since we don't have an association, we'll
326 * just discard the packet.
328 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
329 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
331 /* Verify the INIT chunk before processing it. */
333 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
334 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
336 /* This chunk contains fatal error. It is to be discarded.
337 * Send an ABORT, with causes if there is any.
340 packet = sctp_abort_pkt_new(ep, asoc, arg,
341 (__u8 *)(err_chunk->chunk_hdr) +
342 sizeof(sctp_chunkhdr_t),
343 ntohs(err_chunk->chunk_hdr->length) -
344 sizeof(sctp_chunkhdr_t));
346 sctp_chunk_free(err_chunk);
349 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
350 SCTP_PACKET(packet));
351 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
352 return SCTP_DISPOSITION_CONSUME;
354 return SCTP_DISPOSITION_NOMEM;
357 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
362 /* Grab the INIT header. */
363 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
365 /* Tag the variable length parameters. */
366 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
368 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
372 /* The call, sctp_process_init(), can fail on memory allocation. */
373 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
375 (sctp_init_chunk_t *)chunk->chunk_hdr,
379 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
381 /* If there are errors need to be reported for unknown parameters,
382 * make sure to reserve enough room in the INIT ACK for them.
386 len = ntohs(err_chunk->chunk_hdr->length) -
387 sizeof(sctp_chunkhdr_t);
389 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
392 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
396 /* If there are errors need to be reported for unknown parameters,
397 * include them in the outgoing INIT ACK as "Unrecognized parameter"
401 /* Get the "Unrecognized parameter" parameter(s) out of the
402 * ERROR chunk generated by sctp_verify_init(). Since the
403 * error cause code for "unknown parameter" and the
404 * "Unrecognized parameter" type is the same, we can
405 * construct the parameters in INIT ACK by copying the
408 unk_param = (sctp_unrecognized_param_t *)
409 ((__u8 *)(err_chunk->chunk_hdr) +
410 sizeof(sctp_chunkhdr_t));
411 /* Replace the cause code with the "Unrecognized parameter"
414 sctp_addto_chunk(repl, len, unk_param);
415 sctp_chunk_free(err_chunk);
418 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
420 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
423 * Note: After sending out INIT ACK with the State Cookie parameter,
424 * "Z" MUST NOT allocate any resources, nor keep any states for the
425 * new association. Otherwise, "Z" will be vulnerable to resource
428 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
430 return SCTP_DISPOSITION_DELETE_TCB;
433 sctp_association_free(new_asoc);
436 sctp_chunk_free(err_chunk);
437 return SCTP_DISPOSITION_NOMEM;
441 * Respond to a normal INIT ACK chunk.
442 * We are the side that is initiating the association.
444 * Section: 5.1 Normal Establishment of an Association, C
445 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
446 * timer and leave COOKIE-WAIT state. "A" shall then send the State
447 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
448 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
450 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
451 * DATA chunks, but it MUST be the first chunk in the packet and
452 * until the COOKIE ACK is returned the sender MUST NOT send any
453 * other packets to the peer.
455 * Verification Tag: 3.3.3
456 * If the value of the Initiate Tag in a received INIT ACK chunk is
457 * found to be 0, the receiver MUST treat it as an error and close the
458 * association by transmitting an ABORT.
461 * (endpoint, asoc, chunk)
464 * (asoc, reply_msg, msg_up, timers, counters)
466 * The return value is the disposition of the chunk.
468 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
469 const struct sctp_association *asoc,
470 const sctp_subtype_t type,
472 sctp_cmd_seq_t *commands)
474 struct sctp_chunk *chunk = arg;
475 sctp_init_chunk_t *initchunk;
476 struct sctp_chunk *err_chunk;
477 struct sctp_packet *packet;
480 if (!sctp_vtag_verify(chunk, asoc))
481 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
484 * An endpoint MUST NOT bundle INIT, INIT ACK or
485 * SHUTDOWN COMPLETE with any other chunks.
487 if (!chunk->singleton)
488 return sctp_sf_violation_chunk(ep, asoc, type, arg, commands);
490 /* Make sure that the INIT-ACK chunk has a valid length */
491 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
492 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
494 /* Grab the INIT header. */
495 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
497 /* Verify the INIT chunk before processing it. */
499 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
500 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
503 /* This chunk contains fatal error. It is to be discarded.
504 * Send an ABORT, with causes if there is any.
507 packet = sctp_abort_pkt_new(ep, asoc, arg,
508 (__u8 *)(err_chunk->chunk_hdr) +
509 sizeof(sctp_chunkhdr_t),
510 ntohs(err_chunk->chunk_hdr->length) -
511 sizeof(sctp_chunkhdr_t));
513 sctp_chunk_free(err_chunk);
516 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
517 SCTP_PACKET(packet));
518 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
519 error = SCTP_ERROR_INV_PARAM;
521 error = SCTP_ERROR_NO_RESOURCE;
524 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
525 error = SCTP_ERROR_INV_PARAM;
528 /* SCTP-AUTH, Section 6.3:
529 * It should be noted that if the receiver wants to tear
530 * down an association in an authenticated way only, the
531 * handling of malformed packets should not result in
532 * tearing down the association.
534 * This means that if we only want to abort associations
535 * in an authenticated way (i.e AUTH+ABORT), then we
536 * can't destory this association just becuase the packet
539 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
540 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
542 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
543 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
544 asoc, chunk->transport);
547 /* Tag the variable length parameters. Note that we never
548 * convert the parameters in an INIT chunk.
550 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
552 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
554 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
555 SCTP_PEER_INIT(initchunk));
557 /* Reset init error count upon receipt of INIT-ACK. */
558 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
560 /* 5.1 C) "A" shall stop the T1-init timer and leave
561 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
562 * timer, and enter the COOKIE-ECHOED state.
564 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
565 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
566 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
567 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
568 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
569 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
571 /* SCTP-AUTH: genereate the assocition shared keys so that
572 * we can potentially signe the COOKIE-ECHO.
574 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
576 /* 5.1 C) "A" shall then send the State Cookie received in the
577 * INIT ACK chunk in a COOKIE ECHO chunk, ...
579 /* If there is any errors to report, send the ERROR chunk generated
580 * for unknown parameters as well.
582 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
583 SCTP_CHUNK(err_chunk));
585 return SCTP_DISPOSITION_CONSUME;
589 * Respond to a normal COOKIE ECHO chunk.
590 * We are the side that is being asked for an association.
592 * Section: 5.1 Normal Establishment of an Association, D
593 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
594 * with a COOKIE ACK chunk after building a TCB and moving to
595 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
596 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
597 * chunk MUST be the first chunk in the packet.
599 * IMPLEMENTATION NOTE: An implementation may choose to send the
600 * Communication Up notification to the SCTP user upon reception
601 * of a valid COOKIE ECHO chunk.
603 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
604 * D) Rules for packet carrying a COOKIE ECHO
606 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
607 * Initial Tag received in the INIT ACK.
609 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
612 * (endpoint, asoc, chunk)
615 * (asoc, reply_msg, msg_up, timers, counters)
617 * The return value is the disposition of the chunk.
619 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
620 const struct sctp_association *asoc,
621 const sctp_subtype_t type, void *arg,
622 sctp_cmd_seq_t *commands)
624 struct sctp_chunk *chunk = arg;
625 struct sctp_association *new_asoc;
626 sctp_init_chunk_t *peer_init;
627 struct sctp_chunk *repl;
628 struct sctp_ulpevent *ev, *ai_ev = NULL;
630 struct sctp_chunk *err_chk_p;
633 /* If the packet is an OOTB packet which is temporarily on the
634 * control endpoint, respond with an ABORT.
636 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
637 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
639 /* Make sure that the COOKIE_ECHO chunk has a valid length.
640 * In this case, we check that we have enough for at least a
641 * chunk header. More detailed verification is done
642 * in sctp_unpack_cookie().
644 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
645 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
647 /* If the endpoint is not listening or if the number of associations
648 * on the TCP-style socket exceed the max backlog, respond with an
652 if (!sctp_sstate(sk, LISTENING) ||
653 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
654 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
656 /* "Decode" the chunk. We have no optional parameters so we
659 chunk->subh.cookie_hdr =
660 (struct sctp_signed_cookie *)chunk->skb->data;
661 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
662 sizeof(sctp_chunkhdr_t)))
665 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
666 * "Z" will reply with a COOKIE ACK chunk after building a TCB
667 * and moving to the ESTABLISHED state.
669 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
673 * If the re-build failed, what is the proper error path
676 * [We should abort the association. --piggy]
679 /* FIXME: Several errors are possible. A bad cookie should
680 * be silently discarded, but think about logging it too.
683 case -SCTP_IERROR_NOMEM:
686 case -SCTP_IERROR_STALE_COOKIE:
687 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
689 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
691 case -SCTP_IERROR_BAD_SIG:
693 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
698 /* Delay state machine commands until later.
700 * Re-build the bind address for the association is done in
701 * the sctp_unpack_cookie() already.
703 /* This is a brand-new association, so these are not yet side
704 * effects--it is safe to run them here.
706 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
708 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
709 &chunk->subh.cookie_hdr->c.peer_addr,
710 peer_init, GFP_ATOMIC))
713 /* SCTP-AUTH: Now that we've populate required fields in
714 * sctp_process_init, set up the assocaition shared keys as
715 * necessary so that we can potentially authenticate the ACK
717 error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
721 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
722 * is supposed to be authenticated and we have to do delayed
723 * authentication. We've just recreated the association using
724 * the information in the cookie and now it's much easier to
725 * do the authentication.
727 if (chunk->auth_chunk) {
728 struct sctp_chunk auth;
731 /* set-up our fake chunk so that we can process it */
732 auth.skb = chunk->auth_chunk;
733 auth.asoc = chunk->asoc;
734 auth.sctp_hdr = chunk->sctp_hdr;
735 auth.chunk_hdr = (sctp_chunkhdr_t *)skb_push(chunk->auth_chunk,
736 sizeof(sctp_chunkhdr_t));
737 skb_pull(chunk->auth_chunk, sizeof(sctp_chunkhdr_t));
738 auth.transport = chunk->transport;
740 ret = sctp_sf_authenticate(ep, new_asoc, type, &auth);
742 /* We can now safely free the auth_chunk clone */
743 kfree_skb(chunk->auth_chunk);
745 if (ret != SCTP_IERROR_NO_ERROR) {
746 sctp_association_free(new_asoc);
747 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
751 repl = sctp_make_cookie_ack(new_asoc, chunk);
755 /* RFC 2960 5.1 Normal Establishment of an Association
757 * D) IMPLEMENTATION NOTE: An implementation may choose to
758 * send the Communication Up notification to the SCTP user
759 * upon reception of a valid COOKIE ECHO chunk.
761 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
762 new_asoc->c.sinit_num_ostreams,
763 new_asoc->c.sinit_max_instreams,
768 /* Sockets API Draft Section 5.3.1.6
769 * When a peer sends a Adaptation Layer Indication parameter , SCTP
770 * delivers this notification to inform the application that of the
771 * peers requested adaptation layer.
773 if (new_asoc->peer.adaptation_ind) {
774 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
780 /* Add all the state machine commands now since we've created
781 * everything. This way we don't introduce memory corruptions
782 * during side-effect processing and correclty count established
785 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
786 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
787 SCTP_STATE(SCTP_STATE_ESTABLISHED));
788 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
789 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
790 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
792 if (new_asoc->autoclose)
793 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
794 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
796 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
798 /* This will send the COOKIE ACK */
799 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
801 /* Queue the ASSOC_CHANGE event */
802 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
804 /* Send up the Adaptation Layer Indication event */
806 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
807 SCTP_ULPEVENT(ai_ev));
809 return SCTP_DISPOSITION_CONSUME;
812 sctp_ulpevent_free(ev);
814 sctp_chunk_free(repl);
816 sctp_association_free(new_asoc);
818 return SCTP_DISPOSITION_NOMEM;
822 * Respond to a normal COOKIE ACK chunk.
823 * We are the side that is being asked for an association.
825 * RFC 2960 5.1 Normal Establishment of an Association
827 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
828 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
829 * timer. It may also notify its ULP about the successful
830 * establishment of the association with a Communication Up
831 * notification (see Section 10).
835 * (endpoint, asoc, chunk)
838 * (asoc, reply_msg, msg_up, timers, counters)
840 * The return value is the disposition of the chunk.
842 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
843 const struct sctp_association *asoc,
844 const sctp_subtype_t type, void *arg,
845 sctp_cmd_seq_t *commands)
847 struct sctp_chunk *chunk = arg;
848 struct sctp_ulpevent *ev;
850 if (!sctp_vtag_verify(chunk, asoc))
851 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
853 /* Verify that the chunk length for the COOKIE-ACK is OK.
854 * If we don't do this, any bundled chunks may be junked.
856 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
857 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
860 /* Reset init error count upon receipt of COOKIE-ACK,
861 * to avoid problems with the managemement of this
862 * counter in stale cookie situations when a transition back
863 * from the COOKIE-ECHOED state to the COOKIE-WAIT
864 * state is performed.
866 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
868 /* RFC 2960 5.1 Normal Establishment of an Association
870 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
871 * from the COOKIE-ECHOED state to the ESTABLISHED state,
872 * stopping the T1-cookie timer.
874 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
875 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
876 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
877 SCTP_STATE(SCTP_STATE_ESTABLISHED));
878 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
879 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
880 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
882 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
883 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
884 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
886 /* It may also notify its ULP about the successful
887 * establishment of the association with a Communication Up
888 * notification (see Section 10).
890 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
891 0, asoc->c.sinit_num_ostreams,
892 asoc->c.sinit_max_instreams,
898 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
900 /* Sockets API Draft Section 5.3.1.6
901 * When a peer sends a Adaptation Layer Indication parameter , SCTP
902 * delivers this notification to inform the application that of the
903 * peers requested adaptation layer.
905 if (asoc->peer.adaptation_ind) {
906 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
910 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
914 return SCTP_DISPOSITION_CONSUME;
916 return SCTP_DISPOSITION_NOMEM;
919 /* Generate and sendout a heartbeat packet. */
920 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
921 const struct sctp_association *asoc,
922 const sctp_subtype_t type,
924 sctp_cmd_seq_t *commands)
926 struct sctp_transport *transport = (struct sctp_transport *) arg;
927 struct sctp_chunk *reply;
928 sctp_sender_hb_info_t hbinfo;
931 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
932 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
933 hbinfo.daddr = transport->ipaddr;
934 hbinfo.sent_at = jiffies;
935 hbinfo.hb_nonce = transport->hb_nonce;
937 /* Send a heartbeat to our peer. */
938 paylen = sizeof(sctp_sender_hb_info_t);
939 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
941 return SCTP_DISPOSITION_NOMEM;
943 /* Set rto_pending indicating that an RTT measurement
944 * is started with this heartbeat chunk.
946 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
947 SCTP_TRANSPORT(transport));
949 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
950 return SCTP_DISPOSITION_CONSUME;
953 /* Generate a HEARTBEAT packet on the given transport. */
954 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
955 const struct sctp_association *asoc,
956 const sctp_subtype_t type,
958 sctp_cmd_seq_t *commands)
960 struct sctp_transport *transport = (struct sctp_transport *) arg;
962 if (asoc->overall_error_count > asoc->max_retrans) {
963 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
964 SCTP_ERROR(ETIMEDOUT));
965 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
966 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
967 SCTP_PERR(SCTP_ERROR_NO_ERROR));
968 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
969 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
970 return SCTP_DISPOSITION_DELETE_TCB;
974 * The Sender-specific Heartbeat Info field should normally include
975 * information about the sender's current time when this HEARTBEAT
976 * chunk is sent and the destination transport address to which this
977 * HEARTBEAT is sent (see Section 8.3).
980 if (transport->param_flags & SPP_HB_ENABLE) {
981 if (SCTP_DISPOSITION_NOMEM ==
982 sctp_sf_heartbeat(ep, asoc, type, arg,
984 return SCTP_DISPOSITION_NOMEM;
985 /* Set transport error counter and association error counter
986 * when sending heartbeat.
988 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
989 SCTP_TRANSPORT(transport));
991 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
992 SCTP_TRANSPORT(transport));
994 return SCTP_DISPOSITION_CONSUME;
998 * Process an heartbeat request.
1000 * Section: 8.3 Path Heartbeat
1001 * The receiver of the HEARTBEAT should immediately respond with a
1002 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1003 * from the received HEARTBEAT chunk.
1005 * Verification Tag: 8.5 Verification Tag [Normal verification]
1006 * When receiving an SCTP packet, the endpoint MUST ensure that the
1007 * value in the Verification Tag field of the received SCTP packet
1008 * matches its own Tag. If the received Verification Tag value does not
1009 * match the receiver's own tag value, the receiver shall silently
1010 * discard the packet and shall not process it any further except for
1011 * those cases listed in Section 8.5.1 below.
1014 * (endpoint, asoc, chunk)
1017 * (asoc, reply_msg, msg_up, timers, counters)
1019 * The return value is the disposition of the chunk.
1021 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
1022 const struct sctp_association *asoc,
1023 const sctp_subtype_t type,
1025 sctp_cmd_seq_t *commands)
1027 struct sctp_chunk *chunk = arg;
1028 struct sctp_chunk *reply;
1031 if (!sctp_vtag_verify(chunk, asoc))
1032 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1034 /* Make sure that the HEARTBEAT chunk has a valid length. */
1035 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1036 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1039 /* 8.3 The receiver of the HEARTBEAT should immediately
1040 * respond with a HEARTBEAT ACK that contains the Heartbeat
1041 * Information field copied from the received HEARTBEAT chunk.
1043 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
1044 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
1045 if (!pskb_pull(chunk->skb, paylen))
1048 reply = sctp_make_heartbeat_ack(asoc, chunk,
1049 chunk->subh.hb_hdr, paylen);
1053 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1054 return SCTP_DISPOSITION_CONSUME;
1057 return SCTP_DISPOSITION_NOMEM;
1061 * Process the returning HEARTBEAT ACK.
1063 * Section: 8.3 Path Heartbeat
1064 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1065 * should clear the error counter of the destination transport
1066 * address to which the HEARTBEAT was sent, and mark the destination
1067 * transport address as active if it is not so marked. The endpoint may
1068 * optionally report to the upper layer when an inactive destination
1069 * address is marked as active due to the reception of the latest
1070 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1071 * clear the association overall error count as well (as defined
1074 * The receiver of the HEARTBEAT ACK should also perform an RTT
1075 * measurement for that destination transport address using the time
1076 * value carried in the HEARTBEAT ACK chunk.
1078 * Verification Tag: 8.5 Verification Tag [Normal verification]
1081 * (endpoint, asoc, chunk)
1084 * (asoc, reply_msg, msg_up, timers, counters)
1086 * The return value is the disposition of the chunk.
1088 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1089 const struct sctp_association *asoc,
1090 const sctp_subtype_t type,
1092 sctp_cmd_seq_t *commands)
1094 struct sctp_chunk *chunk = arg;
1095 union sctp_addr from_addr;
1096 struct sctp_transport *link;
1097 sctp_sender_hb_info_t *hbinfo;
1098 unsigned long max_interval;
1100 if (!sctp_vtag_verify(chunk, asoc))
1101 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1103 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1104 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1105 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1108 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1109 /* Make sure that the length of the parameter is what we expect */
1110 if (ntohs(hbinfo->param_hdr.length) !=
1111 sizeof(sctp_sender_hb_info_t)) {
1112 return SCTP_DISPOSITION_DISCARD;
1115 from_addr = hbinfo->daddr;
1116 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1118 /* This should never happen, but lets log it if so. */
1119 if (unlikely(!link)) {
1120 if (from_addr.sa.sa_family == AF_INET6) {
1121 if (net_ratelimit())
1123 "%s association %p could not find address "
1127 NIP6(from_addr.v6.sin6_addr));
1129 if (net_ratelimit())
1131 "%s association %p could not find address "
1135 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1137 return SCTP_DISPOSITION_DISCARD;
1140 /* Validate the 64-bit random nonce. */
1141 if (hbinfo->hb_nonce != link->hb_nonce)
1142 return SCTP_DISPOSITION_DISCARD;
1144 max_interval = link->hbinterval + link->rto;
1146 /* Check if the timestamp looks valid. */
1147 if (time_after(hbinfo->sent_at, jiffies) ||
1148 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1149 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1150 "received for transport: %p\n",
1151 __FUNCTION__, link);
1152 return SCTP_DISPOSITION_DISCARD;
1155 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1156 * the HEARTBEAT should clear the error counter of the
1157 * destination transport address to which the HEARTBEAT was
1158 * sent and mark the destination transport address as active if
1159 * it is not so marked.
1161 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1163 return SCTP_DISPOSITION_CONSUME;
1166 /* Helper function to send out an abort for the restart
1169 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1170 struct sctp_chunk *init,
1171 sctp_cmd_seq_t *commands)
1174 struct sctp_packet *pkt;
1175 union sctp_addr_param *addrparm;
1176 struct sctp_errhdr *errhdr;
1177 struct sctp_endpoint *ep;
1178 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1179 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1181 /* Build the error on the stack. We are way to malloc crazy
1182 * throughout the code today.
1184 errhdr = (struct sctp_errhdr *)buffer;
1185 addrparm = (union sctp_addr_param *)errhdr->variable;
1187 /* Copy into a parm format. */
1188 len = af->to_addr_param(ssa, addrparm);
1189 len += sizeof(sctp_errhdr_t);
1191 errhdr->cause = SCTP_ERROR_RESTART;
1192 errhdr->length = htons(len);
1194 /* Assign to the control socket. */
1195 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1197 /* Association is NULL since this may be a restart attack and we
1198 * want to send back the attacker's vtag.
1200 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1204 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1206 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1208 /* Discard the rest of the inbound packet. */
1209 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1212 /* Even if there is no memory, treat as a failure so
1213 * the packet will get dropped.
1218 /* A restart is occurring, check to make sure no new addresses
1219 * are being added as we may be under a takeover attack.
1221 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1222 const struct sctp_association *asoc,
1223 struct sctp_chunk *init,
1224 sctp_cmd_seq_t *commands)
1226 struct sctp_transport *new_addr, *addr;
1227 struct list_head *pos, *pos2;
1230 /* Implementor's Guide - Sectin 5.2.2
1232 * Before responding the endpoint MUST check to see if the
1233 * unexpected INIT adds new addresses to the association. If new
1234 * addresses are added to the association, the endpoint MUST respond
1238 /* Search through all current addresses and make sure
1239 * we aren't adding any new ones.
1244 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1245 new_addr = list_entry(pos, struct sctp_transport, transports);
1247 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1248 addr = list_entry(pos2, struct sctp_transport,
1250 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1260 /* If a new address was added, ABORT the sender. */
1261 if (!found && new_addr) {
1262 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1265 /* Return success if all addresses were found. */
1269 /* Populate the verification/tie tags based on overlapping INIT
1272 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1274 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1275 const struct sctp_association *asoc)
1277 switch (asoc->state) {
1279 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1281 case SCTP_STATE_COOKIE_WAIT:
1282 new_asoc->c.my_vtag = asoc->c.my_vtag;
1283 new_asoc->c.my_ttag = asoc->c.my_vtag;
1284 new_asoc->c.peer_ttag = 0;
1287 case SCTP_STATE_COOKIE_ECHOED:
1288 new_asoc->c.my_vtag = asoc->c.my_vtag;
1289 new_asoc->c.my_ttag = asoc->c.my_vtag;
1290 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1293 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1294 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1297 new_asoc->c.my_ttag = asoc->c.my_vtag;
1298 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1302 /* Other parameters for the endpoint SHOULD be copied from the
1303 * existing parameters of the association (e.g. number of
1304 * outbound streams) into the INIT ACK and cookie.
1306 new_asoc->rwnd = asoc->rwnd;
1307 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1308 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1309 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1313 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1316 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1318 * Returns value representing action to be taken. These action values
1319 * correspond to Action/Description values in RFC 2960, Table 2.
1321 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1322 const struct sctp_association *asoc)
1324 /* In this case, the peer may have restarted. */
1325 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1326 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1327 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1328 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1331 /* Collision case B. */
1332 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1333 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1334 (0 == asoc->c.peer_vtag))) {
1338 /* Collision case D. */
1339 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1340 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1343 /* Collision case C. */
1344 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1345 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1346 (0 == new_asoc->c.my_ttag) &&
1347 (0 == new_asoc->c.peer_ttag))
1350 /* No match to any of the special cases; discard this packet. */
1354 /* Common helper routine for both duplicate and simulataneous INIT
1357 static sctp_disposition_t sctp_sf_do_unexpected_init(
1358 const struct sctp_endpoint *ep,
1359 const struct sctp_association *asoc,
1360 const sctp_subtype_t type,
1361 void *arg, sctp_cmd_seq_t *commands)
1363 sctp_disposition_t retval;
1364 struct sctp_chunk *chunk = arg;
1365 struct sctp_chunk *repl;
1366 struct sctp_association *new_asoc;
1367 struct sctp_chunk *err_chunk;
1368 struct sctp_packet *packet;
1369 sctp_unrecognized_param_t *unk_param;
1373 * An endpoint MUST NOT bundle INIT, INIT ACK or
1374 * SHUTDOWN COMPLETE with any other chunks.
1377 * Furthermore, we require that the receiver of an INIT chunk MUST
1378 * enforce these rules by silently discarding an arriving packet
1379 * with an INIT chunk that is bundled with other chunks.
1381 if (!chunk->singleton)
1382 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1384 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1387 if (chunk->sctp_hdr->vtag != 0)
1388 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1390 /* Make sure that the INIT chunk has a valid length.
1391 * In this case, we generate a protocol violation since we have
1392 * an association established.
1394 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1395 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1397 /* Grab the INIT header. */
1398 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1400 /* Tag the variable length parameters. */
1401 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1403 /* Verify the INIT chunk before processing it. */
1405 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1406 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1408 /* This chunk contains fatal error. It is to be discarded.
1409 * Send an ABORT, with causes if there is any.
1412 packet = sctp_abort_pkt_new(ep, asoc, arg,
1413 (__u8 *)(err_chunk->chunk_hdr) +
1414 sizeof(sctp_chunkhdr_t),
1415 ntohs(err_chunk->chunk_hdr->length) -
1416 sizeof(sctp_chunkhdr_t));
1419 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1420 SCTP_PACKET(packet));
1421 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1422 retval = SCTP_DISPOSITION_CONSUME;
1424 retval = SCTP_DISPOSITION_NOMEM;
1428 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1434 * Other parameters for the endpoint SHOULD be copied from the
1435 * existing parameters of the association (e.g. number of
1436 * outbound streams) into the INIT ACK and cookie.
1437 * FIXME: We are copying parameters from the endpoint not the
1440 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1444 /* In the outbound INIT ACK the endpoint MUST copy its current
1445 * Verification Tag and Peers Verification tag into a reserved
1446 * place (local tie-tag and per tie-tag) within the state cookie.
1448 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1450 (sctp_init_chunk_t *)chunk->chunk_hdr,
1454 /* Make sure no new addresses are being added during the
1455 * restart. Do not do this check for COOKIE-WAIT state,
1456 * since there are no peer addresses to check against.
1457 * Upon return an ABORT will have been sent if needed.
1459 if (!sctp_state(asoc, COOKIE_WAIT)) {
1460 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1462 retval = SCTP_DISPOSITION_CONSUME;
1467 sctp_tietags_populate(new_asoc, asoc);
1469 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1471 /* If there are errors need to be reported for unknown parameters,
1472 * make sure to reserve enough room in the INIT ACK for them.
1476 len = ntohs(err_chunk->chunk_hdr->length) -
1477 sizeof(sctp_chunkhdr_t);
1480 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1483 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1487 /* If there are errors need to be reported for unknown parameters,
1488 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1492 /* Get the "Unrecognized parameter" parameter(s) out of the
1493 * ERROR chunk generated by sctp_verify_init(). Since the
1494 * error cause code for "unknown parameter" and the
1495 * "Unrecognized parameter" type is the same, we can
1496 * construct the parameters in INIT ACK by copying the
1497 * ERROR causes over.
1499 unk_param = (sctp_unrecognized_param_t *)
1500 ((__u8 *)(err_chunk->chunk_hdr) +
1501 sizeof(sctp_chunkhdr_t));
1502 /* Replace the cause code with the "Unrecognized parameter"
1505 sctp_addto_chunk(repl, len, unk_param);
1508 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1509 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1512 * Note: After sending out INIT ACK with the State Cookie parameter,
1513 * "Z" MUST NOT allocate any resources for this new association.
1514 * Otherwise, "Z" will be vulnerable to resource attacks.
1516 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1517 retval = SCTP_DISPOSITION_CONSUME;
1522 retval = SCTP_DISPOSITION_NOMEM;
1525 sctp_association_free(new_asoc);
1528 sctp_chunk_free(err_chunk);
1533 * Handle simultanous INIT.
1534 * This means we started an INIT and then we got an INIT request from
1537 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1538 * This usually indicates an initialization collision, i.e., each
1539 * endpoint is attempting, at about the same time, to establish an
1540 * association with the other endpoint.
1542 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1543 * endpoint MUST respond with an INIT ACK using the same parameters it
1544 * sent in its original INIT chunk (including its Verification Tag,
1545 * unchanged). These original parameters are combined with those from the
1546 * newly received INIT chunk. The endpoint shall also generate a State
1547 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1548 * INIT to calculate the State Cookie.
1550 * After that, the endpoint MUST NOT change its state, the T1-init
1551 * timer shall be left running and the corresponding TCB MUST NOT be
1552 * destroyed. The normal procedures for handling State Cookies when
1553 * a TCB exists will resolve the duplicate INITs to a single association.
1555 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1556 * its Tie-Tags with the Tag information of itself and its peer (see
1557 * section 5.2.2 for a description of the Tie-Tags).
1559 * Verification Tag: Not explicit, but an INIT can not have a valid
1560 * verification tag, so we skip the check.
1563 * (endpoint, asoc, chunk)
1566 * (asoc, reply_msg, msg_up, timers, counters)
1568 * The return value is the disposition of the chunk.
1570 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1571 const struct sctp_association *asoc,
1572 const sctp_subtype_t type,
1574 sctp_cmd_seq_t *commands)
1576 /* Call helper to do the real work for both simulataneous and
1577 * duplicate INIT chunk handling.
1579 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1583 * Handle duplicated INIT messages. These are usually delayed
1586 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1587 * COOKIE-ECHOED and COOKIE-WAIT
1589 * Unless otherwise stated, upon reception of an unexpected INIT for
1590 * this association, the endpoint shall generate an INIT ACK with a
1591 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1592 * current Verification Tag and peer's Verification Tag into a reserved
1593 * place within the state cookie. We shall refer to these locations as
1594 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1595 * containing this INIT ACK MUST carry a Verification Tag value equal to
1596 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1597 * MUST contain a new Initiation Tag (randomly generated see Section
1598 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1599 * existing parameters of the association (e.g. number of outbound
1600 * streams) into the INIT ACK and cookie.
1602 * After sending out the INIT ACK, the endpoint shall take no further
1603 * actions, i.e., the existing association, including its current state,
1604 * and the corresponding TCB MUST NOT be changed.
1606 * Note: Only when a TCB exists and the association is not in a COOKIE-
1607 * WAIT state are the Tie-Tags populated. For a normal association INIT
1608 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1609 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1610 * State Cookie are populated as specified in section 5.2.1.
1612 * Verification Tag: Not specified, but an INIT has no way of knowing
1613 * what the verification tag could be, so we ignore it.
1616 * (endpoint, asoc, chunk)
1619 * (asoc, reply_msg, msg_up, timers, counters)
1621 * The return value is the disposition of the chunk.
1623 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1624 const struct sctp_association *asoc,
1625 const sctp_subtype_t type,
1627 sctp_cmd_seq_t *commands)
1629 /* Call helper to do the real work for both simulataneous and
1630 * duplicate INIT chunk handling.
1632 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1637 * Unexpected INIT-ACK handler.
1640 * If an INIT ACK received by an endpoint in any state other than the
1641 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1642 * An unexpected INIT ACK usually indicates the processing of an old or
1643 * duplicated INIT chunk.
1645 sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1646 const struct sctp_association *asoc,
1647 const sctp_subtype_t type,
1648 void *arg, sctp_cmd_seq_t *commands)
1650 /* Per the above section, we'll discard the chunk if we have an
1651 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1653 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1654 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1656 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1659 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1662 * A) In this case, the peer may have restarted.
1664 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1665 const struct sctp_association *asoc,
1666 struct sctp_chunk *chunk,
1667 sctp_cmd_seq_t *commands,
1668 struct sctp_association *new_asoc)
1670 sctp_init_chunk_t *peer_init;
1671 struct sctp_ulpevent *ev;
1672 struct sctp_chunk *repl;
1673 struct sctp_chunk *err;
1674 sctp_disposition_t disposition;
1676 /* new_asoc is a brand-new association, so these are not yet
1677 * side effects--it is safe to run them here.
1679 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1681 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1682 sctp_source(chunk), peer_init,
1686 /* Make sure no new addresses are being added during the
1687 * restart. Though this is a pretty complicated attack
1688 * since you'd have to get inside the cookie.
1690 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1691 return SCTP_DISPOSITION_CONSUME;
1694 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1695 * the peer has restarted (Action A), it MUST NOT setup a new
1696 * association but instead resend the SHUTDOWN ACK and send an ERROR
1697 * chunk with a "Cookie Received while Shutting Down" error cause to
1700 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1701 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1702 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1704 if (SCTP_DISPOSITION_NOMEM == disposition)
1707 err = sctp_make_op_error(asoc, chunk,
1708 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1711 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1714 return SCTP_DISPOSITION_CONSUME;
1717 /* For now, fail any unsent/unacked data. Consider the optional
1718 * choice of resending of this data.
1720 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1722 repl = sctp_make_cookie_ack(new_asoc, chunk);
1726 /* Report association restart to upper layer. */
1727 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1728 new_asoc->c.sinit_num_ostreams,
1729 new_asoc->c.sinit_max_instreams,
1734 /* Update the content of current association. */
1735 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1736 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1737 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1738 return SCTP_DISPOSITION_CONSUME;
1741 sctp_chunk_free(repl);
1743 return SCTP_DISPOSITION_NOMEM;
1746 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1749 * B) In this case, both sides may be attempting to start an association
1750 * at about the same time but the peer endpoint started its INIT
1751 * after responding to the local endpoint's INIT
1753 /* This case represents an initialization collision. */
1754 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1755 const struct sctp_association *asoc,
1756 struct sctp_chunk *chunk,
1757 sctp_cmd_seq_t *commands,
1758 struct sctp_association *new_asoc)
1760 sctp_init_chunk_t *peer_init;
1761 struct sctp_chunk *repl;
1763 /* new_asoc is a brand-new association, so these are not yet
1764 * side effects--it is safe to run them here.
1766 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1767 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1768 sctp_source(chunk), peer_init,
1772 /* Update the content of current association. */
1773 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1774 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1775 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1776 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1777 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1779 repl = sctp_make_cookie_ack(new_asoc, chunk);
1783 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1784 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1786 /* RFC 2960 5.1 Normal Establishment of an Association
1788 * D) IMPLEMENTATION NOTE: An implementation may choose to
1789 * send the Communication Up notification to the SCTP user
1790 * upon reception of a valid COOKIE ECHO chunk.
1792 * Sadly, this needs to be implemented as a side-effect, because
1793 * we are not guaranteed to have set the association id of the real
1794 * association and so these notifications need to be delayed until
1795 * the association id is allocated.
1798 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1800 /* Sockets API Draft Section 5.3.1.6
1801 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1802 * delivers this notification to inform the application that of the
1803 * peers requested adaptation layer.
1805 * This also needs to be done as a side effect for the same reason as
1808 if (asoc->peer.adaptation_ind)
1809 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1811 return SCTP_DISPOSITION_CONSUME;
1814 return SCTP_DISPOSITION_NOMEM;
1817 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1820 * C) In this case, the local endpoint's cookie has arrived late.
1821 * Before it arrived, the local endpoint sent an INIT and received an
1822 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1823 * but a new tag of its own.
1825 /* This case represents an initialization collision. */
1826 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1827 const struct sctp_association *asoc,
1828 struct sctp_chunk *chunk,
1829 sctp_cmd_seq_t *commands,
1830 struct sctp_association *new_asoc)
1832 /* The cookie should be silently discarded.
1833 * The endpoint SHOULD NOT change states and should leave
1834 * any timers running.
1836 return SCTP_DISPOSITION_DISCARD;
1839 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1843 * D) When both local and remote tags match the endpoint should always
1844 * enter the ESTABLISHED state, if it has not already done so.
1846 /* This case represents an initialization collision. */
1847 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1848 const struct sctp_association *asoc,
1849 struct sctp_chunk *chunk,
1850 sctp_cmd_seq_t *commands,
1851 struct sctp_association *new_asoc)
1853 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1854 struct sctp_chunk *repl;
1856 /* Clarification from Implementor's Guide:
1857 * D) When both local and remote tags match the endpoint should
1858 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1859 * It should stop any cookie timer that may be running and send
1863 /* Don't accidentally move back into established state. */
1864 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1865 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1866 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1867 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1868 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1869 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1870 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1873 /* RFC 2960 5.1 Normal Establishment of an Association
1875 * D) IMPLEMENTATION NOTE: An implementation may choose
1876 * to send the Communication Up notification to the
1877 * SCTP user upon reception of a valid COOKIE
1880 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1882 asoc->c.sinit_num_ostreams,
1883 asoc->c.sinit_max_instreams,
1888 /* Sockets API Draft Section 5.3.1.6
1889 * When a peer sends a Adaptation Layer Indication parameter,
1890 * SCTP delivers this notification to inform the application
1891 * that of the peers requested adaptation layer.
1893 if (asoc->peer.adaptation_ind) {
1894 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1901 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1903 repl = sctp_make_cookie_ack(new_asoc, chunk);
1908 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1911 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1912 SCTP_ULPEVENT(ai_ev));
1914 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1915 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1917 return SCTP_DISPOSITION_CONSUME;
1921 sctp_ulpevent_free(ai_ev);
1923 sctp_ulpevent_free(ev);
1924 return SCTP_DISPOSITION_NOMEM;
1928 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1929 * chunk was retransmitted and then delayed in the network.
1931 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1933 * Verification Tag: None. Do cookie validation.
1936 * (endpoint, asoc, chunk)
1939 * (asoc, reply_msg, msg_up, timers, counters)
1941 * The return value is the disposition of the chunk.
1943 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1944 const struct sctp_association *asoc,
1945 const sctp_subtype_t type,
1947 sctp_cmd_seq_t *commands)
1949 sctp_disposition_t retval;
1950 struct sctp_chunk *chunk = arg;
1951 struct sctp_association *new_asoc;
1954 struct sctp_chunk *err_chk_p;
1956 /* Make sure that the chunk has a valid length from the protocol
1957 * perspective. In this case check to make sure we have at least
1958 * enough for the chunk header. Cookie length verification is
1961 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1962 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1965 /* "Decode" the chunk. We have no optional parameters so we
1966 * are in good shape.
1968 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1969 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1970 sizeof(sctp_chunkhdr_t)))
1973 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1974 * of a duplicate COOKIE ECHO match the Verification Tags of the
1975 * current association, consider the State Cookie valid even if
1976 * the lifespan is exceeded.
1978 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1982 * If the re-build failed, what is the proper error path
1985 * [We should abort the association. --piggy]
1988 /* FIXME: Several errors are possible. A bad cookie should
1989 * be silently discarded, but think about logging it too.
1992 case -SCTP_IERROR_NOMEM:
1995 case -SCTP_IERROR_STALE_COOKIE:
1996 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1998 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1999 case -SCTP_IERROR_BAD_SIG:
2001 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2005 /* Compare the tie_tag in cookie with the verification tag of
2006 * current association.
2008 action = sctp_tietags_compare(new_asoc, asoc);
2011 case 'A': /* Association restart. */
2012 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
2016 case 'B': /* Collision case B. */
2017 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
2021 case 'C': /* Collision case C. */
2022 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
2026 case 'D': /* Collision case D. */
2027 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
2031 default: /* Discard packet for all others. */
2032 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2036 /* Delete the tempory new association. */
2037 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
2038 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2043 return SCTP_DISPOSITION_NOMEM;
2047 * Process an ABORT. (SHUTDOWN-PENDING state)
2049 * See sctp_sf_do_9_1_abort().
2051 sctp_disposition_t sctp_sf_shutdown_pending_abort(
2052 const struct sctp_endpoint *ep,
2053 const struct sctp_association *asoc,
2054 const sctp_subtype_t type,
2056 sctp_cmd_seq_t *commands)
2058 struct sctp_chunk *chunk = arg;
2060 if (!sctp_vtag_verify_either(chunk, asoc))
2061 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2063 /* Make sure that the ABORT chunk has a valid length.
2064 * Since this is an ABORT chunk, we have to discard it
2065 * because of the following text:
2066 * RFC 2960, Section 3.3.7
2067 * If an endpoint receives an ABORT with a format error or for an
2068 * association that doesn't exist, it MUST silently discard it.
2069 * Becasue the length is "invalid", we can't really discard just
2070 * as we do not know its true length. So, to be safe, discard the
2073 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2074 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2076 /* Stop the T5-shutdown guard timer. */
2077 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2078 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2080 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2084 * Process an ABORT. (SHUTDOWN-SENT state)
2086 * See sctp_sf_do_9_1_abort().
2088 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2089 const struct sctp_association *asoc,
2090 const sctp_subtype_t type,
2092 sctp_cmd_seq_t *commands)
2094 struct sctp_chunk *chunk = arg;
2096 if (!sctp_vtag_verify_either(chunk, asoc))
2097 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2099 /* Make sure that the ABORT chunk has a valid length.
2100 * Since this is an ABORT chunk, we have to discard it
2101 * because of the following text:
2102 * RFC 2960, Section 3.3.7
2103 * If an endpoint receives an ABORT with a format error or for an
2104 * association that doesn't exist, it MUST silently discard it.
2105 * Becasue the length is "invalid", we can't really discard just
2106 * as we do not know its true length. So, to be safe, discard the
2109 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2110 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2112 /* Stop the T2-shutdown timer. */
2113 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2114 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2116 /* Stop the T5-shutdown guard timer. */
2117 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2118 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2120 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2124 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2126 * See sctp_sf_do_9_1_abort().
2128 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2129 const struct sctp_endpoint *ep,
2130 const struct sctp_association *asoc,
2131 const sctp_subtype_t type,
2133 sctp_cmd_seq_t *commands)
2135 /* The same T2 timer, so we should be able to use
2136 * common function with the SHUTDOWN-SENT state.
2138 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2142 * Handle an Error received in COOKIE_ECHOED state.
2144 * Only handle the error type of stale COOKIE Error, the other errors will
2148 * (endpoint, asoc, chunk)
2151 * (asoc, reply_msg, msg_up, timers, counters)
2153 * The return value is the disposition of the chunk.
2155 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2156 const struct sctp_association *asoc,
2157 const sctp_subtype_t type,
2159 sctp_cmd_seq_t *commands)
2161 struct sctp_chunk *chunk = arg;
2164 if (!sctp_vtag_verify(chunk, asoc))
2165 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2167 /* Make sure that the ERROR chunk has a valid length.
2168 * The parameter walking depends on this as well.
2170 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2171 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2174 /* Process the error here */
2175 /* FUTURE FIXME: When PR-SCTP related and other optional
2176 * parms are emitted, this will have to change to handle multiple
2179 sctp_walk_errors(err, chunk->chunk_hdr) {
2180 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2181 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2185 /* It is possible to have malformed error causes, and that
2186 * will cause us to end the walk early. However, since
2187 * we are discarding the packet, there should be no adverse
2190 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2194 * Handle a Stale COOKIE Error
2196 * Section: 5.2.6 Handle Stale COOKIE Error
2197 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2198 * one of the following three alternatives.
2200 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2201 * Preservative parameter requesting an extension to the lifetime of
2202 * the State Cookie. When calculating the time extension, an
2203 * implementation SHOULD use the RTT information measured based on the
2204 * previous COOKIE ECHO / ERROR exchange, and should add no more
2205 * than 1 second beyond the measured RTT, due to long State Cookie
2206 * lifetimes making the endpoint more subject to a replay attack.
2208 * Verification Tag: Not explicit, but safe to ignore.
2211 * (endpoint, asoc, chunk)
2214 * (asoc, reply_msg, msg_up, timers, counters)
2216 * The return value is the disposition of the chunk.
2218 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2219 const struct sctp_association *asoc,
2220 const sctp_subtype_t type,
2222 sctp_cmd_seq_t *commands)
2224 struct sctp_chunk *chunk = arg;
2226 sctp_cookie_preserve_param_t bht;
2228 struct sctp_chunk *reply;
2229 struct sctp_bind_addr *bp;
2230 int attempts = asoc->init_err_counter + 1;
2232 if (attempts > asoc->max_init_attempts) {
2233 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2234 SCTP_ERROR(ETIMEDOUT));
2235 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2236 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2237 return SCTP_DISPOSITION_DELETE_TCB;
2240 err = (sctp_errhdr_t *)(chunk->skb->data);
2242 /* When calculating the time extension, an implementation
2243 * SHOULD use the RTT information measured based on the
2244 * previous COOKIE ECHO / ERROR exchange, and should add no
2245 * more than 1 second beyond the measured RTT, due to long
2246 * State Cookie lifetimes making the endpoint more subject to
2248 * Measure of Staleness's unit is usec. (1/1000000 sec)
2249 * Suggested Cookie Life-span Increment's unit is msec.
2251 * In general, if you use the suggested cookie life, the value
2252 * found in the field of measure of staleness should be doubled
2253 * to give ample time to retransmit the new cookie and thus
2254 * yield a higher probability of success on the reattempt.
2256 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2257 stale = (stale * 2) / 1000;
2259 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2260 bht.param_hdr.length = htons(sizeof(bht));
2261 bht.lifespan_increment = htonl(stale);
2263 /* Build that new INIT chunk. */
2264 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2265 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2269 sctp_addto_chunk(reply, sizeof(bht), &bht);
2271 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2272 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2274 /* Stop pending T3-rtx and heartbeat timers */
2275 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2276 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2278 /* Delete non-primary peer ip addresses since we are transitioning
2279 * back to the COOKIE-WAIT state
2281 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2283 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2286 sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
2287 SCTP_TRANSPORT(asoc->peer.primary_path));
2289 /* Cast away the const modifier, as we want to just
2290 * rerun it through as a sideffect.
2292 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2294 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2295 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2296 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2297 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2298 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2299 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2301 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2303 return SCTP_DISPOSITION_CONSUME;
2306 return SCTP_DISPOSITION_NOMEM;
2313 * After checking the Verification Tag, the receiving endpoint shall
2314 * remove the association from its record, and shall report the
2315 * termination to its upper layer.
2317 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2318 * B) Rules for packet carrying ABORT:
2320 * - The endpoint shall always fill in the Verification Tag field of the
2321 * outbound packet with the destination endpoint's tag value if it
2324 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2325 * MUST follow the procedure described in Section 8.4.
2327 * - The receiver MUST accept the packet if the Verification Tag
2328 * matches either its own tag, OR the tag of its peer. Otherwise, the
2329 * receiver MUST silently discard the packet and take no further
2333 * (endpoint, asoc, chunk)
2336 * (asoc, reply_msg, msg_up, timers, counters)
2338 * The return value is the disposition of the chunk.
2340 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2341 const struct sctp_association *asoc,
2342 const sctp_subtype_t type,
2344 sctp_cmd_seq_t *commands)
2346 struct sctp_chunk *chunk = arg;
2348 __be16 error = SCTP_ERROR_NO_ERROR;
2350 if (!sctp_vtag_verify_either(chunk, asoc))
2351 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2353 /* Make sure that the ABORT chunk has a valid length.
2354 * Since this is an ABORT chunk, we have to discard it
2355 * because of the following text:
2356 * RFC 2960, Section 3.3.7
2357 * If an endpoint receives an ABORT with a format error or for an
2358 * association that doesn't exist, it MUST silently discard it.
2359 * Becasue the length is "invalid", we can't really discard just
2360 * as we do not know its true length. So, to be safe, discard the
2363 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2364 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2366 /* See if we have an error cause code in the chunk. */
2367 len = ntohs(chunk->chunk_hdr->length);
2368 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2369 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2371 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2372 /* ASSOC_FAILED will DELETE_TCB. */
2373 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2374 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2375 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2377 return SCTP_DISPOSITION_ABORT;
2381 * Process an ABORT. (COOKIE-WAIT state)
2383 * See sctp_sf_do_9_1_abort() above.
2385 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2386 const struct sctp_association *asoc,
2387 const sctp_subtype_t type,
2389 sctp_cmd_seq_t *commands)
2391 struct sctp_chunk *chunk = arg;
2393 __be16 error = SCTP_ERROR_NO_ERROR;
2395 if (!sctp_vtag_verify_either(chunk, asoc))
2396 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2398 /* Make sure that the ABORT chunk has a valid length.
2399 * Since this is an ABORT chunk, we have to discard it
2400 * because of the following text:
2401 * RFC 2960, Section 3.3.7
2402 * If an endpoint receives an ABORT with a format error or for an
2403 * association that doesn't exist, it MUST silently discard it.
2404 * Becasue the length is "invalid", we can't really discard just
2405 * as we do not know its true length. So, to be safe, discard the
2408 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2409 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2411 /* See if we have an error cause code in the chunk. */
2412 len = ntohs(chunk->chunk_hdr->length);
2413 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2414 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2416 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2421 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2423 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2424 const struct sctp_association *asoc,
2425 const sctp_subtype_t type,
2427 sctp_cmd_seq_t *commands)
2429 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2431 (struct sctp_transport *)arg);
2435 * Process an ABORT. (COOKIE-ECHOED state)
2437 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2438 const struct sctp_association *asoc,
2439 const sctp_subtype_t type,
2441 sctp_cmd_seq_t *commands)
2443 /* There is a single T1 timer, so we should be able to use
2444 * common function with the COOKIE-WAIT state.
2446 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2450 * Stop T1 timer and abort association with "INIT failed".
2452 * This is common code called by several sctp_sf_*_abort() functions above.
2454 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2455 __be16 error, int sk_err,
2456 const struct sctp_association *asoc,
2457 struct sctp_transport *transport)
2459 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2460 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2461 SCTP_STATE(SCTP_STATE_CLOSED));
2462 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2463 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2464 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2465 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2466 /* CMD_INIT_FAILED will DELETE_TCB. */
2467 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2469 return SCTP_DISPOSITION_ABORT;
2473 * sctp_sf_do_9_2_shut
2476 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2477 * - enter the SHUTDOWN-RECEIVED state,
2479 * - stop accepting new data from its SCTP user
2481 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2482 * that all its outstanding DATA chunks have been received by the
2485 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2486 * send a SHUTDOWN in response to a ULP request. And should discard
2487 * subsequent SHUTDOWN chunks.
2489 * If there are still outstanding DATA chunks left, the SHUTDOWN
2490 * receiver shall continue to follow normal data transmission
2491 * procedures defined in Section 6 until all outstanding DATA chunks
2492 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2493 * new data from its SCTP user.
2495 * Verification Tag: 8.5 Verification Tag [Normal verification]
2498 * (endpoint, asoc, chunk)
2501 * (asoc, reply_msg, msg_up, timers, counters)
2503 * The return value is the disposition of the chunk.
2505 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2506 const struct sctp_association *asoc,
2507 const sctp_subtype_t type,
2509 sctp_cmd_seq_t *commands)
2511 struct sctp_chunk *chunk = arg;
2512 sctp_shutdownhdr_t *sdh;
2513 sctp_disposition_t disposition;
2514 struct sctp_ulpevent *ev;
2516 if (!sctp_vtag_verify(chunk, asoc))
2517 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2519 /* Make sure that the SHUTDOWN chunk has a valid length. */
2520 if (!sctp_chunk_length_valid(chunk,
2521 sizeof(struct sctp_shutdown_chunk_t)))
2522 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2525 /* Convert the elaborate header. */
2526 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2527 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2528 chunk->subh.shutdown_hdr = sdh;
2530 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2531 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2532 * inform the application that it should cease sending data.
2534 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2536 disposition = SCTP_DISPOSITION_NOMEM;
2539 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2541 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2542 * - enter the SHUTDOWN-RECEIVED state,
2543 * - stop accepting new data from its SCTP user
2545 * [This is implicit in the new state.]
2547 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2548 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2549 disposition = SCTP_DISPOSITION_CONSUME;
2551 if (sctp_outq_is_empty(&asoc->outqueue)) {
2552 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2556 if (SCTP_DISPOSITION_NOMEM == disposition)
2559 /* - verify, by checking the Cumulative TSN Ack field of the
2560 * chunk, that all its outstanding DATA chunks have been
2561 * received by the SHUTDOWN sender.
2563 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2564 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2571 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2572 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2573 * transport addresses (either in the IP addresses or in the INIT chunk)
2574 * that belong to this association, it should discard the INIT chunk and
2575 * retransmit the SHUTDOWN ACK chunk.
2577 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2578 const struct sctp_association *asoc,
2579 const sctp_subtype_t type,
2581 sctp_cmd_seq_t *commands)
2583 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2584 struct sctp_chunk *reply;
2586 /* Make sure that the chunk has a valid length */
2587 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
2588 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2591 /* Since we are not going to really process this INIT, there
2592 * is no point in verifying chunk boundries. Just generate
2595 reply = sctp_make_shutdown_ack(asoc, chunk);
2599 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2600 * the T2-SHUTDOWN timer.
2602 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2604 /* and restart the T2-shutdown timer. */
2605 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2606 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2608 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2610 return SCTP_DISPOSITION_CONSUME;
2612 return SCTP_DISPOSITION_NOMEM;
2616 * sctp_sf_do_ecn_cwr
2618 * Section: Appendix A: Explicit Congestion Notification
2622 * RFC 2481 details a specific bit for a sender to send in the header of
2623 * its next outbound TCP segment to indicate to its peer that it has
2624 * reduced its congestion window. This is termed the CWR bit. For
2625 * SCTP the same indication is made by including the CWR chunk.
2626 * This chunk contains one data element, i.e. the TSN number that
2627 * was sent in the ECNE chunk. This element represents the lowest
2628 * TSN number in the datagram that was originally marked with the
2631 * Verification Tag: 8.5 Verification Tag [Normal verification]
2633 * (endpoint, asoc, chunk)
2636 * (asoc, reply_msg, msg_up, timers, counters)
2638 * The return value is the disposition of the chunk.
2640 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2641 const struct sctp_association *asoc,
2642 const sctp_subtype_t type,
2644 sctp_cmd_seq_t *commands)
2647 struct sctp_chunk *chunk = arg;
2650 if (!sctp_vtag_verify(chunk, asoc))
2651 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2653 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2654 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2657 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2658 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2660 lowest_tsn = ntohl(cwr->lowest_tsn);
2662 /* Does this CWR ack the last sent congestion notification? */
2663 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2664 /* Stop sending ECNE. */
2665 sctp_add_cmd_sf(commands,
2667 SCTP_U32(lowest_tsn));
2669 return SCTP_DISPOSITION_CONSUME;
2675 * Section: Appendix A: Explicit Congestion Notification
2679 * RFC 2481 details a specific bit for a receiver to send back in its
2680 * TCP acknowledgements to notify the sender of the Congestion
2681 * Experienced (CE) bit having arrived from the network. For SCTP this
2682 * same indication is made by including the ECNE chunk. This chunk
2683 * contains one data element, i.e. the lowest TSN associated with the IP
2684 * datagram marked with the CE bit.....
2686 * Verification Tag: 8.5 Verification Tag [Normal verification]
2688 * (endpoint, asoc, chunk)
2691 * (asoc, reply_msg, msg_up, timers, counters)
2693 * The return value is the disposition of the chunk.
2695 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2696 const struct sctp_association *asoc,
2697 const sctp_subtype_t type,
2699 sctp_cmd_seq_t *commands)
2701 sctp_ecnehdr_t *ecne;
2702 struct sctp_chunk *chunk = arg;
2704 if (!sctp_vtag_verify(chunk, asoc))
2705 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2707 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2708 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2711 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2712 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2714 /* If this is a newer ECNE than the last CWR packet we sent out */
2715 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2716 SCTP_U32(ntohl(ecne->lowest_tsn)));
2718 return SCTP_DISPOSITION_CONSUME;
2722 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2724 * The SCTP endpoint MUST always acknowledge the reception of each valid
2727 * The guidelines on delayed acknowledgement algorithm specified in
2728 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2729 * acknowledgement SHOULD be generated for at least every second packet
2730 * (not every second DATA chunk) received, and SHOULD be generated within
2731 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2732 * situations it may be beneficial for an SCTP transmitter to be more
2733 * conservative than the algorithms detailed in this document allow.
2734 * However, an SCTP transmitter MUST NOT be more aggressive than the
2735 * following algorithms allow.
2737 * A SCTP receiver MUST NOT generate more than one SACK for every
2738 * incoming packet, other than to update the offered window as the
2739 * receiving application consumes new data.
2741 * Verification Tag: 8.5 Verification Tag [Normal verification]
2744 * (endpoint, asoc, chunk)
2747 * (asoc, reply_msg, msg_up, timers, counters)
2749 * The return value is the disposition of the chunk.
2751 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2752 const struct sctp_association *asoc,
2753 const sctp_subtype_t type,
2755 sctp_cmd_seq_t *commands)
2757 struct sctp_chunk *chunk = arg;
2760 if (!sctp_vtag_verify(chunk, asoc)) {
2761 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2763 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2766 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2767 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2770 error = sctp_eat_data(asoc, chunk, commands );
2772 case SCTP_IERROR_NO_ERROR:
2774 case SCTP_IERROR_HIGH_TSN:
2775 case SCTP_IERROR_BAD_STREAM:
2776 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2777 goto discard_noforce;
2778 case SCTP_IERROR_DUP_TSN:
2779 case SCTP_IERROR_IGNORE_TSN:
2780 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2782 case SCTP_IERROR_NO_DATA:
2788 if (asoc->autoclose) {
2789 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2790 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2793 /* If this is the last chunk in a packet, we need to count it
2794 * toward sack generation. Note that we need to SACK every
2795 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2796 * THEM. We elect to NOT generate SACK's if the chunk fails
2797 * the verification tag test.
2799 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2801 * The SCTP endpoint MUST always acknowledge the reception of
2802 * each valid DATA chunk.
2804 * The guidelines on delayed acknowledgement algorithm
2805 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2806 * Specifically, an acknowledgement SHOULD be generated for at
2807 * least every second packet (not every second DATA chunk)
2808 * received, and SHOULD be generated within 200 ms of the
2809 * arrival of any unacknowledged DATA chunk. In some
2810 * situations it may be beneficial for an SCTP transmitter to
2811 * be more conservative than the algorithms detailed in this
2812 * document allow. However, an SCTP transmitter MUST NOT be
2813 * more aggressive than the following algorithms allow.
2815 if (chunk->end_of_packet)
2816 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2818 return SCTP_DISPOSITION_CONSUME;
2821 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2823 * When a packet arrives with duplicate DATA chunk(s) and with
2824 * no new DATA chunk(s), the endpoint MUST immediately send a
2825 * SACK with no delay. If a packet arrives with duplicate
2826 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2827 * MAY immediately send a SACK. Normally receipt of duplicate
2828 * DATA chunks will occur when the original SACK chunk was lost
2829 * and the peer's RTO has expired. The duplicate TSN number(s)
2830 * SHOULD be reported in the SACK as duplicate.
2832 /* In our case, we split the MAY SACK advice up whether or not
2833 * the last chunk is a duplicate.'
2835 if (chunk->end_of_packet)
2836 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2837 return SCTP_DISPOSITION_DISCARD;
2840 if (chunk->end_of_packet)
2841 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2843 return SCTP_DISPOSITION_DISCARD;
2845 return SCTP_DISPOSITION_CONSUME;
2850 * sctp_sf_eat_data_fast_4_4
2853 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2854 * DATA chunks without delay.
2856 * Verification Tag: 8.5 Verification Tag [Normal verification]
2858 * (endpoint, asoc, chunk)
2861 * (asoc, reply_msg, msg_up, timers, counters)
2863 * The return value is the disposition of the chunk.
2865 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2866 const struct sctp_association *asoc,
2867 const sctp_subtype_t type,
2869 sctp_cmd_seq_t *commands)
2871 struct sctp_chunk *chunk = arg;
2874 if (!sctp_vtag_verify(chunk, asoc)) {
2875 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2877 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2880 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2881 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2884 error = sctp_eat_data(asoc, chunk, commands );
2886 case SCTP_IERROR_NO_ERROR:
2887 case SCTP_IERROR_HIGH_TSN:
2888 case SCTP_IERROR_DUP_TSN:
2889 case SCTP_IERROR_IGNORE_TSN:
2890 case SCTP_IERROR_BAD_STREAM:
2892 case SCTP_IERROR_NO_DATA:
2898 /* Go a head and force a SACK, since we are shutting down. */
2900 /* Implementor's Guide.
2902 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2903 * respond to each received packet containing one or more DATA chunk(s)
2904 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2906 if (chunk->end_of_packet) {
2907 /* We must delay the chunk creation since the cumulative
2908 * TSN has not been updated yet.
2910 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2911 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2912 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2913 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2917 return SCTP_DISPOSITION_CONSUME;
2921 * Section: 6.2 Processing a Received SACK
2922 * D) Any time a SACK arrives, the endpoint performs the following:
2924 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2925 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2926 * increasing, a SACK whose Cumulative TSN Ack is less than the
2927 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2929 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2930 * of bytes still outstanding after processing the Cumulative TSN Ack
2931 * and the Gap Ack Blocks.
2933 * iii) If the SACK is missing a TSN that was previously
2934 * acknowledged via a Gap Ack Block (e.g., the data receiver
2935 * reneged on the data), then mark the corresponding DATA chunk
2936 * as available for retransmit: Mark it as missing for fast
2937 * retransmit as described in Section 7.2.4 and if no retransmit
2938 * timer is running for the destination address to which the DATA
2939 * chunk was originally transmitted, then T3-rtx is started for
2940 * that destination address.
2942 * Verification Tag: 8.5 Verification Tag [Normal verification]
2945 * (endpoint, asoc, chunk)
2948 * (asoc, reply_msg, msg_up, timers, counters)
2950 * The return value is the disposition of the chunk.
2952 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2953 const struct sctp_association *asoc,
2954 const sctp_subtype_t type,
2956 sctp_cmd_seq_t *commands)
2958 struct sctp_chunk *chunk = arg;
2959 sctp_sackhdr_t *sackh;
2962 if (!sctp_vtag_verify(chunk, asoc))
2963 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2965 /* Make sure that the SACK chunk has a valid length. */
2966 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
2967 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2970 /* Pull the SACK chunk from the data buffer */
2971 sackh = sctp_sm_pull_sack(chunk);
2972 /* Was this a bogus SACK? */
2974 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2975 chunk->subh.sack_hdr = sackh;
2976 ctsn = ntohl(sackh->cum_tsn_ack);
2978 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2979 * Ack Point, then drop the SACK. Since Cumulative TSN
2980 * Ack is monotonically increasing, a SACK whose
2981 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2982 * Point indicates an out-of-order SACK.
2984 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2985 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2986 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2987 return SCTP_DISPOSITION_DISCARD;
2990 /* If Cumulative TSN Ack beyond the max tsn currently
2991 * send, terminating the association and respond to the
2992 * sender with an ABORT.
2994 if (!TSN_lt(ctsn, asoc->next_tsn))
2995 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
2997 /* Return this SACK for further processing. */
2998 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
3000 /* Note: We do the rest of the work on the PROCESS_SACK
3003 return SCTP_DISPOSITION_CONSUME;
3007 * Generate an ABORT in response to a packet.
3009 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3011 * 8) The receiver should respond to the sender of the OOTB packet with
3012 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3013 * MUST fill in the Verification Tag field of the outbound packet
3014 * with the value found in the Verification Tag field of the OOTB
3015 * packet and set the T-bit in the Chunk Flags to indicate that the
3016 * Verification Tag is reflected. After sending this ABORT, the
3017 * receiver of the OOTB packet shall discard the OOTB packet and take
3018 * no further action.
3022 * The return value is the disposition of the chunk.
3024 static sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
3025 const struct sctp_association *asoc,
3026 const sctp_subtype_t type,
3028 sctp_cmd_seq_t *commands)
3030 struct sctp_packet *packet = NULL;
3031 struct sctp_chunk *chunk = arg;
3032 struct sctp_chunk *abort;
3034 packet = sctp_ootb_pkt_new(asoc, chunk);
3037 /* Make an ABORT. The T bit will be set if the asoc
3040 abort = sctp_make_abort(asoc, chunk, 0);
3042 sctp_ootb_pkt_free(packet);
3043 return SCTP_DISPOSITION_NOMEM;
3046 /* Reflect vtag if T-Bit is set */
3047 if (sctp_test_T_bit(abort))
3048 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3050 /* Set the skb to the belonging sock for accounting. */
3051 abort->skb->sk = ep->base.sk;
3053 sctp_packet_append_chunk(packet, abort);
3055 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3056 SCTP_PACKET(packet));
3058 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3060 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3061 return SCTP_DISPOSITION_CONSUME;
3064 return SCTP_DISPOSITION_NOMEM;
3068 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3069 * event as ULP notification for each cause included in the chunk.
3071 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3073 * The return value is the disposition of the chunk.
3075 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
3076 const struct sctp_association *asoc,
3077 const sctp_subtype_t type,
3079 sctp_cmd_seq_t *commands)
3081 struct sctp_chunk *chunk = arg;
3082 struct sctp_ulpevent *ev;
3084 if (!sctp_vtag_verify(chunk, asoc))
3085 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3087 /* Make sure that the ERROR chunk has a valid length. */
3088 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
3089 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3092 while (chunk->chunk_end > chunk->skb->data) {
3093 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
3098 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
3099 SCTP_ULPEVENT(ev))) {
3100 sctp_ulpevent_free(ev);
3104 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3107 return SCTP_DISPOSITION_CONSUME;
3110 return SCTP_DISPOSITION_NOMEM;
3114 * Process an inbound SHUTDOWN ACK.
3117 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3118 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3119 * peer, and remove all record of the association.
3121 * The return value is the disposition.
3123 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3124 const struct sctp_association *asoc,
3125 const sctp_subtype_t type,
3127 sctp_cmd_seq_t *commands)
3129 struct sctp_chunk *chunk = arg;
3130 struct sctp_chunk *reply;
3131 struct sctp_ulpevent *ev;
3133 if (!sctp_vtag_verify(chunk, asoc))
3134 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3136 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3137 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3138 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3140 /* 10.2 H) SHUTDOWN COMPLETE notification
3142 * When SCTP completes the shutdown procedures (section 9.2) this
3143 * notification is passed to the upper layer.
3145 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3146 0, 0, 0, NULL, GFP_ATOMIC);
3150 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3151 reply = sctp_make_shutdown_complete(asoc, chunk);
3155 /* Do all the commands now (after allocation), so that we
3156 * have consistent state if memory allocation failes
3158 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3160 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3161 * stop the T2-shutdown timer,
3163 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3164 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3166 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3167 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3169 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3170 SCTP_STATE(SCTP_STATE_CLOSED));
3171 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3172 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3173 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3175 /* ...and remove all record of the association. */
3176 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3177 return SCTP_DISPOSITION_DELETE_TCB;
3180 sctp_ulpevent_free(ev);
3182 return SCTP_DISPOSITION_NOMEM;
3186 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3188 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3189 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3190 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3191 * packet must fill in the Verification Tag field of the outbound
3192 * packet with the Verification Tag received in the SHUTDOWN ACK and
3193 * set the T-bit in the Chunk Flags to indicate that the Verification
3196 * 8) The receiver should respond to the sender of the OOTB packet with
3197 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3198 * MUST fill in the Verification Tag field of the outbound packet
3199 * with the value found in the Verification Tag field of the OOTB
3200 * packet and set the T-bit in the Chunk Flags to indicate that the
3201 * Verification Tag is reflected. After sending this ABORT, the
3202 * receiver of the OOTB packet shall discard the OOTB packet and take
3203 * no further action.
3205 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3206 const struct sctp_association *asoc,
3207 const sctp_subtype_t type,
3209 sctp_cmd_seq_t *commands)
3211 struct sctp_chunk *chunk = arg;
3212 struct sk_buff *skb = chunk->skb;
3213 sctp_chunkhdr_t *ch;
3215 int ootb_shut_ack = 0;
3217 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
3219 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
3221 /* Report violation if the chunk is less then minimal */
3222 if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t))
3223 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3226 /* Now that we know we at least have a chunk header,
3227 * do things that are type appropriate.
3229 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
3232 /* RFC 2960, Section 3.3.7
3233 * Moreover, under any circumstances, an endpoint that
3234 * receives an ABORT MUST NOT respond to that ABORT by
3235 * sending an ABORT of its own.
3237 if (SCTP_CID_ABORT == ch->type)
3238 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3240 /* Report violation if chunk len overflows */
3241 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
3242 if (ch_end > skb_tail_pointer(skb))
3243 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3246 ch = (sctp_chunkhdr_t *) ch_end;
3247 } while (ch_end < skb_tail_pointer(skb));
3250 return sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
3252 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
3256 * Handle an "Out of the blue" SHUTDOWN ACK.
3258 * Section: 8.4 5, sctpimpguide 2.41.
3260 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3261 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3262 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3263 * packet must fill in the Verification Tag field of the outbound
3264 * packet with the Verification Tag received in the SHUTDOWN ACK and
3265 * set the T-bit in the Chunk Flags to indicate that the Verification
3269 * (endpoint, asoc, type, arg, commands)
3272 * (sctp_disposition_t)
3274 * The return value is the disposition of the chunk.
3276 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3277 const struct sctp_association *asoc,
3278 const sctp_subtype_t type,
3280 sctp_cmd_seq_t *commands)
3282 struct sctp_packet *packet = NULL;
3283 struct sctp_chunk *chunk = arg;
3284 struct sctp_chunk *shut;
3286 packet = sctp_ootb_pkt_new(asoc, chunk);
3289 /* Make an SHUTDOWN_COMPLETE.
3290 * The T bit will be set if the asoc is NULL.
3292 shut = sctp_make_shutdown_complete(asoc, chunk);
3294 sctp_ootb_pkt_free(packet);
3295 return SCTP_DISPOSITION_NOMEM;
3298 /* Reflect vtag if T-Bit is set */
3299 if (sctp_test_T_bit(shut))
3300 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
3302 /* Set the skb to the belonging sock for accounting. */
3303 shut->skb->sk = ep->base.sk;
3305 sctp_packet_append_chunk(packet, shut);
3307 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3308 SCTP_PACKET(packet));
3310 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
3312 /* If the chunk length is invalid, we don't want to process
3313 * the reset of the packet.
3315 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3316 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3318 /* We need to discard the rest of the packet to prevent
3319 * potential bomming attacks from additional bundled chunks.
3320 * This is documented in SCTP Threats ID.
3322 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3325 return SCTP_DISPOSITION_NOMEM;
3329 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3331 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3332 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3333 * procedures in section 8.4 SHOULD be followed, in other words it
3334 * should be treated as an Out Of The Blue packet.
3335 * [This means that we do NOT check the Verification Tag on these
3339 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3340 const struct sctp_association *asoc,
3341 const sctp_subtype_t type,
3343 sctp_cmd_seq_t *commands)
3345 struct sctp_chunk *chunk = arg;
3347 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3348 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3349 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3352 /* Although we do have an association in this case, it corresponds
3353 * to a restarted association. So the packet is treated as an OOTB
3354 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3355 * called with a NULL association.
3357 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3360 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3361 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3362 const struct sctp_association *asoc,
3363 const sctp_subtype_t type, void *arg,
3364 sctp_cmd_seq_t *commands)
3366 struct sctp_chunk *chunk = arg;
3367 struct sctp_chunk *asconf_ack = NULL;
3368 struct sctp_paramhdr *err_param = NULL;
3369 sctp_addiphdr_t *hdr;
3370 union sctp_addr_param *addr_param;
3374 if (!sctp_vtag_verify(chunk, asoc)) {
3375 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3377 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3380 /* ADD-IP: Section 4.1.1
3381 * This chunk MUST be sent in an authenticated way by using
3382 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3383 * is received unauthenticated it MUST be silently discarded as
3384 * described in [I-D.ietf-tsvwg-sctp-auth].
3386 if (!sctp_addip_noauth && !chunk->auth)
3387 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3389 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3390 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_addip_chunk_t)))
3391 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3394 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3395 serial = ntohl(hdr->serial);
3397 addr_param = (union sctp_addr_param *)hdr->params;
3398 length = ntohs(addr_param->p.length);
3399 if (length < sizeof(sctp_paramhdr_t))
3400 return sctp_sf_violation_paramlen(ep, asoc, type,
3401 (void *)addr_param, commands);
3403 /* Verify the ASCONF chunk before processing it. */
3404 if (!sctp_verify_asconf(asoc,
3405 (sctp_paramhdr_t *)((void *)addr_param + length),
3406 (void *)chunk->chunk_end,
3408 return sctp_sf_violation_paramlen(ep, asoc, type,
3409 (void *)&err_param, commands);
3411 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3412 * the endpoint stored in a new association variable
3413 * 'Peer-Serial-Number'.
3415 if (serial == asoc->peer.addip_serial + 1) {
3416 /* ADDIP 4.2 C2) If the value found in the serial number is
3417 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3420 asconf_ack = sctp_process_asconf((struct sctp_association *)
3423 return SCTP_DISPOSITION_NOMEM;
3424 } else if (serial == asoc->peer.addip_serial) {
3425 /* ADDIP 4.2 C3) If the value found in the serial number is
3426 * equal to the value stored in the 'Peer-Serial-Number'
3427 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3428 * to save the last ASCONF-ACK for some predetermined period of
3429 * time and instead of re-processing the ASCONF (with the same
3430 * serial number) it may just re-transmit the ASCONF-ACK.
3432 if (asoc->addip_last_asconf_ack)
3433 asconf_ack = asoc->addip_last_asconf_ack;
3435 return SCTP_DISPOSITION_DISCARD;
3437 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3438 * it must be either a stale packet or from an attacker.
3440 return SCTP_DISPOSITION_DISCARD;
3443 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3444 * back to the source address contained in the IP header of the ASCONF
3445 * being responded to.
3447 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3449 return SCTP_DISPOSITION_CONSUME;
3453 * ADDIP Section 4.3 General rules for address manipulation
3454 * When building TLV parameters for the ASCONF Chunk that will add or
3455 * delete IP addresses the D0 to D13 rules should be applied:
3457 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3458 const struct sctp_association *asoc,
3459 const sctp_subtype_t type, void *arg,
3460 sctp_cmd_seq_t *commands)
3462 struct sctp_chunk *asconf_ack = arg;
3463 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3464 struct sctp_chunk *abort;
3465 struct sctp_paramhdr *err_param = NULL;
3466 sctp_addiphdr_t *addip_hdr;
3467 __u32 sent_serial, rcvd_serial;
3469 if (!sctp_vtag_verify(asconf_ack, asoc)) {
3470 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3472 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3475 /* ADD-IP, Section 4.1.2:
3476 * This chunk MUST be sent in an authenticated way by using
3477 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3478 * is received unauthenticated it MUST be silently discarded as
3479 * described in [I-D.ietf-tsvwg-sctp-auth].
3481 if (!sctp_addip_noauth && !asconf_ack->auth)
3482 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
3484 /* Make sure that the ADDIP chunk has a valid length. */
3485 if (!sctp_chunk_length_valid(asconf_ack, sizeof(sctp_addip_chunk_t)))
3486 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3489 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3490 rcvd_serial = ntohl(addip_hdr->serial);
3492 /* Verify the ASCONF-ACK chunk before processing it. */
3493 if (!sctp_verify_asconf(asoc,
3494 (sctp_paramhdr_t *)addip_hdr->params,
3495 (void *)asconf_ack->chunk_end,
3497 return sctp_sf_violation_paramlen(ep, asoc, type,
3498 (void *)&err_param, commands);
3501 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3502 sent_serial = ntohl(addip_hdr->serial);
3504 sent_serial = asoc->addip_serial - 1;
3507 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3508 * equal to the next serial number to be used but no ASCONF chunk is
3509 * outstanding the endpoint MUST ABORT the association. Note that a
3510 * sequence number is greater than if it is no more than 2^^31-1
3511 * larger than the current sequence number (using serial arithmetic).
3513 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3514 !(asoc->addip_last_asconf)) {
3515 abort = sctp_make_abort(asoc, asconf_ack,
3516 sizeof(sctp_errhdr_t));
3518 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
3519 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3522 /* We are going to ABORT, so we might as well stop
3523 * processing the rest of the chunks in the packet.
3525 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3526 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3527 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3528 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3529 SCTP_ERROR(ECONNABORTED));
3530 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3531 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3532 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3533 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3534 return SCTP_DISPOSITION_ABORT;
3537 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3538 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3539 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3541 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3543 return SCTP_DISPOSITION_CONSUME;
3545 abort = sctp_make_abort(asoc, asconf_ack,
3546 sizeof(sctp_errhdr_t));
3548 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
3549 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3552 /* We are going to ABORT, so we might as well stop
3553 * processing the rest of the chunks in the packet.
3555 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3556 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
3557 SCTP_ERROR(ECONNABORTED));
3558 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3559 SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
3560 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3561 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3562 return SCTP_DISPOSITION_ABORT;
3565 return SCTP_DISPOSITION_DISCARD;
3569 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3571 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3572 * its cumulative TSN point to the value carried in the FORWARD TSN
3573 * chunk, and then MUST further advance its cumulative TSN point locally
3575 * After the above processing, the data receiver MUST stop reporting any
3576 * missing TSNs earlier than or equal to the new cumulative TSN point.
3578 * Verification Tag: 8.5 Verification Tag [Normal verification]
3580 * The return value is the disposition of the chunk.
3582 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3583 const struct sctp_association *asoc,
3584 const sctp_subtype_t type,
3586 sctp_cmd_seq_t *commands)
3588 struct sctp_chunk *chunk = arg;
3589 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3593 if (!sctp_vtag_verify(chunk, asoc)) {
3594 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3596 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3599 /* Make sure that the FORWARD_TSN chunk has valid length. */
3600 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3601 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3604 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3605 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3606 len = ntohs(chunk->chunk_hdr->length);
3607 len -= sizeof(struct sctp_chunkhdr);
3608 skb_pull(chunk->skb, len);
3610 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3611 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3613 /* The TSN is too high--silently discard the chunk and count on it
3614 * getting retransmitted later.
3616 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3617 goto discard_noforce;
3619 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3620 if (len > sizeof(struct sctp_fwdtsn_hdr))
3621 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3624 /* Count this as receiving DATA. */
3625 if (asoc->autoclose) {
3626 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3627 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3630 /* FIXME: For now send a SACK, but DATA processing may
3633 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3635 return SCTP_DISPOSITION_CONSUME;
3638 return SCTP_DISPOSITION_DISCARD;
3641 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3642 const struct sctp_endpoint *ep,
3643 const struct sctp_association *asoc,
3644 const sctp_subtype_t type,
3646 sctp_cmd_seq_t *commands)
3648 struct sctp_chunk *chunk = arg;
3649 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3653 if (!sctp_vtag_verify(chunk, asoc)) {
3654 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3656 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3659 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3660 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_fwdtsn_chunk)))
3661 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3664 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3665 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3666 len = ntohs(chunk->chunk_hdr->length);
3667 len -= sizeof(struct sctp_chunkhdr);
3668 skb_pull(chunk->skb, len);
3670 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3671 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3673 /* The TSN is too high--silently discard the chunk and count on it
3674 * getting retransmitted later.
3676 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3679 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3680 if (len > sizeof(struct sctp_fwdtsn_hdr))
3681 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3684 /* Go a head and force a SACK, since we are shutting down. */
3686 /* Implementor's Guide.
3688 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3689 * respond to each received packet containing one or more DATA chunk(s)
3690 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3692 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3693 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3694 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3695 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3697 return SCTP_DISPOSITION_CONSUME;
3701 * SCTP-AUTH Section 6.3 Receving authenticated chukns
3703 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3704 * Identifier field. If this algorithm was not specified by the
3705 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3706 * during association setup, the AUTH chunk and all chunks after it MUST
3707 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3708 * defined in Section 4.1.
3710 * If an endpoint with no shared key receives a Shared Key Identifier
3711 * other than 0, it MUST silently discard all authenticated chunks. If
3712 * the endpoint has at least one endpoint pair shared key for the peer,
3713 * it MUST use the key specified by the Shared Key Identifier if a
3714 * key has been configured for that Shared Key Identifier. If no
3715 * endpoint pair shared key has been configured for that Shared Key
3716 * Identifier, all authenticated chunks MUST be silently discarded.
3718 * Verification Tag: 8.5 Verification Tag [Normal verification]
3720 * The return value is the disposition of the chunk.
3722 static sctp_ierror_t sctp_sf_authenticate(const struct sctp_endpoint *ep,
3723 const struct sctp_association *asoc,
3724 const sctp_subtype_t type,
3725 struct sctp_chunk *chunk)
3727 struct sctp_authhdr *auth_hdr;
3728 struct sctp_hmac *hmac;
3729 unsigned int sig_len;
3734 /* Pull in the auth header, so we can do some more verification */
3735 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3736 chunk->subh.auth_hdr = auth_hdr;
3737 skb_pull(chunk->skb, sizeof(struct sctp_authhdr));
3739 /* Make sure that we suport the HMAC algorithm from the auth
3742 if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
3743 return SCTP_IERROR_AUTH_BAD_HMAC;
3745 /* Make sure that the provided shared key identifier has been
3748 key_id = ntohs(auth_hdr->shkey_id);
3749 if (key_id != asoc->active_key_id && !sctp_auth_get_shkey(asoc, key_id))
3750 return SCTP_IERROR_AUTH_BAD_KEYID;
3753 /* Make sure that the length of the signature matches what
3756 sig_len = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_auth_chunk_t);
3757 hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
3758 if (sig_len != hmac->hmac_len)
3759 return SCTP_IERROR_PROTO_VIOLATION;
3761 /* Now that we've done validation checks, we can compute and
3762 * verify the hmac. The steps involved are:
3763 * 1. Save the digest from the chunk.
3764 * 2. Zero out the digest in the chunk.
3765 * 3. Compute the new digest
3766 * 4. Compare saved and new digests.
3768 digest = auth_hdr->hmac;
3769 skb_pull(chunk->skb, sig_len);
3771 save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
3775 memset(digest, 0, sig_len);
3777 sctp_auth_calculate_hmac(asoc, chunk->skb,
3778 (struct sctp_auth_chunk *)chunk->chunk_hdr,
3781 /* Discard the packet if the digests do not match */
3782 if (memcmp(save_digest, digest, sig_len)) {
3784 return SCTP_IERROR_BAD_SIG;
3790 return SCTP_IERROR_NO_ERROR;
3792 return SCTP_IERROR_NOMEM;
3795 sctp_disposition_t sctp_sf_eat_auth(const struct sctp_endpoint *ep,
3796 const struct sctp_association *asoc,
3797 const sctp_subtype_t type,
3799 sctp_cmd_seq_t *commands)
3801 struct sctp_authhdr *auth_hdr;
3802 struct sctp_chunk *chunk = arg;
3803 struct sctp_chunk *err_chunk;
3804 sctp_ierror_t error;
3806 if (!sctp_vtag_verify(chunk, asoc)) {
3807 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3809 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3812 /* Make sure that the AUTH chunk has valid length. */
3813 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
3814 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3817 auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
3818 error = sctp_sf_authenticate(ep, asoc, type, chunk);
3820 case SCTP_IERROR_AUTH_BAD_HMAC:
3821 /* Generate the ERROR chunk and discard the rest
3824 err_chunk = sctp_make_op_error(asoc, chunk,
3825 SCTP_ERROR_UNSUP_HMAC,
3829 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3830 SCTP_CHUNK(err_chunk));
3833 case SCTP_IERROR_AUTH_BAD_KEYID:
3834 case SCTP_IERROR_BAD_SIG:
3835 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3837 case SCTP_IERROR_PROTO_VIOLATION:
3838 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3841 case SCTP_IERROR_NOMEM:
3842 return SCTP_DISPOSITION_NOMEM;
3847 if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
3848 struct sctp_ulpevent *ev;
3850 ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
3851 SCTP_AUTH_NEWKEY, GFP_ATOMIC);
3856 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
3860 return SCTP_DISPOSITION_CONSUME;
3864 * Process an unknown chunk.
3866 * Section: 3.2. Also, 2.1 in the implementor's guide.
3868 * Chunk Types are encoded such that the highest-order two bits specify
3869 * the action that must be taken if the processing endpoint does not
3870 * recognize the Chunk Type.
3872 * 00 - Stop processing this SCTP packet and discard it, do not process
3873 * any further chunks within it.
3875 * 01 - Stop processing this SCTP packet and discard it, do not process
3876 * any further chunks within it, and report the unrecognized
3877 * chunk in an 'Unrecognized Chunk Type'.
3879 * 10 - Skip this chunk and continue processing.
3881 * 11 - Skip this chunk and continue processing, but report in an ERROR
3882 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3884 * The return value is the disposition of the chunk.
3886 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3887 const struct sctp_association *asoc,
3888 const sctp_subtype_t type,
3890 sctp_cmd_seq_t *commands)
3892 struct sctp_chunk *unk_chunk = arg;
3893 struct sctp_chunk *err_chunk;
3894 sctp_chunkhdr_t *hdr;
3896 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3898 if (!sctp_vtag_verify(unk_chunk, asoc))
3899 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3901 /* Make sure that the chunk has a valid length.
3902 * Since we don't know the chunk type, we use a general
3903 * chunkhdr structure to make a comparison.
3905 if (!sctp_chunk_length_valid(unk_chunk, sizeof(sctp_chunkhdr_t)))
3906 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3909 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3910 case SCTP_CID_ACTION_DISCARD:
3911 /* Discard the packet. */
3912 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3914 case SCTP_CID_ACTION_DISCARD_ERR:
3915 /* Discard the packet. */
3916 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3918 /* Generate an ERROR chunk as response. */
3919 hdr = unk_chunk->chunk_hdr;
3920 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3921 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3922 WORD_ROUND(ntohs(hdr->length)));
3924 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3925 SCTP_CHUNK(err_chunk));
3927 return SCTP_DISPOSITION_CONSUME;
3929 case SCTP_CID_ACTION_SKIP:
3930 /* Skip the chunk. */
3931 return SCTP_DISPOSITION_DISCARD;
3933 case SCTP_CID_ACTION_SKIP_ERR:
3934 /* Generate an ERROR chunk as response. */
3935 hdr = unk_chunk->chunk_hdr;
3936 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3937 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3938 WORD_ROUND(ntohs(hdr->length)));
3940 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3941 SCTP_CHUNK(err_chunk));
3943 /* Skip the chunk. */
3944 return SCTP_DISPOSITION_CONSUME;
3950 return SCTP_DISPOSITION_DISCARD;
3954 * Discard the chunk.
3956 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3957 * [Too numerous to mention...]
3958 * Verification Tag: No verification needed.
3960 * (endpoint, asoc, chunk)
3963 * (asoc, reply_msg, msg_up, timers, counters)
3965 * The return value is the disposition of the chunk.
3967 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3968 const struct sctp_association *asoc,
3969 const sctp_subtype_t type,
3971 sctp_cmd_seq_t *commands)
3973 struct sctp_chunk *chunk = arg;
3975 /* Make sure that the chunk has a valid length.
3976 * Since we don't know the chunk type, we use a general
3977 * chunkhdr structure to make a comparison.
3979 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3980 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3983 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3984 return SCTP_DISPOSITION_DISCARD;
3988 * Discard the whole packet.
3992 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3993 * silently discard the OOTB packet and take no further action.
3995 * Verification Tag: No verification necessary
3998 * (endpoint, asoc, chunk)
4001 * (asoc, reply_msg, msg_up, timers, counters)
4003 * The return value is the disposition of the chunk.
4005 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
4006 const struct sctp_association *asoc,
4007 const sctp_subtype_t type,
4009 sctp_cmd_seq_t *commands)
4011 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS);
4012 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
4014 return SCTP_DISPOSITION_CONSUME;
4019 * The other end is violating protocol.
4021 * Section: Not specified
4022 * Verification Tag: Not specified
4024 * (endpoint, asoc, chunk)
4027 * (asoc, reply_msg, msg_up, timers, counters)
4029 * We simply tag the chunk as a violation. The state machine will log
4030 * the violation and continue.
4032 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
4033 const struct sctp_association *asoc,
4034 const sctp_subtype_t type,
4036 sctp_cmd_seq_t *commands)
4038 struct sctp_chunk *chunk = arg;
4040 /* Make sure that the chunk has a valid length. */
4041 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
4042 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4045 return SCTP_DISPOSITION_VIOLATION;
4049 * Common function to handle a protocol violation.
4051 static sctp_disposition_t sctp_sf_abort_violation(
4052 const struct sctp_endpoint *ep,
4053 const struct sctp_association *asoc,
4055 sctp_cmd_seq_t *commands,
4056 const __u8 *payload,
4057 const size_t paylen)
4059 struct sctp_packet *packet = NULL;
4060 struct sctp_chunk *chunk = arg;
4061 struct sctp_chunk *abort = NULL;
4063 /* SCTP-AUTH, Section 6.3:
4064 * It should be noted that if the receiver wants to tear
4065 * down an association in an authenticated way only, the
4066 * handling of malformed packets should not result in
4067 * tearing down the association.
4069 * This means that if we only want to abort associations
4070 * in an authenticated way (i.e AUTH+ABORT), then we
4071 * can't destory this association just becuase the packet
4074 if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
4077 /* Make the abort chunk. */
4078 abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
4083 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4084 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4086 if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
4087 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4088 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4089 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4090 SCTP_ERROR(ECONNREFUSED));
4091 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4092 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4094 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4095 SCTP_ERROR(ECONNABORTED));
4096 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4097 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
4098 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4101 packet = sctp_ootb_pkt_new(asoc, chunk);
4106 if (sctp_test_T_bit(abort))
4107 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
4109 abort->skb->sk = ep->base.sk;
4111 sctp_packet_append_chunk(packet, abort);
4113 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4114 SCTP_PACKET(packet));
4116 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4120 sctp_sf_pdiscard(ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
4122 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4124 return SCTP_DISPOSITION_ABORT;
4127 sctp_chunk_free(abort);
4129 return SCTP_DISPOSITION_NOMEM;
4133 * Handle a protocol violation when the chunk length is invalid.
4134 * "Invalid" length is identified as smaller then the minimal length a
4135 * given chunk can be. For example, a SACK chunk has invalid length
4136 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
4138 * We inform the other end by sending an ABORT with a Protocol Violation
4141 * Section: Not specified
4142 * Verification Tag: Nothing to do
4144 * (endpoint, asoc, chunk)
4147 * (reply_msg, msg_up, counters)
4149 * Generate an ABORT chunk and terminate the association.
4151 static sctp_disposition_t sctp_sf_violation_chunklen(
4152 const struct sctp_endpoint *ep,
4153 const struct sctp_association *asoc,
4154 const sctp_subtype_t type,
4156 sctp_cmd_seq_t *commands)
4158 char err_str[]="The following chunk had invalid length:";
4160 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4165 * Handle a protocol violation when the parameter length is invalid.
4166 * "Invalid" length is identified as smaller then the minimal length a
4167 * given parameter can be.
4169 static sctp_disposition_t sctp_sf_violation_paramlen(
4170 const struct sctp_endpoint *ep,
4171 const struct sctp_association *asoc,
4172 const sctp_subtype_t type,
4174 sctp_cmd_seq_t *commands) {
4175 char err_str[] = "The following parameter had invalid length:";
4177 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4181 /* Handle a protocol violation when the peer trying to advance the
4182 * cumulative tsn ack to a point beyond the max tsn currently sent.
4184 * We inform the other end by sending an ABORT with a Protocol Violation
4187 static sctp_disposition_t sctp_sf_violation_ctsn(
4188 const struct sctp_endpoint *ep,
4189 const struct sctp_association *asoc,
4190 const sctp_subtype_t type,
4192 sctp_cmd_seq_t *commands)
4194 char err_str[]="The cumulative tsn ack beyond the max tsn currently sent:";
4196 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4200 /* Handle protocol violation of an invalid chunk bundling. For example,
4201 * when we have an association and we recieve bundled INIT-ACK, or
4202 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4203 * statement from the specs. Additinally, there might be an attacker
4204 * on the path and we may not want to continue this communication.
4206 static sctp_disposition_t sctp_sf_violation_chunk(
4207 const struct sctp_endpoint *ep,
4208 const struct sctp_association *asoc,
4209 const sctp_subtype_t type,
4211 sctp_cmd_seq_t *commands)
4213 char err_str[]="The following chunk violates protocol:";
4216 return sctp_sf_violation(ep, asoc, type, arg, commands);
4218 return sctp_sf_abort_violation(ep, asoc, arg, commands, err_str,
4221 /***************************************************************************
4222 * These are the state functions for handling primitive (Section 10) events.
4223 ***************************************************************************/
4225 * sctp_sf_do_prm_asoc
4227 * Section: 10.1 ULP-to-SCTP
4230 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4231 * outbound stream count)
4232 * -> association id [,destination transport addr list] [,outbound stream
4235 * This primitive allows the upper layer to initiate an association to a
4236 * specific peer endpoint.
4238 * The peer endpoint shall be specified by one of the transport addresses
4239 * which defines the endpoint (see Section 1.4). If the local SCTP
4240 * instance has not been initialized, the ASSOCIATE is considered an
4242 * [This is not relevant for the kernel implementation since we do all
4243 * initialization at boot time. It we hadn't initialized we wouldn't
4244 * get anywhere near this code.]
4246 * An association id, which is a local handle to the SCTP association,
4247 * will be returned on successful establishment of the association. If
4248 * SCTP is not able to open an SCTP association with the peer endpoint,
4249 * an error is returned.
4250 * [In the kernel implementation, the struct sctp_association needs to
4251 * be created BEFORE causing this primitive to run.]
4253 * Other association parameters may be returned, including the
4254 * complete destination transport addresses of the peer as well as the
4255 * outbound stream count of the local endpoint. One of the transport
4256 * address from the returned destination addresses will be selected by
4257 * the local endpoint as default primary path for sending SCTP packets
4258 * to this peer. The returned "destination transport addr list" can
4259 * be used by the ULP to change the default primary path or to force
4260 * sending a packet to a specific transport address. [All of this
4261 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4264 * Mandatory attributes:
4266 * o local SCTP instance name - obtained from the INITIALIZE operation.
4267 * [This is the argument asoc.]
4268 * o destination transport addr - specified as one of the transport
4269 * addresses of the peer endpoint with which the association is to be
4271 * [This is asoc->peer.active_path.]
4272 * o outbound stream count - the number of outbound streams the ULP
4273 * would like to open towards this peer endpoint.
4274 * [BUG: This is not currently implemented.]
4275 * Optional attributes:
4279 * The return value is a disposition.
4281 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
4282 const struct sctp_association *asoc,
4283 const sctp_subtype_t type,
4285 sctp_cmd_seq_t *commands)
4287 struct sctp_chunk *repl;
4289 /* The comment below says that we enter COOKIE-WAIT AFTER
4290 * sending the INIT, but that doesn't actually work in our
4293 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4294 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
4296 /* RFC 2960 5.1 Normal Establishment of an Association
4298 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4299 * must provide its Verification Tag (Tag_A) in the Initiate
4300 * Tag field. Tag_A SHOULD be a random number in the range of
4301 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4304 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
4308 /* Cast away the const modifier, as we want to just
4309 * rerun it through as a sideffect.
4311 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
4312 SCTP_ASOC((struct sctp_association *) asoc));
4314 /* Choose transport for INIT. */
4315 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
4318 /* After sending the INIT, "A" starts the T1-init timer and
4319 * enters the COOKIE-WAIT state.
4321 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4322 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4323 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4324 return SCTP_DISPOSITION_CONSUME;
4327 return SCTP_DISPOSITION_NOMEM;
4331 * Process the SEND primitive.
4333 * Section: 10.1 ULP-to-SCTP
4336 * Format: SEND(association id, buffer address, byte count [,context]
4337 * [,stream id] [,life time] [,destination transport address]
4338 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4341 * This is the main method to send user data via SCTP.
4343 * Mandatory attributes:
4345 * o association id - local handle to the SCTP association
4347 * o buffer address - the location where the user message to be
4348 * transmitted is stored;
4350 * o byte count - The size of the user data in number of bytes;
4352 * Optional attributes:
4354 * o context - an optional 32 bit integer that will be carried in the
4355 * sending failure notification to the ULP if the transportation of
4356 * this User Message fails.
4358 * o stream id - to indicate which stream to send the data on. If not
4359 * specified, stream 0 will be used.
4361 * o life time - specifies the life time of the user data. The user data
4362 * will not be sent by SCTP after the life time expires. This
4363 * parameter can be used to avoid efforts to transmit stale
4364 * user messages. SCTP notifies the ULP if the data cannot be
4365 * initiated to transport (i.e. sent to the destination via SCTP's
4366 * send primitive) within the life time variable. However, the
4367 * user data will be transmitted if SCTP has attempted to transmit a
4368 * chunk before the life time expired.
4370 * o destination transport address - specified as one of the destination
4371 * transport addresses of the peer endpoint to which this packet
4372 * should be sent. Whenever possible, SCTP should use this destination
4373 * transport address for sending the packets, instead of the current
4376 * o unorder flag - this flag, if present, indicates that the user
4377 * would like the data delivered in an unordered fashion to the peer
4378 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4381 * o no-bundle flag - instructs SCTP not to bundle this user data with
4382 * other outbound DATA chunks. SCTP MAY still bundle even when
4383 * this flag is present, when faced with network congestion.
4385 * o payload protocol-id - A 32 bit unsigned integer that is to be
4386 * passed to the peer indicating the type of payload protocol data
4387 * being transmitted. This value is passed as opaque data by SCTP.
4389 * The return value is the disposition.
4391 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
4392 const struct sctp_association *asoc,
4393 const sctp_subtype_t type,
4395 sctp_cmd_seq_t *commands)
4397 struct sctp_chunk *chunk = arg;
4399 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4400 return SCTP_DISPOSITION_CONSUME;
4404 * Process the SHUTDOWN primitive.
4409 * Format: SHUTDOWN(association id)
4412 * Gracefully closes an association. Any locally queued user data
4413 * will be delivered to the peer. The association will be terminated only
4414 * after the peer acknowledges all the SCTP packets sent. A success code
4415 * will be returned on successful termination of the association. If
4416 * attempting to terminate the association results in a failure, an error
4417 * code shall be returned.
4419 * Mandatory attributes:
4421 * o association id - local handle to the SCTP association
4423 * Optional attributes:
4427 * The return value is the disposition.
4429 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
4430 const struct sctp_endpoint *ep,
4431 const struct sctp_association *asoc,
4432 const sctp_subtype_t type,
4434 sctp_cmd_seq_t *commands)
4438 /* From 9.2 Shutdown of an Association
4439 * Upon receipt of the SHUTDOWN primitive from its upper
4440 * layer, the endpoint enters SHUTDOWN-PENDING state and
4441 * remains there until all outstanding data has been
4442 * acknowledged by its peer. The endpoint accepts no new data
4443 * from its upper layer, but retransmits data to the far end
4444 * if necessary to fill gaps.
4446 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4447 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4449 /* sctpimpguide-05 Section 2.12.2
4450 * The sender of the SHUTDOWN MAY also start an overall guard timer
4451 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4453 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4454 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4456 disposition = SCTP_DISPOSITION_CONSUME;
4457 if (sctp_outq_is_empty(&asoc->outqueue)) {
4458 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4465 * Process the ABORT primitive.
4470 * Format: Abort(association id [, cause code])
4473 * Ungracefully closes an association. Any locally queued user data
4474 * will be discarded and an ABORT chunk is sent to the peer. A success code
4475 * will be returned on successful abortion of the association. If
4476 * attempting to abort the association results in a failure, an error
4477 * code shall be returned.
4479 * Mandatory attributes:
4481 * o association id - local handle to the SCTP association
4483 * Optional attributes:
4485 * o cause code - reason of the abort to be passed to the peer
4489 * The return value is the disposition.
4491 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
4492 const struct sctp_endpoint *ep,
4493 const struct sctp_association *asoc,
4494 const sctp_subtype_t type,
4496 sctp_cmd_seq_t *commands)
4498 /* From 9.1 Abort of an Association
4499 * Upon receipt of the ABORT primitive from its upper
4500 * layer, the endpoint enters CLOSED state and
4501 * discard all outstanding data has been
4502 * acknowledged by its peer. The endpoint accepts no new data
4503 * from its upper layer, but retransmits data to the far end
4504 * if necessary to fill gaps.
4506 struct sctp_chunk *abort = arg;
4507 sctp_disposition_t retval;
4509 retval = SCTP_DISPOSITION_CONSUME;
4511 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4513 /* Even if we can't send the ABORT due to low memory delete the
4514 * TCB. This is a departure from our typical NOMEM handling.
4517 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4518 SCTP_ERROR(ECONNABORTED));
4519 /* Delete the established association. */
4520 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4521 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4523 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4524 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4529 /* We tried an illegal operation on an association which is closed. */
4530 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
4531 const struct sctp_association *asoc,
4532 const sctp_subtype_t type,
4534 sctp_cmd_seq_t *commands)
4536 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
4537 return SCTP_DISPOSITION_CONSUME;
4540 /* We tried an illegal operation on an association which is shutting
4543 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
4544 const struct sctp_association *asoc,
4545 const sctp_subtype_t type,
4547 sctp_cmd_seq_t *commands)
4549 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
4550 SCTP_ERROR(-ESHUTDOWN));
4551 return SCTP_DISPOSITION_CONSUME;
4555 * sctp_cookie_wait_prm_shutdown
4557 * Section: 4 Note: 2
4562 * The RFC does not explicitly address this issue, but is the route through the
4563 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4568 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
4569 const struct sctp_endpoint *ep,
4570 const struct sctp_association *asoc,
4571 const sctp_subtype_t type,
4573 sctp_cmd_seq_t *commands)
4575 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4576 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4578 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4579 SCTP_STATE(SCTP_STATE_CLOSED));
4581 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
4583 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
4585 return SCTP_DISPOSITION_DELETE_TCB;
4589 * sctp_cookie_echoed_prm_shutdown
4591 * Section: 4 Note: 2
4596 * The RFC does not explcitly address this issue, but is the route through the
4597 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4602 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
4603 const struct sctp_endpoint *ep,
4604 const struct sctp_association *asoc,
4605 const sctp_subtype_t type,
4606 void *arg, sctp_cmd_seq_t *commands)
4608 /* There is a single T1 timer, so we should be able to use
4609 * common function with the COOKIE-WAIT state.
4611 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
4615 * sctp_sf_cookie_wait_prm_abort
4617 * Section: 4 Note: 2
4622 * The RFC does not explicitly address this issue, but is the route through the
4623 * state table when someone issues an abort while in COOKIE_WAIT state.
4628 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
4629 const struct sctp_endpoint *ep,
4630 const struct sctp_association *asoc,
4631 const sctp_subtype_t type,
4633 sctp_cmd_seq_t *commands)
4635 struct sctp_chunk *abort = arg;
4636 sctp_disposition_t retval;
4638 /* Stop T1-init timer */
4639 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4640 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
4641 retval = SCTP_DISPOSITION_CONSUME;
4643 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
4645 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4646 SCTP_STATE(SCTP_STATE_CLOSED));
4648 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4650 /* Even if we can't send the ABORT due to low memory delete the
4651 * TCB. This is a departure from our typical NOMEM handling.
4654 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
4655 SCTP_ERROR(ECONNREFUSED));
4656 /* Delete the established association. */
4657 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4658 SCTP_PERR(SCTP_ERROR_USER_ABORT));
4664 * sctp_sf_cookie_echoed_prm_abort
4666 * Section: 4 Note: 3
4671 * The RFC does not explcitly address this issue, but is the route through the
4672 * state table when someone issues an abort while in COOKIE_ECHOED state.
4677 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
4678 const struct sctp_endpoint *ep,
4679 const struct sctp_association *asoc,
4680 const sctp_subtype_t type,
4682 sctp_cmd_seq_t *commands)
4684 /* There is a single T1 timer, so we should be able to use
4685 * common function with the COOKIE-WAIT state.
4687 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
4691 * sctp_sf_shutdown_pending_prm_abort
4696 * The RFC does not explicitly address this issue, but is the route through the
4697 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4702 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
4703 const struct sctp_endpoint *ep,
4704 const struct sctp_association *asoc,
4705 const sctp_subtype_t type,
4707 sctp_cmd_seq_t *commands)
4709 /* Stop the T5-shutdown guard timer. */
4710 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4711 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4713 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4717 * sctp_sf_shutdown_sent_prm_abort
4722 * The RFC does not explicitly address this issue, but is the route through the
4723 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4728 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4729 const struct sctp_endpoint *ep,
4730 const struct sctp_association *asoc,
4731 const sctp_subtype_t type,
4733 sctp_cmd_seq_t *commands)
4735 /* Stop the T2-shutdown timer. */
4736 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4737 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4739 /* Stop the T5-shutdown guard timer. */
4740 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4741 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4743 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4747 * sctp_sf_cookie_echoed_prm_abort
4752 * The RFC does not explcitly address this issue, but is the route through the
4753 * state table when someone issues an abort while in COOKIE_ECHOED state.
4758 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4759 const struct sctp_endpoint *ep,
4760 const struct sctp_association *asoc,
4761 const sctp_subtype_t type,
4763 sctp_cmd_seq_t *commands)
4765 /* The same T2 timer, so we should be able to use
4766 * common function with the SHUTDOWN-SENT state.
4768 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4772 * Process the REQUESTHEARTBEAT primitive
4775 * J) Request Heartbeat
4777 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4781 * Instructs the local endpoint to perform a HeartBeat on the specified
4782 * destination transport address of the given association. The returned
4783 * result should indicate whether the transmission of the HEARTBEAT
4784 * chunk to the destination address is successful.
4786 * Mandatory attributes:
4788 * o association id - local handle to the SCTP association
4790 * o destination transport address - the transport address of the
4791 * association on which a heartbeat should be issued.
4793 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4794 const struct sctp_endpoint *ep,
4795 const struct sctp_association *asoc,
4796 const sctp_subtype_t type,
4798 sctp_cmd_seq_t *commands)
4800 if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
4801 (struct sctp_transport *)arg, commands))
4802 return SCTP_DISPOSITION_NOMEM;
4805 * RFC 2960 (bis), section 8.3
4807 * D) Request an on-demand HEARTBEAT on a specific destination
4808 * transport address of a given association.
4810 * The endpoint should increment the respective error counter of
4811 * the destination transport address each time a HEARTBEAT is sent
4812 * to that address and not acknowledged within one RTO.
4815 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
4816 SCTP_TRANSPORT(arg));
4817 return SCTP_DISPOSITION_CONSUME;
4821 * ADDIP Section 4.1 ASCONF Chunk Procedures
4822 * When an endpoint has an ASCONF signaled change to be sent to the
4823 * remote endpoint it should do A1 to A9
4825 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4826 const struct sctp_association *asoc,
4827 const sctp_subtype_t type,
4829 sctp_cmd_seq_t *commands)
4831 struct sctp_chunk *chunk = arg;
4833 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4834 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4835 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4836 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4837 return SCTP_DISPOSITION_CONSUME;
4841 * Ignore the primitive event
4843 * The return value is the disposition of the primitive.
4845 sctp_disposition_t sctp_sf_ignore_primitive(
4846 const struct sctp_endpoint *ep,
4847 const struct sctp_association *asoc,
4848 const sctp_subtype_t type,
4850 sctp_cmd_seq_t *commands)
4852 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4853 return SCTP_DISPOSITION_DISCARD;
4856 /***************************************************************************
4857 * These are the state functions for the OTHER events.
4858 ***************************************************************************/
4861 * Start the shutdown negotiation.
4864 * Once all its outstanding data has been acknowledged, the endpoint
4865 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4866 * TSN Ack field the last sequential TSN it has received from the peer.
4867 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4868 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4869 * with the updated last sequential TSN received from its peer.
4871 * The return value is the disposition.
4873 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4874 const struct sctp_endpoint *ep,
4875 const struct sctp_association *asoc,
4876 const sctp_subtype_t type,
4878 sctp_cmd_seq_t *commands)
4880 struct sctp_chunk *reply;
4882 /* Once all its outstanding data has been acknowledged, the
4883 * endpoint shall send a SHUTDOWN chunk to its peer including
4884 * in the Cumulative TSN Ack field the last sequential TSN it
4885 * has received from the peer.
4887 reply = sctp_make_shutdown(asoc, NULL);
4891 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4892 * T2-shutdown timer.
4894 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4896 /* It shall then start the T2-shutdown timer */
4897 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4898 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4900 if (asoc->autoclose)
4901 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4902 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4904 /* and enter the SHUTDOWN-SENT state. */
4905 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4906 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4908 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4910 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4913 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4915 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4917 return SCTP_DISPOSITION_CONSUME;
4920 return SCTP_DISPOSITION_NOMEM;
4924 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4928 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4929 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4930 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4931 * endpoint must re-send the SHUTDOWN ACK.
4933 * The return value is the disposition.
4935 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4936 const struct sctp_endpoint *ep,
4937 const struct sctp_association *asoc,
4938 const sctp_subtype_t type,
4940 sctp_cmd_seq_t *commands)
4942 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4943 struct sctp_chunk *reply;
4945 /* There are 2 ways of getting here:
4946 * 1) called in response to a SHUTDOWN chunk
4947 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4949 * For the case (2), the arg parameter is set to NULL. We need
4950 * to check that we have a chunk before accessing it's fields.
4953 if (!sctp_vtag_verify(chunk, asoc))
4954 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
4956 /* Make sure that the SHUTDOWN chunk has a valid length. */
4957 if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk_t)))
4958 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
4962 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4963 * shall send a SHUTDOWN ACK ...
4965 reply = sctp_make_shutdown_ack(asoc, chunk);
4969 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4970 * the T2-shutdown timer.
4972 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4974 /* and start/restart a T2-shutdown timer of its own, */
4975 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4976 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4978 if (asoc->autoclose)
4979 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4980 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4982 /* Enter the SHUTDOWN-ACK-SENT state. */
4983 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4984 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4986 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4988 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4991 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4993 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4995 return SCTP_DISPOSITION_CONSUME;
4998 return SCTP_DISPOSITION_NOMEM;
5002 * Ignore the event defined as other
5004 * The return value is the disposition of the event.
5006 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
5007 const struct sctp_association *asoc,
5008 const sctp_subtype_t type,
5010 sctp_cmd_seq_t *commands)
5012 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
5013 return SCTP_DISPOSITION_DISCARD;
5016 /************************************************************
5017 * These are the state functions for handling timeout events.
5018 ************************************************************/
5023 * Section: 6.3.3 Handle T3-rtx Expiration
5025 * Whenever the retransmission timer T3-rtx expires for a destination
5026 * address, do the following:
5029 * The return value is the disposition of the chunk.
5031 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
5032 const struct sctp_association *asoc,
5033 const sctp_subtype_t type,
5035 sctp_cmd_seq_t *commands)
5037 struct sctp_transport *transport = arg;
5039 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS);
5041 if (asoc->overall_error_count >= asoc->max_retrans) {
5042 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5043 SCTP_ERROR(ETIMEDOUT));
5044 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5045 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5046 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5047 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5048 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5049 return SCTP_DISPOSITION_DELETE_TCB;
5052 /* E1) For the destination address for which the timer
5053 * expires, adjust its ssthresh with rules defined in Section
5054 * 7.2.3 and set the cwnd <- MTU.
5057 /* E2) For the destination address for which the timer
5058 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5059 * maximum value discussed in rule C7 above (RTO.max) may be
5060 * used to provide an upper bound to this doubling operation.
5063 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5064 * outstanding DATA chunks for the address for which the
5065 * T3-rtx has expired will fit into a single packet, subject
5066 * to the MTU constraint for the path corresponding to the
5067 * destination transport address to which the retransmission
5068 * is being sent (this may be different from the address for
5069 * which the timer expires [see Section 6.4]). Call this
5070 * value K. Bundle and retransmit those K DATA chunks in a
5071 * single packet to the destination endpoint.
5073 * Note: Any DATA chunks that were sent to the address for
5074 * which the T3-rtx timer expired but did not fit in one MTU
5075 * (rule E3 above), should be marked for retransmission and
5076 * sent as soon as cwnd allows (normally when a SACK arrives).
5079 /* Do some failure management (Section 8.2). */
5080 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5082 /* NB: Rules E4 and F1 are implicit in R1. */
5083 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
5085 return SCTP_DISPOSITION_CONSUME;
5089 * Generate delayed SACK on timeout
5091 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5093 * The guidelines on delayed acknowledgement algorithm specified in
5094 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5095 * acknowledgement SHOULD be generated for at least every second packet
5096 * (not every second DATA chunk) received, and SHOULD be generated
5097 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5098 * some situations it may be beneficial for an SCTP transmitter to be
5099 * more conservative than the algorithms detailed in this document
5100 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5101 * the following algorithms allow.
5103 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
5104 const struct sctp_association *asoc,
5105 const sctp_subtype_t type,
5107 sctp_cmd_seq_t *commands)
5109 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS);
5110 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
5111 return SCTP_DISPOSITION_CONSUME;
5115 * sctp_sf_t1_init_timer_expire
5117 * Section: 4 Note: 2
5122 * RFC 2960 Section 4 Notes
5123 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5124 * and re-start the T1-init timer without changing state. This MUST
5125 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5126 * endpoint MUST abort the initialization process and report the
5127 * error to SCTP user.
5133 sctp_disposition_t sctp_sf_t1_init_timer_expire(const struct sctp_endpoint *ep,
5134 const struct sctp_association *asoc,
5135 const sctp_subtype_t type,
5137 sctp_cmd_seq_t *commands)
5139 struct sctp_chunk *repl = NULL;
5140 struct sctp_bind_addr *bp;
5141 int attempts = asoc->init_err_counter + 1;
5143 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5144 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS);
5146 if (attempts <= asoc->max_init_attempts) {
5147 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
5148 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
5150 return SCTP_DISPOSITION_NOMEM;
5152 /* Choose transport for INIT. */
5153 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
5156 /* Issue a sideeffect to do the needed accounting. */
5157 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
5158 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
5160 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5162 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5163 " max_init_attempts: %d\n",
5164 attempts, asoc->max_init_attempts);
5165 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5166 SCTP_ERROR(ETIMEDOUT));
5167 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5168 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5169 return SCTP_DISPOSITION_DELETE_TCB;
5172 return SCTP_DISPOSITION_CONSUME;
5176 * sctp_sf_t1_cookie_timer_expire
5178 * Section: 4 Note: 2
5183 * RFC 2960 Section 4 Notes
5184 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5185 * COOKIE ECHO and re-start the T1-cookie timer without changing
5186 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5187 * After that, the endpoint MUST abort the initialization process and
5188 * report the error to SCTP user.
5194 sctp_disposition_t sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint *ep,
5195 const struct sctp_association *asoc,
5196 const sctp_subtype_t type,
5198 sctp_cmd_seq_t *commands)
5200 struct sctp_chunk *repl = NULL;
5201 int attempts = asoc->init_err_counter + 1;
5203 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5204 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS);
5206 if (attempts <= asoc->max_init_attempts) {
5207 repl = sctp_make_cookie_echo(asoc, NULL);
5209 return SCTP_DISPOSITION_NOMEM;
5211 /* Issue a sideeffect to do the needed accounting. */
5212 sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
5213 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
5215 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
5217 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5218 SCTP_ERROR(ETIMEDOUT));
5219 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
5220 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5221 return SCTP_DISPOSITION_DELETE_TCB;
5224 return SCTP_DISPOSITION_CONSUME;
5227 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5228 * with the updated last sequential TSN received from its peer.
5230 * An endpoint should limit the number of retransmissions of the
5231 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5232 * If this threshold is exceeded the endpoint should destroy the TCB and
5233 * MUST report the peer endpoint unreachable to the upper layer (and
5234 * thus the association enters the CLOSED state). The reception of any
5235 * packet from its peer (i.e. as the peer sends all of its queued DATA
5236 * chunks) should clear the endpoint's retransmission count and restart
5237 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5238 * all of its queued DATA chunks that have not yet been sent.
5240 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
5241 const struct sctp_association *asoc,
5242 const sctp_subtype_t type,
5244 sctp_cmd_seq_t *commands)
5246 struct sctp_chunk *reply = NULL;
5248 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5249 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
5251 if (asoc->overall_error_count >= asoc->max_retrans) {
5252 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5253 SCTP_ERROR(ETIMEDOUT));
5254 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5255 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5256 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5257 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5258 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5259 return SCTP_DISPOSITION_DELETE_TCB;
5262 switch (asoc->state) {
5263 case SCTP_STATE_SHUTDOWN_SENT:
5264 reply = sctp_make_shutdown(asoc, NULL);
5267 case SCTP_STATE_SHUTDOWN_ACK_SENT:
5268 reply = sctp_make_shutdown_ack(asoc, NULL);
5279 /* Do some failure management (Section 8.2). */
5280 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
5281 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
5283 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5284 * the T2-shutdown timer.
5286 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
5288 /* Restart the T2-shutdown timer. */
5289 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5290 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
5291 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5292 return SCTP_DISPOSITION_CONSUME;
5295 return SCTP_DISPOSITION_NOMEM;
5299 * ADDIP Section 4.1 ASCONF CHunk Procedures
5300 * If the T4 RTO timer expires the endpoint should do B1 to B5
5302 sctp_disposition_t sctp_sf_t4_timer_expire(
5303 const struct sctp_endpoint *ep,
5304 const struct sctp_association *asoc,
5305 const sctp_subtype_t type,
5307 sctp_cmd_seq_t *commands)
5309 struct sctp_chunk *chunk = asoc->addip_last_asconf;
5310 struct sctp_transport *transport = chunk->transport;
5312 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS);
5314 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5315 * detection on the appropriate destination address as defined in
5316 * RFC2960 [5] section 8.1 and 8.2.
5318 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
5320 /* Reconfig T4 timer and transport. */
5321 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
5323 /* ADDIP 4.1 B2) Increment the association error counters and perform
5324 * endpoint failure detection on the association as defined in
5325 * RFC2960 [5] section 8.1 and 8.2.
5326 * association error counter is incremented in SCTP_CMD_STRIKE.
5328 if (asoc->overall_error_count >= asoc->max_retrans) {
5329 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
5330 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5331 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5332 SCTP_ERROR(ETIMEDOUT));
5333 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5334 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5335 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5336 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
5337 return SCTP_DISPOSITION_ABORT;
5340 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5341 * the ASCONF chunk was sent by doubling the RTO timer value.
5342 * This is done in SCTP_CMD_STRIKE.
5345 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5346 * choose an alternate destination address (please refer to RFC2960
5347 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5348 * chunk, it MUST be the same (including its serial number) as the last
5351 sctp_chunk_hold(asoc->addip_last_asconf);
5352 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5353 SCTP_CHUNK(asoc->addip_last_asconf));
5355 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5356 * destination is selected, then the RTO used will be that of the new
5357 * destination address.
5359 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
5360 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
5362 return SCTP_DISPOSITION_CONSUME;
5365 /* sctpimpguide-05 Section 2.12.2
5366 * The sender of the SHUTDOWN MAY also start an overall guard timer
5367 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5368 * At the expiration of this timer the sender SHOULD abort the association
5369 * by sending an ABORT chunk.
5371 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
5372 const struct sctp_association *asoc,
5373 const sctp_subtype_t type,
5375 sctp_cmd_seq_t *commands)
5377 struct sctp_chunk *reply = NULL;
5379 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5380 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
5382 reply = sctp_make_abort(asoc, NULL, 0);
5386 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
5387 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5388 SCTP_ERROR(ETIMEDOUT));
5389 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5390 SCTP_PERR(SCTP_ERROR_NO_ERROR));
5392 return SCTP_DISPOSITION_DELETE_TCB;
5394 return SCTP_DISPOSITION_NOMEM;
5397 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5398 * the association is automatically closed by starting the shutdown process.
5399 * The work that needs to be done is same as when SHUTDOWN is initiated by
5400 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5402 sctp_disposition_t sctp_sf_autoclose_timer_expire(
5403 const struct sctp_endpoint *ep,
5404 const struct sctp_association *asoc,
5405 const sctp_subtype_t type,
5407 sctp_cmd_seq_t *commands)
5411 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS);
5413 /* From 9.2 Shutdown of an Association
5414 * Upon receipt of the SHUTDOWN primitive from its upper
5415 * layer, the endpoint enters SHUTDOWN-PENDING state and
5416 * remains there until all outstanding data has been
5417 * acknowledged by its peer. The endpoint accepts no new data
5418 * from its upper layer, but retransmits data to the far end
5419 * if necessary to fill gaps.
5421 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
5422 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
5424 /* sctpimpguide-05 Section 2.12.2
5425 * The sender of the SHUTDOWN MAY also start an overall guard timer
5426 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5428 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
5429 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
5430 disposition = SCTP_DISPOSITION_CONSUME;
5431 if (sctp_outq_is_empty(&asoc->outqueue)) {
5432 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
5438 /*****************************************************************************
5439 * These are sa state functions which could apply to all types of events.
5440 ****************************************************************************/
5443 * This table entry is not implemented.
5446 * (endpoint, asoc, chunk)
5448 * The return value is the disposition of the chunk.
5450 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
5451 const struct sctp_association *asoc,
5452 const sctp_subtype_t type,
5454 sctp_cmd_seq_t *commands)
5456 return SCTP_DISPOSITION_NOT_IMPL;
5460 * This table entry represents a bug.
5463 * (endpoint, asoc, chunk)
5465 * The return value is the disposition of the chunk.
5467 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
5468 const struct sctp_association *asoc,
5469 const sctp_subtype_t type,
5471 sctp_cmd_seq_t *commands)
5473 return SCTP_DISPOSITION_BUG;
5477 * This table entry represents the firing of a timer in the wrong state.
5478 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5479 * when the association is in the wrong state. This event should
5480 * be ignored, so as to prevent any rearming of the timer.
5483 * (endpoint, asoc, chunk)
5485 * The return value is the disposition of the chunk.
5487 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
5488 const struct sctp_association *asoc,
5489 const sctp_subtype_t type,
5491 sctp_cmd_seq_t *commands)
5493 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
5494 return SCTP_DISPOSITION_CONSUME;
5497 /********************************************************************
5498 * 2nd Level Abstractions
5499 ********************************************************************/
5501 /* Pull the SACK chunk based on the SACK header. */
5502 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
5504 struct sctp_sackhdr *sack;
5509 /* Protect ourselves from reading too far into
5510 * the skb from a bogus sender.
5512 sack = (struct sctp_sackhdr *) chunk->skb->data;
5514 num_blocks = ntohs(sack->num_gap_ack_blocks);
5515 num_dup_tsns = ntohs(sack->num_dup_tsns);
5516 len = sizeof(struct sctp_sackhdr);
5517 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
5518 if (len > chunk->skb->len)
5521 skb_pull(chunk->skb, len);
5526 /* Create an ABORT packet to be sent as a response, with the specified
5529 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
5530 const struct sctp_association *asoc,
5531 struct sctp_chunk *chunk,
5532 const void *payload,
5535 struct sctp_packet *packet;
5536 struct sctp_chunk *abort;
5538 packet = sctp_ootb_pkt_new(asoc, chunk);
5542 * The T bit will be set if the asoc is NULL.
5544 abort = sctp_make_abort(asoc, chunk, paylen);
5546 sctp_ootb_pkt_free(packet);
5550 /* Reflect vtag if T-Bit is set */
5551 if (sctp_test_T_bit(abort))
5552 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
5554 /* Add specified error causes, i.e., payload, to the
5557 sctp_addto_chunk(abort, paylen, payload);
5559 /* Set the skb to the belonging sock for accounting. */
5560 abort->skb->sk = ep->base.sk;
5562 sctp_packet_append_chunk(packet, abort);
5569 /* Allocate a packet for responding in the OOTB conditions. */
5570 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
5571 const struct sctp_chunk *chunk)
5573 struct sctp_packet *packet;
5574 struct sctp_transport *transport;
5579 /* Get the source and destination port from the inbound packet. */
5580 sport = ntohs(chunk->sctp_hdr->dest);
5581 dport = ntohs(chunk->sctp_hdr->source);
5583 /* The V-tag is going to be the same as the inbound packet if no
5584 * association exists, otherwise, use the peer's vtag.
5587 /* Special case the INIT-ACK as there is no peer's vtag
5590 switch(chunk->chunk_hdr->type) {
5591 case SCTP_CID_INIT_ACK:
5593 sctp_initack_chunk_t *initack;
5595 initack = (sctp_initack_chunk_t *)chunk->chunk_hdr;
5596 vtag = ntohl(initack->init_hdr.init_tag);
5600 vtag = asoc->peer.i.init_tag;
5604 /* Special case the INIT and stale COOKIE_ECHO as there is no
5607 switch(chunk->chunk_hdr->type) {
5610 sctp_init_chunk_t *init;
5612 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
5613 vtag = ntohl(init->init_hdr.init_tag);
5617 vtag = ntohl(chunk->sctp_hdr->vtag);
5622 /* Make a transport for the bucket, Eliza... */
5623 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
5627 /* Cache a route for the transport with the chunk's destination as
5628 * the source address.
5630 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
5631 sctp_sk(sctp_get_ctl_sock()));
5633 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
5634 packet = sctp_packet_config(packet, vtag, 0);
5642 /* Free the packet allocated earlier for responding in the OOTB condition. */
5643 void sctp_ootb_pkt_free(struct sctp_packet *packet)
5645 sctp_transport_free(packet->transport);
5648 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5649 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
5650 const struct sctp_association *asoc,
5651 const struct sctp_chunk *chunk,
5652 sctp_cmd_seq_t *commands,
5653 struct sctp_chunk *err_chunk)
5655 struct sctp_packet *packet;
5658 packet = sctp_ootb_pkt_new(asoc, chunk);
5660 struct sctp_signed_cookie *cookie;
5662 /* Override the OOTB vtag from the cookie. */
5663 cookie = chunk->subh.cookie_hdr;
5664 packet->vtag = cookie->c.peer_vtag;
5666 /* Set the skb to the belonging sock for accounting. */
5667 err_chunk->skb->sk = ep->base.sk;
5668 sctp_packet_append_chunk(packet, err_chunk);
5669 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
5670 SCTP_PACKET(packet));
5671 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
5673 sctp_chunk_free (err_chunk);
5678 /* Process a data chunk */
5679 static int sctp_eat_data(const struct sctp_association *asoc,
5680 struct sctp_chunk *chunk,
5681 sctp_cmd_seq_t *commands)
5683 sctp_datahdr_t *data_hdr;
5684 struct sctp_chunk *err;
5686 sctp_verb_t deliver;
5689 struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
5690 struct sock *sk = asoc->base.sk;
5692 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
5693 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
5695 tsn = ntohl(data_hdr->tsn);
5696 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
5698 /* ASSERT: Now skb->data is really the user data. */
5700 /* Process ECN based congestion.
5702 * Since the chunk structure is reused for all chunks within
5703 * a packet, we use ecn_ce_done to track if we've already
5704 * done CE processing for this packet.
5706 * We need to do ECN processing even if we plan to discard the
5710 if (!chunk->ecn_ce_done) {
5712 chunk->ecn_ce_done = 1;
5714 af = sctp_get_af_specific(
5715 ipver2af(ip_hdr(chunk->skb)->version));
5717 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
5718 /* Do real work as sideffect. */
5719 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
5724 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
5726 /* The TSN is too high--silently discard the chunk and
5727 * count on it getting retransmitted later.
5729 return SCTP_IERROR_HIGH_TSN;
5730 } else if (tmp > 0) {
5731 /* This is a duplicate. Record it. */
5732 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
5733 return SCTP_IERROR_DUP_TSN;
5736 /* This is a new TSN. */
5738 /* Discard if there is no room in the receive window.
5739 * Actually, allow a little bit of overflow (up to a MTU).
5741 datalen = ntohs(chunk->chunk_hdr->length);
5742 datalen -= sizeof(sctp_data_chunk_t);
5744 deliver = SCTP_CMD_CHUNK_ULP;
5746 /* Think about partial delivery. */
5747 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
5749 /* Even if we don't accept this chunk there is
5752 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
5755 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5756 * seems a bit troublesome in that frag_point varies based on
5757 * PMTU. In cases, such as loopback, this might be a rather
5760 if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
5761 (datalen > asoc->rwnd + asoc->frag_point))) {
5763 /* If this is the next TSN, consider reneging to make
5764 * room. Note: Playing nice with a confused sender. A
5765 * malicious sender can still eat up all our buffer
5766 * space and in the future we may want to detect and
5767 * do more drastic reneging.
5769 if (sctp_tsnmap_has_gap(map) &&
5770 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5771 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
5772 deliver = SCTP_CMD_RENEGE;
5774 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5775 "rwnd: %d\n", tsn, datalen,
5777 return SCTP_IERROR_IGNORE_TSN;
5782 * Also try to renege to limit our memory usage in the event that
5783 * we are under memory pressure
5784 * If we can't renege, don't worry about it, the sk_stream_rmem_schedule
5785 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5786 * memory usage too much
5788 if (*sk->sk_prot_creator->memory_pressure) {
5789 if (sctp_tsnmap_has_gap(map) &&
5790 (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
5791 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn);
5792 deliver = SCTP_CMD_RENEGE;
5797 * Section 3.3.10.9 No User Data (9)
5801 * No User Data: This error cause is returned to the originator of a
5802 * DATA chunk if a received DATA chunk has no user data.
5804 if (unlikely(0 == datalen)) {
5805 err = sctp_make_abort_no_data(asoc, chunk, tsn);
5807 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5810 /* We are going to ABORT, so we might as well stop
5811 * processing the rest of the chunks in the packet.
5813 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
5814 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
5815 SCTP_ERROR(ECONNABORTED));
5816 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
5817 SCTP_PERR(SCTP_ERROR_NO_DATA));
5818 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
5819 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
5820 return SCTP_IERROR_NO_DATA;
5823 /* If definately accepting the DATA chunk, record its TSN, otherwise
5824 * wait for renege processing.
5826 if (SCTP_CMD_CHUNK_ULP == deliver)
5827 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
5829 chunk->data_accepted = 1;
5831 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5832 * if we renege and the chunk arrives again.
5834 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
5835 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
5837 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
5839 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5841 * If an endpoint receive a DATA chunk with an invalid stream
5842 * identifier, it shall acknowledge the reception of the DATA chunk
5843 * following the normal procedure, immediately send an ERROR chunk
5844 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5845 * and discard the DATA chunk.
5847 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
5848 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
5850 sizeof(data_hdr->stream));
5852 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
5854 return SCTP_IERROR_BAD_STREAM;
5857 /* Send the data up to the user. Note: Schedule the
5858 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5859 * chunk needs the updated rwnd.
5861 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
5863 return SCTP_IERROR_NO_ERROR;