1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet *sctp_abort_pkt_new(const struct sctp_endpoint *ep,
69 const struct sctp_association *asoc,
70 struct sctp_chunk *chunk,
73 static int sctp_eat_data(const struct sctp_association *asoc,
74 struct sctp_chunk *chunk,
75 sctp_cmd_seq_t *commands);
76 static struct sctp_packet *sctp_ootb_pkt_new(const struct sctp_association *asoc,
77 const struct sctp_chunk *chunk);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint *ep,
79 const struct sctp_association *asoc,
80 const struct sctp_chunk *chunk,
81 sctp_cmd_seq_t *commands,
82 struct sctp_chunk *err_chunk);
83 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
84 const struct sctp_association *asoc,
85 const sctp_subtype_t type,
87 sctp_cmd_seq_t *commands);
88 static sctp_disposition_t sctp_sf_shut_8_4_5(const struct sctp_endpoint *ep,
89 const struct sctp_association *asoc,
90 const sctp_subtype_t type,
92 sctp_cmd_seq_t *commands);
93 static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
95 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
96 __be16 error, int sk_err,
97 const struct sctp_association *asoc,
98 struct sctp_transport *transport);
100 static sctp_disposition_t sctp_sf_abort_violation(
101 const struct sctp_association *asoc,
103 sctp_cmd_seq_t *commands,
105 const size_t paylen);
107 static sctp_disposition_t sctp_sf_violation_chunklen(
108 const struct sctp_endpoint *ep,
109 const struct sctp_association *asoc,
110 const sctp_subtype_t type,
112 sctp_cmd_seq_t *commands);
114 static sctp_disposition_t sctp_sf_violation_ctsn(
115 const struct sctp_endpoint *ep,
116 const struct sctp_association *asoc,
117 const sctp_subtype_t type,
119 sctp_cmd_seq_t *commands);
121 /* Small helper function that checks if the chunk length
122 * is of the appropriate length. The 'required_length' argument
123 * is set to be the size of a specific chunk we are testing.
124 * Return Values: 1 = Valid length
129 sctp_chunk_length_valid(struct sctp_chunk *chunk,
130 __u16 required_length)
132 __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
134 if (unlikely(chunk_length < required_length))
140 /**********************************************************
141 * These are the state functions for handling chunk events.
142 **********************************************************/
145 * Process the final SHUTDOWN COMPLETE.
147 * Section: 4 (C) (diagram), 9.2
148 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
149 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
150 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
151 * should stop the T2-shutdown timer and remove all knowledge of the
152 * association (and thus the association enters the CLOSED state).
154 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
155 * C) Rules for packet carrying SHUTDOWN COMPLETE:
157 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
158 * if the Verification Tag field of the packet matches its own tag and
159 * the T bit is not set
161 * it is set to its peer's tag and the T bit is set in the Chunk
163 * Otherwise, the receiver MUST silently discard the packet
164 * and take no further action. An endpoint MUST ignore the
165 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
168 * (endpoint, asoc, chunk)
171 * (asoc, reply_msg, msg_up, timers, counters)
173 * The return value is the disposition of the chunk.
175 sctp_disposition_t sctp_sf_do_4_C(const struct sctp_endpoint *ep,
176 const struct sctp_association *asoc,
177 const sctp_subtype_t type,
179 sctp_cmd_seq_t *commands)
181 struct sctp_chunk *chunk = arg;
182 struct sctp_ulpevent *ev;
184 /* RFC 2960 6.10 Bundling
186 * An endpoint MUST NOT bundle INIT, INIT ACK or
187 * SHUTDOWN COMPLETE with any other chunks.
189 if (!chunk->singleton)
190 return SCTP_DISPOSITION_VIOLATION;
192 if (!sctp_vtag_verify_either(chunk, asoc))
193 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
195 /* RFC 2960 10.2 SCTP-to-ULP
197 * H) SHUTDOWN COMPLETE notification
199 * When SCTP completes the shutdown procedures (section 9.2) this
200 * notification is passed to the upper layer.
202 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
203 0, 0, 0, NULL, GFP_ATOMIC);
205 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
208 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
209 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
210 * not the chunk should be discarded. If the endpoint is in
211 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
212 * T2-shutdown timer and remove all knowledge of the
213 * association (and thus the association enters the CLOSED
216 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
217 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
219 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
220 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
222 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
223 SCTP_STATE(SCTP_STATE_CLOSED));
225 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
226 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
228 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
230 return SCTP_DISPOSITION_DELETE_TCB;
234 * Respond to a normal INIT chunk.
235 * We are the side that is being asked for an association.
237 * Section: 5.1 Normal Establishment of an Association, B
238 * B) "Z" shall respond immediately with an INIT ACK chunk. The
239 * destination IP address of the INIT ACK MUST be set to the source
240 * IP address of the INIT to which this INIT ACK is responding. In
241 * the response, besides filling in other parameters, "Z" must set the
242 * Verification Tag field to Tag_A, and also provide its own
243 * Verification Tag (Tag_Z) in the Initiate Tag field.
245 * Verification Tag: Must be 0.
248 * (endpoint, asoc, chunk)
251 * (asoc, reply_msg, msg_up, timers, counters)
253 * The return value is the disposition of the chunk.
255 sctp_disposition_t sctp_sf_do_5_1B_init(const struct sctp_endpoint *ep,
256 const struct sctp_association *asoc,
257 const sctp_subtype_t type,
259 sctp_cmd_seq_t *commands)
261 struct sctp_chunk *chunk = arg;
262 struct sctp_chunk *repl;
263 struct sctp_association *new_asoc;
264 struct sctp_chunk *err_chunk;
265 struct sctp_packet *packet;
266 sctp_unrecognized_param_t *unk_param;
270 * An endpoint MUST NOT bundle INIT, INIT ACK or
271 * SHUTDOWN COMPLETE with any other chunks.
274 * Furthermore, we require that the receiver of an INIT chunk MUST
275 * enforce these rules by silently discarding an arriving packet
276 * with an INIT chunk that is bundled with other chunks.
278 if (!chunk->singleton)
279 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
281 /* If the packet is an OOTB packet which is temporarily on the
282 * control endpoint, respond with an ABORT.
284 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
285 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
287 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
290 if (chunk->sctp_hdr->vtag != 0)
291 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
293 /* Make sure that the INIT chunk has a valid length.
294 * Normally, this would cause an ABORT with a Protocol Violation
295 * error, but since we don't have an association, we'll
296 * just discard the packet.
298 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
299 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
301 /* Verify the INIT chunk before processing it. */
303 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
304 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
306 /* This chunk contains fatal error. It is to be discarded.
307 * Send an ABORT, with causes if there is any.
310 packet = sctp_abort_pkt_new(ep, asoc, arg,
311 (__u8 *)(err_chunk->chunk_hdr) +
312 sizeof(sctp_chunkhdr_t),
313 ntohs(err_chunk->chunk_hdr->length) -
314 sizeof(sctp_chunkhdr_t));
316 sctp_chunk_free(err_chunk);
319 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
320 SCTP_PACKET(packet));
321 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
322 return SCTP_DISPOSITION_CONSUME;
324 return SCTP_DISPOSITION_NOMEM;
327 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
332 /* Grab the INIT header. */
333 chunk->subh.init_hdr = (sctp_inithdr_t *)chunk->skb->data;
335 /* Tag the variable length parameters. */
336 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
338 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
342 /* The call, sctp_process_init(), can fail on memory allocation. */
343 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
345 (sctp_init_chunk_t *)chunk->chunk_hdr,
349 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
351 /* If there are errors need to be reported for unknown parameters,
352 * make sure to reserve enough room in the INIT ACK for them.
356 len = ntohs(err_chunk->chunk_hdr->length) -
357 sizeof(sctp_chunkhdr_t);
359 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
362 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
366 /* If there are errors need to be reported for unknown parameters,
367 * include them in the outgoing INIT ACK as "Unrecognized parameter"
371 /* Get the "Unrecognized parameter" parameter(s) out of the
372 * ERROR chunk generated by sctp_verify_init(). Since the
373 * error cause code for "unknown parameter" and the
374 * "Unrecognized parameter" type is the same, we can
375 * construct the parameters in INIT ACK by copying the
378 unk_param = (sctp_unrecognized_param_t *)
379 ((__u8 *)(err_chunk->chunk_hdr) +
380 sizeof(sctp_chunkhdr_t));
381 /* Replace the cause code with the "Unrecognized parameter"
384 sctp_addto_chunk(repl, len, unk_param);
385 sctp_chunk_free(err_chunk);
388 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
390 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
393 * Note: After sending out INIT ACK with the State Cookie parameter,
394 * "Z" MUST NOT allocate any resources, nor keep any states for the
395 * new association. Otherwise, "Z" will be vulnerable to resource
398 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
400 return SCTP_DISPOSITION_DELETE_TCB;
403 sctp_association_free(new_asoc);
406 sctp_chunk_free(err_chunk);
407 return SCTP_DISPOSITION_NOMEM;
411 * Respond to a normal INIT ACK chunk.
412 * We are the side that is initiating the association.
414 * Section: 5.1 Normal Establishment of an Association, C
415 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
416 * timer and leave COOKIE-WAIT state. "A" shall then send the State
417 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
418 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
420 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
421 * DATA chunks, but it MUST be the first chunk in the packet and
422 * until the COOKIE ACK is returned the sender MUST NOT send any
423 * other packets to the peer.
425 * Verification Tag: 3.3.3
426 * If the value of the Initiate Tag in a received INIT ACK chunk is
427 * found to be 0, the receiver MUST treat it as an error and close the
428 * association by transmitting an ABORT.
431 * (endpoint, asoc, chunk)
434 * (asoc, reply_msg, msg_up, timers, counters)
436 * The return value is the disposition of the chunk.
438 sctp_disposition_t sctp_sf_do_5_1C_ack(const struct sctp_endpoint *ep,
439 const struct sctp_association *asoc,
440 const sctp_subtype_t type,
442 sctp_cmd_seq_t *commands)
444 struct sctp_chunk *chunk = arg;
445 sctp_init_chunk_t *initchunk;
446 struct sctp_chunk *err_chunk;
447 struct sctp_packet *packet;
450 if (!sctp_vtag_verify(chunk, asoc))
451 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
453 /* Make sure that the INIT-ACK chunk has a valid length */
454 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_initack_chunk_t)))
455 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
458 * An endpoint MUST NOT bundle INIT, INIT ACK or
459 * SHUTDOWN COMPLETE with any other chunks.
461 if (!chunk->singleton)
462 return SCTP_DISPOSITION_VIOLATION;
464 /* Grab the INIT header. */
465 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
467 /* Verify the INIT chunk before processing it. */
469 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
470 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
473 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
475 /* This chunk contains fatal error. It is to be discarded.
476 * Send an ABORT, with causes if there is any.
479 packet = sctp_abort_pkt_new(ep, asoc, arg,
480 (__u8 *)(err_chunk->chunk_hdr) +
481 sizeof(sctp_chunkhdr_t),
482 ntohs(err_chunk->chunk_hdr->length) -
483 sizeof(sctp_chunkhdr_t));
485 sctp_chunk_free(err_chunk);
488 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
489 SCTP_PACKET(packet));
490 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
491 error = SCTP_ERROR_INV_PARAM;
493 error = SCTP_ERROR_NO_RESOURCE;
496 sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
497 error = SCTP_ERROR_INV_PARAM;
499 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED,
500 asoc, chunk->transport);
503 /* Tag the variable length parameters. Note that we never
504 * convert the parameters in an INIT chunk.
506 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
508 initchunk = (sctp_init_chunk_t *) chunk->chunk_hdr;
510 sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
511 SCTP_PEER_INIT(initchunk));
513 /* Reset init error count upon receipt of INIT-ACK. */
514 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
516 /* 5.1 C) "A" shall stop the T1-init timer and leave
517 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
518 * timer, and enter the COOKIE-ECHOED state.
520 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
521 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
522 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
523 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
524 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
525 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
527 /* 5.1 C) "A" shall then send the State Cookie received in the
528 * INIT ACK chunk in a COOKIE ECHO chunk, ...
530 /* If there is any errors to report, send the ERROR chunk generated
531 * for unknown parameters as well.
533 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
534 SCTP_CHUNK(err_chunk));
536 return SCTP_DISPOSITION_CONSUME;
540 * Respond to a normal COOKIE ECHO chunk.
541 * We are the side that is being asked for an association.
543 * Section: 5.1 Normal Establishment of an Association, D
544 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
545 * with a COOKIE ACK chunk after building a TCB and moving to
546 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
547 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
548 * chunk MUST be the first chunk in the packet.
550 * IMPLEMENTATION NOTE: An implementation may choose to send the
551 * Communication Up notification to the SCTP user upon reception
552 * of a valid COOKIE ECHO chunk.
554 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
555 * D) Rules for packet carrying a COOKIE ECHO
557 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
558 * Initial Tag received in the INIT ACK.
560 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
563 * (endpoint, asoc, chunk)
566 * (asoc, reply_msg, msg_up, timers, counters)
568 * The return value is the disposition of the chunk.
570 sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep,
571 const struct sctp_association *asoc,
572 const sctp_subtype_t type, void *arg,
573 sctp_cmd_seq_t *commands)
575 struct sctp_chunk *chunk = arg;
576 struct sctp_association *new_asoc;
577 sctp_init_chunk_t *peer_init;
578 struct sctp_chunk *repl;
579 struct sctp_ulpevent *ev, *ai_ev = NULL;
581 struct sctp_chunk *err_chk_p;
584 /* If the packet is an OOTB packet which is temporarily on the
585 * control endpoint, respond with an ABORT.
587 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
588 return sctp_sf_ootb(ep, asoc, type, arg, commands);
590 /* Make sure that the COOKIE_ECHO chunk has a valid length.
591 * In this case, we check that we have enough for at least a
592 * chunk header. More detailed verification is done
593 * in sctp_unpack_cookie().
595 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
596 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
598 /* If the endpoint is not listening or if the number of associations
599 * on the TCP-style socket exceed the max backlog, respond with an
603 if (!sctp_sstate(sk, LISTENING) ||
604 (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
605 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
607 /* "Decode" the chunk. We have no optional parameters so we
610 chunk->subh.cookie_hdr =
611 (struct sctp_signed_cookie *)chunk->skb->data;
612 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
613 sizeof(sctp_chunkhdr_t)))
616 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
617 * "Z" will reply with a COOKIE ACK chunk after building a TCB
618 * and moving to the ESTABLISHED state.
620 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
624 * If the re-build failed, what is the proper error path
627 * [We should abort the association. --piggy]
630 /* FIXME: Several errors are possible. A bad cookie should
631 * be silently discarded, but think about logging it too.
634 case -SCTP_IERROR_NOMEM:
637 case -SCTP_IERROR_STALE_COOKIE:
638 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
640 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
642 case -SCTP_IERROR_BAD_SIG:
644 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
649 /* Delay state machine commands until later.
651 * Re-build the bind address for the association is done in
652 * the sctp_unpack_cookie() already.
654 /* This is a brand-new association, so these are not yet side
655 * effects--it is safe to run them here.
657 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
659 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
660 &chunk->subh.cookie_hdr->c.peer_addr,
661 peer_init, GFP_ATOMIC))
664 repl = sctp_make_cookie_ack(new_asoc, chunk);
668 /* RFC 2960 5.1 Normal Establishment of an Association
670 * D) IMPLEMENTATION NOTE: An implementation may choose to
671 * send the Communication Up notification to the SCTP user
672 * upon reception of a valid COOKIE ECHO chunk.
674 ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
675 new_asoc->c.sinit_num_ostreams,
676 new_asoc->c.sinit_max_instreams,
681 /* Sockets API Draft Section 5.3.1.6
682 * When a peer sends a Adaptation Layer Indication parameter , SCTP
683 * delivers this notification to inform the application that of the
684 * peers requested adaptation layer.
686 if (new_asoc->peer.adaptation_ind) {
687 ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
693 /* Add all the state machine commands now since we've created
694 * everything. This way we don't introduce memory corruptions
695 * during side-effect processing and correclty count established
698 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
699 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
700 SCTP_STATE(SCTP_STATE_ESTABLISHED));
701 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
702 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS);
703 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
705 if (new_asoc->autoclose)
706 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
707 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
709 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
711 /* This will send the COOKIE ACK */
712 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
714 /* Queue the ASSOC_CHANGE event */
715 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
717 /* Send up the Adaptation Layer Indication event */
719 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
720 SCTP_ULPEVENT(ai_ev));
722 return SCTP_DISPOSITION_CONSUME;
725 sctp_ulpevent_free(ev);
727 sctp_chunk_free(repl);
729 sctp_association_free(new_asoc);
731 return SCTP_DISPOSITION_NOMEM;
735 * Respond to a normal COOKIE ACK chunk.
736 * We are the side that is being asked for an association.
738 * RFC 2960 5.1 Normal Establishment of an Association
740 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
741 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
742 * timer. It may also notify its ULP about the successful
743 * establishment of the association with a Communication Up
744 * notification (see Section 10).
748 * (endpoint, asoc, chunk)
751 * (asoc, reply_msg, msg_up, timers, counters)
753 * The return value is the disposition of the chunk.
755 sctp_disposition_t sctp_sf_do_5_1E_ca(const struct sctp_endpoint *ep,
756 const struct sctp_association *asoc,
757 const sctp_subtype_t type, void *arg,
758 sctp_cmd_seq_t *commands)
760 struct sctp_chunk *chunk = arg;
761 struct sctp_ulpevent *ev;
763 if (!sctp_vtag_verify(chunk, asoc))
764 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
766 /* Verify that the chunk length for the COOKIE-ACK is OK.
767 * If we don't do this, any bundled chunks may be junked.
769 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
770 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
773 /* Reset init error count upon receipt of COOKIE-ACK,
774 * to avoid problems with the managemement of this
775 * counter in stale cookie situations when a transition back
776 * from the COOKIE-ECHOED state to the COOKIE-WAIT
777 * state is performed.
779 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
781 /* RFC 2960 5.1 Normal Establishment of an Association
783 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
784 * from the COOKIE-ECHOED state to the ESTABLISHED state,
785 * stopping the T1-cookie timer.
787 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
788 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
789 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
790 SCTP_STATE(SCTP_STATE_ESTABLISHED));
791 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
792 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS);
793 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
795 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
796 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
797 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
799 /* It may also notify its ULP about the successful
800 * establishment of the association with a Communication Up
801 * notification (see Section 10).
803 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
804 0, asoc->c.sinit_num_ostreams,
805 asoc->c.sinit_max_instreams,
811 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
813 /* Sockets API Draft Section 5.3.1.6
814 * When a peer sends a Adaptation Layer Indication parameter , SCTP
815 * delivers this notification to inform the application that of the
816 * peers requested adaptation layer.
818 if (asoc->peer.adaptation_ind) {
819 ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
823 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
827 return SCTP_DISPOSITION_CONSUME;
829 return SCTP_DISPOSITION_NOMEM;
832 /* Generate and sendout a heartbeat packet. */
833 static sctp_disposition_t sctp_sf_heartbeat(const struct sctp_endpoint *ep,
834 const struct sctp_association *asoc,
835 const sctp_subtype_t type,
837 sctp_cmd_seq_t *commands)
839 struct sctp_transport *transport = (struct sctp_transport *) arg;
840 struct sctp_chunk *reply;
841 sctp_sender_hb_info_t hbinfo;
844 hbinfo.param_hdr.type = SCTP_PARAM_HEARTBEAT_INFO;
845 hbinfo.param_hdr.length = htons(sizeof(sctp_sender_hb_info_t));
846 hbinfo.daddr = transport->ipaddr;
847 hbinfo.sent_at = jiffies;
848 hbinfo.hb_nonce = transport->hb_nonce;
850 /* Send a heartbeat to our peer. */
851 paylen = sizeof(sctp_sender_hb_info_t);
852 reply = sctp_make_heartbeat(asoc, transport, &hbinfo, paylen);
854 return SCTP_DISPOSITION_NOMEM;
856 /* Set rto_pending indicating that an RTT measurement
857 * is started with this heartbeat chunk.
859 sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
860 SCTP_TRANSPORT(transport));
862 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
863 return SCTP_DISPOSITION_CONSUME;
866 /* Generate a HEARTBEAT packet on the given transport. */
867 sctp_disposition_t sctp_sf_sendbeat_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_transport *transport = (struct sctp_transport *) arg;
875 if (asoc->overall_error_count >= asoc->max_retrans) {
876 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
877 SCTP_ERROR(ETIMEDOUT));
878 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
879 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
880 SCTP_PERR(SCTP_ERROR_NO_ERROR));
881 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
882 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
883 return SCTP_DISPOSITION_DELETE_TCB;
887 * The Sender-specific Heartbeat Info field should normally include
888 * information about the sender's current time when this HEARTBEAT
889 * chunk is sent and the destination transport address to which this
890 * HEARTBEAT is sent (see Section 8.3).
893 if (transport->param_flags & SPP_HB_ENABLE) {
894 if (SCTP_DISPOSITION_NOMEM ==
895 sctp_sf_heartbeat(ep, asoc, type, arg,
897 return SCTP_DISPOSITION_NOMEM;
898 /* Set transport error counter and association error counter
899 * when sending heartbeat.
901 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_RESET,
902 SCTP_TRANSPORT(transport));
904 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
905 SCTP_TRANSPORT(transport));
907 return SCTP_DISPOSITION_CONSUME;
911 * Process an heartbeat request.
913 * Section: 8.3 Path Heartbeat
914 * The receiver of the HEARTBEAT should immediately respond with a
915 * HEARTBEAT ACK that contains the Heartbeat Information field copied
916 * from the received HEARTBEAT chunk.
918 * Verification Tag: 8.5 Verification Tag [Normal verification]
919 * When receiving an SCTP packet, the endpoint MUST ensure that the
920 * value in the Verification Tag field of the received SCTP packet
921 * matches its own Tag. If the received Verification Tag value does not
922 * match the receiver's own tag value, the receiver shall silently
923 * discard the packet and shall not process it any further except for
924 * those cases listed in Section 8.5.1 below.
927 * (endpoint, asoc, chunk)
930 * (asoc, reply_msg, msg_up, timers, counters)
932 * The return value is the disposition of the chunk.
934 sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep,
935 const struct sctp_association *asoc,
936 const sctp_subtype_t type,
938 sctp_cmd_seq_t *commands)
940 struct sctp_chunk *chunk = arg;
941 struct sctp_chunk *reply;
944 if (!sctp_vtag_verify(chunk, asoc))
945 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
947 /* Make sure that the HEARTBEAT chunk has a valid length. */
948 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
949 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
952 /* 8.3 The receiver of the HEARTBEAT should immediately
953 * respond with a HEARTBEAT ACK that contains the Heartbeat
954 * Information field copied from the received HEARTBEAT chunk.
956 chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data;
957 paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t);
958 if (!pskb_pull(chunk->skb, paylen))
961 reply = sctp_make_heartbeat_ack(asoc, chunk,
962 chunk->subh.hb_hdr, paylen);
966 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
967 return SCTP_DISPOSITION_CONSUME;
970 return SCTP_DISPOSITION_NOMEM;
974 * Process the returning HEARTBEAT ACK.
976 * Section: 8.3 Path Heartbeat
977 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
978 * should clear the error counter of the destination transport
979 * address to which the HEARTBEAT was sent, and mark the destination
980 * transport address as active if it is not so marked. The endpoint may
981 * optionally report to the upper layer when an inactive destination
982 * address is marked as active due to the reception of the latest
983 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
984 * clear the association overall error count as well (as defined
987 * The receiver of the HEARTBEAT ACK should also perform an RTT
988 * measurement for that destination transport address using the time
989 * value carried in the HEARTBEAT ACK chunk.
991 * Verification Tag: 8.5 Verification Tag [Normal verification]
994 * (endpoint, asoc, chunk)
997 * (asoc, reply_msg, msg_up, timers, counters)
999 * The return value is the disposition of the chunk.
1001 sctp_disposition_t sctp_sf_backbeat_8_3(const struct sctp_endpoint *ep,
1002 const struct sctp_association *asoc,
1003 const sctp_subtype_t type,
1005 sctp_cmd_seq_t *commands)
1007 struct sctp_chunk *chunk = arg;
1008 union sctp_addr from_addr;
1009 struct sctp_transport *link;
1010 sctp_sender_hb_info_t *hbinfo;
1011 unsigned long max_interval;
1013 if (!sctp_vtag_verify(chunk, asoc))
1014 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1016 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1017 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_heartbeat_chunk_t)))
1018 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1021 hbinfo = (sctp_sender_hb_info_t *) chunk->skb->data;
1022 /* Make sure that the length of the parameter is what we expect */
1023 if (ntohs(hbinfo->param_hdr.length) !=
1024 sizeof(sctp_sender_hb_info_t)) {
1025 return SCTP_DISPOSITION_DISCARD;
1028 from_addr = hbinfo->daddr;
1029 link = sctp_assoc_lookup_paddr(asoc, &from_addr);
1031 /* This should never happen, but lets log it if so. */
1032 if (unlikely(!link)) {
1033 if (from_addr.sa.sa_family == AF_INET6) {
1034 if (net_ratelimit())
1036 "%s association %p could not find address "
1040 NIP6(from_addr.v6.sin6_addr));
1042 if (net_ratelimit())
1044 "%s association %p could not find address "
1048 NIPQUAD(from_addr.v4.sin_addr.s_addr));
1050 return SCTP_DISPOSITION_DISCARD;
1053 /* Validate the 64-bit random nonce. */
1054 if (hbinfo->hb_nonce != link->hb_nonce)
1055 return SCTP_DISPOSITION_DISCARD;
1057 max_interval = link->hbinterval + link->rto;
1059 /* Check if the timestamp looks valid. */
1060 if (time_after(hbinfo->sent_at, jiffies) ||
1061 time_after(jiffies, hbinfo->sent_at + max_interval)) {
1062 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1063 "received for transport: %p\n",
1064 __FUNCTION__, link);
1065 return SCTP_DISPOSITION_DISCARD;
1068 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1069 * the HEARTBEAT should clear the error counter of the
1070 * destination transport address to which the HEARTBEAT was
1071 * sent and mark the destination transport address as active if
1072 * it is not so marked.
1074 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
1076 return SCTP_DISPOSITION_CONSUME;
1079 /* Helper function to send out an abort for the restart
1082 static int sctp_sf_send_restart_abort(union sctp_addr *ssa,
1083 struct sctp_chunk *init,
1084 sctp_cmd_seq_t *commands)
1087 struct sctp_packet *pkt;
1088 union sctp_addr_param *addrparm;
1089 struct sctp_errhdr *errhdr;
1090 struct sctp_endpoint *ep;
1091 char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
1092 struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
1094 /* Build the error on the stack. We are way to malloc crazy
1095 * throughout the code today.
1097 errhdr = (struct sctp_errhdr *)buffer;
1098 addrparm = (union sctp_addr_param *)errhdr->variable;
1100 /* Copy into a parm format. */
1101 len = af->to_addr_param(ssa, addrparm);
1102 len += sizeof(sctp_errhdr_t);
1104 errhdr->cause = SCTP_ERROR_RESTART;
1105 errhdr->length = htons(len);
1107 /* Assign to the control socket. */
1108 ep = sctp_sk((sctp_get_ctl_sock()))->ep;
1110 /* Association is NULL since this may be a restart attack and we
1111 * want to send back the attacker's vtag.
1113 pkt = sctp_abort_pkt_new(ep, NULL, init, errhdr, len);
1117 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
1119 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1121 /* Discard the rest of the inbound packet. */
1122 sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
1125 /* Even if there is no memory, treat as a failure so
1126 * the packet will get dropped.
1131 /* A restart is occurring, check to make sure no new addresses
1132 * are being added as we may be under a takeover attack.
1134 static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
1135 const struct sctp_association *asoc,
1136 struct sctp_chunk *init,
1137 sctp_cmd_seq_t *commands)
1139 struct sctp_transport *new_addr, *addr;
1140 struct list_head *pos, *pos2;
1143 /* Implementor's Guide - Sectin 5.2.2
1145 * Before responding the endpoint MUST check to see if the
1146 * unexpected INIT adds new addresses to the association. If new
1147 * addresses are added to the association, the endpoint MUST respond
1151 /* Search through all current addresses and make sure
1152 * we aren't adding any new ones.
1157 list_for_each(pos, &new_asoc->peer.transport_addr_list) {
1158 new_addr = list_entry(pos, struct sctp_transport, transports);
1160 list_for_each(pos2, &asoc->peer.transport_addr_list) {
1161 addr = list_entry(pos2, struct sctp_transport,
1163 if (sctp_cmp_addr_exact(&new_addr->ipaddr,
1173 /* If a new address was added, ABORT the sender. */
1174 if (!found && new_addr) {
1175 sctp_sf_send_restart_abort(&new_addr->ipaddr, init, commands);
1178 /* Return success if all addresses were found. */
1182 /* Populate the verification/tie tags based on overlapping INIT
1185 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1187 static void sctp_tietags_populate(struct sctp_association *new_asoc,
1188 const struct sctp_association *asoc)
1190 switch (asoc->state) {
1192 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1194 case SCTP_STATE_COOKIE_WAIT:
1195 new_asoc->c.my_vtag = asoc->c.my_vtag;
1196 new_asoc->c.my_ttag = asoc->c.my_vtag;
1197 new_asoc->c.peer_ttag = 0;
1200 case SCTP_STATE_COOKIE_ECHOED:
1201 new_asoc->c.my_vtag = asoc->c.my_vtag;
1202 new_asoc->c.my_ttag = asoc->c.my_vtag;
1203 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1206 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1207 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1210 new_asoc->c.my_ttag = asoc->c.my_vtag;
1211 new_asoc->c.peer_ttag = asoc->c.peer_vtag;
1215 /* Other parameters for the endpoint SHOULD be copied from the
1216 * existing parameters of the association (e.g. number of
1217 * outbound streams) into the INIT ACK and cookie.
1219 new_asoc->rwnd = asoc->rwnd;
1220 new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
1221 new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
1222 new_asoc->c.initial_tsn = asoc->c.initial_tsn;
1226 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1229 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1231 * Returns value representing action to be taken. These action values
1232 * correspond to Action/Description values in RFC 2960, Table 2.
1234 static char sctp_tietags_compare(struct sctp_association *new_asoc,
1235 const struct sctp_association *asoc)
1237 /* In this case, the peer may have restarted. */
1238 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1239 (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
1240 (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
1241 (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
1244 /* Collision case B. */
1245 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1246 ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
1247 (0 == asoc->c.peer_vtag))) {
1251 /* Collision case D. */
1252 if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
1253 (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
1256 /* Collision case C. */
1257 if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
1258 (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
1259 (0 == new_asoc->c.my_ttag) &&
1260 (0 == new_asoc->c.peer_ttag))
1263 /* No match to any of the special cases; discard this packet. */
1267 /* Common helper routine for both duplicate and simulataneous INIT
1270 static sctp_disposition_t sctp_sf_do_unexpected_init(
1271 const struct sctp_endpoint *ep,
1272 const struct sctp_association *asoc,
1273 const sctp_subtype_t type,
1274 void *arg, sctp_cmd_seq_t *commands)
1276 sctp_disposition_t retval;
1277 struct sctp_chunk *chunk = arg;
1278 struct sctp_chunk *repl;
1279 struct sctp_association *new_asoc;
1280 struct sctp_chunk *err_chunk;
1281 struct sctp_packet *packet;
1282 sctp_unrecognized_param_t *unk_param;
1286 * An endpoint MUST NOT bundle INIT, INIT ACK or
1287 * SHUTDOWN COMPLETE with any other chunks.
1290 * Furthermore, we require that the receiver of an INIT chunk MUST
1291 * enforce these rules by silently discarding an arriving packet
1292 * with an INIT chunk that is bundled with other chunks.
1294 if (!chunk->singleton)
1295 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1297 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1300 if (chunk->sctp_hdr->vtag != 0)
1301 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg, commands);
1303 /* Make sure that the INIT chunk has a valid length.
1304 * In this case, we generate a protocol violation since we have
1305 * an association established.
1307 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_init_chunk_t)))
1308 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1310 /* Grab the INIT header. */
1311 chunk->subh.init_hdr = (sctp_inithdr_t *) chunk->skb->data;
1313 /* Tag the variable length parameters. */
1314 chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(sctp_inithdr_t));
1316 /* Verify the INIT chunk before processing it. */
1318 if (!sctp_verify_init(asoc, chunk->chunk_hdr->type,
1319 (sctp_init_chunk_t *)chunk->chunk_hdr, chunk,
1321 /* This chunk contains fatal error. It is to be discarded.
1322 * Send an ABORT, with causes if there is any.
1325 packet = sctp_abort_pkt_new(ep, asoc, arg,
1326 (__u8 *)(err_chunk->chunk_hdr) +
1327 sizeof(sctp_chunkhdr_t),
1328 ntohs(err_chunk->chunk_hdr->length) -
1329 sizeof(sctp_chunkhdr_t));
1332 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
1333 SCTP_PACKET(packet));
1334 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
1335 retval = SCTP_DISPOSITION_CONSUME;
1337 retval = SCTP_DISPOSITION_NOMEM;
1341 return sctp_sf_tabort_8_4_8(ep, asoc, type, arg,
1347 * Other parameters for the endpoint SHOULD be copied from the
1348 * existing parameters of the association (e.g. number of
1349 * outbound streams) into the INIT ACK and cookie.
1350 * FIXME: We are copying parameters from the endpoint not the
1353 new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
1357 /* In the outbound INIT ACK the endpoint MUST copy its current
1358 * Verification Tag and Peers Verification tag into a reserved
1359 * place (local tie-tag and per tie-tag) within the state cookie.
1361 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1363 (sctp_init_chunk_t *)chunk->chunk_hdr,
1367 /* Make sure no new addresses are being added during the
1368 * restart. Do not do this check for COOKIE-WAIT state,
1369 * since there are no peer addresses to check against.
1370 * Upon return an ABORT will have been sent if needed.
1372 if (!sctp_state(asoc, COOKIE_WAIT)) {
1373 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
1375 retval = SCTP_DISPOSITION_CONSUME;
1380 sctp_tietags_populate(new_asoc, asoc);
1382 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1384 /* If there are errors need to be reported for unknown parameters,
1385 * make sure to reserve enough room in the INIT ACK for them.
1389 len = ntohs(err_chunk->chunk_hdr->length) -
1390 sizeof(sctp_chunkhdr_t);
1393 if (sctp_assoc_set_bind_addr_from_ep(new_asoc, GFP_ATOMIC) < 0)
1396 repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
1400 /* If there are errors need to be reported for unknown parameters,
1401 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1405 /* Get the "Unrecognized parameter" parameter(s) out of the
1406 * ERROR chunk generated by sctp_verify_init(). Since the
1407 * error cause code for "unknown parameter" and the
1408 * "Unrecognized parameter" type is the same, we can
1409 * construct the parameters in INIT ACK by copying the
1410 * ERROR causes over.
1412 unk_param = (sctp_unrecognized_param_t *)
1413 ((__u8 *)(err_chunk->chunk_hdr) +
1414 sizeof(sctp_chunkhdr_t));
1415 /* Replace the cause code with the "Unrecognized parameter"
1418 sctp_addto_chunk(repl, len, unk_param);
1421 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1422 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1425 * Note: After sending out INIT ACK with the State Cookie parameter,
1426 * "Z" MUST NOT allocate any resources for this new association.
1427 * Otherwise, "Z" will be vulnerable to resource attacks.
1429 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1430 retval = SCTP_DISPOSITION_CONSUME;
1435 retval = SCTP_DISPOSITION_NOMEM;
1438 sctp_association_free(new_asoc);
1441 sctp_chunk_free(err_chunk);
1446 * Handle simultanous INIT.
1447 * This means we started an INIT and then we got an INIT request from
1450 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1451 * This usually indicates an initialization collision, i.e., each
1452 * endpoint is attempting, at about the same time, to establish an
1453 * association with the other endpoint.
1455 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1456 * endpoint MUST respond with an INIT ACK using the same parameters it
1457 * sent in its original INIT chunk (including its Verification Tag,
1458 * unchanged). These original parameters are combined with those from the
1459 * newly received INIT chunk. The endpoint shall also generate a State
1460 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1461 * INIT to calculate the State Cookie.
1463 * After that, the endpoint MUST NOT change its state, the T1-init
1464 * timer shall be left running and the corresponding TCB MUST NOT be
1465 * destroyed. The normal procedures for handling State Cookies when
1466 * a TCB exists will resolve the duplicate INITs to a single association.
1468 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1469 * its Tie-Tags with the Tag information of itself and its peer (see
1470 * section 5.2.2 for a description of the Tie-Tags).
1472 * Verification Tag: Not explicit, but an INIT can not have a valid
1473 * verification tag, so we skip the check.
1476 * (endpoint, asoc, chunk)
1479 * (asoc, reply_msg, msg_up, timers, counters)
1481 * The return value is the disposition of the chunk.
1483 sctp_disposition_t sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint *ep,
1484 const struct sctp_association *asoc,
1485 const sctp_subtype_t type,
1487 sctp_cmd_seq_t *commands)
1489 /* Call helper to do the real work for both simulataneous and
1490 * duplicate INIT chunk handling.
1492 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1496 * Handle duplicated INIT messages. These are usually delayed
1499 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1500 * COOKIE-ECHOED and COOKIE-WAIT
1502 * Unless otherwise stated, upon reception of an unexpected INIT for
1503 * this association, the endpoint shall generate an INIT ACK with a
1504 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1505 * current Verification Tag and peer's Verification Tag into a reserved
1506 * place within the state cookie. We shall refer to these locations as
1507 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1508 * containing this INIT ACK MUST carry a Verification Tag value equal to
1509 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1510 * MUST contain a new Initiation Tag (randomly generated see Section
1511 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1512 * existing parameters of the association (e.g. number of outbound
1513 * streams) into the INIT ACK and cookie.
1515 * After sending out the INIT ACK, the endpoint shall take no further
1516 * actions, i.e., the existing association, including its current state,
1517 * and the corresponding TCB MUST NOT be changed.
1519 * Note: Only when a TCB exists and the association is not in a COOKIE-
1520 * WAIT state are the Tie-Tags populated. For a normal association INIT
1521 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1522 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1523 * State Cookie are populated as specified in section 5.2.1.
1525 * Verification Tag: Not specified, but an INIT has no way of knowing
1526 * what the verification tag could be, so we ignore it.
1529 * (endpoint, asoc, chunk)
1532 * (asoc, reply_msg, msg_up, timers, counters)
1534 * The return value is the disposition of the chunk.
1536 sctp_disposition_t sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint *ep,
1537 const struct sctp_association *asoc,
1538 const sctp_subtype_t type,
1540 sctp_cmd_seq_t *commands)
1542 /* Call helper to do the real work for both simulataneous and
1543 * duplicate INIT chunk handling.
1545 return sctp_sf_do_unexpected_init(ep, asoc, type, arg, commands);
1550 * Unexpected INIT-ACK handler.
1553 * If an INIT ACK received by an endpoint in any state other than the
1554 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1555 * An unexpected INIT ACK usually indicates the processing of an old or
1556 * duplicated INIT chunk.
1558 sctp_disposition_t sctp_sf_do_5_2_3_initack(const struct sctp_endpoint *ep,
1559 const struct sctp_association *asoc,
1560 const sctp_subtype_t type,
1561 void *arg, sctp_cmd_seq_t *commands)
1563 /* Per the above section, we'll discard the chunk if we have an
1564 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1566 if (ep == sctp_sk((sctp_get_ctl_sock()))->ep)
1567 return sctp_sf_ootb(ep, asoc, type, arg, commands);
1569 return sctp_sf_discard_chunk(ep, asoc, type, arg, commands);
1572 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1575 * A) In this case, the peer may have restarted.
1577 static sctp_disposition_t sctp_sf_do_dupcook_a(const struct sctp_endpoint *ep,
1578 const struct sctp_association *asoc,
1579 struct sctp_chunk *chunk,
1580 sctp_cmd_seq_t *commands,
1581 struct sctp_association *new_asoc)
1583 sctp_init_chunk_t *peer_init;
1584 struct sctp_ulpevent *ev;
1585 struct sctp_chunk *repl;
1586 struct sctp_chunk *err;
1587 sctp_disposition_t disposition;
1589 /* new_asoc is a brand-new association, so these are not yet
1590 * side effects--it is safe to run them here.
1592 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1594 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1595 sctp_source(chunk), peer_init,
1599 /* Make sure no new addresses are being added during the
1600 * restart. Though this is a pretty complicated attack
1601 * since you'd have to get inside the cookie.
1603 if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands)) {
1604 return SCTP_DISPOSITION_CONSUME;
1607 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1608 * the peer has restarted (Action A), it MUST NOT setup a new
1609 * association but instead resend the SHUTDOWN ACK and send an ERROR
1610 * chunk with a "Cookie Received while Shutting Down" error cause to
1613 if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
1614 disposition = sctp_sf_do_9_2_reshutack(ep, asoc,
1615 SCTP_ST_CHUNK(chunk->chunk_hdr->type),
1617 if (SCTP_DISPOSITION_NOMEM == disposition)
1620 err = sctp_make_op_error(asoc, chunk,
1621 SCTP_ERROR_COOKIE_IN_SHUTDOWN,
1624 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
1627 return SCTP_DISPOSITION_CONSUME;
1630 /* For now, fail any unsent/unacked data. Consider the optional
1631 * choice of resending of this data.
1633 sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
1635 repl = sctp_make_cookie_ack(new_asoc, chunk);
1639 /* Report association restart to upper layer. */
1640 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
1641 new_asoc->c.sinit_num_ostreams,
1642 new_asoc->c.sinit_max_instreams,
1647 /* Update the content of current association. */
1648 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1649 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1650 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
1651 return SCTP_DISPOSITION_CONSUME;
1654 sctp_chunk_free(repl);
1656 return SCTP_DISPOSITION_NOMEM;
1659 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1662 * B) In this case, both sides may be attempting to start an association
1663 * at about the same time but the peer endpoint started its INIT
1664 * after responding to the local endpoint's INIT
1666 /* This case represents an initialization collision. */
1667 static sctp_disposition_t sctp_sf_do_dupcook_b(const struct sctp_endpoint *ep,
1668 const struct sctp_association *asoc,
1669 struct sctp_chunk *chunk,
1670 sctp_cmd_seq_t *commands,
1671 struct sctp_association *new_asoc)
1673 sctp_init_chunk_t *peer_init;
1674 struct sctp_chunk *repl;
1676 /* new_asoc is a brand-new association, so these are not yet
1677 * side effects--it is safe to run them here.
1679 peer_init = &chunk->subh.cookie_hdr->c.peer_init[0];
1680 if (!sctp_process_init(new_asoc, chunk->chunk_hdr->type,
1681 sctp_source(chunk), peer_init,
1685 /* Update the content of current association. */
1686 sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_ASSOC, SCTP_ASOC(new_asoc));
1687 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1688 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1689 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1690 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
1692 repl = sctp_make_cookie_ack(new_asoc, chunk);
1696 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1697 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1699 /* RFC 2960 5.1 Normal Establishment of an Association
1701 * D) IMPLEMENTATION NOTE: An implementation may choose to
1702 * send the Communication Up notification to the SCTP user
1703 * upon reception of a valid COOKIE ECHO chunk.
1705 * Sadly, this needs to be implemented as a side-effect, because
1706 * we are not guaranteed to have set the association id of the real
1707 * association and so these notifications need to be delayed until
1708 * the association id is allocated.
1711 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
1713 /* Sockets API Draft Section 5.3.1.6
1714 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1715 * delivers this notification to inform the application that of the
1716 * peers requested adaptation layer.
1718 * This also needs to be done as a side effect for the same reason as
1721 if (asoc->peer.adaptation_ind)
1722 sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
1724 return SCTP_DISPOSITION_CONSUME;
1727 return SCTP_DISPOSITION_NOMEM;
1730 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1733 * C) In this case, the local endpoint's cookie has arrived late.
1734 * Before it arrived, the local endpoint sent an INIT and received an
1735 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1736 * but a new tag of its own.
1738 /* This case represents an initialization collision. */
1739 static sctp_disposition_t sctp_sf_do_dupcook_c(const struct sctp_endpoint *ep,
1740 const struct sctp_association *asoc,
1741 struct sctp_chunk *chunk,
1742 sctp_cmd_seq_t *commands,
1743 struct sctp_association *new_asoc)
1745 /* The cookie should be silently discarded.
1746 * The endpoint SHOULD NOT change states and should leave
1747 * any timers running.
1749 return SCTP_DISPOSITION_DISCARD;
1752 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1756 * D) When both local and remote tags match the endpoint should always
1757 * enter the ESTABLISHED state, if it has not already done so.
1759 /* This case represents an initialization collision. */
1760 static sctp_disposition_t sctp_sf_do_dupcook_d(const struct sctp_endpoint *ep,
1761 const struct sctp_association *asoc,
1762 struct sctp_chunk *chunk,
1763 sctp_cmd_seq_t *commands,
1764 struct sctp_association *new_asoc)
1766 struct sctp_ulpevent *ev = NULL, *ai_ev = NULL;
1767 struct sctp_chunk *repl;
1769 /* Clarification from Implementor's Guide:
1770 * D) When both local and remote tags match the endpoint should
1771 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1772 * It should stop any cookie timer that may be running and send
1776 /* Don't accidentally move back into established state. */
1777 if (asoc->state < SCTP_STATE_ESTABLISHED) {
1778 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1779 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
1780 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
1781 SCTP_STATE(SCTP_STATE_ESTABLISHED));
1782 SCTP_INC_STATS(SCTP_MIB_CURRESTAB);
1783 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
1786 /* RFC 2960 5.1 Normal Establishment of an Association
1788 * D) IMPLEMENTATION NOTE: An implementation may choose
1789 * to send the Communication Up notification to the
1790 * SCTP user upon reception of a valid COOKIE
1793 ev = sctp_ulpevent_make_assoc_change(asoc, 0,
1795 asoc->c.sinit_num_ostreams,
1796 asoc->c.sinit_max_instreams,
1801 /* Sockets API Draft Section 5.3.1.6
1802 * When a peer sends a Adaptation Layer Indication parameter,
1803 * SCTP delivers this notification to inform the application
1804 * that of the peers requested adaptation layer.
1806 if (asoc->peer.adaptation_ind) {
1807 ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
1814 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1816 repl = sctp_make_cookie_ack(new_asoc, chunk);
1821 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1824 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
1825 SCTP_ULPEVENT(ai_ev));
1827 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
1828 sctp_add_cmd_sf(commands, SCTP_CMD_TRANSMIT, SCTP_NULL());
1830 return SCTP_DISPOSITION_CONSUME;
1834 sctp_ulpevent_free(ai_ev);
1836 sctp_ulpevent_free(ev);
1837 return SCTP_DISPOSITION_NOMEM;
1841 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1842 * chunk was retransmitted and then delayed in the network.
1844 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1846 * Verification Tag: None. Do cookie validation.
1849 * (endpoint, asoc, chunk)
1852 * (asoc, reply_msg, msg_up, timers, counters)
1854 * The return value is the disposition of the chunk.
1856 sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep,
1857 const struct sctp_association *asoc,
1858 const sctp_subtype_t type,
1860 sctp_cmd_seq_t *commands)
1862 sctp_disposition_t retval;
1863 struct sctp_chunk *chunk = arg;
1864 struct sctp_association *new_asoc;
1867 struct sctp_chunk *err_chk_p;
1869 /* Make sure that the chunk has a valid length from the protocol
1870 * perspective. In this case check to make sure we have at least
1871 * enough for the chunk header. Cookie length verification is
1874 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
1875 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
1878 /* "Decode" the chunk. We have no optional parameters so we
1879 * are in good shape.
1881 chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
1882 if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
1883 sizeof(sctp_chunkhdr_t)))
1886 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1887 * of a duplicate COOKIE ECHO match the Verification Tags of the
1888 * current association, consider the State Cookie valid even if
1889 * the lifespan is exceeded.
1891 new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
1895 * If the re-build failed, what is the proper error path
1898 * [We should abort the association. --piggy]
1901 /* FIXME: Several errors are possible. A bad cookie should
1902 * be silently discarded, but think about logging it too.
1905 case -SCTP_IERROR_NOMEM:
1908 case -SCTP_IERROR_STALE_COOKIE:
1909 sctp_send_stale_cookie_err(ep, asoc, chunk, commands,
1911 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1912 case -SCTP_IERROR_BAD_SIG:
1914 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1918 /* Compare the tie_tag in cookie with the verification tag of
1919 * current association.
1921 action = sctp_tietags_compare(new_asoc, asoc);
1924 case 'A': /* Association restart. */
1925 retval = sctp_sf_do_dupcook_a(ep, asoc, chunk, commands,
1929 case 'B': /* Collision case B. */
1930 retval = sctp_sf_do_dupcook_b(ep, asoc, chunk, commands,
1934 case 'C': /* Collision case C. */
1935 retval = sctp_sf_do_dupcook_c(ep, asoc, chunk, commands,
1939 case 'D': /* Collision case D. */
1940 retval = sctp_sf_do_dupcook_d(ep, asoc, chunk, commands,
1944 default: /* Discard packet for all others. */
1945 retval = sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1949 /* Delete the tempory new association. */
1950 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
1951 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
1956 return SCTP_DISPOSITION_NOMEM;
1960 * Process an ABORT. (SHUTDOWN-PENDING state)
1962 * See sctp_sf_do_9_1_abort().
1964 sctp_disposition_t sctp_sf_shutdown_pending_abort(
1965 const struct sctp_endpoint *ep,
1966 const struct sctp_association *asoc,
1967 const sctp_subtype_t type,
1969 sctp_cmd_seq_t *commands)
1971 struct sctp_chunk *chunk = arg;
1973 if (!sctp_vtag_verify_either(chunk, asoc))
1974 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1976 /* Make sure that the ABORT chunk has a valid length.
1977 * Since this is an ABORT chunk, we have to discard it
1978 * because of the following text:
1979 * RFC 2960, Section 3.3.7
1980 * If an endpoint receives an ABORT with a format error or for an
1981 * association that doesn't exist, it MUST silently discard it.
1982 * Becasue the length is "invalid", we can't really discard just
1983 * as we do not know its true length. So, to be safe, discard the
1986 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
1987 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
1989 /* Stop the T5-shutdown guard timer. */
1990 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
1991 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
1993 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
1997 * Process an ABORT. (SHUTDOWN-SENT state)
1999 * See sctp_sf_do_9_1_abort().
2001 sctp_disposition_t sctp_sf_shutdown_sent_abort(const struct sctp_endpoint *ep,
2002 const struct sctp_association *asoc,
2003 const sctp_subtype_t type,
2005 sctp_cmd_seq_t *commands)
2007 struct sctp_chunk *chunk = arg;
2009 if (!sctp_vtag_verify_either(chunk, asoc))
2010 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2012 /* Make sure that the ABORT chunk has a valid length.
2013 * Since this is an ABORT chunk, we have to discard it
2014 * because of the following text:
2015 * RFC 2960, Section 3.3.7
2016 * If an endpoint receives an ABORT with a format error or for an
2017 * association that doesn't exist, it MUST silently discard it.
2018 * Becasue the length is "invalid", we can't really discard just
2019 * as we do not know its true length. So, to be safe, discard the
2022 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2023 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2025 /* Stop the T2-shutdown timer. */
2026 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2027 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2029 /* Stop the T5-shutdown guard timer. */
2030 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2031 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
2033 return sctp_sf_do_9_1_abort(ep, asoc, type, arg, commands);
2037 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2039 * See sctp_sf_do_9_1_abort().
2041 sctp_disposition_t sctp_sf_shutdown_ack_sent_abort(
2042 const struct sctp_endpoint *ep,
2043 const struct sctp_association *asoc,
2044 const sctp_subtype_t type,
2046 sctp_cmd_seq_t *commands)
2048 /* The same T2 timer, so we should be able to use
2049 * common function with the SHUTDOWN-SENT state.
2051 return sctp_sf_shutdown_sent_abort(ep, asoc, type, arg, commands);
2055 * Handle an Error received in COOKIE_ECHOED state.
2057 * Only handle the error type of stale COOKIE Error, the other errors will
2061 * (endpoint, asoc, chunk)
2064 * (asoc, reply_msg, msg_up, timers, counters)
2066 * The return value is the disposition of the chunk.
2068 sctp_disposition_t sctp_sf_cookie_echoed_err(const struct sctp_endpoint *ep,
2069 const struct sctp_association *asoc,
2070 const sctp_subtype_t type,
2072 sctp_cmd_seq_t *commands)
2074 struct sctp_chunk *chunk = arg;
2077 if (!sctp_vtag_verify(chunk, asoc))
2078 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2080 /* Make sure that the ERROR chunk has a valid length.
2081 * The parameter walking depends on this as well.
2083 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2084 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2087 /* Process the error here */
2088 /* FUTURE FIXME: When PR-SCTP related and other optional
2089 * parms are emitted, this will have to change to handle multiple
2092 sctp_walk_errors(err, chunk->chunk_hdr) {
2093 if (SCTP_ERROR_STALE_COOKIE == err->cause)
2094 return sctp_sf_do_5_2_6_stale(ep, asoc, type,
2098 /* It is possible to have malformed error causes, and that
2099 * will cause us to end the walk early. However, since
2100 * we are discarding the packet, there should be no adverse
2103 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2107 * Handle a Stale COOKIE Error
2109 * Section: 5.2.6 Handle Stale COOKIE Error
2110 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2111 * one of the following three alternatives.
2113 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2114 * Preservative parameter requesting an extension to the lifetime of
2115 * the State Cookie. When calculating the time extension, an
2116 * implementation SHOULD use the RTT information measured based on the
2117 * previous COOKIE ECHO / ERROR exchange, and should add no more
2118 * than 1 second beyond the measured RTT, due to long State Cookie
2119 * lifetimes making the endpoint more subject to a replay attack.
2121 * Verification Tag: Not explicit, but safe to ignore.
2124 * (endpoint, asoc, chunk)
2127 * (asoc, reply_msg, msg_up, timers, counters)
2129 * The return value is the disposition of the chunk.
2131 static sctp_disposition_t sctp_sf_do_5_2_6_stale(const struct sctp_endpoint *ep,
2132 const struct sctp_association *asoc,
2133 const sctp_subtype_t type,
2135 sctp_cmd_seq_t *commands)
2137 struct sctp_chunk *chunk = arg;
2139 sctp_cookie_preserve_param_t bht;
2141 struct sctp_chunk *reply;
2142 struct sctp_bind_addr *bp;
2143 int attempts = asoc->init_err_counter + 1;
2145 if (attempts > asoc->max_init_attempts) {
2146 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
2147 SCTP_ERROR(ETIMEDOUT));
2148 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2149 SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
2150 return SCTP_DISPOSITION_DELETE_TCB;
2153 err = (sctp_errhdr_t *)(chunk->skb->data);
2155 /* When calculating the time extension, an implementation
2156 * SHOULD use the RTT information measured based on the
2157 * previous COOKIE ECHO / ERROR exchange, and should add no
2158 * more than 1 second beyond the measured RTT, due to long
2159 * State Cookie lifetimes making the endpoint more subject to
2161 * Measure of Staleness's unit is usec. (1/1000000 sec)
2162 * Suggested Cookie Life-span Increment's unit is msec.
2164 * In general, if you use the suggested cookie life, the value
2165 * found in the field of measure of staleness should be doubled
2166 * to give ample time to retransmit the new cookie and thus
2167 * yield a higher probability of success on the reattempt.
2169 stale = ntohl(*(__be32 *)((u8 *)err + sizeof(sctp_errhdr_t)));
2170 stale = (stale * 2) / 1000;
2172 bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
2173 bht.param_hdr.length = htons(sizeof(bht));
2174 bht.lifespan_increment = htonl(stale);
2176 /* Build that new INIT chunk. */
2177 bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
2178 reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
2182 sctp_addto_chunk(reply, sizeof(bht), &bht);
2184 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2185 sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
2187 /* Stop pending T3-rtx and heartbeat timers */
2188 sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
2189 sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
2191 /* Delete non-primary peer ip addresses since we are transitioning
2192 * back to the COOKIE-WAIT state
2194 sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
2196 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2199 sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN,
2200 SCTP_TRANSPORT(asoc->peer.primary_path));
2202 /* Cast away the const modifier, as we want to just
2203 * rerun it through as a sideffect.
2205 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
2207 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2208 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
2209 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2210 SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
2211 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
2212 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2214 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2216 return SCTP_DISPOSITION_CONSUME;
2219 return SCTP_DISPOSITION_NOMEM;
2226 * After checking the Verification Tag, the receiving endpoint shall
2227 * remove the association from its record, and shall report the
2228 * termination to its upper layer.
2230 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2231 * B) Rules for packet carrying ABORT:
2233 * - The endpoint shall always fill in the Verification Tag field of the
2234 * outbound packet with the destination endpoint's tag value if it
2237 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2238 * MUST follow the procedure described in Section 8.4.
2240 * - The receiver MUST accept the packet if the Verification Tag
2241 * matches either its own tag, OR the tag of its peer. Otherwise, the
2242 * receiver MUST silently discard the packet and take no further
2246 * (endpoint, asoc, chunk)
2249 * (asoc, reply_msg, msg_up, timers, counters)
2251 * The return value is the disposition of the chunk.
2253 sctp_disposition_t sctp_sf_do_9_1_abort(const struct sctp_endpoint *ep,
2254 const struct sctp_association *asoc,
2255 const sctp_subtype_t type,
2257 sctp_cmd_seq_t *commands)
2259 struct sctp_chunk *chunk = arg;
2261 __be16 error = SCTP_ERROR_NO_ERROR;
2263 if (!sctp_vtag_verify_either(chunk, asoc))
2264 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2266 /* Make sure that the ABORT chunk has a valid length.
2267 * Since this is an ABORT chunk, we have to discard it
2268 * because of the following text:
2269 * RFC 2960, Section 3.3.7
2270 * If an endpoint receives an ABORT with a format error or for an
2271 * association that doesn't exist, it MUST silently discard it.
2272 * Becasue the length is "invalid", we can't really discard just
2273 * as we do not know its true length. So, to be safe, discard the
2276 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2277 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2279 /* See if we have an error cause code in the chunk. */
2280 len = ntohs(chunk->chunk_hdr->length);
2281 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2282 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2284 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
2285 /* ASSOC_FAILED will DELETE_TCB. */
2286 sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
2287 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2288 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
2290 return SCTP_DISPOSITION_ABORT;
2294 * Process an ABORT. (COOKIE-WAIT state)
2296 * See sctp_sf_do_9_1_abort() above.
2298 sctp_disposition_t sctp_sf_cookie_wait_abort(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;
2306 __be16 error = SCTP_ERROR_NO_ERROR;
2308 if (!sctp_vtag_verify_either(chunk, asoc))
2309 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2311 /* Make sure that the ABORT chunk has a valid length.
2312 * Since this is an ABORT chunk, we have to discard it
2313 * because of the following text:
2314 * RFC 2960, Section 3.3.7
2315 * If an endpoint receives an ABORT with a format error or for an
2316 * association that doesn't exist, it MUST silently discard it.
2317 * Becasue the length is "invalid", we can't really discard just
2318 * as we do not know its true length. So, to be safe, discard the
2321 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_abort_chunk_t)))
2322 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2324 /* See if we have an error cause code in the chunk. */
2325 len = ntohs(chunk->chunk_hdr->length);
2326 if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
2327 error = ((sctp_errhdr_t *)chunk->skb->data)->cause;
2329 return sctp_stop_t1_and_abort(commands, error, ECONNREFUSED, asoc,
2334 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2336 sctp_disposition_t sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint *ep,
2337 const struct sctp_association *asoc,
2338 const sctp_subtype_t type,
2340 sctp_cmd_seq_t *commands)
2342 return sctp_stop_t1_and_abort(commands, SCTP_ERROR_NO_ERROR,
2344 (struct sctp_transport *)arg);
2348 * Process an ABORT. (COOKIE-ECHOED state)
2350 sctp_disposition_t sctp_sf_cookie_echoed_abort(const struct sctp_endpoint *ep,
2351 const struct sctp_association *asoc,
2352 const sctp_subtype_t type,
2354 sctp_cmd_seq_t *commands)
2356 /* There is a single T1 timer, so we should be able to use
2357 * common function with the COOKIE-WAIT state.
2359 return sctp_sf_cookie_wait_abort(ep, asoc, type, arg, commands);
2363 * Stop T1 timer and abort association with "INIT failed".
2365 * This is common code called by several sctp_sf_*_abort() functions above.
2367 static sctp_disposition_t sctp_stop_t1_and_abort(sctp_cmd_seq_t *commands,
2368 __be16 error, int sk_err,
2369 const struct sctp_association *asoc,
2370 struct sctp_transport *transport)
2372 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2373 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2374 SCTP_STATE(SCTP_STATE_CLOSED));
2375 SCTP_INC_STATS(SCTP_MIB_ABORTEDS);
2376 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
2377 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
2378 sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
2379 /* CMD_INIT_FAILED will DELETE_TCB. */
2380 sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
2382 return SCTP_DISPOSITION_ABORT;
2386 * sctp_sf_do_9_2_shut
2389 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2390 * - enter the SHUTDOWN-RECEIVED state,
2392 * - stop accepting new data from its SCTP user
2394 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2395 * that all its outstanding DATA chunks have been received by the
2398 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2399 * send a SHUTDOWN in response to a ULP request. And should discard
2400 * subsequent SHUTDOWN chunks.
2402 * If there are still outstanding DATA chunks left, the SHUTDOWN
2403 * receiver shall continue to follow normal data transmission
2404 * procedures defined in Section 6 until all outstanding DATA chunks
2405 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2406 * new data from its SCTP user.
2408 * Verification Tag: 8.5 Verification Tag [Normal verification]
2411 * (endpoint, asoc, chunk)
2414 * (asoc, reply_msg, msg_up, timers, counters)
2416 * The return value is the disposition of the chunk.
2418 sctp_disposition_t sctp_sf_do_9_2_shutdown(const struct sctp_endpoint *ep,
2419 const struct sctp_association *asoc,
2420 const sctp_subtype_t type,
2422 sctp_cmd_seq_t *commands)
2424 struct sctp_chunk *chunk = arg;
2425 sctp_shutdownhdr_t *sdh;
2426 sctp_disposition_t disposition;
2427 struct sctp_ulpevent *ev;
2429 if (!sctp_vtag_verify(chunk, asoc))
2430 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2432 /* Make sure that the SHUTDOWN chunk has a valid length. */
2433 if (!sctp_chunk_length_valid(chunk,
2434 sizeof(struct sctp_shutdown_chunk_t)))
2435 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2438 /* Convert the elaborate header. */
2439 sdh = (sctp_shutdownhdr_t *)chunk->skb->data;
2440 skb_pull(chunk->skb, sizeof(sctp_shutdownhdr_t));
2441 chunk->subh.shutdown_hdr = sdh;
2443 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2444 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2445 * inform the application that it should cease sending data.
2447 ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
2449 disposition = SCTP_DISPOSITION_NOMEM;
2452 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
2454 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2455 * - enter the SHUTDOWN-RECEIVED state,
2456 * - stop accepting new data from its SCTP user
2458 * [This is implicit in the new state.]
2460 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
2461 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
2462 disposition = SCTP_DISPOSITION_CONSUME;
2464 if (sctp_outq_is_empty(&asoc->outqueue)) {
2465 disposition = sctp_sf_do_9_2_shutdown_ack(ep, asoc, type,
2469 if (SCTP_DISPOSITION_NOMEM == disposition)
2472 /* - verify, by checking the Cumulative TSN Ack field of the
2473 * chunk, that all its outstanding DATA chunks have been
2474 * received by the SHUTDOWN sender.
2476 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
2477 SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
2484 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2485 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2486 * transport addresses (either in the IP addresses or in the INIT chunk)
2487 * that belong to this association, it should discard the INIT chunk and
2488 * retransmit the SHUTDOWN ACK chunk.
2490 sctp_disposition_t sctp_sf_do_9_2_reshutack(const struct sctp_endpoint *ep,
2491 const struct sctp_association *asoc,
2492 const sctp_subtype_t type,
2494 sctp_cmd_seq_t *commands)
2496 struct sctp_chunk *chunk = (struct sctp_chunk *) arg;
2497 struct sctp_chunk *reply;
2499 /* Since we are not going to really process this INIT, there
2500 * is no point in verifying chunk boundries. Just generate
2503 reply = sctp_make_shutdown_ack(asoc, chunk);
2507 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2508 * the T2-SHUTDOWN timer.
2510 sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
2512 /* and restart the T2-shutdown timer. */
2513 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2514 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2516 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
2518 return SCTP_DISPOSITION_CONSUME;
2520 return SCTP_DISPOSITION_NOMEM;
2524 * sctp_sf_do_ecn_cwr
2526 * Section: Appendix A: Explicit Congestion Notification
2530 * RFC 2481 details a specific bit for a sender to send in the header of
2531 * its next outbound TCP segment to indicate to its peer that it has
2532 * reduced its congestion window. This is termed the CWR bit. For
2533 * SCTP the same indication is made by including the CWR chunk.
2534 * This chunk contains one data element, i.e. the TSN number that
2535 * was sent in the ECNE chunk. This element represents the lowest
2536 * TSN number in the datagram that was originally marked with the
2539 * Verification Tag: 8.5 Verification Tag [Normal verification]
2541 * (endpoint, asoc, chunk)
2544 * (asoc, reply_msg, msg_up, timers, counters)
2546 * The return value is the disposition of the chunk.
2548 sctp_disposition_t sctp_sf_do_ecn_cwr(const struct sctp_endpoint *ep,
2549 const struct sctp_association *asoc,
2550 const sctp_subtype_t type,
2552 sctp_cmd_seq_t *commands)
2555 struct sctp_chunk *chunk = arg;
2558 if (!sctp_vtag_verify(chunk, asoc))
2559 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2561 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2562 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2565 cwr = (sctp_cwrhdr_t *) chunk->skb->data;
2566 skb_pull(chunk->skb, sizeof(sctp_cwrhdr_t));
2568 lowest_tsn = ntohl(cwr->lowest_tsn);
2570 /* Does this CWR ack the last sent congestion notification? */
2571 if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
2572 /* Stop sending ECNE. */
2573 sctp_add_cmd_sf(commands,
2575 SCTP_U32(lowest_tsn));
2577 return SCTP_DISPOSITION_CONSUME;
2583 * Section: Appendix A: Explicit Congestion Notification
2587 * RFC 2481 details a specific bit for a receiver to send back in its
2588 * TCP acknowledgements to notify the sender of the Congestion
2589 * Experienced (CE) bit having arrived from the network. For SCTP this
2590 * same indication is made by including the ECNE chunk. This chunk
2591 * contains one data element, i.e. the lowest TSN associated with the IP
2592 * datagram marked with the CE bit.....
2594 * Verification Tag: 8.5 Verification Tag [Normal verification]
2596 * (endpoint, asoc, chunk)
2599 * (asoc, reply_msg, msg_up, timers, counters)
2601 * The return value is the disposition of the chunk.
2603 sctp_disposition_t sctp_sf_do_ecne(const struct sctp_endpoint *ep,
2604 const struct sctp_association *asoc,
2605 const sctp_subtype_t type,
2607 sctp_cmd_seq_t *commands)
2609 sctp_ecnehdr_t *ecne;
2610 struct sctp_chunk *chunk = arg;
2612 if (!sctp_vtag_verify(chunk, asoc))
2613 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2615 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_ecne_chunk_t)))
2616 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2619 ecne = (sctp_ecnehdr_t *) chunk->skb->data;
2620 skb_pull(chunk->skb, sizeof(sctp_ecnehdr_t));
2622 /* If this is a newer ECNE than the last CWR packet we sent out */
2623 sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
2624 SCTP_U32(ntohl(ecne->lowest_tsn)));
2626 return SCTP_DISPOSITION_CONSUME;
2630 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2632 * The SCTP endpoint MUST always acknowledge the reception of each valid
2635 * The guidelines on delayed acknowledgement algorithm specified in
2636 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2637 * acknowledgement SHOULD be generated for at least every second packet
2638 * (not every second DATA chunk) received, and SHOULD be generated within
2639 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2640 * situations it may be beneficial for an SCTP transmitter to be more
2641 * conservative than the algorithms detailed in this document allow.
2642 * However, an SCTP transmitter MUST NOT be more aggressive than the
2643 * following algorithms allow.
2645 * A SCTP receiver MUST NOT generate more than one SACK for every
2646 * incoming packet, other than to update the offered window as the
2647 * receiving application consumes new data.
2649 * Verification Tag: 8.5 Verification Tag [Normal verification]
2652 * (endpoint, asoc, chunk)
2655 * (asoc, reply_msg, msg_up, timers, counters)
2657 * The return value is the disposition of the chunk.
2659 sctp_disposition_t sctp_sf_eat_data_6_2(const struct sctp_endpoint *ep,
2660 const struct sctp_association *asoc,
2661 const sctp_subtype_t type,
2663 sctp_cmd_seq_t *commands)
2665 struct sctp_chunk *chunk = arg;
2668 if (!sctp_vtag_verify(chunk, asoc)) {
2669 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2671 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2674 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2675 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2678 error = sctp_eat_data(asoc, chunk, commands );
2680 case SCTP_IERROR_NO_ERROR:
2682 case SCTP_IERROR_HIGH_TSN:
2683 case SCTP_IERROR_BAD_STREAM:
2684 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2685 goto discard_noforce;
2686 case SCTP_IERROR_DUP_TSN:
2687 case SCTP_IERROR_IGNORE_TSN:
2688 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
2690 case SCTP_IERROR_NO_DATA:
2696 if (asoc->autoclose) {
2697 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2698 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
2701 /* If this is the last chunk in a packet, we need to count it
2702 * toward sack generation. Note that we need to SACK every
2703 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2704 * THEM. We elect to NOT generate SACK's if the chunk fails
2705 * the verification tag test.
2707 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2709 * The SCTP endpoint MUST always acknowledge the reception of
2710 * each valid DATA chunk.
2712 * The guidelines on delayed acknowledgement algorithm
2713 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2714 * Specifically, an acknowledgement SHOULD be generated for at
2715 * least every second packet (not every second DATA chunk)
2716 * received, and SHOULD be generated within 200 ms of the
2717 * arrival of any unacknowledged DATA chunk. In some
2718 * situations it may be beneficial for an SCTP transmitter to
2719 * be more conservative than the algorithms detailed in this
2720 * document allow. However, an SCTP transmitter MUST NOT be
2721 * more aggressive than the following algorithms allow.
2723 if (chunk->end_of_packet)
2724 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2726 return SCTP_DISPOSITION_CONSUME;
2729 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2731 * When a packet arrives with duplicate DATA chunk(s) and with
2732 * no new DATA chunk(s), the endpoint MUST immediately send a
2733 * SACK with no delay. If a packet arrives with duplicate
2734 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2735 * MAY immediately send a SACK. Normally receipt of duplicate
2736 * DATA chunks will occur when the original SACK chunk was lost
2737 * and the peer's RTO has expired. The duplicate TSN number(s)
2738 * SHOULD be reported in the SACK as duplicate.
2740 /* In our case, we split the MAY SACK advice up whether or not
2741 * the last chunk is a duplicate.'
2743 if (chunk->end_of_packet)
2744 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2745 return SCTP_DISPOSITION_DISCARD;
2748 if (chunk->end_of_packet)
2749 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
2751 return SCTP_DISPOSITION_DISCARD;
2753 return SCTP_DISPOSITION_CONSUME;
2758 * sctp_sf_eat_data_fast_4_4
2761 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2762 * DATA chunks without delay.
2764 * Verification Tag: 8.5 Verification Tag [Normal verification]
2766 * (endpoint, asoc, chunk)
2769 * (asoc, reply_msg, msg_up, timers, counters)
2771 * The return value is the disposition of the chunk.
2773 sctp_disposition_t sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint *ep,
2774 const struct sctp_association *asoc,
2775 const sctp_subtype_t type,
2777 sctp_cmd_seq_t *commands)
2779 struct sctp_chunk *chunk = arg;
2782 if (!sctp_vtag_verify(chunk, asoc)) {
2783 sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
2785 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2788 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_data_chunk_t)))
2789 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2792 error = sctp_eat_data(asoc, chunk, commands );
2794 case SCTP_IERROR_NO_ERROR:
2795 case SCTP_IERROR_HIGH_TSN:
2796 case SCTP_IERROR_DUP_TSN:
2797 case SCTP_IERROR_IGNORE_TSN:
2798 case SCTP_IERROR_BAD_STREAM:
2800 case SCTP_IERROR_NO_DATA:
2806 /* Go a head and force a SACK, since we are shutting down. */
2808 /* Implementor's Guide.
2810 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2811 * respond to each received packet containing one or more DATA chunk(s)
2812 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2814 if (chunk->end_of_packet) {
2815 /* We must delay the chunk creation since the cumulative
2816 * TSN has not been updated yet.
2818 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
2819 sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
2820 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
2821 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
2825 return SCTP_DISPOSITION_CONSUME;
2829 * Section: 6.2 Processing a Received SACK
2830 * D) Any time a SACK arrives, the endpoint performs the following:
2832 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2833 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2834 * increasing, a SACK whose Cumulative TSN Ack is less than the
2835 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2837 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2838 * of bytes still outstanding after processing the Cumulative TSN Ack
2839 * and the Gap Ack Blocks.
2841 * iii) If the SACK is missing a TSN that was previously
2842 * acknowledged via a Gap Ack Block (e.g., the data receiver
2843 * reneged on the data), then mark the corresponding DATA chunk
2844 * as available for retransmit: Mark it as missing for fast
2845 * retransmit as described in Section 7.2.4 and if no retransmit
2846 * timer is running for the destination address to which the DATA
2847 * chunk was originally transmitted, then T3-rtx is started for
2848 * that destination address.
2850 * Verification Tag: 8.5 Verification Tag [Normal verification]
2853 * (endpoint, asoc, chunk)
2856 * (asoc, reply_msg, msg_up, timers, counters)
2858 * The return value is the disposition of the chunk.
2860 sctp_disposition_t sctp_sf_eat_sack_6_2(const struct sctp_endpoint *ep,
2861 const struct sctp_association *asoc,
2862 const sctp_subtype_t type,
2864 sctp_cmd_seq_t *commands)
2866 struct sctp_chunk *chunk = arg;
2867 sctp_sackhdr_t *sackh;
2870 if (!sctp_vtag_verify(chunk, asoc))
2871 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2873 /* Make sure that the SACK chunk has a valid length. */
2874 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_sack_chunk_t)))
2875 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2878 /* Pull the SACK chunk from the data buffer */
2879 sackh = sctp_sm_pull_sack(chunk);
2880 /* Was this a bogus SACK? */
2882 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2883 chunk->subh.sack_hdr = sackh;
2884 ctsn = ntohl(sackh->cum_tsn_ack);
2886 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2887 * Ack Point, then drop the SACK. Since Cumulative TSN
2888 * Ack is monotonically increasing, a SACK whose
2889 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2890 * Point indicates an out-of-order SACK.
2892 if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
2893 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn);
2894 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc->ctsn_ack_point);
2895 return SCTP_DISPOSITION_DISCARD;
2898 /* If Cumulative TSN Ack beyond the max tsn currently
2899 * send, terminating the association and respond to the
2900 * sender with an ABORT.
2902 if (!TSN_lt(ctsn, asoc->next_tsn))
2903 return sctp_sf_violation_ctsn(ep, asoc, type, arg, commands);
2905 /* Return this SACK for further processing. */
2906 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_SACKH(sackh));
2908 /* Note: We do the rest of the work on the PROCESS_SACK
2911 return SCTP_DISPOSITION_CONSUME;
2915 * Generate an ABORT in response to a packet.
2917 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2919 * 8) The receiver should respond to the sender of the OOTB packet with
2920 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2921 * MUST fill in the Verification Tag field of the outbound packet
2922 * with the value found in the Verification Tag field of the OOTB
2923 * packet and set the T-bit in the Chunk Flags to indicate that the
2924 * Verification Tag is reflected. After sending this ABORT, the
2925 * receiver of the OOTB packet shall discard the OOTB packet and take
2926 * no further action.
2930 * The return value is the disposition of the chunk.
2932 sctp_disposition_t sctp_sf_tabort_8_4_8(const struct sctp_endpoint *ep,
2933 const struct sctp_association *asoc,
2934 const sctp_subtype_t type,
2936 sctp_cmd_seq_t *commands)
2938 struct sctp_packet *packet = NULL;
2939 struct sctp_chunk *chunk = arg;
2940 struct sctp_chunk *abort;
2942 packet = sctp_ootb_pkt_new(asoc, chunk);
2945 /* Make an ABORT. The T bit will be set if the asoc
2948 abort = sctp_make_abort(asoc, chunk, 0);
2950 sctp_ootb_pkt_free(packet);
2951 return SCTP_DISPOSITION_NOMEM;
2954 /* Reflect vtag if T-Bit is set */
2955 if (sctp_test_T_bit(abort))
2956 packet->vtag = ntohl(chunk->sctp_hdr->vtag);
2958 /* Set the skb to the belonging sock for accounting. */
2959 abort->skb->sk = ep->base.sk;
2961 sctp_packet_append_chunk(packet, abort);
2963 sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
2964 SCTP_PACKET(packet));
2966 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS);
2968 return SCTP_DISPOSITION_CONSUME;
2971 return SCTP_DISPOSITION_NOMEM;
2975 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2976 * event as ULP notification for each cause included in the chunk.
2978 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2980 * The return value is the disposition of the chunk.
2982 sctp_disposition_t sctp_sf_operr_notify(const struct sctp_endpoint *ep,
2983 const struct sctp_association *asoc,
2984 const sctp_subtype_t type,
2986 sctp_cmd_seq_t *commands)
2988 struct sctp_chunk *chunk = arg;
2989 struct sctp_ulpevent *ev;
2991 if (!sctp_vtag_verify(chunk, asoc))
2992 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
2994 /* Make sure that the ERROR chunk has a valid length. */
2995 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_operr_chunk_t)))
2996 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
2999 while (chunk->chunk_end > chunk->skb->data) {
3000 ev = sctp_ulpevent_make_remote_error(asoc, chunk, 0,
3005 if (!sctp_add_cmd(commands, SCTP_CMD_EVENT_ULP,
3006 SCTP_ULPEVENT(ev))) {
3007 sctp_ulpevent_free(ev);
3011 sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
3014 return SCTP_DISPOSITION_CONSUME;
3017 return SCTP_DISPOSITION_NOMEM;
3021 * Process an inbound SHUTDOWN ACK.
3024 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3025 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3026 * peer, and remove all record of the association.
3028 * The return value is the disposition.
3030 sctp_disposition_t sctp_sf_do_9_2_final(const struct sctp_endpoint *ep,
3031 const struct sctp_association *asoc,
3032 const sctp_subtype_t type,
3034 sctp_cmd_seq_t *commands)
3036 struct sctp_chunk *chunk = arg;
3037 struct sctp_chunk *reply;
3038 struct sctp_ulpevent *ev;
3040 if (!sctp_vtag_verify(chunk, asoc))
3041 return sctp_sf_pdiscard(ep, asoc, type, arg, commands);
3043 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3044 if (!sctp_chunk_length_valid(chunk, sizeof(sctp_chunkhdr_t)))
3045 return sctp_sf_violation_chunklen(ep, asoc, type, arg,
3047 /* 10.2 H) SHUTDOWN COMPLETE notification
3049 * When SCTP completes the shutdown procedures (section 9.2) this
3050 * notification is passed to the upper layer.
3052 ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
3053 0, 0, 0, NULL, GFP_ATOMIC);
3057 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3058 reply = sctp_make_shutdown_complete(asoc, chunk);
3062 /* Do all the commands now (after allocation), so that we
3063 * have consistent state if memory allocation failes
3065 sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
3067 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3068 * stop the T2-shutdown timer,
3070 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3071 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
3073 sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
3074 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
3076 sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
3077 SCTP_STATE(SCTP_STATE_CLOSED));
3078 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS);
3079 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB);
3080 sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
3082 /* ...and remove all record of the association. */
3083 sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
3084 return SCTP_DISPOSITION_DELETE_TCB;
3087 sctp_ulpevent_free(ev);
3089 return SCTP_DISPOSITION_NOMEM;
3093 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3095 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3096 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3097 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3098 * packet must fill in the Verification Tag field of the outbound
3099 * packet with the Verification Tag received in the SHUTDOWN ACK and
3100 * set the T-bit in the Chunk Flags to indicate that the Verification
3103 * 8) The receiver should respond to the sender of the OOTB packet with
3104 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3105 * MUST fill in the Verification Tag field of the outbound packet
3106 * with the value found in the Verification Tag field of the OOTB
3107 * packet and set the T-bit in the Chunk Flags to indicate that the
3108 * Verification Tag is reflected. After sending this ABORT, the
3109 * receiver of the OOTB packet shall discard the OOTB packet and take
3110 * no further action.
3112 sctp_disposition_t sctp_sf_ootb(const struct sctp_endpoint *ep,
3113 const struct sctp_association *asoc,
3114 const sctp_subtype_t type,
3116 sctp_cmd_seq_t *commands)