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, see
26 * <http://www.gnu.org/licenses/>.
28 * Please send any bug reports or fixes you make to the
30 * lksctp developers <linux-sctp@vger.kernel.org>
32 * Written or modified by:
33 * La Monte H.P. Yarroll <piggy@acm.org>
34 * Karl Knutson <karl@athena.chicago.il.us>
35 * Mathew Kotowsky <kotowsky@sctp.org>
36 * Sridhar Samudrala <samudrala@us.ibm.com>
37 * Jon Grimm <jgrimm@us.ibm.com>
38 * Hui Huang <hui.huang@nokia.com>
39 * Dajiang Zhang <dajiang.zhang@nokia.com>
40 * Daisy Chang <daisyc@us.ibm.com>
41 * Ardelle Fan <ardelle.fan@intel.com>
42 * Ryan Layer <rmlayer@us.ibm.com>
43 * Kevin Gao <kevin.gao@intel.com>
46 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
48 #include <linux/types.h>
49 #include <linux/kernel.h>
51 #include <linux/ipv6.h>
52 #include <linux/net.h>
53 #include <linux/inet.h>
54 #include <linux/slab.h>
56 #include <net/inet_ecn.h>
57 #include <linux/skbuff.h>
58 #include <net/sctp/sctp.h>
59 #include <net/sctp/sm.h>
60 #include <net/sctp/structs.h>
62 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
63 const struct sctp_endpoint
*ep
,
64 const struct sctp_association
*asoc
,
65 struct sctp_chunk
*chunk
,
68 static int sctp_eat_data(const struct sctp_association
*asoc
,
69 struct sctp_chunk
*chunk
,
70 sctp_cmd_seq_t
*commands
);
71 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
72 const struct sctp_association
*asoc
,
73 const struct sctp_chunk
*chunk
);
74 static void sctp_send_stale_cookie_err(struct net
*net
,
75 const struct sctp_endpoint
*ep
,
76 const struct sctp_association
*asoc
,
77 const struct sctp_chunk
*chunk
,
78 sctp_cmd_seq_t
*commands
,
79 struct sctp_chunk
*err_chunk
);
80 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(struct net
*net
,
81 const struct sctp_endpoint
*ep
,
82 const struct sctp_association
*asoc
,
83 const sctp_subtype_t type
,
85 sctp_cmd_seq_t
*commands
);
86 static sctp_disposition_t
sctp_sf_shut_8_4_5(struct net
*net
,
87 const struct sctp_endpoint
*ep
,
88 const struct sctp_association
*asoc
,
89 const sctp_subtype_t type
,
91 sctp_cmd_seq_t
*commands
);
92 static sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
93 const struct sctp_endpoint
*ep
,
94 const struct sctp_association
*asoc
,
95 const sctp_subtype_t type
,
97 sctp_cmd_seq_t
*commands
);
98 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
100 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
101 sctp_cmd_seq_t
*commands
,
102 __be16 error
, int sk_err
,
103 const struct sctp_association
*asoc
,
104 struct sctp_transport
*transport
);
106 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(
117 const struct sctp_endpoint
*ep
,
118 const struct sctp_association
*asoc
,
119 const sctp_subtype_t type
,
121 sctp_cmd_seq_t
*commands
);
123 static sctp_disposition_t
sctp_sf_violation_paramlen(
125 const struct sctp_endpoint
*ep
,
126 const struct sctp_association
*asoc
,
127 const sctp_subtype_t type
,
128 void *arg
, void *ext
,
129 sctp_cmd_seq_t
*commands
);
131 static sctp_disposition_t
sctp_sf_violation_ctsn(
133 const struct sctp_endpoint
*ep
,
134 const struct sctp_association
*asoc
,
135 const sctp_subtype_t type
,
137 sctp_cmd_seq_t
*commands
);
139 static sctp_disposition_t
sctp_sf_violation_chunk(
141 const struct sctp_endpoint
*ep
,
142 const struct sctp_association
*asoc
,
143 const sctp_subtype_t type
,
145 sctp_cmd_seq_t
*commands
);
147 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
148 const struct sctp_endpoint
*ep
,
149 const struct sctp_association
*asoc
,
150 const sctp_subtype_t type
,
151 struct sctp_chunk
*chunk
);
153 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
154 const struct sctp_endpoint
*ep
,
155 const struct sctp_association
*asoc
,
156 const sctp_subtype_t type
,
158 sctp_cmd_seq_t
*commands
);
160 /* Small helper function that checks if the chunk length
161 * is of the appropriate length. The 'required_length' argument
162 * is set to be the size of a specific chunk we are testing.
163 * Return Values: true = Valid length
164 * false = Invalid length
168 sctp_chunk_length_valid(struct sctp_chunk
*chunk
, __u16 required_length
)
170 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
172 /* Previously already marked? */
173 if (unlikely(chunk
->pdiscard
))
175 if (unlikely(chunk_length
< required_length
))
181 /**********************************************************
182 * These are the state functions for handling chunk events.
183 **********************************************************/
186 * Process the final SHUTDOWN COMPLETE.
188 * Section: 4 (C) (diagram), 9.2
189 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
190 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
191 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
192 * should stop the T2-shutdown timer and remove all knowledge of the
193 * association (and thus the association enters the CLOSED state).
195 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
196 * C) Rules for packet carrying SHUTDOWN COMPLETE:
198 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
199 * if the Verification Tag field of the packet matches its own tag and
200 * the T bit is not set
202 * it is set to its peer's tag and the T bit is set in the Chunk
204 * Otherwise, the receiver MUST silently discard the packet
205 * and take no further action. An endpoint MUST ignore the
206 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
209 * (endpoint, asoc, chunk)
212 * (asoc, reply_msg, msg_up, timers, counters)
214 * The return value is the disposition of the chunk.
216 sctp_disposition_t
sctp_sf_do_4_C(struct net
*net
,
217 const struct sctp_endpoint
*ep
,
218 const struct sctp_association
*asoc
,
219 const sctp_subtype_t type
,
221 sctp_cmd_seq_t
*commands
)
223 struct sctp_chunk
*chunk
= arg
;
224 struct sctp_ulpevent
*ev
;
226 if (!sctp_vtag_verify_either(chunk
, asoc
))
227 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
229 /* RFC 2960 6.10 Bundling
231 * An endpoint MUST NOT bundle INIT, INIT ACK or
232 * SHUTDOWN COMPLETE with any other chunks.
234 if (!chunk
->singleton
)
235 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
237 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
238 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
239 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
242 /* RFC 2960 10.2 SCTP-to-ULP
244 * H) SHUTDOWN COMPLETE notification
246 * When SCTP completes the shutdown procedures (section 9.2) this
247 * notification is passed to the upper layer.
249 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
250 0, 0, 0, NULL
, GFP_ATOMIC
);
252 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
255 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
256 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
257 * not the chunk should be discarded. If the endpoint is in
258 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
259 * T2-shutdown timer and remove all knowledge of the
260 * association (and thus the association enters the CLOSED
263 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
264 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
266 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
267 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
269 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
270 SCTP_STATE(SCTP_STATE_CLOSED
));
272 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
273 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
275 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
277 return SCTP_DISPOSITION_DELETE_TCB
;
281 * Respond to a normal INIT chunk.
282 * We are the side that is being asked for an association.
284 * Section: 5.1 Normal Establishment of an Association, B
285 * B) "Z" shall respond immediately with an INIT ACK chunk. The
286 * destination IP address of the INIT ACK MUST be set to the source
287 * IP address of the INIT to which this INIT ACK is responding. In
288 * the response, besides filling in other parameters, "Z" must set the
289 * Verification Tag field to Tag_A, and also provide its own
290 * Verification Tag (Tag_Z) in the Initiate Tag field.
292 * Verification Tag: Must be 0.
295 * (endpoint, asoc, chunk)
298 * (asoc, reply_msg, msg_up, timers, counters)
300 * The return value is the disposition of the chunk.
302 sctp_disposition_t
sctp_sf_do_5_1B_init(struct net
*net
,
303 const struct sctp_endpoint
*ep
,
304 const struct sctp_association
*asoc
,
305 const sctp_subtype_t type
,
307 sctp_cmd_seq_t
*commands
)
309 struct sctp_chunk
*chunk
= arg
;
310 struct sctp_chunk
*repl
;
311 struct sctp_association
*new_asoc
;
312 struct sctp_chunk
*err_chunk
;
313 struct sctp_packet
*packet
;
314 sctp_unrecognized_param_t
*unk_param
;
318 * An endpoint MUST NOT bundle INIT, INIT ACK or
319 * SHUTDOWN COMPLETE with any other chunks.
322 * Furthermore, we require that the receiver of an INIT chunk MUST
323 * enforce these rules by silently discarding an arriving packet
324 * with an INIT chunk that is bundled with other chunks.
326 if (!chunk
->singleton
)
327 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
329 /* If the packet is an OOTB packet which is temporarily on the
330 * control endpoint, respond with an ABORT.
332 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
333 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
334 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
337 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
340 if (chunk
->sctp_hdr
->vtag
!= 0)
341 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
343 /* Make sure that the INIT chunk has a valid length.
344 * Normally, this would cause an ABORT with a Protocol Violation
345 * error, but since we don't have an association, we'll
346 * just discard the packet.
348 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
349 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
351 /* If the INIT is coming toward a closing socket, we'll send back
352 * and ABORT. Essentially, this catches the race of INIT being
353 * backloged to the socket at the same time as the user isses close().
354 * Since the socket and all its associations are going away, we
355 * can treat this OOTB
357 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
358 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
360 /* Verify the INIT chunk before processing it. */
362 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
363 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
365 /* This chunk contains fatal error. It is to be discarded.
366 * Send an ABORT, with causes if there is any.
369 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
370 (__u8
*)(err_chunk
->chunk_hdr
) +
371 sizeof(sctp_chunkhdr_t
),
372 ntohs(err_chunk
->chunk_hdr
->length
) -
373 sizeof(sctp_chunkhdr_t
));
375 sctp_chunk_free(err_chunk
);
378 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
379 SCTP_PACKET(packet
));
380 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
381 return SCTP_DISPOSITION_CONSUME
;
383 return SCTP_DISPOSITION_NOMEM
;
386 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
391 /* Grab the INIT header. */
392 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
394 /* Tag the variable length parameters. */
395 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
397 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
401 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
402 sctp_scope(sctp_source(chunk
)),
406 /* The call, sctp_process_init(), can fail on memory allocation. */
407 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
408 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
412 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
414 /* If there are errors need to be reported for unknown parameters,
415 * make sure to reserve enough room in the INIT ACK for them.
419 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
420 sizeof(sctp_chunkhdr_t
);
422 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
426 /* If there are errors need to be reported for unknown parameters,
427 * include them in the outgoing INIT ACK as "Unrecognized parameter"
431 /* Get the "Unrecognized parameter" parameter(s) out of the
432 * ERROR chunk generated by sctp_verify_init(). Since the
433 * error cause code for "unknown parameter" and the
434 * "Unrecognized parameter" type is the same, we can
435 * construct the parameters in INIT ACK by copying the
438 unk_param
= (sctp_unrecognized_param_t
*)
439 ((__u8
*)(err_chunk
->chunk_hdr
) +
440 sizeof(sctp_chunkhdr_t
));
441 /* Replace the cause code with the "Unrecognized parameter"
444 sctp_addto_chunk(repl
, len
, unk_param
);
445 sctp_chunk_free(err_chunk
);
448 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
450 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
453 * Note: After sending out INIT ACK with the State Cookie parameter,
454 * "Z" MUST NOT allocate any resources, nor keep any states for the
455 * new association. Otherwise, "Z" will be vulnerable to resource
458 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
460 return SCTP_DISPOSITION_DELETE_TCB
;
463 sctp_association_free(new_asoc
);
466 sctp_chunk_free(err_chunk
);
467 return SCTP_DISPOSITION_NOMEM
;
471 * Respond to a normal INIT ACK chunk.
472 * We are the side that is initiating the association.
474 * Section: 5.1 Normal Establishment of an Association, C
475 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
476 * timer and leave COOKIE-WAIT state. "A" shall then send the State
477 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
478 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
480 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
481 * DATA chunks, but it MUST be the first chunk in the packet and
482 * until the COOKIE ACK is returned the sender MUST NOT send any
483 * other packets to the peer.
485 * Verification Tag: 3.3.3
486 * If the value of the Initiate Tag in a received INIT ACK chunk is
487 * found to be 0, the receiver MUST treat it as an error and close the
488 * association by transmitting an ABORT.
491 * (endpoint, asoc, chunk)
494 * (asoc, reply_msg, msg_up, timers, counters)
496 * The return value is the disposition of the chunk.
498 sctp_disposition_t
sctp_sf_do_5_1C_ack(struct net
*net
,
499 const struct sctp_endpoint
*ep
,
500 const struct sctp_association
*asoc
,
501 const sctp_subtype_t type
,
503 sctp_cmd_seq_t
*commands
)
505 struct sctp_chunk
*chunk
= arg
;
506 sctp_init_chunk_t
*initchunk
;
507 struct sctp_chunk
*err_chunk
;
508 struct sctp_packet
*packet
;
510 if (!sctp_vtag_verify(chunk
, asoc
))
511 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
514 * An endpoint MUST NOT bundle INIT, INIT ACK or
515 * SHUTDOWN COMPLETE with any other chunks.
517 if (!chunk
->singleton
)
518 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
520 /* Make sure that the INIT-ACK chunk has a valid length */
521 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
522 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
524 /* Grab the INIT header. */
525 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
527 /* Verify the INIT chunk before processing it. */
529 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
530 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
533 sctp_error_t error
= SCTP_ERROR_NO_RESOURCE
;
535 /* This chunk contains fatal error. It is to be discarded.
536 * Send an ABORT, with causes. If there are no causes,
537 * then there wasn't enough memory. Just terminate
541 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
542 (__u8
*)(err_chunk
->chunk_hdr
) +
543 sizeof(sctp_chunkhdr_t
),
544 ntohs(err_chunk
->chunk_hdr
->length
) -
545 sizeof(sctp_chunkhdr_t
));
547 sctp_chunk_free(err_chunk
);
550 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
551 SCTP_PACKET(packet
));
552 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
553 error
= SCTP_ERROR_INV_PARAM
;
557 /* SCTP-AUTH, Section 6.3:
558 * It should be noted that if the receiver wants to tear
559 * down an association in an authenticated way only, the
560 * handling of malformed packets should not result in
561 * tearing down the association.
563 * This means that if we only want to abort associations
564 * in an authenticated way (i.e AUTH+ABORT), then we
565 * can't destroy this association just because the packet
568 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
569 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
571 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
572 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
573 asoc
, chunk
->transport
);
576 /* Tag the variable length parameters. Note that we never
577 * convert the parameters in an INIT chunk.
579 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
581 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
583 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
584 SCTP_PEER_INIT(initchunk
));
586 /* Reset init error count upon receipt of INIT-ACK. */
587 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
589 /* 5.1 C) "A" shall stop the T1-init timer and leave
590 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
591 * timer, and enter the COOKIE-ECHOED state.
593 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
594 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
595 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
596 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
597 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
598 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
600 /* SCTP-AUTH: genereate the assocition shared keys so that
601 * we can potentially signe the COOKIE-ECHO.
603 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
605 /* 5.1 C) "A" shall then send the State Cookie received in the
606 * INIT ACK chunk in a COOKIE ECHO chunk, ...
608 /* If there is any errors to report, send the ERROR chunk generated
609 * for unknown parameters as well.
611 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
612 SCTP_CHUNK(err_chunk
));
614 return SCTP_DISPOSITION_CONSUME
;
618 * Respond to a normal COOKIE ECHO chunk.
619 * We are the side that is being asked for an association.
621 * Section: 5.1 Normal Establishment of an Association, D
622 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
623 * with a COOKIE ACK chunk after building a TCB and moving to
624 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
625 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
626 * chunk MUST be the first chunk in the packet.
628 * IMPLEMENTATION NOTE: An implementation may choose to send the
629 * Communication Up notification to the SCTP user upon reception
630 * of a valid COOKIE ECHO chunk.
632 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
633 * D) Rules for packet carrying a COOKIE ECHO
635 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
636 * Initial Tag received in the INIT ACK.
638 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
641 * (endpoint, asoc, chunk)
644 * (asoc, reply_msg, msg_up, timers, counters)
646 * The return value is the disposition of the chunk.
648 sctp_disposition_t
sctp_sf_do_5_1D_ce(struct net
*net
,
649 const struct sctp_endpoint
*ep
,
650 const struct sctp_association
*asoc
,
651 const sctp_subtype_t type
, void *arg
,
652 sctp_cmd_seq_t
*commands
)
654 struct sctp_chunk
*chunk
= arg
;
655 struct sctp_association
*new_asoc
;
656 sctp_init_chunk_t
*peer_init
;
657 struct sctp_chunk
*repl
;
658 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
660 struct sctp_chunk
*err_chk_p
;
663 /* If the packet is an OOTB packet which is temporarily on the
664 * control endpoint, respond with an ABORT.
666 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
667 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
668 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
671 /* Make sure that the COOKIE_ECHO chunk has a valid length.
672 * In this case, we check that we have enough for at least a
673 * chunk header. More detailed verification is done
674 * in sctp_unpack_cookie().
676 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
677 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
679 /* If the endpoint is not listening or if the number of associations
680 * on the TCP-style socket exceed the max backlog, respond with an
684 if (!sctp_sstate(sk
, LISTENING
) ||
685 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
686 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
688 /* "Decode" the chunk. We have no optional parameters so we
691 chunk
->subh
.cookie_hdr
=
692 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
693 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
694 sizeof(sctp_chunkhdr_t
)))
697 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
698 * "Z" will reply with a COOKIE ACK chunk after building a TCB
699 * and moving to the ESTABLISHED state.
701 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
705 * If the re-build failed, what is the proper error path
708 * [We should abort the association. --piggy]
711 /* FIXME: Several errors are possible. A bad cookie should
712 * be silently discarded, but think about logging it too.
715 case -SCTP_IERROR_NOMEM
:
718 case -SCTP_IERROR_STALE_COOKIE
:
719 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
721 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
723 case -SCTP_IERROR_BAD_SIG
:
725 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
730 /* Delay state machine commands until later.
732 * Re-build the bind address for the association is done in
733 * the sctp_unpack_cookie() already.
735 /* This is a brand-new association, so these are not yet side
736 * effects--it is safe to run them here.
738 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
740 if (!sctp_process_init(new_asoc
, chunk
,
741 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
742 peer_init
, GFP_ATOMIC
))
745 /* SCTP-AUTH: Now that we've populate required fields in
746 * sctp_process_init, set up the assocaition shared keys as
747 * necessary so that we can potentially authenticate the ACK
749 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
753 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
754 * is supposed to be authenticated and we have to do delayed
755 * authentication. We've just recreated the association using
756 * the information in the cookie and now it's much easier to
757 * do the authentication.
759 if (chunk
->auth_chunk
) {
760 struct sctp_chunk auth
;
763 /* Make sure that we and the peer are AUTH capable */
764 if (!net
->sctp
.auth_enable
|| !new_asoc
->peer
.auth_capable
) {
765 sctp_association_free(new_asoc
);
766 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
769 /* set-up our fake chunk so that we can process it */
770 auth
.skb
= chunk
->auth_chunk
;
771 auth
.asoc
= chunk
->asoc
;
772 auth
.sctp_hdr
= chunk
->sctp_hdr
;
773 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
774 sizeof(sctp_chunkhdr_t
));
775 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
776 auth
.transport
= chunk
->transport
;
778 ret
= sctp_sf_authenticate(net
, ep
, new_asoc
, type
, &auth
);
779 if (ret
!= SCTP_IERROR_NO_ERROR
) {
780 sctp_association_free(new_asoc
);
781 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
785 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
789 /* RFC 2960 5.1 Normal Establishment of an Association
791 * D) IMPLEMENTATION NOTE: An implementation may choose to
792 * send the Communication Up notification to the SCTP user
793 * upon reception of a valid COOKIE ECHO chunk.
795 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
796 new_asoc
->c
.sinit_num_ostreams
,
797 new_asoc
->c
.sinit_max_instreams
,
802 /* Sockets API Draft Section 5.3.1.6
803 * When a peer sends a Adaptation Layer Indication parameter , SCTP
804 * delivers this notification to inform the application that of the
805 * peers requested adaptation layer.
807 if (new_asoc
->peer
.adaptation_ind
) {
808 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
814 /* Add all the state machine commands now since we've created
815 * everything. This way we don't introduce memory corruptions
816 * during side-effect processing and correclty count established
819 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
820 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
821 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
822 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
823 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
824 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
826 if (new_asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
827 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
828 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
830 /* This will send the COOKIE ACK */
831 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
833 /* Queue the ASSOC_CHANGE event */
834 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
836 /* Send up the Adaptation Layer Indication event */
838 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
839 SCTP_ULPEVENT(ai_ev
));
841 return SCTP_DISPOSITION_CONSUME
;
844 sctp_ulpevent_free(ev
);
846 sctp_chunk_free(repl
);
848 sctp_association_free(new_asoc
);
850 return SCTP_DISPOSITION_NOMEM
;
854 * Respond to a normal COOKIE ACK chunk.
855 * We are the side that is asking for an association.
857 * RFC 2960 5.1 Normal Establishment of an Association
859 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
860 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
861 * timer. It may also notify its ULP about the successful
862 * establishment of the association with a Communication Up
863 * notification (see Section 10).
867 * (endpoint, asoc, chunk)
870 * (asoc, reply_msg, msg_up, timers, counters)
872 * The return value is the disposition of the chunk.
874 sctp_disposition_t
sctp_sf_do_5_1E_ca(struct net
*net
,
875 const struct sctp_endpoint
*ep
,
876 const struct sctp_association
*asoc
,
877 const sctp_subtype_t type
, void *arg
,
878 sctp_cmd_seq_t
*commands
)
880 struct sctp_chunk
*chunk
= arg
;
881 struct sctp_ulpevent
*ev
;
883 if (!sctp_vtag_verify(chunk
, asoc
))
884 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
886 /* Verify that the chunk length for the COOKIE-ACK is OK.
887 * If we don't do this, any bundled chunks may be junked.
889 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
890 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
893 /* Reset init error count upon receipt of COOKIE-ACK,
894 * to avoid problems with the managemement of this
895 * counter in stale cookie situations when a transition back
896 * from the COOKIE-ECHOED state to the COOKIE-WAIT
897 * state is performed.
899 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
901 /* RFC 2960 5.1 Normal Establishment of an Association
903 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
904 * from the COOKIE-ECHOED state to the ESTABLISHED state,
905 * stopping the T1-cookie timer.
907 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
908 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
909 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
910 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
911 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
912 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
913 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
914 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
915 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
916 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
918 /* It may also notify its ULP about the successful
919 * establishment of the association with a Communication Up
920 * notification (see Section 10).
922 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
923 0, asoc
->c
.sinit_num_ostreams
,
924 asoc
->c
.sinit_max_instreams
,
930 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
932 /* Sockets API Draft Section 5.3.1.6
933 * When a peer sends a Adaptation Layer Indication parameter , SCTP
934 * delivers this notification to inform the application that of the
935 * peers requested adaptation layer.
937 if (asoc
->peer
.adaptation_ind
) {
938 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
942 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
946 return SCTP_DISPOSITION_CONSUME
;
948 return SCTP_DISPOSITION_NOMEM
;
951 /* Generate and sendout a heartbeat packet. */
952 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
953 const struct sctp_association
*asoc
,
954 const sctp_subtype_t type
,
956 sctp_cmd_seq_t
*commands
)
958 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
959 struct sctp_chunk
*reply
;
961 /* Send a heartbeat to our peer. */
962 reply
= sctp_make_heartbeat(asoc
, transport
);
964 return SCTP_DISPOSITION_NOMEM
;
966 /* Set rto_pending indicating that an RTT measurement
967 * is started with this heartbeat chunk.
969 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
970 SCTP_TRANSPORT(transport
));
972 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
973 return SCTP_DISPOSITION_CONSUME
;
976 /* Generate a HEARTBEAT packet on the given transport. */
977 sctp_disposition_t
sctp_sf_sendbeat_8_3(struct net
*net
,
978 const struct sctp_endpoint
*ep
,
979 const struct sctp_association
*asoc
,
980 const sctp_subtype_t type
,
982 sctp_cmd_seq_t
*commands
)
984 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
986 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
987 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
988 SCTP_ERROR(ETIMEDOUT
));
989 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
990 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
991 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
992 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
993 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
994 return SCTP_DISPOSITION_DELETE_TCB
;
998 * The Sender-specific Heartbeat Info field should normally include
999 * information about the sender's current time when this HEARTBEAT
1000 * chunk is sent and the destination transport address to which this
1001 * HEARTBEAT is sent (see Section 8.3).
1004 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1005 if (SCTP_DISPOSITION_NOMEM
==
1006 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1008 return SCTP_DISPOSITION_NOMEM
;
1010 /* Set transport error counter and association error counter
1011 * when sending heartbeat.
1013 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1014 SCTP_TRANSPORT(transport
));
1016 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1017 SCTP_TRANSPORT(transport
));
1018 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1019 SCTP_TRANSPORT(transport
));
1021 return SCTP_DISPOSITION_CONSUME
;
1025 * Process an heartbeat request.
1027 * Section: 8.3 Path Heartbeat
1028 * The receiver of the HEARTBEAT should immediately respond with a
1029 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1030 * from the received HEARTBEAT chunk.
1032 * Verification Tag: 8.5 Verification Tag [Normal verification]
1033 * When receiving an SCTP packet, the endpoint MUST ensure that the
1034 * value in the Verification Tag field of the received SCTP packet
1035 * matches its own Tag. If the received Verification Tag value does not
1036 * match the receiver's own tag value, the receiver shall silently
1037 * discard the packet and shall not process it any further except for
1038 * those cases listed in Section 8.5.1 below.
1041 * (endpoint, asoc, chunk)
1044 * (asoc, reply_msg, msg_up, timers, counters)
1046 * The return value is the disposition of the chunk.
1048 sctp_disposition_t
sctp_sf_beat_8_3(struct net
*net
,
1049 const struct sctp_endpoint
*ep
,
1050 const struct sctp_association
*asoc
,
1051 const sctp_subtype_t type
,
1053 sctp_cmd_seq_t
*commands
)
1055 sctp_paramhdr_t
*param_hdr
;
1056 struct sctp_chunk
*chunk
= arg
;
1057 struct sctp_chunk
*reply
;
1060 if (!sctp_vtag_verify(chunk
, asoc
))
1061 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1063 /* Make sure that the HEARTBEAT chunk has a valid length. */
1064 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1065 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1068 /* 8.3 The receiver of the HEARTBEAT should immediately
1069 * respond with a HEARTBEAT ACK that contains the Heartbeat
1070 * Information field copied from the received HEARTBEAT chunk.
1072 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
1073 param_hdr
= (sctp_paramhdr_t
*) chunk
->subh
.hb_hdr
;
1074 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1076 if (ntohs(param_hdr
->length
) > paylen
)
1077 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1078 param_hdr
, commands
);
1080 if (!pskb_pull(chunk
->skb
, paylen
))
1083 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1087 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1088 return SCTP_DISPOSITION_CONSUME
;
1091 return SCTP_DISPOSITION_NOMEM
;
1095 * Process the returning HEARTBEAT ACK.
1097 * Section: 8.3 Path Heartbeat
1098 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1099 * should clear the error counter of the destination transport
1100 * address to which the HEARTBEAT was sent, and mark the destination
1101 * transport address as active if it is not so marked. The endpoint may
1102 * optionally report to the upper layer when an inactive destination
1103 * address is marked as active due to the reception of the latest
1104 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1105 * clear the association overall error count as well (as defined
1108 * The receiver of the HEARTBEAT ACK should also perform an RTT
1109 * measurement for that destination transport address using the time
1110 * value carried in the HEARTBEAT ACK chunk.
1112 * Verification Tag: 8.5 Verification Tag [Normal verification]
1115 * (endpoint, asoc, chunk)
1118 * (asoc, reply_msg, msg_up, timers, counters)
1120 * The return value is the disposition of the chunk.
1122 sctp_disposition_t
sctp_sf_backbeat_8_3(struct net
*net
,
1123 const struct sctp_endpoint
*ep
,
1124 const struct sctp_association
*asoc
,
1125 const sctp_subtype_t type
,
1127 sctp_cmd_seq_t
*commands
)
1129 struct sctp_chunk
*chunk
= arg
;
1130 union sctp_addr from_addr
;
1131 struct sctp_transport
*link
;
1132 sctp_sender_hb_info_t
*hbinfo
;
1133 unsigned long max_interval
;
1135 if (!sctp_vtag_verify(chunk
, asoc
))
1136 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1138 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1139 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
) +
1140 sizeof(sctp_sender_hb_info_t
)))
1141 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1144 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1145 /* Make sure that the length of the parameter is what we expect */
1146 if (ntohs(hbinfo
->param_hdr
.length
) !=
1147 sizeof(sctp_sender_hb_info_t
)) {
1148 return SCTP_DISPOSITION_DISCARD
;
1151 from_addr
= hbinfo
->daddr
;
1152 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1154 /* This should never happen, but lets log it if so. */
1155 if (unlikely(!link
)) {
1156 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1157 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1160 &from_addr
.v6
.sin6_addr
);
1162 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1165 &from_addr
.v4
.sin_addr
.s_addr
);
1167 return SCTP_DISPOSITION_DISCARD
;
1170 /* Validate the 64-bit random nonce. */
1171 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1172 return SCTP_DISPOSITION_DISCARD
;
1174 max_interval
= link
->hbinterval
+ link
->rto
;
1176 /* Check if the timestamp looks valid. */
1177 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1178 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1179 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1180 "for transport:%p\n", __func__
, link
);
1182 return SCTP_DISPOSITION_DISCARD
;
1185 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1186 * the HEARTBEAT should clear the error counter of the
1187 * destination transport address to which the HEARTBEAT was
1188 * sent and mark the destination transport address as active if
1189 * it is not so marked.
1191 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1193 return SCTP_DISPOSITION_CONSUME
;
1196 /* Helper function to send out an abort for the restart
1199 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1200 struct sctp_chunk
*init
,
1201 sctp_cmd_seq_t
*commands
)
1204 struct sctp_packet
*pkt
;
1205 union sctp_addr_param
*addrparm
;
1206 struct sctp_errhdr
*errhdr
;
1207 struct sctp_endpoint
*ep
;
1208 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1209 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1211 /* Build the error on the stack. We are way to malloc crazy
1212 * throughout the code today.
1214 errhdr
= (struct sctp_errhdr
*)buffer
;
1215 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1217 /* Copy into a parm format. */
1218 len
= af
->to_addr_param(ssa
, addrparm
);
1219 len
+= sizeof(sctp_errhdr_t
);
1221 errhdr
->cause
= SCTP_ERROR_RESTART
;
1222 errhdr
->length
= htons(len
);
1224 /* Assign to the control socket. */
1225 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1227 /* Association is NULL since this may be a restart attack and we
1228 * want to send back the attacker's vtag.
1230 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1234 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1236 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1238 /* Discard the rest of the inbound packet. */
1239 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1242 /* Even if there is no memory, treat as a failure so
1243 * the packet will get dropped.
1248 static bool list_has_sctp_addr(const struct list_head
*list
,
1249 union sctp_addr
*ipaddr
)
1251 struct sctp_transport
*addr
;
1253 list_for_each_entry(addr
, list
, transports
) {
1254 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1260 /* A restart is occurring, check to make sure no new addresses
1261 * are being added as we may be under a takeover attack.
1263 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1264 const struct sctp_association
*asoc
,
1265 struct sctp_chunk
*init
,
1266 sctp_cmd_seq_t
*commands
)
1268 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1269 struct sctp_transport
*new_addr
;
1272 /* Implementor's Guide - Section 5.2.2
1274 * Before responding the endpoint MUST check to see if the
1275 * unexpected INIT adds new addresses to the association. If new
1276 * addresses are added to the association, the endpoint MUST respond
1280 /* Search through all current addresses and make sure
1281 * we aren't adding any new ones.
1283 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1285 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1286 &new_addr
->ipaddr
)) {
1287 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1294 /* Return success if all addresses were found. */
1298 /* Populate the verification/tie tags based on overlapping INIT
1301 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1303 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1304 const struct sctp_association
*asoc
)
1306 switch (asoc
->state
) {
1308 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1310 case SCTP_STATE_COOKIE_WAIT
:
1311 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1312 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1313 new_asoc
->c
.peer_ttag
= 0;
1316 case SCTP_STATE_COOKIE_ECHOED
:
1317 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1318 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1319 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1322 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1323 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1326 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1327 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1331 /* Other parameters for the endpoint SHOULD be copied from the
1332 * existing parameters of the association (e.g. number of
1333 * outbound streams) into the INIT ACK and cookie.
1335 new_asoc
->rwnd
= asoc
->rwnd
;
1336 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1337 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1338 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1342 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1345 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1347 * Returns value representing action to be taken. These action values
1348 * correspond to Action/Description values in RFC 2960, Table 2.
1350 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1351 const struct sctp_association
*asoc
)
1353 /* In this case, the peer may have restarted. */
1354 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1355 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1356 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1357 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1360 /* Collision case B. */
1361 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1362 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1363 (0 == asoc
->c
.peer_vtag
))) {
1367 /* Collision case D. */
1368 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1369 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1372 /* Collision case C. */
1373 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1374 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1375 (0 == new_asoc
->c
.my_ttag
) &&
1376 (0 == new_asoc
->c
.peer_ttag
))
1379 /* No match to any of the special cases; discard this packet. */
1383 /* Common helper routine for both duplicate and simulataneous INIT
1386 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1388 const struct sctp_endpoint
*ep
,
1389 const struct sctp_association
*asoc
,
1390 const sctp_subtype_t type
,
1391 void *arg
, sctp_cmd_seq_t
*commands
)
1393 sctp_disposition_t retval
;
1394 struct sctp_chunk
*chunk
= arg
;
1395 struct sctp_chunk
*repl
;
1396 struct sctp_association
*new_asoc
;
1397 struct sctp_chunk
*err_chunk
;
1398 struct sctp_packet
*packet
;
1399 sctp_unrecognized_param_t
*unk_param
;
1403 * An endpoint MUST NOT bundle INIT, INIT ACK or
1404 * SHUTDOWN COMPLETE with any other chunks.
1407 * Furthermore, we require that the receiver of an INIT chunk MUST
1408 * enforce these rules by silently discarding an arriving packet
1409 * with an INIT chunk that is bundled with other chunks.
1411 if (!chunk
->singleton
)
1412 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1414 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1417 if (chunk
->sctp_hdr
->vtag
!= 0)
1418 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1420 /* Make sure that the INIT chunk has a valid length.
1421 * In this case, we generate a protocol violation since we have
1422 * an association established.
1424 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1425 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1427 /* Grab the INIT header. */
1428 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1430 /* Tag the variable length parameters. */
1431 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1433 /* Verify the INIT chunk before processing it. */
1435 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
1436 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1438 /* This chunk contains fatal error. It is to be discarded.
1439 * Send an ABORT, with causes if there is any.
1442 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1443 (__u8
*)(err_chunk
->chunk_hdr
) +
1444 sizeof(sctp_chunkhdr_t
),
1445 ntohs(err_chunk
->chunk_hdr
->length
) -
1446 sizeof(sctp_chunkhdr_t
));
1449 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1450 SCTP_PACKET(packet
));
1451 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1452 retval
= SCTP_DISPOSITION_CONSUME
;
1454 retval
= SCTP_DISPOSITION_NOMEM
;
1458 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1464 * Other parameters for the endpoint SHOULD be copied from the
1465 * existing parameters of the association (e.g. number of
1466 * outbound streams) into the INIT ACK and cookie.
1467 * FIXME: We are copying parameters from the endpoint not the
1470 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1474 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1475 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1478 /* In the outbound INIT ACK the endpoint MUST copy its current
1479 * Verification Tag and Peers Verification tag into a reserved
1480 * place (local tie-tag and per tie-tag) within the state cookie.
1482 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1483 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1487 /* Make sure no new addresses are being added during the
1488 * restart. Do not do this check for COOKIE-WAIT state,
1489 * since there are no peer addresses to check against.
1490 * Upon return an ABORT will have been sent if needed.
1492 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1493 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1495 retval
= SCTP_DISPOSITION_CONSUME
;
1500 sctp_tietags_populate(new_asoc
, asoc
);
1502 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1504 /* If there are errors need to be reported for unknown parameters,
1505 * make sure to reserve enough room in the INIT ACK for them.
1509 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1510 sizeof(sctp_chunkhdr_t
);
1513 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1517 /* If there are errors need to be reported for unknown parameters,
1518 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1522 /* Get the "Unrecognized parameter" parameter(s) out of the
1523 * ERROR chunk generated by sctp_verify_init(). Since the
1524 * error cause code for "unknown parameter" and the
1525 * "Unrecognized parameter" type is the same, we can
1526 * construct the parameters in INIT ACK by copying the
1527 * ERROR causes over.
1529 unk_param
= (sctp_unrecognized_param_t
*)
1530 ((__u8
*)(err_chunk
->chunk_hdr
) +
1531 sizeof(sctp_chunkhdr_t
));
1532 /* Replace the cause code with the "Unrecognized parameter"
1535 sctp_addto_chunk(repl
, len
, unk_param
);
1538 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1539 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1542 * Note: After sending out INIT ACK with the State Cookie parameter,
1543 * "Z" MUST NOT allocate any resources for this new association.
1544 * Otherwise, "Z" will be vulnerable to resource attacks.
1546 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1547 retval
= SCTP_DISPOSITION_CONSUME
;
1552 retval
= SCTP_DISPOSITION_NOMEM
;
1555 sctp_association_free(new_asoc
);
1558 sctp_chunk_free(err_chunk
);
1563 * Handle simultaneous INIT.
1564 * This means we started an INIT and then we got an INIT request from
1567 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1568 * This usually indicates an initialization collision, i.e., each
1569 * endpoint is attempting, at about the same time, to establish an
1570 * association with the other endpoint.
1572 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1573 * endpoint MUST respond with an INIT ACK using the same parameters it
1574 * sent in its original INIT chunk (including its Verification Tag,
1575 * unchanged). These original parameters are combined with those from the
1576 * newly received INIT chunk. The endpoint shall also generate a State
1577 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1578 * INIT to calculate the State Cookie.
1580 * After that, the endpoint MUST NOT change its state, the T1-init
1581 * timer shall be left running and the corresponding TCB MUST NOT be
1582 * destroyed. The normal procedures for handling State Cookies when
1583 * a TCB exists will resolve the duplicate INITs to a single association.
1585 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1586 * its Tie-Tags with the Tag information of itself and its peer (see
1587 * section 5.2.2 for a description of the Tie-Tags).
1589 * Verification Tag: Not explicit, but an INIT can not have a valid
1590 * verification tag, so we skip the check.
1593 * (endpoint, asoc, chunk)
1596 * (asoc, reply_msg, msg_up, timers, counters)
1598 * The return value is the disposition of the chunk.
1600 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(struct net
*net
,
1601 const struct sctp_endpoint
*ep
,
1602 const struct sctp_association
*asoc
,
1603 const sctp_subtype_t type
,
1605 sctp_cmd_seq_t
*commands
)
1607 /* Call helper to do the real work for both simulataneous and
1608 * duplicate INIT chunk handling.
1610 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1614 * Handle duplicated INIT messages. These are usually delayed
1617 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1618 * COOKIE-ECHOED and COOKIE-WAIT
1620 * Unless otherwise stated, upon reception of an unexpected INIT for
1621 * this association, the endpoint shall generate an INIT ACK with a
1622 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1623 * current Verification Tag and peer's Verification Tag into a reserved
1624 * place within the state cookie. We shall refer to these locations as
1625 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1626 * containing this INIT ACK MUST carry a Verification Tag value equal to
1627 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1628 * MUST contain a new Initiation Tag (randomly generated see Section
1629 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1630 * existing parameters of the association (e.g. number of outbound
1631 * streams) into the INIT ACK and cookie.
1633 * After sending out the INIT ACK, the endpoint shall take no further
1634 * actions, i.e., the existing association, including its current state,
1635 * and the corresponding TCB MUST NOT be changed.
1637 * Note: Only when a TCB exists and the association is not in a COOKIE-
1638 * WAIT state are the Tie-Tags populated. For a normal association INIT
1639 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1640 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1641 * State Cookie are populated as specified in section 5.2.1.
1643 * Verification Tag: Not specified, but an INIT has no way of knowing
1644 * what the verification tag could be, so we ignore it.
1647 * (endpoint, asoc, chunk)
1650 * (asoc, reply_msg, msg_up, timers, counters)
1652 * The return value is the disposition of the chunk.
1654 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(struct net
*net
,
1655 const struct sctp_endpoint
*ep
,
1656 const struct sctp_association
*asoc
,
1657 const sctp_subtype_t type
,
1659 sctp_cmd_seq_t
*commands
)
1661 /* Call helper to do the real work for both simulataneous and
1662 * duplicate INIT chunk handling.
1664 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1669 * Unexpected INIT-ACK handler.
1672 * If an INIT ACK received by an endpoint in any state other than the
1673 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1674 * An unexpected INIT ACK usually indicates the processing of an old or
1675 * duplicated INIT chunk.
1677 sctp_disposition_t
sctp_sf_do_5_2_3_initack(struct net
*net
,
1678 const struct sctp_endpoint
*ep
,
1679 const struct sctp_association
*asoc
,
1680 const sctp_subtype_t type
,
1681 void *arg
, sctp_cmd_seq_t
*commands
)
1683 /* Per the above section, we'll discard the chunk if we have an
1684 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1686 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1687 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1689 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1692 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1695 * A) In this case, the peer may have restarted.
1697 static sctp_disposition_t
sctp_sf_do_dupcook_a(struct net
*net
,
1698 const struct sctp_endpoint
*ep
,
1699 const struct sctp_association
*asoc
,
1700 struct sctp_chunk
*chunk
,
1701 sctp_cmd_seq_t
*commands
,
1702 struct sctp_association
*new_asoc
)
1704 sctp_init_chunk_t
*peer_init
;
1705 struct sctp_ulpevent
*ev
;
1706 struct sctp_chunk
*repl
;
1707 struct sctp_chunk
*err
;
1708 sctp_disposition_t disposition
;
1710 /* new_asoc is a brand-new association, so these are not yet
1711 * side effects--it is safe to run them here.
1713 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1715 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1719 /* Make sure no new addresses are being added during the
1720 * restart. Though this is a pretty complicated attack
1721 * since you'd have to get inside the cookie.
1723 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1724 return SCTP_DISPOSITION_CONSUME
;
1727 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1728 * the peer has restarted (Action A), it MUST NOT setup a new
1729 * association but instead resend the SHUTDOWN ACK and send an ERROR
1730 * chunk with a "Cookie Received while Shutting Down" error cause to
1733 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1734 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1735 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1737 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1740 err
= sctp_make_op_error(asoc
, chunk
,
1741 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1744 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1747 return SCTP_DISPOSITION_CONSUME
;
1750 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1751 * data. Consider the optional choice of resending of this data.
1753 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1754 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1755 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1756 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1758 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1759 * and ASCONF-ACK cache.
1761 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1762 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1763 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1765 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1769 /* Report association restart to upper layer. */
1770 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1771 new_asoc
->c
.sinit_num_ostreams
,
1772 new_asoc
->c
.sinit_max_instreams
,
1777 /* Update the content of current association. */
1778 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1779 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1780 if (sctp_state(asoc
, SHUTDOWN_PENDING
) &&
1781 (sctp_sstate(asoc
->base
.sk
, CLOSING
) ||
1782 sock_flag(asoc
->base
.sk
, SOCK_DEAD
))) {
1783 /* if were currently in SHUTDOWN_PENDING, but the socket
1784 * has been closed by user, don't transition to ESTABLISHED.
1785 * Instead trigger SHUTDOWN bundled with COOKIE_ACK.
1787 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1788 return sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
,
1789 SCTP_ST_CHUNK(0), NULL
,
1792 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1793 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1794 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1796 return SCTP_DISPOSITION_CONSUME
;
1799 sctp_chunk_free(repl
);
1801 return SCTP_DISPOSITION_NOMEM
;
1804 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1807 * B) In this case, both sides may be attempting to start an association
1808 * at about the same time but the peer endpoint started its INIT
1809 * after responding to the local endpoint's INIT
1811 /* This case represents an initialization collision. */
1812 static sctp_disposition_t
sctp_sf_do_dupcook_b(struct net
*net
,
1813 const struct sctp_endpoint
*ep
,
1814 const struct sctp_association
*asoc
,
1815 struct sctp_chunk
*chunk
,
1816 sctp_cmd_seq_t
*commands
,
1817 struct sctp_association
*new_asoc
)
1819 sctp_init_chunk_t
*peer_init
;
1820 struct sctp_chunk
*repl
;
1822 /* new_asoc is a brand-new association, so these are not yet
1823 * side effects--it is safe to run them here.
1825 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1826 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1830 /* Update the content of current association. */
1831 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1832 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1833 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1834 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1835 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1837 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1841 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1843 /* RFC 2960 5.1 Normal Establishment of an Association
1845 * D) IMPLEMENTATION NOTE: An implementation may choose to
1846 * send the Communication Up notification to the SCTP user
1847 * upon reception of a valid COOKIE ECHO chunk.
1849 * Sadly, this needs to be implemented as a side-effect, because
1850 * we are not guaranteed to have set the association id of the real
1851 * association and so these notifications need to be delayed until
1852 * the association id is allocated.
1855 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1857 /* Sockets API Draft Section 5.3.1.6
1858 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1859 * delivers this notification to inform the application that of the
1860 * peers requested adaptation layer.
1862 * This also needs to be done as a side effect for the same reason as
1865 if (asoc
->peer
.adaptation_ind
)
1866 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1868 return SCTP_DISPOSITION_CONSUME
;
1871 return SCTP_DISPOSITION_NOMEM
;
1874 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1877 * C) In this case, the local endpoint's cookie has arrived late.
1878 * Before it arrived, the local endpoint sent an INIT and received an
1879 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1880 * but a new tag of its own.
1882 /* This case represents an initialization collision. */
1883 static sctp_disposition_t
sctp_sf_do_dupcook_c(struct net
*net
,
1884 const struct sctp_endpoint
*ep
,
1885 const struct sctp_association
*asoc
,
1886 struct sctp_chunk
*chunk
,
1887 sctp_cmd_seq_t
*commands
,
1888 struct sctp_association
*new_asoc
)
1890 /* The cookie should be silently discarded.
1891 * The endpoint SHOULD NOT change states and should leave
1892 * any timers running.
1894 return SCTP_DISPOSITION_DISCARD
;
1897 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1901 * D) When both local and remote tags match the endpoint should always
1902 * enter the ESTABLISHED state, if it has not already done so.
1904 /* This case represents an initialization collision. */
1905 static sctp_disposition_t
sctp_sf_do_dupcook_d(struct net
*net
,
1906 const struct sctp_endpoint
*ep
,
1907 const struct sctp_association
*asoc
,
1908 struct sctp_chunk
*chunk
,
1909 sctp_cmd_seq_t
*commands
,
1910 struct sctp_association
*new_asoc
)
1912 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1913 struct sctp_chunk
*repl
;
1915 /* Clarification from Implementor's Guide:
1916 * D) When both local and remote tags match the endpoint should
1917 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1918 * It should stop any cookie timer that may be running and send
1922 /* Don't accidentally move back into established state. */
1923 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1924 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1925 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1926 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1927 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1928 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1929 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1932 /* RFC 2960 5.1 Normal Establishment of an Association
1934 * D) IMPLEMENTATION NOTE: An implementation may choose
1935 * to send the Communication Up notification to the
1936 * SCTP user upon reception of a valid COOKIE
1939 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1941 asoc
->c
.sinit_num_ostreams
,
1942 asoc
->c
.sinit_max_instreams
,
1947 /* Sockets API Draft Section 5.3.1.6
1948 * When a peer sends a Adaptation Layer Indication parameter,
1949 * SCTP delivers this notification to inform the application
1950 * that of the peers requested adaptation layer.
1952 if (asoc
->peer
.adaptation_ind
) {
1953 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1961 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1965 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1968 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1971 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1972 SCTP_ULPEVENT(ai_ev
));
1974 return SCTP_DISPOSITION_CONSUME
;
1978 sctp_ulpevent_free(ai_ev
);
1980 sctp_ulpevent_free(ev
);
1981 return SCTP_DISPOSITION_NOMEM
;
1985 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1986 * chunk was retransmitted and then delayed in the network.
1988 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1990 * Verification Tag: None. Do cookie validation.
1993 * (endpoint, asoc, chunk)
1996 * (asoc, reply_msg, msg_up, timers, counters)
1998 * The return value is the disposition of the chunk.
2000 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(struct net
*net
,
2001 const struct sctp_endpoint
*ep
,
2002 const struct sctp_association
*asoc
,
2003 const sctp_subtype_t type
,
2005 sctp_cmd_seq_t
*commands
)
2007 sctp_disposition_t retval
;
2008 struct sctp_chunk
*chunk
= arg
;
2009 struct sctp_association
*new_asoc
;
2012 struct sctp_chunk
*err_chk_p
;
2014 /* Make sure that the chunk has a valid length from the protocol
2015 * perspective. In this case check to make sure we have at least
2016 * enough for the chunk header. Cookie length verification is
2019 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2020 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2023 /* "Decode" the chunk. We have no optional parameters so we
2024 * are in good shape.
2026 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2027 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2028 sizeof(sctp_chunkhdr_t
)))
2031 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2032 * of a duplicate COOKIE ECHO match the Verification Tags of the
2033 * current association, consider the State Cookie valid even if
2034 * the lifespan is exceeded.
2036 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2040 * If the re-build failed, what is the proper error path
2043 * [We should abort the association. --piggy]
2046 /* FIXME: Several errors are possible. A bad cookie should
2047 * be silently discarded, but think about logging it too.
2050 case -SCTP_IERROR_NOMEM
:
2053 case -SCTP_IERROR_STALE_COOKIE
:
2054 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2056 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2057 case -SCTP_IERROR_BAD_SIG
:
2059 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2063 /* Compare the tie_tag in cookie with the verification tag of
2064 * current association.
2066 action
= sctp_tietags_compare(new_asoc
, asoc
);
2069 case 'A': /* Association restart. */
2070 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2074 case 'B': /* Collision case B. */
2075 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2079 case 'C': /* Collision case C. */
2080 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2084 case 'D': /* Collision case D. */
2085 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2089 default: /* Discard packet for all others. */
2090 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2094 /* Delete the tempory new association. */
2095 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
, SCTP_ASOC(new_asoc
));
2096 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2098 /* Restore association pointer to provide SCTP command interpeter
2099 * with a valid context in case it needs to manipulate
2101 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2102 SCTP_ASOC((struct sctp_association
*)asoc
));
2107 return SCTP_DISPOSITION_NOMEM
;
2111 * Process an ABORT. (SHUTDOWN-PENDING state)
2113 * See sctp_sf_do_9_1_abort().
2115 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2117 const struct sctp_endpoint
*ep
,
2118 const struct sctp_association
*asoc
,
2119 const sctp_subtype_t type
,
2121 sctp_cmd_seq_t
*commands
)
2123 struct sctp_chunk
*chunk
= arg
;
2125 if (!sctp_vtag_verify_either(chunk
, asoc
))
2126 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2128 /* Make sure that the ABORT chunk has a valid length.
2129 * Since this is an ABORT chunk, we have to discard it
2130 * because of the following text:
2131 * RFC 2960, Section 3.3.7
2132 * If an endpoint receives an ABORT with a format error or for an
2133 * association that doesn't exist, it MUST silently discard it.
2134 * Because the length is "invalid", we can't really discard just
2135 * as we do not know its true length. So, to be safe, discard the
2138 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2139 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2141 /* ADD-IP: Special case for ABORT chunks
2142 * F4) One special consideration is that ABORT Chunks arriving
2143 * destined to the IP address being deleted MUST be
2144 * ignored (see Section 5.3.1 for further details).
2146 if (SCTP_ADDR_DEL
==
2147 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2148 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2150 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2154 * Process an ABORT. (SHUTDOWN-SENT state)
2156 * See sctp_sf_do_9_1_abort().
2158 sctp_disposition_t
sctp_sf_shutdown_sent_abort(struct net
*net
,
2159 const struct sctp_endpoint
*ep
,
2160 const struct sctp_association
*asoc
,
2161 const sctp_subtype_t type
,
2163 sctp_cmd_seq_t
*commands
)
2165 struct sctp_chunk
*chunk
= arg
;
2167 if (!sctp_vtag_verify_either(chunk
, asoc
))
2168 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2170 /* Make sure that the ABORT chunk has a valid length.
2171 * Since this is an ABORT chunk, we have to discard it
2172 * because of the following text:
2173 * RFC 2960, Section 3.3.7
2174 * If an endpoint receives an ABORT with a format error or for an
2175 * association that doesn't exist, it MUST silently discard it.
2176 * Because the length is "invalid", we can't really discard just
2177 * as we do not know its true length. So, to be safe, discard the
2180 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2181 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2183 /* ADD-IP: Special case for ABORT chunks
2184 * F4) One special consideration is that ABORT Chunks arriving
2185 * destined to the IP address being deleted MUST be
2186 * ignored (see Section 5.3.1 for further details).
2188 if (SCTP_ADDR_DEL
==
2189 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2190 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2192 /* Stop the T2-shutdown timer. */
2193 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2194 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2196 /* Stop the T5-shutdown guard timer. */
2197 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2198 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2200 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2204 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2206 * See sctp_sf_do_9_1_abort().
2208 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2210 const struct sctp_endpoint
*ep
,
2211 const struct sctp_association
*asoc
,
2212 const sctp_subtype_t type
,
2214 sctp_cmd_seq_t
*commands
)
2216 /* The same T2 timer, so we should be able to use
2217 * common function with the SHUTDOWN-SENT state.
2219 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2223 * Handle an Error received in COOKIE_ECHOED state.
2225 * Only handle the error type of stale COOKIE Error, the other errors will
2229 * (endpoint, asoc, chunk)
2232 * (asoc, reply_msg, msg_up, timers, counters)
2234 * The return value is the disposition of the chunk.
2236 sctp_disposition_t
sctp_sf_cookie_echoed_err(struct net
*net
,
2237 const struct sctp_endpoint
*ep
,
2238 const struct sctp_association
*asoc
,
2239 const sctp_subtype_t type
,
2241 sctp_cmd_seq_t
*commands
)
2243 struct sctp_chunk
*chunk
= arg
;
2246 if (!sctp_vtag_verify(chunk
, asoc
))
2247 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2249 /* Make sure that the ERROR chunk has a valid length.
2250 * The parameter walking depends on this as well.
2252 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2253 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2256 /* Process the error here */
2257 /* FUTURE FIXME: When PR-SCTP related and other optional
2258 * parms are emitted, this will have to change to handle multiple
2261 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2262 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2263 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2267 /* It is possible to have malformed error causes, and that
2268 * will cause us to end the walk early. However, since
2269 * we are discarding the packet, there should be no adverse
2272 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2276 * Handle a Stale COOKIE Error
2278 * Section: 5.2.6 Handle Stale COOKIE Error
2279 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2280 * one of the following three alternatives.
2282 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2283 * Preservative parameter requesting an extension to the lifetime of
2284 * the State Cookie. When calculating the time extension, an
2285 * implementation SHOULD use the RTT information measured based on the
2286 * previous COOKIE ECHO / ERROR exchange, and should add no more
2287 * than 1 second beyond the measured RTT, due to long State Cookie
2288 * lifetimes making the endpoint more subject to a replay attack.
2290 * Verification Tag: Not explicit, but safe to ignore.
2293 * (endpoint, asoc, chunk)
2296 * (asoc, reply_msg, msg_up, timers, counters)
2298 * The return value is the disposition of the chunk.
2300 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(struct net
*net
,
2301 const struct sctp_endpoint
*ep
,
2302 const struct sctp_association
*asoc
,
2303 const sctp_subtype_t type
,
2305 sctp_cmd_seq_t
*commands
)
2307 struct sctp_chunk
*chunk
= arg
;
2309 sctp_cookie_preserve_param_t bht
;
2311 struct sctp_chunk
*reply
;
2312 struct sctp_bind_addr
*bp
;
2313 int attempts
= asoc
->init_err_counter
+ 1;
2315 if (attempts
> asoc
->max_init_attempts
) {
2316 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2317 SCTP_ERROR(ETIMEDOUT
));
2318 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2319 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2320 return SCTP_DISPOSITION_DELETE_TCB
;
2323 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2325 /* When calculating the time extension, an implementation
2326 * SHOULD use the RTT information measured based on the
2327 * previous COOKIE ECHO / ERROR exchange, and should add no
2328 * more than 1 second beyond the measured RTT, due to long
2329 * State Cookie lifetimes making the endpoint more subject to
2331 * Measure of Staleness's unit is usec. (1/1000000 sec)
2332 * Suggested Cookie Life-span Increment's unit is msec.
2334 * In general, if you use the suggested cookie life, the value
2335 * found in the field of measure of staleness should be doubled
2336 * to give ample time to retransmit the new cookie and thus
2337 * yield a higher probability of success on the reattempt.
2339 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2340 stale
= (stale
* 2) / 1000;
2342 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2343 bht
.param_hdr
.length
= htons(sizeof(bht
));
2344 bht
.lifespan_increment
= htonl(stale
);
2346 /* Build that new INIT chunk. */
2347 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2348 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2352 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2354 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2355 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2357 /* Stop pending T3-rtx and heartbeat timers */
2358 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2359 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2361 /* Delete non-primary peer ip addresses since we are transitioning
2362 * back to the COOKIE-WAIT state
2364 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2366 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2369 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2370 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2372 /* Cast away the const modifier, as we want to just
2373 * rerun it through as a sideffect.
2375 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2377 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2378 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2379 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2380 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2381 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2382 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2384 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2386 return SCTP_DISPOSITION_CONSUME
;
2389 return SCTP_DISPOSITION_NOMEM
;
2396 * After checking the Verification Tag, the receiving endpoint shall
2397 * remove the association from its record, and shall report the
2398 * termination to its upper layer.
2400 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2401 * B) Rules for packet carrying ABORT:
2403 * - The endpoint shall always fill in the Verification Tag field of the
2404 * outbound packet with the destination endpoint's tag value if it
2407 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2408 * MUST follow the procedure described in Section 8.4.
2410 * - The receiver MUST accept the packet if the Verification Tag
2411 * matches either its own tag, OR the tag of its peer. Otherwise, the
2412 * receiver MUST silently discard the packet and take no further
2416 * (endpoint, asoc, chunk)
2419 * (asoc, reply_msg, msg_up, timers, counters)
2421 * The return value is the disposition of the chunk.
2423 sctp_disposition_t
sctp_sf_do_9_1_abort(struct net
*net
,
2424 const struct sctp_endpoint
*ep
,
2425 const struct sctp_association
*asoc
,
2426 const sctp_subtype_t type
,
2428 sctp_cmd_seq_t
*commands
)
2430 struct sctp_chunk
*chunk
= arg
;
2432 if (!sctp_vtag_verify_either(chunk
, asoc
))
2433 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2435 /* Make sure that the ABORT chunk has a valid length.
2436 * Since this is an ABORT chunk, we have to discard it
2437 * because of the following text:
2438 * RFC 2960, Section 3.3.7
2439 * If an endpoint receives an ABORT with a format error or for an
2440 * association that doesn't exist, it MUST silently discard it.
2441 * Because the length is "invalid", we can't really discard just
2442 * as we do not know its true length. So, to be safe, discard the
2445 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2446 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2448 /* ADD-IP: Special case for ABORT chunks
2449 * F4) One special consideration is that ABORT Chunks arriving
2450 * destined to the IP address being deleted MUST be
2451 * ignored (see Section 5.3.1 for further details).
2453 if (SCTP_ADDR_DEL
==
2454 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2455 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2457 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2460 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
2461 const struct sctp_endpoint
*ep
,
2462 const struct sctp_association
*asoc
,
2463 const sctp_subtype_t type
,
2465 sctp_cmd_seq_t
*commands
)
2467 struct sctp_chunk
*chunk
= arg
;
2469 __be16 error
= SCTP_ERROR_NO_ERROR
;
2471 /* See if we have an error cause code in the chunk. */
2472 len
= ntohs(chunk
->chunk_hdr
->length
);
2473 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2476 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2477 if ((void *)err
!= (void *)chunk
->chunk_end
)
2478 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2480 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2483 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2484 /* ASSOC_FAILED will DELETE_TCB. */
2485 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2486 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2487 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2489 return SCTP_DISPOSITION_ABORT
;
2493 * Process an ABORT. (COOKIE-WAIT state)
2495 * See sctp_sf_do_9_1_abort() above.
2497 sctp_disposition_t
sctp_sf_cookie_wait_abort(struct net
*net
,
2498 const struct sctp_endpoint
*ep
,
2499 const struct sctp_association
*asoc
,
2500 const sctp_subtype_t type
,
2502 sctp_cmd_seq_t
*commands
)
2504 struct sctp_chunk
*chunk
= arg
;
2506 __be16 error
= SCTP_ERROR_NO_ERROR
;
2508 if (!sctp_vtag_verify_either(chunk
, asoc
))
2509 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2511 /* Make sure that the ABORT chunk has a valid length.
2512 * Since this is an ABORT chunk, we have to discard it
2513 * because of the following text:
2514 * RFC 2960, Section 3.3.7
2515 * If an endpoint receives an ABORT with a format error or for an
2516 * association that doesn't exist, it MUST silently discard it.
2517 * Because the length is "invalid", we can't really discard just
2518 * as we do not know its true length. So, to be safe, discard the
2521 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2522 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2524 /* See if we have an error cause code in the chunk. */
2525 len
= ntohs(chunk
->chunk_hdr
->length
);
2526 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2527 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2529 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2534 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2536 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(struct net
*net
,
2537 const struct sctp_endpoint
*ep
,
2538 const struct sctp_association
*asoc
,
2539 const sctp_subtype_t type
,
2541 sctp_cmd_seq_t
*commands
)
2543 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2545 (struct sctp_transport
*)arg
);
2549 * Process an ABORT. (COOKIE-ECHOED state)
2551 sctp_disposition_t
sctp_sf_cookie_echoed_abort(struct net
*net
,
2552 const struct sctp_endpoint
*ep
,
2553 const struct sctp_association
*asoc
,
2554 const sctp_subtype_t type
,
2556 sctp_cmd_seq_t
*commands
)
2558 /* There is a single T1 timer, so we should be able to use
2559 * common function with the COOKIE-WAIT state.
2561 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2565 * Stop T1 timer and abort association with "INIT failed".
2567 * This is common code called by several sctp_sf_*_abort() functions above.
2569 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
2570 sctp_cmd_seq_t
*commands
,
2571 __be16 error
, int sk_err
,
2572 const struct sctp_association
*asoc
,
2573 struct sctp_transport
*transport
)
2575 pr_debug("%s: ABORT received (INIT)\n", __func__
);
2577 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2578 SCTP_STATE(SCTP_STATE_CLOSED
));
2579 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2580 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2581 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2582 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2583 /* CMD_INIT_FAILED will DELETE_TCB. */
2584 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2587 return SCTP_DISPOSITION_ABORT
;
2591 * sctp_sf_do_9_2_shut
2594 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2595 * - enter the SHUTDOWN-RECEIVED state,
2597 * - stop accepting new data from its SCTP user
2599 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2600 * that all its outstanding DATA chunks have been received by the
2603 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2604 * send a SHUTDOWN in response to a ULP request. And should discard
2605 * subsequent SHUTDOWN chunks.
2607 * If there are still outstanding DATA chunks left, the SHUTDOWN
2608 * receiver shall continue to follow normal data transmission
2609 * procedures defined in Section 6 until all outstanding DATA chunks
2610 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2611 * new data from its SCTP user.
2613 * Verification Tag: 8.5 Verification Tag [Normal verification]
2616 * (endpoint, asoc, chunk)
2619 * (asoc, reply_msg, msg_up, timers, counters)
2621 * The return value is the disposition of the chunk.
2623 sctp_disposition_t
sctp_sf_do_9_2_shutdown(struct net
*net
,
2624 const struct sctp_endpoint
*ep
,
2625 const struct sctp_association
*asoc
,
2626 const sctp_subtype_t type
,
2628 sctp_cmd_seq_t
*commands
)
2630 struct sctp_chunk
*chunk
= arg
;
2631 sctp_shutdownhdr_t
*sdh
;
2632 sctp_disposition_t disposition
;
2633 struct sctp_ulpevent
*ev
;
2636 if (!sctp_vtag_verify(chunk
, asoc
))
2637 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2639 /* Make sure that the SHUTDOWN chunk has a valid length. */
2640 if (!sctp_chunk_length_valid(chunk
,
2641 sizeof(struct sctp_shutdown_chunk_t
)))
2642 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2645 /* Convert the elaborate header. */
2646 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2647 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2648 chunk
->subh
.shutdown_hdr
= sdh
;
2649 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2651 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2652 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2653 asoc
->ctsn_ack_point
);
2655 return SCTP_DISPOSITION_DISCARD
;
2658 /* If Cumulative TSN Ack beyond the max tsn currently
2659 * send, terminating the association and respond to the
2660 * sender with an ABORT.
2662 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2663 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2665 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2666 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2667 * inform the application that it should cease sending data.
2669 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2671 disposition
= SCTP_DISPOSITION_NOMEM
;
2674 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2676 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2677 * - enter the SHUTDOWN-RECEIVED state,
2678 * - stop accepting new data from its SCTP user
2680 * [This is implicit in the new state.]
2682 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2683 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2684 disposition
= SCTP_DISPOSITION_CONSUME
;
2686 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2687 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2691 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2694 /* - verify, by checking the Cumulative TSN Ack field of the
2695 * chunk, that all its outstanding DATA chunks have been
2696 * received by the SHUTDOWN sender.
2698 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2699 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2706 * sctp_sf_do_9_2_shut_ctsn
2708 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2709 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2710 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2711 * MUST be processed.
2713 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(struct net
*net
,
2714 const struct sctp_endpoint
*ep
,
2715 const struct sctp_association
*asoc
,
2716 const sctp_subtype_t type
,
2718 sctp_cmd_seq_t
*commands
)
2720 struct sctp_chunk
*chunk
= arg
;
2721 sctp_shutdownhdr_t
*sdh
;
2724 if (!sctp_vtag_verify(chunk
, asoc
))
2725 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2727 /* Make sure that the SHUTDOWN chunk has a valid length. */
2728 if (!sctp_chunk_length_valid(chunk
,
2729 sizeof(struct sctp_shutdown_chunk_t
)))
2730 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2733 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2734 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2736 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2737 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2738 asoc
->ctsn_ack_point
);
2740 return SCTP_DISPOSITION_DISCARD
;
2743 /* If Cumulative TSN Ack beyond the max tsn currently
2744 * send, terminating the association and respond to the
2745 * sender with an ABORT.
2747 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2748 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2750 /* verify, by checking the Cumulative TSN Ack field of the
2751 * chunk, that all its outstanding DATA chunks have been
2752 * received by the SHUTDOWN sender.
2754 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2755 SCTP_BE32(sdh
->cum_tsn_ack
));
2757 return SCTP_DISPOSITION_CONSUME
;
2761 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2762 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2763 * transport addresses (either in the IP addresses or in the INIT chunk)
2764 * that belong to this association, it should discard the INIT chunk and
2765 * retransmit the SHUTDOWN ACK chunk.
2767 sctp_disposition_t
sctp_sf_do_9_2_reshutack(struct net
*net
,
2768 const struct sctp_endpoint
*ep
,
2769 const struct sctp_association
*asoc
,
2770 const sctp_subtype_t type
,
2772 sctp_cmd_seq_t
*commands
)
2774 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2775 struct sctp_chunk
*reply
;
2777 /* Make sure that the chunk has a valid length */
2778 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2779 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2782 /* Since we are not going to really process this INIT, there
2783 * is no point in verifying chunk boundries. Just generate
2786 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2790 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2791 * the T2-SHUTDOWN timer.
2793 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2795 /* and restart the T2-shutdown timer. */
2796 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2797 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2799 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2801 return SCTP_DISPOSITION_CONSUME
;
2803 return SCTP_DISPOSITION_NOMEM
;
2807 * sctp_sf_do_ecn_cwr
2809 * Section: Appendix A: Explicit Congestion Notification
2813 * RFC 2481 details a specific bit for a sender to send in the header of
2814 * its next outbound TCP segment to indicate to its peer that it has
2815 * reduced its congestion window. This is termed the CWR bit. For
2816 * SCTP the same indication is made by including the CWR chunk.
2817 * This chunk contains one data element, i.e. the TSN number that
2818 * was sent in the ECNE chunk. This element represents the lowest
2819 * TSN number in the datagram that was originally marked with the
2822 * Verification Tag: 8.5 Verification Tag [Normal verification]
2824 * (endpoint, asoc, chunk)
2827 * (asoc, reply_msg, msg_up, timers, counters)
2829 * The return value is the disposition of the chunk.
2831 sctp_disposition_t
sctp_sf_do_ecn_cwr(struct net
*net
,
2832 const struct sctp_endpoint
*ep
,
2833 const struct sctp_association
*asoc
,
2834 const sctp_subtype_t type
,
2836 sctp_cmd_seq_t
*commands
)
2839 struct sctp_chunk
*chunk
= arg
;
2842 if (!sctp_vtag_verify(chunk
, asoc
))
2843 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2845 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2846 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2849 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2850 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2852 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2854 /* Does this CWR ack the last sent congestion notification? */
2855 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2856 /* Stop sending ECNE. */
2857 sctp_add_cmd_sf(commands
,
2859 SCTP_U32(lowest_tsn
));
2861 return SCTP_DISPOSITION_CONSUME
;
2867 * Section: Appendix A: Explicit Congestion Notification
2871 * RFC 2481 details a specific bit for a receiver to send back in its
2872 * TCP acknowledgements to notify the sender of the Congestion
2873 * Experienced (CE) bit having arrived from the network. For SCTP this
2874 * same indication is made by including the ECNE chunk. This chunk
2875 * contains one data element, i.e. the lowest TSN associated with the IP
2876 * datagram marked with the CE bit.....
2878 * Verification Tag: 8.5 Verification Tag [Normal verification]
2880 * (endpoint, asoc, chunk)
2883 * (asoc, reply_msg, msg_up, timers, counters)
2885 * The return value is the disposition of the chunk.
2887 sctp_disposition_t
sctp_sf_do_ecne(struct net
*net
,
2888 const struct sctp_endpoint
*ep
,
2889 const struct sctp_association
*asoc
,
2890 const sctp_subtype_t type
,
2892 sctp_cmd_seq_t
*commands
)
2894 sctp_ecnehdr_t
*ecne
;
2895 struct sctp_chunk
*chunk
= arg
;
2897 if (!sctp_vtag_verify(chunk
, asoc
))
2898 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2900 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2901 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2904 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2905 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2907 /* If this is a newer ECNE than the last CWR packet we sent out */
2908 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2909 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2911 return SCTP_DISPOSITION_CONSUME
;
2915 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2917 * The SCTP endpoint MUST always acknowledge the reception of each valid
2920 * The guidelines on delayed acknowledgement algorithm specified in
2921 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2922 * acknowledgement SHOULD be generated for at least every second packet
2923 * (not every second DATA chunk) received, and SHOULD be generated within
2924 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2925 * situations it may be beneficial for an SCTP transmitter to be more
2926 * conservative than the algorithms detailed in this document allow.
2927 * However, an SCTP transmitter MUST NOT be more aggressive than the
2928 * following algorithms allow.
2930 * A SCTP receiver MUST NOT generate more than one SACK for every
2931 * incoming packet, other than to update the offered window as the
2932 * receiving application consumes new data.
2934 * Verification Tag: 8.5 Verification Tag [Normal verification]
2937 * (endpoint, asoc, chunk)
2940 * (asoc, reply_msg, msg_up, timers, counters)
2942 * The return value is the disposition of the chunk.
2944 sctp_disposition_t
sctp_sf_eat_data_6_2(struct net
*net
,
2945 const struct sctp_endpoint
*ep
,
2946 const struct sctp_association
*asoc
,
2947 const sctp_subtype_t type
,
2949 sctp_cmd_seq_t
*commands
)
2951 struct sctp_chunk
*chunk
= arg
;
2952 sctp_arg_t force
= SCTP_NOFORCE();
2955 if (!sctp_vtag_verify(chunk
, asoc
)) {
2956 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2958 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2961 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2962 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2965 error
= sctp_eat_data(asoc
, chunk
, commands
);
2967 case SCTP_IERROR_NO_ERROR
:
2969 case SCTP_IERROR_HIGH_TSN
:
2970 case SCTP_IERROR_BAD_STREAM
:
2971 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2972 goto discard_noforce
;
2973 case SCTP_IERROR_DUP_TSN
:
2974 case SCTP_IERROR_IGNORE_TSN
:
2975 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2977 case SCTP_IERROR_NO_DATA
:
2978 return SCTP_DISPOSITION_ABORT
;
2979 case SCTP_IERROR_PROTO_VIOLATION
:
2980 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
2981 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2986 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
2987 force
= SCTP_FORCE();
2989 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
2990 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2991 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2994 /* If this is the last chunk in a packet, we need to count it
2995 * toward sack generation. Note that we need to SACK every
2996 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2997 * THEM. We elect to NOT generate SACK's if the chunk fails
2998 * the verification tag test.
3000 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3002 * The SCTP endpoint MUST always acknowledge the reception of
3003 * each valid DATA chunk.
3005 * The guidelines on delayed acknowledgement algorithm
3006 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3007 * Specifically, an acknowledgement SHOULD be generated for at
3008 * least every second packet (not every second DATA chunk)
3009 * received, and SHOULD be generated within 200 ms of the
3010 * arrival of any unacknowledged DATA chunk. In some
3011 * situations it may be beneficial for an SCTP transmitter to
3012 * be more conservative than the algorithms detailed in this
3013 * document allow. However, an SCTP transmitter MUST NOT be
3014 * more aggressive than the following algorithms allow.
3016 if (chunk
->end_of_packet
)
3017 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3019 return SCTP_DISPOSITION_CONSUME
;
3022 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3024 * When a packet arrives with duplicate DATA chunk(s) and with
3025 * no new DATA chunk(s), the endpoint MUST immediately send a
3026 * SACK with no delay. If a packet arrives with duplicate
3027 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3028 * MAY immediately send a SACK. Normally receipt of duplicate
3029 * DATA chunks will occur when the original SACK chunk was lost
3030 * and the peer's RTO has expired. The duplicate TSN number(s)
3031 * SHOULD be reported in the SACK as duplicate.
3033 /* In our case, we split the MAY SACK advice up whether or not
3034 * the last chunk is a duplicate.'
3036 if (chunk
->end_of_packet
)
3037 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3038 return SCTP_DISPOSITION_DISCARD
;
3041 if (chunk
->end_of_packet
)
3042 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3044 return SCTP_DISPOSITION_DISCARD
;
3048 * sctp_sf_eat_data_fast_4_4
3051 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3052 * DATA chunks without delay.
3054 * Verification Tag: 8.5 Verification Tag [Normal verification]
3056 * (endpoint, asoc, chunk)
3059 * (asoc, reply_msg, msg_up, timers, counters)
3061 * The return value is the disposition of the chunk.
3063 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(struct net
*net
,
3064 const struct sctp_endpoint
*ep
,
3065 const struct sctp_association
*asoc
,
3066 const sctp_subtype_t type
,
3068 sctp_cmd_seq_t
*commands
)
3070 struct sctp_chunk
*chunk
= arg
;
3073 if (!sctp_vtag_verify(chunk
, asoc
)) {
3074 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3076 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3079 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
3080 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3083 error
= sctp_eat_data(asoc
, chunk
, commands
);
3085 case SCTP_IERROR_NO_ERROR
:
3086 case SCTP_IERROR_HIGH_TSN
:
3087 case SCTP_IERROR_DUP_TSN
:
3088 case SCTP_IERROR_IGNORE_TSN
:
3089 case SCTP_IERROR_BAD_STREAM
:
3091 case SCTP_IERROR_NO_DATA
:
3092 return SCTP_DISPOSITION_ABORT
;
3093 case SCTP_IERROR_PROTO_VIOLATION
:
3094 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3095 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
3100 /* Go a head and force a SACK, since we are shutting down. */
3102 /* Implementor's Guide.
3104 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3105 * respond to each received packet containing one or more DATA chunk(s)
3106 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3108 if (chunk
->end_of_packet
) {
3109 /* We must delay the chunk creation since the cumulative
3110 * TSN has not been updated yet.
3112 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3113 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3114 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3115 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3118 return SCTP_DISPOSITION_CONSUME
;
3122 * Section: 6.2 Processing a Received SACK
3123 * D) Any time a SACK arrives, the endpoint performs the following:
3125 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3126 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3127 * increasing, a SACK whose Cumulative TSN Ack is less than the
3128 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3130 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3131 * of bytes still outstanding after processing the Cumulative TSN Ack
3132 * and the Gap Ack Blocks.
3134 * iii) If the SACK is missing a TSN that was previously
3135 * acknowledged via a Gap Ack Block (e.g., the data receiver
3136 * reneged on the data), then mark the corresponding DATA chunk
3137 * as available for retransmit: Mark it as missing for fast
3138 * retransmit as described in Section 7.2.4 and if no retransmit
3139 * timer is running for the destination address to which the DATA
3140 * chunk was originally transmitted, then T3-rtx is started for
3141 * that destination address.
3143 * Verification Tag: 8.5 Verification Tag [Normal verification]
3146 * (endpoint, asoc, chunk)
3149 * (asoc, reply_msg, msg_up, timers, counters)
3151 * The return value is the disposition of the chunk.
3153 sctp_disposition_t
sctp_sf_eat_sack_6_2(struct net
*net
,
3154 const struct sctp_endpoint
*ep
,
3155 const struct sctp_association
*asoc
,
3156 const sctp_subtype_t type
,
3158 sctp_cmd_seq_t
*commands
)
3160 struct sctp_chunk
*chunk
= arg
;
3161 sctp_sackhdr_t
*sackh
;
3164 if (!sctp_vtag_verify(chunk
, asoc
))
3165 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3167 /* Make sure that the SACK chunk has a valid length. */
3168 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3169 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3172 /* Pull the SACK chunk from the data buffer */
3173 sackh
= sctp_sm_pull_sack(chunk
);
3174 /* Was this a bogus SACK? */
3176 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3177 chunk
->subh
.sack_hdr
= sackh
;
3178 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3180 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3181 * Ack Point, then drop the SACK. Since Cumulative TSN
3182 * Ack is monotonically increasing, a SACK whose
3183 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3184 * Point indicates an out-of-order SACK.
3186 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3187 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
3188 asoc
->ctsn_ack_point
);
3190 return SCTP_DISPOSITION_DISCARD
;
3193 /* If Cumulative TSN Ack beyond the max tsn currently
3194 * send, terminating the association and respond to the
3195 * sender with an ABORT.
3197 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3198 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3200 /* Return this SACK for further processing. */
3201 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3203 /* Note: We do the rest of the work on the PROCESS_SACK
3206 return SCTP_DISPOSITION_CONSUME
;
3210 * Generate an ABORT in response to a packet.
3212 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3214 * 8) The receiver should respond to the sender of the OOTB packet with
3215 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3216 * MUST fill in the Verification Tag field of the outbound packet
3217 * with the value found in the Verification Tag field of the OOTB
3218 * packet and set the T-bit in the Chunk Flags to indicate that the
3219 * Verification Tag is reflected. After sending this ABORT, the
3220 * receiver of the OOTB packet shall discard the OOTB packet and take
3221 * no further action.
3225 * The return value is the disposition of the chunk.
3227 static sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
3228 const struct sctp_endpoint
*ep
,
3229 const struct sctp_association
*asoc
,
3230 const sctp_subtype_t type
,
3232 sctp_cmd_seq_t
*commands
)
3234 struct sctp_packet
*packet
= NULL
;
3235 struct sctp_chunk
*chunk
= arg
;
3236 struct sctp_chunk
*abort
;
3238 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3240 return SCTP_DISPOSITION_NOMEM
;
3242 /* Make an ABORT. The T bit will be set if the asoc
3245 abort
= sctp_make_abort(asoc
, chunk
, 0);
3247 sctp_ootb_pkt_free(packet
);
3248 return SCTP_DISPOSITION_NOMEM
;
3251 /* Reflect vtag if T-Bit is set */
3252 if (sctp_test_T_bit(abort
))
3253 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3255 /* Set the skb to the belonging sock for accounting. */
3256 abort
->skb
->sk
= ep
->base
.sk
;
3258 sctp_packet_append_chunk(packet
, abort
);
3260 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3261 SCTP_PACKET(packet
));
3263 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3265 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3266 return SCTP_DISPOSITION_CONSUME
;
3270 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3271 * event as ULP notification for each cause included in the chunk.
3273 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3275 * The return value is the disposition of the chunk.
3277 sctp_disposition_t
sctp_sf_operr_notify(struct net
*net
,
3278 const struct sctp_endpoint
*ep
,
3279 const struct sctp_association
*asoc
,
3280 const sctp_subtype_t type
,
3282 sctp_cmd_seq_t
*commands
)
3284 struct sctp_chunk
*chunk
= arg
;
3287 if (!sctp_vtag_verify(chunk
, asoc
))
3288 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3290 /* Make sure that the ERROR chunk has a valid length. */
3291 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3292 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3294 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3295 if ((void *)err
!= (void *)chunk
->chunk_end
)
3296 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3297 (void *)err
, commands
);
3299 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3302 return SCTP_DISPOSITION_CONSUME
;
3306 * Process an inbound SHUTDOWN ACK.
3309 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3310 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3311 * peer, and remove all record of the association.
3313 * The return value is the disposition.
3315 sctp_disposition_t
sctp_sf_do_9_2_final(struct net
*net
,
3316 const struct sctp_endpoint
*ep
,
3317 const struct sctp_association
*asoc
,
3318 const sctp_subtype_t type
,
3320 sctp_cmd_seq_t
*commands
)
3322 struct sctp_chunk
*chunk
= arg
;
3323 struct sctp_chunk
*reply
;
3324 struct sctp_ulpevent
*ev
;
3326 if (!sctp_vtag_verify(chunk
, asoc
))
3327 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3329 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3330 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3331 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3333 /* 10.2 H) SHUTDOWN COMPLETE notification
3335 * When SCTP completes the shutdown procedures (section 9.2) this
3336 * notification is passed to the upper layer.
3338 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3339 0, 0, 0, NULL
, GFP_ATOMIC
);
3343 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3344 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3348 /* Do all the commands now (after allocation), so that we
3349 * have consistent state if memory allocation failes
3351 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3353 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3354 * stop the T2-shutdown timer,
3356 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3357 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3359 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3360 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3362 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3363 SCTP_STATE(SCTP_STATE_CLOSED
));
3364 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3365 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3366 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3368 /* ...and remove all record of the association. */
3369 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3370 return SCTP_DISPOSITION_DELETE_TCB
;
3373 sctp_ulpevent_free(ev
);
3375 return SCTP_DISPOSITION_NOMEM
;
3379 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3381 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3382 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3383 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3384 * packet must fill in the Verification Tag field of the outbound
3385 * packet with the Verification Tag received in the SHUTDOWN ACK and
3386 * set the T-bit in the Chunk Flags to indicate that the Verification
3389 * 8) The receiver should respond to the sender of the OOTB packet with
3390 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3391 * MUST fill in the Verification Tag field of the outbound packet
3392 * with the value found in the Verification Tag field of the OOTB
3393 * packet and set the T-bit in the Chunk Flags to indicate that the
3394 * Verification Tag is reflected. After sending this ABORT, the
3395 * receiver of the OOTB packet shall discard the OOTB packet and take
3396 * no further action.
3398 sctp_disposition_t
sctp_sf_ootb(struct net
*net
,
3399 const struct sctp_endpoint
*ep
,
3400 const struct sctp_association
*asoc
,
3401 const sctp_subtype_t type
,
3403 sctp_cmd_seq_t
*commands
)
3405 struct sctp_chunk
*chunk
= arg
;
3406 struct sk_buff
*skb
= chunk
->skb
;
3407 sctp_chunkhdr_t
*ch
;
3410 int ootb_shut_ack
= 0;
3411 int ootb_cookie_ack
= 0;
3413 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3415 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3417 /* Report violation if the chunk is less then minimal */
3418 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3419 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3422 /* Report violation if chunk len overflows */
3423 ch_end
= ((__u8
*)ch
) + SCTP_PAD4(ntohs(ch
->length
));
3424 if (ch_end
> skb_tail_pointer(skb
))
3425 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3428 /* Now that we know we at least have a chunk header,
3429 * do things that are type appropriate.
3431 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3434 /* RFC 2960, Section 3.3.7
3435 * Moreover, under any circumstances, an endpoint that
3436 * receives an ABORT MUST NOT respond to that ABORT by
3437 * sending an ABORT of its own.
3439 if (SCTP_CID_ABORT
== ch
->type
)
3440 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3442 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3443 * or a COOKIE ACK the SCTP Packet should be silently
3447 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3448 ootb_cookie_ack
= 1;
3450 if (SCTP_CID_ERROR
== ch
->type
) {
3451 sctp_walk_errors(err
, ch
) {
3452 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3453 ootb_cookie_ack
= 1;
3459 ch
= (sctp_chunkhdr_t
*) ch_end
;
3460 } while (ch_end
< skb_tail_pointer(skb
));
3463 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3464 else if (ootb_cookie_ack
)
3465 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3467 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3471 * Handle an "Out of the blue" SHUTDOWN ACK.
3473 * Section: 8.4 5, sctpimpguide 2.41.
3475 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3476 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3477 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3478 * packet must fill in the Verification Tag field of the outbound
3479 * packet with the Verification Tag received in the SHUTDOWN ACK and
3480 * set the T-bit in the Chunk Flags to indicate that the Verification
3484 * (endpoint, asoc, type, arg, commands)
3487 * (sctp_disposition_t)
3489 * The return value is the disposition of the chunk.
3491 static sctp_disposition_t
sctp_sf_shut_8_4_5(struct net
*net
,
3492 const struct sctp_endpoint
*ep
,
3493 const struct sctp_association
*asoc
,
3494 const sctp_subtype_t type
,
3496 sctp_cmd_seq_t
*commands
)
3498 struct sctp_packet
*packet
= NULL
;
3499 struct sctp_chunk
*chunk
= arg
;
3500 struct sctp_chunk
*shut
;
3502 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3504 return SCTP_DISPOSITION_NOMEM
;
3506 /* Make an SHUTDOWN_COMPLETE.
3507 * The T bit will be set if the asoc is NULL.
3509 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3511 sctp_ootb_pkt_free(packet
);
3512 return SCTP_DISPOSITION_NOMEM
;
3515 /* Reflect vtag if T-Bit is set */
3516 if (sctp_test_T_bit(shut
))
3517 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3519 /* Set the skb to the belonging sock for accounting. */
3520 shut
->skb
->sk
= ep
->base
.sk
;
3522 sctp_packet_append_chunk(packet
, shut
);
3524 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3525 SCTP_PACKET(packet
));
3527 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3529 /* If the chunk length is invalid, we don't want to process
3530 * the reset of the packet.
3532 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3533 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3535 /* We need to discard the rest of the packet to prevent
3536 * potential bomming attacks from additional bundled chunks.
3537 * This is documented in SCTP Threats ID.
3539 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3543 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3545 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3546 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3547 * procedures in section 8.4 SHOULD be followed, in other words it
3548 * should be treated as an Out Of The Blue packet.
3549 * [This means that we do NOT check the Verification Tag on these
3553 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3554 const struct sctp_endpoint
*ep
,
3555 const struct sctp_association
*asoc
,
3556 const sctp_subtype_t type
,
3558 sctp_cmd_seq_t
*commands
)
3560 struct sctp_chunk
*chunk
= arg
;
3562 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3563 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3564 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3567 /* Although we do have an association in this case, it corresponds
3568 * to a restarted association. So the packet is treated as an OOTB
3569 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3570 * called with a NULL association.
3572 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3574 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3577 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3578 sctp_disposition_t
sctp_sf_do_asconf(struct net
*net
,
3579 const struct sctp_endpoint
*ep
,
3580 const struct sctp_association
*asoc
,
3581 const sctp_subtype_t type
, void *arg
,
3582 sctp_cmd_seq_t
*commands
)
3584 struct sctp_chunk
*chunk
= arg
;
3585 struct sctp_chunk
*asconf_ack
= NULL
;
3586 struct sctp_paramhdr
*err_param
= NULL
;
3587 sctp_addiphdr_t
*hdr
;
3590 if (!sctp_vtag_verify(chunk
, asoc
)) {
3591 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3593 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3596 /* ADD-IP: Section 4.1.1
3597 * This chunk MUST be sent in an authenticated way by using
3598 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3599 * is received unauthenticated it MUST be silently discarded as
3600 * described in [I-D.ietf-tsvwg-sctp-auth].
3602 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3603 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3605 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3606 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3607 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3610 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3611 serial
= ntohl(hdr
->serial
);
3613 /* Verify the ASCONF chunk before processing it. */
3614 if (!sctp_verify_asconf(asoc
, chunk
, true, &err_param
))
3615 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3616 (void *)err_param
, commands
);
3618 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3619 * the endpoint stored in a new association variable
3620 * 'Peer-Serial-Number'.
3622 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3623 /* If this is the first instance of ASCONF in the packet,
3624 * we can clean our old ASCONF-ACKs.
3626 if (!chunk
->has_asconf
)
3627 sctp_assoc_clean_asconf_ack_cache(asoc
);
3629 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3630 * expected, process the ASCONF as described below and after
3631 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3632 * the response packet and cache a copy of it (in the event it
3633 * later needs to be retransmitted).
3635 * Essentially, do V1-V5.
3637 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3640 return SCTP_DISPOSITION_NOMEM
;
3641 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3643 * If the value found in the Sequence Number is less than the
3644 * ('Peer- Sequence-Number' + 1), simply skip to the next
3645 * ASCONF, and include in the outbound response packet
3646 * any previously cached ASCONF-ACK response that was
3647 * sent and saved that matches the Sequence Number of the
3648 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3649 * Chunk exists. This will occur when an older ASCONF
3650 * arrives out of order. In such a case, the receiver
3651 * should skip the ASCONF Chunk and not include ASCONF-ACK
3652 * Chunk for that chunk.
3654 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3656 return SCTP_DISPOSITION_DISCARD
;
3658 /* Reset the transport so that we select the correct one
3659 * this time around. This is to make sure that we don't
3660 * accidentally use a stale transport that's been removed.
3662 asconf_ack
->transport
= NULL
;
3664 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3665 * it must be either a stale packet or from an attacker.
3667 return SCTP_DISPOSITION_DISCARD
;
3670 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3671 * containing the ASCONF-ACK Chunks MUST be the source address of
3672 * the SCTP packet that held the ASCONF Chunks.
3674 * To do this properly, we'll set the destination address of the chunk
3675 * and at the transmit time, will try look up the transport to use.
3676 * Since ASCONFs may be bundled, the correct transport may not be
3677 * created until we process the entire packet, thus this workaround.
3679 asconf_ack
->dest
= chunk
->source
;
3680 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3681 if (asoc
->new_transport
) {
3682 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
, commands
);
3683 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3686 return SCTP_DISPOSITION_CONSUME
;
3690 * ADDIP Section 4.3 General rules for address manipulation
3691 * When building TLV parameters for the ASCONF Chunk that will add or
3692 * delete IP addresses the D0 to D13 rules should be applied:
3694 sctp_disposition_t
sctp_sf_do_asconf_ack(struct net
*net
,
3695 const struct sctp_endpoint
*ep
,
3696 const struct sctp_association
*asoc
,
3697 const sctp_subtype_t type
, void *arg
,
3698 sctp_cmd_seq_t
*commands
)
3700 struct sctp_chunk
*asconf_ack
= arg
;
3701 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3702 struct sctp_chunk
*abort
;
3703 struct sctp_paramhdr
*err_param
= NULL
;
3704 sctp_addiphdr_t
*addip_hdr
;
3705 __u32 sent_serial
, rcvd_serial
;
3707 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3708 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3710 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3713 /* ADD-IP, Section 4.1.2:
3714 * This chunk MUST be sent in an authenticated way by using
3715 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3716 * is received unauthenticated it MUST be silently discarded as
3717 * described in [I-D.ietf-tsvwg-sctp-auth].
3719 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3720 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3722 /* Make sure that the ADDIP chunk has a valid length. */
3723 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3724 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3727 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3728 rcvd_serial
= ntohl(addip_hdr
->serial
);
3730 /* Verify the ASCONF-ACK chunk before processing it. */
3731 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
3732 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3733 (void *)err_param
, commands
);
3736 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3737 sent_serial
= ntohl(addip_hdr
->serial
);
3739 sent_serial
= asoc
->addip_serial
- 1;
3742 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3743 * equal to the next serial number to be used but no ASCONF chunk is
3744 * outstanding the endpoint MUST ABORT the association. Note that a
3745 * sequence number is greater than if it is no more than 2^^31-1
3746 * larger than the current sequence number (using serial arithmetic).
3748 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3749 !(asoc
->addip_last_asconf
)) {
3750 abort
= sctp_make_abort(asoc
, asconf_ack
,
3751 sizeof(sctp_errhdr_t
));
3753 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3754 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3757 /* We are going to ABORT, so we might as well stop
3758 * processing the rest of the chunks in the packet.
3760 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3761 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3762 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3763 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3764 SCTP_ERROR(ECONNABORTED
));
3765 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3766 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3767 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3768 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3769 return SCTP_DISPOSITION_ABORT
;
3772 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3773 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3774 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3776 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3778 /* Successfully processed ASCONF_ACK. We can
3779 * release the next asconf if we have one.
3781 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3783 return SCTP_DISPOSITION_CONSUME
;
3786 abort
= sctp_make_abort(asoc
, asconf_ack
,
3787 sizeof(sctp_errhdr_t
));
3789 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3790 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3793 /* We are going to ABORT, so we might as well stop
3794 * processing the rest of the chunks in the packet.
3796 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
3797 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3798 SCTP_ERROR(ECONNABORTED
));
3799 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3800 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3801 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3802 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3803 return SCTP_DISPOSITION_ABORT
;
3806 return SCTP_DISPOSITION_DISCARD
;
3810 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3812 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3813 * its cumulative TSN point to the value carried in the FORWARD TSN
3814 * chunk, and then MUST further advance its cumulative TSN point locally
3816 * After the above processing, the data receiver MUST stop reporting any
3817 * missing TSNs earlier than or equal to the new cumulative TSN point.
3819 * Verification Tag: 8.5 Verification Tag [Normal verification]
3821 * The return value is the disposition of the chunk.
3823 sctp_disposition_t
sctp_sf_eat_fwd_tsn(struct net
*net
,
3824 const struct sctp_endpoint
*ep
,
3825 const struct sctp_association
*asoc
,
3826 const sctp_subtype_t type
,
3828 sctp_cmd_seq_t
*commands
)
3830 struct sctp_chunk
*chunk
= arg
;
3831 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3832 struct sctp_fwdtsn_skip
*skip
;
3836 if (!sctp_vtag_verify(chunk
, asoc
)) {
3837 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3839 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3842 /* Make sure that the FORWARD_TSN chunk has valid length. */
3843 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3844 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3847 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3848 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3849 len
= ntohs(chunk
->chunk_hdr
->length
);
3850 len
-= sizeof(struct sctp_chunkhdr
);
3851 skb_pull(chunk
->skb
, len
);
3853 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3854 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3856 /* The TSN is too high--silently discard the chunk and count on it
3857 * getting retransmitted later.
3859 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3860 goto discard_noforce
;
3862 /* Silently discard the chunk if stream-id is not valid */
3863 sctp_walk_fwdtsn(skip
, chunk
) {
3864 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3865 goto discard_noforce
;
3868 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3869 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3870 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3873 /* Count this as receiving DATA. */
3874 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
]) {
3875 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3876 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3879 /* FIXME: For now send a SACK, but DATA processing may
3882 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3884 return SCTP_DISPOSITION_CONSUME
;
3887 return SCTP_DISPOSITION_DISCARD
;
3890 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3892 const struct sctp_endpoint
*ep
,
3893 const struct sctp_association
*asoc
,
3894 const sctp_subtype_t type
,
3896 sctp_cmd_seq_t
*commands
)
3898 struct sctp_chunk
*chunk
= arg
;
3899 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3900 struct sctp_fwdtsn_skip
*skip
;
3904 if (!sctp_vtag_verify(chunk
, asoc
)) {
3905 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3907 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3910 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3911 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3912 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3915 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3916 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3917 len
= ntohs(chunk
->chunk_hdr
->length
);
3918 len
-= sizeof(struct sctp_chunkhdr
);
3919 skb_pull(chunk
->skb
, len
);
3921 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3922 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3924 /* The TSN is too high--silently discard the chunk and count on it
3925 * getting retransmitted later.
3927 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3930 /* Silently discard the chunk if stream-id is not valid */
3931 sctp_walk_fwdtsn(skip
, chunk
) {
3932 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3936 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3937 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3938 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3941 /* Go a head and force a SACK, since we are shutting down. */
3943 /* Implementor's Guide.
3945 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3946 * respond to each received packet containing one or more DATA chunk(s)
3947 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3949 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3950 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3951 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3952 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3954 return SCTP_DISPOSITION_CONSUME
;
3958 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
3960 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3961 * Identifier field. If this algorithm was not specified by the
3962 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3963 * during association setup, the AUTH chunk and all chunks after it MUST
3964 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3965 * defined in Section 4.1.
3967 * If an endpoint with no shared key receives a Shared Key Identifier
3968 * other than 0, it MUST silently discard all authenticated chunks. If
3969 * the endpoint has at least one endpoint pair shared key for the peer,
3970 * it MUST use the key specified by the Shared Key Identifier if a
3971 * key has been configured for that Shared Key Identifier. If no
3972 * endpoint pair shared key has been configured for that Shared Key
3973 * Identifier, all authenticated chunks MUST be silently discarded.
3975 * Verification Tag: 8.5 Verification Tag [Normal verification]
3977 * The return value is the disposition of the chunk.
3979 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
3980 const struct sctp_endpoint
*ep
,
3981 const struct sctp_association
*asoc
,
3982 const sctp_subtype_t type
,
3983 struct sctp_chunk
*chunk
)
3985 struct sctp_authhdr
*auth_hdr
;
3986 struct sctp_hmac
*hmac
;
3987 unsigned int sig_len
;
3992 /* Pull in the auth header, so we can do some more verification */
3993 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3994 chunk
->subh
.auth_hdr
= auth_hdr
;
3995 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
3997 /* Make sure that we support the HMAC algorithm from the auth
4000 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4001 return SCTP_IERROR_AUTH_BAD_HMAC
;
4003 /* Make sure that the provided shared key identifier has been
4006 key_id
= ntohs(auth_hdr
->shkey_id
);
4007 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4008 return SCTP_IERROR_AUTH_BAD_KEYID
;
4011 /* Make sure that the length of the signature matches what
4014 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
4015 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4016 if (sig_len
!= hmac
->hmac_len
)
4017 return SCTP_IERROR_PROTO_VIOLATION
;
4019 /* Now that we've done validation checks, we can compute and
4020 * verify the hmac. The steps involved are:
4021 * 1. Save the digest from the chunk.
4022 * 2. Zero out the digest in the chunk.
4023 * 3. Compute the new digest
4024 * 4. Compare saved and new digests.
4026 digest
= auth_hdr
->hmac
;
4027 skb_pull(chunk
->skb
, sig_len
);
4029 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4033 memset(digest
, 0, sig_len
);
4035 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4036 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4039 /* Discard the packet if the digests do not match */
4040 if (memcmp(save_digest
, digest
, sig_len
)) {
4042 return SCTP_IERROR_BAD_SIG
;
4048 return SCTP_IERROR_NO_ERROR
;
4050 return SCTP_IERROR_NOMEM
;
4053 sctp_disposition_t
sctp_sf_eat_auth(struct net
*net
,
4054 const struct sctp_endpoint
*ep
,
4055 const struct sctp_association
*asoc
,
4056 const sctp_subtype_t type
,
4058 sctp_cmd_seq_t
*commands
)
4060 struct sctp_authhdr
*auth_hdr
;
4061 struct sctp_chunk
*chunk
= arg
;
4062 struct sctp_chunk
*err_chunk
;
4063 sctp_ierror_t error
;
4065 /* Make sure that the peer has AUTH capable */
4066 if (!asoc
->peer
.auth_capable
)
4067 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4069 if (!sctp_vtag_verify(chunk
, asoc
)) {
4070 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4072 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4075 /* Make sure that the AUTH chunk has valid length. */
4076 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4077 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4080 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4081 error
= sctp_sf_authenticate(net
, ep
, asoc
, type
, chunk
);
4083 case SCTP_IERROR_AUTH_BAD_HMAC
:
4084 /* Generate the ERROR chunk and discard the rest
4087 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4088 SCTP_ERROR_UNSUP_HMAC
,
4092 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4093 SCTP_CHUNK(err_chunk
));
4096 case SCTP_IERROR_AUTH_BAD_KEYID
:
4097 case SCTP_IERROR_BAD_SIG
:
4098 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4100 case SCTP_IERROR_PROTO_VIOLATION
:
4101 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4104 case SCTP_IERROR_NOMEM
:
4105 return SCTP_DISPOSITION_NOMEM
;
4107 default: /* Prevent gcc warnings */
4111 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4112 struct sctp_ulpevent
*ev
;
4114 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4115 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4120 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4124 return SCTP_DISPOSITION_CONSUME
;
4128 * Process an unknown chunk.
4130 * Section: 3.2. Also, 2.1 in the implementor's guide.
4132 * Chunk Types are encoded such that the highest-order two bits specify
4133 * the action that must be taken if the processing endpoint does not
4134 * recognize the Chunk Type.
4136 * 00 - Stop processing this SCTP packet and discard it, do not process
4137 * any further chunks within it.
4139 * 01 - Stop processing this SCTP packet and discard it, do not process
4140 * any further chunks within it, and report the unrecognized
4141 * chunk in an 'Unrecognized Chunk Type'.
4143 * 10 - Skip this chunk and continue processing.
4145 * 11 - Skip this chunk and continue processing, but report in an ERROR
4146 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4148 * The return value is the disposition of the chunk.
4150 sctp_disposition_t
sctp_sf_unk_chunk(struct net
*net
,
4151 const struct sctp_endpoint
*ep
,
4152 const struct sctp_association
*asoc
,
4153 const sctp_subtype_t type
,
4155 sctp_cmd_seq_t
*commands
)
4157 struct sctp_chunk
*unk_chunk
= arg
;
4158 struct sctp_chunk
*err_chunk
;
4159 sctp_chunkhdr_t
*hdr
;
4161 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4163 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4164 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4166 /* Make sure that the chunk has a valid length.
4167 * Since we don't know the chunk type, we use a general
4168 * chunkhdr structure to make a comparison.
4170 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4171 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4174 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4175 case SCTP_CID_ACTION_DISCARD
:
4176 /* Discard the packet. */
4177 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4178 case SCTP_CID_ACTION_DISCARD_ERR
:
4179 /* Generate an ERROR chunk as response. */
4180 hdr
= unk_chunk
->chunk_hdr
;
4181 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4182 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4183 SCTP_PAD4(ntohs(hdr
->length
)),
4186 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4187 SCTP_CHUNK(err_chunk
));
4190 /* Discard the packet. */
4191 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4192 return SCTP_DISPOSITION_CONSUME
;
4193 case SCTP_CID_ACTION_SKIP
:
4194 /* Skip the chunk. */
4195 return SCTP_DISPOSITION_DISCARD
;
4196 case SCTP_CID_ACTION_SKIP_ERR
:
4197 /* Generate an ERROR chunk as response. */
4198 hdr
= unk_chunk
->chunk_hdr
;
4199 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4200 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4201 SCTP_PAD4(ntohs(hdr
->length
)),
4204 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4205 SCTP_CHUNK(err_chunk
));
4207 /* Skip the chunk. */
4208 return SCTP_DISPOSITION_CONSUME
;
4213 return SCTP_DISPOSITION_DISCARD
;
4217 * Discard the chunk.
4219 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4220 * [Too numerous to mention...]
4221 * Verification Tag: No verification needed.
4223 * (endpoint, asoc, chunk)
4226 * (asoc, reply_msg, msg_up, timers, counters)
4228 * The return value is the disposition of the chunk.
4230 sctp_disposition_t
sctp_sf_discard_chunk(struct net
*net
,
4231 const struct sctp_endpoint
*ep
,
4232 const struct sctp_association
*asoc
,
4233 const sctp_subtype_t type
,
4235 sctp_cmd_seq_t
*commands
)
4237 struct sctp_chunk
*chunk
= arg
;
4239 /* Make sure that the chunk has a valid length.
4240 * Since we don't know the chunk type, we use a general
4241 * chunkhdr structure to make a comparison.
4243 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4244 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4247 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4249 return SCTP_DISPOSITION_DISCARD
;
4253 * Discard the whole packet.
4257 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4258 * silently discard the OOTB packet and take no further action.
4260 * Verification Tag: No verification necessary
4263 * (endpoint, asoc, chunk)
4266 * (asoc, reply_msg, msg_up, timers, counters)
4268 * The return value is the disposition of the chunk.
4270 sctp_disposition_t
sctp_sf_pdiscard(struct net
*net
,
4271 const struct sctp_endpoint
*ep
,
4272 const struct sctp_association
*asoc
,
4273 const sctp_subtype_t type
,
4275 sctp_cmd_seq_t
*commands
)
4277 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4278 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4280 return SCTP_DISPOSITION_CONSUME
;
4285 * The other end is violating protocol.
4287 * Section: Not specified
4288 * Verification Tag: Not specified
4290 * (endpoint, asoc, chunk)
4293 * (asoc, reply_msg, msg_up, timers, counters)
4295 * We simply tag the chunk as a violation. The state machine will log
4296 * the violation and continue.
4298 sctp_disposition_t
sctp_sf_violation(struct net
*net
,
4299 const struct sctp_endpoint
*ep
,
4300 const struct sctp_association
*asoc
,
4301 const sctp_subtype_t type
,
4303 sctp_cmd_seq_t
*commands
)
4305 struct sctp_chunk
*chunk
= arg
;
4307 /* Make sure that the chunk has a valid length. */
4308 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4309 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4312 return SCTP_DISPOSITION_VIOLATION
;
4316 * Common function to handle a protocol violation.
4318 static sctp_disposition_t
sctp_sf_abort_violation(
4320 const struct sctp_endpoint
*ep
,
4321 const struct sctp_association
*asoc
,
4323 sctp_cmd_seq_t
*commands
,
4324 const __u8
*payload
,
4325 const size_t paylen
)
4327 struct sctp_packet
*packet
= NULL
;
4328 struct sctp_chunk
*chunk
= arg
;
4329 struct sctp_chunk
*abort
= NULL
;
4331 /* SCTP-AUTH, Section 6.3:
4332 * It should be noted that if the receiver wants to tear
4333 * down an association in an authenticated way only, the
4334 * handling of malformed packets should not result in
4335 * tearing down the association.
4337 * This means that if we only want to abort associations
4338 * in an authenticated way (i.e AUTH+ABORT), then we
4339 * can't destroy this association just because the packet
4342 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4345 /* Make the abort chunk. */
4346 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4351 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4352 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4353 !asoc
->peer
.i
.init_tag
) {
4354 sctp_initack_chunk_t
*initack
;
4356 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4357 if (!sctp_chunk_length_valid(chunk
,
4358 sizeof(sctp_initack_chunk_t
)))
4359 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4361 unsigned int inittag
;
4363 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4364 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4369 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4370 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4372 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4373 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4374 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4375 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4376 SCTP_ERROR(ECONNREFUSED
));
4377 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4378 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4380 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4381 SCTP_ERROR(ECONNABORTED
));
4382 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4383 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4384 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4387 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4392 if (sctp_test_T_bit(abort
))
4393 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4395 abort
->skb
->sk
= ep
->base
.sk
;
4397 sctp_packet_append_chunk(packet
, abort
);
4399 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4400 SCTP_PACKET(packet
));
4402 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4405 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4408 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4409 return SCTP_DISPOSITION_ABORT
;
4412 sctp_chunk_free(abort
);
4414 return SCTP_DISPOSITION_NOMEM
;
4418 * Handle a protocol violation when the chunk length is invalid.
4419 * "Invalid" length is identified as smaller than the minimal length a
4420 * given chunk can be. For example, a SACK chunk has invalid length
4421 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4423 * We inform the other end by sending an ABORT with a Protocol Violation
4426 * Section: Not specified
4427 * Verification Tag: Nothing to do
4429 * (endpoint, asoc, chunk)
4432 * (reply_msg, msg_up, counters)
4434 * Generate an ABORT chunk and terminate the association.
4436 static sctp_disposition_t
sctp_sf_violation_chunklen(
4438 const struct sctp_endpoint
*ep
,
4439 const struct sctp_association
*asoc
,
4440 const sctp_subtype_t type
,
4442 sctp_cmd_seq_t
*commands
)
4444 static const char err_str
[] = "The following chunk had invalid length:";
4446 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4451 * Handle a protocol violation when the parameter length is invalid.
4452 * If the length is smaller than the minimum length of a given parameter,
4453 * or accumulated length in multi parameters exceeds the end of the chunk,
4454 * the length is considered as invalid.
4456 static sctp_disposition_t
sctp_sf_violation_paramlen(
4458 const struct sctp_endpoint
*ep
,
4459 const struct sctp_association
*asoc
,
4460 const sctp_subtype_t type
,
4461 void *arg
, void *ext
,
4462 sctp_cmd_seq_t
*commands
)
4464 struct sctp_chunk
*chunk
= arg
;
4465 struct sctp_paramhdr
*param
= ext
;
4466 struct sctp_chunk
*abort
= NULL
;
4468 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4471 /* Make the abort chunk. */
4472 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4476 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4477 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4479 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4480 SCTP_ERROR(ECONNABORTED
));
4481 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4482 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4483 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4484 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4487 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4488 return SCTP_DISPOSITION_ABORT
;
4490 return SCTP_DISPOSITION_NOMEM
;
4493 /* Handle a protocol violation when the peer trying to advance the
4494 * cumulative tsn ack to a point beyond the max tsn currently sent.
4496 * We inform the other end by sending an ABORT with a Protocol Violation
4499 static sctp_disposition_t
sctp_sf_violation_ctsn(
4501 const struct sctp_endpoint
*ep
,
4502 const struct sctp_association
*asoc
,
4503 const sctp_subtype_t type
,
4505 sctp_cmd_seq_t
*commands
)
4507 static const char err_str
[] = "The cumulative tsn ack beyond the max tsn currently sent:";
4509 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4513 /* Handle protocol violation of an invalid chunk bundling. For example,
4514 * when we have an association and we receive bundled INIT-ACK, or
4515 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4516 * statement from the specs. Additionally, there might be an attacker
4517 * on the path and we may not want to continue this communication.
4519 static sctp_disposition_t
sctp_sf_violation_chunk(
4521 const struct sctp_endpoint
*ep
,
4522 const struct sctp_association
*asoc
,
4523 const sctp_subtype_t type
,
4525 sctp_cmd_seq_t
*commands
)
4527 static const char err_str
[] = "The following chunk violates protocol:";
4530 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4532 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4535 /***************************************************************************
4536 * These are the state functions for handling primitive (Section 10) events.
4537 ***************************************************************************/
4539 * sctp_sf_do_prm_asoc
4541 * Section: 10.1 ULP-to-SCTP
4544 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4545 * outbound stream count)
4546 * -> association id [,destination transport addr list] [,outbound stream
4549 * This primitive allows the upper layer to initiate an association to a
4550 * specific peer endpoint.
4552 * The peer endpoint shall be specified by one of the transport addresses
4553 * which defines the endpoint (see Section 1.4). If the local SCTP
4554 * instance has not been initialized, the ASSOCIATE is considered an
4556 * [This is not relevant for the kernel implementation since we do all
4557 * initialization at boot time. It we hadn't initialized we wouldn't
4558 * get anywhere near this code.]
4560 * An association id, which is a local handle to the SCTP association,
4561 * will be returned on successful establishment of the association. If
4562 * SCTP is not able to open an SCTP association with the peer endpoint,
4563 * an error is returned.
4564 * [In the kernel implementation, the struct sctp_association needs to
4565 * be created BEFORE causing this primitive to run.]
4567 * Other association parameters may be returned, including the
4568 * complete destination transport addresses of the peer as well as the
4569 * outbound stream count of the local endpoint. One of the transport
4570 * address from the returned destination addresses will be selected by
4571 * the local endpoint as default primary path for sending SCTP packets
4572 * to this peer. The returned "destination transport addr list" can
4573 * be used by the ULP to change the default primary path or to force
4574 * sending a packet to a specific transport address. [All of this
4575 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4578 * Mandatory attributes:
4580 * o local SCTP instance name - obtained from the INITIALIZE operation.
4581 * [This is the argument asoc.]
4582 * o destination transport addr - specified as one of the transport
4583 * addresses of the peer endpoint with which the association is to be
4585 * [This is asoc->peer.active_path.]
4586 * o outbound stream count - the number of outbound streams the ULP
4587 * would like to open towards this peer endpoint.
4588 * [BUG: This is not currently implemented.]
4589 * Optional attributes:
4593 * The return value is a disposition.
4595 sctp_disposition_t
sctp_sf_do_prm_asoc(struct net
*net
,
4596 const struct sctp_endpoint
*ep
,
4597 const struct sctp_association
*asoc
,
4598 const sctp_subtype_t type
,
4600 sctp_cmd_seq_t
*commands
)
4602 struct sctp_chunk
*repl
;
4603 struct sctp_association
*my_asoc
;
4605 /* The comment below says that we enter COOKIE-WAIT AFTER
4606 * sending the INIT, but that doesn't actually work in our
4609 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4610 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4612 /* RFC 2960 5.1 Normal Establishment of an Association
4614 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4615 * must provide its Verification Tag (Tag_A) in the Initiate
4616 * Tag field. Tag_A SHOULD be a random number in the range of
4617 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4620 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4624 /* Choose transport for INIT. */
4625 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4628 /* Cast away the const modifier, as we want to just
4629 * rerun it through as a sideffect.
4631 my_asoc
= (struct sctp_association
*)asoc
;
4632 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4634 /* After sending the INIT, "A" starts the T1-init timer and
4635 * enters the COOKIE-WAIT state.
4637 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4638 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4639 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4640 return SCTP_DISPOSITION_CONSUME
;
4643 return SCTP_DISPOSITION_NOMEM
;
4647 * Process the SEND primitive.
4649 * Section: 10.1 ULP-to-SCTP
4652 * Format: SEND(association id, buffer address, byte count [,context]
4653 * [,stream id] [,life time] [,destination transport address]
4654 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4657 * This is the main method to send user data via SCTP.
4659 * Mandatory attributes:
4661 * o association id - local handle to the SCTP association
4663 * o buffer address - the location where the user message to be
4664 * transmitted is stored;
4666 * o byte count - The size of the user data in number of bytes;
4668 * Optional attributes:
4670 * o context - an optional 32 bit integer that will be carried in the
4671 * sending failure notification to the ULP if the transportation of
4672 * this User Message fails.
4674 * o stream id - to indicate which stream to send the data on. If not
4675 * specified, stream 0 will be used.
4677 * o life time - specifies the life time of the user data. The user data
4678 * will not be sent by SCTP after the life time expires. This
4679 * parameter can be used to avoid efforts to transmit stale
4680 * user messages. SCTP notifies the ULP if the data cannot be
4681 * initiated to transport (i.e. sent to the destination via SCTP's
4682 * send primitive) within the life time variable. However, the
4683 * user data will be transmitted if SCTP has attempted to transmit a
4684 * chunk before the life time expired.
4686 * o destination transport address - specified as one of the destination
4687 * transport addresses of the peer endpoint to which this packet
4688 * should be sent. Whenever possible, SCTP should use this destination
4689 * transport address for sending the packets, instead of the current
4692 * o unorder flag - this flag, if present, indicates that the user
4693 * would like the data delivered in an unordered fashion to the peer
4694 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4697 * o no-bundle flag - instructs SCTP not to bundle this user data with
4698 * other outbound DATA chunks. SCTP MAY still bundle even when
4699 * this flag is present, when faced with network congestion.
4701 * o payload protocol-id - A 32 bit unsigned integer that is to be
4702 * passed to the peer indicating the type of payload protocol data
4703 * being transmitted. This value is passed as opaque data by SCTP.
4705 * The return value is the disposition.
4707 sctp_disposition_t
sctp_sf_do_prm_send(struct net
*net
,
4708 const struct sctp_endpoint
*ep
,
4709 const struct sctp_association
*asoc
,
4710 const sctp_subtype_t type
,
4712 sctp_cmd_seq_t
*commands
)
4714 struct sctp_datamsg
*msg
= arg
;
4716 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4717 return SCTP_DISPOSITION_CONSUME
;
4721 * Process the SHUTDOWN primitive.
4726 * Format: SHUTDOWN(association id)
4729 * Gracefully closes an association. Any locally queued user data
4730 * will be delivered to the peer. The association will be terminated only
4731 * after the peer acknowledges all the SCTP packets sent. A success code
4732 * will be returned on successful termination of the association. If
4733 * attempting to terminate the association results in a failure, an error
4734 * code shall be returned.
4736 * Mandatory attributes:
4738 * o association id - local handle to the SCTP association
4740 * Optional attributes:
4744 * The return value is the disposition.
4746 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4748 const struct sctp_endpoint
*ep
,
4749 const struct sctp_association
*asoc
,
4750 const sctp_subtype_t type
,
4752 sctp_cmd_seq_t
*commands
)
4756 /* From 9.2 Shutdown of an Association
4757 * Upon receipt of the SHUTDOWN primitive from its upper
4758 * layer, the endpoint enters SHUTDOWN-PENDING state and
4759 * remains there until all outstanding data has been
4760 * acknowledged by its peer. The endpoint accepts no new data
4761 * from its upper layer, but retransmits data to the far end
4762 * if necessary to fill gaps.
4764 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4765 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4767 disposition
= SCTP_DISPOSITION_CONSUME
;
4768 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4769 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4776 * Process the ABORT primitive.
4781 * Format: Abort(association id [, cause code])
4784 * Ungracefully closes an association. Any locally queued user data
4785 * will be discarded and an ABORT chunk is sent to the peer. A success code
4786 * will be returned on successful abortion of the association. If
4787 * attempting to abort the association results in a failure, an error
4788 * code shall be returned.
4790 * Mandatory attributes:
4792 * o association id - local handle to the SCTP association
4794 * Optional attributes:
4796 * o cause code - reason of the abort to be passed to the peer
4800 * The return value is the disposition.
4802 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4804 const struct sctp_endpoint
*ep
,
4805 const struct sctp_association
*asoc
,
4806 const sctp_subtype_t type
,
4808 sctp_cmd_seq_t
*commands
)
4810 /* From 9.1 Abort of an Association
4811 * Upon receipt of the ABORT primitive from its upper
4812 * layer, the endpoint enters CLOSED state and
4813 * discard all outstanding data has been
4814 * acknowledged by its peer. The endpoint accepts no new data
4815 * from its upper layer, but retransmits data to the far end
4816 * if necessary to fill gaps.
4818 struct sctp_chunk
*abort
= arg
;
4821 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4823 /* Even if we can't send the ABORT due to low memory delete the
4824 * TCB. This is a departure from our typical NOMEM handling.
4827 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4828 SCTP_ERROR(ECONNABORTED
));
4829 /* Delete the established association. */
4830 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4831 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4833 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4834 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4836 return SCTP_DISPOSITION_ABORT
;
4839 /* We tried an illegal operation on an association which is closed. */
4840 sctp_disposition_t
sctp_sf_error_closed(struct net
*net
,
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 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4848 return SCTP_DISPOSITION_CONSUME
;
4851 /* We tried an illegal operation on an association which is shutting
4854 sctp_disposition_t
sctp_sf_error_shutdown(struct net
*net
,
4855 const struct sctp_endpoint
*ep
,
4856 const struct sctp_association
*asoc
,
4857 const sctp_subtype_t type
,
4859 sctp_cmd_seq_t
*commands
)
4861 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4862 SCTP_ERROR(-ESHUTDOWN
));
4863 return SCTP_DISPOSITION_CONSUME
;
4867 * sctp_cookie_wait_prm_shutdown
4869 * Section: 4 Note: 2
4874 * The RFC does not explicitly address this issue, but is the route through the
4875 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4880 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4882 const struct sctp_endpoint
*ep
,
4883 const struct sctp_association
*asoc
,
4884 const sctp_subtype_t type
,
4886 sctp_cmd_seq_t
*commands
)
4888 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4889 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4891 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4892 SCTP_STATE(SCTP_STATE_CLOSED
));
4894 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
4896 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4898 return SCTP_DISPOSITION_DELETE_TCB
;
4902 * sctp_cookie_echoed_prm_shutdown
4904 * Section: 4 Note: 2
4909 * The RFC does not explcitly address this issue, but is the route through the
4910 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4915 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4917 const struct sctp_endpoint
*ep
,
4918 const struct sctp_association
*asoc
,
4919 const sctp_subtype_t type
,
4920 void *arg
, sctp_cmd_seq_t
*commands
)
4922 /* There is a single T1 timer, so we should be able to use
4923 * common function with the COOKIE-WAIT state.
4925 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
4929 * sctp_sf_cookie_wait_prm_abort
4931 * Section: 4 Note: 2
4936 * The RFC does not explicitly address this issue, but is the route through the
4937 * state table when someone issues an abort while in COOKIE_WAIT state.
4942 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4944 const struct sctp_endpoint
*ep
,
4945 const struct sctp_association
*asoc
,
4946 const sctp_subtype_t type
,
4948 sctp_cmd_seq_t
*commands
)
4950 struct sctp_chunk
*abort
= arg
;
4952 /* Stop T1-init timer */
4953 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4954 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4957 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4959 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4960 SCTP_STATE(SCTP_STATE_CLOSED
));
4962 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4964 /* Even if we can't send the ABORT due to low memory delete the
4965 * TCB. This is a departure from our typical NOMEM handling.
4968 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4969 SCTP_ERROR(ECONNREFUSED
));
4970 /* Delete the established association. */
4971 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4972 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4974 return SCTP_DISPOSITION_ABORT
;
4978 * sctp_sf_cookie_echoed_prm_abort
4980 * Section: 4 Note: 3
4985 * The RFC does not explcitly address this issue, but is the route through the
4986 * state table when someone issues an abort while in COOKIE_ECHOED state.
4991 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4993 const struct sctp_endpoint
*ep
,
4994 const struct sctp_association
*asoc
,
4995 const sctp_subtype_t type
,
4997 sctp_cmd_seq_t
*commands
)
4999 /* There is a single T1 timer, so we should be able to use
5000 * common function with the COOKIE-WAIT state.
5002 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5006 * sctp_sf_shutdown_pending_prm_abort
5011 * The RFC does not explicitly address this issue, but is the route through the
5012 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5017 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
5019 const struct sctp_endpoint
*ep
,
5020 const struct sctp_association
*asoc
,
5021 const sctp_subtype_t type
,
5023 sctp_cmd_seq_t
*commands
)
5025 /* Stop the T5-shutdown guard timer. */
5026 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5027 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5029 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5033 * sctp_sf_shutdown_sent_prm_abort
5038 * The RFC does not explicitly address this issue, but is the route through the
5039 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5044 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
5046 const struct sctp_endpoint
*ep
,
5047 const struct sctp_association
*asoc
,
5048 const sctp_subtype_t type
,
5050 sctp_cmd_seq_t
*commands
)
5052 /* Stop the T2-shutdown timer. */
5053 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5054 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5056 /* Stop the T5-shutdown guard timer. */
5057 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5058 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5060 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5064 * sctp_sf_cookie_echoed_prm_abort
5069 * The RFC does not explcitly address this issue, but is the route through the
5070 * state table when someone issues an abort while in COOKIE_ECHOED state.
5075 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
5077 const struct sctp_endpoint
*ep
,
5078 const struct sctp_association
*asoc
,
5079 const sctp_subtype_t type
,
5081 sctp_cmd_seq_t
*commands
)
5083 /* The same T2 timer, so we should be able to use
5084 * common function with the SHUTDOWN-SENT state.
5086 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5090 * Process the REQUESTHEARTBEAT primitive
5093 * J) Request Heartbeat
5095 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5099 * Instructs the local endpoint to perform a HeartBeat on the specified
5100 * destination transport address of the given association. The returned
5101 * result should indicate whether the transmission of the HEARTBEAT
5102 * chunk to the destination address is successful.
5104 * Mandatory attributes:
5106 * o association id - local handle to the SCTP association
5108 * o destination transport address - the transport address of the
5109 * association on which a heartbeat should be issued.
5111 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
5113 const struct sctp_endpoint
*ep
,
5114 const struct sctp_association
*asoc
,
5115 const sctp_subtype_t type
,
5117 sctp_cmd_seq_t
*commands
)
5119 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5120 (struct sctp_transport
*)arg
, commands
))
5121 return SCTP_DISPOSITION_NOMEM
;
5124 * RFC 2960 (bis), section 8.3
5126 * D) Request an on-demand HEARTBEAT on a specific destination
5127 * transport address of a given association.
5129 * The endpoint should increment the respective error counter of
5130 * the destination transport address each time a HEARTBEAT is sent
5131 * to that address and not acknowledged within one RTO.
5134 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5135 SCTP_TRANSPORT(arg
));
5136 return SCTP_DISPOSITION_CONSUME
;
5140 * ADDIP Section 4.1 ASCONF Chunk Procedures
5141 * When an endpoint has an ASCONF signaled change to be sent to the
5142 * remote endpoint it should do A1 to A9
5144 sctp_disposition_t
sctp_sf_do_prm_asconf(struct net
*net
,
5145 const struct sctp_endpoint
*ep
,
5146 const struct sctp_association
*asoc
,
5147 const sctp_subtype_t type
,
5149 sctp_cmd_seq_t
*commands
)
5151 struct sctp_chunk
*chunk
= arg
;
5153 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5154 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5155 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5156 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5157 return SCTP_DISPOSITION_CONSUME
;
5161 * Ignore the primitive event
5163 * The return value is the disposition of the primitive.
5165 sctp_disposition_t
sctp_sf_ignore_primitive(
5167 const struct sctp_endpoint
*ep
,
5168 const struct sctp_association
*asoc
,
5169 const sctp_subtype_t type
,
5171 sctp_cmd_seq_t
*commands
)
5173 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5176 return SCTP_DISPOSITION_DISCARD
;
5179 /***************************************************************************
5180 * These are the state functions for the OTHER events.
5181 ***************************************************************************/
5184 * When the SCTP stack has no more user data to send or retransmit, this
5185 * notification is given to the user. Also, at the time when a user app
5186 * subscribes to this event, if there is no data to be sent or
5187 * retransmit, the stack will immediately send up this notification.
5189 sctp_disposition_t
sctp_sf_do_no_pending_tsn(
5191 const struct sctp_endpoint
*ep
,
5192 const struct sctp_association
*asoc
,
5193 const sctp_subtype_t type
,
5195 sctp_cmd_seq_t
*commands
)
5197 struct sctp_ulpevent
*event
;
5199 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5201 return SCTP_DISPOSITION_NOMEM
;
5203 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5205 return SCTP_DISPOSITION_CONSUME
;
5209 * Start the shutdown negotiation.
5212 * Once all its outstanding data has been acknowledged, the endpoint
5213 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5214 * TSN Ack field the last sequential TSN it has received from the peer.
5215 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5216 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5217 * with the updated last sequential TSN received from its peer.
5219 * The return value is the disposition.
5221 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5223 const struct sctp_endpoint
*ep
,
5224 const struct sctp_association
*asoc
,
5225 const sctp_subtype_t type
,
5227 sctp_cmd_seq_t
*commands
)
5229 struct sctp_chunk
*reply
;
5231 /* Once all its outstanding data has been acknowledged, the
5232 * endpoint shall send a SHUTDOWN chunk to its peer including
5233 * in the Cumulative TSN Ack field the last sequential TSN it
5234 * has received from the peer.
5236 reply
= sctp_make_shutdown(asoc
, NULL
);
5240 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5241 * T2-shutdown timer.
5243 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5245 /* It shall then start the T2-shutdown timer */
5246 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5247 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5249 /* RFC 4960 Section 9.2
5250 * The sender of the SHUTDOWN MAY also start an overall guard timer
5251 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5253 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5254 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5256 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5257 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5258 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5260 /* and enter the SHUTDOWN-SENT state. */
5261 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5262 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5264 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5266 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5269 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5271 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5273 return SCTP_DISPOSITION_CONSUME
;
5276 return SCTP_DISPOSITION_NOMEM
;
5280 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5284 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5285 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5286 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5287 * endpoint must re-send the SHUTDOWN ACK.
5289 * The return value is the disposition.
5291 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5293 const struct sctp_endpoint
*ep
,
5294 const struct sctp_association
*asoc
,
5295 const sctp_subtype_t type
,
5297 sctp_cmd_seq_t
*commands
)
5299 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5300 struct sctp_chunk
*reply
;
5302 /* There are 2 ways of getting here:
5303 * 1) called in response to a SHUTDOWN chunk
5304 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5306 * For the case (2), the arg parameter is set to NULL. We need
5307 * to check that we have a chunk before accessing it's fields.
5310 if (!sctp_vtag_verify(chunk
, asoc
))
5311 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
5313 /* Make sure that the SHUTDOWN chunk has a valid length. */
5314 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5315 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
5319 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5320 * shall send a SHUTDOWN ACK ...
5322 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5326 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5327 * the T2-shutdown timer.
5329 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5331 /* and start/restart a T2-shutdown timer of its own, */
5332 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5333 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5335 if (asoc
->timeouts
[SCTP_EVENT_TIMEOUT_AUTOCLOSE
])
5336 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5337 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5339 /* Enter the SHUTDOWN-ACK-SENT state. */
5340 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5341 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5343 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5345 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5348 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5350 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5352 return SCTP_DISPOSITION_CONSUME
;
5355 return SCTP_DISPOSITION_NOMEM
;
5359 * Ignore the event defined as other
5361 * The return value is the disposition of the event.
5363 sctp_disposition_t
sctp_sf_ignore_other(struct net
*net
,
5364 const struct sctp_endpoint
*ep
,
5365 const struct sctp_association
*asoc
,
5366 const sctp_subtype_t type
,
5368 sctp_cmd_seq_t
*commands
)
5370 pr_debug("%s: the event other type:%d is ignored\n",
5371 __func__
, type
.other
);
5373 return SCTP_DISPOSITION_DISCARD
;
5376 /************************************************************
5377 * These are the state functions for handling timeout events.
5378 ************************************************************/
5383 * Section: 6.3.3 Handle T3-rtx Expiration
5385 * Whenever the retransmission timer T3-rtx expires for a destination
5386 * address, do the following:
5389 * The return value is the disposition of the chunk.
5391 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5392 const struct sctp_endpoint
*ep
,
5393 const struct sctp_association
*asoc
,
5394 const sctp_subtype_t type
,
5396 sctp_cmd_seq_t
*commands
)
5398 struct sctp_transport
*transport
= arg
;
5400 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5402 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5403 if (asoc
->peer
.zero_window_announced
&&
5404 asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5406 * We are here likely because the receiver had its rwnd
5407 * closed for a while and we have not been able to
5408 * transmit the locally queued data within the maximum
5409 * retransmission attempts limit. Start the T5
5410 * shutdown guard timer to give the receiver one last
5411 * chance and some additional time to recover before
5414 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5415 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5417 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5418 SCTP_ERROR(ETIMEDOUT
));
5419 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5420 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5421 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5422 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5423 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5424 return SCTP_DISPOSITION_DELETE_TCB
;
5428 /* E1) For the destination address for which the timer
5429 * expires, adjust its ssthresh with rules defined in Section
5430 * 7.2.3 and set the cwnd <- MTU.
5433 /* E2) For the destination address for which the timer
5434 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5435 * maximum value discussed in rule C7 above (RTO.max) may be
5436 * used to provide an upper bound to this doubling operation.
5439 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5440 * outstanding DATA chunks for the address for which the
5441 * T3-rtx has expired will fit into a single packet, subject
5442 * to the MTU constraint for the path corresponding to the
5443 * destination transport address to which the retransmission
5444 * is being sent (this may be different from the address for
5445 * which the timer expires [see Section 6.4]). Call this
5446 * value K. Bundle and retransmit those K DATA chunks in a
5447 * single packet to the destination endpoint.
5449 * Note: Any DATA chunks that were sent to the address for
5450 * which the T3-rtx timer expired but did not fit in one MTU
5451 * (rule E3 above), should be marked for retransmission and
5452 * sent as soon as cwnd allows (normally when a SACK arrives).
5455 /* Do some failure management (Section 8.2). */
5456 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5458 /* NB: Rules E4 and F1 are implicit in R1. */
5459 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5461 return SCTP_DISPOSITION_CONSUME
;
5465 * Generate delayed SACK on timeout
5467 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5469 * The guidelines on delayed acknowledgement algorithm specified in
5470 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5471 * acknowledgement SHOULD be generated for at least every second packet
5472 * (not every second DATA chunk) received, and SHOULD be generated
5473 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5474 * some situations it may be beneficial for an SCTP transmitter to be
5475 * more conservative than the algorithms detailed in this document
5476 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5477 * the following algorithms allow.
5479 sctp_disposition_t
sctp_sf_do_6_2_sack(struct net
*net
,
5480 const struct sctp_endpoint
*ep
,
5481 const struct sctp_association
*asoc
,
5482 const sctp_subtype_t type
,
5484 sctp_cmd_seq_t
*commands
)
5486 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5487 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5488 return SCTP_DISPOSITION_CONSUME
;
5492 * sctp_sf_t1_init_timer_expire
5494 * Section: 4 Note: 2
5499 * RFC 2960 Section 4 Notes
5500 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5501 * and re-start the T1-init timer without changing state. This MUST
5502 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5503 * endpoint MUST abort the initialization process and report the
5504 * error to SCTP user.
5510 sctp_disposition_t
sctp_sf_t1_init_timer_expire(struct net
*net
,
5511 const struct sctp_endpoint
*ep
,
5512 const struct sctp_association
*asoc
,
5513 const sctp_subtype_t type
,
5515 sctp_cmd_seq_t
*commands
)
5517 struct sctp_chunk
*repl
= NULL
;
5518 struct sctp_bind_addr
*bp
;
5519 int attempts
= asoc
->init_err_counter
+ 1;
5521 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5523 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5525 if (attempts
<= asoc
->max_init_attempts
) {
5526 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5527 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5529 return SCTP_DISPOSITION_NOMEM
;
5531 /* Choose transport for INIT. */
5532 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5535 /* Issue a sideeffect to do the needed accounting. */
5536 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5537 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5539 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5541 pr_debug("%s: giving up on INIT, attempts:%d "
5542 "max_init_attempts:%d\n", __func__
, attempts
,
5543 asoc
->max_init_attempts
);
5545 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5546 SCTP_ERROR(ETIMEDOUT
));
5547 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5548 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5549 return SCTP_DISPOSITION_DELETE_TCB
;
5552 return SCTP_DISPOSITION_CONSUME
;
5556 * sctp_sf_t1_cookie_timer_expire
5558 * Section: 4 Note: 2
5563 * RFC 2960 Section 4 Notes
5564 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5565 * COOKIE ECHO and re-start the T1-cookie timer without changing
5566 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5567 * After that, the endpoint MUST abort the initialization process and
5568 * report the error to SCTP user.
5574 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(struct net
*net
,
5575 const struct sctp_endpoint
*ep
,
5576 const struct sctp_association
*asoc
,
5577 const sctp_subtype_t type
,
5579 sctp_cmd_seq_t
*commands
)
5581 struct sctp_chunk
*repl
= NULL
;
5582 int attempts
= asoc
->init_err_counter
+ 1;
5584 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5586 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5588 if (attempts
<= asoc
->max_init_attempts
) {
5589 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5591 return SCTP_DISPOSITION_NOMEM
;
5593 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5595 /* Issue a sideeffect to do the needed accounting. */
5596 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5597 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5599 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5601 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5602 SCTP_ERROR(ETIMEDOUT
));
5603 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5604 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5605 return SCTP_DISPOSITION_DELETE_TCB
;
5608 return SCTP_DISPOSITION_CONSUME
;
5611 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5612 * with the updated last sequential TSN received from its peer.
5614 * An endpoint should limit the number of retransmissions of the
5615 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5616 * If this threshold is exceeded the endpoint should destroy the TCB and
5617 * MUST report the peer endpoint unreachable to the upper layer (and
5618 * thus the association enters the CLOSED state). The reception of any
5619 * packet from its peer (i.e. as the peer sends all of its queued DATA
5620 * chunks) should clear the endpoint's retransmission count and restart
5621 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5622 * all of its queued DATA chunks that have not yet been sent.
5624 sctp_disposition_t
sctp_sf_t2_timer_expire(struct net
*net
,
5625 const struct sctp_endpoint
*ep
,
5626 const struct sctp_association
*asoc
,
5627 const sctp_subtype_t type
,
5629 sctp_cmd_seq_t
*commands
)
5631 struct sctp_chunk
*reply
= NULL
;
5633 pr_debug("%s: timer T2 expired\n", __func__
);
5635 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5637 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5639 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5640 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5641 SCTP_ERROR(ETIMEDOUT
));
5642 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5643 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5644 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5645 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5646 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5647 return SCTP_DISPOSITION_DELETE_TCB
;
5650 switch (asoc
->state
) {
5651 case SCTP_STATE_SHUTDOWN_SENT
:
5652 reply
= sctp_make_shutdown(asoc
, NULL
);
5655 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5656 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5667 /* Do some failure management (Section 8.2).
5668 * If we remove the transport an SHUTDOWN was last sent to, don't
5669 * do failure management.
5671 if (asoc
->shutdown_last_sent_to
)
5672 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5673 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5675 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5676 * the T2-shutdown timer.
5678 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5680 /* Restart the T2-shutdown timer. */
5681 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5682 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5683 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5684 return SCTP_DISPOSITION_CONSUME
;
5687 return SCTP_DISPOSITION_NOMEM
;
5691 * ADDIP Section 4.1 ASCONF CHunk Procedures
5692 * If the T4 RTO timer expires the endpoint should do B1 to B5
5694 sctp_disposition_t
sctp_sf_t4_timer_expire(
5696 const struct sctp_endpoint
*ep
,
5697 const struct sctp_association
*asoc
,
5698 const sctp_subtype_t type
,
5700 sctp_cmd_seq_t
*commands
)
5702 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5703 struct sctp_transport
*transport
= chunk
->transport
;
5705 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5707 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5708 * detection on the appropriate destination address as defined in
5709 * RFC2960 [5] section 8.1 and 8.2.
5712 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5713 SCTP_TRANSPORT(transport
));
5715 /* Reconfig T4 timer and transport. */
5716 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5718 /* ADDIP 4.1 B2) Increment the association error counters and perform
5719 * endpoint failure detection on the association as defined in
5720 * RFC2960 [5] section 8.1 and 8.2.
5721 * association error counter is incremented in SCTP_CMD_STRIKE.
5723 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5724 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5725 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5726 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5727 SCTP_ERROR(ETIMEDOUT
));
5728 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5729 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5730 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5731 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5732 return SCTP_DISPOSITION_ABORT
;
5735 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5736 * the ASCONF chunk was sent by doubling the RTO timer value.
5737 * This is done in SCTP_CMD_STRIKE.
5740 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5741 * choose an alternate destination address (please refer to RFC2960
5742 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5743 * chunk, it MUST be the same (including its serial number) as the last
5746 sctp_chunk_hold(asoc
->addip_last_asconf
);
5747 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5748 SCTP_CHUNK(asoc
->addip_last_asconf
));
5750 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5751 * destination is selected, then the RTO used will be that of the new
5752 * destination address.
5754 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5755 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5757 return SCTP_DISPOSITION_CONSUME
;
5760 /* sctpimpguide-05 Section 2.12.2
5761 * The sender of the SHUTDOWN MAY also start an overall guard timer
5762 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5763 * At the expiration of this timer the sender SHOULD abort the association
5764 * by sending an ABORT chunk.
5766 sctp_disposition_t
sctp_sf_t5_timer_expire(struct net
*net
,
5767 const struct sctp_endpoint
*ep
,
5768 const struct sctp_association
*asoc
,
5769 const sctp_subtype_t type
,
5771 sctp_cmd_seq_t
*commands
)
5773 struct sctp_chunk
*reply
= NULL
;
5775 pr_debug("%s: timer T5 expired\n", __func__
);
5777 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5779 reply
= sctp_make_abort(asoc
, NULL
, 0);
5783 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5784 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5785 SCTP_ERROR(ETIMEDOUT
));
5786 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5787 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5789 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5790 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5792 return SCTP_DISPOSITION_DELETE_TCB
;
5794 return SCTP_DISPOSITION_NOMEM
;
5797 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5798 * the association is automatically closed by starting the shutdown process.
5799 * The work that needs to be done is same as when SHUTDOWN is initiated by
5800 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5802 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5804 const struct sctp_endpoint
*ep
,
5805 const struct sctp_association
*asoc
,
5806 const sctp_subtype_t type
,
5808 sctp_cmd_seq_t
*commands
)
5812 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5814 /* From 9.2 Shutdown of an Association
5815 * Upon receipt of the SHUTDOWN primitive from its upper
5816 * layer, the endpoint enters SHUTDOWN-PENDING state and
5817 * remains there until all outstanding data has been
5818 * acknowledged by its peer. The endpoint accepts no new data
5819 * from its upper layer, but retransmits data to the far end
5820 * if necessary to fill gaps.
5822 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5823 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5825 disposition
= SCTP_DISPOSITION_CONSUME
;
5826 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5827 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5833 /*****************************************************************************
5834 * These are sa state functions which could apply to all types of events.
5835 ****************************************************************************/
5838 * This table entry is not implemented.
5841 * (endpoint, asoc, chunk)
5843 * The return value is the disposition of the chunk.
5845 sctp_disposition_t
sctp_sf_not_impl(struct net
*net
,
5846 const struct sctp_endpoint
*ep
,
5847 const struct sctp_association
*asoc
,
5848 const sctp_subtype_t type
,
5850 sctp_cmd_seq_t
*commands
)
5852 return SCTP_DISPOSITION_NOT_IMPL
;
5856 * This table entry represents a bug.
5859 * (endpoint, asoc, chunk)
5861 * The return value is the disposition of the chunk.
5863 sctp_disposition_t
sctp_sf_bug(struct net
*net
,
5864 const struct sctp_endpoint
*ep
,
5865 const struct sctp_association
*asoc
,
5866 const sctp_subtype_t type
,
5868 sctp_cmd_seq_t
*commands
)
5870 return SCTP_DISPOSITION_BUG
;
5874 * This table entry represents the firing of a timer in the wrong state.
5875 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5876 * when the association is in the wrong state. This event should
5877 * be ignored, so as to prevent any rearming of the timer.
5880 * (endpoint, asoc, chunk)
5882 * The return value is the disposition of the chunk.
5884 sctp_disposition_t
sctp_sf_timer_ignore(struct net
*net
,
5885 const struct sctp_endpoint
*ep
,
5886 const struct sctp_association
*asoc
,
5887 const sctp_subtype_t type
,
5889 sctp_cmd_seq_t
*commands
)
5891 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
5893 return SCTP_DISPOSITION_CONSUME
;
5896 /********************************************************************
5897 * 2nd Level Abstractions
5898 ********************************************************************/
5900 /* Pull the SACK chunk based on the SACK header. */
5901 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5903 struct sctp_sackhdr
*sack
;
5908 /* Protect ourselves from reading too far into
5909 * the skb from a bogus sender.
5911 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5913 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5914 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5915 len
= sizeof(struct sctp_sackhdr
);
5916 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5917 if (len
> chunk
->skb
->len
)
5920 skb_pull(chunk
->skb
, len
);
5925 /* Create an ABORT packet to be sent as a response, with the specified
5928 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
5929 const struct sctp_endpoint
*ep
,
5930 const struct sctp_association
*asoc
,
5931 struct sctp_chunk
*chunk
,
5932 const void *payload
,
5935 struct sctp_packet
*packet
;
5936 struct sctp_chunk
*abort
;
5938 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
5942 * The T bit will be set if the asoc is NULL.
5944 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5946 sctp_ootb_pkt_free(packet
);
5950 /* Reflect vtag if T-Bit is set */
5951 if (sctp_test_T_bit(abort
))
5952 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5954 /* Add specified error causes, i.e., payload, to the
5957 sctp_addto_chunk(abort
, paylen
, payload
);
5959 /* Set the skb to the belonging sock for accounting. */
5960 abort
->skb
->sk
= ep
->base
.sk
;
5962 sctp_packet_append_chunk(packet
, abort
);
5969 /* Allocate a packet for responding in the OOTB conditions. */
5970 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
5971 const struct sctp_association
*asoc
,
5972 const struct sctp_chunk
*chunk
)
5974 struct sctp_packet
*packet
;
5975 struct sctp_transport
*transport
;
5980 /* Get the source and destination port from the inbound packet. */
5981 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5982 dport
= ntohs(chunk
->sctp_hdr
->source
);
5984 /* The V-tag is going to be the same as the inbound packet if no
5985 * association exists, otherwise, use the peer's vtag.
5988 /* Special case the INIT-ACK as there is no peer's vtag
5991 switch (chunk
->chunk_hdr
->type
) {
5992 case SCTP_CID_INIT_ACK
:
5994 sctp_initack_chunk_t
*initack
;
5996 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5997 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6001 vtag
= asoc
->peer
.i
.init_tag
;
6005 /* Special case the INIT and stale COOKIE_ECHO as there is no
6008 switch (chunk
->chunk_hdr
->type
) {
6011 sctp_init_chunk_t
*init
;
6013 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
6014 vtag
= ntohl(init
->init_hdr
.init_tag
);
6018 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6023 /* Make a transport for the bucket, Eliza... */
6024 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6028 /* Cache a route for the transport with the chunk's destination as
6029 * the source address.
6031 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6032 sctp_sk(net
->sctp
.ctl_sock
));
6034 packet
= &transport
->packet
;
6035 sctp_packet_init(packet
, transport
, sport
, dport
);
6036 sctp_packet_config(packet
, vtag
, 0);
6044 /* Free the packet allocated earlier for responding in the OOTB condition. */
6045 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6047 sctp_transport_free(packet
->transport
);
6050 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6051 static void sctp_send_stale_cookie_err(struct net
*net
,
6052 const struct sctp_endpoint
*ep
,
6053 const struct sctp_association
*asoc
,
6054 const struct sctp_chunk
*chunk
,
6055 sctp_cmd_seq_t
*commands
,
6056 struct sctp_chunk
*err_chunk
)
6058 struct sctp_packet
*packet
;
6061 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6063 struct sctp_signed_cookie
*cookie
;
6065 /* Override the OOTB vtag from the cookie. */
6066 cookie
= chunk
->subh
.cookie_hdr
;
6067 packet
->vtag
= cookie
->c
.peer_vtag
;
6069 /* Set the skb to the belonging sock for accounting. */
6070 err_chunk
->skb
->sk
= ep
->base
.sk
;
6071 sctp_packet_append_chunk(packet
, err_chunk
);
6072 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6073 SCTP_PACKET(packet
));
6074 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6076 sctp_chunk_free (err_chunk
);
6081 /* Process a data chunk */
6082 static int sctp_eat_data(const struct sctp_association
*asoc
,
6083 struct sctp_chunk
*chunk
,
6084 sctp_cmd_seq_t
*commands
)
6086 sctp_datahdr_t
*data_hdr
;
6087 struct sctp_chunk
*err
;
6089 sctp_verb_t deliver
;
6092 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6093 struct sock
*sk
= asoc
->base
.sk
;
6094 struct net
*net
= sock_net(sk
);
6099 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
6100 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
6102 tsn
= ntohl(data_hdr
->tsn
);
6103 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6105 /* ASSERT: Now skb->data is really the user data. */
6107 /* Process ECN based congestion.
6109 * Since the chunk structure is reused for all chunks within
6110 * a packet, we use ecn_ce_done to track if we've already
6111 * done CE processing for this packet.
6113 * We need to do ECN processing even if we plan to discard the
6117 if (asoc
->peer
.ecn_capable
&& !chunk
->ecn_ce_done
) {
6118 struct sctp_af
*af
= SCTP_INPUT_CB(chunk
->skb
)->af
;
6119 chunk
->ecn_ce_done
= 1;
6121 if (af
->is_ce(sctp_gso_headskb(chunk
->skb
))) {
6122 /* Do real work as sideffect. */
6123 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6128 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6130 /* The TSN is too high--silently discard the chunk and
6131 * count on it getting retransmitted later.
6134 chunk
->asoc
->stats
.outofseqtsns
++;
6135 return SCTP_IERROR_HIGH_TSN
;
6136 } else if (tmp
> 0) {
6137 /* This is a duplicate. Record it. */
6138 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6139 return SCTP_IERROR_DUP_TSN
;
6142 /* This is a new TSN. */
6144 /* Discard if there is no room in the receive window.
6145 * Actually, allow a little bit of overflow (up to a MTU).
6147 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6148 datalen
-= sizeof(sctp_data_chunk_t
);
6150 deliver
= SCTP_CMD_CHUNK_ULP
;
6152 /* Think about partial delivery. */
6153 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6155 /* Even if we don't accept this chunk there is
6158 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6161 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6162 * seems a bit troublesome in that frag_point varies based on
6163 * PMTU. In cases, such as loopback, this might be a rather
6166 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6167 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6169 /* If this is the next TSN, consider reneging to make
6170 * room. Note: Playing nice with a confused sender. A
6171 * malicious sender can still eat up all our buffer
6172 * space and in the future we may want to detect and
6173 * do more drastic reneging.
6175 if (sctp_tsnmap_has_gap(map
) &&
6176 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6177 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6178 deliver
= SCTP_CMD_RENEGE
;
6180 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6181 __func__
, tsn
, datalen
, asoc
->rwnd
);
6183 return SCTP_IERROR_IGNORE_TSN
;
6188 * Also try to renege to limit our memory usage in the event that
6189 * we are under memory pressure
6190 * If we can't renege, don't worry about it, the sk_rmem_schedule
6191 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6192 * memory usage too much
6194 if (*sk
->sk_prot_creator
->memory_pressure
) {
6195 if (sctp_tsnmap_has_gap(map
) &&
6196 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6197 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6199 deliver
= SCTP_CMD_RENEGE
;
6204 * Section 3.3.10.9 No User Data (9)
6208 * No User Data: This error cause is returned to the originator of a
6209 * DATA chunk if a received DATA chunk has no user data.
6211 if (unlikely(0 == datalen
)) {
6212 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6214 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6217 /* We are going to ABORT, so we might as well stop
6218 * processing the rest of the chunks in the packet.
6220 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
6221 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6222 SCTP_ERROR(ECONNABORTED
));
6223 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6224 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6225 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6226 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6227 return SCTP_IERROR_NO_DATA
;
6230 chunk
->data_accepted
= 1;
6232 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6233 * if we renege and the chunk arrives again.
6235 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6236 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6238 chunk
->asoc
->stats
.iuodchunks
++;
6240 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6242 chunk
->asoc
->stats
.iodchunks
++;
6246 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6248 * If an endpoint receive a DATA chunk with an invalid stream
6249 * identifier, it shall acknowledge the reception of the DATA chunk
6250 * following the normal procedure, immediately send an ERROR chunk
6251 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6252 * and discard the DATA chunk.
6254 sid
= ntohs(data_hdr
->stream
);
6255 if (sid
>= asoc
->c
.sinit_max_instreams
) {
6256 /* Mark tsn as received even though we drop it */
6257 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6259 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6261 sizeof(data_hdr
->stream
),
6264 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6266 return SCTP_IERROR_BAD_STREAM
;
6269 /* Check to see if the SSN is possible for this TSN.
6270 * The biggest gap we can record is 4K wide. Since SSNs wrap
6271 * at an unsigned short, there is no way that an SSN can
6272 * wrap and for a valid TSN. We can simply check if the current
6273 * SSN is smaller then the next expected one. If it is, it wrapped
6276 ssn
= ntohs(data_hdr
->ssn
);
6277 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(asoc
->stream
, in
, sid
)))
6278 return SCTP_IERROR_PROTO_VIOLATION
;
6280 /* Send the data up to the user. Note: Schedule the
6281 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6282 * chunk needs the updated rwnd.
6284 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6286 return SCTP_IERROR_NO_ERROR
;