1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
69 const struct sctp_association
*asoc
,
70 struct sctp_chunk
*chunk
,
73 static int sctp_eat_data(const struct sctp_association
*asoc
,
74 struct sctp_chunk
*chunk
,
75 sctp_cmd_seq_t
*commands
);
76 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
77 const struct sctp_chunk
*chunk
);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
79 const struct sctp_association
*asoc
,
80 const struct sctp_chunk
*chunk
,
81 sctp_cmd_seq_t
*commands
,
82 struct sctp_chunk
*err_chunk
);
83 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
84 const struct sctp_association
*asoc
,
85 const sctp_subtype_t type
,
87 sctp_cmd_seq_t
*commands
);
88 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
89 const struct sctp_association
*asoc
,
90 const sctp_subtype_t type
,
92 sctp_cmd_seq_t
*commands
);
93 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
94 const struct sctp_association
*asoc
,
95 const sctp_subtype_t type
,
97 sctp_cmd_seq_t
*commands
);
98 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
100 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
101 __be16 error
, int sk_err
,
102 const struct sctp_association
*asoc
,
103 struct sctp_transport
*transport
);
105 static sctp_disposition_t
sctp_sf_abort_violation(
106 const struct sctp_endpoint
*ep
,
107 const struct sctp_association
*asoc
,
109 sctp_cmd_seq_t
*commands
,
111 const size_t paylen
);
113 static sctp_disposition_t
sctp_sf_violation_chunklen(
114 const struct sctp_endpoint
*ep
,
115 const struct sctp_association
*asoc
,
116 const sctp_subtype_t type
,
118 sctp_cmd_seq_t
*commands
);
120 static sctp_disposition_t
sctp_sf_violation_paramlen(
121 const struct sctp_endpoint
*ep
,
122 const struct sctp_association
*asoc
,
123 const sctp_subtype_t type
,
125 sctp_cmd_seq_t
*commands
);
127 static sctp_disposition_t
sctp_sf_violation_ctsn(
128 const struct sctp_endpoint
*ep
,
129 const struct sctp_association
*asoc
,
130 const sctp_subtype_t type
,
132 sctp_cmd_seq_t
*commands
);
134 static sctp_disposition_t
sctp_sf_violation_chunk(
135 const struct sctp_endpoint
*ep
,
136 const struct sctp_association
*asoc
,
137 const sctp_subtype_t type
,
139 sctp_cmd_seq_t
*commands
);
141 /* Small helper function that checks if the chunk length
142 * is of the appropriate length. The 'required_length' argument
143 * is set to be the size of a specific chunk we are testing.
144 * Return Values: 1 = Valid length
149 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
150 __u16 required_length
)
152 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
154 if (unlikely(chunk_length
< required_length
))
160 /**********************************************************
161 * These are the state functions for handling chunk events.
162 **********************************************************/
165 * Process the final SHUTDOWN COMPLETE.
167 * Section: 4 (C) (diagram), 9.2
168 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
169 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
170 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
171 * should stop the T2-shutdown timer and remove all knowledge of the
172 * association (and thus the association enters the CLOSED state).
174 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
175 * C) Rules for packet carrying SHUTDOWN COMPLETE:
177 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
178 * if the Verification Tag field of the packet matches its own tag and
179 * the T bit is not set
181 * it is set to its peer's tag and the T bit is set in the Chunk
183 * Otherwise, the receiver MUST silently discard the packet
184 * and take no further action. An endpoint MUST ignore the
185 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
188 * (endpoint, asoc, chunk)
191 * (asoc, reply_msg, msg_up, timers, counters)
193 * The return value is the disposition of the chunk.
195 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
196 const struct sctp_association
*asoc
,
197 const sctp_subtype_t type
,
199 sctp_cmd_seq_t
*commands
)
201 struct sctp_chunk
*chunk
= arg
;
202 struct sctp_ulpevent
*ev
;
204 if (!sctp_vtag_verify_either(chunk
, asoc
))
205 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
207 /* RFC 2960 6.10 Bundling
209 * An endpoint MUST NOT bundle INIT, INIT ACK or
210 * SHUTDOWN COMPLETE with any other chunks.
212 if (!chunk
->singleton
)
213 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
215 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
216 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
217 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
220 /* RFC 2960 10.2 SCTP-to-ULP
222 * H) SHUTDOWN COMPLETE notification
224 * When SCTP completes the shutdown procedures (section 9.2) this
225 * notification is passed to the upper layer.
227 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
228 0, 0, 0, NULL
, GFP_ATOMIC
);
230 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
233 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
234 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
235 * not the chunk should be discarded. If the endpoint is in
236 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
237 * T2-shutdown timer and remove all knowledge of the
238 * association (and thus the association enters the CLOSED
241 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
242 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
244 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
245 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
247 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
248 SCTP_STATE(SCTP_STATE_CLOSED
));
250 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
251 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
253 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
255 return SCTP_DISPOSITION_DELETE_TCB
;
259 * Respond to a normal INIT chunk.
260 * We are the side that is being asked for an association.
262 * Section: 5.1 Normal Establishment of an Association, B
263 * B) "Z" shall respond immediately with an INIT ACK chunk. The
264 * destination IP address of the INIT ACK MUST be set to the source
265 * IP address of the INIT to which this INIT ACK is responding. In
266 * the response, besides filling in other parameters, "Z" must set the
267 * Verification Tag field to Tag_A, and also provide its own
268 * Verification Tag (Tag_Z) in the Initiate Tag field.
270 * Verification Tag: Must be 0.
273 * (endpoint, asoc, chunk)
276 * (asoc, reply_msg, msg_up, timers, counters)
278 * The return value is the disposition of the chunk.
280 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
281 const struct sctp_association
*asoc
,
282 const sctp_subtype_t type
,
284 sctp_cmd_seq_t
*commands
)
286 struct sctp_chunk
*chunk
= arg
;
287 struct sctp_chunk
*repl
;
288 struct sctp_association
*new_asoc
;
289 struct sctp_chunk
*err_chunk
;
290 struct sctp_packet
*packet
;
291 sctp_unrecognized_param_t
*unk_param
;
295 * An endpoint MUST NOT bundle INIT, INIT ACK or
296 * SHUTDOWN COMPLETE with any other chunks.
299 * Furthermore, we require that the receiver of an INIT chunk MUST
300 * enforce these rules by silently discarding an arriving packet
301 * with an INIT chunk that is bundled with other chunks.
303 if (!chunk
->singleton
)
304 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
306 /* If the packet is an OOTB packet which is temporarily on the
307 * control endpoint, respond with an ABORT.
309 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
310 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
312 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
315 if (chunk
->sctp_hdr
->vtag
!= 0)
316 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
318 /* Make sure that the INIT chunk has a valid length.
319 * Normally, this would cause an ABORT with a Protocol Violation
320 * error, but since we don't have an association, we'll
321 * just discard the packet.
323 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
324 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
326 /* Verify the INIT chunk before processing it. */
328 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
329 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
331 /* This chunk contains fatal error. It is to be discarded.
332 * Send an ABORT, with causes if there is any.
335 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
336 (__u8
*)(err_chunk
->chunk_hdr
) +
337 sizeof(sctp_chunkhdr_t
),
338 ntohs(err_chunk
->chunk_hdr
->length
) -
339 sizeof(sctp_chunkhdr_t
));
341 sctp_chunk_free(err_chunk
);
344 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
345 SCTP_PACKET(packet
));
346 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
347 return SCTP_DISPOSITION_CONSUME
;
349 return SCTP_DISPOSITION_NOMEM
;
352 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
357 /* Grab the INIT header. */
358 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
360 /* Tag the variable length parameters. */
361 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
363 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
367 /* The call, sctp_process_init(), can fail on memory allocation. */
368 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
370 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
374 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
376 /* If there are errors need to be reported for unknown parameters,
377 * make sure to reserve enough room in the INIT ACK for them.
381 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
382 sizeof(sctp_chunkhdr_t
);
384 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
387 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
391 /* If there are errors need to be reported for unknown parameters,
392 * include them in the outgoing INIT ACK as "Unrecognized parameter"
396 /* Get the "Unrecognized parameter" parameter(s) out of the
397 * ERROR chunk generated by sctp_verify_init(). Since the
398 * error cause code for "unknown parameter" and the
399 * "Unrecognized parameter" type is the same, we can
400 * construct the parameters in INIT ACK by copying the
403 unk_param
= (sctp_unrecognized_param_t
*)
404 ((__u8
*)(err_chunk
->chunk_hdr
) +
405 sizeof(sctp_chunkhdr_t
));
406 /* Replace the cause code with the "Unrecognized parameter"
409 sctp_addto_chunk(repl
, len
, unk_param
);
410 sctp_chunk_free(err_chunk
);
413 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
415 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
418 * Note: After sending out INIT ACK with the State Cookie parameter,
419 * "Z" MUST NOT allocate any resources, nor keep any states for the
420 * new association. Otherwise, "Z" will be vulnerable to resource
423 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
425 return SCTP_DISPOSITION_DELETE_TCB
;
428 sctp_association_free(new_asoc
);
431 sctp_chunk_free(err_chunk
);
432 return SCTP_DISPOSITION_NOMEM
;
436 * Respond to a normal INIT ACK chunk.
437 * We are the side that is initiating the association.
439 * Section: 5.1 Normal Establishment of an Association, C
440 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
441 * timer and leave COOKIE-WAIT state. "A" shall then send the State
442 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
443 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
445 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
446 * DATA chunks, but it MUST be the first chunk in the packet and
447 * until the COOKIE ACK is returned the sender MUST NOT send any
448 * other packets to the peer.
450 * Verification Tag: 3.3.3
451 * If the value of the Initiate Tag in a received INIT ACK chunk is
452 * found to be 0, the receiver MUST treat it as an error and close the
453 * association by transmitting an ABORT.
456 * (endpoint, asoc, chunk)
459 * (asoc, reply_msg, msg_up, timers, counters)
461 * The return value is the disposition of the chunk.
463 sctp_disposition_t
sctp_sf_do_5_1C_ack(const struct sctp_endpoint
*ep
,
464 const struct sctp_association
*asoc
,
465 const sctp_subtype_t type
,
467 sctp_cmd_seq_t
*commands
)
469 struct sctp_chunk
*chunk
= arg
;
470 sctp_init_chunk_t
*initchunk
;
471 struct sctp_chunk
*err_chunk
;
472 struct sctp_packet
*packet
;
475 if (!sctp_vtag_verify(chunk
, asoc
))
476 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
479 * An endpoint MUST NOT bundle INIT, INIT ACK or
480 * SHUTDOWN COMPLETE with any other chunks.
482 if (!chunk
->singleton
)
483 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
485 /* Make sure that the INIT-ACK chunk has a valid length */
486 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
487 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
489 /* Grab the INIT header. */
490 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
492 /* Verify the INIT chunk before processing it. */
494 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
495 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
498 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
500 /* This chunk contains fatal error. It is to be discarded.
501 * Send an ABORT, with causes if there is any.
504 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
505 (__u8
*)(err_chunk
->chunk_hdr
) +
506 sizeof(sctp_chunkhdr_t
),
507 ntohs(err_chunk
->chunk_hdr
->length
) -
508 sizeof(sctp_chunkhdr_t
));
510 sctp_chunk_free(err_chunk
);
513 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
514 SCTP_PACKET(packet
));
515 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
516 error
= SCTP_ERROR_INV_PARAM
;
518 error
= SCTP_ERROR_NO_RESOURCE
;
521 sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
522 error
= SCTP_ERROR_INV_PARAM
;
524 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
,
525 asoc
, chunk
->transport
);
528 /* Tag the variable length parameters. Note that we never
529 * convert the parameters in an INIT chunk.
531 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
533 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
535 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
536 SCTP_PEER_INIT(initchunk
));
538 /* Reset init error count upon receipt of INIT-ACK. */
539 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
541 /* 5.1 C) "A" shall stop the T1-init timer and leave
542 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
543 * timer, and enter the COOKIE-ECHOED state.
545 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
546 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
547 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
548 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
549 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
550 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
552 /* 5.1 C) "A" shall then send the State Cookie received in the
553 * INIT ACK chunk in a COOKIE ECHO chunk, ...
555 /* If there is any errors to report, send the ERROR chunk generated
556 * for unknown parameters as well.
558 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
559 SCTP_CHUNK(err_chunk
));
561 return SCTP_DISPOSITION_CONSUME
;
565 * Respond to a normal COOKIE ECHO chunk.
566 * We are the side that is being asked for an association.
568 * Section: 5.1 Normal Establishment of an Association, D
569 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
570 * with a COOKIE ACK chunk after building a TCB and moving to
571 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
572 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
573 * chunk MUST be the first chunk in the packet.
575 * IMPLEMENTATION NOTE: An implementation may choose to send the
576 * Communication Up notification to the SCTP user upon reception
577 * of a valid COOKIE ECHO chunk.
579 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
580 * D) Rules for packet carrying a COOKIE ECHO
582 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
583 * Initial Tag received in the INIT ACK.
585 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
588 * (endpoint, asoc, chunk)
591 * (asoc, reply_msg, msg_up, timers, counters)
593 * The return value is the disposition of the chunk.
595 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
596 const struct sctp_association
*asoc
,
597 const sctp_subtype_t type
, void *arg
,
598 sctp_cmd_seq_t
*commands
)
600 struct sctp_chunk
*chunk
= arg
;
601 struct sctp_association
*new_asoc
;
602 sctp_init_chunk_t
*peer_init
;
603 struct sctp_chunk
*repl
;
604 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
606 struct sctp_chunk
*err_chk_p
;
609 /* If the packet is an OOTB packet which is temporarily on the
610 * control endpoint, respond with an ABORT.
612 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
613 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
615 /* Make sure that the COOKIE_ECHO chunk has a valid length.
616 * In this case, we check that we have enough for at least a
617 * chunk header. More detailed verification is done
618 * in sctp_unpack_cookie().
620 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
621 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
623 /* If the endpoint is not listening or if the number of associations
624 * on the TCP-style socket exceed the max backlog, respond with an
628 if (!sctp_sstate(sk
, LISTENING
) ||
629 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
630 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
632 /* "Decode" the chunk. We have no optional parameters so we
635 chunk
->subh
.cookie_hdr
=
636 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
637 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
638 sizeof(sctp_chunkhdr_t
)))
641 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
642 * "Z" will reply with a COOKIE ACK chunk after building a TCB
643 * and moving to the ESTABLISHED state.
645 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
649 * If the re-build failed, what is the proper error path
652 * [We should abort the association. --piggy]
655 /* FIXME: Several errors are possible. A bad cookie should
656 * be silently discarded, but think about logging it too.
659 case -SCTP_IERROR_NOMEM
:
662 case -SCTP_IERROR_STALE_COOKIE
:
663 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
665 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
667 case -SCTP_IERROR_BAD_SIG
:
669 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
674 /* Delay state machine commands until later.
676 * Re-build the bind address for the association is done in
677 * the sctp_unpack_cookie() already.
679 /* This is a brand-new association, so these are not yet side
680 * effects--it is safe to run them here.
682 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
684 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
685 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
686 peer_init
, GFP_ATOMIC
))
689 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
693 /* RFC 2960 5.1 Normal Establishment of an Association
695 * D) IMPLEMENTATION NOTE: An implementation may choose to
696 * send the Communication Up notification to the SCTP user
697 * upon reception of a valid COOKIE ECHO chunk.
699 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
700 new_asoc
->c
.sinit_num_ostreams
,
701 new_asoc
->c
.sinit_max_instreams
,
706 /* Sockets API Draft Section 5.3.1.6
707 * When a peer sends a Adaptation Layer Indication parameter , SCTP
708 * delivers this notification to inform the application that of the
709 * peers requested adaptation layer.
711 if (new_asoc
->peer
.adaptation_ind
) {
712 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
718 /* Add all the state machine commands now since we've created
719 * everything. This way we don't introduce memory corruptions
720 * during side-effect processing and correclty count established
723 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
724 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
725 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
726 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
727 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS
);
728 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
730 if (new_asoc
->autoclose
)
731 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
732 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
734 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
736 /* This will send the COOKIE ACK */
737 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
739 /* Queue the ASSOC_CHANGE event */
740 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
742 /* Send up the Adaptation Layer Indication event */
744 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
745 SCTP_ULPEVENT(ai_ev
));
747 return SCTP_DISPOSITION_CONSUME
;
750 sctp_ulpevent_free(ev
);
752 sctp_chunk_free(repl
);
754 sctp_association_free(new_asoc
);
756 return SCTP_DISPOSITION_NOMEM
;
760 * Respond to a normal COOKIE ACK chunk.
761 * We are the side that is being asked for an association.
763 * RFC 2960 5.1 Normal Establishment of an Association
765 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
766 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
767 * timer. It may also notify its ULP about the successful
768 * establishment of the association with a Communication Up
769 * notification (see Section 10).
773 * (endpoint, asoc, chunk)
776 * (asoc, reply_msg, msg_up, timers, counters)
778 * The return value is the disposition of the chunk.
780 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
781 const struct sctp_association
*asoc
,
782 const sctp_subtype_t type
, void *arg
,
783 sctp_cmd_seq_t
*commands
)
785 struct sctp_chunk
*chunk
= arg
;
786 struct sctp_ulpevent
*ev
;
788 if (!sctp_vtag_verify(chunk
, asoc
))
789 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
791 /* Verify that the chunk length for the COOKIE-ACK is OK.
792 * If we don't do this, any bundled chunks may be junked.
794 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
795 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
798 /* Reset init error count upon receipt of COOKIE-ACK,
799 * to avoid problems with the managemement of this
800 * counter in stale cookie situations when a transition back
801 * from the COOKIE-ECHOED state to the COOKIE-WAIT
802 * state is performed.
804 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
806 /* RFC 2960 5.1 Normal Establishment of an Association
808 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
809 * from the COOKIE-ECHOED state to the ESTABLISHED state,
810 * stopping the T1-cookie timer.
812 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
813 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
814 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
815 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
816 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
817 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS
);
818 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
820 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
821 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
822 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
824 /* It may also notify its ULP about the successful
825 * establishment of the association with a Communication Up
826 * notification (see Section 10).
828 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
829 0, asoc
->c
.sinit_num_ostreams
,
830 asoc
->c
.sinit_max_instreams
,
836 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
838 /* Sockets API Draft Section 5.3.1.6
839 * When a peer sends a Adaptation Layer Indication parameter , SCTP
840 * delivers this notification to inform the application that of the
841 * peers requested adaptation layer.
843 if (asoc
->peer
.adaptation_ind
) {
844 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
848 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
852 return SCTP_DISPOSITION_CONSUME
;
854 return SCTP_DISPOSITION_NOMEM
;
857 /* Generate and sendout a heartbeat packet. */
858 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
859 const struct sctp_association
*asoc
,
860 const sctp_subtype_t type
,
862 sctp_cmd_seq_t
*commands
)
864 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
865 struct sctp_chunk
*reply
;
866 sctp_sender_hb_info_t hbinfo
;
869 hbinfo
.param_hdr
.type
= SCTP_PARAM_HEARTBEAT_INFO
;
870 hbinfo
.param_hdr
.length
= htons(sizeof(sctp_sender_hb_info_t
));
871 hbinfo
.daddr
= transport
->ipaddr
;
872 hbinfo
.sent_at
= jiffies
;
873 hbinfo
.hb_nonce
= transport
->hb_nonce
;
875 /* Send a heartbeat to our peer. */
876 paylen
= sizeof(sctp_sender_hb_info_t
);
877 reply
= sctp_make_heartbeat(asoc
, transport
, &hbinfo
, paylen
);
879 return SCTP_DISPOSITION_NOMEM
;
881 /* Set rto_pending indicating that an RTT measurement
882 * is started with this heartbeat chunk.
884 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
885 SCTP_TRANSPORT(transport
));
887 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
888 return SCTP_DISPOSITION_CONSUME
;
891 /* Generate a HEARTBEAT packet on the given transport. */
892 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
893 const struct sctp_association
*asoc
,
894 const sctp_subtype_t type
,
896 sctp_cmd_seq_t
*commands
)
898 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
900 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
901 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
902 SCTP_ERROR(ETIMEDOUT
));
903 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
904 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
905 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
906 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
907 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
908 return SCTP_DISPOSITION_DELETE_TCB
;
912 * The Sender-specific Heartbeat Info field should normally include
913 * information about the sender's current time when this HEARTBEAT
914 * chunk is sent and the destination transport address to which this
915 * HEARTBEAT is sent (see Section 8.3).
918 if (transport
->param_flags
& SPP_HB_ENABLE
) {
919 if (SCTP_DISPOSITION_NOMEM
==
920 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
922 return SCTP_DISPOSITION_NOMEM
;
923 /* Set transport error counter and association error counter
924 * when sending heartbeat.
926 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
927 SCTP_TRANSPORT(transport
));
929 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
930 SCTP_TRANSPORT(transport
));
932 return SCTP_DISPOSITION_CONSUME
;
936 * Process an heartbeat request.
938 * Section: 8.3 Path Heartbeat
939 * The receiver of the HEARTBEAT should immediately respond with a
940 * HEARTBEAT ACK that contains the Heartbeat Information field copied
941 * from the received HEARTBEAT chunk.
943 * Verification Tag: 8.5 Verification Tag [Normal verification]
944 * When receiving an SCTP packet, the endpoint MUST ensure that the
945 * value in the Verification Tag field of the received SCTP packet
946 * matches its own Tag. If the received Verification Tag value does not
947 * match the receiver's own tag value, the receiver shall silently
948 * discard the packet and shall not process it any further except for
949 * those cases listed in Section 8.5.1 below.
952 * (endpoint, asoc, chunk)
955 * (asoc, reply_msg, msg_up, timers, counters)
957 * The return value is the disposition of the chunk.
959 sctp_disposition_t
sctp_sf_beat_8_3(const struct sctp_endpoint
*ep
,
960 const struct sctp_association
*asoc
,
961 const sctp_subtype_t type
,
963 sctp_cmd_seq_t
*commands
)
965 struct sctp_chunk
*chunk
= arg
;
966 struct sctp_chunk
*reply
;
969 if (!sctp_vtag_verify(chunk
, asoc
))
970 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
972 /* Make sure that the HEARTBEAT chunk has a valid length. */
973 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
974 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
977 /* 8.3 The receiver of the HEARTBEAT should immediately
978 * respond with a HEARTBEAT ACK that contains the Heartbeat
979 * Information field copied from the received HEARTBEAT chunk.
981 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
982 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
983 if (!pskb_pull(chunk
->skb
, paylen
))
986 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
987 chunk
->subh
.hb_hdr
, paylen
);
991 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
992 return SCTP_DISPOSITION_CONSUME
;
995 return SCTP_DISPOSITION_NOMEM
;
999 * Process the returning HEARTBEAT ACK.
1001 * Section: 8.3 Path Heartbeat
1002 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1003 * should clear the error counter of the destination transport
1004 * address to which the HEARTBEAT was sent, and mark the destination
1005 * transport address as active if it is not so marked. The endpoint may
1006 * optionally report to the upper layer when an inactive destination
1007 * address is marked as active due to the reception of the latest
1008 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1009 * clear the association overall error count as well (as defined
1012 * The receiver of the HEARTBEAT ACK should also perform an RTT
1013 * measurement for that destination transport address using the time
1014 * value carried in the HEARTBEAT ACK chunk.
1016 * Verification Tag: 8.5 Verification Tag [Normal verification]
1019 * (endpoint, asoc, chunk)
1022 * (asoc, reply_msg, msg_up, timers, counters)
1024 * The return value is the disposition of the chunk.
1026 sctp_disposition_t
sctp_sf_backbeat_8_3(const struct sctp_endpoint
*ep
,
1027 const struct sctp_association
*asoc
,
1028 const sctp_subtype_t type
,
1030 sctp_cmd_seq_t
*commands
)
1032 struct sctp_chunk
*chunk
= arg
;
1033 union sctp_addr from_addr
;
1034 struct sctp_transport
*link
;
1035 sctp_sender_hb_info_t
*hbinfo
;
1036 unsigned long max_interval
;
1038 if (!sctp_vtag_verify(chunk
, asoc
))
1039 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1041 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1042 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1043 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1046 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1047 /* Make sure that the length of the parameter is what we expect */
1048 if (ntohs(hbinfo
->param_hdr
.length
) !=
1049 sizeof(sctp_sender_hb_info_t
)) {
1050 return SCTP_DISPOSITION_DISCARD
;
1053 from_addr
= hbinfo
->daddr
;
1054 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1056 /* This should never happen, but lets log it if so. */
1057 if (unlikely(!link
)) {
1058 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1059 if (net_ratelimit())
1061 "%s association %p could not find address "
1065 NIP6(from_addr
.v6
.sin6_addr
));
1067 if (net_ratelimit())
1069 "%s association %p could not find address "
1073 NIPQUAD(from_addr
.v4
.sin_addr
.s_addr
));
1075 return SCTP_DISPOSITION_DISCARD
;
1078 /* Validate the 64-bit random nonce. */
1079 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1080 return SCTP_DISPOSITION_DISCARD
;
1082 max_interval
= link
->hbinterval
+ link
->rto
;
1084 /* Check if the timestamp looks valid. */
1085 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1086 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1087 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1088 "received for transport: %p\n",
1089 __FUNCTION__
, link
);
1090 return SCTP_DISPOSITION_DISCARD
;
1093 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1094 * the HEARTBEAT should clear the error counter of the
1095 * destination transport address to which the HEARTBEAT was
1096 * sent and mark the destination transport address as active if
1097 * it is not so marked.
1099 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1101 return SCTP_DISPOSITION_CONSUME
;
1104 /* Helper function to send out an abort for the restart
1107 static int sctp_sf_send_restart_abort(union sctp_addr
*ssa
,
1108 struct sctp_chunk
*init
,
1109 sctp_cmd_seq_t
*commands
)
1112 struct sctp_packet
*pkt
;
1113 union sctp_addr_param
*addrparm
;
1114 struct sctp_errhdr
*errhdr
;
1115 struct sctp_endpoint
*ep
;
1116 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1117 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1119 /* Build the error on the stack. We are way to malloc crazy
1120 * throughout the code today.
1122 errhdr
= (struct sctp_errhdr
*)buffer
;
1123 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1125 /* Copy into a parm format. */
1126 len
= af
->to_addr_param(ssa
, addrparm
);
1127 len
+= sizeof(sctp_errhdr_t
);
1129 errhdr
->cause
= SCTP_ERROR_RESTART
;
1130 errhdr
->length
= htons(len
);
1132 /* Assign to the control socket. */
1133 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
1135 /* Association is NULL since this may be a restart attack and we
1136 * want to send back the attacker's vtag.
1138 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1142 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1144 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1146 /* Discard the rest of the inbound packet. */
1147 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1150 /* Even if there is no memory, treat as a failure so
1151 * the packet will get dropped.
1156 /* A restart is occurring, check to make sure no new addresses
1157 * are being added as we may be under a takeover attack.
1159 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1160 const struct sctp_association
*asoc
,
1161 struct sctp_chunk
*init
,
1162 sctp_cmd_seq_t
*commands
)
1164 struct sctp_transport
*new_addr
, *addr
;
1165 struct list_head
*pos
, *pos2
;
1168 /* Implementor's Guide - Sectin 5.2.2
1170 * Before responding the endpoint MUST check to see if the
1171 * unexpected INIT adds new addresses to the association. If new
1172 * addresses are added to the association, the endpoint MUST respond
1176 /* Search through all current addresses and make sure
1177 * we aren't adding any new ones.
1182 list_for_each(pos
, &new_asoc
->peer
.transport_addr_list
) {
1183 new_addr
= list_entry(pos
, struct sctp_transport
, transports
);
1185 list_for_each(pos2
, &asoc
->peer
.transport_addr_list
) {
1186 addr
= list_entry(pos2
, struct sctp_transport
,
1188 if (sctp_cmp_addr_exact(&new_addr
->ipaddr
,
1198 /* If a new address was added, ABORT the sender. */
1199 if (!found
&& new_addr
) {
1200 sctp_sf_send_restart_abort(&new_addr
->ipaddr
, init
, commands
);
1203 /* Return success if all addresses were found. */
1207 /* Populate the verification/tie tags based on overlapping INIT
1210 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1212 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1213 const struct sctp_association
*asoc
)
1215 switch (asoc
->state
) {
1217 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1219 case SCTP_STATE_COOKIE_WAIT
:
1220 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1221 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1222 new_asoc
->c
.peer_ttag
= 0;
1225 case SCTP_STATE_COOKIE_ECHOED
:
1226 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1227 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1228 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1231 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1232 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1235 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1236 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1240 /* Other parameters for the endpoint SHOULD be copied from the
1241 * existing parameters of the association (e.g. number of
1242 * outbound streams) into the INIT ACK and cookie.
1244 new_asoc
->rwnd
= asoc
->rwnd
;
1245 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1246 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1247 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1251 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1254 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1256 * Returns value representing action to be taken. These action values
1257 * correspond to Action/Description values in RFC 2960, Table 2.
1259 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1260 const struct sctp_association
*asoc
)
1262 /* In this case, the peer may have restarted. */
1263 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1264 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1265 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1266 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1269 /* Collision case B. */
1270 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1271 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1272 (0 == asoc
->c
.peer_vtag
))) {
1276 /* Collision case D. */
1277 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1278 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1281 /* Collision case C. */
1282 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1283 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1284 (0 == new_asoc
->c
.my_ttag
) &&
1285 (0 == new_asoc
->c
.peer_ttag
))
1288 /* No match to any of the special cases; discard this packet. */
1292 /* Common helper routine for both duplicate and simulataneous INIT
1295 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1296 const struct sctp_endpoint
*ep
,
1297 const struct sctp_association
*asoc
,
1298 const sctp_subtype_t type
,
1299 void *arg
, sctp_cmd_seq_t
*commands
)
1301 sctp_disposition_t retval
;
1302 struct sctp_chunk
*chunk
= arg
;
1303 struct sctp_chunk
*repl
;
1304 struct sctp_association
*new_asoc
;
1305 struct sctp_chunk
*err_chunk
;
1306 struct sctp_packet
*packet
;
1307 sctp_unrecognized_param_t
*unk_param
;
1311 * An endpoint MUST NOT bundle INIT, INIT ACK or
1312 * SHUTDOWN COMPLETE with any other chunks.
1315 * Furthermore, we require that the receiver of an INIT chunk MUST
1316 * enforce these rules by silently discarding an arriving packet
1317 * with an INIT chunk that is bundled with other chunks.
1319 if (!chunk
->singleton
)
1320 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1322 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1325 if (chunk
->sctp_hdr
->vtag
!= 0)
1326 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1328 /* Make sure that the INIT chunk has a valid length.
1329 * In this case, we generate a protocol violation since we have
1330 * an association established.
1332 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1333 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1335 /* Grab the INIT header. */
1336 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1338 /* Tag the variable length parameters. */
1339 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1341 /* Verify the INIT chunk before processing it. */
1343 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1344 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1346 /* This chunk contains fatal error. It is to be discarded.
1347 * Send an ABORT, with causes if there is any.
1350 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1351 (__u8
*)(err_chunk
->chunk_hdr
) +
1352 sizeof(sctp_chunkhdr_t
),
1353 ntohs(err_chunk
->chunk_hdr
->length
) -
1354 sizeof(sctp_chunkhdr_t
));
1357 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1358 SCTP_PACKET(packet
));
1359 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1360 retval
= SCTP_DISPOSITION_CONSUME
;
1362 retval
= SCTP_DISPOSITION_NOMEM
;
1366 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1372 * Other parameters for the endpoint SHOULD be copied from the
1373 * existing parameters of the association (e.g. number of
1374 * outbound streams) into the INIT ACK and cookie.
1375 * FIXME: We are copying parameters from the endpoint not the
1378 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1382 /* In the outbound INIT ACK the endpoint MUST copy its current
1383 * Verification Tag and Peers Verification tag into a reserved
1384 * place (local tie-tag and per tie-tag) within the state cookie.
1386 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1388 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1392 /* Make sure no new addresses are being added during the
1393 * restart. Do not do this check for COOKIE-WAIT state,
1394 * since there are no peer addresses to check against.
1395 * Upon return an ABORT will have been sent if needed.
1397 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1398 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1400 retval
= SCTP_DISPOSITION_CONSUME
;
1405 sctp_tietags_populate(new_asoc
, asoc
);
1407 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1409 /* If there are errors need to be reported for unknown parameters,
1410 * make sure to reserve enough room in the INIT ACK for them.
1414 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1415 sizeof(sctp_chunkhdr_t
);
1418 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
1421 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1425 /* If there are errors need to be reported for unknown parameters,
1426 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1430 /* Get the "Unrecognized parameter" parameter(s) out of the
1431 * ERROR chunk generated by sctp_verify_init(). Since the
1432 * error cause code for "unknown parameter" and the
1433 * "Unrecognized parameter" type is the same, we can
1434 * construct the parameters in INIT ACK by copying the
1435 * ERROR causes over.
1437 unk_param
= (sctp_unrecognized_param_t
*)
1438 ((__u8
*)(err_chunk
->chunk_hdr
) +
1439 sizeof(sctp_chunkhdr_t
));
1440 /* Replace the cause code with the "Unrecognized parameter"
1443 sctp_addto_chunk(repl
, len
, unk_param
);
1446 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1447 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1450 * Note: After sending out INIT ACK with the State Cookie parameter,
1451 * "Z" MUST NOT allocate any resources for this new association.
1452 * Otherwise, "Z" will be vulnerable to resource attacks.
1454 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1455 retval
= SCTP_DISPOSITION_CONSUME
;
1460 retval
= SCTP_DISPOSITION_NOMEM
;
1463 sctp_association_free(new_asoc
);
1466 sctp_chunk_free(err_chunk
);
1471 * Handle simultanous INIT.
1472 * This means we started an INIT and then we got an INIT request from
1475 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1476 * This usually indicates an initialization collision, i.e., each
1477 * endpoint is attempting, at about the same time, to establish an
1478 * association with the other endpoint.
1480 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1481 * endpoint MUST respond with an INIT ACK using the same parameters it
1482 * sent in its original INIT chunk (including its Verification Tag,
1483 * unchanged). These original parameters are combined with those from the
1484 * newly received INIT chunk. The endpoint shall also generate a State
1485 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1486 * INIT to calculate the State Cookie.
1488 * After that, the endpoint MUST NOT change its state, the T1-init
1489 * timer shall be left running and the corresponding TCB MUST NOT be
1490 * destroyed. The normal procedures for handling State Cookies when
1491 * a TCB exists will resolve the duplicate INITs to a single association.
1493 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1494 * its Tie-Tags with the Tag information of itself and its peer (see
1495 * section 5.2.2 for a description of the Tie-Tags).
1497 * Verification Tag: Not explicit, but an INIT can not have a valid
1498 * verification tag, so we skip the check.
1501 * (endpoint, asoc, chunk)
1504 * (asoc, reply_msg, msg_up, timers, counters)
1506 * The return value is the disposition of the chunk.
1508 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1509 const struct sctp_association
*asoc
,
1510 const sctp_subtype_t type
,
1512 sctp_cmd_seq_t
*commands
)
1514 /* Call helper to do the real work for both simulataneous and
1515 * duplicate INIT chunk handling.
1517 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1521 * Handle duplicated INIT messages. These are usually delayed
1524 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1525 * COOKIE-ECHOED and COOKIE-WAIT
1527 * Unless otherwise stated, upon reception of an unexpected INIT for
1528 * this association, the endpoint shall generate an INIT ACK with a
1529 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1530 * current Verification Tag and peer's Verification Tag into a reserved
1531 * place within the state cookie. We shall refer to these locations as
1532 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1533 * containing this INIT ACK MUST carry a Verification Tag value equal to
1534 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1535 * MUST contain a new Initiation Tag (randomly generated see Section
1536 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1537 * existing parameters of the association (e.g. number of outbound
1538 * streams) into the INIT ACK and cookie.
1540 * After sending out the INIT ACK, the endpoint shall take no further
1541 * actions, i.e., the existing association, including its current state,
1542 * and the corresponding TCB MUST NOT be changed.
1544 * Note: Only when a TCB exists and the association is not in a COOKIE-
1545 * WAIT state are the Tie-Tags populated. For a normal association INIT
1546 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1547 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1548 * State Cookie are populated as specified in section 5.2.1.
1550 * Verification Tag: Not specified, but an INIT has no way of knowing
1551 * what the verification tag could be, so we ignore it.
1554 * (endpoint, asoc, chunk)
1557 * (asoc, reply_msg, msg_up, timers, counters)
1559 * The return value is the disposition of the chunk.
1561 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1562 const struct sctp_association
*asoc
,
1563 const sctp_subtype_t type
,
1565 sctp_cmd_seq_t
*commands
)
1567 /* Call helper to do the real work for both simulataneous and
1568 * duplicate INIT chunk handling.
1570 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1575 * Unexpected INIT-ACK handler.
1578 * If an INIT ACK received by an endpoint in any state other than the
1579 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1580 * An unexpected INIT ACK usually indicates the processing of an old or
1581 * duplicated INIT chunk.
1583 sctp_disposition_t
sctp_sf_do_5_2_3_initack(const struct sctp_endpoint
*ep
,
1584 const struct sctp_association
*asoc
,
1585 const sctp_subtype_t type
,
1586 void *arg
, sctp_cmd_seq_t
*commands
)
1588 /* Per the above section, we'll discard the chunk if we have an
1589 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1591 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
1592 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
1594 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
1597 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1600 * A) In this case, the peer may have restarted.
1602 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1603 const struct sctp_association
*asoc
,
1604 struct sctp_chunk
*chunk
,
1605 sctp_cmd_seq_t
*commands
,
1606 struct sctp_association
*new_asoc
)
1608 sctp_init_chunk_t
*peer_init
;
1609 struct sctp_ulpevent
*ev
;
1610 struct sctp_chunk
*repl
;
1611 struct sctp_chunk
*err
;
1612 sctp_disposition_t disposition
;
1614 /* new_asoc is a brand-new association, so these are not yet
1615 * side effects--it is safe to run them here.
1617 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1619 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1620 sctp_source(chunk
), peer_init
,
1624 /* Make sure no new addresses are being added during the
1625 * restart. Though this is a pretty complicated attack
1626 * since you'd have to get inside the cookie.
1628 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1629 return SCTP_DISPOSITION_CONSUME
;
1632 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1633 * the peer has restarted (Action A), it MUST NOT setup a new
1634 * association but instead resend the SHUTDOWN ACK and send an ERROR
1635 * chunk with a "Cookie Received while Shutting Down" error cause to
1638 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1639 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1640 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1642 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1645 err
= sctp_make_op_error(asoc
, chunk
,
1646 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1649 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1652 return SCTP_DISPOSITION_CONSUME
;
1655 /* For now, fail any unsent/unacked data. Consider the optional
1656 * choice of resending of this data.
1658 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1660 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1664 /* Report association restart to upper layer. */
1665 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1666 new_asoc
->c
.sinit_num_ostreams
,
1667 new_asoc
->c
.sinit_max_instreams
,
1672 /* Update the content of current association. */
1673 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1674 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1675 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1676 return SCTP_DISPOSITION_CONSUME
;
1679 sctp_chunk_free(repl
);
1681 return SCTP_DISPOSITION_NOMEM
;
1684 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1687 * B) In this case, both sides may be attempting to start an association
1688 * at about the same time but the peer endpoint started its INIT
1689 * after responding to the local endpoint's INIT
1691 /* This case represents an initialization collision. */
1692 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1693 const struct sctp_association
*asoc
,
1694 struct sctp_chunk
*chunk
,
1695 sctp_cmd_seq_t
*commands
,
1696 struct sctp_association
*new_asoc
)
1698 sctp_init_chunk_t
*peer_init
;
1699 struct sctp_chunk
*repl
;
1701 /* new_asoc is a brand-new association, so these are not yet
1702 * side effects--it is safe to run them here.
1704 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1705 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1706 sctp_source(chunk
), peer_init
,
1710 /* Update the content of current association. */
1711 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1712 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1713 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1714 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1715 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1717 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1721 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1722 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1724 /* RFC 2960 5.1 Normal Establishment of an Association
1726 * D) IMPLEMENTATION NOTE: An implementation may choose to
1727 * send the Communication Up notification to the SCTP user
1728 * upon reception of a valid COOKIE ECHO chunk.
1730 * Sadly, this needs to be implemented as a side-effect, because
1731 * we are not guaranteed to have set the association id of the real
1732 * association and so these notifications need to be delayed until
1733 * the association id is allocated.
1736 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1738 /* Sockets API Draft Section 5.3.1.6
1739 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1740 * delivers this notification to inform the application that of the
1741 * peers requested adaptation layer.
1743 * This also needs to be done as a side effect for the same reason as
1746 if (asoc
->peer
.adaptation_ind
)
1747 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1749 return SCTP_DISPOSITION_CONSUME
;
1752 return SCTP_DISPOSITION_NOMEM
;
1755 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1758 * C) In this case, the local endpoint's cookie has arrived late.
1759 * Before it arrived, the local endpoint sent an INIT and received an
1760 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1761 * but a new tag of its own.
1763 /* This case represents an initialization collision. */
1764 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1765 const struct sctp_association
*asoc
,
1766 struct sctp_chunk
*chunk
,
1767 sctp_cmd_seq_t
*commands
,
1768 struct sctp_association
*new_asoc
)
1770 /* The cookie should be silently discarded.
1771 * The endpoint SHOULD NOT change states and should leave
1772 * any timers running.
1774 return SCTP_DISPOSITION_DISCARD
;
1777 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1781 * D) When both local and remote tags match the endpoint should always
1782 * enter the ESTABLISHED state, if it has not already done so.
1784 /* This case represents an initialization collision. */
1785 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1786 const struct sctp_association
*asoc
,
1787 struct sctp_chunk
*chunk
,
1788 sctp_cmd_seq_t
*commands
,
1789 struct sctp_association
*new_asoc
)
1791 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1792 struct sctp_chunk
*repl
;
1794 /* Clarification from Implementor's Guide:
1795 * D) When both local and remote tags match the endpoint should
1796 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1797 * It should stop any cookie timer that may be running and send
1801 /* Don't accidentally move back into established state. */
1802 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1803 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1804 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1805 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1806 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1807 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1808 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1811 /* RFC 2960 5.1 Normal Establishment of an Association
1813 * D) IMPLEMENTATION NOTE: An implementation may choose
1814 * to send the Communication Up notification to the
1815 * SCTP user upon reception of a valid COOKIE
1818 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1820 asoc
->c
.sinit_num_ostreams
,
1821 asoc
->c
.sinit_max_instreams
,
1826 /* Sockets API Draft Section 5.3.1.6
1827 * When a peer sends a Adaptation Layer Indication parameter,
1828 * SCTP delivers this notification to inform the application
1829 * that of the peers requested adaptation layer.
1831 if (asoc
->peer
.adaptation_ind
) {
1832 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1839 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1841 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1846 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1849 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1850 SCTP_ULPEVENT(ai_ev
));
1852 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1853 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1855 return SCTP_DISPOSITION_CONSUME
;
1859 sctp_ulpevent_free(ai_ev
);
1861 sctp_ulpevent_free(ev
);
1862 return SCTP_DISPOSITION_NOMEM
;
1866 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1867 * chunk was retransmitted and then delayed in the network.
1869 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1871 * Verification Tag: None. Do cookie validation.
1874 * (endpoint, asoc, chunk)
1877 * (asoc, reply_msg, msg_up, timers, counters)
1879 * The return value is the disposition of the chunk.
1881 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1882 const struct sctp_association
*asoc
,
1883 const sctp_subtype_t type
,
1885 sctp_cmd_seq_t
*commands
)
1887 sctp_disposition_t retval
;
1888 struct sctp_chunk
*chunk
= arg
;
1889 struct sctp_association
*new_asoc
;
1892 struct sctp_chunk
*err_chk_p
;
1894 /* Make sure that the chunk has a valid length from the protocol
1895 * perspective. In this case check to make sure we have at least
1896 * enough for the chunk header. Cookie length verification is
1899 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1900 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1903 /* "Decode" the chunk. We have no optional parameters so we
1904 * are in good shape.
1906 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1907 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1908 sizeof(sctp_chunkhdr_t
)))
1911 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1912 * of a duplicate COOKIE ECHO match the Verification Tags of the
1913 * current association, consider the State Cookie valid even if
1914 * the lifespan is exceeded.
1916 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
1920 * If the re-build failed, what is the proper error path
1923 * [We should abort the association. --piggy]
1926 /* FIXME: Several errors are possible. A bad cookie should
1927 * be silently discarded, but think about logging it too.
1930 case -SCTP_IERROR_NOMEM
:
1933 case -SCTP_IERROR_STALE_COOKIE
:
1934 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
1936 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1937 case -SCTP_IERROR_BAD_SIG
:
1939 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1943 /* Compare the tie_tag in cookie with the verification tag of
1944 * current association.
1946 action
= sctp_tietags_compare(new_asoc
, asoc
);
1949 case 'A': /* Association restart. */
1950 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
1954 case 'B': /* Collision case B. */
1955 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
1959 case 'C': /* Collision case C. */
1960 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
1964 case 'D': /* Collision case D. */
1965 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
1969 default: /* Discard packet for all others. */
1970 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1974 /* Delete the tempory new association. */
1975 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1976 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1981 return SCTP_DISPOSITION_NOMEM
;
1985 * Process an ABORT. (SHUTDOWN-PENDING state)
1987 * See sctp_sf_do_9_1_abort().
1989 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
1990 const struct sctp_endpoint
*ep
,
1991 const struct sctp_association
*asoc
,
1992 const sctp_subtype_t type
,
1994 sctp_cmd_seq_t
*commands
)
1996 struct sctp_chunk
*chunk
= arg
;
1998 if (!sctp_vtag_verify_either(chunk
, asoc
))
1999 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2001 /* Make sure that the ABORT chunk has a valid length.
2002 * Since this is an ABORT chunk, we have to discard it
2003 * because of the following text:
2004 * RFC 2960, Section 3.3.7
2005 * If an endpoint receives an ABORT with a format error or for an
2006 * association that doesn't exist, it MUST silently discard it.
2007 * Becasue the length is "invalid", we can't really discard just
2008 * as we do not know its true length. So, to be safe, discard the
2011 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2012 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2014 /* Stop the T5-shutdown guard timer. */
2015 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2016 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2018 return sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2022 * Process an ABORT. (SHUTDOWN-SENT state)
2024 * See sctp_sf_do_9_1_abort().
2026 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
2027 const struct sctp_association
*asoc
,
2028 const sctp_subtype_t type
,
2030 sctp_cmd_seq_t
*commands
)
2032 struct sctp_chunk
*chunk
= arg
;
2034 if (!sctp_vtag_verify_either(chunk
, asoc
))
2035 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2037 /* Make sure that the ABORT chunk has a valid length.
2038 * Since this is an ABORT chunk, we have to discard it
2039 * because of the following text:
2040 * RFC 2960, Section 3.3.7
2041 * If an endpoint receives an ABORT with a format error or for an
2042 * association that doesn't exist, it MUST silently discard it.
2043 * Becasue the length is "invalid", we can't really discard just
2044 * as we do not know its true length. So, to be safe, discard the
2047 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2048 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2050 /* Stop the T2-shutdown timer. */
2051 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2052 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2054 /* Stop the T5-shutdown guard timer. */
2055 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2056 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2058 return sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2062 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2064 * See sctp_sf_do_9_1_abort().
2066 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2067 const struct sctp_endpoint
*ep
,
2068 const struct sctp_association
*asoc
,
2069 const sctp_subtype_t type
,
2071 sctp_cmd_seq_t
*commands
)
2073 /* The same T2 timer, so we should be able to use
2074 * common function with the SHUTDOWN-SENT state.
2076 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2080 * Handle an Error received in COOKIE_ECHOED state.
2082 * Only handle the error type of stale COOKIE Error, the other errors will
2086 * (endpoint, asoc, chunk)
2089 * (asoc, reply_msg, msg_up, timers, counters)
2091 * The return value is the disposition of the chunk.
2093 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2094 const struct sctp_association
*asoc
,
2095 const sctp_subtype_t type
,
2097 sctp_cmd_seq_t
*commands
)
2099 struct sctp_chunk
*chunk
= arg
;
2102 if (!sctp_vtag_verify(chunk
, asoc
))
2103 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2105 /* Make sure that the ERROR chunk has a valid length.
2106 * The parameter walking depends on this as well.
2108 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2109 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2112 /* Process the error here */
2113 /* FUTURE FIXME: When PR-SCTP related and other optional
2114 * parms are emitted, this will have to change to handle multiple
2117 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2118 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2119 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2123 /* It is possible to have malformed error causes, and that
2124 * will cause us to end the walk early. However, since
2125 * we are discarding the packet, there should be no adverse
2128 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2132 * Handle a Stale COOKIE Error
2134 * Section: 5.2.6 Handle Stale COOKIE Error
2135 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2136 * one of the following three alternatives.
2138 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2139 * Preservative parameter requesting an extension to the lifetime of
2140 * the State Cookie. When calculating the time extension, an
2141 * implementation SHOULD use the RTT information measured based on the
2142 * previous COOKIE ECHO / ERROR exchange, and should add no more
2143 * than 1 second beyond the measured RTT, due to long State Cookie
2144 * lifetimes making the endpoint more subject to a replay attack.
2146 * Verification Tag: Not explicit, but safe to ignore.
2149 * (endpoint, asoc, chunk)
2152 * (asoc, reply_msg, msg_up, timers, counters)
2154 * The return value is the disposition of the chunk.
2156 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2157 const struct sctp_association
*asoc
,
2158 const sctp_subtype_t type
,
2160 sctp_cmd_seq_t
*commands
)
2162 struct sctp_chunk
*chunk
= arg
;
2164 sctp_cookie_preserve_param_t bht
;
2166 struct sctp_chunk
*reply
;
2167 struct sctp_bind_addr
*bp
;
2168 int attempts
= asoc
->init_err_counter
+ 1;
2170 if (attempts
> asoc
->max_init_attempts
) {
2171 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2172 SCTP_ERROR(ETIMEDOUT
));
2173 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2174 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2175 return SCTP_DISPOSITION_DELETE_TCB
;
2178 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2180 /* When calculating the time extension, an implementation
2181 * SHOULD use the RTT information measured based on the
2182 * previous COOKIE ECHO / ERROR exchange, and should add no
2183 * more than 1 second beyond the measured RTT, due to long
2184 * State Cookie lifetimes making the endpoint more subject to
2186 * Measure of Staleness's unit is usec. (1/1000000 sec)
2187 * Suggested Cookie Life-span Increment's unit is msec.
2189 * In general, if you use the suggested cookie life, the value
2190 * found in the field of measure of staleness should be doubled
2191 * to give ample time to retransmit the new cookie and thus
2192 * yield a higher probability of success on the reattempt.
2194 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2195 stale
= (stale
* 2) / 1000;
2197 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2198 bht
.param_hdr
.length
= htons(sizeof(bht
));
2199 bht
.lifespan_increment
= htonl(stale
);
2201 /* Build that new INIT chunk. */
2202 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2203 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2207 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2209 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2210 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2212 /* Stop pending T3-rtx and heartbeat timers */
2213 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2214 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2216 /* Delete non-primary peer ip addresses since we are transitioning
2217 * back to the COOKIE-WAIT state
2219 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2221 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2224 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
,
2225 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2227 /* Cast away the const modifier, as we want to just
2228 * rerun it through as a sideffect.
2230 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2232 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2233 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2234 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2235 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2236 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2237 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2239 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2241 return SCTP_DISPOSITION_CONSUME
;
2244 return SCTP_DISPOSITION_NOMEM
;
2251 * After checking the Verification Tag, the receiving endpoint shall
2252 * remove the association from its record, and shall report the
2253 * termination to its upper layer.
2255 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2256 * B) Rules for packet carrying ABORT:
2258 * - The endpoint shall always fill in the Verification Tag field of the
2259 * outbound packet with the destination endpoint's tag value if it
2262 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2263 * MUST follow the procedure described in Section 8.4.
2265 * - The receiver MUST accept the packet if the Verification Tag
2266 * matches either its own tag, OR the tag of its peer. Otherwise, the
2267 * receiver MUST silently discard the packet and take no further
2271 * (endpoint, asoc, chunk)
2274 * (asoc, reply_msg, msg_up, timers, counters)
2276 * The return value is the disposition of the chunk.
2278 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2279 const struct sctp_association
*asoc
,
2280 const sctp_subtype_t type
,
2282 sctp_cmd_seq_t
*commands
)
2284 struct sctp_chunk
*chunk
= arg
;
2286 __be16 error
= SCTP_ERROR_NO_ERROR
;
2288 if (!sctp_vtag_verify_either(chunk
, asoc
))
2289 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2291 /* Make sure that the ABORT chunk has a valid length.
2292 * Since this is an ABORT chunk, we have to discard it
2293 * because of the following text:
2294 * RFC 2960, Section 3.3.7
2295 * If an endpoint receives an ABORT with a format error or for an
2296 * association that doesn't exist, it MUST silently discard it.
2297 * Becasue the length is "invalid", we can't really discard just
2298 * as we do not know its true length. So, to be safe, discard the
2301 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2302 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2304 /* See if we have an error cause code in the chunk. */
2305 len
= ntohs(chunk
->chunk_hdr
->length
);
2306 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2307 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2309 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2310 /* ASSOC_FAILED will DELETE_TCB. */
2311 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2312 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2313 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
2315 return SCTP_DISPOSITION_ABORT
;
2319 * Process an ABORT. (COOKIE-WAIT state)
2321 * See sctp_sf_do_9_1_abort() above.
2323 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2324 const struct sctp_association
*asoc
,
2325 const sctp_subtype_t type
,
2327 sctp_cmd_seq_t
*commands
)
2329 struct sctp_chunk
*chunk
= arg
;
2331 __be16 error
= SCTP_ERROR_NO_ERROR
;
2333 if (!sctp_vtag_verify_either(chunk
, asoc
))
2334 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2336 /* Make sure that the ABORT chunk has a valid length.
2337 * Since this is an ABORT chunk, we have to discard it
2338 * because of the following text:
2339 * RFC 2960, Section 3.3.7
2340 * If an endpoint receives an ABORT with a format error or for an
2341 * association that doesn't exist, it MUST silently discard it.
2342 * Becasue the length is "invalid", we can't really discard just
2343 * as we do not know its true length. So, to be safe, discard the
2346 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2347 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2349 /* See if we have an error cause code in the chunk. */
2350 len
= ntohs(chunk
->chunk_hdr
->length
);
2351 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2352 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2354 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
, asoc
,
2359 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2361 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2362 const struct sctp_association
*asoc
,
2363 const sctp_subtype_t type
,
2365 sctp_cmd_seq_t
*commands
)
2367 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
,
2369 (struct sctp_transport
*)arg
);
2373 * Process an ABORT. (COOKIE-ECHOED state)
2375 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2376 const struct sctp_association
*asoc
,
2377 const sctp_subtype_t type
,
2379 sctp_cmd_seq_t
*commands
)
2381 /* There is a single T1 timer, so we should be able to use
2382 * common function with the COOKIE-WAIT state.
2384 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2388 * Stop T1 timer and abort association with "INIT failed".
2390 * This is common code called by several sctp_sf_*_abort() functions above.
2392 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2393 __be16 error
, int sk_err
,
2394 const struct sctp_association
*asoc
,
2395 struct sctp_transport
*transport
)
2397 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2398 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2399 SCTP_STATE(SCTP_STATE_CLOSED
));
2400 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2401 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2402 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2403 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2404 /* CMD_INIT_FAILED will DELETE_TCB. */
2405 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2407 return SCTP_DISPOSITION_ABORT
;
2411 * sctp_sf_do_9_2_shut
2414 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2415 * - enter the SHUTDOWN-RECEIVED state,
2417 * - stop accepting new data from its SCTP user
2419 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2420 * that all its outstanding DATA chunks have been received by the
2423 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2424 * send a SHUTDOWN in response to a ULP request. And should discard
2425 * subsequent SHUTDOWN chunks.
2427 * If there are still outstanding DATA chunks left, the SHUTDOWN
2428 * receiver shall continue to follow normal data transmission
2429 * procedures defined in Section 6 until all outstanding DATA chunks
2430 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2431 * new data from its SCTP user.
2433 * Verification Tag: 8.5 Verification Tag [Normal verification]
2436 * (endpoint, asoc, chunk)
2439 * (asoc, reply_msg, msg_up, timers, counters)
2441 * The return value is the disposition of the chunk.
2443 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2444 const struct sctp_association
*asoc
,
2445 const sctp_subtype_t type
,
2447 sctp_cmd_seq_t
*commands
)
2449 struct sctp_chunk
*chunk
= arg
;
2450 sctp_shutdownhdr_t
*sdh
;
2451 sctp_disposition_t disposition
;
2452 struct sctp_ulpevent
*ev
;
2454 if (!sctp_vtag_verify(chunk
, asoc
))
2455 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2457 /* Make sure that the SHUTDOWN chunk has a valid length. */
2458 if (!sctp_chunk_length_valid(chunk
,
2459 sizeof(struct sctp_shutdown_chunk_t
)))
2460 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2463 /* Convert the elaborate header. */
2464 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2465 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2466 chunk
->subh
.shutdown_hdr
= sdh
;
2468 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2469 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2470 * inform the application that it should cease sending data.
2472 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2474 disposition
= SCTP_DISPOSITION_NOMEM
;
2477 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2479 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2480 * - enter the SHUTDOWN-RECEIVED state,
2481 * - stop accepting new data from its SCTP user
2483 * [This is implicit in the new state.]
2485 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2486 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2487 disposition
= SCTP_DISPOSITION_CONSUME
;
2489 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2490 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2494 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2497 /* - verify, by checking the Cumulative TSN Ack field of the
2498 * chunk, that all its outstanding DATA chunks have been
2499 * received by the SHUTDOWN sender.
2501 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2502 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2509 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2510 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2511 * transport addresses (either in the IP addresses or in the INIT chunk)
2512 * that belong to this association, it should discard the INIT chunk and
2513 * retransmit the SHUTDOWN ACK chunk.
2515 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2516 const struct sctp_association
*asoc
,
2517 const sctp_subtype_t type
,
2519 sctp_cmd_seq_t
*commands
)
2521 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2522 struct sctp_chunk
*reply
;
2524 /* Make sure that the chunk has a valid length */
2525 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2526 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2529 /* Since we are not going to really process this INIT, there
2530 * is no point in verifying chunk boundries. Just generate
2533 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2537 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2538 * the T2-SHUTDOWN timer.
2540 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2542 /* and restart the T2-shutdown timer. */
2543 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2544 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2546 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2548 return SCTP_DISPOSITION_CONSUME
;
2550 return SCTP_DISPOSITION_NOMEM
;
2554 * sctp_sf_do_ecn_cwr
2556 * Section: Appendix A: Explicit Congestion Notification
2560 * RFC 2481 details a specific bit for a sender to send in the header of
2561 * its next outbound TCP segment to indicate to its peer that it has
2562 * reduced its congestion window. This is termed the CWR bit. For
2563 * SCTP the same indication is made by including the CWR chunk.
2564 * This chunk contains one data element, i.e. the TSN number that
2565 * was sent in the ECNE chunk. This element represents the lowest
2566 * TSN number in the datagram that was originally marked with the
2569 * Verification Tag: 8.5 Verification Tag [Normal verification]
2571 * (endpoint, asoc, chunk)
2574 * (asoc, reply_msg, msg_up, timers, counters)
2576 * The return value is the disposition of the chunk.
2578 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2579 const struct sctp_association
*asoc
,
2580 const sctp_subtype_t type
,
2582 sctp_cmd_seq_t
*commands
)
2585 struct sctp_chunk
*chunk
= arg
;
2588 if (!sctp_vtag_verify(chunk
, asoc
))
2589 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2591 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2592 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2595 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2596 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2598 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2600 /* Does this CWR ack the last sent congestion notification? */
2601 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2602 /* Stop sending ECNE. */
2603 sctp_add_cmd_sf(commands
,
2605 SCTP_U32(lowest_tsn
));
2607 return SCTP_DISPOSITION_CONSUME
;
2613 * Section: Appendix A: Explicit Congestion Notification
2617 * RFC 2481 details a specific bit for a receiver to send back in its
2618 * TCP acknowledgements to notify the sender of the Congestion
2619 * Experienced (CE) bit having arrived from the network. For SCTP this
2620 * same indication is made by including the ECNE chunk. This chunk
2621 * contains one data element, i.e. the lowest TSN associated with the IP
2622 * datagram marked with the CE bit.....
2624 * Verification Tag: 8.5 Verification Tag [Normal verification]
2626 * (endpoint, asoc, chunk)
2629 * (asoc, reply_msg, msg_up, timers, counters)
2631 * The return value is the disposition of the chunk.
2633 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2634 const struct sctp_association
*asoc
,
2635 const sctp_subtype_t type
,
2637 sctp_cmd_seq_t
*commands
)
2639 sctp_ecnehdr_t
*ecne
;
2640 struct sctp_chunk
*chunk
= arg
;
2642 if (!sctp_vtag_verify(chunk
, asoc
))
2643 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2645 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2646 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2649 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2650 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2652 /* If this is a newer ECNE than the last CWR packet we sent out */
2653 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2654 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2656 return SCTP_DISPOSITION_CONSUME
;
2660 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2662 * The SCTP endpoint MUST always acknowledge the reception of each valid
2665 * The guidelines on delayed acknowledgement algorithm specified in
2666 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2667 * acknowledgement SHOULD be generated for at least every second packet
2668 * (not every second DATA chunk) received, and SHOULD be generated within
2669 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2670 * situations it may be beneficial for an SCTP transmitter to be more
2671 * conservative than the algorithms detailed in this document allow.
2672 * However, an SCTP transmitter MUST NOT be more aggressive than the
2673 * following algorithms allow.
2675 * A SCTP receiver MUST NOT generate more than one SACK for every
2676 * incoming packet, other than to update the offered window as the
2677 * receiving application consumes new data.
2679 * Verification Tag: 8.5 Verification Tag [Normal verification]
2682 * (endpoint, asoc, chunk)
2685 * (asoc, reply_msg, msg_up, timers, counters)
2687 * The return value is the disposition of the chunk.
2689 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2690 const struct sctp_association
*asoc
,
2691 const sctp_subtype_t type
,
2693 sctp_cmd_seq_t
*commands
)
2695 struct sctp_chunk
*chunk
= arg
;
2698 if (!sctp_vtag_verify(chunk
, asoc
)) {
2699 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2701 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2704 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2705 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2708 error
= sctp_eat_data(asoc
, chunk
, commands
);
2710 case SCTP_IERROR_NO_ERROR
:
2712 case SCTP_IERROR_HIGH_TSN
:
2713 case SCTP_IERROR_BAD_STREAM
:
2714 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2715 goto discard_noforce
;
2716 case SCTP_IERROR_DUP_TSN
:
2717 case SCTP_IERROR_IGNORE_TSN
:
2718 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2720 case SCTP_IERROR_NO_DATA
:
2726 if (asoc
->autoclose
) {
2727 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2728 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2731 /* If this is the last chunk in a packet, we need to count it
2732 * toward sack generation. Note that we need to SACK every
2733 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2734 * THEM. We elect to NOT generate SACK's if the chunk fails
2735 * the verification tag test.
2737 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2739 * The SCTP endpoint MUST always acknowledge the reception of
2740 * each valid DATA chunk.
2742 * The guidelines on delayed acknowledgement algorithm
2743 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2744 * Specifically, an acknowledgement SHOULD be generated for at
2745 * least every second packet (not every second DATA chunk)
2746 * received, and SHOULD be generated within 200 ms of the
2747 * arrival of any unacknowledged DATA chunk. In some
2748 * situations it may be beneficial for an SCTP transmitter to
2749 * be more conservative than the algorithms detailed in this
2750 * document allow. However, an SCTP transmitter MUST NOT be
2751 * more aggressive than the following algorithms allow.
2753 if (chunk
->end_of_packet
)
2754 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2756 return SCTP_DISPOSITION_CONSUME
;
2759 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2761 * When a packet arrives with duplicate DATA chunk(s) and with
2762 * no new DATA chunk(s), the endpoint MUST immediately send a
2763 * SACK with no delay. If a packet arrives with duplicate
2764 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2765 * MAY immediately send a SACK. Normally receipt of duplicate
2766 * DATA chunks will occur when the original SACK chunk was lost
2767 * and the peer's RTO has expired. The duplicate TSN number(s)
2768 * SHOULD be reported in the SACK as duplicate.
2770 /* In our case, we split the MAY SACK advice up whether or not
2771 * the last chunk is a duplicate.'
2773 if (chunk
->end_of_packet
)
2774 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2775 return SCTP_DISPOSITION_DISCARD
;
2778 if (chunk
->end_of_packet
)
2779 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2781 return SCTP_DISPOSITION_DISCARD
;
2783 return SCTP_DISPOSITION_CONSUME
;
2788 * sctp_sf_eat_data_fast_4_4
2791 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2792 * DATA chunks without delay.
2794 * Verification Tag: 8.5 Verification Tag [Normal verification]
2796 * (endpoint, asoc, chunk)
2799 * (asoc, reply_msg, msg_up, timers, counters)
2801 * The return value is the disposition of the chunk.
2803 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
2804 const struct sctp_association
*asoc
,
2805 const sctp_subtype_t type
,
2807 sctp_cmd_seq_t
*commands
)
2809 struct sctp_chunk
*chunk
= arg
;
2812 if (!sctp_vtag_verify(chunk
, asoc
)) {
2813 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2815 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2818 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2819 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2822 error
= sctp_eat_data(asoc
, chunk
, commands
);
2824 case SCTP_IERROR_NO_ERROR
:
2825 case SCTP_IERROR_HIGH_TSN
:
2826 case SCTP_IERROR_DUP_TSN
:
2827 case SCTP_IERROR_IGNORE_TSN
:
2828 case SCTP_IERROR_BAD_STREAM
:
2830 case SCTP_IERROR_NO_DATA
:
2836 /* Go a head and force a SACK, since we are shutting down. */
2838 /* Implementor's Guide.
2840 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2841 * respond to each received packet containing one or more DATA chunk(s)
2842 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2844 if (chunk
->end_of_packet
) {
2845 /* We must delay the chunk creation since the cumulative
2846 * TSN has not been updated yet.
2848 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
2849 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2850 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2851 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2855 return SCTP_DISPOSITION_CONSUME
;
2859 * Section: 6.2 Processing a Received SACK
2860 * D) Any time a SACK arrives, the endpoint performs the following:
2862 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2863 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2864 * increasing, a SACK whose Cumulative TSN Ack is less than the
2865 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2867 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2868 * of bytes still outstanding after processing the Cumulative TSN Ack
2869 * and the Gap Ack Blocks.
2871 * iii) If the SACK is missing a TSN that was previously
2872 * acknowledged via a Gap Ack Block (e.g., the data receiver
2873 * reneged on the data), then mark the corresponding DATA chunk
2874 * as available for retransmit: Mark it as missing for fast
2875 * retransmit as described in Section 7.2.4 and if no retransmit
2876 * timer is running for the destination address to which the DATA
2877 * chunk was originally transmitted, then T3-rtx is started for
2878 * that destination address.
2880 * Verification Tag: 8.5 Verification Tag [Normal verification]
2883 * (endpoint, asoc, chunk)
2886 * (asoc, reply_msg, msg_up, timers, counters)
2888 * The return value is the disposition of the chunk.
2890 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
2891 const struct sctp_association
*asoc
,
2892 const sctp_subtype_t type
,
2894 sctp_cmd_seq_t
*commands
)
2896 struct sctp_chunk
*chunk
= arg
;
2897 sctp_sackhdr_t
*sackh
;
2900 if (!sctp_vtag_verify(chunk
, asoc
))
2901 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2903 /* Make sure that the SACK chunk has a valid length. */
2904 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
2905 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2908 /* Pull the SACK chunk from the data buffer */
2909 sackh
= sctp_sm_pull_sack(chunk
);
2910 /* Was this a bogus SACK? */
2912 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2913 chunk
->subh
.sack_hdr
= sackh
;
2914 ctsn
= ntohl(sackh
->cum_tsn_ack
);
2916 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2917 * Ack Point, then drop the SACK. Since Cumulative TSN
2918 * Ack is monotonically increasing, a SACK whose
2919 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2920 * Point indicates an out-of-order SACK.
2922 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2923 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2924 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2925 return SCTP_DISPOSITION_DISCARD
;
2928 /* If Cumulative TSN Ack beyond the max tsn currently
2929 * send, terminating the association and respond to the
2930 * sender with an ABORT.
2932 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2933 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2935 /* Return this SACK for further processing. */
2936 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
2938 /* Note: We do the rest of the work on the PROCESS_SACK
2941 return SCTP_DISPOSITION_CONSUME
;
2945 * Generate an ABORT in response to a packet.
2947 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2949 * 8) The receiver should respond to the sender of the OOTB packet with
2950 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2951 * MUST fill in the Verification Tag field of the outbound packet
2952 * with the value found in the Verification Tag field of the OOTB
2953 * packet and set the T-bit in the Chunk Flags to indicate that the
2954 * Verification Tag is reflected. After sending this ABORT, the
2955 * receiver of the OOTB packet shall discard the OOTB packet and take
2956 * no further action.
2960 * The return value is the disposition of the chunk.
2962 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
2963 const struct sctp_association
*asoc
,
2964 const sctp_subtype_t type
,
2966 sctp_cmd_seq_t
*commands
)
2968 struct sctp_packet
*packet
= NULL
;
2969 struct sctp_chunk
*chunk
= arg
;
2970 struct sctp_chunk
*abort
;
2972 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
2975 /* Make an ABORT. The T bit will be set if the asoc
2978 abort
= sctp_make_abort(asoc
, chunk
, 0);
2980 sctp_ootb_pkt_free(packet
);
2981 return SCTP_DISPOSITION_NOMEM
;
2984 /* Reflect vtag if T-Bit is set */
2985 if (sctp_test_T_bit(abort
))
2986 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
2988 /* Set the skb to the belonging sock for accounting. */
2989 abort
->skb
->sk
= ep
->base
.sk
;
2991 sctp_packet_append_chunk(packet
, abort
);
2993 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
2994 SCTP_PACKET(packet
));
2996 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
2998 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2999 return SCTP_DISPOSITION_CONSUME
;
3002 return SCTP_DISPOSITION_NOMEM
;
3006 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3007 * event as ULP notification for each cause included in the chunk.
3009 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3011 * The return value is the disposition of the chunk.
3013 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
3014 const struct sctp_association
*asoc
,
3015 const sctp_subtype_t type
,
3017 sctp_cmd_seq_t
*commands
)
3019 struct sctp_chunk
*chunk
= arg
;
3020 struct sctp_ulpevent
*ev
;
3022 if (!sctp_vtag_verify(chunk
, asoc
))
3023 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3025 /* Make sure that the ERROR chunk has a valid length. */
3026 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3027 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3030 while (chunk
->chunk_end
> chunk
->skb
->data
) {
3031 ev
= sctp_ulpevent_make_remote_error(asoc
, chunk
, 0,
3036 if (!sctp_add_cmd(commands
, SCTP_CMD_EVENT_ULP
,
3037 SCTP_ULPEVENT(ev
))) {
3038 sctp_ulpevent_free(ev
);
3042 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3045 return SCTP_DISPOSITION_CONSUME
;
3048 return SCTP_DISPOSITION_NOMEM
;
3052 * Process an inbound SHUTDOWN ACK.
3055 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3056 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3057 * peer, and remove all record of the association.
3059 * The return value is the disposition.
3061 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
3062 const struct sctp_association
*asoc
,
3063 const sctp_subtype_t type
,
3065 sctp_cmd_seq_t
*commands
)
3067 struct sctp_chunk
*chunk
= arg
;
3068 struct sctp_chunk
*reply
;
3069 struct sctp_ulpevent
*ev
;
3071 if (!sctp_vtag_verify(chunk
, asoc
))
3072 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3074 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3075 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3076 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3078 /* 10.2 H) SHUTDOWN COMPLETE notification
3080 * When SCTP completes the shutdown procedures (section 9.2) this
3081 * notification is passed to the upper layer.
3083 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3084 0, 0, 0, NULL
, GFP_ATOMIC
);
3088 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3089 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3093 /* Do all the commands now (after allocation), so that we
3094 * have consistent state if memory allocation failes
3096 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3098 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3099 * stop the T2-shutdown timer,
3101 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3102 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3104 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3105 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3107 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3108 SCTP_STATE(SCTP_STATE_CLOSED
));
3109 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
3110 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3111 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3113 /* ...and remove all record of the association. */
3114 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3115 return SCTP_DISPOSITION_DELETE_TCB
;
3118 sctp_ulpevent_free(ev
);
3120 return SCTP_DISPOSITION_NOMEM
;
3124 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3126 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3127 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3128 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3129 * packet must fill in the Verification Tag field of the outbound
3130 * packet with the Verification Tag received in the SHUTDOWN ACK and
3131 * set the T-bit in the Chunk Flags to indicate that the Verification
3134 * 8) The receiver should respond to the sender of the OOTB packet with
3135 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3136 * MUST fill in the Verification Tag field of the outbound packet
3137 * with the value found in the Verification Tag field of the OOTB
3138 * packet and set the T-bit in the Chunk Flags to indicate that the
3139 * Verification Tag is reflected. After sending this ABORT, the
3140 * receiver of the OOTB packet shall discard the OOTB packet and take
3141 * no further action.
3143 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3144 const struct sctp_association
*asoc
,
3145 const sctp_subtype_t type
,
3147 sctp_cmd_seq_t
*commands
)
3149 struct sctp_chunk
*chunk
= arg
;
3150 struct sk_buff
*skb
= chunk
->skb
;
3151 sctp_chunkhdr_t
*ch
;
3153 int ootb_shut_ack
= 0;
3155 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3157 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3159 /* Report violation if the chunk is less then minimal */
3160 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3161 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3164 /* Now that we know we at least have a chunk header,
3165 * do things that are type appropriate.
3167 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3170 /* RFC 2960, Section 3.3.7
3171 * Moreover, under any circumstances, an endpoint that
3172 * receives an ABORT MUST NOT respond to that ABORT by
3173 * sending an ABORT of its own.
3175 if (SCTP_CID_ABORT
== ch
->type
)
3176 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3178 /* Report violation if chunk len overflows */
3179 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3180 if (ch_end
> skb_tail_pointer(skb
))
3181 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3184 ch
= (sctp_chunkhdr_t
*) ch_end
;
3185 } while (ch_end
< skb_tail_pointer(skb
));
3188 return sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3190 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3194 * Handle an "Out of the blue" SHUTDOWN ACK.
3196 * Section: 8.4 5, sctpimpguide 2.41.
3198 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3199 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3200 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3201 * packet must fill in the Verification Tag field of the outbound
3202 * packet with the Verification Tag received in the SHUTDOWN ACK and
3203 * set the T-bit in the Chunk Flags to indicate that the Verification
3207 * (endpoint, asoc, type, arg, commands)
3210 * (sctp_disposition_t)
3212 * The return value is the disposition of the chunk.
3214 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3215 const struct sctp_association
*asoc
,
3216 const sctp_subtype_t type
,
3218 sctp_cmd_seq_t
*commands
)
3220 struct sctp_packet
*packet
= NULL
;
3221 struct sctp_chunk
*chunk
= arg
;
3222 struct sctp_chunk
*shut
;
3224 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3227 /* Make an SHUTDOWN_COMPLETE.
3228 * The T bit will be set if the asoc is NULL.
3230 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3232 sctp_ootb_pkt_free(packet
);
3233 return SCTP_DISPOSITION_NOMEM
;
3236 /* Reflect vtag if T-Bit is set */
3237 if (sctp_test_T_bit(shut
))
3238 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3240 /* Set the skb to the belonging sock for accounting. */
3241 shut
->skb
->sk
= ep
->base
.sk
;
3243 sctp_packet_append_chunk(packet
, shut
);
3245 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3246 SCTP_PACKET(packet
));
3248 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3250 /* If the chunk length is invalid, we don't want to process
3251 * the reset of the packet.
3253 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3254 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3256 /* We need to discard the rest of the packet to prevent
3257 * potential bomming attacks from additional bundled chunks.
3258 * This is documented in SCTP Threats ID.
3260 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3263 return SCTP_DISPOSITION_NOMEM
;
3267 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3269 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3270 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3271 * procedures in section 8.4 SHOULD be followed, in other words it
3272 * should be treated as an Out Of The Blue packet.
3273 * [This means that we do NOT check the Verification Tag on these
3277 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3278 const struct sctp_association
*asoc
,
3279 const sctp_subtype_t type
,
3281 sctp_cmd_seq_t
*commands
)
3283 struct sctp_chunk
*chunk
= arg
;
3285 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3286 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3287 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3290 /* Although we do have an association in this case, it corresponds
3291 * to a restarted association. So the packet is treated as an OOTB
3292 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3293 * called with a NULL association.
3295 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3298 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3299 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3300 const struct sctp_association
*asoc
,
3301 const sctp_subtype_t type
, void *arg
,
3302 sctp_cmd_seq_t
*commands
)
3304 struct sctp_chunk
*chunk
= arg
;
3305 struct sctp_chunk
*asconf_ack
= NULL
;
3306 struct sctp_paramhdr
*err_param
= NULL
;
3307 sctp_addiphdr_t
*hdr
;
3308 union sctp_addr_param
*addr_param
;
3312 if (!sctp_vtag_verify(chunk
, asoc
)) {
3313 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3315 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3318 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3319 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3320 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3323 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3324 serial
= ntohl(hdr
->serial
);
3326 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3327 length
= ntohs(addr_param
->p
.length
);
3328 if (length
< sizeof(sctp_paramhdr_t
))
3329 return sctp_sf_violation_paramlen(ep
, asoc
, type
,
3330 (void *)addr_param
, commands
);
3332 /* Verify the ASCONF chunk before processing it. */
3333 if (!sctp_verify_asconf(asoc
,
3334 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3335 (void *)chunk
->chunk_end
,
3337 return sctp_sf_violation_paramlen(ep
, asoc
, type
,
3338 (void *)&err_param
, commands
);
3340 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3341 * the endpoint stored in a new association variable
3342 * 'Peer-Serial-Number'.
3344 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3345 /* ADDIP 4.2 C2) If the value found in the serial number is
3346 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3349 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3352 return SCTP_DISPOSITION_NOMEM
;
3353 } else if (serial
== asoc
->peer
.addip_serial
) {
3354 /* ADDIP 4.2 C3) If the value found in the serial number is
3355 * equal to the value stored in the 'Peer-Serial-Number'
3356 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3357 * to save the last ASCONF-ACK for some predetermined period of
3358 * time and instead of re-processing the ASCONF (with the same
3359 * serial number) it may just re-transmit the ASCONF-ACK.
3361 if (asoc
->addip_last_asconf_ack
)
3362 asconf_ack
= asoc
->addip_last_asconf_ack
;
3364 return SCTP_DISPOSITION_DISCARD
;
3366 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3367 * it must be either a stale packet or from an attacker.
3369 return SCTP_DISPOSITION_DISCARD
;
3372 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3373 * back to the source address contained in the IP header of the ASCONF
3374 * being responded to.
3376 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3378 return SCTP_DISPOSITION_CONSUME
;
3382 * ADDIP Section 4.3 General rules for address manipulation
3383 * When building TLV parameters for the ASCONF Chunk that will add or
3384 * delete IP addresses the D0 to D13 rules should be applied:
3386 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3387 const struct sctp_association
*asoc
,
3388 const sctp_subtype_t type
, void *arg
,
3389 sctp_cmd_seq_t
*commands
)
3391 struct sctp_chunk
*asconf_ack
= arg
;
3392 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3393 struct sctp_chunk
*abort
;
3394 struct sctp_paramhdr
*err_param
= NULL
;
3395 sctp_addiphdr_t
*addip_hdr
;
3396 __u32 sent_serial
, rcvd_serial
;
3398 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3399 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3401 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3404 /* Make sure that the ADDIP chunk has a valid length. */
3405 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3406 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3409 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3410 rcvd_serial
= ntohl(addip_hdr
->serial
);
3412 /* Verify the ASCONF-ACK chunk before processing it. */
3413 if (!sctp_verify_asconf(asoc
,
3414 (sctp_paramhdr_t
*)addip_hdr
->params
,
3415 (void *)asconf_ack
->chunk_end
,
3417 return sctp_sf_violation_paramlen(ep
, asoc
, type
,
3418 (void *)&err_param
, commands
);
3421 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3422 sent_serial
= ntohl(addip_hdr
->serial
);
3424 sent_serial
= asoc
->addip_serial
- 1;
3427 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3428 * equal to the next serial number to be used but no ASCONF chunk is
3429 * outstanding the endpoint MUST ABORT the association. Note that a
3430 * sequence number is greater than if it is no more than 2^^31-1
3431 * larger than the current sequence number (using serial arithmetic).
3433 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3434 !(asoc
->addip_last_asconf
)) {
3435 abort
= sctp_make_abort(asoc
, asconf_ack
,
3436 sizeof(sctp_errhdr_t
));
3438 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3439 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3442 /* We are going to ABORT, so we might as well stop
3443 * processing the rest of the chunks in the packet.
3445 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3446 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3447 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3448 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3449 SCTP_ERROR(ECONNABORTED
));
3450 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3451 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3452 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3453 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3454 return SCTP_DISPOSITION_ABORT
;
3457 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3458 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3459 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3461 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3463 return SCTP_DISPOSITION_CONSUME
;
3465 abort
= sctp_make_abort(asoc
, asconf_ack
,
3466 sizeof(sctp_errhdr_t
));
3468 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3469 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3472 /* We are going to ABORT, so we might as well stop
3473 * processing the rest of the chunks in the packet.
3475 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3476 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3477 SCTP_ERROR(ECONNABORTED
));
3478 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3479 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3480 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3481 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3482 return SCTP_DISPOSITION_ABORT
;
3485 return SCTP_DISPOSITION_DISCARD
;
3489 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3491 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3492 * its cumulative TSN point to the value carried in the FORWARD TSN
3493 * chunk, and then MUST further advance its cumulative TSN point locally
3495 * After the above processing, the data receiver MUST stop reporting any
3496 * missing TSNs earlier than or equal to the new cumulative TSN point.
3498 * Verification Tag: 8.5 Verification Tag [Normal verification]
3500 * The return value is the disposition of the chunk.
3502 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3503 const struct sctp_association
*asoc
,
3504 const sctp_subtype_t type
,
3506 sctp_cmd_seq_t
*commands
)
3508 struct sctp_chunk
*chunk
= arg
;
3509 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3513 if (!sctp_vtag_verify(chunk
, asoc
)) {
3514 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3516 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3519 /* Make sure that the FORWARD_TSN chunk has valid length. */
3520 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3521 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3524 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3525 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3526 len
= ntohs(chunk
->chunk_hdr
->length
);
3527 len
-= sizeof(struct sctp_chunkhdr
);
3528 skb_pull(chunk
->skb
, len
);
3530 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3531 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3533 /* The TSN is too high--silently discard the chunk and count on it
3534 * getting retransmitted later.
3536 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3537 goto discard_noforce
;
3539 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3540 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3541 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3544 /* Count this as receiving DATA. */
3545 if (asoc
->autoclose
) {
3546 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3547 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3550 /* FIXME: For now send a SACK, but DATA processing may
3553 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3555 return SCTP_DISPOSITION_CONSUME
;
3558 return SCTP_DISPOSITION_DISCARD
;
3561 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3562 const struct sctp_endpoint
*ep
,
3563 const struct sctp_association
*asoc
,
3564 const sctp_subtype_t type
,
3566 sctp_cmd_seq_t
*commands
)
3568 struct sctp_chunk
*chunk
= arg
;
3569 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3573 if (!sctp_vtag_verify(chunk
, asoc
)) {
3574 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3576 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3579 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3580 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3581 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3584 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3585 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3586 len
= ntohs(chunk
->chunk_hdr
->length
);
3587 len
-= sizeof(struct sctp_chunkhdr
);
3588 skb_pull(chunk
->skb
, len
);
3590 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3591 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3593 /* The TSN is too high--silently discard the chunk and count on it
3594 * getting retransmitted later.
3596 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3599 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3600 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3601 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3604 /* Go a head and force a SACK, since we are shutting down. */
3606 /* Implementor's Guide.
3608 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3609 * respond to each received packet containing one or more DATA chunk(s)
3610 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3612 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3613 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3614 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3615 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3617 return SCTP_DISPOSITION_CONSUME
;
3621 * Process an unknown chunk.
3623 * Section: 3.2. Also, 2.1 in the implementor's guide.
3625 * Chunk Types are encoded such that the highest-order two bits specify
3626 * the action that must be taken if the processing endpoint does not
3627 * recognize the Chunk Type.
3629 * 00 - Stop processing this SCTP packet and discard it, do not process
3630 * any further chunks within it.
3632 * 01 - Stop processing this SCTP packet and discard it, do not process
3633 * any further chunks within it, and report the unrecognized
3634 * chunk in an 'Unrecognized Chunk Type'.
3636 * 10 - Skip this chunk and continue processing.
3638 * 11 - Skip this chunk and continue processing, but report in an ERROR
3639 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3641 * The return value is the disposition of the chunk.
3643 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
3644 const struct sctp_association
*asoc
,
3645 const sctp_subtype_t type
,
3647 sctp_cmd_seq_t
*commands
)
3649 struct sctp_chunk
*unk_chunk
= arg
;
3650 struct sctp_chunk
*err_chunk
;
3651 sctp_chunkhdr_t
*hdr
;
3653 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
3655 if (!sctp_vtag_verify(unk_chunk
, asoc
))
3656 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3658 /* Make sure that the chunk has a valid length.
3659 * Since we don't know the chunk type, we use a general
3660 * chunkhdr structure to make a comparison.
3662 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
3663 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3666 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
3667 case SCTP_CID_ACTION_DISCARD
:
3668 /* Discard the packet. */
3669 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3671 case SCTP_CID_ACTION_DISCARD_ERR
:
3672 /* Discard the packet. */
3673 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3675 /* Generate an ERROR chunk as response. */
3676 hdr
= unk_chunk
->chunk_hdr
;
3677 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3678 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3679 WORD_ROUND(ntohs(hdr
->length
)));
3681 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3682 SCTP_CHUNK(err_chunk
));
3684 return SCTP_DISPOSITION_CONSUME
;
3686 case SCTP_CID_ACTION_SKIP
:
3687 /* Skip the chunk. */
3688 return SCTP_DISPOSITION_DISCARD
;
3690 case SCTP_CID_ACTION_SKIP_ERR
:
3691 /* Generate an ERROR chunk as response. */
3692 hdr
= unk_chunk
->chunk_hdr
;
3693 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3694 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3695 WORD_ROUND(ntohs(hdr
->length
)));
3697 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3698 SCTP_CHUNK(err_chunk
));
3700 /* Skip the chunk. */
3701 return SCTP_DISPOSITION_CONSUME
;
3707 return SCTP_DISPOSITION_DISCARD
;
3711 * Discard the chunk.
3713 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3714 * [Too numerous to mention...]
3715 * Verification Tag: No verification needed.
3717 * (endpoint, asoc, chunk)
3720 * (asoc, reply_msg, msg_up, timers, counters)
3722 * The return value is the disposition of the chunk.
3724 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
3725 const struct sctp_association
*asoc
,
3726 const sctp_subtype_t type
,
3728 sctp_cmd_seq_t
*commands
)
3730 struct sctp_chunk
*chunk
= arg
;
3732 /* Make sure that the chunk has a valid length.
3733 * Since we don't know the chunk type, we use a general
3734 * chunkhdr structure to make a comparison.
3736 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3737 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3740 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
3741 return SCTP_DISPOSITION_DISCARD
;
3745 * Discard the whole packet.
3749 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3750 * silently discard the OOTB packet and take no further action.
3752 * Verification Tag: No verification necessary
3755 * (endpoint, asoc, chunk)
3758 * (asoc, reply_msg, msg_up, timers, counters)
3760 * The return value is the disposition of the chunk.
3762 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
3763 const struct sctp_association
*asoc
,
3764 const sctp_subtype_t type
,
3766 sctp_cmd_seq_t
*commands
)
3768 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS
);
3769 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3771 return SCTP_DISPOSITION_CONSUME
;
3776 * The other end is violating protocol.
3778 * Section: Not specified
3779 * Verification Tag: Not specified
3781 * (endpoint, asoc, chunk)
3784 * (asoc, reply_msg, msg_up, timers, counters)
3786 * We simply tag the chunk as a violation. The state machine will log
3787 * the violation and continue.
3789 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
3790 const struct sctp_association
*asoc
,
3791 const sctp_subtype_t type
,
3793 sctp_cmd_seq_t
*commands
)
3795 struct sctp_chunk
*chunk
= arg
;
3797 /* Make sure that the chunk has a valid length. */
3798 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3799 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3802 return SCTP_DISPOSITION_VIOLATION
;
3806 * Common function to handle a protocol violation.
3808 static sctp_disposition_t
sctp_sf_abort_violation(
3809 const struct sctp_endpoint
*ep
,
3810 const struct sctp_association
*asoc
,
3812 sctp_cmd_seq_t
*commands
,
3813 const __u8
*payload
,
3814 const size_t paylen
)
3816 struct sctp_packet
*packet
= NULL
;
3817 struct sctp_chunk
*chunk
= arg
;
3818 struct sctp_chunk
*abort
= NULL
;
3820 /* Make the abort chunk. */
3821 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
3826 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
3827 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3829 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
3830 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3831 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
3832 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3833 SCTP_ERROR(ECONNREFUSED
));
3834 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
3835 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
3837 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3838 SCTP_ERROR(ECONNABORTED
));
3839 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3840 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
3841 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3844 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3849 if (sctp_test_T_bit(abort
))
3850 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3852 abort
->skb
->sk
= ep
->base
.sk
;
3854 sctp_packet_append_chunk(packet
, abort
);
3856 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3857 SCTP_PACKET(packet
));
3859 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3862 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
3864 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3866 return SCTP_DISPOSITION_ABORT
;
3869 sctp_chunk_free(abort
);
3871 return SCTP_DISPOSITION_NOMEM
;
3875 * Handle a protocol violation when the chunk length is invalid.
3876 * "Invalid" length is identified as smaller then the minimal length a
3877 * given chunk can be. For example, a SACK chunk has invalid length
3878 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3880 * We inform the other end by sending an ABORT with a Protocol Violation
3883 * Section: Not specified
3884 * Verification Tag: Nothing to do
3886 * (endpoint, asoc, chunk)
3889 * (reply_msg, msg_up, counters)
3891 * Generate an ABORT chunk and terminate the association.
3893 static sctp_disposition_t
sctp_sf_violation_chunklen(
3894 const struct sctp_endpoint
*ep
,
3895 const struct sctp_association
*asoc
,
3896 const sctp_subtype_t type
,
3898 sctp_cmd_seq_t
*commands
)
3900 char err_str
[]="The following chunk had invalid length:";
3902 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
3907 * Handle a protocol violation when the parameter length is invalid.
3908 * "Invalid" length is identified as smaller then the minimal length a
3909 * given parameter can be.
3911 static sctp_disposition_t
sctp_sf_violation_paramlen(
3912 const struct sctp_endpoint
*ep
,
3913 const struct sctp_association
*asoc
,
3914 const sctp_subtype_t type
,
3916 sctp_cmd_seq_t
*commands
) {
3917 char err_str
[] = "The following parameter had invalid length:";
3919 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
3923 /* Handle a protocol violation when the peer trying to advance the
3924 * cumulative tsn ack to a point beyond the max tsn currently sent.
3926 * We inform the other end by sending an ABORT with a Protocol Violation
3929 static sctp_disposition_t
sctp_sf_violation_ctsn(
3930 const struct sctp_endpoint
*ep
,
3931 const struct sctp_association
*asoc
,
3932 const sctp_subtype_t type
,
3934 sctp_cmd_seq_t
*commands
)
3936 char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
3938 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
3942 /* Handle protocol violation of an invalid chunk bundling. For example,
3943 * when we have an association and we recieve bundled INIT-ACK, or
3944 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
3945 * statement from the specs. Additinally, there might be an attacker
3946 * on the path and we may not want to continue this communication.
3948 static sctp_disposition_t
sctp_sf_violation_chunk(
3949 const struct sctp_endpoint
*ep
,
3950 const struct sctp_association
*asoc
,
3951 const sctp_subtype_t type
,
3953 sctp_cmd_seq_t
*commands
)
3955 char err_str
[]="The following chunk violates protocol:";
3958 return sctp_sf_violation(ep
, asoc
, type
, arg
, commands
);
3960 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
3963 /***************************************************************************
3964 * These are the state functions for handling primitive (Section 10) events.
3965 ***************************************************************************/
3967 * sctp_sf_do_prm_asoc
3969 * Section: 10.1 ULP-to-SCTP
3972 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3973 * outbound stream count)
3974 * -> association id [,destination transport addr list] [,outbound stream
3977 * This primitive allows the upper layer to initiate an association to a
3978 * specific peer endpoint.
3980 * The peer endpoint shall be specified by one of the transport addresses
3981 * which defines the endpoint (see Section 1.4). If the local SCTP
3982 * instance has not been initialized, the ASSOCIATE is considered an
3984 * [This is not relevant for the kernel implementation since we do all
3985 * initialization at boot time. It we hadn't initialized we wouldn't
3986 * get anywhere near this code.]
3988 * An association id, which is a local handle to the SCTP association,
3989 * will be returned on successful establishment of the association. If
3990 * SCTP is not able to open an SCTP association with the peer endpoint,
3991 * an error is returned.
3992 * [In the kernel implementation, the struct sctp_association needs to
3993 * be created BEFORE causing this primitive to run.]
3995 * Other association parameters may be returned, including the
3996 * complete destination transport addresses of the peer as well as the
3997 * outbound stream count of the local endpoint. One of the transport
3998 * address from the returned destination addresses will be selected by
3999 * the local endpoint as default primary path for sending SCTP packets
4000 * to this peer. The returned "destination transport addr list" can
4001 * be used by the ULP to change the default primary path or to force
4002 * sending a packet to a specific transport address. [All of this
4003 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4006 * Mandatory attributes:
4008 * o local SCTP instance name - obtained from the INITIALIZE operation.
4009 * [This is the argument asoc.]
4010 * o destination transport addr - specified as one of the transport
4011 * addresses of the peer endpoint with which the association is to be
4013 * [This is asoc->peer.active_path.]
4014 * o outbound stream count - the number of outbound streams the ULP
4015 * would like to open towards this peer endpoint.
4016 * [BUG: This is not currently implemented.]
4017 * Optional attributes:
4021 * The return value is a disposition.
4023 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
4024 const struct sctp_association
*asoc
,
4025 const sctp_subtype_t type
,
4027 sctp_cmd_seq_t
*commands
)
4029 struct sctp_chunk
*repl
;
4031 /* The comment below says that we enter COOKIE-WAIT AFTER
4032 * sending the INIT, but that doesn't actually work in our
4035 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4036 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4038 /* RFC 2960 5.1 Normal Establishment of an Association
4040 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4041 * must provide its Verification Tag (Tag_A) in the Initiate
4042 * Tag field. Tag_A SHOULD be a random number in the range of
4043 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4046 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4050 /* Cast away the const modifier, as we want to just
4051 * rerun it through as a sideffect.
4053 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
,
4054 SCTP_ASOC((struct sctp_association
*) asoc
));
4056 /* Choose transport for INIT. */
4057 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4060 /* After sending the INIT, "A" starts the T1-init timer and
4061 * enters the COOKIE-WAIT state.
4063 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4064 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4065 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4066 return SCTP_DISPOSITION_CONSUME
;
4069 return SCTP_DISPOSITION_NOMEM
;
4073 * Process the SEND primitive.
4075 * Section: 10.1 ULP-to-SCTP
4078 * Format: SEND(association id, buffer address, byte count [,context]
4079 * [,stream id] [,life time] [,destination transport address]
4080 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4083 * This is the main method to send user data via SCTP.
4085 * Mandatory attributes:
4087 * o association id - local handle to the SCTP association
4089 * o buffer address - the location where the user message to be
4090 * transmitted is stored;
4092 * o byte count - The size of the user data in number of bytes;
4094 * Optional attributes:
4096 * o context - an optional 32 bit integer that will be carried in the
4097 * sending failure notification to the ULP if the transportation of
4098 * this User Message fails.
4100 * o stream id - to indicate which stream to send the data on. If not
4101 * specified, stream 0 will be used.
4103 * o life time - specifies the life time of the user data. The user data
4104 * will not be sent by SCTP after the life time expires. This
4105 * parameter can be used to avoid efforts to transmit stale
4106 * user messages. SCTP notifies the ULP if the data cannot be
4107 * initiated to transport (i.e. sent to the destination via SCTP's
4108 * send primitive) within the life time variable. However, the
4109 * user data will be transmitted if SCTP has attempted to transmit a
4110 * chunk before the life time expired.
4112 * o destination transport address - specified as one of the destination
4113 * transport addresses of the peer endpoint to which this packet
4114 * should be sent. Whenever possible, SCTP should use this destination
4115 * transport address for sending the packets, instead of the current
4118 * o unorder flag - this flag, if present, indicates that the user
4119 * would like the data delivered in an unordered fashion to the peer
4120 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4123 * o no-bundle flag - instructs SCTP not to bundle this user data with
4124 * other outbound DATA chunks. SCTP MAY still bundle even when
4125 * this flag is present, when faced with network congestion.
4127 * o payload protocol-id - A 32 bit unsigned integer that is to be
4128 * passed to the peer indicating the type of payload protocol data
4129 * being transmitted. This value is passed as opaque data by SCTP.
4131 * The return value is the disposition.
4133 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
4134 const struct sctp_association
*asoc
,
4135 const sctp_subtype_t type
,
4137 sctp_cmd_seq_t
*commands
)
4139 struct sctp_chunk
*chunk
= arg
;
4141 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4142 return SCTP_DISPOSITION_CONSUME
;
4146 * Process the SHUTDOWN primitive.
4151 * Format: SHUTDOWN(association id)
4154 * Gracefully closes an association. Any locally queued user data
4155 * will be delivered to the peer. The association will be terminated only
4156 * after the peer acknowledges all the SCTP packets sent. A success code
4157 * will be returned on successful termination of the association. If
4158 * attempting to terminate the association results in a failure, an error
4159 * code shall be returned.
4161 * Mandatory attributes:
4163 * o association id - local handle to the SCTP association
4165 * Optional attributes:
4169 * The return value is the disposition.
4171 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4172 const struct sctp_endpoint
*ep
,
4173 const struct sctp_association
*asoc
,
4174 const sctp_subtype_t type
,
4176 sctp_cmd_seq_t
*commands
)
4180 /* From 9.2 Shutdown of an Association
4181 * Upon receipt of the SHUTDOWN primitive from its upper
4182 * layer, the endpoint enters SHUTDOWN-PENDING state and
4183 * remains there until all outstanding data has been
4184 * acknowledged by its peer. The endpoint accepts no new data
4185 * from its upper layer, but retransmits data to the far end
4186 * if necessary to fill gaps.
4188 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4189 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4191 /* sctpimpguide-05 Section 2.12.2
4192 * The sender of the SHUTDOWN MAY also start an overall guard timer
4193 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4195 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4196 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4198 disposition
= SCTP_DISPOSITION_CONSUME
;
4199 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4200 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4207 * Process the ABORT primitive.
4212 * Format: Abort(association id [, cause code])
4215 * Ungracefully closes an association. Any locally queued user data
4216 * will be discarded and an ABORT chunk is sent to the peer. A success code
4217 * will be returned on successful abortion of the association. If
4218 * attempting to abort the association results in a failure, an error
4219 * code shall be returned.
4221 * Mandatory attributes:
4223 * o association id - local handle to the SCTP association
4225 * Optional attributes:
4227 * o cause code - reason of the abort to be passed to the peer
4231 * The return value is the disposition.
4233 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4234 const struct sctp_endpoint
*ep
,
4235 const struct sctp_association
*asoc
,
4236 const sctp_subtype_t type
,
4238 sctp_cmd_seq_t
*commands
)
4240 /* From 9.1 Abort of an Association
4241 * Upon receipt of the ABORT primitive from its upper
4242 * layer, the endpoint enters CLOSED state and
4243 * discard all outstanding data has been
4244 * acknowledged by its peer. The endpoint accepts no new data
4245 * from its upper layer, but retransmits data to the far end
4246 * if necessary to fill gaps.
4248 struct sctp_chunk
*abort
= arg
;
4249 sctp_disposition_t retval
;
4251 retval
= SCTP_DISPOSITION_CONSUME
;
4253 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4255 /* Even if we can't send the ABORT due to low memory delete the
4256 * TCB. This is a departure from our typical NOMEM handling.
4259 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4260 SCTP_ERROR(ECONNABORTED
));
4261 /* Delete the established association. */
4262 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4263 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4265 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4266 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4271 /* We tried an illegal operation on an association which is closed. */
4272 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4273 const struct sctp_association
*asoc
,
4274 const sctp_subtype_t type
,
4276 sctp_cmd_seq_t
*commands
)
4278 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4279 return SCTP_DISPOSITION_CONSUME
;
4282 /* We tried an illegal operation on an association which is shutting
4285 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4286 const struct sctp_association
*asoc
,
4287 const sctp_subtype_t type
,
4289 sctp_cmd_seq_t
*commands
)
4291 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4292 SCTP_ERROR(-ESHUTDOWN
));
4293 return SCTP_DISPOSITION_CONSUME
;
4297 * sctp_cookie_wait_prm_shutdown
4299 * Section: 4 Note: 2
4304 * The RFC does not explicitly address this issue, but is the route through the
4305 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4310 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4311 const struct sctp_endpoint
*ep
,
4312 const struct sctp_association
*asoc
,
4313 const sctp_subtype_t type
,
4315 sctp_cmd_seq_t
*commands
)
4317 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4318 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4320 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4321 SCTP_STATE(SCTP_STATE_CLOSED
));
4323 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
4325 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4327 return SCTP_DISPOSITION_DELETE_TCB
;
4331 * sctp_cookie_echoed_prm_shutdown
4333 * Section: 4 Note: 2
4338 * The RFC does not explcitly address this issue, but is the route through the
4339 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4344 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4345 const struct sctp_endpoint
*ep
,
4346 const struct sctp_association
*asoc
,
4347 const sctp_subtype_t type
,
4348 void *arg
, sctp_cmd_seq_t
*commands
)
4350 /* There is a single T1 timer, so we should be able to use
4351 * common function with the COOKIE-WAIT state.
4353 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4357 * sctp_sf_cookie_wait_prm_abort
4359 * Section: 4 Note: 2
4364 * The RFC does not explicitly address this issue, but is the route through the
4365 * state table when someone issues an abort while in COOKIE_WAIT state.
4370 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4371 const struct sctp_endpoint
*ep
,
4372 const struct sctp_association
*asoc
,
4373 const sctp_subtype_t type
,
4375 sctp_cmd_seq_t
*commands
)
4377 struct sctp_chunk
*abort
= arg
;
4378 sctp_disposition_t retval
;
4380 /* Stop T1-init timer */
4381 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4382 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4383 retval
= SCTP_DISPOSITION_CONSUME
;
4385 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4387 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4388 SCTP_STATE(SCTP_STATE_CLOSED
));
4390 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4392 /* Even if we can't send the ABORT due to low memory delete the
4393 * TCB. This is a departure from our typical NOMEM handling.
4396 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4397 SCTP_ERROR(ECONNREFUSED
));
4398 /* Delete the established association. */
4399 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4400 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4406 * sctp_sf_cookie_echoed_prm_abort
4408 * Section: 4 Note: 3
4413 * The RFC does not explcitly address this issue, but is the route through the
4414 * state table when someone issues an abort while in COOKIE_ECHOED state.
4419 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4420 const struct sctp_endpoint
*ep
,
4421 const struct sctp_association
*asoc
,
4422 const sctp_subtype_t type
,
4424 sctp_cmd_seq_t
*commands
)
4426 /* There is a single T1 timer, so we should be able to use
4427 * common function with the COOKIE-WAIT state.
4429 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4433 * sctp_sf_shutdown_pending_prm_abort
4438 * The RFC does not explicitly address this issue, but is the route through the
4439 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4444 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4445 const struct sctp_endpoint
*ep
,
4446 const struct sctp_association
*asoc
,
4447 const sctp_subtype_t type
,
4449 sctp_cmd_seq_t
*commands
)
4451 /* Stop the T5-shutdown guard timer. */
4452 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4453 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4455 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4459 * sctp_sf_shutdown_sent_prm_abort
4464 * The RFC does not explicitly address this issue, but is the route through the
4465 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4470 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
4471 const struct sctp_endpoint
*ep
,
4472 const struct sctp_association
*asoc
,
4473 const sctp_subtype_t type
,
4475 sctp_cmd_seq_t
*commands
)
4477 /* Stop the T2-shutdown timer. */
4478 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4479 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4481 /* Stop the T5-shutdown guard timer. */
4482 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4483 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4485 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4489 * sctp_sf_cookie_echoed_prm_abort
4494 * The RFC does not explcitly address this issue, but is the route through the
4495 * state table when someone issues an abort while in COOKIE_ECHOED state.
4500 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
4501 const struct sctp_endpoint
*ep
,
4502 const struct sctp_association
*asoc
,
4503 const sctp_subtype_t type
,
4505 sctp_cmd_seq_t
*commands
)
4507 /* The same T2 timer, so we should be able to use
4508 * common function with the SHUTDOWN-SENT state.
4510 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
4514 * Process the REQUESTHEARTBEAT primitive
4517 * J) Request Heartbeat
4519 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4523 * Instructs the local endpoint to perform a HeartBeat on the specified
4524 * destination transport address of the given association. The returned
4525 * result should indicate whether the transmission of the HEARTBEAT
4526 * chunk to the destination address is successful.
4528 * Mandatory attributes:
4530 * o association id - local handle to the SCTP association
4532 * o destination transport address - the transport address of the
4533 * association on which a heartbeat should be issued.
4535 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
4536 const struct sctp_endpoint
*ep
,
4537 const struct sctp_association
*asoc
,
4538 const sctp_subtype_t type
,
4540 sctp_cmd_seq_t
*commands
)
4542 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
4543 (struct sctp_transport
*)arg
, commands
))
4544 return SCTP_DISPOSITION_NOMEM
;
4547 * RFC 2960 (bis), section 8.3
4549 * D) Request an on-demand HEARTBEAT on a specific destination
4550 * transport address of a given association.
4552 * The endpoint should increment the respective error counter of
4553 * the destination transport address each time a HEARTBEAT is sent
4554 * to that address and not acknowledged within one RTO.
4557 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
4558 SCTP_TRANSPORT(arg
));
4559 return SCTP_DISPOSITION_CONSUME
;
4563 * ADDIP Section 4.1 ASCONF Chunk Procedures
4564 * When an endpoint has an ASCONF signaled change to be sent to the
4565 * remote endpoint it should do A1 to A9
4567 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
4568 const struct sctp_association
*asoc
,
4569 const sctp_subtype_t type
,
4571 sctp_cmd_seq_t
*commands
)
4573 struct sctp_chunk
*chunk
= arg
;
4575 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4576 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4577 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4578 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4579 return SCTP_DISPOSITION_CONSUME
;
4583 * Ignore the primitive event
4585 * The return value is the disposition of the primitive.
4587 sctp_disposition_t
sctp_sf_ignore_primitive(
4588 const struct sctp_endpoint
*ep
,
4589 const struct sctp_association
*asoc
,
4590 const sctp_subtype_t type
,
4592 sctp_cmd_seq_t
*commands
)
4594 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
4595 return SCTP_DISPOSITION_DISCARD
;
4598 /***************************************************************************
4599 * These are the state functions for the OTHER events.
4600 ***************************************************************************/
4603 * Start the shutdown negotiation.
4606 * Once all its outstanding data has been acknowledged, the endpoint
4607 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4608 * TSN Ack field the last sequential TSN it has received from the peer.
4609 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4610 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4611 * with the updated last sequential TSN received from its peer.
4613 * The return value is the disposition.
4615 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
4616 const struct sctp_endpoint
*ep
,
4617 const struct sctp_association
*asoc
,
4618 const sctp_subtype_t type
,
4620 sctp_cmd_seq_t
*commands
)
4622 struct sctp_chunk
*reply
;
4624 /* Once all its outstanding data has been acknowledged, the
4625 * endpoint shall send a SHUTDOWN chunk to its peer including
4626 * in the Cumulative TSN Ack field the last sequential TSN it
4627 * has received from the peer.
4629 reply
= sctp_make_shutdown(asoc
, NULL
);
4633 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4634 * T2-shutdown timer.
4636 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4638 /* It shall then start the T2-shutdown timer */
4639 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4640 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4642 if (asoc
->autoclose
)
4643 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4644 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4646 /* and enter the SHUTDOWN-SENT state. */
4647 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4648 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
4650 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4652 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4655 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4657 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4659 return SCTP_DISPOSITION_CONSUME
;
4662 return SCTP_DISPOSITION_NOMEM
;
4666 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4670 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4671 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4672 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4673 * endpoint must re-send the SHUTDOWN ACK.
4675 * The return value is the disposition.
4677 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
4678 const struct sctp_endpoint
*ep
,
4679 const struct sctp_association
*asoc
,
4680 const sctp_subtype_t type
,
4682 sctp_cmd_seq_t
*commands
)
4684 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
4685 struct sctp_chunk
*reply
;
4687 /* There are 2 ways of getting here:
4688 * 1) called in response to a SHUTDOWN chunk
4689 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4691 * For the case (2), the arg parameter is set to NULL. We need
4692 * to check that we have a chunk before accessing it's fields.
4695 if (!sctp_vtag_verify(chunk
, asoc
))
4696 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4698 /* Make sure that the SHUTDOWN chunk has a valid length. */
4699 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
4700 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4704 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4705 * shall send a SHUTDOWN ACK ...
4707 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
4711 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4712 * the T2-shutdown timer.
4714 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4716 /* and start/restart a T2-shutdown timer of its own, */
4717 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4718 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4720 if (asoc
->autoclose
)
4721 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4722 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4724 /* Enter the SHUTDOWN-ACK-SENT state. */
4725 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4726 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
4728 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4730 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4733 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4735 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4737 return SCTP_DISPOSITION_CONSUME
;
4740 return SCTP_DISPOSITION_NOMEM
;
4744 * Ignore the event defined as other
4746 * The return value is the disposition of the event.
4748 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
4749 const struct sctp_association
*asoc
,
4750 const sctp_subtype_t type
,
4752 sctp_cmd_seq_t
*commands
)
4754 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
4755 return SCTP_DISPOSITION_DISCARD
;
4758 /************************************************************
4759 * These are the state functions for handling timeout events.
4760 ************************************************************/
4765 * Section: 6.3.3 Handle T3-rtx Expiration
4767 * Whenever the retransmission timer T3-rtx expires for a destination
4768 * address, do the following:
4771 * The return value is the disposition of the chunk.
4773 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
4774 const struct sctp_association
*asoc
,
4775 const sctp_subtype_t type
,
4777 sctp_cmd_seq_t
*commands
)
4779 struct sctp_transport
*transport
= arg
;
4781 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS
);
4783 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4784 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4785 SCTP_ERROR(ETIMEDOUT
));
4786 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4787 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4788 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4789 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4790 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4791 return SCTP_DISPOSITION_DELETE_TCB
;
4794 /* E1) For the destination address for which the timer
4795 * expires, adjust its ssthresh with rules defined in Section
4796 * 7.2.3 and set the cwnd <- MTU.
4799 /* E2) For the destination address for which the timer
4800 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4801 * maximum value discussed in rule C7 above (RTO.max) may be
4802 * used to provide an upper bound to this doubling operation.
4805 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4806 * outstanding DATA chunks for the address for which the
4807 * T3-rtx has expired will fit into a single packet, subject
4808 * to the MTU constraint for the path corresponding to the
4809 * destination transport address to which the retransmission
4810 * is being sent (this may be different from the address for
4811 * which the timer expires [see Section 6.4]). Call this
4812 * value K. Bundle and retransmit those K DATA chunks in a
4813 * single packet to the destination endpoint.
4815 * Note: Any DATA chunks that were sent to the address for
4816 * which the T3-rtx timer expired but did not fit in one MTU
4817 * (rule E3 above), should be marked for retransmission and
4818 * sent as soon as cwnd allows (normally when a SACK arrives).
4821 /* Do some failure management (Section 8.2). */
4822 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
4824 /* NB: Rules E4 and F1 are implicit in R1. */
4825 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
4827 return SCTP_DISPOSITION_CONSUME
;
4831 * Generate delayed SACK on timeout
4833 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4835 * The guidelines on delayed acknowledgement algorithm specified in
4836 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4837 * acknowledgement SHOULD be generated for at least every second packet
4838 * (not every second DATA chunk) received, and SHOULD be generated
4839 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4840 * some situations it may be beneficial for an SCTP transmitter to be
4841 * more conservative than the algorithms detailed in this document
4842 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4843 * the following algorithms allow.
4845 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
4846 const struct sctp_association
*asoc
,
4847 const sctp_subtype_t type
,
4849 sctp_cmd_seq_t
*commands
)
4851 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS
);
4852 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4853 return SCTP_DISPOSITION_CONSUME
;
4857 * sctp_sf_t1_init_timer_expire
4859 * Section: 4 Note: 2
4864 * RFC 2960 Section 4 Notes
4865 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4866 * and re-start the T1-init timer without changing state. This MUST
4867 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4868 * endpoint MUST abort the initialization process and report the
4869 * error to SCTP user.
4875 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
4876 const struct sctp_association
*asoc
,
4877 const sctp_subtype_t type
,
4879 sctp_cmd_seq_t
*commands
)
4881 struct sctp_chunk
*repl
= NULL
;
4882 struct sctp_bind_addr
*bp
;
4883 int attempts
= asoc
->init_err_counter
+ 1;
4885 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4886 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS
);
4888 if (attempts
<= asoc
->max_init_attempts
) {
4889 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
4890 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
4892 return SCTP_DISPOSITION_NOMEM
;
4894 /* Choose transport for INIT. */
4895 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4898 /* Issue a sideeffect to do the needed accounting. */
4899 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
4900 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4902 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4904 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4905 " max_init_attempts: %d\n",
4906 attempts
, asoc
->max_init_attempts
);
4907 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4908 SCTP_ERROR(ETIMEDOUT
));
4909 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4910 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4911 return SCTP_DISPOSITION_DELETE_TCB
;
4914 return SCTP_DISPOSITION_CONSUME
;
4918 * sctp_sf_t1_cookie_timer_expire
4920 * Section: 4 Note: 2
4925 * RFC 2960 Section 4 Notes
4926 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4927 * COOKIE ECHO and re-start the T1-cookie timer without changing
4928 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4929 * After that, the endpoint MUST abort the initialization process and
4930 * report the error to SCTP user.
4936 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
4937 const struct sctp_association
*asoc
,
4938 const sctp_subtype_t type
,
4940 sctp_cmd_seq_t
*commands
)
4942 struct sctp_chunk
*repl
= NULL
;
4943 int attempts
= asoc
->init_err_counter
+ 1;
4945 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4946 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS
);
4948 if (attempts
<= asoc
->max_init_attempts
) {
4949 repl
= sctp_make_cookie_echo(asoc
, NULL
);
4951 return SCTP_DISPOSITION_NOMEM
;
4953 /* Issue a sideeffect to do the needed accounting. */
4954 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
4955 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
4957 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4959 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4960 SCTP_ERROR(ETIMEDOUT
));
4961 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4962 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4963 return SCTP_DISPOSITION_DELETE_TCB
;
4966 return SCTP_DISPOSITION_CONSUME
;
4969 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4970 * with the updated last sequential TSN received from its peer.
4972 * An endpoint should limit the number of retransmissions of the
4973 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4974 * If this threshold is exceeded the endpoint should destroy the TCB and
4975 * MUST report the peer endpoint unreachable to the upper layer (and
4976 * thus the association enters the CLOSED state). The reception of any
4977 * packet from its peer (i.e. as the peer sends all of its queued DATA
4978 * chunks) should clear the endpoint's retransmission count and restart
4979 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4980 * all of its queued DATA chunks that have not yet been sent.
4982 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
4983 const struct sctp_association
*asoc
,
4984 const sctp_subtype_t type
,
4986 sctp_cmd_seq_t
*commands
)
4988 struct sctp_chunk
*reply
= NULL
;
4990 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4991 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
4993 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4994 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4995 SCTP_ERROR(ETIMEDOUT
));
4996 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4997 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4998 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4999 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5000 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5001 return SCTP_DISPOSITION_DELETE_TCB
;
5004 switch (asoc
->state
) {
5005 case SCTP_STATE_SHUTDOWN_SENT
:
5006 reply
= sctp_make_shutdown(asoc
, NULL
);
5009 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5010 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5021 /* Do some failure management (Section 8.2). */
5022 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5023 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5025 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5026 * the T2-shutdown timer.
5028 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5030 /* Restart the T2-shutdown timer. */
5031 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5032 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5033 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5034 return SCTP_DISPOSITION_CONSUME
;
5037 return SCTP_DISPOSITION_NOMEM
;
5041 * ADDIP Section 4.1 ASCONF CHunk Procedures
5042 * If the T4 RTO timer expires the endpoint should do B1 to B5
5044 sctp_disposition_t
sctp_sf_t4_timer_expire(
5045 const struct sctp_endpoint
*ep
,
5046 const struct sctp_association
*asoc
,
5047 const sctp_subtype_t type
,
5049 sctp_cmd_seq_t
*commands
)
5051 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5052 struct sctp_transport
*transport
= chunk
->transport
;
5054 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS
);
5056 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5057 * detection on the appropriate destination address as defined in
5058 * RFC2960 [5] section 8.1 and 8.2.
5060 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5062 /* Reconfig T4 timer and transport. */
5063 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5065 /* ADDIP 4.1 B2) Increment the association error counters and perform
5066 * endpoint failure detection on the association as defined in
5067 * RFC2960 [5] section 8.1 and 8.2.
5068 * association error counter is incremented in SCTP_CMD_STRIKE.
5070 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5071 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5072 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5073 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5074 SCTP_ERROR(ETIMEDOUT
));
5075 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5076 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5077 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5078 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
5079 return SCTP_DISPOSITION_ABORT
;
5082 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5083 * the ASCONF chunk was sent by doubling the RTO timer value.
5084 * This is done in SCTP_CMD_STRIKE.
5087 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5088 * choose an alternate destination address (please refer to RFC2960
5089 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5090 * chunk, it MUST be the same (including its serial number) as the last
5093 sctp_chunk_hold(asoc
->addip_last_asconf
);
5094 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5095 SCTP_CHUNK(asoc
->addip_last_asconf
));
5097 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5098 * destination is selected, then the RTO used will be that of the new
5099 * destination address.
5101 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5102 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5104 return SCTP_DISPOSITION_CONSUME
;
5107 /* sctpimpguide-05 Section 2.12.2
5108 * The sender of the SHUTDOWN MAY also start an overall guard timer
5109 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5110 * At the expiration of this timer the sender SHOULD abort the association
5111 * by sending an ABORT chunk.
5113 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
5114 const struct sctp_association
*asoc
,
5115 const sctp_subtype_t type
,
5117 sctp_cmd_seq_t
*commands
)
5119 struct sctp_chunk
*reply
= NULL
;
5121 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5122 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5124 reply
= sctp_make_abort(asoc
, NULL
, 0);
5128 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5129 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5130 SCTP_ERROR(ETIMEDOUT
));
5131 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5132 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5134 return SCTP_DISPOSITION_DELETE_TCB
;
5136 return SCTP_DISPOSITION_NOMEM
;
5139 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5140 * the association is automatically closed by starting the shutdown process.
5141 * The work that needs to be done is same as when SHUTDOWN is initiated by
5142 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5144 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5145 const struct sctp_endpoint
*ep
,
5146 const struct sctp_association
*asoc
,
5147 const sctp_subtype_t type
,
5149 sctp_cmd_seq_t
*commands
)
5153 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5155 /* From 9.2 Shutdown of an Association
5156 * Upon receipt of the SHUTDOWN primitive from its upper
5157 * layer, the endpoint enters SHUTDOWN-PENDING state and
5158 * remains there until all outstanding data has been
5159 * acknowledged by its peer. The endpoint accepts no new data
5160 * from its upper layer, but retransmits data to the far end
5161 * if necessary to fill gaps.
5163 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5164 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5166 /* sctpimpguide-05 Section 2.12.2
5167 * The sender of the SHUTDOWN MAY also start an overall guard timer
5168 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5170 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5171 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5172 disposition
= SCTP_DISPOSITION_CONSUME
;
5173 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5174 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
5180 /*****************************************************************************
5181 * These are sa state functions which could apply to all types of events.
5182 ****************************************************************************/
5185 * This table entry is not implemented.
5188 * (endpoint, asoc, chunk)
5190 * The return value is the disposition of the chunk.
5192 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
5193 const struct sctp_association
*asoc
,
5194 const sctp_subtype_t type
,
5196 sctp_cmd_seq_t
*commands
)
5198 return SCTP_DISPOSITION_NOT_IMPL
;
5202 * This table entry represents a bug.
5205 * (endpoint, asoc, chunk)
5207 * The return value is the disposition of the chunk.
5209 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
5210 const struct sctp_association
*asoc
,
5211 const sctp_subtype_t type
,
5213 sctp_cmd_seq_t
*commands
)
5215 return SCTP_DISPOSITION_BUG
;
5219 * This table entry represents the firing of a timer in the wrong state.
5220 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5221 * when the association is in the wrong state. This event should
5222 * be ignored, so as to prevent any rearming of the timer.
5225 * (endpoint, asoc, chunk)
5227 * The return value is the disposition of the chunk.
5229 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
5230 const struct sctp_association
*asoc
,
5231 const sctp_subtype_t type
,
5233 sctp_cmd_seq_t
*commands
)
5235 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5236 return SCTP_DISPOSITION_CONSUME
;
5239 /********************************************************************
5240 * 2nd Level Abstractions
5241 ********************************************************************/
5243 /* Pull the SACK chunk based on the SACK header. */
5244 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5246 struct sctp_sackhdr
*sack
;
5251 /* Protect ourselves from reading too far into
5252 * the skb from a bogus sender.
5254 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5256 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5257 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5258 len
= sizeof(struct sctp_sackhdr
);
5259 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5260 if (len
> chunk
->skb
->len
)
5263 skb_pull(chunk
->skb
, len
);
5268 /* Create an ABORT packet to be sent as a response, with the specified
5271 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5272 const struct sctp_association
*asoc
,
5273 struct sctp_chunk
*chunk
,
5274 const void *payload
,
5277 struct sctp_packet
*packet
;
5278 struct sctp_chunk
*abort
;
5280 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5284 * The T bit will be set if the asoc is NULL.
5286 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5288 sctp_ootb_pkt_free(packet
);
5292 /* Reflect vtag if T-Bit is set */
5293 if (sctp_test_T_bit(abort
))
5294 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5296 /* Add specified error causes, i.e., payload, to the
5299 sctp_addto_chunk(abort
, paylen
, payload
);
5301 /* Set the skb to the belonging sock for accounting. */
5302 abort
->skb
->sk
= ep
->base
.sk
;
5304 sctp_packet_append_chunk(packet
, abort
);
5311 /* Allocate a packet for responding in the OOTB conditions. */
5312 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
5313 const struct sctp_chunk
*chunk
)
5315 struct sctp_packet
*packet
;
5316 struct sctp_transport
*transport
;
5321 /* Get the source and destination port from the inbound packet. */
5322 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5323 dport
= ntohs(chunk
->sctp_hdr
->source
);
5325 /* The V-tag is going to be the same as the inbound packet if no
5326 * association exists, otherwise, use the peer's vtag.
5329 /* Special case the INIT-ACK as there is no peer's vtag
5332 switch(chunk
->chunk_hdr
->type
) {
5333 case SCTP_CID_INIT_ACK
:
5335 sctp_initack_chunk_t
*initack
;
5337 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5338 vtag
= ntohl(initack
->init_hdr
.init_tag
);
5342 vtag
= asoc
->peer
.i
.init_tag
;
5346 /* Special case the INIT and stale COOKIE_ECHO as there is no
5349 switch(chunk
->chunk_hdr
->type
) {
5352 sctp_init_chunk_t
*init
;
5354 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5355 vtag
= ntohl(init
->init_hdr
.init_tag
);
5359 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5364 /* Make a transport for the bucket, Eliza... */
5365 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5369 /* Cache a route for the transport with the chunk's destination as
5370 * the source address.
5372 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5373 sctp_sk(sctp_get_ctl_sock()));
5375 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5376 packet
= sctp_packet_config(packet
, vtag
, 0);
5384 /* Free the packet allocated earlier for responding in the OOTB condition. */
5385 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5387 sctp_transport_free(packet
->transport
);
5390 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5391 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5392 const struct sctp_association
*asoc
,
5393 const struct sctp_chunk
*chunk
,
5394 sctp_cmd_seq_t
*commands
,
5395 struct sctp_chunk
*err_chunk
)
5397 struct sctp_packet
*packet
;
5400 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5402 struct sctp_signed_cookie
*cookie
;
5404 /* Override the OOTB vtag from the cookie. */
5405 cookie
= chunk
->subh
.cookie_hdr
;
5406 packet
->vtag
= cookie
->c
.peer_vtag
;
5408 /* Set the skb to the belonging sock for accounting. */
5409 err_chunk
->skb
->sk
= ep
->base
.sk
;
5410 sctp_packet_append_chunk(packet
, err_chunk
);
5411 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
5412 SCTP_PACKET(packet
));
5413 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
5415 sctp_chunk_free (err_chunk
);
5420 /* Process a data chunk */
5421 static int sctp_eat_data(const struct sctp_association
*asoc
,
5422 struct sctp_chunk
*chunk
,
5423 sctp_cmd_seq_t
*commands
)
5425 sctp_datahdr_t
*data_hdr
;
5426 struct sctp_chunk
*err
;
5428 sctp_verb_t deliver
;
5432 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
5433 struct sock
*sk
= asoc
->base
.sk
;
5434 int rcvbuf_over
= 0;
5436 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
5437 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
5439 tsn
= ntohl(data_hdr
->tsn
);
5440 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
5442 /* ASSERT: Now skb->data is really the user data. */
5445 * If we are established, and we have used up our receive buffer
5446 * memory, think about droping the frame.
5447 * Note that we have an opportunity to improve performance here.
5448 * If we accept one chunk from an skbuff, we have to keep all the
5449 * memory of that skbuff around until the chunk is read into user
5450 * space. Therefore, once we accept 1 chunk we may as well accept all
5451 * remaining chunks in the skbuff. The data_accepted flag helps us do
5454 if ((asoc
->state
== SCTP_STATE_ESTABLISHED
) && (!chunk
->data_accepted
)) {
5456 * If the receive buffer policy is 1, then each
5457 * association can allocate up to sk_rcvbuf bytes
5458 * otherwise, all the associations in aggregate
5459 * may allocate up to sk_rcvbuf bytes
5461 if (asoc
->ep
->rcvbuf_policy
)
5462 account_value
= atomic_read(&asoc
->rmem_alloc
);
5464 account_value
= atomic_read(&sk
->sk_rmem_alloc
);
5465 if (account_value
> sk
->sk_rcvbuf
) {
5467 * We need to make forward progress, even when we are
5468 * under memory pressure, so we always allow the
5469 * next tsn after the ctsn ack point to be accepted.
5470 * This lets us avoid deadlocks in which we have to
5471 * drop frames that would otherwise let us drain the
5474 if ((sctp_tsnmap_get_ctsn(map
) + 1) != tsn
)
5475 return SCTP_IERROR_IGNORE_TSN
;
5478 * We're going to accept the frame but we should renege
5479 * to make space for it. This will send us down that
5480 * path later in this function.
5486 /* Process ECN based congestion.
5488 * Since the chunk structure is reused for all chunks within
5489 * a packet, we use ecn_ce_done to track if we've already
5490 * done CE processing for this packet.
5492 * We need to do ECN processing even if we plan to discard the
5496 if (!chunk
->ecn_ce_done
) {
5498 chunk
->ecn_ce_done
= 1;
5500 af
= sctp_get_af_specific(
5501 ipver2af(ip_hdr(chunk
->skb
)->version
));
5503 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
5504 /* Do real work as sideffect. */
5505 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
5510 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
5512 /* The TSN is too high--silently discard the chunk and
5513 * count on it getting retransmitted later.
5515 return SCTP_IERROR_HIGH_TSN
;
5516 } else if (tmp
> 0) {
5517 /* This is a duplicate. Record it. */
5518 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
5519 return SCTP_IERROR_DUP_TSN
;
5522 /* This is a new TSN. */
5524 /* Discard if there is no room in the receive window.
5525 * Actually, allow a little bit of overflow (up to a MTU).
5527 datalen
= ntohs(chunk
->chunk_hdr
->length
);
5528 datalen
-= sizeof(sctp_data_chunk_t
);
5530 deliver
= SCTP_CMD_CHUNK_ULP
;
5532 /* Think about partial delivery. */
5533 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
5535 /* Even if we don't accept this chunk there is
5538 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
5541 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5542 * seems a bit troublesome in that frag_point varies based on
5543 * PMTU. In cases, such as loopback, this might be a rather
5545 * NOTE: If we have a full receive buffer here, we only renege if
5546 * our receiver can still make progress without the tsn being
5547 * received. We do this because in the event that the associations
5548 * receive queue is empty we are filling a leading gap, and since
5549 * reneging moves the gap to the end of the tsn stream, we are likely
5550 * to stall again very shortly. Avoiding the renege when we fill a
5551 * leading gap is a good heuristic for avoiding such steady state
5554 if (!asoc
->rwnd
|| asoc
->rwnd_over
||
5555 (datalen
> asoc
->rwnd
+ asoc
->frag_point
) ||
5556 (rcvbuf_over
&& (!skb_queue_len(&sk
->sk_receive_queue
)))) {
5558 /* If this is the next TSN, consider reneging to make
5559 * room. Note: Playing nice with a confused sender. A
5560 * malicious sender can still eat up all our buffer
5561 * space and in the future we may want to detect and
5562 * do more drastic reneging.
5564 if (sctp_tsnmap_has_gap(map
) &&
5565 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5566 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
5567 deliver
= SCTP_CMD_RENEGE
;
5569 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5570 "rwnd: %d\n", tsn
, datalen
,
5572 return SCTP_IERROR_IGNORE_TSN
;
5577 * Section 3.3.10.9 No User Data (9)
5581 * No User Data: This error cause is returned to the originator of a
5582 * DATA chunk if a received DATA chunk has no user data.
5584 if (unlikely(0 == datalen
)) {
5585 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
5587 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5590 /* We are going to ABORT, so we might as well stop
5591 * processing the rest of the chunks in the packet.
5593 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
5594 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5595 SCTP_ERROR(ECONNABORTED
));
5596 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5597 SCTP_PERR(SCTP_ERROR_NO_DATA
));
5598 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5599 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5600 return SCTP_IERROR_NO_DATA
;
5603 /* If definately accepting the DATA chunk, record its TSN, otherwise
5604 * wait for renege processing.
5606 if (SCTP_CMD_CHUNK_ULP
== deliver
)
5607 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
5609 chunk
->data_accepted
= 1;
5611 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5612 * if we renege and the chunk arrives again.
5614 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
5615 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS
);
5617 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS
);
5619 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5621 * If an endpoint receive a DATA chunk with an invalid stream
5622 * identifier, it shall acknowledge the reception of the DATA chunk
5623 * following the normal procedure, immediately send an ERROR chunk
5624 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5625 * and discard the DATA chunk.
5627 if (ntohs(data_hdr
->stream
) >= asoc
->c
.sinit_max_instreams
) {
5628 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
5630 sizeof(data_hdr
->stream
));
5632 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5634 return SCTP_IERROR_BAD_STREAM
;
5637 /* Send the data up to the user. Note: Schedule the
5638 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5639 * chunk needs the updated rwnd.
5641 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
5643 return SCTP_IERROR_NO_ERROR
;