1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This file is part of the SCTP kernel reference Implementation
10 * This is part of the SCTP Linux Kernel Reference Implementation.
12 * These are the state functions for the state machine.
14 * The SCTP reference implementation is free software;
15 * you can redistribute it and/or modify it under the terms of
16 * the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * The SCTP reference implementation is distributed in the hope that it
21 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
22 * ************************
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with GNU CC; see the file COPYING. If not, write to
28 * the Free Software Foundation, 59 Temple Place - Suite 330,
29 * Boston, MA 02111-1307, USA.
31 * Please send any bug reports or fixes you make to the
33 * lksctp developers <lksctp-developers@lists.sourceforge.net>
35 * Or submit a bug report through the following website:
36 * http://www.sf.net/projects/lksctp
38 * Written or modified by:
39 * La Monte H.P. Yarroll <piggy@acm.org>
40 * Karl Knutson <karl@athena.chicago.il.us>
41 * Mathew Kotowsky <kotowsky@sctp.org>
42 * Sridhar Samudrala <samudrala@us.ibm.com>
43 * Jon Grimm <jgrimm@us.ibm.com>
44 * Hui Huang <hui.huang@nokia.com>
45 * Dajiang Zhang <dajiang.zhang@nokia.com>
46 * Daisy Chang <daisyc@us.ibm.com>
47 * Ardelle Fan <ardelle.fan@intel.com>
48 * Ryan Layer <rmlayer@us.ibm.com>
49 * Kevin Gao <kevin.gao@intel.com>
51 * Any bugs reported given to us we will try to fix... any fixes shared will
52 * be incorporated into the next SCTP release.
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
62 #include <net/inet_ecn.h>
63 #include <linux/skbuff.h>
64 #include <net/sctp/sctp.h>
65 #include <net/sctp/sm.h>
66 #include <net/sctp/structs.h>
68 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
69 const struct sctp_association
*asoc
,
70 struct sctp_chunk
*chunk
,
73 static int sctp_eat_data(const struct sctp_association
*asoc
,
74 struct sctp_chunk
*chunk
,
75 sctp_cmd_seq_t
*commands
);
76 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
77 const struct sctp_chunk
*chunk
);
78 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
79 const struct sctp_association
*asoc
,
80 const struct sctp_chunk
*chunk
,
81 sctp_cmd_seq_t
*commands
,
82 struct sctp_chunk
*err_chunk
);
83 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
84 const struct sctp_association
*asoc
,
85 const sctp_subtype_t type
,
87 sctp_cmd_seq_t
*commands
);
88 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
89 const struct sctp_association
*asoc
,
90 const sctp_subtype_t type
,
92 sctp_cmd_seq_t
*commands
);
93 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
94 const struct sctp_association
*asoc
,
95 const sctp_subtype_t type
,
97 sctp_cmd_seq_t
*commands
);
98 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
100 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
101 __be16 error
, int sk_err
,
102 const struct sctp_association
*asoc
,
103 struct sctp_transport
*transport
);
105 static sctp_disposition_t
sctp_sf_abort_violation(
106 const struct sctp_endpoint
*ep
,
107 const struct sctp_association
*asoc
,
109 sctp_cmd_seq_t
*commands
,
111 const size_t paylen
);
113 static sctp_disposition_t
sctp_sf_violation_chunklen(
114 const struct sctp_endpoint
*ep
,
115 const struct sctp_association
*asoc
,
116 const sctp_subtype_t type
,
118 sctp_cmd_seq_t
*commands
);
120 static sctp_disposition_t
sctp_sf_violation_paramlen(
121 const struct sctp_endpoint
*ep
,
122 const struct sctp_association
*asoc
,
123 const sctp_subtype_t type
,
125 sctp_cmd_seq_t
*commands
);
127 static sctp_disposition_t
sctp_sf_violation_ctsn(
128 const struct sctp_endpoint
*ep
,
129 const struct sctp_association
*asoc
,
130 const sctp_subtype_t type
,
132 sctp_cmd_seq_t
*commands
);
134 static sctp_disposition_t
sctp_sf_violation_chunk(
135 const struct sctp_endpoint
*ep
,
136 const struct sctp_association
*asoc
,
137 const sctp_subtype_t type
,
139 sctp_cmd_seq_t
*commands
);
141 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
142 const struct sctp_association
*asoc
,
143 const sctp_subtype_t type
,
144 struct sctp_chunk
*chunk
);
146 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
147 const struct sctp_association
*asoc
,
148 const sctp_subtype_t type
,
150 sctp_cmd_seq_t
*commands
);
152 /* Small helper function that checks if the chunk length
153 * is of the appropriate length. The 'required_length' argument
154 * is set to be the size of a specific chunk we are testing.
155 * Return Values: 1 = Valid length
160 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
161 __u16 required_length
)
163 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
165 if (unlikely(chunk_length
< required_length
))
171 /**********************************************************
172 * These are the state functions for handling chunk events.
173 **********************************************************/
176 * Process the final SHUTDOWN COMPLETE.
178 * Section: 4 (C) (diagram), 9.2
179 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
180 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
181 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
182 * should stop the T2-shutdown timer and remove all knowledge of the
183 * association (and thus the association enters the CLOSED state).
185 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
186 * C) Rules for packet carrying SHUTDOWN COMPLETE:
188 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
189 * if the Verification Tag field of the packet matches its own tag and
190 * the T bit is not set
192 * it is set to its peer's tag and the T bit is set in the Chunk
194 * Otherwise, the receiver MUST silently discard the packet
195 * and take no further action. An endpoint MUST ignore the
196 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
199 * (endpoint, asoc, chunk)
202 * (asoc, reply_msg, msg_up, timers, counters)
204 * The return value is the disposition of the chunk.
206 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
207 const struct sctp_association
*asoc
,
208 const sctp_subtype_t type
,
210 sctp_cmd_seq_t
*commands
)
212 struct sctp_chunk
*chunk
= arg
;
213 struct sctp_ulpevent
*ev
;
215 if (!sctp_vtag_verify_either(chunk
, asoc
))
216 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
218 /* RFC 2960 6.10 Bundling
220 * An endpoint MUST NOT bundle INIT, INIT ACK or
221 * SHUTDOWN COMPLETE with any other chunks.
223 if (!chunk
->singleton
)
224 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
226 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
227 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
228 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
231 /* RFC 2960 10.2 SCTP-to-ULP
233 * H) SHUTDOWN COMPLETE notification
235 * When SCTP completes the shutdown procedures (section 9.2) this
236 * notification is passed to the upper layer.
238 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
239 0, 0, 0, NULL
, GFP_ATOMIC
);
241 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
244 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
245 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
246 * not the chunk should be discarded. If the endpoint is in
247 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
248 * T2-shutdown timer and remove all knowledge of the
249 * association (and thus the association enters the CLOSED
252 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
253 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
255 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
256 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
258 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
259 SCTP_STATE(SCTP_STATE_CLOSED
));
261 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
262 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
264 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
266 return SCTP_DISPOSITION_DELETE_TCB
;
270 * Respond to a normal INIT chunk.
271 * We are the side that is being asked for an association.
273 * Section: 5.1 Normal Establishment of an Association, B
274 * B) "Z" shall respond immediately with an INIT ACK chunk. The
275 * destination IP address of the INIT ACK MUST be set to the source
276 * IP address of the INIT to which this INIT ACK is responding. In
277 * the response, besides filling in other parameters, "Z" must set the
278 * Verification Tag field to Tag_A, and also provide its own
279 * Verification Tag (Tag_Z) in the Initiate Tag field.
281 * Verification Tag: Must be 0.
284 * (endpoint, asoc, chunk)
287 * (asoc, reply_msg, msg_up, timers, counters)
289 * The return value is the disposition of the chunk.
291 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
292 const struct sctp_association
*asoc
,
293 const sctp_subtype_t type
,
295 sctp_cmd_seq_t
*commands
)
297 struct sctp_chunk
*chunk
= arg
;
298 struct sctp_chunk
*repl
;
299 struct sctp_association
*new_asoc
;
300 struct sctp_chunk
*err_chunk
;
301 struct sctp_packet
*packet
;
302 sctp_unrecognized_param_t
*unk_param
;
306 * An endpoint MUST NOT bundle INIT, INIT ACK or
307 * SHUTDOWN COMPLETE with any other chunks.
310 * Furthermore, we require that the receiver of an INIT chunk MUST
311 * enforce these rules by silently discarding an arriving packet
312 * with an INIT chunk that is bundled with other chunks.
314 if (!chunk
->singleton
)
315 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
317 /* If the packet is an OOTB packet which is temporarily on the
318 * control endpoint, respond with an ABORT.
320 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
321 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
;
484 sctp_error_t error
= SCTP_ERROR_NO_ERROR
;
486 if (!sctp_vtag_verify(chunk
, asoc
))
487 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
490 * An endpoint MUST NOT bundle INIT, INIT ACK or
491 * SHUTDOWN COMPLETE with any other chunks.
493 if (!chunk
->singleton
)
494 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
496 /* Make sure that the INIT-ACK chunk has a valid length */
497 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
498 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
500 /* Grab the INIT header. */
501 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
503 /* Verify the INIT chunk before processing it. */
505 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
506 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
509 /* This chunk contains fatal error. It is to be discarded.
510 * Send an ABORT, with causes. If there are no causes,
511 * then there wasn't enough memory. Just terminate
515 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
516 (__u8
*)(err_chunk
->chunk_hdr
) +
517 sizeof(sctp_chunkhdr_t
),
518 ntohs(err_chunk
->chunk_hdr
->length
) -
519 sizeof(sctp_chunkhdr_t
));
521 sctp_chunk_free(err_chunk
);
524 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
525 SCTP_PACKET(packet
));
526 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
527 error
= SCTP_ERROR_INV_PARAM
;
529 error
= SCTP_ERROR_NO_RESOURCE
;
533 /* SCTP-AUTH, Section 6.3:
534 * It should be noted that if the receiver wants to tear
535 * down an association in an authenticated way only, the
536 * handling of malformed packets should not result in
537 * tearing down the association.
539 * This means that if we only want to abort associations
540 * in an authenticated way (i.e AUTH+ABORT), then we
541 * can't destory this association just becuase the packet
544 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
545 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
547 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
548 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
,
549 asoc
, chunk
->transport
);
552 /* Tag the variable length parameters. Note that we never
553 * convert the parameters in an INIT chunk.
555 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
557 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
559 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
560 SCTP_PEER_INIT(initchunk
));
562 /* Reset init error count upon receipt of INIT-ACK. */
563 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
565 /* 5.1 C) "A" shall stop the T1-init timer and leave
566 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
567 * timer, and enter the COOKIE-ECHOED state.
569 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
570 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
571 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
572 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
573 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
574 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
576 /* SCTP-AUTH: genereate the assocition shared keys so that
577 * we can potentially signe the COOKIE-ECHO.
579 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
581 /* 5.1 C) "A" shall then send the State Cookie received in the
582 * INIT ACK chunk in a COOKIE ECHO chunk, ...
584 /* If there is any errors to report, send the ERROR chunk generated
585 * for unknown parameters as well.
587 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
588 SCTP_CHUNK(err_chunk
));
590 return SCTP_DISPOSITION_CONSUME
;
594 * Respond to a normal COOKIE ECHO chunk.
595 * We are the side that is being asked for an association.
597 * Section: 5.1 Normal Establishment of an Association, D
598 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
599 * with a COOKIE ACK chunk after building a TCB and moving to
600 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
601 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
602 * chunk MUST be the first chunk in the packet.
604 * IMPLEMENTATION NOTE: An implementation may choose to send the
605 * Communication Up notification to the SCTP user upon reception
606 * of a valid COOKIE ECHO chunk.
608 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
609 * D) Rules for packet carrying a COOKIE ECHO
611 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
612 * Initial Tag received in the INIT ACK.
614 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
617 * (endpoint, asoc, chunk)
620 * (asoc, reply_msg, msg_up, timers, counters)
622 * The return value is the disposition of the chunk.
624 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
625 const struct sctp_association
*asoc
,
626 const sctp_subtype_t type
, void *arg
,
627 sctp_cmd_seq_t
*commands
)
629 struct sctp_chunk
*chunk
= arg
;
630 struct sctp_association
*new_asoc
;
631 sctp_init_chunk_t
*peer_init
;
632 struct sctp_chunk
*repl
;
633 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
635 struct sctp_chunk
*err_chk_p
;
638 /* If the packet is an OOTB packet which is temporarily on the
639 * control endpoint, respond with an ABORT.
641 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
642 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
644 /* Make sure that the COOKIE_ECHO chunk has a valid length.
645 * In this case, we check that we have enough for at least a
646 * chunk header. More detailed verification is done
647 * in sctp_unpack_cookie().
649 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
650 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
652 /* If the endpoint is not listening or if the number of associations
653 * on the TCP-style socket exceed the max backlog, respond with an
657 if (!sctp_sstate(sk
, LISTENING
) ||
658 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
659 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
661 /* "Decode" the chunk. We have no optional parameters so we
664 chunk
->subh
.cookie_hdr
=
665 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
666 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
667 sizeof(sctp_chunkhdr_t
)))
670 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
671 * "Z" will reply with a COOKIE ACK chunk after building a TCB
672 * and moving to the ESTABLISHED state.
674 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
678 * If the re-build failed, what is the proper error path
681 * [We should abort the association. --piggy]
684 /* FIXME: Several errors are possible. A bad cookie should
685 * be silently discarded, but think about logging it too.
688 case -SCTP_IERROR_NOMEM
:
691 case -SCTP_IERROR_STALE_COOKIE
:
692 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
694 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
696 case -SCTP_IERROR_BAD_SIG
:
698 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
703 /* Delay state machine commands until later.
705 * Re-build the bind address for the association is done in
706 * the sctp_unpack_cookie() already.
708 /* This is a brand-new association, so these are not yet side
709 * effects--it is safe to run them here.
711 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
713 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
714 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
715 peer_init
, GFP_ATOMIC
))
718 /* SCTP-AUTH: Now that we've populate required fields in
719 * sctp_process_init, set up the assocaition shared keys as
720 * necessary so that we can potentially authenticate the ACK
722 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
726 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
727 * is supposed to be authenticated and we have to do delayed
728 * authentication. We've just recreated the association using
729 * the information in the cookie and now it's much easier to
730 * do the authentication.
732 if (chunk
->auth_chunk
) {
733 struct sctp_chunk auth
;
736 /* set-up our fake chunk so that we can process it */
737 auth
.skb
= chunk
->auth_chunk
;
738 auth
.asoc
= chunk
->asoc
;
739 auth
.sctp_hdr
= chunk
->sctp_hdr
;
740 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
741 sizeof(sctp_chunkhdr_t
));
742 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
743 auth
.transport
= chunk
->transport
;
745 ret
= sctp_sf_authenticate(ep
, new_asoc
, type
, &auth
);
747 /* We can now safely free the auth_chunk clone */
748 kfree_skb(chunk
->auth_chunk
);
750 if (ret
!= SCTP_IERROR_NO_ERROR
) {
751 sctp_association_free(new_asoc
);
752 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
756 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
760 /* RFC 2960 5.1 Normal Establishment of an Association
762 * D) IMPLEMENTATION NOTE: An implementation may choose to
763 * send the Communication Up notification to the SCTP user
764 * upon reception of a valid COOKIE ECHO chunk.
766 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
767 new_asoc
->c
.sinit_num_ostreams
,
768 new_asoc
->c
.sinit_max_instreams
,
773 /* Sockets API Draft Section 5.3.1.6
774 * When a peer sends a Adaptation Layer Indication parameter , SCTP
775 * delivers this notification to inform the application that of the
776 * peers requested adaptation layer.
778 if (new_asoc
->peer
.adaptation_ind
) {
779 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
785 /* Add all the state machine commands now since we've created
786 * everything. This way we don't introduce memory corruptions
787 * during side-effect processing and correclty count established
790 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
791 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
792 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
793 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
794 SCTP_INC_STATS(SCTP_MIB_PASSIVEESTABS
);
795 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
797 if (new_asoc
->autoclose
)
798 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
799 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
801 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
803 /* This will send the COOKIE ACK */
804 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
806 /* Queue the ASSOC_CHANGE event */
807 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
809 /* Send up the Adaptation Layer Indication event */
811 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
812 SCTP_ULPEVENT(ai_ev
));
814 return SCTP_DISPOSITION_CONSUME
;
817 sctp_ulpevent_free(ev
);
819 sctp_chunk_free(repl
);
821 sctp_association_free(new_asoc
);
823 return SCTP_DISPOSITION_NOMEM
;
827 * Respond to a normal COOKIE ACK chunk.
828 * We are the side that is being asked for an association.
830 * RFC 2960 5.1 Normal Establishment of an Association
832 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
833 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
834 * timer. It may also notify its ULP about the successful
835 * establishment of the association with a Communication Up
836 * notification (see Section 10).
840 * (endpoint, asoc, chunk)
843 * (asoc, reply_msg, msg_up, timers, counters)
845 * The return value is the disposition of the chunk.
847 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
848 const struct sctp_association
*asoc
,
849 const sctp_subtype_t type
, void *arg
,
850 sctp_cmd_seq_t
*commands
)
852 struct sctp_chunk
*chunk
= arg
;
853 struct sctp_ulpevent
*ev
;
855 if (!sctp_vtag_verify(chunk
, asoc
))
856 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
858 /* Verify that the chunk length for the COOKIE-ACK is OK.
859 * If we don't do this, any bundled chunks may be junked.
861 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
862 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
865 /* Reset init error count upon receipt of COOKIE-ACK,
866 * to avoid problems with the managemement of this
867 * counter in stale cookie situations when a transition back
868 * from the COOKIE-ECHOED state to the COOKIE-WAIT
869 * state is performed.
871 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
873 /* RFC 2960 5.1 Normal Establishment of an Association
875 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
876 * from the COOKIE-ECHOED state to the ESTABLISHED state,
877 * stopping the T1-cookie timer.
879 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
880 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
881 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
882 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
883 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
884 SCTP_INC_STATS(SCTP_MIB_ACTIVEESTABS
);
885 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
887 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
888 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
889 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
891 /* It may also notify its ULP about the successful
892 * establishment of the association with a Communication Up
893 * notification (see Section 10).
895 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
896 0, asoc
->c
.sinit_num_ostreams
,
897 asoc
->c
.sinit_max_instreams
,
903 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
905 /* Sockets API Draft Section 5.3.1.6
906 * When a peer sends a Adaptation Layer Indication parameter , SCTP
907 * delivers this notification to inform the application that of the
908 * peers requested adaptation layer.
910 if (asoc
->peer
.adaptation_ind
) {
911 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
915 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
919 return SCTP_DISPOSITION_CONSUME
;
921 return SCTP_DISPOSITION_NOMEM
;
924 /* Generate and sendout a heartbeat packet. */
925 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
926 const struct sctp_association
*asoc
,
927 const sctp_subtype_t type
,
929 sctp_cmd_seq_t
*commands
)
931 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
932 struct sctp_chunk
*reply
;
933 sctp_sender_hb_info_t hbinfo
;
936 hbinfo
.param_hdr
.type
= SCTP_PARAM_HEARTBEAT_INFO
;
937 hbinfo
.param_hdr
.length
= htons(sizeof(sctp_sender_hb_info_t
));
938 hbinfo
.daddr
= transport
->ipaddr
;
939 hbinfo
.sent_at
= jiffies
;
940 hbinfo
.hb_nonce
= transport
->hb_nonce
;
942 /* Send a heartbeat to our peer. */
943 paylen
= sizeof(sctp_sender_hb_info_t
);
944 reply
= sctp_make_heartbeat(asoc
, transport
, &hbinfo
, paylen
);
946 return SCTP_DISPOSITION_NOMEM
;
948 /* Set rto_pending indicating that an RTT measurement
949 * is started with this heartbeat chunk.
951 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
952 SCTP_TRANSPORT(transport
));
954 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
955 return SCTP_DISPOSITION_CONSUME
;
958 /* Generate a HEARTBEAT packet on the given transport. */
959 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
960 const struct sctp_association
*asoc
,
961 const sctp_subtype_t type
,
963 sctp_cmd_seq_t
*commands
)
965 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
967 if (asoc
->overall_error_count
> asoc
->max_retrans
) {
968 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
969 SCTP_ERROR(ETIMEDOUT
));
970 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
971 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
972 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
973 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
974 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
975 return SCTP_DISPOSITION_DELETE_TCB
;
979 * The Sender-specific Heartbeat Info field should normally include
980 * information about the sender's current time when this HEARTBEAT
981 * chunk is sent and the destination transport address to which this
982 * HEARTBEAT is sent (see Section 8.3).
985 if (transport
->param_flags
& SPP_HB_ENABLE
) {
986 if (SCTP_DISPOSITION_NOMEM
==
987 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
989 return SCTP_DISPOSITION_NOMEM
;
990 /* Set transport error counter and association error counter
991 * when sending heartbeat.
993 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
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 "
1132 NIP6(from_addr
.v6
.sin6_addr
));
1134 if (net_ratelimit())
1136 "%s association %p could not find address "
1140 NIPQUAD(from_addr
.v4
.sin_addr
.s_addr
));
1142 return SCTP_DISPOSITION_DISCARD
;
1145 /* Validate the 64-bit random nonce. */
1146 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1147 return SCTP_DISPOSITION_DISCARD
;
1149 max_interval
= link
->hbinterval
+ link
->rto
;
1151 /* Check if the timestamp looks valid. */
1152 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1153 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1154 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1155 "received for transport: %p\n",
1156 __FUNCTION__
, link
);
1157 return SCTP_DISPOSITION_DISCARD
;
1160 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1161 * the HEARTBEAT should clear the error counter of the
1162 * destination transport address to which the HEARTBEAT was
1163 * sent and mark the destination transport address as active if
1164 * it is not so marked.
1166 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1168 return SCTP_DISPOSITION_CONSUME
;
1171 /* Helper function to send out an abort for the restart
1174 static int sctp_sf_send_restart_abort(union sctp_addr
*ssa
,
1175 struct sctp_chunk
*init
,
1176 sctp_cmd_seq_t
*commands
)
1179 struct sctp_packet
*pkt
;
1180 union sctp_addr_param
*addrparm
;
1181 struct sctp_errhdr
*errhdr
;
1182 struct sctp_endpoint
*ep
;
1183 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1184 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1186 /* Build the error on the stack. We are way to malloc crazy
1187 * throughout the code today.
1189 errhdr
= (struct sctp_errhdr
*)buffer
;
1190 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1192 /* Copy into a parm format. */
1193 len
= af
->to_addr_param(ssa
, addrparm
);
1194 len
+= sizeof(sctp_errhdr_t
);
1196 errhdr
->cause
= SCTP_ERROR_RESTART
;
1197 errhdr
->length
= htons(len
);
1199 /* Assign to the control socket. */
1200 ep
= sctp_sk((sctp_get_ctl_sock()))->ep
;
1202 /* Association is NULL since this may be a restart attack and we
1203 * want to send back the attacker's vtag.
1205 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1209 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1211 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1213 /* Discard the rest of the inbound packet. */
1214 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1217 /* Even if there is no memory, treat as a failure so
1218 * the packet will get dropped.
1223 /* A restart is occurring, check to make sure no new addresses
1224 * are being added as we may be under a takeover attack.
1226 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1227 const struct sctp_association
*asoc
,
1228 struct sctp_chunk
*init
,
1229 sctp_cmd_seq_t
*commands
)
1231 struct sctp_transport
*new_addr
, *addr
;
1232 struct list_head
*pos
, *pos2
;
1235 /* Implementor's Guide - Sectin 5.2.2
1237 * Before responding the endpoint MUST check to see if the
1238 * unexpected INIT adds new addresses to the association. If new
1239 * addresses are added to the association, the endpoint MUST respond
1243 /* Search through all current addresses and make sure
1244 * we aren't adding any new ones.
1249 list_for_each(pos
, &new_asoc
->peer
.transport_addr_list
) {
1250 new_addr
= list_entry(pos
, struct sctp_transport
, transports
);
1252 list_for_each(pos2
, &asoc
->peer
.transport_addr_list
) {
1253 addr
= list_entry(pos2
, struct sctp_transport
,
1255 if (sctp_cmp_addr_exact(&new_addr
->ipaddr
,
1265 /* If a new address was added, ABORT the sender. */
1266 if (!found
&& new_addr
) {
1267 sctp_sf_send_restart_abort(&new_addr
->ipaddr
, init
, commands
);
1270 /* Return success if all addresses were found. */
1274 /* Populate the verification/tie tags based on overlapping INIT
1277 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1279 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1280 const struct sctp_association
*asoc
)
1282 switch (asoc
->state
) {
1284 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1286 case SCTP_STATE_COOKIE_WAIT
:
1287 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1288 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1289 new_asoc
->c
.peer_ttag
= 0;
1292 case SCTP_STATE_COOKIE_ECHOED
:
1293 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1294 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1295 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1298 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1299 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1302 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1303 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1307 /* Other parameters for the endpoint SHOULD be copied from the
1308 * existing parameters of the association (e.g. number of
1309 * outbound streams) into the INIT ACK and cookie.
1311 new_asoc
->rwnd
= asoc
->rwnd
;
1312 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1313 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1314 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1318 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1321 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1323 * Returns value representing action to be taken. These action values
1324 * correspond to Action/Description values in RFC 2960, Table 2.
1326 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1327 const struct sctp_association
*asoc
)
1329 /* In this case, the peer may have restarted. */
1330 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1331 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1332 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1333 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1336 /* Collision case B. */
1337 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1338 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1339 (0 == asoc
->c
.peer_vtag
))) {
1343 /* Collision case D. */
1344 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1345 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1348 /* Collision case C. */
1349 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1350 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1351 (0 == new_asoc
->c
.my_ttag
) &&
1352 (0 == new_asoc
->c
.peer_ttag
))
1355 /* No match to any of the special cases; discard this packet. */
1359 /* Common helper routine for both duplicate and simulataneous INIT
1362 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1363 const struct sctp_endpoint
*ep
,
1364 const struct sctp_association
*asoc
,
1365 const sctp_subtype_t type
,
1366 void *arg
, sctp_cmd_seq_t
*commands
)
1368 sctp_disposition_t retval
;
1369 struct sctp_chunk
*chunk
= arg
;
1370 struct sctp_chunk
*repl
;
1371 struct sctp_association
*new_asoc
;
1372 struct sctp_chunk
*err_chunk
;
1373 struct sctp_packet
*packet
;
1374 sctp_unrecognized_param_t
*unk_param
;
1378 * An endpoint MUST NOT bundle INIT, INIT ACK or
1379 * SHUTDOWN COMPLETE with any other chunks.
1382 * Furthermore, we require that the receiver of an INIT chunk MUST
1383 * enforce these rules by silently discarding an arriving packet
1384 * with an INIT chunk that is bundled with other chunks.
1386 if (!chunk
->singleton
)
1387 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1389 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1392 if (chunk
->sctp_hdr
->vtag
!= 0)
1393 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1395 /* Make sure that the INIT chunk has a valid length.
1396 * In this case, we generate a protocol violation since we have
1397 * an association established.
1399 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1400 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1402 /* Grab the INIT header. */
1403 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1405 /* Tag the variable length parameters. */
1406 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1408 /* Verify the INIT chunk before processing it. */
1410 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1411 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1413 /* This chunk contains fatal error. It is to be discarded.
1414 * Send an ABORT, with causes if there is any.
1417 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1418 (__u8
*)(err_chunk
->chunk_hdr
) +
1419 sizeof(sctp_chunkhdr_t
),
1420 ntohs(err_chunk
->chunk_hdr
->length
) -
1421 sizeof(sctp_chunkhdr_t
));
1424 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1425 SCTP_PACKET(packet
));
1426 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
1427 retval
= SCTP_DISPOSITION_CONSUME
;
1429 retval
= SCTP_DISPOSITION_NOMEM
;
1433 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1439 * Other parameters for the endpoint SHOULD be copied from the
1440 * existing parameters of the association (e.g. number of
1441 * outbound streams) into the INIT ACK and cookie.
1442 * FIXME: We are copying parameters from the endpoint not the
1445 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1449 /* In the outbound INIT ACK the endpoint MUST copy its current
1450 * Verification Tag and Peers Verification tag into a reserved
1451 * place (local tie-tag and per tie-tag) within the state cookie.
1453 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1455 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1459 /* Make sure no new addresses are being added during the
1460 * restart. Do not do this check for COOKIE-WAIT state,
1461 * since there are no peer addresses to check against.
1462 * Upon return an ABORT will have been sent if needed.
1464 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1465 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1467 retval
= SCTP_DISPOSITION_CONSUME
;
1472 sctp_tietags_populate(new_asoc
, asoc
);
1474 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1476 /* If there are errors need to be reported for unknown parameters,
1477 * make sure to reserve enough room in the INIT ACK for them.
1481 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1482 sizeof(sctp_chunkhdr_t
);
1485 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
, GFP_ATOMIC
) < 0)
1488 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1492 /* If there are errors need to be reported for unknown parameters,
1493 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1497 /* Get the "Unrecognized parameter" parameter(s) out of the
1498 * ERROR chunk generated by sctp_verify_init(). Since the
1499 * error cause code for "unknown parameter" and the
1500 * "Unrecognized parameter" type is the same, we can
1501 * construct the parameters in INIT ACK by copying the
1502 * ERROR causes over.
1504 unk_param
= (sctp_unrecognized_param_t
*)
1505 ((__u8
*)(err_chunk
->chunk_hdr
) +
1506 sizeof(sctp_chunkhdr_t
));
1507 /* Replace the cause code with the "Unrecognized parameter"
1510 sctp_addto_chunk(repl
, len
, unk_param
);
1513 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1514 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1517 * Note: After sending out INIT ACK with the State Cookie parameter,
1518 * "Z" MUST NOT allocate any resources for this new association.
1519 * Otherwise, "Z" will be vulnerable to resource attacks.
1521 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1522 retval
= SCTP_DISPOSITION_CONSUME
;
1527 retval
= SCTP_DISPOSITION_NOMEM
;
1530 sctp_association_free(new_asoc
);
1533 sctp_chunk_free(err_chunk
);
1538 * Handle simultanous INIT.
1539 * This means we started an INIT and then we got an INIT request from
1542 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1543 * This usually indicates an initialization collision, i.e., each
1544 * endpoint is attempting, at about the same time, to establish an
1545 * association with the other endpoint.
1547 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1548 * endpoint MUST respond with an INIT ACK using the same parameters it
1549 * sent in its original INIT chunk (including its Verification Tag,
1550 * unchanged). These original parameters are combined with those from the
1551 * newly received INIT chunk. The endpoint shall also generate a State
1552 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1553 * INIT to calculate the State Cookie.
1555 * After that, the endpoint MUST NOT change its state, the T1-init
1556 * timer shall be left running and the corresponding TCB MUST NOT be
1557 * destroyed. The normal procedures for handling State Cookies when
1558 * a TCB exists will resolve the duplicate INITs to a single association.
1560 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1561 * its Tie-Tags with the Tag information of itself and its peer (see
1562 * section 5.2.2 for a description of the Tie-Tags).
1564 * Verification Tag: Not explicit, but an INIT can not have a valid
1565 * verification tag, so we skip the check.
1568 * (endpoint, asoc, chunk)
1571 * (asoc, reply_msg, msg_up, timers, counters)
1573 * The return value is the disposition of the chunk.
1575 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1576 const struct sctp_association
*asoc
,
1577 const sctp_subtype_t type
,
1579 sctp_cmd_seq_t
*commands
)
1581 /* Call helper to do the real work for both simulataneous and
1582 * duplicate INIT chunk handling.
1584 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1588 * Handle duplicated INIT messages. These are usually delayed
1591 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1592 * COOKIE-ECHOED and COOKIE-WAIT
1594 * Unless otherwise stated, upon reception of an unexpected INIT for
1595 * this association, the endpoint shall generate an INIT ACK with a
1596 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1597 * current Verification Tag and peer's Verification Tag into a reserved
1598 * place within the state cookie. We shall refer to these locations as
1599 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1600 * containing this INIT ACK MUST carry a Verification Tag value equal to
1601 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1602 * MUST contain a new Initiation Tag (randomly generated see Section
1603 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1604 * existing parameters of the association (e.g. number of outbound
1605 * streams) into the INIT ACK and cookie.
1607 * After sending out the INIT ACK, the endpoint shall take no further
1608 * actions, i.e., the existing association, including its current state,
1609 * and the corresponding TCB MUST NOT be changed.
1611 * Note: Only when a TCB exists and the association is not in a COOKIE-
1612 * WAIT state are the Tie-Tags populated. For a normal association INIT
1613 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1614 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1615 * State Cookie are populated as specified in section 5.2.1.
1617 * Verification Tag: Not specified, but an INIT has no way of knowing
1618 * what the verification tag could be, so we ignore it.
1621 * (endpoint, asoc, chunk)
1624 * (asoc, reply_msg, msg_up, timers, counters)
1626 * The return value is the disposition of the chunk.
1628 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1629 const struct sctp_association
*asoc
,
1630 const sctp_subtype_t type
,
1632 sctp_cmd_seq_t
*commands
)
1634 /* Call helper to do the real work for both simulataneous and
1635 * duplicate INIT chunk handling.
1637 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1642 * Unexpected INIT-ACK handler.
1645 * If an INIT ACK received by an endpoint in any state other than the
1646 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1647 * An unexpected INIT ACK usually indicates the processing of an old or
1648 * duplicated INIT chunk.
1650 sctp_disposition_t
sctp_sf_do_5_2_3_initack(const struct sctp_endpoint
*ep
,
1651 const struct sctp_association
*asoc
,
1652 const sctp_subtype_t type
,
1653 void *arg
, sctp_cmd_seq_t
*commands
)
1655 /* Per the above section, we'll discard the chunk if we have an
1656 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1658 if (ep
== sctp_sk((sctp_get_ctl_sock()))->ep
)
1659 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
1661 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
1664 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1667 * A) In this case, the peer may have restarted.
1669 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1670 const struct sctp_association
*asoc
,
1671 struct sctp_chunk
*chunk
,
1672 sctp_cmd_seq_t
*commands
,
1673 struct sctp_association
*new_asoc
)
1675 sctp_init_chunk_t
*peer_init
;
1676 struct sctp_ulpevent
*ev
;
1677 struct sctp_chunk
*repl
;
1678 struct sctp_chunk
*err
;
1679 sctp_disposition_t disposition
;
1681 /* new_asoc is a brand-new association, so these are not yet
1682 * side effects--it is safe to run them here.
1684 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1686 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1687 sctp_source(chunk
), peer_init
,
1691 /* Make sure no new addresses are being added during the
1692 * restart. Though this is a pretty complicated attack
1693 * since you'd have to get inside the cookie.
1695 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1696 return SCTP_DISPOSITION_CONSUME
;
1699 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1700 * the peer has restarted (Action A), it MUST NOT setup a new
1701 * association but instead resend the SHUTDOWN ACK and send an ERROR
1702 * chunk with a "Cookie Received while Shutting Down" error cause to
1705 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1706 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1707 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1709 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1712 err
= sctp_make_op_error(asoc
, chunk
,
1713 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1716 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1719 return SCTP_DISPOSITION_CONSUME
;
1722 /* For now, fail any unsent/unacked data. Consider the optional
1723 * choice of resending of this data.
1725 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1727 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1731 /* Report association restart to upper layer. */
1732 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1733 new_asoc
->c
.sinit_num_ostreams
,
1734 new_asoc
->c
.sinit_max_instreams
,
1739 /* Update the content of current association. */
1740 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1741 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1742 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1743 return SCTP_DISPOSITION_CONSUME
;
1746 sctp_chunk_free(repl
);
1748 return SCTP_DISPOSITION_NOMEM
;
1751 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1754 * B) In this case, both sides may be attempting to start an association
1755 * at about the same time but the peer endpoint started its INIT
1756 * after responding to the local endpoint's INIT
1758 /* This case represents an initialization collision. */
1759 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1760 const struct sctp_association
*asoc
,
1761 struct sctp_chunk
*chunk
,
1762 sctp_cmd_seq_t
*commands
,
1763 struct sctp_association
*new_asoc
)
1765 sctp_init_chunk_t
*peer_init
;
1766 struct sctp_chunk
*repl
;
1768 /* new_asoc is a brand-new association, so these are not yet
1769 * side effects--it is safe to run them here.
1771 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1772 if (!sctp_process_init(new_asoc
, chunk
->chunk_hdr
->type
,
1773 sctp_source(chunk
), peer_init
,
1777 /* Update the content of current association. */
1778 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1779 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1780 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1781 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1782 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1784 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1788 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1789 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1791 /* RFC 2960 5.1 Normal Establishment of an Association
1793 * D) IMPLEMENTATION NOTE: An implementation may choose to
1794 * send the Communication Up notification to the SCTP user
1795 * upon reception of a valid COOKIE ECHO chunk.
1797 * Sadly, this needs to be implemented as a side-effect, because
1798 * we are not guaranteed to have set the association id of the real
1799 * association and so these notifications need to be delayed until
1800 * the association id is allocated.
1803 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1805 /* Sockets API Draft Section 5.3.1.6
1806 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1807 * delivers this notification to inform the application that of the
1808 * peers requested adaptation layer.
1810 * This also needs to be done as a side effect for the same reason as
1813 if (asoc
->peer
.adaptation_ind
)
1814 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1816 return SCTP_DISPOSITION_CONSUME
;
1819 return SCTP_DISPOSITION_NOMEM
;
1822 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1825 * C) In this case, the local endpoint's cookie has arrived late.
1826 * Before it arrived, the local endpoint sent an INIT and received an
1827 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1828 * but a new tag of its own.
1830 /* This case represents an initialization collision. */
1831 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1832 const struct sctp_association
*asoc
,
1833 struct sctp_chunk
*chunk
,
1834 sctp_cmd_seq_t
*commands
,
1835 struct sctp_association
*new_asoc
)
1837 /* The cookie should be silently discarded.
1838 * The endpoint SHOULD NOT change states and should leave
1839 * any timers running.
1841 return SCTP_DISPOSITION_DISCARD
;
1844 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1848 * D) When both local and remote tags match the endpoint should always
1849 * enter the ESTABLISHED state, if it has not already done so.
1851 /* This case represents an initialization collision. */
1852 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1853 const struct sctp_association
*asoc
,
1854 struct sctp_chunk
*chunk
,
1855 sctp_cmd_seq_t
*commands
,
1856 struct sctp_association
*new_asoc
)
1858 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1859 struct sctp_chunk
*repl
;
1861 /* Clarification from Implementor's Guide:
1862 * D) When both local and remote tags match the endpoint should
1863 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1864 * It should stop any cookie timer that may be running and send
1868 /* Don't accidentally move back into established state. */
1869 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1870 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1871 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1872 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1873 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1874 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
1875 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1878 /* RFC 2960 5.1 Normal Establishment of an Association
1880 * D) IMPLEMENTATION NOTE: An implementation may choose
1881 * to send the Communication Up notification to the
1882 * SCTP user upon reception of a valid COOKIE
1885 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1887 asoc
->c
.sinit_num_ostreams
,
1888 asoc
->c
.sinit_max_instreams
,
1893 /* Sockets API Draft Section 5.3.1.6
1894 * When a peer sends a Adaptation Layer Indication parameter,
1895 * SCTP delivers this notification to inform the application
1896 * that of the peers requested adaptation layer.
1898 if (asoc
->peer
.adaptation_ind
) {
1899 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1906 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1908 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1913 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1916 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1917 SCTP_ULPEVENT(ai_ev
));
1919 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1920 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSMIT
, SCTP_NULL());
1922 return SCTP_DISPOSITION_CONSUME
;
1926 sctp_ulpevent_free(ai_ev
);
1928 sctp_ulpevent_free(ev
);
1929 return SCTP_DISPOSITION_NOMEM
;
1933 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1934 * chunk was retransmitted and then delayed in the network.
1936 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1938 * Verification Tag: None. Do cookie validation.
1941 * (endpoint, asoc, chunk)
1944 * (asoc, reply_msg, msg_up, timers, counters)
1946 * The return value is the disposition of the chunk.
1948 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1949 const struct sctp_association
*asoc
,
1950 const sctp_subtype_t type
,
1952 sctp_cmd_seq_t
*commands
)
1954 sctp_disposition_t retval
;
1955 struct sctp_chunk
*chunk
= arg
;
1956 struct sctp_association
*new_asoc
;
1959 struct sctp_chunk
*err_chk_p
;
1961 /* Make sure that the chunk has a valid length from the protocol
1962 * perspective. In this case check to make sure we have at least
1963 * enough for the chunk header. Cookie length verification is
1966 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1967 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1970 /* "Decode" the chunk. We have no optional parameters so we
1971 * are in good shape.
1973 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1974 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1975 sizeof(sctp_chunkhdr_t
)))
1978 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1979 * of a duplicate COOKIE ECHO match the Verification Tags of the
1980 * current association, consider the State Cookie valid even if
1981 * the lifespan is exceeded.
1983 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
1987 * If the re-build failed, what is the proper error path
1990 * [We should abort the association. --piggy]
1993 /* FIXME: Several errors are possible. A bad cookie should
1994 * be silently discarded, but think about logging it too.
1997 case -SCTP_IERROR_NOMEM
:
2000 case -SCTP_IERROR_STALE_COOKIE
:
2001 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
2003 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2004 case -SCTP_IERROR_BAD_SIG
:
2006 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2010 /* Compare the tie_tag in cookie with the verification tag of
2011 * current association.
2013 action
= sctp_tietags_compare(new_asoc
, asoc
);
2016 case 'A': /* Association restart. */
2017 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
2021 case 'B': /* Collision case B. */
2022 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
2026 case 'C': /* Collision case C. */
2027 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
2031 case 'D': /* Collision case D. */
2032 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
2036 default: /* Discard packet for all others. */
2037 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2041 /* Delete the tempory new association. */
2042 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
2043 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2048 return SCTP_DISPOSITION_NOMEM
;
2052 * Process an ABORT. (SHUTDOWN-PENDING state)
2054 * See sctp_sf_do_9_1_abort().
2056 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2057 const struct sctp_endpoint
*ep
,
2058 const struct sctp_association
*asoc
,
2059 const sctp_subtype_t type
,
2061 sctp_cmd_seq_t
*commands
)
2063 struct sctp_chunk
*chunk
= arg
;
2065 if (!sctp_vtag_verify_either(chunk
, asoc
))
2066 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2068 /* Make sure that the ABORT chunk has a valid length.
2069 * Since this is an ABORT chunk, we have to discard it
2070 * because of the following text:
2071 * RFC 2960, Section 3.3.7
2072 * If an endpoint receives an ABORT with a format error or for an
2073 * association that doesn't exist, it MUST silently discard it.
2074 * Becasue the length is "invalid", we can't really discard just
2075 * as we do not know its true length. So, to be safe, discard the
2078 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2079 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2081 /* ADD-IP: Special case for ABORT chunks
2082 * F4) One special consideration is that ABORT Chunks arriving
2083 * destined to the IP address being deleted MUST be
2084 * ignored (see Section 5.3.1 for further details).
2086 if (SCTP_ADDR_DEL
==
2087 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2088 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2090 /* Stop the T5-shutdown guard timer. */
2091 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2092 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2094 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2098 * Process an ABORT. (SHUTDOWN-SENT state)
2100 * See sctp_sf_do_9_1_abort().
2102 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
2103 const struct sctp_association
*asoc
,
2104 const sctp_subtype_t type
,
2106 sctp_cmd_seq_t
*commands
)
2108 struct sctp_chunk
*chunk
= arg
;
2110 if (!sctp_vtag_verify_either(chunk
, asoc
))
2111 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2113 /* Make sure that the ABORT chunk has a valid length.
2114 * Since this is an ABORT chunk, we have to discard it
2115 * because of the following text:
2116 * RFC 2960, Section 3.3.7
2117 * If an endpoint receives an ABORT with a format error or for an
2118 * association that doesn't exist, it MUST silently discard it.
2119 * Becasue the length is "invalid", we can't really discard just
2120 * as we do not know its true length. So, to be safe, discard the
2123 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2124 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2126 /* ADD-IP: Special case for ABORT chunks
2127 * F4) One special consideration is that ABORT Chunks arriving
2128 * destined to the IP address being deleted MUST be
2129 * ignored (see Section 5.3.1 for further details).
2131 if (SCTP_ADDR_DEL
==
2132 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2133 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2135 /* Stop the T2-shutdown timer. */
2136 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2137 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2139 /* Stop the T5-shutdown guard timer. */
2140 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2141 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2143 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2147 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2149 * See sctp_sf_do_9_1_abort().
2151 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2152 const struct sctp_endpoint
*ep
,
2153 const struct sctp_association
*asoc
,
2154 const sctp_subtype_t type
,
2156 sctp_cmd_seq_t
*commands
)
2158 /* The same T2 timer, so we should be able to use
2159 * common function with the SHUTDOWN-SENT state.
2161 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2165 * Handle an Error received in COOKIE_ECHOED state.
2167 * Only handle the error type of stale COOKIE Error, the other errors will
2171 * (endpoint, asoc, chunk)
2174 * (asoc, reply_msg, msg_up, timers, counters)
2176 * The return value is the disposition of the chunk.
2178 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2179 const struct sctp_association
*asoc
,
2180 const sctp_subtype_t type
,
2182 sctp_cmd_seq_t
*commands
)
2184 struct sctp_chunk
*chunk
= arg
;
2187 if (!sctp_vtag_verify(chunk
, asoc
))
2188 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2190 /* Make sure that the ERROR chunk has a valid length.
2191 * The parameter walking depends on this as well.
2193 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2194 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2197 /* Process the error here */
2198 /* FUTURE FIXME: When PR-SCTP related and other optional
2199 * parms are emitted, this will have to change to handle multiple
2202 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2203 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2204 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2208 /* It is possible to have malformed error causes, and that
2209 * will cause us to end the walk early. However, since
2210 * we are discarding the packet, there should be no adverse
2213 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2217 * Handle a Stale COOKIE Error
2219 * Section: 5.2.6 Handle Stale COOKIE Error
2220 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2221 * one of the following three alternatives.
2223 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2224 * Preservative parameter requesting an extension to the lifetime of
2225 * the State Cookie. When calculating the time extension, an
2226 * implementation SHOULD use the RTT information measured based on the
2227 * previous COOKIE ECHO / ERROR exchange, and should add no more
2228 * than 1 second beyond the measured RTT, due to long State Cookie
2229 * lifetimes making the endpoint more subject to a replay attack.
2231 * Verification Tag: Not explicit, but safe to ignore.
2234 * (endpoint, asoc, chunk)
2237 * (asoc, reply_msg, msg_up, timers, counters)
2239 * The return value is the disposition of the chunk.
2241 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2242 const struct sctp_association
*asoc
,
2243 const sctp_subtype_t type
,
2245 sctp_cmd_seq_t
*commands
)
2247 struct sctp_chunk
*chunk
= arg
;
2249 sctp_cookie_preserve_param_t bht
;
2251 struct sctp_chunk
*reply
;
2252 struct sctp_bind_addr
*bp
;
2253 int attempts
= asoc
->init_err_counter
+ 1;
2255 if (attempts
> asoc
->max_init_attempts
) {
2256 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2257 SCTP_ERROR(ETIMEDOUT
));
2258 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2259 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2260 return SCTP_DISPOSITION_DELETE_TCB
;
2263 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2265 /* When calculating the time extension, an implementation
2266 * SHOULD use the RTT information measured based on the
2267 * previous COOKIE ECHO / ERROR exchange, and should add no
2268 * more than 1 second beyond the measured RTT, due to long
2269 * State Cookie lifetimes making the endpoint more subject to
2271 * Measure of Staleness's unit is usec. (1/1000000 sec)
2272 * Suggested Cookie Life-span Increment's unit is msec.
2274 * In general, if you use the suggested cookie life, the value
2275 * found in the field of measure of staleness should be doubled
2276 * to give ample time to retransmit the new cookie and thus
2277 * yield a higher probability of success on the reattempt.
2279 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2280 stale
= (stale
* 2) / 1000;
2282 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2283 bht
.param_hdr
.length
= htons(sizeof(bht
));
2284 bht
.lifespan_increment
= htonl(stale
);
2286 /* Build that new INIT chunk. */
2287 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2288 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2292 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2294 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2295 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2297 /* Stop pending T3-rtx and heartbeat timers */
2298 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2299 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2301 /* Delete non-primary peer ip addresses since we are transitioning
2302 * back to the COOKIE-WAIT state
2304 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2306 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2309 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2310 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2312 /* Cast away the const modifier, as we want to just
2313 * rerun it through as a sideffect.
2315 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2317 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2318 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2319 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2320 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2321 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2322 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2324 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2326 return SCTP_DISPOSITION_CONSUME
;
2329 return SCTP_DISPOSITION_NOMEM
;
2336 * After checking the Verification Tag, the receiving endpoint shall
2337 * remove the association from its record, and shall report the
2338 * termination to its upper layer.
2340 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2341 * B) Rules for packet carrying ABORT:
2343 * - The endpoint shall always fill in the Verification Tag field of the
2344 * outbound packet with the destination endpoint's tag value if it
2347 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2348 * MUST follow the procedure described in Section 8.4.
2350 * - The receiver MUST accept the packet if the Verification Tag
2351 * matches either its own tag, OR the tag of its peer. Otherwise, the
2352 * receiver MUST silently discard the packet and take no further
2356 * (endpoint, asoc, chunk)
2359 * (asoc, reply_msg, msg_up, timers, counters)
2361 * The return value is the disposition of the chunk.
2363 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2364 const struct sctp_association
*asoc
,
2365 const sctp_subtype_t type
,
2367 sctp_cmd_seq_t
*commands
)
2369 struct sctp_chunk
*chunk
= arg
;
2371 if (!sctp_vtag_verify_either(chunk
, asoc
))
2372 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2374 /* Make sure that the ABORT chunk has a valid length.
2375 * Since this is an ABORT chunk, we have to discard it
2376 * because of the following text:
2377 * RFC 2960, Section 3.3.7
2378 * If an endpoint receives an ABORT with a format error or for an
2379 * association that doesn't exist, it MUST silently discard it.
2380 * Becasue the length is "invalid", we can't really discard just
2381 * as we do not know its true length. So, to be safe, discard the
2384 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2385 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2387 /* ADD-IP: Special case for ABORT chunks
2388 * F4) One special consideration is that ABORT Chunks arriving
2389 * destined to the IP address being deleted MUST be
2390 * ignored (see Section 5.3.1 for further details).
2392 if (SCTP_ADDR_DEL
==
2393 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2394 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2396 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2399 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2400 const struct sctp_association
*asoc
,
2401 const sctp_subtype_t type
,
2403 sctp_cmd_seq_t
*commands
)
2405 struct sctp_chunk
*chunk
= arg
;
2407 __be16 error
= SCTP_ERROR_NO_ERROR
;
2409 /* See if we have an error cause code in the chunk. */
2410 len
= ntohs(chunk
->chunk_hdr
->length
);
2411 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2412 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2414 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2415 /* ASSOC_FAILED will DELETE_TCB. */
2416 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2417 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2418 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
2420 return SCTP_DISPOSITION_ABORT
;
2424 * Process an ABORT. (COOKIE-WAIT state)
2426 * See sctp_sf_do_9_1_abort() above.
2428 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2429 const struct sctp_association
*asoc
,
2430 const sctp_subtype_t type
,
2432 sctp_cmd_seq_t
*commands
)
2434 struct sctp_chunk
*chunk
= arg
;
2436 __be16 error
= SCTP_ERROR_NO_ERROR
;
2438 if (!sctp_vtag_verify_either(chunk
, asoc
))
2439 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2441 /* Make sure that the ABORT chunk has a valid length.
2442 * Since this is an ABORT chunk, we have to discard it
2443 * because of the following text:
2444 * RFC 2960, Section 3.3.7
2445 * If an endpoint receives an ABORT with a format error or for an
2446 * association that doesn't exist, it MUST silently discard it.
2447 * Becasue the length is "invalid", we can't really discard just
2448 * as we do not know its true length. So, to be safe, discard the
2451 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2452 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2454 /* See if we have an error cause code in the chunk. */
2455 len
= ntohs(chunk
->chunk_hdr
->length
);
2456 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2457 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2459 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
, asoc
,
2464 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2466 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2467 const struct sctp_association
*asoc
,
2468 const sctp_subtype_t type
,
2470 sctp_cmd_seq_t
*commands
)
2472 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
,
2474 (struct sctp_transport
*)arg
);
2478 * Process an ABORT. (COOKIE-ECHOED state)
2480 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2481 const struct sctp_association
*asoc
,
2482 const sctp_subtype_t type
,
2484 sctp_cmd_seq_t
*commands
)
2486 /* There is a single T1 timer, so we should be able to use
2487 * common function with the COOKIE-WAIT state.
2489 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2493 * Stop T1 timer and abort association with "INIT failed".
2495 * This is common code called by several sctp_sf_*_abort() functions above.
2497 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2498 __be16 error
, int sk_err
,
2499 const struct sctp_association
*asoc
,
2500 struct sctp_transport
*transport
)
2502 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2503 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2504 SCTP_STATE(SCTP_STATE_CLOSED
));
2505 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
2506 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2507 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2508 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2509 /* CMD_INIT_FAILED will DELETE_TCB. */
2510 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2512 return SCTP_DISPOSITION_ABORT
;
2516 * sctp_sf_do_9_2_shut
2519 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2520 * - enter the SHUTDOWN-RECEIVED state,
2522 * - stop accepting new data from its SCTP user
2524 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2525 * that all its outstanding DATA chunks have been received by the
2528 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2529 * send a SHUTDOWN in response to a ULP request. And should discard
2530 * subsequent SHUTDOWN chunks.
2532 * If there are still outstanding DATA chunks left, the SHUTDOWN
2533 * receiver shall continue to follow normal data transmission
2534 * procedures defined in Section 6 until all outstanding DATA chunks
2535 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2536 * new data from its SCTP user.
2538 * Verification Tag: 8.5 Verification Tag [Normal verification]
2541 * (endpoint, asoc, chunk)
2544 * (asoc, reply_msg, msg_up, timers, counters)
2546 * The return value is the disposition of the chunk.
2548 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2549 const struct sctp_association
*asoc
,
2550 const sctp_subtype_t type
,
2552 sctp_cmd_seq_t
*commands
)
2554 struct sctp_chunk
*chunk
= arg
;
2555 sctp_shutdownhdr_t
*sdh
;
2556 sctp_disposition_t disposition
;
2557 struct sctp_ulpevent
*ev
;
2559 if (!sctp_vtag_verify(chunk
, asoc
))
2560 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2562 /* Make sure that the SHUTDOWN chunk has a valid length. */
2563 if (!sctp_chunk_length_valid(chunk
,
2564 sizeof(struct sctp_shutdown_chunk_t
)))
2565 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2568 /* Convert the elaborate header. */
2569 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2570 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2571 chunk
->subh
.shutdown_hdr
= sdh
;
2573 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2574 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2575 * inform the application that it should cease sending data.
2577 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2579 disposition
= SCTP_DISPOSITION_NOMEM
;
2582 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2584 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2585 * - enter the SHUTDOWN-RECEIVED state,
2586 * - stop accepting new data from its SCTP user
2588 * [This is implicit in the new state.]
2590 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2591 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2592 disposition
= SCTP_DISPOSITION_CONSUME
;
2594 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2595 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2599 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2602 /* - verify, by checking the Cumulative TSN Ack field of the
2603 * chunk, that all its outstanding DATA chunks have been
2604 * received by the SHUTDOWN sender.
2606 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2607 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2614 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2615 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2616 * transport addresses (either in the IP addresses or in the INIT chunk)
2617 * that belong to this association, it should discard the INIT chunk and
2618 * retransmit the SHUTDOWN ACK chunk.
2620 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2621 const struct sctp_association
*asoc
,
2622 const sctp_subtype_t type
,
2624 sctp_cmd_seq_t
*commands
)
2626 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2627 struct sctp_chunk
*reply
;
2629 /* Make sure that the chunk has a valid length */
2630 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2631 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2634 /* Since we are not going to really process this INIT, there
2635 * is no point in verifying chunk boundries. Just generate
2638 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2642 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2643 * the T2-SHUTDOWN timer.
2645 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2647 /* and restart the T2-shutdown timer. */
2648 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2649 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2651 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2653 return SCTP_DISPOSITION_CONSUME
;
2655 return SCTP_DISPOSITION_NOMEM
;
2659 * sctp_sf_do_ecn_cwr
2661 * Section: Appendix A: Explicit Congestion Notification
2665 * RFC 2481 details a specific bit for a sender to send in the header of
2666 * its next outbound TCP segment to indicate to its peer that it has
2667 * reduced its congestion window. This is termed the CWR bit. For
2668 * SCTP the same indication is made by including the CWR chunk.
2669 * This chunk contains one data element, i.e. the TSN number that
2670 * was sent in the ECNE chunk. This element represents the lowest
2671 * TSN number in the datagram that was originally marked with the
2674 * Verification Tag: 8.5 Verification Tag [Normal verification]
2676 * (endpoint, asoc, chunk)
2679 * (asoc, reply_msg, msg_up, timers, counters)
2681 * The return value is the disposition of the chunk.
2683 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2684 const struct sctp_association
*asoc
,
2685 const sctp_subtype_t type
,
2687 sctp_cmd_seq_t
*commands
)
2690 struct sctp_chunk
*chunk
= arg
;
2693 if (!sctp_vtag_verify(chunk
, asoc
))
2694 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2696 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2697 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2700 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2701 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2703 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2705 /* Does this CWR ack the last sent congestion notification? */
2706 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2707 /* Stop sending ECNE. */
2708 sctp_add_cmd_sf(commands
,
2710 SCTP_U32(lowest_tsn
));
2712 return SCTP_DISPOSITION_CONSUME
;
2718 * Section: Appendix A: Explicit Congestion Notification
2722 * RFC 2481 details a specific bit for a receiver to send back in its
2723 * TCP acknowledgements to notify the sender of the Congestion
2724 * Experienced (CE) bit having arrived from the network. For SCTP this
2725 * same indication is made by including the ECNE chunk. This chunk
2726 * contains one data element, i.e. the lowest TSN associated with the IP
2727 * datagram marked with the CE bit.....
2729 * Verification Tag: 8.5 Verification Tag [Normal verification]
2731 * (endpoint, asoc, chunk)
2734 * (asoc, reply_msg, msg_up, timers, counters)
2736 * The return value is the disposition of the chunk.
2738 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2739 const struct sctp_association
*asoc
,
2740 const sctp_subtype_t type
,
2742 sctp_cmd_seq_t
*commands
)
2744 sctp_ecnehdr_t
*ecne
;
2745 struct sctp_chunk
*chunk
= arg
;
2747 if (!sctp_vtag_verify(chunk
, asoc
))
2748 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2750 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2751 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2754 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2755 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2757 /* If this is a newer ECNE than the last CWR packet we sent out */
2758 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2759 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2761 return SCTP_DISPOSITION_CONSUME
;
2765 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2767 * The SCTP endpoint MUST always acknowledge the reception of each valid
2770 * The guidelines on delayed acknowledgement algorithm specified in
2771 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2772 * acknowledgement SHOULD be generated for at least every second packet
2773 * (not every second DATA chunk) received, and SHOULD be generated within
2774 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2775 * situations it may be beneficial for an SCTP transmitter to be more
2776 * conservative than the algorithms detailed in this document allow.
2777 * However, an SCTP transmitter MUST NOT be more aggressive than the
2778 * following algorithms allow.
2780 * A SCTP receiver MUST NOT generate more than one SACK for every
2781 * incoming packet, other than to update the offered window as the
2782 * receiving application consumes new data.
2784 * Verification Tag: 8.5 Verification Tag [Normal verification]
2787 * (endpoint, asoc, chunk)
2790 * (asoc, reply_msg, msg_up, timers, counters)
2792 * The return value is the disposition of the chunk.
2794 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2795 const struct sctp_association
*asoc
,
2796 const sctp_subtype_t type
,
2798 sctp_cmd_seq_t
*commands
)
2800 struct sctp_chunk
*chunk
= arg
;
2803 if (!sctp_vtag_verify(chunk
, asoc
)) {
2804 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2806 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2809 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2810 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2813 error
= sctp_eat_data(asoc
, chunk
, commands
);
2815 case SCTP_IERROR_NO_ERROR
:
2817 case SCTP_IERROR_HIGH_TSN
:
2818 case SCTP_IERROR_BAD_STREAM
:
2819 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2820 goto discard_noforce
;
2821 case SCTP_IERROR_DUP_TSN
:
2822 case SCTP_IERROR_IGNORE_TSN
:
2823 SCTP_INC_STATS(SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2825 case SCTP_IERROR_NO_DATA
:
2831 if (asoc
->autoclose
) {
2832 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2833 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2836 /* If this is the last chunk in a packet, we need to count it
2837 * toward sack generation. Note that we need to SACK every
2838 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2839 * THEM. We elect to NOT generate SACK's if the chunk fails
2840 * the verification tag test.
2842 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2844 * The SCTP endpoint MUST always acknowledge the reception of
2845 * each valid DATA chunk.
2847 * The guidelines on delayed acknowledgement algorithm
2848 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2849 * Specifically, an acknowledgement SHOULD be generated for at
2850 * least every second packet (not every second DATA chunk)
2851 * received, and SHOULD be generated within 200 ms of the
2852 * arrival of any unacknowledged DATA chunk. In some
2853 * situations it may be beneficial for an SCTP transmitter to
2854 * be more conservative than the algorithms detailed in this
2855 * document allow. However, an SCTP transmitter MUST NOT be
2856 * more aggressive than the following algorithms allow.
2858 if (chunk
->end_of_packet
)
2859 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2861 return SCTP_DISPOSITION_CONSUME
;
2864 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2866 * When a packet arrives with duplicate DATA chunk(s) and with
2867 * no new DATA chunk(s), the endpoint MUST immediately send a
2868 * SACK with no delay. If a packet arrives with duplicate
2869 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2870 * MAY immediately send a SACK. Normally receipt of duplicate
2871 * DATA chunks will occur when the original SACK chunk was lost
2872 * and the peer's RTO has expired. The duplicate TSN number(s)
2873 * SHOULD be reported in the SACK as duplicate.
2875 /* In our case, we split the MAY SACK advice up whether or not
2876 * the last chunk is a duplicate.'
2878 if (chunk
->end_of_packet
)
2879 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2880 return SCTP_DISPOSITION_DISCARD
;
2883 if (chunk
->end_of_packet
)
2884 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
2886 return SCTP_DISPOSITION_DISCARD
;
2888 return SCTP_DISPOSITION_CONSUME
;
2893 * sctp_sf_eat_data_fast_4_4
2896 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2897 * DATA chunks without delay.
2899 * Verification Tag: 8.5 Verification Tag [Normal verification]
2901 * (endpoint, asoc, chunk)
2904 * (asoc, reply_msg, msg_up, timers, counters)
2906 * The return value is the disposition of the chunk.
2908 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
2909 const struct sctp_association
*asoc
,
2910 const sctp_subtype_t type
,
2912 sctp_cmd_seq_t
*commands
)
2914 struct sctp_chunk
*chunk
= arg
;
2917 if (!sctp_vtag_verify(chunk
, asoc
)) {
2918 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2920 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2923 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2924 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2927 error
= sctp_eat_data(asoc
, chunk
, commands
);
2929 case SCTP_IERROR_NO_ERROR
:
2930 case SCTP_IERROR_HIGH_TSN
:
2931 case SCTP_IERROR_DUP_TSN
:
2932 case SCTP_IERROR_IGNORE_TSN
:
2933 case SCTP_IERROR_BAD_STREAM
:
2935 case SCTP_IERROR_NO_DATA
:
2941 /* Go a head and force a SACK, since we are shutting down. */
2943 /* Implementor's Guide.
2945 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
2946 * respond to each received packet containing one or more DATA chunk(s)
2947 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
2949 if (chunk
->end_of_packet
) {
2950 /* We must delay the chunk creation since the cumulative
2951 * TSN has not been updated yet.
2953 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
2954 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2955 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2956 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2960 return SCTP_DISPOSITION_CONSUME
;
2964 * Section: 6.2 Processing a Received SACK
2965 * D) Any time a SACK arrives, the endpoint performs the following:
2967 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
2968 * then drop the SACK. Since Cumulative TSN Ack is monotonically
2969 * increasing, a SACK whose Cumulative TSN Ack is less than the
2970 * Cumulative TSN Ack Point indicates an out-of-order SACK.
2972 * ii) Set rwnd equal to the newly received a_rwnd minus the number
2973 * of bytes still outstanding after processing the Cumulative TSN Ack
2974 * and the Gap Ack Blocks.
2976 * iii) If the SACK is missing a TSN that was previously
2977 * acknowledged via a Gap Ack Block (e.g., the data receiver
2978 * reneged on the data), then mark the corresponding DATA chunk
2979 * as available for retransmit: Mark it as missing for fast
2980 * retransmit as described in Section 7.2.4 and if no retransmit
2981 * timer is running for the destination address to which the DATA
2982 * chunk was originally transmitted, then T3-rtx is started for
2983 * that destination address.
2985 * Verification Tag: 8.5 Verification Tag [Normal verification]
2988 * (endpoint, asoc, chunk)
2991 * (asoc, reply_msg, msg_up, timers, counters)
2993 * The return value is the disposition of the chunk.
2995 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
2996 const struct sctp_association
*asoc
,
2997 const sctp_subtype_t type
,
2999 sctp_cmd_seq_t
*commands
)
3001 struct sctp_chunk
*chunk
= arg
;
3002 sctp_sackhdr_t
*sackh
;
3005 if (!sctp_vtag_verify(chunk
, asoc
))
3006 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3008 /* Make sure that the SACK chunk has a valid length. */
3009 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3010 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3013 /* Pull the SACK chunk from the data buffer */
3014 sackh
= sctp_sm_pull_sack(chunk
);
3015 /* Was this a bogus SACK? */
3017 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3018 chunk
->subh
.sack_hdr
= sackh
;
3019 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3021 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3022 * Ack Point, then drop the SACK. Since Cumulative TSN
3023 * Ack is monotonically increasing, a SACK whose
3024 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3025 * Point indicates an out-of-order SACK.
3027 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3028 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
3029 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
3030 return SCTP_DISPOSITION_DISCARD
;
3033 /* If Cumulative TSN Ack beyond the max tsn currently
3034 * send, terminating the association and respond to the
3035 * sender with an ABORT.
3037 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3038 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
3040 /* Return this SACK for further processing. */
3041 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
3043 /* Note: We do the rest of the work on the PROCESS_SACK
3046 return SCTP_DISPOSITION_CONSUME
;
3050 * Generate an ABORT in response to a packet.
3052 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3054 * 8) The receiver should respond to the sender of the OOTB packet with
3055 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3056 * MUST fill in the Verification Tag field of the outbound packet
3057 * with the value found in the Verification Tag field of the OOTB
3058 * packet and set the T-bit in the Chunk Flags to indicate that the
3059 * Verification Tag is reflected. After sending this ABORT, the
3060 * receiver of the OOTB packet shall discard the OOTB packet and take
3061 * no further action.
3065 * The return value is the disposition of the chunk.
3067 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
3068 const struct sctp_association
*asoc
,
3069 const sctp_subtype_t type
,
3071 sctp_cmd_seq_t
*commands
)
3073 struct sctp_packet
*packet
= NULL
;
3074 struct sctp_chunk
*chunk
= arg
;
3075 struct sctp_chunk
*abort
;
3077 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3080 /* Make an ABORT. The T bit will be set if the asoc
3083 abort
= sctp_make_abort(asoc
, chunk
, 0);
3085 sctp_ootb_pkt_free(packet
);
3086 return SCTP_DISPOSITION_NOMEM
;
3089 /* Reflect vtag if T-Bit is set */
3090 if (sctp_test_T_bit(abort
))
3091 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3093 /* Set the skb to the belonging sock for accounting. */
3094 abort
->skb
->sk
= ep
->base
.sk
;
3096 sctp_packet_append_chunk(packet
, abort
);
3098 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3099 SCTP_PACKET(packet
));
3101 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3103 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3104 return SCTP_DISPOSITION_CONSUME
;
3107 return SCTP_DISPOSITION_NOMEM
;
3111 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3112 * event as ULP notification for each cause included in the chunk.
3114 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3116 * The return value is the disposition of the chunk.
3118 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
3119 const struct sctp_association
*asoc
,
3120 const sctp_subtype_t type
,
3122 sctp_cmd_seq_t
*commands
)
3124 struct sctp_chunk
*chunk
= arg
;
3125 struct sctp_ulpevent
*ev
;
3127 if (!sctp_vtag_verify(chunk
, asoc
))
3128 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3130 /* Make sure that the ERROR chunk has a valid length. */
3131 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3132 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3135 while (chunk
->chunk_end
> chunk
->skb
->data
) {
3136 ev
= sctp_ulpevent_make_remote_error(asoc
, chunk
, 0,
3141 if (!sctp_add_cmd(commands
, SCTP_CMD_EVENT_ULP
,
3142 SCTP_ULPEVENT(ev
))) {
3143 sctp_ulpevent_free(ev
);
3147 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3150 return SCTP_DISPOSITION_CONSUME
;
3153 return SCTP_DISPOSITION_NOMEM
;
3157 * Process an inbound SHUTDOWN ACK.
3160 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3161 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3162 * peer, and remove all record of the association.
3164 * The return value is the disposition.
3166 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
3167 const struct sctp_association
*asoc
,
3168 const sctp_subtype_t type
,
3170 sctp_cmd_seq_t
*commands
)
3172 struct sctp_chunk
*chunk
= arg
;
3173 struct sctp_chunk
*reply
;
3174 struct sctp_ulpevent
*ev
;
3176 if (!sctp_vtag_verify(chunk
, asoc
))
3177 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3179 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3180 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3181 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3183 /* 10.2 H) SHUTDOWN COMPLETE notification
3185 * When SCTP completes the shutdown procedures (section 9.2) this
3186 * notification is passed to the upper layer.
3188 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3189 0, 0, 0, NULL
, GFP_ATOMIC
);
3193 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3194 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3198 /* Do all the commands now (after allocation), so that we
3199 * have consistent state if memory allocation failes
3201 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3203 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3204 * stop the T2-shutdown timer,
3206 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3207 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3209 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3210 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3212 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3213 SCTP_STATE(SCTP_STATE_CLOSED
));
3214 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
3215 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3216 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3218 /* ...and remove all record of the association. */
3219 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3220 return SCTP_DISPOSITION_DELETE_TCB
;
3223 sctp_ulpevent_free(ev
);
3225 return SCTP_DISPOSITION_NOMEM
;
3229 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3231 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3232 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3233 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3234 * packet must fill in the Verification Tag field of the outbound
3235 * packet with the Verification Tag received in the SHUTDOWN ACK and
3236 * set the T-bit in the Chunk Flags to indicate that the Verification
3239 * 8) The receiver should respond to the sender of the OOTB packet with
3240 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3241 * MUST fill in the Verification Tag field of the outbound packet
3242 * with the value found in the Verification Tag field of the OOTB
3243 * packet and set the T-bit in the Chunk Flags to indicate that the
3244 * Verification Tag is reflected. After sending this ABORT, the
3245 * receiver of the OOTB packet shall discard the OOTB packet and take
3246 * no further action.
3248 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3249 const struct sctp_association
*asoc
,
3250 const sctp_subtype_t type
,
3252 sctp_cmd_seq_t
*commands
)
3254 struct sctp_chunk
*chunk
= arg
;
3255 struct sk_buff
*skb
= chunk
->skb
;
3256 sctp_chunkhdr_t
*ch
;
3258 int ootb_shut_ack
= 0;
3260 SCTP_INC_STATS(SCTP_MIB_OUTOFBLUES
);
3262 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3264 /* Report violation if the chunk is less then minimal */
3265 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3266 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3269 /* Now that we know we at least have a chunk header,
3270 * do things that are type appropriate.
3272 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3275 /* RFC 2960, Section 3.3.7
3276 * Moreover, under any circumstances, an endpoint that
3277 * receives an ABORT MUST NOT respond to that ABORT by
3278 * sending an ABORT of its own.
3280 if (SCTP_CID_ABORT
== ch
->type
)
3281 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3283 /* Report violation if chunk len overflows */
3284 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3285 if (ch_end
> skb_tail_pointer(skb
))
3286 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3289 ch
= (sctp_chunkhdr_t
*) ch_end
;
3290 } while (ch_end
< skb_tail_pointer(skb
));
3293 return sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3295 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3299 * Handle an "Out of the blue" SHUTDOWN ACK.
3301 * Section: 8.4 5, sctpimpguide 2.41.
3303 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3304 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3305 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3306 * packet must fill in the Verification Tag field of the outbound
3307 * packet with the Verification Tag received in the SHUTDOWN ACK and
3308 * set the T-bit in the Chunk Flags to indicate that the Verification
3312 * (endpoint, asoc, type, arg, commands)
3315 * (sctp_disposition_t)
3317 * The return value is the disposition of the chunk.
3319 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3320 const struct sctp_association
*asoc
,
3321 const sctp_subtype_t type
,
3323 sctp_cmd_seq_t
*commands
)
3325 struct sctp_packet
*packet
= NULL
;
3326 struct sctp_chunk
*chunk
= arg
;
3327 struct sctp_chunk
*shut
;
3329 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
3332 /* Make an SHUTDOWN_COMPLETE.
3333 * The T bit will be set if the asoc is NULL.
3335 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3337 sctp_ootb_pkt_free(packet
);
3338 return SCTP_DISPOSITION_NOMEM
;
3341 /* Reflect vtag if T-Bit is set */
3342 if (sctp_test_T_bit(shut
))
3343 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3345 /* Set the skb to the belonging sock for accounting. */
3346 shut
->skb
->sk
= ep
->base
.sk
;
3348 sctp_packet_append_chunk(packet
, shut
);
3350 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3351 SCTP_PACKET(packet
));
3353 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
3355 /* If the chunk length is invalid, we don't want to process
3356 * the reset of the packet.
3358 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3359 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3361 /* We need to discard the rest of the packet to prevent
3362 * potential bomming attacks from additional bundled chunks.
3363 * This is documented in SCTP Threats ID.
3365 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3368 return SCTP_DISPOSITION_NOMEM
;
3372 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3374 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3375 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3376 * procedures in section 8.4 SHOULD be followed, in other words it
3377 * should be treated as an Out Of The Blue packet.
3378 * [This means that we do NOT check the Verification Tag on these
3382 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3383 const struct sctp_association
*asoc
,
3384 const sctp_subtype_t type
,
3386 sctp_cmd_seq_t
*commands
)
3388 struct sctp_chunk
*chunk
= arg
;
3390 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3391 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3392 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3395 /* Although we do have an association in this case, it corresponds
3396 * to a restarted association. So the packet is treated as an OOTB
3397 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3398 * called with a NULL association.
3400 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3403 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3404 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3405 const struct sctp_association
*asoc
,
3406 const sctp_subtype_t type
, void *arg
,
3407 sctp_cmd_seq_t
*commands
)
3409 struct sctp_chunk
*chunk
= arg
;
3410 struct sctp_chunk
*asconf_ack
= NULL
;
3411 struct sctp_paramhdr
*err_param
= NULL
;
3412 sctp_addiphdr_t
*hdr
;
3413 union sctp_addr_param
*addr_param
;
3417 if (!sctp_vtag_verify(chunk
, asoc
)) {
3418 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3420 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3423 /* ADD-IP: Section 4.1.1
3424 * This chunk MUST be sent in an authenticated way by using
3425 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3426 * is received unauthenticated it MUST be silently discarded as
3427 * described in [I-D.ietf-tsvwg-sctp-auth].
3429 if (!sctp_addip_noauth
&& !chunk
->auth
)
3430 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3432 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3433 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3434 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3437 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3438 serial
= ntohl(hdr
->serial
);
3440 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3441 length
= ntohs(addr_param
->p
.length
);
3442 if (length
< sizeof(sctp_paramhdr_t
))
3443 return sctp_sf_violation_paramlen(ep
, asoc
, type
,
3444 (void *)addr_param
, commands
);
3446 /* Verify the ASCONF chunk before processing it. */
3447 if (!sctp_verify_asconf(asoc
,
3448 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3449 (void *)chunk
->chunk_end
,
3451 return sctp_sf_violation_paramlen(ep
, asoc
, type
,
3452 (void *)&err_param
, commands
);
3454 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3455 * the endpoint stored in a new association variable
3456 * 'Peer-Serial-Number'.
3458 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3459 /* If this is the first instance of ASCONF in the packet,
3460 * we can clean our old ASCONF-ACKs.
3462 if (!chunk
->has_asconf
)
3463 sctp_assoc_clean_asconf_ack_cache(asoc
);
3465 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3466 * expected, process the ASCONF as described below and after
3467 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3468 * the response packet and cache a copy of it (in the event it
3469 * later needs to be retransmitted).
3471 * Essentially, do V1-V5.
3473 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3476 return SCTP_DISPOSITION_NOMEM
;
3477 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3479 * If the value found in the Sequence Number is less than the
3480 * ('Peer- Sequence-Number' + 1), simply skip to the next
3481 * ASCONF, and include in the outbound response packet
3482 * any previously cached ASCONF-ACK response that was
3483 * sent and saved that matches the Sequence Number of the
3484 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3485 * Chunk exists. This will occur when an older ASCONF
3486 * arrives out of order. In such a case, the receiver
3487 * should skip the ASCONF Chunk and not include ASCONF-ACK
3488 * Chunk for that chunk.
3490 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3492 return SCTP_DISPOSITION_DISCARD
;
3494 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3495 * it must be either a stale packet or from an attacker.
3497 return SCTP_DISPOSITION_DISCARD
;
3500 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3501 * containing the ASCONF-ACK Chunks MUST be the source address of
3502 * the SCTP packet that held the ASCONF Chunks.
3504 * To do this properly, we'll set the destination address of the chunk
3505 * and at the transmit time, will try look up the transport to use.
3506 * Since ASCONFs may be bundled, the correct transport may not be
3507 * created untill we process the entire packet, thus this workaround.
3509 asconf_ack
->dest
= chunk
->source
;
3510 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3512 return SCTP_DISPOSITION_CONSUME
;
3516 * ADDIP Section 4.3 General rules for address manipulation
3517 * When building TLV parameters for the ASCONF Chunk that will add or
3518 * delete IP addresses the D0 to D13 rules should be applied:
3520 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3521 const struct sctp_association
*asoc
,
3522 const sctp_subtype_t type
, void *arg
,
3523 sctp_cmd_seq_t
*commands
)
3525 struct sctp_chunk
*asconf_ack
= arg
;
3526 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3527 struct sctp_chunk
*abort
;
3528 struct sctp_paramhdr
*err_param
= NULL
;
3529 sctp_addiphdr_t
*addip_hdr
;
3530 __u32 sent_serial
, rcvd_serial
;
3532 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3533 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3535 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3538 /* ADD-IP, Section 4.1.2:
3539 * This chunk MUST be sent in an authenticated way by using
3540 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3541 * is received unauthenticated it MUST be silently discarded as
3542 * described in [I-D.ietf-tsvwg-sctp-auth].
3544 if (!sctp_addip_noauth
&& !asconf_ack
->auth
)
3545 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3547 /* Make sure that the ADDIP chunk has a valid length. */
3548 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3549 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3552 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3553 rcvd_serial
= ntohl(addip_hdr
->serial
);
3555 /* Verify the ASCONF-ACK chunk before processing it. */
3556 if (!sctp_verify_asconf(asoc
,
3557 (sctp_paramhdr_t
*)addip_hdr
->params
,
3558 (void *)asconf_ack
->chunk_end
,
3560 return sctp_sf_violation_paramlen(ep
, asoc
, type
,
3561 (void *)&err_param
, commands
);
3564 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3565 sent_serial
= ntohl(addip_hdr
->serial
);
3567 sent_serial
= asoc
->addip_serial
- 1;
3570 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3571 * equal to the next serial number to be used but no ASCONF chunk is
3572 * outstanding the endpoint MUST ABORT the association. Note that a
3573 * sequence number is greater than if it is no more than 2^^31-1
3574 * larger than the current sequence number (using serial arithmetic).
3576 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3577 !(asoc
->addip_last_asconf
)) {
3578 abort
= sctp_make_abort(asoc
, asconf_ack
,
3579 sizeof(sctp_errhdr_t
));
3581 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3582 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3585 /* We are going to ABORT, so we might as well stop
3586 * processing the rest of the chunks in the packet.
3588 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3589 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3590 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3591 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3592 SCTP_ERROR(ECONNABORTED
));
3593 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3594 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3595 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3596 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3597 return SCTP_DISPOSITION_ABORT
;
3600 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3601 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3602 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3604 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3606 return SCTP_DISPOSITION_CONSUME
;
3608 abort
= sctp_make_abort(asoc
, asconf_ack
,
3609 sizeof(sctp_errhdr_t
));
3611 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3612 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3615 /* We are going to ABORT, so we might as well stop
3616 * processing the rest of the chunks in the packet.
3618 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3619 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3620 SCTP_ERROR(ECONNABORTED
));
3621 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3622 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3623 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
3624 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
3625 return SCTP_DISPOSITION_ABORT
;
3628 return SCTP_DISPOSITION_DISCARD
;
3632 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3634 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3635 * its cumulative TSN point to the value carried in the FORWARD TSN
3636 * chunk, and then MUST further advance its cumulative TSN point locally
3638 * After the above processing, the data receiver MUST stop reporting any
3639 * missing TSNs earlier than or equal to the new cumulative TSN point.
3641 * Verification Tag: 8.5 Verification Tag [Normal verification]
3643 * The return value is the disposition of the chunk.
3645 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3646 const struct sctp_association
*asoc
,
3647 const sctp_subtype_t type
,
3649 sctp_cmd_seq_t
*commands
)
3651 struct sctp_chunk
*chunk
= arg
;
3652 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3656 if (!sctp_vtag_verify(chunk
, asoc
)) {
3657 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3659 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3662 /* Make sure that the FORWARD_TSN chunk has valid length. */
3663 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3664 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3667 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3668 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3669 len
= ntohs(chunk
->chunk_hdr
->length
);
3670 len
-= sizeof(struct sctp_chunkhdr
);
3671 skb_pull(chunk
->skb
, len
);
3673 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3674 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3676 /* The TSN is too high--silently discard the chunk and count on it
3677 * getting retransmitted later.
3679 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3680 goto discard_noforce
;
3682 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3683 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3684 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3687 /* Count this as receiving DATA. */
3688 if (asoc
->autoclose
) {
3689 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3690 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3693 /* FIXME: For now send a SACK, but DATA processing may
3696 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3698 return SCTP_DISPOSITION_CONSUME
;
3701 return SCTP_DISPOSITION_DISCARD
;
3704 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3705 const struct sctp_endpoint
*ep
,
3706 const struct sctp_association
*asoc
,
3707 const sctp_subtype_t type
,
3709 sctp_cmd_seq_t
*commands
)
3711 struct sctp_chunk
*chunk
= arg
;
3712 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3716 if (!sctp_vtag_verify(chunk
, asoc
)) {
3717 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3719 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3722 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3723 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3724 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3727 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3728 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3729 len
= ntohs(chunk
->chunk_hdr
->length
);
3730 len
-= sizeof(struct sctp_chunkhdr
);
3731 skb_pull(chunk
->skb
, len
);
3733 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3734 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __FUNCTION__
, tsn
);
3736 /* The TSN is too high--silently discard the chunk and count on it
3737 * getting retransmitted later.
3739 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3742 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3743 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3744 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3747 /* Go a head and force a SACK, since we are shutting down. */
3749 /* Implementor's Guide.
3751 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3752 * respond to each received packet containing one or more DATA chunk(s)
3753 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3755 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3756 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3757 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3758 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3760 return SCTP_DISPOSITION_CONSUME
;
3764 * SCTP-AUTH Section 6.3 Receving authenticated chukns
3766 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3767 * Identifier field. If this algorithm was not specified by the
3768 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3769 * during association setup, the AUTH chunk and all chunks after it MUST
3770 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3771 * defined in Section 4.1.
3773 * If an endpoint with no shared key receives a Shared Key Identifier
3774 * other than 0, it MUST silently discard all authenticated chunks. If
3775 * the endpoint has at least one endpoint pair shared key for the peer,
3776 * it MUST use the key specified by the Shared Key Identifier if a
3777 * key has been configured for that Shared Key Identifier. If no
3778 * endpoint pair shared key has been configured for that Shared Key
3779 * Identifier, all authenticated chunks MUST be silently discarded.
3781 * Verification Tag: 8.5 Verification Tag [Normal verification]
3783 * The return value is the disposition of the chunk.
3785 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
3786 const struct sctp_association
*asoc
,
3787 const sctp_subtype_t type
,
3788 struct sctp_chunk
*chunk
)
3790 struct sctp_authhdr
*auth_hdr
;
3791 struct sctp_hmac
*hmac
;
3792 unsigned int sig_len
;
3797 /* Pull in the auth header, so we can do some more verification */
3798 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3799 chunk
->subh
.auth_hdr
= auth_hdr
;
3800 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
3802 /* Make sure that we suport the HMAC algorithm from the auth
3805 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
3806 return SCTP_IERROR_AUTH_BAD_HMAC
;
3808 /* Make sure that the provided shared key identifier has been
3811 key_id
= ntohs(auth_hdr
->shkey_id
);
3812 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
3813 return SCTP_IERROR_AUTH_BAD_KEYID
;
3816 /* Make sure that the length of the signature matches what
3819 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
3820 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
3821 if (sig_len
!= hmac
->hmac_len
)
3822 return SCTP_IERROR_PROTO_VIOLATION
;
3824 /* Now that we've done validation checks, we can compute and
3825 * verify the hmac. The steps involved are:
3826 * 1. Save the digest from the chunk.
3827 * 2. Zero out the digest in the chunk.
3828 * 3. Compute the new digest
3829 * 4. Compare saved and new digests.
3831 digest
= auth_hdr
->hmac
;
3832 skb_pull(chunk
->skb
, sig_len
);
3834 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
3838 memset(digest
, 0, sig_len
);
3840 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
3841 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
3844 /* Discard the packet if the digests do not match */
3845 if (memcmp(save_digest
, digest
, sig_len
)) {
3847 return SCTP_IERROR_BAD_SIG
;
3853 return SCTP_IERROR_NO_ERROR
;
3855 return SCTP_IERROR_NOMEM
;
3858 sctp_disposition_t
sctp_sf_eat_auth(const struct sctp_endpoint
*ep
,
3859 const struct sctp_association
*asoc
,
3860 const sctp_subtype_t type
,
3862 sctp_cmd_seq_t
*commands
)
3864 struct sctp_authhdr
*auth_hdr
;
3865 struct sctp_chunk
*chunk
= arg
;
3866 struct sctp_chunk
*err_chunk
;
3867 sctp_ierror_t error
;
3869 if (!sctp_vtag_verify(chunk
, asoc
)) {
3870 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3872 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3875 /* Make sure that the AUTH chunk has valid length. */
3876 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
3877 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3880 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3881 error
= sctp_sf_authenticate(ep
, asoc
, type
, chunk
);
3883 case SCTP_IERROR_AUTH_BAD_HMAC
:
3884 /* Generate the ERROR chunk and discard the rest
3887 err_chunk
= sctp_make_op_error(asoc
, chunk
,
3888 SCTP_ERROR_UNSUP_HMAC
,
3892 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3893 SCTP_CHUNK(err_chunk
));
3896 case SCTP_IERROR_AUTH_BAD_KEYID
:
3897 case SCTP_IERROR_BAD_SIG
:
3898 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3900 case SCTP_IERROR_PROTO_VIOLATION
:
3901 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3904 case SCTP_IERROR_NOMEM
:
3905 return SCTP_DISPOSITION_NOMEM
;
3910 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
3911 struct sctp_ulpevent
*ev
;
3913 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
3914 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
3919 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
3923 return SCTP_DISPOSITION_CONSUME
;
3927 * Process an unknown chunk.
3929 * Section: 3.2. Also, 2.1 in the implementor's guide.
3931 * Chunk Types are encoded such that the highest-order two bits specify
3932 * the action that must be taken if the processing endpoint does not
3933 * recognize the Chunk Type.
3935 * 00 - Stop processing this SCTP packet and discard it, do not process
3936 * any further chunks within it.
3938 * 01 - Stop processing this SCTP packet and discard it, do not process
3939 * any further chunks within it, and report the unrecognized
3940 * chunk in an 'Unrecognized Chunk Type'.
3942 * 10 - Skip this chunk and continue processing.
3944 * 11 - Skip this chunk and continue processing, but report in an ERROR
3945 * Chunk using the 'Unrecognized Chunk Type' cause of error.
3947 * The return value is the disposition of the chunk.
3949 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
3950 const struct sctp_association
*asoc
,
3951 const sctp_subtype_t type
,
3953 sctp_cmd_seq_t
*commands
)
3955 struct sctp_chunk
*unk_chunk
= arg
;
3956 struct sctp_chunk
*err_chunk
;
3957 sctp_chunkhdr_t
*hdr
;
3959 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
3961 if (!sctp_vtag_verify(unk_chunk
, asoc
))
3962 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3964 /* Make sure that the chunk has a valid length.
3965 * Since we don't know the chunk type, we use a general
3966 * chunkhdr structure to make a comparison.
3968 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
3969 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3972 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
3973 case SCTP_CID_ACTION_DISCARD
:
3974 /* Discard the packet. */
3975 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3977 case SCTP_CID_ACTION_DISCARD_ERR
:
3978 /* Discard the packet. */
3979 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3981 /* Generate an ERROR chunk as response. */
3982 hdr
= unk_chunk
->chunk_hdr
;
3983 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
3984 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
3985 WORD_ROUND(ntohs(hdr
->length
)));
3987 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3988 SCTP_CHUNK(err_chunk
));
3990 return SCTP_DISPOSITION_CONSUME
;
3992 case SCTP_CID_ACTION_SKIP
:
3993 /* Skip the chunk. */
3994 return SCTP_DISPOSITION_DISCARD
;
3996 case SCTP_CID_ACTION_SKIP_ERR
:
3997 /* Generate an ERROR chunk as response. */
3998 hdr
= unk_chunk
->chunk_hdr
;
3999 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4000 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4001 WORD_ROUND(ntohs(hdr
->length
)));
4003 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4004 SCTP_CHUNK(err_chunk
));
4006 /* Skip the chunk. */
4007 return SCTP_DISPOSITION_CONSUME
;
4013 return SCTP_DISPOSITION_DISCARD
;
4017 * Discard the chunk.
4019 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4020 * [Too numerous to mention...]
4021 * Verification Tag: No verification needed.
4023 * (endpoint, asoc, chunk)
4026 * (asoc, reply_msg, msg_up, timers, counters)
4028 * The return value is the disposition of the chunk.
4030 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
4031 const struct sctp_association
*asoc
,
4032 const sctp_subtype_t type
,
4034 sctp_cmd_seq_t
*commands
)
4036 struct sctp_chunk
*chunk
= arg
;
4038 /* Make sure that the chunk has a valid length.
4039 * Since we don't know the chunk type, we use a general
4040 * chunkhdr structure to make a comparison.
4042 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4043 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4046 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
4047 return SCTP_DISPOSITION_DISCARD
;
4051 * Discard the whole packet.
4055 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4056 * silently discard the OOTB packet and take no further action.
4058 * Verification Tag: No verification necessary
4061 * (endpoint, asoc, chunk)
4064 * (asoc, reply_msg, msg_up, timers, counters)
4066 * The return value is the disposition of the chunk.
4068 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
4069 const struct sctp_association
*asoc
,
4070 const sctp_subtype_t type
,
4072 sctp_cmd_seq_t
*commands
)
4074 SCTP_INC_STATS(SCTP_MIB_IN_PKT_DISCARDS
);
4075 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4077 return SCTP_DISPOSITION_CONSUME
;
4082 * The other end is violating protocol.
4084 * Section: Not specified
4085 * Verification Tag: Not specified
4087 * (endpoint, asoc, chunk)
4090 * (asoc, reply_msg, msg_up, timers, counters)
4092 * We simply tag the chunk as a violation. The state machine will log
4093 * the violation and continue.
4095 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
4096 const struct sctp_association
*asoc
,
4097 const sctp_subtype_t type
,
4099 sctp_cmd_seq_t
*commands
)
4101 struct sctp_chunk
*chunk
= arg
;
4103 /* Make sure that the chunk has a valid length. */
4104 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4105 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4108 return SCTP_DISPOSITION_VIOLATION
;
4112 * Common function to handle a protocol violation.
4114 static sctp_disposition_t
sctp_sf_abort_violation(
4115 const struct sctp_endpoint
*ep
,
4116 const struct sctp_association
*asoc
,
4118 sctp_cmd_seq_t
*commands
,
4119 const __u8
*payload
,
4120 const size_t paylen
)
4122 struct sctp_packet
*packet
= NULL
;
4123 struct sctp_chunk
*chunk
= arg
;
4124 struct sctp_chunk
*abort
= NULL
;
4126 /* SCTP-AUTH, Section 6.3:
4127 * It should be noted that if the receiver wants to tear
4128 * down an association in an authenticated way only, the
4129 * handling of malformed packets should not result in
4130 * tearing down the association.
4132 * This means that if we only want to abort associations
4133 * in an authenticated way (i.e AUTH+ABORT), then we
4134 * can't destory this association just becuase the packet
4137 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4140 /* Make the abort chunk. */
4141 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4146 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4147 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4149 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4150 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4151 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4152 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4153 SCTP_ERROR(ECONNREFUSED
));
4154 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4155 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4157 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4158 SCTP_ERROR(ECONNABORTED
));
4159 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4160 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4161 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4164 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
4169 if (sctp_test_T_bit(abort
))
4170 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4172 abort
->skb
->sk
= ep
->base
.sk
;
4174 sctp_packet_append_chunk(packet
, abort
);
4176 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4177 SCTP_PACKET(packet
));
4179 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
4183 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4185 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4187 return SCTP_DISPOSITION_ABORT
;
4190 sctp_chunk_free(abort
);
4192 return SCTP_DISPOSITION_NOMEM
;
4196 * Handle a protocol violation when the chunk length is invalid.
4197 * "Invalid" length is identified as smaller then the minimal length a
4198 * given chunk can be. For example, a SACK chunk has invalid length
4199 * if it's length is set to be smaller then the size of sctp_sack_chunk_t.
4201 * We inform the other end by sending an ABORT with a Protocol Violation
4204 * Section: Not specified
4205 * Verification Tag: Nothing to do
4207 * (endpoint, asoc, chunk)
4210 * (reply_msg, msg_up, counters)
4212 * Generate an ABORT chunk and terminate the association.
4214 static sctp_disposition_t
sctp_sf_violation_chunklen(
4215 const struct sctp_endpoint
*ep
,
4216 const struct sctp_association
*asoc
,
4217 const sctp_subtype_t type
,
4219 sctp_cmd_seq_t
*commands
)
4221 char err_str
[]="The following chunk had invalid length:";
4223 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4228 * Handle a protocol violation when the parameter length is invalid.
4229 * "Invalid" length is identified as smaller then the minimal length a
4230 * given parameter can be.
4232 static sctp_disposition_t
sctp_sf_violation_paramlen(
4233 const struct sctp_endpoint
*ep
,
4234 const struct sctp_association
*asoc
,
4235 const sctp_subtype_t type
,
4237 sctp_cmd_seq_t
*commands
) {
4238 char err_str
[] = "The following parameter had invalid length:";
4240 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4244 /* Handle a protocol violation when the peer trying to advance the
4245 * cumulative tsn ack to a point beyond the max tsn currently sent.
4247 * We inform the other end by sending an ABORT with a Protocol Violation
4250 static sctp_disposition_t
sctp_sf_violation_ctsn(
4251 const struct sctp_endpoint
*ep
,
4252 const struct sctp_association
*asoc
,
4253 const sctp_subtype_t type
,
4255 sctp_cmd_seq_t
*commands
)
4257 char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4259 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4263 /* Handle protocol violation of an invalid chunk bundling. For example,
4264 * when we have an association and we recieve bundled INIT-ACK, or
4265 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4266 * statement from the specs. Additinally, there might be an attacker
4267 * on the path and we may not want to continue this communication.
4269 static sctp_disposition_t
sctp_sf_violation_chunk(
4270 const struct sctp_endpoint
*ep
,
4271 const struct sctp_association
*asoc
,
4272 const sctp_subtype_t type
,
4274 sctp_cmd_seq_t
*commands
)
4276 char err_str
[]="The following chunk violates protocol:";
4279 return sctp_sf_violation(ep
, asoc
, type
, arg
, commands
);
4281 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4284 /***************************************************************************
4285 * These are the state functions for handling primitive (Section 10) events.
4286 ***************************************************************************/
4288 * sctp_sf_do_prm_asoc
4290 * Section: 10.1 ULP-to-SCTP
4293 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4294 * outbound stream count)
4295 * -> association id [,destination transport addr list] [,outbound stream
4298 * This primitive allows the upper layer to initiate an association to a
4299 * specific peer endpoint.
4301 * The peer endpoint shall be specified by one of the transport addresses
4302 * which defines the endpoint (see Section 1.4). If the local SCTP
4303 * instance has not been initialized, the ASSOCIATE is considered an
4305 * [This is not relevant for the kernel implementation since we do all
4306 * initialization at boot time. It we hadn't initialized we wouldn't
4307 * get anywhere near this code.]
4309 * An association id, which is a local handle to the SCTP association,
4310 * will be returned on successful establishment of the association. If
4311 * SCTP is not able to open an SCTP association with the peer endpoint,
4312 * an error is returned.
4313 * [In the kernel implementation, the struct sctp_association needs to
4314 * be created BEFORE causing this primitive to run.]
4316 * Other association parameters may be returned, including the
4317 * complete destination transport addresses of the peer as well as the
4318 * outbound stream count of the local endpoint. One of the transport
4319 * address from the returned destination addresses will be selected by
4320 * the local endpoint as default primary path for sending SCTP packets
4321 * to this peer. The returned "destination transport addr list" can
4322 * be used by the ULP to change the default primary path or to force
4323 * sending a packet to a specific transport address. [All of this
4324 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4327 * Mandatory attributes:
4329 * o local SCTP instance name - obtained from the INITIALIZE operation.
4330 * [This is the argument asoc.]
4331 * o destination transport addr - specified as one of the transport
4332 * addresses of the peer endpoint with which the association is to be
4334 * [This is asoc->peer.active_path.]
4335 * o outbound stream count - the number of outbound streams the ULP
4336 * would like to open towards this peer endpoint.
4337 * [BUG: This is not currently implemented.]
4338 * Optional attributes:
4342 * The return value is a disposition.
4344 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
4345 const struct sctp_association
*asoc
,
4346 const sctp_subtype_t type
,
4348 sctp_cmd_seq_t
*commands
)
4350 struct sctp_chunk
*repl
;
4352 /* The comment below says that we enter COOKIE-WAIT AFTER
4353 * sending the INIT, but that doesn't actually work in our
4356 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4357 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4359 /* RFC 2960 5.1 Normal Establishment of an Association
4361 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4362 * must provide its Verification Tag (Tag_A) in the Initiate
4363 * Tag field. Tag_A SHOULD be a random number in the range of
4364 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4367 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4371 /* Cast away the const modifier, as we want to just
4372 * rerun it through as a sideffect.
4374 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
,
4375 SCTP_ASOC((struct sctp_association
*) asoc
));
4377 /* Choose transport for INIT. */
4378 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4381 /* After sending the INIT, "A" starts the T1-init timer and
4382 * enters the COOKIE-WAIT state.
4384 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4385 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4386 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4387 return SCTP_DISPOSITION_CONSUME
;
4390 return SCTP_DISPOSITION_NOMEM
;
4394 * Process the SEND primitive.
4396 * Section: 10.1 ULP-to-SCTP
4399 * Format: SEND(association id, buffer address, byte count [,context]
4400 * [,stream id] [,life time] [,destination transport address]
4401 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4404 * This is the main method to send user data via SCTP.
4406 * Mandatory attributes:
4408 * o association id - local handle to the SCTP association
4410 * o buffer address - the location where the user message to be
4411 * transmitted is stored;
4413 * o byte count - The size of the user data in number of bytes;
4415 * Optional attributes:
4417 * o context - an optional 32 bit integer that will be carried in the
4418 * sending failure notification to the ULP if the transportation of
4419 * this User Message fails.
4421 * o stream id - to indicate which stream to send the data on. If not
4422 * specified, stream 0 will be used.
4424 * o life time - specifies the life time of the user data. The user data
4425 * will not be sent by SCTP after the life time expires. This
4426 * parameter can be used to avoid efforts to transmit stale
4427 * user messages. SCTP notifies the ULP if the data cannot be
4428 * initiated to transport (i.e. sent to the destination via SCTP's
4429 * send primitive) within the life time variable. However, the
4430 * user data will be transmitted if SCTP has attempted to transmit a
4431 * chunk before the life time expired.
4433 * o destination transport address - specified as one of the destination
4434 * transport addresses of the peer endpoint to which this packet
4435 * should be sent. Whenever possible, SCTP should use this destination
4436 * transport address for sending the packets, instead of the current
4439 * o unorder flag - this flag, if present, indicates that the user
4440 * would like the data delivered in an unordered fashion to the peer
4441 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4444 * o no-bundle flag - instructs SCTP not to bundle this user data with
4445 * other outbound DATA chunks. SCTP MAY still bundle even when
4446 * this flag is present, when faced with network congestion.
4448 * o payload protocol-id - A 32 bit unsigned integer that is to be
4449 * passed to the peer indicating the type of payload protocol data
4450 * being transmitted. This value is passed as opaque data by SCTP.
4452 * The return value is the disposition.
4454 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
4455 const struct sctp_association
*asoc
,
4456 const sctp_subtype_t type
,
4458 sctp_cmd_seq_t
*commands
)
4460 struct sctp_chunk
*chunk
= arg
;
4462 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4463 return SCTP_DISPOSITION_CONSUME
;
4467 * Process the SHUTDOWN primitive.
4472 * Format: SHUTDOWN(association id)
4475 * Gracefully closes an association. Any locally queued user data
4476 * will be delivered to the peer. The association will be terminated only
4477 * after the peer acknowledges all the SCTP packets sent. A success code
4478 * will be returned on successful termination of the association. If
4479 * attempting to terminate the association results in a failure, an error
4480 * code shall be returned.
4482 * Mandatory attributes:
4484 * o association id - local handle to the SCTP association
4486 * Optional attributes:
4490 * The return value is the disposition.
4492 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4493 const struct sctp_endpoint
*ep
,
4494 const struct sctp_association
*asoc
,
4495 const sctp_subtype_t type
,
4497 sctp_cmd_seq_t
*commands
)
4501 /* From 9.2 Shutdown of an Association
4502 * Upon receipt of the SHUTDOWN primitive from its upper
4503 * layer, the endpoint enters SHUTDOWN-PENDING state and
4504 * remains there until all outstanding data has been
4505 * acknowledged by its peer. The endpoint accepts no new data
4506 * from its upper layer, but retransmits data to the far end
4507 * if necessary to fill gaps.
4509 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4510 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4512 /* sctpimpguide-05 Section 2.12.2
4513 * The sender of the SHUTDOWN MAY also start an overall guard timer
4514 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
4516 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4517 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4519 disposition
= SCTP_DISPOSITION_CONSUME
;
4520 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4521 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4528 * Process the ABORT primitive.
4533 * Format: Abort(association id [, cause code])
4536 * Ungracefully closes an association. Any locally queued user data
4537 * will be discarded and an ABORT chunk is sent to the peer. A success code
4538 * will be returned on successful abortion of the association. If
4539 * attempting to abort the association results in a failure, an error
4540 * code shall be returned.
4542 * Mandatory attributes:
4544 * o association id - local handle to the SCTP association
4546 * Optional attributes:
4548 * o cause code - reason of the abort to be passed to the peer
4552 * The return value is the disposition.
4554 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4555 const struct sctp_endpoint
*ep
,
4556 const struct sctp_association
*asoc
,
4557 const sctp_subtype_t type
,
4559 sctp_cmd_seq_t
*commands
)
4561 /* From 9.1 Abort of an Association
4562 * Upon receipt of the ABORT primitive from its upper
4563 * layer, the endpoint enters CLOSED state and
4564 * discard all outstanding data has been
4565 * acknowledged by its peer. The endpoint accepts no new data
4566 * from its upper layer, but retransmits data to the far end
4567 * if necessary to fill gaps.
4569 struct sctp_chunk
*abort
= arg
;
4570 sctp_disposition_t retval
;
4572 retval
= SCTP_DISPOSITION_CONSUME
;
4574 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4576 /* Even if we can't send the ABORT due to low memory delete the
4577 * TCB. This is a departure from our typical NOMEM handling.
4580 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4581 SCTP_ERROR(ECONNABORTED
));
4582 /* Delete the established association. */
4583 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4584 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4586 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4587 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
4592 /* We tried an illegal operation on an association which is closed. */
4593 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4594 const struct sctp_association
*asoc
,
4595 const sctp_subtype_t type
,
4597 sctp_cmd_seq_t
*commands
)
4599 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4600 return SCTP_DISPOSITION_CONSUME
;
4603 /* We tried an illegal operation on an association which is shutting
4606 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4607 const struct sctp_association
*asoc
,
4608 const sctp_subtype_t type
,
4610 sctp_cmd_seq_t
*commands
)
4612 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4613 SCTP_ERROR(-ESHUTDOWN
));
4614 return SCTP_DISPOSITION_CONSUME
;
4618 * sctp_cookie_wait_prm_shutdown
4620 * Section: 4 Note: 2
4625 * The RFC does not explicitly address this issue, but is the route through the
4626 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4631 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4632 const struct sctp_endpoint
*ep
,
4633 const struct sctp_association
*asoc
,
4634 const sctp_subtype_t type
,
4636 sctp_cmd_seq_t
*commands
)
4638 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4639 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4641 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4642 SCTP_STATE(SCTP_STATE_CLOSED
));
4644 SCTP_INC_STATS(SCTP_MIB_SHUTDOWNS
);
4646 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4648 return SCTP_DISPOSITION_DELETE_TCB
;
4652 * sctp_cookie_echoed_prm_shutdown
4654 * Section: 4 Note: 2
4659 * The RFC does not explcitly address this issue, but is the route through the
4660 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4665 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4666 const struct sctp_endpoint
*ep
,
4667 const struct sctp_association
*asoc
,
4668 const sctp_subtype_t type
,
4669 void *arg
, sctp_cmd_seq_t
*commands
)
4671 /* There is a single T1 timer, so we should be able to use
4672 * common function with the COOKIE-WAIT state.
4674 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4678 * sctp_sf_cookie_wait_prm_abort
4680 * Section: 4 Note: 2
4685 * The RFC does not explicitly address this issue, but is the route through the
4686 * state table when someone issues an abort while in COOKIE_WAIT state.
4691 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4692 const struct sctp_endpoint
*ep
,
4693 const struct sctp_association
*asoc
,
4694 const sctp_subtype_t type
,
4696 sctp_cmd_seq_t
*commands
)
4698 struct sctp_chunk
*abort
= arg
;
4699 sctp_disposition_t retval
;
4701 /* Stop T1-init timer */
4702 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4703 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4704 retval
= SCTP_DISPOSITION_CONSUME
;
4706 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4708 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4709 SCTP_STATE(SCTP_STATE_CLOSED
));
4711 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
4713 /* Even if we can't send the ABORT due to low memory delete the
4714 * TCB. This is a departure from our typical NOMEM handling.
4717 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4718 SCTP_ERROR(ECONNREFUSED
));
4719 /* Delete the established association. */
4720 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4721 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4727 * sctp_sf_cookie_echoed_prm_abort
4729 * Section: 4 Note: 3
4734 * The RFC does not explcitly address this issue, but is the route through the
4735 * state table when someone issues an abort while in COOKIE_ECHOED state.
4740 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4741 const struct sctp_endpoint
*ep
,
4742 const struct sctp_association
*asoc
,
4743 const sctp_subtype_t type
,
4745 sctp_cmd_seq_t
*commands
)
4747 /* There is a single T1 timer, so we should be able to use
4748 * common function with the COOKIE-WAIT state.
4750 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4754 * sctp_sf_shutdown_pending_prm_abort
4759 * The RFC does not explicitly address this issue, but is the route through the
4760 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4765 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4766 const struct sctp_endpoint
*ep
,
4767 const struct sctp_association
*asoc
,
4768 const sctp_subtype_t type
,
4770 sctp_cmd_seq_t
*commands
)
4772 /* Stop the T5-shutdown guard timer. */
4773 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4774 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4776 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4780 * sctp_sf_shutdown_sent_prm_abort
4785 * The RFC does not explicitly address this issue, but is the route through the
4786 * state table when someone issues an abort while in SHUTDOWN-SENT state.
4791 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
4792 const struct sctp_endpoint
*ep
,
4793 const struct sctp_association
*asoc
,
4794 const sctp_subtype_t type
,
4796 sctp_cmd_seq_t
*commands
)
4798 /* Stop the T2-shutdown timer. */
4799 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4800 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4802 /* Stop the T5-shutdown guard timer. */
4803 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4804 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4806 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4810 * sctp_sf_cookie_echoed_prm_abort
4815 * The RFC does not explcitly address this issue, but is the route through the
4816 * state table when someone issues an abort while in COOKIE_ECHOED state.
4821 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
4822 const struct sctp_endpoint
*ep
,
4823 const struct sctp_association
*asoc
,
4824 const sctp_subtype_t type
,
4826 sctp_cmd_seq_t
*commands
)
4828 /* The same T2 timer, so we should be able to use
4829 * common function with the SHUTDOWN-SENT state.
4831 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
4835 * Process the REQUESTHEARTBEAT primitive
4838 * J) Request Heartbeat
4840 * Format: REQUESTHEARTBEAT(association id, destination transport address)
4844 * Instructs the local endpoint to perform a HeartBeat on the specified
4845 * destination transport address of the given association. The returned
4846 * result should indicate whether the transmission of the HEARTBEAT
4847 * chunk to the destination address is successful.
4849 * Mandatory attributes:
4851 * o association id - local handle to the SCTP association
4853 * o destination transport address - the transport address of the
4854 * association on which a heartbeat should be issued.
4856 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
4857 const struct sctp_endpoint
*ep
,
4858 const struct sctp_association
*asoc
,
4859 const sctp_subtype_t type
,
4861 sctp_cmd_seq_t
*commands
)
4863 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
4864 (struct sctp_transport
*)arg
, commands
))
4865 return SCTP_DISPOSITION_NOMEM
;
4868 * RFC 2960 (bis), section 8.3
4870 * D) Request an on-demand HEARTBEAT on a specific destination
4871 * transport address of a given association.
4873 * The endpoint should increment the respective error counter of
4874 * the destination transport address each time a HEARTBEAT is sent
4875 * to that address and not acknowledged within one RTO.
4878 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_RESET
,
4879 SCTP_TRANSPORT(arg
));
4880 return SCTP_DISPOSITION_CONSUME
;
4884 * ADDIP Section 4.1 ASCONF Chunk Procedures
4885 * When an endpoint has an ASCONF signaled change to be sent to the
4886 * remote endpoint it should do A1 to A9
4888 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
4889 const struct sctp_association
*asoc
,
4890 const sctp_subtype_t type
,
4892 sctp_cmd_seq_t
*commands
)
4894 struct sctp_chunk
*chunk
= arg
;
4896 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
4897 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4898 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
4899 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
4900 return SCTP_DISPOSITION_CONSUME
;
4904 * Ignore the primitive event
4906 * The return value is the disposition of the primitive.
4908 sctp_disposition_t
sctp_sf_ignore_primitive(
4909 const struct sctp_endpoint
*ep
,
4910 const struct sctp_association
*asoc
,
4911 const sctp_subtype_t type
,
4913 sctp_cmd_seq_t
*commands
)
4915 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
4916 return SCTP_DISPOSITION_DISCARD
;
4919 /***************************************************************************
4920 * These are the state functions for the OTHER events.
4921 ***************************************************************************/
4924 * Start the shutdown negotiation.
4927 * Once all its outstanding data has been acknowledged, the endpoint
4928 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
4929 * TSN Ack field the last sequential TSN it has received from the peer.
4930 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
4931 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
4932 * with the updated last sequential TSN received from its peer.
4934 * The return value is the disposition.
4936 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
4937 const struct sctp_endpoint
*ep
,
4938 const struct sctp_association
*asoc
,
4939 const sctp_subtype_t type
,
4941 sctp_cmd_seq_t
*commands
)
4943 struct sctp_chunk
*reply
;
4945 /* Once all its outstanding data has been acknowledged, the
4946 * endpoint shall send a SHUTDOWN chunk to its peer including
4947 * in the Cumulative TSN Ack field the last sequential TSN it
4948 * has received from the peer.
4950 reply
= sctp_make_shutdown(asoc
, NULL
);
4954 /* Set the transport for the SHUTDOWN chunk and the timeout for the
4955 * T2-shutdown timer.
4957 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
4959 /* It shall then start the T2-shutdown timer */
4960 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4961 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
4963 if (asoc
->autoclose
)
4964 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4965 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
4967 /* and enter the SHUTDOWN-SENT state. */
4968 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4969 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
4971 /* sctp-implguide 2.10 Issues with Heartbeating and failover
4973 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
4976 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
4978 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
4980 return SCTP_DISPOSITION_CONSUME
;
4983 return SCTP_DISPOSITION_NOMEM
;
4987 * Generate a SHUTDOWN ACK now that everything is SACK'd.
4991 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
4992 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
4993 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
4994 * endpoint must re-send the SHUTDOWN ACK.
4996 * The return value is the disposition.
4998 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
4999 const struct sctp_endpoint
*ep
,
5000 const struct sctp_association
*asoc
,
5001 const sctp_subtype_t type
,
5003 sctp_cmd_seq_t
*commands
)
5005 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5006 struct sctp_chunk
*reply
;
5008 /* There are 2 ways of getting here:
5009 * 1) called in response to a SHUTDOWN chunk
5010 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5012 * For the case (2), the arg parameter is set to NULL. We need
5013 * to check that we have a chunk before accessing it's fields.
5016 if (!sctp_vtag_verify(chunk
, asoc
))
5017 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
5019 /* Make sure that the SHUTDOWN chunk has a valid length. */
5020 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5021 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
5025 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5026 * shall send a SHUTDOWN ACK ...
5028 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5032 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5033 * the T2-shutdown timer.
5035 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5037 /* and start/restart a T2-shutdown timer of its own, */
5038 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5039 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5041 if (asoc
->autoclose
)
5042 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5043 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5045 /* Enter the SHUTDOWN-ACK-SENT state. */
5046 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5047 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5049 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5051 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5054 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5056 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5058 return SCTP_DISPOSITION_CONSUME
;
5061 return SCTP_DISPOSITION_NOMEM
;
5065 * Ignore the event defined as other
5067 * The return value is the disposition of the event.
5069 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
5070 const struct sctp_association
*asoc
,
5071 const sctp_subtype_t type
,
5073 sctp_cmd_seq_t
*commands
)
5075 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
5076 return SCTP_DISPOSITION_DISCARD
;
5079 /************************************************************
5080 * These are the state functions for handling timeout events.
5081 ************************************************************/
5086 * Section: 6.3.3 Handle T3-rtx Expiration
5088 * Whenever the retransmission timer T3-rtx expires for a destination
5089 * address, do the following:
5092 * The return value is the disposition of the chunk.
5094 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
5095 const struct sctp_association
*asoc
,
5096 const sctp_subtype_t type
,
5098 sctp_cmd_seq_t
*commands
)
5100 struct sctp_transport
*transport
= arg
;
5102 SCTP_INC_STATS(SCTP_MIB_T3_RTX_EXPIREDS
);
5104 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5105 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5106 SCTP_ERROR(ETIMEDOUT
));
5107 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5108 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5109 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5110 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5111 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5112 return SCTP_DISPOSITION_DELETE_TCB
;
5115 /* E1) For the destination address for which the timer
5116 * expires, adjust its ssthresh with rules defined in Section
5117 * 7.2.3 and set the cwnd <- MTU.
5120 /* E2) For the destination address for which the timer
5121 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5122 * maximum value discussed in rule C7 above (RTO.max) may be
5123 * used to provide an upper bound to this doubling operation.
5126 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5127 * outstanding DATA chunks for the address for which the
5128 * T3-rtx has expired will fit into a single packet, subject
5129 * to the MTU constraint for the path corresponding to the
5130 * destination transport address to which the retransmission
5131 * is being sent (this may be different from the address for
5132 * which the timer expires [see Section 6.4]). Call this
5133 * value K. Bundle and retransmit those K DATA chunks in a
5134 * single packet to the destination endpoint.
5136 * Note: Any DATA chunks that were sent to the address for
5137 * which the T3-rtx timer expired but did not fit in one MTU
5138 * (rule E3 above), should be marked for retransmission and
5139 * sent as soon as cwnd allows (normally when a SACK arrives).
5142 /* Do some failure management (Section 8.2). */
5143 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5145 /* NB: Rules E4 and F1 are implicit in R1. */
5146 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5148 return SCTP_DISPOSITION_CONSUME
;
5152 * Generate delayed SACK on timeout
5154 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5156 * The guidelines on delayed acknowledgement algorithm specified in
5157 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5158 * acknowledgement SHOULD be generated for at least every second packet
5159 * (not every second DATA chunk) received, and SHOULD be generated
5160 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5161 * some situations it may be beneficial for an SCTP transmitter to be
5162 * more conservative than the algorithms detailed in this document
5163 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5164 * the following algorithms allow.
5166 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
5167 const struct sctp_association
*asoc
,
5168 const sctp_subtype_t type
,
5170 sctp_cmd_seq_t
*commands
)
5172 SCTP_INC_STATS(SCTP_MIB_DELAY_SACK_EXPIREDS
);
5173 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5174 return SCTP_DISPOSITION_CONSUME
;
5178 * sctp_sf_t1_init_timer_expire
5180 * Section: 4 Note: 2
5185 * RFC 2960 Section 4 Notes
5186 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5187 * and re-start the T1-init timer without changing state. This MUST
5188 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5189 * endpoint MUST abort the initialization process and report the
5190 * error to SCTP user.
5196 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
5197 const struct sctp_association
*asoc
,
5198 const sctp_subtype_t type
,
5200 sctp_cmd_seq_t
*commands
)
5202 struct sctp_chunk
*repl
= NULL
;
5203 struct sctp_bind_addr
*bp
;
5204 int attempts
= asoc
->init_err_counter
+ 1;
5206 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5207 SCTP_INC_STATS(SCTP_MIB_T1_INIT_EXPIREDS
);
5209 if (attempts
<= asoc
->max_init_attempts
) {
5210 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5211 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5213 return SCTP_DISPOSITION_NOMEM
;
5215 /* Choose transport for INIT. */
5216 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5219 /* Issue a sideeffect to do the needed accounting. */
5220 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5221 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5223 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5225 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5226 " max_init_attempts: %d\n",
5227 attempts
, asoc
->max_init_attempts
);
5228 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5229 SCTP_ERROR(ETIMEDOUT
));
5230 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5231 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5232 return SCTP_DISPOSITION_DELETE_TCB
;
5235 return SCTP_DISPOSITION_CONSUME
;
5239 * sctp_sf_t1_cookie_timer_expire
5241 * Section: 4 Note: 2
5246 * RFC 2960 Section 4 Notes
5247 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5248 * COOKIE ECHO and re-start the T1-cookie timer without changing
5249 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5250 * After that, the endpoint MUST abort the initialization process and
5251 * report the error to SCTP user.
5257 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
5258 const struct sctp_association
*asoc
,
5259 const sctp_subtype_t type
,
5261 sctp_cmd_seq_t
*commands
)
5263 struct sctp_chunk
*repl
= NULL
;
5264 int attempts
= asoc
->init_err_counter
+ 1;
5266 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5267 SCTP_INC_STATS(SCTP_MIB_T1_COOKIE_EXPIREDS
);
5269 if (attempts
<= asoc
->max_init_attempts
) {
5270 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5272 return SCTP_DISPOSITION_NOMEM
;
5274 /* Issue a sideeffect to do the needed accounting. */
5275 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5276 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5278 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5280 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5281 SCTP_ERROR(ETIMEDOUT
));
5282 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5283 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5284 return SCTP_DISPOSITION_DELETE_TCB
;
5287 return SCTP_DISPOSITION_CONSUME
;
5290 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5291 * with the updated last sequential TSN received from its peer.
5293 * An endpoint should limit the number of retransmissions of the
5294 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5295 * If this threshold is exceeded the endpoint should destroy the TCB and
5296 * MUST report the peer endpoint unreachable to the upper layer (and
5297 * thus the association enters the CLOSED state). The reception of any
5298 * packet from its peer (i.e. as the peer sends all of its queued DATA
5299 * chunks) should clear the endpoint's retransmission count and restart
5300 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5301 * all of its queued DATA chunks that have not yet been sent.
5303 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
5304 const struct sctp_association
*asoc
,
5305 const sctp_subtype_t type
,
5307 sctp_cmd_seq_t
*commands
)
5309 struct sctp_chunk
*reply
= NULL
;
5311 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5312 SCTP_INC_STATS(SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5314 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5315 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5316 SCTP_ERROR(ETIMEDOUT
));
5317 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5318 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5319 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5320 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5321 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5322 return SCTP_DISPOSITION_DELETE_TCB
;
5325 switch (asoc
->state
) {
5326 case SCTP_STATE_SHUTDOWN_SENT
:
5327 reply
= sctp_make_shutdown(asoc
, NULL
);
5330 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5331 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5342 /* Do some failure management (Section 8.2). */
5343 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5344 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5346 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5347 * the T2-shutdown timer.
5349 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5351 /* Restart the T2-shutdown timer. */
5352 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5353 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5354 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5355 return SCTP_DISPOSITION_CONSUME
;
5358 return SCTP_DISPOSITION_NOMEM
;
5362 * ADDIP Section 4.1 ASCONF CHunk Procedures
5363 * If the T4 RTO timer expires the endpoint should do B1 to B5
5365 sctp_disposition_t
sctp_sf_t4_timer_expire(
5366 const struct sctp_endpoint
*ep
,
5367 const struct sctp_association
*asoc
,
5368 const sctp_subtype_t type
,
5370 sctp_cmd_seq_t
*commands
)
5372 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5373 struct sctp_transport
*transport
= chunk
->transport
;
5375 SCTP_INC_STATS(SCTP_MIB_T4_RTO_EXPIREDS
);
5377 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5378 * detection on the appropriate destination address as defined in
5379 * RFC2960 [5] section 8.1 and 8.2.
5381 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5383 /* Reconfig T4 timer and transport. */
5384 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5386 /* ADDIP 4.1 B2) Increment the association error counters and perform
5387 * endpoint failure detection on the association as defined in
5388 * RFC2960 [5] section 8.1 and 8.2.
5389 * association error counter is incremented in SCTP_CMD_STRIKE.
5391 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5392 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5393 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5394 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5395 SCTP_ERROR(ETIMEDOUT
));
5396 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5397 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5398 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5399 SCTP_INC_STATS(SCTP_MIB_CURRESTAB
);
5400 return SCTP_DISPOSITION_ABORT
;
5403 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5404 * the ASCONF chunk was sent by doubling the RTO timer value.
5405 * This is done in SCTP_CMD_STRIKE.
5408 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5409 * choose an alternate destination address (please refer to RFC2960
5410 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5411 * chunk, it MUST be the same (including its serial number) as the last
5414 sctp_chunk_hold(asoc
->addip_last_asconf
);
5415 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5416 SCTP_CHUNK(asoc
->addip_last_asconf
));
5418 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5419 * destination is selected, then the RTO used will be that of the new
5420 * destination address.
5422 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5423 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5425 return SCTP_DISPOSITION_CONSUME
;
5428 /* sctpimpguide-05 Section 2.12.2
5429 * The sender of the SHUTDOWN MAY also start an overall guard timer
5430 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5431 * At the expiration of this timer the sender SHOULD abort the association
5432 * by sending an ABORT chunk.
5434 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
5435 const struct sctp_association
*asoc
,
5436 const sctp_subtype_t type
,
5438 sctp_cmd_seq_t
*commands
)
5440 struct sctp_chunk
*reply
= NULL
;
5442 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5443 SCTP_INC_STATS(SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5445 reply
= sctp_make_abort(asoc
, NULL
, 0);
5449 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5450 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5451 SCTP_ERROR(ETIMEDOUT
));
5452 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5453 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5455 return SCTP_DISPOSITION_DELETE_TCB
;
5457 return SCTP_DISPOSITION_NOMEM
;
5460 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5461 * the association is automatically closed by starting the shutdown process.
5462 * The work that needs to be done is same as when SHUTDOWN is initiated by
5463 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5465 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5466 const struct sctp_endpoint
*ep
,
5467 const struct sctp_association
*asoc
,
5468 const sctp_subtype_t type
,
5470 sctp_cmd_seq_t
*commands
)
5474 SCTP_INC_STATS(SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5476 /* From 9.2 Shutdown of an Association
5477 * Upon receipt of the SHUTDOWN primitive from its upper
5478 * layer, the endpoint enters SHUTDOWN-PENDING state and
5479 * remains there until all outstanding data has been
5480 * acknowledged by its peer. The endpoint accepts no new data
5481 * from its upper layer, but retransmits data to the far end
5482 * if necessary to fill gaps.
5484 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5485 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5487 /* sctpimpguide-05 Section 2.12.2
5488 * The sender of the SHUTDOWN MAY also start an overall guard timer
5489 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5491 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5492 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5493 disposition
= SCTP_DISPOSITION_CONSUME
;
5494 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5495 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
5501 /*****************************************************************************
5502 * These are sa state functions which could apply to all types of events.
5503 ****************************************************************************/
5506 * This table entry is not implemented.
5509 * (endpoint, asoc, chunk)
5511 * The return value is the disposition of the chunk.
5513 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
5514 const struct sctp_association
*asoc
,
5515 const sctp_subtype_t type
,
5517 sctp_cmd_seq_t
*commands
)
5519 return SCTP_DISPOSITION_NOT_IMPL
;
5523 * This table entry represents a bug.
5526 * (endpoint, asoc, chunk)
5528 * The return value is the disposition of the chunk.
5530 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
5531 const struct sctp_association
*asoc
,
5532 const sctp_subtype_t type
,
5534 sctp_cmd_seq_t
*commands
)
5536 return SCTP_DISPOSITION_BUG
;
5540 * This table entry represents the firing of a timer in the wrong state.
5541 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5542 * when the association is in the wrong state. This event should
5543 * be ignored, so as to prevent any rearming of the timer.
5546 * (endpoint, asoc, chunk)
5548 * The return value is the disposition of the chunk.
5550 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
5551 const struct sctp_association
*asoc
,
5552 const sctp_subtype_t type
,
5554 sctp_cmd_seq_t
*commands
)
5556 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5557 return SCTP_DISPOSITION_CONSUME
;
5560 /********************************************************************
5561 * 2nd Level Abstractions
5562 ********************************************************************/
5564 /* Pull the SACK chunk based on the SACK header. */
5565 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5567 struct sctp_sackhdr
*sack
;
5572 /* Protect ourselves from reading too far into
5573 * the skb from a bogus sender.
5575 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5577 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5578 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5579 len
= sizeof(struct sctp_sackhdr
);
5580 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5581 if (len
> chunk
->skb
->len
)
5584 skb_pull(chunk
->skb
, len
);
5589 /* Create an ABORT packet to be sent as a response, with the specified
5592 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5593 const struct sctp_association
*asoc
,
5594 struct sctp_chunk
*chunk
,
5595 const void *payload
,
5598 struct sctp_packet
*packet
;
5599 struct sctp_chunk
*abort
;
5601 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5605 * The T bit will be set if the asoc is NULL.
5607 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5609 sctp_ootb_pkt_free(packet
);
5613 /* Reflect vtag if T-Bit is set */
5614 if (sctp_test_T_bit(abort
))
5615 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5617 /* Add specified error causes, i.e., payload, to the
5620 sctp_addto_chunk(abort
, paylen
, payload
);
5622 /* Set the skb to the belonging sock for accounting. */
5623 abort
->skb
->sk
= ep
->base
.sk
;
5625 sctp_packet_append_chunk(packet
, abort
);
5632 /* Allocate a packet for responding in the OOTB conditions. */
5633 static struct sctp_packet
*sctp_ootb_pkt_new(const struct sctp_association
*asoc
,
5634 const struct sctp_chunk
*chunk
)
5636 struct sctp_packet
*packet
;
5637 struct sctp_transport
*transport
;
5642 /* Get the source and destination port from the inbound packet. */
5643 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5644 dport
= ntohs(chunk
->sctp_hdr
->source
);
5646 /* The V-tag is going to be the same as the inbound packet if no
5647 * association exists, otherwise, use the peer's vtag.
5650 /* Special case the INIT-ACK as there is no peer's vtag
5653 switch(chunk
->chunk_hdr
->type
) {
5654 case SCTP_CID_INIT_ACK
:
5656 sctp_initack_chunk_t
*initack
;
5658 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5659 vtag
= ntohl(initack
->init_hdr
.init_tag
);
5663 vtag
= asoc
->peer
.i
.init_tag
;
5667 /* Special case the INIT and stale COOKIE_ECHO as there is no
5670 switch(chunk
->chunk_hdr
->type
) {
5673 sctp_init_chunk_t
*init
;
5675 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5676 vtag
= ntohl(init
->init_hdr
.init_tag
);
5680 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5685 /* Make a transport for the bucket, Eliza... */
5686 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5690 /* Cache a route for the transport with the chunk's destination as
5691 * the source address.
5693 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5694 sctp_sk(sctp_get_ctl_sock()));
5696 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5697 packet
= sctp_packet_config(packet
, vtag
, 0);
5705 /* Free the packet allocated earlier for responding in the OOTB condition. */
5706 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5708 sctp_transport_free(packet
->transport
);
5711 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5712 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5713 const struct sctp_association
*asoc
,
5714 const struct sctp_chunk
*chunk
,
5715 sctp_cmd_seq_t
*commands
,
5716 struct sctp_chunk
*err_chunk
)
5718 struct sctp_packet
*packet
;
5721 packet
= sctp_ootb_pkt_new(asoc
, chunk
);
5723 struct sctp_signed_cookie
*cookie
;
5725 /* Override the OOTB vtag from the cookie. */
5726 cookie
= chunk
->subh
.cookie_hdr
;
5727 packet
->vtag
= cookie
->c
.peer_vtag
;
5729 /* Set the skb to the belonging sock for accounting. */
5730 err_chunk
->skb
->sk
= ep
->base
.sk
;
5731 sctp_packet_append_chunk(packet
, err_chunk
);
5732 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
5733 SCTP_PACKET(packet
));
5734 SCTP_INC_STATS(SCTP_MIB_OUTCTRLCHUNKS
);
5736 sctp_chunk_free (err_chunk
);
5741 /* Process a data chunk */
5742 static int sctp_eat_data(const struct sctp_association
*asoc
,
5743 struct sctp_chunk
*chunk
,
5744 sctp_cmd_seq_t
*commands
)
5746 sctp_datahdr_t
*data_hdr
;
5747 struct sctp_chunk
*err
;
5749 sctp_verb_t deliver
;
5752 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
5753 struct sock
*sk
= asoc
->base
.sk
;
5755 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
5756 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
5758 tsn
= ntohl(data_hdr
->tsn
);
5759 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
5761 /* ASSERT: Now skb->data is really the user data. */
5763 /* Process ECN based congestion.
5765 * Since the chunk structure is reused for all chunks within
5766 * a packet, we use ecn_ce_done to track if we've already
5767 * done CE processing for this packet.
5769 * We need to do ECN processing even if we plan to discard the
5773 if (!chunk
->ecn_ce_done
) {
5775 chunk
->ecn_ce_done
= 1;
5777 af
= sctp_get_af_specific(
5778 ipver2af(ip_hdr(chunk
->skb
)->version
));
5780 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
5781 /* Do real work as sideffect. */
5782 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
5787 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
5789 /* The TSN is too high--silently discard the chunk and
5790 * count on it getting retransmitted later.
5792 return SCTP_IERROR_HIGH_TSN
;
5793 } else if (tmp
> 0) {
5794 /* This is a duplicate. Record it. */
5795 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
5796 return SCTP_IERROR_DUP_TSN
;
5799 /* This is a new TSN. */
5801 /* Discard if there is no room in the receive window.
5802 * Actually, allow a little bit of overflow (up to a MTU).
5804 datalen
= ntohs(chunk
->chunk_hdr
->length
);
5805 datalen
-= sizeof(sctp_data_chunk_t
);
5807 deliver
= SCTP_CMD_CHUNK_ULP
;
5809 /* Think about partial delivery. */
5810 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
5812 /* Even if we don't accept this chunk there is
5815 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
5818 /* Spill over rwnd a little bit. Note: While allowed, this spill over
5819 * seems a bit troublesome in that frag_point varies based on
5820 * PMTU. In cases, such as loopback, this might be a rather
5823 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
5824 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
5826 /* If this is the next TSN, consider reneging to make
5827 * room. Note: Playing nice with a confused sender. A
5828 * malicious sender can still eat up all our buffer
5829 * space and in the future we may want to detect and
5830 * do more drastic reneging.
5832 if (sctp_tsnmap_has_gap(map
) &&
5833 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5834 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
5835 deliver
= SCTP_CMD_RENEGE
;
5837 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
5838 "rwnd: %d\n", tsn
, datalen
,
5840 return SCTP_IERROR_IGNORE_TSN
;
5845 * Also try to renege to limit our memory usage in the event that
5846 * we are under memory pressure
5847 * If we can't renege, don't worry about it, the sk_rmem_schedule
5848 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
5849 * memory usage too much
5851 if (*sk
->sk_prot_creator
->memory_pressure
) {
5852 if (sctp_tsnmap_has_gap(map
) &&
5853 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
5854 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn
);
5855 deliver
= SCTP_CMD_RENEGE
;
5860 * Section 3.3.10.9 No User Data (9)
5864 * No User Data: This error cause is returned to the originator of a
5865 * DATA chunk if a received DATA chunk has no user data.
5867 if (unlikely(0 == datalen
)) {
5868 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
5870 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5873 /* We are going to ABORT, so we might as well stop
5874 * processing the rest of the chunks in the packet.
5876 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
5877 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5878 SCTP_ERROR(ECONNABORTED
));
5879 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5880 SCTP_PERR(SCTP_ERROR_NO_DATA
));
5881 SCTP_INC_STATS(SCTP_MIB_ABORTEDS
);
5882 SCTP_DEC_STATS(SCTP_MIB_CURRESTAB
);
5883 return SCTP_IERROR_NO_DATA
;
5886 /* If definately accepting the DATA chunk, record its TSN, otherwise
5887 * wait for renege processing.
5889 if (SCTP_CMD_CHUNK_ULP
== deliver
)
5890 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
5892 chunk
->data_accepted
= 1;
5894 /* Note: Some chunks may get overcounted (if we drop) or overcounted
5895 * if we renege and the chunk arrives again.
5897 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
5898 SCTP_INC_STATS(SCTP_MIB_INUNORDERCHUNKS
);
5900 SCTP_INC_STATS(SCTP_MIB_INORDERCHUNKS
);
5902 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
5904 * If an endpoint receive a DATA chunk with an invalid stream
5905 * identifier, it shall acknowledge the reception of the DATA chunk
5906 * following the normal procedure, immediately send an ERROR chunk
5907 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
5908 * and discard the DATA chunk.
5910 if (ntohs(data_hdr
->stream
) >= asoc
->c
.sinit_max_instreams
) {
5911 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
5913 sizeof(data_hdr
->stream
));
5915 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5917 return SCTP_IERROR_BAD_STREAM
;
5920 /* Send the data up to the user. Note: Schedule the
5921 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
5922 * chunk needs the updated rwnd.
5924 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
5926 return SCTP_IERROR_NO_ERROR
;