1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
69 const struct sctp_association
*asoc
,
70 struct sctp_chunk
*chunk
,
73 static int sctp_eat_data(const struct sctp_association
*asoc
,
74 struct sctp_chunk
*chunk
,
75 sctp_cmd_seq_t
*commands
);
76 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
77 const struct sctp_chunk
*chunk
);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
79 const struct sctp_association
*asoc
,
80 const struct sctp_chunk
*chunk
,
81 sctp_cmd_seq_t
*commands
,
82 struct sctp_chunk
*err_chunk
);
83 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
84 const struct sctp_association
*asoc
,
85 const sctp_subtype_t type
,
87 sctp_cmd_seq_t
*commands
);
88 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
89 const struct sctp_association
*asoc
,
90 const sctp_subtype_t type
,
92 sctp_cmd_seq_t
*commands
);
93 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
95 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
96 __be16 error
, int sk_err
,
97 const struct sctp_association
*asoc
,
98 struct sctp_transport
*transport
);
100 static sctp_disposition_t
sctp_sf_abort_violation(
101 const struct sctp_association
*asoc
,
103 sctp_cmd_seq_t
*commands
,
105 const size_t paylen
);
107 static sctp_disposition_t
sctp_sf_violation_chunklen(
108 const struct sctp_endpoint
*ep
,
109 const struct sctp_association
*asoc
,
110 const sctp_subtype_t type
,
112 sctp_cmd_seq_t
*commands
);
114 static sctp_disposition_t
sctp_sf_violation_ctsn(
115 const struct sctp_endpoint
*ep
,
116 const struct sctp_association
*asoc
,
117 const sctp_subtype_t type
,
119 sctp_cmd_seq_t
*commands
);
121 /* Small helper function that checks if the chunk length
122 * is of the appropriate length. The 'required_length' argument
123 * is set to be the size of a specific chunk we are testing.
124 * Return Values: 1 = Valid length
129 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
130 __u16 required_length
)
132 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
134 if (unlikely(chunk_length
< required_length
))
140 /**********************************************************
141 * These are the state functions for handling chunk events.
142 **********************************************************/
145 * Process the final SHUTDOWN COMPLETE.
147 * Section: 4 (C) (diagram), 9.2
148 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
149 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
150 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
151 * should stop the T2-shutdown timer and remove all knowledge of the
152 * association (and thus the association enters the CLOSED state).
154 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
155 * C) Rules for packet carrying SHUTDOWN COMPLETE:
157 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
158 * if the Verification Tag field of the packet matches its own tag and
159 * the T bit is not set
161 * it is set to its peer's tag and the T bit is set in the Chunk
163 * Otherwise, the receiver MUST silently discard the packet
164 * and take no further action. An endpoint MUST ignore the
165 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
168 * (endpoint, asoc, chunk)
171 * (asoc, reply_msg, msg_up, timers, counters)
173 * The return value is the disposition of the chunk.
175 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
176 const struct sctp_association
*asoc
,
177 const sctp_subtype_t type
,
179 sctp_cmd_seq_t
*commands
)
181 struct sctp_chunk
*chunk
= arg
;
182 struct sctp_ulpevent
*ev
;
184 /* RFC 2960 6.10 Bundling
186 * An endpoint MUST NOT bundle INIT, INIT ACK or
187 * SHUTDOWN COMPLETE with any other chunks.
189 if (!chunk
->singleton
)
190 return SCTP_DISPOSITION_VIOLATION
;
192 if (!sctp_vtag_verify_either(chunk
, asoc
))
193 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
195 /* RFC 2960 10.2 SCTP-to-ULP
197 * H) SHUTDOWN COMPLETE notification
199 * When SCTP completes the shutdown procedures (section 9.2) this
200 * notification is passed to the upper layer.
202 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
203 0, 0, 0, NULL
, GFP_ATOMIC
);
205 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
208 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
209 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
210 * not the chunk should be discarded. If the endpoint is in
211 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
212 * T2-shutdown timer and remove all knowledge of the
213 * association (and thus the association enters the CLOSED
216 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
217 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
219 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
220 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
222 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
223 SCTP_STATE(SCTP_STATE_CLOSED
));
225 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
226 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
228 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
230 return SCTP_DISPOSITION_DELETE_TCB
;
234 * Respond to a normal INIT chunk.
235 * We are the side that is being asked for an association.
237 * Section: 5.1 Normal Establishment of an Association, B
238 * B) "Z" shall respond immediately with an INIT ACK chunk. The
239 * destination IP address of the INIT ACK MUST be set to the source
240 * IP address of the INIT to which this INIT ACK is responding. In
241 * the response, besides filling in other parameters, "Z" must set the
242 * Verification Tag field to Tag_A, and also provide its own
243 * Verification Tag (Tag_Z) in the Initiate Tag field.
245 * Verification Tag: Must be 0.
248 * (endpoint, asoc, chunk)
251 * (asoc, reply_msg, msg_up, timers, counters)
253 * The return value is the disposition of the chunk.
255 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
256 const struct sctp_association
*asoc
,
257 const sctp_subtype_t type
,
259 sctp_cmd_seq_t
*commands
)
261 struct sctp_chunk
*chunk
= arg
;
262 struct sctp_chunk
*repl
;
263 struct sctp_association
*new_asoc
;
264 struct sctp_chunk
*err_chunk
;
265 struct sctp_packet
*packet
;
266 sctp_unrecognized_param_t
*unk_param
;
270 * An endpoint MUST NOT bundle INIT, INIT ACK or
271 * SHUTDOWN COMPLETE with any other chunks.
274 * Furthermore, we require that the receiver of an INIT chunk MUST
275 * enforce these rules by silently discarding an arriving packet
276 * with an INIT chunk that is bundled with other chunks.
278 if (!chunk
->singleton
)
279 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
281 /* If the packet is an OOTB packet which is temporarily on the
282 * control endpoint, respond with an ABORT.
284 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
285 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
287 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
290 if (chunk
->sctp_hdr
->vtag
!= 0)
291 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
293 /* Make sure that the INIT chunk has a valid length.
294 * Normally, this would cause an ABORT with a Protocol Violation
295 * error, but since we don't have an association, we'll
296 * just discard the packet.
298 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
299 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
301 /* Verify the INIT chunk before processing it. */
303 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
304 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
306 /* This chunk contains fatal error. It is to be discarded.
307 * Send an ABORT, with causes if there is any.
310 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
311 (__u8
*)(err_chunk
->chunk_hdr
) +
312 sizeof(sctp_chunkhdr_t
),
313 ntohs(err_chunk
->chunk_hdr
->length
) -
314 sizeof(sctp_chunkhdr_t
));
316 sctp_chunk_free(err_chunk
);
319 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
320 SCTP_PACKET(packet
));
321 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
322 return SCTP_DISPOSITION_CONSUME
;
324 return SCTP_DISPOSITION_NOMEM
;
327 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
332 /* Grab the INIT header. */
333 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
335 /* Tag the variable length parameters. */
336 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
338 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
342 /* The call, sctp_process_init(), can fail on memory allocation. */
343 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
345 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
349 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
351 /* If there are errors need to be reported for unknown parameters,
352 * make sure to reserve enough room in the INIT ACK for them.
356 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
357 sizeof(sctp_chunkhdr_t
);
359 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
362 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
366 /* If there are errors need to be reported for unknown parameters,
367 * include them in the outgoing INIT ACK as "Unrecognized parameter"
371 /* Get the "Unrecognized parameter" parameter(s) out of the
372 * ERROR chunk generated by sctp_verify_init(). Since the
373 * error cause code for "unknown parameter" and the
374 * "Unrecognized parameter" type is the same, we can
375 * construct the parameters in INIT ACK by copying the
378 unk_param
= (sctp_unrecognized_param_t
*)
379 ((__u8
*)(err_chunk
->chunk_hdr
) +
380 sizeof(sctp_chunkhdr_t
));
381 /* Replace the cause code with the "Unrecognized parameter"
384 sctp_addto_chunk(repl
, len
, unk_param
);
385 sctp_chunk_free(err_chunk
);
388 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
390 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
393 * Note: After sending out INIT ACK with the State Cookie parameter,
394 * "Z" MUST NOT allocate any resources, nor keep any states for the
395 * new association. Otherwise, "Z" will be vulnerable to resource
398 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
400 return SCTP_DISPOSITION_DELETE_TCB
;
403 sctp_association_free(new_asoc
);
406 sctp_chunk_free(err_chunk
);
407 return SCTP_DISPOSITION_NOMEM
;
411 * Respond to a normal INIT ACK chunk.
412 * We are the side that is initiating the association.
414 * Section: 5.1 Normal Establishment of an Association, C
415 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
416 * timer and leave COOKIE-WAIT state. "A" shall then send the State
417 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
418 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
420 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
421 * DATA chunks, but it MUST be the first chunk in the packet and
422 * until the COOKIE ACK is returned the sender MUST NOT send any
423 * other packets to the peer.
425 * Verification Tag: 3.3.3
426 * If the value of the Initiate Tag in a received INIT ACK chunk is
427 * found to be 0, the receiver MUST treat it as an error and close the
428 * association by transmitting an ABORT.
431 * (endpoint, asoc, chunk)
434 * (asoc, reply_msg, msg_up, timers, counters)
436 * The return value is the disposition of the chunk.
438 sctp_disposition_t
sctp_sf_do_5_1C_ack(const struct sctp_endpoint
*ep
,
439 const struct sctp_association
*asoc
,
440 const sctp_subtype_t type
,
442 sctp_cmd_seq_t
*commands
)
444 struct sctp_chunk
*chunk
= arg
;
445 sctp_init_chunk_t
*initchunk
;
446 struct sctp_chunk
*err_chunk
;
447 struct sctp_packet
*packet
;
450 if (!sctp_vtag_verify(chunk
, asoc
))
451 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
453 /* Make sure that the INIT-ACK chunk has a valid length */
454 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
455 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
458 * An endpoint MUST NOT bundle INIT, INIT ACK or
459 * SHUTDOWN COMPLETE with any other chunks.
461 if (!chunk
->singleton
)
462 return SCTP_DISPOSITION_VIOLATION
;
464 /* Grab the INIT header. */
465 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
467 /* Verify the INIT chunk before processing it. */
469 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
470 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
473 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
475 /* This chunk contains fatal error. It is to be discarded.
476 * Send an ABORT, with causes if there is any.
479 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
480 (__u8
*)(err_chunk
->chunk_hdr
) +
481 sizeof(sctp_chunkhdr_t
),
482 ntohs(err_chunk
->chunk_hdr
->length
) -
483 sizeof(sctp_chunkhdr_t
));
485 sctp_chunk_free(err_chunk
);
488 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
489 SCTP_PACKET(packet
));
490 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
491 error
= SCTP_ERROR_INV_PARAM
;
493 error
= SCTP_ERROR_NO_RESOURCE
;
496 sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
497 error
= SCTP_ERROR_INV_PARAM
;
499 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
,
500 asoc
, chunk
->transport
);
503 /* Tag the variable length parameters. Note that we never
504 * convert the parameters in an INIT chunk.
506 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
508 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
510 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
511 SCTP_PEER_INIT(initchunk
));
513 /* Reset init error count upon receipt of INIT-ACK. */
514 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
516 /* 5.1 C) "A" shall stop the T1-init timer and leave
517 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
518 * timer, and enter the COOKIE-ECHOED state.
520 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
521 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
522 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
523 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
524 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
525 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
527 /* 5.1 C) "A" shall then send the State Cookie received in the
528 * INIT ACK chunk in a COOKIE ECHO chunk, ...
530 /* If there is any errors to report, send the ERROR chunk generated
531 * for unknown parameters as well.
533 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
534 SCTP_CHUNK(err_chunk
));
536 return SCTP_DISPOSITION_CONSUME
;
540 * Respond to a normal COOKIE ECHO chunk.
541 * We are the side that is being asked for an association.
543 * Section: 5.1 Normal Establishment of an Association, D
544 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
545 * with a COOKIE ACK chunk after building a TCB and moving to
546 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
547 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
548 * chunk MUST be the first chunk in the packet.
550 * IMPLEMENTATION NOTE: An implementation may choose to send the
551 * Communication Up notification to the SCTP user upon reception
552 * of a valid COOKIE ECHO chunk.
554 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
555 * D) Rules for packet carrying a COOKIE ECHO
557 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
558 * Initial Tag received in the INIT ACK.
560 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
563 * (endpoint, asoc, chunk)
566 * (asoc, reply_msg, msg_up, timers, counters)
568 * The return value is the disposition of the chunk.
570 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
571 const struct sctp_association
*asoc
,
572 const sctp_subtype_t type
, void *arg
,
573 sctp_cmd_seq_t
*commands
)
575 struct sctp_chunk
*chunk
= arg
;
576 struct sctp_association
*new_asoc
;
577 sctp_init_chunk_t
*peer_init
;
578 struct sctp_chunk
*repl
;
579 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
581 struct sctp_chunk
*err_chk_p
;
584 /* If the packet is an OOTB packet which is temporarily on the
585 * control endpoint, respond with an ABORT.
587 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
588 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
590 /* Make sure that the COOKIE_ECHO chunk has a valid length.
591 * In this case, we check that we have enough for at least a
592 * chunk header. More detailed verification is done
593 * in sctp_unpack_cookie().
595 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
596 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
598 /* If the endpoint is not listening or if the number of associations
599 * on the TCP-style socket exceed the max backlog, respond with an
603 if (!sctp_sstate(sk
, LISTENING
) ||
604 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
605 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
607 /* "Decode" the chunk. We have no optional parameters so we
610 chunk
->subh
.cookie_hdr
=
611 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
612 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
613 sizeof(sctp_chunkhdr_t
)))
616 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
617 * "Z" will reply with a COOKIE ACK chunk after building a TCB
618 * and moving to the ESTABLISHED state.
620 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
624 * If the re-build failed, what is the proper error path
627 * [We should abort the association. --piggy]
630 /* FIXME: Several errors are possible. A bad cookie should
631 * be silently discarded, but think about logging it too.
634 case -SCTP_IERROR_NOMEM
:
637 case -SCTP_IERROR_STALE_COOKIE
:
638 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
640 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
642 case -SCTP_IERROR_BAD_SIG
:
644 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
649 /* Delay state machine commands until later.
651 * Re-build the bind address for the association is done in
652 * the sctp_unpack_cookie() already.
654 /* This is a brand-new association, so these are not yet side
655 * effects--it is safe to run them here.
657 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
659 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
660 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
661 peer_init
, GFP_ATOMIC
))
664 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
668 /* RFC 2960 5.1 Normal Establishment of an Association
670 * D) IMPLEMENTATION NOTE: An implementation may choose to
671 * send the Communication Up notification to the SCTP user
672 * upon reception of a valid COOKIE ECHO chunk.
674 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
675 new_asoc
->c
.sinit_num_ostreams
,
676 new_asoc
->c
.sinit_max_instreams
,
681 /* Sockets API Draft Section 5.3.1.6
682 * When a peer sends a Adaptation Layer Indication parameter , SCTP
683 * delivers this notification to inform the application that of the
684 * peers requested adaptation layer.
686 if (new_asoc
->peer
.adaptation_ind
) {
687 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
693 /* Add all the state machine commands now since we've created
694 * everything. This way we don't introduce memory corruptions
695 * during side-effect processing and correclty count established
698 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
699 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
700 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
701 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
702 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS
);
703 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
705 if (new_asoc
->autoclose
)
706 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
707 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
709 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
711 /* This will send the COOKIE ACK */
712 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
714 /* Queue the ASSOC_CHANGE event */
715 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
717 /* Send up the Adaptation Layer Indication event */
719 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
720 SCTP_ULPEVENT(ai_ev
));
722 return SCTP_DISPOSITION_CONSUME
;
725 sctp_ulpevent_free(ev
);
727 sctp_chunk_free(repl
);
729 sctp_association_free(new_asoc
);
731 return SCTP_DISPOSITION_NOMEM
;
735 * Respond to a normal COOKIE ACK chunk.
736 * We are the side that is being asked for an association.
738 * RFC 2960 5.1 Normal Establishment of an Association
740 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
741 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
742 * timer. It may also notify its ULP about the successful
743 * establishment of the association with a Communication Up
744 * notification (see Section 10).
748 * (endpoint, asoc, chunk)
751 * (asoc, reply_msg, msg_up, timers, counters)
753 * The return value is the disposition of the chunk.
755 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
756 const struct sctp_association
*asoc
,
757 const sctp_subtype_t type
, void *arg
,
758 sctp_cmd_seq_t
*commands
)
760 struct sctp_chunk
*chunk
= arg
;
761 struct sctp_ulpevent
*ev
;
763 if (!sctp_vtag_verify(chunk
, asoc
))
764 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
766 /* Verify that the chunk length for the COOKIE-ACK is OK.
767 * If we don't do this, any bundled chunks may be junked.
769 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
770 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
773 /* Reset init error count upon receipt of COOKIE-ACK,
774 * to avoid problems with the managemement of this
775 * counter in stale cookie situations when a transition back
776 * from the COOKIE-ECHOED state to the COOKIE-WAIT
777 * state is performed.
779 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
781 /* RFC 2960 5.1 Normal Establishment of an Association
783 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
784 * from the COOKIE-ECHOED state to the ESTABLISHED state,
785 * stopping the T1-cookie timer.
787 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
788 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
789 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
790 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
791 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
792 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS
);
793 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
795 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
796 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
797 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
799 /* It may also notify its ULP about the successful
800 * establishment of the association with a Communication Up
801 * notification (see Section 10).
803 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
804 0, asoc
->c
.sinit_num_ostreams
,
805 asoc
->c
.sinit_max_instreams
,
811 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
813 /* Sockets API Draft Section 5.3.1.6
814 * When a peer sends a Adaptation Layer Indication parameter , SCTP
815 * delivers this notification to inform the application that of the
816 * peers requested adaptation layer.
818 if (asoc
->peer
.adaptation_ind
) {
819 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
823 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
827 return SCTP_DISPOSITION_CONSUME
;
829 return SCTP_DISPOSITION_NOMEM
;
832 /* Generate and sendout a heartbeat packet. */
833 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
834 const struct sctp_association
*asoc
,
835 const sctp_subtype_t type
,
837 sctp_cmd_seq_t
*commands
)
839 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
840 struct sctp_chunk
*reply
;
841 sctp_sender_hb_info_t hbinfo
;
844 hbinfo
.param_hdr
.type
= SCTP_PARAM_HEARTBEAT_INFO
;
845 hbinfo
.param_hdr
.length
= htons(sizeof(sctp_sender_hb_info_t
));
846 hbinfo
.daddr
= transport
->ipaddr
;
847 hbinfo
.sent_at
= jiffies
;
848 hbinfo
.hb_nonce
= transport
->hb_nonce
;
850 /* Send a heartbeat to our peer. */
851 paylen
= sizeof(sctp_sender_hb_info_t
);
852 reply
= sctp_make_heartbeat(asoc
, transport
, &hbinfo
, paylen
);
854 return SCTP_DISPOSITION_NOMEM
;
856 /* Set rto_pending indicating that an RTT measurement
857 * is started with this heartbeat chunk.
859 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
860 SCTP_TRANSPORT(transport
));
862 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
863 return SCTP_DISPOSITION_CONSUME
;
866 /* Generate a HEARTBEAT packet on the given transport. */
867 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
868 const struct sctp_association
*asoc
,
869 const sctp_subtype_t type
,
871 sctp_cmd_seq_t
*commands
)
873 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
875 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
876 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
877 SCTP_ERROR(ETIMEDOUT
));
878 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
879 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
880 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
881 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
882 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
883 return SCTP_DISPOSITION_DELETE_TCB
;
887 * The Sender-specific Heartbeat Info field should normally include
888 * information about the sender's current time when this HEARTBEAT
889 * chunk is sent and the destination transport address to which this
890 * HEARTBEAT is sent (see Section 8.3).
893 if (transport
->param_flags
& SPP_HB_ENABLE
) {
894 if (SCTP_DISPOSITION_NOMEM
==
895 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
897 return SCTP_DISPOSITION_NOMEM
;
898 /* Set transport error counter and association error counter
899 * when sending heartbeat.
901 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
902 SCTP_TRANSPORT(transport
));
904 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
905 SCTP_TRANSPORT(transport
));
907 return SCTP_DISPOSITION_CONSUME
;
911 * Process an heartbeat request.
913 * Section: 8.3 Path Heartbeat
914 * The receiver of the HEARTBEAT should immediately respond with a
915 * HEARTBEAT ACK that contains the Heartbeat Information field copied
916 * from the received HEARTBEAT chunk.
918 * Verification Tag: 8.5 Verification Tag [Normal verification]
919 * When receiving an SCTP packet, the endpoint MUST ensure that the
920 * value in the Verification Tag field of the received SCTP packet
921 * matches its own Tag. If the received Verification Tag value does not
922 * match the receiver's own tag value, the receiver shall silently
923 * discard the packet and shall not process it any further except for
924 * those cases listed in Section 8.5.1 below.
927 * (endpoint, asoc, chunk)
930 * (asoc, reply_msg, msg_up, timers, counters)
932 * The return value is the disposition of the chunk.
934 sctp_disposition_t
sctp_sf_beat_8_3(const struct sctp_endpoint
*ep
,
935 const struct sctp_association
*asoc
,
936 const sctp_subtype_t type
,
938 sctp_cmd_seq_t
*commands
)
940 struct sctp_chunk
*chunk
= arg
;
941 struct sctp_chunk
*reply
;
944 if (!sctp_vtag_verify(chunk
, asoc
))
945 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
947 /* Make sure that the HEARTBEAT chunk has a valid length. */
948 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
949 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
952 /* 8.3 The receiver of the HEARTBEAT should immediately
953 * respond with a HEARTBEAT ACK that contains the Heartbeat
954 * Information field copied from the received HEARTBEAT chunk.
956 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
957 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
958 if (!pskb_pull(chunk
->skb
, paylen
))
961 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
962 chunk
->subh
.hb_hdr
, paylen
);
966 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
967 return SCTP_DISPOSITION_CONSUME
;
970 return SCTP_DISPOSITION_NOMEM
;
974 * Process the returning HEARTBEAT ACK.
976 * Section: 8.3 Path Heartbeat
977 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
978 * should clear the error counter of the destination transport
979 * address to which the HEARTBEAT was sent, and mark the destination
980 * transport address as active if it is not so marked. The endpoint may
981 * optionally report to the upper layer when an inactive destination
982 * address is marked as active due to the reception of the latest
983 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
984 * clear the association overall error count as well (as defined
987 * The receiver of the HEARTBEAT ACK should also perform an RTT
988 * measurement for that destination transport address using the time
989 * value carried in the HEARTBEAT ACK chunk.
991 * Verification Tag: 8.5 Verification Tag [Normal verification]
994 * (endpoint, asoc, chunk)
997 * (asoc, reply_msg, msg_up, timers, counters)
999 * The return value is the disposition of the chunk.
1001 sctp_disposition_t
sctp_sf_backbeat_8_3(const struct sctp_endpoint
*ep
,
1002 const struct sctp_association
*asoc
,
1003 const sctp_subtype_t type
,
1005 sctp_cmd_seq_t
*commands
)
1007 struct sctp_chunk
*chunk
= arg
;
1008 union sctp_addr from_addr
;
1009 struct sctp_transport
*link
;
1010 sctp_sender_hb_info_t
*hbinfo
;
1011 unsigned long max_interval
;
1013 if (!sctp_vtag_verify(chunk
, asoc
))
1014 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1016 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1017 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1018 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1021 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1022 /* Make sure that the length of the parameter is what we expect */
1023 if (ntohs(hbinfo
->param_hdr
.length
) !=
1024 sizeof(sctp_sender_hb_info_t
)) {
1025 return SCTP_DISPOSITION_DISCARD
;
1028 from_addr
= hbinfo
->daddr
;
1029 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1031 /* This should never happen, but lets log it if so. */
1032 if (unlikely(!link
)) {
1033 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1034 if (net_ratelimit())
1036 "%s association %p could not find address "
1040 NIP6(from_addr
.v6
.sin6_addr
));
1042 if (net_ratelimit())
1044 "%s association %p could not find address "
1048 NIPQUAD(from_addr
.v4
.sin_addr
.s_addr
));
1050 return SCTP_DISPOSITION_DISCARD
;
1053 /* Validate the 64-bit random nonce. */
1054 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1055 return SCTP_DISPOSITION_DISCARD
;
1057 max_interval
= link
->hbinterval
+ link
->rto
;
1059 /* Check if the timestamp looks valid. */
1060 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1061 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1062 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp"
1063 "received for transport: %p\n",
1064 __FUNCTION__
, link
);
1065 return SCTP_DISPOSITION_DISCARD
;
1068 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1069 * the HEARTBEAT should clear the error counter of the
1070 * destination transport address to which the HEARTBEAT was
1071 * sent and mark the destination transport address as active if
1072 * it is not so marked.
1074 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1076 return SCTP_DISPOSITION_CONSUME
;
1079 /* Helper function to send out an abort for the restart
1082 static int sctp_sf_send_restart_abort(union sctp_addr
*ssa
,
1083 struct sctp_chunk
*init
,
1084 sctp_cmd_seq_t
*commands
)
1087 struct sctp_packet
*pkt
;
1088 union sctp_addr_param
*addrparm
;
1089 struct sctp_errhdr
*errhdr
;
1090 struct sctp_endpoint
*ep
;
1091 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1092 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1094 /* Build the error on the stack. We are way to malloc crazy
1095 * throughout the code today.
1097 errhdr
= (struct sctp_errhdr
*)buffer
;
1098 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1100 /* Copy into a parm format. */
1101 len
= af
->to_addr_param(ssa
, addrparm
);
1102 len
+= sizeof(sctp_errhdr_t
);
1104 errhdr
->cause
= SCTP_ERROR_RESTART
;
1105 errhdr
->length
= htons(len
);
1107 /* Assign to the control socket. */
1108 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
1110 /* Association is NULL since this may be a restart attack and we
1111 * want to send back the attacker's vtag.
1113 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1117 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1119 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1121 /* Discard the rest of the inbound packet. */
1122 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1125 /* Even if there is no memory, treat as a failure so
1126 * the packet will get dropped.
1131 /* A restart is occurring, check to make sure no new addresses
1132 * are being added as we may be under a takeover attack.
1134 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1135 const struct sctp_association
*asoc
,
1136 struct sctp_chunk
*init
,
1137 sctp_cmd_seq_t
*commands
)
1139 struct sctp_transport
*new_addr
, *addr
;
1140 struct list_head
*pos
, *pos2
;
1143 /* Implementor's Guide - Sectin 5.2.2
1145 * Before responding the endpoint MUST check to see if the
1146 * unexpected INIT adds new addresses to the association. If new
1147 * addresses are added to the association, the endpoint MUST respond
1151 /* Search through all current addresses and make sure
1152 * we aren't adding any new ones.
1157 list_for_each(pos
, &new_asoc
->peer
.transport_addr_list
) {
1158 new_addr
= list_entry(pos
, struct sctp_transport
, transports
);
1160 list_for_each(pos2
, &asoc
->peer
.transport_addr_list
) {
1161 addr
= list_entry(pos2
, struct sctp_transport
,
1163 if (sctp_cmp_addr_exact(&new_addr
->ipaddr
,
1173 /* If a new address was added, ABORT the sender. */
1174 if (!found
&& new_addr
) {
1175 sctp_sf_send_restart_abort(&new_addr
->ipaddr
, init
, commands
);
1178 /* Return success if all addresses were found. */
1182 /* Populate the verification/tie tags based on overlapping INIT
1185 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1187 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1188 const struct sctp_association
*asoc
)
1190 switch (asoc
->state
) {
1192 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1194 case SCTP_STATE_COOKIE_WAIT
:
1195 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1196 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1197 new_asoc
->c
.peer_ttag
= 0;
1200 case SCTP_STATE_COOKIE_ECHOED
:
1201 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1202 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1203 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1206 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1207 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1210 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1211 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1215 /* Other parameters for the endpoint SHOULD be copied from the
1216 * existing parameters of the association (e.g. number of
1217 * outbound streams) into the INIT ACK and cookie.
1219 new_asoc
->rwnd
= asoc
->rwnd
;
1220 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1221 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1222 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1226 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1229 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1231 * Returns value representing action to be taken. These action values
1232 * correspond to Action/Description values in RFC 2960, Table 2.
1234 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1235 const struct sctp_association
*asoc
)
1237 /* In this case, the peer may have restarted. */
1238 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1239 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1240 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1241 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1244 /* Collision case B. */
1245 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1246 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1247 (0 == asoc
->c
.peer_vtag
))) {
1251 /* Collision case D. */
1252 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1253 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1256 /* Collision case C. */
1257 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1258 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1259 (0 == new_asoc
->c
.my_ttag
) &&
1260 (0 == new_asoc
->c
.peer_ttag
))
1263 /* No match to any of the special cases; discard this packet. */
1267 /* Common helper routine for both duplicate and simulataneous INIT
1270 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1271 const struct sctp_endpoint
*ep
,
1272 const struct sctp_association
*asoc
,
1273 const sctp_subtype_t type
,
1274 void *arg
, sctp_cmd_seq_t
*commands
)
1276 sctp_disposition_t retval
;
1277 struct sctp_chunk
*chunk
= arg
;
1278 struct sctp_chunk
*repl
;
1279 struct sctp_association
*new_asoc
;
1280 struct sctp_chunk
*err_chunk
;
1281 struct sctp_packet
*packet
;
1282 sctp_unrecognized_param_t
*unk_param
;
1286 * An endpoint MUST NOT bundle INIT, INIT ACK or
1287 * SHUTDOWN COMPLETE with any other chunks.
1290 * Furthermore, we require that the receiver of an INIT chunk MUST
1291 * enforce these rules by silently discarding an arriving packet
1292 * with an INIT chunk that is bundled with other chunks.
1294 if (!chunk
->singleton
)
1295 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1297 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1300 if (chunk
->sctp_hdr
->vtag
!= 0)
1301 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1303 /* Make sure that the INIT chunk has a valid length.
1304 * In this case, we generate a protocol violation since we have
1305 * an association established.
1307 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1308 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1310 /* Grab the INIT header. */
1311 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1313 /* Tag the variable length parameters. */
1314 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1316 /* Verify the INIT chunk before processing it. */
1318 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1319 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1321 /* This chunk contains fatal error. It is to be discarded.
1322 * Send an ABORT, with causes if there is any.
1325 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1326 (__u8
*)(err_chunk
->chunk_hdr
) +
1327 sizeof(sctp_chunkhdr_t
),
1328 ntohs(err_chunk
->chunk_hdr
->length
) -
1329 sizeof(sctp_chunkhdr_t
));
1332 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1333 SCTP_PACKET(packet
));
1334 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1335 retval
= SCTP_DISPOSITION_CONSUME
;
1337 retval
= SCTP_DISPOSITION_NOMEM
;
1341 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1347 * Other parameters for the endpoint SHOULD be copied from the
1348 * existing parameters of the association (e.g. number of
1349 * outbound streams) into the INIT ACK and cookie.
1350 * FIXME: We are copying parameters from the endpoint not the
1353 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1357 /* In the outbound INIT ACK the endpoint MUST copy its current
1358 * Verification Tag and Peers Verification tag into a reserved
1359 * place (local tie-tag and per tie-tag) within the state cookie.
1361 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1363 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1367 /* Make sure no new addresses are being added during the
1368 * restart. Do not do this check for COOKIE-WAIT state,
1369 * since there are no peer addresses to check against.
1370 * Upon return an ABORT will have been sent if needed.
1372 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1373 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1375 retval
= SCTP_DISPOSITION_CONSUME
;
1380 sctp_tietags_populate(new_asoc
, asoc
);
1382 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1384 /* If there are errors need to be reported for unknown parameters,
1385 * make sure to reserve enough room in the INIT ACK for them.
1389 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1390 sizeof(sctp_chunkhdr_t
);
1393 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
1396 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1400 /* If there are errors need to be reported for unknown parameters,
1401 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1405 /* Get the "Unrecognized parameter" parameter(s) out of the
1406 * ERROR chunk generated by sctp_verify_init(). Since the
1407 * error cause code for "unknown parameter" and the
1408 * "Unrecognized parameter" type is the same, we can
1409 * construct the parameters in INIT ACK by copying the
1410 * ERROR causes over.
1412 unk_param
= (sctp_unrecognized_param_t
*)
1413 ((__u8
*)(err_chunk
->chunk_hdr
) +
1414 sizeof(sctp_chunkhdr_t
));
1415 /* Replace the cause code with the "Unrecognized parameter"
1418 sctp_addto_chunk(repl
, len
, unk_param
);
1421 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1422 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1425 * Note: After sending out INIT ACK with the State Cookie parameter,
1426 * "Z" MUST NOT allocate any resources for this new association.
1427 * Otherwise, "Z" will be vulnerable to resource attacks.
1429 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1430 retval
= SCTP_DISPOSITION_CONSUME
;
1435 retval
= SCTP_DISPOSITION_NOMEM
;
1438 sctp_association_free(new_asoc
);
1441 sctp_chunk_free(err_chunk
);
1446 * Handle simultanous INIT.
1447 * This means we started an INIT and then we got an INIT request from
1450 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1451 * This usually indicates an initialization collision, i.e., each
1452 * endpoint is attempting, at about the same time, to establish an
1453 * association with the other endpoint.
1455 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1456 * endpoint MUST respond with an INIT ACK using the same parameters it
1457 * sent in its original INIT chunk (including its Verification Tag,
1458 * unchanged). These original parameters are combined with those from the
1459 * newly received INIT chunk. The endpoint shall also generate a State
1460 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1461 * INIT to calculate the State Cookie.
1463 * After that, the endpoint MUST NOT change its state, the T1-init
1464 * timer shall be left running and the corresponding TCB MUST NOT be
1465 * destroyed. The normal procedures for handling State Cookies when
1466 * a TCB exists will resolve the duplicate INITs to a single association.
1468 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1469 * its Tie-Tags with the Tag information of itself and its peer (see
1470 * section 5.2.2 for a description of the Tie-Tags).
1472 * Verification Tag: Not explicit, but an INIT can not have a valid
1473 * verification tag, so we skip the check.
1476 * (endpoint, asoc, chunk)
1479 * (asoc, reply_msg, msg_up, timers, counters)
1481 * The return value is the disposition of the chunk.
1483 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1484 const struct sctp_association
*asoc
,
1485 const sctp_subtype_t type
,
1487 sctp_cmd_seq_t
*commands
)
1489 /* Call helper to do the real work for both simulataneous and
1490 * duplicate INIT chunk handling.
1492 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1496 * Handle duplicated INIT messages. These are usually delayed
1499 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1500 * COOKIE-ECHOED and COOKIE-WAIT
1502 * Unless otherwise stated, upon reception of an unexpected INIT for
1503 * this association, the endpoint shall generate an INIT ACK with a
1504 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1505 * current Verification Tag and peer's Verification Tag into a reserved
1506 * place within the state cookie. We shall refer to these locations as
1507 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1508 * containing this INIT ACK MUST carry a Verification Tag value equal to
1509 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1510 * MUST contain a new Initiation Tag (randomly generated see Section
1511 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1512 * existing parameters of the association (e.g. number of outbound
1513 * streams) into the INIT ACK and cookie.
1515 * After sending out the INIT ACK, the endpoint shall take no further
1516 * actions, i.e., the existing association, including its current state,
1517 * and the corresponding TCB MUST NOT be changed.
1519 * Note: Only when a TCB exists and the association is not in a COOKIE-
1520 * WAIT state are the Tie-Tags populated. For a normal association INIT
1521 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1522 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1523 * State Cookie are populated as specified in section 5.2.1.
1525 * Verification Tag: Not specified, but an INIT has no way of knowing
1526 * what the verification tag could be, so we ignore it.
1529 * (endpoint, asoc, chunk)
1532 * (asoc, reply_msg, msg_up, timers, counters)
1534 * The return value is the disposition of the chunk.
1536 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1537 const struct sctp_association
*asoc
,
1538 const sctp_subtype_t type
,
1540 sctp_cmd_seq_t
*commands
)
1542 /* Call helper to do the real work for both simulataneous and
1543 * duplicate INIT chunk handling.
1545 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1550 * Unexpected INIT-ACK handler.
1553 * If an INIT ACK received by an endpoint in any state other than the
1554 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1555 * An unexpected INIT ACK usually indicates the processing of an old or
1556 * duplicated INIT chunk.
1558 sctp_disposition_t
sctp_sf_do_5_2_3_initack(const struct sctp_endpoint
*ep
,
1559 const struct sctp_association
*asoc
,
1560 const sctp_subtype_t type
,
1561 void *arg
, sctp_cmd_seq_t
*commands
)
1563 /* Per the above section, we'll discard the chunk if we have an
1564 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1566 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
1567 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
1569 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
1572 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1575 * A) In this case, the peer may have restarted.
1577 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1578 const struct sctp_association
*asoc
,
1579 struct sctp_chunk
*chunk
,
1580 sctp_cmd_seq_t
*commands
,
1581 struct sctp_association
*new_asoc
)
1583 sctp_init_chunk_t
*peer_init
;
1584 struct sctp_ulpevent
*ev
;
1585 struct sctp_chunk
*repl
;
1586 struct sctp_chunk
*err
;
1587 sctp_disposition_t disposition
;
1589 /* new_asoc is a brand-new association, so these are not yet
1590 * side effects--it is safe to run them here.
1592 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1594 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1595 sctp_source(chunk
), peer_init
,
1599 /* Make sure no new addresses are being added during the
1600 * restart. Though this is a pretty complicated attack
1601 * since you'd have to get inside the cookie.
1603 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1604 return SCTP_DISPOSITION_CONSUME
;
1607 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1608 * the peer has restarted (Action A), it MUST NOT setup a new
1609 * association but instead resend the SHUTDOWN ACK and send an ERROR
1610 * chunk with a "Cookie Received while Shutting Down" error cause to
1613 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1614 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1615 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1617 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1620 err
= sctp_make_op_error(asoc
, chunk
,
1621 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1624 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1627 return SCTP_DISPOSITION_CONSUME
;
1630 /* For now, fail any unsent/unacked data. Consider the optional
1631 * choice of resending of this data.
1633 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1635 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1639 /* Report association restart to upper layer. */
1640 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1641 new_asoc
->c
.sinit_num_ostreams
,
1642 new_asoc
->c
.sinit_max_instreams
,
1647 /* Update the content of current association. */
1648 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1649 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1650 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1651 return SCTP_DISPOSITION_CONSUME
;
1654 sctp_chunk_free(repl
);
1656 return SCTP_DISPOSITION_NOMEM
;
1659 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1662 * B) In this case, both sides may be attempting to start an association
1663 * at about the same time but the peer endpoint started its INIT
1664 * after responding to the local endpoint's INIT
1666 /* This case represents an initialization collision. */
1667 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1668 const struct sctp_association
*asoc
,
1669 struct sctp_chunk
*chunk
,
1670 sctp_cmd_seq_t
*commands
,
1671 struct sctp_association
*new_asoc
)
1673 sctp_init_chunk_t
*peer_init
;
1674 struct sctp_chunk
*repl
;
1676 /* new_asoc is a brand-new association, so these are not yet
1677 * side effects--it is safe to run them here.
1679 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1680 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1681 sctp_source(chunk
), peer_init
,
1685 /* Update the content of current association. */
1686 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1687 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1688 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1689 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1690 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1692 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1696 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1697 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1699 /* RFC 2960 5.1 Normal Establishment of an Association
1701 * D) IMPLEMENTATION NOTE: An implementation may choose to
1702 * send the Communication Up notification to the SCTP user
1703 * upon reception of a valid COOKIE ECHO chunk.
1705 * Sadly, this needs to be implemented as a side-effect, because
1706 * we are not guaranteed to have set the association id of the real
1707 * association and so these notifications need to be delayed until
1708 * the association id is allocated.
1711 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1713 /* Sockets API Draft Section 5.3.1.6
1714 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1715 * delivers this notification to inform the application that of the
1716 * peers requested adaptation layer.
1718 * This also needs to be done as a side effect for the same reason as
1721 if (asoc
->peer
.adaptation_ind
)
1722 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1724 return SCTP_DISPOSITION_CONSUME
;
1727 return SCTP_DISPOSITION_NOMEM
;
1730 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1733 * C) In this case, the local endpoint's cookie has arrived late.
1734 * Before it arrived, the local endpoint sent an INIT and received an
1735 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1736 * but a new tag of its own.
1738 /* This case represents an initialization collision. */
1739 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1740 const struct sctp_association
*asoc
,
1741 struct sctp_chunk
*chunk
,
1742 sctp_cmd_seq_t
*commands
,
1743 struct sctp_association
*new_asoc
)
1745 /* The cookie should be silently discarded.
1746 * The endpoint SHOULD NOT change states and should leave
1747 * any timers running.
1749 return SCTP_DISPOSITION_DISCARD
;
1752 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1756 * D) When both local and remote tags match the endpoint should always
1757 * enter the ESTABLISHED state, if it has not already done so.
1759 /* This case represents an initialization collision. */
1760 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1761 const struct sctp_association
*asoc
,
1762 struct sctp_chunk
*chunk
,
1763 sctp_cmd_seq_t
*commands
,
1764 struct sctp_association
*new_asoc
)
1766 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1767 struct sctp_chunk
*repl
;
1769 /* Clarification from Implementor's Guide:
1770 * D) When both local and remote tags match the endpoint should
1771 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1772 * It should stop any cookie timer that may be running and send
1776 /* Don't accidentally move back into established state. */
1777 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1778 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1779 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1780 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1781 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1782 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1783 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1786 /* RFC 2960 5.1 Normal Establishment of an Association
1788 * D) IMPLEMENTATION NOTE: An implementation may choose
1789 * to send the Communication Up notification to the
1790 * SCTP user upon reception of a valid COOKIE
1793 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1795 asoc
->c
.sinit_num_ostreams
,
1796 asoc
->c
.sinit_max_instreams
,
1801 /* Sockets API Draft Section 5.3.1.6
1802 * When a peer sends a Adaptation Layer Indication parameter,
1803 * SCTP delivers this notification to inform the application
1804 * that of the peers requested adaptation layer.
1806 if (asoc
->peer
.adaptation_ind
) {
1807 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1814 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1816 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1821 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1824 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1825 SCTP_ULPEVENT(ai_ev
));
1827 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1828 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1830 return SCTP_DISPOSITION_CONSUME
;
1834 sctp_ulpevent_free(ai_ev
);
1836 sctp_ulpevent_free(ev
);
1837 return SCTP_DISPOSITION_NOMEM
;
1841 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1842 * chunk was retransmitted and then delayed in the network.
1844 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1846 * Verification Tag: None. Do cookie validation.
1849 * (endpoint, asoc, chunk)
1852 * (asoc, reply_msg, msg_up, timers, counters)
1854 * The return value is the disposition of the chunk.
1856 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1857 const struct sctp_association
*asoc
,
1858 const sctp_subtype_t type
,
1860 sctp_cmd_seq_t
*commands
)
1862 sctp_disposition_t retval
;
1863 struct sctp_chunk
*chunk
= arg
;
1864 struct sctp_association
*new_asoc
;
1867 struct sctp_chunk
*err_chk_p
;
1869 /* Make sure that the chunk has a valid length from the protocol
1870 * perspective. In this case check to make sure we have at least
1871 * enough for the chunk header. Cookie length verification is
1874 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1875 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1878 /* "Decode" the chunk. We have no optional parameters so we
1879 * are in good shape.
1881 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1882 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1883 sizeof(sctp_chunkhdr_t
)))
1886 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1887 * of a duplicate COOKIE ECHO match the Verification Tags of the
1888 * current association, consider the State Cookie valid even if
1889 * the lifespan is exceeded.
1891 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
1895 * If the re-build failed, what is the proper error path
1898 * [We should abort the association. --piggy]
1901 /* FIXME: Several errors are possible. A bad cookie should
1902 * be silently discarded, but think about logging it too.
1905 case -SCTP_IERROR_NOMEM
:
1908 case -SCTP_IERROR_STALE_COOKIE
:
1909 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
1911 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1912 case -SCTP_IERROR_BAD_SIG
:
1914 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1918 /* Compare the tie_tag in cookie with the verification tag of
1919 * current association.
1921 action
= sctp_tietags_compare(new_asoc
, asoc
);
1924 case 'A': /* Association restart. */
1925 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
1929 case 'B': /* Collision case B. */
1930 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
1934 case 'C': /* Collision case C. */
1935 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
1939 case 'D': /* Collision case D. */
1940 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
1944 default: /* Discard packet for all others. */
1945 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1949 /* Delete the tempory new association. */
1950 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1951 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1956 return SCTP_DISPOSITION_NOMEM
;
1960 * Process an ABORT. (SHUTDOWN-PENDING state)
1962 * See sctp_sf_do_9_1_abort().
1964 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
1965 const struct sctp_endpoint
*ep
,
1966 const struct sctp_association
*asoc
,
1967 const sctp_subtype_t type
,
1969 sctp_cmd_seq_t
*commands
)
1971 struct sctp_chunk
*chunk
= arg
;
1973 if (!sctp_vtag_verify_either(chunk
, asoc
))
1974 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1976 /* Make sure that the ABORT chunk has a valid length.
1977 * Since this is an ABORT chunk, we have to discard it
1978 * because of the following text:
1979 * RFC 2960, Section 3.3.7
1980 * If an endpoint receives an ABORT with a format error or for an
1981 * association that doesn't exist, it MUST silently discard it.
1982 * Becasue the length is "invalid", we can't really discard just
1983 * as we do not know its true length. So, to be safe, discard the
1986 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
1987 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1989 /* Stop the T5-shutdown guard timer. */
1990 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1991 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
1993 return sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
1997 * Process an ABORT. (SHUTDOWN-SENT state)
1999 * See sctp_sf_do_9_1_abort().
2001 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
2002 const struct sctp_association
*asoc
,
2003 const sctp_subtype_t type
,
2005 sctp_cmd_seq_t
*commands
)
2007 struct sctp_chunk
*chunk
= arg
;
2009 if (!sctp_vtag_verify_either(chunk
, asoc
))
2010 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2012 /* Make sure that the ABORT chunk has a valid length.
2013 * Since this is an ABORT chunk, we have to discard it
2014 * because of the following text:
2015 * RFC 2960, Section 3.3.7
2016 * If an endpoint receives an ABORT with a format error or for an
2017 * association that doesn't exist, it MUST silently discard it.
2018 * Becasue the length is "invalid", we can't really discard just
2019 * as we do not know its true length. So, to be safe, discard the
2022 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2023 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2025 /* Stop the T2-shutdown timer. */
2026 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2027 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2029 /* Stop the T5-shutdown guard timer. */
2030 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2031 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2033 return sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2037 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2039 * See sctp_sf_do_9_1_abort().
2041 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2042 const struct sctp_endpoint
*ep
,
2043 const struct sctp_association
*asoc
,
2044 const sctp_subtype_t type
,
2046 sctp_cmd_seq_t
*commands
)
2048 /* The same T2 timer, so we should be able to use
2049 * common function with the SHUTDOWN-SENT state.
2051 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2055 * Handle an Error received in COOKIE_ECHOED state.
2057 * Only handle the error type of stale COOKIE Error, the other errors will
2061 * (endpoint, asoc, chunk)
2064 * (asoc, reply_msg, msg_up, timers, counters)
2066 * The return value is the disposition of the chunk.
2068 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2069 const struct sctp_association
*asoc
,
2070 const sctp_subtype_t type
,
2072 sctp_cmd_seq_t
*commands
)
2074 struct sctp_chunk
*chunk
= arg
;
2077 if (!sctp_vtag_verify(chunk
, asoc
))
2078 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2080 /* Make sure that the ERROR chunk has a valid length.
2081 * The parameter walking depends on this as well.
2083 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2084 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2087 /* Process the error here */
2088 /* FUTURE FIXME: When PR-SCTP related and other optional
2089 * parms are emitted, this will have to change to handle multiple
2092 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2093 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2094 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2098 /* It is possible to have malformed error causes, and that
2099 * will cause us to end the walk early. However, since
2100 * we are discarding the packet, there should be no adverse
2103 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2107 * Handle a Stale COOKIE Error
2109 * Section: 5.2.6 Handle Stale COOKIE Error
2110 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2111 * one of the following three alternatives.
2113 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2114 * Preservative parameter requesting an extension to the lifetime of
2115 * the State Cookie. When calculating the time extension, an
2116 * implementation SHOULD use the RTT information measured based on the
2117 * previous COOKIE ECHO / ERROR exchange, and should add no more
2118 * than 1 second beyond the measured RTT, due to long State Cookie
2119 * lifetimes making the endpoint more subject to a replay attack.
2121 * Verification Tag: Not explicit, but safe to ignore.
2124 * (endpoint, asoc, chunk)
2127 * (asoc, reply_msg, msg_up, timers, counters)
2129 * The return value is the disposition of the chunk.
2131 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2132 const struct sctp_association
*asoc
,
2133 const sctp_subtype_t type
,
2135 sctp_cmd_seq_t
*commands
)
2137 struct sctp_chunk
*chunk
= arg
;
2139 sctp_cookie_preserve_param_t bht
;
2141 struct sctp_chunk
*reply
;
2142 struct sctp_bind_addr
*bp
;
2143 int attempts
= asoc
->init_err_counter
+ 1;
2145 if (attempts
> asoc
->max_init_attempts
) {
2146 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2147 SCTP_ERROR(ETIMEDOUT
));
2148 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2149 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2150 return SCTP_DISPOSITION_DELETE_TCB
;
2153 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2155 /* When calculating the time extension, an implementation
2156 * SHOULD use the RTT information measured based on the
2157 * previous COOKIE ECHO / ERROR exchange, and should add no
2158 * more than 1 second beyond the measured RTT, due to long
2159 * State Cookie lifetimes making the endpoint more subject to
2161 * Measure of Staleness's unit is usec. (1/1000000 sec)
2162 * Suggested Cookie Life-span Increment's unit is msec.
2164 * In general, if you use the suggested cookie life, the value
2165 * found in the field of measure of staleness should be doubled
2166 * to give ample time to retransmit the new cookie and thus
2167 * yield a higher probability of success on the reattempt.
2169 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2170 stale
= (stale
* 2) / 1000;
2172 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2173 bht
.param_hdr
.length
= htons(sizeof(bht
));
2174 bht
.lifespan_increment
= htonl(stale
);
2176 /* Build that new INIT chunk. */
2177 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2178 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2182 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2184 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2185 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2187 /* Stop pending T3-rtx and heartbeat timers */
2188 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2189 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2191 /* Delete non-primary peer ip addresses since we are transitioning
2192 * back to the COOKIE-WAIT state
2194 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2196 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2199 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
,
2200 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2202 /* Cast away the const modifier, as we want to just
2203 * rerun it through as a sideffect.
2205 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2207 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2208 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2209 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2210 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2211 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2212 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2214 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2216 return SCTP_DISPOSITION_CONSUME
;
2219 return SCTP_DISPOSITION_NOMEM
;
2226 * After checking the Verification Tag, the receiving endpoint shall
2227 * remove the association from its record, and shall report the
2228 * termination to its upper layer.
2230 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2231 * B) Rules for packet carrying ABORT:
2233 * - The endpoint shall always fill in the Verification Tag field of the
2234 * outbound packet with the destination endpoint's tag value if it
2237 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2238 * MUST follow the procedure described in Section 8.4.
2240 * - The receiver MUST accept the packet if the Verification Tag
2241 * matches either its own tag, OR the tag of its peer. Otherwise, the
2242 * receiver MUST silently discard the packet and take no further
2246 * (endpoint, asoc, chunk)
2249 * (asoc, reply_msg, msg_up, timers, counters)
2251 * The return value is the disposition of the chunk.
2253 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2254 const struct sctp_association
*asoc
,
2255 const sctp_subtype_t type
,
2257 sctp_cmd_seq_t
*commands
)
2259 struct sctp_chunk
*chunk
= arg
;
2261 __be16 error
= SCTP_ERROR_NO_ERROR
;
2263 if (!sctp_vtag_verify_either(chunk
, asoc
))
2264 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2266 /* Make sure that the ABORT chunk has a valid length.
2267 * Since this is an ABORT chunk, we have to discard it
2268 * because of the following text:
2269 * RFC 2960, Section 3.3.7
2270 * If an endpoint receives an ABORT with a format error or for an
2271 * association that doesn't exist, it MUST silently discard it.
2272 * Becasue the length is "invalid", we can't really discard just
2273 * as we do not know its true length. So, to be safe, discard the
2276 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2277 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2279 /* See if we have an error cause code in the chunk. */
2280 len
= ntohs(chunk
->chunk_hdr
->length
);
2281 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2282 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2284 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2285 /* ASSOC_FAILED will DELETE_TCB. */
2286 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2287 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2288 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
2290 return SCTP_DISPOSITION_ABORT
;
2294 * Process an ABORT. (COOKIE-WAIT state)
2296 * See sctp_sf_do_9_1_abort() above.
2298 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2299 const struct sctp_association
*asoc
,
2300 const sctp_subtype_t type
,
2302 sctp_cmd_seq_t
*commands
)
2304 struct sctp_chunk
*chunk
= arg
;
2306 __be16 error
= SCTP_ERROR_NO_ERROR
;
2308 if (!sctp_vtag_verify_either(chunk
, asoc
))
2309 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2311 /* Make sure that the ABORT chunk has a valid length.
2312 * Since this is an ABORT chunk, we have to discard it
2313 * because of the following text:
2314 * RFC 2960, Section 3.3.7
2315 * If an endpoint receives an ABORT with a format error or for an
2316 * association that doesn't exist, it MUST silently discard it.
2317 * Becasue the length is "invalid", we can't really discard just
2318 * as we do not know its true length. So, to be safe, discard the
2321 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2322 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2324 /* See if we have an error cause code in the chunk. */
2325 len
= ntohs(chunk
->chunk_hdr
->length
);
2326 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2327 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2329 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
, asoc
,
2334 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2336 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2337 const struct sctp_association
*asoc
,
2338 const sctp_subtype_t type
,
2340 sctp_cmd_seq_t
*commands
)
2342 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
,
2344 (struct sctp_transport
*)arg
);
2348 * Process an ABORT. (COOKIE-ECHOED state)
2350 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2351 const struct sctp_association
*asoc
,
2352 const sctp_subtype_t type
,
2354 sctp_cmd_seq_t
*commands
)
2356 /* There is a single T1 timer, so we should be able to use
2357 * common function with the COOKIE-WAIT state.
2359 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2363 * Stop T1 timer and abort association with "INIT failed".
2365 * This is common code called by several sctp_sf_*_abort() functions above.
2367 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2368 __be16 error
, int sk_err
,
2369 const struct sctp_association
*asoc
,
2370 struct sctp_transport
*transport
)
2372 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2373 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2374 SCTP_STATE(SCTP_STATE_CLOSED
));
2375 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2376 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2377 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2378 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2379 /* CMD_INIT_FAILED will DELETE_TCB. */
2380 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2382 return SCTP_DISPOSITION_ABORT
;
2386 * sctp_sf_do_9_2_shut
2389 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2390 * - enter the SHUTDOWN-RECEIVED state,
2392 * - stop accepting new data from its SCTP user
2394 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2395 * that all its outstanding DATA chunks have been received by the
2398 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2399 * send a SHUTDOWN in response to a ULP request. And should discard
2400 * subsequent SHUTDOWN chunks.
2402 * If there are still outstanding DATA chunks left, the SHUTDOWN
2403 * receiver shall continue to follow normal data transmission
2404 * procedures defined in Section 6 until all outstanding DATA chunks
2405 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2406 * new data from its SCTP user.
2408 * Verification Tag: 8.5 Verification Tag [Normal verification]
2411 * (endpoint, asoc, chunk)
2414 * (asoc, reply_msg, msg_up, timers, counters)
2416 * The return value is the disposition of the chunk.
2418 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2419 const struct sctp_association
*asoc
,
2420 const sctp_subtype_t type
,
2422 sctp_cmd_seq_t
*commands
)
2424 struct sctp_chunk
*chunk
= arg
;
2425 sctp_shutdownhdr_t
*sdh
;
2426 sctp_disposition_t disposition
;
2427 struct sctp_ulpevent
*ev
;
2429 if (!sctp_vtag_verify(chunk
, asoc
))
2430 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2432 /* Make sure that the SHUTDOWN chunk has a valid length. */
2433 if (!sctp_chunk_length_valid(chunk
,
2434 sizeof(struct sctp_shutdown_chunk_t
)))
2435 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2438 /* Convert the elaborate header. */
2439 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2440 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2441 chunk
->subh
.shutdown_hdr
= sdh
;
2443 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2444 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2445 * inform the application that it should cease sending data.
2447 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2449 disposition
= SCTP_DISPOSITION_NOMEM
;
2452 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2454 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2455 * - enter the SHUTDOWN-RECEIVED state,
2456 * - stop accepting new data from its SCTP user
2458 * [This is implicit in the new state.]
2460 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2461 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2462 disposition
= SCTP_DISPOSITION_CONSUME
;
2464 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2465 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2469 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2472 /* - verify, by checking the Cumulative TSN Ack field of the
2473 * chunk, that all its outstanding DATA chunks have been
2474 * received by the SHUTDOWN sender.
2476 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2477 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2484 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2485 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2486 * transport addresses (either in the IP addresses or in the INIT chunk)
2487 * that belong to this association, it should discard the INIT chunk and
2488 * retransmit the SHUTDOWN ACK chunk.
2490 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2491 const struct sctp_association
*asoc
,
2492 const sctp_subtype_t type
,
2494 sctp_cmd_seq_t
*commands
)
2496 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2497 struct sctp_chunk
*reply
;
2499 /* Since we are not going to really process this INIT, there
2500 * is no point in verifying chunk boundries. Just generate
2503 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2507 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2508 * the T2-SHUTDOWN timer.
2510 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2512 /* and restart the T2-shutdown timer. */
2513 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2514 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2516 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2518 return SCTP_DISPOSITION_CONSUME
;
2520 return SCTP_DISPOSITION_NOMEM
;
2524 * sctp_sf_do_ecn_cwr
2526 * Section: Appendix A: Explicit Congestion Notification
2530 * RFC 2481 details a specific bit for a sender to send in the header of
2531 * its next outbound TCP segment to indicate to its peer that it has
2532 * reduced its congestion window. This is termed the CWR bit. For
2533 * SCTP the same indication is made by including the CWR chunk.
2534 * This chunk contains one data element, i.e. the TSN number that
2535 * was sent in the ECNE chunk. This element represents the lowest
2536 * TSN number in the datagram that was originally marked with the
2539 * Verification Tag: 8.5 Verification Tag [Normal verification]
2541 * (endpoint, asoc, chunk)
2544 * (asoc, reply_msg, msg_up, timers, counters)
2546 * The return value is the disposition of the chunk.
2548 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2549 const struct sctp_association
*asoc
,
2550 const sctp_subtype_t type
,
2552 sctp_cmd_seq_t
*commands
)
2555 struct sctp_chunk
*chunk
= arg
;
2558 if (!sctp_vtag_verify(chunk
, asoc
))
2559 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2561 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2562 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2565 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2566 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2568 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2570 /* Does this CWR ack the last sent congestion notification? */
2571 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2572 /* Stop sending ECNE. */
2573 sctp_add_cmd_sf(commands
,
2575 SCTP_U32(lowest_tsn
));
2577 return SCTP_DISPOSITION_CONSUME
;
2583 * Section: Appendix A: Explicit Congestion Notification
2587 * RFC 2481 details a specific bit for a receiver to send back in its
2588 * TCP acknowledgements to notify the sender of the Congestion
2589 * Experienced (CE) bit having arrived from the network. For SCTP this
2590 * same indication is made by including the ECNE chunk. This chunk
2591 * contains one data element, i.e. the lowest TSN associated with the IP
2592 * datagram marked with the CE bit.....
2594 * Verification Tag: 8.5 Verification Tag [Normal verification]
2596 * (endpoint, asoc, chunk)
2599 * (asoc, reply_msg, msg_up, timers, counters)
2601 * The return value is the disposition of the chunk.
2603 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2604 const struct sctp_association
*asoc
,
2605 const sctp_subtype_t type
,
2607 sctp_cmd_seq_t
*commands
)
2609 sctp_ecnehdr_t
*ecne
;
2610 struct sctp_chunk
*chunk
= arg
;
2612 if (!sctp_vtag_verify(chunk
, asoc
))
2613 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2615 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2616 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2619 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2620 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2622 /* If this is a newer ECNE than the last CWR packet we sent out */
2623 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2624 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2626 return SCTP_DISPOSITION_CONSUME
;
2630 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2632 * The SCTP endpoint MUST always acknowledge the reception of each valid
2635 * The guidelines on delayed acknowledgement algorithm specified in
2636 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2637 * acknowledgement SHOULD be generated for at least every second packet
2638 * (not every second DATA chunk) received, and SHOULD be generated within
2639 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2640 * situations it may be beneficial for an SCTP transmitter to be more
2641 * conservative than the algorithms detailed in this document allow.
2642 * However, an SCTP transmitter MUST NOT be more aggressive than the
2643 * following algorithms allow.
2645 * A SCTP receiver MUST NOT generate more than one SACK for every
2646 * incoming packet, other than to update the offered window as the
2647 * receiving application consumes new data.
2649 * Verification Tag: 8.5 Verification Tag [Normal verification]
2652 * (endpoint, asoc, chunk)
2655 * (asoc, reply_msg, msg_up, timers, counters)
2657 * The return value is the disposition of the chunk.
2659 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2660 const struct sctp_association
*asoc
,
2661 const sctp_subtype_t type
,
2663 sctp_cmd_seq_t
*commands
)
2665 struct sctp_chunk
*chunk
= arg
;
2668 if (!sctp_vtag_verify(chunk
, asoc
)) {
2669 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2671 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2674 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2675 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2678 error
= sctp_eat_data(asoc
, chunk
, commands
);
2680 case SCTP_IERROR_NO_ERROR
:
2682 case SCTP_IERROR_HIGH_TSN
:
2683 case SCTP_IERROR_BAD_STREAM
:
2684 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2685 goto discard_noforce
;
2686 case SCTP_IERROR_DUP_TSN
:
2687 case SCTP_IERROR_IGNORE_TSN
:
2688 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2690 case SCTP_IERROR_NO_DATA
:
2696 if (asoc
->autoclose
) {
2697 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2698 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2701 /* If this is the last chunk in a packet, we need to count it
2702 * toward sack generation. Note that we need to SACK every
2703 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2704 * THEM. We elect to NOT generate SACK's if the chunk fails
2705 * the verification tag test.
2707 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2709 * The SCTP endpoint MUST always acknowledge the reception of
2710 * each valid DATA chunk.
2712 * The guidelines on delayed acknowledgement algorithm
2713 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2714 * Specifically, an acknowledgement SHOULD be generated for at
2715 * least every second packet (not every second DATA chunk)
2716 * received, and SHOULD be generated within 200 ms of the
2717 * arrival of any unacknowledged DATA chunk. In some
2718 * situations it may be beneficial for an SCTP transmitter to
2719 * be more conservative than the algorithms detailed in this
2720 * document allow. However, an SCTP transmitter MUST NOT be
2721 * more aggressive than the following algorithms allow.
2723 if (chunk
->end_of_packet
)
2724 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2726 return SCTP_DISPOSITION_CONSUME
;
2729 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2731 * When a packet arrives with duplicate DATA chunk(s) and with
2732 * no new DATA chunk(s), the endpoint MUST immediately send a
2733 * SACK with no delay. If a packet arrives with duplicate
2734 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2735 * MAY immediately send a SACK. Normally receipt of duplicate
2736 * DATA chunks will occur when the original SACK chunk was lost
2737 * and the peer's RTO has expired. The duplicate TSN number(s)
2738 * SHOULD be reported in the SACK as duplicate.
2740 /* In our case, we split the MAY SACK advice up whether or not
2741 * the last chunk is a duplicate.'
2743 if (chunk
->end_of_packet
)
2744 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2745 return SCTP_DISPOSITION_DISCARD
;
2748 if (chunk
->end_of_packet
)
2749 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2751 return SCTP_DISPOSITION_DISCARD
;
2753 return SCTP_DISPOSITION_CONSUME
;
2758 * sctp_sf_eat_data_fast_4_4
2761 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2762 * DATA chunks without delay.
2764 * Verification Tag: 8.5 Verification Tag [Normal verification]
2766 * (endpoint, asoc, chunk)
2769 * (asoc, reply_msg, msg_up, timers, counters)
2771 * The return value is the disposition of the chunk.
2773 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
2774 const struct sctp_association
*asoc
,
2775 const sctp_subtype_t type
,
2777 sctp_cmd_seq_t
*commands
)
2779 struct sctp_chunk
*chunk
= arg
;
2782 if (!sctp_vtag_verify(chunk
, asoc
)) {
2783 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2785 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2788 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2789 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2792 error
= sctp_eat_data(asoc
, chunk
, commands
);
2794 case SCTP_IERROR_NO_ERROR
:
2795 case SCTP_IERROR_HIGH_TSN
:
2796 case SCTP_IERROR_DUP_TSN
:
2797 case SCTP_IERROR_IGNORE_TSN
:
2798 case SCTP_IERROR_BAD_STREAM
:
2800 case SCTP_IERROR_NO_DATA
:
2806 /* Go a head and force a SACK, since we are shutting down. */
2808 /* Implementor's Guide.
2810 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2811 * respond to each received packet containing one or more DATA chunk(s)
2812 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2814 if (chunk
->end_of_packet
) {
2815 /* We must delay the chunk creation since the cumulative
2816 * TSN has not been updated yet.
2818 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
2819 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2820 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2821 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2825 return SCTP_DISPOSITION_CONSUME
;
2829 * Section: 6.2 Processing a Received SACK
2830 * D) Any time a SACK arrives, the endpoint performs the following:
2832 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2833 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2834 * increasing, a SACK whose Cumulative TSN Ack is less than the
2835 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2837 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2838 * of bytes still outstanding after processing the Cumulative TSN Ack
2839 * and the Gap Ack Blocks.
2841 * iii) If the SACK is missing a TSN that was previously
2842 * acknowledged via a Gap Ack Block (e.g., the data receiver
2843 * reneged on the data), then mark the corresponding DATA chunk
2844 * as available for retransmit: Mark it as missing for fast
2845 * retransmit as described in Section 7.2.4 and if no retransmit
2846 * timer is running for the destination address to which the DATA
2847 * chunk was originally transmitted, then T3-rtx is started for
2848 * that destination address.
2850 * Verification Tag: 8.5 Verification Tag [Normal verification]
2853 * (endpoint, asoc, chunk)
2856 * (asoc, reply_msg, msg_up, timers, counters)
2858 * The return value is the disposition of the chunk.
2860 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
2861 const struct sctp_association
*asoc
,
2862 const sctp_subtype_t type
,
2864 sctp_cmd_seq_t
*commands
)
2866 struct sctp_chunk
*chunk
= arg
;
2867 sctp_sackhdr_t
*sackh
;
2870 if (!sctp_vtag_verify(chunk
, asoc
))
2871 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2873 /* Make sure that the SACK chunk has a valid length. */
2874 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
2875 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2878 /* Pull the SACK chunk from the data buffer */
2879 sackh
= sctp_sm_pull_sack(chunk
);
2880 /* Was this a bogus SACK? */
2882 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2883 chunk
->subh
.sack_hdr
= sackh
;
2884 ctsn
= ntohl(sackh
->cum_tsn_ack
);
2886 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
2887 * Ack Point, then drop the SACK. Since Cumulative TSN
2888 * Ack is monotonically increasing, a SACK whose
2889 * Cumulative TSN Ack is less than the Cumulative TSN Ack
2890 * Point indicates an out-of-order SACK.
2892 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2893 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2894 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2895 return SCTP_DISPOSITION_DISCARD
;
2898 /* If Cumulative TSN Ack beyond the max tsn currently
2899 * send, terminating the association and respond to the
2900 * sender with an ABORT.
2902 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2903 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2905 /* Return this SACK for further processing. */
2906 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
2908 /* Note: We do the rest of the work on the PROCESS_SACK
2911 return SCTP_DISPOSITION_CONSUME
;
2915 * Generate an ABORT in response to a packet.
2917 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
2919 * 8) The receiver should respond to the sender of the OOTB packet with
2920 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
2921 * MUST fill in the Verification Tag field of the outbound packet
2922 * with the value found in the Verification Tag field of the OOTB
2923 * packet and set the T-bit in the Chunk Flags to indicate that the
2924 * Verification Tag is reflected. After sending this ABORT, the
2925 * receiver of the OOTB packet shall discard the OOTB packet and take
2926 * no further action.
2930 * The return value is the disposition of the chunk.
2932 sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
2933 const struct sctp_association
*asoc
,
2934 const sctp_subtype_t type
,
2936 sctp_cmd_seq_t
*commands
)
2938 struct sctp_packet
*packet
= NULL
;
2939 struct sctp_chunk
*chunk
= arg
;
2940 struct sctp_chunk
*abort
;
2942 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
2945 /* Make an ABORT. The T bit will be set if the asoc
2948 abort
= sctp_make_abort(asoc
, chunk
, 0);
2950 sctp_ootb_pkt_free(packet
);
2951 return SCTP_DISPOSITION_NOMEM
;
2954 /* Reflect vtag if T-Bit is set */
2955 if (sctp_test_T_bit(abort
))
2956 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
2958 /* Set the skb to the belonging sock for accounting. */
2959 abort
->skb
->sk
= ep
->base
.sk
;
2961 sctp_packet_append_chunk(packet
, abort
);
2963 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
2964 SCTP_PACKET(packet
));
2966 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
2968 return SCTP_DISPOSITION_CONSUME
;
2971 return SCTP_DISPOSITION_NOMEM
;
2975 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
2976 * event as ULP notification for each cause included in the chunk.
2978 * API 5.3.1.3 - SCTP_REMOTE_ERROR
2980 * The return value is the disposition of the chunk.
2982 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
2983 const struct sctp_association
*asoc
,
2984 const sctp_subtype_t type
,
2986 sctp_cmd_seq_t
*commands
)
2988 struct sctp_chunk
*chunk
= arg
;
2989 struct sctp_ulpevent
*ev
;
2991 if (!sctp_vtag_verify(chunk
, asoc
))
2992 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2994 /* Make sure that the ERROR chunk has a valid length. */
2995 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2996 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2999 while (chunk
->chunk_end
> chunk
->skb
->data
) {
3000 ev
= sctp_ulpevent_make_remote_error(asoc
, chunk
, 0,
3005 if (!sctp_add_cmd(commands
, SCTP_CMD_EVENT_ULP
,
3006 SCTP_ULPEVENT(ev
))) {
3007 sctp_ulpevent_free(ev
);
3011 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3014 return SCTP_DISPOSITION_CONSUME
;
3017 return SCTP_DISPOSITION_NOMEM
;
3021 * Process an inbound SHUTDOWN ACK.
3024 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3025 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3026 * peer, and remove all record of the association.
3028 * The return value is the disposition.
3030 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
3031 const struct sctp_association
*asoc
,
3032 const sctp_subtype_t type
,
3034 sctp_cmd_seq_t
*commands
)
3036 struct sctp_chunk
*chunk
= arg
;
3037 struct sctp_chunk
*reply
;
3038 struct sctp_ulpevent
*ev
;
3040 if (!sctp_vtag_verify(chunk
, asoc
))
3041 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3043 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3044 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3045 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3047 /* 10.2 H) SHUTDOWN COMPLETE notification
3049 * When SCTP completes the shutdown procedures (section 9.2) this
3050 * notification is passed to the upper layer.
3052 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3053 0, 0, 0, NULL
, GFP_ATOMIC
);
3057 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3058 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3062 /* Do all the commands now (after allocation), so that we
3063 * have consistent state if memory allocation failes
3065 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3067 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3068 * stop the T2-shutdown timer,
3070 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3071 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3073 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3074 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3076 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3077 SCTP_STATE(SCTP_STATE_CLOSED
));
3078 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
3079 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3080 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3082 /* ...and remove all record of the association. */
3083 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3084 return SCTP_DISPOSITION_DELETE_TCB
;
3087 sctp_ulpevent_free(ev
);
3089 return SCTP_DISPOSITION_NOMEM
;
3093 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3095 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3096 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3097 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3098 * packet must fill in the Verification Tag field of the outbound
3099 * packet with the Verification Tag received in the SHUTDOWN ACK and
3100 * set the T-bit in the Chunk Flags to indicate that the Verification
3103 * 8) The receiver should respond to the sender of the OOTB packet with
3104 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3105 * MUST fill in the Verification Tag field of the outbound packet
3106 * with the value found in the Verification Tag field of the OOTB
3107 * packet and set the T-bit in the Chunk Flags to indicate that the
3108 * Verification Tag is reflected. After sending this ABORT, the
3109 * receiver of the OOTB packet shall discard the OOTB packet and take
3110 * no further action.
3112 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3113 const struct sctp_association
*asoc
,
3114 const sctp_subtype_t type
,
3116 sctp_cmd_seq_t
*commands
)
3118 struct sctp_chunk
*chunk
= arg
;
3119 struct sk_buff
*skb
= chunk
->skb
;
3120 sctp_chunkhdr_t
*ch
;
3122 int ootb_shut_ack
= 0;
3124 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3126 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3128 /* Break out if chunk length is less then minimal. */
3129 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3132 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3133 if (ch_end
> skb_tail_pointer(skb
))
3136 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3139 /* RFC 2960, Section 3.3.7
3140 * Moreover, under any circumstances, an endpoint that
3141 * receives an ABORT MUST NOT respond to that ABORT by
3142 * sending an ABORT of its own.
3144 if (SCTP_CID_ABORT
== ch
->type
)
3145 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3147 ch
= (sctp_chunkhdr_t
*) ch_end
;
3148 } while (ch_end
< skb_tail_pointer(skb
));
3151 sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3153 sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3155 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3159 * Handle an "Out of the blue" SHUTDOWN ACK.
3161 * Section: 8.4 5, sctpimpguide 2.41.
3163 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3164 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3165 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3166 * packet must fill in the Verification Tag field of the outbound
3167 * packet with the Verification Tag received in the SHUTDOWN ACK and
3168 * set the T-bit in the Chunk Flags to indicate that the Verification
3172 * (endpoint, asoc, type, arg, commands)
3175 * (sctp_disposition_t)
3177 * The return value is the disposition of the chunk.
3179 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3180 const struct sctp_association
*asoc
,
3181 const sctp_subtype_t type
,
3183 sctp_cmd_seq_t
*commands
)
3185 struct sctp_packet
*packet
= NULL
;
3186 struct sctp_chunk
*chunk
= arg
;
3187 struct sctp_chunk
*shut
;
3189 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3192 /* Make an SHUTDOWN_COMPLETE.
3193 * The T bit will be set if the asoc is NULL.
3195 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3197 sctp_ootb_pkt_free(packet
);
3198 return SCTP_DISPOSITION_NOMEM
;
3201 /* Reflect vtag if T-Bit is set */
3202 if (sctp_test_T_bit(shut
))
3203 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3205 /* Set the skb to the belonging sock for accounting. */
3206 shut
->skb
->sk
= ep
->base
.sk
;
3208 sctp_packet_append_chunk(packet
, shut
);
3210 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3211 SCTP_PACKET(packet
));
3213 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3215 /* If the chunk length is invalid, we don't want to process
3216 * the reset of the packet.
3218 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3219 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3221 return SCTP_DISPOSITION_CONSUME
;
3224 return SCTP_DISPOSITION_NOMEM
;
3228 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3230 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3231 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3232 * procedures in section 8.4 SHOULD be followed, in other words it
3233 * should be treated as an Out Of The Blue packet.
3234 * [This means that we do NOT check the Verification Tag on these
3238 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3239 const struct sctp_association
*asoc
,
3240 const sctp_subtype_t type
,
3242 sctp_cmd_seq_t
*commands
)
3244 /* Although we do have an association in this case, it corresponds
3245 * to a restarted association. So the packet is treated as an OOTB
3246 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3247 * called with a NULL association.
3249 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3252 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3253 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3254 const struct sctp_association
*asoc
,
3255 const sctp_subtype_t type
, void *arg
,
3256 sctp_cmd_seq_t
*commands
)
3258 struct sctp_chunk
*chunk
= arg
;
3259 struct sctp_chunk
*asconf_ack
= NULL
;
3260 sctp_addiphdr_t
*hdr
;
3263 if (!sctp_vtag_verify(chunk
, asoc
)) {
3264 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3266 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3269 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3270 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3271 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3274 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3275 serial
= ntohl(hdr
->serial
);
3277 /* ADDIP 4.2 C1) Compare the value of the serial number to the value
3278 * the endpoint stored in a new association variable
3279 * 'Peer-Serial-Number'.
3281 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3282 /* ADDIP 4.2 C2) If the value found in the serial number is
3283 * equal to the ('Peer-Serial-Number' + 1), the endpoint MUST
3286 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3289 return SCTP_DISPOSITION_NOMEM
;
3290 } else if (serial
== asoc
->peer
.addip_serial
) {
3291 /* ADDIP 4.2 C3) If the value found in the serial number is
3292 * equal to the value stored in the 'Peer-Serial-Number'
3293 * IMPLEMENTATION NOTE: As an optimization a receiver may wish
3294 * to save the last ASCONF-ACK for some predetermined period of
3295 * time and instead of re-processing the ASCONF (with the same
3296 * serial number) it may just re-transmit the ASCONF-ACK.
3298 if (asoc
->addip_last_asconf_ack
)
3299 asconf_ack
= asoc
->addip_last_asconf_ack
;
3301 return SCTP_DISPOSITION_DISCARD
;
3303 /* ADDIP 4.2 C4) Otherwise, the ASCONF Chunk is discarded since
3304 * it must be either a stale packet or from an attacker.
3306 return SCTP_DISPOSITION_DISCARD
;
3309 /* ADDIP 4.2 C5) In both cases C2 and C3 the ASCONF-ACK MUST be sent
3310 * back to the source address contained in the IP header of the ASCONF
3311 * being responded to.
3313 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3315 return SCTP_DISPOSITION_CONSUME
;
3319 * ADDIP Section 4.3 General rules for address manipulation
3320 * When building TLV parameters for the ASCONF Chunk that will add or
3321 * delete IP addresses the D0 to D13 rules should be applied:
3323 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3324 const struct sctp_association
*asoc
,
3325 const sctp_subtype_t type
, void *arg
,
3326 sctp_cmd_seq_t
*commands
)
3328 struct sctp_chunk
*asconf_ack
= arg
;
3329 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3330 struct sctp_chunk
*abort
;
3331 sctp_addiphdr_t
*addip_hdr
;
3332 __u32 sent_serial
, rcvd_serial
;
3334 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3335 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3337 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3340 /* Make sure that the ADDIP chunk has a valid length. */
3341 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3342 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3345 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3346 rcvd_serial
= ntohl(addip_hdr
->serial
);
3349 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3350 sent_serial
= ntohl(addip_hdr
->serial
);
3352 sent_serial
= asoc
->addip_serial
- 1;
3355 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3356 * equal to the next serial number to be used but no ASCONF chunk is
3357 * outstanding the endpoint MUST ABORT the association. Note that a
3358 * sequence number is greater than if it is no more than 2^^31-1
3359 * larger than the current sequence number (using serial arithmetic).
3361 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3362 !(asoc
->addip_last_asconf
)) {
3363 abort
= sctp_make_abort(asoc
, asconf_ack
,
3364 sizeof(sctp_errhdr_t
));
3366 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3367 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3370 /* We are going to ABORT, so we might as well stop
3371 * processing the rest of the chunks in the packet.
3373 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3374 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3375 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3376 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3377 SCTP_ERROR(ECONNABORTED
));
3378 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3379 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3380 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3381 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3382 return SCTP_DISPOSITION_ABORT
;
3385 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3386 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3387 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3389 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3391 return SCTP_DISPOSITION_CONSUME
;
3393 abort
= sctp_make_abort(asoc
, asconf_ack
,
3394 sizeof(sctp_errhdr_t
));
3396 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3397 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3400 /* We are going to ABORT, so we might as well stop
3401 * processing the rest of the chunks in the packet.
3403 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3404 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3405 SCTP_ERROR(ECONNABORTED
));
3406 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3407 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3408 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3409 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3410 return SCTP_DISPOSITION_ABORT
;
3413 return SCTP_DISPOSITION_DISCARD
;
3417 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3419 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3420 * its cumulative TSN point to the value carried in the FORWARD TSN
3421 * chunk, and then MUST further advance its cumulative TSN point locally
3423 * After the above processing, the data receiver MUST stop reporting any
3424 * missing TSNs earlier than or equal to the new cumulative TSN point.
3426 * Verification Tag: 8.5 Verification Tag [Normal verification]
3428 * The return value is the disposition of the chunk.
3430 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3431 const struct sctp_association
*asoc
,
3432 const sctp_subtype_t type
,
3434 sctp_cmd_seq_t
*commands
)
3436 struct sctp_chunk
*chunk
= arg
;
3437 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3441 if (!sctp_vtag_verify(chunk
, asoc
)) {
3442 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3444 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3447 /* Make sure that the FORWARD_TSN chunk has valid length. */
3448 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3449 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3452 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3453 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3454 len
= ntohs(chunk
->chunk_hdr
->length
);
3455 len
-= sizeof(struct sctp_chunkhdr
);
3456 skb_pull(chunk
->skb
, len
);
3458 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3459 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3461 /* The TSN is too high--silently discard the chunk and count on it
3462 * getting retransmitted later.
3464 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3465 goto discard_noforce
;
3467 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3468 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3469 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3472 /* Count this as receiving DATA. */
3473 if (asoc
->autoclose
) {
3474 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3475 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3478 /* FIXME: For now send a SACK, but DATA processing may
3481 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3483 return SCTP_DISPOSITION_CONSUME
;
3486 return SCTP_DISPOSITION_DISCARD
;
3489 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3490 const struct sctp_endpoint
*ep
,
3491 const struct sctp_association
*asoc
,
3492 const sctp_subtype_t type
,
3494 sctp_cmd_seq_t
*commands
)
3496 struct sctp_chunk
*chunk
= arg
;
3497 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3501 if (!sctp_vtag_verify(chunk
, asoc
)) {
3502 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3504 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3507 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3508 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3509 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3512 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3513 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3514 len
= ntohs(chunk
->chunk_hdr
->length
);
3515 len
-= sizeof(struct sctp_chunkhdr
);
3516 skb_pull(chunk
->skb
, len
);
3518 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3519 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3521 /* The TSN is too high--silently discard the chunk and count on it
3522 * getting retransmitted later.
3524 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3527 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3528 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3529 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3532 /* Go a head and force a SACK, since we are shutting down. */
3534 /* Implementor's Guide.
3536 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3537 * respond to each received packet containing one or more DATA chunk(s)
3538 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3540 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3541 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3542 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3543 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3545 return SCTP_DISPOSITION_CONSUME
;
3549 * Process an unknown chunk.
3551 * Section: 3.2. Also, 2.1 in the implementor's guide.
3553 * Chunk Types are encoded such that the highest-order two bits specify
3554 * the action that must be taken if the processing endpoint does not
3555 * recognize the Chunk Type.
3557 * 00 - Stop processing this SCTP packet and discard it, do not process
3558 * any further chunks within it.
3560 * 01 - Stop processing this SCTP packet and discard it, do not process
3561 * any further chunks within it, and report the unrecognized
3562 * chunk in an 'Unrecognized Chunk Type'.
3564 * 10 - Skip this chunk and continue processing.
3566 * 11 - Skip this chunk and continue processing, but report in an ERROR
3567 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3569 * The return value is the disposition of the chunk.
3571 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
3572 const struct sctp_association
*asoc
,
3573 const sctp_subtype_t type
,
3575 sctp_cmd_seq_t
*commands
)
3577 struct sctp_chunk
*unk_chunk
= arg
;
3578 struct sctp_chunk
*err_chunk
;
3579 sctp_chunkhdr_t
*hdr
;
3581 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
3583 if (!sctp_vtag_verify(unk_chunk
, asoc
))
3584 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3586 /* Make sure that the chunk has a valid length.
3587 * Since we don't know the chunk type, we use a general
3588 * chunkhdr structure to make a comparison.
3590 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
3591 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3594 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
3595 case SCTP_CID_ACTION_DISCARD
:
3596 /* Discard the packet. */
3597 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3599 case SCTP_CID_ACTION_DISCARD_ERR
:
3600 /* Discard the packet. */
3601 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3603 /* Generate an ERROR chunk as response. */
3604 hdr
= unk_chunk
->chunk_hdr
;
3605 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3606 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3607 WORD_ROUND(ntohs(hdr
->length
)));
3609 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3610 SCTP_CHUNK(err_chunk
));
3612 return SCTP_DISPOSITION_CONSUME
;
3614 case SCTP_CID_ACTION_SKIP
:
3615 /* Skip the chunk. */
3616 return SCTP_DISPOSITION_DISCARD
;
3618 case SCTP_CID_ACTION_SKIP_ERR
:
3619 /* Generate an ERROR chunk as response. */
3620 hdr
= unk_chunk
->chunk_hdr
;
3621 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3622 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3623 WORD_ROUND(ntohs(hdr
->length
)));
3625 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3626 SCTP_CHUNK(err_chunk
));
3628 /* Skip the chunk. */
3629 return SCTP_DISPOSITION_CONSUME
;
3635 return SCTP_DISPOSITION_DISCARD
;
3639 * Discard the chunk.
3641 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
3642 * [Too numerous to mention...]
3643 * Verification Tag: No verification needed.
3645 * (endpoint, asoc, chunk)
3648 * (asoc, reply_msg, msg_up, timers, counters)
3650 * The return value is the disposition of the chunk.
3652 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
3653 const struct sctp_association
*asoc
,
3654 const sctp_subtype_t type
,
3656 sctp_cmd_seq_t
*commands
)
3658 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
3659 return SCTP_DISPOSITION_DISCARD
;
3663 * Discard the whole packet.
3667 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
3668 * silently discard the OOTB packet and take no further action.
3670 * Verification Tag: No verification necessary
3673 * (endpoint, asoc, chunk)
3676 * (asoc, reply_msg, msg_up, timers, counters)
3678 * The return value is the disposition of the chunk.
3680 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
3681 const struct sctp_association
*asoc
,
3682 const sctp_subtype_t type
,
3684 sctp_cmd_seq_t
*commands
)
3686 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS
);
3687 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3689 return SCTP_DISPOSITION_CONSUME
;
3694 * The other end is violating protocol.
3696 * Section: Not specified
3697 * Verification Tag: Not specified
3699 * (endpoint, asoc, chunk)
3702 * (asoc, reply_msg, msg_up, timers, counters)
3704 * We simply tag the chunk as a violation. The state machine will log
3705 * the violation and continue.
3707 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
3708 const struct sctp_association
*asoc
,
3709 const sctp_subtype_t type
,
3711 sctp_cmd_seq_t
*commands
)
3713 return SCTP_DISPOSITION_VIOLATION
;
3717 * Common function to handle a protocol violation.
3719 static sctp_disposition_t
sctp_sf_abort_violation(
3720 const struct sctp_association
*asoc
,
3722 sctp_cmd_seq_t
*commands
,
3723 const __u8
*payload
,
3724 const size_t paylen
)
3726 struct sctp_chunk
*chunk
= arg
;
3727 struct sctp_chunk
*abort
= NULL
;
3729 /* Make the abort chunk. */
3730 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
3734 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
3735 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3737 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
3738 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3739 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
3740 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3741 SCTP_ERROR(ECONNREFUSED
));
3742 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
3743 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
3745 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3746 SCTP_ERROR(ECONNABORTED
));
3747 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3748 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
3749 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3752 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3754 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3756 return SCTP_DISPOSITION_ABORT
;
3759 return SCTP_DISPOSITION_NOMEM
;
3763 * Handle a protocol violation when the chunk length is invalid.
3764 * "Invalid" length is identified as smaller then the minimal length a
3765 * given chunk can be. For example, a SACK chunk has invalid length
3766 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
3768 * We inform the other end by sending an ABORT with a Protocol Violation
3771 * Section: Not specified
3772 * Verification Tag: Nothing to do
3774 * (endpoint, asoc, chunk)
3777 * (reply_msg, msg_up, counters)
3779 * Generate an ABORT chunk and terminate the association.
3781 static sctp_disposition_t
sctp_sf_violation_chunklen(
3782 const struct sctp_endpoint
*ep
,
3783 const struct sctp_association
*asoc
,
3784 const sctp_subtype_t type
,
3786 sctp_cmd_seq_t
*commands
)
3788 char err_str
[]="The following chunk had invalid length:";
3790 return sctp_sf_abort_violation(asoc
, arg
, commands
, err_str
,
3794 /* Handle a protocol violation when the peer trying to advance the
3795 * cumulative tsn ack to a point beyond the max tsn currently sent.
3797 * We inform the other end by sending an ABORT with a Protocol Violation
3800 static sctp_disposition_t
sctp_sf_violation_ctsn(
3801 const struct sctp_endpoint
*ep
,
3802 const struct sctp_association
*asoc
,
3803 const sctp_subtype_t type
,
3805 sctp_cmd_seq_t
*commands
)
3807 char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
3809 return sctp_sf_abort_violation(asoc
, arg
, commands
, err_str
,
3813 /***************************************************************************
3814 * These are the state functions for handling primitive (Section 10) events.
3815 ***************************************************************************/
3817 * sctp_sf_do_prm_asoc
3819 * Section: 10.1 ULP-to-SCTP
3822 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
3823 * outbound stream count)
3824 * -> association id [,destination transport addr list] [,outbound stream
3827 * This primitive allows the upper layer to initiate an association to a
3828 * specific peer endpoint.
3830 * The peer endpoint shall be specified by one of the transport addresses
3831 * which defines the endpoint (see Section 1.4). If the local SCTP
3832 * instance has not been initialized, the ASSOCIATE is considered an
3834 * [This is not relevant for the kernel implementation since we do all
3835 * initialization at boot time. It we hadn't initialized we wouldn't
3836 * get anywhere near this code.]
3838 * An association id, which is a local handle to the SCTP association,
3839 * will be returned on successful establishment of the association. If
3840 * SCTP is not able to open an SCTP association with the peer endpoint,
3841 * an error is returned.
3842 * [In the kernel implementation, the struct sctp_association needs to
3843 * be created BEFORE causing this primitive to run.]
3845 * Other association parameters may be returned, including the
3846 * complete destination transport addresses of the peer as well as the
3847 * outbound stream count of the local endpoint. One of the transport
3848 * address from the returned destination addresses will be selected by
3849 * the local endpoint as default primary path for sending SCTP packets
3850 * to this peer. The returned "destination transport addr list" can
3851 * be used by the ULP to change the default primary path or to force
3852 * sending a packet to a specific transport address. [All of this
3853 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
3856 * Mandatory attributes:
3858 * o local SCTP instance name - obtained from the INITIALIZE operation.
3859 * [This is the argument asoc.]
3860 * o destination transport addr - specified as one of the transport
3861 * addresses of the peer endpoint with which the association is to be
3863 * [This is asoc->peer.active_path.]
3864 * o outbound stream count - the number of outbound streams the ULP
3865 * would like to open towards this peer endpoint.
3866 * [BUG: This is not currently implemented.]
3867 * Optional attributes:
3871 * The return value is a disposition.
3873 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
3874 const struct sctp_association
*asoc
,
3875 const sctp_subtype_t type
,
3877 sctp_cmd_seq_t
*commands
)
3879 struct sctp_chunk
*repl
;
3881 /* The comment below says that we enter COOKIE-WAIT AFTER
3882 * sending the INIT, but that doesn't actually work in our
3885 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3886 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
3888 /* RFC 2960 5.1 Normal Establishment of an Association
3890 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
3891 * must provide its Verification Tag (Tag_A) in the Initiate
3892 * Tag field. Tag_A SHOULD be a random number in the range of
3893 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
3896 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
3900 /* Cast away the const modifier, as we want to just
3901 * rerun it through as a sideffect.
3903 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
,
3904 SCTP_ASOC((struct sctp_association
*) asoc
));
3906 /* Choose transport for INIT. */
3907 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
3910 /* After sending the INIT, "A" starts the T1-init timer and
3911 * enters the COOKIE-WAIT state.
3913 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
3914 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
3915 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
3916 return SCTP_DISPOSITION_CONSUME
;
3919 return SCTP_DISPOSITION_NOMEM
;
3923 * Process the SEND primitive.
3925 * Section: 10.1 ULP-to-SCTP
3928 * Format: SEND(association id, buffer address, byte count [,context]
3929 * [,stream id] [,life time] [,destination transport address]
3930 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
3933 * This is the main method to send user data via SCTP.
3935 * Mandatory attributes:
3937 * o association id - local handle to the SCTP association
3939 * o buffer address - the location where the user message to be
3940 * transmitted is stored;
3942 * o byte count - The size of the user data in number of bytes;
3944 * Optional attributes:
3946 * o context - an optional 32 bit integer that will be carried in the
3947 * sending failure notification to the ULP if the transportation of
3948 * this User Message fails.
3950 * o stream id - to indicate which stream to send the data on. If not
3951 * specified, stream 0 will be used.
3953 * o life time - specifies the life time of the user data. The user data
3954 * will not be sent by SCTP after the life time expires. This
3955 * parameter can be used to avoid efforts to transmit stale
3956 * user messages. SCTP notifies the ULP if the data cannot be
3957 * initiated to transport (i.e. sent to the destination via SCTP's
3958 * send primitive) within the life time variable. However, the
3959 * user data will be transmitted if SCTP has attempted to transmit a
3960 * chunk before the life time expired.
3962 * o destination transport address - specified as one of the destination
3963 * transport addresses of the peer endpoint to which this packet
3964 * should be sent. Whenever possible, SCTP should use this destination
3965 * transport address for sending the packets, instead of the current
3968 * o unorder flag - this flag, if present, indicates that the user
3969 * would like the data delivered in an unordered fashion to the peer
3970 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
3973 * o no-bundle flag - instructs SCTP not to bundle this user data with
3974 * other outbound DATA chunks. SCTP MAY still bundle even when
3975 * this flag is present, when faced with network congestion.
3977 * o payload protocol-id - A 32 bit unsigned integer that is to be
3978 * passed to the peer indicating the type of payload protocol data
3979 * being transmitted. This value is passed as opaque data by SCTP.
3981 * The return value is the disposition.
3983 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
3984 const struct sctp_association
*asoc
,
3985 const sctp_subtype_t type
,
3987 sctp_cmd_seq_t
*commands
)
3989 struct sctp_chunk
*chunk
= arg
;
3991 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
3992 return SCTP_DISPOSITION_CONSUME
;
3996 * Process the SHUTDOWN primitive.
4001 * Format: SHUTDOWN(association id)
4004 * Gracefully closes an association. Any locally queued user data
4005 * will be delivered to the peer. The association will be terminated only
4006 * after the peer acknowledges all the SCTP packets sent. A success code
4007 * will be returned on successful termination of the association. If
4008 * attempting to terminate the association results in a failure, an error
4009 * code shall be returned.
4011 * Mandatory attributes:
4013 * o association id - local handle to the SCTP association
4015 * Optional attributes:
4019 * The return value is the disposition.
4021 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4022 const struct sctp_endpoint
*ep
,
4023 const struct sctp_association
*asoc
,
4024 const sctp_subtype_t type
,
4026 sctp_cmd_seq_t
*commands
)
4030 /* From 9.2 Shutdown of an Association
4031 * Upon receipt of the SHUTDOWN primitive from its upper
4032 * layer, the endpoint enters SHUTDOWN-PENDING state and
4033 * remains there until all outstanding data has been
4034 * acknowledged by its peer. The endpoint accepts no new data
4035 * from its upper layer, but retransmits data to the far end
4036 * if necessary to fill gaps.
4038 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4039 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4041 /* sctpimpguide-05 Section 2.12.2
4042 * The sender of the SHUTDOWN MAY also start an overall guard timer
4043 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4045 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4046 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4048 disposition
= SCTP_DISPOSITION_CONSUME
;
4049 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4050 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4057 * Process the ABORT primitive.
4062 * Format: Abort(association id [, cause code])
4065 * Ungracefully closes an association. Any locally queued user data
4066 * will be discarded and an ABORT chunk is sent to the peer. A success code
4067 * will be returned on successful abortion of the association. If
4068 * attempting to abort the association results in a failure, an error
4069 * code shall be returned.
4071 * Mandatory attributes:
4073 * o association id - local handle to the SCTP association
4075 * Optional attributes:
4077 * o cause code - reason of the abort to be passed to the peer
4081 * The return value is the disposition.
4083 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4084 const struct sctp_endpoint
*ep
,
4085 const struct sctp_association
*asoc
,
4086 const sctp_subtype_t type
,
4088 sctp_cmd_seq_t
*commands
)
4090 /* From 9.1 Abort of an Association
4091 * Upon receipt of the ABORT primitive from its upper
4092 * layer, the endpoint enters CLOSED state and
4093 * discard all outstanding data has been
4094 * acknowledged by its peer. The endpoint accepts no new data
4095 * from its upper layer, but retransmits data to the far end
4096 * if necessary to fill gaps.
4098 struct sctp_chunk
*abort
= arg
;
4099 sctp_disposition_t retval
;
4101 retval
= SCTP_DISPOSITION_CONSUME
;
4103 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4105 /* Even if we can't send the ABORT due to low memory delete the
4106 * TCB. This is a departure from our typical NOMEM handling.
4109 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4110 SCTP_ERROR(ECONNABORTED
));
4111 /* Delete the established association. */
4112 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4113 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4115 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4116 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4121 /* We tried an illegal operation on an association which is closed. */
4122 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4123 const struct sctp_association
*asoc
,
4124 const sctp_subtype_t type
,
4126 sctp_cmd_seq_t
*commands
)
4128 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4129 return SCTP_DISPOSITION_CONSUME
;
4132 /* We tried an illegal operation on an association which is shutting
4135 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4136 const struct sctp_association
*asoc
,
4137 const sctp_subtype_t type
,
4139 sctp_cmd_seq_t
*commands
)
4141 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4142 SCTP_ERROR(-ESHUTDOWN
));
4143 return SCTP_DISPOSITION_CONSUME
;
4147 * sctp_cookie_wait_prm_shutdown
4149 * Section: 4 Note: 2
4154 * The RFC does not explicitly address this issue, but is the route through the
4155 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4160 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4161 const struct sctp_endpoint
*ep
,
4162 const struct sctp_association
*asoc
,
4163 const sctp_subtype_t type
,
4165 sctp_cmd_seq_t
*commands
)
4167 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4168 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4170 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4171 SCTP_STATE(SCTP_STATE_CLOSED
));
4173 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
4175 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4177 return SCTP_DISPOSITION_DELETE_TCB
;
4181 * sctp_cookie_echoed_prm_shutdown
4183 * Section: 4 Note: 2
4188 * The RFC does not explcitly address this issue, but is the route through the
4189 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4194 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4195 const struct sctp_endpoint
*ep
,
4196 const struct sctp_association
*asoc
,
4197 const sctp_subtype_t type
,
4198 void *arg
, sctp_cmd_seq_t
*commands
)
4200 /* There is a single T1 timer, so we should be able to use
4201 * common function with the COOKIE-WAIT state.
4203 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4207 * sctp_sf_cookie_wait_prm_abort
4209 * Section: 4 Note: 2
4214 * The RFC does not explicitly address this issue, but is the route through the
4215 * state table when someone issues an abort while in COOKIE_WAIT state.
4220 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4221 const struct sctp_endpoint
*ep
,
4222 const struct sctp_association
*asoc
,
4223 const sctp_subtype_t type
,
4225 sctp_cmd_seq_t
*commands
)
4227 struct sctp_chunk
*abort
= arg
;
4228 sctp_disposition_t retval
;
4230 /* Stop T1-init timer */
4231 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4232 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4233 retval
= SCTP_DISPOSITION_CONSUME
;
4235 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4237 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4238 SCTP_STATE(SCTP_STATE_CLOSED
));
4240 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4242 /* Even if we can't send the ABORT due to low memory delete the
4243 * TCB. This is a departure from our typical NOMEM handling.
4246 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4247 SCTP_ERROR(ECONNREFUSED
));
4248 /* Delete the established association. */
4249 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4250 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4256 * sctp_sf_cookie_echoed_prm_abort
4258 * Section: 4 Note: 3
4263 * The RFC does not explcitly address this issue, but is the route through the
4264 * state table when someone issues an abort while in COOKIE_ECHOED state.
4269 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4270 const struct sctp_endpoint
*ep
,
4271 const struct sctp_association
*asoc
,
4272 const sctp_subtype_t type
,
4274 sctp_cmd_seq_t
*commands
)
4276 /* There is a single T1 timer, so we should be able to use
4277 * common function with the COOKIE-WAIT state.
4279 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4283 * sctp_sf_shutdown_pending_prm_abort
4288 * The RFC does not explicitly address this issue, but is the route through the
4289 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4294 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4295 const struct sctp_endpoint
*ep
,
4296 const struct sctp_association
*asoc
,
4297 const sctp_subtype_t type
,
4299 sctp_cmd_seq_t
*commands
)
4301 /* Stop the T5-shutdown guard timer. */
4302 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4303 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4305 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4309 * sctp_sf_shutdown_sent_prm_abort
4314 * The RFC does not explicitly address this issue, but is the route through the
4315 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4320 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
4321 const struct sctp_endpoint
*ep
,
4322 const struct sctp_association
*asoc
,
4323 const sctp_subtype_t type
,
4325 sctp_cmd_seq_t
*commands
)
4327 /* Stop the T2-shutdown timer. */
4328 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4329 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4331 /* Stop the T5-shutdown guard timer. */
4332 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4333 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4335 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4339 * sctp_sf_cookie_echoed_prm_abort
4344 * The RFC does not explcitly address this issue, but is the route through the
4345 * state table when someone issues an abort while in COOKIE_ECHOED state.
4350 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
4351 const struct sctp_endpoint
*ep
,
4352 const struct sctp_association
*asoc
,
4353 const sctp_subtype_t type
,
4355 sctp_cmd_seq_t
*commands
)
4357 /* The same T2 timer, so we should be able to use
4358 * common function with the SHUTDOWN-SENT state.
4360 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
4364 * Process the REQUESTHEARTBEAT primitive
4367 * J) Request Heartbeat
4369 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4373 * Instructs the local endpoint to perform a HeartBeat on the specified
4374 * destination transport address of the given association. The returned
4375 * result should indicate whether the transmission of the HEARTBEAT
4376 * chunk to the destination address is successful.
4378 * Mandatory attributes:
4380 * o association id - local handle to the SCTP association
4382 * o destination transport address - the transport address of the
4383 * association on which a heartbeat should be issued.
4385 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
4386 const struct sctp_endpoint
*ep
,
4387 const struct sctp_association
*asoc
,
4388 const sctp_subtype_t type
,
4390 sctp_cmd_seq_t
*commands
)
4392 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
4393 (struct sctp_transport
*)arg
, commands
))
4394 return SCTP_DISPOSITION_NOMEM
;
4397 * RFC 2960 (bis), section 8.3
4399 * D) Request an on-demand HEARTBEAT on a specific destination
4400 * transport address of a given association.
4402 * The endpoint should increment the respective error counter of
4403 * the destination transport address each time a HEARTBEAT is sent
4404 * to that address and not acknowledged within one RTO.
4407 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
4408 SCTP_TRANSPORT(arg
));
4409 return SCTP_DISPOSITION_CONSUME
;
4413 * ADDIP Section 4.1 ASCONF Chunk Procedures
4414 * When an endpoint has an ASCONF signaled change to be sent to the
4415 * remote endpoint it should do A1 to A9
4417 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
4418 const struct sctp_association
*asoc
,
4419 const sctp_subtype_t type
,
4421 sctp_cmd_seq_t
*commands
)
4423 struct sctp_chunk
*chunk
= arg
;
4425 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4426 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4427 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4428 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4429 return SCTP_DISPOSITION_CONSUME
;
4433 * Ignore the primitive event
4435 * The return value is the disposition of the primitive.
4437 sctp_disposition_t
sctp_sf_ignore_primitive(
4438 const struct sctp_endpoint
*ep
,
4439 const struct sctp_association
*asoc
,
4440 const sctp_subtype_t type
,
4442 sctp_cmd_seq_t
*commands
)
4444 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
4445 return SCTP_DISPOSITION_DISCARD
;
4448 /***************************************************************************
4449 * These are the state functions for the OTHER events.
4450 ***************************************************************************/
4453 * Start the shutdown negotiation.
4456 * Once all its outstanding data has been acknowledged, the endpoint
4457 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4458 * TSN Ack field the last sequential TSN it has received from the peer.
4459 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4460 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4461 * with the updated last sequential TSN received from its peer.
4463 * The return value is the disposition.
4465 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
4466 const struct sctp_endpoint
*ep
,
4467 const struct sctp_association
*asoc
,
4468 const sctp_subtype_t type
,
4470 sctp_cmd_seq_t
*commands
)
4472 struct sctp_chunk
*reply
;
4474 /* Once all its outstanding data has been acknowledged, the
4475 * endpoint shall send a SHUTDOWN chunk to its peer including
4476 * in the Cumulative TSN Ack field the last sequential TSN it
4477 * has received from the peer.
4479 reply
= sctp_make_shutdown(asoc
, NULL
);
4483 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4484 * T2-shutdown timer.
4486 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4488 /* It shall then start the T2-shutdown timer */
4489 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4490 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4492 if (asoc
->autoclose
)
4493 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4494 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4496 /* and enter the SHUTDOWN-SENT state. */
4497 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4498 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
4500 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4502 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4505 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4507 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4509 return SCTP_DISPOSITION_CONSUME
;
4512 return SCTP_DISPOSITION_NOMEM
;
4516 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4520 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4521 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4522 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4523 * endpoint must re-send the SHUTDOWN ACK.
4525 * The return value is the disposition.
4527 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
4528 const struct sctp_endpoint
*ep
,
4529 const struct sctp_association
*asoc
,
4530 const sctp_subtype_t type
,
4532 sctp_cmd_seq_t
*commands
)
4534 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
4535 struct sctp_chunk
*reply
;
4537 /* There are 2 ways of getting here:
4538 * 1) called in response to a SHUTDOWN chunk
4539 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
4541 * For the case (2), the arg parameter is set to NULL. We need
4542 * to check that we have a chunk before accessing it's fields.
4545 if (!sctp_vtag_verify(chunk
, asoc
))
4546 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4548 /* Make sure that the SHUTDOWN chunk has a valid length. */
4549 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
4550 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4554 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4555 * shall send a SHUTDOWN ACK ...
4557 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
4561 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
4562 * the T2-shutdown timer.
4564 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4566 /* and start/restart a T2-shutdown timer of its own, */
4567 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4568 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4570 if (asoc
->autoclose
)
4571 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4572 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4574 /* Enter the SHUTDOWN-ACK-SENT state. */
4575 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4576 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
4578 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4580 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4583 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4585 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4587 return SCTP_DISPOSITION_CONSUME
;
4590 return SCTP_DISPOSITION_NOMEM
;
4594 * Ignore the event defined as other
4596 * The return value is the disposition of the event.
4598 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
4599 const struct sctp_association
*asoc
,
4600 const sctp_subtype_t type
,
4602 sctp_cmd_seq_t
*commands
)
4604 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
4605 return SCTP_DISPOSITION_DISCARD
;
4608 /************************************************************
4609 * These are the state functions for handling timeout events.
4610 ************************************************************/
4615 * Section: 6.3.3 Handle T3-rtx Expiration
4617 * Whenever the retransmission timer T3-rtx expires for a destination
4618 * address, do the following:
4621 * The return value is the disposition of the chunk.
4623 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
4624 const struct sctp_association
*asoc
,
4625 const sctp_subtype_t type
,
4627 sctp_cmd_seq_t
*commands
)
4629 struct sctp_transport
*transport
= arg
;
4631 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS
);
4633 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4634 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4635 SCTP_ERROR(ETIMEDOUT
));
4636 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4637 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4638 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4639 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4640 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4641 return SCTP_DISPOSITION_DELETE_TCB
;
4644 /* E1) For the destination address for which the timer
4645 * expires, adjust its ssthresh with rules defined in Section
4646 * 7.2.3 and set the cwnd <- MTU.
4649 /* E2) For the destination address for which the timer
4650 * expires, set RTO <- RTO * 2 ("back off the timer"). The
4651 * maximum value discussed in rule C7 above (RTO.max) may be
4652 * used to provide an upper bound to this doubling operation.
4655 /* E3) Determine how many of the earliest (i.e., lowest TSN)
4656 * outstanding DATA chunks for the address for which the
4657 * T3-rtx has expired will fit into a single packet, subject
4658 * to the MTU constraint for the path corresponding to the
4659 * destination transport address to which the retransmission
4660 * is being sent (this may be different from the address for
4661 * which the timer expires [see Section 6.4]). Call this
4662 * value K. Bundle and retransmit those K DATA chunks in a
4663 * single packet to the destination endpoint.
4665 * Note: Any DATA chunks that were sent to the address for
4666 * which the T3-rtx timer expired but did not fit in one MTU
4667 * (rule E3 above), should be marked for retransmission and
4668 * sent as soon as cwnd allows (normally when a SACK arrives).
4671 /* Do some failure management (Section 8.2). */
4672 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
4674 /* NB: Rules E4 and F1 are implicit in R1. */
4675 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
4677 return SCTP_DISPOSITION_CONSUME
;
4681 * Generate delayed SACK on timeout
4683 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
4685 * The guidelines on delayed acknowledgement algorithm specified in
4686 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
4687 * acknowledgement SHOULD be generated for at least every second packet
4688 * (not every second DATA chunk) received, and SHOULD be generated
4689 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
4690 * some situations it may be beneficial for an SCTP transmitter to be
4691 * more conservative than the algorithms detailed in this document
4692 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
4693 * the following algorithms allow.
4695 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
4696 const struct sctp_association
*asoc
,
4697 const sctp_subtype_t type
,
4699 sctp_cmd_seq_t
*commands
)
4701 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS
);
4702 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
4703 return SCTP_DISPOSITION_CONSUME
;
4707 * sctp_sf_t1_init_timer_expire
4709 * Section: 4 Note: 2
4714 * RFC 2960 Section 4 Notes
4715 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
4716 * and re-start the T1-init timer without changing state. This MUST
4717 * be repeated up to 'Max.Init.Retransmits' times. After that, the
4718 * endpoint MUST abort the initialization process and report the
4719 * error to SCTP user.
4725 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
4726 const struct sctp_association
*asoc
,
4727 const sctp_subtype_t type
,
4729 sctp_cmd_seq_t
*commands
)
4731 struct sctp_chunk
*repl
= NULL
;
4732 struct sctp_bind_addr
*bp
;
4733 int attempts
= asoc
->init_err_counter
+ 1;
4735 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
4736 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS
);
4738 if (attempts
<= asoc
->max_init_attempts
) {
4739 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
4740 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
4742 return SCTP_DISPOSITION_NOMEM
;
4744 /* Choose transport for INIT. */
4745 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4748 /* Issue a sideeffect to do the needed accounting. */
4749 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
4750 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4752 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4754 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
4755 " max_init_attempts: %d\n",
4756 attempts
, asoc
->max_init_attempts
);
4757 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4758 SCTP_ERROR(ETIMEDOUT
));
4759 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4760 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4761 return SCTP_DISPOSITION_DELETE_TCB
;
4764 return SCTP_DISPOSITION_CONSUME
;
4768 * sctp_sf_t1_cookie_timer_expire
4770 * Section: 4 Note: 2
4775 * RFC 2960 Section 4 Notes
4776 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
4777 * COOKIE ECHO and re-start the T1-cookie timer without changing
4778 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
4779 * After that, the endpoint MUST abort the initialization process and
4780 * report the error to SCTP user.
4786 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
4787 const struct sctp_association
*asoc
,
4788 const sctp_subtype_t type
,
4790 sctp_cmd_seq_t
*commands
)
4792 struct sctp_chunk
*repl
= NULL
;
4793 int attempts
= asoc
->init_err_counter
+ 1;
4795 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
4796 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS
);
4798 if (attempts
<= asoc
->max_init_attempts
) {
4799 repl
= sctp_make_cookie_echo(asoc
, NULL
);
4801 return SCTP_DISPOSITION_NOMEM
;
4803 /* Issue a sideeffect to do the needed accounting. */
4804 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
4805 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
4807 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4809 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4810 SCTP_ERROR(ETIMEDOUT
));
4811 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4812 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4813 return SCTP_DISPOSITION_DELETE_TCB
;
4816 return SCTP_DISPOSITION_CONSUME
;
4819 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
4820 * with the updated last sequential TSN received from its peer.
4822 * An endpoint should limit the number of retransmissions of the
4823 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
4824 * If this threshold is exceeded the endpoint should destroy the TCB and
4825 * MUST report the peer endpoint unreachable to the upper layer (and
4826 * thus the association enters the CLOSED state). The reception of any
4827 * packet from its peer (i.e. as the peer sends all of its queued DATA
4828 * chunks) should clear the endpoint's retransmission count and restart
4829 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
4830 * all of its queued DATA chunks that have not yet been sent.
4832 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
4833 const struct sctp_association
*asoc
,
4834 const sctp_subtype_t type
,
4836 sctp_cmd_seq_t
*commands
)
4838 struct sctp_chunk
*reply
= NULL
;
4840 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
4841 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
4843 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4844 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4845 SCTP_ERROR(ETIMEDOUT
));
4846 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
4847 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4848 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4849 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4850 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4851 return SCTP_DISPOSITION_DELETE_TCB
;
4854 switch (asoc
->state
) {
4855 case SCTP_STATE_SHUTDOWN_SENT
:
4856 reply
= sctp_make_shutdown(asoc
, NULL
);
4859 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
4860 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
4871 /* Do some failure management (Section 8.2). */
4872 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
4873 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
4875 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
4876 * the T2-shutdown timer.
4878 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4880 /* Restart the T2-shutdown timer. */
4881 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4882 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4883 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4884 return SCTP_DISPOSITION_CONSUME
;
4887 return SCTP_DISPOSITION_NOMEM
;
4891 * ADDIP Section 4.1 ASCONF CHunk Procedures
4892 * If the T4 RTO timer expires the endpoint should do B1 to B5
4894 sctp_disposition_t
sctp_sf_t4_timer_expire(
4895 const struct sctp_endpoint
*ep
,
4896 const struct sctp_association
*asoc
,
4897 const sctp_subtype_t type
,
4899 sctp_cmd_seq_t
*commands
)
4901 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
4902 struct sctp_transport
*transport
= chunk
->transport
;
4904 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS
);
4906 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
4907 * detection on the appropriate destination address as defined in
4908 * RFC2960 [5] section 8.1 and 8.2.
4910 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
4912 /* Reconfig T4 timer and transport. */
4913 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4915 /* ADDIP 4.1 B2) Increment the association error counters and perform
4916 * endpoint failure detection on the association as defined in
4917 * RFC2960 [5] section 8.1 and 8.2.
4918 * association error counter is incremented in SCTP_CMD_STRIKE.
4920 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
4921 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4922 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4923 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4924 SCTP_ERROR(ETIMEDOUT
));
4925 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4926 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4927 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4928 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
4929 return SCTP_DISPOSITION_ABORT
;
4932 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
4933 * the ASCONF chunk was sent by doubling the RTO timer value.
4934 * This is done in SCTP_CMD_STRIKE.
4937 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
4938 * choose an alternate destination address (please refer to RFC2960
4939 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
4940 * chunk, it MUST be the same (including its serial number) as the last
4943 sctp_chunk_hold(asoc
->addip_last_asconf
);
4944 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4945 SCTP_CHUNK(asoc
->addip_last_asconf
));
4947 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
4948 * destination is selected, then the RTO used will be that of the new
4949 * destination address.
4951 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
4952 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4954 return SCTP_DISPOSITION_CONSUME
;
4957 /* sctpimpguide-05 Section 2.12.2
4958 * The sender of the SHUTDOWN MAY also start an overall guard timer
4959 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4960 * At the expiration of this timer the sender SHOULD abort the association
4961 * by sending an ABORT chunk.
4963 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
4964 const struct sctp_association
*asoc
,
4965 const sctp_subtype_t type
,
4967 sctp_cmd_seq_t
*commands
)
4969 struct sctp_chunk
*reply
= NULL
;
4971 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
4972 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
4974 reply
= sctp_make_abort(asoc
, NULL
, 0);
4978 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4979 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4980 SCTP_ERROR(ETIMEDOUT
));
4981 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4982 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
4984 return SCTP_DISPOSITION_DELETE_TCB
;
4986 return SCTP_DISPOSITION_NOMEM
;
4989 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
4990 * the association is automatically closed by starting the shutdown process.
4991 * The work that needs to be done is same as when SHUTDOWN is initiated by
4992 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
4994 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
4995 const struct sctp_endpoint
*ep
,
4996 const struct sctp_association
*asoc
,
4997 const sctp_subtype_t type
,
4999 sctp_cmd_seq_t
*commands
)
5003 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5005 /* From 9.2 Shutdown of an Association
5006 * Upon receipt of the SHUTDOWN primitive from its upper
5007 * layer, the endpoint enters SHUTDOWN-PENDING state and
5008 * remains there until all outstanding data has been
5009 * acknowledged by its peer. The endpoint accepts no new data
5010 * from its upper layer, but retransmits data to the far end
5011 * if necessary to fill gaps.
5013 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5014 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5016 /* sctpimpguide-05 Section 2.12.2
5017 * The sender of the SHUTDOWN MAY also start an overall guard timer
5018 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5020 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5021 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5022 disposition
= SCTP_DISPOSITION_CONSUME
;
5023 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5024 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
5030 /*****************************************************************************
5031 * These are sa state functions which could apply to all types of events.
5032 ****************************************************************************/
5035 * This table entry is not implemented.
5038 * (endpoint, asoc, chunk)
5040 * The return value is the disposition of the chunk.
5042 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
5043 const struct sctp_association
*asoc
,
5044 const sctp_subtype_t type
,
5046 sctp_cmd_seq_t
*commands
)
5048 return SCTP_DISPOSITION_NOT_IMPL
;
5052 * This table entry represents a bug.
5055 * (endpoint, asoc, chunk)
5057 * The return value is the disposition of the chunk.
5059 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
5060 const struct sctp_association
*asoc
,
5061 const sctp_subtype_t type
,
5063 sctp_cmd_seq_t
*commands
)
5065 return SCTP_DISPOSITION_BUG
;
5069 * This table entry represents the firing of a timer in the wrong state.
5070 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5071 * when the association is in the wrong state. This event should
5072 * be ignored, so as to prevent any rearming of the timer.
5075 * (endpoint, asoc, chunk)
5077 * The return value is the disposition of the chunk.
5079 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
5080 const struct sctp_association
*asoc
,
5081 const sctp_subtype_t type
,
5083 sctp_cmd_seq_t
*commands
)
5085 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5086 return SCTP_DISPOSITION_CONSUME
;
5089 /********************************************************************
5090 * 2nd Level Abstractions
5091 ********************************************************************/
5093 /* Pull the SACK chunk based on the SACK header. */
5094 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5096 struct sctp_sackhdr
*sack
;
5101 /* Protect ourselves from reading too far into
5102 * the skb from a bogus sender.
5104 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5106 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5107 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5108 len
= sizeof(struct sctp_sackhdr
);
5109 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5110 if (len
> chunk
->skb
->len
)
5113 skb_pull(chunk
->skb
, len
);
5118 /* Create an ABORT packet to be sent as a response, with the specified
5121 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5122 const struct sctp_association
*asoc
,
5123 struct sctp_chunk
*chunk
,
5124 const void *payload
,
5127 struct sctp_packet
*packet
;
5128 struct sctp_chunk
*abort
;
5130 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5134 * The T bit will be set if the asoc is NULL.
5136 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5138 sctp_ootb_pkt_free(packet
);
5142 /* Reflect vtag if T-Bit is set */
5143 if (sctp_test_T_bit(abort
))
5144 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5146 /* Add specified error causes, i.e., payload, to the
5149 sctp_addto_chunk(abort
, paylen
, payload
);
5151 /* Set the skb to the belonging sock for accounting. */
5152 abort
->skb
->sk
= ep
->base
.sk
;
5154 sctp_packet_append_chunk(packet
, abort
);
5161 /* Allocate a packet for responding in the OOTB conditions. */
5162 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
5163 const struct sctp_chunk
*chunk
)
5165 struct sctp_packet
*packet
;
5166 struct sctp_transport
*transport
;
5171 /* Get the source and destination port from the inbound packet. */
5172 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5173 dport
= ntohs(chunk
->sctp_hdr
->source
);
5175 /* The V-tag is going to be the same as the inbound packet if no
5176 * association exists, otherwise, use the peer's vtag.
5179 vtag
= asoc
->peer
.i
.init_tag
;
5181 /* Special case the INIT and stale COOKIE_ECHO as there is no
5184 switch(chunk
->chunk_hdr
->type
) {
5187 sctp_init_chunk_t
*init
;
5189 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5190 vtag
= ntohl(init
->init_hdr
.init_tag
);
5194 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5199 /* Make a transport for the bucket, Eliza... */
5200 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5204 /* Cache a route for the transport with the chunk's destination as
5205 * the source address.
5207 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5208 sctp_sk(sctp_get_ctl_sock()));
5210 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5211 packet
= sctp_packet_config(packet
, vtag
, 0);
5219 /* Free the packet allocated earlier for responding in the OOTB condition. */
5220 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5222 sctp_transport_free(packet
->transport
);
5225 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5226 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5227 const struct sctp_association
*asoc
,
5228 const struct sctp_chunk
*chunk
,
5229 sctp_cmd_seq_t
*commands
,
5230 struct sctp_chunk
*err_chunk
)
5232 struct sctp_packet
*packet
;
5235 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5237 struct sctp_signed_cookie
*cookie
;
5239 /* Override the OOTB vtag from the cookie. */
5240 cookie
= chunk
->subh
.cookie_hdr
;
5241 packet
->vtag
= cookie
->c
.peer_vtag
;
5243 /* Set the skb to the belonging sock for accounting. */
5244 err_chunk
->skb
->sk
= ep
->base
.sk
;
5245 sctp_packet_append_chunk(packet
, err_chunk
);
5246 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
5247 SCTP_PACKET(packet
));
5248 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
5250 sctp_chunk_free (err_chunk
);
5255 /* Process a data chunk */
5256 static int sctp_eat_data(const struct sctp_association
*asoc
,
5257 struct sctp_chunk
*chunk
,
5258 sctp_cmd_seq_t
*commands
)
5260 sctp_datahdr_t
*data_hdr
;
5261 struct sctp_chunk
*err
;
5263 sctp_verb_t deliver
;
5267 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
5268 struct sock
*sk
= asoc
->base
.sk
;
5269 int rcvbuf_over
= 0;
5271 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
5272 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
5274 tsn
= ntohl(data_hdr
->tsn
);
5275 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
5277 /* ASSERT: Now skb->data is really the user data. */
5280 * If we are established, and we have used up our receive buffer
5281 * memory, think about droping the frame.
5282 * Note that we have an opportunity to improve performance here.
5283 * If we accept one chunk from an skbuff, we have to keep all the
5284 * memory of that skbuff around until the chunk is read into user
5285 * space. Therefore, once we accept 1 chunk we may as well accept all
5286 * remaining chunks in the skbuff. The data_accepted flag helps us do
5289 if ((asoc
->state
== SCTP_STATE_ESTABLISHED
) && (!chunk
->data_accepted
)) {
5291 * If the receive buffer policy is 1, then each
5292 * association can allocate up to sk_rcvbuf bytes
5293 * otherwise, all the associations in aggregate
5294 * may allocate up to sk_rcvbuf bytes
5296 if (asoc
->ep
->rcvbuf_policy
)
5297 account_value
= atomic_read(&asoc
->rmem_alloc
);
5299 account_value
= atomic_read(&sk
->sk_rmem_alloc
);
5300 if (account_value
> sk
->sk_rcvbuf
) {
5302 * We need to make forward progress, even when we are
5303 * under memory pressure, so we always allow the
5304 * next tsn after the ctsn ack point to be accepted.
5305 * This lets us avoid deadlocks in which we have to
5306 * drop frames that would otherwise let us drain the
5309 if ((sctp_tsnmap_get_ctsn(map
) + 1) != tsn
)
5310 return SCTP_IERROR_IGNORE_TSN
;
5313 * We're going to accept the frame but we should renege
5314 * to make space for it. This will send us down that
5315 * path later in this function.
5321 /* Process ECN based congestion.
5323 * Since the chunk structure is reused for all chunks within
5324 * a packet, we use ecn_ce_done to track if we've already
5325 * done CE processing for this packet.
5327 * We need to do ECN processing even if we plan to discard the
5331 if (!chunk
->ecn_ce_done
) {
5333 chunk
->ecn_ce_done
= 1;
5335 af
= sctp_get_af_specific(
5336 ipver2af(ip_hdr(chunk
->skb
)->version
));
5338 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
5339 /* Do real work as sideffect. */
5340 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
5345 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
5347 /* The TSN is too high--silently discard the chunk and
5348 * count on it getting retransmitted later.
5350 return SCTP_IERROR_HIGH_TSN
;
5351 } else if (tmp
> 0) {
5352 /* This is a duplicate. Record it. */
5353 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
5354 return SCTP_IERROR_DUP_TSN
;
5357 /* This is a new TSN. */
5359 /* Discard if there is no room in the receive window.
5360 * Actually, allow a little bit of overflow (up to a MTU).
5362 datalen
= ntohs(chunk
->chunk_hdr
->length
);
5363 datalen
-= sizeof(sctp_data_chunk_t
);
5365 deliver
= SCTP_CMD_CHUNK_ULP
;
5367 /* Think about partial delivery. */
5368 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
5370 /* Even if we don't accept this chunk there is
5373 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
5376 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5377 * seems a bit troublesome in that frag_point varies based on
5378 * PMTU. In cases, such as loopback, this might be a rather
5380 * NOTE: If we have a full receive buffer here, we only renege if
5381 * our receiver can still make progress without the tsn being
5382 * received. We do this because in the event that the associations
5383 * receive queue is empty we are filling a leading gap, and since
5384 * reneging moves the gap to the end of the tsn stream, we are likely
5385 * to stall again very shortly. Avoiding the renege when we fill a
5386 * leading gap is a good heuristic for avoiding such steady state
5389 if (!asoc
->rwnd
|| asoc
->rwnd_over
||
5390 (datalen
> asoc
->rwnd
+ asoc
->frag_point
) ||
5391 (rcvbuf_over
&& (!skb_queue_len(&sk
->sk_receive_queue
)))) {
5393 /* If this is the next TSN, consider reneging to make
5394 * room. Note: Playing nice with a confused sender. A
5395 * malicious sender can still eat up all our buffer
5396 * space and in the future we may want to detect and
5397 * do more drastic reneging.
5399 if (sctp_tsnmap_has_gap(map
) &&
5400 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5401 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
5402 deliver
= SCTP_CMD_RENEGE
;
5404 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5405 "rwnd: %d\n", tsn
, datalen
,
5407 return SCTP_IERROR_IGNORE_TSN
;
5412 * Section 3.3.10.9 No User Data (9)
5416 * No User Data: This error cause is returned to the originator of a
5417 * DATA chunk if a received DATA chunk has no user data.
5419 if (unlikely(0 == datalen
)) {
5420 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
5422 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5425 /* We are going to ABORT, so we might as well stop
5426 * processing the rest of the chunks in the packet.
5428 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
5429 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5430 SCTP_ERROR(ECONNABORTED
));
5431 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5432 SCTP_PERR(SCTP_ERROR_NO_DATA
));
5433 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5434 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5435 return SCTP_IERROR_NO_DATA
;
5438 /* If definately accepting the DATA chunk, record its TSN, otherwise
5439 * wait for renege processing.
5441 if (SCTP_CMD_CHUNK_ULP
== deliver
)
5442 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
5444 chunk
->data_accepted
= 1;
5446 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5447 * if we renege and the chunk arrives again.
5449 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
5450 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS
);
5452 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS
);
5454 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5456 * If an endpoint receive a DATA chunk with an invalid stream
5457 * identifier, it shall acknowledge the reception of the DATA chunk
5458 * following the normal procedure, immediately send an ERROR chunk
5459 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5460 * and discard the DATA chunk.
5462 if (ntohs(data_hdr
->stream
) >= asoc
->c
.sinit_max_instreams
) {
5463 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
5465 sizeof(data_hdr
->stream
));
5467 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5469 return SCTP_IERROR_BAD_STREAM
;
5472 /* Send the data up to the user. Note: Schedule the
5473 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5474 * chunk needs the updated rwnd.
5476 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
5478 return SCTP_IERROR_NO_ERROR
;