1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 /**********************************************************
69 * These are the state functions for handling chunk events.
70 **********************************************************/
73 * Process the final SHUTDOWN COMPLETE.
75 * Section: 4 (C) (diagram), 9.2
76 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
77 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
78 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
79 * should stop the T2-shutdown timer and remove all knowledge of the
80 * association (and thus the association enters the CLOSED state).
82 * Verification Tag: 8.5.1(C)
83 * C) Rules for packet carrying SHUTDOWN COMPLETE:
85 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet if the
86 * Verification Tag field of the packet matches its own tag OR it is
87 * set to its peer's tag and the T bit is set in the Chunk Flags.
88 * Otherwise, the receiver MUST silently discard the packet and take
89 * no further action. An endpoint MUST ignore the SHUTDOWN COMPLETE if
90 * it is not in the SHUTDOWN-ACK-SENT state.
93 * (endpoint, asoc, chunk)
96 * (asoc, reply_msg, msg_up, timers, counters)
98 * The return value is the disposition of the chunk.
100 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
101 const struct sctp_association *asoc,
102 const sctp_subtype_t type,
104 sctp_cmd_seq_t *commands)
106 struct sctp_chunk *chunk = arg;
107 struct sctp_ulpevent *ev;
109 /* RFC 2960 6.10 Bundling
111 * An endpoint MUST NOT bundle INIT, INIT ACK or
112 * SHUTDOWN COMPLETE with any other chunks.
114 if (!chunk->singleton)
115 return SCTP_DISPOSITION_VIOLATION;
117 if (!sctp_vtag_verify_either(chunk, asoc))
118 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
120 /* RFC 2960 10.2 SCTP-to-ULP
122 * H) SHUTDOWN COMPLETE notification
124 * When SCTP completes the shutdown procedures (section 9.2) this
125 * notification is passed to the upper layer.
127 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
128 0, 0, 0, GFP_ATOMIC);
132 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
134 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
135 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
136 * not the chunk should be discarded. If the endpoint is in
137 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
138 * T2-shutdown timer and remove all knowledge of the
139 * association (and thus the association enters the CLOSED
142 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
143 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
145 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
146 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
148 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
149 SCTP_STATE(SCTP_STATE_CLOSED));
151 SCTP_INC_STATS(SctpShutdowns);
152 SCTP_DEC_STATS(SctpCurrEstab);
154 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
156 return SCTP_DISPOSITION_DELETE_TCB;
159 return SCTP_DISPOSITION_NOMEM;
163 * Respond to a normal INIT chunk.
164 * We are the side that is being asked for an association.
166 * Section: 5.1 Normal Establishment of an Association, B
167 * B) "Z" shall respond immediately with an INIT ACK chunk. The
168 * destination IP address of the INIT ACK MUST be set to the source
169 * IP address of the INIT to which this INIT ACK is responding. In
170 * the response, besides filling in other parameters, "Z" must set the
171 * Verification Tag field to Tag_A, and also provide its own
172 * Verification Tag (Tag_Z) in the Initiate Tag field.
174 * Verification Tag: No checking.
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 /* Verify the INIT chunk before processing it. */
224 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
225 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
227 /* This chunk contains fatal error. It is to be discarded.
228 * Send an ABORT, with causes if there is any.
231 packet = sctp_abort_pkt_new(ep, asoc, arg,
232 (__u8 *)(err_chunk->chunk_hdr) +
233 sizeof(sctp_chunkhdr_t),
234 ntohs(err_chunk->chunk_hdr->length) -
235 sizeof(sctp_chunkhdr_t));
237 sctp_chunk_free(err_chunk);
240 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
241 SCTP_PACKET(packet));
242 SCTP_INC_STATS(SctpOutCtrlChunks);
243 return SCTP_DISPOSITION_CONSUME;
245 return SCTP_DISPOSITION_NOMEM;
248 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
253 /* Grab the INIT header. */
254 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
256 /* Tag the variable length parameters. */
257 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
259 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
263 /* The call, sctp_process_init(), can fail on memory allocation. */
264 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
266 (sctp_init_chunk_t *)chunk->chunk_hdr,
270 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
272 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
274 /* If there are errors need to be reported for unknown parameters,
275 * make sure to reserve enough room in the INIT ACK for them.
279 len = ntohs(err_chunk->chunk_hdr->length) -
280 sizeof(sctp_chunkhdr_t);
282 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
285 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
289 /* If there are errors need to be reported for unknown parameters,
290 * include them in the outgoing INIT ACK as "Unrecognized parameter"
294 /* Get the "Unrecognized parameter" parameter(s) out of the
295 * ERROR chunk generated by sctp_verify_init(). Since the
296 * error cause code for "unknown parameter" and the
297 * "Unrecognized parameter" type is the same, we can
298 * construct the parameters in INIT ACK by copying the
301 unk_param = (sctp_unrecognized_param_t *)
302 ((__u8 *)(err_chunk->chunk_hdr) +
303 sizeof(sctp_chunkhdr_t));
304 /* Replace the cause code with the "Unrecognized parameter"
307 sctp_addto_chunk(repl, len, unk_param);
308 sctp_chunk_free(err_chunk);
311 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
314 * Note: After sending out INIT ACK with the State Cookie parameter,
315 * "Z" MUST NOT allocate any resources, nor keep any states for the
316 * new association. Otherwise, "Z" will be vulnerable to resource
319 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
321 return SCTP_DISPOSITION_DELETE_TCB;
325 sctp_chunk_free(err_chunk);
327 sctp_association_free(new_asoc);
329 return SCTP_DISPOSITION_NOMEM;
333 * Respond to a normal INIT ACK chunk.
334 * We are the side that is initiating the association.
336 * Section: 5.1 Normal Establishment of an Association, C
337 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
338 * timer and leave COOKIE-WAIT state. "A" shall then send the State
339 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
340 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
342 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
343 * DATA chunks, but it MUST be the first chunk in the packet and
344 * until the COOKIE ACK is returned the sender MUST NOT send any
345 * other packets to the peer.
347 * Verification Tag: 3.3.3
348 * If the value of the Initiate Tag in a received INIT ACK chunk is
349 * found to be 0, the receiver MUST treat it as an error and close the
350 * association by transmitting an ABORT.
353 * (endpoint, asoc, chunk)
356 * (asoc, reply_msg, msg_up, timers, counters)
358 * The return value is the disposition of the chunk.
360 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
361 const struct sctp_association *asoc,
362 const sctp_subtype_t type,
364 sctp_cmd_seq_t *commands)
366 struct sctp_chunk *chunk = arg;
367 sctp_init_chunk_t *initchunk;
369 struct sctp_chunk *err_chunk;
370 struct sctp_packet *packet;
371 sctp_disposition_t ret;
374 * An endpoint MUST NOT bundle INIT, INIT ACK or
375 * SHUTDOWN COMPLETE with any other chunks.
377 if (!chunk->singleton)
378 return SCTP_DISPOSITION_VIOLATION;
380 /* Grab the INIT header. */
381 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
383 init_tag = ntohl(chunk->subh.init_hdr->init_tag);
385 /* Verification Tag: 3.3.3
386 * If the value of the Initiate Tag in a received INIT ACK
387 * chunk is found to be 0, the receiver MUST treat it as an
388 * error and close the association by transmitting an ABORT.
391 struct sctp_chunk *reply = sctp_make_abort(asoc, chunk, 0);
395 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
396 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
397 SCTP_STATE(SCTP_STATE_CLOSED));
398 SCTP_INC_STATS(SctpAborteds);
399 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
400 return SCTP_DISPOSITION_DELETE_TCB;
403 /* Verify the INIT chunk before processing it. */
405 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
406 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
409 SCTP_INC_STATS(SctpAborteds);
411 /* This chunk contains fatal error. It is to be discarded.
412 * Send an ABORT, with causes if there is any.
415 packet = sctp_abort_pkt_new(ep, asoc, arg,
416 (__u8 *)(err_chunk->chunk_hdr) +
417 sizeof(sctp_chunkhdr_t),
418 ntohs(err_chunk->chunk_hdr->length) -
419 sizeof(sctp_chunkhdr_t));
421 sctp_chunk_free(err_chunk);
424 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
425 SCTP_PACKET(packet));
426 SCTP_INC_STATS(SctpOutCtrlChunks);
427 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
428 SCTP_STATE(SCTP_STATE_CLOSED));
429 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
431 return SCTP_DISPOSITION_CONSUME;
433 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
434 SCTP_STATE(SCTP_STATE_CLOSED));
435 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB,
437 return SCTP_DISPOSITION_NOMEM;
440 ret = sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
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,
450 /* Tag the variable length parameters. Note that we never
451 * convert the parameters in an INIT chunk.
453 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
455 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
457 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
458 SCTP_PEER_INIT(initchunk));
460 /* 5.1 C) "A" shall stop the T1-init timer and leave
461 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
462 * timer, and enter the COOKIE-ECHOED state.
464 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
465 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
466 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_RESET,
467 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
468 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
469 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
470 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
471 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
473 /* 5.1 C) "A" shall then send the State Cookie received in the
474 * INIT ACK chunk in a COOKIE ECHO chunk, ...
476 /* If there is any errors to report, send the ERROR chunk generated
477 * for unknown parameters as well.
479 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
480 SCTP_CHUNK(err_chunk));
482 return SCTP_DISPOSITION_CONSUME;
485 return SCTP_DISPOSITION_NOMEM;
489 * Respond to a normal COOKIE ECHO chunk.
490 * We are the side that is being asked for an association.
492 * Section: 5.1 Normal Establishment of an Association, D
493 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
494 * with a COOKIE ACK chunk after building a TCB and moving to
495 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
496 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
497 * chunk MUST be the first chunk in the packet.
499 * IMPLEMENTATION NOTE: An implementation may choose to send the
500 * Communication Up notification to the SCTP user upon reception
501 * of a valid COOKIE ECHO chunk.
503 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
504 * D) Rules for packet carrying a COOKIE ECHO
506 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
507 * Initial Tag received in the INIT ACK.
509 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
512 * (endpoint, asoc, chunk)
515 * (asoc, reply_msg, msg_up, timers, counters)
517 * The return value is the disposition of the chunk.
519 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
520 const struct sctp_association *asoc,
521 const sctp_subtype_t type, void *arg,
522 sctp_cmd_seq_t *commands)
524 struct sctp_chunk *chunk = arg;
525 struct sctp_association *new_asoc;
526 sctp_init_chunk_t *peer_init;
527 struct sctp_chunk *repl;
528 struct sctp_ulpevent *ev;
530 struct sctp_chunk *err_chk_p;
532 /* If the packet is an OOTB packet which is temporarily on the
533 * control endpoint, respond with an ABORT.
535 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
536 return sctp_sf_ootb(ep, asoc, type, arg, commands);
538 /* "Decode" the chunk. We have no optional parameters so we
541 chunk->subh.cookie_hdr =
542 (struct sctp_signed_cookie *)chunk->skb->data;
544 ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t));
546 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
547 * "Z" will reply with a COOKIE ACK chunk after building a TCB
548 * and moving to the ESTABLISHED state.
550 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
554 * If the re-build failed, what is the proper error path
557 * [We should abort the association. --piggy]
560 /* FIXME: Several errors are possible. A bad cookie should
561 * be silently discarded, but think about logging it too.
564 case -SCTP_IERROR_NOMEM:
567 case -SCTP_IERROR_STALE_COOKIE:
568 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
570 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
572 case -SCTP_IERROR_BAD_SIG:
574 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
578 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
579 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
580 SCTP_STATE(SCTP_STATE_ESTABLISHED));
581 SCTP_INC_STATS(SctpCurrEstab);
582 SCTP_INC_STATS(SctpPassiveEstabs);
583 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
585 if (new_asoc->autoclose)
586 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
587 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
589 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
591 /* Re-build the bind address for the association is done in
592 * the sctp_unpack_cookie() already.
594 /* This is a brand-new association, so these are not yet side
595 * effects--it is safe to run them here.
597 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
599 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
600 &chunk->subh.cookie_hdr->c.peer_addr,
601 peer_init, GFP_ATOMIC))
604 repl = sctp_make_cookie_ack(new_asoc, chunk);
608 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
610 /* RFC 2960 5.1 Normal Establishment of an Association
612 * D) IMPLEMENTATION NOTE: An implementation may choose to
613 * send the Communication Up notification to the SCTP user
614 * upon reception of a valid COOKIE ECHO chunk.
616 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
617 new_asoc->c.sinit_num_ostreams,
618 new_asoc->c.sinit_max_instreams,
623 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
625 return SCTP_DISPOSITION_CONSUME;
628 sctp_chunk_free(repl);
631 sctp_association_free(new_asoc);
633 return SCTP_DISPOSITION_NOMEM;
637 * Respond to a normal COOKIE ACK chunk.
638 * We are the side that is being asked for an association.
640 * RFC 2960 5.1 Normal Establishment of an Association
642 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
643 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
644 * timer. It may also notify its ULP about the successful
645 * establishment of the association with a Communication Up
646 * notification (see Section 10).
650 * (endpoint, asoc, chunk)
653 * (asoc, reply_msg, msg_up, timers, counters)
655 * The return value is the disposition of the chunk.
657 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
658 const struct sctp_association *asoc,
659 const sctp_subtype_t type, void *arg,
660 sctp_cmd_seq_t *commands)
662 struct sctp_ulpevent *ev;
664 /* RFC 2960 5.1 Normal Establishment of an Association
666 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
667 * from the COOKIE-ECHOED state to the ESTABLISHED state,
668 * stopping the T1-cookie timer.
670 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
671 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
672 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
673 SCTP_STATE(SCTP_STATE_ESTABLISHED));
674 SCTP_INC_STATS(SctpCurrEstab);
675 SCTP_INC_STATS(SctpActiveEstabs);
676 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
678 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
679 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
680 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
682 /* It may also notify its ULP about the successful
683 * establishment of the association with a Communication Up
684 * notification (see Section 10).
686 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
687 0, asoc->c.sinit_num_ostreams,
688 asoc->c.sinit_max_instreams,
694 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
696 return SCTP_DISPOSITION_CONSUME;
698 return SCTP_DISPOSITION_NOMEM;
701 /* Generate and sendout a heartbeat packet. */
702 sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
703 const struct sctp_association *asoc,
704 const sctp_subtype_t type,
706 sctp_cmd_seq_t *commands)
708 struct sctp_transport *transport = (struct sctp_transport *) arg;
709 struct sctp_chunk *reply;
710 sctp_sender_hb_info_t hbinfo;
713 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
714 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
715 hbinfo.daddr = transport->ipaddr;
716 hbinfo.sent_at = jiffies;
718 /* Send a heartbeat to our peer. */
719 paylen = sizeof(sctp_sender_hb_info_t);
720 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
722 return SCTP_DISPOSITION_NOMEM;
724 /* Set rto_pending indicating that an RTT measurement
725 * is started with this heartbeat chunk.
727 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
728 SCTP_TRANSPORT(transport));
730 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
731 return SCTP_DISPOSITION_CONSUME;
734 /* Generate a HEARTBEAT packet on the given transport. */
735 sctp_disposition_t sctp_sf_sendbeat_8_3(const struct sctp_endpoint *ep,
736 const struct sctp_association *asoc,
737 const sctp_subtype_t type,
739 sctp_cmd_seq_t *commands)
741 struct sctp_transport *transport = (struct sctp_transport *) arg;
743 if (asoc->overall_error_count > asoc->max_retrans) {
744 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
745 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
746 SCTP_U32(SCTP_ERROR_NO_ERROR));
747 SCTP_INC_STATS(SctpAborteds);
748 SCTP_DEC_STATS(SctpCurrEstab);
749 return SCTP_DISPOSITION_DELETE_TCB;
753 * The Sender-specific Heartbeat Info field should normally include
754 * information about the sender's current time when this HEARTBEAT
755 * chunk is sent and the destination transport address to which this
756 * HEARTBEAT is sent (see Section 8.3).
759 if (transport->hb_allowed) {
760 if (SCTP_DISPOSITION_NOMEM ==
761 sctp_sf_heartbeat(ep, asoc, type, arg,
763 return SCTP_DISPOSITION_NOMEM;
764 /* Set transport error counter and association error counter
765 * when sending heartbeat.
767 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
768 SCTP_TRANSPORT(transport));
770 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
771 SCTP_TRANSPORT(transport));
773 return SCTP_DISPOSITION_CONSUME;
777 * Process an heartbeat request.
779 * Section: 8.3 Path Heartbeat
780 * The receiver of the HEARTBEAT should immediately respond with a
781 * HEARTBEAT ACK that contains the Heartbeat Information field copied
782 * from the received HEARTBEAT chunk.
784 * Verification Tag: 8.5 Verification Tag [Normal verification]
785 * When receiving an SCTP packet, the endpoint MUST ensure that the
786 * value in the Verification Tag field of the received SCTP packet
787 * matches its own Tag. If the received Verification Tag value does not
788 * match the receiver's own tag value, the receiver shall silently
789 * discard the packet and shall not process it any further except for
790 * those cases listed in Section 8.5.1 below.
793 * (endpoint, asoc, chunk)
796 * (asoc, reply_msg, msg_up, timers, counters)
798 * The return value is the disposition of the chunk.
800 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
801 const struct sctp_association *asoc,
802 const sctp_subtype_t type,
804 sctp_cmd_seq_t *commands)
806 struct sctp_chunk *chunk = arg;
807 struct sctp_chunk *reply;
810 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
811 * that the value in the Verification Tag field of the
812 * received SCTP packet matches its own Tag. If the received
813 * Verification Tag value does not match the receiver's own
814 * tag value, the receiver shall silently discard the packet...
816 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
817 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
819 /* 8.3 The receiver of the HEARTBEAT should immediately
820 * respond with a HEARTBEAT ACK that contains the Heartbeat
821 * Information field copied from the received HEARTBEAT chunk.
823 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
824 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
825 skb_pull(chunk->skb, paylen);
827 reply = sctp_make_heartbeat_ack(asoc, chunk,
828 chunk->subh.hb_hdr, paylen);
832 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
833 return SCTP_DISPOSITION_CONSUME;
836 return SCTP_DISPOSITION_NOMEM;
840 * Process the returning HEARTBEAT ACK.
842 * Section: 8.3 Path Heartbeat
843 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
844 * should clear the error counter of the destination transport
845 * address to which the HEARTBEAT was sent, and mark the destination
846 * transport address as active if it is not so marked. The endpoint may
847 * optionally report to the upper layer when an inactive destination
848 * address is marked as active due to the reception of the latest
849 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
850 * clear the association overall error count as well (as defined
853 * The receiver of the HEARTBEAT ACK should also perform an RTT
854 * measurement for that destination transport address using the time
855 * value carried in the HEARTBEAT ACK chunk.
857 * Verification Tag: 8.5 Verification Tag [Normal verification]
860 * (endpoint, asoc, chunk)
863 * (asoc, reply_msg, msg_up, timers, counters)
865 * The return value is the disposition of the chunk.
867 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
868 const struct sctp_association *asoc,
869 const sctp_subtype_t type,
871 sctp_cmd_seq_t *commands)
873 struct sctp_chunk *chunk = arg;
874 union sctp_addr from_addr;
875 struct sctp_transport *link;
876 sctp_sender_hb_info_t *hbinfo;
877 unsigned long max_interval;
879 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
880 * that the value in the Verification Tag field of the
881 * received SCTP packet matches its own Tag. ...
883 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
884 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
886 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
887 from_addr = hbinfo->daddr;
888 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
890 /* This should never happen, but lets log it if so. */
893 "%s: Could not find address %d.%d.%d.%d\n",
894 __FUNCTION__, NIPQUAD(from_addr.v4.sin_addr));
895 return SCTP_DISPOSITION_DISCARD;
898 max_interval = link->hb_interval + link->rto;
900 /* Check if the timestamp looks valid. */
901 if (time_after(hbinfo->sent_at, jiffies) ||
902 time_after(jiffies, hbinfo->sent_at + max_interval)) {
903 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
904 "received for transport: %p\n",
906 return SCTP_DISPOSITION_DISCARD;
909 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
910 * the HEARTBEAT should clear the error counter of the
911 * destination transport address to which the HEARTBEAT was
912 * sent and mark the destination transport address as active if
913 * it is not so marked.
915 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
917 return SCTP_DISPOSITION_CONSUME;
920 /* Helper function to send out an abort for the restart
923 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
924 struct sctp_chunk *init,
925 sctp_cmd_seq_t *commands)
928 struct sctp_packet *pkt;
929 union sctp_addr_param *addrparm;
930 struct sctp_errhdr *errhdr;
931 struct sctp_endpoint *ep;
932 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
933 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
935 /* Build the error on the stack. We are way to malloc crazy
936 * throughout the code today.
938 errhdr = (struct sctp_errhdr *)buffer;
939 addrparm = (union sctp_addr_param *)errhdr->variable;
941 /* Copy into a parm format. */
942 len = af->to_addr_param(ssa, addrparm);
943 len += sizeof(sctp_errhdr_t);
945 errhdr->cause = SCTP_ERROR_RESTART;
946 errhdr->length = htons(len);
948 /* Assign to the control socket. */
949 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
951 /* Association is NULL since this may be a restart attack and we
952 * want to send back the attacker's vtag.
954 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
958 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
960 SCTP_INC_STATS(SctpOutCtrlChunks);
962 /* Discard the rest of the inbound packet. */
963 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
966 /* Even if there is no memory, treat as a failure so
967 * the packet will get dropped.
972 /* A restart is occurring, check to make sure no new addresses
973 * are being added as we may be under a takeover attack.
975 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
976 const struct sctp_association *asoc,
977 struct sctp_chunk *init,
978 sctp_cmd_seq_t *commands)
980 struct sctp_transport *new_addr, *addr;
981 struct list_head *pos, *pos2;
984 /* Implementor's Guide - Sectin 5.2.2
986 * Before responding the endpoint MUST check to see if the
987 * unexpected INIT adds new addresses to the association. If new
988 * addresses are added to the association, the endpoint MUST respond
992 /* Search through all current addresses and make sure
993 * we aren't adding any new ones.
998 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
999 new_addr = list_entry(pos, struct sctp_transport, transports);
1001 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1002 addr = list_entry(pos2, struct sctp_transport,
1004 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1014 /* If a new address was added, ABORT the sender. */
1015 if (!found && new_addr) {
1016 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1019 /* Return success if all addresses were found. */
1023 /* Populate the verification/tie tags based on overlapping INIT
1026 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1028 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1029 const struct sctp_association *asoc)
1031 switch (asoc->state) {
1033 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1035 case SCTP_STATE_COOKIE_WAIT:
1036 new_asoc->c.my_vtag = asoc->c.my_vtag;
1037 new_asoc->c.my_ttag = asoc->c.my_vtag;
1038 new_asoc->c.peer_ttag = 0;
1041 case SCTP_STATE_COOKIE_ECHOED:
1042 new_asoc->c.my_vtag = asoc->c.my_vtag;
1043 new_asoc->c.my_ttag = asoc->c.my_vtag;
1044 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1047 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1048 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1051 new_asoc->c.my_ttag = asoc->c.my_vtag;
1052 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1056 /* Other parameters for the endpoint SHOULD be copied from the
1057 * existing parameters of the association (e.g. number of
1058 * outbound streams) into the INIT ACK and cookie.
1060 new_asoc->rwnd = asoc->rwnd;
1061 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1062 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1063 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1067 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1070 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1072 * Returns value representing action to be taken. These action values
1073 * correspond to Action/Description values in RFC 2960, Table 2.
1075 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1076 const struct sctp_association *asoc)
1078 /* In this case, the peer may have restarted. */
1079 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1080 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1081 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1082 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1085 /* Collision case B. */
1086 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1087 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1088 (0 == asoc->c.peer_vtag))) {
1092 /* Collision case D. */
1093 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1094 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1097 /* Collision case C. */
1098 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1099 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1100 (0 == new_asoc->c.my_ttag) &&
1101 (0 == new_asoc->c.peer_ttag))
1104 /* No match to any of the special cases; discard this packet. */
1108 /* Common helper routine for both duplicate and simulataneous INIT
1111 static sctp_disposition_t sctp_sf_do_unexpected_init(
1112 const struct sctp_endpoint *ep,
1113 const struct sctp_association *asoc,
1114 const sctp_subtype_t type,
1115 void *arg, sctp_cmd_seq_t *commands)
1117 sctp_disposition_t retval;
1118 struct sctp_chunk *chunk = arg;
1119 struct sctp_chunk *repl;
1120 struct sctp_association *new_asoc;
1121 struct sctp_chunk *err_chunk;
1122 struct sctp_packet *packet;
1123 sctp_unrecognized_param_t *unk_param;
1127 * An endpoint MUST NOT bundle INIT, INIT ACK or
1128 * SHUTDOWN COMPLETE with any other chunks.
1130 if (!chunk->singleton)
1131 return SCTP_DISPOSITION_VIOLATION;
1133 /* Grab the INIT header. */
1134 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1136 /* Tag the variable length parameters. */
1137 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1139 /* Verify the INIT chunk before processing it. */
1141 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1142 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1144 /* This chunk contains fatal error. It is to be discarded.
1145 * Send an ABORT, with causes if there is any.
1148 packet = sctp_abort_pkt_new(ep, asoc, arg,
1149 (__u8 *)(err_chunk->chunk_hdr) +
1150 sizeof(sctp_chunkhdr_t),
1151 ntohs(err_chunk->chunk_hdr->length) -
1152 sizeof(sctp_chunkhdr_t));
1155 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1156 SCTP_PACKET(packet));
1157 SCTP_INC_STATS(SctpOutCtrlChunks);
1158 retval = SCTP_DISPOSITION_CONSUME;
1160 retval = SCTP_DISPOSITION_NOMEM;
1164 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1170 * Other parameters for the endpoint SHOULD be copied from the
1171 * existing parameters of the association (e.g. number of
1172 * outbound streams) into the INIT ACK and cookie.
1173 * FIXME: We are copying parameters from the endpoint not the
1176 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1180 /* In the outbound INIT ACK the endpoint MUST copy its current
1181 * Verification Tag and Peers Verification tag into a reserved
1182 * place (local tie-tag and per tie-tag) within the state cookie.
1184 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1186 (sctp_init_chunk_t *)chunk->chunk_hdr,
1188 retval = SCTP_DISPOSITION_NOMEM;
1192 /* Make sure no new addresses are being added during the
1193 * restart. Do not do this check for COOKIE-WAIT state,
1194 * since there are no peer addresses to check against.
1195 * Upon return an ABORT will have been sent if needed.
1197 if (!sctp_state(asoc, COOKIE_WAIT)) {
1198 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1200 retval = SCTP_DISPOSITION_CONSUME;
1205 sctp_tietags_populate(new_asoc, asoc);
1207 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1209 /* If there are errors need to be reported for unknown parameters,
1210 * make sure to reserve enough room in the INIT ACK for them.
1214 len = ntohs(err_chunk->chunk_hdr->length) -
1215 sizeof(sctp_chunkhdr_t);
1218 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1221 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1225 /* If there are errors need to be reported for unknown parameters,
1226 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1230 /* Get the "Unrecognized parameter" parameter(s) out of the
1231 * ERROR chunk generated by sctp_verify_init(). Since the
1232 * error cause code for "unknown parameter" and the
1233 * "Unrecognized parameter" type is the same, we can
1234 * construct the parameters in INIT ACK by copying the
1235 * ERROR causes over.
1237 unk_param = (sctp_unrecognized_param_t *)
1238 ((__u8 *)(err_chunk->chunk_hdr) +
1239 sizeof(sctp_chunkhdr_t));
1240 /* Replace the cause code with the "Unrecognized parameter"
1243 sctp_addto_chunk(repl, len, unk_param);
1246 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1247 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1250 * Note: After sending out INIT ACK with the State Cookie parameter,
1251 * "Z" MUST NOT allocate any resources for this new association.
1252 * Otherwise, "Z" will be vulnerable to resource attacks.
1254 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1255 retval = SCTP_DISPOSITION_CONSUME;
1259 sctp_chunk_free(err_chunk);
1262 retval = SCTP_DISPOSITION_NOMEM;
1266 sctp_association_free(new_asoc);
1271 * Handle simultanous INIT.
1272 * This means we started an INIT and then we got an INIT request from
1275 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1276 * This usually indicates an initialization collision, i.e., each
1277 * endpoint is attempting, at about the same time, to establish an
1278 * association with the other endpoint.
1280 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1281 * endpoint MUST respond with an INIT ACK using the same parameters it
1282 * sent in its original INIT chunk (including its Verification Tag,
1283 * unchanged). These original parameters are combined with those from the
1284 * newly received INIT chunk. The endpoint shall also generate a State
1285 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1286 * INIT to calculate the State Cookie.
1288 * After that, the endpoint MUST NOT change its state, the T1-init
1289 * timer shall be left running and the corresponding TCB MUST NOT be
1290 * destroyed. The normal procedures for handling State Cookies when
1291 * a TCB exists will resolve the duplicate INITs to a single association.
1293 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1294 * its Tie-Tags with the Tag information of itself and its peer (see
1295 * section 5.2.2 for a description of the Tie-Tags).
1297 * Verification Tag: Not explicit, but an INIT can not have a valid
1298 * verification tag, so we skip the check.
1301 * (endpoint, asoc, chunk)
1304 * (asoc, reply_msg, msg_up, timers, counters)
1306 * The return value is the disposition of the chunk.
1308 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1309 const struct sctp_association *asoc,
1310 const sctp_subtype_t type,
1312 sctp_cmd_seq_t *commands)
1314 /* Call helper to do the real work for both simulataneous and
1315 * duplicate INIT chunk handling.
1317 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1321 * Handle duplicated INIT messages. These are usually delayed
1324 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1325 * COOKIE-ECHOED and COOKIE-WAIT
1327 * Unless otherwise stated, upon reception of an unexpected INIT for
1328 * this association, the endpoint shall generate an INIT ACK with a
1329 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1330 * current Verification Tag and peer's Verification Tag into a reserved
1331 * place within the state cookie. We shall refer to these locations as
1332 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1333 * containing this INIT ACK MUST carry a Verification Tag value equal to
1334 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1335 * MUST contain a new Initiation Tag (randomly generated see Section
1336 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1337 * existing parameters of the association (e.g. number of outbound
1338 * streams) into the INIT ACK and cookie.
1340 * After sending out the INIT ACK, the endpoint shall take no further
1341 * actions, i.e., the existing association, including its current state,
1342 * and the corresponding TCB MUST NOT be changed.
1344 * Note: Only when a TCB exists and the association is not in a COOKIE-
1345 * WAIT state are the Tie-Tags populated. For a normal association INIT
1346 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1347 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1348 * State Cookie are populated as specified in section 5.2.1.
1350 * Verification Tag: Not specified, but an INIT has no way of knowing
1351 * what the verification tag could be, so we ignore it.
1354 * (endpoint, asoc, chunk)
1357 * (asoc, reply_msg, msg_up, timers, counters)
1359 * The return value is the disposition of the chunk.
1361 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1362 const struct sctp_association *asoc,
1363 const sctp_subtype_t type,
1365 sctp_cmd_seq_t *commands)
1367 /* Call helper to do the real work for both simulataneous and
1368 * duplicate INIT chunk handling.
1370 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1375 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1378 * A) In this case, the peer may have restarted.
1380 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1381 const struct sctp_association *asoc,
1382 struct sctp_chunk *chunk,
1383 sctp_cmd_seq_t *commands,
1384 struct sctp_association *new_asoc)
1386 sctp_init_chunk_t *peer_init;
1387 struct sctp_ulpevent *ev;
1388 struct sctp_chunk *repl;
1390 /* new_asoc is a brand-new association, so these are not yet
1391 * side effects--it is safe to run them here.
1393 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1395 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1396 sctp_source(chunk), peer_init,
1400 /* Make sure no new addresses are being added during the
1401 * restart. Though this is a pretty complicated attack
1402 * since you'd have to get inside the cookie.
1404 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1405 return SCTP_DISPOSITION_CONSUME;
1408 /* For now, fail any unsent/unacked data. Consider the optional
1409 * choice of resending of this data.
1411 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1413 /* Update the content of current association. */
1414 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1416 repl = sctp_make_cookie_ack(new_asoc, chunk);
1420 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1422 /* Report association restart to upper layer. */
1423 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1424 new_asoc->c.sinit_num_ostreams,
1425 new_asoc->c.sinit_max_instreams,
1430 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1431 return SCTP_DISPOSITION_CONSUME;
1434 sctp_chunk_free(repl);
1436 return SCTP_DISPOSITION_NOMEM;
1439 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1442 * B) In this case, both sides may be attempting to start an association
1443 * at about the same time but the peer endpoint started its INIT
1444 * after responding to the local endpoint's INIT
1446 /* This case represents an initialization collision. */
1447 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1448 const struct sctp_association *asoc,
1449 struct sctp_chunk *chunk,
1450 sctp_cmd_seq_t *commands,
1451 struct sctp_association *new_asoc)
1453 sctp_init_chunk_t *peer_init;
1454 struct sctp_ulpevent *ev;
1455 struct sctp_chunk *repl;
1457 /* new_asoc is a brand-new association, so these are not yet
1458 * side effects--it is safe to run them here.
1460 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1461 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1462 sctp_source(chunk), peer_init,
1466 /* Update the content of current association. */
1467 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1468 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1469 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1470 SCTP_INC_STATS(SctpCurrEstab);
1471 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1473 repl = sctp_make_cookie_ack(new_asoc, chunk);
1477 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1478 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1480 /* RFC 2960 5.1 Normal Establishment of an Association
1482 * D) IMPLEMENTATION NOTE: An implementation may choose to
1483 * send the Communication Up notification to the SCTP user
1484 * upon reception of a valid COOKIE ECHO chunk.
1486 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP, 0,
1487 new_asoc->c.sinit_num_ostreams,
1488 new_asoc->c.sinit_max_instreams,
1493 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1494 return SCTP_DISPOSITION_CONSUME;
1497 sctp_chunk_free(repl);
1499 return SCTP_DISPOSITION_NOMEM;
1502 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1505 * C) In this case, the local endpoint's cookie has arrived late.
1506 * Before it arrived, the local endpoint sent an INIT and received an
1507 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1508 * but a new tag of its own.
1510 /* This case represents an initialization collision. */
1511 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1512 const struct sctp_association *asoc,
1513 struct sctp_chunk *chunk,
1514 sctp_cmd_seq_t *commands,
1515 struct sctp_association *new_asoc)
1517 /* The cookie should be silently discarded.
1518 * The endpoint SHOULD NOT change states and should leave
1519 * any timers running.
1521 return SCTP_DISPOSITION_DISCARD;
1524 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1528 * D) When both local and remote tags match the endpoint should always
1529 * enter the ESTABLISHED state, if it has not already done so.
1531 /* This case represents an initialization collision. */
1532 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1533 const struct sctp_association *asoc,
1534 struct sctp_chunk *chunk,
1535 sctp_cmd_seq_t *commands,
1536 struct sctp_association *new_asoc)
1538 struct sctp_ulpevent *ev = NULL;
1539 struct sctp_chunk *repl;
1541 /* Clarification from Implementor's Guide:
1542 * D) When both local and remote tags match the endpoint should
1543 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1544 * It should stop any cookie timer that may be running and send
1548 /* Don't accidentally move back into established state. */
1549 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1550 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1551 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1552 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1553 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1554 SCTP_INC_STATS(SctpCurrEstab);
1555 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1558 /* RFC 2960 5.1 Normal Establishment of an Association
1560 * D) IMPLEMENTATION NOTE: An implementation may choose
1561 * to send the Communication Up notification to the
1562 * SCTP user upon reception of a valid COOKIE
1565 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0,
1567 new_asoc->c.sinit_num_ostreams,
1568 new_asoc->c.sinit_max_instreams,
1572 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1575 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1577 repl = sctp_make_cookie_ack(new_asoc, chunk);
1581 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1582 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1584 return SCTP_DISPOSITION_CONSUME;
1588 sctp_ulpevent_free(ev);
1589 return SCTP_DISPOSITION_NOMEM;
1593 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1594 * chunk was retransmitted and then delayed in the network.
1596 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1598 * Verification Tag: None. Do cookie validation.
1601 * (endpoint, asoc, chunk)
1604 * (asoc, reply_msg, msg_up, timers, counters)
1606 * The return value is the disposition of the chunk.
1608 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1609 const struct sctp_association *asoc,
1610 const sctp_subtype_t type,
1612 sctp_cmd_seq_t *commands)
1614 sctp_disposition_t retval;
1615 struct sctp_chunk *chunk = arg;
1616 struct sctp_association *new_asoc;
1619 struct sctp_chunk *err_chk_p;
1621 /* "Decode" the chunk. We have no optional parameters so we
1622 * are in good shape.
1624 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1625 skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1626 sizeof(sctp_chunkhdr_t));
1628 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1629 * of a duplicate COOKIE ECHO match the Verification Tags of the
1630 * current association, consider the State Cookie valid even if
1631 * the lifespan is exceeded.
1633 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1637 * If the re-build failed, what is the proper error path
1640 * [We should abort the association. --piggy]
1643 /* FIXME: Several errors are possible. A bad cookie should
1644 * be silently discarded, but think about logging it too.
1647 case -SCTP_IERROR_NOMEM:
1650 case -SCTP_IERROR_STALE_COOKIE:
1651 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1653 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1654 case -SCTP_IERROR_BAD_SIG:
1656 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1660 /* Compare the tie_tag in cookie with the verification tag of
1661 * current association.
1663 action = sctp_tietags_compare(new_asoc, asoc);
1666 case 'A': /* Association restart. */
1667 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1671 case 'B': /* Collision case B. */
1672 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1676 case 'C': /* Collision case C. */
1677 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1681 case 'D': /* Collision case D. */
1682 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1686 default: /* Discard packet for all others. */
1687 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1691 /* Delete the tempory new association. */
1692 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1693 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1698 return SCTP_DISPOSITION_NOMEM;
1702 * Process an ABORT. (SHUTDOWN-PENDING state)
1704 * See sctp_sf_do_9_1_abort().
1706 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1707 const struct sctp_endpoint *ep,
1708 const struct sctp_association *asoc,
1709 const sctp_subtype_t type,
1711 sctp_cmd_seq_t *commands)
1713 struct sctp_chunk *chunk = arg;
1715 if (!sctp_vtag_verify_either(chunk, asoc))
1716 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1718 /* Stop the T5-shutdown guard timer. */
1719 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1720 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1722 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1726 * Process an ABORT. (SHUTDOWN-SENT state)
1728 * See sctp_sf_do_9_1_abort().
1730 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
1731 const struct sctp_association *asoc,
1732 const sctp_subtype_t type,
1734 sctp_cmd_seq_t *commands)
1736 struct sctp_chunk *chunk = arg;
1738 if (!sctp_vtag_verify_either(chunk, asoc))
1739 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1741 /* Stop the T2-shutdown timer. */
1742 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1743 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
1745 /* Stop the T5-shutdown guard timer. */
1746 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1747 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1749 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1753 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
1755 * See sctp_sf_do_9_1_abort().
1757 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
1758 const struct sctp_endpoint *ep,
1759 const struct sctp_association *asoc,
1760 const sctp_subtype_t type,
1762 sctp_cmd_seq_t *commands)
1764 /* The same T2 timer, so we should be able to use
1765 * common function with the SHUTDOWN-SENT state.
1767 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
1771 * Handle an Error received in COOKIE_ECHOED state.
1773 * Only handle the error type of stale COOKIE Error, the other errors will
1777 * (endpoint, asoc, chunk)
1780 * (asoc, reply_msg, msg_up, timers, counters)
1782 * The return value is the disposition of the chunk.
1784 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
1785 const struct sctp_association *asoc,
1786 const sctp_subtype_t type,
1788 sctp_cmd_seq_t *commands)
1790 struct sctp_chunk *chunk = arg;
1793 /* Process the error here */
1794 /* FUTURE FIXME: When PR-SCTP related and other optional
1795 * parms are emitted, this will have to change to handle multiple
1798 sctp_walk_errors(err, chunk->chunk_hdr) {
1799 if (SCTP_ERROR_STALE_COOKIE == err->cause)
1800 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
1803 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1807 * Handle a Stale COOKIE Error
1809 * Section: 5.2.6 Handle Stale COOKIE Error
1810 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
1811 * one of the following three alternatives.
1813 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
1814 * Preservative parameter requesting an extension to the lifetime of
1815 * the State Cookie. When calculating the time extension, an
1816 * implementation SHOULD use the RTT information measured based on the
1817 * previous COOKIE ECHO / ERROR exchange, and should add no more
1818 * than 1 second beyond the measured RTT, due to long State Cookie
1819 * lifetimes making the endpoint more subject to a replay attack.
1821 * Verification Tag: Not explicit, but safe to ignore.
1824 * (endpoint, asoc, chunk)
1827 * (asoc, reply_msg, msg_up, timers, counters)
1829 * The return value is the disposition of the chunk.
1831 sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
1832 const struct sctp_association *asoc,
1833 const sctp_subtype_t type,
1835 sctp_cmd_seq_t *commands)
1837 struct sctp_chunk *chunk = arg;
1839 sctp_cookie_preserve_param_t bht;
1841 struct list_head *pos;
1842 struct sctp_transport *t;
1843 struct sctp_chunk *reply;
1844 struct sctp_bind_addr *bp;
1847 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
1849 if (attempts >= asoc->max_init_attempts) {
1850 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
1851 SCTP_U32(SCTP_ERROR_STALE_COOKIE));
1852 return SCTP_DISPOSITION_DELETE_TCB;
1855 err = (sctp_errhdr_t *)(chunk->skb->data);
1857 /* When calculating the time extension, an implementation
1858 * SHOULD use the RTT information measured based on the
1859 * previous COOKIE ECHO / ERROR exchange, and should add no
1860 * more than 1 second beyond the measured RTT, due to long
1861 * State Cookie lifetimes making the endpoint more subject to
1863 * Measure of Staleness's unit is usec. (1/1000000 sec)
1864 * Suggested Cookie Life-span Increment's unit is msec.
1866 * In general, if you use the suggested cookie life, the value
1867 * found in the field of measure of staleness should be doubled
1868 * to give ample time to retransmit the new cookie and thus
1869 * yield a higher probability of success on the reattempt.
1871 stale = ntohl(*(suseconds_t *)((u8 *)err + sizeof(sctp_errhdr_t)));
1872 stale = (stale * 2) / 1000;
1874 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
1875 bht.param_hdr.length = htons(sizeof(bht));
1876 bht.lifespan_increment = htonl(stale);
1878 /* Build that new INIT chunk. */
1879 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
1880 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
1884 sctp_addto_chunk(reply, sizeof(bht), &bht);
1886 /* Cast away the const modifier, as we want to just
1887 * rerun it through as a sideffect.
1889 sctp_add_cmd_sf(commands, SCTP_CMD_COUNTER_INC,
1890 SCTP_COUNTER(SCTP_COUNTER_INIT_ERROR));
1892 /* If we've sent any data bundled with COOKIE-ECHO we need to
1895 list_for_each(pos, &asoc->peer.transport_addr_list) {
1896 t = list_entry(pos, struct sctp_transport, transports);
1897 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(t));
1900 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1901 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1902 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1903 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
1904 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
1905 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1907 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
1909 return SCTP_DISPOSITION_CONSUME;
1912 return SCTP_DISPOSITION_NOMEM;
1919 * After checking the Verification Tag, the receiving endpoint shall
1920 * remove the association from its record, and shall report the
1921 * termination to its upper layer.
1923 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
1924 * B) Rules for packet carrying ABORT:
1926 * - The endpoint shall always fill in the Verification Tag field of the
1927 * outbound packet with the destination endpoint's tag value if it
1930 * - If the ABORT is sent in response to an OOTB packet, the endpoint
1931 * MUST follow the procedure described in Section 8.4.
1933 * - The receiver MUST accept the packet if the Verification Tag
1934 * matches either its own tag, OR the tag of its peer. Otherwise, the
1935 * receiver MUST silently discard the packet and take no further
1939 * (endpoint, asoc, chunk)
1942 * (asoc, reply_msg, msg_up, timers, counters)
1944 * The return value is the disposition of the chunk.
1946 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
1947 const struct sctp_association *asoc,
1948 const sctp_subtype_t type,
1950 sctp_cmd_seq_t *commands)
1952 struct sctp_chunk *chunk = arg;
1954 __u16 error = SCTP_ERROR_NO_ERROR;
1956 if (!sctp_vtag_verify_either(chunk, asoc))
1957 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1959 /* Check that chunk header looks valid. */
1960 len = ntohs(chunk->chunk_hdr->length);
1961 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
1962 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
1965 /* ASSOC_FAILED will DELETE_TCB. */
1966 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_U32(error));
1967 SCTP_INC_STATS(SctpAborteds);
1968 SCTP_DEC_STATS(SctpCurrEstab);
1970 return SCTP_DISPOSITION_ABORT;
1974 * Process an ABORT. (COOKIE-WAIT state)
1976 * See sctp_sf_do_9_1_abort() above.
1978 sctp_disposition_t sctp_sf_cookie_wait_abort(const struct sctp_endpoint *ep,
1979 const struct sctp_association *asoc,
1980 const sctp_subtype_t type,
1982 sctp_cmd_seq_t *commands)
1984 struct sctp_chunk *chunk = arg;
1986 __u16 error = SCTP_ERROR_NO_ERROR;
1988 if (!sctp_vtag_verify_either(chunk, asoc))
1989 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1991 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1992 SCTP_STATE(SCTP_STATE_CLOSED));
1993 SCTP_INC_STATS(SctpAborteds);
1994 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1995 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
1997 /* Check that chunk header looks valid. */
1998 len = ntohs(chunk->chunk_hdr->length);
1999 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2000 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2002 /* CMD_INIT_FAILED will DELETE_TCB. */
2003 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED, SCTP_U32(error));
2005 return SCTP_DISPOSITION_ABORT;
2009 * Process an ABORT. (COOKIE-ECHOED state)
2011 * See sctp_sf_do_9_1_abort() above.
2013 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2014 const struct sctp_association *asoc,
2015 const sctp_subtype_t type,
2017 sctp_cmd_seq_t *commands)
2019 /* There is a single T1 timer, so we should be able to use
2020 * common function with the COOKIE-WAIT state.
2022 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2026 * sctp_sf_do_9_2_shut
2029 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2030 * - enter the SHUTDOWN-RECEIVED state,
2032 * - stop accepting new data from its SCTP user
2034 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2035 * that all its outstanding DATA chunks have been received by the
2038 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2039 * send a SHUTDOWN in response to a ULP request. And should discard
2040 * subsequent SHUTDOWN chunks.
2042 * If there are still outstanding DATA chunks left, the SHUTDOWN
2043 * receiver shall continue to follow normal data transmission
2044 * procedures defined in Section 6 until all outstanding DATA chunks
2045 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2046 * new data from its SCTP user.
2048 * Verification Tag: 8.5 Verification Tag [Normal verification]
2051 * (endpoint, asoc, chunk)
2054 * (asoc, reply_msg, msg_up, timers, counters)
2056 * The return value is the disposition of the chunk.
2058 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2059 const struct sctp_association *asoc,
2060 const sctp_subtype_t type,
2062 sctp_cmd_seq_t *commands)
2064 struct sctp_chunk *chunk = arg;
2065 sctp_shutdownhdr_t *sdh;
2066 sctp_disposition_t disposition;
2067 struct sctp_ulpevent *ev;
2069 /* Convert the elaborate header. */
2070 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2071 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2072 chunk->subh.shutdown_hdr = sdh;
2074 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2075 * that the value in the Verification Tag field of the
2076 * received SCTP packet matches its own Tag. If the received
2077 * Verification Tag value does not match the receiver's own
2078 * tag value, the receiver shall silently discard the packet...
2080 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2081 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2083 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2084 * - enter the SHUTDOWN-RECEIVED state,
2085 * - stop accepting new data from its SCTP user
2087 * [This is implicit in the new state.]
2089 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2090 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2091 disposition = SCTP_DISPOSITION_CONSUME;
2093 if (sctp_outq_is_empty(&asoc->outqueue)) {
2094 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2098 if (SCTP_DISPOSITION_NOMEM == disposition)
2101 /* - verify, by checking the Cumulative TSN Ack field of the
2102 * chunk, that all its outstanding DATA chunks have been
2103 * received by the SHUTDOWN sender.
2105 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2106 SCTP_U32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2108 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2109 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2110 * inform the application that it should cease sending data.
2112 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2114 disposition = SCTP_DISPOSITION_NOMEM;
2117 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2124 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2125 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2126 * transport addresses (either in the IP addresses or in the INIT chunk)
2127 * that belong to this association, it should discard the INIT chunk and
2128 * retransmit the SHUTDOWN ACK chunk.
2130 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2131 const struct sctp_association *asoc,
2132 const sctp_subtype_t type,
2134 sctp_cmd_seq_t *commands)
2136 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2137 struct sctp_chunk *reply;
2139 reply = sctp_make_shutdown_ack(asoc, chunk);
2143 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2144 * the T2-SHUTDOWN timer.
2146 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2148 /* and restart the T2-shutdown timer. */
2149 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2150 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2152 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2154 return SCTP_DISPOSITION_CONSUME;
2156 return SCTP_DISPOSITION_NOMEM;
2160 * sctp_sf_do_ecn_cwr
2162 * Section: Appendix A: Explicit Congestion Notification
2166 * RFC 2481 details a specific bit for a sender to send in the header of
2167 * its next outbound TCP segment to indicate to its peer that it has
2168 * reduced its congestion window. This is termed the CWR bit. For
2169 * SCTP the same indication is made by including the CWR chunk.
2170 * This chunk contains one data element, i.e. the TSN number that
2171 * was sent in the ECNE chunk. This element represents the lowest
2172 * TSN number in the datagram that was originally marked with the
2175 * Verification Tag: 8.5 Verification Tag [Normal verification]
2177 * (endpoint, asoc, chunk)
2180 * (asoc, reply_msg, msg_up, timers, counters)
2182 * The return value is the disposition of the chunk.
2184 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2185 const struct sctp_association *asoc,
2186 const sctp_subtype_t type,
2188 sctp_cmd_seq_t *commands)
2191 struct sctp_chunk *chunk = arg;
2193 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2194 * that the value in the Verification Tag field of the
2195 * received SCTP packet matches its own Tag. If the received
2196 * Verification Tag value does not match the receiver's own
2197 * tag value, the receiver shall silently discard the packet...
2199 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2200 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2202 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2203 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2205 cwr->lowest_tsn = ntohl(cwr->lowest_tsn);
2207 /* Does this CWR ack the last sent congestion notification? */
2208 if (TSN_lte(asoc->last_ecne_tsn, cwr->lowest_tsn)) {
2209 /* Stop sending ECNE. */
2210 sctp_add_cmd_sf(commands,
2212 SCTP_U32(cwr->lowest_tsn));
2214 return SCTP_DISPOSITION_CONSUME;
2220 * Section: Appendix A: Explicit Congestion Notification
2224 * RFC 2481 details a specific bit for a receiver to send back in its
2225 * TCP acknowledgements to notify the sender of the Congestion
2226 * Experienced (CE) bit having arrived from the network. For SCTP this
2227 * same indication is made by including the ECNE chunk. This chunk
2228 * contains one data element, i.e. the lowest TSN associated with the IP
2229 * datagram marked with the CE bit.....
2231 * Verification Tag: 8.5 Verification Tag [Normal verification]
2233 * (endpoint, asoc, chunk)
2236 * (asoc, reply_msg, msg_up, timers, counters)
2238 * The return value is the disposition of the chunk.
2240 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2241 const struct sctp_association *asoc,
2242 const sctp_subtype_t type,
2244 sctp_cmd_seq_t *commands)
2246 sctp_ecnehdr_t *ecne;
2247 struct sctp_chunk *chunk = arg;
2249 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2250 * that the value in the Verification Tag field of the
2251 * received SCTP packet matches its own Tag. If the received
2252 * Verification Tag value does not match the receiver's own
2253 * tag value, the receiver shall silently discard the packet...
2255 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2256 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2258 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2259 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2261 /* If this is a newer ECNE than the last CWR packet we sent out */
2262 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2263 SCTP_U32(ntohl(ecne->lowest_tsn)));
2265 return SCTP_DISPOSITION_CONSUME;
2269 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2271 * The SCTP endpoint MUST always acknowledge the reception of each valid
2274 * The guidelines on delayed acknowledgement algorithm specified in
2275 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2276 * acknowledgement SHOULD be generated for at least every second packet
2277 * (not every second DATA chunk) received, and SHOULD be generated within
2278 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2279 * situations it may be beneficial for an SCTP transmitter to be more
2280 * conservative than the algorithms detailed in this document allow.
2281 * However, an SCTP transmitter MUST NOT be more aggressive than the
2282 * following algorithms allow.
2284 * A SCTP receiver MUST NOT generate more than one SACK for every
2285 * incoming packet, other than to update the offered window as the
2286 * receiving application consumes new data.
2288 * Verification Tag: 8.5 Verification Tag [Normal verification]
2291 * (endpoint, asoc, chunk)
2294 * (asoc, reply_msg, msg_up, timers, counters)
2296 * The return value is the disposition of the chunk.
2298 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2299 const struct sctp_association *asoc,
2300 const sctp_subtype_t type,
2302 sctp_cmd_seq_t *commands)
2304 struct sctp_chunk *chunk = arg;
2305 sctp_datahdr_t *data_hdr;
2306 struct sctp_chunk *err;
2308 sctp_verb_t deliver;
2312 /* RFC 2960 8.5 Verification Tag
2314 * When receiving an SCTP packet, the endpoint MUST ensure
2315 * that the value in the Verification Tag field of the
2316 * received SCTP packet matches its own Tag.
2318 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
2319 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2321 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2324 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
2325 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
2327 tsn = ntohl(data_hdr->tsn);
2328 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
2330 /* ASSERT: Now skb->data is really the user data. */
2332 /* Process ECN based congestion.
2334 * Since the chunk structure is reused for all chunks within
2335 * a packet, we use ecn_ce_done to track if we've already
2336 * done CE processing for this packet.
2338 * We need to do ECN processing even if we plan to discard the
2342 if (!chunk->ecn_ce_done) {
2344 chunk->ecn_ce_done = 1;
2346 af = sctp_get_af_specific(
2347 ipver2af(chunk->skb->nh.iph->version));
2349 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
2350 /* Do real work as sideffect. */
2351 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
2356 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
2358 /* The TSN is too high--silently discard the chunk and
2359 * count on it getting retransmitted later.
2361 goto discard_noforce;
2362 } else if (tmp > 0) {
2363 /* This is a duplicate. Record it. */
2364 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
2368 /* This is a new TSN. */
2370 /* Discard if there is no room in the receive window.
2371 * Actually, allow a little bit of overflow (up to a MTU).
2373 datalen = ntohs(chunk->chunk_hdr->length);
2374 datalen -= sizeof(sctp_data_chunk_t);
2376 deliver = SCTP_CMD_CHUNK_ULP;
2378 /* Think about partial delivery. */
2379 if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
2381 /* Even if we don't accept this chunk there is
2384 sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
2387 /* Spill over rwnd a little bit. Note: While allowed, this spill over
2388 * seems a bit troublesome in that frag_point varies based on
2389 * PMTU. In cases, such as loopback, this might be a rather
2392 if (!asoc->rwnd || asoc->rwnd_over ||
2393 (datalen > asoc->rwnd + asoc->frag_point)) {
2395 /* If this is the next TSN, consider reneging to make
2396 * room. Note: Playing nice with a confused sender. A
2397 * malicious sender can still eat up all our buffer
2398 * space and in the future we may want to detect and
2399 * do more drastic reneging.
2401 if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) &&
2402 (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) {
2403 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
2404 deliver = SCTP_CMD_RENEGE;
2406 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
2407 "rwnd: %d\n", tsn, datalen,
2414 * Section 3.3.10.9 No User Data (9)
2418 * No User Data: This error cause is returned to the originator of a
2419 * DATA chunk if a received DATA chunk has no user data.
2421 if (unlikely(0 == datalen)) {
2422 err = sctp_make_abort_no_data(asoc, chunk, tsn);
2424 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2427 /* We are going to ABORT, so we might as well stop
2428 * processing the rest of the chunks in the packet.
2430 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
2431 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
2432 SCTP_U32(SCTP_ERROR_NO_DATA));
2433 SCTP_INC_STATS(SctpAborteds);
2434 SCTP_DEC_STATS(SctpCurrEstab);
2435 return SCTP_DISPOSITION_CONSUME;
2438 /* If definately accepting the DATA chunk, record its TSN, otherwise
2439 * wait for renege processing.
2441 if (SCTP_CMD_CHUNK_ULP == deliver)
2442 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
2444 /* Note: Some chunks may get overcounted (if we drop) or overcounted
2445 * if we renege and the chunk arrives again.
2447 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
2448 SCTP_INC_STATS(SctpInUnorderChunks);
2450 SCTP_INC_STATS(SctpInOrderChunks);
2452 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
2454 * If an endpoint receive a DATA chunk with an invalid stream
2455 * identifier, it shall acknowledge the reception of the DATA chunk
2456 * following the normal procedure, immediately send an ERROR chunk
2457 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
2458 * and discard the DATA chunk.
2460 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
2461 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
2463 sizeof(data_hdr->stream));
2465 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2467 goto discard_noforce;
2470 /* Send the data up to the user. Note: Schedule the
2471 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
2472 * chunk needs the updated rwnd.
2474 sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
2476 if (asoc->autoclose) {
2477 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2478 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2481 /* If this is the last chunk in a packet, we need to count it
2482 * toward sack generation. Note that we need to SACK every
2483 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2484 * THEM. We elect to NOT generate SACK's if the chunk fails
2485 * the verification tag test.
2487 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2489 * The SCTP endpoint MUST always acknowledge the reception of
2490 * each valid DATA chunk.
2492 * The guidelines on delayed acknowledgement algorithm
2493 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2494 * Specifically, an acknowledgement SHOULD be generated for at
2495 * least every second packet (not every second DATA chunk)
2496 * received, and SHOULD be generated within 200 ms of the
2497 * arrival of any unacknowledged DATA chunk. In some
2498 * situations it may be beneficial for an SCTP transmitter to
2499 * be more conservative than the algorithms detailed in this
2500 * document allow. However, an SCTP transmitter MUST NOT be
2501 * more aggressive than the following algorithms allow.
2503 if (chunk->end_of_packet) {
2504 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2506 /* Start the SACK timer. */
2507 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2508 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2511 return SCTP_DISPOSITION_CONSUME;
2514 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2516 * When a packet arrives with duplicate DATA chunk(s) and with
2517 * no new DATA chunk(s), the endpoint MUST immediately send a
2518 * SACK with no delay. If a packet arrives with duplicate
2519 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2520 * MAY immediately send a SACK. Normally receipt of duplicate
2521 * DATA chunks will occur when the original SACK chunk was lost
2522 * and the peer's RTO has expired. The duplicate TSN number(s)
2523 * SHOULD be reported in the SACK as duplicate.
2525 /* In our case, we split the MAY SACK advice up whether or not
2526 * the last chunk is a duplicate.'
2528 if (chunk->end_of_packet)
2529 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2530 return SCTP_DISPOSITION_DISCARD;
2533 if (chunk->end_of_packet) {
2534 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2536 /* Start the SACK timer. */
2537 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2538 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
2540 return SCTP_DISPOSITION_DISCARD;
2544 * sctp_sf_eat_data_fast_4_4
2547 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2548 * DATA chunks without delay.
2550 * Verification Tag: 8.5 Verification Tag [Normal verification]
2552 * (endpoint, asoc, chunk)
2555 * (asoc, reply_msg, msg_up, timers, counters)
2557 * The return value is the disposition of the chunk.
2559 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2560 const struct sctp_association *asoc,
2561 const sctp_subtype_t type,
2563 sctp_cmd_seq_t *commands)
2565 struct sctp_chunk *chunk = arg;
2566 sctp_datahdr_t *data_hdr;
2567 struct sctp_chunk *err;
2572 /* RFC 2960 8.5 Verification Tag
2574 * When receiving an SCTP packet, the endpoint MUST ensure
2575 * that the value in the Verification Tag field of the
2576 * received SCTP packet matches its own Tag.
2578 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
2579 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2581 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2584 data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *) chunk->skb->data;
2585 skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
2587 tsn = ntohl(data_hdr->tsn);
2589 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn);
2591 /* ASSERT: Now skb->data is really the user data. */
2593 /* Process ECN based congestion.
2595 * Since the chunk structure is reused for all chunks within
2596 * a packet, we use ecn_ce_done to track if we've already
2597 * done CE processing for this packet.
2599 * We need to do ECN processing even if we plan to discard the
2602 if (!chunk->ecn_ce_done) {
2604 chunk->ecn_ce_done = 1;
2606 af = sctp_get_af_specific(
2607 ipver2af(chunk->skb->nh.iph->version));
2609 if (af && af->is_ce(chunk->skb) && asoc->peer.ecn_capable) {
2610 /* Do real work as sideffect. */
2611 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
2616 tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
2618 /* The TSN is too high--silently discard the chunk and
2619 * count on it getting retransmitted later.
2622 } else if (tmp > 0) {
2623 /* This is a duplicate. Record it. */
2624 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
2628 /* This is a new TSN. */
2630 datalen = ntohs(chunk->chunk_hdr->length);
2631 datalen -= sizeof(sctp_data_chunk_t);
2634 * Section 3.3.10.9 No User Data (9)
2638 * No User Data: This error cause is returned to the originator of a
2639 * DATA chunk if a received DATA chunk has no user data.
2641 if (unlikely(0 == datalen)) {
2642 err = sctp_make_abort_no_data(asoc, chunk, tsn);
2644 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2647 /* We are going to ABORT, so we might as well stop
2648 * processing the rest of the chunks in the packet.
2650 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
2651 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
2652 SCTP_U32(SCTP_ERROR_NO_DATA));
2653 SCTP_INC_STATS(SctpAborteds);
2654 SCTP_DEC_STATS(SctpCurrEstab);
2655 return SCTP_DISPOSITION_CONSUME;
2658 /* We are accepting this DATA chunk. */
2660 /* Record the fact that we have received this TSN. */
2661 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
2663 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
2664 SCTP_INC_STATS(SctpInUnorderChunks);
2666 SCTP_INC_STATS(SctpInOrderChunks);
2668 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
2670 * If an endpoint receive a DATA chunk with an invalid stream
2671 * identifier, it shall acknowledge the reception of the DATA chunk
2672 * following the normal procedure, immediately send an ERROR chunk
2673 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
2674 * and discard the DATA chunk.
2676 if (ntohs(data_hdr->stream) >= asoc->c.sinit_max_instreams) {
2677 err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
2679 sizeof(data_hdr->stream));
2681 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
2686 /* Go a head and force a SACK, since we are shutting down. */
2688 /* Implementor's Guide.
2690 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2691 * respond to each received packet containing one or more DATA chunk(s)
2692 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2694 if (chunk->end_of_packet) {
2695 /* We must delay the chunk creation since the cumulative
2696 * TSN has not been updated yet.
2698 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2699 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2700 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2701 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2703 return SCTP_DISPOSITION_CONSUME;
2707 * Section: 6.2 Processing a Received SACK
2708 * D) Any time a SACK arrives, the endpoint performs the following:
2710 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2711 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2712 * increasing, a SACK whose Cumulative TSN Ack is less than the
2713 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2715 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2716 * of bytes still outstanding after processing the Cumulative TSN Ack
2717 * and the Gap Ack Blocks.
2719 * iii) If the SACK is missing a TSN that was previously
2720 * acknowledged via a Gap Ack Block (e.g., the data receiver
2721 * reneged on the data), then mark the corresponding DATA chunk
2722 * as available for retransmit: Mark it as missing for fast
2723 * retransmit as described in Section 7.2.4 and if no retransmit
2724 * timer is running for the destination address to which the DATA
2725 * chunk was originally transmitted, then T3-rtx is started for
2726 * that destination address.
2728 * Verification Tag: 8.5 Verification Tag [Normal verification]
2731 * (endpoint, asoc, chunk)
2734 * (asoc, reply_msg, msg_up, timers, counters)
2736 * The return value is the disposition of the chunk.
2738 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2739 const struct sctp_association *asoc,
2740 const sctp_subtype_t type,
2742 sctp_cmd_seq_t *commands)
2744 struct sctp_chunk *chunk = arg;
2745 sctp_sackhdr_t *sackh;
2748 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
2749 * that the value in the Verification Tag field of the
2750 * received SCTP packet matches its own Tag. ...
2752 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
2753 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2755 /* Pull the SACK chunk from the data buffer */
2756 sackh = sctp_sm_pull_sack(chunk);
2757 /* Was this a bogus SACK? */
2759 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2760 chunk->subh.sack_hdr = sackh;
2761 ctsn = ntohl(sackh->cum_tsn_ack);
2763 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2764 * Ack Point, then drop the SACK. Since Cumulative TSN
2765 * Ack is monotonically increasing, a SACK whose
2766 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2767 * Point indicates an out-of-order SACK.
2769 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2770 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2771 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2772 return SCTP_DISPOSITION_DISCARD;
2775 /* Return this SACK for further processing. */
2776 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2778 /* Note: We do the rest of the work on the PROCESS_SACK
2781 return SCTP_DISPOSITION_CONSUME;
2785 * Generate an ABORT in response to a packet.
2787 * Section: 8.4 Handle "Out of the blue" Packets
2789 * 8) The receiver should respond to the sender of the OOTB packet
2790 * with an ABORT. When sending the ABORT, the receiver of the
2791 * OOTB packet MUST fill in the Verification Tag field of the
2792 * outbound packet with the value found in the Verification Tag
2793 * field of the OOTB packet and set the T-bit in the Chunk Flags
2794 * to indicate that no TCB was found. After sending this ABORT,
2795 * the receiver of the OOTB packet shall discard the OOTB packet
2796 * and take no further action.
2800 * The return value is the disposition of the chunk.
2802 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2803 const struct sctp_association *asoc,
2804 const sctp_subtype_t type,
2806 sctp_cmd_seq_t *commands)
2808 struct sctp_packet *packet = NULL;
2809 struct sctp_chunk *chunk = arg;
2810 struct sctp_chunk *abort;
2812 packet = sctp_ootb_pkt_new(asoc, chunk);
2815 /* Make an ABORT. The T bit will be set if the asoc
2818 abort = sctp_make_abort(asoc, chunk, 0);
2820 sctp_ootb_pkt_free(packet);
2821 return SCTP_DISPOSITION_NOMEM;
2824 /* Set the skb to the belonging sock for accounting. */
2825 abort->skb->sk = ep->base.sk;
2827 sctp_packet_append_chunk(packet, abort);
2829 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2830 SCTP_PACKET(packet));
2832 SCTP_INC_STATS(SctpOutCtrlChunks);
2834 return SCTP_DISPOSITION_CONSUME;
2837 return SCTP_DISPOSITION_NOMEM;
2841 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2842 * event as ULP notification for each cause included in the chunk.
2844 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2846 * The return value is the disposition of the chunk.
2848 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2849 const struct sctp_association *asoc,
2850 const sctp_subtype_t type,
2852 sctp_cmd_seq_t *commands)
2854 struct sctp_chunk *chunk = arg;
2855 struct sctp_ulpevent *ev;
2857 while (chunk->chunk_end > chunk->skb->data) {
2858 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
2863 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
2864 SCTP_ULPEVENT(ev))) {
2865 sctp_ulpevent_free(ev);
2869 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
2872 return SCTP_DISPOSITION_CONSUME;
2875 return SCTP_DISPOSITION_NOMEM;
2879 * Process an inbound SHUTDOWN ACK.
2882 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2883 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
2884 * peer, and remove all record of the association.
2886 * The return value is the disposition.
2888 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
2889 const struct sctp_association *asoc,
2890 const sctp_subtype_t type,
2892 sctp_cmd_seq_t *commands)
2894 struct sctp_chunk *chunk = arg;
2895 struct sctp_chunk *reply;
2896 struct sctp_ulpevent *ev;
2898 /* 10.2 H) SHUTDOWN COMPLETE notification
2900 * When SCTP completes the shutdown procedures (section 9.2) this
2901 * notification is passed to the upper layer.
2903 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
2904 0, 0, 0, GFP_ATOMIC);
2908 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2910 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
2911 * stop the T2-shutdown timer,
2913 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2914 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2916 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2917 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2919 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
2920 reply = sctp_make_shutdown_complete(asoc, chunk);
2924 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2925 SCTP_STATE(SCTP_STATE_CLOSED));
2926 SCTP_INC_STATS(SctpShutdowns);
2927 SCTP_DEC_STATS(SctpCurrEstab);
2928 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2930 /* ...and remove all record of the association. */
2931 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
2932 return SCTP_DISPOSITION_DELETE_TCB;
2935 return SCTP_DISPOSITION_NOMEM;
2939 * RFC 2960, 8.4 - Handle "Out of the blue" Packets
2940 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2941 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2942 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
2943 * packet must fill in the Verification Tag field of the outbound
2944 * packet with the Verification Tag received in the SHUTDOWN ACK and
2945 * set the T-bit in the Chunk Flags to indicate that no TCB was
2948 * 8) The receiver should respond to the sender of the OOTB packet with
2949 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2950 * MUST fill in the Verification Tag field of the outbound packet
2951 * with the value found in the Verification Tag field of the OOTB
2952 * packet and set the T-bit in the Chunk Flags to indicate that no
2953 * TCB was found. After sending this ABORT, the receiver of the OOTB
2954 * packet shall discard the OOTB packet and take no further action.
2956 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
2957 const struct sctp_association *asoc,
2958 const sctp_subtype_t type,
2960 sctp_cmd_seq_t *commands)
2962 struct sctp_chunk *chunk = arg;
2963 struct sk_buff *skb = chunk->skb;
2964 sctp_chunkhdr_t *ch;
2966 int ootb_shut_ack = 0;
2968 SCTP_INC_STATS(SctpOutOfBlues);
2970 ch = (sctp_chunkhdr_t *) chunk->chunk_hdr;
2972 ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length));
2974 if (SCTP_CID_SHUTDOWN_ACK == ch->type)
2977 ch = (sctp_chunkhdr_t *) ch_end;
2978 } while (ch_end < skb->tail);
2981 sctp_sf_shut_8_4_5(ep, asoc, type, arg, commands);
2983 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
2985 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2989 * Handle an "Out of the blue" SHUTDOWN ACK.
2992 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
2993 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
2994 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB packet
2995 * must fill in the Verification Tag field of the outbound packet with
2996 * the Verification Tag received in the SHUTDOWN ACK and set the
2997 * T-bit in the Chunk Flags to indicate that no TCB was found.
3000 * (endpoint, asoc, type, arg, commands)
3003 * (sctp_disposition_t)
3005 * The return value is the disposition of the chunk.
3007 sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
3008 const struct sctp_association *asoc,
3009 const sctp_subtype_t type,
3011 sctp_cmd_seq_t *commands)
3013 struct sctp_packet *packet = NULL;
3014 struct sctp_chunk *chunk = arg;
3015 struct sctp_chunk *shut;
3017 packet = sctp_ootb_pkt_new(asoc, chunk);
3020 /* Make an SHUTDOWN_COMPLETE.
3021 * The T bit will be set if the asoc is NULL.
3023 shut = sctp_make_shutdown_complete(asoc, chunk);
3025 sctp_ootb_pkt_free(packet);
3026 return SCTP_DISPOSITION_NOMEM;
3029 /* Set the skb to the belonging sock for accounting. */
3030 shut->skb->sk = ep->base.sk;
3032 sctp_packet_append_chunk(packet, shut);
3034 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
3035 SCTP_PACKET(packet));
3037 SCTP_INC_STATS(SctpOutCtrlChunks);
3039 return SCTP_DISPOSITION_CONSUME;
3042 return SCTP_DISPOSITION_NOMEM;
3046 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3048 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3049 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3050 * procedures in section 8.4 SHOULD be followed, in other words it
3051 * should be treated as an Out Of The Blue packet.
3052 * [This means that we do NOT check the Verification Tag on these
3056 sctp_disposition_t sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint *ep,
3057 const struct sctp_association *asoc,
3058 const sctp_subtype_t type,
3060 sctp_cmd_seq_t *commands)
3062 /* Although we do have an association in this case, it corresponds
3063 * to a restarted association. So the packet is treated as an OOTB
3064 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3065 * called with a NULL association.
3067 return sctp_sf_shut_8_4_5(ep, NULL, type, arg, commands);
3070 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3071 sctp_disposition_t sctp_sf_do_asconf(const struct sctp_endpoint *ep,
3072 const struct sctp_association *asoc,
3073 const sctp_subtype_t type, void *arg,
3074 sctp_cmd_seq_t *commands)
3076 struct sctp_chunk *chunk = arg;
3077 struct sctp_chunk *asconf_ack = NULL;
3078 sctp_addiphdr_t *hdr;
3081 hdr = (sctp_addiphdr_t *)chunk->skb->data;
3082 serial = ntohl(hdr->serial);
3084 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3085 * the endpoint stored in a new association variable
3086 * 'Peer-Serial-Number'.
3088 if (serial == asoc->peer.addip_serial + 1) {
3089 /* ADDIP 4.2 C2) If the value found in the serial number is
3090 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3093 asconf_ack = sctp_process_asconf((struct sctp_association *)
3096 return SCTP_DISPOSITION_NOMEM;
3097 } else if (serial == asoc->peer.addip_serial) {
3098 /* ADDIP 4.2 C3) If the value found in the serial number is
3099 * equal to the value stored in the 'Peer-Serial-Number'
3100 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3101 * to save the last ASCONF-ACK for some predetermined period of * time and instead of re-processing the ASCONF (with the same
3102 * serial number) it may just re-transmit the ASCONF-ACK.
3104 if (asoc->addip_last_asconf_ack)
3105 asconf_ack = asoc->addip_last_asconf_ack;
3107 return SCTP_DISPOSITION_DISCARD;
3109 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3110 * it must be either a stale packet or from an attacker.
3112 return SCTP_DISPOSITION_DISCARD;
3115 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3116 * back to the source address contained in the IP header of the ASCONF
3117 * being responded to.
3119 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
3121 return SCTP_DISPOSITION_CONSUME;
3125 * ADDIP Section 4.3 General rules for address manipulation
3126 * When building TLV parameters for the ASCONF Chunk that will add or
3127 * delete IP addresses the D0 to D13 rules should be applied:
3129 sctp_disposition_t sctp_sf_do_asconf_ack(const struct sctp_endpoint *ep,
3130 const struct sctp_association *asoc,
3131 const sctp_subtype_t type, void *arg,
3132 sctp_cmd_seq_t *commands)
3134 struct sctp_chunk *asconf_ack = arg;
3135 struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
3136 struct sctp_chunk *abort;
3137 sctp_addiphdr_t *addip_hdr;
3138 __u32 sent_serial, rcvd_serial;
3140 addip_hdr = (sctp_addiphdr_t *)asconf_ack->skb->data;
3141 rcvd_serial = ntohl(addip_hdr->serial);
3144 addip_hdr = (sctp_addiphdr_t *)last_asconf->subh.addip_hdr;
3145 sent_serial = ntohl(addip_hdr->serial);
3147 sent_serial = asoc->addip_serial - 1;
3150 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3151 * equal to the next serial number to be used but no ASCONF chunk is
3152 * outstanding the endpoint MUST ABORT the association. Note that a
3153 * sequence number is greater than if it is no more than 2^^31-1
3154 * larger than the current sequence number (using serial arithmetic).
3156 if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
3157 !(asoc->addip_last_asconf)) {
3158 abort = sctp_make_abort(asoc, asconf_ack,
3159 sizeof(sctp_errhdr_t));
3161 sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, NULL, 0);
3162 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3165 /* We are going to ABORT, so we might as well stop
3166 * processing the rest of the chunks in the packet.
3168 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3169 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3170 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3171 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3172 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3173 SCTP_INC_STATS(SctpAborteds);
3174 SCTP_DEC_STATS(SctpCurrEstab);
3175 return SCTP_DISPOSITION_ABORT;
3178 if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
3179 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3180 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
3182 if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3184 return SCTP_DISPOSITION_CONSUME;
3186 abort = sctp_make_abort(asoc, asconf_ack,
3187 sizeof(sctp_errhdr_t));
3189 sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, NULL, 0);
3190 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3193 /* We are going to ABORT, so we might as well stop
3194 * processing the rest of the chunks in the packet.
3196 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET,SCTP_NULL());
3197 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3198 SCTP_U32(SCTP_ERROR_ASCONF_ACK));
3199 SCTP_INC_STATS(SctpAborteds);
3200 SCTP_DEC_STATS(SctpCurrEstab);
3201 return SCTP_DISPOSITION_ABORT;
3204 return SCTP_DISPOSITION_DISCARD;
3208 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3210 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3211 * its cumulative TSN point to the value carried in the FORWARD TSN
3212 * chunk, and then MUST further advance its cumulative TSN point locally
3214 * After the above processing, the data receiver MUST stop reporting any
3215 * missing TSNs earlier than or equal to the new cumulative TSN point.
3217 * Verification Tag: 8.5 Verification Tag [Normal verification]
3219 * The return value is the disposition of the chunk.
3221 sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
3222 const struct sctp_association *asoc,
3223 const sctp_subtype_t type,
3225 sctp_cmd_seq_t *commands)
3227 struct sctp_chunk *chunk = arg;
3228 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3232 /* RFC 2960 8.5 Verification Tag
3234 * When receiving an SCTP packet, the endpoint MUST ensure
3235 * that the value in the Verification Tag field of the
3236 * received SCTP packet matches its own Tag.
3238 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
3239 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3241 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3244 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3245 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3246 len = ntohs(chunk->chunk_hdr->length);
3247 len -= sizeof(struct sctp_chunkhdr);
3248 skb_pull(chunk->skb, len);
3250 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3251 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3253 /* The TSN is too high--silently discard the chunk and count on it
3254 * getting retransmitted later.
3256 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3257 goto discard_noforce;
3259 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3260 if (len > sizeof(struct sctp_fwdtsn_hdr))
3261 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3264 /* Count this as receiving DATA. */
3265 if (asoc->autoclose) {
3266 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3267 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
3270 /* FIXME: For now send a SACK, but DATA processing may
3273 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
3274 /* Start the SACK timer. */
3275 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3276 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
3278 return SCTP_DISPOSITION_CONSUME;
3281 return SCTP_DISPOSITION_DISCARD;
3284 sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
3285 const struct sctp_endpoint *ep,
3286 const struct sctp_association *asoc,
3287 const sctp_subtype_t type,
3289 sctp_cmd_seq_t *commands)
3291 struct sctp_chunk *chunk = arg;
3292 struct sctp_fwdtsn_hdr *fwdtsn_hdr;
3296 /* RFC 2960 8.5 Verification Tag
3298 * When receiving an SCTP packet, the endpoint MUST ensure
3299 * that the value in the Verification Tag field of the
3300 * received SCTP packet matches its own Tag.
3302 if (ntohl(chunk->sctp_hdr->vtag) != asoc->c.my_vtag) {
3303 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
3305 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3308 fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
3309 chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
3310 len = ntohs(chunk->chunk_hdr->length);
3311 len -= sizeof(struct sctp_chunkhdr);
3312 skb_pull(chunk->skb, len);
3314 tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
3315 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__, tsn);
3317 /* The TSN is too high--silently discard the chunk and count on it
3318 * getting retransmitted later.
3320 if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
3323 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
3324 if (len > sizeof(struct sctp_fwdtsn_hdr))
3325 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
3328 /* Go a head and force a SACK, since we are shutting down. */
3330 /* Implementor's Guide.
3332 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3333 * respond to each received packet containing one or more DATA chunk(s)
3334 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3336 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
3337 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
3338 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
3339 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3341 return SCTP_DISPOSITION_CONSUME;
3345 * Process an unknown chunk.
3347 * Section: 3.2. Also, 2.1 in the implementor's guide.
3349 * Chunk Types are encoded such that the highest-order two bits specify
3350 * the action that must be taken if the processing endpoint does not
3351 * recognize the Chunk Type.
3353 * 00 - Stop processing this SCTP packet and discard it, do not process
3354 * any further chunks within it.
3356 * 01 - Stop processing this SCTP packet and discard it, do not process
3357 * any further chunks within it, and report the unrecognized
3358 * chunk in an 'Unrecognized Chunk Type'.
3360 * 10 - Skip this chunk and continue processing.
3362 * 11 - Skip this chunk and continue processing, but report in an ERROR
3363 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3365 * The return value is the disposition of the chunk.
3367 sctp_disposition_t sctp_sf_unk_chunk(const struct sctp_endpoint *ep,
3368 const struct sctp_association *asoc,
3369 const sctp_subtype_t type,
3371 sctp_cmd_seq_t *commands)
3373 struct sctp_chunk *unk_chunk = arg;
3374 struct sctp_chunk *err_chunk;
3375 sctp_chunkhdr_t *hdr;
3377 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type.chunk);
3379 /* 8.5 When receiving an SCTP packet, the endpoint MUST ensure
3380 * that the value in the Verification Tag field of the
3381 * received SCTP packet matches its own Tag. If the received
3382 * Verification Tag value does not match the receiver's own
3383 * tag value, the receiver shall silently discard the packet.
3385 if (ntohl(unk_chunk->sctp_hdr->vtag) != asoc->c.my_vtag)
3386 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3388 switch (type.chunk & SCTP_CID_ACTION_MASK) {
3389 case SCTP_CID_ACTION_DISCARD:
3390 /* Discard the packet. */
3391 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3393 case SCTP_CID_ACTION_DISCARD_ERR:
3394 /* Discard the packet. */
3395 sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3397 /* Generate an ERROR chunk as response. */
3398 hdr = unk_chunk->chunk_hdr;
3399 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3400 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3401 WORD_ROUND(ntohs(hdr->length)));
3403 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3404 SCTP_CHUNK(err_chunk));
3406 return SCTP_DISPOSITION_CONSUME;
3408 case SCTP_CID_ACTION_SKIP:
3409 /* Skip the chunk. */
3410 return SCTP_DISPOSITION_DISCARD;
3412 case SCTP_CID_ACTION_SKIP_ERR:
3413 /* Generate an ERROR chunk as response. */
3414 hdr = unk_chunk->chunk_hdr;
3415 err_chunk = sctp_make_op_error(asoc, unk_chunk,
3416 SCTP_ERROR_UNKNOWN_CHUNK, hdr,
3417 WORD_ROUND(ntohs(hdr->length)));
3419 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
3420 SCTP_CHUNK(err_chunk));
3422 /* Skip the chunk. */
3423 return SCTP_DISPOSITION_CONSUME;
3429 return SCTP_DISPOSITION_DISCARD;
3433 * Discard the chunk.
3435 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3436 * [Too numerous to mention...]
3437 * Verification Tag: No verification needed.
3439 * (endpoint, asoc, chunk)
3442 * (asoc, reply_msg, msg_up, timers, counters)
3444 * The return value is the disposition of the chunk.
3446 sctp_disposition_t sctp_sf_discard_chunk(const struct sctp_endpoint *ep,
3447 const struct sctp_association *asoc,
3448 const sctp_subtype_t type,
3450 sctp_cmd_seq_t *commands)
3452 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type.chunk);
3453 return SCTP_DISPOSITION_DISCARD;
3457 * Discard the whole packet.
3461 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3462 * silently discard the OOTB packet and take no further action.
3465 * Verification Tag: No verification necessary
3468 * (endpoint, asoc, chunk)
3471 * (asoc, reply_msg, msg_up, timers, counters)
3473 * The return value is the disposition of the chunk.
3475 sctp_disposition_t sctp_sf_pdiscard(const struct sctp_endpoint *ep,
3476 const struct sctp_association *asoc,
3477 const sctp_subtype_t type,
3479 sctp_cmd_seq_t *commands)
3481 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
3483 return SCTP_DISPOSITION_CONSUME;
3488 * The other end is violating protocol.
3490 * Section: Not specified
3491 * Verification Tag: Not specified
3493 * (endpoint, asoc, chunk)
3496 * (asoc, reply_msg, msg_up, timers, counters)
3498 * We simply tag the chunk as a violation. The state machine will log
3499 * the violation and continue.
3501 sctp_disposition_t sctp_sf_violation(const struct sctp_endpoint *ep,
3502 const struct sctp_association *asoc,
3503 const sctp_subtype_t type,
3505 sctp_cmd_seq_t *commands)
3507 return SCTP_DISPOSITION_VIOLATION;
3510 /***************************************************************************
3511 * These are the state functions for handling primitive (Section 10) events.
3512 ***************************************************************************/
3514 * sctp_sf_do_prm_asoc
3516 * Section: 10.1 ULP-to-SCTP
3519 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3520 * outbound stream count)
3521 * -> association id [,destination transport addr list] [,outbound stream
3524 * This primitive allows the upper layer to initiate an association to a
3525 * specific peer endpoint.
3527 * The peer endpoint shall be specified by one of the transport addresses
3528 * which defines the endpoint (see Section 1.4). If the local SCTP
3529 * instance has not been initialized, the ASSOCIATE is considered an
3531 * [This is not relevant for the kernel implementation since we do all
3532 * initialization at boot time. It we hadn't initialized we wouldn't
3533 * get anywhere near this code.]
3535 * An association id, which is a local handle to the SCTP association,
3536 * will be returned on successful establishment of the association. If
3537 * SCTP is not able to open an SCTP association with the peer endpoint,
3538 * an error is returned.
3539 * [In the kernel implementation, the struct sctp_association needs to
3540 * be created BEFORE causing this primitive to run.]
3542 * Other association parameters may be returned, including the
3543 * complete destination transport addresses of the peer as well as the
3544 * outbound stream count of the local endpoint. One of the transport
3545 * address from the returned destination addresses will be selected by
3546 * the local endpoint as default primary path for sending SCTP packets
3547 * to this peer. The returned "destination transport addr list" can
3548 * be used by the ULP to change the default primary path or to force
3549 * sending a packet to a specific transport address. [All of this
3550 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3553 * Mandatory attributes:
3555 * o local SCTP instance name - obtained from the INITIALIZE operation.
3556 * [This is the argument asoc.]
3557 * o destination transport addr - specified as one of the transport
3558 * addresses of the peer endpoint with which the association is to be
3560 * [This is asoc->peer.active_path.]
3561 * o outbound stream count - the number of outbound streams the ULP
3562 * would like to open towards this peer endpoint.
3563 * [BUG: This is not currently implemented.]
3564 * Optional attributes:
3568 * The return value is a disposition.
3570 sctp_disposition_t sctp_sf_do_prm_asoc(const struct sctp_endpoint *ep,
3571 const struct sctp_association *asoc,
3572 const sctp_subtype_t type,
3574 sctp_cmd_seq_t *commands)
3576 struct sctp_chunk *repl;
3578 /* The comment below says that we enter COOKIE-WAIT AFTER
3579 * sending the INIT, but that doesn't actually work in our
3582 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3583 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
3585 /* RFC 2960 5.1 Normal Establishment of an Association
3587 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3588 * must provide its Verification Tag (Tag_A) in the Initiate
3589 * Tag field. Tag_A SHOULD be a random number in the range of
3590 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3593 repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
3597 /* Cast away the const modifier, as we want to just
3598 * rerun it through as a sideffect.
3600 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC,
3601 SCTP_ASOC((struct sctp_association *) asoc));
3603 /* After sending the INIT, "A" starts the T1-init timer and
3604 * enters the COOKIE-WAIT state.
3606 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3607 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3608 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
3609 return SCTP_DISPOSITION_CONSUME;
3612 return SCTP_DISPOSITION_NOMEM;
3616 * Process the SEND primitive.
3618 * Section: 10.1 ULP-to-SCTP
3621 * Format: SEND(association id, buffer address, byte count [,context]
3622 * [,stream id] [,life time] [,destination transport address]
3623 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3626 * This is the main method to send user data via SCTP.
3628 * Mandatory attributes:
3630 * o association id - local handle to the SCTP association
3632 * o buffer address - the location where the user message to be
3633 * transmitted is stored;
3635 * o byte count - The size of the user data in number of bytes;
3637 * Optional attributes:
3639 * o context - an optional 32 bit integer that will be carried in the
3640 * sending failure notification to the ULP if the transportation of
3641 * this User Message fails.
3643 * o stream id - to indicate which stream to send the data on. If not
3644 * specified, stream 0 will be used.
3646 * o life time - specifies the life time of the user data. The user data
3647 * will not be sent by SCTP after the life time expires. This
3648 * parameter can be used to avoid efforts to transmit stale
3649 * user messages. SCTP notifies the ULP if the data cannot be
3650 * initiated to transport (i.e. sent to the destination via SCTP's
3651 * send primitive) within the life time variable. However, the
3652 * user data will be transmitted if SCTP has attempted to transmit a
3653 * chunk before the life time expired.
3655 * o destination transport address - specified as one of the destination
3656 * transport addresses of the peer endpoint to which this packet
3657 * should be sent. Whenever possible, SCTP should use this destination
3658 * transport address for sending the packets, instead of the current
3661 * o unorder flag - this flag, if present, indicates that the user
3662 * would like the data delivered in an unordered fashion to the peer
3663 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3666 * o no-bundle flag - instructs SCTP not to bundle this user data with
3667 * other outbound DATA chunks. SCTP MAY still bundle even when
3668 * this flag is present, when faced with network congestion.
3670 * o payload protocol-id - A 32 bit unsigned integer that is to be
3671 * passed to the peer indicating the type of payload protocol data
3672 * being transmitted. This value is passed as opaque data by SCTP.
3674 * The return value is the disposition.
3676 sctp_disposition_t sctp_sf_do_prm_send(const struct sctp_endpoint *ep,
3677 const struct sctp_association *asoc,
3678 const sctp_subtype_t type,
3680 sctp_cmd_seq_t *commands)
3682 struct sctp_chunk *chunk = arg;
3684 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
3685 return SCTP_DISPOSITION_CONSUME;
3689 * Process the SHUTDOWN primitive.
3694 * Format: SHUTDOWN(association id)
3697 * Gracefully closes an association. Any locally queued user data
3698 * will be delivered to the peer. The association will be terminated only
3699 * after the peer acknowledges all the SCTP packets sent. A success code
3700 * will be returned on successful termination of the association. If
3701 * attempting to terminate the association results in a failure, an error
3702 * code shall be returned.
3704 * Mandatory attributes:
3706 * o association id - local handle to the SCTP association
3708 * Optional attributes:
3712 * The return value is the disposition.
3714 sctp_disposition_t sctp_sf_do_9_2_prm_shutdown(
3715 const struct sctp_endpoint *ep,
3716 const struct sctp_association *asoc,
3717 const sctp_subtype_t type,
3719 sctp_cmd_seq_t *commands)
3723 /* From 9.2 Shutdown of an Association
3724 * Upon receipt of the SHUTDOWN primitive from its upper
3725 * layer, the endpoint enters SHUTDOWN-PENDING state and
3726 * remains there until all outstanding data has been
3727 * acknowledged by its peer. The endpoint accepts no new data
3728 * from its upper layer, but retransmits data to the far end
3729 * if necessary to fill gaps.
3731 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3732 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
3734 /* sctpimpguide-05 Section 2.12.2
3735 * The sender of the SHUTDOWN MAY also start an overall guard timer
3736 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
3738 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
3739 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3741 disposition = SCTP_DISPOSITION_CONSUME;
3742 if (sctp_outq_is_empty(&asoc->outqueue)) {
3743 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
3750 * Process the ABORT primitive.
3755 * Format: Abort(association id [, cause code])
3758 * Ungracefully closes an association. Any locally queued user data
3759 * will be discarded and an ABORT chunk is sent to the peer. A success code
3760 * will be returned on successful abortion of the association. If
3761 * attempting to abort the association results in a failure, an error
3762 * code shall be returned.
3764 * Mandatory attributes:
3766 * o association id - local handle to the SCTP association
3768 * Optional attributes:
3770 * o cause code - reason of the abort to be passed to the peer
3774 * The return value is the disposition.
3776 sctp_disposition_t sctp_sf_do_9_1_prm_abort(
3777 const struct sctp_endpoint *ep,
3778 const struct sctp_association *asoc,
3779 const sctp_subtype_t type,
3781 sctp_cmd_seq_t *commands)
3783 /* From 9.1 Abort of an Association
3784 * Upon receipt of the ABORT primitive from its upper
3785 * layer, the endpoint enters CLOSED state and
3786 * discard all outstanding data has been
3787 * acknowledged by its peer. The endpoint accepts no new data
3788 * from its upper layer, but retransmits data to the far end
3789 * if necessary to fill gaps.
3791 struct msghdr *msg = arg;
3792 struct sctp_chunk *abort;
3793 sctp_disposition_t retval;
3795 retval = SCTP_DISPOSITION_CONSUME;
3797 /* Generate ABORT chunk to send the peer. */
3798 abort = sctp_make_abort_user(asoc, NULL, msg);
3800 retval = SCTP_DISPOSITION_NOMEM;
3802 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3804 /* Even if we can't send the ABORT due to low memory delete the
3805 * TCB. This is a departure from our typical NOMEM handling.
3808 /* Delete the established association. */
3809 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
3810 SCTP_U32(SCTP_ERROR_USER_ABORT));
3812 SCTP_INC_STATS(SctpAborteds);
3813 SCTP_DEC_STATS(SctpCurrEstab);
3818 /* We tried an illegal operation on an association which is closed. */
3819 sctp_disposition_t sctp_sf_error_closed(const struct sctp_endpoint *ep,
3820 const struct sctp_association *asoc,
3821 const sctp_subtype_t type,
3823 sctp_cmd_seq_t *commands)
3825 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
3826 return SCTP_DISPOSITION_CONSUME;
3829 /* We tried an illegal operation on an association which is shutting
3832 sctp_disposition_t sctp_sf_error_shutdown(const struct sctp_endpoint *ep,
3833 const struct sctp_association *asoc,
3834 const sctp_subtype_t type,
3836 sctp_cmd_seq_t *commands)
3838 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
3839 SCTP_ERROR(-ESHUTDOWN));
3840 return SCTP_DISPOSITION_CONSUME;
3844 * sctp_cookie_wait_prm_shutdown
3846 * Section: 4 Note: 2
3851 * The RFC does not explicitly address this issue, but is the route through the
3852 * state table when someone issues a shutdown while in COOKIE_WAIT state.
3857 sctp_disposition_t sctp_sf_cookie_wait_prm_shutdown(
3858 const struct sctp_endpoint *ep,
3859 const struct sctp_association *asoc,
3860 const sctp_subtype_t type,
3862 sctp_cmd_seq_t *commands)
3864 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3865 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3867 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3868 SCTP_STATE(SCTP_STATE_CLOSED));
3870 SCTP_INC_STATS(SctpShutdowns);
3872 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3874 return SCTP_DISPOSITION_DELETE_TCB;
3878 * sctp_cookie_echoed_prm_shutdown
3880 * Section: 4 Note: 2
3885 * The RFC does not explcitly address this issue, but is the route through the
3886 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
3891 sctp_disposition_t sctp_sf_cookie_echoed_prm_shutdown(
3892 const struct sctp_endpoint *ep,
3893 const struct sctp_association *asoc,
3894 const sctp_subtype_t type,
3895 void *arg, sctp_cmd_seq_t *commands)
3897 /* There is a single T1 timer, so we should be able to use
3898 * common function with the COOKIE-WAIT state.
3900 return sctp_sf_cookie_wait_prm_shutdown(ep, asoc, type, arg, commands);
3904 * sctp_sf_cookie_wait_prm_abort
3906 * Section: 4 Note: 2
3911 * The RFC does not explicitly address this issue, but is the route through the
3912 * state table when someone issues an abort while in COOKIE_WAIT state.
3917 sctp_disposition_t sctp_sf_cookie_wait_prm_abort(
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 struct msghdr *msg = arg;
3925 struct sctp_chunk *abort;
3926 sctp_disposition_t retval;
3928 /* Stop T1-init timer */
3929 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3930 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
3931 retval = SCTP_DISPOSITION_CONSUME;
3933 /* Generate ABORT chunk to send the peer */
3934 abort = sctp_make_abort_user(asoc, NULL, msg);
3936 retval = SCTP_DISPOSITION_NOMEM;
3938 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
3940 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3941 SCTP_STATE(SCTP_STATE_CLOSED));
3943 SCTP_INC_STATS(SctpAborteds);
3945 /* Even if we can't send the ABORT due to low memory delete the
3946 * TCB. This is a departure from our typical NOMEM handling.
3949 /* Delete the established association. */
3950 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
3951 SCTP_U32(SCTP_ERROR_USER_ABORT));
3957 * sctp_sf_cookie_echoed_prm_abort
3959 * Section: 4 Note: 3
3964 * The RFC does not explcitly address this issue, but is the route through the
3965 * state table when someone issues an abort while in COOKIE_ECHOED state.
3970 sctp_disposition_t sctp_sf_cookie_echoed_prm_abort(
3971 const struct sctp_endpoint *ep,
3972 const struct sctp_association *asoc,
3973 const sctp_subtype_t type,
3975 sctp_cmd_seq_t *commands)
3977 /* There is a single T1 timer, so we should be able to use
3978 * common function with the COOKIE-WAIT state.
3980 return sctp_sf_cookie_wait_prm_abort(ep, asoc, type, arg, commands);
3984 * sctp_sf_shutdown_pending_prm_abort
3989 * The RFC does not explicitly address this issue, but is the route through the
3990 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
3995 sctp_disposition_t sctp_sf_shutdown_pending_prm_abort(
3996 const struct sctp_endpoint *ep,
3997 const struct sctp_association *asoc,
3998 const sctp_subtype_t type,
4000 sctp_cmd_seq_t *commands)
4002 /* Stop the T5-shutdown guard timer. */
4003 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4004 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4006 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4010 * sctp_sf_shutdown_sent_prm_abort
4015 * The RFC does not explicitly address this issue, but is the route through the
4016 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4021 sctp_disposition_t sctp_sf_shutdown_sent_prm_abort(
4022 const struct sctp_endpoint *ep,
4023 const struct sctp_association *asoc,
4024 const sctp_subtype_t type,
4026 sctp_cmd_seq_t *commands)
4028 /* Stop the T2-shutdown timer. */
4029 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4030 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4032 /* Stop the T5-shutdown guard timer. */
4033 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4034 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4036 return sctp_sf_do_9_1_prm_abort(ep, asoc, type, arg, commands);
4040 * sctp_sf_cookie_echoed_prm_abort
4045 * The RFC does not explcitly address this issue, but is the route through the
4046 * state table when someone issues an abort while in COOKIE_ECHOED state.
4051 sctp_disposition_t sctp_sf_shutdown_ack_sent_prm_abort(
4052 const struct sctp_endpoint *ep,
4053 const struct sctp_association *asoc,
4054 const sctp_subtype_t type,
4056 sctp_cmd_seq_t *commands)
4058 /* The same T2 timer, so we should be able to use
4059 * common function with the SHUTDOWN-SENT state.
4061 return sctp_sf_shutdown_sent_prm_abort(ep, asoc, type, arg, commands);
4065 * Process the REQUESTHEARTBEAT primitive
4068 * J) Request Heartbeat
4070 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4074 * Instructs the local endpoint to perform a HeartBeat on the specified
4075 * destination transport address of the given association. The returned
4076 * result should indicate whether the transmission of the HEARTBEAT
4077 * chunk to the destination address is successful.
4079 * Mandatory attributes:
4081 * o association id - local handle to the SCTP association
4083 * o destination transport address - the transport address of the
4084 * association on which a heartbeat should be issued.
4086 sctp_disposition_t sctp_sf_do_prm_requestheartbeat(
4087 const struct sctp_endpoint *ep,
4088 const struct sctp_association *asoc,
4089 const sctp_subtype_t type,
4091 sctp_cmd_seq_t *commands)
4093 return sctp_sf_heartbeat(ep, asoc, type, (struct sctp_transport *)arg,
4098 * ADDIP Section 4.1 ASCONF Chunk Procedures
4099 * When an endpoint has an ASCONF signaled change to be sent to the
4100 * remote endpoint it should do A1 to A9
4102 sctp_disposition_t sctp_sf_do_prm_asconf(const struct sctp_endpoint *ep,
4103 const struct sctp_association *asoc,
4104 const sctp_subtype_t type,
4106 sctp_cmd_seq_t *commands)
4108 struct sctp_chunk *chunk = arg;
4110 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4111 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4112 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4113 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
4114 return SCTP_DISPOSITION_CONSUME;
4118 * Ignore the primitive event
4120 * The return value is the disposition of the primitive.
4122 sctp_disposition_t sctp_sf_ignore_primitive(
4123 const struct sctp_endpoint *ep,
4124 const struct sctp_association *asoc,
4125 const sctp_subtype_t type,
4127 sctp_cmd_seq_t *commands)
4129 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type.primitive);
4130 return SCTP_DISPOSITION_DISCARD;
4133 /***************************************************************************
4134 * These are the state functions for the OTHER events.
4135 ***************************************************************************/
4138 * Start the shutdown negotiation.
4141 * Once all its outstanding data has been acknowledged, the endpoint
4142 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4143 * TSN Ack field the last sequential TSN it has received from the peer.
4144 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4145 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4146 * with the updated last sequential TSN received from its peer.
4148 * The return value is the disposition.
4150 sctp_disposition_t sctp_sf_do_9_2_start_shutdown(
4151 const struct sctp_endpoint *ep,
4152 const struct sctp_association *asoc,
4153 const sctp_subtype_t type,
4155 sctp_cmd_seq_t *commands)
4157 struct sctp_chunk *reply;
4159 /* Once all its outstanding data has been acknowledged, the
4160 * endpoint shall send a SHUTDOWN chunk to its peer including
4161 * in the Cumulative TSN Ack field the last sequential TSN it
4162 * has received from the peer.
4164 reply = sctp_make_shutdown(asoc, NULL);
4168 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4169 * T2-shutdown timer.
4171 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4173 /* It shall then start the T2-shutdown timer */
4174 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4175 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4177 if (asoc->autoclose)
4178 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4179 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4181 /* and enter the SHUTDOWN-SENT state. */
4182 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4183 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
4185 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4187 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4190 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4192 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4194 return SCTP_DISPOSITION_CONSUME;
4197 return SCTP_DISPOSITION_NOMEM;
4201 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4205 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4206 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4207 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4208 * endpoint must re-send the SHUTDOWN ACK.
4210 * The return value is the disposition.
4212 sctp_disposition_t sctp_sf_do_9_2_shutdown_ack(
4213 const struct sctp_endpoint *ep,
4214 const struct sctp_association *asoc,
4215 const sctp_subtype_t type,
4217 sctp_cmd_seq_t *commands)
4219 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
4220 struct sctp_chunk *reply;
4222 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4223 * shall send a SHUTDOWN ACK ...
4225 reply = sctp_make_shutdown_ack(asoc, chunk);
4229 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4230 * the T2-shutdown timer.
4232 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4234 /* and start/restart a T2-shutdown timer of its own, */
4235 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4236 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4238 if (asoc->autoclose)
4239 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4240 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
4242 /* Enter the SHUTDOWN-ACK-SENT state. */
4243 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4244 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
4246 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4248 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4251 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
4253 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4255 return SCTP_DISPOSITION_CONSUME;
4258 return SCTP_DISPOSITION_NOMEM;
4262 * Ignore the event defined as other
4264 * The return value is the disposition of the event.
4266 sctp_disposition_t sctp_sf_ignore_other(const struct sctp_endpoint *ep,
4267 const struct sctp_association *asoc,
4268 const sctp_subtype_t type,
4270 sctp_cmd_seq_t *commands)
4272 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type.other);
4273 return SCTP_DISPOSITION_DISCARD;
4276 /************************************************************
4277 * These are the state functions for handling timeout events.
4278 ************************************************************/
4283 * Section: 6.3.3 Handle T3-rtx Expiration
4285 * Whenever the retransmission timer T3-rtx expires for a destination
4286 * address, do the following:
4289 * The return value is the disposition of the chunk.
4291 sctp_disposition_t sctp_sf_do_6_3_3_rtx(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_transport *transport = arg;
4299 if (asoc->overall_error_count >= asoc->max_retrans) {
4300 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4301 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4302 SCTP_U32(SCTP_ERROR_NO_ERROR));
4303 SCTP_INC_STATS(SctpAborteds);
4304 SCTP_DEC_STATS(SctpCurrEstab);
4305 return SCTP_DISPOSITION_DELETE_TCB;
4308 /* E1) For the destination address for which the timer
4309 * expires, adjust its ssthresh with rules defined in Section
4310 * 7.2.3 and set the cwnd <- MTU.
4313 /* E2) For the destination address for which the timer
4314 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4315 * maximum value discussed in rule C7 above (RTO.max) may be
4316 * used to provide an upper bound to this doubling operation.
4319 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4320 * outstanding DATA chunks for the address for which the
4321 * T3-rtx has expired will fit into a single packet, subject
4322 * to the MTU constraint for the path corresponding to the
4323 * destination transport address to which the retransmission
4324 * is being sent (this may be different from the address for
4325 * which the timer expires [see Section 6.4]). Call this
4326 * value K. Bundle and retransmit those K DATA chunks in a
4327 * single packet to the destination endpoint.
4329 * Note: Any DATA chunks that were sent to the address for
4330 * which the T3-rtx timer expired but did not fit in one MTU
4331 * (rule E3 above), should be marked for retransmission and
4332 * sent as soon as cwnd allows (normally when a SACK arrives).
4335 /* NB: Rules E4 and F1 are implicit in R1. */
4336 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
4338 /* Do some failure management (Section 8.2). */
4339 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4341 return SCTP_DISPOSITION_CONSUME;
4345 * Generate delayed SACK on timeout
4347 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4349 * The guidelines on delayed acknowledgement algorithm specified in
4350 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4351 * acknowledgement SHOULD be generated for at least every second packet
4352 * (not every second DATA chunk) received, and SHOULD be generated
4353 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4354 * some situations it may be beneficial for an SCTP transmitter to be
4355 * more conservative than the algorithms detailed in this document
4356 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4357 * the following algorithms allow.
4359 sctp_disposition_t sctp_sf_do_6_2_sack(const struct sctp_endpoint *ep,
4360 const struct sctp_association *asoc,
4361 const sctp_subtype_t type,
4363 sctp_cmd_seq_t *commands)
4365 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
4366 return SCTP_DISPOSITION_CONSUME;
4370 * sctp_sf_t1_timer_expire
4372 * Section: 4 Note: 2
4377 * RFC 2960 Section 4 Notes
4378 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4379 * and re-start the T1-init timer without changing state. This MUST
4380 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4381 * endpoint MUST abort the initialization process and report the
4382 * error to SCTP user.
4384 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4385 * COOKIE ECHO and re-start the T1-cookie timer without changing
4386 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4387 * After that, the endpoint MUST abort the initialization process and
4388 * report the error to SCTP user.
4394 sctp_disposition_t sctp_sf_t1_timer_expire(const struct sctp_endpoint *ep,
4395 const struct sctp_association *asoc,
4396 const sctp_subtype_t type,
4398 sctp_cmd_seq_t *commands)
4400 struct sctp_chunk *repl;
4401 struct sctp_bind_addr *bp;
4402 sctp_event_timeout_t timer = (sctp_event_timeout_t) arg;
4406 timeout = asoc->timeouts[timer];
4407 attempts = asoc->counters[SCTP_COUNTER_INIT_ERROR] + 1;
4410 SCTP_DEBUG_PRINTK("Timer T1 expired.\n");
4412 if (attempts < asoc->max_init_attempts) {
4414 case SCTP_EVENT_TIMEOUT_T1_INIT:
4415 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
4416 repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
4419 case SCTP_EVENT_TIMEOUT_T1_COOKIE:
4420 repl = sctp_make_cookie_echo(asoc, NULL);
4431 /* Issue a sideeffect to do the needed accounting. */
4432 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
4434 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
4436 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
4437 SCTP_U32(SCTP_ERROR_NO_ERROR));
4438 return SCTP_DISPOSITION_DELETE_TCB;
4441 return SCTP_DISPOSITION_CONSUME;
4444 return SCTP_DISPOSITION_NOMEM;
4447 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4448 * with the updated last sequential TSN received from its peer.
4450 * An endpoint should limit the number of retransmissions of the
4451 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4452 * If this threshold is exceeded the endpoint should destroy the TCB and
4453 * MUST report the peer endpoint unreachable to the upper layer (and
4454 * thus the association enters the CLOSED state). The reception of any
4455 * packet from its peer (i.e. as the peer sends all of its queued DATA
4456 * chunks) should clear the endpoint's retransmission count and restart
4457 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4458 * all of its queued DATA chunks that have not yet been sent.
4460 sctp_disposition_t sctp_sf_t2_timer_expire(const struct sctp_endpoint *ep,
4461 const struct sctp_association *asoc,
4462 const sctp_subtype_t type,
4464 sctp_cmd_seq_t *commands)
4466 struct sctp_chunk *reply = NULL;
4468 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4469 if (asoc->overall_error_count >= asoc->max_retrans) {
4470 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4471 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4472 SCTP_U32(SCTP_ERROR_NO_ERROR));
4473 SCTP_INC_STATS(SctpAborteds);
4474 SCTP_DEC_STATS(SctpCurrEstab);
4475 return SCTP_DISPOSITION_DELETE_TCB;
4478 switch (asoc->state) {
4479 case SCTP_STATE_SHUTDOWN_SENT:
4480 reply = sctp_make_shutdown(asoc, NULL);
4483 case SCTP_STATE_SHUTDOWN_ACK_SENT:
4484 reply = sctp_make_shutdown_ack(asoc, NULL);
4495 /* Do some failure management (Section 8.2). */
4496 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
4497 SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
4499 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4500 * the T2-shutdown timer.
4502 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
4504 /* Restart the T2-shutdown timer. */
4505 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4506 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
4507 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4508 return SCTP_DISPOSITION_CONSUME;
4511 return SCTP_DISPOSITION_NOMEM;
4515 * ADDIP Section 4.1 ASCONF CHunk Procedures
4516 * If the T4 RTO timer expires the endpoint should do B1 to B5
4518 sctp_disposition_t sctp_sf_t4_timer_expire(
4519 const struct sctp_endpoint *ep,
4520 const struct sctp_association *asoc,
4521 const sctp_subtype_t type,
4523 sctp_cmd_seq_t *commands)
4525 struct sctp_chunk *chunk = asoc->addip_last_asconf;
4526 struct sctp_transport *transport = chunk->transport;
4528 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4529 * detection on the appropriate destination address as defined in
4530 * RFC2960 [5] section 8.1 and 8.2.
4532 sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
4534 /* Reconfig T4 timer and transport. */
4535 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
4537 /* ADDIP 4.1 B2) Increment the association error counters and perform
4538 * endpoint failure detection on the association as defined in
4539 * RFC2960 [5] section 8.1 and 8.2.
4540 * association error counter is incremented in SCTP_CMD_STRIKE.
4542 if (asoc->overall_error_count >= asoc->max_retrans) {
4543 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
4544 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4545 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4546 SCTP_U32(SCTP_ERROR_NO_ERROR));
4547 SCTP_INC_STATS(SctpAborteds);
4548 SCTP_INC_STATS(SctpCurrEstab);
4549 return SCTP_DISPOSITION_ABORT;
4552 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4553 * the ASCONF chunk was sent by doubling the RTO timer value.
4554 * This is done in SCTP_CMD_STRIKE.
4557 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4558 * choose an alternate destination address (please refer to RFC2960
4559 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4560 * chunk, it MUST be the same (including its serial number) as the last
4563 sctp_chunk_hold(asoc->addip_last_asconf);
4564 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
4565 SCTP_CHUNK(asoc->addip_last_asconf));
4567 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4568 * destination is selected, then the RTO used will be that of the new
4569 * destination address.
4571 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
4572 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
4574 return SCTP_DISPOSITION_CONSUME;
4577 /* sctpimpguide-05 Section 2.12.2
4578 * The sender of the SHUTDOWN MAY also start an overall guard timer
4579 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4580 * At the expiration of this timer the sender SHOULD abort the association
4581 * by sending an ABORT chunk.
4583 sctp_disposition_t sctp_sf_t5_timer_expire(const struct sctp_endpoint *ep,
4584 const struct sctp_association *asoc,
4585 const sctp_subtype_t type,
4587 sctp_cmd_seq_t *commands)
4589 struct sctp_chunk *reply = NULL;
4591 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4593 reply = sctp_make_abort(asoc, NULL, 0);
4597 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
4598 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
4599 SCTP_U32(SCTP_ERROR_NO_ERROR));
4601 return SCTP_DISPOSITION_DELETE_TCB;
4603 return SCTP_DISPOSITION_NOMEM;
4606 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4607 * the association is automatically closed by starting the shutdown process.
4608 * The work that needs to be done is same as when SHUTDOWN is initiated by
4609 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4611 sctp_disposition_t sctp_sf_autoclose_timer_expire(
4612 const struct sctp_endpoint *ep,
4613 const struct sctp_association *asoc,
4614 const sctp_subtype_t type,
4616 sctp_cmd_seq_t *commands)
4620 /* From 9.2 Shutdown of an Association
4621 * Upon receipt of the SHUTDOWN primitive from its upper
4622 * layer, the endpoint enters SHUTDOWN-PENDING state and
4623 * remains there until all outstanding data has been
4624 * acknowledged by its peer. The endpoint accepts no new data
4625 * from its upper layer, but retransmits data to the far end
4626 * if necessary to fill gaps.
4628 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
4629 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
4631 /* sctpimpguide-05 Section 2.12.2
4632 * The sender of the SHUTDOWN MAY also start an overall guard timer
4633 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4635 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
4636 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
4637 disposition = SCTP_DISPOSITION_CONSUME;
4638 if (sctp_outq_is_empty(&asoc->outqueue)) {
4639 disposition = sctp_sf_do_9_2_start_shutdown(ep, asoc, type,
4645 /*****************************************************************************
4646 * These are sa state functions which could apply to all types of events.
4647 ****************************************************************************/
4650 * This table entry is not implemented.
4653 * (endpoint, asoc, chunk)
4655 * The return value is the disposition of the chunk.
4657 sctp_disposition_t sctp_sf_not_impl(const struct sctp_endpoint *ep,
4658 const struct sctp_association *asoc,
4659 const sctp_subtype_t type,
4661 sctp_cmd_seq_t *commands)
4663 return SCTP_DISPOSITION_NOT_IMPL;
4667 * This table entry represents a bug.
4670 * (endpoint, asoc, chunk)
4672 * The return value is the disposition of the chunk.
4674 sctp_disposition_t sctp_sf_bug(const struct sctp_endpoint *ep,
4675 const struct sctp_association *asoc,
4676 const sctp_subtype_t type,
4678 sctp_cmd_seq_t *commands)
4680 return SCTP_DISPOSITION_BUG;
4684 * This table entry represents the firing of a timer in the wrong state.
4685 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
4686 * when the association is in the wrong state. This event should
4687 * be ignored, so as to prevent any rearming of the timer.
4690 * (endpoint, asoc, chunk)
4692 * The return value is the disposition of the chunk.
4694 sctp_disposition_t sctp_sf_timer_ignore(const struct sctp_endpoint *ep,
4695 const struct sctp_association *asoc,
4696 const sctp_subtype_t type,
4698 sctp_cmd_seq_t *commands)
4700 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type.chunk);
4701 return SCTP_DISPOSITION_CONSUME;
4704 /********************************************************************
4705 * 2nd Level Abstractions
4706 ********************************************************************/
4708 /* Pull the SACK chunk based on the SACK header. */
4709 struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
4711 struct sctp_sackhdr *sack;
4716 /* Protect ourselves from reading too far into
4717 * the skb from a bogus sender.
4719 sack = (struct sctp_sackhdr *) chunk->skb->data;
4721 num_blocks = ntohs(sack->num_gap_ack_blocks);
4722 num_dup_tsns = ntohs(sack->num_dup_tsns);
4723 len = sizeof(struct sctp_sackhdr);
4724 len = (num_blocks + num_dup_tsns) * sizeof(__u32);
4725 if (len > chunk->skb->len)
4728 skb_pull(chunk->skb, len);
4733 /* Create an ABORT packet to be sent as a response, with the specified
4736 struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
4737 const struct sctp_association *asoc,
4738 struct sctp_chunk *chunk,
4739 const void *payload,
4742 struct sctp_packet *packet;
4743 struct sctp_chunk *abort;
4745 packet = sctp_ootb_pkt_new(asoc, chunk);
4749 * The T bit will be set if the asoc is NULL.
4751 abort = sctp_make_abort(asoc, chunk, paylen);
4753 sctp_ootb_pkt_free(packet);
4756 /* Add specified error causes, i.e., payload, to the
4759 sctp_addto_chunk(abort, paylen, payload);
4761 /* Set the skb to the belonging sock for accounting. */
4762 abort->skb->sk = ep->base.sk;
4764 sctp_packet_append_chunk(packet, abort);
4771 /* Allocate a packet for responding in the OOTB conditions. */
4772 struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
4773 const struct sctp_chunk *chunk)
4775 struct sctp_packet *packet;
4776 struct sctp_transport *transport;
4781 /* Get the source and destination port from the inbound packet. */
4782 sport = ntohs(chunk->sctp_hdr->dest);
4783 dport = ntohs(chunk->sctp_hdr->source);
4785 /* The V-tag is going to be the same as the inbound packet if no
4786 * association exists, otherwise, use the peer's vtag.
4789 vtag = asoc->peer.i.init_tag;
4791 /* Special case the INIT and stale COOKIE_ECHO as there is no
4794 switch(chunk->chunk_hdr->type) {
4797 sctp_init_chunk_t *init;
4799 init = (sctp_init_chunk_t *)chunk->chunk_hdr;
4800 vtag = ntohl(init->init_hdr.init_tag);
4804 vtag = ntohl(chunk->sctp_hdr->vtag);
4809 /* Make a transport for the bucket, Eliza... */
4810 transport = sctp_transport_new(sctp_source(chunk), GFP_ATOMIC);
4814 /* Cache a route for the transport with the chunk's destination as
4815 * the source address.
4817 sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
4818 sctp_sk(sctp_get_ctl_sock()));
4820 packet = sctp_packet_init(&transport->packet, transport, sport, dport);
4821 packet = sctp_packet_config(packet, vtag, 0);
4829 /* Free the packet allocated earlier for responding in the OOTB condition. */
4830 void sctp_ootb_pkt_free(struct sctp_packet *packet)
4832 sctp_transport_free(packet->transport);
4835 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
4836 void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
4837 const struct sctp_association *asoc,
4838 const struct sctp_chunk *chunk,
4839 sctp_cmd_seq_t *commands,
4840 struct sctp_chunk *err_chunk)
4842 struct sctp_packet *packet;
4845 packet = sctp_ootb_pkt_new(asoc, chunk);
4847 struct sctp_signed_cookie *cookie;
4849 /* Override the OOTB vtag from the cookie. */
4850 cookie = chunk->subh.cookie_hdr;
4851 packet->vtag = cookie->c.peer_vtag;
4853 /* Set the skb to the belonging sock for accounting. */
4854 err_chunk->skb->sk = ep->base.sk;
4855 sctp_packet_append_chunk(packet, err_chunk);
4856 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
4857 SCTP_PACKET(packet));
4858 SCTP_INC_STATS(SctpOutCtrlChunks);
4860 sctp_chunk_free (err_chunk);