1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <linux-sctp@vger.kernel.org>
33 * Written or modified by:
34 * La Monte H.P. Yarroll <piggy@acm.org>
35 * Karl Knutson <karl@athena.chicago.il.us>
36 * Mathew Kotowsky <kotowsky@sctp.org>
37 * Sridhar Samudrala <samudrala@us.ibm.com>
38 * Jon Grimm <jgrimm@us.ibm.com>
39 * Hui Huang <hui.huang@nokia.com>
40 * Dajiang Zhang <dajiang.zhang@nokia.com>
41 * Daisy Chang <daisyc@us.ibm.com>
42 * Ardelle Fan <ardelle.fan@intel.com>
43 * Ryan Layer <rmlayer@us.ibm.com>
44 * Kevin Gao <kevin.gao@intel.com>
47 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
49 #include <linux/types.h>
50 #include <linux/kernel.h>
52 #include <linux/ipv6.h>
53 #include <linux/net.h>
54 #include <linux/inet.h>
55 #include <linux/slab.h>
57 #include <net/inet_ecn.h>
58 #include <linux/skbuff.h>
59 #include <net/sctp/sctp.h>
60 #include <net/sctp/sm.h>
61 #include <net/sctp/structs.h>
63 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
64 const struct sctp_endpoint
*ep
,
65 const struct sctp_association
*asoc
,
66 struct sctp_chunk
*chunk
,
69 static int sctp_eat_data(const struct sctp_association
*asoc
,
70 struct sctp_chunk
*chunk
,
71 sctp_cmd_seq_t
*commands
);
72 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
73 const struct sctp_association
*asoc
,
74 const struct sctp_chunk
*chunk
);
75 static void sctp_send_stale_cookie_err(struct net
*net
,
76 const struct sctp_endpoint
*ep
,
77 const struct sctp_association
*asoc
,
78 const struct sctp_chunk
*chunk
,
79 sctp_cmd_seq_t
*commands
,
80 struct sctp_chunk
*err_chunk
);
81 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(struct net
*net
,
82 const struct sctp_endpoint
*ep
,
83 const struct sctp_association
*asoc
,
84 const sctp_subtype_t type
,
86 sctp_cmd_seq_t
*commands
);
87 static sctp_disposition_t
sctp_sf_shut_8_4_5(struct net
*net
,
88 const struct sctp_endpoint
*ep
,
89 const struct sctp_association
*asoc
,
90 const sctp_subtype_t type
,
92 sctp_cmd_seq_t
*commands
);
93 static sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
94 const struct sctp_endpoint
*ep
,
95 const struct sctp_association
*asoc
,
96 const sctp_subtype_t type
,
98 sctp_cmd_seq_t
*commands
);
99 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
101 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
102 sctp_cmd_seq_t
*commands
,
103 __be16 error
, int sk_err
,
104 const struct sctp_association
*asoc
,
105 struct sctp_transport
*transport
);
107 static sctp_disposition_t
sctp_sf_abort_violation(
109 const struct sctp_endpoint
*ep
,
110 const struct sctp_association
*asoc
,
112 sctp_cmd_seq_t
*commands
,
114 const size_t paylen
);
116 static sctp_disposition_t
sctp_sf_violation_chunklen(
118 const struct sctp_endpoint
*ep
,
119 const struct sctp_association
*asoc
,
120 const sctp_subtype_t type
,
122 sctp_cmd_seq_t
*commands
);
124 static sctp_disposition_t
sctp_sf_violation_paramlen(
126 const struct sctp_endpoint
*ep
,
127 const struct sctp_association
*asoc
,
128 const sctp_subtype_t type
,
129 void *arg
, void *ext
,
130 sctp_cmd_seq_t
*commands
);
132 static sctp_disposition_t
sctp_sf_violation_ctsn(
134 const struct sctp_endpoint
*ep
,
135 const struct sctp_association
*asoc
,
136 const sctp_subtype_t type
,
138 sctp_cmd_seq_t
*commands
);
140 static sctp_disposition_t
sctp_sf_violation_chunk(
142 const struct sctp_endpoint
*ep
,
143 const struct sctp_association
*asoc
,
144 const sctp_subtype_t type
,
146 sctp_cmd_seq_t
*commands
);
148 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
149 const struct sctp_endpoint
*ep
,
150 const struct sctp_association
*asoc
,
151 const sctp_subtype_t type
,
152 struct sctp_chunk
*chunk
);
154 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
155 const struct sctp_endpoint
*ep
,
156 const struct sctp_association
*asoc
,
157 const sctp_subtype_t type
,
159 sctp_cmd_seq_t
*commands
);
161 /* Small helper function that checks if the chunk length
162 * is of the appropriate length. The 'required_length' argument
163 * is set to be the size of a specific chunk we are testing.
164 * Return Values: 1 = Valid length
169 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
170 __u16 required_length
)
172 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
174 /* Previously already marked? */
175 if (unlikely(chunk
->pdiscard
))
177 if (unlikely(chunk_length
< required_length
))
183 /**********************************************************
184 * These are the state functions for handling chunk events.
185 **********************************************************/
188 * Process the final SHUTDOWN COMPLETE.
190 * Section: 4 (C) (diagram), 9.2
191 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
192 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
193 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
194 * should stop the T2-shutdown timer and remove all knowledge of the
195 * association (and thus the association enters the CLOSED state).
197 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
198 * C) Rules for packet carrying SHUTDOWN COMPLETE:
200 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
201 * if the Verification Tag field of the packet matches its own tag and
202 * the T bit is not set
204 * it is set to its peer's tag and the T bit is set in the Chunk
206 * Otherwise, the receiver MUST silently discard the packet
207 * and take no further action. An endpoint MUST ignore the
208 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
211 * (endpoint, asoc, chunk)
214 * (asoc, reply_msg, msg_up, timers, counters)
216 * The return value is the disposition of the chunk.
218 sctp_disposition_t
sctp_sf_do_4_C(struct net
*net
,
219 const struct sctp_endpoint
*ep
,
220 const struct sctp_association
*asoc
,
221 const sctp_subtype_t type
,
223 sctp_cmd_seq_t
*commands
)
225 struct sctp_chunk
*chunk
= arg
;
226 struct sctp_ulpevent
*ev
;
228 if (!sctp_vtag_verify_either(chunk
, asoc
))
229 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
231 /* RFC 2960 6.10 Bundling
233 * An endpoint MUST NOT bundle INIT, INIT ACK or
234 * SHUTDOWN COMPLETE with any other chunks.
236 if (!chunk
->singleton
)
237 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
239 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
240 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
241 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
244 /* RFC 2960 10.2 SCTP-to-ULP
246 * H) SHUTDOWN COMPLETE notification
248 * When SCTP completes the shutdown procedures (section 9.2) this
249 * notification is passed to the upper layer.
251 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
252 0, 0, 0, NULL
, GFP_ATOMIC
);
254 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
257 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
258 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
259 * not the chunk should be discarded. If the endpoint is in
260 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
261 * T2-shutdown timer and remove all knowledge of the
262 * association (and thus the association enters the CLOSED
265 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
266 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
268 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
269 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
271 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
272 SCTP_STATE(SCTP_STATE_CLOSED
));
274 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
275 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
277 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
279 return SCTP_DISPOSITION_DELETE_TCB
;
283 * Respond to a normal INIT chunk.
284 * We are the side that is being asked for an association.
286 * Section: 5.1 Normal Establishment of an Association, B
287 * B) "Z" shall respond immediately with an INIT ACK chunk. The
288 * destination IP address of the INIT ACK MUST be set to the source
289 * IP address of the INIT to which this INIT ACK is responding. In
290 * the response, besides filling in other parameters, "Z" must set the
291 * Verification Tag field to Tag_A, and also provide its own
292 * Verification Tag (Tag_Z) in the Initiate Tag field.
294 * Verification Tag: Must be 0.
297 * (endpoint, asoc, chunk)
300 * (asoc, reply_msg, msg_up, timers, counters)
302 * The return value is the disposition of the chunk.
304 sctp_disposition_t
sctp_sf_do_5_1B_init(struct net
*net
,
305 const struct sctp_endpoint
*ep
,
306 const struct sctp_association
*asoc
,
307 const sctp_subtype_t type
,
309 sctp_cmd_seq_t
*commands
)
311 struct sctp_chunk
*chunk
= arg
;
312 struct sctp_chunk
*repl
;
313 struct sctp_association
*new_asoc
;
314 struct sctp_chunk
*err_chunk
;
315 struct sctp_packet
*packet
;
316 sctp_unrecognized_param_t
*unk_param
;
320 * An endpoint MUST NOT bundle INIT, INIT ACK or
321 * SHUTDOWN COMPLETE with any other chunks.
324 * Furthermore, we require that the receiver of an INIT chunk MUST
325 * enforce these rules by silently discarding an arriving packet
326 * with an INIT chunk that is bundled with other chunks.
328 if (!chunk
->singleton
)
329 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
331 /* If the packet is an OOTB packet which is temporarily on the
332 * control endpoint, respond with an ABORT.
334 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
335 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
336 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
339 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
342 if (chunk
->sctp_hdr
->vtag
!= 0)
343 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
345 /* Make sure that the INIT chunk has a valid length.
346 * Normally, this would cause an ABORT with a Protocol Violation
347 * error, but since we don't have an association, we'll
348 * just discard the packet.
350 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
351 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
353 /* If the INIT is coming toward a closing socket, we'll send back
354 * and ABORT. Essentially, this catches the race of INIT being
355 * backloged to the socket at the same time as the user isses close().
356 * Since the socket and all its associations are going away, we
357 * can treat this OOTB
359 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
360 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
362 /* Verify the INIT chunk before processing it. */
364 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
365 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
367 /* This chunk contains fatal error. It is to be discarded.
368 * Send an ABORT, with causes if there is any.
371 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
372 (__u8
*)(err_chunk
->chunk_hdr
) +
373 sizeof(sctp_chunkhdr_t
),
374 ntohs(err_chunk
->chunk_hdr
->length
) -
375 sizeof(sctp_chunkhdr_t
));
377 sctp_chunk_free(err_chunk
);
380 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
381 SCTP_PACKET(packet
));
382 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
383 return SCTP_DISPOSITION_CONSUME
;
385 return SCTP_DISPOSITION_NOMEM
;
388 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
393 /* Grab the INIT header. */
394 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
396 /* Tag the variable length parameters. */
397 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
399 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
403 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
404 sctp_scope(sctp_source(chunk
)),
408 /* The call, sctp_process_init(), can fail on memory allocation. */
409 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
410 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
414 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
416 /* If there are errors need to be reported for unknown parameters,
417 * make sure to reserve enough room in the INIT ACK for them.
421 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
422 sizeof(sctp_chunkhdr_t
);
424 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
428 /* If there are errors need to be reported for unknown parameters,
429 * include them in the outgoing INIT ACK as "Unrecognized parameter"
433 /* Get the "Unrecognized parameter" parameter(s) out of the
434 * ERROR chunk generated by sctp_verify_init(). Since the
435 * error cause code for "unknown parameter" and the
436 * "Unrecognized parameter" type is the same, we can
437 * construct the parameters in INIT ACK by copying the
440 unk_param
= (sctp_unrecognized_param_t
*)
441 ((__u8
*)(err_chunk
->chunk_hdr
) +
442 sizeof(sctp_chunkhdr_t
));
443 /* Replace the cause code with the "Unrecognized parameter"
446 sctp_addto_chunk(repl
, len
, unk_param
);
447 sctp_chunk_free(err_chunk
);
450 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
452 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
455 * Note: After sending out INIT ACK with the State Cookie parameter,
456 * "Z" MUST NOT allocate any resources, nor keep any states for the
457 * new association. Otherwise, "Z" will be vulnerable to resource
460 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
462 return SCTP_DISPOSITION_DELETE_TCB
;
465 sctp_association_free(new_asoc
);
468 sctp_chunk_free(err_chunk
);
469 return SCTP_DISPOSITION_NOMEM
;
473 * Respond to a normal INIT ACK chunk.
474 * We are the side that is initiating the association.
476 * Section: 5.1 Normal Establishment of an Association, C
477 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
478 * timer and leave COOKIE-WAIT state. "A" shall then send the State
479 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
480 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
482 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
483 * DATA chunks, but it MUST be the first chunk in the packet and
484 * until the COOKIE ACK is returned the sender MUST NOT send any
485 * other packets to the peer.
487 * Verification Tag: 3.3.3
488 * If the value of the Initiate Tag in a received INIT ACK chunk is
489 * found to be 0, the receiver MUST treat it as an error and close the
490 * association by transmitting an ABORT.
493 * (endpoint, asoc, chunk)
496 * (asoc, reply_msg, msg_up, timers, counters)
498 * The return value is the disposition of the chunk.
500 sctp_disposition_t
sctp_sf_do_5_1C_ack(struct net
*net
,
501 const struct sctp_endpoint
*ep
,
502 const struct sctp_association
*asoc
,
503 const sctp_subtype_t type
,
505 sctp_cmd_seq_t
*commands
)
507 struct sctp_chunk
*chunk
= arg
;
508 sctp_init_chunk_t
*initchunk
;
509 struct sctp_chunk
*err_chunk
;
510 struct sctp_packet
*packet
;
512 if (!sctp_vtag_verify(chunk
, asoc
))
513 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
516 * An endpoint MUST NOT bundle INIT, INIT ACK or
517 * SHUTDOWN COMPLETE with any other chunks.
519 if (!chunk
->singleton
)
520 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
522 /* Make sure that the INIT-ACK chunk has a valid length */
523 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
524 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
526 /* Grab the INIT header. */
527 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
529 /* Verify the INIT chunk before processing it. */
531 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
532 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
535 sctp_error_t error
= SCTP_ERROR_NO_RESOURCE
;
537 /* This chunk contains fatal error. It is to be discarded.
538 * Send an ABORT, with causes. If there are no causes,
539 * then there wasn't enough memory. Just terminate
543 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
544 (__u8
*)(err_chunk
->chunk_hdr
) +
545 sizeof(sctp_chunkhdr_t
),
546 ntohs(err_chunk
->chunk_hdr
->length
) -
547 sizeof(sctp_chunkhdr_t
));
549 sctp_chunk_free(err_chunk
);
552 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
553 SCTP_PACKET(packet
));
554 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
555 error
= SCTP_ERROR_INV_PARAM
;
559 /* SCTP-AUTH, Section 6.3:
560 * It should be noted that if the receiver wants to tear
561 * down an association in an authenticated way only, the
562 * handling of malformed packets should not result in
563 * tearing down the association.
565 * This means that if we only want to abort associations
566 * in an authenticated way (i.e AUTH+ABORT), then we
567 * can't destroy this association just because the packet
570 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
571 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
573 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
574 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
575 asoc
, chunk
->transport
);
578 /* Tag the variable length parameters. Note that we never
579 * convert the parameters in an INIT chunk.
581 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
583 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
585 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
586 SCTP_PEER_INIT(initchunk
));
588 /* Reset init error count upon receipt of INIT-ACK. */
589 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
591 /* 5.1 C) "A" shall stop the T1-init timer and leave
592 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
593 * timer, and enter the COOKIE-ECHOED state.
595 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
596 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
597 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
598 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
599 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
600 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
602 /* SCTP-AUTH: genereate the assocition shared keys so that
603 * we can potentially signe the COOKIE-ECHO.
605 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
607 /* 5.1 C) "A" shall then send the State Cookie received in the
608 * INIT ACK chunk in a COOKIE ECHO chunk, ...
610 /* If there is any errors to report, send the ERROR chunk generated
611 * for unknown parameters as well.
613 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
614 SCTP_CHUNK(err_chunk
));
616 return SCTP_DISPOSITION_CONSUME
;
620 * Respond to a normal COOKIE ECHO chunk.
621 * We are the side that is being asked for an association.
623 * Section: 5.1 Normal Establishment of an Association, D
624 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
625 * with a COOKIE ACK chunk after building a TCB and moving to
626 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
627 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
628 * chunk MUST be the first chunk in the packet.
630 * IMPLEMENTATION NOTE: An implementation may choose to send the
631 * Communication Up notification to the SCTP user upon reception
632 * of a valid COOKIE ECHO chunk.
634 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
635 * D) Rules for packet carrying a COOKIE ECHO
637 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
638 * Initial Tag received in the INIT ACK.
640 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
643 * (endpoint, asoc, chunk)
646 * (asoc, reply_msg, msg_up, timers, counters)
648 * The return value is the disposition of the chunk.
650 sctp_disposition_t
sctp_sf_do_5_1D_ce(struct net
*net
,
651 const struct sctp_endpoint
*ep
,
652 const struct sctp_association
*asoc
,
653 const sctp_subtype_t type
, void *arg
,
654 sctp_cmd_seq_t
*commands
)
656 struct sctp_chunk
*chunk
= arg
;
657 struct sctp_association
*new_asoc
;
658 sctp_init_chunk_t
*peer_init
;
659 struct sctp_chunk
*repl
;
660 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
662 struct sctp_chunk
*err_chk_p
;
665 /* If the packet is an OOTB packet which is temporarily on the
666 * control endpoint, respond with an ABORT.
668 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
669 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
670 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
673 /* Make sure that the COOKIE_ECHO chunk has a valid length.
674 * In this case, we check that we have enough for at least a
675 * chunk header. More detailed verification is done
676 * in sctp_unpack_cookie().
678 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
679 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
681 /* If the endpoint is not listening or if the number of associations
682 * on the TCP-style socket exceed the max backlog, respond with an
686 if (!sctp_sstate(sk
, LISTENING
) ||
687 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
688 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
690 /* "Decode" the chunk. We have no optional parameters so we
693 chunk
->subh
.cookie_hdr
=
694 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
695 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
696 sizeof(sctp_chunkhdr_t
)))
699 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
700 * "Z" will reply with a COOKIE ACK chunk after building a TCB
701 * and moving to the ESTABLISHED state.
703 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
707 * If the re-build failed, what is the proper error path
710 * [We should abort the association. --piggy]
713 /* FIXME: Several errors are possible. A bad cookie should
714 * be silently discarded, but think about logging it too.
717 case -SCTP_IERROR_NOMEM
:
720 case -SCTP_IERROR_STALE_COOKIE
:
721 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
723 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
725 case -SCTP_IERROR_BAD_SIG
:
727 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
732 /* Delay state machine commands until later.
734 * Re-build the bind address for the association is done in
735 * the sctp_unpack_cookie() already.
737 /* This is a brand-new association, so these are not yet side
738 * effects--it is safe to run them here.
740 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
742 if (!sctp_process_init(new_asoc
, chunk
,
743 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
744 peer_init
, GFP_ATOMIC
))
747 /* SCTP-AUTH: Now that we've populate required fields in
748 * sctp_process_init, set up the assocaition shared keys as
749 * necessary so that we can potentially authenticate the ACK
751 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
755 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
756 * is supposed to be authenticated and we have to do delayed
757 * authentication. We've just recreated the association using
758 * the information in the cookie and now it's much easier to
759 * do the authentication.
761 if (chunk
->auth_chunk
) {
762 struct sctp_chunk auth
;
765 /* Make sure that we and the peer are AUTH capable */
766 if (!net
->sctp
.auth_enable
|| !new_asoc
->peer
.auth_capable
) {
767 sctp_association_free(new_asoc
);
768 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
771 /* set-up our fake chunk so that we can process it */
772 auth
.skb
= chunk
->auth_chunk
;
773 auth
.asoc
= chunk
->asoc
;
774 auth
.sctp_hdr
= chunk
->sctp_hdr
;
775 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
776 sizeof(sctp_chunkhdr_t
));
777 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
778 auth
.transport
= chunk
->transport
;
780 ret
= sctp_sf_authenticate(net
, ep
, new_asoc
, type
, &auth
);
781 if (ret
!= SCTP_IERROR_NO_ERROR
) {
782 sctp_association_free(new_asoc
);
783 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
787 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
791 /* RFC 2960 5.1 Normal Establishment of an Association
793 * D) IMPLEMENTATION NOTE: An implementation may choose to
794 * send the Communication Up notification to the SCTP user
795 * upon reception of a valid COOKIE ECHO chunk.
797 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
798 new_asoc
->c
.sinit_num_ostreams
,
799 new_asoc
->c
.sinit_max_instreams
,
804 /* Sockets API Draft Section 5.3.1.6
805 * When a peer sends a Adaptation Layer Indication parameter , SCTP
806 * delivers this notification to inform the application that of the
807 * peers requested adaptation layer.
809 if (new_asoc
->peer
.adaptation_ind
) {
810 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
816 /* Add all the state machine commands now since we've created
817 * everything. This way we don't introduce memory corruptions
818 * during side-effect processing and correclty count established
821 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
822 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
823 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
824 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
825 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
826 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
828 if (new_asoc
->autoclose
)
829 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
830 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
832 /* This will send the COOKIE ACK */
833 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
835 /* Queue the ASSOC_CHANGE event */
836 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
838 /* Send up the Adaptation Layer Indication event */
840 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
841 SCTP_ULPEVENT(ai_ev
));
843 return SCTP_DISPOSITION_CONSUME
;
846 sctp_ulpevent_free(ev
);
848 sctp_chunk_free(repl
);
850 sctp_association_free(new_asoc
);
852 return SCTP_DISPOSITION_NOMEM
;
856 * Respond to a normal COOKIE ACK chunk.
857 * We are the side that is being asked for an association.
859 * RFC 2960 5.1 Normal Establishment of an Association
861 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
862 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
863 * timer. It may also notify its ULP about the successful
864 * establishment of the association with a Communication Up
865 * notification (see Section 10).
869 * (endpoint, asoc, chunk)
872 * (asoc, reply_msg, msg_up, timers, counters)
874 * The return value is the disposition of the chunk.
876 sctp_disposition_t
sctp_sf_do_5_1E_ca(struct net
*net
,
877 const struct sctp_endpoint
*ep
,
878 const struct sctp_association
*asoc
,
879 const sctp_subtype_t type
, void *arg
,
880 sctp_cmd_seq_t
*commands
)
882 struct sctp_chunk
*chunk
= arg
;
883 struct sctp_ulpevent
*ev
;
885 if (!sctp_vtag_verify(chunk
, asoc
))
886 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
888 /* Verify that the chunk length for the COOKIE-ACK is OK.
889 * If we don't do this, any bundled chunks may be junked.
891 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
892 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
895 /* Reset init error count upon receipt of COOKIE-ACK,
896 * to avoid problems with the managemement of this
897 * counter in stale cookie situations when a transition back
898 * from the COOKIE-ECHOED state to the COOKIE-WAIT
899 * state is performed.
901 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
903 /* RFC 2960 5.1 Normal Establishment of an Association
905 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
906 * from the COOKIE-ECHOED state to the ESTABLISHED state,
907 * stopping the T1-cookie timer.
909 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
910 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
911 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
912 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
913 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
914 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
915 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
917 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
918 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
920 /* It may also notify its ULP about the successful
921 * establishment of the association with a Communication Up
922 * notification (see Section 10).
924 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
925 0, asoc
->c
.sinit_num_ostreams
,
926 asoc
->c
.sinit_max_instreams
,
932 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
934 /* Sockets API Draft Section 5.3.1.6
935 * When a peer sends a Adaptation Layer Indication parameter , SCTP
936 * delivers this notification to inform the application that of the
937 * peers requested adaptation layer.
939 if (asoc
->peer
.adaptation_ind
) {
940 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
944 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
948 return SCTP_DISPOSITION_CONSUME
;
950 return SCTP_DISPOSITION_NOMEM
;
953 /* Generate and sendout a heartbeat packet. */
954 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
955 const struct sctp_association
*asoc
,
956 const sctp_subtype_t type
,
958 sctp_cmd_seq_t
*commands
)
960 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
961 struct sctp_chunk
*reply
;
963 /* Send a heartbeat to our peer. */
964 reply
= sctp_make_heartbeat(asoc
, transport
);
966 return SCTP_DISPOSITION_NOMEM
;
968 /* Set rto_pending indicating that an RTT measurement
969 * is started with this heartbeat chunk.
971 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
972 SCTP_TRANSPORT(transport
));
974 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
975 return SCTP_DISPOSITION_CONSUME
;
978 /* Generate a HEARTBEAT packet on the given transport. */
979 sctp_disposition_t
sctp_sf_sendbeat_8_3(struct net
*net
,
980 const struct sctp_endpoint
*ep
,
981 const struct sctp_association
*asoc
,
982 const sctp_subtype_t type
,
984 sctp_cmd_seq_t
*commands
)
986 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
988 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
989 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
990 SCTP_ERROR(ETIMEDOUT
));
991 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
992 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
993 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
994 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
995 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
996 return SCTP_DISPOSITION_DELETE_TCB
;
1000 * The Sender-specific Heartbeat Info field should normally include
1001 * information about the sender's current time when this HEARTBEAT
1002 * chunk is sent and the destination transport address to which this
1003 * HEARTBEAT is sent (see Section 8.3).
1006 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1007 if (SCTP_DISPOSITION_NOMEM
==
1008 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1010 return SCTP_DISPOSITION_NOMEM
;
1012 /* Set transport error counter and association error counter
1013 * when sending heartbeat.
1015 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1016 SCTP_TRANSPORT(transport
));
1018 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1019 SCTP_TRANSPORT(transport
));
1020 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1021 SCTP_TRANSPORT(transport
));
1023 return SCTP_DISPOSITION_CONSUME
;
1027 * Process an heartbeat request.
1029 * Section: 8.3 Path Heartbeat
1030 * The receiver of the HEARTBEAT should immediately respond with a
1031 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1032 * from the received HEARTBEAT chunk.
1034 * Verification Tag: 8.5 Verification Tag [Normal verification]
1035 * When receiving an SCTP packet, the endpoint MUST ensure that the
1036 * value in the Verification Tag field of the received SCTP packet
1037 * matches its own Tag. If the received Verification Tag value does not
1038 * match the receiver's own tag value, the receiver shall silently
1039 * discard the packet and shall not process it any further except for
1040 * those cases listed in Section 8.5.1 below.
1043 * (endpoint, asoc, chunk)
1046 * (asoc, reply_msg, msg_up, timers, counters)
1048 * The return value is the disposition of the chunk.
1050 sctp_disposition_t
sctp_sf_beat_8_3(struct net
*net
,
1051 const struct sctp_endpoint
*ep
,
1052 const struct sctp_association
*asoc
,
1053 const sctp_subtype_t type
,
1055 sctp_cmd_seq_t
*commands
)
1057 sctp_paramhdr_t
*param_hdr
;
1058 struct sctp_chunk
*chunk
= arg
;
1059 struct sctp_chunk
*reply
;
1062 if (!sctp_vtag_verify(chunk
, asoc
))
1063 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1065 /* Make sure that the HEARTBEAT chunk has a valid length. */
1066 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_heartbeat_chunk_t
)))
1067 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1070 /* 8.3 The receiver of the HEARTBEAT should immediately
1071 * respond with a HEARTBEAT ACK that contains the Heartbeat
1072 * Information field copied from the received HEARTBEAT chunk.
1074 chunk
->subh
.hb_hdr
= (sctp_heartbeathdr_t
*) chunk
->skb
->data
;
1075 param_hdr
= (sctp_paramhdr_t
*) chunk
->subh
.hb_hdr
;
1076 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1078 if (ntohs(param_hdr
->length
) > paylen
)
1079 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
1080 param_hdr
, commands
);
1082 if (!pskb_pull(chunk
->skb
, paylen
))
1085 reply
= sctp_make_heartbeat_ack(asoc
, chunk
, param_hdr
, paylen
);
1089 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1090 return SCTP_DISPOSITION_CONSUME
;
1093 return SCTP_DISPOSITION_NOMEM
;
1097 * Process the returning HEARTBEAT ACK.
1099 * Section: 8.3 Path Heartbeat
1100 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1101 * should clear the error counter of the destination transport
1102 * address to which the HEARTBEAT was sent, and mark the destination
1103 * transport address as active if it is not so marked. The endpoint may
1104 * optionally report to the upper layer when an inactive destination
1105 * address is marked as active due to the reception of the latest
1106 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1107 * clear the association overall error count as well (as defined
1110 * The receiver of the HEARTBEAT ACK should also perform an RTT
1111 * measurement for that destination transport address using the time
1112 * value carried in the HEARTBEAT ACK chunk.
1114 * Verification Tag: 8.5 Verification Tag [Normal verification]
1117 * (endpoint, asoc, chunk)
1120 * (asoc, reply_msg, msg_up, timers, counters)
1122 * The return value is the disposition of the chunk.
1124 sctp_disposition_t
sctp_sf_backbeat_8_3(struct net
*net
,
1125 const struct sctp_endpoint
*ep
,
1126 const struct sctp_association
*asoc
,
1127 const sctp_subtype_t type
,
1129 sctp_cmd_seq_t
*commands
)
1131 struct sctp_chunk
*chunk
= arg
;
1132 union sctp_addr from_addr
;
1133 struct sctp_transport
*link
;
1134 sctp_sender_hb_info_t
*hbinfo
;
1135 unsigned long max_interval
;
1137 if (!sctp_vtag_verify(chunk
, asoc
))
1138 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1140 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1141 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
) +
1142 sizeof(sctp_sender_hb_info_t
)))
1143 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1146 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1147 /* Make sure that the length of the parameter is what we expect */
1148 if (ntohs(hbinfo
->param_hdr
.length
) !=
1149 sizeof(sctp_sender_hb_info_t
)) {
1150 return SCTP_DISPOSITION_DISCARD
;
1153 from_addr
= hbinfo
->daddr
;
1154 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1156 /* This should never happen, but lets log it if so. */
1157 if (unlikely(!link
)) {
1158 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1159 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1162 &from_addr
.v6
.sin6_addr
);
1164 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1167 &from_addr
.v4
.sin_addr
.s_addr
);
1169 return SCTP_DISPOSITION_DISCARD
;
1172 /* Validate the 64-bit random nonce. */
1173 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1174 return SCTP_DISPOSITION_DISCARD
;
1176 max_interval
= link
->hbinterval
+ link
->rto
;
1178 /* Check if the timestamp looks valid. */
1179 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1180 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1181 pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
1182 "for transport:%p\n", __func__
, link
);
1184 return SCTP_DISPOSITION_DISCARD
;
1187 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1188 * the HEARTBEAT should clear the error counter of the
1189 * destination transport address to which the HEARTBEAT was
1190 * sent and mark the destination transport address as active if
1191 * it is not so marked.
1193 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1195 return SCTP_DISPOSITION_CONSUME
;
1198 /* Helper function to send out an abort for the restart
1201 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1202 struct sctp_chunk
*init
,
1203 sctp_cmd_seq_t
*commands
)
1206 struct sctp_packet
*pkt
;
1207 union sctp_addr_param
*addrparm
;
1208 struct sctp_errhdr
*errhdr
;
1209 struct sctp_endpoint
*ep
;
1210 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1211 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1213 /* Build the error on the stack. We are way to malloc crazy
1214 * throughout the code today.
1216 errhdr
= (struct sctp_errhdr
*)buffer
;
1217 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1219 /* Copy into a parm format. */
1220 len
= af
->to_addr_param(ssa
, addrparm
);
1221 len
+= sizeof(sctp_errhdr_t
);
1223 errhdr
->cause
= SCTP_ERROR_RESTART
;
1224 errhdr
->length
= htons(len
);
1226 /* Assign to the control socket. */
1227 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1229 /* Association is NULL since this may be a restart attack and we
1230 * want to send back the attacker's vtag.
1232 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1236 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1238 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1240 /* Discard the rest of the inbound packet. */
1241 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1244 /* Even if there is no memory, treat as a failure so
1245 * the packet will get dropped.
1250 static bool list_has_sctp_addr(const struct list_head
*list
,
1251 union sctp_addr
*ipaddr
)
1253 struct sctp_transport
*addr
;
1255 list_for_each_entry(addr
, list
, transports
) {
1256 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1262 /* A restart is occurring, check to make sure no new addresses
1263 * are being added as we may be under a takeover attack.
1265 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1266 const struct sctp_association
*asoc
,
1267 struct sctp_chunk
*init
,
1268 sctp_cmd_seq_t
*commands
)
1270 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1271 struct sctp_transport
*new_addr
;
1274 /* Implementor's Guide - Section 5.2.2
1276 * Before responding the endpoint MUST check to see if the
1277 * unexpected INIT adds new addresses to the association. If new
1278 * addresses are added to the association, the endpoint MUST respond
1282 /* Search through all current addresses and make sure
1283 * we aren't adding any new ones.
1285 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1287 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1288 &new_addr
->ipaddr
)) {
1289 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1296 /* Return success if all addresses were found. */
1300 /* Populate the verification/tie tags based on overlapping INIT
1303 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1305 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1306 const struct sctp_association
*asoc
)
1308 switch (asoc
->state
) {
1310 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1312 case SCTP_STATE_COOKIE_WAIT
:
1313 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1314 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1315 new_asoc
->c
.peer_ttag
= 0;
1318 case SCTP_STATE_COOKIE_ECHOED
:
1319 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1320 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1321 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1324 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1325 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1328 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1329 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1333 /* Other parameters for the endpoint SHOULD be copied from the
1334 * existing parameters of the association (e.g. number of
1335 * outbound streams) into the INIT ACK and cookie.
1337 new_asoc
->rwnd
= asoc
->rwnd
;
1338 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1339 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1340 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1344 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1347 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1349 * Returns value representing action to be taken. These action values
1350 * correspond to Action/Description values in RFC 2960, Table 2.
1352 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1353 const struct sctp_association
*asoc
)
1355 /* In this case, the peer may have restarted. */
1356 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1357 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1358 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1359 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1362 /* Collision case B. */
1363 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1364 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1365 (0 == asoc
->c
.peer_vtag
))) {
1369 /* Collision case D. */
1370 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1371 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1374 /* Collision case C. */
1375 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1376 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1377 (0 == new_asoc
->c
.my_ttag
) &&
1378 (0 == new_asoc
->c
.peer_ttag
))
1381 /* No match to any of the special cases; discard this packet. */
1385 /* Common helper routine for both duplicate and simulataneous INIT
1388 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1390 const struct sctp_endpoint
*ep
,
1391 const struct sctp_association
*asoc
,
1392 const sctp_subtype_t type
,
1393 void *arg
, sctp_cmd_seq_t
*commands
)
1395 sctp_disposition_t retval
;
1396 struct sctp_chunk
*chunk
= arg
;
1397 struct sctp_chunk
*repl
;
1398 struct sctp_association
*new_asoc
;
1399 struct sctp_chunk
*err_chunk
;
1400 struct sctp_packet
*packet
;
1401 sctp_unrecognized_param_t
*unk_param
;
1405 * An endpoint MUST NOT bundle INIT, INIT ACK or
1406 * SHUTDOWN COMPLETE with any other chunks.
1409 * Furthermore, we require that the receiver of an INIT chunk MUST
1410 * enforce these rules by silently discarding an arriving packet
1411 * with an INIT chunk that is bundled with other chunks.
1413 if (!chunk
->singleton
)
1414 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1416 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1419 if (chunk
->sctp_hdr
->vtag
!= 0)
1420 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1422 /* Make sure that the INIT chunk has a valid length.
1423 * In this case, we generate a protocol violation since we have
1424 * an association established.
1426 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1427 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1429 /* Grab the INIT header. */
1430 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1432 /* Tag the variable length parameters. */
1433 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1435 /* Verify the INIT chunk before processing it. */
1437 if (!sctp_verify_init(net
, ep
, asoc
, chunk
->chunk_hdr
->type
,
1438 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1440 /* This chunk contains fatal error. It is to be discarded.
1441 * Send an ABORT, with causes if there is any.
1444 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1445 (__u8
*)(err_chunk
->chunk_hdr
) +
1446 sizeof(sctp_chunkhdr_t
),
1447 ntohs(err_chunk
->chunk_hdr
->length
) -
1448 sizeof(sctp_chunkhdr_t
));
1451 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1452 SCTP_PACKET(packet
));
1453 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1454 retval
= SCTP_DISPOSITION_CONSUME
;
1456 retval
= SCTP_DISPOSITION_NOMEM
;
1460 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1466 * Other parameters for the endpoint SHOULD be copied from the
1467 * existing parameters of the association (e.g. number of
1468 * outbound streams) into the INIT ACK and cookie.
1469 * FIXME: We are copying parameters from the endpoint not the
1472 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1476 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1477 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1480 /* In the outbound INIT ACK the endpoint MUST copy its current
1481 * Verification Tag and Peers Verification tag into a reserved
1482 * place (local tie-tag and per tie-tag) within the state cookie.
1484 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1485 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1489 /* Make sure no new addresses are being added during the
1490 * restart. Do not do this check for COOKIE-WAIT state,
1491 * since there are no peer addresses to check against.
1492 * Upon return an ABORT will have been sent if needed.
1494 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1495 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1497 retval
= SCTP_DISPOSITION_CONSUME
;
1502 sctp_tietags_populate(new_asoc
, asoc
);
1504 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1506 /* If there are errors need to be reported for unknown parameters,
1507 * make sure to reserve enough room in the INIT ACK for them.
1511 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1512 sizeof(sctp_chunkhdr_t
);
1515 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1519 /* If there are errors need to be reported for unknown parameters,
1520 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1524 /* Get the "Unrecognized parameter" parameter(s) out of the
1525 * ERROR chunk generated by sctp_verify_init(). Since the
1526 * error cause code for "unknown parameter" and the
1527 * "Unrecognized parameter" type is the same, we can
1528 * construct the parameters in INIT ACK by copying the
1529 * ERROR causes over.
1531 unk_param
= (sctp_unrecognized_param_t
*)
1532 ((__u8
*)(err_chunk
->chunk_hdr
) +
1533 sizeof(sctp_chunkhdr_t
));
1534 /* Replace the cause code with the "Unrecognized parameter"
1537 sctp_addto_chunk(repl
, len
, unk_param
);
1540 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1541 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1544 * Note: After sending out INIT ACK with the State Cookie parameter,
1545 * "Z" MUST NOT allocate any resources for this new association.
1546 * Otherwise, "Z" will be vulnerable to resource attacks.
1548 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1549 retval
= SCTP_DISPOSITION_CONSUME
;
1554 retval
= SCTP_DISPOSITION_NOMEM
;
1557 sctp_association_free(new_asoc
);
1560 sctp_chunk_free(err_chunk
);
1565 * Handle simultaneous INIT.
1566 * This means we started an INIT and then we got an INIT request from
1569 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1570 * This usually indicates an initialization collision, i.e., each
1571 * endpoint is attempting, at about the same time, to establish an
1572 * association with the other endpoint.
1574 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1575 * endpoint MUST respond with an INIT ACK using the same parameters it
1576 * sent in its original INIT chunk (including its Verification Tag,
1577 * unchanged). These original parameters are combined with those from the
1578 * newly received INIT chunk. The endpoint shall also generate a State
1579 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1580 * INIT to calculate the State Cookie.
1582 * After that, the endpoint MUST NOT change its state, the T1-init
1583 * timer shall be left running and the corresponding TCB MUST NOT be
1584 * destroyed. The normal procedures for handling State Cookies when
1585 * a TCB exists will resolve the duplicate INITs to a single association.
1587 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1588 * its Tie-Tags with the Tag information of itself and its peer (see
1589 * section 5.2.2 for a description of the Tie-Tags).
1591 * Verification Tag: Not explicit, but an INIT can not have a valid
1592 * verification tag, so we skip the check.
1595 * (endpoint, asoc, chunk)
1598 * (asoc, reply_msg, msg_up, timers, counters)
1600 * The return value is the disposition of the chunk.
1602 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(struct net
*net
,
1603 const struct sctp_endpoint
*ep
,
1604 const struct sctp_association
*asoc
,
1605 const sctp_subtype_t type
,
1607 sctp_cmd_seq_t
*commands
)
1609 /* Call helper to do the real work for both simulataneous and
1610 * duplicate INIT chunk handling.
1612 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1616 * Handle duplicated INIT messages. These are usually delayed
1619 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1620 * COOKIE-ECHOED and COOKIE-WAIT
1622 * Unless otherwise stated, upon reception of an unexpected INIT for
1623 * this association, the endpoint shall generate an INIT ACK with a
1624 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1625 * current Verification Tag and peer's Verification Tag into a reserved
1626 * place within the state cookie. We shall refer to these locations as
1627 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1628 * containing this INIT ACK MUST carry a Verification Tag value equal to
1629 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1630 * MUST contain a new Initiation Tag (randomly generated see Section
1631 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1632 * existing parameters of the association (e.g. number of outbound
1633 * streams) into the INIT ACK and cookie.
1635 * After sending out the INIT ACK, the endpoint shall take no further
1636 * actions, i.e., the existing association, including its current state,
1637 * and the corresponding TCB MUST NOT be changed.
1639 * Note: Only when a TCB exists and the association is not in a COOKIE-
1640 * WAIT state are the Tie-Tags populated. For a normal association INIT
1641 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1642 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1643 * State Cookie are populated as specified in section 5.2.1.
1645 * Verification Tag: Not specified, but an INIT has no way of knowing
1646 * what the verification tag could be, so we ignore it.
1649 * (endpoint, asoc, chunk)
1652 * (asoc, reply_msg, msg_up, timers, counters)
1654 * The return value is the disposition of the chunk.
1656 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(struct net
*net
,
1657 const struct sctp_endpoint
*ep
,
1658 const struct sctp_association
*asoc
,
1659 const sctp_subtype_t type
,
1661 sctp_cmd_seq_t
*commands
)
1663 /* Call helper to do the real work for both simulataneous and
1664 * duplicate INIT chunk handling.
1666 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1671 * Unexpected INIT-ACK handler.
1674 * If an INIT ACK received by an endpoint in any state other than the
1675 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1676 * An unexpected INIT ACK usually indicates the processing of an old or
1677 * duplicated INIT chunk.
1679 sctp_disposition_t
sctp_sf_do_5_2_3_initack(struct net
*net
,
1680 const struct sctp_endpoint
*ep
,
1681 const struct sctp_association
*asoc
,
1682 const sctp_subtype_t type
,
1683 void *arg
, sctp_cmd_seq_t
*commands
)
1685 /* Per the above section, we'll discard the chunk if we have an
1686 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1688 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1689 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1691 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1694 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1697 * A) In this case, the peer may have restarted.
1699 static sctp_disposition_t
sctp_sf_do_dupcook_a(struct net
*net
,
1700 const struct sctp_endpoint
*ep
,
1701 const struct sctp_association
*asoc
,
1702 struct sctp_chunk
*chunk
,
1703 sctp_cmd_seq_t
*commands
,
1704 struct sctp_association
*new_asoc
)
1706 sctp_init_chunk_t
*peer_init
;
1707 struct sctp_ulpevent
*ev
;
1708 struct sctp_chunk
*repl
;
1709 struct sctp_chunk
*err
;
1710 sctp_disposition_t disposition
;
1712 /* new_asoc is a brand-new association, so these are not yet
1713 * side effects--it is safe to run them here.
1715 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1717 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1721 /* Make sure no new addresses are being added during the
1722 * restart. Though this is a pretty complicated attack
1723 * since you'd have to get inside the cookie.
1725 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1726 return SCTP_DISPOSITION_CONSUME
;
1729 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1730 * the peer has restarted (Action A), it MUST NOT setup a new
1731 * association but instead resend the SHUTDOWN ACK and send an ERROR
1732 * chunk with a "Cookie Received while Shutting Down" error cause to
1735 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1736 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1737 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1739 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1742 err
= sctp_make_op_error(asoc
, chunk
,
1743 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1746 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1749 return SCTP_DISPOSITION_CONSUME
;
1752 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1753 * data. Consider the optional choice of resending of this data.
1755 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1756 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1757 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1758 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1760 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1761 * and ASCONF-ACK cache.
1763 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1764 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1765 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1767 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1771 /* Report association restart to upper layer. */
1772 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1773 new_asoc
->c
.sinit_num_ostreams
,
1774 new_asoc
->c
.sinit_max_instreams
,
1779 /* Update the content of current association. */
1780 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1781 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1782 if (sctp_state(asoc
, SHUTDOWN_PENDING
) &&
1783 (sctp_sstate(asoc
->base
.sk
, CLOSING
) ||
1784 sock_flag(asoc
->base
.sk
, SOCK_DEAD
))) {
1785 /* if were currently in SHUTDOWN_PENDING, but the socket
1786 * has been closed by user, don't transition to ESTABLISHED.
1787 * Instead trigger SHUTDOWN bundled with COOKIE_ACK.
1789 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1790 return sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
,
1791 SCTP_ST_CHUNK(0), NULL
,
1794 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1795 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1796 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1798 return SCTP_DISPOSITION_CONSUME
;
1801 sctp_chunk_free(repl
);
1803 return SCTP_DISPOSITION_NOMEM
;
1806 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1809 * B) In this case, both sides may be attempting to start an association
1810 * at about the same time but the peer endpoint started its INIT
1811 * after responding to the local endpoint's INIT
1813 /* This case represents an initialization collision. */
1814 static sctp_disposition_t
sctp_sf_do_dupcook_b(struct net
*net
,
1815 const struct sctp_endpoint
*ep
,
1816 const struct sctp_association
*asoc
,
1817 struct sctp_chunk
*chunk
,
1818 sctp_cmd_seq_t
*commands
,
1819 struct sctp_association
*new_asoc
)
1821 sctp_init_chunk_t
*peer_init
;
1822 struct sctp_chunk
*repl
;
1824 /* new_asoc is a brand-new association, so these are not yet
1825 * side effects--it is safe to run them here.
1827 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1828 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1832 /* Update the content of current association. */
1833 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1834 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1835 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1836 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1837 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1839 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1843 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1845 /* RFC 2960 5.1 Normal Establishment of an Association
1847 * D) IMPLEMENTATION NOTE: An implementation may choose to
1848 * send the Communication Up notification to the SCTP user
1849 * upon reception of a valid COOKIE ECHO chunk.
1851 * Sadly, this needs to be implemented as a side-effect, because
1852 * we are not guaranteed to have set the association id of the real
1853 * association and so these notifications need to be delayed until
1854 * the association id is allocated.
1857 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1859 /* Sockets API Draft Section 5.3.1.6
1860 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1861 * delivers this notification to inform the application that of the
1862 * peers requested adaptation layer.
1864 * This also needs to be done as a side effect for the same reason as
1867 if (asoc
->peer
.adaptation_ind
)
1868 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1870 return SCTP_DISPOSITION_CONSUME
;
1873 return SCTP_DISPOSITION_NOMEM
;
1876 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1879 * C) In this case, the local endpoint's cookie has arrived late.
1880 * Before it arrived, the local endpoint sent an INIT and received an
1881 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1882 * but a new tag of its own.
1884 /* This case represents an initialization collision. */
1885 static sctp_disposition_t
sctp_sf_do_dupcook_c(struct net
*net
,
1886 const struct sctp_endpoint
*ep
,
1887 const struct sctp_association
*asoc
,
1888 struct sctp_chunk
*chunk
,
1889 sctp_cmd_seq_t
*commands
,
1890 struct sctp_association
*new_asoc
)
1892 /* The cookie should be silently discarded.
1893 * The endpoint SHOULD NOT change states and should leave
1894 * any timers running.
1896 return SCTP_DISPOSITION_DISCARD
;
1899 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1903 * D) When both local and remote tags match the endpoint should always
1904 * enter the ESTABLISHED state, if it has not already done so.
1906 /* This case represents an initialization collision. */
1907 static sctp_disposition_t
sctp_sf_do_dupcook_d(struct net
*net
,
1908 const struct sctp_endpoint
*ep
,
1909 const struct sctp_association
*asoc
,
1910 struct sctp_chunk
*chunk
,
1911 sctp_cmd_seq_t
*commands
,
1912 struct sctp_association
*new_asoc
)
1914 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1915 struct sctp_chunk
*repl
;
1917 /* Clarification from Implementor's Guide:
1918 * D) When both local and remote tags match the endpoint should
1919 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1920 * It should stop any cookie timer that may be running and send
1924 /* Don't accidentally move back into established state. */
1925 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1926 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1927 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1928 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1929 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1930 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1931 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1934 /* RFC 2960 5.1 Normal Establishment of an Association
1936 * D) IMPLEMENTATION NOTE: An implementation may choose
1937 * to send the Communication Up notification to the
1938 * SCTP user upon reception of a valid COOKIE
1941 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1943 asoc
->c
.sinit_num_ostreams
,
1944 asoc
->c
.sinit_max_instreams
,
1949 /* Sockets API Draft Section 5.3.1.6
1950 * When a peer sends a Adaptation Layer Indication parameter,
1951 * SCTP delivers this notification to inform the application
1952 * that of the peers requested adaptation layer.
1954 if (asoc
->peer
.adaptation_ind
) {
1955 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1963 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1967 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1970 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1973 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1974 SCTP_ULPEVENT(ai_ev
));
1976 return SCTP_DISPOSITION_CONSUME
;
1980 sctp_ulpevent_free(ai_ev
);
1982 sctp_ulpevent_free(ev
);
1983 return SCTP_DISPOSITION_NOMEM
;
1987 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1988 * chunk was retransmitted and then delayed in the network.
1990 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1992 * Verification Tag: None. Do cookie validation.
1995 * (endpoint, asoc, chunk)
1998 * (asoc, reply_msg, msg_up, timers, counters)
2000 * The return value is the disposition of the chunk.
2002 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(struct net
*net
,
2003 const struct sctp_endpoint
*ep
,
2004 const struct sctp_association
*asoc
,
2005 const sctp_subtype_t type
,
2007 sctp_cmd_seq_t
*commands
)
2009 sctp_disposition_t retval
;
2010 struct sctp_chunk
*chunk
= arg
;
2011 struct sctp_association
*new_asoc
;
2014 struct sctp_chunk
*err_chk_p
;
2016 /* Make sure that the chunk has a valid length from the protocol
2017 * perspective. In this case check to make sure we have at least
2018 * enough for the chunk header. Cookie length verification is
2021 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2022 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2025 /* "Decode" the chunk. We have no optional parameters so we
2026 * are in good shape.
2028 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2029 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2030 sizeof(sctp_chunkhdr_t
)))
2033 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2034 * of a duplicate COOKIE ECHO match the Verification Tags of the
2035 * current association, consider the State Cookie valid even if
2036 * the lifespan is exceeded.
2038 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2042 * If the re-build failed, what is the proper error path
2045 * [We should abort the association. --piggy]
2048 /* FIXME: Several errors are possible. A bad cookie should
2049 * be silently discarded, but think about logging it too.
2052 case -SCTP_IERROR_NOMEM
:
2055 case -SCTP_IERROR_STALE_COOKIE
:
2056 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2058 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2059 case -SCTP_IERROR_BAD_SIG
:
2061 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2065 /* Compare the tie_tag in cookie with the verification tag of
2066 * current association.
2068 action
= sctp_tietags_compare(new_asoc
, asoc
);
2071 case 'A': /* Association restart. */
2072 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2076 case 'B': /* Collision case B. */
2077 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2081 case 'C': /* Collision case C. */
2082 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2086 case 'D': /* Collision case D. */
2087 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2091 default: /* Discard packet for all others. */
2092 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2096 /* Delete the tempory new association. */
2097 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
, SCTP_ASOC(new_asoc
));
2098 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2100 /* Restore association pointer to provide SCTP command interpeter
2101 * with a valid context in case it needs to manipulate
2103 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2104 SCTP_ASOC((struct sctp_association
*)asoc
));
2109 return SCTP_DISPOSITION_NOMEM
;
2113 * Process an ABORT. (SHUTDOWN-PENDING state)
2115 * See sctp_sf_do_9_1_abort().
2117 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2119 const struct sctp_endpoint
*ep
,
2120 const struct sctp_association
*asoc
,
2121 const sctp_subtype_t type
,
2123 sctp_cmd_seq_t
*commands
)
2125 struct sctp_chunk
*chunk
= arg
;
2127 if (!sctp_vtag_verify_either(chunk
, asoc
))
2128 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2130 /* Make sure that the ABORT chunk has a valid length.
2131 * Since this is an ABORT chunk, we have to discard it
2132 * because of the following text:
2133 * RFC 2960, Section 3.3.7
2134 * If an endpoint receives an ABORT with a format error or for an
2135 * association that doesn't exist, it MUST silently discard it.
2136 * Because the length is "invalid", we can't really discard just
2137 * as we do not know its true length. So, to be safe, discard the
2140 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2141 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2143 /* ADD-IP: Special case for ABORT chunks
2144 * F4) One special consideration is that ABORT Chunks arriving
2145 * destined to the IP address being deleted MUST be
2146 * ignored (see Section 5.3.1 for further details).
2148 if (SCTP_ADDR_DEL
==
2149 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2150 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2152 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2156 * Process an ABORT. (SHUTDOWN-SENT state)
2158 * See sctp_sf_do_9_1_abort().
2160 sctp_disposition_t
sctp_sf_shutdown_sent_abort(struct net
*net
,
2161 const struct sctp_endpoint
*ep
,
2162 const struct sctp_association
*asoc
,
2163 const sctp_subtype_t type
,
2165 sctp_cmd_seq_t
*commands
)
2167 struct sctp_chunk
*chunk
= arg
;
2169 if (!sctp_vtag_verify_either(chunk
, asoc
))
2170 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2172 /* Make sure that the ABORT chunk has a valid length.
2173 * Since this is an ABORT chunk, we have to discard it
2174 * because of the following text:
2175 * RFC 2960, Section 3.3.7
2176 * If an endpoint receives an ABORT with a format error or for an
2177 * association that doesn't exist, it MUST silently discard it.
2178 * Because the length is "invalid", we can't really discard just
2179 * as we do not know its true length. So, to be safe, discard the
2182 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2183 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2185 /* ADD-IP: Special case for ABORT chunks
2186 * F4) One special consideration is that ABORT Chunks arriving
2187 * destined to the IP address being deleted MUST be
2188 * ignored (see Section 5.3.1 for further details).
2190 if (SCTP_ADDR_DEL
==
2191 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2192 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2194 /* Stop the T2-shutdown timer. */
2195 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2196 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2198 /* Stop the T5-shutdown guard timer. */
2199 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2200 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2202 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2206 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2208 * See sctp_sf_do_9_1_abort().
2210 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2212 const struct sctp_endpoint
*ep
,
2213 const struct sctp_association
*asoc
,
2214 const sctp_subtype_t type
,
2216 sctp_cmd_seq_t
*commands
)
2218 /* The same T2 timer, so we should be able to use
2219 * common function with the SHUTDOWN-SENT state.
2221 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2225 * Handle an Error received in COOKIE_ECHOED state.
2227 * Only handle the error type of stale COOKIE Error, the other errors will
2231 * (endpoint, asoc, chunk)
2234 * (asoc, reply_msg, msg_up, timers, counters)
2236 * The return value is the disposition of the chunk.
2238 sctp_disposition_t
sctp_sf_cookie_echoed_err(struct net
*net
,
2239 const struct sctp_endpoint
*ep
,
2240 const struct sctp_association
*asoc
,
2241 const sctp_subtype_t type
,
2243 sctp_cmd_seq_t
*commands
)
2245 struct sctp_chunk
*chunk
= arg
;
2248 if (!sctp_vtag_verify(chunk
, asoc
))
2249 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2251 /* Make sure that the ERROR chunk has a valid length.
2252 * The parameter walking depends on this as well.
2254 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2255 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2258 /* Process the error here */
2259 /* FUTURE FIXME: When PR-SCTP related and other optional
2260 * parms are emitted, this will have to change to handle multiple
2263 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2264 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2265 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2269 /* It is possible to have malformed error causes, and that
2270 * will cause us to end the walk early. However, since
2271 * we are discarding the packet, there should be no adverse
2274 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2278 * Handle a Stale COOKIE Error
2280 * Section: 5.2.6 Handle Stale COOKIE Error
2281 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2282 * one of the following three alternatives.
2284 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2285 * Preservative parameter requesting an extension to the lifetime of
2286 * the State Cookie. When calculating the time extension, an
2287 * implementation SHOULD use the RTT information measured based on the
2288 * previous COOKIE ECHO / ERROR exchange, and should add no more
2289 * than 1 second beyond the measured RTT, due to long State Cookie
2290 * lifetimes making the endpoint more subject to a replay attack.
2292 * Verification Tag: Not explicit, but safe to ignore.
2295 * (endpoint, asoc, chunk)
2298 * (asoc, reply_msg, msg_up, timers, counters)
2300 * The return value is the disposition of the chunk.
2302 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(struct net
*net
,
2303 const struct sctp_endpoint
*ep
,
2304 const struct sctp_association
*asoc
,
2305 const sctp_subtype_t type
,
2307 sctp_cmd_seq_t
*commands
)
2309 struct sctp_chunk
*chunk
= arg
;
2311 sctp_cookie_preserve_param_t bht
;
2313 struct sctp_chunk
*reply
;
2314 struct sctp_bind_addr
*bp
;
2315 int attempts
= asoc
->init_err_counter
+ 1;
2317 if (attempts
> asoc
->max_init_attempts
) {
2318 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2319 SCTP_ERROR(ETIMEDOUT
));
2320 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2321 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2322 return SCTP_DISPOSITION_DELETE_TCB
;
2325 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2327 /* When calculating the time extension, an implementation
2328 * SHOULD use the RTT information measured based on the
2329 * previous COOKIE ECHO / ERROR exchange, and should add no
2330 * more than 1 second beyond the measured RTT, due to long
2331 * State Cookie lifetimes making the endpoint more subject to
2333 * Measure of Staleness's unit is usec. (1/1000000 sec)
2334 * Suggested Cookie Life-span Increment's unit is msec.
2336 * In general, if you use the suggested cookie life, the value
2337 * found in the field of measure of staleness should be doubled
2338 * to give ample time to retransmit the new cookie and thus
2339 * yield a higher probability of success on the reattempt.
2341 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2342 stale
= (stale
* 2) / 1000;
2344 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2345 bht
.param_hdr
.length
= htons(sizeof(bht
));
2346 bht
.lifespan_increment
= htonl(stale
);
2348 /* Build that new INIT chunk. */
2349 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2350 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2354 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2356 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2357 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2359 /* Stop pending T3-rtx and heartbeat timers */
2360 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2361 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2363 /* Delete non-primary peer ip addresses since we are transitioning
2364 * back to the COOKIE-WAIT state
2366 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2368 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2371 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2372 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2374 /* Cast away the const modifier, as we want to just
2375 * rerun it through as a sideffect.
2377 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2379 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2380 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2381 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2382 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2383 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2384 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2386 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2388 return SCTP_DISPOSITION_CONSUME
;
2391 return SCTP_DISPOSITION_NOMEM
;
2398 * After checking the Verification Tag, the receiving endpoint shall
2399 * remove the association from its record, and shall report the
2400 * termination to its upper layer.
2402 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2403 * B) Rules for packet carrying ABORT:
2405 * - The endpoint shall always fill in the Verification Tag field of the
2406 * outbound packet with the destination endpoint's tag value if it
2409 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2410 * MUST follow the procedure described in Section 8.4.
2412 * - The receiver MUST accept the packet if the Verification Tag
2413 * matches either its own tag, OR the tag of its peer. Otherwise, the
2414 * receiver MUST silently discard the packet and take no further
2418 * (endpoint, asoc, chunk)
2421 * (asoc, reply_msg, msg_up, timers, counters)
2423 * The return value is the disposition of the chunk.
2425 sctp_disposition_t
sctp_sf_do_9_1_abort(struct net
*net
,
2426 const struct sctp_endpoint
*ep
,
2427 const struct sctp_association
*asoc
,
2428 const sctp_subtype_t type
,
2430 sctp_cmd_seq_t
*commands
)
2432 struct sctp_chunk
*chunk
= arg
;
2434 if (!sctp_vtag_verify_either(chunk
, asoc
))
2435 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2437 /* Make sure that the ABORT chunk has a valid length.
2438 * Since this is an ABORT chunk, we have to discard it
2439 * because of the following text:
2440 * RFC 2960, Section 3.3.7
2441 * If an endpoint receives an ABORT with a format error or for an
2442 * association that doesn't exist, it MUST silently discard it.
2443 * Because the length is "invalid", we can't really discard just
2444 * as we do not know its true length. So, to be safe, discard the
2447 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2448 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2450 /* ADD-IP: Special case for ABORT chunks
2451 * F4) One special consideration is that ABORT Chunks arriving
2452 * destined to the IP address being deleted MUST be
2453 * ignored (see Section 5.3.1 for further details).
2455 if (SCTP_ADDR_DEL
==
2456 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2457 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2459 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2462 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
2463 const struct sctp_endpoint
*ep
,
2464 const struct sctp_association
*asoc
,
2465 const sctp_subtype_t type
,
2467 sctp_cmd_seq_t
*commands
)
2469 struct sctp_chunk
*chunk
= arg
;
2471 __be16 error
= SCTP_ERROR_NO_ERROR
;
2473 /* See if we have an error cause code in the chunk. */
2474 len
= ntohs(chunk
->chunk_hdr
->length
);
2475 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2478 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2479 if ((void *)err
!= (void *)chunk
->chunk_end
)
2480 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2482 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2485 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2486 /* ASSOC_FAILED will DELETE_TCB. */
2487 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2488 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2489 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2491 return SCTP_DISPOSITION_ABORT
;
2495 * Process an ABORT. (COOKIE-WAIT state)
2497 * See sctp_sf_do_9_1_abort() above.
2499 sctp_disposition_t
sctp_sf_cookie_wait_abort(struct net
*net
,
2500 const struct sctp_endpoint
*ep
,
2501 const struct sctp_association
*asoc
,
2502 const sctp_subtype_t type
,
2504 sctp_cmd_seq_t
*commands
)
2506 struct sctp_chunk
*chunk
= arg
;
2508 __be16 error
= SCTP_ERROR_NO_ERROR
;
2510 if (!sctp_vtag_verify_either(chunk
, asoc
))
2511 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2513 /* Make sure that the ABORT chunk has a valid length.
2514 * Since this is an ABORT chunk, we have to discard it
2515 * because of the following text:
2516 * RFC 2960, Section 3.3.7
2517 * If an endpoint receives an ABORT with a format error or for an
2518 * association that doesn't exist, it MUST silently discard it.
2519 * Because the length is "invalid", we can't really discard just
2520 * as we do not know its true length. So, to be safe, discard the
2523 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2524 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2526 /* See if we have an error cause code in the chunk. */
2527 len
= ntohs(chunk
->chunk_hdr
->length
);
2528 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2529 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2531 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2536 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2538 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(struct net
*net
,
2539 const struct sctp_endpoint
*ep
,
2540 const struct sctp_association
*asoc
,
2541 const sctp_subtype_t type
,
2543 sctp_cmd_seq_t
*commands
)
2545 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2547 (struct sctp_transport
*)arg
);
2551 * Process an ABORT. (COOKIE-ECHOED state)
2553 sctp_disposition_t
sctp_sf_cookie_echoed_abort(struct net
*net
,
2554 const struct sctp_endpoint
*ep
,
2555 const struct sctp_association
*asoc
,
2556 const sctp_subtype_t type
,
2558 sctp_cmd_seq_t
*commands
)
2560 /* There is a single T1 timer, so we should be able to use
2561 * common function with the COOKIE-WAIT state.
2563 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2567 * Stop T1 timer and abort association with "INIT failed".
2569 * This is common code called by several sctp_sf_*_abort() functions above.
2571 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
2572 sctp_cmd_seq_t
*commands
,
2573 __be16 error
, int sk_err
,
2574 const struct sctp_association
*asoc
,
2575 struct sctp_transport
*transport
)
2577 pr_debug("%s: ABORT received (INIT)\n", __func__
);
2579 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2580 SCTP_STATE(SCTP_STATE_CLOSED
));
2581 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2582 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2583 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2584 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2585 /* CMD_INIT_FAILED will DELETE_TCB. */
2586 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2589 return SCTP_DISPOSITION_ABORT
;
2593 * sctp_sf_do_9_2_shut
2596 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2597 * - enter the SHUTDOWN-RECEIVED state,
2599 * - stop accepting new data from its SCTP user
2601 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2602 * that all its outstanding DATA chunks have been received by the
2605 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2606 * send a SHUTDOWN in response to a ULP request. And should discard
2607 * subsequent SHUTDOWN chunks.
2609 * If there are still outstanding DATA chunks left, the SHUTDOWN
2610 * receiver shall continue to follow normal data transmission
2611 * procedures defined in Section 6 until all outstanding DATA chunks
2612 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2613 * new data from its SCTP user.
2615 * Verification Tag: 8.5 Verification Tag [Normal verification]
2618 * (endpoint, asoc, chunk)
2621 * (asoc, reply_msg, msg_up, timers, counters)
2623 * The return value is the disposition of the chunk.
2625 sctp_disposition_t
sctp_sf_do_9_2_shutdown(struct net
*net
,
2626 const struct sctp_endpoint
*ep
,
2627 const struct sctp_association
*asoc
,
2628 const sctp_subtype_t type
,
2630 sctp_cmd_seq_t
*commands
)
2632 struct sctp_chunk
*chunk
= arg
;
2633 sctp_shutdownhdr_t
*sdh
;
2634 sctp_disposition_t disposition
;
2635 struct sctp_ulpevent
*ev
;
2638 if (!sctp_vtag_verify(chunk
, asoc
))
2639 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2641 /* Make sure that the SHUTDOWN chunk has a valid length. */
2642 if (!sctp_chunk_length_valid(chunk
,
2643 sizeof(struct sctp_shutdown_chunk_t
)))
2644 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2647 /* Convert the elaborate header. */
2648 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2649 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2650 chunk
->subh
.shutdown_hdr
= sdh
;
2651 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2653 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2654 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2655 asoc
->ctsn_ack_point
);
2657 return SCTP_DISPOSITION_DISCARD
;
2660 /* If Cumulative TSN Ack beyond the max tsn currently
2661 * send, terminating the association and respond to the
2662 * sender with an ABORT.
2664 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2665 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2667 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2668 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2669 * inform the application that it should cease sending data.
2671 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2673 disposition
= SCTP_DISPOSITION_NOMEM
;
2676 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2678 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2679 * - enter the SHUTDOWN-RECEIVED state,
2680 * - stop accepting new data from its SCTP user
2682 * [This is implicit in the new state.]
2684 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2685 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2686 disposition
= SCTP_DISPOSITION_CONSUME
;
2688 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2689 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2693 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2696 /* - verify, by checking the Cumulative TSN Ack field of the
2697 * chunk, that all its outstanding DATA chunks have been
2698 * received by the SHUTDOWN sender.
2700 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2701 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2708 * sctp_sf_do_9_2_shut_ctsn
2710 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2711 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2712 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2713 * MUST be processed.
2715 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(struct net
*net
,
2716 const struct sctp_endpoint
*ep
,
2717 const struct sctp_association
*asoc
,
2718 const sctp_subtype_t type
,
2720 sctp_cmd_seq_t
*commands
)
2722 struct sctp_chunk
*chunk
= arg
;
2723 sctp_shutdownhdr_t
*sdh
;
2726 if (!sctp_vtag_verify(chunk
, asoc
))
2727 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2729 /* Make sure that the SHUTDOWN chunk has a valid length. */
2730 if (!sctp_chunk_length_valid(chunk
,
2731 sizeof(struct sctp_shutdown_chunk_t
)))
2732 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2735 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2736 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2738 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2739 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
2740 asoc
->ctsn_ack_point
);
2742 return SCTP_DISPOSITION_DISCARD
;
2745 /* If Cumulative TSN Ack beyond the max tsn currently
2746 * send, terminating the association and respond to the
2747 * sender with an ABORT.
2749 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2750 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2752 /* verify, by checking the Cumulative TSN Ack field of the
2753 * chunk, that all its outstanding DATA chunks have been
2754 * received by the SHUTDOWN sender.
2756 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2757 SCTP_BE32(sdh
->cum_tsn_ack
));
2759 return SCTP_DISPOSITION_CONSUME
;
2763 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2764 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2765 * transport addresses (either in the IP addresses or in the INIT chunk)
2766 * that belong to this association, it should discard the INIT chunk and
2767 * retransmit the SHUTDOWN ACK chunk.
2769 sctp_disposition_t
sctp_sf_do_9_2_reshutack(struct net
*net
,
2770 const struct sctp_endpoint
*ep
,
2771 const struct sctp_association
*asoc
,
2772 const sctp_subtype_t type
,
2774 sctp_cmd_seq_t
*commands
)
2776 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2777 struct sctp_chunk
*reply
;
2779 /* Make sure that the chunk has a valid length */
2780 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2781 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2784 /* Since we are not going to really process this INIT, there
2785 * is no point in verifying chunk boundries. Just generate
2788 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2792 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2793 * the T2-SHUTDOWN timer.
2795 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2797 /* and restart the T2-shutdown timer. */
2798 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2799 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2801 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2803 return SCTP_DISPOSITION_CONSUME
;
2805 return SCTP_DISPOSITION_NOMEM
;
2809 * sctp_sf_do_ecn_cwr
2811 * Section: Appendix A: Explicit Congestion Notification
2815 * RFC 2481 details a specific bit for a sender to send in the header of
2816 * its next outbound TCP segment to indicate to its peer that it has
2817 * reduced its congestion window. This is termed the CWR bit. For
2818 * SCTP the same indication is made by including the CWR chunk.
2819 * This chunk contains one data element, i.e. the TSN number that
2820 * was sent in the ECNE chunk. This element represents the lowest
2821 * TSN number in the datagram that was originally marked with the
2824 * Verification Tag: 8.5 Verification Tag [Normal verification]
2826 * (endpoint, asoc, chunk)
2829 * (asoc, reply_msg, msg_up, timers, counters)
2831 * The return value is the disposition of the chunk.
2833 sctp_disposition_t
sctp_sf_do_ecn_cwr(struct net
*net
,
2834 const struct sctp_endpoint
*ep
,
2835 const struct sctp_association
*asoc
,
2836 const sctp_subtype_t type
,
2838 sctp_cmd_seq_t
*commands
)
2841 struct sctp_chunk
*chunk
= arg
;
2844 if (!sctp_vtag_verify(chunk
, asoc
))
2845 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2847 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2848 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2851 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2852 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2854 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2856 /* Does this CWR ack the last sent congestion notification? */
2857 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2858 /* Stop sending ECNE. */
2859 sctp_add_cmd_sf(commands
,
2861 SCTP_U32(lowest_tsn
));
2863 return SCTP_DISPOSITION_CONSUME
;
2869 * Section: Appendix A: Explicit Congestion Notification
2873 * RFC 2481 details a specific bit for a receiver to send back in its
2874 * TCP acknowledgements to notify the sender of the Congestion
2875 * Experienced (CE) bit having arrived from the network. For SCTP this
2876 * same indication is made by including the ECNE chunk. This chunk
2877 * contains one data element, i.e. the lowest TSN associated with the IP
2878 * datagram marked with the CE bit.....
2880 * Verification Tag: 8.5 Verification Tag [Normal verification]
2882 * (endpoint, asoc, chunk)
2885 * (asoc, reply_msg, msg_up, timers, counters)
2887 * The return value is the disposition of the chunk.
2889 sctp_disposition_t
sctp_sf_do_ecne(struct net
*net
,
2890 const struct sctp_endpoint
*ep
,
2891 const struct sctp_association
*asoc
,
2892 const sctp_subtype_t type
,
2894 sctp_cmd_seq_t
*commands
)
2896 sctp_ecnehdr_t
*ecne
;
2897 struct sctp_chunk
*chunk
= arg
;
2899 if (!sctp_vtag_verify(chunk
, asoc
))
2900 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2902 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2903 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2906 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2907 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2909 /* If this is a newer ECNE than the last CWR packet we sent out */
2910 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2911 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2913 return SCTP_DISPOSITION_CONSUME
;
2917 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2919 * The SCTP endpoint MUST always acknowledge the reception of each valid
2922 * The guidelines on delayed acknowledgement algorithm specified in
2923 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2924 * acknowledgement SHOULD be generated for at least every second packet
2925 * (not every second DATA chunk) received, and SHOULD be generated within
2926 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2927 * situations it may be beneficial for an SCTP transmitter to be more
2928 * conservative than the algorithms detailed in this document allow.
2929 * However, an SCTP transmitter MUST NOT be more aggressive than the
2930 * following algorithms allow.
2932 * A SCTP receiver MUST NOT generate more than one SACK for every
2933 * incoming packet, other than to update the offered window as the
2934 * receiving application consumes new data.
2936 * Verification Tag: 8.5 Verification Tag [Normal verification]
2939 * (endpoint, asoc, chunk)
2942 * (asoc, reply_msg, msg_up, timers, counters)
2944 * The return value is the disposition of the chunk.
2946 sctp_disposition_t
sctp_sf_eat_data_6_2(struct net
*net
,
2947 const struct sctp_endpoint
*ep
,
2948 const struct sctp_association
*asoc
,
2949 const sctp_subtype_t type
,
2951 sctp_cmd_seq_t
*commands
)
2953 struct sctp_chunk
*chunk
= arg
;
2954 sctp_arg_t force
= SCTP_NOFORCE();
2957 if (!sctp_vtag_verify(chunk
, asoc
)) {
2958 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2960 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2963 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2964 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2967 error
= sctp_eat_data(asoc
, chunk
, commands
);
2969 case SCTP_IERROR_NO_ERROR
:
2971 case SCTP_IERROR_HIGH_TSN
:
2972 case SCTP_IERROR_BAD_STREAM
:
2973 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2974 goto discard_noforce
;
2975 case SCTP_IERROR_DUP_TSN
:
2976 case SCTP_IERROR_IGNORE_TSN
:
2977 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2979 case SCTP_IERROR_NO_DATA
:
2981 case SCTP_IERROR_PROTO_VIOLATION
:
2982 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
2983 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2988 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
2989 force
= SCTP_FORCE();
2991 if (asoc
->autoclose
) {
2992 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2993 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2996 /* If this is the last chunk in a packet, we need to count it
2997 * toward sack generation. Note that we need to SACK every
2998 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2999 * THEM. We elect to NOT generate SACK's if the chunk fails
3000 * the verification tag test.
3002 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3004 * The SCTP endpoint MUST always acknowledge the reception of
3005 * each valid DATA chunk.
3007 * The guidelines on delayed acknowledgement algorithm
3008 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
3009 * Specifically, an acknowledgement SHOULD be generated for at
3010 * least every second packet (not every second DATA chunk)
3011 * received, and SHOULD be generated within 200 ms of the
3012 * arrival of any unacknowledged DATA chunk. In some
3013 * situations it may be beneficial for an SCTP transmitter to
3014 * be more conservative than the algorithms detailed in this
3015 * document allow. However, an SCTP transmitter MUST NOT be
3016 * more aggressive than the following algorithms allow.
3018 if (chunk
->end_of_packet
)
3019 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3021 return SCTP_DISPOSITION_CONSUME
;
3024 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3026 * When a packet arrives with duplicate DATA chunk(s) and with
3027 * no new DATA chunk(s), the endpoint MUST immediately send a
3028 * SACK with no delay. If a packet arrives with duplicate
3029 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3030 * MAY immediately send a SACK. Normally receipt of duplicate
3031 * DATA chunks will occur when the original SACK chunk was lost
3032 * and the peer's RTO has expired. The duplicate TSN number(s)
3033 * SHOULD be reported in the SACK as duplicate.
3035 /* In our case, we split the MAY SACK advice up whether or not
3036 * the last chunk is a duplicate.'
3038 if (chunk
->end_of_packet
)
3039 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3040 return SCTP_DISPOSITION_DISCARD
;
3043 if (chunk
->end_of_packet
)
3044 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3046 return SCTP_DISPOSITION_DISCARD
;
3048 return SCTP_DISPOSITION_CONSUME
;
3053 * sctp_sf_eat_data_fast_4_4
3056 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3057 * DATA chunks without delay.
3059 * Verification Tag: 8.5 Verification Tag [Normal verification]
3061 * (endpoint, asoc, chunk)
3064 * (asoc, reply_msg, msg_up, timers, counters)
3066 * The return value is the disposition of the chunk.
3068 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(struct net
*net
,
3069 const struct sctp_endpoint
*ep
,
3070 const struct sctp_association
*asoc
,
3071 const sctp_subtype_t type
,
3073 sctp_cmd_seq_t
*commands
)
3075 struct sctp_chunk
*chunk
= arg
;
3078 if (!sctp_vtag_verify(chunk
, asoc
)) {
3079 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3081 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3084 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
3085 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3088 error
= sctp_eat_data(asoc
, chunk
, commands
);
3090 case SCTP_IERROR_NO_ERROR
:
3091 case SCTP_IERROR_HIGH_TSN
:
3092 case SCTP_IERROR_DUP_TSN
:
3093 case SCTP_IERROR_IGNORE_TSN
:
3094 case SCTP_IERROR_BAD_STREAM
:
3096 case SCTP_IERROR_NO_DATA
:
3098 case SCTP_IERROR_PROTO_VIOLATION
:
3099 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3100 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
3105 /* Go a head and force a SACK, since we are shutting down. */
3107 /* Implementor's Guide.
3109 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3110 * respond to each received packet containing one or more DATA chunk(s)
3111 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3113 if (chunk
->end_of_packet
) {
3114 /* We must delay the chunk creation since the cumulative
3115 * TSN has not been updated yet.
3117 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3118 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3119 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3120 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3124 return SCTP_DISPOSITION_CONSUME
;
3128 * Section: 6.2 Processing a Received SACK
3129 * D) Any time a SACK arrives, the endpoint performs the following:
3131 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3132 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3133 * increasing, a SACK whose Cumulative TSN Ack is less than the
3134 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3136 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3137 * of bytes still outstanding after processing the Cumulative TSN Ack
3138 * and the Gap Ack Blocks.
3140 * iii) If the SACK is missing a TSN that was previously
3141 * acknowledged via a Gap Ack Block (e.g., the data receiver
3142 * reneged on the data), then mark the corresponding DATA chunk
3143 * as available for retransmit: Mark it as missing for fast
3144 * retransmit as described in Section 7.2.4 and if no retransmit
3145 * timer is running for the destination address to which the DATA
3146 * chunk was originally transmitted, then T3-rtx is started for
3147 * that destination address.
3149 * Verification Tag: 8.5 Verification Tag [Normal verification]
3152 * (endpoint, asoc, chunk)
3155 * (asoc, reply_msg, msg_up, timers, counters)
3157 * The return value is the disposition of the chunk.
3159 sctp_disposition_t
sctp_sf_eat_sack_6_2(struct net
*net
,
3160 const struct sctp_endpoint
*ep
,
3161 const struct sctp_association
*asoc
,
3162 const sctp_subtype_t type
,
3164 sctp_cmd_seq_t
*commands
)
3166 struct sctp_chunk
*chunk
= arg
;
3167 sctp_sackhdr_t
*sackh
;
3170 if (!sctp_vtag_verify(chunk
, asoc
))
3171 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3173 /* Make sure that the SACK chunk has a valid length. */
3174 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3175 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3178 /* Pull the SACK chunk from the data buffer */
3179 sackh
= sctp_sm_pull_sack(chunk
);
3180 /* Was this a bogus SACK? */
3182 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3183 chunk
->subh
.sack_hdr
= sackh
;
3184 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3186 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3187 * Ack Point, then drop the SACK. Since Cumulative TSN
3188 * Ack is monotonically increasing, a SACK whose
3189 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3190 * Point indicates an out-of-order SACK.
3192 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3193 pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__
, ctsn
,
3194 asoc
->ctsn_ack_point
);
3196 return SCTP_DISPOSITION_DISCARD
;
3199 /* If Cumulative TSN Ack beyond the max tsn currently
3200 * send, terminating the association and respond to the
3201 * sender with an ABORT.
3203 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3204 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3206 /* Return this SACK for further processing. */
3207 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_CHUNK(chunk
));
3209 /* Note: We do the rest of the work on the PROCESS_SACK
3212 return SCTP_DISPOSITION_CONSUME
;
3216 * Generate an ABORT in response to a packet.
3218 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3220 * 8) The receiver should respond to the sender of the OOTB packet with
3221 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3222 * MUST fill in the Verification Tag field of the outbound packet
3223 * with the value found in the Verification Tag field of the OOTB
3224 * packet and set the T-bit in the Chunk Flags to indicate that the
3225 * Verification Tag is reflected. After sending this ABORT, the
3226 * receiver of the OOTB packet shall discard the OOTB packet and take
3227 * no further action.
3231 * The return value is the disposition of the chunk.
3233 static sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
3234 const struct sctp_endpoint
*ep
,
3235 const struct sctp_association
*asoc
,
3236 const sctp_subtype_t type
,
3238 sctp_cmd_seq_t
*commands
)
3240 struct sctp_packet
*packet
= NULL
;
3241 struct sctp_chunk
*chunk
= arg
;
3242 struct sctp_chunk
*abort
;
3244 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3247 /* Make an ABORT. The T bit will be set if the asoc
3250 abort
= sctp_make_abort(asoc
, chunk
, 0);
3252 sctp_ootb_pkt_free(packet
);
3253 return SCTP_DISPOSITION_NOMEM
;
3256 /* Reflect vtag if T-Bit is set */
3257 if (sctp_test_T_bit(abort
))
3258 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3260 /* Set the skb to the belonging sock for accounting. */
3261 abort
->skb
->sk
= ep
->base
.sk
;
3263 sctp_packet_append_chunk(packet
, abort
);
3265 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3266 SCTP_PACKET(packet
));
3268 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3270 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3271 return SCTP_DISPOSITION_CONSUME
;
3274 return SCTP_DISPOSITION_NOMEM
;
3278 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3279 * event as ULP notification for each cause included in the chunk.
3281 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3283 * The return value is the disposition of the chunk.
3285 sctp_disposition_t
sctp_sf_operr_notify(struct net
*net
,
3286 const struct sctp_endpoint
*ep
,
3287 const struct sctp_association
*asoc
,
3288 const sctp_subtype_t type
,
3290 sctp_cmd_seq_t
*commands
)
3292 struct sctp_chunk
*chunk
= arg
;
3295 if (!sctp_vtag_verify(chunk
, asoc
))
3296 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3298 /* Make sure that the ERROR chunk has a valid length. */
3299 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3300 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3302 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3303 if ((void *)err
!= (void *)chunk
->chunk_end
)
3304 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3305 (void *)err
, commands
);
3307 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3310 return SCTP_DISPOSITION_CONSUME
;
3314 * Process an inbound SHUTDOWN ACK.
3317 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3318 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3319 * peer, and remove all record of the association.
3321 * The return value is the disposition.
3323 sctp_disposition_t
sctp_sf_do_9_2_final(struct net
*net
,
3324 const struct sctp_endpoint
*ep
,
3325 const struct sctp_association
*asoc
,
3326 const sctp_subtype_t type
,
3328 sctp_cmd_seq_t
*commands
)
3330 struct sctp_chunk
*chunk
= arg
;
3331 struct sctp_chunk
*reply
;
3332 struct sctp_ulpevent
*ev
;
3334 if (!sctp_vtag_verify(chunk
, asoc
))
3335 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3337 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3338 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3339 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3341 /* 10.2 H) SHUTDOWN COMPLETE notification
3343 * When SCTP completes the shutdown procedures (section 9.2) this
3344 * notification is passed to the upper layer.
3346 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3347 0, 0, 0, NULL
, GFP_ATOMIC
);
3351 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3352 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3356 /* Do all the commands now (after allocation), so that we
3357 * have consistent state if memory allocation failes
3359 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3361 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3362 * stop the T2-shutdown timer,
3364 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3365 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3367 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3368 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3370 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3371 SCTP_STATE(SCTP_STATE_CLOSED
));
3372 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3373 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3374 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3376 /* ...and remove all record of the association. */
3377 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3378 return SCTP_DISPOSITION_DELETE_TCB
;
3381 sctp_ulpevent_free(ev
);
3383 return SCTP_DISPOSITION_NOMEM
;
3387 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3389 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3390 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3391 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3392 * packet must fill in the Verification Tag field of the outbound
3393 * packet with the Verification Tag received in the SHUTDOWN ACK and
3394 * set the T-bit in the Chunk Flags to indicate that the Verification
3397 * 8) The receiver should respond to the sender of the OOTB packet with
3398 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3399 * MUST fill in the Verification Tag field of the outbound packet
3400 * with the value found in the Verification Tag field of the OOTB
3401 * packet and set the T-bit in the Chunk Flags to indicate that the
3402 * Verification Tag is reflected. After sending this ABORT, the
3403 * receiver of the OOTB packet shall discard the OOTB packet and take
3404 * no further action.
3406 sctp_disposition_t
sctp_sf_ootb(struct net
*net
,
3407 const struct sctp_endpoint
*ep
,
3408 const struct sctp_association
*asoc
,
3409 const sctp_subtype_t type
,
3411 sctp_cmd_seq_t
*commands
)
3413 struct sctp_chunk
*chunk
= arg
;
3414 struct sk_buff
*skb
= chunk
->skb
;
3415 sctp_chunkhdr_t
*ch
;
3418 int ootb_shut_ack
= 0;
3419 int ootb_cookie_ack
= 0;
3421 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3423 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3425 /* Report violation if the chunk is less then minimal */
3426 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3427 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3430 /* Now that we know we at least have a chunk header,
3431 * do things that are type appropriate.
3433 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3436 /* RFC 2960, Section 3.3.7
3437 * Moreover, under any circumstances, an endpoint that
3438 * receives an ABORT MUST NOT respond to that ABORT by
3439 * sending an ABORT of its own.
3441 if (SCTP_CID_ABORT
== ch
->type
)
3442 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3444 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3445 * or a COOKIE ACK the SCTP Packet should be silently
3449 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3450 ootb_cookie_ack
= 1;
3452 if (SCTP_CID_ERROR
== ch
->type
) {
3453 sctp_walk_errors(err
, ch
) {
3454 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3455 ootb_cookie_ack
= 1;
3461 /* Report violation if chunk len overflows */
3462 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3463 if (ch_end
> skb_tail_pointer(skb
))
3464 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3467 ch
= (sctp_chunkhdr_t
*) ch_end
;
3468 } while (ch_end
< skb_tail_pointer(skb
));
3471 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3472 else if (ootb_cookie_ack
)
3473 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3475 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3479 * Handle an "Out of the blue" SHUTDOWN ACK.
3481 * Section: 8.4 5, sctpimpguide 2.41.
3483 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3484 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3485 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3486 * packet must fill in the Verification Tag field of the outbound
3487 * packet with the Verification Tag received in the SHUTDOWN ACK and
3488 * set the T-bit in the Chunk Flags to indicate that the Verification
3492 * (endpoint, asoc, type, arg, commands)
3495 * (sctp_disposition_t)
3497 * The return value is the disposition of the chunk.
3499 static sctp_disposition_t
sctp_sf_shut_8_4_5(struct net
*net
,
3500 const struct sctp_endpoint
*ep
,
3501 const struct sctp_association
*asoc
,
3502 const sctp_subtype_t type
,
3504 sctp_cmd_seq_t
*commands
)
3506 struct sctp_packet
*packet
= NULL
;
3507 struct sctp_chunk
*chunk
= arg
;
3508 struct sctp_chunk
*shut
;
3510 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3513 /* Make an SHUTDOWN_COMPLETE.
3514 * The T bit will be set if the asoc is NULL.
3516 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3518 sctp_ootb_pkt_free(packet
);
3519 return SCTP_DISPOSITION_NOMEM
;
3522 /* Reflect vtag if T-Bit is set */
3523 if (sctp_test_T_bit(shut
))
3524 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3526 /* Set the skb to the belonging sock for accounting. */
3527 shut
->skb
->sk
= ep
->base
.sk
;
3529 sctp_packet_append_chunk(packet
, shut
);
3531 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3532 SCTP_PACKET(packet
));
3534 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3536 /* If the chunk length is invalid, we don't want to process
3537 * the reset of the packet.
3539 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3540 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3542 /* We need to discard the rest of the packet to prevent
3543 * potential bomming attacks from additional bundled chunks.
3544 * This is documented in SCTP Threats ID.
3546 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3549 return SCTP_DISPOSITION_NOMEM
;
3553 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3555 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3556 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3557 * procedures in section 8.4 SHOULD be followed, in other words it
3558 * should be treated as an Out Of The Blue packet.
3559 * [This means that we do NOT check the Verification Tag on these
3563 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3564 const struct sctp_endpoint
*ep
,
3565 const struct sctp_association
*asoc
,
3566 const sctp_subtype_t type
,
3568 sctp_cmd_seq_t
*commands
)
3570 struct sctp_chunk
*chunk
= arg
;
3572 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3573 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3574 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3577 /* Although we do have an association in this case, it corresponds
3578 * to a restarted association. So the packet is treated as an OOTB
3579 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3580 * called with a NULL association.
3582 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3584 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3587 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3588 sctp_disposition_t
sctp_sf_do_asconf(struct net
*net
,
3589 const struct sctp_endpoint
*ep
,
3590 const struct sctp_association
*asoc
,
3591 const sctp_subtype_t type
, void *arg
,
3592 sctp_cmd_seq_t
*commands
)
3594 struct sctp_chunk
*chunk
= arg
;
3595 struct sctp_chunk
*asconf_ack
= NULL
;
3596 struct sctp_paramhdr
*err_param
= NULL
;
3597 sctp_addiphdr_t
*hdr
;
3600 if (!sctp_vtag_verify(chunk
, asoc
)) {
3601 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3603 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3606 /* ADD-IP: Section 4.1.1
3607 * This chunk MUST be sent in an authenticated way by using
3608 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3609 * is received unauthenticated it MUST be silently discarded as
3610 * described in [I-D.ietf-tsvwg-sctp-auth].
3612 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3613 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3615 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3616 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3617 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3620 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3621 serial
= ntohl(hdr
->serial
);
3623 /* Verify the ASCONF chunk before processing it. */
3624 if (!sctp_verify_asconf(asoc
, chunk
, true, &err_param
))
3625 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3626 (void *)err_param
, commands
);
3628 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3629 * the endpoint stored in a new association variable
3630 * 'Peer-Serial-Number'.
3632 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3633 /* If this is the first instance of ASCONF in the packet,
3634 * we can clean our old ASCONF-ACKs.
3636 if (!chunk
->has_asconf
)
3637 sctp_assoc_clean_asconf_ack_cache(asoc
);
3639 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3640 * expected, process the ASCONF as described below and after
3641 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3642 * the response packet and cache a copy of it (in the event it
3643 * later needs to be retransmitted).
3645 * Essentially, do V1-V5.
3647 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3650 return SCTP_DISPOSITION_NOMEM
;
3651 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3653 * If the value found in the Sequence Number is less than the
3654 * ('Peer- Sequence-Number' + 1), simply skip to the next
3655 * ASCONF, and include in the outbound response packet
3656 * any previously cached ASCONF-ACK response that was
3657 * sent and saved that matches the Sequence Number of the
3658 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3659 * Chunk exists. This will occur when an older ASCONF
3660 * arrives out of order. In such a case, the receiver
3661 * should skip the ASCONF Chunk and not include ASCONF-ACK
3662 * Chunk for that chunk.
3664 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3666 return SCTP_DISPOSITION_DISCARD
;
3668 /* Reset the transport so that we select the correct one
3669 * this time around. This is to make sure that we don't
3670 * accidentally use a stale transport that's been removed.
3672 asconf_ack
->transport
= NULL
;
3674 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3675 * it must be either a stale packet or from an attacker.
3677 return SCTP_DISPOSITION_DISCARD
;
3680 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3681 * containing the ASCONF-ACK Chunks MUST be the source address of
3682 * the SCTP packet that held the ASCONF Chunks.
3684 * To do this properly, we'll set the destination address of the chunk
3685 * and at the transmit time, will try look up the transport to use.
3686 * Since ASCONFs may be bundled, the correct transport may not be
3687 * created until we process the entire packet, thus this workaround.
3689 asconf_ack
->dest
= chunk
->source
;
3690 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3691 if (asoc
->new_transport
) {
3692 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
,
3694 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3697 return SCTP_DISPOSITION_CONSUME
;
3701 * ADDIP Section 4.3 General rules for address manipulation
3702 * When building TLV parameters for the ASCONF Chunk that will add or
3703 * delete IP addresses the D0 to D13 rules should be applied:
3705 sctp_disposition_t
sctp_sf_do_asconf_ack(struct net
*net
,
3706 const struct sctp_endpoint
*ep
,
3707 const struct sctp_association
*asoc
,
3708 const sctp_subtype_t type
, void *arg
,
3709 sctp_cmd_seq_t
*commands
)
3711 struct sctp_chunk
*asconf_ack
= arg
;
3712 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3713 struct sctp_chunk
*abort
;
3714 struct sctp_paramhdr
*err_param
= NULL
;
3715 sctp_addiphdr_t
*addip_hdr
;
3716 __u32 sent_serial
, rcvd_serial
;
3718 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3719 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3721 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3724 /* ADD-IP, Section 4.1.2:
3725 * This chunk MUST be sent in an authenticated way by using
3726 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3727 * is received unauthenticated it MUST be silently discarded as
3728 * described in [I-D.ietf-tsvwg-sctp-auth].
3730 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3731 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3733 /* Make sure that the ADDIP chunk has a valid length. */
3734 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3735 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3738 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3739 rcvd_serial
= ntohl(addip_hdr
->serial
);
3741 /* Verify the ASCONF-ACK chunk before processing it. */
3742 if (!sctp_verify_asconf(asoc
, asconf_ack
, false, &err_param
))
3743 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3744 (void *)err_param
, commands
);
3747 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3748 sent_serial
= ntohl(addip_hdr
->serial
);
3750 sent_serial
= asoc
->addip_serial
- 1;
3753 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3754 * equal to the next serial number to be used but no ASCONF chunk is
3755 * outstanding the endpoint MUST ABORT the association. Note that a
3756 * sequence number is greater than if it is no more than 2^^31-1
3757 * larger than the current sequence number (using serial arithmetic).
3759 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3760 !(asoc
->addip_last_asconf
)) {
3761 abort
= sctp_make_abort(asoc
, asconf_ack
,
3762 sizeof(sctp_errhdr_t
));
3764 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3765 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3768 /* We are going to ABORT, so we might as well stop
3769 * processing the rest of the chunks in the packet.
3771 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3772 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3773 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3774 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3775 SCTP_ERROR(ECONNABORTED
));
3776 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3777 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3778 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3779 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3780 return SCTP_DISPOSITION_ABORT
;
3783 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3784 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3785 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3787 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3789 /* Successfully processed ASCONF_ACK. We can
3790 * release the next asconf if we have one.
3792 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3794 return SCTP_DISPOSITION_CONSUME
;
3797 abort
= sctp_make_abort(asoc
, asconf_ack
,
3798 sizeof(sctp_errhdr_t
));
3800 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3801 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3804 /* We are going to ABORT, so we might as well stop
3805 * processing the rest of the chunks in the packet.
3807 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3808 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3809 SCTP_ERROR(ECONNABORTED
));
3810 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3811 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3812 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3813 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3814 return SCTP_DISPOSITION_ABORT
;
3817 return SCTP_DISPOSITION_DISCARD
;
3821 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3823 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3824 * its cumulative TSN point to the value carried in the FORWARD TSN
3825 * chunk, and then MUST further advance its cumulative TSN point locally
3827 * After the above processing, the data receiver MUST stop reporting any
3828 * missing TSNs earlier than or equal to the new cumulative TSN point.
3830 * Verification Tag: 8.5 Verification Tag [Normal verification]
3832 * The return value is the disposition of the chunk.
3834 sctp_disposition_t
sctp_sf_eat_fwd_tsn(struct net
*net
,
3835 const struct sctp_endpoint
*ep
,
3836 const struct sctp_association
*asoc
,
3837 const sctp_subtype_t type
,
3839 sctp_cmd_seq_t
*commands
)
3841 struct sctp_chunk
*chunk
= arg
;
3842 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3843 struct sctp_fwdtsn_skip
*skip
;
3847 if (!sctp_vtag_verify(chunk
, asoc
)) {
3848 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3850 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3853 /* Make sure that the FORWARD_TSN chunk has valid length. */
3854 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3855 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3858 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3859 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3860 len
= ntohs(chunk
->chunk_hdr
->length
);
3861 len
-= sizeof(struct sctp_chunkhdr
);
3862 skb_pull(chunk
->skb
, len
);
3864 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3865 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3867 /* The TSN is too high--silently discard the chunk and count on it
3868 * getting retransmitted later.
3870 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3871 goto discard_noforce
;
3873 /* Silently discard the chunk if stream-id is not valid */
3874 sctp_walk_fwdtsn(skip
, chunk
) {
3875 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3876 goto discard_noforce
;
3879 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3880 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3881 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3884 /* Count this as receiving DATA. */
3885 if (asoc
->autoclose
) {
3886 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3887 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3890 /* FIXME: For now send a SACK, but DATA processing may
3893 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3895 return SCTP_DISPOSITION_CONSUME
;
3898 return SCTP_DISPOSITION_DISCARD
;
3901 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3903 const struct sctp_endpoint
*ep
,
3904 const struct sctp_association
*asoc
,
3905 const sctp_subtype_t type
,
3907 sctp_cmd_seq_t
*commands
)
3909 struct sctp_chunk
*chunk
= arg
;
3910 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3911 struct sctp_fwdtsn_skip
*skip
;
3915 if (!sctp_vtag_verify(chunk
, asoc
)) {
3916 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3918 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3921 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3922 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3923 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3926 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3927 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3928 len
= ntohs(chunk
->chunk_hdr
->length
);
3929 len
-= sizeof(struct sctp_chunkhdr
);
3930 skb_pull(chunk
->skb
, len
);
3932 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3933 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
3935 /* The TSN is too high--silently discard the chunk and count on it
3936 * getting retransmitted later.
3938 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3941 /* Silently discard the chunk if stream-id is not valid */
3942 sctp_walk_fwdtsn(skip
, chunk
) {
3943 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3947 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3948 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3949 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3952 /* Go a head and force a SACK, since we are shutting down. */
3954 /* Implementor's Guide.
3956 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3957 * respond to each received packet containing one or more DATA chunk(s)
3958 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3960 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3961 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3962 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3963 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3965 return SCTP_DISPOSITION_CONSUME
;
3969 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
3971 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3972 * Identifier field. If this algorithm was not specified by the
3973 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3974 * during association setup, the AUTH chunk and all chunks after it MUST
3975 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3976 * defined in Section 4.1.
3978 * If an endpoint with no shared key receives a Shared Key Identifier
3979 * other than 0, it MUST silently discard all authenticated chunks. If
3980 * the endpoint has at least one endpoint pair shared key for the peer,
3981 * it MUST use the key specified by the Shared Key Identifier if a
3982 * key has been configured for that Shared Key Identifier. If no
3983 * endpoint pair shared key has been configured for that Shared Key
3984 * Identifier, all authenticated chunks MUST be silently discarded.
3986 * Verification Tag: 8.5 Verification Tag [Normal verification]
3988 * The return value is the disposition of the chunk.
3990 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
3991 const struct sctp_endpoint
*ep
,
3992 const struct sctp_association
*asoc
,
3993 const sctp_subtype_t type
,
3994 struct sctp_chunk
*chunk
)
3996 struct sctp_authhdr
*auth_hdr
;
3997 struct sctp_hmac
*hmac
;
3998 unsigned int sig_len
;
4003 /* Pull in the auth header, so we can do some more verification */
4004 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4005 chunk
->subh
.auth_hdr
= auth_hdr
;
4006 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
4008 /* Make sure that we support the HMAC algorithm from the auth
4011 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4012 return SCTP_IERROR_AUTH_BAD_HMAC
;
4014 /* Make sure that the provided shared key identifier has been
4017 key_id
= ntohs(auth_hdr
->shkey_id
);
4018 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4019 return SCTP_IERROR_AUTH_BAD_KEYID
;
4022 /* Make sure that the length of the signature matches what
4025 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
4026 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4027 if (sig_len
!= hmac
->hmac_len
)
4028 return SCTP_IERROR_PROTO_VIOLATION
;
4030 /* Now that we've done validation checks, we can compute and
4031 * verify the hmac. The steps involved are:
4032 * 1. Save the digest from the chunk.
4033 * 2. Zero out the digest in the chunk.
4034 * 3. Compute the new digest
4035 * 4. Compare saved and new digests.
4037 digest
= auth_hdr
->hmac
;
4038 skb_pull(chunk
->skb
, sig_len
);
4040 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4044 memset(digest
, 0, sig_len
);
4046 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4047 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4050 /* Discard the packet if the digests do not match */
4051 if (memcmp(save_digest
, digest
, sig_len
)) {
4053 return SCTP_IERROR_BAD_SIG
;
4059 return SCTP_IERROR_NO_ERROR
;
4061 return SCTP_IERROR_NOMEM
;
4064 sctp_disposition_t
sctp_sf_eat_auth(struct net
*net
,
4065 const struct sctp_endpoint
*ep
,
4066 const struct sctp_association
*asoc
,
4067 const sctp_subtype_t type
,
4069 sctp_cmd_seq_t
*commands
)
4071 struct sctp_authhdr
*auth_hdr
;
4072 struct sctp_chunk
*chunk
= arg
;
4073 struct sctp_chunk
*err_chunk
;
4074 sctp_ierror_t error
;
4076 /* Make sure that the peer has AUTH capable */
4077 if (!asoc
->peer
.auth_capable
)
4078 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4080 if (!sctp_vtag_verify(chunk
, asoc
)) {
4081 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4083 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4086 /* Make sure that the AUTH chunk has valid length. */
4087 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4088 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4091 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4092 error
= sctp_sf_authenticate(net
, ep
, asoc
, type
, chunk
);
4094 case SCTP_IERROR_AUTH_BAD_HMAC
:
4095 /* Generate the ERROR chunk and discard the rest
4098 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4099 SCTP_ERROR_UNSUP_HMAC
,
4103 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4104 SCTP_CHUNK(err_chunk
));
4107 case SCTP_IERROR_AUTH_BAD_KEYID
:
4108 case SCTP_IERROR_BAD_SIG
:
4109 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4111 case SCTP_IERROR_PROTO_VIOLATION
:
4112 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4115 case SCTP_IERROR_NOMEM
:
4116 return SCTP_DISPOSITION_NOMEM
;
4118 default: /* Prevent gcc warnings */
4122 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4123 struct sctp_ulpevent
*ev
;
4125 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4126 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4131 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4135 return SCTP_DISPOSITION_CONSUME
;
4139 * Process an unknown chunk.
4141 * Section: 3.2. Also, 2.1 in the implementor's guide.
4143 * Chunk Types are encoded such that the highest-order two bits specify
4144 * the action that must be taken if the processing endpoint does not
4145 * recognize the Chunk Type.
4147 * 00 - Stop processing this SCTP packet and discard it, do not process
4148 * any further chunks within it.
4150 * 01 - Stop processing this SCTP packet and discard it, do not process
4151 * any further chunks within it, and report the unrecognized
4152 * chunk in an 'Unrecognized Chunk Type'.
4154 * 10 - Skip this chunk and continue processing.
4156 * 11 - Skip this chunk and continue processing, but report in an ERROR
4157 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4159 * The return value is the disposition of the chunk.
4161 sctp_disposition_t
sctp_sf_unk_chunk(struct net
*net
,
4162 const struct sctp_endpoint
*ep
,
4163 const struct sctp_association
*asoc
,
4164 const sctp_subtype_t type
,
4166 sctp_cmd_seq_t
*commands
)
4168 struct sctp_chunk
*unk_chunk
= arg
;
4169 struct sctp_chunk
*err_chunk
;
4170 sctp_chunkhdr_t
*hdr
;
4172 pr_debug("%s: processing unknown chunk id:%d\n", __func__
, type
.chunk
);
4174 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4175 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4177 /* Make sure that the chunk has a valid length.
4178 * Since we don't know the chunk type, we use a general
4179 * chunkhdr structure to make a comparison.
4181 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4182 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4185 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4186 case SCTP_CID_ACTION_DISCARD
:
4187 /* Discard the packet. */
4188 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4190 case SCTP_CID_ACTION_DISCARD_ERR
:
4191 /* Generate an ERROR chunk as response. */
4192 hdr
= unk_chunk
->chunk_hdr
;
4193 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4194 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4195 WORD_ROUND(ntohs(hdr
->length
)),
4198 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4199 SCTP_CHUNK(err_chunk
));
4202 /* Discard the packet. */
4203 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4204 return SCTP_DISPOSITION_CONSUME
;
4206 case SCTP_CID_ACTION_SKIP
:
4207 /* Skip the chunk. */
4208 return SCTP_DISPOSITION_DISCARD
;
4210 case SCTP_CID_ACTION_SKIP_ERR
:
4211 /* Generate an ERROR chunk as response. */
4212 hdr
= unk_chunk
->chunk_hdr
;
4213 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4214 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4215 WORD_ROUND(ntohs(hdr
->length
)),
4218 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4219 SCTP_CHUNK(err_chunk
));
4221 /* Skip the chunk. */
4222 return SCTP_DISPOSITION_CONSUME
;
4228 return SCTP_DISPOSITION_DISCARD
;
4232 * Discard the chunk.
4234 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4235 * [Too numerous to mention...]
4236 * Verification Tag: No verification needed.
4238 * (endpoint, asoc, chunk)
4241 * (asoc, reply_msg, msg_up, timers, counters)
4243 * The return value is the disposition of the chunk.
4245 sctp_disposition_t
sctp_sf_discard_chunk(struct net
*net
,
4246 const struct sctp_endpoint
*ep
,
4247 const struct sctp_association
*asoc
,
4248 const sctp_subtype_t type
,
4250 sctp_cmd_seq_t
*commands
)
4252 struct sctp_chunk
*chunk
= arg
;
4254 /* Make sure that the chunk has a valid length.
4255 * Since we don't know the chunk type, we use a general
4256 * chunkhdr structure to make a comparison.
4258 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4259 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4262 pr_debug("%s: chunk:%d is discarded\n", __func__
, type
.chunk
);
4264 return SCTP_DISPOSITION_DISCARD
;
4268 * Discard the whole packet.
4272 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4273 * silently discard the OOTB packet and take no further action.
4275 * Verification Tag: No verification necessary
4278 * (endpoint, asoc, chunk)
4281 * (asoc, reply_msg, msg_up, timers, counters)
4283 * The return value is the disposition of the chunk.
4285 sctp_disposition_t
sctp_sf_pdiscard(struct net
*net
,
4286 const struct sctp_endpoint
*ep
,
4287 const struct sctp_association
*asoc
,
4288 const sctp_subtype_t type
,
4290 sctp_cmd_seq_t
*commands
)
4292 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4293 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4295 return SCTP_DISPOSITION_CONSUME
;
4300 * The other end is violating protocol.
4302 * Section: Not specified
4303 * Verification Tag: Not specified
4305 * (endpoint, asoc, chunk)
4308 * (asoc, reply_msg, msg_up, timers, counters)
4310 * We simply tag the chunk as a violation. The state machine will log
4311 * the violation and continue.
4313 sctp_disposition_t
sctp_sf_violation(struct net
*net
,
4314 const struct sctp_endpoint
*ep
,
4315 const struct sctp_association
*asoc
,
4316 const sctp_subtype_t type
,
4318 sctp_cmd_seq_t
*commands
)
4320 struct sctp_chunk
*chunk
= arg
;
4322 /* Make sure that the chunk has a valid length. */
4323 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4324 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4327 return SCTP_DISPOSITION_VIOLATION
;
4331 * Common function to handle a protocol violation.
4333 static sctp_disposition_t
sctp_sf_abort_violation(
4335 const struct sctp_endpoint
*ep
,
4336 const struct sctp_association
*asoc
,
4338 sctp_cmd_seq_t
*commands
,
4339 const __u8
*payload
,
4340 const size_t paylen
)
4342 struct sctp_packet
*packet
= NULL
;
4343 struct sctp_chunk
*chunk
= arg
;
4344 struct sctp_chunk
*abort
= NULL
;
4346 /* SCTP-AUTH, Section 6.3:
4347 * It should be noted that if the receiver wants to tear
4348 * down an association in an authenticated way only, the
4349 * handling of malformed packets should not result in
4350 * tearing down the association.
4352 * This means that if we only want to abort associations
4353 * in an authenticated way (i.e AUTH+ABORT), then we
4354 * can't destroy this association just because the packet
4357 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4360 /* Make the abort chunk. */
4361 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4366 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4367 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4368 !asoc
->peer
.i
.init_tag
) {
4369 sctp_initack_chunk_t
*initack
;
4371 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4372 if (!sctp_chunk_length_valid(chunk
,
4373 sizeof(sctp_initack_chunk_t
)))
4374 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4376 unsigned int inittag
;
4378 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4379 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4384 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4385 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4387 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4388 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4389 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4390 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4391 SCTP_ERROR(ECONNREFUSED
));
4392 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4393 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4395 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4396 SCTP_ERROR(ECONNABORTED
));
4397 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4398 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4399 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4402 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4407 if (sctp_test_T_bit(abort
))
4408 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4410 abort
->skb
->sk
= ep
->base
.sk
;
4412 sctp_packet_append_chunk(packet
, abort
);
4414 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4415 SCTP_PACKET(packet
));
4417 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4420 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4423 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4424 return SCTP_DISPOSITION_ABORT
;
4427 sctp_chunk_free(abort
);
4429 return SCTP_DISPOSITION_NOMEM
;
4433 * Handle a protocol violation when the chunk length is invalid.
4434 * "Invalid" length is identified as smaller than the minimal length a
4435 * given chunk can be. For example, a SACK chunk has invalid length
4436 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4438 * We inform the other end by sending an ABORT with a Protocol Violation
4441 * Section: Not specified
4442 * Verification Tag: Nothing to do
4444 * (endpoint, asoc, chunk)
4447 * (reply_msg, msg_up, counters)
4449 * Generate an ABORT chunk and terminate the association.
4451 static sctp_disposition_t
sctp_sf_violation_chunklen(
4453 const struct sctp_endpoint
*ep
,
4454 const struct sctp_association
*asoc
,
4455 const sctp_subtype_t type
,
4457 sctp_cmd_seq_t
*commands
)
4459 static const char err_str
[]="The following chunk had invalid length:";
4461 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4466 * Handle a protocol violation when the parameter length is invalid.
4467 * If the length is smaller than the minimum length of a given parameter,
4468 * or accumulated length in multi parameters exceeds the end of the chunk,
4469 * the length is considered as invalid.
4471 static sctp_disposition_t
sctp_sf_violation_paramlen(
4473 const struct sctp_endpoint
*ep
,
4474 const struct sctp_association
*asoc
,
4475 const sctp_subtype_t type
,
4476 void *arg
, void *ext
,
4477 sctp_cmd_seq_t
*commands
)
4479 struct sctp_chunk
*chunk
= arg
;
4480 struct sctp_paramhdr
*param
= ext
;
4481 struct sctp_chunk
*abort
= NULL
;
4483 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4486 /* Make the abort chunk. */
4487 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4491 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4492 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4494 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4495 SCTP_ERROR(ECONNABORTED
));
4496 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4497 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4498 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4499 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4502 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4503 return SCTP_DISPOSITION_ABORT
;
4505 return SCTP_DISPOSITION_NOMEM
;
4508 /* Handle a protocol violation when the peer trying to advance the
4509 * cumulative tsn ack to a point beyond the max tsn currently sent.
4511 * We inform the other end by sending an ABORT with a Protocol Violation
4514 static sctp_disposition_t
sctp_sf_violation_ctsn(
4516 const struct sctp_endpoint
*ep
,
4517 const struct sctp_association
*asoc
,
4518 const sctp_subtype_t type
,
4520 sctp_cmd_seq_t
*commands
)
4522 static const char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4524 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4528 /* Handle protocol violation of an invalid chunk bundling. For example,
4529 * when we have an association and we receive bundled INIT-ACK, or
4530 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4531 * statement from the specs. Additionally, there might be an attacker
4532 * on the path and we may not want to continue this communication.
4534 static sctp_disposition_t
sctp_sf_violation_chunk(
4536 const struct sctp_endpoint
*ep
,
4537 const struct sctp_association
*asoc
,
4538 const sctp_subtype_t type
,
4540 sctp_cmd_seq_t
*commands
)
4542 static const char err_str
[]="The following chunk violates protocol:";
4545 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4547 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4550 /***************************************************************************
4551 * These are the state functions for handling primitive (Section 10) events.
4552 ***************************************************************************/
4554 * sctp_sf_do_prm_asoc
4556 * Section: 10.1 ULP-to-SCTP
4559 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4560 * outbound stream count)
4561 * -> association id [,destination transport addr list] [,outbound stream
4564 * This primitive allows the upper layer to initiate an association to a
4565 * specific peer endpoint.
4567 * The peer endpoint shall be specified by one of the transport addresses
4568 * which defines the endpoint (see Section 1.4). If the local SCTP
4569 * instance has not been initialized, the ASSOCIATE is considered an
4571 * [This is not relevant for the kernel implementation since we do all
4572 * initialization at boot time. It we hadn't initialized we wouldn't
4573 * get anywhere near this code.]
4575 * An association id, which is a local handle to the SCTP association,
4576 * will be returned on successful establishment of the association. If
4577 * SCTP is not able to open an SCTP association with the peer endpoint,
4578 * an error is returned.
4579 * [In the kernel implementation, the struct sctp_association needs to
4580 * be created BEFORE causing this primitive to run.]
4582 * Other association parameters may be returned, including the
4583 * complete destination transport addresses of the peer as well as the
4584 * outbound stream count of the local endpoint. One of the transport
4585 * address from the returned destination addresses will be selected by
4586 * the local endpoint as default primary path for sending SCTP packets
4587 * to this peer. The returned "destination transport addr list" can
4588 * be used by the ULP to change the default primary path or to force
4589 * sending a packet to a specific transport address. [All of this
4590 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4593 * Mandatory attributes:
4595 * o local SCTP instance name - obtained from the INITIALIZE operation.
4596 * [This is the argument asoc.]
4597 * o destination transport addr - specified as one of the transport
4598 * addresses of the peer endpoint with which the association is to be
4600 * [This is asoc->peer.active_path.]
4601 * o outbound stream count - the number of outbound streams the ULP
4602 * would like to open towards this peer endpoint.
4603 * [BUG: This is not currently implemented.]
4604 * Optional attributes:
4608 * The return value is a disposition.
4610 sctp_disposition_t
sctp_sf_do_prm_asoc(struct net
*net
,
4611 const struct sctp_endpoint
*ep
,
4612 const struct sctp_association
*asoc
,
4613 const sctp_subtype_t type
,
4615 sctp_cmd_seq_t
*commands
)
4617 struct sctp_chunk
*repl
;
4618 struct sctp_association
* my_asoc
;
4620 /* The comment below says that we enter COOKIE-WAIT AFTER
4621 * sending the INIT, but that doesn't actually work in our
4624 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4625 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4627 /* RFC 2960 5.1 Normal Establishment of an Association
4629 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4630 * must provide its Verification Tag (Tag_A) in the Initiate
4631 * Tag field. Tag_A SHOULD be a random number in the range of
4632 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4635 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4639 /* Choose transport for INIT. */
4640 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4643 /* Cast away the const modifier, as we want to just
4644 * rerun it through as a sideffect.
4646 my_asoc
= (struct sctp_association
*)asoc
;
4647 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4649 /* After sending the INIT, "A" starts the T1-init timer and
4650 * enters the COOKIE-WAIT state.
4652 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4653 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4654 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4655 return SCTP_DISPOSITION_CONSUME
;
4658 return SCTP_DISPOSITION_NOMEM
;
4662 * Process the SEND primitive.
4664 * Section: 10.1 ULP-to-SCTP
4667 * Format: SEND(association id, buffer address, byte count [,context]
4668 * [,stream id] [,life time] [,destination transport address]
4669 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4672 * This is the main method to send user data via SCTP.
4674 * Mandatory attributes:
4676 * o association id - local handle to the SCTP association
4678 * o buffer address - the location where the user message to be
4679 * transmitted is stored;
4681 * o byte count - The size of the user data in number of bytes;
4683 * Optional attributes:
4685 * o context - an optional 32 bit integer that will be carried in the
4686 * sending failure notification to the ULP if the transportation of
4687 * this User Message fails.
4689 * o stream id - to indicate which stream to send the data on. If not
4690 * specified, stream 0 will be used.
4692 * o life time - specifies the life time of the user data. The user data
4693 * will not be sent by SCTP after the life time expires. This
4694 * parameter can be used to avoid efforts to transmit stale
4695 * user messages. SCTP notifies the ULP if the data cannot be
4696 * initiated to transport (i.e. sent to the destination via SCTP's
4697 * send primitive) within the life time variable. However, the
4698 * user data will be transmitted if SCTP has attempted to transmit a
4699 * chunk before the life time expired.
4701 * o destination transport address - specified as one of the destination
4702 * transport addresses of the peer endpoint to which this packet
4703 * should be sent. Whenever possible, SCTP should use this destination
4704 * transport address for sending the packets, instead of the current
4707 * o unorder flag - this flag, if present, indicates that the user
4708 * would like the data delivered in an unordered fashion to the peer
4709 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4712 * o no-bundle flag - instructs SCTP not to bundle this user data with
4713 * other outbound DATA chunks. SCTP MAY still bundle even when
4714 * this flag is present, when faced with network congestion.
4716 * o payload protocol-id - A 32 bit unsigned integer that is to be
4717 * passed to the peer indicating the type of payload protocol data
4718 * being transmitted. This value is passed as opaque data by SCTP.
4720 * The return value is the disposition.
4722 sctp_disposition_t
sctp_sf_do_prm_send(struct net
*net
,
4723 const struct sctp_endpoint
*ep
,
4724 const struct sctp_association
*asoc
,
4725 const sctp_subtype_t type
,
4727 sctp_cmd_seq_t
*commands
)
4729 struct sctp_datamsg
*msg
= arg
;
4731 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4732 return SCTP_DISPOSITION_CONSUME
;
4736 * Process the SHUTDOWN primitive.
4741 * Format: SHUTDOWN(association id)
4744 * Gracefully closes an association. Any locally queued user data
4745 * will be delivered to the peer. The association will be terminated only
4746 * after the peer acknowledges all the SCTP packets sent. A success code
4747 * will be returned on successful termination of the association. If
4748 * attempting to terminate the association results in a failure, an error
4749 * code shall be returned.
4751 * Mandatory attributes:
4753 * o association id - local handle to the SCTP association
4755 * Optional attributes:
4759 * The return value is the disposition.
4761 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4763 const struct sctp_endpoint
*ep
,
4764 const struct sctp_association
*asoc
,
4765 const sctp_subtype_t type
,
4767 sctp_cmd_seq_t
*commands
)
4771 /* From 9.2 Shutdown of an Association
4772 * Upon receipt of the SHUTDOWN primitive from its upper
4773 * layer, the endpoint enters SHUTDOWN-PENDING state and
4774 * remains there until all outstanding data has been
4775 * acknowledged by its peer. The endpoint accepts no new data
4776 * from its upper layer, but retransmits data to the far end
4777 * if necessary to fill gaps.
4779 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4780 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4782 disposition
= SCTP_DISPOSITION_CONSUME
;
4783 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4784 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4791 * Process the ABORT primitive.
4796 * Format: Abort(association id [, cause code])
4799 * Ungracefully closes an association. Any locally queued user data
4800 * will be discarded and an ABORT chunk is sent to the peer. A success code
4801 * will be returned on successful abortion of the association. If
4802 * attempting to abort the association results in a failure, an error
4803 * code shall be returned.
4805 * Mandatory attributes:
4807 * o association id - local handle to the SCTP association
4809 * Optional attributes:
4811 * o cause code - reason of the abort to be passed to the peer
4815 * The return value is the disposition.
4817 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4819 const struct sctp_endpoint
*ep
,
4820 const struct sctp_association
*asoc
,
4821 const sctp_subtype_t type
,
4823 sctp_cmd_seq_t
*commands
)
4825 /* From 9.1 Abort of an Association
4826 * Upon receipt of the ABORT primitive from its upper
4827 * layer, the endpoint enters CLOSED state and
4828 * discard all outstanding data has been
4829 * acknowledged by its peer. The endpoint accepts no new data
4830 * from its upper layer, but retransmits data to the far end
4831 * if necessary to fill gaps.
4833 struct sctp_chunk
*abort
= arg
;
4834 sctp_disposition_t retval
;
4836 retval
= SCTP_DISPOSITION_CONSUME
;
4838 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4840 /* Even if we can't send the ABORT due to low memory delete the
4841 * TCB. This is a departure from our typical NOMEM handling.
4844 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4845 SCTP_ERROR(ECONNABORTED
));
4846 /* Delete the established association. */
4847 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4848 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4850 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4851 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4856 /* We tried an illegal operation on an association which is closed. */
4857 sctp_disposition_t
sctp_sf_error_closed(struct net
*net
,
4858 const struct sctp_endpoint
*ep
,
4859 const struct sctp_association
*asoc
,
4860 const sctp_subtype_t type
,
4862 sctp_cmd_seq_t
*commands
)
4864 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4865 return SCTP_DISPOSITION_CONSUME
;
4868 /* We tried an illegal operation on an association which is shutting
4871 sctp_disposition_t
sctp_sf_error_shutdown(struct net
*net
,
4872 const struct sctp_endpoint
*ep
,
4873 const struct sctp_association
*asoc
,
4874 const sctp_subtype_t type
,
4876 sctp_cmd_seq_t
*commands
)
4878 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4879 SCTP_ERROR(-ESHUTDOWN
));
4880 return SCTP_DISPOSITION_CONSUME
;
4884 * sctp_cookie_wait_prm_shutdown
4886 * Section: 4 Note: 2
4891 * The RFC does not explicitly address this issue, but is the route through the
4892 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4897 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4899 const struct sctp_endpoint
*ep
,
4900 const struct sctp_association
*asoc
,
4901 const sctp_subtype_t type
,
4903 sctp_cmd_seq_t
*commands
)
4905 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4906 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4908 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4909 SCTP_STATE(SCTP_STATE_CLOSED
));
4911 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
4913 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4915 return SCTP_DISPOSITION_DELETE_TCB
;
4919 * sctp_cookie_echoed_prm_shutdown
4921 * Section: 4 Note: 2
4926 * The RFC does not explcitly address this issue, but is the route through the
4927 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4932 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4934 const struct sctp_endpoint
*ep
,
4935 const struct sctp_association
*asoc
,
4936 const sctp_subtype_t type
,
4937 void *arg
, sctp_cmd_seq_t
*commands
)
4939 /* There is a single T1 timer, so we should be able to use
4940 * common function with the COOKIE-WAIT state.
4942 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
4946 * sctp_sf_cookie_wait_prm_abort
4948 * Section: 4 Note: 2
4953 * The RFC does not explicitly address this issue, but is the route through the
4954 * state table when someone issues an abort while in COOKIE_WAIT state.
4959 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4961 const struct sctp_endpoint
*ep
,
4962 const struct sctp_association
*asoc
,
4963 const sctp_subtype_t type
,
4965 sctp_cmd_seq_t
*commands
)
4967 struct sctp_chunk
*abort
= arg
;
4968 sctp_disposition_t retval
;
4970 /* Stop T1-init timer */
4971 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4972 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4973 retval
= SCTP_DISPOSITION_CONSUME
;
4975 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4977 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4978 SCTP_STATE(SCTP_STATE_CLOSED
));
4980 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4982 /* Even if we can't send the ABORT due to low memory delete the
4983 * TCB. This is a departure from our typical NOMEM handling.
4986 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4987 SCTP_ERROR(ECONNREFUSED
));
4988 /* Delete the established association. */
4989 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4990 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4996 * sctp_sf_cookie_echoed_prm_abort
4998 * Section: 4 Note: 3
5003 * The RFC does not explcitly address this issue, but is the route through the
5004 * state table when someone issues an abort while in COOKIE_ECHOED state.
5009 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
5011 const struct sctp_endpoint
*ep
,
5012 const struct sctp_association
*asoc
,
5013 const sctp_subtype_t type
,
5015 sctp_cmd_seq_t
*commands
)
5017 /* There is a single T1 timer, so we should be able to use
5018 * common function with the COOKIE-WAIT state.
5020 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5024 * sctp_sf_shutdown_pending_prm_abort
5029 * The RFC does not explicitly address this issue, but is the route through the
5030 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5035 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
5037 const struct sctp_endpoint
*ep
,
5038 const struct sctp_association
*asoc
,
5039 const sctp_subtype_t type
,
5041 sctp_cmd_seq_t
*commands
)
5043 /* Stop the T5-shutdown guard timer. */
5044 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5045 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5047 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5051 * sctp_sf_shutdown_sent_prm_abort
5056 * The RFC does not explicitly address this issue, but is the route through the
5057 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5062 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
5064 const struct sctp_endpoint
*ep
,
5065 const struct sctp_association
*asoc
,
5066 const sctp_subtype_t type
,
5068 sctp_cmd_seq_t
*commands
)
5070 /* Stop the T2-shutdown timer. */
5071 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5072 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5074 /* Stop the T5-shutdown guard timer. */
5075 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5076 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5078 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5082 * sctp_sf_cookie_echoed_prm_abort
5087 * The RFC does not explcitly address this issue, but is the route through the
5088 * state table when someone issues an abort while in COOKIE_ECHOED state.
5093 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
5095 const struct sctp_endpoint
*ep
,
5096 const struct sctp_association
*asoc
,
5097 const sctp_subtype_t type
,
5099 sctp_cmd_seq_t
*commands
)
5101 /* The same T2 timer, so we should be able to use
5102 * common function with the SHUTDOWN-SENT state.
5104 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5108 * Process the REQUESTHEARTBEAT primitive
5111 * J) Request Heartbeat
5113 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5117 * Instructs the local endpoint to perform a HeartBeat on the specified
5118 * destination transport address of the given association. The returned
5119 * result should indicate whether the transmission of the HEARTBEAT
5120 * chunk to the destination address is successful.
5122 * Mandatory attributes:
5124 * o association id - local handle to the SCTP association
5126 * o destination transport address - the transport address of the
5127 * association on which a heartbeat should be issued.
5129 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
5131 const struct sctp_endpoint
*ep
,
5132 const struct sctp_association
*asoc
,
5133 const sctp_subtype_t type
,
5135 sctp_cmd_seq_t
*commands
)
5137 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5138 (struct sctp_transport
*)arg
, commands
))
5139 return SCTP_DISPOSITION_NOMEM
;
5142 * RFC 2960 (bis), section 8.3
5144 * D) Request an on-demand HEARTBEAT on a specific destination
5145 * transport address of a given association.
5147 * The endpoint should increment the respective error counter of
5148 * the destination transport address each time a HEARTBEAT is sent
5149 * to that address and not acknowledged within one RTO.
5152 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5153 SCTP_TRANSPORT(arg
));
5154 return SCTP_DISPOSITION_CONSUME
;
5158 * ADDIP Section 4.1 ASCONF Chunk Procedures
5159 * When an endpoint has an ASCONF signaled change to be sent to the
5160 * remote endpoint it should do A1 to A9
5162 sctp_disposition_t
sctp_sf_do_prm_asconf(struct net
*net
,
5163 const struct sctp_endpoint
*ep
,
5164 const struct sctp_association
*asoc
,
5165 const sctp_subtype_t type
,
5167 sctp_cmd_seq_t
*commands
)
5169 struct sctp_chunk
*chunk
= arg
;
5171 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5172 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5173 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5174 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5175 return SCTP_DISPOSITION_CONSUME
;
5179 * Ignore the primitive event
5181 * The return value is the disposition of the primitive.
5183 sctp_disposition_t
sctp_sf_ignore_primitive(
5185 const struct sctp_endpoint
*ep
,
5186 const struct sctp_association
*asoc
,
5187 const sctp_subtype_t type
,
5189 sctp_cmd_seq_t
*commands
)
5191 pr_debug("%s: primitive type:%d is ignored\n", __func__
,
5194 return SCTP_DISPOSITION_DISCARD
;
5197 /***************************************************************************
5198 * These are the state functions for the OTHER events.
5199 ***************************************************************************/
5202 * When the SCTP stack has no more user data to send or retransmit, this
5203 * notification is given to the user. Also, at the time when a user app
5204 * subscribes to this event, if there is no data to be sent or
5205 * retransmit, the stack will immediately send up this notification.
5207 sctp_disposition_t
sctp_sf_do_no_pending_tsn(
5209 const struct sctp_endpoint
*ep
,
5210 const struct sctp_association
*asoc
,
5211 const sctp_subtype_t type
,
5213 sctp_cmd_seq_t
*commands
)
5215 struct sctp_ulpevent
*event
;
5217 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5219 return SCTP_DISPOSITION_NOMEM
;
5221 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5223 return SCTP_DISPOSITION_CONSUME
;
5227 * Start the shutdown negotiation.
5230 * Once all its outstanding data has been acknowledged, the endpoint
5231 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5232 * TSN Ack field the last sequential TSN it has received from the peer.
5233 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5234 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5235 * with the updated last sequential TSN received from its peer.
5237 * The return value is the disposition.
5239 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5241 const struct sctp_endpoint
*ep
,
5242 const struct sctp_association
*asoc
,
5243 const sctp_subtype_t type
,
5245 sctp_cmd_seq_t
*commands
)
5247 struct sctp_chunk
*reply
;
5249 /* Once all its outstanding data has been acknowledged, the
5250 * endpoint shall send a SHUTDOWN chunk to its peer including
5251 * in the Cumulative TSN Ack field the last sequential TSN it
5252 * has received from the peer.
5254 reply
= sctp_make_shutdown(asoc
, NULL
);
5258 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5259 * T2-shutdown timer.
5261 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5263 /* It shall then start the T2-shutdown timer */
5264 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5265 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5267 /* RFC 4960 Section 9.2
5268 * The sender of the SHUTDOWN MAY also start an overall guard timer
5269 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5271 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5272 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5274 if (asoc
->autoclose
)
5275 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5276 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5278 /* and enter the SHUTDOWN-SENT state. */
5279 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5280 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5282 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5284 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5287 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5289 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5291 return SCTP_DISPOSITION_CONSUME
;
5294 return SCTP_DISPOSITION_NOMEM
;
5298 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5302 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5303 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5304 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5305 * endpoint must re-send the SHUTDOWN ACK.
5307 * The return value is the disposition.
5309 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5311 const struct sctp_endpoint
*ep
,
5312 const struct sctp_association
*asoc
,
5313 const sctp_subtype_t type
,
5315 sctp_cmd_seq_t
*commands
)
5317 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5318 struct sctp_chunk
*reply
;
5320 /* There are 2 ways of getting here:
5321 * 1) called in response to a SHUTDOWN chunk
5322 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5324 * For the case (2), the arg parameter is set to NULL. We need
5325 * to check that we have a chunk before accessing it's fields.
5328 if (!sctp_vtag_verify(chunk
, asoc
))
5329 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
5331 /* Make sure that the SHUTDOWN chunk has a valid length. */
5332 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5333 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
5337 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5338 * shall send a SHUTDOWN ACK ...
5340 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5344 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5345 * the T2-shutdown timer.
5347 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5349 /* and start/restart a T2-shutdown timer of its own, */
5350 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5351 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5353 if (asoc
->autoclose
)
5354 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5355 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5357 /* Enter the SHUTDOWN-ACK-SENT state. */
5358 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5359 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5361 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5363 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5366 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5368 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5370 return SCTP_DISPOSITION_CONSUME
;
5373 return SCTP_DISPOSITION_NOMEM
;
5377 * Ignore the event defined as other
5379 * The return value is the disposition of the event.
5381 sctp_disposition_t
sctp_sf_ignore_other(struct net
*net
,
5382 const struct sctp_endpoint
*ep
,
5383 const struct sctp_association
*asoc
,
5384 const sctp_subtype_t type
,
5386 sctp_cmd_seq_t
*commands
)
5388 pr_debug("%s: the event other type:%d is ignored\n",
5389 __func__
, type
.other
);
5391 return SCTP_DISPOSITION_DISCARD
;
5394 /************************************************************
5395 * These are the state functions for handling timeout events.
5396 ************************************************************/
5401 * Section: 6.3.3 Handle T3-rtx Expiration
5403 * Whenever the retransmission timer T3-rtx expires for a destination
5404 * address, do the following:
5407 * The return value is the disposition of the chunk.
5409 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5410 const struct sctp_endpoint
*ep
,
5411 const struct sctp_association
*asoc
,
5412 const sctp_subtype_t type
,
5414 sctp_cmd_seq_t
*commands
)
5416 struct sctp_transport
*transport
= arg
;
5418 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5420 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5421 if (asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5423 * We are here likely because the receiver had its rwnd
5424 * closed for a while and we have not been able to
5425 * transmit the locally queued data within the maximum
5426 * retransmission attempts limit. Start the T5
5427 * shutdown guard timer to give the receiver one last
5428 * chance and some additional time to recover before
5431 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5432 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5434 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5435 SCTP_ERROR(ETIMEDOUT
));
5436 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5437 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5438 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5439 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5440 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5441 return SCTP_DISPOSITION_DELETE_TCB
;
5445 /* E1) For the destination address for which the timer
5446 * expires, adjust its ssthresh with rules defined in Section
5447 * 7.2.3 and set the cwnd <- MTU.
5450 /* E2) For the destination address for which the timer
5451 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5452 * maximum value discussed in rule C7 above (RTO.max) may be
5453 * used to provide an upper bound to this doubling operation.
5456 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5457 * outstanding DATA chunks for the address for which the
5458 * T3-rtx has expired will fit into a single packet, subject
5459 * to the MTU constraint for the path corresponding to the
5460 * destination transport address to which the retransmission
5461 * is being sent (this may be different from the address for
5462 * which the timer expires [see Section 6.4]). Call this
5463 * value K. Bundle and retransmit those K DATA chunks in a
5464 * single packet to the destination endpoint.
5466 * Note: Any DATA chunks that were sent to the address for
5467 * which the T3-rtx timer expired but did not fit in one MTU
5468 * (rule E3 above), should be marked for retransmission and
5469 * sent as soon as cwnd allows (normally when a SACK arrives).
5472 /* Do some failure management (Section 8.2). */
5473 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5475 /* NB: Rules E4 and F1 are implicit in R1. */
5476 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5478 return SCTP_DISPOSITION_CONSUME
;
5482 * Generate delayed SACK on timeout
5484 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5486 * The guidelines on delayed acknowledgement algorithm specified in
5487 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5488 * acknowledgement SHOULD be generated for at least every second packet
5489 * (not every second DATA chunk) received, and SHOULD be generated
5490 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5491 * some situations it may be beneficial for an SCTP transmitter to be
5492 * more conservative than the algorithms detailed in this document
5493 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5494 * the following algorithms allow.
5496 sctp_disposition_t
sctp_sf_do_6_2_sack(struct net
*net
,
5497 const struct sctp_endpoint
*ep
,
5498 const struct sctp_association
*asoc
,
5499 const sctp_subtype_t type
,
5501 sctp_cmd_seq_t
*commands
)
5503 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5504 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5505 return SCTP_DISPOSITION_CONSUME
;
5509 * sctp_sf_t1_init_timer_expire
5511 * Section: 4 Note: 2
5516 * RFC 2960 Section 4 Notes
5517 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5518 * and re-start the T1-init timer without changing state. This MUST
5519 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5520 * endpoint MUST abort the initialization process and report the
5521 * error to SCTP user.
5527 sctp_disposition_t
sctp_sf_t1_init_timer_expire(struct net
*net
,
5528 const struct sctp_endpoint
*ep
,
5529 const struct sctp_association
*asoc
,
5530 const sctp_subtype_t type
,
5532 sctp_cmd_seq_t
*commands
)
5534 struct sctp_chunk
*repl
= NULL
;
5535 struct sctp_bind_addr
*bp
;
5536 int attempts
= asoc
->init_err_counter
+ 1;
5538 pr_debug("%s: timer T1 expired (INIT)\n", __func__
);
5540 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5542 if (attempts
<= asoc
->max_init_attempts
) {
5543 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5544 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5546 return SCTP_DISPOSITION_NOMEM
;
5548 /* Choose transport for INIT. */
5549 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5552 /* Issue a sideeffect to do the needed accounting. */
5553 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5554 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5556 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5558 pr_debug("%s: giving up on INIT, attempts:%d "
5559 "max_init_attempts:%d\n", __func__
, attempts
,
5560 asoc
->max_init_attempts
);
5562 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5563 SCTP_ERROR(ETIMEDOUT
));
5564 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5565 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5566 return SCTP_DISPOSITION_DELETE_TCB
;
5569 return SCTP_DISPOSITION_CONSUME
;
5573 * sctp_sf_t1_cookie_timer_expire
5575 * Section: 4 Note: 2
5580 * RFC 2960 Section 4 Notes
5581 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5582 * COOKIE ECHO and re-start the T1-cookie timer without changing
5583 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5584 * After that, the endpoint MUST abort the initialization process and
5585 * report the error to SCTP user.
5591 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(struct net
*net
,
5592 const struct sctp_endpoint
*ep
,
5593 const struct sctp_association
*asoc
,
5594 const sctp_subtype_t type
,
5596 sctp_cmd_seq_t
*commands
)
5598 struct sctp_chunk
*repl
= NULL
;
5599 int attempts
= asoc
->init_err_counter
+ 1;
5601 pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__
);
5603 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5605 if (attempts
<= asoc
->max_init_attempts
) {
5606 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5608 return SCTP_DISPOSITION_NOMEM
;
5610 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5612 /* Issue a sideeffect to do the needed accounting. */
5613 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5614 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5616 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5618 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5619 SCTP_ERROR(ETIMEDOUT
));
5620 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5621 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5622 return SCTP_DISPOSITION_DELETE_TCB
;
5625 return SCTP_DISPOSITION_CONSUME
;
5628 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5629 * with the updated last sequential TSN received from its peer.
5631 * An endpoint should limit the number of retransmissions of the
5632 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5633 * If this threshold is exceeded the endpoint should destroy the TCB and
5634 * MUST report the peer endpoint unreachable to the upper layer (and
5635 * thus the association enters the CLOSED state). The reception of any
5636 * packet from its peer (i.e. as the peer sends all of its queued DATA
5637 * chunks) should clear the endpoint's retransmission count and restart
5638 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5639 * all of its queued DATA chunks that have not yet been sent.
5641 sctp_disposition_t
sctp_sf_t2_timer_expire(struct net
*net
,
5642 const struct sctp_endpoint
*ep
,
5643 const struct sctp_association
*asoc
,
5644 const sctp_subtype_t type
,
5646 sctp_cmd_seq_t
*commands
)
5648 struct sctp_chunk
*reply
= NULL
;
5650 pr_debug("%s: timer T2 expired\n", __func__
);
5652 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5654 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5656 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5657 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5658 SCTP_ERROR(ETIMEDOUT
));
5659 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5660 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5661 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5662 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5663 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5664 return SCTP_DISPOSITION_DELETE_TCB
;
5667 switch (asoc
->state
) {
5668 case SCTP_STATE_SHUTDOWN_SENT
:
5669 reply
= sctp_make_shutdown(asoc
, NULL
);
5672 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5673 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5684 /* Do some failure management (Section 8.2).
5685 * If we remove the transport an SHUTDOWN was last sent to, don't
5686 * do failure management.
5688 if (asoc
->shutdown_last_sent_to
)
5689 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5690 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5692 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5693 * the T2-shutdown timer.
5695 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5697 /* Restart the T2-shutdown timer. */
5698 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5699 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5700 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5701 return SCTP_DISPOSITION_CONSUME
;
5704 return SCTP_DISPOSITION_NOMEM
;
5708 * ADDIP Section 4.1 ASCONF CHunk Procedures
5709 * If the T4 RTO timer expires the endpoint should do B1 to B5
5711 sctp_disposition_t
sctp_sf_t4_timer_expire(
5713 const struct sctp_endpoint
*ep
,
5714 const struct sctp_association
*asoc
,
5715 const sctp_subtype_t type
,
5717 sctp_cmd_seq_t
*commands
)
5719 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5720 struct sctp_transport
*transport
= chunk
->transport
;
5722 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5724 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5725 * detection on the appropriate destination address as defined in
5726 * RFC2960 [5] section 8.1 and 8.2.
5729 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5730 SCTP_TRANSPORT(transport
));
5732 /* Reconfig T4 timer and transport. */
5733 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5735 /* ADDIP 4.1 B2) Increment the association error counters and perform
5736 * endpoint failure detection on the association as defined in
5737 * RFC2960 [5] section 8.1 and 8.2.
5738 * association error counter is incremented in SCTP_CMD_STRIKE.
5740 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5741 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5742 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5743 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5744 SCTP_ERROR(ETIMEDOUT
));
5745 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5746 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5747 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5748 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5749 return SCTP_DISPOSITION_ABORT
;
5752 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5753 * the ASCONF chunk was sent by doubling the RTO timer value.
5754 * This is done in SCTP_CMD_STRIKE.
5757 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5758 * choose an alternate destination address (please refer to RFC2960
5759 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5760 * chunk, it MUST be the same (including its serial number) as the last
5763 sctp_chunk_hold(asoc
->addip_last_asconf
);
5764 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5765 SCTP_CHUNK(asoc
->addip_last_asconf
));
5767 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5768 * destination is selected, then the RTO used will be that of the new
5769 * destination address.
5771 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5772 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5774 return SCTP_DISPOSITION_CONSUME
;
5777 /* sctpimpguide-05 Section 2.12.2
5778 * The sender of the SHUTDOWN MAY also start an overall guard timer
5779 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5780 * At the expiration of this timer the sender SHOULD abort the association
5781 * by sending an ABORT chunk.
5783 sctp_disposition_t
sctp_sf_t5_timer_expire(struct net
*net
,
5784 const struct sctp_endpoint
*ep
,
5785 const struct sctp_association
*asoc
,
5786 const sctp_subtype_t type
,
5788 sctp_cmd_seq_t
*commands
)
5790 struct sctp_chunk
*reply
= NULL
;
5792 pr_debug("%s: timer T5 expired\n", __func__
);
5794 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5796 reply
= sctp_make_abort(asoc
, NULL
, 0);
5800 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5801 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5802 SCTP_ERROR(ETIMEDOUT
));
5803 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5804 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5806 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5807 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5809 return SCTP_DISPOSITION_DELETE_TCB
;
5811 return SCTP_DISPOSITION_NOMEM
;
5814 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5815 * the association is automatically closed by starting the shutdown process.
5816 * The work that needs to be done is same as when SHUTDOWN is initiated by
5817 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5819 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5821 const struct sctp_endpoint
*ep
,
5822 const struct sctp_association
*asoc
,
5823 const sctp_subtype_t type
,
5825 sctp_cmd_seq_t
*commands
)
5829 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5831 /* From 9.2 Shutdown of an Association
5832 * Upon receipt of the SHUTDOWN primitive from its upper
5833 * layer, the endpoint enters SHUTDOWN-PENDING state and
5834 * remains there until all outstanding data has been
5835 * acknowledged by its peer. The endpoint accepts no new data
5836 * from its upper layer, but retransmits data to the far end
5837 * if necessary to fill gaps.
5839 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5840 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5842 disposition
= SCTP_DISPOSITION_CONSUME
;
5843 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5844 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5850 /*****************************************************************************
5851 * These are sa state functions which could apply to all types of events.
5852 ****************************************************************************/
5855 * This table entry is not implemented.
5858 * (endpoint, asoc, chunk)
5860 * The return value is the disposition of the chunk.
5862 sctp_disposition_t
sctp_sf_not_impl(struct net
*net
,
5863 const struct sctp_endpoint
*ep
,
5864 const struct sctp_association
*asoc
,
5865 const sctp_subtype_t type
,
5867 sctp_cmd_seq_t
*commands
)
5869 return SCTP_DISPOSITION_NOT_IMPL
;
5873 * This table entry represents a bug.
5876 * (endpoint, asoc, chunk)
5878 * The return value is the disposition of the chunk.
5880 sctp_disposition_t
sctp_sf_bug(struct net
*net
,
5881 const struct sctp_endpoint
*ep
,
5882 const struct sctp_association
*asoc
,
5883 const sctp_subtype_t type
,
5885 sctp_cmd_seq_t
*commands
)
5887 return SCTP_DISPOSITION_BUG
;
5891 * This table entry represents the firing of a timer in the wrong state.
5892 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5893 * when the association is in the wrong state. This event should
5894 * be ignored, so as to prevent any rearming of the timer.
5897 * (endpoint, asoc, chunk)
5899 * The return value is the disposition of the chunk.
5901 sctp_disposition_t
sctp_sf_timer_ignore(struct net
*net
,
5902 const struct sctp_endpoint
*ep
,
5903 const struct sctp_association
*asoc
,
5904 const sctp_subtype_t type
,
5906 sctp_cmd_seq_t
*commands
)
5908 pr_debug("%s: timer %d ignored\n", __func__
, type
.chunk
);
5910 return SCTP_DISPOSITION_CONSUME
;
5913 /********************************************************************
5914 * 2nd Level Abstractions
5915 ********************************************************************/
5917 /* Pull the SACK chunk based on the SACK header. */
5918 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5920 struct sctp_sackhdr
*sack
;
5925 /* Protect ourselves from reading too far into
5926 * the skb from a bogus sender.
5928 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5930 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5931 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5932 len
= sizeof(struct sctp_sackhdr
);
5933 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5934 if (len
> chunk
->skb
->len
)
5937 skb_pull(chunk
->skb
, len
);
5942 /* Create an ABORT packet to be sent as a response, with the specified
5945 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
5946 const struct sctp_endpoint
*ep
,
5947 const struct sctp_association
*asoc
,
5948 struct sctp_chunk
*chunk
,
5949 const void *payload
,
5952 struct sctp_packet
*packet
;
5953 struct sctp_chunk
*abort
;
5955 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
5959 * The T bit will be set if the asoc is NULL.
5961 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5963 sctp_ootb_pkt_free(packet
);
5967 /* Reflect vtag if T-Bit is set */
5968 if (sctp_test_T_bit(abort
))
5969 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5971 /* Add specified error causes, i.e., payload, to the
5974 sctp_addto_chunk(abort
, paylen
, payload
);
5976 /* Set the skb to the belonging sock for accounting. */
5977 abort
->skb
->sk
= ep
->base
.sk
;
5979 sctp_packet_append_chunk(packet
, abort
);
5986 /* Allocate a packet for responding in the OOTB conditions. */
5987 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
5988 const struct sctp_association
*asoc
,
5989 const struct sctp_chunk
*chunk
)
5991 struct sctp_packet
*packet
;
5992 struct sctp_transport
*transport
;
5997 /* Get the source and destination port from the inbound packet. */
5998 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5999 dport
= ntohs(chunk
->sctp_hdr
->source
);
6001 /* The V-tag is going to be the same as the inbound packet if no
6002 * association exists, otherwise, use the peer's vtag.
6005 /* Special case the INIT-ACK as there is no peer's vtag
6008 switch(chunk
->chunk_hdr
->type
) {
6009 case SCTP_CID_INIT_ACK
:
6011 sctp_initack_chunk_t
*initack
;
6013 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
6014 vtag
= ntohl(initack
->init_hdr
.init_tag
);
6018 vtag
= asoc
->peer
.i
.init_tag
;
6022 /* Special case the INIT and stale COOKIE_ECHO as there is no
6025 switch(chunk
->chunk_hdr
->type
) {
6028 sctp_init_chunk_t
*init
;
6030 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
6031 vtag
= ntohl(init
->init_hdr
.init_tag
);
6035 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6040 /* Make a transport for the bucket, Eliza... */
6041 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6045 /* Cache a route for the transport with the chunk's destination as
6046 * the source address.
6048 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6049 sctp_sk(net
->sctp
.ctl_sock
));
6051 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
6052 packet
= sctp_packet_config(packet
, vtag
, 0);
6060 /* Free the packet allocated earlier for responding in the OOTB condition. */
6061 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6063 sctp_transport_free(packet
->transport
);
6066 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6067 static void sctp_send_stale_cookie_err(struct net
*net
,
6068 const struct sctp_endpoint
*ep
,
6069 const struct sctp_association
*asoc
,
6070 const struct sctp_chunk
*chunk
,
6071 sctp_cmd_seq_t
*commands
,
6072 struct sctp_chunk
*err_chunk
)
6074 struct sctp_packet
*packet
;
6077 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6079 struct sctp_signed_cookie
*cookie
;
6081 /* Override the OOTB vtag from the cookie. */
6082 cookie
= chunk
->subh
.cookie_hdr
;
6083 packet
->vtag
= cookie
->c
.peer_vtag
;
6085 /* Set the skb to the belonging sock for accounting. */
6086 err_chunk
->skb
->sk
= ep
->base
.sk
;
6087 sctp_packet_append_chunk(packet
, err_chunk
);
6088 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6089 SCTP_PACKET(packet
));
6090 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6092 sctp_chunk_free (err_chunk
);
6097 /* Process a data chunk */
6098 static int sctp_eat_data(const struct sctp_association
*asoc
,
6099 struct sctp_chunk
*chunk
,
6100 sctp_cmd_seq_t
*commands
)
6102 sctp_datahdr_t
*data_hdr
;
6103 struct sctp_chunk
*err
;
6105 sctp_verb_t deliver
;
6108 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6109 struct sock
*sk
= asoc
->base
.sk
;
6110 struct net
*net
= sock_net(sk
);
6115 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
6116 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
6118 tsn
= ntohl(data_hdr
->tsn
);
6119 pr_debug("%s: TSN 0x%x\n", __func__
, tsn
);
6121 /* ASSERT: Now skb->data is really the user data. */
6123 /* Process ECN based congestion.
6125 * Since the chunk structure is reused for all chunks within
6126 * a packet, we use ecn_ce_done to track if we've already
6127 * done CE processing for this packet.
6129 * We need to do ECN processing even if we plan to discard the
6133 if (!chunk
->ecn_ce_done
) {
6135 chunk
->ecn_ce_done
= 1;
6137 af
= sctp_get_af_specific(
6138 ipver2af(ip_hdr(chunk
->skb
)->version
));
6140 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
6141 /* Do real work as sideffect. */
6142 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6147 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6149 /* The TSN is too high--silently discard the chunk and
6150 * count on it getting retransmitted later.
6153 chunk
->asoc
->stats
.outofseqtsns
++;
6154 return SCTP_IERROR_HIGH_TSN
;
6155 } else if (tmp
> 0) {
6156 /* This is a duplicate. Record it. */
6157 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6158 return SCTP_IERROR_DUP_TSN
;
6161 /* This is a new TSN. */
6163 /* Discard if there is no room in the receive window.
6164 * Actually, allow a little bit of overflow (up to a MTU).
6166 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6167 datalen
-= sizeof(sctp_data_chunk_t
);
6169 deliver
= SCTP_CMD_CHUNK_ULP
;
6171 /* Think about partial delivery. */
6172 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6174 /* Even if we don't accept this chunk there is
6177 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6180 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6181 * seems a bit troublesome in that frag_point varies based on
6182 * PMTU. In cases, such as loopback, this might be a rather
6185 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6186 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6188 /* If this is the next TSN, consider reneging to make
6189 * room. Note: Playing nice with a confused sender. A
6190 * malicious sender can still eat up all our buffer
6191 * space and in the future we may want to detect and
6192 * do more drastic reneging.
6194 if (sctp_tsnmap_has_gap(map
) &&
6195 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6196 pr_debug("%s: reneging for tsn:%u\n", __func__
, tsn
);
6197 deliver
= SCTP_CMD_RENEGE
;
6199 pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
6200 __func__
, tsn
, datalen
, asoc
->rwnd
);
6202 return SCTP_IERROR_IGNORE_TSN
;
6207 * Also try to renege to limit our memory usage in the event that
6208 * we are under memory pressure
6209 * If we can't renege, don't worry about it, the sk_rmem_schedule
6210 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6211 * memory usage too much
6213 if (*sk
->sk_prot_creator
->memory_pressure
) {
6214 if (sctp_tsnmap_has_gap(map
) &&
6215 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6216 pr_debug("%s: under pressure, reneging for tsn:%u\n",
6218 deliver
= SCTP_CMD_RENEGE
;
6223 * Section 3.3.10.9 No User Data (9)
6227 * No User Data: This error cause is returned to the originator of a
6228 * DATA chunk if a received DATA chunk has no user data.
6230 if (unlikely(0 == datalen
)) {
6231 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6233 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6236 /* We are going to ABORT, so we might as well stop
6237 * processing the rest of the chunks in the packet.
6239 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
6240 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6241 SCTP_ERROR(ECONNABORTED
));
6242 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6243 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6244 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6245 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6246 return SCTP_IERROR_NO_DATA
;
6249 chunk
->data_accepted
= 1;
6251 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6252 * if we renege and the chunk arrives again.
6254 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
6255 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6257 chunk
->asoc
->stats
.iuodchunks
++;
6259 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6261 chunk
->asoc
->stats
.iodchunks
++;
6265 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6267 * If an endpoint receive a DATA chunk with an invalid stream
6268 * identifier, it shall acknowledge the reception of the DATA chunk
6269 * following the normal procedure, immediately send an ERROR chunk
6270 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6271 * and discard the DATA chunk.
6273 sid
= ntohs(data_hdr
->stream
);
6274 if (sid
>= asoc
->c
.sinit_max_instreams
) {
6275 /* Mark tsn as received even though we drop it */
6276 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6278 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6280 sizeof(data_hdr
->stream
),
6283 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6285 return SCTP_IERROR_BAD_STREAM
;
6288 /* Check to see if the SSN is possible for this TSN.
6289 * The biggest gap we can record is 4K wide. Since SSNs wrap
6290 * at an unsigned short, there is no way that an SSN can
6291 * wrap and for a valid TSN. We can simply check if the current
6292 * SSN is smaller then the next expected one. If it is, it wrapped
6295 ssn
= ntohs(data_hdr
->ssn
);
6296 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->ssnmap
->in
, sid
))) {
6297 return SCTP_IERROR_PROTO_VIOLATION
;
6300 /* Send the data up to the user. Note: Schedule the
6301 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6302 * chunk needs the updated rwnd.
6304 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6306 return SCTP_IERROR_NO_ERROR
;