1 /* SCTP kernel 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 is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Mathew Kotowsky <kotowsky@sctp.org>
40 * Sridhar Samudrala <samudrala@us.ibm.com>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Hui Huang <hui.huang@nokia.com>
43 * Dajiang Zhang <dajiang.zhang@nokia.com>
44 * Daisy Chang <daisyc@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Kevin Gao <kevin.gao@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #include <linux/types.h>
54 #include <linux/kernel.h>
56 #include <linux/ipv6.h>
57 #include <linux/net.h>
58 #include <linux/inet.h>
60 #include <net/inet_ecn.h>
61 #include <linux/skbuff.h>
62 #include <net/sctp/sctp.h>
63 #include <net/sctp/sm.h>
64 #include <net/sctp/structs.h>
66 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
67 const struct sctp_association
*asoc
,
68 struct sctp_chunk
*chunk
,
71 static int sctp_eat_data(const struct sctp_association
*asoc
,
72 struct sctp_chunk
*chunk
,
73 sctp_cmd_seq_t
*commands
);
74 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
75 const struct sctp_chunk
*chunk
);
76 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
77 const struct sctp_association
*asoc
,
78 const struct sctp_chunk
*chunk
,
79 sctp_cmd_seq_t
*commands
,
80 struct sctp_chunk
*err_chunk
);
81 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
82 const struct sctp_association
*asoc
,
83 const sctp_subtype_t type
,
85 sctp_cmd_seq_t
*commands
);
86 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
87 const struct sctp_association
*asoc
,
88 const sctp_subtype_t type
,
90 sctp_cmd_seq_t
*commands
);
91 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
92 const struct sctp_association
*asoc
,
93 const sctp_subtype_t type
,
95 sctp_cmd_seq_t
*commands
);
96 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
98 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
99 __be16 error
, int sk_err
,
100 const struct sctp_association
*asoc
,
101 struct sctp_transport
*transport
);
103 static sctp_disposition_t
sctp_sf_abort_violation(
104 const struct sctp_endpoint
*ep
,
105 const struct sctp_association
*asoc
,
107 sctp_cmd_seq_t
*commands
,
109 const size_t paylen
);
111 static sctp_disposition_t
sctp_sf_violation_chunklen(
112 const struct sctp_endpoint
*ep
,
113 const struct sctp_association
*asoc
,
114 const sctp_subtype_t type
,
116 sctp_cmd_seq_t
*commands
);
118 static sctp_disposition_t
sctp_sf_violation_paramlen(
119 const struct sctp_endpoint
*ep
,
120 const struct sctp_association
*asoc
,
121 const sctp_subtype_t type
,
122 void *arg
, void *ext
,
123 sctp_cmd_seq_t
*commands
);
125 static sctp_disposition_t
sctp_sf_violation_ctsn(
126 const struct sctp_endpoint
*ep
,
127 const struct sctp_association
*asoc
,
128 const sctp_subtype_t type
,
130 sctp_cmd_seq_t
*commands
);
132 static sctp_disposition_t
sctp_sf_violation_chunk(
133 const struct sctp_endpoint
*ep
,
134 const struct sctp_association
*asoc
,
135 const sctp_subtype_t type
,
137 sctp_cmd_seq_t
*commands
);
139 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
140 const struct sctp_association
*asoc
,
141 const sctp_subtype_t type
,
142 struct sctp_chunk
*chunk
);
144 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
145 const struct sctp_association
*asoc
,
146 const sctp_subtype_t type
,
148 sctp_cmd_seq_t
*commands
);
150 /* Small helper function that checks if the chunk length
151 * is of the appropriate length. The 'required_length' argument
152 * is set to be the size of a specific chunk we are testing.
153 * Return Values: 1 = Valid length
158 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
159 __u16 required_length
)
161 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
163 if (unlikely(chunk_length
< required_length
))
169 /**********************************************************
170 * These are the state functions for handling chunk events.
171 **********************************************************/
174 * Process the final SHUTDOWN COMPLETE.
176 * Section: 4 (C) (diagram), 9.2
177 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
178 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
179 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
180 * should stop the T2-shutdown timer and remove all knowledge of the
181 * association (and thus the association enters the CLOSED state).
183 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
184 * C) Rules for packet carrying SHUTDOWN COMPLETE:
186 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
187 * if the Verification Tag field of the packet matches its own tag and
188 * the T bit is not set
190 * it is set to its peer's tag and the T bit is set in the Chunk
192 * Otherwise, the receiver MUST silently discard the packet
193 * and take no further action. An endpoint MUST ignore the
194 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
197 * (endpoint, asoc, chunk)
200 * (asoc, reply_msg, msg_up, timers, counters)
202 * The return value is the disposition of the chunk.
204 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
205 const struct sctp_association
*asoc
,
206 const sctp_subtype_t type
,
208 sctp_cmd_seq_t
*commands
)
210 struct sctp_chunk
*chunk
= arg
;
211 struct sctp_ulpevent
*ev
;
213 if (!sctp_vtag_verify_either(chunk
, asoc
))
214 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
216 /* RFC 2960 6.10 Bundling
218 * An endpoint MUST NOT bundle INIT, INIT ACK or
219 * SHUTDOWN COMPLETE with any other chunks.
221 if (!chunk
->singleton
)
222 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
224 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
225 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
226 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
229 /* RFC 2960 10.2 SCTP-to-ULP
231 * H) SHUTDOWN COMPLETE notification
233 * When SCTP completes the shutdown procedures (section 9.2) this
234 * notification is passed to the upper layer.
236 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
237 0, 0, 0, NULL
, GFP_ATOMIC
);
239 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
242 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
243 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
244 * not the chunk should be discarded. If the endpoint is in
245 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
246 * T2-shutdown timer and remove all knowledge of the
247 * association (and thus the association enters the CLOSED
250 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
251 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
253 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
254 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
256 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
257 SCTP_STATE(SCTP_STATE_CLOSED
));
259 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
260 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
262 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
264 return SCTP_DISPOSITION_DELETE_TCB
;
268 * Respond to a normal INIT chunk.
269 * We are the side that is being asked for an association.
271 * Section: 5.1 Normal Establishment of an Association, B
272 * B) "Z" shall respond immediately with an INIT ACK chunk. The
273 * destination IP address of the INIT ACK MUST be set to the source
274 * IP address of the INIT to which this INIT ACK is responding. In
275 * the response, besides filling in other parameters, "Z" must set the
276 * Verification Tag field to Tag_A, and also provide its own
277 * Verification Tag (Tag_Z) in the Initiate Tag field.
279 * Verification Tag: Must be 0.
282 * (endpoint, asoc, chunk)
285 * (asoc, reply_msg, msg_up, timers, counters)
287 * The return value is the disposition of the chunk.
289 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
290 const struct sctp_association
*asoc
,
291 const sctp_subtype_t type
,
293 sctp_cmd_seq_t
*commands
)
295 struct sctp_chunk
*chunk
= arg
;
296 struct sctp_chunk
*repl
;
297 struct sctp_association
*new_asoc
;
298 struct sctp_chunk
*err_chunk
;
299 struct sctp_packet
*packet
;
300 sctp_unrecognized_param_t
*unk_param
;
304 * An endpoint MUST NOT bundle INIT, INIT ACK or
305 * SHUTDOWN COMPLETE with any other chunks.
308 * Furthermore, we require that the receiver of an INIT chunk MUST
309 * enforce these rules by silently discarding an arriving packet
310 * with an INIT chunk that is bundled with other chunks.
312 if (!chunk
->singleton
)
313 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
315 /* If the packet is an OOTB packet which is temporarily on the
316 * control endpoint, respond with an ABORT.
318 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
) {
319 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
320 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
323 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
326 if (chunk
->sctp_hdr
->vtag
!= 0)
327 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
329 /* Make sure that the INIT chunk has a valid length.
330 * Normally, this would cause an ABORT with a Protocol Violation
331 * error, but since we don't have an association, we'll
332 * just discard the packet.
334 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
335 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
337 /* Verify the INIT chunk before processing it. */
339 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
340 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
342 /* This chunk contains fatal error. It is to be discarded.
343 * Send an ABORT, with causes if there is any.
346 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
347 (__u8
*)(err_chunk
->chunk_hdr
) +
348 sizeof(sctp_chunkhdr_t
),
349 ntohs(err_chunk
->chunk_hdr
->length
) -
350 sizeof(sctp_chunkhdr_t
));
352 sctp_chunk_free(err_chunk
);
355 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
356 SCTP_PACKET(packet
));
357 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
358 return SCTP_DISPOSITION_CONSUME
;
360 return SCTP_DISPOSITION_NOMEM
;
363 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
368 /* Grab the INIT header. */
369 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
371 /* Tag the variable length parameters. */
372 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
374 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
378 /* The call, sctp_process_init(), can fail on memory allocation. */
379 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
381 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
385 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
387 /* If there are errors need to be reported for unknown parameters,
388 * make sure to reserve enough room in the INIT ACK for them.
392 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
393 sizeof(sctp_chunkhdr_t
);
395 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
398 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
402 /* If there are errors need to be reported for unknown parameters,
403 * include them in the outgoing INIT ACK as "Unrecognized parameter"
407 /* Get the "Unrecognized parameter" parameter(s) out of the
408 * ERROR chunk generated by sctp_verify_init(). Since the
409 * error cause code for "unknown parameter" and the
410 * "Unrecognized parameter" type is the same, we can
411 * construct the parameters in INIT ACK by copying the
414 unk_param
= (sctp_unrecognized_param_t
*)
415 ((__u8
*)(err_chunk
->chunk_hdr
) +
416 sizeof(sctp_chunkhdr_t
));
417 /* Replace the cause code with the "Unrecognized parameter"
420 sctp_addto_chunk(repl
, len
, unk_param
);
421 sctp_chunk_free(err_chunk
);
424 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
426 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
429 * Note: After sending out INIT ACK with the State Cookie parameter,
430 * "Z" MUST NOT allocate any resources, nor keep any states for the
431 * new association. Otherwise, "Z" will be vulnerable to resource
434 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
436 return SCTP_DISPOSITION_DELETE_TCB
;
439 sctp_association_free(new_asoc
);
442 sctp_chunk_free(err_chunk
);
443 return SCTP_DISPOSITION_NOMEM
;
447 * Respond to a normal INIT ACK chunk.
448 * We are the side that is initiating the association.
450 * Section: 5.1 Normal Establishment of an Association, C
451 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
452 * timer and leave COOKIE-WAIT state. "A" shall then send the State
453 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
454 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
456 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
457 * DATA chunks, but it MUST be the first chunk in the packet and
458 * until the COOKIE ACK is returned the sender MUST NOT send any
459 * other packets to the peer.
461 * Verification Tag: 3.3.3
462 * If the value of the Initiate Tag in a received INIT ACK chunk is
463 * found to be 0, the receiver MUST treat it as an error and close the
464 * association by transmitting an ABORT.
467 * (endpoint, asoc, chunk)
470 * (asoc, reply_msg, msg_up, timers, counters)
472 * The return value is the disposition of the chunk.
474 sctp_disposition_t
sctp_sf_do_5_1C_ack(const struct sctp_endpoint
*ep
,
475 const struct sctp_association
*asoc
,
476 const sctp_subtype_t type
,
478 sctp_cmd_seq_t
*commands
)
480 struct sctp_chunk
*chunk
= arg
;
481 sctp_init_chunk_t
*initchunk
;
482 struct sctp_chunk
*err_chunk
;
483 struct sctp_packet
*packet
;
485 if (!sctp_vtag_verify(chunk
, asoc
))
486 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
489 * An endpoint MUST NOT bundle INIT, INIT ACK or
490 * SHUTDOWN COMPLETE with any other chunks.
492 if (!chunk
->singleton
)
493 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
495 /* Make sure that the INIT-ACK chunk has a valid length */
496 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
497 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
499 /* Grab the INIT header. */
500 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
502 /* Verify the INIT chunk before processing it. */
504 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
505 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
508 sctp_error_t error
= SCTP_ERROR_NO_RESOURCE
;
510 /* This chunk contains fatal error. It is to be discarded.
511 * Send an ABORT, with causes. If there are no causes,
512 * then there wasn't enough memory. Just terminate
516 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
517 (__u8
*)(err_chunk
->chunk_hdr
) +
518 sizeof(sctp_chunkhdr_t
),
519 ntohs(err_chunk
->chunk_hdr
->length
) -
520 sizeof(sctp_chunkhdr_t
));
522 sctp_chunk_free(err_chunk
);
525 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
526 SCTP_PACKET(packet
));
527 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
528 error
= SCTP_ERROR_INV_PARAM
;
532 /* SCTP-AUTH, Section 6.3:
533 * It should be noted that if the receiver wants to tear
534 * down an association in an authenticated way only, the
535 * handling of malformed packets should not result in
536 * tearing down the association.
538 * This means that if we only want to abort associations
539 * in an authenticated way (i.e AUTH+ABORT), then we
540 * can't destroy this association just becuase the packet
543 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
544 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
546 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
547 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
,
548 asoc
, chunk
->transport
);
551 /* Tag the variable length parameters. Note that we never
552 * convert the parameters in an INIT chunk.
554 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
556 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
558 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
559 SCTP_PEER_INIT(initchunk
));
561 /* Reset init error count upon receipt of INIT-ACK. */
562 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
564 /* 5.1 C) "A" shall stop the T1-init timer and leave
565 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
566 * timer, and enter the COOKIE-ECHOED state.
568 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
569 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
570 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
571 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
572 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
573 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
575 /* SCTP-AUTH: genereate the assocition shared keys so that
576 * we can potentially signe the COOKIE-ECHO.
578 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
580 /* 5.1 C) "A" shall then send the State Cookie received in the
581 * INIT ACK chunk in a COOKIE ECHO chunk, ...
583 /* If there is any errors to report, send the ERROR chunk generated
584 * for unknown parameters as well.
586 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
587 SCTP_CHUNK(err_chunk
));
589 return SCTP_DISPOSITION_CONSUME
;
593 * Respond to a normal COOKIE ECHO chunk.
594 * We are the side that is being asked for an association.
596 * Section: 5.1 Normal Establishment of an Association, D
597 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
598 * with a COOKIE ACK chunk after building a TCB and moving to
599 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
600 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
601 * chunk MUST be the first chunk in the packet.
603 * IMPLEMENTATION NOTE: An implementation may choose to send the
604 * Communication Up notification to the SCTP user upon reception
605 * of a valid COOKIE ECHO chunk.
607 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
608 * D) Rules for packet carrying a COOKIE ECHO
610 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
611 * Initial Tag received in the INIT ACK.
613 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
616 * (endpoint, asoc, chunk)
619 * (asoc, reply_msg, msg_up, timers, counters)
621 * The return value is the disposition of the chunk.
623 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
624 const struct sctp_association
*asoc
,
625 const sctp_subtype_t type
, void *arg
,
626 sctp_cmd_seq_t
*commands
)
628 struct sctp_chunk
*chunk
= arg
;
629 struct sctp_association
*new_asoc
;
630 sctp_init_chunk_t
*peer_init
;
631 struct sctp_chunk
*repl
;
632 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
634 struct sctp_chunk
*err_chk_p
;
637 /* If the packet is an OOTB packet which is temporarily on the
638 * control endpoint, respond with an ABORT.
640 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
) {
641 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
642 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
645 /* Make sure that the COOKIE_ECHO chunk has a valid length.
646 * In this case, we check that we have enough for at least a
647 * chunk header. More detailed verification is done
648 * in sctp_unpack_cookie().
650 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
651 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
653 /* If the endpoint is not listening or if the number of associations
654 * on the TCP-style socket exceed the max backlog, respond with an
658 if (!sctp_sstate(sk
, LISTENING
) ||
659 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
660 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
662 /* "Decode" the chunk. We have no optional parameters so we
665 chunk
->subh
.cookie_hdr
=
666 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
667 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
668 sizeof(sctp_chunkhdr_t
)))
671 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
672 * "Z" will reply with a COOKIE ACK chunk after building a TCB
673 * and moving to the ESTABLISHED state.
675 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
679 * If the re-build failed, what is the proper error path
682 * [We should abort the association. --piggy]
685 /* FIXME: Several errors are possible. A bad cookie should
686 * be silently discarded, but think about logging it too.
689 case -SCTP_IERROR_NOMEM
:
692 case -SCTP_IERROR_STALE_COOKIE
:
693 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
695 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
697 case -SCTP_IERROR_BAD_SIG
:
699 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
704 /* Delay state machine commands until later.
706 * Re-build the bind address for the association is done in
707 * the sctp_unpack_cookie() already.
709 /* This is a brand-new association, so these are not yet side
710 * effects--it is safe to run them here.
712 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
714 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
715 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
716 peer_init
, GFP_ATOMIC
))
719 /* SCTP-AUTH: Now that we've populate required fields in
720 * sctp_process_init, set up the assocaition shared keys as
721 * necessary so that we can potentially authenticate the ACK
723 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
727 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
728 * is supposed to be authenticated and we have to do delayed
729 * authentication. We've just recreated the association using
730 * the information in the cookie and now it's much easier to
731 * do the authentication.
733 if (chunk
->auth_chunk
) {
734 struct sctp_chunk auth
;
737 /* set-up our fake chunk so that we can process it */
738 auth
.skb
= chunk
->auth_chunk
;
739 auth
.asoc
= chunk
->asoc
;
740 auth
.sctp_hdr
= chunk
->sctp_hdr
;
741 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
742 sizeof(sctp_chunkhdr_t
));
743 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
744 auth
.transport
= chunk
->transport
;
746 ret
= sctp_sf_authenticate(ep
, new_asoc
, type
, &auth
);
748 /* We can now safely free the auth_chunk clone */
749 kfree_skb(chunk
->auth_chunk
);
751 if (ret
!= SCTP_IERROR_NO_ERROR
) {
752 sctp_association_free(new_asoc
);
753 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
757 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
761 /* RFC 2960 5.1 Normal Establishment of an Association
763 * D) IMPLEMENTATION NOTE: An implementation may choose to
764 * send the Communication Up notification to the SCTP user
765 * upon reception of a valid COOKIE ECHO chunk.
767 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
768 new_asoc
->c
.sinit_num_ostreams
,
769 new_asoc
->c
.sinit_max_instreams
,
774 /* Sockets API Draft Section 5.3.1.6
775 * When a peer sends a Adaptation Layer Indication parameter , SCTP
776 * delivers this notification to inform the application that of the
777 * peers requested adaptation layer.
779 if (new_asoc
->peer
.adaptation_ind
) {
780 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
786 /* Add all the state machine commands now since we've created
787 * everything. This way we don't introduce memory corruptions
788 * during side-effect processing and correclty count established
791 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
792 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
793 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
794 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
795 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS
);
796 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
798 if (new_asoc
->autoclose
)
799 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
800 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
802 /* This will send the COOKIE ACK */
803 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
805 /* Queue the ASSOC_CHANGE event */
806 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
808 /* Send up the Adaptation Layer Indication event */
810 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
811 SCTP_ULPEVENT(ai_ev
));
813 return SCTP_DISPOSITION_CONSUME
;
816 sctp_ulpevent_free(ev
);
818 sctp_chunk_free(repl
);
820 sctp_association_free(new_asoc
);
822 return SCTP_DISPOSITION_NOMEM
;
826 * Respond to a normal COOKIE ACK chunk.
827 * We are the side that is being asked for an association.
829 * RFC 2960 5.1 Normal Establishment of an Association
831 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
832 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
833 * timer. It may also notify its ULP about the successful
834 * establishment of the association with a Communication Up
835 * notification (see Section 10).
839 * (endpoint, asoc, chunk)
842 * (asoc, reply_msg, msg_up, timers, counters)
844 * The return value is the disposition of the chunk.
846 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
847 const struct sctp_association
*asoc
,
848 const sctp_subtype_t type
, void *arg
,
849 sctp_cmd_seq_t
*commands
)
851 struct sctp_chunk
*chunk
= arg
;
852 struct sctp_ulpevent
*ev
;
854 if (!sctp_vtag_verify(chunk
, asoc
))
855 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
857 /* Verify that the chunk length for the COOKIE-ACK is OK.
858 * If we don't do this, any bundled chunks may be junked.
860 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
861 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
864 /* Reset init error count upon receipt of COOKIE-ACK,
865 * to avoid problems with the managemement of this
866 * counter in stale cookie situations when a transition back
867 * from the COOKIE-ECHOED state to the COOKIE-WAIT
868 * state is performed.
870 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
872 /* RFC 2960 5.1 Normal Establishment of an Association
874 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
875 * from the COOKIE-ECHOED state to the ESTABLISHED state,
876 * stopping the T1-cookie timer.
878 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
879 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
880 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
881 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
882 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
883 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS
);
884 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
886 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
887 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
889 /* It may also notify its ULP about the successful
890 * establishment of the association with a Communication Up
891 * notification (see Section 10).
893 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
894 0, asoc
->c
.sinit_num_ostreams
,
895 asoc
->c
.sinit_max_instreams
,
901 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
903 /* Sockets API Draft Section 5.3.1.6
904 * When a peer sends a Adaptation Layer Indication parameter , SCTP
905 * delivers this notification to inform the application that of the
906 * peers requested adaptation layer.
908 if (asoc
->peer
.adaptation_ind
) {
909 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
913 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
917 return SCTP_DISPOSITION_CONSUME
;
919 return SCTP_DISPOSITION_NOMEM
;
922 /* Generate and sendout a heartbeat packet. */
923 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
924 const struct sctp_association
*asoc
,
925 const sctp_subtype_t type
,
927 sctp_cmd_seq_t
*commands
)
929 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
930 struct sctp_chunk
*reply
;
931 sctp_sender_hb_info_t hbinfo
;
934 hbinfo
.param_hdr
.type
= SCTP_PARAM_HEARTBEAT_INFO
;
935 hbinfo
.param_hdr
.length
= htons(sizeof(sctp_sender_hb_info_t
));
936 hbinfo
.daddr
= transport
->ipaddr
;
937 hbinfo
.sent_at
= jiffies
;
938 hbinfo
.hb_nonce
= transport
->hb_nonce
;
940 /* Send a heartbeat to our peer. */
941 paylen
= sizeof(sctp_sender_hb_info_t
);
942 reply
= sctp_make_heartbeat(asoc
, transport
, &hbinfo
, paylen
);
944 return SCTP_DISPOSITION_NOMEM
;
946 /* Set rto_pending indicating that an RTT measurement
947 * is started with this heartbeat chunk.
949 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
950 SCTP_TRANSPORT(transport
));
952 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
953 return SCTP_DISPOSITION_CONSUME
;
956 /* Generate a HEARTBEAT packet on the given transport. */
957 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
958 const struct sctp_association
*asoc
,
959 const sctp_subtype_t type
,
961 sctp_cmd_seq_t
*commands
)
963 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
965 if (asoc
->overall_error_count
> asoc
->max_retrans
) {
966 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
967 SCTP_ERROR(ETIMEDOUT
));
968 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
969 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
970 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
971 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
972 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
973 return SCTP_DISPOSITION_DELETE_TCB
;
977 * The Sender-specific Heartbeat Info field should normally include
978 * information about the sender's current time when this HEARTBEAT
979 * chunk is sent and the destination transport address to which this
980 * HEARTBEAT is sent (see Section 8.3).
983 if (transport
->param_flags
& SPP_HB_ENABLE
) {
984 if (SCTP_DISPOSITION_NOMEM
==
985 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
987 return SCTP_DISPOSITION_NOMEM
;
988 /* Set transport error counter and association error counter
989 * when sending heartbeat.
991 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
992 SCTP_TRANSPORT(transport
));
993 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
994 SCTP_TRANSPORT(transport
));
996 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
997 SCTP_TRANSPORT(transport
));
999 return SCTP_DISPOSITION_CONSUME
;
1003 * Process an heartbeat request.
1005 * Section: 8.3 Path Heartbeat
1006 * The receiver of the HEARTBEAT should immediately respond with a
1007 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1008 * from the received HEARTBEAT chunk.
1010 * Verification Tag: 8.5 Verification Tag [Normal verification]
1011 * When receiving an SCTP packet, the endpoint MUST ensure that the
1012 * value in the Verification Tag field of the received SCTP packet
1013 * matches its own Tag. If the received Verification Tag value does not
1014 * match the receiver's own tag value, the receiver shall silently
1015 * discard the packet and shall not process it any further except for
1016 * those cases listed in Section 8.5.1 below.
1019 * (endpoint, asoc, chunk)
1022 * (asoc, reply_msg, msg_up, timers, counters)
1024 * The return value is the disposition of the chunk.
1026 sctp_disposition_t
sctp_sf_beat_8_3(const struct sctp_endpoint
*ep
,
1027 const struct sctp_association
*asoc
,
1028 const sctp_subtype_t type
,
1030 sctp_cmd_seq_t
*commands
)
1032 struct sctp_chunk
*chunk
= arg
;
1033 struct sctp_chunk
*reply
;
1036 if (!sctp_vtag_verify(chunk
, asoc
))
1037 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1039 /* Make sure that the HEARTBEAT chunk has a valid length. */
1040 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1041 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1044 /* 8.3 The receiver of the HEARTBEAT should immediately
1045 * respond with a HEARTBEAT ACK that contains the Heartbeat
1046 * Information field copied from the received HEARTBEAT chunk.
1048 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
1049 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1050 if (!pskb_pull(chunk
->skb
, paylen
))
1053 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
1054 chunk
->subh
.hb_hdr
, paylen
);
1058 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1059 return SCTP_DISPOSITION_CONSUME
;
1062 return SCTP_DISPOSITION_NOMEM
;
1066 * Process the returning HEARTBEAT ACK.
1068 * Section: 8.3 Path Heartbeat
1069 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1070 * should clear the error counter of the destination transport
1071 * address to which the HEARTBEAT was sent, and mark the destination
1072 * transport address as active if it is not so marked. The endpoint may
1073 * optionally report to the upper layer when an inactive destination
1074 * address is marked as active due to the reception of the latest
1075 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1076 * clear the association overall error count as well (as defined
1079 * The receiver of the HEARTBEAT ACK should also perform an RTT
1080 * measurement for that destination transport address using the time
1081 * value carried in the HEARTBEAT ACK chunk.
1083 * Verification Tag: 8.5 Verification Tag [Normal verification]
1086 * (endpoint, asoc, chunk)
1089 * (asoc, reply_msg, msg_up, timers, counters)
1091 * The return value is the disposition of the chunk.
1093 sctp_disposition_t
sctp_sf_backbeat_8_3(const struct sctp_endpoint
*ep
,
1094 const struct sctp_association
*asoc
,
1095 const sctp_subtype_t type
,
1097 sctp_cmd_seq_t
*commands
)
1099 struct sctp_chunk
*chunk
= arg
;
1100 union sctp_addr from_addr
;
1101 struct sctp_transport
*link
;
1102 sctp_sender_hb_info_t
*hbinfo
;
1103 unsigned long max_interval
;
1105 if (!sctp_vtag_verify(chunk
, asoc
))
1106 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1108 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1109 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1110 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1113 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1114 /* Make sure that the length of the parameter is what we expect */
1115 if (ntohs(hbinfo
->param_hdr
.length
) !=
1116 sizeof(sctp_sender_hb_info_t
)) {
1117 return SCTP_DISPOSITION_DISCARD
;
1120 from_addr
= hbinfo
->daddr
;
1121 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1123 /* This should never happen, but lets log it if so. */
1124 if (unlikely(!link
)) {
1125 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1126 if (net_ratelimit())
1128 "%s association %p could not find address %pI6\n",
1131 &from_addr
.v6
.sin6_addr
);
1133 if (net_ratelimit())
1135 "%s association %p could not find address %pI4\n",
1138 &from_addr
.v4
.sin_addr
.s_addr
);
1140 return SCTP_DISPOSITION_DISCARD
;
1143 /* Validate the 64-bit random nonce. */
1144 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1145 return SCTP_DISPOSITION_DISCARD
;
1147 max_interval
= link
->hbinterval
+ link
->rto
;
1149 /* Check if the timestamp looks valid. */
1150 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1151 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1152 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1153 "received for transport: %p\n",
1155 return SCTP_DISPOSITION_DISCARD
;
1158 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1159 * the HEARTBEAT should clear the error counter of the
1160 * destination transport address to which the HEARTBEAT was
1161 * sent and mark the destination transport address as active if
1162 * it is not so marked.
1164 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1166 return SCTP_DISPOSITION_CONSUME
;
1169 /* Helper function to send out an abort for the restart
1172 static int sctp_sf_send_restart_abort(union sctp_addr
*ssa
,
1173 struct sctp_chunk
*init
,
1174 sctp_cmd_seq_t
*commands
)
1177 struct sctp_packet
*pkt
;
1178 union sctp_addr_param
*addrparm
;
1179 struct sctp_errhdr
*errhdr
;
1180 struct sctp_endpoint
*ep
;
1181 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1182 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1184 /* Build the error on the stack. We are way to malloc crazy
1185 * throughout the code today.
1187 errhdr
= (struct sctp_errhdr
*)buffer
;
1188 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1190 /* Copy into a parm format. */
1191 len
= af
->to_addr_param(ssa
, addrparm
);
1192 len
+= sizeof(sctp_errhdr_t
);
1194 errhdr
->cause
= SCTP_ERROR_RESTART
;
1195 errhdr
->length
= htons(len
);
1197 /* Assign to the control socket. */
1198 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
1200 /* Association is NULL since this may be a restart attack and we
1201 * want to send back the attacker's vtag.
1203 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1207 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1209 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1211 /* Discard the rest of the inbound packet. */
1212 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1215 /* Even if there is no memory, treat as a failure so
1216 * the packet will get dropped.
1221 /* A restart is occurring, check to make sure no new addresses
1222 * are being added as we may be under a takeover attack.
1224 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1225 const struct sctp_association
*asoc
,
1226 struct sctp_chunk
*init
,
1227 sctp_cmd_seq_t
*commands
)
1229 struct sctp_transport
*new_addr
, *addr
;
1232 /* Implementor's Guide - Sectin 5.2.2
1234 * Before responding the endpoint MUST check to see if the
1235 * unexpected INIT adds new addresses to the association. If new
1236 * addresses are added to the association, the endpoint MUST respond
1240 /* Search through all current addresses and make sure
1241 * we aren't adding any new ones.
1246 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1249 list_for_each_entry(addr
, &asoc
->peer
.transport_addr_list
,
1251 if (sctp_cmp_addr_exact(&new_addr
->ipaddr
,
1261 /* If a new address was added, ABORT the sender. */
1262 if (!found
&& new_addr
) {
1263 sctp_sf_send_restart_abort(&new_addr
->ipaddr
, init
, commands
);
1266 /* Return success if all addresses were found. */
1270 /* Populate the verification/tie tags based on overlapping INIT
1273 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1275 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1276 const struct sctp_association
*asoc
)
1278 switch (asoc
->state
) {
1280 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1282 case SCTP_STATE_COOKIE_WAIT
:
1283 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1284 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1285 new_asoc
->c
.peer_ttag
= 0;
1288 case SCTP_STATE_COOKIE_ECHOED
:
1289 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1290 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1291 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1294 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1295 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1298 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1299 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1303 /* Other parameters for the endpoint SHOULD be copied from the
1304 * existing parameters of the association (e.g. number of
1305 * outbound streams) into the INIT ACK and cookie.
1307 new_asoc
->rwnd
= asoc
->rwnd
;
1308 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1309 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1310 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1314 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1317 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1319 * Returns value representing action to be taken. These action values
1320 * correspond to Action/Description values in RFC 2960, Table 2.
1322 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1323 const struct sctp_association
*asoc
)
1325 /* In this case, the peer may have restarted. */
1326 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1327 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1328 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1329 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1332 /* Collision case B. */
1333 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1334 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1335 (0 == asoc
->c
.peer_vtag
))) {
1339 /* Collision case D. */
1340 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1341 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1344 /* Collision case C. */
1345 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1346 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1347 (0 == new_asoc
->c
.my_ttag
) &&
1348 (0 == new_asoc
->c
.peer_ttag
))
1351 /* No match to any of the special cases; discard this packet. */
1355 /* Common helper routine for both duplicate and simulataneous INIT
1358 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1359 const struct sctp_endpoint
*ep
,
1360 const struct sctp_association
*asoc
,
1361 const sctp_subtype_t type
,
1362 void *arg
, sctp_cmd_seq_t
*commands
)
1364 sctp_disposition_t retval
;
1365 struct sctp_chunk
*chunk
= arg
;
1366 struct sctp_chunk
*repl
;
1367 struct sctp_association
*new_asoc
;
1368 struct sctp_chunk
*err_chunk
;
1369 struct sctp_packet
*packet
;
1370 sctp_unrecognized_param_t
*unk_param
;
1374 * An endpoint MUST NOT bundle INIT, INIT ACK or
1375 * SHUTDOWN COMPLETE with any other chunks.
1378 * Furthermore, we require that the receiver of an INIT chunk MUST
1379 * enforce these rules by silently discarding an arriving packet
1380 * with an INIT chunk that is bundled with other chunks.
1382 if (!chunk
->singleton
)
1383 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1385 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1388 if (chunk
->sctp_hdr
->vtag
!= 0)
1389 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1391 /* Make sure that the INIT chunk has a valid length.
1392 * In this case, we generate a protocol violation since we have
1393 * an association established.
1395 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1396 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1398 /* Grab the INIT header. */
1399 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1401 /* Tag the variable length parameters. */
1402 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1404 /* Verify the INIT chunk before processing it. */
1406 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1407 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1409 /* This chunk contains fatal error. It is to be discarded.
1410 * Send an ABORT, with causes if there is any.
1413 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1414 (__u8
*)(err_chunk
->chunk_hdr
) +
1415 sizeof(sctp_chunkhdr_t
),
1416 ntohs(err_chunk
->chunk_hdr
->length
) -
1417 sizeof(sctp_chunkhdr_t
));
1420 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1421 SCTP_PACKET(packet
));
1422 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1423 retval
= SCTP_DISPOSITION_CONSUME
;
1425 retval
= SCTP_DISPOSITION_NOMEM
;
1429 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1435 * Other parameters for the endpoint SHOULD be copied from the
1436 * existing parameters of the association (e.g. number of
1437 * outbound streams) into the INIT ACK and cookie.
1438 * FIXME: We are copying parameters from the endpoint not the
1441 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1445 /* In the outbound INIT ACK the endpoint MUST copy its current
1446 * Verification Tag and Peers Verification tag into a reserved
1447 * place (local tie-tag and per tie-tag) within the state cookie.
1449 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1451 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1455 /* Make sure no new addresses are being added during the
1456 * restart. Do not do this check for COOKIE-WAIT state,
1457 * since there are no peer addresses to check against.
1458 * Upon return an ABORT will have been sent if needed.
1460 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1461 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1463 retval
= SCTP_DISPOSITION_CONSUME
;
1468 sctp_tietags_populate(new_asoc
, asoc
);
1470 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1472 /* If there are errors need to be reported for unknown parameters,
1473 * make sure to reserve enough room in the INIT ACK for them.
1477 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1478 sizeof(sctp_chunkhdr_t
);
1481 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
1484 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1488 /* If there are errors need to be reported for unknown parameters,
1489 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1493 /* Get the "Unrecognized parameter" parameter(s) out of the
1494 * ERROR chunk generated by sctp_verify_init(). Since the
1495 * error cause code for "unknown parameter" and the
1496 * "Unrecognized parameter" type is the same, we can
1497 * construct the parameters in INIT ACK by copying the
1498 * ERROR causes over.
1500 unk_param
= (sctp_unrecognized_param_t
*)
1501 ((__u8
*)(err_chunk
->chunk_hdr
) +
1502 sizeof(sctp_chunkhdr_t
));
1503 /* Replace the cause code with the "Unrecognized parameter"
1506 sctp_addto_chunk(repl
, len
, unk_param
);
1509 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1510 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1513 * Note: After sending out INIT ACK with the State Cookie parameter,
1514 * "Z" MUST NOT allocate any resources for this new association.
1515 * Otherwise, "Z" will be vulnerable to resource attacks.
1517 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1518 retval
= SCTP_DISPOSITION_CONSUME
;
1523 retval
= SCTP_DISPOSITION_NOMEM
;
1526 sctp_association_free(new_asoc
);
1529 sctp_chunk_free(err_chunk
);
1534 * Handle simultanous INIT.
1535 * This means we started an INIT and then we got an INIT request from
1538 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1539 * This usually indicates an initialization collision, i.e., each
1540 * endpoint is attempting, at about the same time, to establish an
1541 * association with the other endpoint.
1543 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1544 * endpoint MUST respond with an INIT ACK using the same parameters it
1545 * sent in its original INIT chunk (including its Verification Tag,
1546 * unchanged). These original parameters are combined with those from the
1547 * newly received INIT chunk. The endpoint shall also generate a State
1548 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1549 * INIT to calculate the State Cookie.
1551 * After that, the endpoint MUST NOT change its state, the T1-init
1552 * timer shall be left running and the corresponding TCB MUST NOT be
1553 * destroyed. The normal procedures for handling State Cookies when
1554 * a TCB exists will resolve the duplicate INITs to a single association.
1556 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1557 * its Tie-Tags with the Tag information of itself and its peer (see
1558 * section 5.2.2 for a description of the Tie-Tags).
1560 * Verification Tag: Not explicit, but an INIT can not have a valid
1561 * verification tag, so we skip the check.
1564 * (endpoint, asoc, chunk)
1567 * (asoc, reply_msg, msg_up, timers, counters)
1569 * The return value is the disposition of the chunk.
1571 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1572 const struct sctp_association
*asoc
,
1573 const sctp_subtype_t type
,
1575 sctp_cmd_seq_t
*commands
)
1577 /* Call helper to do the real work for both simulataneous and
1578 * duplicate INIT chunk handling.
1580 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1584 * Handle duplicated INIT messages. These are usually delayed
1587 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1588 * COOKIE-ECHOED and COOKIE-WAIT
1590 * Unless otherwise stated, upon reception of an unexpected INIT for
1591 * this association, the endpoint shall generate an INIT ACK with a
1592 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1593 * current Verification Tag and peer's Verification Tag into a reserved
1594 * place within the state cookie. We shall refer to these locations as
1595 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1596 * containing this INIT ACK MUST carry a Verification Tag value equal to
1597 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1598 * MUST contain a new Initiation Tag (randomly generated see Section
1599 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1600 * existing parameters of the association (e.g. number of outbound
1601 * streams) into the INIT ACK and cookie.
1603 * After sending out the INIT ACK, the endpoint shall take no further
1604 * actions, i.e., the existing association, including its current state,
1605 * and the corresponding TCB MUST NOT be changed.
1607 * Note: Only when a TCB exists and the association is not in a COOKIE-
1608 * WAIT state are the Tie-Tags populated. For a normal association INIT
1609 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1610 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1611 * State Cookie are populated as specified in section 5.2.1.
1613 * Verification Tag: Not specified, but an INIT has no way of knowing
1614 * what the verification tag could be, so we ignore it.
1617 * (endpoint, asoc, chunk)
1620 * (asoc, reply_msg, msg_up, timers, counters)
1622 * The return value is the disposition of the chunk.
1624 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1625 const struct sctp_association
*asoc
,
1626 const sctp_subtype_t type
,
1628 sctp_cmd_seq_t
*commands
)
1630 /* Call helper to do the real work for both simulataneous and
1631 * duplicate INIT chunk handling.
1633 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1638 * Unexpected INIT-ACK handler.
1641 * If an INIT ACK received by an endpoint in any state other than the
1642 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1643 * An unexpected INIT ACK usually indicates the processing of an old or
1644 * duplicated INIT chunk.
1646 sctp_disposition_t
sctp_sf_do_5_2_3_initack(const struct sctp_endpoint
*ep
,
1647 const struct sctp_association
*asoc
,
1648 const sctp_subtype_t type
,
1649 void *arg
, sctp_cmd_seq_t
*commands
)
1651 /* Per the above section, we'll discard the chunk if we have an
1652 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1654 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
1655 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
1657 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
1660 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1663 * A) In this case, the peer may have restarted.
1665 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1666 const struct sctp_association
*asoc
,
1667 struct sctp_chunk
*chunk
,
1668 sctp_cmd_seq_t
*commands
,
1669 struct sctp_association
*new_asoc
)
1671 sctp_init_chunk_t
*peer_init
;
1672 struct sctp_ulpevent
*ev
;
1673 struct sctp_chunk
*repl
;
1674 struct sctp_chunk
*err
;
1675 sctp_disposition_t disposition
;
1677 /* new_asoc is a brand-new association, so these are not yet
1678 * side effects--it is safe to run them here.
1680 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1682 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1683 sctp_source(chunk
), peer_init
,
1687 /* Make sure no new addresses are being added during the
1688 * restart. Though this is a pretty complicated attack
1689 * since you'd have to get inside the cookie.
1691 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1692 return SCTP_DISPOSITION_CONSUME
;
1695 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1696 * the peer has restarted (Action A), it MUST NOT setup a new
1697 * association but instead resend the SHUTDOWN ACK and send an ERROR
1698 * chunk with a "Cookie Received while Shutting Down" error cause to
1701 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1702 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1703 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1705 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1708 err
= sctp_make_op_error(asoc
, chunk
,
1709 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1712 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1715 return SCTP_DISPOSITION_CONSUME
;
1718 /* For now, fail any unsent/unacked data. Consider the optional
1719 * choice of resending of this data.
1721 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1723 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1727 /* Report association restart to upper layer. */
1728 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1729 new_asoc
->c
.sinit_num_ostreams
,
1730 new_asoc
->c
.sinit_max_instreams
,
1735 /* Update the content of current association. */
1736 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1737 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1738 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1739 return SCTP_DISPOSITION_CONSUME
;
1742 sctp_chunk_free(repl
);
1744 return SCTP_DISPOSITION_NOMEM
;
1747 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1750 * B) In this case, both sides may be attempting to start an association
1751 * at about the same time but the peer endpoint started its INIT
1752 * after responding to the local endpoint's INIT
1754 /* This case represents an initialization collision. */
1755 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1756 const struct sctp_association
*asoc
,
1757 struct sctp_chunk
*chunk
,
1758 sctp_cmd_seq_t
*commands
,
1759 struct sctp_association
*new_asoc
)
1761 sctp_init_chunk_t
*peer_init
;
1762 struct sctp_chunk
*repl
;
1764 /* new_asoc is a brand-new association, so these are not yet
1765 * side effects--it is safe to run them here.
1767 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1768 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1769 sctp_source(chunk
), peer_init
,
1773 /* Update the content of current association. */
1774 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1775 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1776 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1777 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1778 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1780 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1784 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1786 /* RFC 2960 5.1 Normal Establishment of an Association
1788 * D) IMPLEMENTATION NOTE: An implementation may choose to
1789 * send the Communication Up notification to the SCTP user
1790 * upon reception of a valid COOKIE ECHO chunk.
1792 * Sadly, this needs to be implemented as a side-effect, because
1793 * we are not guaranteed to have set the association id of the real
1794 * association and so these notifications need to be delayed until
1795 * the association id is allocated.
1798 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1800 /* Sockets API Draft Section 5.3.1.6
1801 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1802 * delivers this notification to inform the application that of the
1803 * peers requested adaptation layer.
1805 * This also needs to be done as a side effect for the same reason as
1808 if (asoc
->peer
.adaptation_ind
)
1809 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1811 return SCTP_DISPOSITION_CONSUME
;
1814 return SCTP_DISPOSITION_NOMEM
;
1817 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1820 * C) In this case, the local endpoint's cookie has arrived late.
1821 * Before it arrived, the local endpoint sent an INIT and received an
1822 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1823 * but a new tag of its own.
1825 /* This case represents an initialization collision. */
1826 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1827 const struct sctp_association
*asoc
,
1828 struct sctp_chunk
*chunk
,
1829 sctp_cmd_seq_t
*commands
,
1830 struct sctp_association
*new_asoc
)
1832 /* The cookie should be silently discarded.
1833 * The endpoint SHOULD NOT change states and should leave
1834 * any timers running.
1836 return SCTP_DISPOSITION_DISCARD
;
1839 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1843 * D) When both local and remote tags match the endpoint should always
1844 * enter the ESTABLISHED state, if it has not already done so.
1846 /* This case represents an initialization collision. */
1847 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1848 const struct sctp_association
*asoc
,
1849 struct sctp_chunk
*chunk
,
1850 sctp_cmd_seq_t
*commands
,
1851 struct sctp_association
*new_asoc
)
1853 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1854 struct sctp_chunk
*repl
;
1856 /* Clarification from Implementor's Guide:
1857 * D) When both local and remote tags match the endpoint should
1858 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1859 * It should stop any cookie timer that may be running and send
1863 /* Don't accidentally move back into established state. */
1864 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1865 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1866 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1867 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1868 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1869 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1870 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1873 /* RFC 2960 5.1 Normal Establishment of an Association
1875 * D) IMPLEMENTATION NOTE: An implementation may choose
1876 * to send the Communication Up notification to the
1877 * SCTP user upon reception of a valid COOKIE
1880 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1882 asoc
->c
.sinit_num_ostreams
,
1883 asoc
->c
.sinit_max_instreams
,
1888 /* Sockets API Draft Section 5.3.1.6
1889 * When a peer sends a Adaptation Layer Indication parameter,
1890 * SCTP delivers this notification to inform the application
1891 * that of the peers requested adaptation layer.
1893 if (asoc
->peer
.adaptation_ind
) {
1894 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1902 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1906 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1909 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1912 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1913 SCTP_ULPEVENT(ai_ev
));
1915 return SCTP_DISPOSITION_CONSUME
;
1919 sctp_ulpevent_free(ai_ev
);
1921 sctp_ulpevent_free(ev
);
1922 return SCTP_DISPOSITION_NOMEM
;
1926 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1927 * chunk was retransmitted and then delayed in the network.
1929 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1931 * Verification Tag: None. Do cookie validation.
1934 * (endpoint, asoc, chunk)
1937 * (asoc, reply_msg, msg_up, timers, counters)
1939 * The return value is the disposition of the chunk.
1941 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1942 const struct sctp_association
*asoc
,
1943 const sctp_subtype_t type
,
1945 sctp_cmd_seq_t
*commands
)
1947 sctp_disposition_t retval
;
1948 struct sctp_chunk
*chunk
= arg
;
1949 struct sctp_association
*new_asoc
;
1952 struct sctp_chunk
*err_chk_p
;
1954 /* Make sure that the chunk has a valid length from the protocol
1955 * perspective. In this case check to make sure we have at least
1956 * enough for the chunk header. Cookie length verification is
1959 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1960 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1963 /* "Decode" the chunk. We have no optional parameters so we
1964 * are in good shape.
1966 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1967 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1968 sizeof(sctp_chunkhdr_t
)))
1971 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1972 * of a duplicate COOKIE ECHO match the Verification Tags of the
1973 * current association, consider the State Cookie valid even if
1974 * the lifespan is exceeded.
1976 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
1980 * If the re-build failed, what is the proper error path
1983 * [We should abort the association. --piggy]
1986 /* FIXME: Several errors are possible. A bad cookie should
1987 * be silently discarded, but think about logging it too.
1990 case -SCTP_IERROR_NOMEM
:
1993 case -SCTP_IERROR_STALE_COOKIE
:
1994 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
1996 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1997 case -SCTP_IERROR_BAD_SIG
:
1999 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2003 /* Compare the tie_tag in cookie with the verification tag of
2004 * current association.
2006 action
= sctp_tietags_compare(new_asoc
, asoc
);
2009 case 'A': /* Association restart. */
2010 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
2014 case 'B': /* Collision case B. */
2015 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
2019 case 'C': /* Collision case C. */
2020 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
2024 case 'D': /* Collision case D. */
2025 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
2029 default: /* Discard packet for all others. */
2030 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2034 /* Delete the tempory new association. */
2035 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
2036 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2041 return SCTP_DISPOSITION_NOMEM
;
2045 * Process an ABORT. (SHUTDOWN-PENDING state)
2047 * See sctp_sf_do_9_1_abort().
2049 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2050 const struct sctp_endpoint
*ep
,
2051 const struct sctp_association
*asoc
,
2052 const sctp_subtype_t type
,
2054 sctp_cmd_seq_t
*commands
)
2056 struct sctp_chunk
*chunk
= arg
;
2058 if (!sctp_vtag_verify_either(chunk
, asoc
))
2059 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2061 /* Make sure that the ABORT chunk has a valid length.
2062 * Since this is an ABORT chunk, we have to discard it
2063 * because of the following text:
2064 * RFC 2960, Section 3.3.7
2065 * If an endpoint receives an ABORT with a format error or for an
2066 * association that doesn't exist, it MUST silently discard it.
2067 * Becasue the length is "invalid", we can't really discard just
2068 * as we do not know its true length. So, to be safe, discard the
2071 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2072 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2074 /* ADD-IP: Special case for ABORT chunks
2075 * F4) One special consideration is that ABORT Chunks arriving
2076 * destined to the IP address being deleted MUST be
2077 * ignored (see Section 5.3.1 for further details).
2079 if (SCTP_ADDR_DEL
==
2080 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2081 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2083 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2087 * Process an ABORT. (SHUTDOWN-SENT state)
2089 * See sctp_sf_do_9_1_abort().
2091 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
2092 const struct sctp_association
*asoc
,
2093 const sctp_subtype_t type
,
2095 sctp_cmd_seq_t
*commands
)
2097 struct sctp_chunk
*chunk
= arg
;
2099 if (!sctp_vtag_verify_either(chunk
, asoc
))
2100 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2102 /* Make sure that the ABORT chunk has a valid length.
2103 * Since this is an ABORT chunk, we have to discard it
2104 * because of the following text:
2105 * RFC 2960, Section 3.3.7
2106 * If an endpoint receives an ABORT with a format error or for an
2107 * association that doesn't exist, it MUST silently discard it.
2108 * Becasue the length is "invalid", we can't really discard just
2109 * as we do not know its true length. So, to be safe, discard the
2112 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2113 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2115 /* ADD-IP: Special case for ABORT chunks
2116 * F4) One special consideration is that ABORT Chunks arriving
2117 * destined to the IP address being deleted MUST be
2118 * ignored (see Section 5.3.1 for further details).
2120 if (SCTP_ADDR_DEL
==
2121 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2122 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2124 /* Stop the T2-shutdown timer. */
2125 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2126 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2128 /* Stop the T5-shutdown guard timer. */
2129 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2130 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2132 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2136 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2138 * See sctp_sf_do_9_1_abort().
2140 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2141 const struct sctp_endpoint
*ep
,
2142 const struct sctp_association
*asoc
,
2143 const sctp_subtype_t type
,
2145 sctp_cmd_seq_t
*commands
)
2147 /* The same T2 timer, so we should be able to use
2148 * common function with the SHUTDOWN-SENT state.
2150 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2154 * Handle an Error received in COOKIE_ECHOED state.
2156 * Only handle the error type of stale COOKIE Error, the other errors will
2160 * (endpoint, asoc, chunk)
2163 * (asoc, reply_msg, msg_up, timers, counters)
2165 * The return value is the disposition of the chunk.
2167 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2168 const struct sctp_association
*asoc
,
2169 const sctp_subtype_t type
,
2171 sctp_cmd_seq_t
*commands
)
2173 struct sctp_chunk
*chunk
= arg
;
2176 if (!sctp_vtag_verify(chunk
, asoc
))
2177 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2179 /* Make sure that the ERROR chunk has a valid length.
2180 * The parameter walking depends on this as well.
2182 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2183 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2186 /* Process the error here */
2187 /* FUTURE FIXME: When PR-SCTP related and other optional
2188 * parms are emitted, this will have to change to handle multiple
2191 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2192 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2193 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2197 /* It is possible to have malformed error causes, and that
2198 * will cause us to end the walk early. However, since
2199 * we are discarding the packet, there should be no adverse
2202 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2206 * Handle a Stale COOKIE Error
2208 * Section: 5.2.6 Handle Stale COOKIE Error
2209 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2210 * one of the following three alternatives.
2212 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2213 * Preservative parameter requesting an extension to the lifetime of
2214 * the State Cookie. When calculating the time extension, an
2215 * implementation SHOULD use the RTT information measured based on the
2216 * previous COOKIE ECHO / ERROR exchange, and should add no more
2217 * than 1 second beyond the measured RTT, due to long State Cookie
2218 * lifetimes making the endpoint more subject to a replay attack.
2220 * Verification Tag: Not explicit, but safe to ignore.
2223 * (endpoint, asoc, chunk)
2226 * (asoc, reply_msg, msg_up, timers, counters)
2228 * The return value is the disposition of the chunk.
2230 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2231 const struct sctp_association
*asoc
,
2232 const sctp_subtype_t type
,
2234 sctp_cmd_seq_t
*commands
)
2236 struct sctp_chunk
*chunk
= arg
;
2238 sctp_cookie_preserve_param_t bht
;
2240 struct sctp_chunk
*reply
;
2241 struct sctp_bind_addr
*bp
;
2242 int attempts
= asoc
->init_err_counter
+ 1;
2244 if (attempts
> asoc
->max_init_attempts
) {
2245 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2246 SCTP_ERROR(ETIMEDOUT
));
2247 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2248 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2249 return SCTP_DISPOSITION_DELETE_TCB
;
2252 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2254 /* When calculating the time extension, an implementation
2255 * SHOULD use the RTT information measured based on the
2256 * previous COOKIE ECHO / ERROR exchange, and should add no
2257 * more than 1 second beyond the measured RTT, due to long
2258 * State Cookie lifetimes making the endpoint more subject to
2260 * Measure of Staleness's unit is usec. (1/1000000 sec)
2261 * Suggested Cookie Life-span Increment's unit is msec.
2263 * In general, if you use the suggested cookie life, the value
2264 * found in the field of measure of staleness should be doubled
2265 * to give ample time to retransmit the new cookie and thus
2266 * yield a higher probability of success on the reattempt.
2268 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2269 stale
= (stale
* 2) / 1000;
2271 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2272 bht
.param_hdr
.length
= htons(sizeof(bht
));
2273 bht
.lifespan_increment
= htonl(stale
);
2275 /* Build that new INIT chunk. */
2276 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2277 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2281 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2283 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2284 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2286 /* Stop pending T3-rtx and heartbeat timers */
2287 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2288 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2290 /* Delete non-primary peer ip addresses since we are transitioning
2291 * back to the COOKIE-WAIT state
2293 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2295 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2298 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2299 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2301 /* Cast away the const modifier, as we want to just
2302 * rerun it through as a sideffect.
2304 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2306 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2307 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2308 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2309 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2310 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2311 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2313 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2315 return SCTP_DISPOSITION_CONSUME
;
2318 return SCTP_DISPOSITION_NOMEM
;
2325 * After checking the Verification Tag, the receiving endpoint shall
2326 * remove the association from its record, and shall report the
2327 * termination to its upper layer.
2329 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2330 * B) Rules for packet carrying ABORT:
2332 * - The endpoint shall always fill in the Verification Tag field of the
2333 * outbound packet with the destination endpoint's tag value if it
2336 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2337 * MUST follow the procedure described in Section 8.4.
2339 * - The receiver MUST accept the packet if the Verification Tag
2340 * matches either its own tag, OR the tag of its peer. Otherwise, the
2341 * receiver MUST silently discard the packet and take no further
2345 * (endpoint, asoc, chunk)
2348 * (asoc, reply_msg, msg_up, timers, counters)
2350 * The return value is the disposition of the chunk.
2352 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2353 const struct sctp_association
*asoc
,
2354 const sctp_subtype_t type
,
2356 sctp_cmd_seq_t
*commands
)
2358 struct sctp_chunk
*chunk
= arg
;
2360 if (!sctp_vtag_verify_either(chunk
, asoc
))
2361 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2363 /* Make sure that the ABORT chunk has a valid length.
2364 * Since this is an ABORT chunk, we have to discard it
2365 * because of the following text:
2366 * RFC 2960, Section 3.3.7
2367 * If an endpoint receives an ABORT with a format error or for an
2368 * association that doesn't exist, it MUST silently discard it.
2369 * Becasue the length is "invalid", we can't really discard just
2370 * as we do not know its true length. So, to be safe, discard the
2373 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2374 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2376 /* ADD-IP: Special case for ABORT chunks
2377 * F4) One special consideration is that ABORT Chunks arriving
2378 * destined to the IP address being deleted MUST be
2379 * ignored (see Section 5.3.1 for further details).
2381 if (SCTP_ADDR_DEL
==
2382 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2383 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2385 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2388 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2389 const struct sctp_association
*asoc
,
2390 const sctp_subtype_t type
,
2392 sctp_cmd_seq_t
*commands
)
2394 struct sctp_chunk
*chunk
= arg
;
2396 __be16 error
= SCTP_ERROR_NO_ERROR
;
2398 /* See if we have an error cause code in the chunk. */
2399 len
= ntohs(chunk
->chunk_hdr
->length
);
2400 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2401 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2403 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2404 /* ASSOC_FAILED will DELETE_TCB. */
2405 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2406 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2407 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
2409 return SCTP_DISPOSITION_ABORT
;
2413 * Process an ABORT. (COOKIE-WAIT state)
2415 * See sctp_sf_do_9_1_abort() above.
2417 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2418 const struct sctp_association
*asoc
,
2419 const sctp_subtype_t type
,
2421 sctp_cmd_seq_t
*commands
)
2423 struct sctp_chunk
*chunk
= arg
;
2425 __be16 error
= SCTP_ERROR_NO_ERROR
;
2427 if (!sctp_vtag_verify_either(chunk
, asoc
))
2428 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2430 /* Make sure that the ABORT chunk has a valid length.
2431 * Since this is an ABORT chunk, we have to discard it
2432 * because of the following text:
2433 * RFC 2960, Section 3.3.7
2434 * If an endpoint receives an ABORT with a format error or for an
2435 * association that doesn't exist, it MUST silently discard it.
2436 * Becasue the length is "invalid", we can't really discard just
2437 * as we do not know its true length. So, to be safe, discard the
2440 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2441 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2443 /* See if we have an error cause code in the chunk. */
2444 len
= ntohs(chunk
->chunk_hdr
->length
);
2445 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2446 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2448 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
, asoc
,
2453 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2455 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2456 const struct sctp_association
*asoc
,
2457 const sctp_subtype_t type
,
2459 sctp_cmd_seq_t
*commands
)
2461 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
,
2463 (struct sctp_transport
*)arg
);
2467 * Process an ABORT. (COOKIE-ECHOED state)
2469 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2470 const struct sctp_association
*asoc
,
2471 const sctp_subtype_t type
,
2473 sctp_cmd_seq_t
*commands
)
2475 /* There is a single T1 timer, so we should be able to use
2476 * common function with the COOKIE-WAIT state.
2478 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2482 * Stop T1 timer and abort association with "INIT failed".
2484 * This is common code called by several sctp_sf_*_abort() functions above.
2486 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2487 __be16 error
, int sk_err
,
2488 const struct sctp_association
*asoc
,
2489 struct sctp_transport
*transport
)
2491 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2492 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2493 SCTP_STATE(SCTP_STATE_CLOSED
));
2494 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2495 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2496 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2497 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2498 /* CMD_INIT_FAILED will DELETE_TCB. */
2499 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2501 return SCTP_DISPOSITION_ABORT
;
2505 * sctp_sf_do_9_2_shut
2508 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2509 * - enter the SHUTDOWN-RECEIVED state,
2511 * - stop accepting new data from its SCTP user
2513 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2514 * that all its outstanding DATA chunks have been received by the
2517 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2518 * send a SHUTDOWN in response to a ULP request. And should discard
2519 * subsequent SHUTDOWN chunks.
2521 * If there are still outstanding DATA chunks left, the SHUTDOWN
2522 * receiver shall continue to follow normal data transmission
2523 * procedures defined in Section 6 until all outstanding DATA chunks
2524 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2525 * new data from its SCTP user.
2527 * Verification Tag: 8.5 Verification Tag [Normal verification]
2530 * (endpoint, asoc, chunk)
2533 * (asoc, reply_msg, msg_up, timers, counters)
2535 * The return value is the disposition of the chunk.
2537 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2538 const struct sctp_association
*asoc
,
2539 const sctp_subtype_t type
,
2541 sctp_cmd_seq_t
*commands
)
2543 struct sctp_chunk
*chunk
= arg
;
2544 sctp_shutdownhdr_t
*sdh
;
2545 sctp_disposition_t disposition
;
2546 struct sctp_ulpevent
*ev
;
2549 if (!sctp_vtag_verify(chunk
, asoc
))
2550 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2552 /* Make sure that the SHUTDOWN chunk has a valid length. */
2553 if (!sctp_chunk_length_valid(chunk
,
2554 sizeof(struct sctp_shutdown_chunk_t
)))
2555 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2558 /* Convert the elaborate header. */
2559 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2560 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2561 chunk
->subh
.shutdown_hdr
= sdh
;
2562 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2564 /* If Cumulative TSN Ack beyond the max tsn currently
2565 * send, terminating the association and respond to the
2566 * sender with an ABORT.
2568 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2569 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2571 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2572 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2573 * inform the application that it should cease sending data.
2575 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2577 disposition
= SCTP_DISPOSITION_NOMEM
;
2580 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2582 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2583 * - enter the SHUTDOWN-RECEIVED state,
2584 * - stop accepting new data from its SCTP user
2586 * [This is implicit in the new state.]
2588 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2589 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2590 disposition
= SCTP_DISPOSITION_CONSUME
;
2592 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2593 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2597 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2600 /* - verify, by checking the Cumulative TSN Ack field of the
2601 * chunk, that all its outstanding DATA chunks have been
2602 * received by the SHUTDOWN sender.
2604 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2605 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2612 * sctp_sf_do_9_2_shut_ctsn
2614 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2615 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2616 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2617 * MUST be processed.
2619 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(const struct sctp_endpoint
*ep
,
2620 const struct sctp_association
*asoc
,
2621 const sctp_subtype_t type
,
2623 sctp_cmd_seq_t
*commands
)
2625 struct sctp_chunk
*chunk
= arg
;
2626 sctp_shutdownhdr_t
*sdh
;
2628 if (!sctp_vtag_verify(chunk
, asoc
))
2629 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2631 /* Make sure that the SHUTDOWN chunk has a valid length. */
2632 if (!sctp_chunk_length_valid(chunk
,
2633 sizeof(struct sctp_shutdown_chunk_t
)))
2634 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2637 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2639 /* If Cumulative TSN Ack beyond the max tsn currently
2640 * send, terminating the association and respond to the
2641 * sender with an ABORT.
2643 if (!TSN_lt(ntohl(sdh
->cum_tsn_ack
), asoc
->next_tsn
))
2644 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2646 /* verify, by checking the Cumulative TSN Ack field of the
2647 * chunk, that all its outstanding DATA chunks have been
2648 * received by the SHUTDOWN sender.
2650 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2651 SCTP_BE32(sdh
->cum_tsn_ack
));
2653 return SCTP_DISPOSITION_CONSUME
;
2657 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2658 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2659 * transport addresses (either in the IP addresses or in the INIT chunk)
2660 * that belong to this association, it should discard the INIT chunk and
2661 * retransmit the SHUTDOWN ACK chunk.
2663 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2664 const struct sctp_association
*asoc
,
2665 const sctp_subtype_t type
,
2667 sctp_cmd_seq_t
*commands
)
2669 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2670 struct sctp_chunk
*reply
;
2672 /* Make sure that the chunk has a valid length */
2673 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2674 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2677 /* Since we are not going to really process this INIT, there
2678 * is no point in verifying chunk boundries. Just generate
2681 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2685 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2686 * the T2-SHUTDOWN timer.
2688 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2690 /* and restart the T2-shutdown timer. */
2691 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2692 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2694 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2696 return SCTP_DISPOSITION_CONSUME
;
2698 return SCTP_DISPOSITION_NOMEM
;
2702 * sctp_sf_do_ecn_cwr
2704 * Section: Appendix A: Explicit Congestion Notification
2708 * RFC 2481 details a specific bit for a sender to send in the header of
2709 * its next outbound TCP segment to indicate to its peer that it has
2710 * reduced its congestion window. This is termed the CWR bit. For
2711 * SCTP the same indication is made by including the CWR chunk.
2712 * This chunk contains one data element, i.e. the TSN number that
2713 * was sent in the ECNE chunk. This element represents the lowest
2714 * TSN number in the datagram that was originally marked with the
2717 * Verification Tag: 8.5 Verification Tag [Normal verification]
2719 * (endpoint, asoc, chunk)
2722 * (asoc, reply_msg, msg_up, timers, counters)
2724 * The return value is the disposition of the chunk.
2726 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2727 const struct sctp_association
*asoc
,
2728 const sctp_subtype_t type
,
2730 sctp_cmd_seq_t
*commands
)
2733 struct sctp_chunk
*chunk
= arg
;
2736 if (!sctp_vtag_verify(chunk
, asoc
))
2737 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2739 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2740 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2743 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2744 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2746 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2748 /* Does this CWR ack the last sent congestion notification? */
2749 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2750 /* Stop sending ECNE. */
2751 sctp_add_cmd_sf(commands
,
2753 SCTP_U32(lowest_tsn
));
2755 return SCTP_DISPOSITION_CONSUME
;
2761 * Section: Appendix A: Explicit Congestion Notification
2765 * RFC 2481 details a specific bit for a receiver to send back in its
2766 * TCP acknowledgements to notify the sender of the Congestion
2767 * Experienced (CE) bit having arrived from the network. For SCTP this
2768 * same indication is made by including the ECNE chunk. This chunk
2769 * contains one data element, i.e. the lowest TSN associated with the IP
2770 * datagram marked with the CE bit.....
2772 * Verification Tag: 8.5 Verification Tag [Normal verification]
2774 * (endpoint, asoc, chunk)
2777 * (asoc, reply_msg, msg_up, timers, counters)
2779 * The return value is the disposition of the chunk.
2781 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2782 const struct sctp_association
*asoc
,
2783 const sctp_subtype_t type
,
2785 sctp_cmd_seq_t
*commands
)
2787 sctp_ecnehdr_t
*ecne
;
2788 struct sctp_chunk
*chunk
= arg
;
2790 if (!sctp_vtag_verify(chunk
, asoc
))
2791 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2793 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2794 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2797 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2798 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2800 /* If this is a newer ECNE than the last CWR packet we sent out */
2801 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2802 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2804 return SCTP_DISPOSITION_CONSUME
;
2808 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2810 * The SCTP endpoint MUST always acknowledge the reception of each valid
2813 * The guidelines on delayed acknowledgement algorithm specified in
2814 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2815 * acknowledgement SHOULD be generated for at least every second packet
2816 * (not every second DATA chunk) received, and SHOULD be generated within
2817 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2818 * situations it may be beneficial for an SCTP transmitter to be more
2819 * conservative than the algorithms detailed in this document allow.
2820 * However, an SCTP transmitter MUST NOT be more aggressive than the
2821 * following algorithms allow.
2823 * A SCTP receiver MUST NOT generate more than one SACK for every
2824 * incoming packet, other than to update the offered window as the
2825 * receiving application consumes new data.
2827 * Verification Tag: 8.5 Verification Tag [Normal verification]
2830 * (endpoint, asoc, chunk)
2833 * (asoc, reply_msg, msg_up, timers, counters)
2835 * The return value is the disposition of the chunk.
2837 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2838 const struct sctp_association
*asoc
,
2839 const sctp_subtype_t type
,
2841 sctp_cmd_seq_t
*commands
)
2843 struct sctp_chunk
*chunk
= arg
;
2846 if (!sctp_vtag_verify(chunk
, asoc
)) {
2847 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2849 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2852 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2853 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2856 error
= sctp_eat_data(asoc
, chunk
, commands
);
2858 case SCTP_IERROR_NO_ERROR
:
2860 case SCTP_IERROR_HIGH_TSN
:
2861 case SCTP_IERROR_BAD_STREAM
:
2862 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2863 goto discard_noforce
;
2864 case SCTP_IERROR_DUP_TSN
:
2865 case SCTP_IERROR_IGNORE_TSN
:
2866 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2868 case SCTP_IERROR_NO_DATA
:
2874 if (asoc
->autoclose
) {
2875 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2876 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2879 /* If this is the last chunk in a packet, we need to count it
2880 * toward sack generation. Note that we need to SACK every
2881 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2882 * THEM. We elect to NOT generate SACK's if the chunk fails
2883 * the verification tag test.
2885 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2887 * The SCTP endpoint MUST always acknowledge the reception of
2888 * each valid DATA chunk.
2890 * The guidelines on delayed acknowledgement algorithm
2891 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2892 * Specifically, an acknowledgement SHOULD be generated for at
2893 * least every second packet (not every second DATA chunk)
2894 * received, and SHOULD be generated within 200 ms of the
2895 * arrival of any unacknowledged DATA chunk. In some
2896 * situations it may be beneficial for an SCTP transmitter to
2897 * be more conservative than the algorithms detailed in this
2898 * document allow. However, an SCTP transmitter MUST NOT be
2899 * more aggressive than the following algorithms allow.
2901 if (chunk
->end_of_packet
)
2902 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2904 return SCTP_DISPOSITION_CONSUME
;
2907 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2909 * When a packet arrives with duplicate DATA chunk(s) and with
2910 * no new DATA chunk(s), the endpoint MUST immediately send a
2911 * SACK with no delay. If a packet arrives with duplicate
2912 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2913 * MAY immediately send a SACK. Normally receipt of duplicate
2914 * DATA chunks will occur when the original SACK chunk was lost
2915 * and the peer's RTO has expired. The duplicate TSN number(s)
2916 * SHOULD be reported in the SACK as duplicate.
2918 /* In our case, we split the MAY SACK advice up whether or not
2919 * the last chunk is a duplicate.'
2921 if (chunk
->end_of_packet
)
2922 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2923 return SCTP_DISPOSITION_DISCARD
;
2926 if (chunk
->end_of_packet
)
2927 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2929 return SCTP_DISPOSITION_DISCARD
;
2931 return SCTP_DISPOSITION_CONSUME
;
2936 * sctp_sf_eat_data_fast_4_4
2939 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2940 * DATA chunks without delay.
2942 * Verification Tag: 8.5 Verification Tag [Normal verification]
2944 * (endpoint, asoc, chunk)
2947 * (asoc, reply_msg, msg_up, timers, counters)
2949 * The return value is the disposition of the chunk.
2951 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
2952 const struct sctp_association
*asoc
,
2953 const sctp_subtype_t type
,
2955 sctp_cmd_seq_t
*commands
)
2957 struct sctp_chunk
*chunk
= arg
;
2960 if (!sctp_vtag_verify(chunk
, asoc
)) {
2961 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2963 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2966 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2967 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2970 error
= sctp_eat_data(asoc
, chunk
, commands
);
2972 case SCTP_IERROR_NO_ERROR
:
2973 case SCTP_IERROR_HIGH_TSN
:
2974 case SCTP_IERROR_DUP_TSN
:
2975 case SCTP_IERROR_IGNORE_TSN
:
2976 case SCTP_IERROR_BAD_STREAM
:
2978 case SCTP_IERROR_NO_DATA
:
2984 /* Go a head and force a SACK, since we are shutting down. */
2986 /* Implementor's Guide.
2988 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2989 * respond to each received packet containing one or more DATA chunk(s)
2990 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2992 if (chunk
->end_of_packet
) {
2993 /* We must delay the chunk creation since the cumulative
2994 * TSN has not been updated yet.
2996 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
2997 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2998 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2999 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3003 return SCTP_DISPOSITION_CONSUME
;
3007 * Section: 6.2 Processing a Received SACK
3008 * D) Any time a SACK arrives, the endpoint performs the following:
3010 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3011 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3012 * increasing, a SACK whose Cumulative TSN Ack is less than the
3013 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3015 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3016 * of bytes still outstanding after processing the Cumulative TSN Ack
3017 * and the Gap Ack Blocks.
3019 * iii) If the SACK is missing a TSN that was previously
3020 * acknowledged via a Gap Ack Block (e.g., the data receiver
3021 * reneged on the data), then mark the corresponding DATA chunk
3022 * as available for retransmit: Mark it as missing for fast
3023 * retransmit as described in Section 7.2.4 and if no retransmit
3024 * timer is running for the destination address to which the DATA
3025 * chunk was originally transmitted, then T3-rtx is started for
3026 * that destination address.
3028 * Verification Tag: 8.5 Verification Tag [Normal verification]
3031 * (endpoint, asoc, chunk)
3034 * (asoc, reply_msg, msg_up, timers, counters)
3036 * The return value is the disposition of the chunk.
3038 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
3039 const struct sctp_association
*asoc
,
3040 const sctp_subtype_t type
,
3042 sctp_cmd_seq_t
*commands
)
3044 struct sctp_chunk
*chunk
= arg
;
3045 sctp_sackhdr_t
*sackh
;
3048 if (!sctp_vtag_verify(chunk
, asoc
))
3049 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3051 /* Make sure that the SACK chunk has a valid length. */
3052 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3053 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3056 /* Pull the SACK chunk from the data buffer */
3057 sackh
= sctp_sm_pull_sack(chunk
);
3058 /* Was this a bogus SACK? */
3060 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3061 chunk
->subh
.sack_hdr
= sackh
;
3062 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3064 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3065 * Ack Point, then drop the SACK. Since Cumulative TSN
3066 * Ack is monotonically increasing, a SACK whose
3067 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3068 * Point indicates an out-of-order SACK.
3070 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3071 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
3072 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
3073 return SCTP_DISPOSITION_DISCARD
;
3076 /* If Cumulative TSN Ack beyond the max tsn currently
3077 * send, terminating the association and respond to the
3078 * sender with an ABORT.
3080 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3081 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
3083 /* Return this SACK for further processing. */
3084 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
3086 /* Note: We do the rest of the work on the PROCESS_SACK
3089 return SCTP_DISPOSITION_CONSUME
;
3093 * Generate an ABORT in response to a packet.
3095 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3097 * 8) The receiver should respond to the sender of the OOTB packet with
3098 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3099 * MUST fill in the Verification Tag field of the outbound packet
3100 * with the value found in the Verification Tag field of the OOTB
3101 * packet and set the T-bit in the Chunk Flags to indicate that the
3102 * Verification Tag is reflected. After sending this ABORT, the
3103 * receiver of the OOTB packet shall discard the OOTB packet and take
3104 * no further action.
3108 * The return value is the disposition of the chunk.
3110 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
3111 const struct sctp_association
*asoc
,
3112 const sctp_subtype_t type
,
3114 sctp_cmd_seq_t
*commands
)
3116 struct sctp_packet
*packet
= NULL
;
3117 struct sctp_chunk
*chunk
= arg
;
3118 struct sctp_chunk
*abort
;
3120 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3123 /* Make an ABORT. The T bit will be set if the asoc
3126 abort
= sctp_make_abort(asoc
, chunk
, 0);
3128 sctp_ootb_pkt_free(packet
);
3129 return SCTP_DISPOSITION_NOMEM
;
3132 /* Reflect vtag if T-Bit is set */
3133 if (sctp_test_T_bit(abort
))
3134 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3136 /* Set the skb to the belonging sock for accounting. */
3137 abort
->skb
->sk
= ep
->base
.sk
;
3139 sctp_packet_append_chunk(packet
, abort
);
3141 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3142 SCTP_PACKET(packet
));
3144 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3146 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3147 return SCTP_DISPOSITION_CONSUME
;
3150 return SCTP_DISPOSITION_NOMEM
;
3154 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3155 * event as ULP notification for each cause included in the chunk.
3157 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3159 * The return value is the disposition of the chunk.
3161 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
3162 const struct sctp_association
*asoc
,
3163 const sctp_subtype_t type
,
3165 sctp_cmd_seq_t
*commands
)
3167 struct sctp_chunk
*chunk
= arg
;
3169 if (!sctp_vtag_verify(chunk
, asoc
))
3170 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3172 /* Make sure that the ERROR chunk has a valid length. */
3173 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3174 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3177 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3180 return SCTP_DISPOSITION_CONSUME
;
3184 * Process an inbound SHUTDOWN ACK.
3187 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3188 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3189 * peer, and remove all record of the association.
3191 * The return value is the disposition.
3193 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
3194 const struct sctp_association
*asoc
,
3195 const sctp_subtype_t type
,
3197 sctp_cmd_seq_t
*commands
)
3199 struct sctp_chunk
*chunk
= arg
;
3200 struct sctp_chunk
*reply
;
3201 struct sctp_ulpevent
*ev
;
3203 if (!sctp_vtag_verify(chunk
, asoc
))
3204 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3206 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3207 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3208 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3210 /* 10.2 H) SHUTDOWN COMPLETE notification
3212 * When SCTP completes the shutdown procedures (section 9.2) this
3213 * notification is passed to the upper layer.
3215 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3216 0, 0, 0, NULL
, GFP_ATOMIC
);
3220 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3221 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3225 /* Do all the commands now (after allocation), so that we
3226 * have consistent state if memory allocation failes
3228 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3230 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3231 * stop the T2-shutdown timer,
3233 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3234 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3236 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3237 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3239 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3240 SCTP_STATE(SCTP_STATE_CLOSED
));
3241 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
3242 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3243 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3245 /* ...and remove all record of the association. */
3246 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3247 return SCTP_DISPOSITION_DELETE_TCB
;
3250 sctp_ulpevent_free(ev
);
3252 return SCTP_DISPOSITION_NOMEM
;
3256 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3258 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3259 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3260 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3261 * packet must fill in the Verification Tag field of the outbound
3262 * packet with the Verification Tag received in the SHUTDOWN ACK and
3263 * set the T-bit in the Chunk Flags to indicate that the Verification
3266 * 8) The receiver should respond to the sender of the OOTB packet with
3267 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3268 * MUST fill in the Verification Tag field of the outbound packet
3269 * with the value found in the Verification Tag field of the OOTB
3270 * packet and set the T-bit in the Chunk Flags to indicate that the
3271 * Verification Tag is reflected. After sending this ABORT, the
3272 * receiver of the OOTB packet shall discard the OOTB packet and take
3273 * no further action.
3275 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3276 const struct sctp_association
*asoc
,
3277 const sctp_subtype_t type
,
3279 sctp_cmd_seq_t
*commands
)
3281 struct sctp_chunk
*chunk
= arg
;
3282 struct sk_buff
*skb
= chunk
->skb
;
3283 sctp_chunkhdr_t
*ch
;
3285 int ootb_shut_ack
= 0;
3287 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3289 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3291 /* Report violation if the chunk is less then minimal */
3292 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3293 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3296 /* Now that we know we at least have a chunk header,
3297 * do things that are type appropriate.
3299 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3302 /* RFC 2960, Section 3.3.7
3303 * Moreover, under any circumstances, an endpoint that
3304 * receives an ABORT MUST NOT respond to that ABORT by
3305 * sending an ABORT of its own.
3307 if (SCTP_CID_ABORT
== ch
->type
)
3308 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3310 /* Report violation if chunk len overflows */
3311 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3312 if (ch_end
> skb_tail_pointer(skb
))
3313 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3316 ch
= (sctp_chunkhdr_t
*) ch_end
;
3317 } while (ch_end
< skb_tail_pointer(skb
));
3320 return sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3322 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3326 * Handle an "Out of the blue" SHUTDOWN ACK.
3328 * Section: 8.4 5, sctpimpguide 2.41.
3330 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3331 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3332 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3333 * packet must fill in the Verification Tag field of the outbound
3334 * packet with the Verification Tag received in the SHUTDOWN ACK and
3335 * set the T-bit in the Chunk Flags to indicate that the Verification
3339 * (endpoint, asoc, type, arg, commands)
3342 * (sctp_disposition_t)
3344 * The return value is the disposition of the chunk.
3346 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3347 const struct sctp_association
*asoc
,
3348 const sctp_subtype_t type
,
3350 sctp_cmd_seq_t
*commands
)
3352 struct sctp_packet
*packet
= NULL
;
3353 struct sctp_chunk
*chunk
= arg
;
3354 struct sctp_chunk
*shut
;
3356 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3359 /* Make an SHUTDOWN_COMPLETE.
3360 * The T bit will be set if the asoc is NULL.
3362 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3364 sctp_ootb_pkt_free(packet
);
3365 return SCTP_DISPOSITION_NOMEM
;
3368 /* Reflect vtag if T-Bit is set */
3369 if (sctp_test_T_bit(shut
))
3370 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3372 /* Set the skb to the belonging sock for accounting. */
3373 shut
->skb
->sk
= ep
->base
.sk
;
3375 sctp_packet_append_chunk(packet
, shut
);
3377 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3378 SCTP_PACKET(packet
));
3380 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3382 /* If the chunk length is invalid, we don't want to process
3383 * the reset of the packet.
3385 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3386 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3388 /* We need to discard the rest of the packet to prevent
3389 * potential bomming attacks from additional bundled chunks.
3390 * This is documented in SCTP Threats ID.
3392 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3395 return SCTP_DISPOSITION_NOMEM
;
3399 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3401 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3402 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3403 * procedures in section 8.4 SHOULD be followed, in other words it
3404 * should be treated as an Out Of The Blue packet.
3405 * [This means that we do NOT check the Verification Tag on these
3409 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3410 const struct sctp_association
*asoc
,
3411 const sctp_subtype_t type
,
3413 sctp_cmd_seq_t
*commands
)
3415 struct sctp_chunk
*chunk
= arg
;
3417 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3418 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3419 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3422 /* Although we do have an association in this case, it corresponds
3423 * to a restarted association. So the packet is treated as an OOTB
3424 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3425 * called with a NULL association.
3427 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3429 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3432 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3433 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3434 const struct sctp_association
*asoc
,
3435 const sctp_subtype_t type
, void *arg
,
3436 sctp_cmd_seq_t
*commands
)
3438 struct sctp_chunk
*chunk
= arg
;
3439 struct sctp_chunk
*asconf_ack
= NULL
;
3440 struct sctp_paramhdr
*err_param
= NULL
;
3441 sctp_addiphdr_t
*hdr
;
3442 union sctp_addr_param
*addr_param
;
3446 if (!sctp_vtag_verify(chunk
, asoc
)) {
3447 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3449 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3452 /* ADD-IP: Section 4.1.1
3453 * This chunk MUST be sent in an authenticated way by using
3454 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3455 * is received unauthenticated it MUST be silently discarded as
3456 * described in [I-D.ietf-tsvwg-sctp-auth].
3458 if (!sctp_addip_noauth
&& !chunk
->auth
)
3459 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3461 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3462 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3463 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3466 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3467 serial
= ntohl(hdr
->serial
);
3469 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3470 length
= ntohs(addr_param
->p
.length
);
3471 if (length
< sizeof(sctp_paramhdr_t
))
3472 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3473 (void *)addr_param
, commands
);
3475 /* Verify the ASCONF chunk before processing it. */
3476 if (!sctp_verify_asconf(asoc
,
3477 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3478 (void *)chunk
->chunk_end
,
3480 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3481 (void *)err_param
, commands
);
3483 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3484 * the endpoint stored in a new association variable
3485 * 'Peer-Serial-Number'.
3487 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3488 /* If this is the first instance of ASCONF in the packet,
3489 * we can clean our old ASCONF-ACKs.
3491 if (!chunk
->has_asconf
)
3492 sctp_assoc_clean_asconf_ack_cache(asoc
);
3494 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3495 * expected, process the ASCONF as described below and after
3496 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3497 * the response packet and cache a copy of it (in the event it
3498 * later needs to be retransmitted).
3500 * Essentially, do V1-V5.
3502 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3505 return SCTP_DISPOSITION_NOMEM
;
3506 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3508 * If the value found in the Sequence Number is less than the
3509 * ('Peer- Sequence-Number' + 1), simply skip to the next
3510 * ASCONF, and include in the outbound response packet
3511 * any previously cached ASCONF-ACK response that was
3512 * sent and saved that matches the Sequence Number of the
3513 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3514 * Chunk exists. This will occur when an older ASCONF
3515 * arrives out of order. In such a case, the receiver
3516 * should skip the ASCONF Chunk and not include ASCONF-ACK
3517 * Chunk for that chunk.
3519 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3521 return SCTP_DISPOSITION_DISCARD
;
3523 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3524 * it must be either a stale packet or from an attacker.
3526 return SCTP_DISPOSITION_DISCARD
;
3529 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3530 * containing the ASCONF-ACK Chunks MUST be the source address of
3531 * the SCTP packet that held the ASCONF Chunks.
3533 * To do this properly, we'll set the destination address of the chunk
3534 * and at the transmit time, will try look up the transport to use.
3535 * Since ASCONFs may be bundled, the correct transport may not be
3536 * created untill we process the entire packet, thus this workaround.
3538 asconf_ack
->dest
= chunk
->source
;
3539 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3541 return SCTP_DISPOSITION_CONSUME
;
3545 * ADDIP Section 4.3 General rules for address manipulation
3546 * When building TLV parameters for the ASCONF Chunk that will add or
3547 * delete IP addresses the D0 to D13 rules should be applied:
3549 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3550 const struct sctp_association
*asoc
,
3551 const sctp_subtype_t type
, void *arg
,
3552 sctp_cmd_seq_t
*commands
)
3554 struct sctp_chunk
*asconf_ack
= arg
;
3555 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3556 struct sctp_chunk
*abort
;
3557 struct sctp_paramhdr
*err_param
= NULL
;
3558 sctp_addiphdr_t
*addip_hdr
;
3559 __u32 sent_serial
, rcvd_serial
;
3561 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3562 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3564 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3567 /* ADD-IP, Section 4.1.2:
3568 * This chunk MUST be sent in an authenticated way by using
3569 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3570 * is received unauthenticated it MUST be silently discarded as
3571 * described in [I-D.ietf-tsvwg-sctp-auth].
3573 if (!sctp_addip_noauth
&& !asconf_ack
->auth
)
3574 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3576 /* Make sure that the ADDIP chunk has a valid length. */
3577 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3578 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3581 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3582 rcvd_serial
= ntohl(addip_hdr
->serial
);
3584 /* Verify the ASCONF-ACK chunk before processing it. */
3585 if (!sctp_verify_asconf(asoc
,
3586 (sctp_paramhdr_t
*)addip_hdr
->params
,
3587 (void *)asconf_ack
->chunk_end
,
3589 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3590 (void *)err_param
, commands
);
3593 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3594 sent_serial
= ntohl(addip_hdr
->serial
);
3596 sent_serial
= asoc
->addip_serial
- 1;
3599 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3600 * equal to the next serial number to be used but no ASCONF chunk is
3601 * outstanding the endpoint MUST ABORT the association. Note that a
3602 * sequence number is greater than if it is no more than 2^^31-1
3603 * larger than the current sequence number (using serial arithmetic).
3605 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3606 !(asoc
->addip_last_asconf
)) {
3607 abort
= sctp_make_abort(asoc
, asconf_ack
,
3608 sizeof(sctp_errhdr_t
));
3610 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3611 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3614 /* We are going to ABORT, so we might as well stop
3615 * processing the rest of the chunks in the packet.
3617 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3618 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3619 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3620 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3621 SCTP_ERROR(ECONNABORTED
));
3622 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3623 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3624 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3625 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3626 return SCTP_DISPOSITION_ABORT
;
3629 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3630 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3631 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3633 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3635 return SCTP_DISPOSITION_CONSUME
;
3637 abort
= sctp_make_abort(asoc
, asconf_ack
,
3638 sizeof(sctp_errhdr_t
));
3640 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3641 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3644 /* We are going to ABORT, so we might as well stop
3645 * processing the rest of the chunks in the packet.
3647 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3648 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3649 SCTP_ERROR(ECONNABORTED
));
3650 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3651 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3652 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3653 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3654 return SCTP_DISPOSITION_ABORT
;
3657 return SCTP_DISPOSITION_DISCARD
;
3661 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3663 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3664 * its cumulative TSN point to the value carried in the FORWARD TSN
3665 * chunk, and then MUST further advance its cumulative TSN point locally
3667 * After the above processing, the data receiver MUST stop reporting any
3668 * missing TSNs earlier than or equal to the new cumulative TSN point.
3670 * Verification Tag: 8.5 Verification Tag [Normal verification]
3672 * The return value is the disposition of the chunk.
3674 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3675 const struct sctp_association
*asoc
,
3676 const sctp_subtype_t type
,
3678 sctp_cmd_seq_t
*commands
)
3680 struct sctp_chunk
*chunk
= arg
;
3681 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3682 struct sctp_fwdtsn_skip
*skip
;
3686 if (!sctp_vtag_verify(chunk
, asoc
)) {
3687 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3689 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3692 /* Make sure that the FORWARD_TSN chunk has valid length. */
3693 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3694 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3697 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3698 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3699 len
= ntohs(chunk
->chunk_hdr
->length
);
3700 len
-= sizeof(struct sctp_chunkhdr
);
3701 skb_pull(chunk
->skb
, len
);
3703 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3704 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3706 /* The TSN is too high--silently discard the chunk and count on it
3707 * getting retransmitted later.
3709 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3710 goto discard_noforce
;
3712 /* Silently discard the chunk if stream-id is not valid */
3713 sctp_walk_fwdtsn(skip
, chunk
) {
3714 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3715 goto discard_noforce
;
3718 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3719 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3720 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3723 /* Count this as receiving DATA. */
3724 if (asoc
->autoclose
) {
3725 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3726 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3729 /* FIXME: For now send a SACK, but DATA processing may
3732 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3734 return SCTP_DISPOSITION_CONSUME
;
3737 return SCTP_DISPOSITION_DISCARD
;
3740 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3741 const struct sctp_endpoint
*ep
,
3742 const struct sctp_association
*asoc
,
3743 const sctp_subtype_t type
,
3745 sctp_cmd_seq_t
*commands
)
3747 struct sctp_chunk
*chunk
= arg
;
3748 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3749 struct sctp_fwdtsn_skip
*skip
;
3753 if (!sctp_vtag_verify(chunk
, asoc
)) {
3754 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3756 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3759 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3760 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3761 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3764 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3765 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3766 len
= ntohs(chunk
->chunk_hdr
->length
);
3767 len
-= sizeof(struct sctp_chunkhdr
);
3768 skb_pull(chunk
->skb
, len
);
3770 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3771 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3773 /* The TSN is too high--silently discard the chunk and count on it
3774 * getting retransmitted later.
3776 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3779 /* Silently discard the chunk if stream-id is not valid */
3780 sctp_walk_fwdtsn(skip
, chunk
) {
3781 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3785 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3786 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3787 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3790 /* Go a head and force a SACK, since we are shutting down. */
3792 /* Implementor's Guide.
3794 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3795 * respond to each received packet containing one or more DATA chunk(s)
3796 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3798 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3799 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3800 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3801 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3803 return SCTP_DISPOSITION_CONSUME
;
3807 * SCTP-AUTH Section 6.3 Receving authenticated chukns
3809 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3810 * Identifier field. If this algorithm was not specified by the
3811 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3812 * during association setup, the AUTH chunk and all chunks after it MUST
3813 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3814 * defined in Section 4.1.
3816 * If an endpoint with no shared key receives a Shared Key Identifier
3817 * other than 0, it MUST silently discard all authenticated chunks. If
3818 * the endpoint has at least one endpoint pair shared key for the peer,
3819 * it MUST use the key specified by the Shared Key Identifier if a
3820 * key has been configured for that Shared Key Identifier. If no
3821 * endpoint pair shared key has been configured for that Shared Key
3822 * Identifier, all authenticated chunks MUST be silently discarded.
3824 * Verification Tag: 8.5 Verification Tag [Normal verification]
3826 * The return value is the disposition of the chunk.
3828 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
3829 const struct sctp_association
*asoc
,
3830 const sctp_subtype_t type
,
3831 struct sctp_chunk
*chunk
)
3833 struct sctp_authhdr
*auth_hdr
;
3834 struct sctp_hmac
*hmac
;
3835 unsigned int sig_len
;
3840 /* Pull in the auth header, so we can do some more verification */
3841 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3842 chunk
->subh
.auth_hdr
= auth_hdr
;
3843 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
3845 /* Make sure that we suport the HMAC algorithm from the auth
3848 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
3849 return SCTP_IERROR_AUTH_BAD_HMAC
;
3851 /* Make sure that the provided shared key identifier has been
3854 key_id
= ntohs(auth_hdr
->shkey_id
);
3855 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
3856 return SCTP_IERROR_AUTH_BAD_KEYID
;
3859 /* Make sure that the length of the signature matches what
3862 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
3863 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
3864 if (sig_len
!= hmac
->hmac_len
)
3865 return SCTP_IERROR_PROTO_VIOLATION
;
3867 /* Now that we've done validation checks, we can compute and
3868 * verify the hmac. The steps involved are:
3869 * 1. Save the digest from the chunk.
3870 * 2. Zero out the digest in the chunk.
3871 * 3. Compute the new digest
3872 * 4. Compare saved and new digests.
3874 digest
= auth_hdr
->hmac
;
3875 skb_pull(chunk
->skb
, sig_len
);
3877 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
3881 memset(digest
, 0, sig_len
);
3883 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
3884 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
3887 /* Discard the packet if the digests do not match */
3888 if (memcmp(save_digest
, digest
, sig_len
)) {
3890 return SCTP_IERROR_BAD_SIG
;
3896 return SCTP_IERROR_NO_ERROR
;
3898 return SCTP_IERROR_NOMEM
;
3901 sctp_disposition_t
sctp_sf_eat_auth(const struct sctp_endpoint
*ep
,
3902 const struct sctp_association
*asoc
,
3903 const sctp_subtype_t type
,
3905 sctp_cmd_seq_t
*commands
)
3907 struct sctp_authhdr
*auth_hdr
;
3908 struct sctp_chunk
*chunk
= arg
;
3909 struct sctp_chunk
*err_chunk
;
3910 sctp_ierror_t error
;
3912 /* Make sure that the peer has AUTH capable */
3913 if (!asoc
->peer
.auth_capable
)
3914 return sctp_sf_unk_chunk(ep
, asoc
, type
, arg
, commands
);
3916 if (!sctp_vtag_verify(chunk
, asoc
)) {
3917 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3919 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3922 /* Make sure that the AUTH chunk has valid length. */
3923 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
3924 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3927 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3928 error
= sctp_sf_authenticate(ep
, asoc
, type
, chunk
);
3930 case SCTP_IERROR_AUTH_BAD_HMAC
:
3931 /* Generate the ERROR chunk and discard the rest
3934 err_chunk
= sctp_make_op_error(asoc
, chunk
,
3935 SCTP_ERROR_UNSUP_HMAC
,
3939 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3940 SCTP_CHUNK(err_chunk
));
3943 case SCTP_IERROR_AUTH_BAD_KEYID
:
3944 case SCTP_IERROR_BAD_SIG
:
3945 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3947 case SCTP_IERROR_PROTO_VIOLATION
:
3948 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3951 case SCTP_IERROR_NOMEM
:
3952 return SCTP_DISPOSITION_NOMEM
;
3957 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
3958 struct sctp_ulpevent
*ev
;
3960 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
3961 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
3966 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3970 return SCTP_DISPOSITION_CONSUME
;
3974 * Process an unknown chunk.
3976 * Section: 3.2. Also, 2.1 in the implementor's guide.
3978 * Chunk Types are encoded such that the highest-order two bits specify
3979 * the action that must be taken if the processing endpoint does not
3980 * recognize the Chunk Type.
3982 * 00 - Stop processing this SCTP packet and discard it, do not process
3983 * any further chunks within it.
3985 * 01 - Stop processing this SCTP packet and discard it, do not process
3986 * any further chunks within it, and report the unrecognized
3987 * chunk in an 'Unrecognized Chunk Type'.
3989 * 10 - Skip this chunk and continue processing.
3991 * 11 - Skip this chunk and continue processing, but report in an ERROR
3992 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3994 * The return value is the disposition of the chunk.
3996 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
3997 const struct sctp_association
*asoc
,
3998 const sctp_subtype_t type
,
4000 sctp_cmd_seq_t
*commands
)
4002 struct sctp_chunk
*unk_chunk
= arg
;
4003 struct sctp_chunk
*err_chunk
;
4004 sctp_chunkhdr_t
*hdr
;
4006 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
4008 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4009 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4011 /* Make sure that the chunk has a valid length.
4012 * Since we don't know the chunk type, we use a general
4013 * chunkhdr structure to make a comparison.
4015 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4016 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4019 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4020 case SCTP_CID_ACTION_DISCARD
:
4021 /* Discard the packet. */
4022 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4024 case SCTP_CID_ACTION_DISCARD_ERR
:
4025 /* Generate an ERROR chunk as response. */
4026 hdr
= unk_chunk
->chunk_hdr
;
4027 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4028 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4029 WORD_ROUND(ntohs(hdr
->length
)));
4031 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4032 SCTP_CHUNK(err_chunk
));
4035 /* Discard the packet. */
4036 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4037 return SCTP_DISPOSITION_CONSUME
;
4039 case SCTP_CID_ACTION_SKIP
:
4040 /* Skip the chunk. */
4041 return SCTP_DISPOSITION_DISCARD
;
4043 case SCTP_CID_ACTION_SKIP_ERR
:
4044 /* Generate an ERROR chunk as response. */
4045 hdr
= unk_chunk
->chunk_hdr
;
4046 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4047 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4048 WORD_ROUND(ntohs(hdr
->length
)));
4050 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4051 SCTP_CHUNK(err_chunk
));
4053 /* Skip the chunk. */
4054 return SCTP_DISPOSITION_CONSUME
;
4060 return SCTP_DISPOSITION_DISCARD
;
4064 * Discard the chunk.
4066 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4067 * [Too numerous to mention...]
4068 * Verification Tag: No verification needed.
4070 * (endpoint, asoc, chunk)
4073 * (asoc, reply_msg, msg_up, timers, counters)
4075 * The return value is the disposition of the chunk.
4077 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
4078 const struct sctp_association
*asoc
,
4079 const sctp_subtype_t type
,
4081 sctp_cmd_seq_t
*commands
)
4083 struct sctp_chunk
*chunk
= arg
;
4085 /* Make sure that the chunk has a valid length.
4086 * Since we don't know the chunk type, we use a general
4087 * chunkhdr structure to make a comparison.
4089 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4090 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4093 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
4094 return SCTP_DISPOSITION_DISCARD
;
4098 * Discard the whole packet.
4102 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4103 * silently discard the OOTB packet and take no further action.
4105 * Verification Tag: No verification necessary
4108 * (endpoint, asoc, chunk)
4111 * (asoc, reply_msg, msg_up, timers, counters)
4113 * The return value is the disposition of the chunk.
4115 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
4116 const struct sctp_association
*asoc
,
4117 const sctp_subtype_t type
,
4119 sctp_cmd_seq_t
*commands
)
4121 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS
);
4122 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4124 return SCTP_DISPOSITION_CONSUME
;
4129 * The other end is violating protocol.
4131 * Section: Not specified
4132 * Verification Tag: Not specified
4134 * (endpoint, asoc, chunk)
4137 * (asoc, reply_msg, msg_up, timers, counters)
4139 * We simply tag the chunk as a violation. The state machine will log
4140 * the violation and continue.
4142 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
4143 const struct sctp_association
*asoc
,
4144 const sctp_subtype_t type
,
4146 sctp_cmd_seq_t
*commands
)
4148 struct sctp_chunk
*chunk
= arg
;
4150 /* Make sure that the chunk has a valid length. */
4151 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4152 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4155 return SCTP_DISPOSITION_VIOLATION
;
4159 * Common function to handle a protocol violation.
4161 static sctp_disposition_t
sctp_sf_abort_violation(
4162 const struct sctp_endpoint
*ep
,
4163 const struct sctp_association
*asoc
,
4165 sctp_cmd_seq_t
*commands
,
4166 const __u8
*payload
,
4167 const size_t paylen
)
4169 struct sctp_packet
*packet
= NULL
;
4170 struct sctp_chunk
*chunk
= arg
;
4171 struct sctp_chunk
*abort
= NULL
;
4173 /* SCTP-AUTH, Section 6.3:
4174 * It should be noted that if the receiver wants to tear
4175 * down an association in an authenticated way only, the
4176 * handling of malformed packets should not result in
4177 * tearing down the association.
4179 * This means that if we only want to abort associations
4180 * in an authenticated way (i.e AUTH+ABORT), then we
4181 * can't destroy this association just becuase the packet
4184 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4187 /* Make the abort chunk. */
4188 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4193 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4194 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4195 !asoc
->peer
.i
.init_tag
) {
4196 sctp_initack_chunk_t
*initack
;
4198 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4199 if (!sctp_chunk_length_valid(chunk
,
4200 sizeof(sctp_initack_chunk_t
)))
4201 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4203 unsigned int inittag
;
4205 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4206 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4211 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4212 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4214 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4215 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4216 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4217 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4218 SCTP_ERROR(ECONNREFUSED
));
4219 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4220 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4222 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4223 SCTP_ERROR(ECONNABORTED
));
4224 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4225 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4226 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4229 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
4234 if (sctp_test_T_bit(abort
))
4235 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4237 abort
->skb
->sk
= ep
->base
.sk
;
4239 sctp_packet_append_chunk(packet
, abort
);
4241 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4242 SCTP_PACKET(packet
));
4244 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4247 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4250 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4251 return SCTP_DISPOSITION_ABORT
;
4254 sctp_chunk_free(abort
);
4256 return SCTP_DISPOSITION_NOMEM
;
4260 * Handle a protocol violation when the chunk length is invalid.
4261 * "Invalid" length is identified as smaller than the minimal length a
4262 * given chunk can be. For example, a SACK chunk has invalid length
4263 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4265 * We inform the other end by sending an ABORT with a Protocol Violation
4268 * Section: Not specified
4269 * Verification Tag: Nothing to do
4271 * (endpoint, asoc, chunk)
4274 * (reply_msg, msg_up, counters)
4276 * Generate an ABORT chunk and terminate the association.
4278 static sctp_disposition_t
sctp_sf_violation_chunklen(
4279 const struct sctp_endpoint
*ep
,
4280 const struct sctp_association
*asoc
,
4281 const sctp_subtype_t type
,
4283 sctp_cmd_seq_t
*commands
)
4285 static const char err_str
[]="The following chunk had invalid length:";
4287 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4292 * Handle a protocol violation when the parameter length is invalid.
4293 * "Invalid" length is identified as smaller than the minimal length a
4294 * given parameter can be.
4296 static sctp_disposition_t
sctp_sf_violation_paramlen(
4297 const struct sctp_endpoint
*ep
,
4298 const struct sctp_association
*asoc
,
4299 const sctp_subtype_t type
,
4300 void *arg
, void *ext
,
4301 sctp_cmd_seq_t
*commands
)
4303 struct sctp_chunk
*chunk
= arg
;
4304 struct sctp_paramhdr
*param
= ext
;
4305 struct sctp_chunk
*abort
= NULL
;
4307 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4310 /* Make the abort chunk. */
4311 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4315 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4316 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4318 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4319 SCTP_ERROR(ECONNABORTED
));
4320 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4321 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4322 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4323 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4326 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4327 return SCTP_DISPOSITION_ABORT
;
4329 return SCTP_DISPOSITION_NOMEM
;
4332 /* Handle a protocol violation when the peer trying to advance the
4333 * cumulative tsn ack to a point beyond the max tsn currently sent.
4335 * We inform the other end by sending an ABORT with a Protocol Violation
4338 static sctp_disposition_t
sctp_sf_violation_ctsn(
4339 const struct sctp_endpoint
*ep
,
4340 const struct sctp_association
*asoc
,
4341 const sctp_subtype_t type
,
4343 sctp_cmd_seq_t
*commands
)
4345 static const char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4347 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4351 /* Handle protocol violation of an invalid chunk bundling. For example,
4352 * when we have an association and we recieve bundled INIT-ACK, or
4353 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4354 * statement from the specs. Additinally, there might be an attacker
4355 * on the path and we may not want to continue this communication.
4357 static sctp_disposition_t
sctp_sf_violation_chunk(
4358 const struct sctp_endpoint
*ep
,
4359 const struct sctp_association
*asoc
,
4360 const sctp_subtype_t type
,
4362 sctp_cmd_seq_t
*commands
)
4364 static const char err_str
[]="The following chunk violates protocol:";
4367 return sctp_sf_violation(ep
, asoc
, type
, arg
, commands
);
4369 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4372 /***************************************************************************
4373 * These are the state functions for handling primitive (Section 10) events.
4374 ***************************************************************************/
4376 * sctp_sf_do_prm_asoc
4378 * Section: 10.1 ULP-to-SCTP
4381 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4382 * outbound stream count)
4383 * -> association id [,destination transport addr list] [,outbound stream
4386 * This primitive allows the upper layer to initiate an association to a
4387 * specific peer endpoint.
4389 * The peer endpoint shall be specified by one of the transport addresses
4390 * which defines the endpoint (see Section 1.4). If the local SCTP
4391 * instance has not been initialized, the ASSOCIATE is considered an
4393 * [This is not relevant for the kernel implementation since we do all
4394 * initialization at boot time. It we hadn't initialized we wouldn't
4395 * get anywhere near this code.]
4397 * An association id, which is a local handle to the SCTP association,
4398 * will be returned on successful establishment of the association. If
4399 * SCTP is not able to open an SCTP association with the peer endpoint,
4400 * an error is returned.
4401 * [In the kernel implementation, the struct sctp_association needs to
4402 * be created BEFORE causing this primitive to run.]
4404 * Other association parameters may be returned, including the
4405 * complete destination transport addresses of the peer as well as the
4406 * outbound stream count of the local endpoint. One of the transport
4407 * address from the returned destination addresses will be selected by
4408 * the local endpoint as default primary path for sending SCTP packets
4409 * to this peer. The returned "destination transport addr list" can
4410 * be used by the ULP to change the default primary path or to force
4411 * sending a packet to a specific transport address. [All of this
4412 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4415 * Mandatory attributes:
4417 * o local SCTP instance name - obtained from the INITIALIZE operation.
4418 * [This is the argument asoc.]
4419 * o destination transport addr - specified as one of the transport
4420 * addresses of the peer endpoint with which the association is to be
4422 * [This is asoc->peer.active_path.]
4423 * o outbound stream count - the number of outbound streams the ULP
4424 * would like to open towards this peer endpoint.
4425 * [BUG: This is not currently implemented.]
4426 * Optional attributes:
4430 * The return value is a disposition.
4432 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
4433 const struct sctp_association
*asoc
,
4434 const sctp_subtype_t type
,
4436 sctp_cmd_seq_t
*commands
)
4438 struct sctp_chunk
*repl
;
4439 struct sctp_association
* my_asoc
;
4441 /* The comment below says that we enter COOKIE-WAIT AFTER
4442 * sending the INIT, but that doesn't actually work in our
4445 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4446 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4448 /* RFC 2960 5.1 Normal Establishment of an Association
4450 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4451 * must provide its Verification Tag (Tag_A) in the Initiate
4452 * Tag field. Tag_A SHOULD be a random number in the range of
4453 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4456 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4460 /* Cast away the const modifier, as we want to just
4461 * rerun it through as a sideffect.
4463 my_asoc
= (struct sctp_association
*)asoc
;
4464 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4466 /* Choose transport for INIT. */
4467 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4470 /* After sending the INIT, "A" starts the T1-init timer and
4471 * enters the COOKIE-WAIT state.
4473 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4474 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4475 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4476 return SCTP_DISPOSITION_CONSUME
;
4479 return SCTP_DISPOSITION_NOMEM
;
4483 * Process the SEND primitive.
4485 * Section: 10.1 ULP-to-SCTP
4488 * Format: SEND(association id, buffer address, byte count [,context]
4489 * [,stream id] [,life time] [,destination transport address]
4490 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4493 * This is the main method to send user data via SCTP.
4495 * Mandatory attributes:
4497 * o association id - local handle to the SCTP association
4499 * o buffer address - the location where the user message to be
4500 * transmitted is stored;
4502 * o byte count - The size of the user data in number of bytes;
4504 * Optional attributes:
4506 * o context - an optional 32 bit integer that will be carried in the
4507 * sending failure notification to the ULP if the transportation of
4508 * this User Message fails.
4510 * o stream id - to indicate which stream to send the data on. If not
4511 * specified, stream 0 will be used.
4513 * o life time - specifies the life time of the user data. The user data
4514 * will not be sent by SCTP after the life time expires. This
4515 * parameter can be used to avoid efforts to transmit stale
4516 * user messages. SCTP notifies the ULP if the data cannot be
4517 * initiated to transport (i.e. sent to the destination via SCTP's
4518 * send primitive) within the life time variable. However, the
4519 * user data will be transmitted if SCTP has attempted to transmit a
4520 * chunk before the life time expired.
4522 * o destination transport address - specified as one of the destination
4523 * transport addresses of the peer endpoint to which this packet
4524 * should be sent. Whenever possible, SCTP should use this destination
4525 * transport address for sending the packets, instead of the current
4528 * o unorder flag - this flag, if present, indicates that the user
4529 * would like the data delivered in an unordered fashion to the peer
4530 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4533 * o no-bundle flag - instructs SCTP not to bundle this user data with
4534 * other outbound DATA chunks. SCTP MAY still bundle even when
4535 * this flag is present, when faced with network congestion.
4537 * o payload protocol-id - A 32 bit unsigned integer that is to be
4538 * passed to the peer indicating the type of payload protocol data
4539 * being transmitted. This value is passed as opaque data by SCTP.
4541 * The return value is the disposition.
4543 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
4544 const struct sctp_association
*asoc
,
4545 const sctp_subtype_t type
,
4547 sctp_cmd_seq_t
*commands
)
4549 struct sctp_chunk
*chunk
= arg
;
4551 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4552 return SCTP_DISPOSITION_CONSUME
;
4556 * Process the SHUTDOWN primitive.
4561 * Format: SHUTDOWN(association id)
4564 * Gracefully closes an association. Any locally queued user data
4565 * will be delivered to the peer. The association will be terminated only
4566 * after the peer acknowledges all the SCTP packets sent. A success code
4567 * will be returned on successful termination of the association. If
4568 * attempting to terminate the association results in a failure, an error
4569 * code shall be returned.
4571 * Mandatory attributes:
4573 * o association id - local handle to the SCTP association
4575 * Optional attributes:
4579 * The return value is the disposition.
4581 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4582 const struct sctp_endpoint
*ep
,
4583 const struct sctp_association
*asoc
,
4584 const sctp_subtype_t type
,
4586 sctp_cmd_seq_t
*commands
)
4590 /* From 9.2 Shutdown of an Association
4591 * Upon receipt of the SHUTDOWN primitive from its upper
4592 * layer, the endpoint enters SHUTDOWN-PENDING state and
4593 * remains there until all outstanding data has been
4594 * acknowledged by its peer. The endpoint accepts no new data
4595 * from its upper layer, but retransmits data to the far end
4596 * if necessary to fill gaps.
4598 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4599 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4601 disposition
= SCTP_DISPOSITION_CONSUME
;
4602 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4603 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4610 * Process the ABORT primitive.
4615 * Format: Abort(association id [, cause code])
4618 * Ungracefully closes an association. Any locally queued user data
4619 * will be discarded and an ABORT chunk is sent to the peer. A success code
4620 * will be returned on successful abortion of the association. If
4621 * attempting to abort the association results in a failure, an error
4622 * code shall be returned.
4624 * Mandatory attributes:
4626 * o association id - local handle to the SCTP association
4628 * Optional attributes:
4630 * o cause code - reason of the abort to be passed to the peer
4634 * The return value is the disposition.
4636 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4637 const struct sctp_endpoint
*ep
,
4638 const struct sctp_association
*asoc
,
4639 const sctp_subtype_t type
,
4641 sctp_cmd_seq_t
*commands
)
4643 /* From 9.1 Abort of an Association
4644 * Upon receipt of the ABORT primitive from its upper
4645 * layer, the endpoint enters CLOSED state and
4646 * discard all outstanding data has been
4647 * acknowledged by its peer. The endpoint accepts no new data
4648 * from its upper layer, but retransmits data to the far end
4649 * if necessary to fill gaps.
4651 struct sctp_chunk
*abort
= arg
;
4652 sctp_disposition_t retval
;
4654 retval
= SCTP_DISPOSITION_CONSUME
;
4656 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4658 /* Even if we can't send the ABORT due to low memory delete the
4659 * TCB. This is a departure from our typical NOMEM handling.
4662 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4663 SCTP_ERROR(ECONNABORTED
));
4664 /* Delete the established association. */
4665 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4666 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4668 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4669 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4674 /* We tried an illegal operation on an association which is closed. */
4675 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4676 const struct sctp_association
*asoc
,
4677 const sctp_subtype_t type
,
4679 sctp_cmd_seq_t
*commands
)
4681 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4682 return SCTP_DISPOSITION_CONSUME
;
4685 /* We tried an illegal operation on an association which is shutting
4688 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4689 const struct sctp_association
*asoc
,
4690 const sctp_subtype_t type
,
4692 sctp_cmd_seq_t
*commands
)
4694 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4695 SCTP_ERROR(-ESHUTDOWN
));
4696 return SCTP_DISPOSITION_CONSUME
;
4700 * sctp_cookie_wait_prm_shutdown
4702 * Section: 4 Note: 2
4707 * The RFC does not explicitly address this issue, but is the route through the
4708 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4713 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4714 const struct sctp_endpoint
*ep
,
4715 const struct sctp_association
*asoc
,
4716 const sctp_subtype_t type
,
4718 sctp_cmd_seq_t
*commands
)
4720 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4721 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4723 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4724 SCTP_STATE(SCTP_STATE_CLOSED
));
4726 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
4728 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4730 return SCTP_DISPOSITION_DELETE_TCB
;
4734 * sctp_cookie_echoed_prm_shutdown
4736 * Section: 4 Note: 2
4741 * The RFC does not explcitly address this issue, but is the route through the
4742 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4747 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4748 const struct sctp_endpoint
*ep
,
4749 const struct sctp_association
*asoc
,
4750 const sctp_subtype_t type
,
4751 void *arg
, sctp_cmd_seq_t
*commands
)
4753 /* There is a single T1 timer, so we should be able to use
4754 * common function with the COOKIE-WAIT state.
4756 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4760 * sctp_sf_cookie_wait_prm_abort
4762 * Section: 4 Note: 2
4767 * The RFC does not explicitly address this issue, but is the route through the
4768 * state table when someone issues an abort while in COOKIE_WAIT state.
4773 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4774 const struct sctp_endpoint
*ep
,
4775 const struct sctp_association
*asoc
,
4776 const sctp_subtype_t type
,
4778 sctp_cmd_seq_t
*commands
)
4780 struct sctp_chunk
*abort
= arg
;
4781 sctp_disposition_t retval
;
4783 /* Stop T1-init timer */
4784 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4785 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4786 retval
= SCTP_DISPOSITION_CONSUME
;
4788 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4790 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4791 SCTP_STATE(SCTP_STATE_CLOSED
));
4793 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4795 /* Even if we can't send the ABORT due to low memory delete the
4796 * TCB. This is a departure from our typical NOMEM handling.
4799 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4800 SCTP_ERROR(ECONNREFUSED
));
4801 /* Delete the established association. */
4802 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4803 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4809 * sctp_sf_cookie_echoed_prm_abort
4811 * Section: 4 Note: 3
4816 * The RFC does not explcitly address this issue, but is the route through the
4817 * state table when someone issues an abort while in COOKIE_ECHOED state.
4822 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4823 const struct sctp_endpoint
*ep
,
4824 const struct sctp_association
*asoc
,
4825 const sctp_subtype_t type
,
4827 sctp_cmd_seq_t
*commands
)
4829 /* There is a single T1 timer, so we should be able to use
4830 * common function with the COOKIE-WAIT state.
4832 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4836 * sctp_sf_shutdown_pending_prm_abort
4841 * The RFC does not explicitly address this issue, but is the route through the
4842 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4847 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4848 const struct sctp_endpoint
*ep
,
4849 const struct sctp_association
*asoc
,
4850 const sctp_subtype_t type
,
4852 sctp_cmd_seq_t
*commands
)
4854 /* Stop the T5-shutdown guard timer. */
4855 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4856 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4858 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4862 * sctp_sf_shutdown_sent_prm_abort
4867 * The RFC does not explicitly address this issue, but is the route through the
4868 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4873 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
4874 const struct sctp_endpoint
*ep
,
4875 const struct sctp_association
*asoc
,
4876 const sctp_subtype_t type
,
4878 sctp_cmd_seq_t
*commands
)
4880 /* Stop the T2-shutdown timer. */
4881 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4882 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4884 /* Stop the T5-shutdown guard timer. */
4885 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4886 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4888 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4892 * sctp_sf_cookie_echoed_prm_abort
4897 * The RFC does not explcitly address this issue, but is the route through the
4898 * state table when someone issues an abort while in COOKIE_ECHOED state.
4903 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
4904 const struct sctp_endpoint
*ep
,
4905 const struct sctp_association
*asoc
,
4906 const sctp_subtype_t type
,
4908 sctp_cmd_seq_t
*commands
)
4910 /* The same T2 timer, so we should be able to use
4911 * common function with the SHUTDOWN-SENT state.
4913 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
4917 * Process the REQUESTHEARTBEAT primitive
4920 * J) Request Heartbeat
4922 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4926 * Instructs the local endpoint to perform a HeartBeat on the specified
4927 * destination transport address of the given association. The returned
4928 * result should indicate whether the transmission of the HEARTBEAT
4929 * chunk to the destination address is successful.
4931 * Mandatory attributes:
4933 * o association id - local handle to the SCTP association
4935 * o destination transport address - the transport address of the
4936 * association on which a heartbeat should be issued.
4938 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
4939 const struct sctp_endpoint
*ep
,
4940 const struct sctp_association
*asoc
,
4941 const sctp_subtype_t type
,
4943 sctp_cmd_seq_t
*commands
)
4945 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
4946 (struct sctp_transport
*)arg
, commands
))
4947 return SCTP_DISPOSITION_NOMEM
;
4950 * RFC 2960 (bis), section 8.3
4952 * D) Request an on-demand HEARTBEAT on a specific destination
4953 * transport address of a given association.
4955 * The endpoint should increment the respective error counter of
4956 * the destination transport address each time a HEARTBEAT is sent
4957 * to that address and not acknowledged within one RTO.
4960 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
4961 SCTP_TRANSPORT(arg
));
4962 return SCTP_DISPOSITION_CONSUME
;
4966 * ADDIP Section 4.1 ASCONF Chunk Procedures
4967 * When an endpoint has an ASCONF signaled change to be sent to the
4968 * remote endpoint it should do A1 to A9
4970 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
4971 const struct sctp_association
*asoc
,
4972 const sctp_subtype_t type
,
4974 sctp_cmd_seq_t
*commands
)
4976 struct sctp_chunk
*chunk
= arg
;
4978 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4979 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4980 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4981 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4982 return SCTP_DISPOSITION_CONSUME
;
4986 * Ignore the primitive event
4988 * The return value is the disposition of the primitive.
4990 sctp_disposition_t
sctp_sf_ignore_primitive(
4991 const struct sctp_endpoint
*ep
,
4992 const struct sctp_association
*asoc
,
4993 const sctp_subtype_t type
,
4995 sctp_cmd_seq_t
*commands
)
4997 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
4998 return SCTP_DISPOSITION_DISCARD
;
5001 /***************************************************************************
5002 * These are the state functions for the OTHER events.
5003 ***************************************************************************/
5006 * Start the shutdown negotiation.
5009 * Once all its outstanding data has been acknowledged, the endpoint
5010 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5011 * TSN Ack field the last sequential TSN it has received from the peer.
5012 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5013 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5014 * with the updated last sequential TSN received from its peer.
5016 * The return value is the disposition.
5018 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5019 const struct sctp_endpoint
*ep
,
5020 const struct sctp_association
*asoc
,
5021 const sctp_subtype_t type
,
5023 sctp_cmd_seq_t
*commands
)
5025 struct sctp_chunk
*reply
;
5027 /* Once all its outstanding data has been acknowledged, the
5028 * endpoint shall send a SHUTDOWN chunk to its peer including
5029 * in the Cumulative TSN Ack field the last sequential TSN it
5030 * has received from the peer.
5032 reply
= sctp_make_shutdown(asoc
, NULL
);
5036 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5037 * T2-shutdown timer.
5039 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5041 /* It shall then start the T2-shutdown timer */
5042 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5043 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5045 /* RFC 4960 Section 9.2
5046 * The sender of the SHUTDOWN MAY also start an overall guard timer
5047 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5049 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5050 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5052 if (asoc
->autoclose
)
5053 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5054 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5056 /* and enter the SHUTDOWN-SENT state. */
5057 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5058 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5060 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5062 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5065 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5067 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5069 return SCTP_DISPOSITION_CONSUME
;
5072 return SCTP_DISPOSITION_NOMEM
;
5076 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5080 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5081 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5082 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5083 * endpoint must re-send the SHUTDOWN ACK.
5085 * The return value is the disposition.
5087 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5088 const struct sctp_endpoint
*ep
,
5089 const struct sctp_association
*asoc
,
5090 const sctp_subtype_t type
,
5092 sctp_cmd_seq_t
*commands
)
5094 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5095 struct sctp_chunk
*reply
;
5097 /* There are 2 ways of getting here:
5098 * 1) called in response to a SHUTDOWN chunk
5099 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5101 * For the case (2), the arg parameter is set to NULL. We need
5102 * to check that we have a chunk before accessing it's fields.
5105 if (!sctp_vtag_verify(chunk
, asoc
))
5106 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
5108 /* Make sure that the SHUTDOWN chunk has a valid length. */
5109 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5110 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
5114 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5115 * shall send a SHUTDOWN ACK ...
5117 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5121 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5122 * the T2-shutdown timer.
5124 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5126 /* and start/restart a T2-shutdown timer of its own, */
5127 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5128 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5130 if (asoc
->autoclose
)
5131 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5132 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5134 /* Enter the SHUTDOWN-ACK-SENT state. */
5135 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5136 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5138 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5140 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5143 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5145 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5147 return SCTP_DISPOSITION_CONSUME
;
5150 return SCTP_DISPOSITION_NOMEM
;
5154 * Ignore the event defined as other
5156 * The return value is the disposition of the event.
5158 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
5159 const struct sctp_association
*asoc
,
5160 const sctp_subtype_t type
,
5162 sctp_cmd_seq_t
*commands
)
5164 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
5165 return SCTP_DISPOSITION_DISCARD
;
5168 /************************************************************
5169 * These are the state functions for handling timeout events.
5170 ************************************************************/
5175 * Section: 6.3.3 Handle T3-rtx Expiration
5177 * Whenever the retransmission timer T3-rtx expires for a destination
5178 * address, do the following:
5181 * The return value is the disposition of the chunk.
5183 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
5184 const struct sctp_association
*asoc
,
5185 const sctp_subtype_t type
,
5187 sctp_cmd_seq_t
*commands
)
5189 struct sctp_transport
*transport
= arg
;
5191 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS
);
5193 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5194 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5195 SCTP_ERROR(ETIMEDOUT
));
5196 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5197 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5198 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5199 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5200 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5201 return SCTP_DISPOSITION_DELETE_TCB
;
5204 /* E1) For the destination address for which the timer
5205 * expires, adjust its ssthresh with rules defined in Section
5206 * 7.2.3 and set the cwnd <- MTU.
5209 /* E2) For the destination address for which the timer
5210 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5211 * maximum value discussed in rule C7 above (RTO.max) may be
5212 * used to provide an upper bound to this doubling operation.
5215 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5216 * outstanding DATA chunks for the address for which the
5217 * T3-rtx has expired will fit into a single packet, subject
5218 * to the MTU constraint for the path corresponding to the
5219 * destination transport address to which the retransmission
5220 * is being sent (this may be different from the address for
5221 * which the timer expires [see Section 6.4]). Call this
5222 * value K. Bundle and retransmit those K DATA chunks in a
5223 * single packet to the destination endpoint.
5225 * Note: Any DATA chunks that were sent to the address for
5226 * which the T3-rtx timer expired but did not fit in one MTU
5227 * (rule E3 above), should be marked for retransmission and
5228 * sent as soon as cwnd allows (normally when a SACK arrives).
5231 /* Do some failure management (Section 8.2). */
5232 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5234 /* NB: Rules E4 and F1 are implicit in R1. */
5235 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5237 return SCTP_DISPOSITION_CONSUME
;
5241 * Generate delayed SACK on timeout
5243 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5245 * The guidelines on delayed acknowledgement algorithm specified in
5246 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5247 * acknowledgement SHOULD be generated for at least every second packet
5248 * (not every second DATA chunk) received, and SHOULD be generated
5249 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5250 * some situations it may be beneficial for an SCTP transmitter to be
5251 * more conservative than the algorithms detailed in this document
5252 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5253 * the following algorithms allow.
5255 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
5256 const struct sctp_association
*asoc
,
5257 const sctp_subtype_t type
,
5259 sctp_cmd_seq_t
*commands
)
5261 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS
);
5262 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5263 return SCTP_DISPOSITION_CONSUME
;
5267 * sctp_sf_t1_init_timer_expire
5269 * Section: 4 Note: 2
5274 * RFC 2960 Section 4 Notes
5275 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5276 * and re-start the T1-init timer without changing state. This MUST
5277 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5278 * endpoint MUST abort the initialization process and report the
5279 * error to SCTP user.
5285 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
5286 const struct sctp_association
*asoc
,
5287 const sctp_subtype_t type
,
5289 sctp_cmd_seq_t
*commands
)
5291 struct sctp_chunk
*repl
= NULL
;
5292 struct sctp_bind_addr
*bp
;
5293 int attempts
= asoc
->init_err_counter
+ 1;
5295 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5296 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS
);
5298 if (attempts
<= asoc
->max_init_attempts
) {
5299 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5300 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5302 return SCTP_DISPOSITION_NOMEM
;
5304 /* Choose transport for INIT. */
5305 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5308 /* Issue a sideeffect to do the needed accounting. */
5309 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5310 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5312 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5314 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5315 " max_init_attempts: %d\n",
5316 attempts
, asoc
->max_init_attempts
);
5317 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5318 SCTP_ERROR(ETIMEDOUT
));
5319 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5320 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5321 return SCTP_DISPOSITION_DELETE_TCB
;
5324 return SCTP_DISPOSITION_CONSUME
;
5328 * sctp_sf_t1_cookie_timer_expire
5330 * Section: 4 Note: 2
5335 * RFC 2960 Section 4 Notes
5336 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5337 * COOKIE ECHO and re-start the T1-cookie timer without changing
5338 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5339 * After that, the endpoint MUST abort the initialization process and
5340 * report the error to SCTP user.
5346 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
5347 const struct sctp_association
*asoc
,
5348 const sctp_subtype_t type
,
5350 sctp_cmd_seq_t
*commands
)
5352 struct sctp_chunk
*repl
= NULL
;
5353 int attempts
= asoc
->init_err_counter
+ 1;
5355 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5356 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS
);
5358 if (attempts
<= asoc
->max_init_attempts
) {
5359 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5361 return SCTP_DISPOSITION_NOMEM
;
5363 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5365 /* Issue a sideeffect to do the needed accounting. */
5366 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5367 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5369 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5371 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5372 SCTP_ERROR(ETIMEDOUT
));
5373 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5374 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5375 return SCTP_DISPOSITION_DELETE_TCB
;
5378 return SCTP_DISPOSITION_CONSUME
;
5381 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5382 * with the updated last sequential TSN received from its peer.
5384 * An endpoint should limit the number of retransmissions of the
5385 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5386 * If this threshold is exceeded the endpoint should destroy the TCB and
5387 * MUST report the peer endpoint unreachable to the upper layer (and
5388 * thus the association enters the CLOSED state). The reception of any
5389 * packet from its peer (i.e. as the peer sends all of its queued DATA
5390 * chunks) should clear the endpoint's retransmission count and restart
5391 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5392 * all of its queued DATA chunks that have not yet been sent.
5394 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
5395 const struct sctp_association
*asoc
,
5396 const sctp_subtype_t type
,
5398 sctp_cmd_seq_t
*commands
)
5400 struct sctp_chunk
*reply
= NULL
;
5402 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5403 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5405 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5407 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5408 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5409 SCTP_ERROR(ETIMEDOUT
));
5410 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5411 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5412 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5413 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5414 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5415 return SCTP_DISPOSITION_DELETE_TCB
;
5418 switch (asoc
->state
) {
5419 case SCTP_STATE_SHUTDOWN_SENT
:
5420 reply
= sctp_make_shutdown(asoc
, NULL
);
5423 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5424 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5435 /* Do some failure management (Section 8.2).
5436 * If we remove the transport an SHUTDOWN was last sent to, don't
5437 * do failure management.
5439 if (asoc
->shutdown_last_sent_to
)
5440 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5441 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5443 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5444 * the T2-shutdown timer.
5446 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5448 /* Restart the T2-shutdown timer. */
5449 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5450 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5451 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5452 return SCTP_DISPOSITION_CONSUME
;
5455 return SCTP_DISPOSITION_NOMEM
;
5459 * ADDIP Section 4.1 ASCONF CHunk Procedures
5460 * If the T4 RTO timer expires the endpoint should do B1 to B5
5462 sctp_disposition_t
sctp_sf_t4_timer_expire(
5463 const struct sctp_endpoint
*ep
,
5464 const struct sctp_association
*asoc
,
5465 const sctp_subtype_t type
,
5467 sctp_cmd_seq_t
*commands
)
5469 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5470 struct sctp_transport
*transport
= chunk
->transport
;
5472 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS
);
5474 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5475 * detection on the appropriate destination address as defined in
5476 * RFC2960 [5] section 8.1 and 8.2.
5479 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5480 SCTP_TRANSPORT(transport
));
5482 /* Reconfig T4 timer and transport. */
5483 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5485 /* ADDIP 4.1 B2) Increment the association error counters and perform
5486 * endpoint failure detection on the association as defined in
5487 * RFC2960 [5] section 8.1 and 8.2.
5488 * association error counter is incremented in SCTP_CMD_STRIKE.
5490 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5491 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5492 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5493 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5494 SCTP_ERROR(ETIMEDOUT
));
5495 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5496 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5497 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5498 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5499 return SCTP_DISPOSITION_ABORT
;
5502 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5503 * the ASCONF chunk was sent by doubling the RTO timer value.
5504 * This is done in SCTP_CMD_STRIKE.
5507 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5508 * choose an alternate destination address (please refer to RFC2960
5509 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5510 * chunk, it MUST be the same (including its serial number) as the last
5513 sctp_chunk_hold(asoc
->addip_last_asconf
);
5514 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5515 SCTP_CHUNK(asoc
->addip_last_asconf
));
5517 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5518 * destination is selected, then the RTO used will be that of the new
5519 * destination address.
5521 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5522 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5524 return SCTP_DISPOSITION_CONSUME
;
5527 /* sctpimpguide-05 Section 2.12.2
5528 * The sender of the SHUTDOWN MAY also start an overall guard timer
5529 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5530 * At the expiration of this timer the sender SHOULD abort the association
5531 * by sending an ABORT chunk.
5533 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
5534 const struct sctp_association
*asoc
,
5535 const sctp_subtype_t type
,
5537 sctp_cmd_seq_t
*commands
)
5539 struct sctp_chunk
*reply
= NULL
;
5541 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5542 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5544 reply
= sctp_make_abort(asoc
, NULL
, 0);
5548 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5549 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5550 SCTP_ERROR(ETIMEDOUT
));
5551 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5552 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5554 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5555 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5557 return SCTP_DISPOSITION_DELETE_TCB
;
5559 return SCTP_DISPOSITION_NOMEM
;
5562 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5563 * the association is automatically closed by starting the shutdown process.
5564 * The work that needs to be done is same as when SHUTDOWN is initiated by
5565 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5567 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5568 const struct sctp_endpoint
*ep
,
5569 const struct sctp_association
*asoc
,
5570 const sctp_subtype_t type
,
5572 sctp_cmd_seq_t
*commands
)
5576 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5578 /* From 9.2 Shutdown of an Association
5579 * Upon receipt of the SHUTDOWN primitive from its upper
5580 * layer, the endpoint enters SHUTDOWN-PENDING state and
5581 * remains there until all outstanding data has been
5582 * acknowledged by its peer. The endpoint accepts no new data
5583 * from its upper layer, but retransmits data to the far end
5584 * if necessary to fill gaps.
5586 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5587 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5589 disposition
= SCTP_DISPOSITION_CONSUME
;
5590 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5591 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
5597 /*****************************************************************************
5598 * These are sa state functions which could apply to all types of events.
5599 ****************************************************************************/
5602 * This table entry is not implemented.
5605 * (endpoint, asoc, chunk)
5607 * The return value is the disposition of the chunk.
5609 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
5610 const struct sctp_association
*asoc
,
5611 const sctp_subtype_t type
,
5613 sctp_cmd_seq_t
*commands
)
5615 return SCTP_DISPOSITION_NOT_IMPL
;
5619 * This table entry represents a bug.
5622 * (endpoint, asoc, chunk)
5624 * The return value is the disposition of the chunk.
5626 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
5627 const struct sctp_association
*asoc
,
5628 const sctp_subtype_t type
,
5630 sctp_cmd_seq_t
*commands
)
5632 return SCTP_DISPOSITION_BUG
;
5636 * This table entry represents the firing of a timer in the wrong state.
5637 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5638 * when the association is in the wrong state. This event should
5639 * be ignored, so as to prevent any rearming of the timer.
5642 * (endpoint, asoc, chunk)
5644 * The return value is the disposition of the chunk.
5646 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
5647 const struct sctp_association
*asoc
,
5648 const sctp_subtype_t type
,
5650 sctp_cmd_seq_t
*commands
)
5652 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5653 return SCTP_DISPOSITION_CONSUME
;
5656 /********************************************************************
5657 * 2nd Level Abstractions
5658 ********************************************************************/
5660 /* Pull the SACK chunk based on the SACK header. */
5661 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5663 struct sctp_sackhdr
*sack
;
5668 /* Protect ourselves from reading too far into
5669 * the skb from a bogus sender.
5671 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5673 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5674 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5675 len
= sizeof(struct sctp_sackhdr
);
5676 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5677 if (len
> chunk
->skb
->len
)
5680 skb_pull(chunk
->skb
, len
);
5685 /* Create an ABORT packet to be sent as a response, with the specified
5688 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5689 const struct sctp_association
*asoc
,
5690 struct sctp_chunk
*chunk
,
5691 const void *payload
,
5694 struct sctp_packet
*packet
;
5695 struct sctp_chunk
*abort
;
5697 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5701 * The T bit will be set if the asoc is NULL.
5703 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5705 sctp_ootb_pkt_free(packet
);
5709 /* Reflect vtag if T-Bit is set */
5710 if (sctp_test_T_bit(abort
))
5711 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5713 /* Add specified error causes, i.e., payload, to the
5716 sctp_addto_chunk(abort
, paylen
, payload
);
5718 /* Set the skb to the belonging sock for accounting. */
5719 abort
->skb
->sk
= ep
->base
.sk
;
5721 sctp_packet_append_chunk(packet
, abort
);
5728 /* Allocate a packet for responding in the OOTB conditions. */
5729 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
5730 const struct sctp_chunk
*chunk
)
5732 struct sctp_packet
*packet
;
5733 struct sctp_transport
*transport
;
5738 /* Get the source and destination port from the inbound packet. */
5739 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5740 dport
= ntohs(chunk
->sctp_hdr
->source
);
5742 /* The V-tag is going to be the same as the inbound packet if no
5743 * association exists, otherwise, use the peer's vtag.
5746 /* Special case the INIT-ACK as there is no peer's vtag
5749 switch(chunk
->chunk_hdr
->type
) {
5750 case SCTP_CID_INIT_ACK
:
5752 sctp_initack_chunk_t
*initack
;
5754 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5755 vtag
= ntohl(initack
->init_hdr
.init_tag
);
5759 vtag
= asoc
->peer
.i
.init_tag
;
5763 /* Special case the INIT and stale COOKIE_ECHO as there is no
5766 switch(chunk
->chunk_hdr
->type
) {
5769 sctp_init_chunk_t
*init
;
5771 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5772 vtag
= ntohl(init
->init_hdr
.init_tag
);
5776 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5781 /* Make a transport for the bucket, Eliza... */
5782 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5786 /* Cache a route for the transport with the chunk's destination as
5787 * the source address.
5789 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5790 sctp_sk(sctp_get_ctl_sock()));
5792 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5793 packet
= sctp_packet_config(packet
, vtag
, 0);
5801 /* Free the packet allocated earlier for responding in the OOTB condition. */
5802 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5804 sctp_transport_free(packet
->transport
);
5807 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5808 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5809 const struct sctp_association
*asoc
,
5810 const struct sctp_chunk
*chunk
,
5811 sctp_cmd_seq_t
*commands
,
5812 struct sctp_chunk
*err_chunk
)
5814 struct sctp_packet
*packet
;
5817 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5819 struct sctp_signed_cookie
*cookie
;
5821 /* Override the OOTB vtag from the cookie. */
5822 cookie
= chunk
->subh
.cookie_hdr
;
5823 packet
->vtag
= cookie
->c
.peer_vtag
;
5825 /* Set the skb to the belonging sock for accounting. */
5826 err_chunk
->skb
->sk
= ep
->base
.sk
;
5827 sctp_packet_append_chunk(packet
, err_chunk
);
5828 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
5829 SCTP_PACKET(packet
));
5830 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
5832 sctp_chunk_free (err_chunk
);
5837 /* Process a data chunk */
5838 static int sctp_eat_data(const struct sctp_association
*asoc
,
5839 struct sctp_chunk
*chunk
,
5840 sctp_cmd_seq_t
*commands
)
5842 sctp_datahdr_t
*data_hdr
;
5843 struct sctp_chunk
*err
;
5845 sctp_verb_t deliver
;
5848 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
5849 struct sock
*sk
= asoc
->base
.sk
;
5851 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
5852 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
5854 tsn
= ntohl(data_hdr
->tsn
);
5855 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
5857 /* ASSERT: Now skb->data is really the user data. */
5859 /* Process ECN based congestion.
5861 * Since the chunk structure is reused for all chunks within
5862 * a packet, we use ecn_ce_done to track if we've already
5863 * done CE processing for this packet.
5865 * We need to do ECN processing even if we plan to discard the
5869 if (!chunk
->ecn_ce_done
) {
5871 chunk
->ecn_ce_done
= 1;
5873 af
= sctp_get_af_specific(
5874 ipver2af(ip_hdr(chunk
->skb
)->version
));
5876 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
5877 /* Do real work as sideffect. */
5878 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
5883 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
5885 /* The TSN is too high--silently discard the chunk and
5886 * count on it getting retransmitted later.
5888 return SCTP_IERROR_HIGH_TSN
;
5889 } else if (tmp
> 0) {
5890 /* This is a duplicate. Record it. */
5891 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
5892 return SCTP_IERROR_DUP_TSN
;
5895 /* This is a new TSN. */
5897 /* Discard if there is no room in the receive window.
5898 * Actually, allow a little bit of overflow (up to a MTU).
5900 datalen
= ntohs(chunk
->chunk_hdr
->length
);
5901 datalen
-= sizeof(sctp_data_chunk_t
);
5903 deliver
= SCTP_CMD_CHUNK_ULP
;
5905 /* Think about partial delivery. */
5906 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
5908 /* Even if we don't accept this chunk there is
5911 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
5914 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5915 * seems a bit troublesome in that frag_point varies based on
5916 * PMTU. In cases, such as loopback, this might be a rather
5919 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
5920 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
5922 /* If this is the next TSN, consider reneging to make
5923 * room. Note: Playing nice with a confused sender. A
5924 * malicious sender can still eat up all our buffer
5925 * space and in the future we may want to detect and
5926 * do more drastic reneging.
5928 if (sctp_tsnmap_has_gap(map
) &&
5929 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5930 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
5931 deliver
= SCTP_CMD_RENEGE
;
5933 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5934 "rwnd: %d\n", tsn
, datalen
,
5936 return SCTP_IERROR_IGNORE_TSN
;
5941 * Also try to renege to limit our memory usage in the event that
5942 * we are under memory pressure
5943 * If we can't renege, don't worry about it, the sk_rmem_schedule
5944 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5945 * memory usage too much
5947 if (*sk
->sk_prot_creator
->memory_pressure
) {
5948 if (sctp_tsnmap_has_gap(map
) &&
5949 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5950 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn
);
5951 deliver
= SCTP_CMD_RENEGE
;
5956 * Section 3.3.10.9 No User Data (9)
5960 * No User Data: This error cause is returned to the originator of a
5961 * DATA chunk if a received DATA chunk has no user data.
5963 if (unlikely(0 == datalen
)) {
5964 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
5966 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5969 /* We are going to ABORT, so we might as well stop
5970 * processing the rest of the chunks in the packet.
5972 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
5973 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5974 SCTP_ERROR(ECONNABORTED
));
5975 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5976 SCTP_PERR(SCTP_ERROR_NO_DATA
));
5977 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5978 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5979 return SCTP_IERROR_NO_DATA
;
5982 chunk
->data_accepted
= 1;
5984 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5985 * if we renege and the chunk arrives again.
5987 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
5988 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS
);
5990 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS
);
5992 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5994 * If an endpoint receive a DATA chunk with an invalid stream
5995 * identifier, it shall acknowledge the reception of the DATA chunk
5996 * following the normal procedure, immediately send an ERROR chunk
5997 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5998 * and discard the DATA chunk.
6000 if (ntohs(data_hdr
->stream
) >= asoc
->c
.sinit_max_instreams
) {
6001 /* Mark tsn as received even though we drop it */
6002 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6004 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6006 sizeof(data_hdr
->stream
));
6008 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6010 return SCTP_IERROR_BAD_STREAM
;
6013 /* Send the data up to the user. Note: Schedule the
6014 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6015 * chunk needs the updated rwnd.
6017 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6019 return SCTP_IERROR_NO_ERROR
;