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 /**********************************************************
69 * These are the state functions for handling chunk events.
70 **********************************************************/
73 * Process the final SHUTDOWN COMPLETE.
75 * Section: 4 (C) (diagram), 9.2
76 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
77 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
78 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
79 * should stop the T2-shutdown timer and remove all knowledge of the
80 * association (and thus the association enters the CLOSED state).
82 * Verification Tag: 8.5.1(C)
83 * C) Rules for packet carrying SHUTDOWN COMPLETE:
85 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet if the
86 * Verification Tag field of the packet matches its own tag OR it is
87 * set to its peer's tag and the T bit is set in the Chunk Flags.
88 * Otherwise, the receiver MUST silently discard the packet and take
89 * no further action. An endpoint MUST ignore the SHUTDOWN COMPLETE if
90 * it is not in the SHUTDOWN-ACK-SENT state.
93 * (endpoint, asoc, chunk)
96 * (asoc, reply_msg, msg_up, timers, counters)
98 * The return value is the disposition of the chunk.
100 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
101 const struct sctp_association *asoc,
102 const sctp_subtype_t type,
104 sctp_cmd_seq_t *commands)
106 struct sctp_chunk *chunk = arg;
107 struct sctp_ulpevent *ev;
109 /* RFC 2960 6.10 Bundling
111 * An endpoint MUST NOT bundle INIT, INIT ACK or
112 * SHUTDOWN COMPLETE with any other chunks.
114 if (!chunk->singleton)
115 return SCTP_DISPOSITION_VIOLATION;
117 if (!sctp_vtag_verify_either(chunk, asoc))
118 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
120 /* RFC 2960 10.2 SCTP-to-ULP
122 * H) SHUTDOWN COMPLETE notification
124 * When SCTP completes the shutdown procedures (section 9.2) this
125 * notification is passed to the upper layer.
127 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
128 0, 0, 0, GFP_ATOMIC);
132 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
134 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
135 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
136 * not the chunk should be discarded. If the endpoint is in
137 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
138 * T2-shutdown timer and remove all knowledge of the
139 * association (and thus the association enters the CLOSED
142 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
143 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
145 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
146 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
148 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
149 SCTP_STATE(SCTP_STATE_CLOSED));
151 SCTP_INC_STATS(SctpShutdowns);
152 SCTP_DEC_STATS(SctpCurrEstab);
154 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
156 return SCTP_DISPOSITION_DELETE_TCB;
159 return SCTP_DISPOSITION_NOMEM;
163 * Respond to a normal INIT chunk.
164 * We are the side that is being asked for an association.
166 * Section: 5.1 Normal Establishment of an Association, B
167 * B) "Z" shall respond immediately with an INIT ACK chunk. The
168 * destination IP address of the INIT ACK MUST be set to the source
169 * IP address of the INIT to which this INIT ACK is responding. In
170 * the response, besides filling in other parameters, "Z" must set the
171 * Verification Tag field to Tag_A, and also provide its own
172 * Verification Tag (Tag_Z) in the Initiate Tag field.
174 * Verification Tag: Must be 0.
177 * (endpoint, asoc, chunk)
180 * (asoc, reply_msg, msg_up, timers, counters)
182 * The return value is the disposition of the chunk.
184 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
185 const struct sctp_association *asoc,
186 const sctp_subtype_t type,
188 sctp_cmd_seq_t *commands)
190 struct sctp_chunk *chunk = arg;
191 struct sctp_chunk *repl;
192 struct sctp_association *new_asoc;
193 struct sctp_chunk *err_chunk;
194 struct sctp_packet *packet;
195 sctp_unrecognized_param_t *unk_param;
200 * An endpoint MUST NOT bundle INIT, INIT ACK or
201 * SHUTDOWN COMPLETE with any other chunks.
203 if (!chunk->singleton)
204 return SCTP_DISPOSITION_VIOLATION;
206 /* If the packet is an OOTB packet which is temporarily on the
207 * control endpoint, respond with an ABORT.
209 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
210 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
213 /* If the endpoint is not listening or if the number of associations
214 * on the TCP-style socket exceed the max backlog, respond with an
217 if (!sctp_sstate(sk, LISTENING) ||
218 (sctp_style(sk, TCP) &&
219 (sk->sk_ack_backlog >= sk->sk_max_ack_backlog)))
220 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
222 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
225 if (chunk->sctp_hdr->vtag != 0)
226 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
228 /* Verify the INIT chunk before processing it. */
230 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
231 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
233 /* This chunk contains fatal error. It is to be discarded.
234 * Send an ABORT, with causes if there is any.
237 packet = sctp_abort_pkt_new(ep, asoc, arg,
238 (__u8 *)(err_chunk->chunk_hdr) +
239 sizeof(sctp_chunkhdr_t),
240 ntohs(err_chunk->chunk_hdr->length) -
241 sizeof(sctp_chunkhdr_t));
243 sctp_chunk_free(err_chunk);
246 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
247 SCTP_PACKET(packet));
248 SCTP_INC_STATS(SctpOutCtrlChunks);
249 return SCTP_DISPOSITION_CONSUME;
251 return SCTP_DISPOSITION_NOMEM;
254 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
259 /* Grab the INIT header. */
260 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
262 /* Tag the variable length parameters. */
263 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
265 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
269 /* The call, sctp_process_init(), can fail on memory allocation. */
270 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
272 (sctp_init_chunk_t *)chunk->chunk_hdr,
276 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
278 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
280 /* If there are errors need to be reported for unknown parameters,
281 * make sure to reserve enough room in the INIT ACK for them.
285 len = ntohs(err_chunk->chunk_hdr->length) -
286 sizeof(sctp_chunkhdr_t);
288 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
291 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
295 /* If there are errors need to be reported for unknown parameters,
296 * include them in the outgoing INIT ACK as "Unrecognized parameter"
300 /* Get the "Unrecognized parameter" parameter(s) out of the
301 * ERROR chunk generated by sctp_verify_init(). Since the
302 * error cause code for "unknown parameter" and the
303 * "Unrecognized parameter" type is the same, we can
304 * construct the parameters in INIT ACK by copying the
307 unk_param = (sctp_unrecognized_param_t *)
308 ((__u8 *)(err_chunk->chunk_hdr) +
309 sizeof(sctp_chunkhdr_t));
310 /* Replace the cause code with the "Unrecognized parameter"
313 sctp_addto_chunk(repl, len, unk_param);
314 sctp_chunk_free(err_chunk);
317 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
320 * Note: After sending out INIT ACK with the State Cookie parameter,
321 * "Z" MUST NOT allocate any resources, nor keep any states for the
322 * new association. Otherwise, "Z" will be vulnerable to resource
325 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
327 return SCTP_DISPOSITION_DELETE_TCB;
331 sctp_chunk_free(err_chunk);
333 sctp_association_free(new_asoc);
335 return SCTP_DISPOSITION_NOMEM;
339 * Respond to a normal INIT ACK chunk.
340 * We are the side that is initiating the association.
342 * Section: 5.1 Normal Establishment of an Association, C
343 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
344 * timer and leave COOKIE-WAIT state. "A" shall then send the State
345 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
346 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
348 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
349 * DATA chunks, but it MUST be the first chunk in the packet and
350 * until the COOKIE ACK is returned the sender MUST NOT send any
351 * other packets to the peer.
353 * Verification Tag: 3.3.3
354 * If the value of the Initiate Tag in a received INIT ACK chunk is
355 * found to be 0, the receiver MUST treat it as an error and close the
356 * association by transmitting an ABORT.
359 * (endpoint, asoc, chunk)
362 * (asoc, reply_msg, msg_up, timers, counters)
364 * The return value is the disposition of the chunk.
366 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
367 const struct sctp_association *asoc,
368 const sctp_subtype_t type,
370 sctp_cmd_seq_t *commands)
372 struct sctp_chunk *chunk = arg;
373 sctp_init_chunk_t *initchunk;
375 struct sctp_chunk *err_chunk;
376 struct sctp_packet *packet;
377 sctp_disposition_t ret;
380 * An endpoint MUST NOT bundle INIT, INIT ACK or
381 * SHUTDOWN COMPLETE with any other chunks.
383 if (!chunk->singleton)
384 return SCTP_DISPOSITION_VIOLATION;
386 if (!sctp_vtag_verify(chunk, asoc))
387 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
389 /* Grab the INIT header. */
390 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
392 init_tag = ntohl(chunk->subh.init_hdr->init_tag);
394 /* Verification Tag: 3.3.3
395 * If the value of the Initiate Tag in a received INIT ACK
396 * chunk is found to be 0, the receiver MUST treat it as an
397 * error and close the association by transmitting an ABORT.
400 struct sctp_chunk *reply = sctp_make_abort(asoc, chunk, 0);
404 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
405 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
406 SCTP_STATE(SCTP_STATE_CLOSED));
407 SCTP_INC_STATS(SctpAborteds);
408 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
409 return SCTP_DISPOSITION_DELETE_TCB;
412 /* Verify the INIT chunk before processing it. */
414 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
415 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
418 SCTP_INC_STATS(SctpAborteds);
420 /* This chunk contains fatal error. It is to be discarded.
421 * Send an ABORT, with causes if there is any.
424 packet = sctp_abort_pkt_new(ep, asoc, arg,
425 (__u8 *)(err_chunk->chunk_hdr) +
426 sizeof(sctp_chunkhdr_t),
427 ntohs(err_chunk->chunk_hdr->length) -
428 sizeof(sctp_chunkhdr_t));
430 sctp_chunk_free(err_chunk);
433 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
434 SCTP_PACKET(packet));
435 SCTP_INC_STATS(SctpOutCtrlChunks);
436 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
437 SCTP_STATE(SCTP_STATE_CLOSED));
438 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
440 return SCTP_DISPOSITION_CONSUME;
442 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
443 SCTP_STATE(SCTP_STATE_CLOSED));
444 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
446 return SCTP_DISPOSITION_NOMEM;
449 ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
451 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
452 SCTP_STATE(SCTP_STATE_CLOSED));
453 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
459 /* Tag the variable length parameters. Note that we never
460 * convert the parameters in an INIT chunk.
462 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
464 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
466 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
467 SCTP_PEER_INIT(initchunk));
469 /* 5.1 C) "A" shall stop the T1-init timer and leave
470 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
471 * timer, and enter the COOKIE-ECHOED state.
473 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
474 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
475 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET,
476 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
477 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
478 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
479 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
480 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
482 /* 5.1 C) "A" shall then send the State Cookie received in the
483 * INIT ACK chunk in a COOKIE ECHO chunk, ...
485 /* If there is any errors to report, send the ERROR chunk generated
486 * for unknown parameters as well.
488 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
489 SCTP_CHUNK(err_chunk));
491 return SCTP_DISPOSITION_CONSUME;
494 return SCTP_DISPOSITION_NOMEM;
498 * Respond to a normal COOKIE ECHO chunk.
499 * We are the side that is being asked for an association.
501 * Section: 5.1 Normal Establishment of an Association, D
502 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
503 * with a COOKIE ACK chunk after building a TCB and moving to
504 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
505 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
506 * chunk MUST be the first chunk in the packet.
508 * IMPLEMENTATION NOTE: An implementation may choose to send the
509 * Communication Up notification to the SCTP user upon reception
510 * of a valid COOKIE ECHO chunk.
512 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
513 * D) Rules for packet carrying a COOKIE ECHO
515 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
516 * Initial Tag received in the INIT ACK.
518 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
521 * (endpoint, asoc, chunk)
524 * (asoc, reply_msg, msg_up, timers, counters)
526 * The return value is the disposition of the chunk.
528 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
529 const struct sctp_association *asoc,
530 const sctp_subtype_t type, void *arg,
531 sctp_cmd_seq_t *commands)
533 struct sctp_chunk *chunk = arg;
534 struct sctp_association *new_asoc;
535 sctp_init_chunk_t *peer_init;
536 struct sctp_chunk *repl;
537 struct sctp_ulpevent *ev;
539 struct sctp_chunk *err_chk_p;
541 /* If the packet is an OOTB packet which is temporarily on the
542 * control endpoint, respond with an ABORT.
544 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
545 return sctp_sf_ootb(ep, asoc, type, arg, commands);
547 /* "Decode" the chunk. We have no optional parameters so we
550 chunk->subh.cookie_hdr =
551 (struct sctp_signed_cookie *)chunk->skb->data;
553 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
555 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
556 * "Z" will reply with a COOKIE ACK chunk after building a TCB
557 * and moving to the ESTABLISHED state.
559 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
563 * If the re-build failed, what is the proper error path
566 * [We should abort the association. --piggy]
569 /* FIXME: Several errors are possible. A bad cookie should
570 * be silently discarded, but think about logging it too.
573 case -SCTP_IERROR_NOMEM:
576 case -SCTP_IERROR_STALE_COOKIE:
577 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
579 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
581 case -SCTP_IERROR_BAD_SIG:
583 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
587 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
588 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
589 SCTP_STATE(SCTP_STATE_ESTABLISHED));
590 SCTP_INC_STATS(SctpCurrEstab);
591 SCTP_INC_STATS(SctpPassiveEstabs);
592 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
594 if (new_asoc->autoclose)
595 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
596 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
598 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
600 /* Re-build the bind address for the association is done in
601 * the sctp_unpack_cookie() already.
603 /* This is a brand-new association, so these are not yet side
604 * effects--it is safe to run them here.
606 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
608 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
609 &chunk->subh.cookie_hdr->c.peer_addr,
610 peer_init, GFP_ATOMIC))
613 repl = sctp_make_cookie_ack(new_asoc, chunk);
617 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
619 /* RFC 2960 5.1 Normal Establishment of an Association
621 * D) IMPLEMENTATION NOTE: An implementation may choose to
622 * send the Communication Up notification to the SCTP user
623 * upon reception of a valid COOKIE ECHO chunk.
625 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
626 new_asoc->c.sinit_num_ostreams,
627 new_asoc->c.sinit_max_instreams,
632 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
634 return SCTP_DISPOSITION_CONSUME;
637 sctp_chunk_free(repl);
640 sctp_association_free(new_asoc);
642 return SCTP_DISPOSITION_NOMEM;
646 * Respond to a normal COOKIE ACK chunk.
647 * We are the side that is being asked for an association.
649 * RFC 2960 5.1 Normal Establishment of an Association
651 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
652 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
653 * timer. It may also notify its ULP about the successful
654 * establishment of the association with a Communication Up
655 * notification (see Section 10).
659 * (endpoint, asoc, chunk)
662 * (asoc, reply_msg, msg_up, timers, counters)
664 * The return value is the disposition of the chunk.
666 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
667 const struct sctp_association *asoc,
668 const sctp_subtype_t type, void *arg,
669 sctp_cmd_seq_t *commands)
671 struct sctp_chunk *chunk = arg;
672 struct sctp_ulpevent *ev;
674 if (!sctp_vtag_verify(chunk, asoc))
675 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
677 /* RFC 2960 5.1 Normal Establishment of an Association
679 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
680 * from the COOKIE-ECHOED state to the ESTABLISHED state,
681 * stopping the T1-cookie timer.
683 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
684 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
685 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
686 SCTP_STATE(SCTP_STATE_ESTABLISHED));
687 SCTP_INC_STATS(SctpCurrEstab);
688 SCTP_INC_STATS(SctpActiveEstabs);
689 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
691 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
692 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
693 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
695 /* It may also notify its ULP about the successful
696 * establishment of the association with a Communication Up
697 * notification (see Section 10).
699 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
700 0, asoc->c.sinit_num_ostreams,
701 asoc->c.sinit_max_instreams,
707 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
709 return SCTP_DISPOSITION_CONSUME;
711 return SCTP_DISPOSITION_NOMEM;
714 /* Generate and sendout a heartbeat packet. */
715 sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
716 const struct sctp_association *asoc,
717 const sctp_subtype_t type,
719 sctp_cmd_seq_t *commands)
721 struct sctp_transport *transport = (struct sctp_transport *) arg;
722 struct sctp_chunk *reply;
723 sctp_sender_hb_info_t hbinfo;
726 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
727 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
728 hbinfo.daddr = transport->ipaddr;
729 hbinfo.sent_at = jiffies;
731 /* Send a heartbeat to our peer. */
732 paylen = sizeof(sctp_sender_hb_info_t);
733 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
735 return SCTP_DISPOSITION_NOMEM;
737 /* Set rto_pending indicating that an RTT measurement
738 * is started with this heartbeat chunk.
740 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
741 SCTP_TRANSPORT(transport));
743 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
744 return SCTP_DISPOSITION_CONSUME;
747 /* Generate a HEARTBEAT packet on the given transport. */
748 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
749 const struct sctp_association *asoc,
750 const sctp_subtype_t type,
752 sctp_cmd_seq_t *commands)
754 struct sctp_transport *transport = (struct sctp_transport *) arg;
756 if (asoc->overall_error_count > asoc->max_retrans) {
757 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
758 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
759 SCTP_U32(SCTP_ERROR_NO_ERROR));
760 SCTP_INC_STATS(SctpAborteds);
761 SCTP_DEC_STATS(SctpCurrEstab);
762 return SCTP_DISPOSITION_DELETE_TCB;
766 * The Sender-specific Heartbeat Info field should normally include
767 * information about the sender's current time when this HEARTBEAT
768 * chunk is sent and the destination transport address to which this
769 * HEARTBEAT is sent (see Section 8.3).
772 if (transport->hb_allowed) {
773 if (SCTP_DISPOSITION_NOMEM ==
774 sctp_sf_heartbeat(ep, asoc, type, arg,
776 return SCTP_DISPOSITION_NOMEM;
777 /* Set transport error counter and association error counter
778 * when sending heartbeat.
780 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
781 SCTP_TRANSPORT(transport));
783 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
784 SCTP_TRANSPORT(transport));
786 return SCTP_DISPOSITION_CONSUME;
790 * Process an heartbeat request.
792 * Section: 8.3 Path Heartbeat
793 * The receiver of the HEARTBEAT should immediately respond with a
794 * HEARTBEAT ACK that contains the Heartbeat Information field copied
795 * from the received HEARTBEAT chunk.
797 * Verification Tag: 8.5 Verification Tag [Normal verification]
798 * When receiving an SCTP packet, the endpoint MUST ensure that the
799 * value in the Verification Tag field of the received SCTP packet
800 * matches its own Tag. If the received Verification Tag value does not
801 * match the receiver's own tag value, the receiver shall silently
802 * discard the packet and shall not process it any further except for
803 * those cases listed in Section 8.5.1 below.
806 * (endpoint, asoc, chunk)
809 * (asoc, reply_msg, msg_up, timers, counters)
811 * The return value is the disposition of the chunk.
813 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
814 const struct sctp_association *asoc,
815 const sctp_subtype_t type,
817 sctp_cmd_seq_t *commands)
819 struct sctp_chunk *chunk = arg;
820 struct sctp_chunk *reply;
823 if (!sctp_vtag_verify(chunk, asoc))
824 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
826 /* 8.3 The receiver of the HEARTBEAT should immediately
827 * respond with a HEARTBEAT ACK that contains the Heartbeat
828 * Information field copied from the received HEARTBEAT chunk.
830 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
831 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
832 skb_pull(chunk->skb, paylen);
834 reply = sctp_make_heartbeat_ack(asoc, chunk,
835 chunk->subh.hb_hdr, paylen);
839 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
840 return SCTP_DISPOSITION_CONSUME;
843 return SCTP_DISPOSITION_NOMEM;
847 * Process the returning HEARTBEAT ACK.
849 * Section: 8.3 Path Heartbeat
850 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
851 * should clear the error counter of the destination transport
852 * address to which the HEARTBEAT was sent, and mark the destination
853 * transport address as active if it is not so marked. The endpoint may
854 * optionally report to the upper layer when an inactive destination
855 * address is marked as active due to the reception of the latest
856 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
857 * clear the association overall error count as well (as defined
860 * The receiver of the HEARTBEAT ACK should also perform an RTT
861 * measurement for that destination transport address using the time
862 * value carried in the HEARTBEAT ACK chunk.
864 * Verification Tag: 8.5 Verification Tag [Normal verification]
867 * (endpoint, asoc, chunk)
870 * (asoc, reply_msg, msg_up, timers, counters)
872 * The return value is the disposition of the chunk.
874 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
875 const struct sctp_association *asoc,
876 const sctp_subtype_t type,
878 sctp_cmd_seq_t *commands)
880 struct sctp_chunk *chunk = arg;
881 union sctp_addr from_addr;
882 struct sctp_transport *link;
883 sctp_sender_hb_info_t *hbinfo;
884 unsigned long max_interval;
886 if (!sctp_vtag_verify(chunk, asoc))
887 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
889 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
890 from_addr = hbinfo->daddr;
891 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
893 /* This should never happen, but lets log it if so. */
896 "%s: Could not find address %d.%d.%d.%d\n",
897 __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr));
898 return SCTP_DISPOSITION_DISCARD;
901 max_interval = link->hb_interval + link->rto;
903 /* Check if the timestamp looks valid. */
904 if (time_after(hbinfo->sent_at, jiffies) ||
905 time_after(jiffies, hbinfo->sent_at + max_interval)) {
906 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
907 "received for transport: %p\n",
909 return SCTP_DISPOSITION_DISCARD;
912 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
913 * the HEARTBEAT should clear the error counter of the
914 * destination transport address to which the HEARTBEAT was
915 * sent and mark the destination transport address as active if
916 * it is not so marked.
918 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
920 return SCTP_DISPOSITION_CONSUME;
923 /* Helper function to send out an abort for the restart
926 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
927 struct sctp_chunk *init,
928 sctp_cmd_seq_t *commands)
931 struct sctp_packet *pkt;
932 union sctp_addr_param *addrparm;
933 struct sctp_errhdr *errhdr;
934 struct sctp_endpoint *ep;
935 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
936 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
938 /* Build the error on the stack. We are way to malloc crazy
939 * throughout the code today.
941 errhdr = (struct sctp_errhdr *)buffer;
942 addrparm = (union sctp_addr_param *)errhdr->variable;
944 /* Copy into a parm format. */
945 len = af->to_addr_param(ssa, addrparm);
946 len += sizeof(sctp_errhdr_t);
948 errhdr->cause = SCTP_ERROR_RESTART;
949 errhdr->length = htons(len);
951 /* Assign to the control socket. */
952 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
954 /* Association is NULL since this may be a restart attack and we
955 * want to send back the attacker's vtag.
957 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
961 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
963 SCTP_INC_STATS(SctpOutCtrlChunks);
965 /* Discard the rest of the inbound packet. */
966 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
969 /* Even if there is no memory, treat as a failure so
970 * the packet will get dropped.
975 /* A restart is occurring, check to make sure no new addresses
976 * are being added as we may be under a takeover attack.
978 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
979 const struct sctp_association *asoc,
980 struct sctp_chunk *init,
981 sctp_cmd_seq_t *commands)
983 struct sctp_transport *new_addr, *addr;
984 struct list_head *pos, *pos2;
987 /* Implementor's Guide - Sectin 5.2.2
989 * Before responding the endpoint MUST check to see if the
990 * unexpected INIT adds new addresses to the association. If new
991 * addresses are added to the association, the endpoint MUST respond
995 /* Search through all current addresses and make sure
996 * we aren't adding any new ones.
1001 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1002 new_addr = list_entry(pos, struct sctp_transport, transports);
1004 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1005 addr = list_entry(pos2, struct sctp_transport,
1007 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1017 /* If a new address was added, ABORT the sender. */
1018 if (!found && new_addr) {
1019 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1022 /* Return success if all addresses were found. */
1026 /* Populate the verification/tie tags based on overlapping INIT
1029 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1031 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1032 const struct sctp_association *asoc)
1034 switch (asoc->state) {
1036 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1038 case SCTP_STATE_COOKIE_WAIT:
1039 new_asoc->c.my_vtag = asoc->c.my_vtag;
1040 new_asoc->c.my_ttag = asoc->c.my_vtag;
1041 new_asoc->c.peer_ttag = 0;
1044 case SCTP_STATE_COOKIE_ECHOED:
1045 new_asoc->c.my_vtag = asoc->c.my_vtag;
1046 new_asoc->c.my_ttag = asoc->c.my_vtag;
1047 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1050 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1051 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1054 new_asoc->c.my_ttag = asoc->c.my_vtag;
1055 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1059 /* Other parameters for the endpoint SHOULD be copied from the
1060 * existing parameters of the association (e.g. number of
1061 * outbound streams) into the INIT ACK and cookie.
1063 new_asoc->rwnd = asoc->rwnd;
1064 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1065 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1066 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1070 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1073 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1075 * Returns value representing action to be taken. These action values
1076 * correspond to Action/Description values in RFC 2960, Table 2.
1078 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1079 const struct sctp_association *asoc)
1081 /* In this case, the peer may have restarted. */
1082 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1083 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1084 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1085 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1088 /* Collision case B. */
1089 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1090 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1091 (0 == asoc->c.peer_vtag))) {
1095 /* Collision case D. */
1096 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1097 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1100 /* Collision case C. */
1101 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1102 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1103 (0 == new_asoc->c.my_ttag) &&
1104 (0 == new_asoc->c.peer_ttag))
1107 /* No match to any of the special cases; discard this packet. */
1111 /* Common helper routine for both duplicate and simulataneous INIT
1114 static sctp_disposition_t sctp_sf_do_unexpected_init(
1115 const struct sctp_endpoint *ep,
1116 const struct sctp_association *asoc,
1117 const sctp_subtype_t type,
1118 void *arg, sctp_cmd_seq_t *commands)
1120 sctp_disposition_t retval;
1121 struct sctp_chunk *chunk = arg;
1122 struct sctp_chunk *repl;
1123 struct sctp_association *new_asoc;
1124 struct sctp_chunk *err_chunk;
1125 struct sctp_packet *packet;
1126 sctp_unrecognized_param_t *unk_param;
1130 * An endpoint MUST NOT bundle INIT, INIT ACK or
1131 * SHUTDOWN COMPLETE with any other chunks.
1133 if (!chunk->singleton)
1134 return SCTP_DISPOSITION_VIOLATION;
1136 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1139 if (chunk->sctp_hdr->vtag != 0)
1140 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1142 /* Grab the INIT header. */
1143 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1145 /* Tag the variable length parameters. */
1146 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1148 /* Verify the INIT chunk before processing it. */
1150 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1151 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1153 /* This chunk contains fatal error. It is to be discarded.
1154 * Send an ABORT, with causes if there is any.
1157 packet = sctp_abort_pkt_new(ep, asoc, arg,
1158 (__u8 *)(err_chunk->chunk_hdr) +
1159 sizeof(sctp_chunkhdr_t),
1160 ntohs(err_chunk->chunk_hdr->length) -
1161 sizeof(sctp_chunkhdr_t));
1164 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1165 SCTP_PACKET(packet));
1166 SCTP_INC_STATS(SctpOutCtrlChunks);
1167 retval = SCTP_DISPOSITION_CONSUME;
1169 retval = SCTP_DISPOSITION_NOMEM;
1173 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1179 * Other parameters for the endpoint SHOULD be copied from the
1180 * existing parameters of the association (e.g. number of
1181 * outbound streams) into the INIT ACK and cookie.
1182 * FIXME: We are copying parameters from the endpoint not the
1185 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1189 /* In the outbound INIT ACK the endpoint MUST copy its current
1190 * Verification Tag and Peers Verification tag into a reserved
1191 * place (local tie-tag and per tie-tag) within the state cookie.
1193 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1195 (sctp_init_chunk_t *)chunk->chunk_hdr,
1197 retval = SCTP_DISPOSITION_NOMEM;
1201 /* Make sure no new addresses are being added during the
1202 * restart. Do not do this check for COOKIE-WAIT state,
1203 * since there are no peer addresses to check against.
1204 * Upon return an ABORT will have been sent if needed.
1206 if (!sctp_state(asoc, COOKIE_WAIT)) {
1207 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1209 retval = SCTP_DISPOSITION_CONSUME;
1214 sctp_tietags_populate(new_asoc, asoc);
1216 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1218 /* If there are errors need to be reported for unknown parameters,
1219 * make sure to reserve enough room in the INIT ACK for them.
1223 len = ntohs(err_chunk->chunk_hdr->length) -
1224 sizeof(sctp_chunkhdr_t);
1227 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1230 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1234 /* If there are errors need to be reported for unknown parameters,
1235 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1239 /* Get the "Unrecognized parameter" parameter(s) out of the
1240 * ERROR chunk generated by sctp_verify_init(). Since the
1241 * error cause code for "unknown parameter" and the
1242 * "Unrecognized parameter" type is the same, we can
1243 * construct the parameters in INIT ACK by copying the
1244 * ERROR causes over.
1246 unk_param = (sctp_unrecognized_param_t *)
1247 ((__u8 *)(err_chunk->chunk_hdr) +
1248 sizeof(sctp_chunkhdr_t));
1249 /* Replace the cause code with the "Unrecognized parameter"
1252 sctp_addto_chunk(repl, len, unk_param);
1255 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1256 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1259 * Note: After sending out INIT ACK with the State Cookie parameter,
1260 * "Z" MUST NOT allocate any resources for this new association.
1261 * Otherwise, "Z" will be vulnerable to resource attacks.
1263 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1264 retval = SCTP_DISPOSITION_CONSUME;
1268 sctp_chunk_free(err_chunk);
1271 retval = SCTP_DISPOSITION_NOMEM;
1275 sctp_association_free(new_asoc);
1280 * Handle simultanous INIT.
1281 * This means we started an INIT and then we got an INIT request from
1284 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1285 * This usually indicates an initialization collision, i.e., each
1286 * endpoint is attempting, at about the same time, to establish an
1287 * association with the other endpoint.
1289 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1290 * endpoint MUST respond with an INIT ACK using the same parameters it
1291 * sent in its original INIT chunk (including its Verification Tag,
1292 * unchanged). These original parameters are combined with those from the
1293 * newly received INIT chunk. The endpoint shall also generate a State
1294 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1295 * INIT to calculate the State Cookie.
1297 * After that, the endpoint MUST NOT change its state, the T1-init
1298 * timer shall be left running and the corresponding TCB MUST NOT be
1299 * destroyed. The normal procedures for handling State Cookies when
1300 * a TCB exists will resolve the duplicate INITs to a single association.
1302 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1303 * its Tie-Tags with the Tag information of itself and its peer (see
1304 * section 5.2.2 for a description of the Tie-Tags).
1306 * Verification Tag: Not explicit, but an INIT can not have a valid
1307 * verification tag, so we skip the check.
1310 * (endpoint, asoc, chunk)
1313 * (asoc, reply_msg, msg_up, timers, counters)
1315 * The return value is the disposition of the chunk.
1317 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1318 const struct sctp_association *asoc,
1319 const sctp_subtype_t type,
1321 sctp_cmd_seq_t *commands)
1323 /* Call helper to do the real work for both simulataneous and
1324 * duplicate INIT chunk handling.
1326 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1330 * Handle duplicated INIT messages. These are usually delayed
1333 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1334 * COOKIE-ECHOED and COOKIE-WAIT
1336 * Unless otherwise stated, upon reception of an unexpected INIT for
1337 * this association, the endpoint shall generate an INIT ACK with a
1338 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1339 * current Verification Tag and peer's Verification Tag into a reserved
1340 * place within the state cookie. We shall refer to these locations as
1341 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1342 * containing this INIT ACK MUST carry a Verification Tag value equal to
1343 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1344 * MUST contain a new Initiation Tag (randomly generated see Section
1345 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1346 * existing parameters of the association (e.g. number of outbound
1347 * streams) into the INIT ACK and cookie.
1349 * After sending out the INIT ACK, the endpoint shall take no further
1350 * actions, i.e., the existing association, including its current state,
1351 * and the corresponding TCB MUST NOT be changed.
1353 * Note: Only when a TCB exists and the association is not in a COOKIE-
1354 * WAIT state are the Tie-Tags populated. For a normal association INIT
1355 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1356 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1357 * State Cookie are populated as specified in section 5.2.1.
1359 * Verification Tag: Not specified, but an INIT has no way of knowing
1360 * what the verification tag could be, so we ignore it.
1363 * (endpoint, asoc, chunk)
1366 * (asoc, reply_msg, msg_up, timers, counters)
1368 * The return value is the disposition of the chunk.
1370 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1371 const struct sctp_association *asoc,
1372 const sctp_subtype_t type,
1374 sctp_cmd_seq_t *commands)
1376 /* Call helper to do the real work for both simulataneous and
1377 * duplicate INIT chunk handling.
1379 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1384 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1387 * A) In this case, the peer may have restarted.
1389 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1390 const struct sctp_association *asoc,
1391 struct sctp_chunk *chunk,
1392 sctp_cmd_seq_t *commands,
1393 struct sctp_association *new_asoc)
1395 sctp_init_chunk_t *peer_init;
1396 struct sctp_ulpevent *ev;
1397 struct sctp_chunk *repl;
1398 struct sctp_chunk *err;
1399 sctp_disposition_t disposition;
1401 /* new_asoc is a brand-new association, so these are not yet
1402 * side effects--it is safe to run them here.
1404 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1406 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1407 sctp_source(chunk), peer_init,
1411 /* Make sure no new addresses are being added during the
1412 * restart. Though this is a pretty complicated attack
1413 * since you'd have to get inside the cookie.
1415 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1416 return SCTP_DISPOSITION_CONSUME;
1419 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1420 * the peer has restarted (Action A), it MUST NOT setup a new
1421 * association but instead resend the SHUTDOWN ACK and send an ERROR
1422 * chunk with a "Cookie Received while Shutting Down" error cause to
1425 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1426 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1427 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1429 if (SCTP_DISPOSITION_NOMEM == disposition)
1432 err = sctp_make_op_error(asoc, chunk,
1433 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1436 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1439 return SCTP_DISPOSITION_CONSUME;
1442 /* For now, fail any unsent/unacked data. Consider the optional
1443 * choice of resending of this data.
1445 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1447 /* Update the content of current association. */
1448 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1450 repl = sctp_make_cookie_ack(new_asoc, chunk);
1454 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1456 /* Report association restart to upper layer. */
1457 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1458 new_asoc->c.sinit_num_ostreams,
1459 new_asoc->c.sinit_max_instreams,
1464 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1465 return SCTP_DISPOSITION_CONSUME;
1468 sctp_chunk_free(repl);
1470 return SCTP_DISPOSITION_NOMEM;
1473 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1476 * B) In this case, both sides may be attempting to start an association
1477 * at about the same time but the peer endpoint started its INIT
1478 * after responding to the local endpoint's INIT
1480 /* This case represents an initialization collision. */
1481 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1482 const struct sctp_association *asoc,
1483 struct sctp_chunk *chunk,
1484 sctp_cmd_seq_t *commands,
1485 struct sctp_association *new_asoc)
1487 sctp_init_chunk_t *peer_init;
1488 struct sctp_ulpevent *ev;
1489 struct sctp_chunk *repl;
1491 /* new_asoc is a brand-new association, so these are not yet
1492 * side effects--it is safe to run them here.
1494 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1495 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1496 sctp_source(chunk), peer_init,
1500 /* Update the content of current association. */
1501 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1502 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1503 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1504 SCTP_INC_STATS(SctpCurrEstab);
1505 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1507 repl = sctp_make_cookie_ack(new_asoc, chunk);
1511 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1512 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1514 /* RFC 2960 5.1 Normal Establishment of an Association
1516 * D) IMPLEMENTATION NOTE: An implementation may choose to
1517 * send the Communication Up notification to the SCTP user
1518 * upon reception of a valid COOKIE ECHO chunk.
1520 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
1521 new_asoc->c.sinit_num_ostreams,
1522 new_asoc->c.sinit_max_instreams,
1527 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1528 return SCTP_DISPOSITION_CONSUME;
1531 sctp_chunk_free(repl);
1533 return SCTP_DISPOSITION_NOMEM;
1536 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1539 * C) In this case, the local endpoint's cookie has arrived late.
1540 * Before it arrived, the local endpoint sent an INIT and received an
1541 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1542 * but a new tag of its own.
1544 /* This case represents an initialization collision. */
1545 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1546 const struct sctp_association *asoc,
1547 struct sctp_chunk *chunk,
1548 sctp_cmd_seq_t *commands,
1549 struct sctp_association *new_asoc)
1551 /* The cookie should be silently discarded.
1552 * The endpoint SHOULD NOT change states and should leave
1553 * any timers running.
1555 return SCTP_DISPOSITION_DISCARD;
1558 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1562 * D) When both local and remote tags match the endpoint should always
1563 * enter the ESTABLISHED state, if it has not already done so.
1565 /* This case represents an initialization collision. */
1566 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1567 const struct sctp_association *asoc,
1568 struct sctp_chunk *chunk,
1569 sctp_cmd_seq_t *commands,
1570 struct sctp_association *new_asoc)
1572 struct sctp_ulpevent *ev = NULL;
1573 struct sctp_chunk *repl;
1575 /* Clarification from Implementor's Guide:
1576 * D) When both local and remote tags match the endpoint should
1577 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1578 * It should stop any cookie timer that may be running and send
1582 /* Don't accidentally move back into established state. */
1583 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1584 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1585 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1586 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1587 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1588 SCTP_INC_STATS(SctpCurrEstab);
1589 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1592 /* RFC 2960 5.1 Normal Establishment of an Association
1594 * D) IMPLEMENTATION NOTE: An implementation may choose
1595 * to send the Communication Up notification to the
1596 * SCTP user upon reception of a valid COOKIE
1599 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
1601 new_asoc->c.sinit_num_ostreams,
1602 new_asoc->c.sinit_max_instreams,
1606 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1609 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1611 repl = sctp_make_cookie_ack(new_asoc, chunk);
1615 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1616 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1618 return SCTP_DISPOSITION_CONSUME;
1622 sctp_ulpevent_free(ev);
1623 return SCTP_DISPOSITION_NOMEM;
1627 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1628 * chunk was retransmitted and then delayed in the network.
1630 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1632 * Verification Tag: None. Do cookie validation.
1635 * (endpoint, asoc, chunk)
1638 * (asoc, reply_msg, msg_up, timers, counters)
1640 * The return value is the disposition of the chunk.
1642 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1643 const struct sctp_association *asoc,
1644 const sctp_subtype_t type,
1646 sctp_cmd_seq_t *commands)
1648 sctp_disposition_t retval;
1649 struct sctp_chunk *chunk = arg;
1650 struct sctp_association *new_asoc;
1653 struct sctp_chunk *err_chk_p;
1655 /* "Decode" the chunk. We have no optional parameters so we
1656 * are in good shape.
1658 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1659 skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1660 sizeof(sctp_chunkhdr_t));
1662 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1663 * of a duplicate COOKIE ECHO match the Verification Tags of the
1664 * current association, consider the State Cookie valid even if
1665 * the lifespan is exceeded.
1667 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1671 * If the re-build failed, what is the proper error path
1674 * [We should abort the association. --piggy]
1677 /* FIXME: Several errors are possible. A bad cookie should
1678 * be silently discarded, but think about logging it too.
1681 case -SCTP_IERROR_NOMEM:
1684 case -SCTP_IERROR_STALE_COOKIE:
1685 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1687 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1688 case -SCTP_IERROR_BAD_SIG:
1690 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1694 /* Compare the tie_tag in cookie with the verification tag of
1695 * current association.
1697 action = sctp_tietags_compare(new_asoc, asoc);
1700 case 'A': /* Association restart. */
1701 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1705 case 'B': /* Collision case B. */
1706 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1710 case 'C': /* Collision case C. */
1711 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1715 case 'D': /* Collision case D. */
1716 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1720 default: /* Discard packet for all others. */
1721 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1725 /* Delete the tempory new association. */
1726 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1727 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1732 return SCTP_DISPOSITION_NOMEM;
1736 * Process an ABORT. (SHUTDOWN-PENDING state)
1738 * See sctp_sf_do_9_1_abort().
1740 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1741 const struct sctp_endpoint *ep,
1742 const struct sctp_association *asoc,
1743 const sctp_subtype_t type,
1745 sctp_cmd_seq_t *commands)
1747 struct sctp_chunk *chunk = arg;
1749 if (!sctp_vtag_verify_either(chunk, asoc))
1750 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1752 /* Stop the T5-shutdown guard timer. */
1753 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1754 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1756 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1760 * Process an ABORT. (SHUTDOWN-SENT state)
1762 * See sctp_sf_do_9_1_abort().
1764 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
1765 const struct sctp_association *asoc,
1766 const sctp_subtype_t type,
1768 sctp_cmd_seq_t *commands)
1770 struct sctp_chunk *chunk = arg;
1772 if (!sctp_vtag_verify_either(chunk, asoc))
1773 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1775 /* Stop the T2-shutdown timer. */
1776 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1777 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
1779 /* Stop the T5-shutdown guard timer. */
1780 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1781 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1783 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1787 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
1789 * See sctp_sf_do_9_1_abort().
1791 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
1792 const struct sctp_endpoint *ep,
1793 const struct sctp_association *asoc,
1794 const sctp_subtype_t type,
1796 sctp_cmd_seq_t *commands)
1798 /* The same T2 timer, so we should be able to use
1799 * common function with the SHUTDOWN-SENT state.
1801 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
1805 * Handle an Error received in COOKIE_ECHOED state.
1807 * Only handle the error type of stale COOKIE Error, the other errors will
1811 * (endpoint, asoc, chunk)
1814 * (asoc, reply_msg, msg_up, timers, counters)
1816 * The return value is the disposition of the chunk.
1818 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
1819 const struct sctp_association *asoc,
1820 const sctp_subtype_t type,
1822 sctp_cmd_seq_t *commands)
1824 struct sctp_chunk *chunk = arg;
1827 /* Process the error here */
1828 /* FUTURE FIXME: When PR-SCTP related and other optional
1829 * parms are emitted, this will have to change to handle multiple
1832 sctp_walk_errors(err, chunk->chunk_hdr) {
1833 if (SCTP_ERROR_STALE_COOKIE == err->cause)
1834 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
1837 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1841 * Handle a Stale COOKIE Error
1843 * Section: 5.2.6 Handle Stale COOKIE Error
1844 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
1845 * one of the following three alternatives.
1847 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
1848 * Preservative parameter requesting an extension to the lifetime of
1849 * the State Cookie. When calculating the time extension, an
1850 * implementation SHOULD use the RTT information measured based on the
1851 * previous COOKIE ECHO / ERROR exchange, and should add no more
1852 * than 1 second beyond the measured RTT, due to long State Cookie
1853 * lifetimes making the endpoint more subject to a replay attack.
1855 * Verification Tag: Not explicit, but safe to ignore.
1858 * (endpoint, asoc, chunk)
1861 * (asoc, reply_msg, msg_up, timers, counters)
1863 * The return value is the disposition of the chunk.
1865 sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
1866 const struct sctp_association *asoc,
1867 const sctp_subtype_t type,
1869 sctp_cmd_seq_t *commands)
1871 struct sctp_chunk *chunk = arg;
1873 sctp_cookie_preserve_param_t bht;
1875 struct list_head *pos;
1876 struct sctp_transport *t;
1877 struct sctp_chunk *reply;
1878 struct sctp_bind_addr *bp;
1881 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
1883 if (attempts >= asoc->max_init_attempts) {
1884 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
1885 SCTP_U32(SCTP_ERROR_STALE_COOKIE));
1886 return SCTP_DISPOSITION_DELETE_TCB;
1889 err = (sctp_errhdr_t *)(chunk->skb->data);
1891 /* When calculating the time extension, an implementation
1892 * SHOULD use the RTT information measured based on the
1893 * previous COOKIE ECHO / ERROR exchange, and should add no
1894 * more than 1 second beyond the measured RTT, due to long
1895 * State Cookie lifetimes making the endpoint more subject to
1897 * Measure of Staleness's unit is usec. (1/1000000 sec)
1898 * Suggested Cookie Life-span Increment's unit is msec.
1900 * In general, if you use the suggested cookie life, the value
1901 * found in the field of measure of staleness should be doubled
1902 * to give ample time to retransmit the new cookie and thus
1903 * yield a higher probability of success on the reattempt.
1905 stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
1906 stale = (stale * 2) / 1000;
1908 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
1909 bht.param_hdr.length = htons(sizeof(bht));
1910 bht.lifespan_increment = htonl(stale);
1912 /* Build that new INIT chunk. */
1913 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
1914 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
1918 sctp_addto_chunk(reply, sizeof(bht), &bht);
1920 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
1921 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
1923 /* Cast away the const modifier, as we want to just
1924 * rerun it through as a sideffect.
1926 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
1927 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
1929 /* If we've sent any data bundled with COOKIE-ECHO we need to
1932 list_for_each(pos, &asoc->peer.transport_addr_list) {
1933 t = list_entry(pos, struct sctp_transport, transports);
1934 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(t));
1937 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1938 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1939 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1940 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
1941 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
1942 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1944 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1946 return SCTP_DISPOSITION_CONSUME;
1949 return SCTP_DISPOSITION_NOMEM;
1956 * After checking the Verification Tag, the receiving endpoint shall
1957 * remove the association from its record, and shall report the
1958 * termination to its upper layer.
1960 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
1961 * B) Rules for packet carrying ABORT:
1963 * - The endpoint shall always fill in the Verification Tag field of the
1964 * outbound packet with the destination endpoint's tag value if it
1967 * - If the ABORT is sent in response to an OOTB packet, the endpoint
1968 * MUST follow the procedure described in Section 8.4.
1970 * - The receiver MUST accept the packet if the Verification Tag
1971 * matches either its own tag, OR the tag of its peer. Otherwise, the
1972 * receiver MUST silently discard the packet and take no further
1976 * (endpoint, asoc, chunk)
1979 * (asoc, reply_msg, msg_up, timers, counters)
1981 * The return value is the disposition of the chunk.
1983 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
1984 const struct sctp_association *asoc,
1985 const sctp_subtype_t type,
1987 sctp_cmd_seq_t *commands)
1989 struct sctp_chunk *chunk = arg;
1991 __u16 error = SCTP_ERROR_NO_ERROR;
1993 if (!sctp_vtag_verify_either(chunk, asoc))
1994 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1996 /* Check that chunk header looks valid. */
1997 len = ntohs(chunk->chunk_hdr->length);
1998 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
1999 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2002 /* ASSOC_FAILED will DELETE_TCB. */
2003 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error));
2004 SCTP_INC_STATS(SctpAborteds);
2005 SCTP_DEC_STATS(SctpCurrEstab);
2007 return SCTP_DISPOSITION_ABORT;
2011 * Process an ABORT. (COOKIE-WAIT state)
2013 * See sctp_sf_do_9_1_abort() above.
2015 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2016 const struct sctp_association *asoc,
2017 const sctp_subtype_t type,
2019 sctp_cmd_seq_t *commands)
2021 struct sctp_chunk *chunk = arg;
2023 __u16 error = SCTP_ERROR_NO_ERROR;
2025 if (!sctp_vtag_verify_either(chunk, asoc))
2026 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2028 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2029 SCTP_STATE(SCTP_STATE_CLOSED));
2030 SCTP_INC_STATS(SctpAborteds);
2031 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2032 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2034 /* Check that chunk header looks valid. */
2035 len = ntohs(chunk->chunk_hdr->length);
2036 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2037 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2039 /* CMD_INIT_FAILED will DELETE_TCB. */
2040 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_U32(error));
2042 return SCTP_DISPOSITION_ABORT;
2046 * Process an ABORT. (COOKIE-ECHOED state)
2048 * See sctp_sf_do_9_1_abort() above.
2050 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2051 const struct sctp_association *asoc,
2052 const sctp_subtype_t type,
2054 sctp_cmd_seq_t *commands)
2056 /* There is a single T1 timer, so we should be able to use
2057 * common function with the COOKIE-WAIT state.
2059 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2063 * sctp_sf_do_9_2_shut
2066 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2067 * - enter the SHUTDOWN-RECEIVED state,
2069 * - stop accepting new data from its SCTP user
2071 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2072 * that all its outstanding DATA chunks have been received by the
2075 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2076 * send a SHUTDOWN in response to a ULP request. And should discard
2077 * subsequent SHUTDOWN chunks.
2079 * If there are still outstanding DATA chunks left, the SHUTDOWN
2080 * receiver shall continue to follow normal data transmission
2081 * procedures defined in Section 6 until all outstanding DATA chunks
2082 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2083 * new data from its SCTP user.
2085 * Verification Tag: 8.5 Verification Tag [Normal verification]
2088 * (endpoint, asoc, chunk)
2091 * (asoc, reply_msg, msg_up, timers, counters)
2093 * The return value is the disposition of the chunk.
2095 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2096 const struct sctp_association *asoc,
2097 const sctp_subtype_t type,
2099 sctp_cmd_seq_t *commands)
2101 struct sctp_chunk *chunk = arg;
2102 sctp_shutdownhdr_t *sdh;
2103 sctp_disposition_t disposition;
2104 struct sctp_ulpevent *ev;
2106 /* Convert the elaborate header. */
2107 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2108 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2109 chunk->subh.shutdown_hdr = sdh;
2111 if (!sctp_vtag_verify(chunk, asoc))
2112 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2114 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2115 * - enter the SHUTDOWN-RECEIVED state,
2116 * - stop accepting new data from its SCTP user
2118 * [This is implicit in the new state.]
2120 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2121 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2122 disposition = SCTP_DISPOSITION_CONSUME;
2124 if (sctp_outq_is_empty(&asoc->outqueue)) {
2125 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2129 if (SCTP_DISPOSITION_NOMEM == disposition)
2132 /* - verify, by checking the Cumulative TSN Ack field of the
2133 * chunk, that all its outstanding DATA chunks have been
2134 * received by the SHUTDOWN sender.
2136 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2137 SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2139 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2140 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2141 * inform the application that it should cease sending data.
2143 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2145 disposition = SCTP_DISPOSITION_NOMEM;
2148 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2155 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2156 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2157 * transport addresses (either in the IP addresses or in the INIT chunk)
2158 * that belong to this association, it should discard the INIT chunk and
2159 * retransmit the SHUTDOWN ACK chunk.
2161 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2162 const struct sctp_association *asoc,
2163 const sctp_subtype_t type,
2165 sctp_cmd_seq_t *commands)
2167 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2168 struct sctp_chunk *reply;
2170 reply = sctp_make_shutdown_ack(asoc, chunk);
2174 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2175 * the T2-SHUTDOWN timer.
2177 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2179 /* and restart the T2-shutdown timer. */
2180 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2181 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2183 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2185 return SCTP_DISPOSITION_CONSUME;
2187 return SCTP_DISPOSITION_NOMEM;
2191 * sctp_sf_do_ecn_cwr
2193 * Section: Appendix A: Explicit Congestion Notification
2197 * RFC 2481 details a specific bit for a sender to send in the header of
2198 * its next outbound TCP segment to indicate to its peer that it has
2199 * reduced its congestion window. This is termed the CWR bit. For
2200 * SCTP the same indication is made by including the CWR chunk.
2201 * This chunk contains one data element, i.e. the TSN number that
2202 * was sent in the ECNE chunk. This element represents the lowest
2203 * TSN number in the datagram that was originally marked with the
2206 * Verification Tag: 8.5 Verification Tag [Normal verification]
2208 * (endpoint, asoc, chunk)
2211 * (asoc, reply_msg, msg_up, timers, counters)
2213 * The return value is the disposition of the chunk.
2215 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2216 const struct sctp_association *asoc,
2217 const sctp_subtype_t type,
2219 sctp_cmd_seq_t *commands)
2222 struct sctp_chunk *chunk = arg;
2224 if (!sctp_vtag_verify(chunk, asoc))
2225 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2227 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2228 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2230 cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
2232 /* Does this CWR ack the last sent congestion notification? */
2233 if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
2234 /* Stop sending ECNE. */
2235 sctp_add_cmd_sf(commands,
2237 SCTP_U32(cwr->lowest_tsn));
2239 return SCTP_DISPOSITION_CONSUME;
2245 * Section: Appendix A: Explicit Congestion Notification
2249 * RFC 2481 details a specific bit for a receiver to send back in its
2250 * TCP acknowledgements to notify the sender of the Congestion
2251 * Experienced (CE) bit having arrived from the network. For SCTP this
2252 * same indication is made by including the ECNE chunk. This chunk
2253 * contains one data element, i.e. the lowest TSN associated with the IP
2254 * datagram marked with the CE bit.....
2256 * Verification Tag: 8.5 Verification Tag [Normal verification]
2258 * (endpoint, asoc, chunk)
2261 * (asoc, reply_msg, msg_up, timers, counters)
2263 * The return value is the disposition of the chunk.
2265 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2266 const struct sctp_association *asoc,
2267 const sctp_subtype_t type,
2269 sctp_cmd_seq_t *commands)
2271 sctp_ecnehdr_t *ecne;
2272 struct sctp_chunk *chunk = arg;
2274 if (!sctp_vtag_verify(chunk, asoc))
2275 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2277 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2278 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2280 /* If this is a newer ECNE than the last CWR packet we sent out */
2281 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2282 SCTP_U32(ntohl(ecne->lowest_tsn)));
2284 return SCTP_DISPOSITION_CONSUME;
2288 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2290 * The SCTP endpoint MUST always acknowledge the reception of each valid
2293 * The guidelines on delayed acknowledgement algorithm specified in
2294 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2295 * acknowledgement SHOULD be generated for at least every second packet
2296 * (not every second DATA chunk) received, and SHOULD be generated within
2297 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2298 * situations it may be beneficial for an SCTP transmitter to be more
2299 * conservative than the algorithms detailed in this document allow.
2300 * However, an SCTP transmitter MUST NOT be more aggressive than the
2301 * following algorithms allow.
2303 * A SCTP receiver MUST NOT generate more than one SACK for every
2304 * incoming packet, other than to update the offered window as the
2305 * receiving application consumes new data.
2307 * Verification Tag: 8.5 Verification Tag [Normal verification]
2310 * (endpoint, asoc, chunk)
2313 * (asoc, reply_msg, msg_up, timers, counters)
2315 * The return value is the disposition of the chunk.
2317 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2318 const struct sctp_association *asoc,
2319 const sctp_subtype_t type,
2321 sctp_cmd_seq_t *commands)
2323 struct sctp_chunk *chunk = arg;
2324 sctp_datahdr_t *data_hdr;
2325 struct sctp_chunk *err;
2327 sctp_verb_t deliver;
2331 if (!sctp_vtag_verify(chunk, asoc)) {
2332 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2334 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2337 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
2338 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
2340 tsn = ntohl(data_hdr->tsn);
2341 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
2343 /* ASSERT: Now skb->data is really the user data. */
2345 /* Process ECN based congestion.
2347 * Since the chunk structure is reused for all chunks within
2348 * a packet, we use ecn_ce_done to track if we've already
2349 * done CE processing for this packet.
2351 * We need to do ECN processing even if we plan to discard the
2355 if (!chunk->ecn_ce_done) {
2357 chunk->ecn_ce_done = 1;
2359 af = sctp_get_af_specific(
2360 ipver2af(chunk->skb->nh.iph->version));
2362 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
2363 /* Do real work as sideffect. */
2364 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
2369 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
2371 /* The TSN is too high--silently discard the chunk and
2372 * count on it getting retransmitted later.
2374 goto discard_noforce;
2375 } else if (tmp > 0) {
2376 /* This is a duplicate. Record it. */
2377 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
2381 /* This is a new TSN. */
2383 /* Discard if there is no room in the receive window.
2384 * Actually, allow a little bit of overflow (up to a MTU).
2386 datalen = ntohs(chunk->chunk_hdr->length);
2387 datalen -= sizeof(sctp_data_chunk_t);
2389 deliver = SCTP_CMD_CHUNK_ULP;
2391 /* Think about partial delivery. */
2392 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
2394 /* Even if we don't accept this chunk there is
2397 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
2400 /* Spill over rwnd a little bit. Note: While allowed, this spill over
2401 * seems a bit troublesome in that frag_point varies based on
2402 * PMTU. In cases, such as loopback, this might be a rather
2405 if (!asoc->rwnd || asoc->rwnd_over ||
2406 (datalen > asoc->rwnd + asoc->frag_point)) {
2408 /* If this is the next TSN, consider reneging to make
2409 * room. Note: Playing nice with a confused sender. A
2410 * malicious sender can still eat up all our buffer
2411 * space and in the future we may want to detect and
2412 * do more drastic reneging.
2414 if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) &&
2415 (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) {
2416 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
2417 deliver = SCTP_CMD_RENEGE;
2419 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
2420 "rwnd: %d\n", tsn, datalen,
2427 * Section 3.3.10.9 No User Data (9)
2431 * No User Data: This error cause is returned to the originator of a
2432 * DATA chunk if a received DATA chunk has no user data.
2434 if (unlikely(0 == datalen)) {
2435 err = sctp_make_abort_no_data(asoc, chunk, tsn);
2437 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2440 /* We are going to ABORT, so we might as well stop
2441 * processing the rest of the chunks in the packet.
2443 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
2444 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
2445 SCTP_U32(SCTP_ERROR_NO_DATA));
2446 SCTP_INC_STATS(SctpAborteds);
2447 SCTP_DEC_STATS(SctpCurrEstab);
2448 return SCTP_DISPOSITION_CONSUME;
2451 /* If definately accepting the DATA chunk, record its TSN, otherwise
2452 * wait for renege processing.
2454 if (SCTP_CMD_CHUNK_ULP == deliver)
2455 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
2457 /* Note: Some chunks may get overcounted (if we drop) or overcounted
2458 * if we renege and the chunk arrives again.
2460 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
2461 SCTP_INC_STATS(SctpInUnorderChunks);
2463 SCTP_INC_STATS(SctpInOrderChunks);
2465 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
2467 * If an endpoint receive a DATA chunk with an invalid stream
2468 * identifier, it shall acknowledge the reception of the DATA chunk
2469 * following the normal procedure, immediately send an ERROR chunk
2470 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
2471 * and discard the DATA chunk.
2473 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
2474 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
2476 sizeof(data_hdr->stream));
2478 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2480 goto discard_noforce;
2483 /* Send the data up to the user. Note: Schedule the
2484 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
2485 * chunk needs the updated rwnd.
2487 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
2489 if (asoc->autoclose) {
2490 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2491 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2494 /* If this is the last chunk in a packet, we need to count it
2495 * toward sack generation. Note that we need to SACK every
2496 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2497 * THEM. We elect to NOT generate SACK's if the chunk fails
2498 * the verification tag test.
2500 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2502 * The SCTP endpoint MUST always acknowledge the reception of
2503 * each valid DATA chunk.
2505 * The guidelines on delayed acknowledgement algorithm
2506 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2507 * Specifically, an acknowledgement SHOULD be generated for at
2508 * least every second packet (not every second DATA chunk)
2509 * received, and SHOULD be generated within 200 ms of the
2510 * arrival of any unacknowledged DATA chunk. In some
2511 * situations it may be beneficial for an SCTP transmitter to
2512 * be more conservative than the algorithms detailed in this
2513 * document allow. However, an SCTP transmitter MUST NOT be
2514 * more aggressive than the following algorithms allow.
2516 if (chunk->end_of_packet) {
2517 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2519 /* Start the SACK timer. */
2520 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2521 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2524 return SCTP_DISPOSITION_CONSUME;
2527 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2529 * When a packet arrives with duplicate DATA chunk(s) and with
2530 * no new DATA chunk(s), the endpoint MUST immediately send a
2531 * SACK with no delay. If a packet arrives with duplicate
2532 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2533 * MAY immediately send a SACK. Normally receipt of duplicate
2534 * DATA chunks will occur when the original SACK chunk was lost
2535 * and the peer's RTO has expired. The duplicate TSN number(s)
2536 * SHOULD be reported in the SACK as duplicate.
2538 /* In our case, we split the MAY SACK advice up whether or not
2539 * the last chunk is a duplicate.'
2541 if (chunk->end_of_packet)
2542 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2543 return SCTP_DISPOSITION_DISCARD;
2546 if (chunk->end_of_packet) {
2547 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2549 /* Start the SACK timer. */
2550 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2551 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2553 return SCTP_DISPOSITION_DISCARD;
2557 * sctp_sf_eat_data_fast_4_4
2560 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2561 * DATA chunks without delay.
2563 * Verification Tag: 8.5 Verification Tag [Normal verification]
2565 * (endpoint, asoc, chunk)
2568 * (asoc, reply_msg, msg_up, timers, counters)
2570 * The return value is the disposition of the chunk.
2572 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2573 const struct sctp_association *asoc,
2574 const sctp_subtype_t type,
2576 sctp_cmd_seq_t *commands)
2578 struct sctp_chunk *chunk = arg;
2579 sctp_datahdr_t *data_hdr;
2580 struct sctp_chunk *err;
2585 if (!sctp_vtag_verify(chunk, asoc)) {
2586 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2588 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2591 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *) chunk->skb->data;
2592 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
2594 tsn = ntohl(data_hdr->tsn);
2596 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
2598 /* ASSERT: Now skb->data is really the user data. */
2600 /* Process ECN based congestion.
2602 * Since the chunk structure is reused for all chunks within
2603 * a packet, we use ecn_ce_done to track if we've already
2604 * done CE processing for this packet.
2606 * We need to do ECN processing even if we plan to discard the
2609 if (!chunk->ecn_ce_done) {
2611 chunk->ecn_ce_done = 1;
2613 af = sctp_get_af_specific(
2614 ipver2af(chunk->skb->nh.iph->version));
2616 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
2617 /* Do real work as sideffect. */
2618 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
2623 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
2625 /* The TSN is too high--silently discard the chunk and
2626 * count on it getting retransmitted later.
2629 } else if (tmp > 0) {
2630 /* This is a duplicate. Record it. */
2631 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
2635 /* This is a new TSN. */
2637 datalen = ntohs(chunk->chunk_hdr->length);
2638 datalen -= sizeof(sctp_data_chunk_t);
2641 * Section 3.3.10.9 No User Data (9)
2645 * No User Data: This error cause is returned to the originator of a
2646 * DATA chunk if a received DATA chunk has no user data.
2648 if (unlikely(0 == datalen)) {
2649 err = sctp_make_abort_no_data(asoc, chunk, tsn);
2651 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2654 /* We are going to ABORT, so we might as well stop
2655 * processing the rest of the chunks in the packet.
2657 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
2658 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
2659 SCTP_U32(SCTP_ERROR_NO_DATA));
2660 SCTP_INC_STATS(SctpAborteds);
2661 SCTP_DEC_STATS(SctpCurrEstab);
2662 return SCTP_DISPOSITION_CONSUME;
2665 /* We are accepting this DATA chunk. */
2667 /* Record the fact that we have received this TSN. */
2668 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
2670 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
2671 SCTP_INC_STATS(SctpInUnorderChunks);
2673 SCTP_INC_STATS(SctpInOrderChunks);
2675 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
2677 * If an endpoint receive a DATA chunk with an invalid stream
2678 * identifier, it shall acknowledge the reception of the DATA chunk
2679 * following the normal procedure, immediately send an ERROR chunk
2680 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
2681 * and discard the DATA chunk.
2683 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
2684 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
2686 sizeof(data_hdr->stream));
2688 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2693 /* Go a head and force a SACK, since we are shutting down. */
2695 /* Implementor's Guide.
2697 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2698 * respond to each received packet containing one or more DATA chunk(s)
2699 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2701 if (chunk->end_of_packet) {
2702 /* We must delay the chunk creation since the cumulative
2703 * TSN has not been updated yet.
2705 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2706 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2707 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2708 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2710 return SCTP_DISPOSITION_CONSUME;
2714 * Section: 6.2 Processing a Received SACK
2715 * D) Any time a SACK arrives, the endpoint performs the following:
2717 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2718 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2719 * increasing, a SACK whose Cumulative TSN Ack is less than the
2720 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2722 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2723 * of bytes still outstanding after processing the Cumulative TSN Ack
2724 * and the Gap Ack Blocks.
2726 * iii) If the SACK is missing a TSN that was previously
2727 * acknowledged via a Gap Ack Block (e.g., the data receiver
2728 * reneged on the data), then mark the corresponding DATA chunk
2729 * as available for retransmit: Mark it as missing for fast
2730 * retransmit as described in Section 7.2.4 and if no retransmit
2731 * timer is running for the destination address to which the DATA
2732 * chunk was originally transmitted, then T3-rtx is started for
2733 * that destination address.
2735 * Verification Tag: 8.5 Verification Tag [Normal verification]
2738 * (endpoint, asoc, chunk)
2741 * (asoc, reply_msg, msg_up, timers, counters)
2743 * The return value is the disposition of the chunk.
2745 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2746 const struct sctp_association *asoc,
2747 const sctp_subtype_t type,
2749 sctp_cmd_seq_t *commands)
2751 struct sctp_chunk *chunk = arg;
2752 sctp_sackhdr_t *sackh;
2755 if (!sctp_vtag_verify(chunk, asoc))
2756 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2758 /* Pull the SACK chunk from the data buffer */
2759 sackh = sctp_sm_pull_sack(chunk);
2760 /* Was this a bogus SACK? */
2762 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2763 chunk->subh.sack_hdr = sackh;
2764 ctsn = ntohl(sackh->cum_tsn_ack);
2766 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2767 * Ack Point, then drop the SACK. Since Cumulative TSN
2768 * Ack is monotonically increasing, a SACK whose
2769 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2770 * Point indicates an out-of-order SACK.
2772 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2773 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2774 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2775 return SCTP_DISPOSITION_DISCARD;
2778 /* Return this SACK for further processing. */
2779 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2781 /* Note: We do the rest of the work on the PROCESS_SACK
2784 return SCTP_DISPOSITION_CONSUME;
2788 * Generate an ABORT in response to a packet.
2790 * Section: 8.4 Handle "Out of the blue" Packets
2792 * 8) The receiver should respond to the sender of the OOTB packet
2793 * with an ABORT. When sending the ABORT, the receiver of the
2794 * OOTB packet MUST fill in the Verification Tag field of the
2795 * outbound packet with the value found in the Verification Tag
2796 * field of the OOTB packet and set the T-bit in the Chunk Flags
2797 * to indicate that no TCB was found. After sending this ABORT,
2798 * the receiver of the OOTB packet shall discard the OOTB packet
2799 * and take no further action.
2803 * The return value is the disposition of the chunk.
2805 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2806 const struct sctp_association *asoc,
2807 const sctp_subtype_t type,
2809 sctp_cmd_seq_t *commands)
2811 struct sctp_packet *packet = NULL;
2812 struct sctp_chunk *chunk = arg;
2813 struct sctp_chunk *abort;
2815 packet = sctp_ootb_pkt_new(asoc, chunk);
2818 /* Make an ABORT. The T bit will be set if the asoc
2821 abort = sctp_make_abort(asoc, chunk, 0);
2823 sctp_ootb_pkt_free(packet);
2824 return SCTP_DISPOSITION_NOMEM;
2827 /* Set the skb to the belonging sock for accounting. */
2828 abort->skb->sk = ep->base.sk;
2830 sctp_packet_append_chunk(packet, abort);
2832 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2833 SCTP_PACKET(packet));
2835 SCTP_INC_STATS(SctpOutCtrlChunks);
2837 return SCTP_DISPOSITION_CONSUME;
2840 return SCTP_DISPOSITION_NOMEM;
2844 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2845 * event as ULP notification for each cause included in the chunk.
2847 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2849 * The return value is the disposition of the chunk.
2851 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2852 const struct sctp_association *asoc,
2853 const sctp_subtype_t type,
2855 sctp_cmd_seq_t *commands)
2857 struct sctp_chunk *chunk = arg;
2858 struct sctp_ulpevent *ev;
2860 while (chunk->chunk_end > chunk->skb->data) {
2861 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
2866 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
2867 SCTP_ULPEVENT(ev))) {
2868 sctp_ulpevent_free(ev);
2872 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
2875 return SCTP_DISPOSITION_CONSUME;
2878 return SCTP_DISPOSITION_NOMEM;
2882 * Process an inbound SHUTDOWN ACK.
2885 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2886 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2887 * peer, and remove all record of the association.
2889 * The return value is the disposition.
2891 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
2892 const struct sctp_association *asoc,
2893 const sctp_subtype_t type,
2895 sctp_cmd_seq_t *commands)
2897 struct sctp_chunk *chunk = arg;
2898 struct sctp_chunk *reply;
2899 struct sctp_ulpevent *ev;
2901 if (!sctp_vtag_verify(chunk, asoc))
2902 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2904 /* 10.2 H) SHUTDOWN COMPLETE notification
2906 * When SCTP completes the shutdown procedures (section 9.2) this
2907 * notification is passed to the upper layer.
2909 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
2910 0, 0, 0, GFP_ATOMIC);
2914 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2916 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2917 * stop the T2-shutdown timer,
2919 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2920 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2922 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2923 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2925 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
2926 reply = sctp_make_shutdown_complete(asoc, chunk);
2930 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2931 SCTP_STATE(SCTP_STATE_CLOSED));
2932 SCTP_INC_STATS(SctpShutdowns);
2933 SCTP_DEC_STATS(SctpCurrEstab);
2934 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2936 /* ...and remove all record of the association. */
2937 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2938 return SCTP_DISPOSITION_DELETE_TCB;
2941 return SCTP_DISPOSITION_NOMEM;
2945 * RFC 2960, 8.4 - Handle "Out of the blue" Packets
2946 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2947 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2948 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
2949 * packet must fill in the Verification Tag field of the outbound
2950 * packet with the Verification Tag received in the SHUTDOWN ACK and
2951 * set the T-bit in the Chunk Flags to indicate that no TCB was
2954 * 8) The receiver should respond to the sender of the OOTB packet with
2955 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2956 * MUST fill in the Verification Tag field of the outbound packet
2957 * with the value found in the Verification Tag field of the OOTB
2958 * packet and set the T-bit in the Chunk Flags to indicate that no
2959 * TCB was found. After sending this ABORT, the receiver of the OOTB
2960 * packet shall discard the OOTB packet and take no further action.
2962 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
2963 const struct sctp_association *asoc,
2964 const sctp_subtype_t type,
2966 sctp_cmd_seq_t *commands)
2968 struct sctp_chunk *chunk = arg;
2969 struct sk_buff *skb = chunk->skb;
2970 sctp_chunkhdr_t *ch;
2972 int ootb_shut_ack = 0;
2974 SCTP_INC_STATS(SctpOutOfBlues);
2976 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
2978 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
2980 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
2983 ch = (sctp_chunkhdr_t *) ch_end;
2984 } while (ch_end < skb->tail);
2987 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
2989 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
2991 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2995 * Handle an "Out of the blue" SHUTDOWN ACK.
2998 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2999 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3000 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB packet
3001 * must fill in the Verification Tag field of the outbound packet with
3002 * the Verification Tag received in the SHUTDOWN ACK and set the
3003 * T-bit in the Chunk Flags to indicate that no TCB was found.
3006 * (endpoint, asoc, type, arg, commands)
3009 * (sctp_disposition_t)
3011 * The return value is the disposition of the chunk.
3013 sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3014 const struct sctp_association *asoc,
3015 const sctp_subtype_t type,
3017 sctp_cmd_seq_t *commands)
3019 struct sctp_packet *packet = NULL;
3020 struct sctp_chunk *chunk = arg;
3021 struct sctp_chunk *shut;
3023 packet = sctp_ootb_pkt_new(asoc, chunk);
3026 /* Make an SHUTDOWN_COMPLETE.
3027 * The T bit will be set if the asoc is NULL.
3029 shut = sctp_make_shutdown_complete(asoc, chunk);
3031 sctp_ootb_pkt_free(packet);
3032 return SCTP_DISPOSITION_NOMEM;
3035 /* Set the skb to the belonging sock for accounting. */
3036 shut->skb->sk = ep->base.sk;
3038 sctp_packet_append_chunk(packet, shut);
3040 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3041 SCTP_PACKET(packet));
3043 SCTP_INC_STATS(SctpOutCtrlChunks);
3045 return SCTP_DISPOSITION_CONSUME;
3048 return SCTP_DISPOSITION_NOMEM;
3052 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3054 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3055 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3056 * procedures in section 8.4 SHOULD be followed, in other words it
3057 * should be treated as an Out Of The Blue packet.
3058 * [This means that we do NOT check the Verification Tag on these
3062 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3063 const struct sctp_association *asoc,
3064 const sctp_subtype_t type,
3066 sctp_cmd_seq_t *commands)
3068 /* Although we do have an association in this case, it corresponds
3069 * to a restarted association. So the packet is treated as an OOTB
3070 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3071 * called with a NULL association.
3073 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3076 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3077 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3078 const struct sctp_association *asoc,
3079 const sctp_subtype_t type, void *arg,
3080 sctp_cmd_seq_t *commands)
3082 struct sctp_chunk *chunk = arg;
3083 struct sctp_chunk *asconf_ack = NULL;
3084 sctp_addiphdr_t *hdr;
3087 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3088 serial = ntohl(hdr->serial);
3090 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3091 * the endpoint stored in a new association variable
3092 * 'Peer-Serial-Number'.
3094 if (serial == asoc->peer.addip_serial + 1) {
3095 /* ADDIP 4.2 C2) If the value found in the serial number is
3096 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3099 asconf_ack = sctp_process_asconf((struct sctp_association *)
3102 return SCTP_DISPOSITION_NOMEM;
3103 } else if (serial == asoc->peer.addip_serial) {
3104 /* ADDIP 4.2 C3) If the value found in the serial number is
3105 * equal to the value stored in the 'Peer-Serial-Number'
3106 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3107 * to save the last ASCONF-ACK for some predetermined period of * time and instead of re-processing the ASCONF (with the same
3108 * serial number) it may just re-transmit the ASCONF-ACK.
3110 if (asoc->addip_last_asconf_ack)
3111 asconf_ack = asoc->addip_last_asconf_ack;
3113 return SCTP_DISPOSITION_DISCARD;
3115 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3116 * it must be either a stale packet or from an attacker.
3118 return SCTP_DISPOSITION_DISCARD;
3121 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3122 * back to the source address contained in the IP header of the ASCONF
3123 * being responded to.
3125 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3127 return SCTP_DISPOSITION_CONSUME;
3131 * ADDIP Section 4.3 General rules for address manipulation
3132 * When building TLV parameters for the ASCONF Chunk that will add or
3133 * delete IP addresses the D0 to D13 rules should be applied:
3135 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3136 const struct sctp_association *asoc,
3137 const sctp_subtype_t type, void *arg,
3138 sctp_cmd_seq_t *commands)
3140 struct sctp_chunk *asconf_ack = arg;
3141 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3142 struct sctp_chunk *abort;
3143 sctp_addiphdr_t *addip_hdr;
3144 __u32 sent_serial, rcvd_serial;
3146 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3147 rcvd_serial = ntohl(addip_hdr->serial);
3150 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3151 sent_serial = ntohl(addip_hdr->serial);
3153 sent_serial = asoc->addip_serial - 1;
3156 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3157 * equal to the next serial number to be used but no ASCONF chunk is
3158 * outstanding the endpoint MUST ABORT the association. Note that a
3159 * sequence number is greater than if it is no more than 2^^31-1
3160 * larger than the current sequence number (using serial arithmetic).
3162 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3163 !(asoc->addip_last_asconf)) {
3164 abort = sctp_make_abort(asoc, asconf_ack,
3165 sizeof(sctp_errhdr_t));
3167 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
3168 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3171 /* We are going to ABORT, so we might as well stop
3172 * processing the rest of the chunks in the packet.
3174 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3175 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3176 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3177 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3178 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3179 SCTP_INC_STATS(SctpAborteds);
3180 SCTP_DEC_STATS(SctpCurrEstab);
3181 return SCTP_DISPOSITION_ABORT;
3184 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3185 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3186 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3188 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3190 return SCTP_DISPOSITION_CONSUME;
3192 abort = sctp_make_abort(asoc, asconf_ack,
3193 sizeof(sctp_errhdr_t));
3195 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
3196 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3199 /* We are going to ABORT, so we might as well stop
3200 * processing the rest of the chunks in the packet.
3202 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3203 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3204 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3205 SCTP_INC_STATS(SctpAborteds);
3206 SCTP_DEC_STATS(SctpCurrEstab);
3207 return SCTP_DISPOSITION_ABORT;
3210 return SCTP_DISPOSITION_DISCARD;
3214 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3216 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3217 * its cumulative TSN point to the value carried in the FORWARD TSN
3218 * chunk, and then MUST further advance its cumulative TSN point locally
3220 * After the above processing, the data receiver MUST stop reporting any
3221 * missing TSNs earlier than or equal to the new cumulative TSN point.
3223 * Verification Tag: 8.5 Verification Tag [Normal verification]
3225 * The return value is the disposition of the chunk.
3227 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3228 const struct sctp_association *asoc,
3229 const sctp_subtype_t type,
3231 sctp_cmd_seq_t *commands)
3233 struct sctp_chunk *chunk = arg;
3234 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3238 if (!sctp_vtag_verify(chunk, asoc)) {
3239 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3241 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3244 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3245 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3246 len = ntohs(chunk->chunk_hdr->length);
3247 len -= sizeof(struct sctp_chunkhdr);
3248 skb_pull(chunk->skb, len);
3250 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3251 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3253 /* The TSN is too high--silently discard the chunk and count on it
3254 * getting retransmitted later.
3256 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3257 goto discard_noforce;
3259 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3260 if (len > sizeof(struct sctp_fwdtsn_hdr))
3261 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3264 /* Count this as receiving DATA. */
3265 if (asoc->autoclose) {
3266 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3267 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3270 /* FIXME: For now send a SACK, but DATA processing may
3273 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3274 /* Start the SACK timer. */
3275 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3276 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
3278 return SCTP_DISPOSITION_CONSUME;
3281 return SCTP_DISPOSITION_DISCARD;
3284 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3285 const struct sctp_endpoint *ep,
3286 const struct sctp_association *asoc,
3287 const sctp_subtype_t type,
3289 sctp_cmd_seq_t *commands)
3291 struct sctp_chunk *chunk = arg;
3292 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3296 if (!sctp_vtag_verify(chunk, asoc)) {
3297 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3299 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3302 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3303 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3304 len = ntohs(chunk->chunk_hdr->length);
3305 len -= sizeof(struct sctp_chunkhdr);
3306 skb_pull(chunk->skb, len);
3308 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3309 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3311 /* The TSN is too high--silently discard the chunk and count on it
3312 * getting retransmitted later.
3314 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3317 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3318 if (len > sizeof(struct sctp_fwdtsn_hdr))
3319 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3322 /* Go a head and force a SACK, since we are shutting down. */
3324 /* Implementor's Guide.
3326 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3327 * respond to each received packet containing one or more DATA chunk(s)
3328 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3330 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3331 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3332 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3333 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3335 return SCTP_DISPOSITION_CONSUME;
3339 * Process an unknown chunk.
3341 * Section: 3.2. Also, 2.1 in the implementor's guide.
3343 * Chunk Types are encoded such that the highest-order two bits specify
3344 * the action that must be taken if the processing endpoint does not
3345 * recognize the Chunk Type.
3347 * 00 - Stop processing this SCTP packet and discard it, do not process
3348 * any further chunks within it.
3350 * 01 - Stop processing this SCTP packet and discard it, do not process
3351 * any further chunks within it, and report the unrecognized
3352 * chunk in an 'Unrecognized Chunk Type'.
3354 * 10 - Skip this chunk and continue processing.
3356 * 11 - Skip this chunk and continue processing, but report in an ERROR
3357 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3359 * The return value is the disposition of the chunk.
3361 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3362 const struct sctp_association *asoc,
3363 const sctp_subtype_t type,
3365 sctp_cmd_seq_t *commands)
3367 struct sctp_chunk *unk_chunk = arg;
3368 struct sctp_chunk *err_chunk;
3369 sctp_chunkhdr_t *hdr;
3371 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3373 if (!sctp_vtag_verify(unk_chunk, asoc))
3374 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3376 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3377 case SCTP_CID_ACTION_DISCARD:
3378 /* Discard the packet. */
3379 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3381 case SCTP_CID_ACTION_DISCARD_ERR:
3382 /* Discard the packet. */
3383 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3385 /* Generate an ERROR chunk as response. */
3386 hdr = unk_chunk->chunk_hdr;
3387 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3388 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3389 WORD_ROUND(ntohs(hdr->length)));
3391 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3392 SCTP_CHUNK(err_chunk));
3394 return SCTP_DISPOSITION_CONSUME;
3396 case SCTP_CID_ACTION_SKIP:
3397 /* Skip the chunk. */
3398 return SCTP_DISPOSITION_DISCARD;
3400 case SCTP_CID_ACTION_SKIP_ERR:
3401 /* Generate an ERROR chunk as response. */
3402 hdr = unk_chunk->chunk_hdr;
3403 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3404 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3405 WORD_ROUND(ntohs(hdr->length)));
3407 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3408 SCTP_CHUNK(err_chunk));
3410 /* Skip the chunk. */
3411 return SCTP_DISPOSITION_CONSUME;
3417 return SCTP_DISPOSITION_DISCARD;
3421 * Discard the chunk.
3423 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3424 * [Too numerous to mention...]
3425 * Verification Tag: No verification needed.
3427 * (endpoint, asoc, chunk)
3430 * (asoc, reply_msg, msg_up, timers, counters)
3432 * The return value is the disposition of the chunk.
3434 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3435 const struct sctp_association *asoc,
3436 const sctp_subtype_t type,
3438 sctp_cmd_seq_t *commands)
3440 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3441 return SCTP_DISPOSITION_DISCARD;
3445 * Discard the whole packet.
3449 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3450 * silently discard the OOTB packet and take no further action.
3453 * Verification Tag: No verification necessary
3456 * (endpoint, asoc, chunk)
3459 * (asoc, reply_msg, msg_up, timers, counters)
3461 * The return value is the disposition of the chunk.
3463 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3464 const struct sctp_association *asoc,
3465 const sctp_subtype_t type,
3467 sctp_cmd_seq_t *commands)
3469 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3471 return SCTP_DISPOSITION_CONSUME;
3476 * The other end is violating protocol.
3478 * Section: Not specified
3479 * Verification Tag: Not specified
3481 * (endpoint, asoc, chunk)
3484 * (asoc, reply_msg, msg_up, timers, counters)
3486 * We simply tag the chunk as a violation. The state machine will log
3487 * the violation and continue.
3489 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3490 const struct sctp_association *asoc,
3491 const sctp_subtype_t type,
3493 sctp_cmd_seq_t *commands)
3495 return SCTP_DISPOSITION_VIOLATION;
3498 /***************************************************************************
3499 * These are the state functions for handling primitive (Section 10) events.
3500 ***************************************************************************/
3502 * sctp_sf_do_prm_asoc
3504 * Section: 10.1 ULP-to-SCTP
3507 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3508 * outbound stream count)
3509 * -> association id [,destination transport addr list] [,outbound stream
3512 * This primitive allows the upper layer to initiate an association to a
3513 * specific peer endpoint.
3515 * The peer endpoint shall be specified by one of the transport addresses
3516 * which defines the endpoint (see Section 1.4). If the local SCTP
3517 * instance has not been initialized, the ASSOCIATE is considered an
3519 * [This is not relevant for the kernel implementation since we do all
3520 * initialization at boot time. It we hadn't initialized we wouldn't
3521 * get anywhere near this code.]
3523 * An association id, which is a local handle to the SCTP association,
3524 * will be returned on successful establishment of the association. If
3525 * SCTP is not able to open an SCTP association with the peer endpoint,
3526 * an error is returned.
3527 * [In the kernel implementation, the struct sctp_association needs to
3528 * be created BEFORE causing this primitive to run.]
3530 * Other association parameters may be returned, including the
3531 * complete destination transport addresses of the peer as well as the
3532 * outbound stream count of the local endpoint. One of the transport
3533 * address from the returned destination addresses will be selected by
3534 * the local endpoint as default primary path for sending SCTP packets
3535 * to this peer. The returned "destination transport addr list" can
3536 * be used by the ULP to change the default primary path or to force
3537 * sending a packet to a specific transport address. [All of this
3538 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3541 * Mandatory attributes:
3543 * o local SCTP instance name - obtained from the INITIALIZE operation.
3544 * [This is the argument asoc.]
3545 * o destination transport addr - specified as one of the transport
3546 * addresses of the peer endpoint with which the association is to be
3548 * [This is asoc->peer.active_path.]
3549 * o outbound stream count - the number of outbound streams the ULP
3550 * would like to open towards this peer endpoint.
3551 * [BUG: This is not currently implemented.]
3552 * Optional attributes:
3556 * The return value is a disposition.
3558 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
3559 const struct sctp_association *asoc,
3560 const sctp_subtype_t type,
3562 sctp_cmd_seq_t *commands)
3564 struct sctp_chunk *repl;
3566 /* The comment below says that we enter COOKIE-WAIT AFTER
3567 * sending the INIT, but that doesn't actually work in our
3570 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3571 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3573 /* RFC 2960 5.1 Normal Establishment of an Association
3575 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3576 * must provide its Verification Tag (Tag_A) in the Initiate
3577 * Tag field. Tag_A SHOULD be a random number in the range of
3578 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3581 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
3585 /* Cast away the const modifier, as we want to just
3586 * rerun it through as a sideffect.
3588 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3589 SCTP_ASOC((struct sctp_association *) asoc));
3591 /* After sending the INIT, "A" starts the T1-init timer and
3592 * enters the COOKIE-WAIT state.
3594 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3595 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3596 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3597 return SCTP_DISPOSITION_CONSUME;
3600 return SCTP_DISPOSITION_NOMEM;
3604 * Process the SEND primitive.
3606 * Section: 10.1 ULP-to-SCTP
3609 * Format: SEND(association id, buffer address, byte count [,context]
3610 * [,stream id] [,life time] [,destination transport address]
3611 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3614 * This is the main method to send user data via SCTP.
3616 * Mandatory attributes:
3618 * o association id - local handle to the SCTP association
3620 * o buffer address - the location where the user message to be
3621 * transmitted is stored;
3623 * o byte count - The size of the user data in number of bytes;
3625 * Optional attributes:
3627 * o context - an optional 32 bit integer that will be carried in the
3628 * sending failure notification to the ULP if the transportation of
3629 * this User Message fails.
3631 * o stream id - to indicate which stream to send the data on. If not
3632 * specified, stream 0 will be used.
3634 * o life time - specifies the life time of the user data. The user data
3635 * will not be sent by SCTP after the life time expires. This
3636 * parameter can be used to avoid efforts to transmit stale
3637 * user messages. SCTP notifies the ULP if the data cannot be
3638 * initiated to transport (i.e. sent to the destination via SCTP's
3639 * send primitive) within the life time variable. However, the
3640 * user data will be transmitted if SCTP has attempted to transmit a
3641 * chunk before the life time expired.
3643 * o destination transport address - specified as one of the destination
3644 * transport addresses of the peer endpoint to which this packet
3645 * should be sent. Whenever possible, SCTP should use this destination
3646 * transport address for sending the packets, instead of the current
3649 * o unorder flag - this flag, if present, indicates that the user
3650 * would like the data delivered in an unordered fashion to the peer
3651 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3654 * o no-bundle flag - instructs SCTP not to bundle this user data with
3655 * other outbound DATA chunks. SCTP MAY still bundle even when
3656 * this flag is present, when faced with network congestion.
3658 * o payload protocol-id - A 32 bit unsigned integer that is to be
3659 * passed to the peer indicating the type of payload protocol data
3660 * being transmitted. This value is passed as opaque data by SCTP.
3662 * The return value is the disposition.
3664 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
3665 const struct sctp_association *asoc,
3666 const sctp_subtype_t type,
3668 sctp_cmd_seq_t *commands)
3670 struct sctp_chunk *chunk = arg;
3672 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3673 return SCTP_DISPOSITION_CONSUME;
3677 * Process the SHUTDOWN primitive.
3682 * Format: SHUTDOWN(association id)
3685 * Gracefully closes an association. Any locally queued user data
3686 * will be delivered to the peer. The association will be terminated only
3687 * after the peer acknowledges all the SCTP packets sent. A success code
3688 * will be returned on successful termination of the association. If
3689 * attempting to terminate the association results in a failure, an error
3690 * code shall be returned.
3692 * Mandatory attributes:
3694 * o association id - local handle to the SCTP association
3696 * Optional attributes:
3700 * The return value is the disposition.
3702 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
3703 const struct sctp_endpoint *ep,
3704 const struct sctp_association *asoc,
3705 const sctp_subtype_t type,
3707 sctp_cmd_seq_t *commands)
3711 /* From 9.2 Shutdown of an Association
3712 * Upon receipt of the SHUTDOWN primitive from its upper
3713 * layer, the endpoint enters SHUTDOWN-PENDING state and
3714 * remains there until all outstanding data has been
3715 * acknowledged by its peer. The endpoint accepts no new data
3716 * from its upper layer, but retransmits data to the far end
3717 * if necessary to fill gaps.
3719 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3720 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
3722 /* sctpimpguide-05 Section 2.12.2
3723 * The sender of the SHUTDOWN MAY also start an overall guard timer
3724 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3726 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3727 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3729 disposition = SCTP_DISPOSITION_CONSUME;
3730 if (sctp_outq_is_empty(&asoc->outqueue)) {
3731 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
3738 * Process the ABORT primitive.
3743 * Format: Abort(association id [, cause code])
3746 * Ungracefully closes an association. Any locally queued user data
3747 * will be discarded and an ABORT chunk is sent to the peer. A success code
3748 * will be returned on successful abortion of the association. If
3749 * attempting to abort the association results in a failure, an error
3750 * code shall be returned.
3752 * Mandatory attributes:
3754 * o association id - local handle to the SCTP association
3756 * Optional attributes:
3758 * o cause code - reason of the abort to be passed to the peer
3762 * The return value is the disposition.
3764 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
3765 const struct sctp_endpoint *ep,
3766 const struct sctp_association *asoc,
3767 const sctp_subtype_t type,
3769 sctp_cmd_seq_t *commands)
3771 /* From 9.1 Abort of an Association
3772 * Upon receipt of the ABORT primitive from its upper
3773 * layer, the endpoint enters CLOSED state and
3774 * discard all outstanding data has been
3775 * acknowledged by its peer. The endpoint accepts no new data
3776 * from its upper layer, but retransmits data to the far end
3777 * if necessary to fill gaps.
3779 struct msghdr *msg = arg;
3780 struct sctp_chunk *abort;
3781 sctp_disposition_t retval;
3783 retval = SCTP_DISPOSITION_CONSUME;
3785 /* Generate ABORT chunk to send the peer. */
3786 abort = sctp_make_abort_user(asoc, NULL, msg);
3788 retval = SCTP_DISPOSITION_NOMEM;
3790 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3792 /* Even if we can't send the ABORT due to low memory delete the
3793 * TCB. This is a departure from our typical NOMEM handling.
3796 /* Delete the established association. */
3797 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3798 SCTP_U32(SCTP_ERROR_USER_ABORT));
3800 SCTP_INC_STATS(SctpAborteds);
3801 SCTP_DEC_STATS(SctpCurrEstab);
3806 /* We tried an illegal operation on an association which is closed. */
3807 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
3808 const struct sctp_association *asoc,
3809 const sctp_subtype_t type,
3811 sctp_cmd_seq_t *commands)
3813 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
3814 return SCTP_DISPOSITION_CONSUME;
3817 /* We tried an illegal operation on an association which is shutting
3820 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
3821 const struct sctp_association *asoc,
3822 const sctp_subtype_t type,
3824 sctp_cmd_seq_t *commands)
3826 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
3827 SCTP_ERROR(-ESHUTDOWN));
3828 return SCTP_DISPOSITION_CONSUME;
3832 * sctp_cookie_wait_prm_shutdown
3834 * Section: 4 Note: 2
3839 * The RFC does not explicitly address this issue, but is the route through the
3840 * state table when someone issues a shutdown while in COOKIE_WAIT state.
3845 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
3846 const struct sctp_endpoint *ep,
3847 const struct sctp_association *asoc,
3848 const sctp_subtype_t type,
3850 sctp_cmd_seq_t *commands)
3852 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3853 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3855 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3856 SCTP_STATE(SCTP_STATE_CLOSED));
3858 SCTP_INC_STATS(SctpShutdowns);
3860 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3862 return SCTP_DISPOSITION_DELETE_TCB;
3866 * sctp_cookie_echoed_prm_shutdown
3868 * Section: 4 Note: 2
3873 * The RFC does not explcitly address this issue, but is the route through the
3874 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
3879 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
3880 const struct sctp_endpoint *ep,
3881 const struct sctp_association *asoc,
3882 const sctp_subtype_t type,
3883 void *arg, sctp_cmd_seq_t *commands)
3885 /* There is a single T1 timer, so we should be able to use
3886 * common function with the COOKIE-WAIT state.
3888 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
3892 * sctp_sf_cookie_wait_prm_abort
3894 * Section: 4 Note: 2
3899 * The RFC does not explicitly address this issue, but is the route through the
3900 * state table when someone issues an abort while in COOKIE_WAIT state.
3905 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
3906 const struct sctp_endpoint *ep,
3907 const struct sctp_association *asoc,
3908 const sctp_subtype_t type,
3910 sctp_cmd_seq_t *commands)
3912 struct msghdr *msg = arg;
3913 struct sctp_chunk *abort;
3914 sctp_disposition_t retval;
3916 /* Stop T1-init timer */
3917 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3918 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3919 retval = SCTP_DISPOSITION_CONSUME;
3921 /* Generate ABORT chunk to send the peer */
3922 abort = sctp_make_abort_user(asoc, NULL, msg);
3924 retval = SCTP_DISPOSITION_NOMEM;
3926 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3928 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3929 SCTP_STATE(SCTP_STATE_CLOSED));
3931 SCTP_INC_STATS(SctpAborteds);
3933 /* Even if we can't send the ABORT due to low memory delete the
3934 * TCB. This is a departure from our typical NOMEM handling.
3937 /* Delete the established association. */
3938 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3939 SCTP_U32(SCTP_ERROR_USER_ABORT));
3945 * sctp_sf_cookie_echoed_prm_abort
3947 * Section: 4 Note: 3
3952 * The RFC does not explcitly address this issue, but is the route through the
3953 * state table when someone issues an abort while in COOKIE_ECHOED state.
3958 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
3959 const struct sctp_endpoint *ep,
3960 const struct sctp_association *asoc,
3961 const sctp_subtype_t type,
3963 sctp_cmd_seq_t *commands)
3965 /* There is a single T1 timer, so we should be able to use
3966 * common function with the COOKIE-WAIT state.
3968 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
3972 * sctp_sf_shutdown_pending_prm_abort
3977 * The RFC does not explicitly address this issue, but is the route through the
3978 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
3983 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
3984 const struct sctp_endpoint *ep,
3985 const struct sctp_association *asoc,
3986 const sctp_subtype_t type,
3988 sctp_cmd_seq_t *commands)
3990 /* Stop the T5-shutdown guard timer. */
3991 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3992 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3994 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
3998 * sctp_sf_shutdown_sent_prm_abort
4003 * The RFC does not explicitly address this issue, but is the route through the
4004 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4009 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4010 const struct sctp_endpoint *ep,
4011 const struct sctp_association *asoc,
4012 const sctp_subtype_t type,
4014 sctp_cmd_seq_t *commands)
4016 /* Stop the T2-shutdown timer. */
4017 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4018 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4020 /* Stop the T5-shutdown guard timer. */
4021 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4022 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4024 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4028 * sctp_sf_cookie_echoed_prm_abort
4033 * The RFC does not explcitly address this issue, but is the route through the
4034 * state table when someone issues an abort while in COOKIE_ECHOED state.
4039 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4040 const struct sctp_endpoint *ep,
4041 const struct sctp_association *asoc,
4042 const sctp_subtype_t type,
4044 sctp_cmd_seq_t *commands)
4046 /* The same T2 timer, so we should be able to use
4047 * common function with the SHUTDOWN-SENT state.
4049 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4053 * Process the REQUESTHEARTBEAT primitive
4056 * J) Request Heartbeat
4058 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4062 * Instructs the local endpoint to perform a HeartBeat on the specified
4063 * destination transport address of the given association. The returned
4064 * result should indicate whether the transmission of the HEARTBEAT
4065 * chunk to the destination address is successful.
4067 * Mandatory attributes:
4069 * o association id - local handle to the SCTP association
4071 * o destination transport address - the transport address of the
4072 * association on which a heartbeat should be issued.
4074 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4075 const struct sctp_endpoint *ep,
4076 const struct sctp_association *asoc,
4077 const sctp_subtype_t type,
4079 sctp_cmd_seq_t *commands)
4081 return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
4086 * ADDIP Section 4.1 ASCONF Chunk Procedures
4087 * When an endpoint has an ASCONF signaled change to be sent to the
4088 * remote endpoint it should do A1 to A9
4090 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4091 const struct sctp_association *asoc,
4092 const sctp_subtype_t type,
4094 sctp_cmd_seq_t *commands)
4096 struct sctp_chunk *chunk = arg;
4098 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4099 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4100 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4101 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4102 return SCTP_DISPOSITION_CONSUME;
4106 * Ignore the primitive event
4108 * The return value is the disposition of the primitive.
4110 sctp_disposition_t sctp_sf_ignore_primitive(
4111 const struct sctp_endpoint *ep,
4112 const struct sctp_association *asoc,
4113 const sctp_subtype_t type,
4115 sctp_cmd_seq_t *commands)
4117 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4118 return SCTP_DISPOSITION_DISCARD;
4121 /***************************************************************************
4122 * These are the state functions for the OTHER events.
4123 ***************************************************************************/
4126 * Start the shutdown negotiation.
4129 * Once all its outstanding data has been acknowledged, the endpoint
4130 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4131 * TSN Ack field the last sequential TSN it has received from the peer.
4132 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4133 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4134 * with the updated last sequential TSN received from its peer.
4136 * The return value is the disposition.
4138 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4139 const struct sctp_endpoint *ep,
4140 const struct sctp_association *asoc,
4141 const sctp_subtype_t type,
4143 sctp_cmd_seq_t *commands)
4145 struct sctp_chunk *reply;
4147 /* Once all its outstanding data has been acknowledged, the
4148 * endpoint shall send a SHUTDOWN chunk to its peer including
4149 * in the Cumulative TSN Ack field the last sequential TSN it
4150 * has received from the peer.
4152 reply = sctp_make_shutdown(asoc, NULL);
4156 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4157 * T2-shutdown timer.
4159 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4161 /* It shall then start the T2-shutdown timer */
4162 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4163 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4165 if (asoc->autoclose)
4166 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4167 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4169 /* and enter the SHUTDOWN-SENT state. */
4170 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4171 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4173 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4175 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4178 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4180 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4182 return SCTP_DISPOSITION_CONSUME;
4185 return SCTP_DISPOSITION_NOMEM;
4189 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4193 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4194 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4195 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4196 * endpoint must re-send the SHUTDOWN ACK.
4198 * The return value is the disposition.
4200 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4201 const struct sctp_endpoint *ep,
4202 const struct sctp_association *asoc,
4203 const sctp_subtype_t type,
4205 sctp_cmd_seq_t *commands)
4207 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4208 struct sctp_chunk *reply;
4210 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4211 * shall send a SHUTDOWN ACK ...
4213 reply = sctp_make_shutdown_ack(asoc, chunk);
4217 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4218 * the T2-shutdown timer.
4220 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4222 /* and start/restart a T2-shutdown timer of its own, */
4223 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4224 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4226 if (asoc->autoclose)
4227 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4228 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4230 /* Enter the SHUTDOWN-ACK-SENT state. */
4231 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4232 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4234 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4236 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4239 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4241 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4243 return SCTP_DISPOSITION_CONSUME;
4246 return SCTP_DISPOSITION_NOMEM;
4250 * Ignore the event defined as other
4252 * The return value is the disposition of the event.
4254 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4255 const struct sctp_association *asoc,
4256 const sctp_subtype_t type,
4258 sctp_cmd_seq_t *commands)
4260 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4261 return SCTP_DISPOSITION_DISCARD;
4264 /************************************************************
4265 * These are the state functions for handling timeout events.
4266 ************************************************************/
4271 * Section: 6.3.3 Handle T3-rtx Expiration
4273 * Whenever the retransmission timer T3-rtx expires for a destination
4274 * address, do the following:
4277 * The return value is the disposition of the chunk.
4279 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
4280 const struct sctp_association *asoc,
4281 const sctp_subtype_t type,
4283 sctp_cmd_seq_t *commands)
4285 struct sctp_transport *transport = arg;
4287 if (asoc->overall_error_count >= asoc->max_retrans) {
4288 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4289 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4290 SCTP_U32(SCTP_ERROR_NO_ERROR));
4291 SCTP_INC_STATS(SctpAborteds);
4292 SCTP_DEC_STATS(SctpCurrEstab);
4293 return SCTP_DISPOSITION_DELETE_TCB;
4296 /* E1) For the destination address for which the timer
4297 * expires, adjust its ssthresh with rules defined in Section
4298 * 7.2.3 and set the cwnd <- MTU.
4301 /* E2) For the destination address for which the timer
4302 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4303 * maximum value discussed in rule C7 above (RTO.max) may be
4304 * used to provide an upper bound to this doubling operation.
4307 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4308 * outstanding DATA chunks for the address for which the
4309 * T3-rtx has expired will fit into a single packet, subject
4310 * to the MTU constraint for the path corresponding to the
4311 * destination transport address to which the retransmission
4312 * is being sent (this may be different from the address for
4313 * which the timer expires [see Section 6.4]). Call this
4314 * value K. Bundle and retransmit those K DATA chunks in a
4315 * single packet to the destination endpoint.
4317 * Note: Any DATA chunks that were sent to the address for
4318 * which the T3-rtx timer expired but did not fit in one MTU
4319 * (rule E3 above), should be marked for retransmission and
4320 * sent as soon as cwnd allows (normally when a SACK arrives).
4323 /* NB: Rules E4 and F1 are implicit in R1. */
4324 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4326 /* Do some failure management (Section 8.2). */
4327 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4329 return SCTP_DISPOSITION_CONSUME;
4333 * Generate delayed SACK on timeout
4335 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4337 * The guidelines on delayed acknowledgement algorithm specified in
4338 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4339 * acknowledgement SHOULD be generated for at least every second packet
4340 * (not every second DATA chunk) received, and SHOULD be generated
4341 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4342 * some situations it may be beneficial for an SCTP transmitter to be
4343 * more conservative than the algorithms detailed in this document
4344 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4345 * the following algorithms allow.
4347 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4348 const struct sctp_association *asoc,
4349 const sctp_subtype_t type,
4351 sctp_cmd_seq_t *commands)
4353 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4354 return SCTP_DISPOSITION_CONSUME;
4358 * sctp_sf_t1_timer_expire
4360 * Section: 4 Note: 2
4365 * RFC 2960 Section 4 Notes
4366 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4367 * and re-start the T1-init timer without changing state. This MUST
4368 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4369 * endpoint MUST abort the initialization process and report the
4370 * error to SCTP user.
4372 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4373 * COOKIE ECHO and re-start the T1-cookie timer without changing
4374 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4375 * After that, the endpoint MUST abort the initialization process and
4376 * report the error to SCTP user.
4382 sctp_disposition_t sctp_sf_t1_timer_expire(const struct sctp_endpoint *ep,
4383 const struct sctp_association *asoc,
4384 const sctp_subtype_t type,
4386 sctp_cmd_seq_t *commands)
4388 struct sctp_chunk *repl;
4389 struct sctp_bind_addr *bp;
4390 sctp_event_timeout_t timer = (sctp_event_timeout_t) arg;
4394 timeout = asoc->timeouts[timer];
4395 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
4398 SCTP_DEBUG_PRINTK("Timer T1 expired.\n");
4400 if (attempts < asoc->max_init_attempts) {
4402 case SCTP_EVENT_TIMEOUT_T1_INIT:
4403 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4404 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4407 case SCTP_EVENT_TIMEOUT_T1_COOKIE:
4408 repl = sctp_make_cookie_echo(asoc, NULL);
4419 /* Issue a sideeffect to do the needed accounting. */
4420 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4422 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4424 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4425 SCTP_U32(SCTP_ERROR_NO_ERROR));
4426 return SCTP_DISPOSITION_DELETE_TCB;
4429 return SCTP_DISPOSITION_CONSUME;
4432 return SCTP_DISPOSITION_NOMEM;
4435 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4436 * with the updated last sequential TSN received from its peer.
4438 * An endpoint should limit the number of retransmissions of the
4439 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4440 * If this threshold is exceeded the endpoint should destroy the TCB and
4441 * MUST report the peer endpoint unreachable to the upper layer (and
4442 * thus the association enters the CLOSED state). The reception of any
4443 * packet from its peer (i.e. as the peer sends all of its queued DATA
4444 * chunks) should clear the endpoint's retransmission count and restart
4445 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4446 * all of its queued DATA chunks that have not yet been sent.
4448 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
4449 const struct sctp_association *asoc,
4450 const sctp_subtype_t type,
4452 sctp_cmd_seq_t *commands)
4454 struct sctp_chunk *reply = NULL;
4456 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4457 if (asoc->overall_error_count >= asoc->max_retrans) {
4458 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4459 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4460 SCTP_U32(SCTP_ERROR_NO_ERROR));
4461 SCTP_INC_STATS(SctpAborteds);
4462 SCTP_DEC_STATS(SctpCurrEstab);
4463 return SCTP_DISPOSITION_DELETE_TCB;
4466 switch (asoc->state) {
4467 case SCTP_STATE_SHUTDOWN_SENT:
4468 reply = sctp_make_shutdown(asoc, NULL);
4471 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4472 reply = sctp_make_shutdown_ack(asoc, NULL);
4483 /* Do some failure management (Section 8.2). */
4484 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4485 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4487 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4488 * the T2-shutdown timer.
4490 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4492 /* Restart the T2-shutdown timer. */
4493 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4494 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4495 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4496 return SCTP_DISPOSITION_CONSUME;
4499 return SCTP_DISPOSITION_NOMEM;
4503 * ADDIP Section 4.1 ASCONF CHunk Procedures
4504 * If the T4 RTO timer expires the endpoint should do B1 to B5
4506 sctp_disposition_t sctp_sf_t4_timer_expire(
4507 const struct sctp_endpoint *ep,
4508 const struct sctp_association *asoc,
4509 const sctp_subtype_t type,
4511 sctp_cmd_seq_t *commands)
4513 struct sctp_chunk *chunk = asoc->addip_last_asconf;
4514 struct sctp_transport *transport = chunk->transport;
4516 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4517 * detection on the appropriate destination address as defined in
4518 * RFC2960 [5] section 8.1 and 8.2.
4520 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4522 /* Reconfig T4 timer and transport. */
4523 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4525 /* ADDIP 4.1 B2) Increment the association error counters and perform
4526 * endpoint failure detection on the association as defined in
4527 * RFC2960 [5] section 8.1 and 8.2.
4528 * association error counter is incremented in SCTP_CMD_STRIKE.
4530 if (asoc->overall_error_count >= asoc->max_retrans) {
4531 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4532 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4533 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4534 SCTP_U32(SCTP_ERROR_NO_ERROR));
4535 SCTP_INC_STATS(SctpAborteds);
4536 SCTP_INC_STATS(SctpCurrEstab);
4537 return SCTP_DISPOSITION_ABORT;
4540 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4541 * the ASCONF chunk was sent by doubling the RTO timer value.
4542 * This is done in SCTP_CMD_STRIKE.
4545 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4546 * choose an alternate destination address (please refer to RFC2960
4547 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4548 * chunk, it MUST be the same (including its serial number) as the last
4551 sctp_chunk_hold(asoc->addip_last_asconf);
4552 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4553 SCTP_CHUNK(asoc->addip_last_asconf));
4555 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4556 * destination is selected, then the RTO used will be that of the new
4557 * destination address.
4559 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4560 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4562 return SCTP_DISPOSITION_CONSUME;
4565 /* sctpimpguide-05 Section 2.12.2
4566 * The sender of the SHUTDOWN MAY also start an overall guard timer
4567 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4568 * At the expiration of this timer the sender SHOULD abort the association
4569 * by sending an ABORT chunk.
4571 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
4572 const struct sctp_association *asoc,
4573 const sctp_subtype_t type,
4575 sctp_cmd_seq_t *commands)
4577 struct sctp_chunk *reply = NULL;
4579 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4581 reply = sctp_make_abort(asoc, NULL, 0);
4585 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4586 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4587 SCTP_U32(SCTP_ERROR_NO_ERROR));
4589 return SCTP_DISPOSITION_DELETE_TCB;
4591 return SCTP_DISPOSITION_NOMEM;
4594 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4595 * the association is automatically closed by starting the shutdown process.
4596 * The work that needs to be done is same as when SHUTDOWN is initiated by
4597 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4599 sctp_disposition_t sctp_sf_autoclose_timer_expire(
4600 const struct sctp_endpoint *ep,
4601 const struct sctp_association *asoc,
4602 const sctp_subtype_t type,
4604 sctp_cmd_seq_t *commands)
4608 /* From 9.2 Shutdown of an Association
4609 * Upon receipt of the SHUTDOWN primitive from its upper
4610 * layer, the endpoint enters SHUTDOWN-PENDING state and
4611 * remains there until all outstanding data has been
4612 * acknowledged by its peer. The endpoint accepts no new data
4613 * from its upper layer, but retransmits data to the far end
4614 * if necessary to fill gaps.
4616 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4617 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4619 /* sctpimpguide-05 Section 2.12.2
4620 * The sender of the SHUTDOWN MAY also start an overall guard timer
4621 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4623 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4624 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4625 disposition = SCTP_DISPOSITION_CONSUME;
4626 if (sctp_outq_is_empty(&asoc->outqueue)) {
4627 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4633 /*****************************************************************************
4634 * These are sa state functions which could apply to all types of events.
4635 ****************************************************************************/
4638 * This table entry is not implemented.
4641 * (endpoint, asoc, chunk)
4643 * The return value is the disposition of the chunk.
4645 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
4646 const struct sctp_association *asoc,
4647 const sctp_subtype_t type,
4649 sctp_cmd_seq_t *commands)
4651 return SCTP_DISPOSITION_NOT_IMPL;
4655 * This table entry represents a bug.
4658 * (endpoint, asoc, chunk)
4660 * The return value is the disposition of the chunk.
4662 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
4663 const struct sctp_association *asoc,
4664 const sctp_subtype_t type,
4666 sctp_cmd_seq_t *commands)
4668 return SCTP_DISPOSITION_BUG;
4672 * This table entry represents the firing of a timer in the wrong state.
4673 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4674 * when the association is in the wrong state. This event should
4675 * be ignored, so as to prevent any rearming of the timer.
4678 * (endpoint, asoc, chunk)
4680 * The return value is the disposition of the chunk.
4682 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
4683 const struct sctp_association *asoc,
4684 const sctp_subtype_t type,
4686 sctp_cmd_seq_t *commands)
4688 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
4689 return SCTP_DISPOSITION_CONSUME;
4692 /********************************************************************
4693 * 2nd Level Abstractions
4694 ********************************************************************/
4696 /* Pull the SACK chunk based on the SACK header. */
4697 struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
4699 struct sctp_sackhdr *sack;
4704 /* Protect ourselves from reading too far into
4705 * the skb from a bogus sender.
4707 sack = (struct sctp_sackhdr *) chunk->skb->data;
4709 num_blocks = ntohs(sack->num_gap_ack_blocks);
4710 num_dup_tsns = ntohs(sack->num_dup_tsns);
4711 len = sizeof(struct sctp_sackhdr);
4712 len = (num_blocks + num_dup_tsns) * sizeof(__u32);
4713 if (len > chunk->skb->len)
4716 skb_pull(chunk->skb, len);
4721 /* Create an ABORT packet to be sent as a response, with the specified
4724 struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
4725 const struct sctp_association *asoc,
4726 struct sctp_chunk *chunk,
4727 const void *payload,
4730 struct sctp_packet *packet;
4731 struct sctp_chunk *abort;
4733 packet = sctp_ootb_pkt_new(asoc, chunk);
4737 * The T bit will be set if the asoc is NULL.
4739 abort = sctp_make_abort(asoc, chunk, paylen);
4741 sctp_ootb_pkt_free(packet);
4744 /* Add specified error causes, i.e., payload, to the
4747 sctp_addto_chunk(abort, paylen, payload);
4749 /* Set the skb to the belonging sock for accounting. */
4750 abort->skb->sk = ep->base.sk;
4752 sctp_packet_append_chunk(packet, abort);
4759 /* Allocate a packet for responding in the OOTB conditions. */
4760 struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
4761 const struct sctp_chunk *chunk)
4763 struct sctp_packet *packet;
4764 struct sctp_transport *transport;
4769 /* Get the source and destination port from the inbound packet. */
4770 sport = ntohs(chunk->sctp_hdr->dest);
4771 dport = ntohs(chunk->sctp_hdr->source);
4773 /* The V-tag is going to be the same as the inbound packet if no
4774 * association exists, otherwise, use the peer's vtag.
4777 vtag = asoc->peer.i.init_tag;
4779 /* Special case the INIT and stale COOKIE_ECHO as there is no
4782 switch(chunk->chunk_hdr->type) {
4785 sctp_init_chunk_t *init;
4787 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
4788 vtag = ntohl(init->init_hdr.init_tag);
4792 vtag = ntohl(chunk->sctp_hdr->vtag);
4797 /* Make a transport for the bucket, Eliza... */
4798 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
4802 /* Cache a route for the transport with the chunk's destination as
4803 * the source address.
4805 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
4806 sctp_sk(sctp_get_ctl_sock()));
4808 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
4809 packet = sctp_packet_config(packet, vtag, 0);
4817 /* Free the packet allocated earlier for responding in the OOTB condition. */
4818 void sctp_ootb_pkt_free(struct sctp_packet *packet)
4820 sctp_transport_free(packet->transport);
4823 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
4824 void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
4825 const struct sctp_association *asoc,
4826 const struct sctp_chunk *chunk,
4827 sctp_cmd_seq_t *commands,
4828 struct sctp_chunk *err_chunk)
4830 struct sctp_packet *packet;
4833 packet = sctp_ootb_pkt_new(asoc, chunk);
4835 struct sctp_signed_cookie *cookie;
4837 /* Override the OOTB vtag from the cookie. */
4838 cookie = chunk->subh.cookie_hdr;
4839 packet->vtag = cookie->c.peer_vtag;
4841 /* Set the skb to the belonging sock for accounting. */
4842 err_chunk->skb->sk = ep->base.sk;
4843 sctp_packet_append_chunk(packet, err_chunk);
4844 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4845 SCTP_PACKET(packet));
4846 SCTP_INC_STATS(SctpOutCtrlChunks);
4848 sctp_chunk_free (err_chunk);