1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Mathew Kotowsky <kotowsky@sctp.org>
40 * Sridhar Samudrala <samudrala@us.ibm.com>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Hui Huang <hui.huang@nokia.com>
43 * Dajiang Zhang <dajiang.zhang@nokia.com>
44 * Daisy Chang <daisyc@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Kevin Gao <kevin.gao@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
61 #include <linux/slab.h>
63 #include <net/inet_ecn.h>
64 #include <linux/skbuff.h>
65 #include <net/sctp/sctp.h>
66 #include <net/sctp/sm.h>
67 #include <net/sctp/structs.h>
69 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
70 const struct sctp_association
*asoc
,
71 struct sctp_chunk
*chunk
,
74 static int sctp_eat_data(const struct sctp_association
*asoc
,
75 struct sctp_chunk
*chunk
,
76 sctp_cmd_seq_t
*commands
);
77 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
78 const struct sctp_association
*asoc
,
79 const struct sctp_chunk
*chunk
);
80 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
81 const struct sctp_association
*asoc
,
82 const struct sctp_chunk
*chunk
,
83 sctp_cmd_seq_t
*commands
,
84 struct sctp_chunk
*err_chunk
);
85 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
86 const struct sctp_association
*asoc
,
87 const sctp_subtype_t type
,
89 sctp_cmd_seq_t
*commands
);
90 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
91 const struct sctp_association
*asoc
,
92 const sctp_subtype_t type
,
94 sctp_cmd_seq_t
*commands
);
95 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
96 const struct sctp_association
*asoc
,
97 const sctp_subtype_t type
,
99 sctp_cmd_seq_t
*commands
);
100 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
102 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
103 __be16 error
, int sk_err
,
104 const struct sctp_association
*asoc
,
105 struct sctp_transport
*transport
);
107 static sctp_disposition_t
sctp_sf_abort_violation(
108 const struct sctp_endpoint
*ep
,
109 const struct sctp_association
*asoc
,
111 sctp_cmd_seq_t
*commands
,
113 const size_t paylen
);
115 static sctp_disposition_t
sctp_sf_violation_chunklen(
116 const struct sctp_endpoint
*ep
,
117 const struct sctp_association
*asoc
,
118 const sctp_subtype_t type
,
120 sctp_cmd_seq_t
*commands
);
122 static sctp_disposition_t
sctp_sf_violation_paramlen(
123 const struct sctp_endpoint
*ep
,
124 const struct sctp_association
*asoc
,
125 const sctp_subtype_t type
,
126 void *arg
, void *ext
,
127 sctp_cmd_seq_t
*commands
);
129 static sctp_disposition_t
sctp_sf_violation_ctsn(
130 const struct sctp_endpoint
*ep
,
131 const struct sctp_association
*asoc
,
132 const sctp_subtype_t type
,
134 sctp_cmd_seq_t
*commands
);
136 static sctp_disposition_t
sctp_sf_violation_chunk(
137 const struct sctp_endpoint
*ep
,
138 const struct sctp_association
*asoc
,
139 const sctp_subtype_t type
,
141 sctp_cmd_seq_t
*commands
);
143 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
144 const struct sctp_association
*asoc
,
145 const sctp_subtype_t type
,
146 struct sctp_chunk
*chunk
);
148 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
149 const struct sctp_association
*asoc
,
150 const sctp_subtype_t type
,
152 sctp_cmd_seq_t
*commands
);
154 /* Small helper function that checks if the chunk length
155 * is of the appropriate length. The 'required_length' argument
156 * is set to be the size of a specific chunk we are testing.
157 * Return Values: 1 = Valid length
162 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
163 __u16 required_length
)
165 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
167 if (unlikely(chunk_length
< required_length
))
173 /**********************************************************
174 * These are the state functions for handling chunk events.
175 **********************************************************/
178 * Process the final SHUTDOWN COMPLETE.
180 * Section: 4 (C) (diagram), 9.2
181 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
182 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
183 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
184 * should stop the T2-shutdown timer and remove all knowledge of the
185 * association (and thus the association enters the CLOSED state).
187 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
188 * C) Rules for packet carrying SHUTDOWN COMPLETE:
190 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
191 * if the Verification Tag field of the packet matches its own tag and
192 * the T bit is not set
194 * it is set to its peer's tag and the T bit is set in the Chunk
196 * Otherwise, the receiver MUST silently discard the packet
197 * and take no further action. An endpoint MUST ignore the
198 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
201 * (endpoint, asoc, chunk)
204 * (asoc, reply_msg, msg_up, timers, counters)
206 * The return value is the disposition of the chunk.
208 sctp_disposition_t
sctp_sf_do_4_C(const struct sctp_endpoint
*ep
,
209 const struct sctp_association
*asoc
,
210 const sctp_subtype_t type
,
212 sctp_cmd_seq_t
*commands
)
214 struct sctp_chunk
*chunk
= arg
;
215 struct sctp_ulpevent
*ev
;
218 if (!sctp_vtag_verify_either(chunk
, asoc
))
219 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
221 /* RFC 2960 6.10 Bundling
223 * An endpoint MUST NOT bundle INIT, INIT ACK or
224 * SHUTDOWN COMPLETE with any other chunks.
226 if (!chunk
->singleton
)
227 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
229 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
230 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
231 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
234 /* RFC 2960 10.2 SCTP-to-ULP
236 * H) SHUTDOWN COMPLETE notification
238 * When SCTP completes the shutdown procedures (section 9.2) this
239 * notification is passed to the upper layer.
241 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
242 0, 0, 0, NULL
, GFP_ATOMIC
);
244 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
247 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
248 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
249 * not the chunk should be discarded. If the endpoint is in
250 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
251 * T2-shutdown timer and remove all knowledge of the
252 * association (and thus the association enters the CLOSED
255 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
256 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
258 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
259 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
261 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
262 SCTP_STATE(SCTP_STATE_CLOSED
));
264 net
= sock_net(asoc
->base
.sk
);
265 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
266 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
268 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
270 return SCTP_DISPOSITION_DELETE_TCB
;
274 * Respond to a normal INIT chunk.
275 * We are the side that is being asked for an association.
277 * Section: 5.1 Normal Establishment of an Association, B
278 * B) "Z" shall respond immediately with an INIT ACK chunk. The
279 * destination IP address of the INIT ACK MUST be set to the source
280 * IP address of the INIT to which this INIT ACK is responding. In
281 * the response, besides filling in other parameters, "Z" must set the
282 * Verification Tag field to Tag_A, and also provide its own
283 * Verification Tag (Tag_Z) in the Initiate Tag field.
285 * Verification Tag: Must be 0.
288 * (endpoint, asoc, chunk)
291 * (asoc, reply_msg, msg_up, timers, counters)
293 * The return value is the disposition of the chunk.
295 sctp_disposition_t
sctp_sf_do_5_1B_init(const struct sctp_endpoint
*ep
,
296 const struct sctp_association
*asoc
,
297 const sctp_subtype_t type
,
299 sctp_cmd_seq_t
*commands
)
301 struct sctp_chunk
*chunk
= arg
;
302 struct sctp_chunk
*repl
;
303 struct sctp_association
*new_asoc
;
304 struct sctp_chunk
*err_chunk
;
305 struct sctp_packet
*packet
;
306 sctp_unrecognized_param_t
*unk_param
;
311 * An endpoint MUST NOT bundle INIT, INIT ACK or
312 * SHUTDOWN COMPLETE with any other chunks.
315 * Furthermore, we require that the receiver of an INIT chunk MUST
316 * enforce these rules by silently discarding an arriving packet
317 * with an INIT chunk that is bundled with other chunks.
319 if (!chunk
->singleton
)
320 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
322 /* If the packet is an OOTB packet which is temporarily on the
323 * control endpoint, respond with an ABORT.
325 net
= sock_net(ep
->base
.sk
);
326 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
327 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
328 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
331 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
334 if (chunk
->sctp_hdr
->vtag
!= 0)
335 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
337 /* Make sure that the INIT chunk has a valid length.
338 * Normally, this would cause an ABORT with a Protocol Violation
339 * error, but since we don't have an association, we'll
340 * just discard the packet.
342 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
343 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
345 /* If the INIT is coming toward a closing socket, we'll send back
346 * and ABORT. Essentially, this catches the race of INIT being
347 * backloged to the socket at the same time as the user isses close().
348 * Since the socket and all its associations are going away, we
349 * can treat this OOTB
351 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
352 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
354 /* Verify the INIT chunk before processing it. */
356 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
357 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
359 /* This chunk contains fatal error. It is to be discarded.
360 * Send an ABORT, with causes if there is any.
363 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
364 (__u8
*)(err_chunk
->chunk_hdr
) +
365 sizeof(sctp_chunkhdr_t
),
366 ntohs(err_chunk
->chunk_hdr
->length
) -
367 sizeof(sctp_chunkhdr_t
));
369 sctp_chunk_free(err_chunk
);
372 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
373 SCTP_PACKET(packet
));
374 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
375 return SCTP_DISPOSITION_CONSUME
;
377 return SCTP_DISPOSITION_NOMEM
;
380 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
385 /* Grab the INIT header. */
386 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
388 /* Tag the variable length parameters. */
389 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
391 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
395 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
396 sctp_scope(sctp_source(chunk
)),
400 /* The call, sctp_process_init(), can fail on memory allocation. */
401 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
402 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
406 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
408 /* If there are errors need to be reported for unknown parameters,
409 * make sure to reserve enough room in the INIT ACK for them.
413 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
414 sizeof(sctp_chunkhdr_t
);
416 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
420 /* If there are errors need to be reported for unknown parameters,
421 * include them in the outgoing INIT ACK as "Unrecognized parameter"
425 /* Get the "Unrecognized parameter" parameter(s) out of the
426 * ERROR chunk generated by sctp_verify_init(). Since the
427 * error cause code for "unknown parameter" and the
428 * "Unrecognized parameter" type is the same, we can
429 * construct the parameters in INIT ACK by copying the
432 unk_param
= (sctp_unrecognized_param_t
*)
433 ((__u8
*)(err_chunk
->chunk_hdr
) +
434 sizeof(sctp_chunkhdr_t
));
435 /* Replace the cause code with the "Unrecognized parameter"
438 sctp_addto_chunk(repl
, len
, unk_param
);
439 sctp_chunk_free(err_chunk
);
442 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
444 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
447 * Note: After sending out INIT ACK with the State Cookie parameter,
448 * "Z" MUST NOT allocate any resources, nor keep any states for the
449 * new association. Otherwise, "Z" will be vulnerable to resource
452 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
454 return SCTP_DISPOSITION_DELETE_TCB
;
457 sctp_association_free(new_asoc
);
460 sctp_chunk_free(err_chunk
);
461 return SCTP_DISPOSITION_NOMEM
;
465 * Respond to a normal INIT ACK chunk.
466 * We are the side that is initiating the association.
468 * Section: 5.1 Normal Establishment of an Association, C
469 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
470 * timer and leave COOKIE-WAIT state. "A" shall then send the State
471 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
472 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
474 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
475 * DATA chunks, but it MUST be the first chunk in the packet and
476 * until the COOKIE ACK is returned the sender MUST NOT send any
477 * other packets to the peer.
479 * Verification Tag: 3.3.3
480 * If the value of the Initiate Tag in a received INIT ACK chunk is
481 * found to be 0, the receiver MUST treat it as an error and close the
482 * association by transmitting an ABORT.
485 * (endpoint, asoc, chunk)
488 * (asoc, reply_msg, msg_up, timers, counters)
490 * The return value is the disposition of the chunk.
492 sctp_disposition_t
sctp_sf_do_5_1C_ack(const struct sctp_endpoint
*ep
,
493 const struct sctp_association
*asoc
,
494 const sctp_subtype_t type
,
496 sctp_cmd_seq_t
*commands
)
498 struct sctp_chunk
*chunk
= arg
;
499 sctp_init_chunk_t
*initchunk
;
500 struct sctp_chunk
*err_chunk
;
501 struct sctp_packet
*packet
;
503 if (!sctp_vtag_verify(chunk
, asoc
))
504 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
507 * An endpoint MUST NOT bundle INIT, INIT ACK or
508 * SHUTDOWN COMPLETE with any other chunks.
510 if (!chunk
->singleton
)
511 return sctp_sf_violation_chunk(ep
, asoc
, type
, arg
, commands
);
513 /* Make sure that the INIT-ACK chunk has a valid length */
514 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
515 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
517 /* Grab the INIT header. */
518 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
520 /* Verify the INIT chunk before processing it. */
522 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
523 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
526 sctp_error_t error
= SCTP_ERROR_NO_RESOURCE
;
528 /* This chunk contains fatal error. It is to be discarded.
529 * Send an ABORT, with causes. If there are no causes,
530 * then there wasn't enough memory. Just terminate
534 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
535 (__u8
*)(err_chunk
->chunk_hdr
) +
536 sizeof(sctp_chunkhdr_t
),
537 ntohs(err_chunk
->chunk_hdr
->length
) -
538 sizeof(sctp_chunkhdr_t
));
540 sctp_chunk_free(err_chunk
);
543 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
544 SCTP_PACKET(packet
));
545 SCTP_INC_STATS(sock_net(ep
->base
.sk
), SCTP_MIB_OUTCTRLCHUNKS
);
546 error
= SCTP_ERROR_INV_PARAM
;
550 /* SCTP-AUTH, Section 6.3:
551 * It should be noted that if the receiver wants to tear
552 * down an association in an authenticated way only, the
553 * handling of malformed packets should not result in
554 * tearing down the association.
556 * This means that if we only want to abort associations
557 * in an authenticated way (i.e AUTH+ABORT), then we
558 * can't destroy this association just because the packet
561 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
562 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
564 SCTP_INC_STATS(sock_net(ep
->base
.sk
), SCTP_MIB_ABORTEDS
);
565 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
,
566 asoc
, chunk
->transport
);
569 /* Tag the variable length parameters. Note that we never
570 * convert the parameters in an INIT chunk.
572 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
574 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
576 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
577 SCTP_PEER_INIT(initchunk
));
579 /* Reset init error count upon receipt of INIT-ACK. */
580 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
582 /* 5.1 C) "A" shall stop the T1-init timer and leave
583 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
584 * timer, and enter the COOKIE-ECHOED state.
586 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
587 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
588 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
589 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
590 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
591 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
593 /* SCTP-AUTH: genereate the assocition shared keys so that
594 * we can potentially signe the COOKIE-ECHO.
596 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
598 /* 5.1 C) "A" shall then send the State Cookie received in the
599 * INIT ACK chunk in a COOKIE ECHO chunk, ...
601 /* If there is any errors to report, send the ERROR chunk generated
602 * for unknown parameters as well.
604 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
605 SCTP_CHUNK(err_chunk
));
607 return SCTP_DISPOSITION_CONSUME
;
611 * Respond to a normal COOKIE ECHO chunk.
612 * We are the side that is being asked for an association.
614 * Section: 5.1 Normal Establishment of an Association, D
615 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
616 * with a COOKIE ACK chunk after building a TCB and moving to
617 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
618 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
619 * chunk MUST be the first chunk in the packet.
621 * IMPLEMENTATION NOTE: An implementation may choose to send the
622 * Communication Up notification to the SCTP user upon reception
623 * of a valid COOKIE ECHO chunk.
625 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
626 * D) Rules for packet carrying a COOKIE ECHO
628 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
629 * Initial Tag received in the INIT ACK.
631 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
634 * (endpoint, asoc, chunk)
637 * (asoc, reply_msg, msg_up, timers, counters)
639 * The return value is the disposition of the chunk.
641 sctp_disposition_t
sctp_sf_do_5_1D_ce(const struct sctp_endpoint
*ep
,
642 const struct sctp_association
*asoc
,
643 const sctp_subtype_t type
, void *arg
,
644 sctp_cmd_seq_t
*commands
)
646 struct sctp_chunk
*chunk
= arg
;
647 struct sctp_association
*new_asoc
;
648 sctp_init_chunk_t
*peer_init
;
649 struct sctp_chunk
*repl
;
650 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
652 struct sctp_chunk
*err_chk_p
;
656 /* If the packet is an OOTB packet which is temporarily on the
657 * control endpoint, respond with an ABORT.
659 net
= sock_net(ep
->base
.sk
);
660 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
661 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
662 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
665 /* Make sure that the COOKIE_ECHO chunk has a valid length.
666 * In this case, we check that we have enough for at least a
667 * chunk header. More detailed verification is done
668 * in sctp_unpack_cookie().
670 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
671 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
673 /* If the endpoint is not listening or if the number of associations
674 * on the TCP-style socket exceed the max backlog, respond with an
678 if (!sctp_sstate(sk
, LISTENING
) ||
679 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
680 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
682 /* "Decode" the chunk. We have no optional parameters so we
685 chunk
->subh
.cookie_hdr
=
686 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
687 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
688 sizeof(sctp_chunkhdr_t
)))
691 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
692 * "Z" will reply with a COOKIE ACK chunk after building a TCB
693 * and moving to the ESTABLISHED state.
695 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
699 * If the re-build failed, what is the proper error path
702 * [We should abort the association. --piggy]
705 /* FIXME: Several errors are possible. A bad cookie should
706 * be silently discarded, but think about logging it too.
709 case -SCTP_IERROR_NOMEM
:
712 case -SCTP_IERROR_STALE_COOKIE
:
713 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
715 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
717 case -SCTP_IERROR_BAD_SIG
:
719 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
724 /* Delay state machine commands until later.
726 * Re-build the bind address for the association is done in
727 * the sctp_unpack_cookie() already.
729 /* This is a brand-new association, so these are not yet side
730 * effects--it is safe to run them here.
732 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
734 if (!sctp_process_init(new_asoc
, chunk
,
735 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
736 peer_init
, GFP_ATOMIC
))
739 /* SCTP-AUTH: Now that we've populate required fields in
740 * sctp_process_init, set up the assocaition shared keys as
741 * necessary so that we can potentially authenticate the ACK
743 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
747 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
748 * is supposed to be authenticated and we have to do delayed
749 * authentication. We've just recreated the association using
750 * the information in the cookie and now it's much easier to
751 * do the authentication.
753 if (chunk
->auth_chunk
) {
754 struct sctp_chunk auth
;
757 /* set-up our fake chunk so that we can process it */
758 auth
.skb
= chunk
->auth_chunk
;
759 auth
.asoc
= chunk
->asoc
;
760 auth
.sctp_hdr
= chunk
->sctp_hdr
;
761 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
762 sizeof(sctp_chunkhdr_t
));
763 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
764 auth
.transport
= chunk
->transport
;
766 ret
= sctp_sf_authenticate(ep
, new_asoc
, type
, &auth
);
768 /* We can now safely free the auth_chunk clone */
769 kfree_skb(chunk
->auth_chunk
);
771 if (ret
!= SCTP_IERROR_NO_ERROR
) {
772 sctp_association_free(new_asoc
);
773 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
777 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
781 /* RFC 2960 5.1 Normal Establishment of an Association
783 * D) IMPLEMENTATION NOTE: An implementation may choose to
784 * send the Communication Up notification to the SCTP user
785 * upon reception of a valid COOKIE ECHO chunk.
787 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
788 new_asoc
->c
.sinit_num_ostreams
,
789 new_asoc
->c
.sinit_max_instreams
,
794 /* Sockets API Draft Section 5.3.1.6
795 * When a peer sends a Adaptation Layer Indication parameter , SCTP
796 * delivers this notification to inform the application that of the
797 * peers requested adaptation layer.
799 if (new_asoc
->peer
.adaptation_ind
) {
800 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
806 /* Add all the state machine commands now since we've created
807 * everything. This way we don't introduce memory corruptions
808 * during side-effect processing and correclty count established
811 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
812 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
813 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
814 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
815 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
816 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
818 if (new_asoc
->autoclose
)
819 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
820 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
822 /* This will send the COOKIE ACK */
823 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
825 /* Queue the ASSOC_CHANGE event */
826 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
828 /* Send up the Adaptation Layer Indication event */
830 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
831 SCTP_ULPEVENT(ai_ev
));
833 return SCTP_DISPOSITION_CONSUME
;
836 sctp_ulpevent_free(ev
);
838 sctp_chunk_free(repl
);
840 sctp_association_free(new_asoc
);
842 return SCTP_DISPOSITION_NOMEM
;
846 * Respond to a normal COOKIE ACK chunk.
847 * We are the side that is being asked for an association.
849 * RFC 2960 5.1 Normal Establishment of an Association
851 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
852 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
853 * timer. It may also notify its ULP about the successful
854 * establishment of the association with a Communication Up
855 * notification (see Section 10).
859 * (endpoint, asoc, chunk)
862 * (asoc, reply_msg, msg_up, timers, counters)
864 * The return value is the disposition of the chunk.
866 sctp_disposition_t
sctp_sf_do_5_1E_ca(const struct sctp_endpoint
*ep
,
867 const struct sctp_association
*asoc
,
868 const sctp_subtype_t type
, void *arg
,
869 sctp_cmd_seq_t
*commands
)
871 struct sctp_chunk
*chunk
= arg
;
872 struct sctp_ulpevent
*ev
;
875 if (!sctp_vtag_verify(chunk
, asoc
))
876 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
878 /* Verify that the chunk length for the COOKIE-ACK is OK.
879 * If we don't do this, any bundled chunks may be junked.
881 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
882 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
885 /* Reset init error count upon receipt of COOKIE-ACK,
886 * to avoid problems with the managemement of this
887 * counter in stale cookie situations when a transition back
888 * from the COOKIE-ECHOED state to the COOKIE-WAIT
889 * state is performed.
891 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
893 /* RFC 2960 5.1 Normal Establishment of an Association
895 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
896 * from the COOKIE-ECHOED state to the ESTABLISHED state,
897 * stopping the T1-cookie timer.
899 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
900 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
901 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
902 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
903 net
= sock_net(ep
->base
.sk
);
904 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
905 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
906 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
908 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
909 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
911 /* It may also notify its ULP about the successful
912 * establishment of the association with a Communication Up
913 * notification (see Section 10).
915 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
916 0, asoc
->c
.sinit_num_ostreams
,
917 asoc
->c
.sinit_max_instreams
,
923 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
925 /* Sockets API Draft Section 5.3.1.6
926 * When a peer sends a Adaptation Layer Indication parameter , SCTP
927 * delivers this notification to inform the application that of the
928 * peers requested adaptation layer.
930 if (asoc
->peer
.adaptation_ind
) {
931 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
935 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
939 return SCTP_DISPOSITION_CONSUME
;
941 return SCTP_DISPOSITION_NOMEM
;
944 /* Generate and sendout a heartbeat packet. */
945 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
946 const struct sctp_association
*asoc
,
947 const sctp_subtype_t type
,
949 sctp_cmd_seq_t
*commands
)
951 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
952 struct sctp_chunk
*reply
;
954 /* Send a heartbeat to our peer. */
955 reply
= sctp_make_heartbeat(asoc
, transport
);
957 return SCTP_DISPOSITION_NOMEM
;
959 /* Set rto_pending indicating that an RTT measurement
960 * is started with this heartbeat chunk.
962 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
963 SCTP_TRANSPORT(transport
));
965 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
966 return SCTP_DISPOSITION_CONSUME
;
969 /* Generate a HEARTBEAT packet on the given transport. */
970 sctp_disposition_t
sctp_sf_sendbeat_8_3(const struct sctp_endpoint
*ep
,
971 const struct sctp_association
*asoc
,
972 const sctp_subtype_t type
,
974 sctp_cmd_seq_t
*commands
)
976 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
978 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
980 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
981 SCTP_ERROR(ETIMEDOUT
));
982 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
983 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
984 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
985 net
= sock_net(ep
->base
.sk
);
986 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
987 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
988 return SCTP_DISPOSITION_DELETE_TCB
;
992 * The Sender-specific Heartbeat Info field should normally include
993 * information about the sender's current time when this HEARTBEAT
994 * chunk is sent and the destination transport address to which this
995 * HEARTBEAT is sent (see Section 8.3).
998 if (transport
->param_flags
& SPP_HB_ENABLE
) {
999 if (SCTP_DISPOSITION_NOMEM
==
1000 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1002 return SCTP_DISPOSITION_NOMEM
;
1004 /* Set transport error counter and association error counter
1005 * when sending heartbeat.
1007 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1008 SCTP_TRANSPORT(transport
));
1010 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1011 SCTP_TRANSPORT(transport
));
1012 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1013 SCTP_TRANSPORT(transport
));
1015 return SCTP_DISPOSITION_CONSUME
;
1019 * Process an heartbeat request.
1021 * Section: 8.3 Path Heartbeat
1022 * The receiver of the HEARTBEAT should immediately respond with a
1023 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1024 * from the received HEARTBEAT chunk.
1026 * Verification Tag: 8.5 Verification Tag [Normal verification]
1027 * When receiving an SCTP packet, the endpoint MUST ensure that the
1028 * value in the Verification Tag field of the received SCTP packet
1029 * matches its own Tag. If the received Verification Tag value does not
1030 * match the receiver's own tag value, the receiver shall silently
1031 * discard the packet and shall not process it any further except for
1032 * those cases listed in Section 8.5.1 below.
1035 * (endpoint, asoc, chunk)
1038 * (asoc, reply_msg, msg_up, timers, counters)
1040 * The return value is the disposition of the chunk.
1042 sctp_disposition_t
sctp_sf_beat_8_3(const struct sctp_endpoint
*ep
,
1043 const struct sctp_association
*asoc
,
1044 const sctp_subtype_t type
,
1046 sctp_cmd_seq_t
*commands
)
1048 struct sctp_chunk
*chunk
= arg
;
1049 struct sctp_chunk
*reply
;
1052 if (!sctp_vtag_verify(chunk
, asoc
))
1053 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1055 /* Make sure that the HEARTBEAT chunk has a valid length. */
1056 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1057 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1060 /* 8.3 The receiver of the HEARTBEAT should immediately
1061 * respond with a HEARTBEAT ACK that contains the Heartbeat
1062 * Information field copied from the received HEARTBEAT chunk.
1064 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
1065 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1066 if (!pskb_pull(chunk
->skb
, paylen
))
1069 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
1070 chunk
->subh
.hb_hdr
, paylen
);
1074 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1075 return SCTP_DISPOSITION_CONSUME
;
1078 return SCTP_DISPOSITION_NOMEM
;
1082 * Process the returning HEARTBEAT ACK.
1084 * Section: 8.3 Path Heartbeat
1085 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1086 * should clear the error counter of the destination transport
1087 * address to which the HEARTBEAT was sent, and mark the destination
1088 * transport address as active if it is not so marked. The endpoint may
1089 * optionally report to the upper layer when an inactive destination
1090 * address is marked as active due to the reception of the latest
1091 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1092 * clear the association overall error count as well (as defined
1095 * The receiver of the HEARTBEAT ACK should also perform an RTT
1096 * measurement for that destination transport address using the time
1097 * value carried in the HEARTBEAT ACK chunk.
1099 * Verification Tag: 8.5 Verification Tag [Normal verification]
1102 * (endpoint, asoc, chunk)
1105 * (asoc, reply_msg, msg_up, timers, counters)
1107 * The return value is the disposition of the chunk.
1109 sctp_disposition_t
sctp_sf_backbeat_8_3(const struct sctp_endpoint
*ep
,
1110 const struct sctp_association
*asoc
,
1111 const sctp_subtype_t type
,
1113 sctp_cmd_seq_t
*commands
)
1115 struct sctp_chunk
*chunk
= arg
;
1116 union sctp_addr from_addr
;
1117 struct sctp_transport
*link
;
1118 sctp_sender_hb_info_t
*hbinfo
;
1119 unsigned long max_interval
;
1121 if (!sctp_vtag_verify(chunk
, asoc
))
1122 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1124 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1125 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
) +
1126 sizeof(sctp_sender_hb_info_t
)))
1127 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1130 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1131 /* Make sure that the length of the parameter is what we expect */
1132 if (ntohs(hbinfo
->param_hdr
.length
) !=
1133 sizeof(sctp_sender_hb_info_t
)) {
1134 return SCTP_DISPOSITION_DISCARD
;
1137 from_addr
= hbinfo
->daddr
;
1138 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1140 /* This should never happen, but lets log it if so. */
1141 if (unlikely(!link
)) {
1142 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1143 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1146 &from_addr
.v6
.sin6_addr
);
1148 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1151 &from_addr
.v4
.sin_addr
.s_addr
);
1153 return SCTP_DISPOSITION_DISCARD
;
1156 /* Validate the 64-bit random nonce. */
1157 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1158 return SCTP_DISPOSITION_DISCARD
;
1160 max_interval
= link
->hbinterval
+ link
->rto
;
1162 /* Check if the timestamp looks valid. */
1163 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1164 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1165 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1166 "received for transport: %p\n",
1168 return SCTP_DISPOSITION_DISCARD
;
1171 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1172 * the HEARTBEAT should clear the error counter of the
1173 * destination transport address to which the HEARTBEAT was
1174 * sent and mark the destination transport address as active if
1175 * it is not so marked.
1177 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1179 return SCTP_DISPOSITION_CONSUME
;
1182 /* Helper function to send out an abort for the restart
1185 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1186 struct sctp_chunk
*init
,
1187 sctp_cmd_seq_t
*commands
)
1190 struct sctp_packet
*pkt
;
1191 union sctp_addr_param
*addrparm
;
1192 struct sctp_errhdr
*errhdr
;
1193 struct sctp_endpoint
*ep
;
1194 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1195 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1197 /* Build the error on the stack. We are way to malloc crazy
1198 * throughout the code today.
1200 errhdr
= (struct sctp_errhdr
*)buffer
;
1201 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1203 /* Copy into a parm format. */
1204 len
= af
->to_addr_param(ssa
, addrparm
);
1205 len
+= sizeof(sctp_errhdr_t
);
1207 errhdr
->cause
= SCTP_ERROR_RESTART
;
1208 errhdr
->length
= htons(len
);
1210 /* Assign to the control socket. */
1211 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1213 /* Association is NULL since this may be a restart attack and we
1214 * want to send back the attacker's vtag.
1216 pkt
= sctp_abort_pkt_new(ep
, NULL
, init
, errhdr
, len
);
1220 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1222 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1224 /* Discard the rest of the inbound packet. */
1225 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1228 /* Even if there is no memory, treat as a failure so
1229 * the packet will get dropped.
1234 static bool list_has_sctp_addr(const struct list_head
*list
,
1235 union sctp_addr
*ipaddr
)
1237 struct sctp_transport
*addr
;
1239 list_for_each_entry(addr
, list
, transports
) {
1240 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1246 /* A restart is occurring, check to make sure no new addresses
1247 * are being added as we may be under a takeover attack.
1249 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1250 const struct sctp_association
*asoc
,
1251 struct sctp_chunk
*init
,
1252 sctp_cmd_seq_t
*commands
)
1254 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1255 struct sctp_transport
*new_addr
;
1258 /* Implementor's Guide - Section 5.2.2
1260 * Before responding the endpoint MUST check to see if the
1261 * unexpected INIT adds new addresses to the association. If new
1262 * addresses are added to the association, the endpoint MUST respond
1266 /* Search through all current addresses and make sure
1267 * we aren't adding any new ones.
1269 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1271 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1272 &new_addr
->ipaddr
)) {
1273 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1280 /* Return success if all addresses were found. */
1284 /* Populate the verification/tie tags based on overlapping INIT
1287 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1289 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1290 const struct sctp_association
*asoc
)
1292 switch (asoc
->state
) {
1294 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1296 case SCTP_STATE_COOKIE_WAIT
:
1297 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1298 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1299 new_asoc
->c
.peer_ttag
= 0;
1302 case SCTP_STATE_COOKIE_ECHOED
:
1303 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1304 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1305 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1308 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1309 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1312 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1313 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1317 /* Other parameters for the endpoint SHOULD be copied from the
1318 * existing parameters of the association (e.g. number of
1319 * outbound streams) into the INIT ACK and cookie.
1321 new_asoc
->rwnd
= asoc
->rwnd
;
1322 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1323 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1324 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1328 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1331 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1333 * Returns value representing action to be taken. These action values
1334 * correspond to Action/Description values in RFC 2960, Table 2.
1336 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1337 const struct sctp_association
*asoc
)
1339 /* In this case, the peer may have restarted. */
1340 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1341 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1342 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1343 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1346 /* Collision case B. */
1347 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1348 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1349 (0 == asoc
->c
.peer_vtag
))) {
1353 /* Collision case D. */
1354 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1355 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1358 /* Collision case C. */
1359 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1360 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1361 (0 == new_asoc
->c
.my_ttag
) &&
1362 (0 == new_asoc
->c
.peer_ttag
))
1365 /* No match to any of the special cases; discard this packet. */
1369 /* Common helper routine for both duplicate and simulataneous INIT
1372 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1373 const struct sctp_endpoint
*ep
,
1374 const struct sctp_association
*asoc
,
1375 const sctp_subtype_t type
,
1376 void *arg
, sctp_cmd_seq_t
*commands
)
1378 sctp_disposition_t retval
;
1379 struct sctp_chunk
*chunk
= arg
;
1380 struct sctp_chunk
*repl
;
1381 struct sctp_association
*new_asoc
;
1382 struct sctp_chunk
*err_chunk
;
1383 struct sctp_packet
*packet
;
1384 sctp_unrecognized_param_t
*unk_param
;
1388 * An endpoint MUST NOT bundle INIT, INIT ACK or
1389 * SHUTDOWN COMPLETE with any other chunks.
1392 * Furthermore, we require that the receiver of an INIT chunk MUST
1393 * enforce these rules by silently discarding an arriving packet
1394 * with an INIT chunk that is bundled with other chunks.
1396 if (!chunk
->singleton
)
1397 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
1399 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1402 if (chunk
->sctp_hdr
->vtag
!= 0)
1403 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
1405 /* Make sure that the INIT chunk has a valid length.
1406 * In this case, we generate a protocol violation since we have
1407 * an association established.
1409 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1410 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1412 /* Grab the INIT header. */
1413 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1415 /* Tag the variable length parameters. */
1416 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1418 /* Verify the INIT chunk before processing it. */
1420 if (!sctp_verify_init(asoc
, chunk
->chunk_hdr
->type
,
1421 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1423 /* This chunk contains fatal error. It is to be discarded.
1424 * Send an ABORT, with causes if there is any.
1427 packet
= sctp_abort_pkt_new(ep
, asoc
, arg
,
1428 (__u8
*)(err_chunk
->chunk_hdr
) +
1429 sizeof(sctp_chunkhdr_t
),
1430 ntohs(err_chunk
->chunk_hdr
->length
) -
1431 sizeof(sctp_chunkhdr_t
));
1434 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1435 SCTP_PACKET(packet
));
1436 SCTP_INC_STATS(sock_net(ep
->base
.sk
), SCTP_MIB_OUTCTRLCHUNKS
);
1437 retval
= SCTP_DISPOSITION_CONSUME
;
1439 retval
= SCTP_DISPOSITION_NOMEM
;
1443 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
,
1449 * Other parameters for the endpoint SHOULD be copied from the
1450 * existing parameters of the association (e.g. number of
1451 * outbound streams) into the INIT ACK and cookie.
1452 * FIXME: We are copying parameters from the endpoint not the
1455 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1459 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1460 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1463 /* In the outbound INIT ACK the endpoint MUST copy its current
1464 * Verification Tag and Peers Verification tag into a reserved
1465 * place (local tie-tag and per tie-tag) within the state cookie.
1467 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1468 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1472 /* Make sure no new addresses are being added during the
1473 * restart. Do not do this check for COOKIE-WAIT state,
1474 * since there are no peer addresses to check against.
1475 * Upon return an ABORT will have been sent if needed.
1477 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1478 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1480 retval
= SCTP_DISPOSITION_CONSUME
;
1485 sctp_tietags_populate(new_asoc
, asoc
);
1487 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1489 /* If there are errors need to be reported for unknown parameters,
1490 * make sure to reserve enough room in the INIT ACK for them.
1494 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1495 sizeof(sctp_chunkhdr_t
);
1498 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1502 /* If there are errors need to be reported for unknown parameters,
1503 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1507 /* Get the "Unrecognized parameter" parameter(s) out of the
1508 * ERROR chunk generated by sctp_verify_init(). Since the
1509 * error cause code for "unknown parameter" and the
1510 * "Unrecognized parameter" type is the same, we can
1511 * construct the parameters in INIT ACK by copying the
1512 * ERROR causes over.
1514 unk_param
= (sctp_unrecognized_param_t
*)
1515 ((__u8
*)(err_chunk
->chunk_hdr
) +
1516 sizeof(sctp_chunkhdr_t
));
1517 /* Replace the cause code with the "Unrecognized parameter"
1520 sctp_addto_chunk(repl
, len
, unk_param
);
1523 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1524 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1527 * Note: After sending out INIT ACK with the State Cookie parameter,
1528 * "Z" MUST NOT allocate any resources for this new association.
1529 * Otherwise, "Z" will be vulnerable to resource attacks.
1531 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1532 retval
= SCTP_DISPOSITION_CONSUME
;
1537 retval
= SCTP_DISPOSITION_NOMEM
;
1540 sctp_association_free(new_asoc
);
1543 sctp_chunk_free(err_chunk
);
1548 * Handle simultaneous INIT.
1549 * This means we started an INIT and then we got an INIT request from
1552 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1553 * This usually indicates an initialization collision, i.e., each
1554 * endpoint is attempting, at about the same time, to establish an
1555 * association with the other endpoint.
1557 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1558 * endpoint MUST respond with an INIT ACK using the same parameters it
1559 * sent in its original INIT chunk (including its Verification Tag,
1560 * unchanged). These original parameters are combined with those from the
1561 * newly received INIT chunk. The endpoint shall also generate a State
1562 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1563 * INIT to calculate the State Cookie.
1565 * After that, the endpoint MUST NOT change its state, the T1-init
1566 * timer shall be left running and the corresponding TCB MUST NOT be
1567 * destroyed. The normal procedures for handling State Cookies when
1568 * a TCB exists will resolve the duplicate INITs to a single association.
1570 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1571 * its Tie-Tags with the Tag information of itself and its peer (see
1572 * section 5.2.2 for a description of the Tie-Tags).
1574 * Verification Tag: Not explicit, but an INIT can not have a valid
1575 * verification tag, so we skip the check.
1578 * (endpoint, asoc, chunk)
1581 * (asoc, reply_msg, msg_up, timers, counters)
1583 * The return value is the disposition of the chunk.
1585 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(const struct sctp_endpoint
*ep
,
1586 const struct sctp_association
*asoc
,
1587 const sctp_subtype_t type
,
1589 sctp_cmd_seq_t
*commands
)
1591 /* Call helper to do the real work for both simulataneous and
1592 * duplicate INIT chunk handling.
1594 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1598 * Handle duplicated INIT messages. These are usually delayed
1601 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1602 * COOKIE-ECHOED and COOKIE-WAIT
1604 * Unless otherwise stated, upon reception of an unexpected INIT for
1605 * this association, the endpoint shall generate an INIT ACK with a
1606 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1607 * current Verification Tag and peer's Verification Tag into a reserved
1608 * place within the state cookie. We shall refer to these locations as
1609 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1610 * containing this INIT ACK MUST carry a Verification Tag value equal to
1611 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1612 * MUST contain a new Initiation Tag (randomly generated see Section
1613 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1614 * existing parameters of the association (e.g. number of outbound
1615 * streams) into the INIT ACK and cookie.
1617 * After sending out the INIT ACK, the endpoint shall take no further
1618 * actions, i.e., the existing association, including its current state,
1619 * and the corresponding TCB MUST NOT be changed.
1621 * Note: Only when a TCB exists and the association is not in a COOKIE-
1622 * WAIT state are the Tie-Tags populated. For a normal association INIT
1623 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1624 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1625 * State Cookie are populated as specified in section 5.2.1.
1627 * Verification Tag: Not specified, but an INIT has no way of knowing
1628 * what the verification tag could be, so we ignore it.
1631 * (endpoint, asoc, chunk)
1634 * (asoc, reply_msg, msg_up, timers, counters)
1636 * The return value is the disposition of the chunk.
1638 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(const struct sctp_endpoint
*ep
,
1639 const struct sctp_association
*asoc
,
1640 const sctp_subtype_t type
,
1642 sctp_cmd_seq_t
*commands
)
1644 /* Call helper to do the real work for both simulataneous and
1645 * duplicate INIT chunk handling.
1647 return sctp_sf_do_unexpected_init(ep
, asoc
, type
, arg
, commands
);
1652 * Unexpected INIT-ACK handler.
1655 * If an INIT ACK received by an endpoint in any state other than the
1656 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1657 * An unexpected INIT ACK usually indicates the processing of an old or
1658 * duplicated INIT chunk.
1660 sctp_disposition_t
sctp_sf_do_5_2_3_initack(const struct sctp_endpoint
*ep
,
1661 const struct sctp_association
*asoc
,
1662 const sctp_subtype_t type
,
1663 void *arg
, sctp_cmd_seq_t
*commands
)
1665 struct net
*net
= sock_net(ep
->base
.sk
);
1666 /* Per the above section, we'll discard the chunk if we have an
1667 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1669 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1670 return sctp_sf_ootb(ep
, asoc
, type
, arg
, commands
);
1672 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
1675 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1678 * A) In this case, the peer may have restarted.
1680 static sctp_disposition_t
sctp_sf_do_dupcook_a(const struct sctp_endpoint
*ep
,
1681 const struct sctp_association
*asoc
,
1682 struct sctp_chunk
*chunk
,
1683 sctp_cmd_seq_t
*commands
,
1684 struct sctp_association
*new_asoc
)
1686 sctp_init_chunk_t
*peer_init
;
1687 struct sctp_ulpevent
*ev
;
1688 struct sctp_chunk
*repl
;
1689 struct sctp_chunk
*err
;
1690 sctp_disposition_t disposition
;
1692 /* new_asoc is a brand-new association, so these are not yet
1693 * side effects--it is safe to run them here.
1695 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1697 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1701 /* Make sure no new addresses are being added during the
1702 * restart. Though this is a pretty complicated attack
1703 * since you'd have to get inside the cookie.
1705 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1706 return SCTP_DISPOSITION_CONSUME
;
1709 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1710 * the peer has restarted (Action A), it MUST NOT setup a new
1711 * association but instead resend the SHUTDOWN ACK and send an ERROR
1712 * chunk with a "Cookie Received while Shutting Down" error cause to
1715 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1716 disposition
= sctp_sf_do_9_2_reshutack(ep
, asoc
,
1717 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1719 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1722 err
= sctp_make_op_error(asoc
, chunk
,
1723 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1726 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1729 return SCTP_DISPOSITION_CONSUME
;
1732 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1733 * data. Consider the optional choice of resending of this data.
1735 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1736 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1737 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1738 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1740 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1741 * and ASCONF-ACK cache.
1743 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1744 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1745 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1747 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1751 /* Report association restart to upper layer. */
1752 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1753 new_asoc
->c
.sinit_num_ostreams
,
1754 new_asoc
->c
.sinit_max_instreams
,
1759 /* Update the content of current association. */
1760 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1761 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1762 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1763 return SCTP_DISPOSITION_CONSUME
;
1766 sctp_chunk_free(repl
);
1768 return SCTP_DISPOSITION_NOMEM
;
1771 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1774 * B) In this case, both sides may be attempting to start an association
1775 * at about the same time but the peer endpoint started its INIT
1776 * after responding to the local endpoint's INIT
1778 /* This case represents an initialization collision. */
1779 static sctp_disposition_t
sctp_sf_do_dupcook_b(const struct sctp_endpoint
*ep
,
1780 const struct sctp_association
*asoc
,
1781 struct sctp_chunk
*chunk
,
1782 sctp_cmd_seq_t
*commands
,
1783 struct sctp_association
*new_asoc
)
1785 sctp_init_chunk_t
*peer_init
;
1786 struct sctp_chunk
*repl
;
1788 /* new_asoc is a brand-new association, so these are not yet
1789 * side effects--it is safe to run them here.
1791 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1792 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1796 /* Update the content of current association. */
1797 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1798 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1799 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1800 SCTP_INC_STATS(sock_net(new_asoc
->base
.sk
), SCTP_MIB_CURRESTAB
);
1801 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1803 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1807 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1809 /* RFC 2960 5.1 Normal Establishment of an Association
1811 * D) IMPLEMENTATION NOTE: An implementation may choose to
1812 * send the Communication Up notification to the SCTP user
1813 * upon reception of a valid COOKIE ECHO chunk.
1815 * Sadly, this needs to be implemented as a side-effect, because
1816 * we are not guaranteed to have set the association id of the real
1817 * association and so these notifications need to be delayed until
1818 * the association id is allocated.
1821 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1823 /* Sockets API Draft Section 5.3.1.6
1824 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1825 * delivers this notification to inform the application that of the
1826 * peers requested adaptation layer.
1828 * This also needs to be done as a side effect for the same reason as
1831 if (asoc
->peer
.adaptation_ind
)
1832 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1834 return SCTP_DISPOSITION_CONSUME
;
1837 return SCTP_DISPOSITION_NOMEM
;
1840 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1843 * C) In this case, the local endpoint's cookie has arrived late.
1844 * Before it arrived, the local endpoint sent an INIT and received an
1845 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1846 * but a new tag of its own.
1848 /* This case represents an initialization collision. */
1849 static sctp_disposition_t
sctp_sf_do_dupcook_c(const struct sctp_endpoint
*ep
,
1850 const struct sctp_association
*asoc
,
1851 struct sctp_chunk
*chunk
,
1852 sctp_cmd_seq_t
*commands
,
1853 struct sctp_association
*new_asoc
)
1855 /* The cookie should be silently discarded.
1856 * The endpoint SHOULD NOT change states and should leave
1857 * any timers running.
1859 return SCTP_DISPOSITION_DISCARD
;
1862 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1866 * D) When both local and remote tags match the endpoint should always
1867 * enter the ESTABLISHED state, if it has not already done so.
1869 /* This case represents an initialization collision. */
1870 static sctp_disposition_t
sctp_sf_do_dupcook_d(const struct sctp_endpoint
*ep
,
1871 const struct sctp_association
*asoc
,
1872 struct sctp_chunk
*chunk
,
1873 sctp_cmd_seq_t
*commands
,
1874 struct sctp_association
*new_asoc
)
1876 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1877 struct sctp_chunk
*repl
;
1879 /* Clarification from Implementor's Guide:
1880 * D) When both local and remote tags match the endpoint should
1881 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1882 * It should stop any cookie timer that may be running and send
1886 /* Don't accidentally move back into established state. */
1887 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1888 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1889 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1890 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1891 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1892 SCTP_INC_STATS(sock_net(asoc
->base
.sk
), SCTP_MIB_CURRESTAB
);
1893 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1896 /* RFC 2960 5.1 Normal Establishment of an Association
1898 * D) IMPLEMENTATION NOTE: An implementation may choose
1899 * to send the Communication Up notification to the
1900 * SCTP user upon reception of a valid COOKIE
1903 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1905 asoc
->c
.sinit_num_ostreams
,
1906 asoc
->c
.sinit_max_instreams
,
1911 /* Sockets API Draft Section 5.3.1.6
1912 * When a peer sends a Adaptation Layer Indication parameter,
1913 * SCTP delivers this notification to inform the application
1914 * that of the peers requested adaptation layer.
1916 if (asoc
->peer
.adaptation_ind
) {
1917 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1925 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1929 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1932 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1935 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1936 SCTP_ULPEVENT(ai_ev
));
1938 return SCTP_DISPOSITION_CONSUME
;
1942 sctp_ulpevent_free(ai_ev
);
1944 sctp_ulpevent_free(ev
);
1945 return SCTP_DISPOSITION_NOMEM
;
1949 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1950 * chunk was retransmitted and then delayed in the network.
1952 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1954 * Verification Tag: None. Do cookie validation.
1957 * (endpoint, asoc, chunk)
1960 * (asoc, reply_msg, msg_up, timers, counters)
1962 * The return value is the disposition of the chunk.
1964 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint
*ep
,
1965 const struct sctp_association
*asoc
,
1966 const sctp_subtype_t type
,
1968 sctp_cmd_seq_t
*commands
)
1970 sctp_disposition_t retval
;
1971 struct sctp_chunk
*chunk
= arg
;
1972 struct sctp_association
*new_asoc
;
1975 struct sctp_chunk
*err_chk_p
;
1977 /* Make sure that the chunk has a valid length from the protocol
1978 * perspective. In this case check to make sure we have at least
1979 * enough for the chunk header. Cookie length verification is
1982 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
1983 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
1986 /* "Decode" the chunk. We have no optional parameters so we
1987 * are in good shape.
1989 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
1990 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
1991 sizeof(sctp_chunkhdr_t
)))
1994 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
1995 * of a duplicate COOKIE ECHO match the Verification Tags of the
1996 * current association, consider the State Cookie valid even if
1997 * the lifespan is exceeded.
1999 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2003 * If the re-build failed, what is the proper error path
2006 * [We should abort the association. --piggy]
2009 /* FIXME: Several errors are possible. A bad cookie should
2010 * be silently discarded, but think about logging it too.
2013 case -SCTP_IERROR_NOMEM
:
2016 case -SCTP_IERROR_STALE_COOKIE
:
2017 sctp_send_stale_cookie_err(ep
, asoc
, chunk
, commands
,
2019 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2020 case -SCTP_IERROR_BAD_SIG
:
2022 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2026 /* Compare the tie_tag in cookie with the verification tag of
2027 * current association.
2029 action
= sctp_tietags_compare(new_asoc
, asoc
);
2032 case 'A': /* Association restart. */
2033 retval
= sctp_sf_do_dupcook_a(ep
, asoc
, chunk
, commands
,
2037 case 'B': /* Collision case B. */
2038 retval
= sctp_sf_do_dupcook_b(ep
, asoc
, chunk
, commands
,
2042 case 'C': /* Collision case C. */
2043 retval
= sctp_sf_do_dupcook_c(ep
, asoc
, chunk
, commands
,
2047 case 'D': /* Collision case D. */
2048 retval
= sctp_sf_do_dupcook_d(ep
, asoc
, chunk
, commands
,
2052 default: /* Discard packet for all others. */
2053 retval
= sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2057 /* Delete the tempory new association. */
2058 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
2059 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2061 /* Restore association pointer to provide SCTP command interpeter
2062 * with a valid context in case it needs to manipulate
2064 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2065 SCTP_ASOC((struct sctp_association
*)asoc
));
2070 return SCTP_DISPOSITION_NOMEM
;
2074 * Process an ABORT. (SHUTDOWN-PENDING state)
2076 * See sctp_sf_do_9_1_abort().
2078 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2079 const struct sctp_endpoint
*ep
,
2080 const struct sctp_association
*asoc
,
2081 const sctp_subtype_t type
,
2083 sctp_cmd_seq_t
*commands
)
2085 struct sctp_chunk
*chunk
= arg
;
2087 if (!sctp_vtag_verify_either(chunk
, asoc
))
2088 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2090 /* Make sure that the ABORT chunk has a valid length.
2091 * Since this is an ABORT chunk, we have to discard it
2092 * because of the following text:
2093 * RFC 2960, Section 3.3.7
2094 * If an endpoint receives an ABORT with a format error or for an
2095 * association that doesn't exist, it MUST silently discard it.
2096 * Because the length is "invalid", we can't really discard just
2097 * as we do not know its true length. So, to be safe, discard the
2100 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2101 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2103 /* ADD-IP: Special case for ABORT chunks
2104 * F4) One special consideration is that ABORT Chunks arriving
2105 * destined to the IP address being deleted MUST be
2106 * ignored (see Section 5.3.1 for further details).
2108 if (SCTP_ADDR_DEL
==
2109 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2110 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2112 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2116 * Process an ABORT. (SHUTDOWN-SENT state)
2118 * See sctp_sf_do_9_1_abort().
2120 sctp_disposition_t
sctp_sf_shutdown_sent_abort(const struct sctp_endpoint
*ep
,
2121 const struct sctp_association
*asoc
,
2122 const sctp_subtype_t type
,
2124 sctp_cmd_seq_t
*commands
)
2126 struct sctp_chunk
*chunk
= arg
;
2128 if (!sctp_vtag_verify_either(chunk
, asoc
))
2129 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2131 /* Make sure that the ABORT chunk has a valid length.
2132 * Since this is an ABORT chunk, we have to discard it
2133 * because of the following text:
2134 * RFC 2960, Section 3.3.7
2135 * If an endpoint receives an ABORT with a format error or for an
2136 * association that doesn't exist, it MUST silently discard it.
2137 * Because the length is "invalid", we can't really discard just
2138 * as we do not know its true length. So, to be safe, discard the
2141 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2142 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2144 /* ADD-IP: Special case for ABORT chunks
2145 * F4) One special consideration is that ABORT Chunks arriving
2146 * destined to the IP address being deleted MUST be
2147 * ignored (see Section 5.3.1 for further details).
2149 if (SCTP_ADDR_DEL
==
2150 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2151 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2153 /* Stop the T2-shutdown timer. */
2154 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2155 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2157 /* Stop the T5-shutdown guard timer. */
2158 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2159 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2161 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2165 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2167 * See sctp_sf_do_9_1_abort().
2169 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2170 const struct sctp_endpoint
*ep
,
2171 const struct sctp_association
*asoc
,
2172 const sctp_subtype_t type
,
2174 sctp_cmd_seq_t
*commands
)
2176 /* The same T2 timer, so we should be able to use
2177 * common function with the SHUTDOWN-SENT state.
2179 return sctp_sf_shutdown_sent_abort(ep
, asoc
, type
, arg
, commands
);
2183 * Handle an Error received in COOKIE_ECHOED state.
2185 * Only handle the error type of stale COOKIE Error, the other errors will
2189 * (endpoint, asoc, chunk)
2192 * (asoc, reply_msg, msg_up, timers, counters)
2194 * The return value is the disposition of the chunk.
2196 sctp_disposition_t
sctp_sf_cookie_echoed_err(const struct sctp_endpoint
*ep
,
2197 const struct sctp_association
*asoc
,
2198 const sctp_subtype_t type
,
2200 sctp_cmd_seq_t
*commands
)
2202 struct sctp_chunk
*chunk
= arg
;
2205 if (!sctp_vtag_verify(chunk
, asoc
))
2206 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2208 /* Make sure that the ERROR chunk has a valid length.
2209 * The parameter walking depends on this as well.
2211 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2212 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2215 /* Process the error here */
2216 /* FUTURE FIXME: When PR-SCTP related and other optional
2217 * parms are emitted, this will have to change to handle multiple
2220 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2221 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2222 return sctp_sf_do_5_2_6_stale(ep
, asoc
, type
,
2226 /* It is possible to have malformed error causes, and that
2227 * will cause us to end the walk early. However, since
2228 * we are discarding the packet, there should be no adverse
2231 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2235 * Handle a Stale COOKIE Error
2237 * Section: 5.2.6 Handle Stale COOKIE Error
2238 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2239 * one of the following three alternatives.
2241 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2242 * Preservative parameter requesting an extension to the lifetime of
2243 * the State Cookie. When calculating the time extension, an
2244 * implementation SHOULD use the RTT information measured based on the
2245 * previous COOKIE ECHO / ERROR exchange, and should add no more
2246 * than 1 second beyond the measured RTT, due to long State Cookie
2247 * lifetimes making the endpoint more subject to a replay attack.
2249 * Verification Tag: Not explicit, but safe to ignore.
2252 * (endpoint, asoc, chunk)
2255 * (asoc, reply_msg, msg_up, timers, counters)
2257 * The return value is the disposition of the chunk.
2259 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(const struct sctp_endpoint
*ep
,
2260 const struct sctp_association
*asoc
,
2261 const sctp_subtype_t type
,
2263 sctp_cmd_seq_t
*commands
)
2265 struct sctp_chunk
*chunk
= arg
;
2267 sctp_cookie_preserve_param_t bht
;
2269 struct sctp_chunk
*reply
;
2270 struct sctp_bind_addr
*bp
;
2271 int attempts
= asoc
->init_err_counter
+ 1;
2273 if (attempts
> asoc
->max_init_attempts
) {
2274 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2275 SCTP_ERROR(ETIMEDOUT
));
2276 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2277 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2278 return SCTP_DISPOSITION_DELETE_TCB
;
2281 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2283 /* When calculating the time extension, an implementation
2284 * SHOULD use the RTT information measured based on the
2285 * previous COOKIE ECHO / ERROR exchange, and should add no
2286 * more than 1 second beyond the measured RTT, due to long
2287 * State Cookie lifetimes making the endpoint more subject to
2289 * Measure of Staleness's unit is usec. (1/1000000 sec)
2290 * Suggested Cookie Life-span Increment's unit is msec.
2292 * In general, if you use the suggested cookie life, the value
2293 * found in the field of measure of staleness should be doubled
2294 * to give ample time to retransmit the new cookie and thus
2295 * yield a higher probability of success on the reattempt.
2297 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2298 stale
= (stale
* 2) / 1000;
2300 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2301 bht
.param_hdr
.length
= htons(sizeof(bht
));
2302 bht
.lifespan_increment
= htonl(stale
);
2304 /* Build that new INIT chunk. */
2305 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2306 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2310 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2312 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2313 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2315 /* Stop pending T3-rtx and heartbeat timers */
2316 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2317 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2319 /* Delete non-primary peer ip addresses since we are transitioning
2320 * back to the COOKIE-WAIT state
2322 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2324 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2327 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2328 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2330 /* Cast away the const modifier, as we want to just
2331 * rerun it through as a sideffect.
2333 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2335 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2336 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2337 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2338 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2339 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2340 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2342 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2344 return SCTP_DISPOSITION_CONSUME
;
2347 return SCTP_DISPOSITION_NOMEM
;
2354 * After checking the Verification Tag, the receiving endpoint shall
2355 * remove the association from its record, and shall report the
2356 * termination to its upper layer.
2358 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2359 * B) Rules for packet carrying ABORT:
2361 * - The endpoint shall always fill in the Verification Tag field of the
2362 * outbound packet with the destination endpoint's tag value if it
2365 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2366 * MUST follow the procedure described in Section 8.4.
2368 * - The receiver MUST accept the packet if the Verification Tag
2369 * matches either its own tag, OR the tag of its peer. Otherwise, the
2370 * receiver MUST silently discard the packet and take no further
2374 * (endpoint, asoc, chunk)
2377 * (asoc, reply_msg, msg_up, timers, counters)
2379 * The return value is the disposition of the chunk.
2381 sctp_disposition_t
sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2382 const struct sctp_association
*asoc
,
2383 const sctp_subtype_t type
,
2385 sctp_cmd_seq_t
*commands
)
2387 struct sctp_chunk
*chunk
= arg
;
2389 if (!sctp_vtag_verify_either(chunk
, asoc
))
2390 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2392 /* Make sure that the ABORT chunk has a valid length.
2393 * Since this is an ABORT chunk, we have to discard it
2394 * because of the following text:
2395 * RFC 2960, Section 3.3.7
2396 * If an endpoint receives an ABORT with a format error or for an
2397 * association that doesn't exist, it MUST silently discard it.
2398 * Because the length is "invalid", we can't really discard just
2399 * as we do not know its true length. So, to be safe, discard the
2402 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2403 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2405 /* ADD-IP: Special case for ABORT chunks
2406 * F4) One special consideration is that ABORT Chunks arriving
2407 * destined to the IP address being deleted MUST be
2408 * ignored (see Section 5.3.1 for further details).
2410 if (SCTP_ADDR_DEL
==
2411 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2412 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
2414 return __sctp_sf_do_9_1_abort(ep
, asoc
, type
, arg
, commands
);
2417 static sctp_disposition_t
__sctp_sf_do_9_1_abort(const struct sctp_endpoint
*ep
,
2418 const struct sctp_association
*asoc
,
2419 const sctp_subtype_t type
,
2421 sctp_cmd_seq_t
*commands
)
2423 struct sctp_chunk
*chunk
= arg
;
2425 __be16 error
= SCTP_ERROR_NO_ERROR
;
2428 /* See if we have an error cause code in the chunk. */
2429 len
= ntohs(chunk
->chunk_hdr
->length
);
2430 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2433 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2434 if ((void *)err
!= (void *)chunk
->chunk_end
)
2435 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2437 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2440 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2441 /* ASSOC_FAILED will DELETE_TCB. */
2442 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2443 net
= sock_net(ep
->base
.sk
);
2444 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2445 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2447 return SCTP_DISPOSITION_ABORT
;
2451 * Process an ABORT. (COOKIE-WAIT state)
2453 * See sctp_sf_do_9_1_abort() above.
2455 sctp_disposition_t
sctp_sf_cookie_wait_abort(const struct sctp_endpoint
*ep
,
2456 const struct sctp_association
*asoc
,
2457 const sctp_subtype_t type
,
2459 sctp_cmd_seq_t
*commands
)
2461 struct sctp_chunk
*chunk
= arg
;
2463 __be16 error
= SCTP_ERROR_NO_ERROR
;
2465 if (!sctp_vtag_verify_either(chunk
, asoc
))
2466 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2468 /* Make sure that the ABORT chunk has a valid length.
2469 * Since this is an ABORT chunk, we have to discard it
2470 * because of the following text:
2471 * RFC 2960, Section 3.3.7
2472 * If an endpoint receives an ABORT with a format error or for an
2473 * association that doesn't exist, it MUST silently discard it.
2474 * Because the length is "invalid", we can't really discard just
2475 * as we do not know its true length. So, to be safe, discard the
2478 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2479 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2481 /* See if we have an error cause code in the chunk. */
2482 len
= ntohs(chunk
->chunk_hdr
->length
);
2483 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2484 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2486 return sctp_stop_t1_and_abort(commands
, error
, ECONNREFUSED
, asoc
,
2491 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2493 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(const struct sctp_endpoint
*ep
,
2494 const struct sctp_association
*asoc
,
2495 const sctp_subtype_t type
,
2497 sctp_cmd_seq_t
*commands
)
2499 return sctp_stop_t1_and_abort(commands
, SCTP_ERROR_NO_ERROR
,
2501 (struct sctp_transport
*)arg
);
2505 * Process an ABORT. (COOKIE-ECHOED state)
2507 sctp_disposition_t
sctp_sf_cookie_echoed_abort(const struct sctp_endpoint
*ep
,
2508 const struct sctp_association
*asoc
,
2509 const sctp_subtype_t type
,
2511 sctp_cmd_seq_t
*commands
)
2513 /* There is a single T1 timer, so we should be able to use
2514 * common function with the COOKIE-WAIT state.
2516 return sctp_sf_cookie_wait_abort(ep
, asoc
, type
, arg
, commands
);
2520 * Stop T1 timer and abort association with "INIT failed".
2522 * This is common code called by several sctp_sf_*_abort() functions above.
2524 static sctp_disposition_t
sctp_stop_t1_and_abort(sctp_cmd_seq_t
*commands
,
2525 __be16 error
, int sk_err
,
2526 const struct sctp_association
*asoc
,
2527 struct sctp_transport
*transport
)
2529 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2530 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2531 SCTP_STATE(SCTP_STATE_CLOSED
));
2532 SCTP_INC_STATS(sock_net(asoc
->base
.sk
), SCTP_MIB_ABORTEDS
);
2533 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2534 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2535 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2536 /* CMD_INIT_FAILED will DELETE_TCB. */
2537 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2539 return SCTP_DISPOSITION_ABORT
;
2543 * sctp_sf_do_9_2_shut
2546 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2547 * - enter the SHUTDOWN-RECEIVED state,
2549 * - stop accepting new data from its SCTP user
2551 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2552 * that all its outstanding DATA chunks have been received by the
2555 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2556 * send a SHUTDOWN in response to a ULP request. And should discard
2557 * subsequent SHUTDOWN chunks.
2559 * If there are still outstanding DATA chunks left, the SHUTDOWN
2560 * receiver shall continue to follow normal data transmission
2561 * procedures defined in Section 6 until all outstanding DATA chunks
2562 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2563 * new data from its SCTP user.
2565 * Verification Tag: 8.5 Verification Tag [Normal verification]
2568 * (endpoint, asoc, chunk)
2571 * (asoc, reply_msg, msg_up, timers, counters)
2573 * The return value is the disposition of the chunk.
2575 sctp_disposition_t
sctp_sf_do_9_2_shutdown(const struct sctp_endpoint
*ep
,
2576 const struct sctp_association
*asoc
,
2577 const sctp_subtype_t type
,
2579 sctp_cmd_seq_t
*commands
)
2581 struct sctp_chunk
*chunk
= arg
;
2582 sctp_shutdownhdr_t
*sdh
;
2583 sctp_disposition_t disposition
;
2584 struct sctp_ulpevent
*ev
;
2587 if (!sctp_vtag_verify(chunk
, asoc
))
2588 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2590 /* Make sure that the SHUTDOWN chunk has a valid length. */
2591 if (!sctp_chunk_length_valid(chunk
,
2592 sizeof(struct sctp_shutdown_chunk_t
)))
2593 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2596 /* Convert the elaborate header. */
2597 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2598 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2599 chunk
->subh
.shutdown_hdr
= sdh
;
2600 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2602 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2603 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2604 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2605 return SCTP_DISPOSITION_DISCARD
;
2608 /* If Cumulative TSN Ack beyond the max tsn currently
2609 * send, terminating the association and respond to the
2610 * sender with an ABORT.
2612 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2613 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2615 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2616 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2617 * inform the application that it should cease sending data.
2619 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2621 disposition
= SCTP_DISPOSITION_NOMEM
;
2624 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2626 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2627 * - enter the SHUTDOWN-RECEIVED state,
2628 * - stop accepting new data from its SCTP user
2630 * [This is implicit in the new state.]
2632 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2633 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2634 disposition
= SCTP_DISPOSITION_CONSUME
;
2636 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2637 disposition
= sctp_sf_do_9_2_shutdown_ack(ep
, asoc
, type
,
2641 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2644 /* - verify, by checking the Cumulative TSN Ack field of the
2645 * chunk, that all its outstanding DATA chunks have been
2646 * received by the SHUTDOWN sender.
2648 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2649 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2656 * sctp_sf_do_9_2_shut_ctsn
2658 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2659 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2660 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2661 * MUST be processed.
2663 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(const struct sctp_endpoint
*ep
,
2664 const struct sctp_association
*asoc
,
2665 const sctp_subtype_t type
,
2667 sctp_cmd_seq_t
*commands
)
2669 struct sctp_chunk
*chunk
= arg
;
2670 sctp_shutdownhdr_t
*sdh
;
2673 if (!sctp_vtag_verify(chunk
, asoc
))
2674 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2676 /* Make sure that the SHUTDOWN chunk has a valid length. */
2677 if (!sctp_chunk_length_valid(chunk
,
2678 sizeof(struct sctp_shutdown_chunk_t
)))
2679 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2682 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2683 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2685 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2686 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2687 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2688 return SCTP_DISPOSITION_DISCARD
;
2691 /* If Cumulative TSN Ack beyond the max tsn currently
2692 * send, terminating the association and respond to the
2693 * sender with an ABORT.
2695 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2696 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
2698 /* verify, by checking the Cumulative TSN Ack field of the
2699 * chunk, that all its outstanding DATA chunks have been
2700 * received by the SHUTDOWN sender.
2702 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2703 SCTP_BE32(sdh
->cum_tsn_ack
));
2705 return SCTP_DISPOSITION_CONSUME
;
2709 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2710 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2711 * transport addresses (either in the IP addresses or in the INIT chunk)
2712 * that belong to this association, it should discard the INIT chunk and
2713 * retransmit the SHUTDOWN ACK chunk.
2715 sctp_disposition_t
sctp_sf_do_9_2_reshutack(const struct sctp_endpoint
*ep
,
2716 const struct sctp_association
*asoc
,
2717 const sctp_subtype_t type
,
2719 sctp_cmd_seq_t
*commands
)
2721 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2722 struct sctp_chunk
*reply
;
2724 /* Make sure that the chunk has a valid length */
2725 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2726 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2729 /* Since we are not going to really process this INIT, there
2730 * is no point in verifying chunk boundries. Just generate
2733 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2737 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2738 * the T2-SHUTDOWN timer.
2740 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2742 /* and restart the T2-shutdown timer. */
2743 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2744 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2746 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2748 return SCTP_DISPOSITION_CONSUME
;
2750 return SCTP_DISPOSITION_NOMEM
;
2754 * sctp_sf_do_ecn_cwr
2756 * Section: Appendix A: Explicit Congestion Notification
2760 * RFC 2481 details a specific bit for a sender to send in the header of
2761 * its next outbound TCP segment to indicate to its peer that it has
2762 * reduced its congestion window. This is termed the CWR bit. For
2763 * SCTP the same indication is made by including the CWR chunk.
2764 * This chunk contains one data element, i.e. the TSN number that
2765 * was sent in the ECNE chunk. This element represents the lowest
2766 * TSN number in the datagram that was originally marked with the
2769 * Verification Tag: 8.5 Verification Tag [Normal verification]
2771 * (endpoint, asoc, chunk)
2774 * (asoc, reply_msg, msg_up, timers, counters)
2776 * The return value is the disposition of the chunk.
2778 sctp_disposition_t
sctp_sf_do_ecn_cwr(const struct sctp_endpoint
*ep
,
2779 const struct sctp_association
*asoc
,
2780 const sctp_subtype_t type
,
2782 sctp_cmd_seq_t
*commands
)
2785 struct sctp_chunk
*chunk
= arg
;
2788 if (!sctp_vtag_verify(chunk
, asoc
))
2789 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2791 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2792 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2795 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2796 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2798 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2800 /* Does this CWR ack the last sent congestion notification? */
2801 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2802 /* Stop sending ECNE. */
2803 sctp_add_cmd_sf(commands
,
2805 SCTP_U32(lowest_tsn
));
2807 return SCTP_DISPOSITION_CONSUME
;
2813 * Section: Appendix A: Explicit Congestion Notification
2817 * RFC 2481 details a specific bit for a receiver to send back in its
2818 * TCP acknowledgements to notify the sender of the Congestion
2819 * Experienced (CE) bit having arrived from the network. For SCTP this
2820 * same indication is made by including the ECNE chunk. This chunk
2821 * contains one data element, i.e. the lowest TSN associated with the IP
2822 * datagram marked with the CE bit.....
2824 * Verification Tag: 8.5 Verification Tag [Normal verification]
2826 * (endpoint, asoc, chunk)
2829 * (asoc, reply_msg, msg_up, timers, counters)
2831 * The return value is the disposition of the chunk.
2833 sctp_disposition_t
sctp_sf_do_ecne(const struct sctp_endpoint
*ep
,
2834 const struct sctp_association
*asoc
,
2835 const sctp_subtype_t type
,
2837 sctp_cmd_seq_t
*commands
)
2839 sctp_ecnehdr_t
*ecne
;
2840 struct sctp_chunk
*chunk
= arg
;
2842 if (!sctp_vtag_verify(chunk
, asoc
))
2843 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2845 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2846 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2849 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2850 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2852 /* If this is a newer ECNE than the last CWR packet we sent out */
2853 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2854 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2856 return SCTP_DISPOSITION_CONSUME
;
2860 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2862 * The SCTP endpoint MUST always acknowledge the reception of each valid
2865 * The guidelines on delayed acknowledgement algorithm specified in
2866 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2867 * acknowledgement SHOULD be generated for at least every second packet
2868 * (not every second DATA chunk) received, and SHOULD be generated within
2869 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2870 * situations it may be beneficial for an SCTP transmitter to be more
2871 * conservative than the algorithms detailed in this document allow.
2872 * However, an SCTP transmitter MUST NOT be more aggressive than the
2873 * following algorithms allow.
2875 * A SCTP receiver MUST NOT generate more than one SACK for every
2876 * incoming packet, other than to update the offered window as the
2877 * receiving application consumes new data.
2879 * Verification Tag: 8.5 Verification Tag [Normal verification]
2882 * (endpoint, asoc, chunk)
2885 * (asoc, reply_msg, msg_up, timers, counters)
2887 * The return value is the disposition of the chunk.
2889 sctp_disposition_t
sctp_sf_eat_data_6_2(const struct sctp_endpoint
*ep
,
2890 const struct sctp_association
*asoc
,
2891 const sctp_subtype_t type
,
2893 sctp_cmd_seq_t
*commands
)
2895 struct sctp_chunk
*chunk
= arg
;
2896 sctp_arg_t force
= SCTP_NOFORCE();
2899 if (!sctp_vtag_verify(chunk
, asoc
)) {
2900 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2902 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
2905 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2906 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
2909 error
= sctp_eat_data(asoc
, chunk
, commands
);
2911 case SCTP_IERROR_NO_ERROR
:
2913 case SCTP_IERROR_HIGH_TSN
:
2914 case SCTP_IERROR_BAD_STREAM
:
2915 SCTP_INC_STATS(sock_net(asoc
->base
.sk
), SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2916 goto discard_noforce
;
2917 case SCTP_IERROR_DUP_TSN
:
2918 case SCTP_IERROR_IGNORE_TSN
:
2919 SCTP_INC_STATS(sock_net(asoc
->base
.sk
), SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2921 case SCTP_IERROR_NO_DATA
:
2923 case SCTP_IERROR_PROTO_VIOLATION
:
2924 return sctp_sf_abort_violation(ep
, asoc
, chunk
, commands
,
2925 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2930 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
2931 force
= SCTP_FORCE();
2933 if (asoc
->autoclose
) {
2934 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2935 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2938 /* If this is the last chunk in a packet, we need to count it
2939 * toward sack generation. Note that we need to SACK every
2940 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2941 * THEM. We elect to NOT generate SACK's if the chunk fails
2942 * the verification tag test.
2944 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2946 * The SCTP endpoint MUST always acknowledge the reception of
2947 * each valid DATA chunk.
2949 * The guidelines on delayed acknowledgement algorithm
2950 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2951 * Specifically, an acknowledgement SHOULD be generated for at
2952 * least every second packet (not every second DATA chunk)
2953 * received, and SHOULD be generated within 200 ms of the
2954 * arrival of any unacknowledged DATA chunk. In some
2955 * situations it may be beneficial for an SCTP transmitter to
2956 * be more conservative than the algorithms detailed in this
2957 * document allow. However, an SCTP transmitter MUST NOT be
2958 * more aggressive than the following algorithms allow.
2960 if (chunk
->end_of_packet
)
2961 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
2963 return SCTP_DISPOSITION_CONSUME
;
2966 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2968 * When a packet arrives with duplicate DATA chunk(s) and with
2969 * no new DATA chunk(s), the endpoint MUST immediately send a
2970 * SACK with no delay. If a packet arrives with duplicate
2971 * DATA chunk(s) bundled with new DATA chunks, the endpoint
2972 * MAY immediately send a SACK. Normally receipt of duplicate
2973 * DATA chunks will occur when the original SACK chunk was lost
2974 * and the peer's RTO has expired. The duplicate TSN number(s)
2975 * SHOULD be reported in the SACK as duplicate.
2977 /* In our case, we split the MAY SACK advice up whether or not
2978 * the last chunk is a duplicate.'
2980 if (chunk
->end_of_packet
)
2981 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
2982 return SCTP_DISPOSITION_DISCARD
;
2985 if (chunk
->end_of_packet
)
2986 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
2988 return SCTP_DISPOSITION_DISCARD
;
2990 return SCTP_DISPOSITION_CONSUME
;
2995 * sctp_sf_eat_data_fast_4_4
2998 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
2999 * DATA chunks without delay.
3001 * Verification Tag: 8.5 Verification Tag [Normal verification]
3003 * (endpoint, asoc, chunk)
3006 * (asoc, reply_msg, msg_up, timers, counters)
3008 * The return value is the disposition of the chunk.
3010 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(const struct sctp_endpoint
*ep
,
3011 const struct sctp_association
*asoc
,
3012 const sctp_subtype_t type
,
3014 sctp_cmd_seq_t
*commands
)
3016 struct sctp_chunk
*chunk
= arg
;
3019 if (!sctp_vtag_verify(chunk
, asoc
)) {
3020 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3022 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3025 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
3026 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3029 error
= sctp_eat_data(asoc
, chunk
, commands
);
3031 case SCTP_IERROR_NO_ERROR
:
3032 case SCTP_IERROR_HIGH_TSN
:
3033 case SCTP_IERROR_DUP_TSN
:
3034 case SCTP_IERROR_IGNORE_TSN
:
3035 case SCTP_IERROR_BAD_STREAM
:
3037 case SCTP_IERROR_NO_DATA
:
3039 case SCTP_IERROR_PROTO_VIOLATION
:
3040 return sctp_sf_abort_violation(ep
, asoc
, chunk
, commands
,
3041 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
3046 /* Go a head and force a SACK, since we are shutting down. */
3048 /* Implementor's Guide.
3050 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3051 * respond to each received packet containing one or more DATA chunk(s)
3052 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3054 if (chunk
->end_of_packet
) {
3055 /* We must delay the chunk creation since the cumulative
3056 * TSN has not been updated yet.
3058 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3059 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3060 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3061 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3065 return SCTP_DISPOSITION_CONSUME
;
3069 * Section: 6.2 Processing a Received SACK
3070 * D) Any time a SACK arrives, the endpoint performs the following:
3072 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3073 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3074 * increasing, a SACK whose Cumulative TSN Ack is less than the
3075 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3077 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3078 * of bytes still outstanding after processing the Cumulative TSN Ack
3079 * and the Gap Ack Blocks.
3081 * iii) If the SACK is missing a TSN that was previously
3082 * acknowledged via a Gap Ack Block (e.g., the data receiver
3083 * reneged on the data), then mark the corresponding DATA chunk
3084 * as available for retransmit: Mark it as missing for fast
3085 * retransmit as described in Section 7.2.4 and if no retransmit
3086 * timer is running for the destination address to which the DATA
3087 * chunk was originally transmitted, then T3-rtx is started for
3088 * that destination address.
3090 * Verification Tag: 8.5 Verification Tag [Normal verification]
3093 * (endpoint, asoc, chunk)
3096 * (asoc, reply_msg, msg_up, timers, counters)
3098 * The return value is the disposition of the chunk.
3100 sctp_disposition_t
sctp_sf_eat_sack_6_2(const struct sctp_endpoint
*ep
,
3101 const struct sctp_association
*asoc
,
3102 const sctp_subtype_t type
,
3104 sctp_cmd_seq_t
*commands
)
3106 struct sctp_chunk
*chunk
= arg
;
3107 sctp_sackhdr_t
*sackh
;
3110 if (!sctp_vtag_verify(chunk
, asoc
))
3111 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3113 /* Make sure that the SACK chunk has a valid length. */
3114 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3115 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3118 /* Pull the SACK chunk from the data buffer */
3119 sackh
= sctp_sm_pull_sack(chunk
);
3120 /* Was this a bogus SACK? */
3122 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3123 chunk
->subh
.sack_hdr
= sackh
;
3124 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3126 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3127 * Ack Point, then drop the SACK. Since Cumulative TSN
3128 * Ack is monotonically increasing, a SACK whose
3129 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3130 * Point indicates an out-of-order SACK.
3132 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3133 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
3134 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
3135 return SCTP_DISPOSITION_DISCARD
;
3138 /* If Cumulative TSN Ack beyond the max tsn currently
3139 * send, terminating the association and respond to the
3140 * sender with an ABORT.
3142 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3143 return sctp_sf_violation_ctsn(ep
, asoc
, type
, arg
, commands
);
3145 /* Return this SACK for further processing. */
3146 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
3148 /* Note: We do the rest of the work on the PROCESS_SACK
3151 return SCTP_DISPOSITION_CONSUME
;
3155 * Generate an ABORT in response to a packet.
3157 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3159 * 8) The receiver should respond to the sender of the OOTB packet with
3160 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3161 * MUST fill in the Verification Tag field of the outbound packet
3162 * with the value found in the Verification Tag field of the OOTB
3163 * packet and set the T-bit in the Chunk Flags to indicate that the
3164 * Verification Tag is reflected. After sending this ABORT, the
3165 * receiver of the OOTB packet shall discard the OOTB packet and take
3166 * no further action.
3170 * The return value is the disposition of the chunk.
3172 static sctp_disposition_t
sctp_sf_tabort_8_4_8(const struct sctp_endpoint
*ep
,
3173 const struct sctp_association
*asoc
,
3174 const sctp_subtype_t type
,
3176 sctp_cmd_seq_t
*commands
)
3178 struct sctp_packet
*packet
= NULL
;
3179 struct sctp_chunk
*chunk
= arg
;
3180 struct sctp_chunk
*abort
;
3183 net
= sock_net(ep
->base
.sk
);
3184 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3187 /* Make an ABORT. The T bit will be set if the asoc
3190 abort
= sctp_make_abort(asoc
, chunk
, 0);
3192 sctp_ootb_pkt_free(packet
);
3193 return SCTP_DISPOSITION_NOMEM
;
3196 /* Reflect vtag if T-Bit is set */
3197 if (sctp_test_T_bit(abort
))
3198 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3200 /* Set the skb to the belonging sock for accounting. */
3201 abort
->skb
->sk
= ep
->base
.sk
;
3203 sctp_packet_append_chunk(packet
, abort
);
3205 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3206 SCTP_PACKET(packet
));
3208 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3210 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3211 return SCTP_DISPOSITION_CONSUME
;
3214 return SCTP_DISPOSITION_NOMEM
;
3218 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3219 * event as ULP notification for each cause included in the chunk.
3221 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3223 * The return value is the disposition of the chunk.
3225 sctp_disposition_t
sctp_sf_operr_notify(const struct sctp_endpoint
*ep
,
3226 const struct sctp_association
*asoc
,
3227 const sctp_subtype_t type
,
3229 sctp_cmd_seq_t
*commands
)
3231 struct sctp_chunk
*chunk
= arg
;
3234 if (!sctp_vtag_verify(chunk
, asoc
))
3235 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3237 /* Make sure that the ERROR chunk has a valid length. */
3238 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3239 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3241 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3242 if ((void *)err
!= (void *)chunk
->chunk_end
)
3243 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3244 (void *)err
, commands
);
3246 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3249 return SCTP_DISPOSITION_CONSUME
;
3253 * Process an inbound SHUTDOWN ACK.
3256 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3257 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3258 * peer, and remove all record of the association.
3260 * The return value is the disposition.
3262 sctp_disposition_t
sctp_sf_do_9_2_final(const struct sctp_endpoint
*ep
,
3263 const struct sctp_association
*asoc
,
3264 const sctp_subtype_t type
,
3266 sctp_cmd_seq_t
*commands
)
3268 struct sctp_chunk
*chunk
= arg
;
3269 struct sctp_chunk
*reply
;
3270 struct sctp_ulpevent
*ev
;
3273 if (!sctp_vtag_verify(chunk
, asoc
))
3274 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3276 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3277 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3278 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3280 /* 10.2 H) SHUTDOWN COMPLETE notification
3282 * When SCTP completes the shutdown procedures (section 9.2) this
3283 * notification is passed to the upper layer.
3285 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3286 0, 0, 0, NULL
, GFP_ATOMIC
);
3290 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3291 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3295 /* Do all the commands now (after allocation), so that we
3296 * have consistent state if memory allocation failes
3298 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3300 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3301 * stop the T2-shutdown timer,
3303 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3304 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3306 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3307 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3309 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3310 SCTP_STATE(SCTP_STATE_CLOSED
));
3311 net
= sock_net(asoc
->base
.sk
);
3312 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3313 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3314 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3316 /* ...and remove all record of the association. */
3317 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3318 return SCTP_DISPOSITION_DELETE_TCB
;
3321 sctp_ulpevent_free(ev
);
3323 return SCTP_DISPOSITION_NOMEM
;
3327 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3329 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3330 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3331 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3332 * packet must fill in the Verification Tag field of the outbound
3333 * packet with the Verification Tag received in the SHUTDOWN ACK and
3334 * set the T-bit in the Chunk Flags to indicate that the Verification
3337 * 8) The receiver should respond to the sender of the OOTB packet with
3338 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3339 * MUST fill in the Verification Tag field of the outbound packet
3340 * with the value found in the Verification Tag field of the OOTB
3341 * packet and set the T-bit in the Chunk Flags to indicate that the
3342 * Verification Tag is reflected. After sending this ABORT, the
3343 * receiver of the OOTB packet shall discard the OOTB packet and take
3344 * no further action.
3346 sctp_disposition_t
sctp_sf_ootb(const struct sctp_endpoint
*ep
,
3347 const struct sctp_association
*asoc
,
3348 const sctp_subtype_t type
,
3350 sctp_cmd_seq_t
*commands
)
3352 struct sctp_chunk
*chunk
= arg
;
3353 struct sk_buff
*skb
= chunk
->skb
;
3354 sctp_chunkhdr_t
*ch
;
3357 int ootb_shut_ack
= 0;
3358 int ootb_cookie_ack
= 0;
3361 net
= sock_net(asoc
->base
.sk
);
3362 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3364 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3366 /* Report violation if the chunk is less then minimal */
3367 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3368 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3371 /* Now that we know we at least have a chunk header,
3372 * do things that are type appropriate.
3374 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3377 /* RFC 2960, Section 3.3.7
3378 * Moreover, under any circumstances, an endpoint that
3379 * receives an ABORT MUST NOT respond to that ABORT by
3380 * sending an ABORT of its own.
3382 if (SCTP_CID_ABORT
== ch
->type
)
3383 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3385 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3386 * or a COOKIE ACK the SCTP Packet should be silently
3390 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3391 ootb_cookie_ack
= 1;
3393 if (SCTP_CID_ERROR
== ch
->type
) {
3394 sctp_walk_errors(err
, ch
) {
3395 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3396 ootb_cookie_ack
= 1;
3402 /* Report violation if chunk len overflows */
3403 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3404 if (ch_end
> skb_tail_pointer(skb
))
3405 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3408 ch
= (sctp_chunkhdr_t
*) ch_end
;
3409 } while (ch_end
< skb_tail_pointer(skb
));
3412 return sctp_sf_shut_8_4_5(ep
, asoc
, type
, arg
, commands
);
3413 else if (ootb_cookie_ack
)
3414 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3416 return sctp_sf_tabort_8_4_8(ep
, asoc
, type
, arg
, commands
);
3420 * Handle an "Out of the blue" SHUTDOWN ACK.
3422 * Section: 8.4 5, sctpimpguide 2.41.
3424 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3425 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3426 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3427 * packet must fill in the Verification Tag field of the outbound
3428 * packet with the Verification Tag received in the SHUTDOWN ACK and
3429 * set the T-bit in the Chunk Flags to indicate that the Verification
3433 * (endpoint, asoc, type, arg, commands)
3436 * (sctp_disposition_t)
3438 * The return value is the disposition of the chunk.
3440 static sctp_disposition_t
sctp_sf_shut_8_4_5(const struct sctp_endpoint
*ep
,
3441 const struct sctp_association
*asoc
,
3442 const sctp_subtype_t type
,
3444 sctp_cmd_seq_t
*commands
)
3446 struct sctp_packet
*packet
= NULL
;
3447 struct sctp_chunk
*chunk
= arg
;
3448 struct sctp_chunk
*shut
;
3451 net
= sock_net(ep
->base
.sk
);
3452 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3455 /* Make an SHUTDOWN_COMPLETE.
3456 * The T bit will be set if the asoc is NULL.
3458 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3460 sctp_ootb_pkt_free(packet
);
3461 return SCTP_DISPOSITION_NOMEM
;
3464 /* Reflect vtag if T-Bit is set */
3465 if (sctp_test_T_bit(shut
))
3466 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3468 /* Set the skb to the belonging sock for accounting. */
3469 shut
->skb
->sk
= ep
->base
.sk
;
3471 sctp_packet_append_chunk(packet
, shut
);
3473 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3474 SCTP_PACKET(packet
));
3476 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3478 /* If the chunk length is invalid, we don't want to process
3479 * the reset of the packet.
3481 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3482 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3484 /* We need to discard the rest of the packet to prevent
3485 * potential bomming attacks from additional bundled chunks.
3486 * This is documented in SCTP Threats ID.
3488 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3491 return SCTP_DISPOSITION_NOMEM
;
3495 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3497 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3498 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3499 * procedures in section 8.4 SHOULD be followed, in other words it
3500 * should be treated as an Out Of The Blue packet.
3501 * [This means that we do NOT check the Verification Tag on these
3505 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(const struct sctp_endpoint
*ep
,
3506 const struct sctp_association
*asoc
,
3507 const sctp_subtype_t type
,
3509 sctp_cmd_seq_t
*commands
)
3511 struct sctp_chunk
*chunk
= arg
;
3513 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3514 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3515 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3518 /* Although we do have an association in this case, it corresponds
3519 * to a restarted association. So the packet is treated as an OOTB
3520 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3521 * called with a NULL association.
3523 SCTP_INC_STATS(sock_net(ep
->base
.sk
), SCTP_MIB_OUTOFBLUES
);
3525 return sctp_sf_shut_8_4_5(ep
, NULL
, type
, arg
, commands
);
3528 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3529 sctp_disposition_t
sctp_sf_do_asconf(const struct sctp_endpoint
*ep
,
3530 const struct sctp_association
*asoc
,
3531 const sctp_subtype_t type
, void *arg
,
3532 sctp_cmd_seq_t
*commands
)
3534 struct sctp_chunk
*chunk
= arg
;
3535 struct sctp_chunk
*asconf_ack
= NULL
;
3536 struct sctp_paramhdr
*err_param
= NULL
;
3537 sctp_addiphdr_t
*hdr
;
3538 union sctp_addr_param
*addr_param
;
3542 if (!sctp_vtag_verify(chunk
, asoc
)) {
3543 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3545 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3548 /* ADD-IP: Section 4.1.1
3549 * This chunk MUST be sent in an authenticated way by using
3550 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3551 * is received unauthenticated it MUST be silently discarded as
3552 * described in [I-D.ietf-tsvwg-sctp-auth].
3554 if (!sctp_addip_noauth
&& !chunk
->auth
)
3555 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3557 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3558 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3559 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3562 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3563 serial
= ntohl(hdr
->serial
);
3565 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3566 length
= ntohs(addr_param
->p
.length
);
3567 if (length
< sizeof(sctp_paramhdr_t
))
3568 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3569 (void *)addr_param
, commands
);
3571 /* Verify the ASCONF chunk before processing it. */
3572 if (!sctp_verify_asconf(asoc
,
3573 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3574 (void *)chunk
->chunk_end
,
3576 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3577 (void *)err_param
, commands
);
3579 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3580 * the endpoint stored in a new association variable
3581 * 'Peer-Serial-Number'.
3583 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3584 /* If this is the first instance of ASCONF in the packet,
3585 * we can clean our old ASCONF-ACKs.
3587 if (!chunk
->has_asconf
)
3588 sctp_assoc_clean_asconf_ack_cache(asoc
);
3590 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3591 * expected, process the ASCONF as described below and after
3592 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3593 * the response packet and cache a copy of it (in the event it
3594 * later needs to be retransmitted).
3596 * Essentially, do V1-V5.
3598 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3601 return SCTP_DISPOSITION_NOMEM
;
3602 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3604 * If the value found in the Sequence Number is less than the
3605 * ('Peer- Sequence-Number' + 1), simply skip to the next
3606 * ASCONF, and include in the outbound response packet
3607 * any previously cached ASCONF-ACK response that was
3608 * sent and saved that matches the Sequence Number of the
3609 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3610 * Chunk exists. This will occur when an older ASCONF
3611 * arrives out of order. In such a case, the receiver
3612 * should skip the ASCONF Chunk and not include ASCONF-ACK
3613 * Chunk for that chunk.
3615 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3617 return SCTP_DISPOSITION_DISCARD
;
3619 /* Reset the transport so that we select the correct one
3620 * this time around. This is to make sure that we don't
3621 * accidentally use a stale transport that's been removed.
3623 asconf_ack
->transport
= NULL
;
3625 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3626 * it must be either a stale packet or from an attacker.
3628 return SCTP_DISPOSITION_DISCARD
;
3631 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3632 * containing the ASCONF-ACK Chunks MUST be the source address of
3633 * the SCTP packet that held the ASCONF Chunks.
3635 * To do this properly, we'll set the destination address of the chunk
3636 * and at the transmit time, will try look up the transport to use.
3637 * Since ASCONFs may be bundled, the correct transport may not be
3638 * created until we process the entire packet, thus this workaround.
3640 asconf_ack
->dest
= chunk
->source
;
3641 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3642 if (asoc
->new_transport
) {
3643 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
,
3645 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3648 return SCTP_DISPOSITION_CONSUME
;
3652 * ADDIP Section 4.3 General rules for address manipulation
3653 * When building TLV parameters for the ASCONF Chunk that will add or
3654 * delete IP addresses the D0 to D13 rules should be applied:
3656 sctp_disposition_t
sctp_sf_do_asconf_ack(const struct sctp_endpoint
*ep
,
3657 const struct sctp_association
*asoc
,
3658 const sctp_subtype_t type
, void *arg
,
3659 sctp_cmd_seq_t
*commands
)
3661 struct sctp_chunk
*asconf_ack
= arg
;
3662 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3663 struct sctp_chunk
*abort
;
3664 struct sctp_paramhdr
*err_param
= NULL
;
3665 sctp_addiphdr_t
*addip_hdr
;
3666 __u32 sent_serial
, rcvd_serial
;
3668 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3669 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3671 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3674 /* ADD-IP, Section 4.1.2:
3675 * This chunk MUST be sent in an authenticated way by using
3676 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3677 * is received unauthenticated it MUST be silently discarded as
3678 * described in [I-D.ietf-tsvwg-sctp-auth].
3680 if (!sctp_addip_noauth
&& !asconf_ack
->auth
)
3681 return sctp_sf_discard_chunk(ep
, asoc
, type
, arg
, commands
);
3683 /* Make sure that the ADDIP chunk has a valid length. */
3684 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3685 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3688 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3689 rcvd_serial
= ntohl(addip_hdr
->serial
);
3691 /* Verify the ASCONF-ACK chunk before processing it. */
3692 if (!sctp_verify_asconf(asoc
,
3693 (sctp_paramhdr_t
*)addip_hdr
->params
,
3694 (void *)asconf_ack
->chunk_end
,
3696 return sctp_sf_violation_paramlen(ep
, asoc
, type
, arg
,
3697 (void *)err_param
, commands
);
3700 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3701 sent_serial
= ntohl(addip_hdr
->serial
);
3703 sent_serial
= asoc
->addip_serial
- 1;
3706 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3707 * equal to the next serial number to be used but no ASCONF chunk is
3708 * outstanding the endpoint MUST ABORT the association. Note that a
3709 * sequence number is greater than if it is no more than 2^^31-1
3710 * larger than the current sequence number (using serial arithmetic).
3712 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3713 !(asoc
->addip_last_asconf
)) {
3715 abort
= sctp_make_abort(asoc
, asconf_ack
,
3716 sizeof(sctp_errhdr_t
));
3718 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3719 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3722 /* We are going to ABORT, so we might as well stop
3723 * processing the rest of the chunks in the packet.
3725 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3726 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3727 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3728 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3729 SCTP_ERROR(ECONNABORTED
));
3730 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3731 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3732 net
= sock_net(asoc
->base
.sk
);
3733 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3734 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3735 return SCTP_DISPOSITION_ABORT
;
3738 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3740 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3741 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3743 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3745 /* Successfully processed ASCONF_ACK. We can
3746 * release the next asconf if we have one.
3748 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3750 return SCTP_DISPOSITION_CONSUME
;
3753 abort
= sctp_make_abort(asoc
, asconf_ack
,
3754 sizeof(sctp_errhdr_t
));
3756 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3757 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3760 /* We are going to ABORT, so we might as well stop
3761 * processing the rest of the chunks in the packet.
3763 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3764 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3765 SCTP_ERROR(ECONNABORTED
));
3766 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3767 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3768 net
= sock_net(asoc
->base
.sk
);
3769 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3770 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3771 return SCTP_DISPOSITION_ABORT
;
3774 return SCTP_DISPOSITION_DISCARD
;
3778 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3780 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3781 * its cumulative TSN point to the value carried in the FORWARD TSN
3782 * chunk, and then MUST further advance its cumulative TSN point locally
3784 * After the above processing, the data receiver MUST stop reporting any
3785 * missing TSNs earlier than or equal to the new cumulative TSN point.
3787 * Verification Tag: 8.5 Verification Tag [Normal verification]
3789 * The return value is the disposition of the chunk.
3791 sctp_disposition_t
sctp_sf_eat_fwd_tsn(const struct sctp_endpoint
*ep
,
3792 const struct sctp_association
*asoc
,
3793 const sctp_subtype_t type
,
3795 sctp_cmd_seq_t
*commands
)
3797 struct sctp_chunk
*chunk
= arg
;
3798 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3799 struct sctp_fwdtsn_skip
*skip
;
3803 if (!sctp_vtag_verify(chunk
, asoc
)) {
3804 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3806 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3809 /* Make sure that the FORWARD_TSN chunk has valid length. */
3810 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3811 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3814 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3815 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3816 len
= ntohs(chunk
->chunk_hdr
->length
);
3817 len
-= sizeof(struct sctp_chunkhdr
);
3818 skb_pull(chunk
->skb
, len
);
3820 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3821 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3823 /* The TSN is too high--silently discard the chunk and count on it
3824 * getting retransmitted later.
3826 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3827 goto discard_noforce
;
3829 /* Silently discard the chunk if stream-id is not valid */
3830 sctp_walk_fwdtsn(skip
, chunk
) {
3831 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3832 goto discard_noforce
;
3835 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3836 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3837 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3840 /* Count this as receiving DATA. */
3841 if (asoc
->autoclose
) {
3842 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3843 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3846 /* FIXME: For now send a SACK, but DATA processing may
3849 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3851 return SCTP_DISPOSITION_CONSUME
;
3854 return SCTP_DISPOSITION_DISCARD
;
3857 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3858 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_chunk
*chunk
= arg
;
3865 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3866 struct sctp_fwdtsn_skip
*skip
;
3870 if (!sctp_vtag_verify(chunk
, asoc
)) {
3871 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3873 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
3876 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3877 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3878 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
3881 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3882 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3883 len
= ntohs(chunk
->chunk_hdr
->length
);
3884 len
-= sizeof(struct sctp_chunkhdr
);
3885 skb_pull(chunk
->skb
, len
);
3887 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3888 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3890 /* The TSN is too high--silently discard the chunk and count on it
3891 * getting retransmitted later.
3893 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3896 /* Silently discard the chunk if stream-id is not valid */
3897 sctp_walk_fwdtsn(skip
, chunk
) {
3898 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3902 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3903 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3904 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3907 /* Go a head and force a SACK, since we are shutting down. */
3909 /* Implementor's Guide.
3911 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3912 * respond to each received packet containing one or more DATA chunk(s)
3913 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3915 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3916 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3917 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3918 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3920 return SCTP_DISPOSITION_CONSUME
;
3924 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
3926 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3927 * Identifier field. If this algorithm was not specified by the
3928 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3929 * during association setup, the AUTH chunk and all chunks after it MUST
3930 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3931 * defined in Section 4.1.
3933 * If an endpoint with no shared key receives a Shared Key Identifier
3934 * other than 0, it MUST silently discard all authenticated chunks. If
3935 * the endpoint has at least one endpoint pair shared key for the peer,
3936 * it MUST use the key specified by the Shared Key Identifier if a
3937 * key has been configured for that Shared Key Identifier. If no
3938 * endpoint pair shared key has been configured for that Shared Key
3939 * Identifier, all authenticated chunks MUST be silently discarded.
3941 * Verification Tag: 8.5 Verification Tag [Normal verification]
3943 * The return value is the disposition of the chunk.
3945 static sctp_ierror_t
sctp_sf_authenticate(const struct sctp_endpoint
*ep
,
3946 const struct sctp_association
*asoc
,
3947 const sctp_subtype_t type
,
3948 struct sctp_chunk
*chunk
)
3950 struct sctp_authhdr
*auth_hdr
;
3951 struct sctp_hmac
*hmac
;
3952 unsigned int sig_len
;
3957 /* Pull in the auth header, so we can do some more verification */
3958 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3959 chunk
->subh
.auth_hdr
= auth_hdr
;
3960 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
3962 /* Make sure that we suport the HMAC algorithm from the auth
3965 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
3966 return SCTP_IERROR_AUTH_BAD_HMAC
;
3968 /* Make sure that the provided shared key identifier has been
3971 key_id
= ntohs(auth_hdr
->shkey_id
);
3972 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
3973 return SCTP_IERROR_AUTH_BAD_KEYID
;
3976 /* Make sure that the length of the signature matches what
3979 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
3980 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
3981 if (sig_len
!= hmac
->hmac_len
)
3982 return SCTP_IERROR_PROTO_VIOLATION
;
3984 /* Now that we've done validation checks, we can compute and
3985 * verify the hmac. The steps involved are:
3986 * 1. Save the digest from the chunk.
3987 * 2. Zero out the digest in the chunk.
3988 * 3. Compute the new digest
3989 * 4. Compare saved and new digests.
3991 digest
= auth_hdr
->hmac
;
3992 skb_pull(chunk
->skb
, sig_len
);
3994 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
3998 memset(digest
, 0, sig_len
);
4000 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4001 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4004 /* Discard the packet if the digests do not match */
4005 if (memcmp(save_digest
, digest
, sig_len
)) {
4007 return SCTP_IERROR_BAD_SIG
;
4013 return SCTP_IERROR_NO_ERROR
;
4015 return SCTP_IERROR_NOMEM
;
4018 sctp_disposition_t
sctp_sf_eat_auth(const struct sctp_endpoint
*ep
,
4019 const struct sctp_association
*asoc
,
4020 const sctp_subtype_t type
,
4022 sctp_cmd_seq_t
*commands
)
4024 struct sctp_authhdr
*auth_hdr
;
4025 struct sctp_chunk
*chunk
= arg
;
4026 struct sctp_chunk
*err_chunk
;
4027 sctp_ierror_t error
;
4029 /* Make sure that the peer has AUTH capable */
4030 if (!asoc
->peer
.auth_capable
)
4031 return sctp_sf_unk_chunk(ep
, asoc
, type
, arg
, commands
);
4033 if (!sctp_vtag_verify(chunk
, asoc
)) {
4034 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4036 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4039 /* Make sure that the AUTH chunk has valid length. */
4040 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4041 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4044 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4045 error
= sctp_sf_authenticate(ep
, asoc
, type
, chunk
);
4047 case SCTP_IERROR_AUTH_BAD_HMAC
:
4048 /* Generate the ERROR chunk and discard the rest
4051 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4052 SCTP_ERROR_UNSUP_HMAC
,
4056 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4057 SCTP_CHUNK(err_chunk
));
4060 case SCTP_IERROR_AUTH_BAD_KEYID
:
4061 case SCTP_IERROR_BAD_SIG
:
4062 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4064 case SCTP_IERROR_PROTO_VIOLATION
:
4065 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4068 case SCTP_IERROR_NOMEM
:
4069 return SCTP_DISPOSITION_NOMEM
;
4071 default: /* Prevent gcc warnings */
4075 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4076 struct sctp_ulpevent
*ev
;
4078 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4079 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4084 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4088 return SCTP_DISPOSITION_CONSUME
;
4092 * Process an unknown chunk.
4094 * Section: 3.2. Also, 2.1 in the implementor's guide.
4096 * Chunk Types are encoded such that the highest-order two bits specify
4097 * the action that must be taken if the processing endpoint does not
4098 * recognize the Chunk Type.
4100 * 00 - Stop processing this SCTP packet and discard it, do not process
4101 * any further chunks within it.
4103 * 01 - Stop processing this SCTP packet and discard it, do not process
4104 * any further chunks within it, and report the unrecognized
4105 * chunk in an 'Unrecognized Chunk Type'.
4107 * 10 - Skip this chunk and continue processing.
4109 * 11 - Skip this chunk and continue processing, but report in an ERROR
4110 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4112 * The return value is the disposition of the chunk.
4114 sctp_disposition_t
sctp_sf_unk_chunk(const struct sctp_endpoint
*ep
,
4115 const struct sctp_association
*asoc
,
4116 const sctp_subtype_t type
,
4118 sctp_cmd_seq_t
*commands
)
4120 struct sctp_chunk
*unk_chunk
= arg
;
4121 struct sctp_chunk
*err_chunk
;
4122 sctp_chunkhdr_t
*hdr
;
4124 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
4126 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4127 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4129 /* Make sure that the chunk has a valid length.
4130 * Since we don't know the chunk type, we use a general
4131 * chunkhdr structure to make a comparison.
4133 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4134 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4137 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4138 case SCTP_CID_ACTION_DISCARD
:
4139 /* Discard the packet. */
4140 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4142 case SCTP_CID_ACTION_DISCARD_ERR
:
4143 /* Generate an ERROR chunk as response. */
4144 hdr
= unk_chunk
->chunk_hdr
;
4145 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4146 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4147 WORD_ROUND(ntohs(hdr
->length
)),
4150 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4151 SCTP_CHUNK(err_chunk
));
4154 /* Discard the packet. */
4155 sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
4156 return SCTP_DISPOSITION_CONSUME
;
4158 case SCTP_CID_ACTION_SKIP
:
4159 /* Skip the chunk. */
4160 return SCTP_DISPOSITION_DISCARD
;
4162 case SCTP_CID_ACTION_SKIP_ERR
:
4163 /* Generate an ERROR chunk as response. */
4164 hdr
= unk_chunk
->chunk_hdr
;
4165 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4166 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4167 WORD_ROUND(ntohs(hdr
->length
)),
4170 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4171 SCTP_CHUNK(err_chunk
));
4173 /* Skip the chunk. */
4174 return SCTP_DISPOSITION_CONSUME
;
4180 return SCTP_DISPOSITION_DISCARD
;
4184 * Discard the chunk.
4186 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4187 * [Too numerous to mention...]
4188 * Verification Tag: No verification needed.
4190 * (endpoint, asoc, chunk)
4193 * (asoc, reply_msg, msg_up, timers, counters)
4195 * The return value is the disposition of the chunk.
4197 sctp_disposition_t
sctp_sf_discard_chunk(const struct sctp_endpoint
*ep
,
4198 const struct sctp_association
*asoc
,
4199 const sctp_subtype_t type
,
4201 sctp_cmd_seq_t
*commands
)
4203 struct sctp_chunk
*chunk
= arg
;
4205 /* Make sure that the chunk has a valid length.
4206 * Since we don't know the chunk type, we use a general
4207 * chunkhdr structure to make a comparison.
4209 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4210 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4213 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
4214 return SCTP_DISPOSITION_DISCARD
;
4218 * Discard the whole packet.
4222 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4223 * silently discard the OOTB packet and take no further action.
4225 * Verification Tag: No verification necessary
4228 * (endpoint, asoc, chunk)
4231 * (asoc, reply_msg, msg_up, timers, counters)
4233 * The return value is the disposition of the chunk.
4235 sctp_disposition_t
sctp_sf_pdiscard(const struct sctp_endpoint
*ep
,
4236 const struct sctp_association
*asoc
,
4237 const sctp_subtype_t type
,
4239 sctp_cmd_seq_t
*commands
)
4241 SCTP_INC_STATS(sock_net(asoc
->base
.sk
), SCTP_MIB_IN_PKT_DISCARDS
);
4242 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4244 return SCTP_DISPOSITION_CONSUME
;
4249 * The other end is violating protocol.
4251 * Section: Not specified
4252 * Verification Tag: Not specified
4254 * (endpoint, asoc, chunk)
4257 * (asoc, reply_msg, msg_up, timers, counters)
4259 * We simply tag the chunk as a violation. The state machine will log
4260 * the violation and continue.
4262 sctp_disposition_t
sctp_sf_violation(const struct sctp_endpoint
*ep
,
4263 const struct sctp_association
*asoc
,
4264 const sctp_subtype_t type
,
4266 sctp_cmd_seq_t
*commands
)
4268 struct sctp_chunk
*chunk
= arg
;
4270 /* Make sure that the chunk has a valid length. */
4271 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4272 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
4275 return SCTP_DISPOSITION_VIOLATION
;
4279 * Common function to handle a protocol violation.
4281 static sctp_disposition_t
sctp_sf_abort_violation(
4282 const struct sctp_endpoint
*ep
,
4283 const struct sctp_association
*asoc
,
4285 sctp_cmd_seq_t
*commands
,
4286 const __u8
*payload
,
4287 const size_t paylen
)
4289 struct sctp_packet
*packet
= NULL
;
4290 struct sctp_chunk
*chunk
= arg
;
4291 struct sctp_chunk
*abort
= NULL
;
4294 /* SCTP-AUTH, Section 6.3:
4295 * It should be noted that if the receiver wants to tear
4296 * down an association in an authenticated way only, the
4297 * handling of malformed packets should not result in
4298 * tearing down the association.
4300 * This means that if we only want to abort associations
4301 * in an authenticated way (i.e AUTH+ABORT), then we
4302 * can't destroy this association just because the packet
4305 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4308 /* Make the abort chunk. */
4309 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4313 net
= sock_net(ep
->base
.sk
);
4315 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4316 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4317 !asoc
->peer
.i
.init_tag
) {
4318 sctp_initack_chunk_t
*initack
;
4320 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4321 if (!sctp_chunk_length_valid(chunk
,
4322 sizeof(sctp_initack_chunk_t
)))
4323 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4325 unsigned int inittag
;
4327 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4328 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4333 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4334 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4336 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4337 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4338 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4339 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4340 SCTP_ERROR(ECONNREFUSED
));
4341 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4342 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4344 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4345 SCTP_ERROR(ECONNABORTED
));
4346 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4347 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4348 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4351 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4356 if (sctp_test_T_bit(abort
))
4357 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4359 abort
->skb
->sk
= ep
->base
.sk
;
4361 sctp_packet_append_chunk(packet
, abort
);
4363 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4364 SCTP_PACKET(packet
));
4366 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4369 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4372 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4373 return SCTP_DISPOSITION_ABORT
;
4376 sctp_chunk_free(abort
);
4378 return SCTP_DISPOSITION_NOMEM
;
4382 * Handle a protocol violation when the chunk length is invalid.
4383 * "Invalid" length is identified as smaller than the minimal length a
4384 * given chunk can be. For example, a SACK chunk has invalid length
4385 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4387 * We inform the other end by sending an ABORT with a Protocol Violation
4390 * Section: Not specified
4391 * Verification Tag: Nothing to do
4393 * (endpoint, asoc, chunk)
4396 * (reply_msg, msg_up, counters)
4398 * Generate an ABORT chunk and terminate the association.
4400 static sctp_disposition_t
sctp_sf_violation_chunklen(
4401 const struct sctp_endpoint
*ep
,
4402 const struct sctp_association
*asoc
,
4403 const sctp_subtype_t type
,
4405 sctp_cmd_seq_t
*commands
)
4407 static const char err_str
[]="The following chunk had invalid length:";
4409 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4414 * Handle a protocol violation when the parameter length is invalid.
4415 * If the length is smaller than the minimum length of a given parameter,
4416 * or accumulated length in multi parameters exceeds the end of the chunk,
4417 * the length is considered as invalid.
4419 static sctp_disposition_t
sctp_sf_violation_paramlen(
4420 const struct sctp_endpoint
*ep
,
4421 const struct sctp_association
*asoc
,
4422 const sctp_subtype_t type
,
4423 void *arg
, void *ext
,
4424 sctp_cmd_seq_t
*commands
)
4426 struct sctp_chunk
*chunk
= arg
;
4427 struct sctp_paramhdr
*param
= ext
;
4428 struct sctp_chunk
*abort
= NULL
;
4431 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4434 /* Make the abort chunk. */
4435 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4439 net
= sock_net(asoc
->base
.sk
);
4440 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4441 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4443 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4444 SCTP_ERROR(ECONNABORTED
));
4445 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4446 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4447 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4448 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4451 sctp_sf_pdiscard(ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4452 return SCTP_DISPOSITION_ABORT
;
4454 return SCTP_DISPOSITION_NOMEM
;
4457 /* Handle a protocol violation when the peer trying to advance the
4458 * cumulative tsn ack to a point beyond the max tsn currently sent.
4460 * We inform the other end by sending an ABORT with a Protocol Violation
4463 static sctp_disposition_t
sctp_sf_violation_ctsn(
4464 const struct sctp_endpoint
*ep
,
4465 const struct sctp_association
*asoc
,
4466 const sctp_subtype_t type
,
4468 sctp_cmd_seq_t
*commands
)
4470 static const char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4472 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4476 /* Handle protocol violation of an invalid chunk bundling. For example,
4477 * when we have an association and we receive bundled INIT-ACK, or
4478 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4479 * statement from the specs. Additionally, there might be an attacker
4480 * on the path and we may not want to continue this communication.
4482 static sctp_disposition_t
sctp_sf_violation_chunk(
4483 const struct sctp_endpoint
*ep
,
4484 const struct sctp_association
*asoc
,
4485 const sctp_subtype_t type
,
4487 sctp_cmd_seq_t
*commands
)
4489 static const char err_str
[]="The following chunk violates protocol:";
4492 return sctp_sf_violation(ep
, asoc
, type
, arg
, commands
);
4494 return sctp_sf_abort_violation(ep
, asoc
, arg
, commands
, err_str
,
4497 /***************************************************************************
4498 * These are the state functions for handling primitive (Section 10) events.
4499 ***************************************************************************/
4501 * sctp_sf_do_prm_asoc
4503 * Section: 10.1 ULP-to-SCTP
4506 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4507 * outbound stream count)
4508 * -> association id [,destination transport addr list] [,outbound stream
4511 * This primitive allows the upper layer to initiate an association to a
4512 * specific peer endpoint.
4514 * The peer endpoint shall be specified by one of the transport addresses
4515 * which defines the endpoint (see Section 1.4). If the local SCTP
4516 * instance has not been initialized, the ASSOCIATE is considered an
4518 * [This is not relevant for the kernel implementation since we do all
4519 * initialization at boot time. It we hadn't initialized we wouldn't
4520 * get anywhere near this code.]
4522 * An association id, which is a local handle to the SCTP association,
4523 * will be returned on successful establishment of the association. If
4524 * SCTP is not able to open an SCTP association with the peer endpoint,
4525 * an error is returned.
4526 * [In the kernel implementation, the struct sctp_association needs to
4527 * be created BEFORE causing this primitive to run.]
4529 * Other association parameters may be returned, including the
4530 * complete destination transport addresses of the peer as well as the
4531 * outbound stream count of the local endpoint. One of the transport
4532 * address from the returned destination addresses will be selected by
4533 * the local endpoint as default primary path for sending SCTP packets
4534 * to this peer. The returned "destination transport addr list" can
4535 * be used by the ULP to change the default primary path or to force
4536 * sending a packet to a specific transport address. [All of this
4537 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4540 * Mandatory attributes:
4542 * o local SCTP instance name - obtained from the INITIALIZE operation.
4543 * [This is the argument asoc.]
4544 * o destination transport addr - specified as one of the transport
4545 * addresses of the peer endpoint with which the association is to be
4547 * [This is asoc->peer.active_path.]
4548 * o outbound stream count - the number of outbound streams the ULP
4549 * would like to open towards this peer endpoint.
4550 * [BUG: This is not currently implemented.]
4551 * Optional attributes:
4555 * The return value is a disposition.
4557 sctp_disposition_t
sctp_sf_do_prm_asoc(const struct sctp_endpoint
*ep
,
4558 const struct sctp_association
*asoc
,
4559 const sctp_subtype_t type
,
4561 sctp_cmd_seq_t
*commands
)
4563 struct sctp_chunk
*repl
;
4564 struct sctp_association
* my_asoc
;
4566 /* The comment below says that we enter COOKIE-WAIT AFTER
4567 * sending the INIT, but that doesn't actually work in our
4570 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4571 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4573 /* RFC 2960 5.1 Normal Establishment of an Association
4575 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4576 * must provide its Verification Tag (Tag_A) in the Initiate
4577 * Tag field. Tag_A SHOULD be a random number in the range of
4578 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4581 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4585 /* Cast away the const modifier, as we want to just
4586 * rerun it through as a sideffect.
4588 my_asoc
= (struct sctp_association
*)asoc
;
4589 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4591 /* Choose transport for INIT. */
4592 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4595 /* After sending the INIT, "A" starts the T1-init timer and
4596 * enters the COOKIE-WAIT state.
4598 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4599 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4600 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4601 return SCTP_DISPOSITION_CONSUME
;
4604 return SCTP_DISPOSITION_NOMEM
;
4608 * Process the SEND primitive.
4610 * Section: 10.1 ULP-to-SCTP
4613 * Format: SEND(association id, buffer address, byte count [,context]
4614 * [,stream id] [,life time] [,destination transport address]
4615 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4618 * This is the main method to send user data via SCTP.
4620 * Mandatory attributes:
4622 * o association id - local handle to the SCTP association
4624 * o buffer address - the location where the user message to be
4625 * transmitted is stored;
4627 * o byte count - The size of the user data in number of bytes;
4629 * Optional attributes:
4631 * o context - an optional 32 bit integer that will be carried in the
4632 * sending failure notification to the ULP if the transportation of
4633 * this User Message fails.
4635 * o stream id - to indicate which stream to send the data on. If not
4636 * specified, stream 0 will be used.
4638 * o life time - specifies the life time of the user data. The user data
4639 * will not be sent by SCTP after the life time expires. This
4640 * parameter can be used to avoid efforts to transmit stale
4641 * user messages. SCTP notifies the ULP if the data cannot be
4642 * initiated to transport (i.e. sent to the destination via SCTP's
4643 * send primitive) within the life time variable. However, the
4644 * user data will be transmitted if SCTP has attempted to transmit a
4645 * chunk before the life time expired.
4647 * o destination transport address - specified as one of the destination
4648 * transport addresses of the peer endpoint to which this packet
4649 * should be sent. Whenever possible, SCTP should use this destination
4650 * transport address for sending the packets, instead of the current
4653 * o unorder flag - this flag, if present, indicates that the user
4654 * would like the data delivered in an unordered fashion to the peer
4655 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4658 * o no-bundle flag - instructs SCTP not to bundle this user data with
4659 * other outbound DATA chunks. SCTP MAY still bundle even when
4660 * this flag is present, when faced with network congestion.
4662 * o payload protocol-id - A 32 bit unsigned integer that is to be
4663 * passed to the peer indicating the type of payload protocol data
4664 * being transmitted. This value is passed as opaque data by SCTP.
4666 * The return value is the disposition.
4668 sctp_disposition_t
sctp_sf_do_prm_send(const struct sctp_endpoint
*ep
,
4669 const struct sctp_association
*asoc
,
4670 const sctp_subtype_t type
,
4672 sctp_cmd_seq_t
*commands
)
4674 struct sctp_datamsg
*msg
= arg
;
4676 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4677 return SCTP_DISPOSITION_CONSUME
;
4681 * Process the SHUTDOWN primitive.
4686 * Format: SHUTDOWN(association id)
4689 * Gracefully closes an association. Any locally queued user data
4690 * will be delivered to the peer. The association will be terminated only
4691 * after the peer acknowledges all the SCTP packets sent. A success code
4692 * will be returned on successful termination of the association. If
4693 * attempting to terminate the association results in a failure, an error
4694 * code shall be returned.
4696 * Mandatory attributes:
4698 * o association id - local handle to the SCTP association
4700 * Optional attributes:
4704 * The return value is the disposition.
4706 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4707 const struct sctp_endpoint
*ep
,
4708 const struct sctp_association
*asoc
,
4709 const sctp_subtype_t type
,
4711 sctp_cmd_seq_t
*commands
)
4715 /* From 9.2 Shutdown of an Association
4716 * Upon receipt of the SHUTDOWN primitive from its upper
4717 * layer, the endpoint enters SHUTDOWN-PENDING state and
4718 * remains there until all outstanding data has been
4719 * acknowledged by its peer. The endpoint accepts no new data
4720 * from its upper layer, but retransmits data to the far end
4721 * if necessary to fill gaps.
4723 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4724 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4726 disposition
= SCTP_DISPOSITION_CONSUME
;
4727 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4728 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
4735 * Process the ABORT primitive.
4740 * Format: Abort(association id [, cause code])
4743 * Ungracefully closes an association. Any locally queued user data
4744 * will be discarded and an ABORT chunk is sent to the peer. A success code
4745 * will be returned on successful abortion of the association. If
4746 * attempting to abort the association results in a failure, an error
4747 * code shall be returned.
4749 * Mandatory attributes:
4751 * o association id - local handle to the SCTP association
4753 * Optional attributes:
4755 * o cause code - reason of the abort to be passed to the peer
4759 * The return value is the disposition.
4761 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4762 const struct sctp_endpoint
*ep
,
4763 const struct sctp_association
*asoc
,
4764 const sctp_subtype_t type
,
4766 sctp_cmd_seq_t
*commands
)
4768 /* From 9.1 Abort of an Association
4769 * Upon receipt of the ABORT primitive from its upper
4770 * layer, the endpoint enters CLOSED state and
4771 * discard all outstanding data has been
4772 * acknowledged by its peer. The endpoint accepts no new data
4773 * from its upper layer, but retransmits data to the far end
4774 * if necessary to fill gaps.
4776 struct sctp_chunk
*abort
= arg
;
4777 sctp_disposition_t retval
;
4780 retval
= SCTP_DISPOSITION_CONSUME
;
4782 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4784 /* Even if we can't send the ABORT due to low memory delete the
4785 * TCB. This is a departure from our typical NOMEM handling.
4788 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4789 SCTP_ERROR(ECONNABORTED
));
4790 /* Delete the established association. */
4791 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4792 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4794 net
= sock_net(asoc
->base
.sk
);
4795 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4796 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4801 /* We tried an illegal operation on an association which is closed. */
4802 sctp_disposition_t
sctp_sf_error_closed(const struct sctp_endpoint
*ep
,
4803 const struct sctp_association
*asoc
,
4804 const sctp_subtype_t type
,
4806 sctp_cmd_seq_t
*commands
)
4808 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4809 return SCTP_DISPOSITION_CONSUME
;
4812 /* We tried an illegal operation on an association which is shutting
4815 sctp_disposition_t
sctp_sf_error_shutdown(const struct sctp_endpoint
*ep
,
4816 const struct sctp_association
*asoc
,
4817 const sctp_subtype_t type
,
4819 sctp_cmd_seq_t
*commands
)
4821 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4822 SCTP_ERROR(-ESHUTDOWN
));
4823 return SCTP_DISPOSITION_CONSUME
;
4827 * sctp_cookie_wait_prm_shutdown
4829 * Section: 4 Note: 2
4834 * The RFC does not explicitly address this issue, but is the route through the
4835 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4840 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4841 const struct sctp_endpoint
*ep
,
4842 const struct sctp_association
*asoc
,
4843 const sctp_subtype_t type
,
4845 sctp_cmd_seq_t
*commands
)
4847 struct net
*net
= sock_net(asoc
->base
.sk
);
4849 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4850 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4852 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4853 SCTP_STATE(SCTP_STATE_CLOSED
));
4855 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
4857 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4859 return SCTP_DISPOSITION_DELETE_TCB
;
4863 * sctp_cookie_echoed_prm_shutdown
4865 * Section: 4 Note: 2
4870 * The RFC does not explcitly address this issue, but is the route through the
4871 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4876 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4877 const struct sctp_endpoint
*ep
,
4878 const struct sctp_association
*asoc
,
4879 const sctp_subtype_t type
,
4880 void *arg
, sctp_cmd_seq_t
*commands
)
4882 /* There is a single T1 timer, so we should be able to use
4883 * common function with the COOKIE-WAIT state.
4885 return sctp_sf_cookie_wait_prm_shutdown(ep
, asoc
, type
, arg
, commands
);
4889 * sctp_sf_cookie_wait_prm_abort
4891 * Section: 4 Note: 2
4896 * The RFC does not explicitly address this issue, but is the route through the
4897 * state table when someone issues an abort while in COOKIE_WAIT state.
4902 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4903 const struct sctp_endpoint
*ep
,
4904 const struct sctp_association
*asoc
,
4905 const sctp_subtype_t type
,
4907 sctp_cmd_seq_t
*commands
)
4909 struct sctp_chunk
*abort
= arg
;
4910 sctp_disposition_t retval
;
4911 struct net
*net
= sock_net(asoc
->base
.sk
);
4913 /* Stop T1-init timer */
4914 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4915 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4916 retval
= SCTP_DISPOSITION_CONSUME
;
4918 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4920 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4921 SCTP_STATE(SCTP_STATE_CLOSED
));
4923 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4925 /* Even if we can't send the ABORT due to low memory delete the
4926 * TCB. This is a departure from our typical NOMEM handling.
4929 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4930 SCTP_ERROR(ECONNREFUSED
));
4931 /* Delete the established association. */
4932 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4933 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4939 * sctp_sf_cookie_echoed_prm_abort
4941 * Section: 4 Note: 3
4946 * The RFC does not explcitly address this issue, but is the route through the
4947 * state table when someone issues an abort while in COOKIE_ECHOED state.
4952 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4953 const struct sctp_endpoint
*ep
,
4954 const struct sctp_association
*asoc
,
4955 const sctp_subtype_t type
,
4957 sctp_cmd_seq_t
*commands
)
4959 /* There is a single T1 timer, so we should be able to use
4960 * common function with the COOKIE-WAIT state.
4962 return sctp_sf_cookie_wait_prm_abort(ep
, asoc
, type
, arg
, commands
);
4966 * sctp_sf_shutdown_pending_prm_abort
4971 * The RFC does not explicitly address this issue, but is the route through the
4972 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
4977 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
4978 const struct sctp_endpoint
*ep
,
4979 const struct sctp_association
*asoc
,
4980 const sctp_subtype_t type
,
4982 sctp_cmd_seq_t
*commands
)
4984 /* Stop the T5-shutdown guard timer. */
4985 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4986 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
4988 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
4992 * sctp_sf_shutdown_sent_prm_abort
4997 * The RFC does not explicitly address this issue, but is the route through the
4998 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5003 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
5004 const struct sctp_endpoint
*ep
,
5005 const struct sctp_association
*asoc
,
5006 const sctp_subtype_t type
,
5008 sctp_cmd_seq_t
*commands
)
5010 /* Stop the T2-shutdown timer. */
5011 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5012 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5014 /* Stop the T5-shutdown guard timer. */
5015 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5016 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5018 return sctp_sf_do_9_1_prm_abort(ep
, asoc
, type
, arg
, commands
);
5022 * sctp_sf_cookie_echoed_prm_abort
5027 * The RFC does not explcitly address this issue, but is the route through the
5028 * state table when someone issues an abort while in COOKIE_ECHOED state.
5033 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
5034 const struct sctp_endpoint
*ep
,
5035 const struct sctp_association
*asoc
,
5036 const sctp_subtype_t type
,
5038 sctp_cmd_seq_t
*commands
)
5040 /* The same T2 timer, so we should be able to use
5041 * common function with the SHUTDOWN-SENT state.
5043 return sctp_sf_shutdown_sent_prm_abort(ep
, asoc
, type
, arg
, commands
);
5047 * Process the REQUESTHEARTBEAT primitive
5050 * J) Request Heartbeat
5052 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5056 * Instructs the local endpoint to perform a HeartBeat on the specified
5057 * destination transport address of the given association. The returned
5058 * result should indicate whether the transmission of the HEARTBEAT
5059 * chunk to the destination address is successful.
5061 * Mandatory attributes:
5063 * o association id - local handle to the SCTP association
5065 * o destination transport address - the transport address of the
5066 * association on which a heartbeat should be issued.
5068 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
5069 const struct sctp_endpoint
*ep
,
5070 const struct sctp_association
*asoc
,
5071 const sctp_subtype_t type
,
5073 sctp_cmd_seq_t
*commands
)
5075 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5076 (struct sctp_transport
*)arg
, commands
))
5077 return SCTP_DISPOSITION_NOMEM
;
5080 * RFC 2960 (bis), section 8.3
5082 * D) Request an on-demand HEARTBEAT on a specific destination
5083 * transport address of a given association.
5085 * The endpoint should increment the respective error counter of
5086 * the destination transport address each time a HEARTBEAT is sent
5087 * to that address and not acknowledged within one RTO.
5090 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5091 SCTP_TRANSPORT(arg
));
5092 return SCTP_DISPOSITION_CONSUME
;
5096 * ADDIP Section 4.1 ASCONF Chunk Procedures
5097 * When an endpoint has an ASCONF signaled change to be sent to the
5098 * remote endpoint it should do A1 to A9
5100 sctp_disposition_t
sctp_sf_do_prm_asconf(const struct sctp_endpoint
*ep
,
5101 const struct sctp_association
*asoc
,
5102 const sctp_subtype_t type
,
5104 sctp_cmd_seq_t
*commands
)
5106 struct sctp_chunk
*chunk
= arg
;
5108 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5109 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5110 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5111 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5112 return SCTP_DISPOSITION_CONSUME
;
5116 * Ignore the primitive event
5118 * The return value is the disposition of the primitive.
5120 sctp_disposition_t
sctp_sf_ignore_primitive(
5121 const struct sctp_endpoint
*ep
,
5122 const struct sctp_association
*asoc
,
5123 const sctp_subtype_t type
,
5125 sctp_cmd_seq_t
*commands
)
5127 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
5128 return SCTP_DISPOSITION_DISCARD
;
5131 /***************************************************************************
5132 * These are the state functions for the OTHER events.
5133 ***************************************************************************/
5136 * When the SCTP stack has no more user data to send or retransmit, this
5137 * notification is given to the user. Also, at the time when a user app
5138 * subscribes to this event, if there is no data to be sent or
5139 * retransmit, the stack will immediately send up this notification.
5141 sctp_disposition_t
sctp_sf_do_no_pending_tsn(
5142 const struct sctp_endpoint
*ep
,
5143 const struct sctp_association
*asoc
,
5144 const sctp_subtype_t type
,
5146 sctp_cmd_seq_t
*commands
)
5148 struct sctp_ulpevent
*event
;
5150 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5152 return SCTP_DISPOSITION_NOMEM
;
5154 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5156 return SCTP_DISPOSITION_CONSUME
;
5160 * Start the shutdown negotiation.
5163 * Once all its outstanding data has been acknowledged, the endpoint
5164 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5165 * TSN Ack field the last sequential TSN it has received from the peer.
5166 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5167 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5168 * with the updated last sequential TSN received from its peer.
5170 * The return value is the disposition.
5172 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5173 const struct sctp_endpoint
*ep
,
5174 const struct sctp_association
*asoc
,
5175 const sctp_subtype_t type
,
5177 sctp_cmd_seq_t
*commands
)
5179 struct sctp_chunk
*reply
;
5181 /* Once all its outstanding data has been acknowledged, the
5182 * endpoint shall send a SHUTDOWN chunk to its peer including
5183 * in the Cumulative TSN Ack field the last sequential TSN it
5184 * has received from the peer.
5186 reply
= sctp_make_shutdown(asoc
, NULL
);
5190 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5191 * T2-shutdown timer.
5193 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5195 /* It shall then start the T2-shutdown timer */
5196 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5197 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5199 /* RFC 4960 Section 9.2
5200 * The sender of the SHUTDOWN MAY also start an overall guard timer
5201 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5203 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5204 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5206 if (asoc
->autoclose
)
5207 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5208 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5210 /* and enter the SHUTDOWN-SENT state. */
5211 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5212 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5214 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5216 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5219 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5221 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5223 return SCTP_DISPOSITION_CONSUME
;
5226 return SCTP_DISPOSITION_NOMEM
;
5230 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5234 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5235 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5236 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5237 * endpoint must re-send the SHUTDOWN ACK.
5239 * The return value is the disposition.
5241 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5242 const struct sctp_endpoint
*ep
,
5243 const struct sctp_association
*asoc
,
5244 const sctp_subtype_t type
,
5246 sctp_cmd_seq_t
*commands
)
5248 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5249 struct sctp_chunk
*reply
;
5251 /* There are 2 ways of getting here:
5252 * 1) called in response to a SHUTDOWN chunk
5253 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5255 * For the case (2), the arg parameter is set to NULL. We need
5256 * to check that we have a chunk before accessing it's fields.
5259 if (!sctp_vtag_verify(chunk
, asoc
))
5260 return sctp_sf_pdiscard(ep
, asoc
, type
, arg
, commands
);
5262 /* Make sure that the SHUTDOWN chunk has a valid length. */
5263 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5264 return sctp_sf_violation_chunklen(ep
, asoc
, type
, arg
,
5268 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5269 * shall send a SHUTDOWN ACK ...
5271 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5275 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5276 * the T2-shutdown timer.
5278 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5280 /* and start/restart a T2-shutdown timer of its own, */
5281 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5282 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5284 if (asoc
->autoclose
)
5285 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5286 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5288 /* Enter the SHUTDOWN-ACK-SENT state. */
5289 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5290 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5292 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5294 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5297 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5299 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5301 return SCTP_DISPOSITION_CONSUME
;
5304 return SCTP_DISPOSITION_NOMEM
;
5308 * Ignore the event defined as other
5310 * The return value is the disposition of the event.
5312 sctp_disposition_t
sctp_sf_ignore_other(const struct sctp_endpoint
*ep
,
5313 const struct sctp_association
*asoc
,
5314 const sctp_subtype_t type
,
5316 sctp_cmd_seq_t
*commands
)
5318 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
5319 return SCTP_DISPOSITION_DISCARD
;
5322 /************************************************************
5323 * These are the state functions for handling timeout events.
5324 ************************************************************/
5329 * Section: 6.3.3 Handle T3-rtx Expiration
5331 * Whenever the retransmission timer T3-rtx expires for a destination
5332 * address, do the following:
5335 * The return value is the disposition of the chunk.
5337 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(const struct sctp_endpoint
*ep
,
5338 const struct sctp_association
*asoc
,
5339 const sctp_subtype_t type
,
5341 sctp_cmd_seq_t
*commands
)
5343 struct sctp_transport
*transport
= arg
;
5344 struct net
*net
= sock_net(asoc
->base
.sk
);
5346 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5348 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5349 if (asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5351 * We are here likely because the receiver had its rwnd
5352 * closed for a while and we have not been able to
5353 * transmit the locally queued data within the maximum
5354 * retransmission attempts limit. Start the T5
5355 * shutdown guard timer to give the receiver one last
5356 * chance and some additional time to recover before
5359 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5360 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5362 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5363 SCTP_ERROR(ETIMEDOUT
));
5364 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5365 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5366 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5367 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5368 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5369 return SCTP_DISPOSITION_DELETE_TCB
;
5373 /* E1) For the destination address for which the timer
5374 * expires, adjust its ssthresh with rules defined in Section
5375 * 7.2.3 and set the cwnd <- MTU.
5378 /* E2) For the destination address for which the timer
5379 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5380 * maximum value discussed in rule C7 above (RTO.max) may be
5381 * used to provide an upper bound to this doubling operation.
5384 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5385 * outstanding DATA chunks for the address for which the
5386 * T3-rtx has expired will fit into a single packet, subject
5387 * to the MTU constraint for the path corresponding to the
5388 * destination transport address to which the retransmission
5389 * is being sent (this may be different from the address for
5390 * which the timer expires [see Section 6.4]). Call this
5391 * value K. Bundle and retransmit those K DATA chunks in a
5392 * single packet to the destination endpoint.
5394 * Note: Any DATA chunks that were sent to the address for
5395 * which the T3-rtx timer expired but did not fit in one MTU
5396 * (rule E3 above), should be marked for retransmission and
5397 * sent as soon as cwnd allows (normally when a SACK arrives).
5400 /* Do some failure management (Section 8.2). */
5401 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5403 /* NB: Rules E4 and F1 are implicit in R1. */
5404 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5406 return SCTP_DISPOSITION_CONSUME
;
5410 * Generate delayed SACK on timeout
5412 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5414 * The guidelines on delayed acknowledgement algorithm specified in
5415 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5416 * acknowledgement SHOULD be generated for at least every second packet
5417 * (not every second DATA chunk) received, and SHOULD be generated
5418 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5419 * some situations it may be beneficial for an SCTP transmitter to be
5420 * more conservative than the algorithms detailed in this document
5421 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5422 * the following algorithms allow.
5424 sctp_disposition_t
sctp_sf_do_6_2_sack(const struct sctp_endpoint
*ep
,
5425 const struct sctp_association
*asoc
,
5426 const sctp_subtype_t type
,
5428 sctp_cmd_seq_t
*commands
)
5430 struct net
*net
= sock_net(asoc
->base
.sk
);
5431 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5432 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5433 return SCTP_DISPOSITION_CONSUME
;
5437 * sctp_sf_t1_init_timer_expire
5439 * Section: 4 Note: 2
5444 * RFC 2960 Section 4 Notes
5445 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5446 * and re-start the T1-init timer without changing state. This MUST
5447 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5448 * endpoint MUST abort the initialization process and report the
5449 * error to SCTP user.
5455 sctp_disposition_t
sctp_sf_t1_init_timer_expire(const struct sctp_endpoint
*ep
,
5456 const struct sctp_association
*asoc
,
5457 const sctp_subtype_t type
,
5459 sctp_cmd_seq_t
*commands
)
5461 struct sctp_chunk
*repl
= NULL
;
5462 struct sctp_bind_addr
*bp
;
5463 int attempts
= asoc
->init_err_counter
+ 1;
5464 struct net
*net
= sock_net(asoc
->base
.sk
);
5466 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5467 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5469 if (attempts
<= asoc
->max_init_attempts
) {
5470 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5471 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5473 return SCTP_DISPOSITION_NOMEM
;
5475 /* Choose transport for INIT. */
5476 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5479 /* Issue a sideeffect to do the needed accounting. */
5480 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5481 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5483 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5485 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5486 " max_init_attempts: %d\n",
5487 attempts
, asoc
->max_init_attempts
);
5488 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5489 SCTP_ERROR(ETIMEDOUT
));
5490 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5491 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5492 return SCTP_DISPOSITION_DELETE_TCB
;
5495 return SCTP_DISPOSITION_CONSUME
;
5499 * sctp_sf_t1_cookie_timer_expire
5501 * Section: 4 Note: 2
5506 * RFC 2960 Section 4 Notes
5507 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5508 * COOKIE ECHO and re-start the T1-cookie timer without changing
5509 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5510 * After that, the endpoint MUST abort the initialization process and
5511 * report the error to SCTP user.
5517 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(const struct sctp_endpoint
*ep
,
5518 const struct sctp_association
*asoc
,
5519 const sctp_subtype_t type
,
5521 sctp_cmd_seq_t
*commands
)
5523 struct sctp_chunk
*repl
= NULL
;
5524 int attempts
= asoc
->init_err_counter
+ 1;
5525 struct net
*net
= sock_net(asoc
->base
.sk
);
5527 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5528 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5530 if (attempts
<= asoc
->max_init_attempts
) {
5531 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5533 return SCTP_DISPOSITION_NOMEM
;
5535 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5537 /* Issue a sideeffect to do the needed accounting. */
5538 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5539 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5541 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5543 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5544 SCTP_ERROR(ETIMEDOUT
));
5545 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5546 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5547 return SCTP_DISPOSITION_DELETE_TCB
;
5550 return SCTP_DISPOSITION_CONSUME
;
5553 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5554 * with the updated last sequential TSN received from its peer.
5556 * An endpoint should limit the number of retransmissions of the
5557 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5558 * If this threshold is exceeded the endpoint should destroy the TCB and
5559 * MUST report the peer endpoint unreachable to the upper layer (and
5560 * thus the association enters the CLOSED state). The reception of any
5561 * packet from its peer (i.e. as the peer sends all of its queued DATA
5562 * chunks) should clear the endpoint's retransmission count and restart
5563 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5564 * all of its queued DATA chunks that have not yet been sent.
5566 sctp_disposition_t
sctp_sf_t2_timer_expire(const struct sctp_endpoint
*ep
,
5567 const struct sctp_association
*asoc
,
5568 const sctp_subtype_t type
,
5570 sctp_cmd_seq_t
*commands
)
5572 struct sctp_chunk
*reply
= NULL
;
5573 struct net
*net
= sock_net(asoc
->base
.sk
);
5575 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5576 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5578 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5580 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5581 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5582 SCTP_ERROR(ETIMEDOUT
));
5583 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5584 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5585 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5586 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5587 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5588 return SCTP_DISPOSITION_DELETE_TCB
;
5591 switch (asoc
->state
) {
5592 case SCTP_STATE_SHUTDOWN_SENT
:
5593 reply
= sctp_make_shutdown(asoc
, NULL
);
5596 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5597 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5608 /* Do some failure management (Section 8.2).
5609 * If we remove the transport an SHUTDOWN was last sent to, don't
5610 * do failure management.
5612 if (asoc
->shutdown_last_sent_to
)
5613 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5614 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5616 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5617 * the T2-shutdown timer.
5619 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5621 /* Restart the T2-shutdown timer. */
5622 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5623 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5624 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5625 return SCTP_DISPOSITION_CONSUME
;
5628 return SCTP_DISPOSITION_NOMEM
;
5632 * ADDIP Section 4.1 ASCONF CHunk Procedures
5633 * If the T4 RTO timer expires the endpoint should do B1 to B5
5635 sctp_disposition_t
sctp_sf_t4_timer_expire(
5636 const struct sctp_endpoint
*ep
,
5637 const struct sctp_association
*asoc
,
5638 const sctp_subtype_t type
,
5640 sctp_cmd_seq_t
*commands
)
5642 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5643 struct sctp_transport
*transport
= chunk
->transport
;
5644 struct net
*net
= sock_net(asoc
->base
.sk
);
5646 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5648 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5649 * detection on the appropriate destination address as defined in
5650 * RFC2960 [5] section 8.1 and 8.2.
5653 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5654 SCTP_TRANSPORT(transport
));
5656 /* Reconfig T4 timer and transport. */
5657 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5659 /* ADDIP 4.1 B2) Increment the association error counters and perform
5660 * endpoint failure detection on the association as defined in
5661 * RFC2960 [5] section 8.1 and 8.2.
5662 * association error counter is incremented in SCTP_CMD_STRIKE.
5664 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5665 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5666 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5667 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5668 SCTP_ERROR(ETIMEDOUT
));
5669 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5670 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5671 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5672 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5673 return SCTP_DISPOSITION_ABORT
;
5676 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5677 * the ASCONF chunk was sent by doubling the RTO timer value.
5678 * This is done in SCTP_CMD_STRIKE.
5681 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5682 * choose an alternate destination address (please refer to RFC2960
5683 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5684 * chunk, it MUST be the same (including its serial number) as the last
5687 sctp_chunk_hold(asoc
->addip_last_asconf
);
5688 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5689 SCTP_CHUNK(asoc
->addip_last_asconf
));
5691 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5692 * destination is selected, then the RTO used will be that of the new
5693 * destination address.
5695 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5696 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5698 return SCTP_DISPOSITION_CONSUME
;
5701 /* sctpimpguide-05 Section 2.12.2
5702 * The sender of the SHUTDOWN MAY also start an overall guard timer
5703 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5704 * At the expiration of this timer the sender SHOULD abort the association
5705 * by sending an ABORT chunk.
5707 sctp_disposition_t
sctp_sf_t5_timer_expire(const struct sctp_endpoint
*ep
,
5708 const struct sctp_association
*asoc
,
5709 const sctp_subtype_t type
,
5711 sctp_cmd_seq_t
*commands
)
5713 struct sctp_chunk
*reply
= NULL
;
5714 struct net
*net
= sock_net(asoc
->base
.sk
);
5716 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5717 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5719 reply
= sctp_make_abort(asoc
, NULL
, 0);
5723 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5724 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5725 SCTP_ERROR(ETIMEDOUT
));
5726 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5727 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5729 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5730 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5732 return SCTP_DISPOSITION_DELETE_TCB
;
5734 return SCTP_DISPOSITION_NOMEM
;
5737 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5738 * the association is automatically closed by starting the shutdown process.
5739 * The work that needs to be done is same as when SHUTDOWN is initiated by
5740 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5742 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5743 const struct sctp_endpoint
*ep
,
5744 const struct sctp_association
*asoc
,
5745 const sctp_subtype_t type
,
5747 sctp_cmd_seq_t
*commands
)
5749 struct net
*net
= sock_net(asoc
->base
.sk
);
5752 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5754 /* From 9.2 Shutdown of an Association
5755 * Upon receipt of the SHUTDOWN primitive from its upper
5756 * layer, the endpoint enters SHUTDOWN-PENDING state and
5757 * remains there until all outstanding data has been
5758 * acknowledged by its peer. The endpoint accepts no new data
5759 * from its upper layer, but retransmits data to the far end
5760 * if necessary to fill gaps.
5762 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5763 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5765 disposition
= SCTP_DISPOSITION_CONSUME
;
5766 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5767 disposition
= sctp_sf_do_9_2_start_shutdown(ep
, asoc
, type
,
5773 /*****************************************************************************
5774 * These are sa state functions which could apply to all types of events.
5775 ****************************************************************************/
5778 * This table entry is not implemented.
5781 * (endpoint, asoc, chunk)
5783 * The return value is the disposition of the chunk.
5785 sctp_disposition_t
sctp_sf_not_impl(const struct sctp_endpoint
*ep
,
5786 const struct sctp_association
*asoc
,
5787 const sctp_subtype_t type
,
5789 sctp_cmd_seq_t
*commands
)
5791 return SCTP_DISPOSITION_NOT_IMPL
;
5795 * This table entry represents a bug.
5798 * (endpoint, asoc, chunk)
5800 * The return value is the disposition of the chunk.
5802 sctp_disposition_t
sctp_sf_bug(const struct sctp_endpoint
*ep
,
5803 const struct sctp_association
*asoc
,
5804 const sctp_subtype_t type
,
5806 sctp_cmd_seq_t
*commands
)
5808 return SCTP_DISPOSITION_BUG
;
5812 * This table entry represents the firing of a timer in the wrong state.
5813 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5814 * when the association is in the wrong state. This event should
5815 * be ignored, so as to prevent any rearming of the timer.
5818 * (endpoint, asoc, chunk)
5820 * The return value is the disposition of the chunk.
5822 sctp_disposition_t
sctp_sf_timer_ignore(const struct sctp_endpoint
*ep
,
5823 const struct sctp_association
*asoc
,
5824 const sctp_subtype_t type
,
5826 sctp_cmd_seq_t
*commands
)
5828 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5829 return SCTP_DISPOSITION_CONSUME
;
5832 /********************************************************************
5833 * 2nd Level Abstractions
5834 ********************************************************************/
5836 /* Pull the SACK chunk based on the SACK header. */
5837 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5839 struct sctp_sackhdr
*sack
;
5844 /* Protect ourselves from reading too far into
5845 * the skb from a bogus sender.
5847 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5849 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5850 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5851 len
= sizeof(struct sctp_sackhdr
);
5852 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5853 if (len
> chunk
->skb
->len
)
5856 skb_pull(chunk
->skb
, len
);
5861 /* Create an ABORT packet to be sent as a response, with the specified
5864 static struct sctp_packet
*sctp_abort_pkt_new(const struct sctp_endpoint
*ep
,
5865 const struct sctp_association
*asoc
,
5866 struct sctp_chunk
*chunk
,
5867 const void *payload
,
5870 struct sctp_packet
*packet
;
5871 struct sctp_chunk
*abort
;
5874 net
= sock_net(ep
->base
.sk
);
5875 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
5879 * The T bit will be set if the asoc is NULL.
5881 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5883 sctp_ootb_pkt_free(packet
);
5887 /* Reflect vtag if T-Bit is set */
5888 if (sctp_test_T_bit(abort
))
5889 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5891 /* Add specified error causes, i.e., payload, to the
5894 sctp_addto_chunk(abort
, paylen
, payload
);
5896 /* Set the skb to the belonging sock for accounting. */
5897 abort
->skb
->sk
= ep
->base
.sk
;
5899 sctp_packet_append_chunk(packet
, abort
);
5906 /* Allocate a packet for responding in the OOTB conditions. */
5907 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
5908 const struct sctp_association
*asoc
,
5909 const struct sctp_chunk
*chunk
)
5911 struct sctp_packet
*packet
;
5912 struct sctp_transport
*transport
;
5917 /* Get the source and destination port from the inbound packet. */
5918 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5919 dport
= ntohs(chunk
->sctp_hdr
->source
);
5921 /* The V-tag is going to be the same as the inbound packet if no
5922 * association exists, otherwise, use the peer's vtag.
5925 /* Special case the INIT-ACK as there is no peer's vtag
5928 switch(chunk
->chunk_hdr
->type
) {
5929 case SCTP_CID_INIT_ACK
:
5931 sctp_initack_chunk_t
*initack
;
5933 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5934 vtag
= ntohl(initack
->init_hdr
.init_tag
);
5938 vtag
= asoc
->peer
.i
.init_tag
;
5942 /* Special case the INIT and stale COOKIE_ECHO as there is no
5945 switch(chunk
->chunk_hdr
->type
) {
5948 sctp_init_chunk_t
*init
;
5950 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
5951 vtag
= ntohl(init
->init_hdr
.init_tag
);
5955 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5960 /* Make a transport for the bucket, Eliza... */
5961 transport
= sctp_transport_new(sctp_source(chunk
), GFP_ATOMIC
);
5965 /* Cache a route for the transport with the chunk's destination as
5966 * the source address.
5968 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
5969 sctp_sk(net
->sctp
.ctl_sock
));
5971 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
5972 packet
= sctp_packet_config(packet
, vtag
, 0);
5980 /* Free the packet allocated earlier for responding in the OOTB condition. */
5981 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
5983 sctp_transport_free(packet
->transport
);
5986 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
5987 static void sctp_send_stale_cookie_err(const struct sctp_endpoint
*ep
,
5988 const struct sctp_association
*asoc
,
5989 const struct sctp_chunk
*chunk
,
5990 sctp_cmd_seq_t
*commands
,
5991 struct sctp_chunk
*err_chunk
)
5993 struct sctp_packet
*packet
;
5996 struct net
*net
= sock_net(ep
->base
.sk
);
5997 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
5999 struct sctp_signed_cookie
*cookie
;
6001 /* Override the OOTB vtag from the cookie. */
6002 cookie
= chunk
->subh
.cookie_hdr
;
6003 packet
->vtag
= cookie
->c
.peer_vtag
;
6005 /* Set the skb to the belonging sock for accounting. */
6006 err_chunk
->skb
->sk
= ep
->base
.sk
;
6007 sctp_packet_append_chunk(packet
, err_chunk
);
6008 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6009 SCTP_PACKET(packet
));
6010 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6012 sctp_chunk_free (err_chunk
);
6017 /* Process a data chunk */
6018 static int sctp_eat_data(const struct sctp_association
*asoc
,
6019 struct sctp_chunk
*chunk
,
6020 sctp_cmd_seq_t
*commands
)
6022 sctp_datahdr_t
*data_hdr
;
6023 struct sctp_chunk
*err
;
6025 sctp_verb_t deliver
;
6028 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6029 struct sock
*sk
= asoc
->base
.sk
;
6035 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
6036 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
6038 tsn
= ntohl(data_hdr
->tsn
);
6039 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
6041 /* ASSERT: Now skb->data is really the user data. */
6043 /* Process ECN based congestion.
6045 * Since the chunk structure is reused for all chunks within
6046 * a packet, we use ecn_ce_done to track if we've already
6047 * done CE processing for this packet.
6049 * We need to do ECN processing even if we plan to discard the
6053 if (!chunk
->ecn_ce_done
) {
6055 chunk
->ecn_ce_done
= 1;
6057 af
= sctp_get_af_specific(
6058 ipver2af(ip_hdr(chunk
->skb
)->version
));
6060 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
6061 /* Do real work as sideffect. */
6062 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6067 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6069 /* The TSN is too high--silently discard the chunk and
6070 * count on it getting retransmitted later.
6072 return SCTP_IERROR_HIGH_TSN
;
6073 } else if (tmp
> 0) {
6074 /* This is a duplicate. Record it. */
6075 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6076 return SCTP_IERROR_DUP_TSN
;
6079 /* This is a new TSN. */
6081 /* Discard if there is no room in the receive window.
6082 * Actually, allow a little bit of overflow (up to a MTU).
6084 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6085 datalen
-= sizeof(sctp_data_chunk_t
);
6087 deliver
= SCTP_CMD_CHUNK_ULP
;
6089 /* Think about partial delivery. */
6090 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6092 /* Even if we don't accept this chunk there is
6095 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6098 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6099 * seems a bit troublesome in that frag_point varies based on
6100 * PMTU. In cases, such as loopback, this might be a rather
6103 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6104 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6106 /* If this is the next TSN, consider reneging to make
6107 * room. Note: Playing nice with a confused sender. A
6108 * malicious sender can still eat up all our buffer
6109 * space and in the future we may want to detect and
6110 * do more drastic reneging.
6112 if (sctp_tsnmap_has_gap(map
) &&
6113 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6114 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
6115 deliver
= SCTP_CMD_RENEGE
;
6117 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
6118 "rwnd: %d\n", tsn
, datalen
,
6120 return SCTP_IERROR_IGNORE_TSN
;
6125 * Also try to renege to limit our memory usage in the event that
6126 * we are under memory pressure
6127 * If we can't renege, don't worry about it, the sk_rmem_schedule
6128 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6129 * memory usage too much
6131 if (*sk
->sk_prot_creator
->memory_pressure
) {
6132 if (sctp_tsnmap_has_gap(map
) &&
6133 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6134 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn
);
6135 deliver
= SCTP_CMD_RENEGE
;
6140 * Section 3.3.10.9 No User Data (9)
6144 * No User Data: This error cause is returned to the originator of a
6145 * DATA chunk if a received DATA chunk has no user data.
6148 if (unlikely(0 == datalen
)) {
6149 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6151 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6154 /* We are going to ABORT, so we might as well stop
6155 * processing the rest of the chunks in the packet.
6157 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
6158 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6159 SCTP_ERROR(ECONNABORTED
));
6160 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6161 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6162 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6163 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6164 return SCTP_IERROR_NO_DATA
;
6167 chunk
->data_accepted
= 1;
6169 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6170 * if we renege and the chunk arrives again.
6172 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
6173 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6175 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6179 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6181 * If an endpoint receive a DATA chunk with an invalid stream
6182 * identifier, it shall acknowledge the reception of the DATA chunk
6183 * following the normal procedure, immediately send an ERROR chunk
6184 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6185 * and discard the DATA chunk.
6187 sid
= ntohs(data_hdr
->stream
);
6188 if (sid
>= asoc
->c
.sinit_max_instreams
) {
6189 /* Mark tsn as received even though we drop it */
6190 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6192 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6194 sizeof(data_hdr
->stream
),
6197 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6199 return SCTP_IERROR_BAD_STREAM
;
6202 /* Check to see if the SSN is possible for this TSN.
6203 * The biggest gap we can record is 4K wide. Since SSNs wrap
6204 * at an unsigned short, there is no way that an SSN can
6205 * wrap and for a valid TSN. We can simply check if the current
6206 * SSN is smaller then the next expected one. If it is, it wrapped
6209 ssn
= ntohs(data_hdr
->ssn
);
6210 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->ssnmap
->in
, sid
))) {
6211 return SCTP_IERROR_PROTO_VIOLATION
;
6214 /* Send the data up to the user. Note: Schedule the
6215 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6216 * chunk needs the updated rwnd.
6218 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6220 return SCTP_IERROR_NO_ERROR
;