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(SCTP_MIB_SHUTDOWNS);
152 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
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(SCTP_MIB_OUTCTRLCHUNKS);
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(SCTP_MIB_ABORTEDS);
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(SCTP_MIB_ABORTEDS);
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(SCTP_MIB_OUTCTRLCHUNKS);
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_TIMER_START,
476 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
477 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
478 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
480 /* 5.1 C) "A" shall then send the State Cookie received in the
481 * INIT ACK chunk in a COOKIE ECHO chunk, ...
483 /* If there is any errors to report, send the ERROR chunk generated
484 * for unknown parameters as well.
486 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
487 SCTP_CHUNK(err_chunk));
489 return SCTP_DISPOSITION_CONSUME;
492 return SCTP_DISPOSITION_NOMEM;
496 * Respond to a normal COOKIE ECHO chunk.
497 * We are the side that is being asked for an association.
499 * Section: 5.1 Normal Establishment of an Association, D
500 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
501 * with a COOKIE ACK chunk after building a TCB and moving to
502 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
503 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
504 * chunk MUST be the first chunk in the packet.
506 * IMPLEMENTATION NOTE: An implementation may choose to send the
507 * Communication Up notification to the SCTP user upon reception
508 * of a valid COOKIE ECHO chunk.
510 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
511 * D) Rules for packet carrying a COOKIE ECHO
513 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
514 * Initial Tag received in the INIT ACK.
516 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
519 * (endpoint, asoc, chunk)
522 * (asoc, reply_msg, msg_up, timers, counters)
524 * The return value is the disposition of the chunk.
526 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
527 const struct sctp_association *asoc,
528 const sctp_subtype_t type, void *arg,
529 sctp_cmd_seq_t *commands)
531 struct sctp_chunk *chunk = arg;
532 struct sctp_association *new_asoc;
533 sctp_init_chunk_t *peer_init;
534 struct sctp_chunk *repl;
535 struct sctp_ulpevent *ev;
537 struct sctp_chunk *err_chk_p;
539 /* If the packet is an OOTB packet which is temporarily on the
540 * control endpoint, respond with an ABORT.
542 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
543 return sctp_sf_ootb(ep, asoc, type, arg, commands);
545 /* "Decode" the chunk. We have no optional parameters so we
548 chunk->subh.cookie_hdr =
549 (struct sctp_signed_cookie *)chunk->skb->data;
551 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
553 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
554 * "Z" will reply with a COOKIE ACK chunk after building a TCB
555 * and moving to the ESTABLISHED state.
557 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
561 * If the re-build failed, what is the proper error path
564 * [We should abort the association. --piggy]
567 /* FIXME: Several errors are possible. A bad cookie should
568 * be silently discarded, but think about logging it too.
571 case -SCTP_IERROR_NOMEM:
574 case -SCTP_IERROR_STALE_COOKIE:
575 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
577 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
579 case -SCTP_IERROR_BAD_SIG:
581 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
585 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
586 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
587 SCTP_STATE(SCTP_STATE_ESTABLISHED));
588 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
589 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
590 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
592 if (new_asoc->autoclose)
593 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
594 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
596 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
598 /* Re-build the bind address for the association is done in
599 * the sctp_unpack_cookie() already.
601 /* This is a brand-new association, so these are not yet side
602 * effects--it is safe to run them here.
604 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
606 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
607 &chunk->subh.cookie_hdr->c.peer_addr,
608 peer_init, GFP_ATOMIC))
611 repl = sctp_make_cookie_ack(new_asoc, chunk);
615 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
617 /* RFC 2960 5.1 Normal Establishment of an Association
619 * D) IMPLEMENTATION NOTE: An implementation may choose to
620 * send the Communication Up notification to the SCTP user
621 * upon reception of a valid COOKIE ECHO chunk.
623 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
624 new_asoc->c.sinit_num_ostreams,
625 new_asoc->c.sinit_max_instreams,
630 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
632 /* Sockets API Draft Section 5.3.1.6
633 * When a peer sends a Adaption Layer Indication parameter , SCTP
634 * delivers this notification to inform the application that of the
635 * peers requested adaption layer.
637 if (new_asoc->peer.adaption_ind) {
638 ev = sctp_ulpevent_make_adaption_indication(new_asoc,
643 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
647 return SCTP_DISPOSITION_CONSUME;
650 sctp_chunk_free(repl);
653 sctp_association_free(new_asoc);
655 return SCTP_DISPOSITION_NOMEM;
659 * Respond to a normal COOKIE ACK chunk.
660 * We are the side that is being asked for an association.
662 * RFC 2960 5.1 Normal Establishment of an Association
664 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
665 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
666 * timer. It may also notify its ULP about the successful
667 * establishment of the association with a Communication Up
668 * notification (see Section 10).
672 * (endpoint, asoc, chunk)
675 * (asoc, reply_msg, msg_up, timers, counters)
677 * The return value is the disposition of the chunk.
679 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
680 const struct sctp_association *asoc,
681 const sctp_subtype_t type, void *arg,
682 sctp_cmd_seq_t *commands)
684 struct sctp_chunk *chunk = arg;
685 struct sctp_ulpevent *ev;
687 if (!sctp_vtag_verify(chunk, asoc))
688 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
690 /* Reset init error count upon receipt of COOKIE-ACK,
691 * to avoid problems with the managemement of this
692 * counter in stale cookie situations when a transition back
693 * from the COOKIE-ECHOED state to the COOKIE-WAIT
694 * state is performed.
696 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET,
697 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
699 /* RFC 2960 5.1 Normal Establishment of an Association
701 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
702 * from the COOKIE-ECHOED state to the ESTABLISHED state,
703 * stopping the T1-cookie timer.
705 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
706 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
707 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
708 SCTP_STATE(SCTP_STATE_ESTABLISHED));
709 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
710 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
711 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
713 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
714 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
715 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
717 /* It may also notify its ULP about the successful
718 * establishment of the association with a Communication Up
719 * notification (see Section 10).
721 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
722 0, asoc->c.sinit_num_ostreams,
723 asoc->c.sinit_max_instreams,
729 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
731 /* Sockets API Draft Section 5.3.1.6
732 * When a peer sends a Adaption Layer Indication parameter , SCTP
733 * delivers this notification to inform the application that of the
734 * peers requested adaption layer.
736 if (asoc->peer.adaption_ind) {
737 ev = sctp_ulpevent_make_adaption_indication(asoc, GFP_ATOMIC);
741 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
745 return SCTP_DISPOSITION_CONSUME;
747 return SCTP_DISPOSITION_NOMEM;
750 /* Generate and sendout a heartbeat packet. */
751 sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
752 const struct sctp_association *asoc,
753 const sctp_subtype_t type,
755 sctp_cmd_seq_t *commands)
757 struct sctp_transport *transport = (struct sctp_transport *) arg;
758 struct sctp_chunk *reply;
759 sctp_sender_hb_info_t hbinfo;
762 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
763 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
764 hbinfo.daddr = transport->ipaddr;
765 hbinfo.sent_at = jiffies;
767 /* Send a heartbeat to our peer. */
768 paylen = sizeof(sctp_sender_hb_info_t);
769 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
771 return SCTP_DISPOSITION_NOMEM;
773 /* Set rto_pending indicating that an RTT measurement
774 * is started with this heartbeat chunk.
776 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
777 SCTP_TRANSPORT(transport));
779 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
780 return SCTP_DISPOSITION_CONSUME;
783 /* Generate a HEARTBEAT packet on the given transport. */
784 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
785 const struct sctp_association *asoc,
786 const sctp_subtype_t type,
788 sctp_cmd_seq_t *commands)
790 struct sctp_transport *transport = (struct sctp_transport *) arg;
792 if (asoc->overall_error_count > asoc->max_retrans) {
793 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
794 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
795 SCTP_U32(SCTP_ERROR_NO_ERROR));
796 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
797 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
798 return SCTP_DISPOSITION_DELETE_TCB;
802 * The Sender-specific Heartbeat Info field should normally include
803 * information about the sender's current time when this HEARTBEAT
804 * chunk is sent and the destination transport address to which this
805 * HEARTBEAT is sent (see Section 8.3).
808 if (transport->hb_allowed) {
809 if (SCTP_DISPOSITION_NOMEM ==
810 sctp_sf_heartbeat(ep, asoc, type, arg,
812 return SCTP_DISPOSITION_NOMEM;
813 /* Set transport error counter and association error counter
814 * when sending heartbeat.
816 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
817 SCTP_TRANSPORT(transport));
819 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
820 SCTP_TRANSPORT(transport));
822 return SCTP_DISPOSITION_CONSUME;
826 * Process an heartbeat request.
828 * Section: 8.3 Path Heartbeat
829 * The receiver of the HEARTBEAT should immediately respond with a
830 * HEARTBEAT ACK that contains the Heartbeat Information field copied
831 * from the received HEARTBEAT chunk.
833 * Verification Tag: 8.5 Verification Tag [Normal verification]
834 * When receiving an SCTP packet, the endpoint MUST ensure that the
835 * value in the Verification Tag field of the received SCTP packet
836 * matches its own Tag. If the received Verification Tag value does not
837 * match the receiver's own tag value, the receiver shall silently
838 * discard the packet and shall not process it any further except for
839 * those cases listed in Section 8.5.1 below.
842 * (endpoint, asoc, chunk)
845 * (asoc, reply_msg, msg_up, timers, counters)
847 * The return value is the disposition of the chunk.
849 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
850 const struct sctp_association *asoc,
851 const sctp_subtype_t type,
853 sctp_cmd_seq_t *commands)
855 struct sctp_chunk *chunk = arg;
856 struct sctp_chunk *reply;
859 if (!sctp_vtag_verify(chunk, asoc))
860 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
862 /* 8.3 The receiver of the HEARTBEAT should immediately
863 * respond with a HEARTBEAT ACK that contains the Heartbeat
864 * Information field copied from the received HEARTBEAT chunk.
866 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
867 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
868 skb_pull(chunk->skb, paylen);
870 reply = sctp_make_heartbeat_ack(asoc, chunk,
871 chunk->subh.hb_hdr, paylen);
875 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
876 return SCTP_DISPOSITION_CONSUME;
879 return SCTP_DISPOSITION_NOMEM;
883 * Process the returning HEARTBEAT ACK.
885 * Section: 8.3 Path Heartbeat
886 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
887 * should clear the error counter of the destination transport
888 * address to which the HEARTBEAT was sent, and mark the destination
889 * transport address as active if it is not so marked. The endpoint may
890 * optionally report to the upper layer when an inactive destination
891 * address is marked as active due to the reception of the latest
892 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
893 * clear the association overall error count as well (as defined
896 * The receiver of the HEARTBEAT ACK should also perform an RTT
897 * measurement for that destination transport address using the time
898 * value carried in the HEARTBEAT ACK chunk.
900 * Verification Tag: 8.5 Verification Tag [Normal verification]
903 * (endpoint, asoc, chunk)
906 * (asoc, reply_msg, msg_up, timers, counters)
908 * The return value is the disposition of the chunk.
910 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
911 const struct sctp_association *asoc,
912 const sctp_subtype_t type,
914 sctp_cmd_seq_t *commands)
916 struct sctp_chunk *chunk = arg;
917 union sctp_addr from_addr;
918 struct sctp_transport *link;
919 sctp_sender_hb_info_t *hbinfo;
920 unsigned long max_interval;
922 if (!sctp_vtag_verify(chunk, asoc))
923 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
925 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
926 from_addr = hbinfo->daddr;
927 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
929 /* This should never happen, but lets log it if so. */
932 "%s: Could not find address %d.%d.%d.%d\n",
933 __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr));
934 return SCTP_DISPOSITION_DISCARD;
937 max_interval = link->hb_interval + link->rto;
939 /* Check if the timestamp looks valid. */
940 if (time_after(hbinfo->sent_at, jiffies) ||
941 time_after(jiffies, hbinfo->sent_at + max_interval)) {
942 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
943 "received for transport: %p\n",
945 return SCTP_DISPOSITION_DISCARD;
948 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
949 * the HEARTBEAT should clear the error counter of the
950 * destination transport address to which the HEARTBEAT was
951 * sent and mark the destination transport address as active if
952 * it is not so marked.
954 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
956 return SCTP_DISPOSITION_CONSUME;
959 /* Helper function to send out an abort for the restart
962 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
963 struct sctp_chunk *init,
964 sctp_cmd_seq_t *commands)
967 struct sctp_packet *pkt;
968 union sctp_addr_param *addrparm;
969 struct sctp_errhdr *errhdr;
970 struct sctp_endpoint *ep;
971 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
972 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
974 /* Build the error on the stack. We are way to malloc crazy
975 * throughout the code today.
977 errhdr = (struct sctp_errhdr *)buffer;
978 addrparm = (union sctp_addr_param *)errhdr->variable;
980 /* Copy into a parm format. */
981 len = af->to_addr_param(ssa, addrparm);
982 len += sizeof(sctp_errhdr_t);
984 errhdr->cause = SCTP_ERROR_RESTART;
985 errhdr->length = htons(len);
987 /* Assign to the control socket. */
988 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
990 /* Association is NULL since this may be a restart attack and we
991 * want to send back the attacker's vtag.
993 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
997 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
999 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1001 /* Discard the rest of the inbound packet. */
1002 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1005 /* Even if there is no memory, treat as a failure so
1006 * the packet will get dropped.
1011 /* A restart is occurring, check to make sure no new addresses
1012 * are being added as we may be under a takeover attack.
1014 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1015 const struct sctp_association *asoc,
1016 struct sctp_chunk *init,
1017 sctp_cmd_seq_t *commands)
1019 struct sctp_transport *new_addr, *addr;
1020 struct list_head *pos, *pos2;
1023 /* Implementor's Guide - Sectin 5.2.2
1025 * Before responding the endpoint MUST check to see if the
1026 * unexpected INIT adds new addresses to the association. If new
1027 * addresses are added to the association, the endpoint MUST respond
1031 /* Search through all current addresses and make sure
1032 * we aren't adding any new ones.
1037 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1038 new_addr = list_entry(pos, struct sctp_transport, transports);
1040 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1041 addr = list_entry(pos2, struct sctp_transport,
1043 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1053 /* If a new address was added, ABORT the sender. */
1054 if (!found && new_addr) {
1055 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1058 /* Return success if all addresses were found. */
1062 /* Populate the verification/tie tags based on overlapping INIT
1065 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1067 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1068 const struct sctp_association *asoc)
1070 switch (asoc->state) {
1072 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1074 case SCTP_STATE_COOKIE_WAIT:
1075 new_asoc->c.my_vtag = asoc->c.my_vtag;
1076 new_asoc->c.my_ttag = asoc->c.my_vtag;
1077 new_asoc->c.peer_ttag = 0;
1080 case SCTP_STATE_COOKIE_ECHOED:
1081 new_asoc->c.my_vtag = asoc->c.my_vtag;
1082 new_asoc->c.my_ttag = asoc->c.my_vtag;
1083 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1086 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1087 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1090 new_asoc->c.my_ttag = asoc->c.my_vtag;
1091 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1095 /* Other parameters for the endpoint SHOULD be copied from the
1096 * existing parameters of the association (e.g. number of
1097 * outbound streams) into the INIT ACK and cookie.
1099 new_asoc->rwnd = asoc->rwnd;
1100 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1101 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1102 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1106 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1109 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1111 * Returns value representing action to be taken. These action values
1112 * correspond to Action/Description values in RFC 2960, Table 2.
1114 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1115 const struct sctp_association *asoc)
1117 /* In this case, the peer may have restarted. */
1118 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1119 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1120 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1121 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1124 /* Collision case B. */
1125 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1126 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1127 (0 == asoc->c.peer_vtag))) {
1131 /* Collision case D. */
1132 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1133 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1136 /* Collision case C. */
1137 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1138 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1139 (0 == new_asoc->c.my_ttag) &&
1140 (0 == new_asoc->c.peer_ttag))
1143 /* No match to any of the special cases; discard this packet. */
1147 /* Common helper routine for both duplicate and simulataneous INIT
1150 static sctp_disposition_t sctp_sf_do_unexpected_init(
1151 const struct sctp_endpoint *ep,
1152 const struct sctp_association *asoc,
1153 const sctp_subtype_t type,
1154 void *arg, sctp_cmd_seq_t *commands)
1156 sctp_disposition_t retval;
1157 struct sctp_chunk *chunk = arg;
1158 struct sctp_chunk *repl;
1159 struct sctp_association *new_asoc;
1160 struct sctp_chunk *err_chunk;
1161 struct sctp_packet *packet;
1162 sctp_unrecognized_param_t *unk_param;
1166 * An endpoint MUST NOT bundle INIT, INIT ACK or
1167 * SHUTDOWN COMPLETE with any other chunks.
1169 if (!chunk->singleton)
1170 return SCTP_DISPOSITION_VIOLATION;
1172 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1175 if (chunk->sctp_hdr->vtag != 0)
1176 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1178 /* Grab the INIT header. */
1179 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1181 /* Tag the variable length parameters. */
1182 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1184 /* Verify the INIT chunk before processing it. */
1186 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1187 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1189 /* This chunk contains fatal error. It is to be discarded.
1190 * Send an ABORT, with causes if there is any.
1193 packet = sctp_abort_pkt_new(ep, asoc, arg,
1194 (__u8 *)(err_chunk->chunk_hdr) +
1195 sizeof(sctp_chunkhdr_t),
1196 ntohs(err_chunk->chunk_hdr->length) -
1197 sizeof(sctp_chunkhdr_t));
1200 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1201 SCTP_PACKET(packet));
1202 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1203 retval = SCTP_DISPOSITION_CONSUME;
1205 retval = SCTP_DISPOSITION_NOMEM;
1209 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1215 * Other parameters for the endpoint SHOULD be copied from the
1216 * existing parameters of the association (e.g. number of
1217 * outbound streams) into the INIT ACK and cookie.
1218 * FIXME: We are copying parameters from the endpoint not the
1221 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1225 /* In the outbound INIT ACK the endpoint MUST copy its current
1226 * Verification Tag and Peers Verification tag into a reserved
1227 * place (local tie-tag and per tie-tag) within the state cookie.
1229 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1231 (sctp_init_chunk_t *)chunk->chunk_hdr,
1233 retval = SCTP_DISPOSITION_NOMEM;
1237 /* Make sure no new addresses are being added during the
1238 * restart. Do not do this check for COOKIE-WAIT state,
1239 * since there are no peer addresses to check against.
1240 * Upon return an ABORT will have been sent if needed.
1242 if (!sctp_state(asoc, COOKIE_WAIT)) {
1243 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1245 retval = SCTP_DISPOSITION_CONSUME;
1250 sctp_tietags_populate(new_asoc, asoc);
1252 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1254 /* If there are errors need to be reported for unknown parameters,
1255 * make sure to reserve enough room in the INIT ACK for them.
1259 len = ntohs(err_chunk->chunk_hdr->length) -
1260 sizeof(sctp_chunkhdr_t);
1263 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1266 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1270 /* If there are errors need to be reported for unknown parameters,
1271 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1275 /* Get the "Unrecognized parameter" parameter(s) out of the
1276 * ERROR chunk generated by sctp_verify_init(). Since the
1277 * error cause code for "unknown parameter" and the
1278 * "Unrecognized parameter" type is the same, we can
1279 * construct the parameters in INIT ACK by copying the
1280 * ERROR causes over.
1282 unk_param = (sctp_unrecognized_param_t *)
1283 ((__u8 *)(err_chunk->chunk_hdr) +
1284 sizeof(sctp_chunkhdr_t));
1285 /* Replace the cause code with the "Unrecognized parameter"
1288 sctp_addto_chunk(repl, len, unk_param);
1291 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1292 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1295 * Note: After sending out INIT ACK with the State Cookie parameter,
1296 * "Z" MUST NOT allocate any resources for this new association.
1297 * Otherwise, "Z" will be vulnerable to resource attacks.
1299 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1300 retval = SCTP_DISPOSITION_CONSUME;
1304 sctp_chunk_free(err_chunk);
1307 retval = SCTP_DISPOSITION_NOMEM;
1311 sctp_association_free(new_asoc);
1316 * Handle simultanous INIT.
1317 * This means we started an INIT and then we got an INIT request from
1320 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1321 * This usually indicates an initialization collision, i.e., each
1322 * endpoint is attempting, at about the same time, to establish an
1323 * association with the other endpoint.
1325 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1326 * endpoint MUST respond with an INIT ACK using the same parameters it
1327 * sent in its original INIT chunk (including its Verification Tag,
1328 * unchanged). These original parameters are combined with those from the
1329 * newly received INIT chunk. The endpoint shall also generate a State
1330 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1331 * INIT to calculate the State Cookie.
1333 * After that, the endpoint MUST NOT change its state, the T1-init
1334 * timer shall be left running and the corresponding TCB MUST NOT be
1335 * destroyed. The normal procedures for handling State Cookies when
1336 * a TCB exists will resolve the duplicate INITs to a single association.
1338 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1339 * its Tie-Tags with the Tag information of itself and its peer (see
1340 * section 5.2.2 for a description of the Tie-Tags).
1342 * Verification Tag: Not explicit, but an INIT can not have a valid
1343 * verification tag, so we skip the check.
1346 * (endpoint, asoc, chunk)
1349 * (asoc, reply_msg, msg_up, timers, counters)
1351 * The return value is the disposition of the chunk.
1353 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1354 const struct sctp_association *asoc,
1355 const sctp_subtype_t type,
1357 sctp_cmd_seq_t *commands)
1359 /* Call helper to do the real work for both simulataneous and
1360 * duplicate INIT chunk handling.
1362 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1366 * Handle duplicated INIT messages. These are usually delayed
1369 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1370 * COOKIE-ECHOED and COOKIE-WAIT
1372 * Unless otherwise stated, upon reception of an unexpected INIT for
1373 * this association, the endpoint shall generate an INIT ACK with a
1374 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1375 * current Verification Tag and peer's Verification Tag into a reserved
1376 * place within the state cookie. We shall refer to these locations as
1377 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1378 * containing this INIT ACK MUST carry a Verification Tag value equal to
1379 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1380 * MUST contain a new Initiation Tag (randomly generated see Section
1381 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1382 * existing parameters of the association (e.g. number of outbound
1383 * streams) into the INIT ACK and cookie.
1385 * After sending out the INIT ACK, the endpoint shall take no further
1386 * actions, i.e., the existing association, including its current state,
1387 * and the corresponding TCB MUST NOT be changed.
1389 * Note: Only when a TCB exists and the association is not in a COOKIE-
1390 * WAIT state are the Tie-Tags populated. For a normal association INIT
1391 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1392 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1393 * State Cookie are populated as specified in section 5.2.1.
1395 * Verification Tag: Not specified, but an INIT has no way of knowing
1396 * what the verification tag could be, so we ignore it.
1399 * (endpoint, asoc, chunk)
1402 * (asoc, reply_msg, msg_up, timers, counters)
1404 * The return value is the disposition of the chunk.
1406 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1407 const struct sctp_association *asoc,
1408 const sctp_subtype_t type,
1410 sctp_cmd_seq_t *commands)
1412 /* Call helper to do the real work for both simulataneous and
1413 * duplicate INIT chunk handling.
1415 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1420 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1423 * A) In this case, the peer may have restarted.
1425 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1426 const struct sctp_association *asoc,
1427 struct sctp_chunk *chunk,
1428 sctp_cmd_seq_t *commands,
1429 struct sctp_association *new_asoc)
1431 sctp_init_chunk_t *peer_init;
1432 struct sctp_ulpevent *ev;
1433 struct sctp_chunk *repl;
1434 struct sctp_chunk *err;
1435 sctp_disposition_t disposition;
1437 /* new_asoc is a brand-new association, so these are not yet
1438 * side effects--it is safe to run them here.
1440 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1442 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1443 sctp_source(chunk), peer_init,
1447 /* Make sure no new addresses are being added during the
1448 * restart. Though this is a pretty complicated attack
1449 * since you'd have to get inside the cookie.
1451 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1452 return SCTP_DISPOSITION_CONSUME;
1455 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1456 * the peer has restarted (Action A), it MUST NOT setup a new
1457 * association but instead resend the SHUTDOWN ACK and send an ERROR
1458 * chunk with a "Cookie Received while Shutting Down" error cause to
1461 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1462 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1463 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1465 if (SCTP_DISPOSITION_NOMEM == disposition)
1468 err = sctp_make_op_error(asoc, chunk,
1469 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1472 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1475 return SCTP_DISPOSITION_CONSUME;
1478 /* For now, fail any unsent/unacked data. Consider the optional
1479 * choice of resending of this data.
1481 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1483 /* Update the content of current association. */
1484 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1486 repl = sctp_make_cookie_ack(new_asoc, chunk);
1490 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1492 /* Report association restart to upper layer. */
1493 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1494 new_asoc->c.sinit_num_ostreams,
1495 new_asoc->c.sinit_max_instreams,
1500 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1501 return SCTP_DISPOSITION_CONSUME;
1504 sctp_chunk_free(repl);
1506 return SCTP_DISPOSITION_NOMEM;
1509 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1512 * B) In this case, both sides may be attempting to start an association
1513 * at about the same time but the peer endpoint started its INIT
1514 * after responding to the local endpoint's INIT
1516 /* This case represents an initialization collision. */
1517 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1518 const struct sctp_association *asoc,
1519 struct sctp_chunk *chunk,
1520 sctp_cmd_seq_t *commands,
1521 struct sctp_association *new_asoc)
1523 sctp_init_chunk_t *peer_init;
1524 struct sctp_ulpevent *ev;
1525 struct sctp_chunk *repl;
1527 /* new_asoc is a brand-new association, so these are not yet
1528 * side effects--it is safe to run them here.
1530 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1531 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1532 sctp_source(chunk), peer_init,
1536 /* Update the content of current association. */
1537 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1538 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1539 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1540 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1541 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1543 repl = sctp_make_cookie_ack(new_asoc, chunk);
1547 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1548 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1550 /* RFC 2960 5.1 Normal Establishment of an Association
1552 * D) IMPLEMENTATION NOTE: An implementation may choose to
1553 * send the Communication Up notification to the SCTP user
1554 * upon reception of a valid COOKIE ECHO chunk.
1556 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
1557 new_asoc->c.sinit_num_ostreams,
1558 new_asoc->c.sinit_max_instreams,
1563 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1565 /* Sockets API Draft Section 5.3.1.6
1566 * When a peer sends a Adaption Layer Indication parameter , SCTP
1567 * delivers this notification to inform the application that of the
1568 * peers requested adaption layer.
1570 if (asoc->peer.adaption_ind) {
1571 ev = sctp_ulpevent_make_adaption_indication(asoc, GFP_ATOMIC);
1575 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1579 return SCTP_DISPOSITION_CONSUME;
1582 sctp_chunk_free(repl);
1584 return SCTP_DISPOSITION_NOMEM;
1587 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1590 * C) In this case, the local endpoint's cookie has arrived late.
1591 * Before it arrived, the local endpoint sent an INIT and received an
1592 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1593 * but a new tag of its own.
1595 /* This case represents an initialization collision. */
1596 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1597 const struct sctp_association *asoc,
1598 struct sctp_chunk *chunk,
1599 sctp_cmd_seq_t *commands,
1600 struct sctp_association *new_asoc)
1602 /* The cookie should be silently discarded.
1603 * The endpoint SHOULD NOT change states and should leave
1604 * any timers running.
1606 return SCTP_DISPOSITION_DISCARD;
1609 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1613 * D) When both local and remote tags match the endpoint should always
1614 * enter the ESTABLISHED state, if it has not already done so.
1616 /* This case represents an initialization collision. */
1617 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1618 const struct sctp_association *asoc,
1619 struct sctp_chunk *chunk,
1620 sctp_cmd_seq_t *commands,
1621 struct sctp_association *new_asoc)
1623 struct sctp_ulpevent *ev = NULL;
1624 struct sctp_chunk *repl;
1626 /* Clarification from Implementor's Guide:
1627 * D) When both local and remote tags match the endpoint should
1628 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1629 * It should stop any cookie timer that may be running and send
1633 /* Don't accidentally move back into established state. */
1634 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1635 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1636 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1637 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1638 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1639 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1640 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1643 /* RFC 2960 5.1 Normal Establishment of an Association
1645 * D) IMPLEMENTATION NOTE: An implementation may choose
1646 * to send the Communication Up notification to the
1647 * SCTP user upon reception of a valid COOKIE
1650 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
1652 new_asoc->c.sinit_num_ostreams,
1653 new_asoc->c.sinit_max_instreams,
1657 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1660 /* Sockets API Draft Section 5.3.1.6
1661 * When a peer sends a Adaption Layer Indication parameter,
1662 * SCTP delivers this notification to inform the application
1663 * that of the peers requested adaption layer.
1665 if (new_asoc->peer.adaption_ind) {
1666 ev = sctp_ulpevent_make_adaption_indication(new_asoc,
1671 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1675 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1677 repl = sctp_make_cookie_ack(new_asoc, chunk);
1681 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1682 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1684 return SCTP_DISPOSITION_CONSUME;
1688 sctp_ulpevent_free(ev);
1689 return SCTP_DISPOSITION_NOMEM;
1693 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1694 * chunk was retransmitted and then delayed in the network.
1696 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1698 * Verification Tag: None. Do cookie validation.
1701 * (endpoint, asoc, chunk)
1704 * (asoc, reply_msg, msg_up, timers, counters)
1706 * The return value is the disposition of the chunk.
1708 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1709 const struct sctp_association *asoc,
1710 const sctp_subtype_t type,
1712 sctp_cmd_seq_t *commands)
1714 sctp_disposition_t retval;
1715 struct sctp_chunk *chunk = arg;
1716 struct sctp_association *new_asoc;
1719 struct sctp_chunk *err_chk_p;
1721 /* "Decode" the chunk. We have no optional parameters so we
1722 * are in good shape.
1724 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1725 skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1726 sizeof(sctp_chunkhdr_t));
1728 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1729 * of a duplicate COOKIE ECHO match the Verification Tags of the
1730 * current association, consider the State Cookie valid even if
1731 * the lifespan is exceeded.
1733 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1737 * If the re-build failed, what is the proper error path
1740 * [We should abort the association. --piggy]
1743 /* FIXME: Several errors are possible. A bad cookie should
1744 * be silently discarded, but think about logging it too.
1747 case -SCTP_IERROR_NOMEM:
1750 case -SCTP_IERROR_STALE_COOKIE:
1751 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1753 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1754 case -SCTP_IERROR_BAD_SIG:
1756 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1760 /* Compare the tie_tag in cookie with the verification tag of
1761 * current association.
1763 action = sctp_tietags_compare(new_asoc, asoc);
1766 case 'A': /* Association restart. */
1767 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1771 case 'B': /* Collision case B. */
1772 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1776 case 'C': /* Collision case C. */
1777 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1781 case 'D': /* Collision case D. */
1782 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1786 default: /* Discard packet for all others. */
1787 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1791 /* Delete the tempory new association. */
1792 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1793 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1798 return SCTP_DISPOSITION_NOMEM;
1802 * Process an ABORT. (SHUTDOWN-PENDING state)
1804 * See sctp_sf_do_9_1_abort().
1806 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1807 const struct sctp_endpoint *ep,
1808 const struct sctp_association *asoc,
1809 const sctp_subtype_t type,
1811 sctp_cmd_seq_t *commands)
1813 struct sctp_chunk *chunk = arg;
1815 if (!sctp_vtag_verify_either(chunk, asoc))
1816 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1818 /* Stop the T5-shutdown guard timer. */
1819 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1820 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1822 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1826 * Process an ABORT. (SHUTDOWN-SENT state)
1828 * See sctp_sf_do_9_1_abort().
1830 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
1831 const struct sctp_association *asoc,
1832 const sctp_subtype_t type,
1834 sctp_cmd_seq_t *commands)
1836 struct sctp_chunk *chunk = arg;
1838 if (!sctp_vtag_verify_either(chunk, asoc))
1839 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1841 /* Stop the T2-shutdown timer. */
1842 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1843 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
1845 /* Stop the T5-shutdown guard timer. */
1846 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1847 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1849 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1853 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
1855 * See sctp_sf_do_9_1_abort().
1857 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
1858 const struct sctp_endpoint *ep,
1859 const struct sctp_association *asoc,
1860 const sctp_subtype_t type,
1862 sctp_cmd_seq_t *commands)
1864 /* The same T2 timer, so we should be able to use
1865 * common function with the SHUTDOWN-SENT state.
1867 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
1871 * Handle an Error received in COOKIE_ECHOED state.
1873 * Only handle the error type of stale COOKIE Error, the other errors will
1877 * (endpoint, asoc, chunk)
1880 * (asoc, reply_msg, msg_up, timers, counters)
1882 * The return value is the disposition of the chunk.
1884 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
1885 const struct sctp_association *asoc,
1886 const sctp_subtype_t type,
1888 sctp_cmd_seq_t *commands)
1890 struct sctp_chunk *chunk = arg;
1893 /* Process the error here */
1894 /* FUTURE FIXME: When PR-SCTP related and other optional
1895 * parms are emitted, this will have to change to handle multiple
1898 sctp_walk_errors(err, chunk->chunk_hdr) {
1899 if (SCTP_ERROR_STALE_COOKIE == err->cause)
1900 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
1903 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1907 * Handle a Stale COOKIE Error
1909 * Section: 5.2.6 Handle Stale COOKIE Error
1910 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
1911 * one of the following three alternatives.
1913 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
1914 * Preservative parameter requesting an extension to the lifetime of
1915 * the State Cookie. When calculating the time extension, an
1916 * implementation SHOULD use the RTT information measured based on the
1917 * previous COOKIE ECHO / ERROR exchange, and should add no more
1918 * than 1 second beyond the measured RTT, due to long State Cookie
1919 * lifetimes making the endpoint more subject to a replay attack.
1921 * Verification Tag: Not explicit, but safe to ignore.
1924 * (endpoint, asoc, chunk)
1927 * (asoc, reply_msg, msg_up, timers, counters)
1929 * The return value is the disposition of the chunk.
1931 sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
1932 const struct sctp_association *asoc,
1933 const sctp_subtype_t type,
1935 sctp_cmd_seq_t *commands)
1937 struct sctp_chunk *chunk = arg;
1939 sctp_cookie_preserve_param_t bht;
1941 struct sctp_chunk *reply;
1942 struct sctp_bind_addr *bp;
1945 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
1947 if (attempts >= asoc->max_init_attempts) {
1948 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
1949 SCTP_U32(SCTP_ERROR_STALE_COOKIE));
1950 return SCTP_DISPOSITION_DELETE_TCB;
1953 err = (sctp_errhdr_t *)(chunk->skb->data);
1955 /* When calculating the time extension, an implementation
1956 * SHOULD use the RTT information measured based on the
1957 * previous COOKIE ECHO / ERROR exchange, and should add no
1958 * more than 1 second beyond the measured RTT, due to long
1959 * State Cookie lifetimes making the endpoint more subject to
1961 * Measure of Staleness's unit is usec. (1/1000000 sec)
1962 * Suggested Cookie Life-span Increment's unit is msec.
1964 * In general, if you use the suggested cookie life, the value
1965 * found in the field of measure of staleness should be doubled
1966 * to give ample time to retransmit the new cookie and thus
1967 * yield a higher probability of success on the reattempt.
1969 stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
1970 stale = (stale * 2) / 1000;
1972 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
1973 bht.param_hdr.length = htons(sizeof(bht));
1974 bht.lifespan_increment = htonl(stale);
1976 /* Build that new INIT chunk. */
1977 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
1978 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
1982 sctp_addto_chunk(reply, sizeof(bht), &bht);
1984 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
1985 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
1987 /* Stop pending T3-rtx and heartbeat timers */
1988 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
1989 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
1991 /* Delete non-primary peer ip addresses since we are transitioning
1992 * back to the COOKIE-WAIT state
1994 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
1996 /* If we've sent any data bundled with COOKIE-ECHO we will need to
1999 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN,
2000 SCTP_TRANSPORT(asoc->peer.primary_path));
2002 /* Cast away the const modifier, as we want to just
2003 * rerun it through as a sideffect.
2005 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
2006 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
2008 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2009 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2010 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2011 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2012 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2013 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2015 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2017 return SCTP_DISPOSITION_CONSUME;
2020 return SCTP_DISPOSITION_NOMEM;
2027 * After checking the Verification Tag, the receiving endpoint shall
2028 * remove the association from its record, and shall report the
2029 * termination to its upper layer.
2031 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2032 * B) Rules for packet carrying ABORT:
2034 * - The endpoint shall always fill in the Verification Tag field of the
2035 * outbound packet with the destination endpoint's tag value if it
2038 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2039 * MUST follow the procedure described in Section 8.4.
2041 * - The receiver MUST accept the packet if the Verification Tag
2042 * matches either its own tag, OR the tag of its peer. Otherwise, the
2043 * receiver MUST silently discard the packet and take no further
2047 * (endpoint, asoc, chunk)
2050 * (asoc, reply_msg, msg_up, timers, counters)
2052 * The return value is the disposition of the chunk.
2054 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2055 const struct sctp_association *asoc,
2056 const sctp_subtype_t type,
2058 sctp_cmd_seq_t *commands)
2060 struct sctp_chunk *chunk = arg;
2062 __u16 error = SCTP_ERROR_NO_ERROR;
2064 if (!sctp_vtag_verify_either(chunk, asoc))
2065 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2067 /* Check that chunk header looks valid. */
2068 len = ntohs(chunk->chunk_hdr->length);
2069 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2070 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2073 /* ASSOC_FAILED will DELETE_TCB. */
2074 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error));
2075 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2076 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2078 return SCTP_DISPOSITION_ABORT;
2082 * Process an ABORT. (COOKIE-WAIT state)
2084 * See sctp_sf_do_9_1_abort() above.
2086 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
2087 const struct sctp_association *asoc,
2088 const sctp_subtype_t type,
2090 sctp_cmd_seq_t *commands)
2092 struct sctp_chunk *chunk = arg;
2094 __u16 error = SCTP_ERROR_NO_ERROR;
2096 if (!sctp_vtag_verify_either(chunk, asoc))
2097 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2099 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2100 SCTP_STATE(SCTP_STATE_CLOSED));
2101 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2102 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2103 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2105 /* Check that chunk header looks valid. */
2106 len = ntohs(chunk->chunk_hdr->length);
2107 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2108 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2110 /* CMD_INIT_FAILED will DELETE_TCB. */
2111 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_U32(error));
2113 return SCTP_DISPOSITION_ABORT;
2117 * Process an ABORT. (COOKIE-ECHOED state)
2119 * See sctp_sf_do_9_1_abort() above.
2121 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2122 const struct sctp_association *asoc,
2123 const sctp_subtype_t type,
2125 sctp_cmd_seq_t *commands)
2127 /* There is a single T1 timer, so we should be able to use
2128 * common function with the COOKIE-WAIT state.
2130 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2134 * sctp_sf_do_9_2_shut
2137 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2138 * - enter the SHUTDOWN-RECEIVED state,
2140 * - stop accepting new data from its SCTP user
2142 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2143 * that all its outstanding DATA chunks have been received by the
2146 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2147 * send a SHUTDOWN in response to a ULP request. And should discard
2148 * subsequent SHUTDOWN chunks.
2150 * If there are still outstanding DATA chunks left, the SHUTDOWN
2151 * receiver shall continue to follow normal data transmission
2152 * procedures defined in Section 6 until all outstanding DATA chunks
2153 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2154 * new data from its SCTP user.
2156 * Verification Tag: 8.5 Verification Tag [Normal verification]
2159 * (endpoint, asoc, chunk)
2162 * (asoc, reply_msg, msg_up, timers, counters)
2164 * The return value is the disposition of the chunk.
2166 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2167 const struct sctp_association *asoc,
2168 const sctp_subtype_t type,
2170 sctp_cmd_seq_t *commands)
2172 struct sctp_chunk *chunk = arg;
2173 sctp_shutdownhdr_t *sdh;
2174 sctp_disposition_t disposition;
2175 struct sctp_ulpevent *ev;
2177 /* Convert the elaborate header. */
2178 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2179 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2180 chunk->subh.shutdown_hdr = sdh;
2182 if (!sctp_vtag_verify(chunk, asoc))
2183 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2185 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2186 * - enter the SHUTDOWN-RECEIVED state,
2187 * - stop accepting new data from its SCTP user
2189 * [This is implicit in the new state.]
2191 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2192 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2193 disposition = SCTP_DISPOSITION_CONSUME;
2195 if (sctp_outq_is_empty(&asoc->outqueue)) {
2196 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2200 if (SCTP_DISPOSITION_NOMEM == disposition)
2203 /* - verify, by checking the Cumulative TSN Ack field of the
2204 * chunk, that all its outstanding DATA chunks have been
2205 * received by the SHUTDOWN sender.
2207 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2208 SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2210 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2211 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2212 * inform the application that it should cease sending data.
2214 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2216 disposition = SCTP_DISPOSITION_NOMEM;
2219 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2226 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2227 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2228 * transport addresses (either in the IP addresses or in the INIT chunk)
2229 * that belong to this association, it should discard the INIT chunk and
2230 * retransmit the SHUTDOWN ACK chunk.
2232 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2233 const struct sctp_association *asoc,
2234 const sctp_subtype_t type,
2236 sctp_cmd_seq_t *commands)
2238 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2239 struct sctp_chunk *reply;
2241 reply = sctp_make_shutdown_ack(asoc, chunk);
2245 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2246 * the T2-SHUTDOWN timer.
2248 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2250 /* and restart the T2-shutdown timer. */
2251 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2252 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2254 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2256 return SCTP_DISPOSITION_CONSUME;
2258 return SCTP_DISPOSITION_NOMEM;
2262 * sctp_sf_do_ecn_cwr
2264 * Section: Appendix A: Explicit Congestion Notification
2268 * RFC 2481 details a specific bit for a sender to send in the header of
2269 * its next outbound TCP segment to indicate to its peer that it has
2270 * reduced its congestion window. This is termed the CWR bit. For
2271 * SCTP the same indication is made by including the CWR chunk.
2272 * This chunk contains one data element, i.e. the TSN number that
2273 * was sent in the ECNE chunk. This element represents the lowest
2274 * TSN number in the datagram that was originally marked with the
2277 * Verification Tag: 8.5 Verification Tag [Normal verification]
2279 * (endpoint, asoc, chunk)
2282 * (asoc, reply_msg, msg_up, timers, counters)
2284 * The return value is the disposition of the chunk.
2286 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2287 const struct sctp_association *asoc,
2288 const sctp_subtype_t type,
2290 sctp_cmd_seq_t *commands)
2293 struct sctp_chunk *chunk = arg;
2295 if (!sctp_vtag_verify(chunk, asoc))
2296 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2298 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2299 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2301 cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
2303 /* Does this CWR ack the last sent congestion notification? */
2304 if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
2305 /* Stop sending ECNE. */
2306 sctp_add_cmd_sf(commands,
2308 SCTP_U32(cwr->lowest_tsn));
2310 return SCTP_DISPOSITION_CONSUME;
2316 * Section: Appendix A: Explicit Congestion Notification
2320 * RFC 2481 details a specific bit for a receiver to send back in its
2321 * TCP acknowledgements to notify the sender of the Congestion
2322 * Experienced (CE) bit having arrived from the network. For SCTP this
2323 * same indication is made by including the ECNE chunk. This chunk
2324 * contains one data element, i.e. the lowest TSN associated with the IP
2325 * datagram marked with the CE bit.....
2327 * Verification Tag: 8.5 Verification Tag [Normal verification]
2329 * (endpoint, asoc, chunk)
2332 * (asoc, reply_msg, msg_up, timers, counters)
2334 * The return value is the disposition of the chunk.
2336 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2337 const struct sctp_association *asoc,
2338 const sctp_subtype_t type,
2340 sctp_cmd_seq_t *commands)
2342 sctp_ecnehdr_t *ecne;
2343 struct sctp_chunk *chunk = arg;
2345 if (!sctp_vtag_verify(chunk, asoc))
2346 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2348 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2349 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2351 /* If this is a newer ECNE than the last CWR packet we sent out */
2352 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2353 SCTP_U32(ntohl(ecne->lowest_tsn)));
2355 return SCTP_DISPOSITION_CONSUME;
2359 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2361 * The SCTP endpoint MUST always acknowledge the reception of each valid
2364 * The guidelines on delayed acknowledgement algorithm specified in
2365 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2366 * acknowledgement SHOULD be generated for at least every second packet
2367 * (not every second DATA chunk) received, and SHOULD be generated within
2368 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2369 * situations it may be beneficial for an SCTP transmitter to be more
2370 * conservative than the algorithms detailed in this document allow.
2371 * However, an SCTP transmitter MUST NOT be more aggressive than the
2372 * following algorithms allow.
2374 * A SCTP receiver MUST NOT generate more than one SACK for every
2375 * incoming packet, other than to update the offered window as the
2376 * receiving application consumes new data.
2378 * Verification Tag: 8.5 Verification Tag [Normal verification]
2381 * (endpoint, asoc, chunk)
2384 * (asoc, reply_msg, msg_up, timers, counters)
2386 * The return value is the disposition of the chunk.
2388 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2389 const struct sctp_association *asoc,
2390 const sctp_subtype_t type,
2392 sctp_cmd_seq_t *commands)
2394 struct sctp_chunk *chunk = arg;
2397 if (!sctp_vtag_verify(chunk, asoc)) {
2398 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2400 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2403 error = sctp_eat_data(asoc, chunk, commands );
2405 case SCTP_IERROR_NO_ERROR:
2407 case SCTP_IERROR_HIGH_TSN:
2408 case SCTP_IERROR_BAD_STREAM:
2409 goto discard_noforce;
2410 case SCTP_IERROR_DUP_TSN:
2411 case SCTP_IERROR_IGNORE_TSN:
2413 case SCTP_IERROR_NO_DATA:
2419 if (asoc->autoclose) {
2420 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2421 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2424 /* If this is the last chunk in a packet, we need to count it
2425 * toward sack generation. Note that we need to SACK every
2426 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2427 * THEM. We elect to NOT generate SACK's if the chunk fails
2428 * the verification tag test.
2430 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2432 * The SCTP endpoint MUST always acknowledge the reception of
2433 * each valid DATA chunk.
2435 * The guidelines on delayed acknowledgement algorithm
2436 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2437 * Specifically, an acknowledgement SHOULD be generated for at
2438 * least every second packet (not every second DATA chunk)
2439 * received, and SHOULD be generated within 200 ms of the
2440 * arrival of any unacknowledged DATA chunk. In some
2441 * situations it may be beneficial for an SCTP transmitter to
2442 * be more conservative than the algorithms detailed in this
2443 * document allow. However, an SCTP transmitter MUST NOT be
2444 * more aggressive than the following algorithms allow.
2446 if (chunk->end_of_packet) {
2447 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2449 /* Start the SACK timer. */
2450 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2451 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2454 return SCTP_DISPOSITION_CONSUME;
2457 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2459 * When a packet arrives with duplicate DATA chunk(s) and with
2460 * no new DATA chunk(s), the endpoint MUST immediately send a
2461 * SACK with no delay. If a packet arrives with duplicate
2462 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2463 * MAY immediately send a SACK. Normally receipt of duplicate
2464 * DATA chunks will occur when the original SACK chunk was lost
2465 * and the peer's RTO has expired. The duplicate TSN number(s)
2466 * SHOULD be reported in the SACK as duplicate.
2468 /* In our case, we split the MAY SACK advice up whether or not
2469 * the last chunk is a duplicate.'
2471 if (chunk->end_of_packet)
2472 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2473 return SCTP_DISPOSITION_DISCARD;
2476 if (chunk->end_of_packet) {
2477 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2479 /* Start the SACK timer. */
2480 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2481 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2483 return SCTP_DISPOSITION_DISCARD;
2485 return SCTP_DISPOSITION_CONSUME;
2490 * sctp_sf_eat_data_fast_4_4
2493 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2494 * DATA chunks without delay.
2496 * Verification Tag: 8.5 Verification Tag [Normal verification]
2498 * (endpoint, asoc, chunk)
2501 * (asoc, reply_msg, msg_up, timers, counters)
2503 * The return value is the disposition of the chunk.
2505 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2506 const struct sctp_association *asoc,
2507 const sctp_subtype_t type,
2509 sctp_cmd_seq_t *commands)
2511 struct sctp_chunk *chunk = arg;
2514 if (!sctp_vtag_verify(chunk, asoc)) {
2515 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2517 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2520 error = sctp_eat_data(asoc, chunk, commands );
2522 case SCTP_IERROR_NO_ERROR:
2523 case SCTP_IERROR_HIGH_TSN:
2524 case SCTP_IERROR_DUP_TSN:
2525 case SCTP_IERROR_IGNORE_TSN:
2526 case SCTP_IERROR_BAD_STREAM:
2528 case SCTP_IERROR_NO_DATA:
2534 /* Go a head and force a SACK, since we are shutting down. */
2536 /* Implementor's Guide.
2538 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2539 * respond to each received packet containing one or more DATA chunk(s)
2540 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2542 if (chunk->end_of_packet) {
2543 /* We must delay the chunk creation since the cumulative
2544 * TSN has not been updated yet.
2546 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2547 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2548 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2549 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2553 return SCTP_DISPOSITION_CONSUME;
2557 * Section: 6.2 Processing a Received SACK
2558 * D) Any time a SACK arrives, the endpoint performs the following:
2560 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2561 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2562 * increasing, a SACK whose Cumulative TSN Ack is less than the
2563 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2565 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2566 * of bytes still outstanding after processing the Cumulative TSN Ack
2567 * and the Gap Ack Blocks.
2569 * iii) If the SACK is missing a TSN that was previously
2570 * acknowledged via a Gap Ack Block (e.g., the data receiver
2571 * reneged on the data), then mark the corresponding DATA chunk
2572 * as available for retransmit: Mark it as missing for fast
2573 * retransmit as described in Section 7.2.4 and if no retransmit
2574 * timer is running for the destination address to which the DATA
2575 * chunk was originally transmitted, then T3-rtx is started for
2576 * that destination address.
2578 * Verification Tag: 8.5 Verification Tag [Normal verification]
2581 * (endpoint, asoc, chunk)
2584 * (asoc, reply_msg, msg_up, timers, counters)
2586 * The return value is the disposition of the chunk.
2588 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2589 const struct sctp_association *asoc,
2590 const sctp_subtype_t type,
2592 sctp_cmd_seq_t *commands)
2594 struct sctp_chunk *chunk = arg;
2595 sctp_sackhdr_t *sackh;
2598 if (!sctp_vtag_verify(chunk, asoc))
2599 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2601 /* Pull the SACK chunk from the data buffer */
2602 sackh = sctp_sm_pull_sack(chunk);
2603 /* Was this a bogus SACK? */
2605 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2606 chunk->subh.sack_hdr = sackh;
2607 ctsn = ntohl(sackh->cum_tsn_ack);
2609 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2610 * Ack Point, then drop the SACK. Since Cumulative TSN
2611 * Ack is monotonically increasing, a SACK whose
2612 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2613 * Point indicates an out-of-order SACK.
2615 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2616 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2617 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2618 return SCTP_DISPOSITION_DISCARD;
2621 /* Return this SACK for further processing. */
2622 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2624 /* Note: We do the rest of the work on the PROCESS_SACK
2627 return SCTP_DISPOSITION_CONSUME;
2631 * Generate an ABORT in response to a packet.
2633 * Section: 8.4 Handle "Out of the blue" Packets
2635 * 8) The receiver should respond to the sender of the OOTB packet
2636 * with an ABORT. When sending the ABORT, the receiver of the
2637 * OOTB packet MUST fill in the Verification Tag field of the
2638 * outbound packet with the value found in the Verification Tag
2639 * field of the OOTB packet and set the T-bit in the Chunk Flags
2640 * to indicate that no TCB was found. After sending this ABORT,
2641 * the receiver of the OOTB packet shall discard the OOTB packet
2642 * and take no further action.
2646 * The return value is the disposition of the chunk.
2648 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2649 const struct sctp_association *asoc,
2650 const sctp_subtype_t type,
2652 sctp_cmd_seq_t *commands)
2654 struct sctp_packet *packet = NULL;
2655 struct sctp_chunk *chunk = arg;
2656 struct sctp_chunk *abort;
2658 packet = sctp_ootb_pkt_new(asoc, chunk);
2661 /* Make an ABORT. The T bit will be set if the asoc
2664 abort = sctp_make_abort(asoc, chunk, 0);
2666 sctp_ootb_pkt_free(packet);
2667 return SCTP_DISPOSITION_NOMEM;
2670 /* Set the skb to the belonging sock for accounting. */
2671 abort->skb->sk = ep->base.sk;
2673 sctp_packet_append_chunk(packet, abort);
2675 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2676 SCTP_PACKET(packet));
2678 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
2680 return SCTP_DISPOSITION_CONSUME;
2683 return SCTP_DISPOSITION_NOMEM;
2687 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2688 * event as ULP notification for each cause included in the chunk.
2690 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2692 * The return value is the disposition of the chunk.
2694 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2695 const struct sctp_association *asoc,
2696 const sctp_subtype_t type,
2698 sctp_cmd_seq_t *commands)
2700 struct sctp_chunk *chunk = arg;
2701 struct sctp_ulpevent *ev;
2703 while (chunk->chunk_end > chunk->skb->data) {
2704 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
2709 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
2710 SCTP_ULPEVENT(ev))) {
2711 sctp_ulpevent_free(ev);
2715 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
2718 return SCTP_DISPOSITION_CONSUME;
2721 return SCTP_DISPOSITION_NOMEM;
2725 * Process an inbound SHUTDOWN ACK.
2728 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2729 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2730 * peer, and remove all record of the association.
2732 * The return value is the disposition.
2734 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
2735 const struct sctp_association *asoc,
2736 const sctp_subtype_t type,
2738 sctp_cmd_seq_t *commands)
2740 struct sctp_chunk *chunk = arg;
2741 struct sctp_chunk *reply;
2742 struct sctp_ulpevent *ev;
2744 if (!sctp_vtag_verify(chunk, asoc))
2745 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2747 /* 10.2 H) SHUTDOWN COMPLETE notification
2749 * When SCTP completes the shutdown procedures (section 9.2) this
2750 * notification is passed to the upper layer.
2752 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
2753 0, 0, 0, GFP_ATOMIC);
2757 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2759 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2760 * stop the T2-shutdown timer,
2762 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2763 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2765 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2766 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2768 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
2769 reply = sctp_make_shutdown_complete(asoc, chunk);
2773 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2774 SCTP_STATE(SCTP_STATE_CLOSED));
2775 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
2776 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2777 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2779 /* ...and remove all record of the association. */
2780 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2781 return SCTP_DISPOSITION_DELETE_TCB;
2784 return SCTP_DISPOSITION_NOMEM;
2788 * RFC 2960, 8.4 - Handle "Out of the blue" Packets
2789 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2790 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2791 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
2792 * packet must fill in the Verification Tag field of the outbound
2793 * packet with the Verification Tag received in the SHUTDOWN ACK and
2794 * set the T-bit in the Chunk Flags to indicate that no TCB was
2797 * 8) The receiver should respond to the sender of the OOTB packet with
2798 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2799 * MUST fill in the Verification Tag field of the outbound packet
2800 * with the value found in the Verification Tag field of the OOTB
2801 * packet and set the T-bit in the Chunk Flags to indicate that no
2802 * TCB was found. After sending this ABORT, the receiver of the OOTB
2803 * packet shall discard the OOTB packet and take no further action.
2805 sctp_disposition_t sctp_sf_ootb(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_chunk *chunk = arg;
2812 struct sk_buff *skb = chunk->skb;
2813 sctp_chunkhdr_t *ch;
2815 int ootb_shut_ack = 0;
2817 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES);
2819 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
2821 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
2823 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
2826 ch = (sctp_chunkhdr_t *) ch_end;
2827 } while (ch_end < skb->tail);
2830 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
2832 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
2834 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2838 * Handle an "Out of the blue" SHUTDOWN ACK.
2841 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2842 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2843 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB packet
2844 * must fill in the Verification Tag field of the outbound packet with
2845 * the Verification Tag received in the SHUTDOWN ACK and set the
2846 * T-bit in the Chunk Flags to indicate that no TCB was found.
2849 * (endpoint, asoc, type, arg, commands)
2852 * (sctp_disposition_t)
2854 * The return value is the disposition of the chunk.
2856 sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
2857 const struct sctp_association *asoc,
2858 const sctp_subtype_t type,
2860 sctp_cmd_seq_t *commands)
2862 struct sctp_packet *packet = NULL;
2863 struct sctp_chunk *chunk = arg;
2864 struct sctp_chunk *shut;
2866 packet = sctp_ootb_pkt_new(asoc, chunk);
2869 /* Make an SHUTDOWN_COMPLETE.
2870 * The T bit will be set if the asoc is NULL.
2872 shut = sctp_make_shutdown_complete(asoc, chunk);
2874 sctp_ootb_pkt_free(packet);
2875 return SCTP_DISPOSITION_NOMEM;
2878 /* Set the skb to the belonging sock for accounting. */
2879 shut->skb->sk = ep->base.sk;
2881 sctp_packet_append_chunk(packet, shut);
2883 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2884 SCTP_PACKET(packet));
2886 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
2888 return SCTP_DISPOSITION_CONSUME;
2891 return SCTP_DISPOSITION_NOMEM;
2895 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
2897 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
2898 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
2899 * procedures in section 8.4 SHOULD be followed, in other words it
2900 * should be treated as an Out Of The Blue packet.
2901 * [This means that we do NOT check the Verification Tag on these
2905 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
2906 const struct sctp_association *asoc,
2907 const sctp_subtype_t type,
2909 sctp_cmd_seq_t *commands)
2911 /* Although we do have an association in this case, it corresponds
2912 * to a restarted association. So the packet is treated as an OOTB
2913 * packet and the state function that handles OOTB SHUTDOWN_ACK is
2914 * called with a NULL association.
2916 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
2919 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
2920 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
2921 const struct sctp_association *asoc,
2922 const sctp_subtype_t type, void *arg,
2923 sctp_cmd_seq_t *commands)
2925 struct sctp_chunk *chunk = arg;
2926 struct sctp_chunk *asconf_ack = NULL;
2927 sctp_addiphdr_t *hdr;
2930 hdr = (sctp_addiphdr_t *)chunk->skb->data;
2931 serial = ntohl(hdr->serial);
2933 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
2934 * the endpoint stored in a new association variable
2935 * 'Peer-Serial-Number'.
2937 if (serial == asoc->peer.addip_serial + 1) {
2938 /* ADDIP 4.2 C2) If the value found in the serial number is
2939 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
2942 asconf_ack = sctp_process_asconf((struct sctp_association *)
2945 return SCTP_DISPOSITION_NOMEM;
2946 } else if (serial == asoc->peer.addip_serial) {
2947 /* ADDIP 4.2 C3) If the value found in the serial number is
2948 * equal to the value stored in the 'Peer-Serial-Number'
2949 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
2950 * to save the last ASCONF-ACK for some predetermined period of * time and instead of re-processing the ASCONF (with the same
2951 * serial number) it may just re-transmit the ASCONF-ACK.
2953 if (asoc->addip_last_asconf_ack)
2954 asconf_ack = asoc->addip_last_asconf_ack;
2956 return SCTP_DISPOSITION_DISCARD;
2958 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
2959 * it must be either a stale packet or from an attacker.
2961 return SCTP_DISPOSITION_DISCARD;
2964 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
2965 * back to the source address contained in the IP header of the ASCONF
2966 * being responded to.
2968 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
2970 return SCTP_DISPOSITION_CONSUME;
2974 * ADDIP Section 4.3 General rules for address manipulation
2975 * When building TLV parameters for the ASCONF Chunk that will add or
2976 * delete IP addresses the D0 to D13 rules should be applied:
2978 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
2979 const struct sctp_association *asoc,
2980 const sctp_subtype_t type, void *arg,
2981 sctp_cmd_seq_t *commands)
2983 struct sctp_chunk *asconf_ack = arg;
2984 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
2985 struct sctp_chunk *abort;
2986 sctp_addiphdr_t *addip_hdr;
2987 __u32 sent_serial, rcvd_serial;
2989 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
2990 rcvd_serial = ntohl(addip_hdr->serial);
2993 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
2994 sent_serial = ntohl(addip_hdr->serial);
2996 sent_serial = asoc->addip_serial - 1;
2999 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3000 * equal to the next serial number to be used but no ASCONF chunk is
3001 * outstanding the endpoint MUST ABORT the association. Note that a
3002 * sequence number is greater than if it is no more than 2^^31-1
3003 * larger than the current sequence number (using serial arithmetic).
3005 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3006 !(asoc->addip_last_asconf)) {
3007 abort = sctp_make_abort(asoc, asconf_ack,
3008 sizeof(sctp_errhdr_t));
3010 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
3011 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3014 /* We are going to ABORT, so we might as well stop
3015 * processing the rest of the chunks in the packet.
3017 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3018 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3019 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3020 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3021 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3022 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3023 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3024 return SCTP_DISPOSITION_ABORT;
3027 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3028 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3029 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3031 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3033 return SCTP_DISPOSITION_CONSUME;
3035 abort = sctp_make_abort(asoc, asconf_ack,
3036 sizeof(sctp_errhdr_t));
3038 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
3039 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3042 /* We are going to ABORT, so we might as well stop
3043 * processing the rest of the chunks in the packet.
3045 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3046 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3047 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3048 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3049 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3050 return SCTP_DISPOSITION_ABORT;
3053 return SCTP_DISPOSITION_DISCARD;
3057 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3059 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3060 * its cumulative TSN point to the value carried in the FORWARD TSN
3061 * chunk, and then MUST further advance its cumulative TSN point locally
3063 * After the above processing, the data receiver MUST stop reporting any
3064 * missing TSNs earlier than or equal to the new cumulative TSN point.
3066 * Verification Tag: 8.5 Verification Tag [Normal verification]
3068 * The return value is the disposition of the chunk.
3070 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3071 const struct sctp_association *asoc,
3072 const sctp_subtype_t type,
3074 sctp_cmd_seq_t *commands)
3076 struct sctp_chunk *chunk = arg;
3077 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3081 if (!sctp_vtag_verify(chunk, asoc)) {
3082 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3084 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3087 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3088 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3089 len = ntohs(chunk->chunk_hdr->length);
3090 len -= sizeof(struct sctp_chunkhdr);
3091 skb_pull(chunk->skb, len);
3093 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3094 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3096 /* The TSN is too high--silently discard the chunk and count on it
3097 * getting retransmitted later.
3099 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3100 goto discard_noforce;
3102 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3103 if (len > sizeof(struct sctp_fwdtsn_hdr))
3104 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3107 /* Count this as receiving DATA. */
3108 if (asoc->autoclose) {
3109 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3110 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3113 /* FIXME: For now send a SACK, but DATA processing may
3116 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3117 /* Start the SACK timer. */
3118 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3119 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
3121 return SCTP_DISPOSITION_CONSUME;
3124 return SCTP_DISPOSITION_DISCARD;
3127 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3128 const struct sctp_endpoint *ep,
3129 const struct sctp_association *asoc,
3130 const sctp_subtype_t type,
3132 sctp_cmd_seq_t *commands)
3134 struct sctp_chunk *chunk = arg;
3135 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3139 if (!sctp_vtag_verify(chunk, asoc)) {
3140 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3142 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3145 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3146 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3147 len = ntohs(chunk->chunk_hdr->length);
3148 len -= sizeof(struct sctp_chunkhdr);
3149 skb_pull(chunk->skb, len);
3151 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3152 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3154 /* The TSN is too high--silently discard the chunk and count on it
3155 * getting retransmitted later.
3157 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3160 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3161 if (len > sizeof(struct sctp_fwdtsn_hdr))
3162 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3165 /* Go a head and force a SACK, since we are shutting down. */
3167 /* Implementor's Guide.
3169 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3170 * respond to each received packet containing one or more DATA chunk(s)
3171 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3173 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3174 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3175 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3176 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3178 return SCTP_DISPOSITION_CONSUME;
3182 * Process an unknown chunk.
3184 * Section: 3.2. Also, 2.1 in the implementor's guide.
3186 * Chunk Types are encoded such that the highest-order two bits specify
3187 * the action that must be taken if the processing endpoint does not
3188 * recognize the Chunk Type.
3190 * 00 - Stop processing this SCTP packet and discard it, do not process
3191 * any further chunks within it.
3193 * 01 - Stop processing this SCTP packet and discard it, do not process
3194 * any further chunks within it, and report the unrecognized
3195 * chunk in an 'Unrecognized Chunk Type'.
3197 * 10 - Skip this chunk and continue processing.
3199 * 11 - Skip this chunk and continue processing, but report in an ERROR
3200 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3202 * The return value is the disposition of the chunk.
3204 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3205 const struct sctp_association *asoc,
3206 const sctp_subtype_t type,
3208 sctp_cmd_seq_t *commands)
3210 struct sctp_chunk *unk_chunk = arg;
3211 struct sctp_chunk *err_chunk;
3212 sctp_chunkhdr_t *hdr;
3214 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3216 if (!sctp_vtag_verify(unk_chunk, asoc))
3217 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3219 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3220 case SCTP_CID_ACTION_DISCARD:
3221 /* Discard the packet. */
3222 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3224 case SCTP_CID_ACTION_DISCARD_ERR:
3225 /* Discard the packet. */
3226 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3228 /* Generate an ERROR chunk as response. */
3229 hdr = unk_chunk->chunk_hdr;
3230 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3231 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3232 WORD_ROUND(ntohs(hdr->length)));
3234 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3235 SCTP_CHUNK(err_chunk));
3237 return SCTP_DISPOSITION_CONSUME;
3239 case SCTP_CID_ACTION_SKIP:
3240 /* Skip the chunk. */
3241 return SCTP_DISPOSITION_DISCARD;
3243 case SCTP_CID_ACTION_SKIP_ERR:
3244 /* Generate an ERROR chunk as response. */
3245 hdr = unk_chunk->chunk_hdr;
3246 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3247 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3248 WORD_ROUND(ntohs(hdr->length)));
3250 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3251 SCTP_CHUNK(err_chunk));
3253 /* Skip the chunk. */
3254 return SCTP_DISPOSITION_CONSUME;
3260 return SCTP_DISPOSITION_DISCARD;
3264 * Discard the chunk.
3266 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3267 * [Too numerous to mention...]
3268 * Verification Tag: No verification needed.
3270 * (endpoint, asoc, chunk)
3273 * (asoc, reply_msg, msg_up, timers, counters)
3275 * The return value is the disposition of the chunk.
3277 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3278 const struct sctp_association *asoc,
3279 const sctp_subtype_t type,
3281 sctp_cmd_seq_t *commands)
3283 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3284 return SCTP_DISPOSITION_DISCARD;
3288 * Discard the whole packet.
3292 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3293 * silently discard the OOTB packet and take no further action.
3296 * Verification Tag: No verification necessary
3299 * (endpoint, asoc, chunk)
3302 * (asoc, reply_msg, msg_up, timers, counters)
3304 * The return value is the disposition of the chunk.
3306 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3307 const struct sctp_association *asoc,
3308 const sctp_subtype_t type,
3310 sctp_cmd_seq_t *commands)
3312 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3314 return SCTP_DISPOSITION_CONSUME;
3319 * The other end is violating protocol.
3321 * Section: Not specified
3322 * Verification Tag: Not specified
3324 * (endpoint, asoc, chunk)
3327 * (asoc, reply_msg, msg_up, timers, counters)
3329 * We simply tag the chunk as a violation. The state machine will log
3330 * the violation and continue.
3332 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3333 const struct sctp_association *asoc,
3334 const sctp_subtype_t type,
3336 sctp_cmd_seq_t *commands)
3338 return SCTP_DISPOSITION_VIOLATION;
3341 /***************************************************************************
3342 * These are the state functions for handling primitive (Section 10) events.
3343 ***************************************************************************/
3345 * sctp_sf_do_prm_asoc
3347 * Section: 10.1 ULP-to-SCTP
3350 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3351 * outbound stream count)
3352 * -> association id [,destination transport addr list] [,outbound stream
3355 * This primitive allows the upper layer to initiate an association to a
3356 * specific peer endpoint.
3358 * The peer endpoint shall be specified by one of the transport addresses
3359 * which defines the endpoint (see Section 1.4). If the local SCTP
3360 * instance has not been initialized, the ASSOCIATE is considered an
3362 * [This is not relevant for the kernel implementation since we do all
3363 * initialization at boot time. It we hadn't initialized we wouldn't
3364 * get anywhere near this code.]
3366 * An association id, which is a local handle to the SCTP association,
3367 * will be returned on successful establishment of the association. If
3368 * SCTP is not able to open an SCTP association with the peer endpoint,
3369 * an error is returned.
3370 * [In the kernel implementation, the struct sctp_association needs to
3371 * be created BEFORE causing this primitive to run.]
3373 * Other association parameters may be returned, including the
3374 * complete destination transport addresses of the peer as well as the
3375 * outbound stream count of the local endpoint. One of the transport
3376 * address from the returned destination addresses will be selected by
3377 * the local endpoint as default primary path for sending SCTP packets
3378 * to this peer. The returned "destination transport addr list" can
3379 * be used by the ULP to change the default primary path or to force
3380 * sending a packet to a specific transport address. [All of this
3381 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3384 * Mandatory attributes:
3386 * o local SCTP instance name - obtained from the INITIALIZE operation.
3387 * [This is the argument asoc.]
3388 * o destination transport addr - specified as one of the transport
3389 * addresses of the peer endpoint with which the association is to be
3391 * [This is asoc->peer.active_path.]
3392 * o outbound stream count - the number of outbound streams the ULP
3393 * would like to open towards this peer endpoint.
3394 * [BUG: This is not currently implemented.]
3395 * Optional attributes:
3399 * The return value is a disposition.
3401 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
3402 const struct sctp_association *asoc,
3403 const sctp_subtype_t type,
3405 sctp_cmd_seq_t *commands)
3407 struct sctp_chunk *repl;
3409 /* The comment below says that we enter COOKIE-WAIT AFTER
3410 * sending the INIT, but that doesn't actually work in our
3413 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3414 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3416 /* RFC 2960 5.1 Normal Establishment of an Association
3418 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3419 * must provide its Verification Tag (Tag_A) in the Initiate
3420 * Tag field. Tag_A SHOULD be a random number in the range of
3421 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3424 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
3428 /* Cast away the const modifier, as we want to just
3429 * rerun it through as a sideffect.
3431 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3432 SCTP_ASOC((struct sctp_association *) asoc));
3434 /* After sending the INIT, "A" starts the T1-init timer and
3435 * enters the COOKIE-WAIT state.
3437 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3438 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3439 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3440 return SCTP_DISPOSITION_CONSUME;
3443 return SCTP_DISPOSITION_NOMEM;
3447 * Process the SEND primitive.
3449 * Section: 10.1 ULP-to-SCTP
3452 * Format: SEND(association id, buffer address, byte count [,context]
3453 * [,stream id] [,life time] [,destination transport address]
3454 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3457 * This is the main method to send user data via SCTP.
3459 * Mandatory attributes:
3461 * o association id - local handle to the SCTP association
3463 * o buffer address - the location where the user message to be
3464 * transmitted is stored;
3466 * o byte count - The size of the user data in number of bytes;
3468 * Optional attributes:
3470 * o context - an optional 32 bit integer that will be carried in the
3471 * sending failure notification to the ULP if the transportation of
3472 * this User Message fails.
3474 * o stream id - to indicate which stream to send the data on. If not
3475 * specified, stream 0 will be used.
3477 * o life time - specifies the life time of the user data. The user data
3478 * will not be sent by SCTP after the life time expires. This
3479 * parameter can be used to avoid efforts to transmit stale
3480 * user messages. SCTP notifies the ULP if the data cannot be
3481 * initiated to transport (i.e. sent to the destination via SCTP's
3482 * send primitive) within the life time variable. However, the
3483 * user data will be transmitted if SCTP has attempted to transmit a
3484 * chunk before the life time expired.
3486 * o destination transport address - specified as one of the destination
3487 * transport addresses of the peer endpoint to which this packet
3488 * should be sent. Whenever possible, SCTP should use this destination
3489 * transport address for sending the packets, instead of the current
3492 * o unorder flag - this flag, if present, indicates that the user
3493 * would like the data delivered in an unordered fashion to the peer
3494 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3497 * o no-bundle flag - instructs SCTP not to bundle this user data with
3498 * other outbound DATA chunks. SCTP MAY still bundle even when
3499 * this flag is present, when faced with network congestion.
3501 * o payload protocol-id - A 32 bit unsigned integer that is to be
3502 * passed to the peer indicating the type of payload protocol data
3503 * being transmitted. This value is passed as opaque data by SCTP.
3505 * The return value is the disposition.
3507 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
3508 const struct sctp_association *asoc,
3509 const sctp_subtype_t type,
3511 sctp_cmd_seq_t *commands)
3513 struct sctp_chunk *chunk = arg;
3515 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3516 return SCTP_DISPOSITION_CONSUME;
3520 * Process the SHUTDOWN primitive.
3525 * Format: SHUTDOWN(association id)
3528 * Gracefully closes an association. Any locally queued user data
3529 * will be delivered to the peer. The association will be terminated only
3530 * after the peer acknowledges all the SCTP packets sent. A success code
3531 * will be returned on successful termination of the association. If
3532 * attempting to terminate the association results in a failure, an error
3533 * code shall be returned.
3535 * Mandatory attributes:
3537 * o association id - local handle to the SCTP association
3539 * Optional attributes:
3543 * The return value is the disposition.
3545 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
3546 const struct sctp_endpoint *ep,
3547 const struct sctp_association *asoc,
3548 const sctp_subtype_t type,
3550 sctp_cmd_seq_t *commands)
3554 /* From 9.2 Shutdown of an Association
3555 * Upon receipt of the SHUTDOWN primitive from its upper
3556 * layer, the endpoint enters SHUTDOWN-PENDING state and
3557 * remains there until all outstanding data has been
3558 * acknowledged by its peer. The endpoint accepts no new data
3559 * from its upper layer, but retransmits data to the far end
3560 * if necessary to fill gaps.
3562 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3563 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
3565 /* sctpimpguide-05 Section 2.12.2
3566 * The sender of the SHUTDOWN MAY also start an overall guard timer
3567 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3569 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3570 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3572 disposition = SCTP_DISPOSITION_CONSUME;
3573 if (sctp_outq_is_empty(&asoc->outqueue)) {
3574 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
3581 * Process the ABORT primitive.
3586 * Format: Abort(association id [, cause code])
3589 * Ungracefully closes an association. Any locally queued user data
3590 * will be discarded and an ABORT chunk is sent to the peer. A success code
3591 * will be returned on successful abortion of the association. If
3592 * attempting to abort the association results in a failure, an error
3593 * code shall be returned.
3595 * Mandatory attributes:
3597 * o association id - local handle to the SCTP association
3599 * Optional attributes:
3601 * o cause code - reason of the abort to be passed to the peer
3605 * The return value is the disposition.
3607 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
3608 const struct sctp_endpoint *ep,
3609 const struct sctp_association *asoc,
3610 const sctp_subtype_t type,
3612 sctp_cmd_seq_t *commands)
3614 /* From 9.1 Abort of an Association
3615 * Upon receipt of the ABORT primitive from its upper
3616 * layer, the endpoint enters CLOSED state and
3617 * discard all outstanding data has been
3618 * acknowledged by its peer. The endpoint accepts no new data
3619 * from its upper layer, but retransmits data to the far end
3620 * if necessary to fill gaps.
3622 struct msghdr *msg = arg;
3623 struct sctp_chunk *abort;
3624 sctp_disposition_t retval;
3626 retval = SCTP_DISPOSITION_CONSUME;
3628 /* Generate ABORT chunk to send the peer. */
3629 abort = sctp_make_abort_user(asoc, NULL, msg);
3631 retval = SCTP_DISPOSITION_NOMEM;
3633 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3635 /* Even if we can't send the ABORT due to low memory delete the
3636 * TCB. This is a departure from our typical NOMEM handling.
3639 /* Delete the established association. */
3640 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3641 SCTP_U32(SCTP_ERROR_USER_ABORT));
3643 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3644 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3649 /* We tried an illegal operation on an association which is closed. */
3650 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
3651 const struct sctp_association *asoc,
3652 const sctp_subtype_t type,
3654 sctp_cmd_seq_t *commands)
3656 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
3657 return SCTP_DISPOSITION_CONSUME;
3660 /* We tried an illegal operation on an association which is shutting
3663 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
3664 const struct sctp_association *asoc,
3665 const sctp_subtype_t type,
3667 sctp_cmd_seq_t *commands)
3669 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
3670 SCTP_ERROR(-ESHUTDOWN));
3671 return SCTP_DISPOSITION_CONSUME;
3675 * sctp_cookie_wait_prm_shutdown
3677 * Section: 4 Note: 2
3682 * The RFC does not explicitly address this issue, but is the route through the
3683 * state table when someone issues a shutdown while in COOKIE_WAIT state.
3688 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
3689 const struct sctp_endpoint *ep,
3690 const struct sctp_association *asoc,
3691 const sctp_subtype_t type,
3693 sctp_cmd_seq_t *commands)
3695 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3696 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3698 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3699 SCTP_STATE(SCTP_STATE_CLOSED));
3701 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3703 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3705 return SCTP_DISPOSITION_DELETE_TCB;
3709 * sctp_cookie_echoed_prm_shutdown
3711 * Section: 4 Note: 2
3716 * The RFC does not explcitly address this issue, but is the route through the
3717 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
3722 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
3723 const struct sctp_endpoint *ep,
3724 const struct sctp_association *asoc,
3725 const sctp_subtype_t type,
3726 void *arg, sctp_cmd_seq_t *commands)
3728 /* There is a single T1 timer, so we should be able to use
3729 * common function with the COOKIE-WAIT state.
3731 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
3735 * sctp_sf_cookie_wait_prm_abort
3737 * Section: 4 Note: 2
3742 * The RFC does not explicitly address this issue, but is the route through the
3743 * state table when someone issues an abort while in COOKIE_WAIT state.
3748 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
3749 const struct sctp_endpoint *ep,
3750 const struct sctp_association *asoc,
3751 const sctp_subtype_t type,
3753 sctp_cmd_seq_t *commands)
3755 struct msghdr *msg = arg;
3756 struct sctp_chunk *abort;
3757 sctp_disposition_t retval;
3759 /* Stop T1-init timer */
3760 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3761 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3762 retval = SCTP_DISPOSITION_CONSUME;
3764 /* Generate ABORT chunk to send the peer */
3765 abort = sctp_make_abort_user(asoc, NULL, msg);
3767 retval = SCTP_DISPOSITION_NOMEM;
3769 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3771 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3772 SCTP_STATE(SCTP_STATE_CLOSED));
3774 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
3776 /* Even if we can't send the ABORT due to low memory delete the
3777 * TCB. This is a departure from our typical NOMEM handling.
3780 /* Delete the established association. */
3781 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3782 SCTP_U32(SCTP_ERROR_USER_ABORT));
3788 * sctp_sf_cookie_echoed_prm_abort
3790 * Section: 4 Note: 3
3795 * The RFC does not explcitly address this issue, but is the route through the
3796 * state table when someone issues an abort while in COOKIE_ECHOED state.
3801 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
3802 const struct sctp_endpoint *ep,
3803 const struct sctp_association *asoc,
3804 const sctp_subtype_t type,
3806 sctp_cmd_seq_t *commands)
3808 /* There is a single T1 timer, so we should be able to use
3809 * common function with the COOKIE-WAIT state.
3811 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
3815 * sctp_sf_shutdown_pending_prm_abort
3820 * The RFC does not explicitly address this issue, but is the route through the
3821 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
3826 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
3827 const struct sctp_endpoint *ep,
3828 const struct sctp_association *asoc,
3829 const sctp_subtype_t type,
3831 sctp_cmd_seq_t *commands)
3833 /* Stop the T5-shutdown guard timer. */
3834 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3835 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3837 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
3841 * sctp_sf_shutdown_sent_prm_abort
3846 * The RFC does not explicitly address this issue, but is the route through the
3847 * state table when someone issues an abort while in SHUTDOWN-SENT state.
3852 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
3853 const struct sctp_endpoint *ep,
3854 const struct sctp_association *asoc,
3855 const sctp_subtype_t type,
3857 sctp_cmd_seq_t *commands)
3859 /* Stop the T2-shutdown timer. */
3860 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3861 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3863 /* Stop the T5-shutdown guard timer. */
3864 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3865 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3867 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
3871 * sctp_sf_cookie_echoed_prm_abort
3876 * The RFC does not explcitly address this issue, but is the route through the
3877 * state table when someone issues an abort while in COOKIE_ECHOED state.
3882 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
3883 const struct sctp_endpoint *ep,
3884 const struct sctp_association *asoc,
3885 const sctp_subtype_t type,
3887 sctp_cmd_seq_t *commands)
3889 /* The same T2 timer, so we should be able to use
3890 * common function with the SHUTDOWN-SENT state.
3892 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
3896 * Process the REQUESTHEARTBEAT primitive
3899 * J) Request Heartbeat
3901 * Format: REQUESTHEARTBEAT(association id, destination transport address)
3905 * Instructs the local endpoint to perform a HeartBeat on the specified
3906 * destination transport address of the given association. The returned
3907 * result should indicate whether the transmission of the HEARTBEAT
3908 * chunk to the destination address is successful.
3910 * Mandatory attributes:
3912 * o association id - local handle to the SCTP association
3914 * o destination transport address - the transport address of the
3915 * association on which a heartbeat should be issued.
3917 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
3918 const struct sctp_endpoint *ep,
3919 const struct sctp_association *asoc,
3920 const sctp_subtype_t type,
3922 sctp_cmd_seq_t *commands)
3924 return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
3929 * ADDIP Section 4.1 ASCONF Chunk Procedures
3930 * When an endpoint has an ASCONF signaled change to be sent to the
3931 * remote endpoint it should do A1 to A9
3933 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
3934 const struct sctp_association *asoc,
3935 const sctp_subtype_t type,
3937 sctp_cmd_seq_t *commands)
3939 struct sctp_chunk *chunk = arg;
3941 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
3942 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3943 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3944 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3945 return SCTP_DISPOSITION_CONSUME;
3949 * Ignore the primitive event
3951 * The return value is the disposition of the primitive.
3953 sctp_disposition_t sctp_sf_ignore_primitive(
3954 const struct sctp_endpoint *ep,
3955 const struct sctp_association *asoc,
3956 const sctp_subtype_t type,
3958 sctp_cmd_seq_t *commands)
3960 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
3961 return SCTP_DISPOSITION_DISCARD;
3964 /***************************************************************************
3965 * These are the state functions for the OTHER events.
3966 ***************************************************************************/
3969 * Start the shutdown negotiation.
3972 * Once all its outstanding data has been acknowledged, the endpoint
3973 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
3974 * TSN Ack field the last sequential TSN it has received from the peer.
3975 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
3976 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
3977 * with the updated last sequential TSN received from its peer.
3979 * The return value is the disposition.
3981 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
3982 const struct sctp_endpoint *ep,
3983 const struct sctp_association *asoc,
3984 const sctp_subtype_t type,
3986 sctp_cmd_seq_t *commands)
3988 struct sctp_chunk *reply;
3990 /* Once all its outstanding data has been acknowledged, the
3991 * endpoint shall send a SHUTDOWN chunk to its peer including
3992 * in the Cumulative TSN Ack field the last sequential TSN it
3993 * has received from the peer.
3995 reply = sctp_make_shutdown(asoc, NULL);
3999 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4000 * T2-shutdown timer.
4002 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4004 /* It shall then start the T2-shutdown timer */
4005 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4006 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4008 if (asoc->autoclose)
4009 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4010 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4012 /* and enter the SHUTDOWN-SENT state. */
4013 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4014 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4016 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4018 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4021 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4023 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4025 return SCTP_DISPOSITION_CONSUME;
4028 return SCTP_DISPOSITION_NOMEM;
4032 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4036 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4037 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4038 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4039 * endpoint must re-send the SHUTDOWN ACK.
4041 * The return value is the disposition.
4043 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4044 const struct sctp_endpoint *ep,
4045 const struct sctp_association *asoc,
4046 const sctp_subtype_t type,
4048 sctp_cmd_seq_t *commands)
4050 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4051 struct sctp_chunk *reply;
4053 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4054 * shall send a SHUTDOWN ACK ...
4056 reply = sctp_make_shutdown_ack(asoc, chunk);
4060 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4061 * the T2-shutdown timer.
4063 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4065 /* and start/restart a T2-shutdown timer of its own, */
4066 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4067 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4069 if (asoc->autoclose)
4070 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4071 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4073 /* Enter the SHUTDOWN-ACK-SENT state. */
4074 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4075 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4077 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4079 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4082 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4084 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4086 return SCTP_DISPOSITION_CONSUME;
4089 return SCTP_DISPOSITION_NOMEM;
4093 * Ignore the event defined as other
4095 * The return value is the disposition of the event.
4097 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4098 const struct sctp_association *asoc,
4099 const sctp_subtype_t type,
4101 sctp_cmd_seq_t *commands)
4103 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4104 return SCTP_DISPOSITION_DISCARD;
4107 /************************************************************
4108 * These are the state functions for handling timeout events.
4109 ************************************************************/
4114 * Section: 6.3.3 Handle T3-rtx Expiration
4116 * Whenever the retransmission timer T3-rtx expires for a destination
4117 * address, do the following:
4120 * The return value is the disposition of the chunk.
4122 sctp_disposition_t sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint *ep,
4123 const struct sctp_association *asoc,
4124 const sctp_subtype_t type,
4126 sctp_cmd_seq_t *commands)
4128 struct sctp_transport *transport = arg;
4130 if (asoc->overall_error_count >= asoc->max_retrans) {
4131 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4132 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4133 SCTP_U32(SCTP_ERROR_NO_ERROR));
4134 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4135 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4136 return SCTP_DISPOSITION_DELETE_TCB;
4139 /* E1) For the destination address for which the timer
4140 * expires, adjust its ssthresh with rules defined in Section
4141 * 7.2.3 and set the cwnd <- MTU.
4144 /* E2) For the destination address for which the timer
4145 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4146 * maximum value discussed in rule C7 above (RTO.max) may be
4147 * used to provide an upper bound to this doubling operation.
4150 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4151 * outstanding DATA chunks for the address for which the
4152 * T3-rtx has expired will fit into a single packet, subject
4153 * to the MTU constraint for the path corresponding to the
4154 * destination transport address to which the retransmission
4155 * is being sent (this may be different from the address for
4156 * which the timer expires [see Section 6.4]). Call this
4157 * value K. Bundle and retransmit those K DATA chunks in a
4158 * single packet to the destination endpoint.
4160 * Note: Any DATA chunks that were sent to the address for
4161 * which the T3-rtx timer expired but did not fit in one MTU
4162 * (rule E3 above), should be marked for retransmission and
4163 * sent as soon as cwnd allows (normally when a SACK arrives).
4166 /* NB: Rules E4 and F1 are implicit in R1. */
4167 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4169 /* Do some failure management (Section 8.2). */
4170 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4172 return SCTP_DISPOSITION_CONSUME;
4176 * Generate delayed SACK on timeout
4178 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4180 * The guidelines on delayed acknowledgement algorithm specified in
4181 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4182 * acknowledgement SHOULD be generated for at least every second packet
4183 * (not every second DATA chunk) received, and SHOULD be generated
4184 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4185 * some situations it may be beneficial for an SCTP transmitter to be
4186 * more conservative than the algorithms detailed in this document
4187 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4188 * the following algorithms allow.
4190 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4191 const struct sctp_association *asoc,
4192 const sctp_subtype_t type,
4194 sctp_cmd_seq_t *commands)
4196 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4197 return SCTP_DISPOSITION_CONSUME;
4201 * sctp_sf_t1_timer_expire
4203 * Section: 4 Note: 2
4208 * RFC 2960 Section 4 Notes
4209 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4210 * and re-start the T1-init timer without changing state. This MUST
4211 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4212 * endpoint MUST abort the initialization process and report the
4213 * error to SCTP user.
4215 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4216 * COOKIE ECHO and re-start the T1-cookie timer without changing
4217 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4218 * After that, the endpoint MUST abort the initialization process and
4219 * report the error to SCTP user.
4225 sctp_disposition_t sctp_sf_t1_timer_expire(const struct sctp_endpoint *ep,
4226 const struct sctp_association *asoc,
4227 const sctp_subtype_t type,
4229 sctp_cmd_seq_t *commands)
4231 struct sctp_chunk *repl;
4232 struct sctp_bind_addr *bp;
4233 sctp_event_timeout_t timer = (sctp_event_timeout_t) arg;
4237 timeout = asoc->timeouts[timer];
4238 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
4241 SCTP_DEBUG_PRINTK("Timer T1 expired.\n");
4243 if (attempts < asoc->max_init_attempts) {
4245 case SCTP_EVENT_TIMEOUT_T1_INIT:
4246 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4247 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4250 case SCTP_EVENT_TIMEOUT_T1_COOKIE:
4251 repl = sctp_make_cookie_echo(asoc, NULL);
4262 /* Issue a sideeffect to do the needed accounting. */
4263 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4265 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4267 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4268 SCTP_U32(SCTP_ERROR_NO_ERROR));
4269 return SCTP_DISPOSITION_DELETE_TCB;
4272 return SCTP_DISPOSITION_CONSUME;
4275 return SCTP_DISPOSITION_NOMEM;
4278 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4279 * with the updated last sequential TSN received from its peer.
4281 * An endpoint should limit the number of retransmissions of the
4282 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4283 * If this threshold is exceeded the endpoint should destroy the TCB and
4284 * MUST report the peer endpoint unreachable to the upper layer (and
4285 * thus the association enters the CLOSED state). The reception of any
4286 * packet from its peer (i.e. as the peer sends all of its queued DATA
4287 * chunks) should clear the endpoint's retransmission count and restart
4288 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4289 * all of its queued DATA chunks that have not yet been sent.
4291 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
4292 const struct sctp_association *asoc,
4293 const sctp_subtype_t type,
4295 sctp_cmd_seq_t *commands)
4297 struct sctp_chunk *reply = NULL;
4299 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4300 if (asoc->overall_error_count >= asoc->max_retrans) {
4301 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4302 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4303 SCTP_U32(SCTP_ERROR_NO_ERROR));
4304 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4305 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4306 return SCTP_DISPOSITION_DELETE_TCB;
4309 switch (asoc->state) {
4310 case SCTP_STATE_SHUTDOWN_SENT:
4311 reply = sctp_make_shutdown(asoc, NULL);
4314 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4315 reply = sctp_make_shutdown_ack(asoc, NULL);
4326 /* Do some failure management (Section 8.2). */
4327 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4328 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4330 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4331 * the T2-shutdown timer.
4333 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4335 /* Restart the T2-shutdown timer. */
4336 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4337 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4338 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4339 return SCTP_DISPOSITION_CONSUME;
4342 return SCTP_DISPOSITION_NOMEM;
4346 * ADDIP Section 4.1 ASCONF CHunk Procedures
4347 * If the T4 RTO timer expires the endpoint should do B1 to B5
4349 sctp_disposition_t sctp_sf_t4_timer_expire(
4350 const struct sctp_endpoint *ep,
4351 const struct sctp_association *asoc,
4352 const sctp_subtype_t type,
4354 sctp_cmd_seq_t *commands)
4356 struct sctp_chunk *chunk = asoc->addip_last_asconf;
4357 struct sctp_transport *transport = chunk->transport;
4359 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4360 * detection on the appropriate destination address as defined in
4361 * RFC2960 [5] section 8.1 and 8.2.
4363 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4365 /* Reconfig T4 timer and transport. */
4366 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4368 /* ADDIP 4.1 B2) Increment the association error counters and perform
4369 * endpoint failure detection on the association as defined in
4370 * RFC2960 [5] section 8.1 and 8.2.
4371 * association error counter is incremented in SCTP_CMD_STRIKE.
4373 if (asoc->overall_error_count >= asoc->max_retrans) {
4374 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4375 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4376 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4377 SCTP_U32(SCTP_ERROR_NO_ERROR));
4378 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4379 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
4380 return SCTP_DISPOSITION_ABORT;
4383 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4384 * the ASCONF chunk was sent by doubling the RTO timer value.
4385 * This is done in SCTP_CMD_STRIKE.
4388 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4389 * choose an alternate destination address (please refer to RFC2960
4390 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4391 * chunk, it MUST be the same (including its serial number) as the last
4394 sctp_chunk_hold(asoc->addip_last_asconf);
4395 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4396 SCTP_CHUNK(asoc->addip_last_asconf));
4398 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4399 * destination is selected, then the RTO used will be that of the new
4400 * destination address.
4402 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4403 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4405 return SCTP_DISPOSITION_CONSUME;
4408 /* sctpimpguide-05 Section 2.12.2
4409 * The sender of the SHUTDOWN MAY also start an overall guard timer
4410 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4411 * At the expiration of this timer the sender SHOULD abort the association
4412 * by sending an ABORT chunk.
4414 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
4415 const struct sctp_association *asoc,
4416 const sctp_subtype_t type,
4418 sctp_cmd_seq_t *commands)
4420 struct sctp_chunk *reply = NULL;
4422 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4424 reply = sctp_make_abort(asoc, NULL, 0);
4428 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4429 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4430 SCTP_U32(SCTP_ERROR_NO_ERROR));
4432 return SCTP_DISPOSITION_DELETE_TCB;
4434 return SCTP_DISPOSITION_NOMEM;
4437 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4438 * the association is automatically closed by starting the shutdown process.
4439 * The work that needs to be done is same as when SHUTDOWN is initiated by
4440 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4442 sctp_disposition_t sctp_sf_autoclose_timer_expire(
4443 const struct sctp_endpoint *ep,
4444 const struct sctp_association *asoc,
4445 const sctp_subtype_t type,
4447 sctp_cmd_seq_t *commands)
4451 /* From 9.2 Shutdown of an Association
4452 * Upon receipt of the SHUTDOWN primitive from its upper
4453 * layer, the endpoint enters SHUTDOWN-PENDING state and
4454 * remains there until all outstanding data has been
4455 * acknowledged by its peer. The endpoint accepts no new data
4456 * from its upper layer, but retransmits data to the far end
4457 * if necessary to fill gaps.
4459 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4460 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4462 /* sctpimpguide-05 Section 2.12.2
4463 * The sender of the SHUTDOWN MAY also start an overall guard timer
4464 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4466 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4467 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4468 disposition = SCTP_DISPOSITION_CONSUME;
4469 if (sctp_outq_is_empty(&asoc->outqueue)) {
4470 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4476 /*****************************************************************************
4477 * These are sa state functions which could apply to all types of events.
4478 ****************************************************************************/
4481 * This table entry is not implemented.
4484 * (endpoint, asoc, chunk)
4486 * The return value is the disposition of the chunk.
4488 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
4489 const struct sctp_association *asoc,
4490 const sctp_subtype_t type,
4492 sctp_cmd_seq_t *commands)
4494 return SCTP_DISPOSITION_NOT_IMPL;
4498 * This table entry represents a bug.
4501 * (endpoint, asoc, chunk)
4503 * The return value is the disposition of the chunk.
4505 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
4506 const struct sctp_association *asoc,
4507 const sctp_subtype_t type,
4509 sctp_cmd_seq_t *commands)
4511 return SCTP_DISPOSITION_BUG;
4515 * This table entry represents the firing of a timer in the wrong state.
4516 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4517 * when the association is in the wrong state. This event should
4518 * be ignored, so as to prevent any rearming of the timer.
4521 * (endpoint, asoc, chunk)
4523 * The return value is the disposition of the chunk.
4525 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
4526 const struct sctp_association *asoc,
4527 const sctp_subtype_t type,
4529 sctp_cmd_seq_t *commands)
4531 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
4532 return SCTP_DISPOSITION_CONSUME;
4535 /********************************************************************
4536 * 2nd Level Abstractions
4537 ********************************************************************/
4539 /* Pull the SACK chunk based on the SACK header. */
4540 struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
4542 struct sctp_sackhdr *sack;
4547 /* Protect ourselves from reading too far into
4548 * the skb from a bogus sender.
4550 sack = (struct sctp_sackhdr *) chunk->skb->data;
4552 num_blocks = ntohs(sack->num_gap_ack_blocks);
4553 num_dup_tsns = ntohs(sack->num_dup_tsns);
4554 len = sizeof(struct sctp_sackhdr);
4555 len += (num_blocks + num_dup_tsns) * sizeof(__u32);
4556 if (len > chunk->skb->len)
4559 skb_pull(chunk->skb, len);
4564 /* Create an ABORT packet to be sent as a response, with the specified
4567 struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
4568 const struct sctp_association *asoc,
4569 struct sctp_chunk *chunk,
4570 const void *payload,
4573 struct sctp_packet *packet;
4574 struct sctp_chunk *abort;
4576 packet = sctp_ootb_pkt_new(asoc, chunk);
4580 * The T bit will be set if the asoc is NULL.
4582 abort = sctp_make_abort(asoc, chunk, paylen);
4584 sctp_ootb_pkt_free(packet);
4587 /* Add specified error causes, i.e., payload, to the
4590 sctp_addto_chunk(abort, paylen, payload);
4592 /* Set the skb to the belonging sock for accounting. */
4593 abort->skb->sk = ep->base.sk;
4595 sctp_packet_append_chunk(packet, abort);
4602 /* Allocate a packet for responding in the OOTB conditions. */
4603 struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
4604 const struct sctp_chunk *chunk)
4606 struct sctp_packet *packet;
4607 struct sctp_transport *transport;
4612 /* Get the source and destination port from the inbound packet. */
4613 sport = ntohs(chunk->sctp_hdr->dest);
4614 dport = ntohs(chunk->sctp_hdr->source);
4616 /* The V-tag is going to be the same as the inbound packet if no
4617 * association exists, otherwise, use the peer's vtag.
4620 vtag = asoc->peer.i.init_tag;
4622 /* Special case the INIT and stale COOKIE_ECHO as there is no
4625 switch(chunk->chunk_hdr->type) {
4628 sctp_init_chunk_t *init;
4630 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
4631 vtag = ntohl(init->init_hdr.init_tag);
4635 vtag = ntohl(chunk->sctp_hdr->vtag);
4640 /* Make a transport for the bucket, Eliza... */
4641 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
4645 /* Cache a route for the transport with the chunk's destination as
4646 * the source address.
4648 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
4649 sctp_sk(sctp_get_ctl_sock()));
4651 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
4652 packet = sctp_packet_config(packet, vtag, 0);
4660 /* Free the packet allocated earlier for responding in the OOTB condition. */
4661 void sctp_ootb_pkt_free(struct sctp_packet *packet)
4663 sctp_transport_free(packet->transport);
4666 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
4667 void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
4668 const struct sctp_association *asoc,
4669 const struct sctp_chunk *chunk,
4670 sctp_cmd_seq_t *commands,
4671 struct sctp_chunk *err_chunk)
4673 struct sctp_packet *packet;
4676 packet = sctp_ootb_pkt_new(asoc, chunk);
4678 struct sctp_signed_cookie *cookie;
4680 /* Override the OOTB vtag from the cookie. */
4681 cookie = chunk->subh.cookie_hdr;
4682 packet->vtag = cookie->c.peer_vtag;
4684 /* Set the skb to the belonging sock for accounting. */
4685 err_chunk->skb->sk = ep->base.sk;
4686 sctp_packet_append_chunk(packet, err_chunk);
4687 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4688 SCTP_PACKET(packet));
4689 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
4691 sctp_chunk_free (err_chunk);
4696 /* Process a data chunk */
4697 int sctp_eat_data(const struct sctp_association *asoc,
4698 struct sctp_chunk *chunk,
4699 sctp_cmd_seq_t *commands)
4701 sctp_datahdr_t *data_hdr;
4702 struct sctp_chunk *err;
4704 sctp_verb_t deliver;
4708 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
4709 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
4711 tsn = ntohl(data_hdr->tsn);
4712 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
4714 /* ASSERT: Now skb->data is really the user data. */
4716 /* Process ECN based congestion.
4718 * Since the chunk structure is reused for all chunks within
4719 * a packet, we use ecn_ce_done to track if we've already
4720 * done CE processing for this packet.
4722 * We need to do ECN processing even if we plan to discard the
4726 if (!chunk->ecn_ce_done) {
4728 chunk->ecn_ce_done = 1;
4730 af = sctp_get_af_specific(
4731 ipver2af(chunk->skb->nh.iph->version));
4733 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
4734 /* Do real work as sideffect. */
4735 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
4740 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
4742 /* The TSN is too high--silently discard the chunk and
4743 * count on it getting retransmitted later.
4745 return SCTP_IERROR_HIGH_TSN;
4746 } else if (tmp > 0) {
4747 /* This is a duplicate. Record it. */
4748 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
4749 return SCTP_IERROR_DUP_TSN;
4752 /* This is a new TSN. */
4754 /* Discard if there is no room in the receive window.
4755 * Actually, allow a little bit of overflow (up to a MTU).
4757 datalen = ntohs(chunk->chunk_hdr->length);
4758 datalen -= sizeof(sctp_data_chunk_t);
4760 deliver = SCTP_CMD_CHUNK_ULP;
4762 /* Think about partial delivery. */
4763 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
4765 /* Even if we don't accept this chunk there is
4768 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
4771 /* Spill over rwnd a little bit. Note: While allowed, this spill over
4772 * seems a bit troublesome in that frag_point varies based on
4773 * PMTU. In cases, such as loopback, this might be a rather
4776 if (!asoc->rwnd || asoc->rwnd_over ||
4777 (datalen > asoc->rwnd + asoc->frag_point)) {
4779 /* If this is the next TSN, consider reneging to make
4780 * room. Note: Playing nice with a confused sender. A
4781 * malicious sender can still eat up all our buffer
4782 * space and in the future we may want to detect and
4783 * do more drastic reneging.
4785 if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) &&
4786 (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) {
4787 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
4788 deliver = SCTP_CMD_RENEGE;
4790 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
4791 "rwnd: %d\n", tsn, datalen,
4793 return SCTP_IERROR_IGNORE_TSN;
4798 * Section 3.3.10.9 No User Data (9)
4802 * No User Data: This error cause is returned to the originator of a
4803 * DATA chunk if a received DATA chunk has no user data.
4805 if (unlikely(0 == datalen)) {
4806 err = sctp_make_abort_no_data(asoc, chunk, tsn);
4808 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4811 /* We are going to ABORT, so we might as well stop
4812 * processing the rest of the chunks in the packet.
4814 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
4815 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4816 SCTP_U32(SCTP_ERROR_NO_DATA));
4817 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
4818 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
4819 return SCTP_IERROR_NO_DATA;
4822 /* If definately accepting the DATA chunk, record its TSN, otherwise
4823 * wait for renege processing.
4825 if (SCTP_CMD_CHUNK_ULP == deliver)
4826 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
4828 /* Note: Some chunks may get overcounted (if we drop) or overcounted
4829 * if we renege and the chunk arrives again.
4831 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
4832 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS);
4834 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS);
4836 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
4838 * If an endpoint receive a DATA chunk with an invalid stream
4839 * identifier, it shall acknowledge the reception of the DATA chunk
4840 * following the normal procedure, immediately send an ERROR chunk
4841 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
4842 * and discard the DATA chunk.
4844 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
4845 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
4847 sizeof(data_hdr->stream));
4849 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4851 return SCTP_IERROR_BAD_STREAM;
4854 /* Send the data up to the user. Note: Schedule the
4855 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
4856 * chunk needs the updated rwnd.
4858 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
4860 return SCTP_IERROR_NO_ERROR;