1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2002 Intel Corp.
6 * Copyright (c) 2002 Nokia Corp.
8 * This is part of the SCTP Linux Kernel Implementation.
10 * These are the state functions for the state machine.
12 * This SCTP implementation is free software;
13 * you can redistribute it and/or modify it under the terms of
14 * the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * This SCTP implementation is distributed in the hope that it
19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20 * ************************
21 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 * See the GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with GNU CC; see the file COPYING. If not, write to
26 * the Free Software Foundation, 59 Temple Place - Suite 330,
27 * Boston, MA 02111-1307, USA.
29 * Please send any bug reports or fixes you make to the
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
36 * Written or modified by:
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Karl Knutson <karl@athena.chicago.il.us>
39 * Mathew Kotowsky <kotowsky@sctp.org>
40 * Sridhar Samudrala <samudrala@us.ibm.com>
41 * Jon Grimm <jgrimm@us.ibm.com>
42 * Hui Huang <hui.huang@nokia.com>
43 * Dajiang Zhang <dajiang.zhang@nokia.com>
44 * Daisy Chang <daisyc@us.ibm.com>
45 * Ardelle Fan <ardelle.fan@intel.com>
46 * Ryan Layer <rmlayer@us.ibm.com>
47 * Kevin Gao <kevin.gao@intel.com>
49 * Any bugs reported given to us we will try to fix... any fixes shared will
50 * be incorporated into the next SCTP release.
53 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55 #include <linux/types.h>
56 #include <linux/kernel.h>
58 #include <linux/ipv6.h>
59 #include <linux/net.h>
60 #include <linux/inet.h>
61 #include <linux/slab.h>
63 #include <net/inet_ecn.h>
64 #include <linux/skbuff.h>
65 #include <net/sctp/sctp.h>
66 #include <net/sctp/sm.h>
67 #include <net/sctp/structs.h>
69 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
70 const struct sctp_endpoint
*ep
,
71 const struct sctp_association
*asoc
,
72 struct sctp_chunk
*chunk
,
75 static int sctp_eat_data(const struct sctp_association
*asoc
,
76 struct sctp_chunk
*chunk
,
77 sctp_cmd_seq_t
*commands
);
78 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
79 const struct sctp_association
*asoc
,
80 const struct sctp_chunk
*chunk
);
81 static void sctp_send_stale_cookie_err(struct net
*net
,
82 const struct sctp_endpoint
*ep
,
83 const struct sctp_association
*asoc
,
84 const struct sctp_chunk
*chunk
,
85 sctp_cmd_seq_t
*commands
,
86 struct sctp_chunk
*err_chunk
);
87 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(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_shut_8_4_5(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 sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
100 const struct sctp_endpoint
*ep
,
101 const struct sctp_association
*asoc
,
102 const sctp_subtype_t type
,
104 sctp_cmd_seq_t
*commands
);
105 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
);
107 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
108 sctp_cmd_seq_t
*commands
,
109 __be16 error
, int sk_err
,
110 const struct sctp_association
*asoc
,
111 struct sctp_transport
*transport
);
113 static sctp_disposition_t
sctp_sf_abort_violation(
115 const struct sctp_endpoint
*ep
,
116 const struct sctp_association
*asoc
,
118 sctp_cmd_seq_t
*commands
,
120 const size_t paylen
);
122 static sctp_disposition_t
sctp_sf_violation_chunklen(
124 const struct sctp_endpoint
*ep
,
125 const struct sctp_association
*asoc
,
126 const sctp_subtype_t type
,
128 sctp_cmd_seq_t
*commands
);
130 static sctp_disposition_t
sctp_sf_violation_paramlen(
132 const struct sctp_endpoint
*ep
,
133 const struct sctp_association
*asoc
,
134 const sctp_subtype_t type
,
135 void *arg
, void *ext
,
136 sctp_cmd_seq_t
*commands
);
138 static sctp_disposition_t
sctp_sf_violation_ctsn(
140 const struct sctp_endpoint
*ep
,
141 const struct sctp_association
*asoc
,
142 const sctp_subtype_t type
,
144 sctp_cmd_seq_t
*commands
);
146 static sctp_disposition_t
sctp_sf_violation_chunk(
148 const struct sctp_endpoint
*ep
,
149 const struct sctp_association
*asoc
,
150 const sctp_subtype_t type
,
152 sctp_cmd_seq_t
*commands
);
154 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
155 const struct sctp_endpoint
*ep
,
156 const struct sctp_association
*asoc
,
157 const sctp_subtype_t type
,
158 struct sctp_chunk
*chunk
);
160 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
161 const struct sctp_endpoint
*ep
,
162 const struct sctp_association
*asoc
,
163 const sctp_subtype_t type
,
165 sctp_cmd_seq_t
*commands
);
167 /* Small helper function that checks if the chunk length
168 * is of the appropriate length. The 'required_length' argument
169 * is set to be the size of a specific chunk we are testing.
170 * Return Values: 1 = Valid length
175 sctp_chunk_length_valid(struct sctp_chunk
*chunk
,
176 __u16 required_length
)
178 __u16 chunk_length
= ntohs(chunk
->chunk_hdr
->length
);
180 if (unlikely(chunk_length
< required_length
))
186 /**********************************************************
187 * These are the state functions for handling chunk events.
188 **********************************************************/
191 * Process the final SHUTDOWN COMPLETE.
193 * Section: 4 (C) (diagram), 9.2
194 * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
195 * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
196 * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
197 * should stop the T2-shutdown timer and remove all knowledge of the
198 * association (and thus the association enters the CLOSED state).
200 * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
201 * C) Rules for packet carrying SHUTDOWN COMPLETE:
203 * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
204 * if the Verification Tag field of the packet matches its own tag and
205 * the T bit is not set
207 * it is set to its peer's tag and the T bit is set in the Chunk
209 * Otherwise, the receiver MUST silently discard the packet
210 * and take no further action. An endpoint MUST ignore the
211 * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
214 * (endpoint, asoc, chunk)
217 * (asoc, reply_msg, msg_up, timers, counters)
219 * The return value is the disposition of the chunk.
221 sctp_disposition_t
sctp_sf_do_4_C(struct net
*net
,
222 const struct sctp_endpoint
*ep
,
223 const struct sctp_association
*asoc
,
224 const sctp_subtype_t type
,
226 sctp_cmd_seq_t
*commands
)
228 struct sctp_chunk
*chunk
= arg
;
229 struct sctp_ulpevent
*ev
;
231 if (!sctp_vtag_verify_either(chunk
, asoc
))
232 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
234 /* RFC 2960 6.10 Bundling
236 * An endpoint MUST NOT bundle INIT, INIT ACK or
237 * SHUTDOWN COMPLETE with any other chunks.
239 if (!chunk
->singleton
)
240 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
242 /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
243 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
244 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
247 /* RFC 2960 10.2 SCTP-to-ULP
249 * H) SHUTDOWN COMPLETE notification
251 * When SCTP completes the shutdown procedures (section 9.2) this
252 * notification is passed to the upper layer.
254 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
255 0, 0, 0, NULL
, GFP_ATOMIC
);
257 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
260 /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
261 * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
262 * not the chunk should be discarded. If the endpoint is in
263 * the SHUTDOWN-ACK-SENT state the endpoint should stop the
264 * T2-shutdown timer and remove all knowledge of the
265 * association (and thus the association enters the CLOSED
268 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
269 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
271 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
272 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
274 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
275 SCTP_STATE(SCTP_STATE_CLOSED
));
277 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
278 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
280 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
282 return SCTP_DISPOSITION_DELETE_TCB
;
286 * Respond to a normal INIT chunk.
287 * We are the side that is being asked for an association.
289 * Section: 5.1 Normal Establishment of an Association, B
290 * B) "Z" shall respond immediately with an INIT ACK chunk. The
291 * destination IP address of the INIT ACK MUST be set to the source
292 * IP address of the INIT to which this INIT ACK is responding. In
293 * the response, besides filling in other parameters, "Z" must set the
294 * Verification Tag field to Tag_A, and also provide its own
295 * Verification Tag (Tag_Z) in the Initiate Tag field.
297 * Verification Tag: Must be 0.
300 * (endpoint, asoc, chunk)
303 * (asoc, reply_msg, msg_up, timers, counters)
305 * The return value is the disposition of the chunk.
307 sctp_disposition_t
sctp_sf_do_5_1B_init(struct net
*net
,
308 const struct sctp_endpoint
*ep
,
309 const struct sctp_association
*asoc
,
310 const sctp_subtype_t type
,
312 sctp_cmd_seq_t
*commands
)
314 struct sctp_chunk
*chunk
= arg
;
315 struct sctp_chunk
*repl
;
316 struct sctp_association
*new_asoc
;
317 struct sctp_chunk
*err_chunk
;
318 struct sctp_packet
*packet
;
319 sctp_unrecognized_param_t
*unk_param
;
323 * An endpoint MUST NOT bundle INIT, INIT ACK or
324 * SHUTDOWN COMPLETE with any other chunks.
327 * Furthermore, we require that the receiver of an INIT chunk MUST
328 * enforce these rules by silently discarding an arriving packet
329 * with an INIT chunk that is bundled with other chunks.
331 if (!chunk
->singleton
)
332 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
334 /* If the packet is an OOTB packet which is temporarily on the
335 * control endpoint, respond with an ABORT.
337 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
338 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
339 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
342 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
345 if (chunk
->sctp_hdr
->vtag
!= 0)
346 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
348 /* Make sure that the INIT chunk has a valid length.
349 * Normally, this would cause an ABORT with a Protocol Violation
350 * error, but since we don't have an association, we'll
351 * just discard the packet.
353 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
354 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
356 /* If the INIT is coming toward a closing socket, we'll send back
357 * and ABORT. Essentially, this catches the race of INIT being
358 * backloged to the socket at the same time as the user isses close().
359 * Since the socket and all its associations are going away, we
360 * can treat this OOTB
362 if (sctp_sstate(ep
->base
.sk
, CLOSING
))
363 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
365 /* Verify the INIT chunk before processing it. */
367 if (!sctp_verify_init(net
, asoc
, chunk
->chunk_hdr
->type
,
368 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
370 /* This chunk contains fatal error. It is to be discarded.
371 * Send an ABORT, with causes if there is any.
374 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
375 (__u8
*)(err_chunk
->chunk_hdr
) +
376 sizeof(sctp_chunkhdr_t
),
377 ntohs(err_chunk
->chunk_hdr
->length
) -
378 sizeof(sctp_chunkhdr_t
));
380 sctp_chunk_free(err_chunk
);
383 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
384 SCTP_PACKET(packet
));
385 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
386 return SCTP_DISPOSITION_CONSUME
;
388 return SCTP_DISPOSITION_NOMEM
;
391 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
396 /* Grab the INIT header. */
397 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*)chunk
->skb
->data
;
399 /* Tag the variable length parameters. */
400 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
402 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
406 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
407 sctp_scope(sctp_source(chunk
)),
411 /* The call, sctp_process_init(), can fail on memory allocation. */
412 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
413 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
417 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
419 /* If there are errors need to be reported for unknown parameters,
420 * make sure to reserve enough room in the INIT ACK for them.
424 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
425 sizeof(sctp_chunkhdr_t
);
427 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
431 /* If there are errors need to be reported for unknown parameters,
432 * include them in the outgoing INIT ACK as "Unrecognized parameter"
436 /* Get the "Unrecognized parameter" parameter(s) out of the
437 * ERROR chunk generated by sctp_verify_init(). Since the
438 * error cause code for "unknown parameter" and the
439 * "Unrecognized parameter" type is the same, we can
440 * construct the parameters in INIT ACK by copying the
443 unk_param
= (sctp_unrecognized_param_t
*)
444 ((__u8
*)(err_chunk
->chunk_hdr
) +
445 sizeof(sctp_chunkhdr_t
));
446 /* Replace the cause code with the "Unrecognized parameter"
449 sctp_addto_chunk(repl
, len
, unk_param
);
450 sctp_chunk_free(err_chunk
);
453 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
455 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
458 * Note: After sending out INIT ACK with the State Cookie parameter,
459 * "Z" MUST NOT allocate any resources, nor keep any states for the
460 * new association. Otherwise, "Z" will be vulnerable to resource
463 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
465 return SCTP_DISPOSITION_DELETE_TCB
;
468 sctp_association_free(new_asoc
);
471 sctp_chunk_free(err_chunk
);
472 return SCTP_DISPOSITION_NOMEM
;
476 * Respond to a normal INIT ACK chunk.
477 * We are the side that is initiating the association.
479 * Section: 5.1 Normal Establishment of an Association, C
480 * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
481 * timer and leave COOKIE-WAIT state. "A" shall then send the State
482 * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
483 * the T1-cookie timer, and enter the COOKIE-ECHOED state.
485 * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
486 * DATA chunks, but it MUST be the first chunk in the packet and
487 * until the COOKIE ACK is returned the sender MUST NOT send any
488 * other packets to the peer.
490 * Verification Tag: 3.3.3
491 * If the value of the Initiate Tag in a received INIT ACK chunk is
492 * found to be 0, the receiver MUST treat it as an error and close the
493 * association by transmitting an ABORT.
496 * (endpoint, asoc, chunk)
499 * (asoc, reply_msg, msg_up, timers, counters)
501 * The return value is the disposition of the chunk.
503 sctp_disposition_t
sctp_sf_do_5_1C_ack(struct net
*net
,
504 const struct sctp_endpoint
*ep
,
505 const struct sctp_association
*asoc
,
506 const sctp_subtype_t type
,
508 sctp_cmd_seq_t
*commands
)
510 struct sctp_chunk
*chunk
= arg
;
511 sctp_init_chunk_t
*initchunk
;
512 struct sctp_chunk
*err_chunk
;
513 struct sctp_packet
*packet
;
515 if (!sctp_vtag_verify(chunk
, asoc
))
516 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
519 * An endpoint MUST NOT bundle INIT, INIT ACK or
520 * SHUTDOWN COMPLETE with any other chunks.
522 if (!chunk
->singleton
)
523 return sctp_sf_violation_chunk(net
, ep
, asoc
, type
, arg
, commands
);
525 /* Make sure that the INIT-ACK chunk has a valid length */
526 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_initack_chunk_t
)))
527 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
529 /* Grab the INIT header. */
530 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
532 /* Verify the INIT chunk before processing it. */
534 if (!sctp_verify_init(net
, asoc
, chunk
->chunk_hdr
->type
,
535 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
538 sctp_error_t error
= SCTP_ERROR_NO_RESOURCE
;
540 /* This chunk contains fatal error. It is to be discarded.
541 * Send an ABORT, with causes. If there are no causes,
542 * then there wasn't enough memory. Just terminate
546 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
547 (__u8
*)(err_chunk
->chunk_hdr
) +
548 sizeof(sctp_chunkhdr_t
),
549 ntohs(err_chunk
->chunk_hdr
->length
) -
550 sizeof(sctp_chunkhdr_t
));
552 sctp_chunk_free(err_chunk
);
555 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
556 SCTP_PACKET(packet
));
557 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
558 error
= SCTP_ERROR_INV_PARAM
;
562 /* SCTP-AUTH, Section 6.3:
563 * It should be noted that if the receiver wants to tear
564 * down an association in an authenticated way only, the
565 * handling of malformed packets should not result in
566 * tearing down the association.
568 * This means that if we only want to abort associations
569 * in an authenticated way (i.e AUTH+ABORT), then we
570 * can't destroy this association just because the packet
573 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
574 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
576 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
577 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
,
578 asoc
, chunk
->transport
);
581 /* Tag the variable length parameters. Note that we never
582 * convert the parameters in an INIT chunk.
584 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
586 initchunk
= (sctp_init_chunk_t
*) chunk
->chunk_hdr
;
588 sctp_add_cmd_sf(commands
, SCTP_CMD_PEER_INIT
,
589 SCTP_PEER_INIT(initchunk
));
591 /* Reset init error count upon receipt of INIT-ACK. */
592 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
594 /* 5.1 C) "A" shall stop the T1-init timer and leave
595 * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
596 * timer, and enter the COOKIE-ECHOED state.
598 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
599 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
600 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
601 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
602 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
603 SCTP_STATE(SCTP_STATE_COOKIE_ECHOED
));
605 /* SCTP-AUTH: genereate the assocition shared keys so that
606 * we can potentially signe the COOKIE-ECHO.
608 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_SHKEY
, SCTP_NULL());
610 /* 5.1 C) "A" shall then send the State Cookie received in the
611 * INIT ACK chunk in a COOKIE ECHO chunk, ...
613 /* If there is any errors to report, send the ERROR chunk generated
614 * for unknown parameters as well.
616 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_COOKIE_ECHO
,
617 SCTP_CHUNK(err_chunk
));
619 return SCTP_DISPOSITION_CONSUME
;
623 * Respond to a normal COOKIE ECHO chunk.
624 * We are the side that is being asked for an association.
626 * Section: 5.1 Normal Establishment of an Association, D
627 * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
628 * with a COOKIE ACK chunk after building a TCB and moving to
629 * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
630 * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
631 * chunk MUST be the first chunk in the packet.
633 * IMPLEMENTATION NOTE: An implementation may choose to send the
634 * Communication Up notification to the SCTP user upon reception
635 * of a valid COOKIE ECHO chunk.
637 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
638 * D) Rules for packet carrying a COOKIE ECHO
640 * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
641 * Initial Tag received in the INIT ACK.
643 * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
646 * (endpoint, asoc, chunk)
649 * (asoc, reply_msg, msg_up, timers, counters)
651 * The return value is the disposition of the chunk.
653 sctp_disposition_t
sctp_sf_do_5_1D_ce(struct net
*net
,
654 const struct sctp_endpoint
*ep
,
655 const struct sctp_association
*asoc
,
656 const sctp_subtype_t type
, void *arg
,
657 sctp_cmd_seq_t
*commands
)
659 struct sctp_chunk
*chunk
= arg
;
660 struct sctp_association
*new_asoc
;
661 sctp_init_chunk_t
*peer_init
;
662 struct sctp_chunk
*repl
;
663 struct sctp_ulpevent
*ev
, *ai_ev
= NULL
;
665 struct sctp_chunk
*err_chk_p
;
668 /* If the packet is an OOTB packet which is temporarily on the
669 * control endpoint, respond with an ABORT.
671 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
) {
672 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
673 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
676 /* Make sure that the COOKIE_ECHO chunk has a valid length.
677 * In this case, we check that we have enough for at least a
678 * chunk header. More detailed verification is done
679 * in sctp_unpack_cookie().
681 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
682 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
684 /* If the endpoint is not listening or if the number of associations
685 * on the TCP-style socket exceed the max backlog, respond with an
689 if (!sctp_sstate(sk
, LISTENING
) ||
690 (sctp_style(sk
, TCP
) && sk_acceptq_is_full(sk
)))
691 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
693 /* "Decode" the chunk. We have no optional parameters so we
696 chunk
->subh
.cookie_hdr
=
697 (struct sctp_signed_cookie
*)chunk
->skb
->data
;
698 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
699 sizeof(sctp_chunkhdr_t
)))
702 /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
703 * "Z" will reply with a COOKIE ACK chunk after building a TCB
704 * and moving to the ESTABLISHED state.
706 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
710 * If the re-build failed, what is the proper error path
713 * [We should abort the association. --piggy]
716 /* FIXME: Several errors are possible. A bad cookie should
717 * be silently discarded, but think about logging it too.
720 case -SCTP_IERROR_NOMEM
:
723 case -SCTP_IERROR_STALE_COOKIE
:
724 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
726 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
728 case -SCTP_IERROR_BAD_SIG
:
730 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
735 /* Delay state machine commands until later.
737 * Re-build the bind address for the association is done in
738 * the sctp_unpack_cookie() already.
740 /* This is a brand-new association, so these are not yet side
741 * effects--it is safe to run them here.
743 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
745 if (!sctp_process_init(new_asoc
, chunk
,
746 &chunk
->subh
.cookie_hdr
->c
.peer_addr
,
747 peer_init
, GFP_ATOMIC
))
750 /* SCTP-AUTH: Now that we've populate required fields in
751 * sctp_process_init, set up the assocaition shared keys as
752 * necessary so that we can potentially authenticate the ACK
754 error
= sctp_auth_asoc_init_active_key(new_asoc
, GFP_ATOMIC
);
758 /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
759 * is supposed to be authenticated and we have to do delayed
760 * authentication. We've just recreated the association using
761 * the information in the cookie and now it's much easier to
762 * do the authentication.
764 if (chunk
->auth_chunk
) {
765 struct sctp_chunk auth
;
768 /* set-up our fake chunk so that we can process it */
769 auth
.skb
= chunk
->auth_chunk
;
770 auth
.asoc
= chunk
->asoc
;
771 auth
.sctp_hdr
= chunk
->sctp_hdr
;
772 auth
.chunk_hdr
= (sctp_chunkhdr_t
*)skb_push(chunk
->auth_chunk
,
773 sizeof(sctp_chunkhdr_t
));
774 skb_pull(chunk
->auth_chunk
, sizeof(sctp_chunkhdr_t
));
775 auth
.transport
= chunk
->transport
;
777 ret
= sctp_sf_authenticate(net
, ep
, new_asoc
, type
, &auth
);
779 /* We can now safely free the auth_chunk clone */
780 kfree_skb(chunk
->auth_chunk
);
782 if (ret
!= SCTP_IERROR_NO_ERROR
) {
783 sctp_association_free(new_asoc
);
784 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
788 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
792 /* RFC 2960 5.1 Normal Establishment of an Association
794 * D) IMPLEMENTATION NOTE: An implementation may choose to
795 * send the Communication Up notification to the SCTP user
796 * upon reception of a valid COOKIE ECHO chunk.
798 ev
= sctp_ulpevent_make_assoc_change(new_asoc
, 0, SCTP_COMM_UP
, 0,
799 new_asoc
->c
.sinit_num_ostreams
,
800 new_asoc
->c
.sinit_max_instreams
,
805 /* Sockets API Draft Section 5.3.1.6
806 * When a peer sends a Adaptation Layer Indication parameter , SCTP
807 * delivers this notification to inform the application that of the
808 * peers requested adaptation layer.
810 if (new_asoc
->peer
.adaptation_ind
) {
811 ai_ev
= sctp_ulpevent_make_adaptation_indication(new_asoc
,
817 /* Add all the state machine commands now since we've created
818 * everything. This way we don't introduce memory corruptions
819 * during side-effect processing and correclty count established
822 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
823 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
824 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
825 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
826 SCTP_INC_STATS(net
, SCTP_MIB_PASSIVEESTABS
);
827 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
829 if (new_asoc
->autoclose
)
830 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
831 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
833 /* This will send the COOKIE ACK */
834 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
836 /* Queue the ASSOC_CHANGE event */
837 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
839 /* Send up the Adaptation Layer Indication event */
841 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
842 SCTP_ULPEVENT(ai_ev
));
844 return SCTP_DISPOSITION_CONSUME
;
847 sctp_ulpevent_free(ev
);
849 sctp_chunk_free(repl
);
851 sctp_association_free(new_asoc
);
853 return SCTP_DISPOSITION_NOMEM
;
857 * Respond to a normal COOKIE ACK chunk.
858 * We are the side that is being asked for an association.
860 * RFC 2960 5.1 Normal Establishment of an Association
862 * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
863 * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
864 * timer. It may also notify its ULP about the successful
865 * establishment of the association with a Communication Up
866 * notification (see Section 10).
870 * (endpoint, asoc, chunk)
873 * (asoc, reply_msg, msg_up, timers, counters)
875 * The return value is the disposition of the chunk.
877 sctp_disposition_t
sctp_sf_do_5_1E_ca(struct net
*net
,
878 const struct sctp_endpoint
*ep
,
879 const struct sctp_association
*asoc
,
880 const sctp_subtype_t type
, void *arg
,
881 sctp_cmd_seq_t
*commands
)
883 struct sctp_chunk
*chunk
= arg
;
884 struct sctp_ulpevent
*ev
;
886 if (!sctp_vtag_verify(chunk
, asoc
))
887 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
889 /* Verify that the chunk length for the COOKIE-ACK is OK.
890 * If we don't do this, any bundled chunks may be junked.
892 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
893 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
896 /* Reset init error count upon receipt of COOKIE-ACK,
897 * to avoid problems with the managemement of this
898 * counter in stale cookie situations when a transition back
899 * from the COOKIE-ECHOED state to the COOKIE-WAIT
900 * state is performed.
902 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_RESET
, SCTP_NULL());
904 /* RFC 2960 5.1 Normal Establishment of an Association
906 * E) Upon reception of the COOKIE ACK, endpoint "A" will move
907 * from the COOKIE-ECHOED state to the ESTABLISHED state,
908 * stopping the T1-cookie timer.
910 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
911 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
912 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
913 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
914 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
915 SCTP_INC_STATS(net
, SCTP_MIB_ACTIVEESTABS
);
916 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
918 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
919 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
921 /* It may also notify its ULP about the successful
922 * establishment of the association with a Communication Up
923 * notification (see Section 10).
925 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_COMM_UP
,
926 0, asoc
->c
.sinit_num_ostreams
,
927 asoc
->c
.sinit_max_instreams
,
933 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
935 /* Sockets API Draft Section 5.3.1.6
936 * When a peer sends a Adaptation Layer Indication parameter , SCTP
937 * delivers this notification to inform the application that of the
938 * peers requested adaptation layer.
940 if (asoc
->peer
.adaptation_ind
) {
941 ev
= sctp_ulpevent_make_adaptation_indication(asoc
, GFP_ATOMIC
);
945 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
949 return SCTP_DISPOSITION_CONSUME
;
951 return SCTP_DISPOSITION_NOMEM
;
954 /* Generate and sendout a heartbeat packet. */
955 static sctp_disposition_t
sctp_sf_heartbeat(const struct sctp_endpoint
*ep
,
956 const struct sctp_association
*asoc
,
957 const sctp_subtype_t type
,
959 sctp_cmd_seq_t
*commands
)
961 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
962 struct sctp_chunk
*reply
;
964 /* Send a heartbeat to our peer. */
965 reply
= sctp_make_heartbeat(asoc
, transport
);
967 return SCTP_DISPOSITION_NOMEM
;
969 /* Set rto_pending indicating that an RTT measurement
970 * is started with this heartbeat chunk.
972 sctp_add_cmd_sf(commands
, SCTP_CMD_RTO_PENDING
,
973 SCTP_TRANSPORT(transport
));
975 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
976 return SCTP_DISPOSITION_CONSUME
;
979 /* Generate a HEARTBEAT packet on the given transport. */
980 sctp_disposition_t
sctp_sf_sendbeat_8_3(struct net
*net
,
981 const struct sctp_endpoint
*ep
,
982 const struct sctp_association
*asoc
,
983 const sctp_subtype_t type
,
985 sctp_cmd_seq_t
*commands
)
987 struct sctp_transport
*transport
= (struct sctp_transport
*) arg
;
989 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
990 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
991 SCTP_ERROR(ETIMEDOUT
));
992 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
993 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
994 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
995 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
996 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
997 return SCTP_DISPOSITION_DELETE_TCB
;
1001 * The Sender-specific Heartbeat Info field should normally include
1002 * information about the sender's current time when this HEARTBEAT
1003 * chunk is sent and the destination transport address to which this
1004 * HEARTBEAT is sent (see Section 8.3).
1007 if (transport
->param_flags
& SPP_HB_ENABLE
) {
1008 if (SCTP_DISPOSITION_NOMEM
==
1009 sctp_sf_heartbeat(ep
, asoc
, type
, arg
,
1011 return SCTP_DISPOSITION_NOMEM
;
1013 /* Set transport error counter and association error counter
1014 * when sending heartbeat.
1016 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
1017 SCTP_TRANSPORT(transport
));
1019 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_IDLE
,
1020 SCTP_TRANSPORT(transport
));
1021 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMER_UPDATE
,
1022 SCTP_TRANSPORT(transport
));
1024 return SCTP_DISPOSITION_CONSUME
;
1028 * Process an heartbeat request.
1030 * Section: 8.3 Path Heartbeat
1031 * The receiver of the HEARTBEAT should immediately respond with a
1032 * HEARTBEAT ACK that contains the Heartbeat Information field copied
1033 * from the received HEARTBEAT chunk.
1035 * Verification Tag: 8.5 Verification Tag [Normal verification]
1036 * When receiving an SCTP packet, the endpoint MUST ensure that the
1037 * value in the Verification Tag field of the received SCTP packet
1038 * matches its own Tag. If the received Verification Tag value does not
1039 * match the receiver's own tag value, the receiver shall silently
1040 * discard the packet and shall not process it any further except for
1041 * those cases listed in Section 8.5.1 below.
1044 * (endpoint, asoc, chunk)
1047 * (asoc, reply_msg, msg_up, timers, counters)
1049 * The return value is the disposition of the chunk.
1051 sctp_disposition_t
sctp_sf_beat_8_3(struct net
*net
,
1052 const struct sctp_endpoint
*ep
,
1053 const struct sctp_association
*asoc
,
1054 const sctp_subtype_t type
,
1056 sctp_cmd_seq_t
*commands
)
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 paylen
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_chunkhdr_t
);
1076 if (!pskb_pull(chunk
->skb
, paylen
))
1079 reply
= sctp_make_heartbeat_ack(asoc
, chunk
,
1080 chunk
->subh
.hb_hdr
, paylen
);
1084 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
1085 return SCTP_DISPOSITION_CONSUME
;
1088 return SCTP_DISPOSITION_NOMEM
;
1092 * Process the returning HEARTBEAT ACK.
1094 * Section: 8.3 Path Heartbeat
1095 * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
1096 * should clear the error counter of the destination transport
1097 * address to which the HEARTBEAT was sent, and mark the destination
1098 * transport address as active if it is not so marked. The endpoint may
1099 * optionally report to the upper layer when an inactive destination
1100 * address is marked as active due to the reception of the latest
1101 * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
1102 * clear the association overall error count as well (as defined
1105 * The receiver of the HEARTBEAT ACK should also perform an RTT
1106 * measurement for that destination transport address using the time
1107 * value carried in the HEARTBEAT ACK chunk.
1109 * Verification Tag: 8.5 Verification Tag [Normal verification]
1112 * (endpoint, asoc, chunk)
1115 * (asoc, reply_msg, msg_up, timers, counters)
1117 * The return value is the disposition of the chunk.
1119 sctp_disposition_t
sctp_sf_backbeat_8_3(struct net
*net
,
1120 const struct sctp_endpoint
*ep
,
1121 const struct sctp_association
*asoc
,
1122 const sctp_subtype_t type
,
1124 sctp_cmd_seq_t
*commands
)
1126 struct sctp_chunk
*chunk
= arg
;
1127 union sctp_addr from_addr
;
1128 struct sctp_transport
*link
;
1129 sctp_sender_hb_info_t
*hbinfo
;
1130 unsigned long max_interval
;
1132 if (!sctp_vtag_verify(chunk
, asoc
))
1133 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1135 /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
1136 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
) +
1137 sizeof(sctp_sender_hb_info_t
)))
1138 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1141 hbinfo
= (sctp_sender_hb_info_t
*) chunk
->skb
->data
;
1142 /* Make sure that the length of the parameter is what we expect */
1143 if (ntohs(hbinfo
->param_hdr
.length
) !=
1144 sizeof(sctp_sender_hb_info_t
)) {
1145 return SCTP_DISPOSITION_DISCARD
;
1148 from_addr
= hbinfo
->daddr
;
1149 link
= sctp_assoc_lookup_paddr(asoc
, &from_addr
);
1151 /* This should never happen, but lets log it if so. */
1152 if (unlikely(!link
)) {
1153 if (from_addr
.sa
.sa_family
== AF_INET6
) {
1154 net_warn_ratelimited("%s association %p could not find address %pI6\n",
1157 &from_addr
.v6
.sin6_addr
);
1159 net_warn_ratelimited("%s association %p could not find address %pI4\n",
1162 &from_addr
.v4
.sin_addr
.s_addr
);
1164 return SCTP_DISPOSITION_DISCARD
;
1167 /* Validate the 64-bit random nonce. */
1168 if (hbinfo
->hb_nonce
!= link
->hb_nonce
)
1169 return SCTP_DISPOSITION_DISCARD
;
1171 max_interval
= link
->hbinterval
+ link
->rto
;
1173 /* Check if the timestamp looks valid. */
1174 if (time_after(hbinfo
->sent_at
, jiffies
) ||
1175 time_after(jiffies
, hbinfo
->sent_at
+ max_interval
)) {
1176 SCTP_DEBUG_PRINTK("%s: HEARTBEAT ACK with invalid timestamp "
1177 "received for transport: %p\n",
1179 return SCTP_DISPOSITION_DISCARD
;
1182 /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
1183 * the HEARTBEAT should clear the error counter of the
1184 * destination transport address to which the HEARTBEAT was
1185 * sent and mark the destination transport address as active if
1186 * it is not so marked.
1188 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_ON
, SCTP_TRANSPORT(link
));
1190 return SCTP_DISPOSITION_CONSUME
;
1193 /* Helper function to send out an abort for the restart
1196 static int sctp_sf_send_restart_abort(struct net
*net
, union sctp_addr
*ssa
,
1197 struct sctp_chunk
*init
,
1198 sctp_cmd_seq_t
*commands
)
1201 struct sctp_packet
*pkt
;
1202 union sctp_addr_param
*addrparm
;
1203 struct sctp_errhdr
*errhdr
;
1204 struct sctp_endpoint
*ep
;
1205 char buffer
[sizeof(struct sctp_errhdr
)+sizeof(union sctp_addr_param
)];
1206 struct sctp_af
*af
= sctp_get_af_specific(ssa
->v4
.sin_family
);
1208 /* Build the error on the stack. We are way to malloc crazy
1209 * throughout the code today.
1211 errhdr
= (struct sctp_errhdr
*)buffer
;
1212 addrparm
= (union sctp_addr_param
*)errhdr
->variable
;
1214 /* Copy into a parm format. */
1215 len
= af
->to_addr_param(ssa
, addrparm
);
1216 len
+= sizeof(sctp_errhdr_t
);
1218 errhdr
->cause
= SCTP_ERROR_RESTART
;
1219 errhdr
->length
= htons(len
);
1221 /* Assign to the control socket. */
1222 ep
= sctp_sk(net
->sctp
.ctl_sock
)->ep
;
1224 /* Association is NULL since this may be a restart attack and we
1225 * want to send back the attacker's vtag.
1227 pkt
= sctp_abort_pkt_new(net
, ep
, NULL
, init
, errhdr
, len
);
1231 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
, SCTP_PACKET(pkt
));
1233 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1235 /* Discard the rest of the inbound packet. */
1236 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
1239 /* Even if there is no memory, treat as a failure so
1240 * the packet will get dropped.
1245 static bool list_has_sctp_addr(const struct list_head
*list
,
1246 union sctp_addr
*ipaddr
)
1248 struct sctp_transport
*addr
;
1250 list_for_each_entry(addr
, list
, transports
) {
1251 if (sctp_cmp_addr_exact(ipaddr
, &addr
->ipaddr
))
1257 /* A restart is occurring, check to make sure no new addresses
1258 * are being added as we may be under a takeover attack.
1260 static int sctp_sf_check_restart_addrs(const struct sctp_association
*new_asoc
,
1261 const struct sctp_association
*asoc
,
1262 struct sctp_chunk
*init
,
1263 sctp_cmd_seq_t
*commands
)
1265 struct net
*net
= sock_net(new_asoc
->base
.sk
);
1266 struct sctp_transport
*new_addr
;
1269 /* Implementor's Guide - Section 5.2.2
1271 * Before responding the endpoint MUST check to see if the
1272 * unexpected INIT adds new addresses to the association. If new
1273 * addresses are added to the association, the endpoint MUST respond
1277 /* Search through all current addresses and make sure
1278 * we aren't adding any new ones.
1280 list_for_each_entry(new_addr
, &new_asoc
->peer
.transport_addr_list
,
1282 if (!list_has_sctp_addr(&asoc
->peer
.transport_addr_list
,
1283 &new_addr
->ipaddr
)) {
1284 sctp_sf_send_restart_abort(net
, &new_addr
->ipaddr
, init
,
1291 /* Return success if all addresses were found. */
1295 /* Populate the verification/tie tags based on overlapping INIT
1298 * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
1300 static void sctp_tietags_populate(struct sctp_association
*new_asoc
,
1301 const struct sctp_association
*asoc
)
1303 switch (asoc
->state
) {
1305 /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
1307 case SCTP_STATE_COOKIE_WAIT
:
1308 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1309 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1310 new_asoc
->c
.peer_ttag
= 0;
1313 case SCTP_STATE_COOKIE_ECHOED
:
1314 new_asoc
->c
.my_vtag
= asoc
->c
.my_vtag
;
1315 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1316 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1319 /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
1320 * COOKIE-WAIT and SHUTDOWN-ACK-SENT
1323 new_asoc
->c
.my_ttag
= asoc
->c
.my_vtag
;
1324 new_asoc
->c
.peer_ttag
= asoc
->c
.peer_vtag
;
1328 /* Other parameters for the endpoint SHOULD be copied from the
1329 * existing parameters of the association (e.g. number of
1330 * outbound streams) into the INIT ACK and cookie.
1332 new_asoc
->rwnd
= asoc
->rwnd
;
1333 new_asoc
->c
.sinit_num_ostreams
= asoc
->c
.sinit_num_ostreams
;
1334 new_asoc
->c
.sinit_max_instreams
= asoc
->c
.sinit_max_instreams
;
1335 new_asoc
->c
.initial_tsn
= asoc
->c
.initial_tsn
;
1339 * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
1342 * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
1344 * Returns value representing action to be taken. These action values
1345 * correspond to Action/Description values in RFC 2960, Table 2.
1347 static char sctp_tietags_compare(struct sctp_association
*new_asoc
,
1348 const struct sctp_association
*asoc
)
1350 /* In this case, the peer may have restarted. */
1351 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1352 (asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) &&
1353 (asoc
->c
.my_vtag
== new_asoc
->c
.my_ttag
) &&
1354 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_ttag
))
1357 /* Collision case B. */
1358 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1359 ((asoc
->c
.peer_vtag
!= new_asoc
->c
.peer_vtag
) ||
1360 (0 == asoc
->c
.peer_vtag
))) {
1364 /* Collision case D. */
1365 if ((asoc
->c
.my_vtag
== new_asoc
->c
.my_vtag
) &&
1366 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
))
1369 /* Collision case C. */
1370 if ((asoc
->c
.my_vtag
!= new_asoc
->c
.my_vtag
) &&
1371 (asoc
->c
.peer_vtag
== new_asoc
->c
.peer_vtag
) &&
1372 (0 == new_asoc
->c
.my_ttag
) &&
1373 (0 == new_asoc
->c
.peer_ttag
))
1376 /* No match to any of the special cases; discard this packet. */
1380 /* Common helper routine for both duplicate and simulataneous INIT
1383 static sctp_disposition_t
sctp_sf_do_unexpected_init(
1385 const struct sctp_endpoint
*ep
,
1386 const struct sctp_association
*asoc
,
1387 const sctp_subtype_t type
,
1388 void *arg
, sctp_cmd_seq_t
*commands
)
1390 sctp_disposition_t retval
;
1391 struct sctp_chunk
*chunk
= arg
;
1392 struct sctp_chunk
*repl
;
1393 struct sctp_association
*new_asoc
;
1394 struct sctp_chunk
*err_chunk
;
1395 struct sctp_packet
*packet
;
1396 sctp_unrecognized_param_t
*unk_param
;
1400 * An endpoint MUST NOT bundle INIT, INIT ACK or
1401 * SHUTDOWN COMPLETE with any other chunks.
1404 * Furthermore, we require that the receiver of an INIT chunk MUST
1405 * enforce these rules by silently discarding an arriving packet
1406 * with an INIT chunk that is bundled with other chunks.
1408 if (!chunk
->singleton
)
1409 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
1411 /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
1414 if (chunk
->sctp_hdr
->vtag
!= 0)
1415 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
1417 /* Make sure that the INIT chunk has a valid length.
1418 * In this case, we generate a protocol violation since we have
1419 * an association established.
1421 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_init_chunk_t
)))
1422 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
1424 /* Grab the INIT header. */
1425 chunk
->subh
.init_hdr
= (sctp_inithdr_t
*) chunk
->skb
->data
;
1427 /* Tag the variable length parameters. */
1428 chunk
->param_hdr
.v
= skb_pull(chunk
->skb
, sizeof(sctp_inithdr_t
));
1430 /* Verify the INIT chunk before processing it. */
1432 if (!sctp_verify_init(net
, asoc
, chunk
->chunk_hdr
->type
,
1433 (sctp_init_chunk_t
*)chunk
->chunk_hdr
, chunk
,
1435 /* This chunk contains fatal error. It is to be discarded.
1436 * Send an ABORT, with causes if there is any.
1439 packet
= sctp_abort_pkt_new(net
, ep
, asoc
, arg
,
1440 (__u8
*)(err_chunk
->chunk_hdr
) +
1441 sizeof(sctp_chunkhdr_t
),
1442 ntohs(err_chunk
->chunk_hdr
->length
) -
1443 sizeof(sctp_chunkhdr_t
));
1446 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
1447 SCTP_PACKET(packet
));
1448 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
1449 retval
= SCTP_DISPOSITION_CONSUME
;
1451 retval
= SCTP_DISPOSITION_NOMEM
;
1455 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
,
1461 * Other parameters for the endpoint SHOULD be copied from the
1462 * existing parameters of the association (e.g. number of
1463 * outbound streams) into the INIT ACK and cookie.
1464 * FIXME: We are copying parameters from the endpoint not the
1467 new_asoc
= sctp_make_temp_asoc(ep
, chunk
, GFP_ATOMIC
);
1471 if (sctp_assoc_set_bind_addr_from_ep(new_asoc
,
1472 sctp_scope(sctp_source(chunk
)), GFP_ATOMIC
) < 0)
1475 /* In the outbound INIT ACK the endpoint MUST copy its current
1476 * Verification Tag and Peers Verification tag into a reserved
1477 * place (local tie-tag and per tie-tag) within the state cookie.
1479 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
),
1480 (sctp_init_chunk_t
*)chunk
->chunk_hdr
,
1484 /* Make sure no new addresses are being added during the
1485 * restart. Do not do this check for COOKIE-WAIT state,
1486 * since there are no peer addresses to check against.
1487 * Upon return an ABORT will have been sent if needed.
1489 if (!sctp_state(asoc
, COOKIE_WAIT
)) {
1490 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
,
1492 retval
= SCTP_DISPOSITION_CONSUME
;
1497 sctp_tietags_populate(new_asoc
, asoc
);
1499 /* B) "Z" shall respond immediately with an INIT ACK chunk. */
1501 /* If there are errors need to be reported for unknown parameters,
1502 * make sure to reserve enough room in the INIT ACK for them.
1506 len
= ntohs(err_chunk
->chunk_hdr
->length
) -
1507 sizeof(sctp_chunkhdr_t
);
1510 repl
= sctp_make_init_ack(new_asoc
, chunk
, GFP_ATOMIC
, len
);
1514 /* If there are errors need to be reported for unknown parameters,
1515 * include them in the outgoing INIT ACK as "Unrecognized parameter"
1519 /* Get the "Unrecognized parameter" parameter(s) out of the
1520 * ERROR chunk generated by sctp_verify_init(). Since the
1521 * error cause code for "unknown parameter" and the
1522 * "Unrecognized parameter" type is the same, we can
1523 * construct the parameters in INIT ACK by copying the
1524 * ERROR causes over.
1526 unk_param
= (sctp_unrecognized_param_t
*)
1527 ((__u8
*)(err_chunk
->chunk_hdr
) +
1528 sizeof(sctp_chunkhdr_t
));
1529 /* Replace the cause code with the "Unrecognized parameter"
1532 sctp_addto_chunk(repl
, len
, unk_param
);
1535 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
1536 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1539 * Note: After sending out INIT ACK with the State Cookie parameter,
1540 * "Z" MUST NOT allocate any resources for this new association.
1541 * Otherwise, "Z" will be vulnerable to resource attacks.
1543 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
1544 retval
= SCTP_DISPOSITION_CONSUME
;
1549 retval
= SCTP_DISPOSITION_NOMEM
;
1552 sctp_association_free(new_asoc
);
1555 sctp_chunk_free(err_chunk
);
1560 * Handle simultaneous INIT.
1561 * This means we started an INIT and then we got an INIT request from
1564 * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
1565 * This usually indicates an initialization collision, i.e., each
1566 * endpoint is attempting, at about the same time, to establish an
1567 * association with the other endpoint.
1569 * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
1570 * endpoint MUST respond with an INIT ACK using the same parameters it
1571 * sent in its original INIT chunk (including its Verification Tag,
1572 * unchanged). These original parameters are combined with those from the
1573 * newly received INIT chunk. The endpoint shall also generate a State
1574 * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
1575 * INIT to calculate the State Cookie.
1577 * After that, the endpoint MUST NOT change its state, the T1-init
1578 * timer shall be left running and the corresponding TCB MUST NOT be
1579 * destroyed. The normal procedures for handling State Cookies when
1580 * a TCB exists will resolve the duplicate INITs to a single association.
1582 * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
1583 * its Tie-Tags with the Tag information of itself and its peer (see
1584 * section 5.2.2 for a description of the Tie-Tags).
1586 * Verification Tag: Not explicit, but an INIT can not have a valid
1587 * verification tag, so we skip the check.
1590 * (endpoint, asoc, chunk)
1593 * (asoc, reply_msg, msg_up, timers, counters)
1595 * The return value is the disposition of the chunk.
1597 sctp_disposition_t
sctp_sf_do_5_2_1_siminit(struct net
*net
,
1598 const struct sctp_endpoint
*ep
,
1599 const struct sctp_association
*asoc
,
1600 const sctp_subtype_t type
,
1602 sctp_cmd_seq_t
*commands
)
1604 /* Call helper to do the real work for both simulataneous and
1605 * duplicate INIT chunk handling.
1607 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1611 * Handle duplicated INIT messages. These are usually delayed
1614 * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
1615 * COOKIE-ECHOED and COOKIE-WAIT
1617 * Unless otherwise stated, upon reception of an unexpected INIT for
1618 * this association, the endpoint shall generate an INIT ACK with a
1619 * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
1620 * current Verification Tag and peer's Verification Tag into a reserved
1621 * place within the state cookie. We shall refer to these locations as
1622 * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
1623 * containing this INIT ACK MUST carry a Verification Tag value equal to
1624 * the Initiation Tag found in the unexpected INIT. And the INIT ACK
1625 * MUST contain a new Initiation Tag (randomly generated see Section
1626 * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
1627 * existing parameters of the association (e.g. number of outbound
1628 * streams) into the INIT ACK and cookie.
1630 * After sending out the INIT ACK, the endpoint shall take no further
1631 * actions, i.e., the existing association, including its current state,
1632 * and the corresponding TCB MUST NOT be changed.
1634 * Note: Only when a TCB exists and the association is not in a COOKIE-
1635 * WAIT state are the Tie-Tags populated. For a normal association INIT
1636 * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
1637 * set to 0 (indicating that no previous TCB existed). The INIT ACK and
1638 * State Cookie are populated as specified in section 5.2.1.
1640 * Verification Tag: Not specified, but an INIT has no way of knowing
1641 * what the verification tag could be, so we ignore it.
1644 * (endpoint, asoc, chunk)
1647 * (asoc, reply_msg, msg_up, timers, counters)
1649 * The return value is the disposition of the chunk.
1651 sctp_disposition_t
sctp_sf_do_5_2_2_dupinit(struct net
*net
,
1652 const struct sctp_endpoint
*ep
,
1653 const struct sctp_association
*asoc
,
1654 const sctp_subtype_t type
,
1656 sctp_cmd_seq_t
*commands
)
1658 /* Call helper to do the real work for both simulataneous and
1659 * duplicate INIT chunk handling.
1661 return sctp_sf_do_unexpected_init(net
, ep
, asoc
, type
, arg
, commands
);
1666 * Unexpected INIT-ACK handler.
1669 * If an INIT ACK received by an endpoint in any state other than the
1670 * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
1671 * An unexpected INIT ACK usually indicates the processing of an old or
1672 * duplicated INIT chunk.
1674 sctp_disposition_t
sctp_sf_do_5_2_3_initack(struct net
*net
,
1675 const struct sctp_endpoint
*ep
,
1676 const struct sctp_association
*asoc
,
1677 const sctp_subtype_t type
,
1678 void *arg
, sctp_cmd_seq_t
*commands
)
1680 /* Per the above section, we'll discard the chunk if we have an
1681 * endpoint. If this is an OOTB INIT-ACK, treat it as such.
1683 if (ep
== sctp_sk(net
->sctp
.ctl_sock
)->ep
)
1684 return sctp_sf_ootb(net
, ep
, asoc
, type
, arg
, commands
);
1686 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
1689 /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
1692 * A) In this case, the peer may have restarted.
1694 static sctp_disposition_t
sctp_sf_do_dupcook_a(struct net
*net
,
1695 const struct sctp_endpoint
*ep
,
1696 const struct sctp_association
*asoc
,
1697 struct sctp_chunk
*chunk
,
1698 sctp_cmd_seq_t
*commands
,
1699 struct sctp_association
*new_asoc
)
1701 sctp_init_chunk_t
*peer_init
;
1702 struct sctp_ulpevent
*ev
;
1703 struct sctp_chunk
*repl
;
1704 struct sctp_chunk
*err
;
1705 sctp_disposition_t disposition
;
1707 /* new_asoc is a brand-new association, so these are not yet
1708 * side effects--it is safe to run them here.
1710 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1712 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1716 /* Make sure no new addresses are being added during the
1717 * restart. Though this is a pretty complicated attack
1718 * since you'd have to get inside the cookie.
1720 if (!sctp_sf_check_restart_addrs(new_asoc
, asoc
, chunk
, commands
)) {
1721 return SCTP_DISPOSITION_CONSUME
;
1724 /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
1725 * the peer has restarted (Action A), it MUST NOT setup a new
1726 * association but instead resend the SHUTDOWN ACK and send an ERROR
1727 * chunk with a "Cookie Received while Shutting Down" error cause to
1730 if (sctp_state(asoc
, SHUTDOWN_ACK_SENT
)) {
1731 disposition
= sctp_sf_do_9_2_reshutack(net
, ep
, asoc
,
1732 SCTP_ST_CHUNK(chunk
->chunk_hdr
->type
),
1734 if (SCTP_DISPOSITION_NOMEM
== disposition
)
1737 err
= sctp_make_op_error(asoc
, chunk
,
1738 SCTP_ERROR_COOKIE_IN_SHUTDOWN
,
1741 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
1744 return SCTP_DISPOSITION_CONSUME
;
1747 /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
1748 * data. Consider the optional choice of resending of this data.
1750 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
1751 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1752 SCTP_TO(SCTP_EVENT_TIMEOUT_SACK
));
1753 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_OUTQUEUE
, SCTP_NULL());
1755 /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
1756 * and ASCONF-ACK cache.
1758 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1759 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
1760 sctp_add_cmd_sf(commands
, SCTP_CMD_PURGE_ASCONF_QUEUE
, SCTP_NULL());
1762 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1766 /* Report association restart to upper layer. */
1767 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_RESTART
, 0,
1768 new_asoc
->c
.sinit_num_ostreams
,
1769 new_asoc
->c
.sinit_max_instreams
,
1774 /* Update the content of current association. */
1775 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1776 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1777 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
1778 return SCTP_DISPOSITION_CONSUME
;
1781 sctp_chunk_free(repl
);
1783 return SCTP_DISPOSITION_NOMEM
;
1786 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
1789 * B) In this case, both sides may be attempting to start an association
1790 * at about the same time but the peer endpoint started its INIT
1791 * after responding to the local endpoint's INIT
1793 /* This case represents an initialization collision. */
1794 static sctp_disposition_t
sctp_sf_do_dupcook_b(struct net
*net
,
1795 const struct sctp_endpoint
*ep
,
1796 const struct sctp_association
*asoc
,
1797 struct sctp_chunk
*chunk
,
1798 sctp_cmd_seq_t
*commands
,
1799 struct sctp_association
*new_asoc
)
1801 sctp_init_chunk_t
*peer_init
;
1802 struct sctp_chunk
*repl
;
1804 /* new_asoc is a brand-new association, so these are not yet
1805 * side effects--it is safe to run them here.
1807 peer_init
= &chunk
->subh
.cookie_hdr
->c
.peer_init
[0];
1808 if (!sctp_process_init(new_asoc
, chunk
, sctp_source(chunk
), peer_init
,
1812 /* Update the content of current association. */
1813 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_ASSOC
, SCTP_ASOC(new_asoc
));
1814 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1815 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1816 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1817 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
, SCTP_NULL());
1819 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1823 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1825 /* RFC 2960 5.1 Normal Establishment of an Association
1827 * D) IMPLEMENTATION NOTE: An implementation may choose to
1828 * send the Communication Up notification to the SCTP user
1829 * upon reception of a valid COOKIE ECHO chunk.
1831 * Sadly, this needs to be implemented as a side-effect, because
1832 * we are not guaranteed to have set the association id of the real
1833 * association and so these notifications need to be delayed until
1834 * the association id is allocated.
1837 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_CHANGE
, SCTP_U8(SCTP_COMM_UP
));
1839 /* Sockets API Draft Section 5.3.1.6
1840 * When a peer sends a Adaptation Layer Indication parameter , SCTP
1841 * delivers this notification to inform the application that of the
1842 * peers requested adaptation layer.
1844 * This also needs to be done as a side effect for the same reason as
1847 if (asoc
->peer
.adaptation_ind
)
1848 sctp_add_cmd_sf(commands
, SCTP_CMD_ADAPTATION_IND
, SCTP_NULL());
1850 return SCTP_DISPOSITION_CONSUME
;
1853 return SCTP_DISPOSITION_NOMEM
;
1856 /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
1859 * C) In this case, the local endpoint's cookie has arrived late.
1860 * Before it arrived, the local endpoint sent an INIT and received an
1861 * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
1862 * but a new tag of its own.
1864 /* This case represents an initialization collision. */
1865 static sctp_disposition_t
sctp_sf_do_dupcook_c(struct net
*net
,
1866 const struct sctp_endpoint
*ep
,
1867 const struct sctp_association
*asoc
,
1868 struct sctp_chunk
*chunk
,
1869 sctp_cmd_seq_t
*commands
,
1870 struct sctp_association
*new_asoc
)
1872 /* The cookie should be silently discarded.
1873 * The endpoint SHOULD NOT change states and should leave
1874 * any timers running.
1876 return SCTP_DISPOSITION_DISCARD
;
1879 /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
1883 * D) When both local and remote tags match the endpoint should always
1884 * enter the ESTABLISHED state, if it has not already done so.
1886 /* This case represents an initialization collision. */
1887 static sctp_disposition_t
sctp_sf_do_dupcook_d(struct net
*net
,
1888 const struct sctp_endpoint
*ep
,
1889 const struct sctp_association
*asoc
,
1890 struct sctp_chunk
*chunk
,
1891 sctp_cmd_seq_t
*commands
,
1892 struct sctp_association
*new_asoc
)
1894 struct sctp_ulpevent
*ev
= NULL
, *ai_ev
= NULL
;
1895 struct sctp_chunk
*repl
;
1897 /* Clarification from Implementor's Guide:
1898 * D) When both local and remote tags match the endpoint should
1899 * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
1900 * It should stop any cookie timer that may be running and send
1904 /* Don't accidentally move back into established state. */
1905 if (asoc
->state
< SCTP_STATE_ESTABLISHED
) {
1906 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
1907 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
1908 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
1909 SCTP_STATE(SCTP_STATE_ESTABLISHED
));
1910 SCTP_INC_STATS(net
, SCTP_MIB_CURRESTAB
);
1911 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_START
,
1914 /* RFC 2960 5.1 Normal Establishment of an Association
1916 * D) IMPLEMENTATION NOTE: An implementation may choose
1917 * to send the Communication Up notification to the
1918 * SCTP user upon reception of a valid COOKIE
1921 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0,
1923 asoc
->c
.sinit_num_ostreams
,
1924 asoc
->c
.sinit_max_instreams
,
1929 /* Sockets API Draft Section 5.3.1.6
1930 * When a peer sends a Adaptation Layer Indication parameter,
1931 * SCTP delivers this notification to inform the application
1932 * that of the peers requested adaptation layer.
1934 if (asoc
->peer
.adaptation_ind
) {
1935 ai_ev
= sctp_ulpevent_make_adaptation_indication(asoc
,
1943 repl
= sctp_make_cookie_ack(new_asoc
, chunk
);
1947 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
1950 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1953 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
1954 SCTP_ULPEVENT(ai_ev
));
1956 return SCTP_DISPOSITION_CONSUME
;
1960 sctp_ulpevent_free(ai_ev
);
1962 sctp_ulpevent_free(ev
);
1963 return SCTP_DISPOSITION_NOMEM
;
1967 * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
1968 * chunk was retransmitted and then delayed in the network.
1970 * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
1972 * Verification Tag: None. Do cookie validation.
1975 * (endpoint, asoc, chunk)
1978 * (asoc, reply_msg, msg_up, timers, counters)
1980 * The return value is the disposition of the chunk.
1982 sctp_disposition_t
sctp_sf_do_5_2_4_dupcook(struct net
*net
,
1983 const struct sctp_endpoint
*ep
,
1984 const struct sctp_association
*asoc
,
1985 const sctp_subtype_t type
,
1987 sctp_cmd_seq_t
*commands
)
1989 sctp_disposition_t retval
;
1990 struct sctp_chunk
*chunk
= arg
;
1991 struct sctp_association
*new_asoc
;
1994 struct sctp_chunk
*err_chk_p
;
1996 /* Make sure that the chunk has a valid length from the protocol
1997 * perspective. In this case check to make sure we have at least
1998 * enough for the chunk header. Cookie length verification is
2001 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2002 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2005 /* "Decode" the chunk. We have no optional parameters so we
2006 * are in good shape.
2008 chunk
->subh
.cookie_hdr
= (struct sctp_signed_cookie
*)chunk
->skb
->data
;
2009 if (!pskb_pull(chunk
->skb
, ntohs(chunk
->chunk_hdr
->length
) -
2010 sizeof(sctp_chunkhdr_t
)))
2013 /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
2014 * of a duplicate COOKIE ECHO match the Verification Tags of the
2015 * current association, consider the State Cookie valid even if
2016 * the lifespan is exceeded.
2018 new_asoc
= sctp_unpack_cookie(ep
, asoc
, chunk
, GFP_ATOMIC
, &error
,
2022 * If the re-build failed, what is the proper error path
2025 * [We should abort the association. --piggy]
2028 /* FIXME: Several errors are possible. A bad cookie should
2029 * be silently discarded, but think about logging it too.
2032 case -SCTP_IERROR_NOMEM
:
2035 case -SCTP_IERROR_STALE_COOKIE
:
2036 sctp_send_stale_cookie_err(net
, ep
, asoc
, chunk
, commands
,
2038 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2039 case -SCTP_IERROR_BAD_SIG
:
2041 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2045 /* Compare the tie_tag in cookie with the verification tag of
2046 * current association.
2048 action
= sctp_tietags_compare(new_asoc
, asoc
);
2051 case 'A': /* Association restart. */
2052 retval
= sctp_sf_do_dupcook_a(net
, ep
, asoc
, chunk
, commands
,
2056 case 'B': /* Collision case B. */
2057 retval
= sctp_sf_do_dupcook_b(net
, ep
, asoc
, chunk
, commands
,
2061 case 'C': /* Collision case C. */
2062 retval
= sctp_sf_do_dupcook_c(net
, ep
, asoc
, chunk
, commands
,
2066 case 'D': /* Collision case D. */
2067 retval
= sctp_sf_do_dupcook_d(net
, ep
, asoc
, chunk
, commands
,
2071 default: /* Discard packet for all others. */
2072 retval
= sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2076 /* Delete the tempory new association. */
2077 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(new_asoc
));
2078 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
2080 /* Restore association pointer to provide SCTP command interpeter
2081 * with a valid context in case it needs to manipulate
2083 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_ASOC
,
2084 SCTP_ASOC((struct sctp_association
*)asoc
));
2089 return SCTP_DISPOSITION_NOMEM
;
2093 * Process an ABORT. (SHUTDOWN-PENDING state)
2095 * See sctp_sf_do_9_1_abort().
2097 sctp_disposition_t
sctp_sf_shutdown_pending_abort(
2099 const struct sctp_endpoint
*ep
,
2100 const struct sctp_association
*asoc
,
2101 const sctp_subtype_t type
,
2103 sctp_cmd_seq_t
*commands
)
2105 struct sctp_chunk
*chunk
= arg
;
2107 if (!sctp_vtag_verify_either(chunk
, asoc
))
2108 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2110 /* Make sure that the ABORT chunk has a valid length.
2111 * Since this is an ABORT chunk, we have to discard it
2112 * because of the following text:
2113 * RFC 2960, Section 3.3.7
2114 * If an endpoint receives an ABORT with a format error or for an
2115 * association that doesn't exist, it MUST silently discard it.
2116 * Because the length is "invalid", we can't really discard just
2117 * as we do not know its true length. So, to be safe, discard the
2120 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2121 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2123 /* ADD-IP: Special case for ABORT chunks
2124 * F4) One special consideration is that ABORT Chunks arriving
2125 * destined to the IP address being deleted MUST be
2126 * ignored (see Section 5.3.1 for further details).
2128 if (SCTP_ADDR_DEL
==
2129 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2130 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2132 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2136 * Process an ABORT. (SHUTDOWN-SENT state)
2138 * See sctp_sf_do_9_1_abort().
2140 sctp_disposition_t
sctp_sf_shutdown_sent_abort(struct net
*net
,
2141 const struct sctp_endpoint
*ep
,
2142 const struct sctp_association
*asoc
,
2143 const sctp_subtype_t type
,
2145 sctp_cmd_seq_t
*commands
)
2147 struct sctp_chunk
*chunk
= arg
;
2149 if (!sctp_vtag_verify_either(chunk
, asoc
))
2150 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2152 /* Make sure that the ABORT chunk has a valid length.
2153 * Since this is an ABORT chunk, we have to discard it
2154 * because of the following text:
2155 * RFC 2960, Section 3.3.7
2156 * If an endpoint receives an ABORT with a format error or for an
2157 * association that doesn't exist, it MUST silently discard it.
2158 * Because the length is "invalid", we can't really discard just
2159 * as we do not know its true length. So, to be safe, discard the
2162 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2163 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2165 /* ADD-IP: Special case for ABORT chunks
2166 * F4) One special consideration is that ABORT Chunks arriving
2167 * destined to the IP address being deleted MUST be
2168 * ignored (see Section 5.3.1 for further details).
2170 if (SCTP_ADDR_DEL
==
2171 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2172 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2174 /* Stop the T2-shutdown timer. */
2175 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2176 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2178 /* Stop the T5-shutdown guard timer. */
2179 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2180 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
2182 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2186 * Process an ABORT. (SHUTDOWN-ACK-SENT state)
2188 * See sctp_sf_do_9_1_abort().
2190 sctp_disposition_t
sctp_sf_shutdown_ack_sent_abort(
2192 const struct sctp_endpoint
*ep
,
2193 const struct sctp_association
*asoc
,
2194 const sctp_subtype_t type
,
2196 sctp_cmd_seq_t
*commands
)
2198 /* The same T2 timer, so we should be able to use
2199 * common function with the SHUTDOWN-SENT state.
2201 return sctp_sf_shutdown_sent_abort(net
, ep
, asoc
, type
, arg
, commands
);
2205 * Handle an Error received in COOKIE_ECHOED state.
2207 * Only handle the error type of stale COOKIE Error, the other errors will
2211 * (endpoint, asoc, chunk)
2214 * (asoc, reply_msg, msg_up, timers, counters)
2216 * The return value is the disposition of the chunk.
2218 sctp_disposition_t
sctp_sf_cookie_echoed_err(struct net
*net
,
2219 const struct sctp_endpoint
*ep
,
2220 const struct sctp_association
*asoc
,
2221 const sctp_subtype_t type
,
2223 sctp_cmd_seq_t
*commands
)
2225 struct sctp_chunk
*chunk
= arg
;
2228 if (!sctp_vtag_verify(chunk
, asoc
))
2229 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2231 /* Make sure that the ERROR chunk has a valid length.
2232 * The parameter walking depends on this as well.
2234 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
2235 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2238 /* Process the error here */
2239 /* FUTURE FIXME: When PR-SCTP related and other optional
2240 * parms are emitted, this will have to change to handle multiple
2243 sctp_walk_errors(err
, chunk
->chunk_hdr
) {
2244 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
)
2245 return sctp_sf_do_5_2_6_stale(net
, ep
, asoc
, type
,
2249 /* It is possible to have malformed error causes, and that
2250 * will cause us to end the walk early. However, since
2251 * we are discarding the packet, there should be no adverse
2254 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2258 * Handle a Stale COOKIE Error
2260 * Section: 5.2.6 Handle Stale COOKIE Error
2261 * If the association is in the COOKIE-ECHOED state, the endpoint may elect
2262 * one of the following three alternatives.
2264 * 3) Send a new INIT chunk to the endpoint, adding a Cookie
2265 * Preservative parameter requesting an extension to the lifetime of
2266 * the State Cookie. When calculating the time extension, an
2267 * implementation SHOULD use the RTT information measured based on the
2268 * previous COOKIE ECHO / ERROR exchange, and should add no more
2269 * than 1 second beyond the measured RTT, due to long State Cookie
2270 * lifetimes making the endpoint more subject to a replay attack.
2272 * Verification Tag: Not explicit, but safe to ignore.
2275 * (endpoint, asoc, chunk)
2278 * (asoc, reply_msg, msg_up, timers, counters)
2280 * The return value is the disposition of the chunk.
2282 static sctp_disposition_t
sctp_sf_do_5_2_6_stale(struct net
*net
,
2283 const struct sctp_endpoint
*ep
,
2284 const struct sctp_association
*asoc
,
2285 const sctp_subtype_t type
,
2287 sctp_cmd_seq_t
*commands
)
2289 struct sctp_chunk
*chunk
= arg
;
2291 sctp_cookie_preserve_param_t bht
;
2293 struct sctp_chunk
*reply
;
2294 struct sctp_bind_addr
*bp
;
2295 int attempts
= asoc
->init_err_counter
+ 1;
2297 if (attempts
> asoc
->max_init_attempts
) {
2298 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
2299 SCTP_ERROR(ETIMEDOUT
));
2300 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2301 SCTP_PERR(SCTP_ERROR_STALE_COOKIE
));
2302 return SCTP_DISPOSITION_DELETE_TCB
;
2305 err
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
2307 /* When calculating the time extension, an implementation
2308 * SHOULD use the RTT information measured based on the
2309 * previous COOKIE ECHO / ERROR exchange, and should add no
2310 * more than 1 second beyond the measured RTT, due to long
2311 * State Cookie lifetimes making the endpoint more subject to
2313 * Measure of Staleness's unit is usec. (1/1000000 sec)
2314 * Suggested Cookie Life-span Increment's unit is msec.
2316 * In general, if you use the suggested cookie life, the value
2317 * found in the field of measure of staleness should be doubled
2318 * to give ample time to retransmit the new cookie and thus
2319 * yield a higher probability of success on the reattempt.
2321 stale
= ntohl(*(__be32
*)((u8
*)err
+ sizeof(sctp_errhdr_t
)));
2322 stale
= (stale
* 2) / 1000;
2324 bht
.param_hdr
.type
= SCTP_PARAM_COOKIE_PRESERVATIVE
;
2325 bht
.param_hdr
.length
= htons(sizeof(bht
));
2326 bht
.lifespan_increment
= htonl(stale
);
2328 /* Build that new INIT chunk. */
2329 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
2330 reply
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, sizeof(bht
));
2334 sctp_addto_chunk(reply
, sizeof(bht
), &bht
);
2336 /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
2337 sctp_add_cmd_sf(commands
, SCTP_CMD_CLEAR_INIT_TAG
, SCTP_NULL());
2339 /* Stop pending T3-rtx and heartbeat timers */
2340 sctp_add_cmd_sf(commands
, SCTP_CMD_T3_RTX_TIMERS_STOP
, SCTP_NULL());
2341 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
2343 /* Delete non-primary peer ip addresses since we are transitioning
2344 * back to the COOKIE-WAIT state
2346 sctp_add_cmd_sf(commands
, SCTP_CMD_DEL_NON_PRIMARY
, SCTP_NULL());
2348 /* If we've sent any data bundled with COOKIE-ECHO we will need to
2351 sctp_add_cmd_sf(commands
, SCTP_CMD_T1_RETRAN
,
2352 SCTP_TRANSPORT(asoc
->peer
.primary_path
));
2354 /* Cast away the const modifier, as we want to just
2355 * rerun it through as a sideffect.
2357 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_COUNTER_INC
, SCTP_NULL());
2359 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2360 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
2361 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2362 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
2363 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
2364 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2366 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2368 return SCTP_DISPOSITION_CONSUME
;
2371 return SCTP_DISPOSITION_NOMEM
;
2378 * After checking the Verification Tag, the receiving endpoint shall
2379 * remove the association from its record, and shall report the
2380 * termination to its upper layer.
2382 * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
2383 * B) Rules for packet carrying ABORT:
2385 * - The endpoint shall always fill in the Verification Tag field of the
2386 * outbound packet with the destination endpoint's tag value if it
2389 * - If the ABORT is sent in response to an OOTB packet, the endpoint
2390 * MUST follow the procedure described in Section 8.4.
2392 * - The receiver MUST accept the packet if the Verification Tag
2393 * matches either its own tag, OR the tag of its peer. Otherwise, the
2394 * receiver MUST silently discard the packet and take no further
2398 * (endpoint, asoc, chunk)
2401 * (asoc, reply_msg, msg_up, timers, counters)
2403 * The return value is the disposition of the chunk.
2405 sctp_disposition_t
sctp_sf_do_9_1_abort(struct net
*net
,
2406 const struct sctp_endpoint
*ep
,
2407 const struct sctp_association
*asoc
,
2408 const sctp_subtype_t type
,
2410 sctp_cmd_seq_t
*commands
)
2412 struct sctp_chunk
*chunk
= arg
;
2414 if (!sctp_vtag_verify_either(chunk
, asoc
))
2415 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2417 /* Make sure that the ABORT chunk has a valid length.
2418 * Since this is an ABORT chunk, we have to discard it
2419 * because of the following text:
2420 * RFC 2960, Section 3.3.7
2421 * If an endpoint receives an ABORT with a format error or for an
2422 * association that doesn't exist, it MUST silently discard it.
2423 * Because the length is "invalid", we can't really discard just
2424 * as we do not know its true length. So, to be safe, discard the
2427 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2428 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2430 /* ADD-IP: Special case for ABORT chunks
2431 * F4) One special consideration is that ABORT Chunks arriving
2432 * destined to the IP address being deleted MUST be
2433 * ignored (see Section 5.3.1 for further details).
2435 if (SCTP_ADDR_DEL
==
2436 sctp_bind_addr_state(&asoc
->base
.bind_addr
, &chunk
->dest
))
2437 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
2439 return __sctp_sf_do_9_1_abort(net
, ep
, asoc
, type
, arg
, commands
);
2442 static sctp_disposition_t
__sctp_sf_do_9_1_abort(struct net
*net
,
2443 const struct sctp_endpoint
*ep
,
2444 const struct sctp_association
*asoc
,
2445 const sctp_subtype_t type
,
2447 sctp_cmd_seq_t
*commands
)
2449 struct sctp_chunk
*chunk
= arg
;
2451 __be16 error
= SCTP_ERROR_NO_ERROR
;
2453 /* See if we have an error cause code in the chunk. */
2454 len
= ntohs(chunk
->chunk_hdr
->length
);
2455 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
)) {
2458 sctp_walk_errors(err
, chunk
->chunk_hdr
);
2459 if ((void *)err
!= (void *)chunk
->chunk_end
)
2460 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2462 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2465 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(ECONNRESET
));
2466 /* ASSOC_FAILED will DELETE_TCB. */
2467 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
, SCTP_PERR(error
));
2468 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2469 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
2471 return SCTP_DISPOSITION_ABORT
;
2475 * Process an ABORT. (COOKIE-WAIT state)
2477 * See sctp_sf_do_9_1_abort() above.
2479 sctp_disposition_t
sctp_sf_cookie_wait_abort(struct net
*net
,
2480 const struct sctp_endpoint
*ep
,
2481 const struct sctp_association
*asoc
,
2482 const sctp_subtype_t type
,
2484 sctp_cmd_seq_t
*commands
)
2486 struct sctp_chunk
*chunk
= arg
;
2488 __be16 error
= SCTP_ERROR_NO_ERROR
;
2490 if (!sctp_vtag_verify_either(chunk
, asoc
))
2491 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2493 /* Make sure that the ABORT chunk has a valid length.
2494 * Since this is an ABORT chunk, we have to discard it
2495 * because of the following text:
2496 * RFC 2960, Section 3.3.7
2497 * If an endpoint receives an ABORT with a format error or for an
2498 * association that doesn't exist, it MUST silently discard it.
2499 * Because the length is "invalid", we can't really discard just
2500 * as we do not know its true length. So, to be safe, discard the
2503 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_abort_chunk_t
)))
2504 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2506 /* See if we have an error cause code in the chunk. */
2507 len
= ntohs(chunk
->chunk_hdr
->length
);
2508 if (len
>= sizeof(struct sctp_chunkhdr
) + sizeof(struct sctp_errhdr
))
2509 error
= ((sctp_errhdr_t
*)chunk
->skb
->data
)->cause
;
2511 return sctp_stop_t1_and_abort(net
, commands
, error
, ECONNREFUSED
, asoc
,
2516 * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
2518 sctp_disposition_t
sctp_sf_cookie_wait_icmp_abort(struct net
*net
,
2519 const struct sctp_endpoint
*ep
,
2520 const struct sctp_association
*asoc
,
2521 const sctp_subtype_t type
,
2523 sctp_cmd_seq_t
*commands
)
2525 return sctp_stop_t1_and_abort(net
, commands
, SCTP_ERROR_NO_ERROR
,
2527 (struct sctp_transport
*)arg
);
2531 * Process an ABORT. (COOKIE-ECHOED state)
2533 sctp_disposition_t
sctp_sf_cookie_echoed_abort(struct net
*net
,
2534 const struct sctp_endpoint
*ep
,
2535 const struct sctp_association
*asoc
,
2536 const sctp_subtype_t type
,
2538 sctp_cmd_seq_t
*commands
)
2540 /* There is a single T1 timer, so we should be able to use
2541 * common function with the COOKIE-WAIT state.
2543 return sctp_sf_cookie_wait_abort(net
, ep
, asoc
, type
, arg
, commands
);
2547 * Stop T1 timer and abort association with "INIT failed".
2549 * This is common code called by several sctp_sf_*_abort() functions above.
2551 static sctp_disposition_t
sctp_stop_t1_and_abort(struct net
*net
,
2552 sctp_cmd_seq_t
*commands
,
2553 __be16 error
, int sk_err
,
2554 const struct sctp_association
*asoc
,
2555 struct sctp_transport
*transport
)
2557 SCTP_DEBUG_PRINTK("ABORT received (INIT).\n");
2558 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2559 SCTP_STATE(SCTP_STATE_CLOSED
));
2560 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
2561 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
2562 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
2563 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
, SCTP_ERROR(sk_err
));
2564 /* CMD_INIT_FAILED will DELETE_TCB. */
2565 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
2567 return SCTP_DISPOSITION_ABORT
;
2571 * sctp_sf_do_9_2_shut
2574 * Upon the reception of the SHUTDOWN, the peer endpoint shall
2575 * - enter the SHUTDOWN-RECEIVED state,
2577 * - stop accepting new data from its SCTP user
2579 * - verify, by checking the Cumulative TSN Ack field of the chunk,
2580 * that all its outstanding DATA chunks have been received by the
2583 * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
2584 * send a SHUTDOWN in response to a ULP request. And should discard
2585 * subsequent SHUTDOWN chunks.
2587 * If there are still outstanding DATA chunks left, the SHUTDOWN
2588 * receiver shall continue to follow normal data transmission
2589 * procedures defined in Section 6 until all outstanding DATA chunks
2590 * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
2591 * new data from its SCTP user.
2593 * Verification Tag: 8.5 Verification Tag [Normal verification]
2596 * (endpoint, asoc, chunk)
2599 * (asoc, reply_msg, msg_up, timers, counters)
2601 * The return value is the disposition of the chunk.
2603 sctp_disposition_t
sctp_sf_do_9_2_shutdown(struct net
*net
,
2604 const struct sctp_endpoint
*ep
,
2605 const struct sctp_association
*asoc
,
2606 const sctp_subtype_t type
,
2608 sctp_cmd_seq_t
*commands
)
2610 struct sctp_chunk
*chunk
= arg
;
2611 sctp_shutdownhdr_t
*sdh
;
2612 sctp_disposition_t disposition
;
2613 struct sctp_ulpevent
*ev
;
2616 if (!sctp_vtag_verify(chunk
, asoc
))
2617 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2619 /* Make sure that the SHUTDOWN chunk has a valid length. */
2620 if (!sctp_chunk_length_valid(chunk
,
2621 sizeof(struct sctp_shutdown_chunk_t
)))
2622 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2625 /* Convert the elaborate header. */
2626 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2627 skb_pull(chunk
->skb
, sizeof(sctp_shutdownhdr_t
));
2628 chunk
->subh
.shutdown_hdr
= sdh
;
2629 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2631 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2632 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2633 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2634 return SCTP_DISPOSITION_DISCARD
;
2637 /* If Cumulative TSN Ack beyond the max tsn currently
2638 * send, terminating the association and respond to the
2639 * sender with an ABORT.
2641 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2642 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2644 /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
2645 * When a peer sends a SHUTDOWN, SCTP delivers this notification to
2646 * inform the application that it should cease sending data.
2648 ev
= sctp_ulpevent_make_shutdown_event(asoc
, 0, GFP_ATOMIC
);
2650 disposition
= SCTP_DISPOSITION_NOMEM
;
2653 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
2655 /* Upon the reception of the SHUTDOWN, the peer endpoint shall
2656 * - enter the SHUTDOWN-RECEIVED state,
2657 * - stop accepting new data from its SCTP user
2659 * [This is implicit in the new state.]
2661 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
2662 SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED
));
2663 disposition
= SCTP_DISPOSITION_CONSUME
;
2665 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
2666 disposition
= sctp_sf_do_9_2_shutdown_ack(net
, ep
, asoc
, type
,
2670 if (SCTP_DISPOSITION_NOMEM
== disposition
)
2673 /* - verify, by checking the Cumulative TSN Ack field of the
2674 * chunk, that all its outstanding DATA chunks have been
2675 * received by the SHUTDOWN sender.
2677 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2678 SCTP_BE32(chunk
->subh
.shutdown_hdr
->cum_tsn_ack
));
2685 * sctp_sf_do_9_2_shut_ctsn
2687 * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
2688 * it MUST NOT send a SHUTDOWN in response to a ULP request.
2689 * The Cumulative TSN Ack of the received SHUTDOWN chunk
2690 * MUST be processed.
2692 sctp_disposition_t
sctp_sf_do_9_2_shut_ctsn(struct net
*net
,
2693 const struct sctp_endpoint
*ep
,
2694 const struct sctp_association
*asoc
,
2695 const sctp_subtype_t type
,
2697 sctp_cmd_seq_t
*commands
)
2699 struct sctp_chunk
*chunk
= arg
;
2700 sctp_shutdownhdr_t
*sdh
;
2703 if (!sctp_vtag_verify(chunk
, asoc
))
2704 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2706 /* Make sure that the SHUTDOWN chunk has a valid length. */
2707 if (!sctp_chunk_length_valid(chunk
,
2708 sizeof(struct sctp_shutdown_chunk_t
)))
2709 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2712 sdh
= (sctp_shutdownhdr_t
*)chunk
->skb
->data
;
2713 ctsn
= ntohl(sdh
->cum_tsn_ack
);
2715 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
2716 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
2717 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
2718 return SCTP_DISPOSITION_DISCARD
;
2721 /* If Cumulative TSN Ack beyond the max tsn currently
2722 * send, terminating the association and respond to the
2723 * sender with an ABORT.
2725 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
2726 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
2728 /* verify, by checking the Cumulative TSN Ack field of the
2729 * chunk, that all its outstanding DATA chunks have been
2730 * received by the SHUTDOWN sender.
2732 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_CTSN
,
2733 SCTP_BE32(sdh
->cum_tsn_ack
));
2735 return SCTP_DISPOSITION_CONSUME
;
2739 * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
2740 * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
2741 * transport addresses (either in the IP addresses or in the INIT chunk)
2742 * that belong to this association, it should discard the INIT chunk and
2743 * retransmit the SHUTDOWN ACK chunk.
2745 sctp_disposition_t
sctp_sf_do_9_2_reshutack(struct net
*net
,
2746 const struct sctp_endpoint
*ep
,
2747 const struct sctp_association
*asoc
,
2748 const sctp_subtype_t type
,
2750 sctp_cmd_seq_t
*commands
)
2752 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
2753 struct sctp_chunk
*reply
;
2755 /* Make sure that the chunk has a valid length */
2756 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
2757 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2760 /* Since we are not going to really process this INIT, there
2761 * is no point in verifying chunk boundries. Just generate
2764 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
2768 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
2769 * the T2-SHUTDOWN timer.
2771 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
2773 /* and restart the T2-shutdown timer. */
2774 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2775 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
2777 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
2779 return SCTP_DISPOSITION_CONSUME
;
2781 return SCTP_DISPOSITION_NOMEM
;
2785 * sctp_sf_do_ecn_cwr
2787 * Section: Appendix A: Explicit Congestion Notification
2791 * RFC 2481 details a specific bit for a sender to send in the header of
2792 * its next outbound TCP segment to indicate to its peer that it has
2793 * reduced its congestion window. This is termed the CWR bit. For
2794 * SCTP the same indication is made by including the CWR chunk.
2795 * This chunk contains one data element, i.e. the TSN number that
2796 * was sent in the ECNE chunk. This element represents the lowest
2797 * TSN number in the datagram that was originally marked with the
2800 * Verification Tag: 8.5 Verification Tag [Normal verification]
2802 * (endpoint, asoc, chunk)
2805 * (asoc, reply_msg, msg_up, timers, counters)
2807 * The return value is the disposition of the chunk.
2809 sctp_disposition_t
sctp_sf_do_ecn_cwr(struct net
*net
,
2810 const struct sctp_endpoint
*ep
,
2811 const struct sctp_association
*asoc
,
2812 const sctp_subtype_t type
,
2814 sctp_cmd_seq_t
*commands
)
2817 struct sctp_chunk
*chunk
= arg
;
2820 if (!sctp_vtag_verify(chunk
, asoc
))
2821 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2823 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2824 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2827 cwr
= (sctp_cwrhdr_t
*) chunk
->skb
->data
;
2828 skb_pull(chunk
->skb
, sizeof(sctp_cwrhdr_t
));
2830 lowest_tsn
= ntohl(cwr
->lowest_tsn
);
2832 /* Does this CWR ack the last sent congestion notification? */
2833 if (TSN_lte(asoc
->last_ecne_tsn
, lowest_tsn
)) {
2834 /* Stop sending ECNE. */
2835 sctp_add_cmd_sf(commands
,
2837 SCTP_U32(lowest_tsn
));
2839 return SCTP_DISPOSITION_CONSUME
;
2845 * Section: Appendix A: Explicit Congestion Notification
2849 * RFC 2481 details a specific bit for a receiver to send back in its
2850 * TCP acknowledgements to notify the sender of the Congestion
2851 * Experienced (CE) bit having arrived from the network. For SCTP this
2852 * same indication is made by including the ECNE chunk. This chunk
2853 * contains one data element, i.e. the lowest TSN associated with the IP
2854 * datagram marked with the CE bit.....
2856 * Verification Tag: 8.5 Verification Tag [Normal verification]
2858 * (endpoint, asoc, chunk)
2861 * (asoc, reply_msg, msg_up, timers, counters)
2863 * The return value is the disposition of the chunk.
2865 sctp_disposition_t
sctp_sf_do_ecne(struct net
*net
,
2866 const struct sctp_endpoint
*ep
,
2867 const struct sctp_association
*asoc
,
2868 const sctp_subtype_t type
,
2870 sctp_cmd_seq_t
*commands
)
2872 sctp_ecnehdr_t
*ecne
;
2873 struct sctp_chunk
*chunk
= arg
;
2875 if (!sctp_vtag_verify(chunk
, asoc
))
2876 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2878 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_ecne_chunk_t
)))
2879 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2882 ecne
= (sctp_ecnehdr_t
*) chunk
->skb
->data
;
2883 skb_pull(chunk
->skb
, sizeof(sctp_ecnehdr_t
));
2885 /* If this is a newer ECNE than the last CWR packet we sent out */
2886 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_ECNE
,
2887 SCTP_U32(ntohl(ecne
->lowest_tsn
)));
2889 return SCTP_DISPOSITION_CONSUME
;
2893 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
2895 * The SCTP endpoint MUST always acknowledge the reception of each valid
2898 * The guidelines on delayed acknowledgement algorithm specified in
2899 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
2900 * acknowledgement SHOULD be generated for at least every second packet
2901 * (not every second DATA chunk) received, and SHOULD be generated within
2902 * 200 ms of the arrival of any unacknowledged DATA chunk. In some
2903 * situations it may be beneficial for an SCTP transmitter to be more
2904 * conservative than the algorithms detailed in this document allow.
2905 * However, an SCTP transmitter MUST NOT be more aggressive than the
2906 * following algorithms allow.
2908 * A SCTP receiver MUST NOT generate more than one SACK for every
2909 * incoming packet, other than to update the offered window as the
2910 * receiving application consumes new data.
2912 * Verification Tag: 8.5 Verification Tag [Normal verification]
2915 * (endpoint, asoc, chunk)
2918 * (asoc, reply_msg, msg_up, timers, counters)
2920 * The return value is the disposition of the chunk.
2922 sctp_disposition_t
sctp_sf_eat_data_6_2(struct net
*net
,
2923 const struct sctp_endpoint
*ep
,
2924 const struct sctp_association
*asoc
,
2925 const sctp_subtype_t type
,
2927 sctp_cmd_seq_t
*commands
)
2929 struct sctp_chunk
*chunk
= arg
;
2930 sctp_arg_t force
= SCTP_NOFORCE();
2933 if (!sctp_vtag_verify(chunk
, asoc
)) {
2934 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
2936 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
2939 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
2940 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
2943 error
= sctp_eat_data(asoc
, chunk
, commands
);
2945 case SCTP_IERROR_NO_ERROR
:
2947 case SCTP_IERROR_HIGH_TSN
:
2948 case SCTP_IERROR_BAD_STREAM
:
2949 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2950 goto discard_noforce
;
2951 case SCTP_IERROR_DUP_TSN
:
2952 case SCTP_IERROR_IGNORE_TSN
:
2953 SCTP_INC_STATS(net
, SCTP_MIB_IN_DATA_CHUNK_DISCARDS
);
2955 case SCTP_IERROR_NO_DATA
:
2957 case SCTP_IERROR_PROTO_VIOLATION
:
2958 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
2959 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
2964 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_SACK_IMM
)
2965 force
= SCTP_FORCE();
2967 if (asoc
->autoclose
) {
2968 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
2969 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
2972 /* If this is the last chunk in a packet, we need to count it
2973 * toward sack generation. Note that we need to SACK every
2974 * OTHER packet containing data chunks, EVEN IF WE DISCARD
2975 * THEM. We elect to NOT generate SACK's if the chunk fails
2976 * the verification tag test.
2978 * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
2980 * The SCTP endpoint MUST always acknowledge the reception of
2981 * each valid DATA chunk.
2983 * The guidelines on delayed acknowledgement algorithm
2984 * specified in Section 4.2 of [RFC2581] SHOULD be followed.
2985 * Specifically, an acknowledgement SHOULD be generated for at
2986 * least every second packet (not every second DATA chunk)
2987 * received, and SHOULD be generated within 200 ms of the
2988 * arrival of any unacknowledged DATA chunk. In some
2989 * situations it may be beneficial for an SCTP transmitter to
2990 * be more conservative than the algorithms detailed in this
2991 * document allow. However, an SCTP transmitter MUST NOT be
2992 * more aggressive than the following algorithms allow.
2994 if (chunk
->end_of_packet
)
2995 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
2997 return SCTP_DISPOSITION_CONSUME
;
3000 /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
3002 * When a packet arrives with duplicate DATA chunk(s) and with
3003 * no new DATA chunk(s), the endpoint MUST immediately send a
3004 * SACK with no delay. If a packet arrives with duplicate
3005 * DATA chunk(s) bundled with new DATA chunks, the endpoint
3006 * MAY immediately send a SACK. Normally receipt of duplicate
3007 * DATA chunks will occur when the original SACK chunk was lost
3008 * and the peer's RTO has expired. The duplicate TSN number(s)
3009 * SHOULD be reported in the SACK as duplicate.
3011 /* In our case, we split the MAY SACK advice up whether or not
3012 * the last chunk is a duplicate.'
3014 if (chunk
->end_of_packet
)
3015 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3016 return SCTP_DISPOSITION_DISCARD
;
3019 if (chunk
->end_of_packet
)
3020 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, force
);
3022 return SCTP_DISPOSITION_DISCARD
;
3024 return SCTP_DISPOSITION_CONSUME
;
3029 * sctp_sf_eat_data_fast_4_4
3032 * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
3033 * DATA chunks without delay.
3035 * Verification Tag: 8.5 Verification Tag [Normal verification]
3037 * (endpoint, asoc, chunk)
3040 * (asoc, reply_msg, msg_up, timers, counters)
3042 * The return value is the disposition of the chunk.
3044 sctp_disposition_t
sctp_sf_eat_data_fast_4_4(struct net
*net
,
3045 const struct sctp_endpoint
*ep
,
3046 const struct sctp_association
*asoc
,
3047 const sctp_subtype_t type
,
3049 sctp_cmd_seq_t
*commands
)
3051 struct sctp_chunk
*chunk
= arg
;
3054 if (!sctp_vtag_verify(chunk
, asoc
)) {
3055 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3057 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3060 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_data_chunk_t
)))
3061 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3064 error
= sctp_eat_data(asoc
, chunk
, commands
);
3066 case SCTP_IERROR_NO_ERROR
:
3067 case SCTP_IERROR_HIGH_TSN
:
3068 case SCTP_IERROR_DUP_TSN
:
3069 case SCTP_IERROR_IGNORE_TSN
:
3070 case SCTP_IERROR_BAD_STREAM
:
3072 case SCTP_IERROR_NO_DATA
:
3074 case SCTP_IERROR_PROTO_VIOLATION
:
3075 return sctp_sf_abort_violation(net
, ep
, asoc
, chunk
, commands
,
3076 (u8
*)chunk
->subh
.data_hdr
, sizeof(sctp_datahdr_t
));
3081 /* Go a head and force a SACK, since we are shutting down. */
3083 /* Implementor's Guide.
3085 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3086 * respond to each received packet containing one or more DATA chunk(s)
3087 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3089 if (chunk
->end_of_packet
) {
3090 /* We must delay the chunk creation since the cumulative
3091 * TSN has not been updated yet.
3093 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3094 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3095 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3096 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3100 return SCTP_DISPOSITION_CONSUME
;
3104 * Section: 6.2 Processing a Received SACK
3105 * D) Any time a SACK arrives, the endpoint performs the following:
3107 * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
3108 * then drop the SACK. Since Cumulative TSN Ack is monotonically
3109 * increasing, a SACK whose Cumulative TSN Ack is less than the
3110 * Cumulative TSN Ack Point indicates an out-of-order SACK.
3112 * ii) Set rwnd equal to the newly received a_rwnd minus the number
3113 * of bytes still outstanding after processing the Cumulative TSN Ack
3114 * and the Gap Ack Blocks.
3116 * iii) If the SACK is missing a TSN that was previously
3117 * acknowledged via a Gap Ack Block (e.g., the data receiver
3118 * reneged on the data), then mark the corresponding DATA chunk
3119 * as available for retransmit: Mark it as missing for fast
3120 * retransmit as described in Section 7.2.4 and if no retransmit
3121 * timer is running for the destination address to which the DATA
3122 * chunk was originally transmitted, then T3-rtx is started for
3123 * that destination address.
3125 * Verification Tag: 8.5 Verification Tag [Normal verification]
3128 * (endpoint, asoc, chunk)
3131 * (asoc, reply_msg, msg_up, timers, counters)
3133 * The return value is the disposition of the chunk.
3135 sctp_disposition_t
sctp_sf_eat_sack_6_2(struct net
*net
,
3136 const struct sctp_endpoint
*ep
,
3137 const struct sctp_association
*asoc
,
3138 const sctp_subtype_t type
,
3140 sctp_cmd_seq_t
*commands
)
3142 struct sctp_chunk
*chunk
= arg
;
3143 sctp_sackhdr_t
*sackh
;
3146 if (!sctp_vtag_verify(chunk
, asoc
))
3147 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3149 /* Make sure that the SACK chunk has a valid length. */
3150 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_sack_chunk_t
)))
3151 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3154 /* Pull the SACK chunk from the data buffer */
3155 sackh
= sctp_sm_pull_sack(chunk
);
3156 /* Was this a bogus SACK? */
3158 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3159 chunk
->subh
.sack_hdr
= sackh
;
3160 ctsn
= ntohl(sackh
->cum_tsn_ack
);
3162 /* i) If Cumulative TSN Ack is less than the Cumulative TSN
3163 * Ack Point, then drop the SACK. Since Cumulative TSN
3164 * Ack is monotonically increasing, a SACK whose
3165 * Cumulative TSN Ack is less than the Cumulative TSN Ack
3166 * Point indicates an out-of-order SACK.
3168 if (TSN_lt(ctsn
, asoc
->ctsn_ack_point
)) {
3169 SCTP_DEBUG_PRINTK("ctsn %x\n", ctsn
);
3170 SCTP_DEBUG_PRINTK("ctsn_ack_point %x\n", asoc
->ctsn_ack_point
);
3171 return SCTP_DISPOSITION_DISCARD
;
3174 /* If Cumulative TSN Ack beyond the max tsn currently
3175 * send, terminating the association and respond to the
3176 * sender with an ABORT.
3178 if (!TSN_lt(ctsn
, asoc
->next_tsn
))
3179 return sctp_sf_violation_ctsn(net
, ep
, asoc
, type
, arg
, commands
);
3181 /* Return this SACK for further processing. */
3182 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_SACK
, SCTP_SACKH(sackh
));
3184 /* Note: We do the rest of the work on the PROCESS_SACK
3187 return SCTP_DISPOSITION_CONSUME
;
3191 * Generate an ABORT in response to a packet.
3193 * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
3195 * 8) The receiver should respond to the sender of the OOTB packet with
3196 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3197 * MUST fill in the Verification Tag field of the outbound packet
3198 * with the value found in the Verification Tag field of the OOTB
3199 * packet and set the T-bit in the Chunk Flags to indicate that the
3200 * Verification Tag is reflected. After sending this ABORT, the
3201 * receiver of the OOTB packet shall discard the OOTB packet and take
3202 * no further action.
3206 * The return value is the disposition of the chunk.
3208 static sctp_disposition_t
sctp_sf_tabort_8_4_8(struct net
*net
,
3209 const struct sctp_endpoint
*ep
,
3210 const struct sctp_association
*asoc
,
3211 const sctp_subtype_t type
,
3213 sctp_cmd_seq_t
*commands
)
3215 struct sctp_packet
*packet
= NULL
;
3216 struct sctp_chunk
*chunk
= arg
;
3217 struct sctp_chunk
*abort
;
3219 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3222 /* Make an ABORT. The T bit will be set if the asoc
3225 abort
= sctp_make_abort(asoc
, chunk
, 0);
3227 sctp_ootb_pkt_free(packet
);
3228 return SCTP_DISPOSITION_NOMEM
;
3231 /* Reflect vtag if T-Bit is set */
3232 if (sctp_test_T_bit(abort
))
3233 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3235 /* Set the skb to the belonging sock for accounting. */
3236 abort
->skb
->sk
= ep
->base
.sk
;
3238 sctp_packet_append_chunk(packet
, abort
);
3240 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3241 SCTP_PACKET(packet
));
3243 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3245 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3246 return SCTP_DISPOSITION_CONSUME
;
3249 return SCTP_DISPOSITION_NOMEM
;
3253 * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
3254 * event as ULP notification for each cause included in the chunk.
3256 * API 5.3.1.3 - SCTP_REMOTE_ERROR
3258 * The return value is the disposition of the chunk.
3260 sctp_disposition_t
sctp_sf_operr_notify(struct net
*net
,
3261 const struct sctp_endpoint
*ep
,
3262 const struct sctp_association
*asoc
,
3263 const sctp_subtype_t type
,
3265 sctp_cmd_seq_t
*commands
)
3267 struct sctp_chunk
*chunk
= arg
;
3270 if (!sctp_vtag_verify(chunk
, asoc
))
3271 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3273 /* Make sure that the ERROR chunk has a valid length. */
3274 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_operr_chunk_t
)))
3275 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3277 sctp_walk_errors(err
, chunk
->chunk_hdr
);
3278 if ((void *)err
!= (void *)chunk
->chunk_end
)
3279 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3280 (void *)err
, commands
);
3282 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_OPERR
,
3285 return SCTP_DISPOSITION_CONSUME
;
3289 * Process an inbound SHUTDOWN ACK.
3292 * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3293 * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
3294 * peer, and remove all record of the association.
3296 * The return value is the disposition.
3298 sctp_disposition_t
sctp_sf_do_9_2_final(struct net
*net
,
3299 const struct sctp_endpoint
*ep
,
3300 const struct sctp_association
*asoc
,
3301 const sctp_subtype_t type
,
3303 sctp_cmd_seq_t
*commands
)
3305 struct sctp_chunk
*chunk
= arg
;
3306 struct sctp_chunk
*reply
;
3307 struct sctp_ulpevent
*ev
;
3309 if (!sctp_vtag_verify(chunk
, asoc
))
3310 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3312 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3313 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3314 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3316 /* 10.2 H) SHUTDOWN COMPLETE notification
3318 * When SCTP completes the shutdown procedures (section 9.2) this
3319 * notification is passed to the upper layer.
3321 ev
= sctp_ulpevent_make_assoc_change(asoc
, 0, SCTP_SHUTDOWN_COMP
,
3322 0, 0, 0, NULL
, GFP_ATOMIC
);
3326 /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
3327 reply
= sctp_make_shutdown_complete(asoc
, chunk
);
3331 /* Do all the commands now (after allocation), so that we
3332 * have consistent state if memory allocation failes
3334 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(ev
));
3336 /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
3337 * stop the T2-shutdown timer,
3339 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3340 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3342 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3343 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
3345 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
3346 SCTP_STATE(SCTP_STATE_CLOSED
));
3347 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
3348 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3349 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
3351 /* ...and remove all record of the association. */
3352 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
3353 return SCTP_DISPOSITION_DELETE_TCB
;
3356 sctp_ulpevent_free(ev
);
3358 return SCTP_DISPOSITION_NOMEM
;
3362 * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
3364 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3365 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3366 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3367 * packet must fill in the Verification Tag field of the outbound
3368 * packet with the Verification Tag received in the SHUTDOWN ACK and
3369 * set the T-bit in the Chunk Flags to indicate that the Verification
3372 * 8) The receiver should respond to the sender of the OOTB packet with
3373 * an ABORT. When sending the ABORT, the receiver of the OOTB packet
3374 * MUST fill in the Verification Tag field of the outbound packet
3375 * with the value found in the Verification Tag field of the OOTB
3376 * packet and set the T-bit in the Chunk Flags to indicate that the
3377 * Verification Tag is reflected. After sending this ABORT, the
3378 * receiver of the OOTB packet shall discard the OOTB packet and take
3379 * no further action.
3381 sctp_disposition_t
sctp_sf_ootb(struct net
*net
,
3382 const struct sctp_endpoint
*ep
,
3383 const struct sctp_association
*asoc
,
3384 const sctp_subtype_t type
,
3386 sctp_cmd_seq_t
*commands
)
3388 struct sctp_chunk
*chunk
= arg
;
3389 struct sk_buff
*skb
= chunk
->skb
;
3390 sctp_chunkhdr_t
*ch
;
3393 int ootb_shut_ack
= 0;
3394 int ootb_cookie_ack
= 0;
3396 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3398 ch
= (sctp_chunkhdr_t
*) chunk
->chunk_hdr
;
3400 /* Report violation if the chunk is less then minimal */
3401 if (ntohs(ch
->length
) < sizeof(sctp_chunkhdr_t
))
3402 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3405 /* Now that we know we at least have a chunk header,
3406 * do things that are type appropriate.
3408 if (SCTP_CID_SHUTDOWN_ACK
== ch
->type
)
3411 /* RFC 2960, Section 3.3.7
3412 * Moreover, under any circumstances, an endpoint that
3413 * receives an ABORT MUST NOT respond to that ABORT by
3414 * sending an ABORT of its own.
3416 if (SCTP_CID_ABORT
== ch
->type
)
3417 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3419 /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
3420 * or a COOKIE ACK the SCTP Packet should be silently
3424 if (SCTP_CID_COOKIE_ACK
== ch
->type
)
3425 ootb_cookie_ack
= 1;
3427 if (SCTP_CID_ERROR
== ch
->type
) {
3428 sctp_walk_errors(err
, ch
) {
3429 if (SCTP_ERROR_STALE_COOKIE
== err
->cause
) {
3430 ootb_cookie_ack
= 1;
3436 /* Report violation if chunk len overflows */
3437 ch_end
= ((__u8
*)ch
) + WORD_ROUND(ntohs(ch
->length
));
3438 if (ch_end
> skb_tail_pointer(skb
))
3439 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3442 ch
= (sctp_chunkhdr_t
*) ch_end
;
3443 } while (ch_end
< skb_tail_pointer(skb
));
3446 return sctp_sf_shut_8_4_5(net
, ep
, asoc
, type
, arg
, commands
);
3447 else if (ootb_cookie_ack
)
3448 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3450 return sctp_sf_tabort_8_4_8(net
, ep
, asoc
, type
, arg
, commands
);
3454 * Handle an "Out of the blue" SHUTDOWN ACK.
3456 * Section: 8.4 5, sctpimpguide 2.41.
3458 * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
3459 * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
3460 * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
3461 * packet must fill in the Verification Tag field of the outbound
3462 * packet with the Verification Tag received in the SHUTDOWN ACK and
3463 * set the T-bit in the Chunk Flags to indicate that the Verification
3467 * (endpoint, asoc, type, arg, commands)
3470 * (sctp_disposition_t)
3472 * The return value is the disposition of the chunk.
3474 static sctp_disposition_t
sctp_sf_shut_8_4_5(struct net
*net
,
3475 const struct sctp_endpoint
*ep
,
3476 const struct sctp_association
*asoc
,
3477 const sctp_subtype_t type
,
3479 sctp_cmd_seq_t
*commands
)
3481 struct sctp_packet
*packet
= NULL
;
3482 struct sctp_chunk
*chunk
= arg
;
3483 struct sctp_chunk
*shut
;
3485 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
3488 /* Make an SHUTDOWN_COMPLETE.
3489 * The T bit will be set if the asoc is NULL.
3491 shut
= sctp_make_shutdown_complete(asoc
, chunk
);
3493 sctp_ootb_pkt_free(packet
);
3494 return SCTP_DISPOSITION_NOMEM
;
3497 /* Reflect vtag if T-Bit is set */
3498 if (sctp_test_T_bit(shut
))
3499 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
3501 /* Set the skb to the belonging sock for accounting. */
3502 shut
->skb
->sk
= ep
->base
.sk
;
3504 sctp_packet_append_chunk(packet
, shut
);
3506 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
3507 SCTP_PACKET(packet
));
3509 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
3511 /* If the chunk length is invalid, we don't want to process
3512 * the reset of the packet.
3514 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3515 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3517 /* We need to discard the rest of the packet to prevent
3518 * potential bomming attacks from additional bundled chunks.
3519 * This is documented in SCTP Threats ID.
3521 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3524 return SCTP_DISPOSITION_NOMEM
;
3528 * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
3530 * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
3531 * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
3532 * procedures in section 8.4 SHOULD be followed, in other words it
3533 * should be treated as an Out Of The Blue packet.
3534 * [This means that we do NOT check the Verification Tag on these
3538 sctp_disposition_t
sctp_sf_do_8_5_1_E_sa(struct net
*net
,
3539 const struct sctp_endpoint
*ep
,
3540 const struct sctp_association
*asoc
,
3541 const sctp_subtype_t type
,
3543 sctp_cmd_seq_t
*commands
)
3545 struct sctp_chunk
*chunk
= arg
;
3547 /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
3548 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
3549 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3552 /* Although we do have an association in this case, it corresponds
3553 * to a restarted association. So the packet is treated as an OOTB
3554 * packet and the state function that handles OOTB SHUTDOWN_ACK is
3555 * called with a NULL association.
3557 SCTP_INC_STATS(net
, SCTP_MIB_OUTOFBLUES
);
3559 return sctp_sf_shut_8_4_5(net
, ep
, NULL
, type
, arg
, commands
);
3562 /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
3563 sctp_disposition_t
sctp_sf_do_asconf(struct net
*net
,
3564 const struct sctp_endpoint
*ep
,
3565 const struct sctp_association
*asoc
,
3566 const sctp_subtype_t type
, void *arg
,
3567 sctp_cmd_seq_t
*commands
)
3569 struct sctp_chunk
*chunk
= arg
;
3570 struct sctp_chunk
*asconf_ack
= NULL
;
3571 struct sctp_paramhdr
*err_param
= NULL
;
3572 sctp_addiphdr_t
*hdr
;
3573 union sctp_addr_param
*addr_param
;
3577 if (!sctp_vtag_verify(chunk
, asoc
)) {
3578 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3580 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3583 /* ADD-IP: Section 4.1.1
3584 * This chunk MUST be sent in an authenticated way by using
3585 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3586 * is received unauthenticated it MUST be silently discarded as
3587 * described in [I-D.ietf-tsvwg-sctp-auth].
3589 if (!net
->sctp
.addip_noauth
&& !chunk
->auth
)
3590 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3592 /* Make sure that the ASCONF ADDIP chunk has a valid length. */
3593 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_addip_chunk_t
)))
3594 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3597 hdr
= (sctp_addiphdr_t
*)chunk
->skb
->data
;
3598 serial
= ntohl(hdr
->serial
);
3600 addr_param
= (union sctp_addr_param
*)hdr
->params
;
3601 length
= ntohs(addr_param
->p
.length
);
3602 if (length
< sizeof(sctp_paramhdr_t
))
3603 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3604 (void *)addr_param
, commands
);
3606 /* Verify the ASCONF chunk before processing it. */
3607 if (!sctp_verify_asconf(asoc
,
3608 (sctp_paramhdr_t
*)((void *)addr_param
+ length
),
3609 (void *)chunk
->chunk_end
,
3611 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3612 (void *)err_param
, commands
);
3614 /* ADDIP 5.2 E1) Compare the value of the serial number to the value
3615 * the endpoint stored in a new association variable
3616 * 'Peer-Serial-Number'.
3618 if (serial
== asoc
->peer
.addip_serial
+ 1) {
3619 /* If this is the first instance of ASCONF in the packet,
3620 * we can clean our old ASCONF-ACKs.
3622 if (!chunk
->has_asconf
)
3623 sctp_assoc_clean_asconf_ack_cache(asoc
);
3625 /* ADDIP 5.2 E4) When the Sequence Number matches the next one
3626 * expected, process the ASCONF as described below and after
3627 * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
3628 * the response packet and cache a copy of it (in the event it
3629 * later needs to be retransmitted).
3631 * Essentially, do V1-V5.
3633 asconf_ack
= sctp_process_asconf((struct sctp_association
*)
3636 return SCTP_DISPOSITION_NOMEM
;
3637 } else if (serial
< asoc
->peer
.addip_serial
+ 1) {
3639 * If the value found in the Sequence Number is less than the
3640 * ('Peer- Sequence-Number' + 1), simply skip to the next
3641 * ASCONF, and include in the outbound response packet
3642 * any previously cached ASCONF-ACK response that was
3643 * sent and saved that matches the Sequence Number of the
3644 * ASCONF. Note: It is possible that no cached ASCONF-ACK
3645 * Chunk exists. This will occur when an older ASCONF
3646 * arrives out of order. In such a case, the receiver
3647 * should skip the ASCONF Chunk and not include ASCONF-ACK
3648 * Chunk for that chunk.
3650 asconf_ack
= sctp_assoc_lookup_asconf_ack(asoc
, hdr
->serial
);
3652 return SCTP_DISPOSITION_DISCARD
;
3654 /* Reset the transport so that we select the correct one
3655 * this time around. This is to make sure that we don't
3656 * accidentally use a stale transport that's been removed.
3658 asconf_ack
->transport
= NULL
;
3660 /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
3661 * it must be either a stale packet or from an attacker.
3663 return SCTP_DISPOSITION_DISCARD
;
3666 /* ADDIP 5.2 E6) The destination address of the SCTP packet
3667 * containing the ASCONF-ACK Chunks MUST be the source address of
3668 * the SCTP packet that held the ASCONF Chunks.
3670 * To do this properly, we'll set the destination address of the chunk
3671 * and at the transmit time, will try look up the transport to use.
3672 * Since ASCONFs may be bundled, the correct transport may not be
3673 * created until we process the entire packet, thus this workaround.
3675 asconf_ack
->dest
= chunk
->source
;
3676 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(asconf_ack
));
3677 if (asoc
->new_transport
) {
3678 sctp_sf_heartbeat(ep
, asoc
, type
, asoc
->new_transport
,
3680 ((struct sctp_association
*)asoc
)->new_transport
= NULL
;
3683 return SCTP_DISPOSITION_CONSUME
;
3687 * ADDIP Section 4.3 General rules for address manipulation
3688 * When building TLV parameters for the ASCONF Chunk that will add or
3689 * delete IP addresses the D0 to D13 rules should be applied:
3691 sctp_disposition_t
sctp_sf_do_asconf_ack(struct net
*net
,
3692 const struct sctp_endpoint
*ep
,
3693 const struct sctp_association
*asoc
,
3694 const sctp_subtype_t type
, void *arg
,
3695 sctp_cmd_seq_t
*commands
)
3697 struct sctp_chunk
*asconf_ack
= arg
;
3698 struct sctp_chunk
*last_asconf
= asoc
->addip_last_asconf
;
3699 struct sctp_chunk
*abort
;
3700 struct sctp_paramhdr
*err_param
= NULL
;
3701 sctp_addiphdr_t
*addip_hdr
;
3702 __u32 sent_serial
, rcvd_serial
;
3704 if (!sctp_vtag_verify(asconf_ack
, asoc
)) {
3705 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3707 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3710 /* ADD-IP, Section 4.1.2:
3711 * This chunk MUST be sent in an authenticated way by using
3712 * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
3713 * is received unauthenticated it MUST be silently discarded as
3714 * described in [I-D.ietf-tsvwg-sctp-auth].
3716 if (!net
->sctp
.addip_noauth
&& !asconf_ack
->auth
)
3717 return sctp_sf_discard_chunk(net
, ep
, asoc
, type
, arg
, commands
);
3719 /* Make sure that the ADDIP chunk has a valid length. */
3720 if (!sctp_chunk_length_valid(asconf_ack
, sizeof(sctp_addip_chunk_t
)))
3721 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3724 addip_hdr
= (sctp_addiphdr_t
*)asconf_ack
->skb
->data
;
3725 rcvd_serial
= ntohl(addip_hdr
->serial
);
3727 /* Verify the ASCONF-ACK chunk before processing it. */
3728 if (!sctp_verify_asconf(asoc
,
3729 (sctp_paramhdr_t
*)addip_hdr
->params
,
3730 (void *)asconf_ack
->chunk_end
,
3732 return sctp_sf_violation_paramlen(net
, ep
, asoc
, type
, arg
,
3733 (void *)err_param
, commands
);
3736 addip_hdr
= (sctp_addiphdr_t
*)last_asconf
->subh
.addip_hdr
;
3737 sent_serial
= ntohl(addip_hdr
->serial
);
3739 sent_serial
= asoc
->addip_serial
- 1;
3742 /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
3743 * equal to the next serial number to be used but no ASCONF chunk is
3744 * outstanding the endpoint MUST ABORT the association. Note that a
3745 * sequence number is greater than if it is no more than 2^^31-1
3746 * larger than the current sequence number (using serial arithmetic).
3748 if (ADDIP_SERIAL_gte(rcvd_serial
, sent_serial
+ 1) &&
3749 !(asoc
->addip_last_asconf
)) {
3750 abort
= sctp_make_abort(asoc
, asconf_ack
,
3751 sizeof(sctp_errhdr_t
));
3753 sctp_init_cause(abort
, SCTP_ERROR_ASCONF_ACK
, 0);
3754 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3757 /* We are going to ABORT, so we might as well stop
3758 * processing the rest of the chunks in the packet.
3760 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3761 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3762 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3763 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3764 SCTP_ERROR(ECONNABORTED
));
3765 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3766 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3767 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3768 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3769 return SCTP_DISPOSITION_ABORT
;
3772 if ((rcvd_serial
== sent_serial
) && asoc
->addip_last_asconf
) {
3773 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
3774 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
3776 if (!sctp_process_asconf_ack((struct sctp_association
*)asoc
,
3778 /* Successfully processed ASCONF_ACK. We can
3779 * release the next asconf if we have one.
3781 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_NEXT_ASCONF
,
3783 return SCTP_DISPOSITION_CONSUME
;
3786 abort
= sctp_make_abort(asoc
, asconf_ack
,
3787 sizeof(sctp_errhdr_t
));
3789 sctp_init_cause(abort
, SCTP_ERROR_RSRC_LOW
, 0);
3790 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
3793 /* We are going to ABORT, so we might as well stop
3794 * processing the rest of the chunks in the packet.
3796 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
3797 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
3798 SCTP_ERROR(ECONNABORTED
));
3799 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
3800 SCTP_PERR(SCTP_ERROR_ASCONF_ACK
));
3801 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
3802 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
3803 return SCTP_DISPOSITION_ABORT
;
3806 return SCTP_DISPOSITION_DISCARD
;
3810 * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
3812 * When a FORWARD TSN chunk arrives, the data receiver MUST first update
3813 * its cumulative TSN point to the value carried in the FORWARD TSN
3814 * chunk, and then MUST further advance its cumulative TSN point locally
3816 * After the above processing, the data receiver MUST stop reporting any
3817 * missing TSNs earlier than or equal to the new cumulative TSN point.
3819 * Verification Tag: 8.5 Verification Tag [Normal verification]
3821 * The return value is the disposition of the chunk.
3823 sctp_disposition_t
sctp_sf_eat_fwd_tsn(struct net
*net
,
3824 const struct sctp_endpoint
*ep
,
3825 const struct sctp_association
*asoc
,
3826 const sctp_subtype_t type
,
3828 sctp_cmd_seq_t
*commands
)
3830 struct sctp_chunk
*chunk
= arg
;
3831 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3832 struct sctp_fwdtsn_skip
*skip
;
3836 if (!sctp_vtag_verify(chunk
, asoc
)) {
3837 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3839 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3842 /* Make sure that the FORWARD_TSN chunk has valid length. */
3843 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3844 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3847 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3848 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3849 len
= ntohs(chunk
->chunk_hdr
->length
);
3850 len
-= sizeof(struct sctp_chunkhdr
);
3851 skb_pull(chunk
->skb
, len
);
3853 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3854 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3856 /* The TSN is too high--silently discard the chunk and count on it
3857 * getting retransmitted later.
3859 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3860 goto discard_noforce
;
3862 /* Silently discard the chunk if stream-id is not valid */
3863 sctp_walk_fwdtsn(skip
, chunk
) {
3864 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3865 goto discard_noforce
;
3868 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3869 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3870 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3873 /* Count this as receiving DATA. */
3874 if (asoc
->autoclose
) {
3875 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3876 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
3879 /* FIXME: For now send a SACK, but DATA processing may
3882 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_NOFORCE());
3884 return SCTP_DISPOSITION_CONSUME
;
3887 return SCTP_DISPOSITION_DISCARD
;
3890 sctp_disposition_t
sctp_sf_eat_fwd_tsn_fast(
3892 const struct sctp_endpoint
*ep
,
3893 const struct sctp_association
*asoc
,
3894 const sctp_subtype_t type
,
3896 sctp_cmd_seq_t
*commands
)
3898 struct sctp_chunk
*chunk
= arg
;
3899 struct sctp_fwdtsn_hdr
*fwdtsn_hdr
;
3900 struct sctp_fwdtsn_skip
*skip
;
3904 if (!sctp_vtag_verify(chunk
, asoc
)) {
3905 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
3907 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
3910 /* Make sure that the FORWARD_TSN chunk has a valid length. */
3911 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_fwdtsn_chunk
)))
3912 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
3915 fwdtsn_hdr
= (struct sctp_fwdtsn_hdr
*)chunk
->skb
->data
;
3916 chunk
->subh
.fwdtsn_hdr
= fwdtsn_hdr
;
3917 len
= ntohs(chunk
->chunk_hdr
->length
);
3918 len
-= sizeof(struct sctp_chunkhdr
);
3919 skb_pull(chunk
->skb
, len
);
3921 tsn
= ntohl(fwdtsn_hdr
->new_cum_tsn
);
3922 SCTP_DEBUG_PRINTK("%s: TSN 0x%x.\n", __func__
, tsn
);
3924 /* The TSN is too high--silently discard the chunk and count on it
3925 * getting retransmitted later.
3927 if (sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
) < 0)
3930 /* Silently discard the chunk if stream-id is not valid */
3931 sctp_walk_fwdtsn(skip
, chunk
) {
3932 if (ntohs(skip
->stream
) >= asoc
->c
.sinit_max_instreams
)
3936 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_FWDTSN
, SCTP_U32(tsn
));
3937 if (len
> sizeof(struct sctp_fwdtsn_hdr
))
3938 sctp_add_cmd_sf(commands
, SCTP_CMD_PROCESS_FWDTSN
,
3941 /* Go a head and force a SACK, since we are shutting down. */
3943 /* Implementor's Guide.
3945 * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
3946 * respond to each received packet containing one or more DATA chunk(s)
3947 * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
3949 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SHUTDOWN
, SCTP_NULL());
3950 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
3951 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
3952 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
3954 return SCTP_DISPOSITION_CONSUME
;
3958 * SCTP-AUTH Section 6.3 Receiving authenticated chukns
3960 * The receiver MUST use the HMAC algorithm indicated in the HMAC
3961 * Identifier field. If this algorithm was not specified by the
3962 * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
3963 * during association setup, the AUTH chunk and all chunks after it MUST
3964 * be discarded and an ERROR chunk SHOULD be sent with the error cause
3965 * defined in Section 4.1.
3967 * If an endpoint with no shared key receives a Shared Key Identifier
3968 * other than 0, it MUST silently discard all authenticated chunks. If
3969 * the endpoint has at least one endpoint pair shared key for the peer,
3970 * it MUST use the key specified by the Shared Key Identifier if a
3971 * key has been configured for that Shared Key Identifier. If no
3972 * endpoint pair shared key has been configured for that Shared Key
3973 * Identifier, all authenticated chunks MUST be silently discarded.
3975 * Verification Tag: 8.5 Verification Tag [Normal verification]
3977 * The return value is the disposition of the chunk.
3979 static sctp_ierror_t
sctp_sf_authenticate(struct net
*net
,
3980 const struct sctp_endpoint
*ep
,
3981 const struct sctp_association
*asoc
,
3982 const sctp_subtype_t type
,
3983 struct sctp_chunk
*chunk
)
3985 struct sctp_authhdr
*auth_hdr
;
3986 struct sctp_hmac
*hmac
;
3987 unsigned int sig_len
;
3992 /* Pull in the auth header, so we can do some more verification */
3993 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
3994 chunk
->subh
.auth_hdr
= auth_hdr
;
3995 skb_pull(chunk
->skb
, sizeof(struct sctp_authhdr
));
3997 /* Make sure that we suport the HMAC algorithm from the auth
4000 if (!sctp_auth_asoc_verify_hmac_id(asoc
, auth_hdr
->hmac_id
))
4001 return SCTP_IERROR_AUTH_BAD_HMAC
;
4003 /* Make sure that the provided shared key identifier has been
4006 key_id
= ntohs(auth_hdr
->shkey_id
);
4007 if (key_id
!= asoc
->active_key_id
&& !sctp_auth_get_shkey(asoc
, key_id
))
4008 return SCTP_IERROR_AUTH_BAD_KEYID
;
4011 /* Make sure that the length of the signature matches what
4014 sig_len
= ntohs(chunk
->chunk_hdr
->length
) - sizeof(sctp_auth_chunk_t
);
4015 hmac
= sctp_auth_get_hmac(ntohs(auth_hdr
->hmac_id
));
4016 if (sig_len
!= hmac
->hmac_len
)
4017 return SCTP_IERROR_PROTO_VIOLATION
;
4019 /* Now that we've done validation checks, we can compute and
4020 * verify the hmac. The steps involved are:
4021 * 1. Save the digest from the chunk.
4022 * 2. Zero out the digest in the chunk.
4023 * 3. Compute the new digest
4024 * 4. Compare saved and new digests.
4026 digest
= auth_hdr
->hmac
;
4027 skb_pull(chunk
->skb
, sig_len
);
4029 save_digest
= kmemdup(digest
, sig_len
, GFP_ATOMIC
);
4033 memset(digest
, 0, sig_len
);
4035 sctp_auth_calculate_hmac(asoc
, chunk
->skb
,
4036 (struct sctp_auth_chunk
*)chunk
->chunk_hdr
,
4039 /* Discard the packet if the digests do not match */
4040 if (memcmp(save_digest
, digest
, sig_len
)) {
4042 return SCTP_IERROR_BAD_SIG
;
4048 return SCTP_IERROR_NO_ERROR
;
4050 return SCTP_IERROR_NOMEM
;
4053 sctp_disposition_t
sctp_sf_eat_auth(struct net
*net
,
4054 const struct sctp_endpoint
*ep
,
4055 const struct sctp_association
*asoc
,
4056 const sctp_subtype_t type
,
4058 sctp_cmd_seq_t
*commands
)
4060 struct sctp_authhdr
*auth_hdr
;
4061 struct sctp_chunk
*chunk
= arg
;
4062 struct sctp_chunk
*err_chunk
;
4063 sctp_ierror_t error
;
4065 /* Make sure that the peer has AUTH capable */
4066 if (!asoc
->peer
.auth_capable
)
4067 return sctp_sf_unk_chunk(net
, ep
, asoc
, type
, arg
, commands
);
4069 if (!sctp_vtag_verify(chunk
, asoc
)) {
4070 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_BAD_TAG
,
4072 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4075 /* Make sure that the AUTH chunk has valid length. */
4076 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_auth_chunk
)))
4077 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4080 auth_hdr
= (struct sctp_authhdr
*)chunk
->skb
->data
;
4081 error
= sctp_sf_authenticate(net
, ep
, asoc
, type
, chunk
);
4083 case SCTP_IERROR_AUTH_BAD_HMAC
:
4084 /* Generate the ERROR chunk and discard the rest
4087 err_chunk
= sctp_make_op_error(asoc
, chunk
,
4088 SCTP_ERROR_UNSUP_HMAC
,
4092 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4093 SCTP_CHUNK(err_chunk
));
4096 case SCTP_IERROR_AUTH_BAD_KEYID
:
4097 case SCTP_IERROR_BAD_SIG
:
4098 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4100 case SCTP_IERROR_PROTO_VIOLATION
:
4101 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4104 case SCTP_IERROR_NOMEM
:
4105 return SCTP_DISPOSITION_NOMEM
;
4107 default: /* Prevent gcc warnings */
4111 if (asoc
->active_key_id
!= ntohs(auth_hdr
->shkey_id
)) {
4112 struct sctp_ulpevent
*ev
;
4114 ev
= sctp_ulpevent_make_authkey(asoc
, ntohs(auth_hdr
->shkey_id
),
4115 SCTP_AUTH_NEWKEY
, GFP_ATOMIC
);
4120 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
,
4124 return SCTP_DISPOSITION_CONSUME
;
4128 * Process an unknown chunk.
4130 * Section: 3.2. Also, 2.1 in the implementor's guide.
4132 * Chunk Types are encoded such that the highest-order two bits specify
4133 * the action that must be taken if the processing endpoint does not
4134 * recognize the Chunk Type.
4136 * 00 - Stop processing this SCTP packet and discard it, do not process
4137 * any further chunks within it.
4139 * 01 - Stop processing this SCTP packet and discard it, do not process
4140 * any further chunks within it, and report the unrecognized
4141 * chunk in an 'Unrecognized Chunk Type'.
4143 * 10 - Skip this chunk and continue processing.
4145 * 11 - Skip this chunk and continue processing, but report in an ERROR
4146 * Chunk using the 'Unrecognized Chunk Type' cause of error.
4148 * The return value is the disposition of the chunk.
4150 sctp_disposition_t
sctp_sf_unk_chunk(struct net
*net
,
4151 const struct sctp_endpoint
*ep
,
4152 const struct sctp_association
*asoc
,
4153 const sctp_subtype_t type
,
4155 sctp_cmd_seq_t
*commands
)
4157 struct sctp_chunk
*unk_chunk
= arg
;
4158 struct sctp_chunk
*err_chunk
;
4159 sctp_chunkhdr_t
*hdr
;
4161 SCTP_DEBUG_PRINTK("Processing the unknown chunk id %d.\n", type
.chunk
);
4163 if (!sctp_vtag_verify(unk_chunk
, asoc
))
4164 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4166 /* Make sure that the chunk has a valid length.
4167 * Since we don't know the chunk type, we use a general
4168 * chunkhdr structure to make a comparison.
4170 if (!sctp_chunk_length_valid(unk_chunk
, sizeof(sctp_chunkhdr_t
)))
4171 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4174 switch (type
.chunk
& SCTP_CID_ACTION_MASK
) {
4175 case SCTP_CID_ACTION_DISCARD
:
4176 /* Discard the packet. */
4177 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4179 case SCTP_CID_ACTION_DISCARD_ERR
:
4180 /* Generate an ERROR chunk as response. */
4181 hdr
= unk_chunk
->chunk_hdr
;
4182 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4183 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4184 WORD_ROUND(ntohs(hdr
->length
)),
4187 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4188 SCTP_CHUNK(err_chunk
));
4191 /* Discard the packet. */
4192 sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
4193 return SCTP_DISPOSITION_CONSUME
;
4195 case SCTP_CID_ACTION_SKIP
:
4196 /* Skip the chunk. */
4197 return SCTP_DISPOSITION_DISCARD
;
4199 case SCTP_CID_ACTION_SKIP_ERR
:
4200 /* Generate an ERROR chunk as response. */
4201 hdr
= unk_chunk
->chunk_hdr
;
4202 err_chunk
= sctp_make_op_error(asoc
, unk_chunk
,
4203 SCTP_ERROR_UNKNOWN_CHUNK
, hdr
,
4204 WORD_ROUND(ntohs(hdr
->length
)),
4207 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
4208 SCTP_CHUNK(err_chunk
));
4210 /* Skip the chunk. */
4211 return SCTP_DISPOSITION_CONSUME
;
4217 return SCTP_DISPOSITION_DISCARD
;
4221 * Discard the chunk.
4223 * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
4224 * [Too numerous to mention...]
4225 * Verification Tag: No verification needed.
4227 * (endpoint, asoc, chunk)
4230 * (asoc, reply_msg, msg_up, timers, counters)
4232 * The return value is the disposition of the chunk.
4234 sctp_disposition_t
sctp_sf_discard_chunk(struct net
*net
,
4235 const struct sctp_endpoint
*ep
,
4236 const struct sctp_association
*asoc
,
4237 const sctp_subtype_t type
,
4239 sctp_cmd_seq_t
*commands
)
4241 struct sctp_chunk
*chunk
= arg
;
4243 /* Make sure that the chunk has a valid length.
4244 * Since we don't know the chunk type, we use a general
4245 * chunkhdr structure to make a comparison.
4247 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4248 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4251 SCTP_DEBUG_PRINTK("Chunk %d is discarded\n", type
.chunk
);
4252 return SCTP_DISPOSITION_DISCARD
;
4256 * Discard the whole packet.
4260 * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
4261 * silently discard the OOTB packet and take no further action.
4263 * Verification Tag: No verification necessary
4266 * (endpoint, asoc, chunk)
4269 * (asoc, reply_msg, msg_up, timers, counters)
4271 * The return value is the disposition of the chunk.
4273 sctp_disposition_t
sctp_sf_pdiscard(struct net
*net
,
4274 const struct sctp_endpoint
*ep
,
4275 const struct sctp_association
*asoc
,
4276 const sctp_subtype_t type
,
4278 sctp_cmd_seq_t
*commands
)
4280 SCTP_INC_STATS(net
, SCTP_MIB_IN_PKT_DISCARDS
);
4281 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
, SCTP_NULL());
4283 return SCTP_DISPOSITION_CONSUME
;
4288 * The other end is violating protocol.
4290 * Section: Not specified
4291 * Verification Tag: Not specified
4293 * (endpoint, asoc, chunk)
4296 * (asoc, reply_msg, msg_up, timers, counters)
4298 * We simply tag the chunk as a violation. The state machine will log
4299 * the violation and continue.
4301 sctp_disposition_t
sctp_sf_violation(struct net
*net
,
4302 const struct sctp_endpoint
*ep
,
4303 const struct sctp_association
*asoc
,
4304 const sctp_subtype_t type
,
4306 sctp_cmd_seq_t
*commands
)
4308 struct sctp_chunk
*chunk
= arg
;
4310 /* Make sure that the chunk has a valid length. */
4311 if (!sctp_chunk_length_valid(chunk
, sizeof(sctp_chunkhdr_t
)))
4312 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
4315 return SCTP_DISPOSITION_VIOLATION
;
4319 * Common function to handle a protocol violation.
4321 static sctp_disposition_t
sctp_sf_abort_violation(
4323 const struct sctp_endpoint
*ep
,
4324 const struct sctp_association
*asoc
,
4326 sctp_cmd_seq_t
*commands
,
4327 const __u8
*payload
,
4328 const size_t paylen
)
4330 struct sctp_packet
*packet
= NULL
;
4331 struct sctp_chunk
*chunk
= arg
;
4332 struct sctp_chunk
*abort
= NULL
;
4334 /* SCTP-AUTH, Section 6.3:
4335 * It should be noted that if the receiver wants to tear
4336 * down an association in an authenticated way only, the
4337 * handling of malformed packets should not result in
4338 * tearing down the association.
4340 * This means that if we only want to abort associations
4341 * in an authenticated way (i.e AUTH+ABORT), then we
4342 * can't destroy this association just because the packet
4345 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4348 /* Make the abort chunk. */
4349 abort
= sctp_make_abort_violation(asoc
, chunk
, payload
, paylen
);
4354 /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
4355 if (chunk
->chunk_hdr
->type
== SCTP_CID_INIT_ACK
&&
4356 !asoc
->peer
.i
.init_tag
) {
4357 sctp_initack_chunk_t
*initack
;
4359 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
4360 if (!sctp_chunk_length_valid(chunk
,
4361 sizeof(sctp_initack_chunk_t
)))
4362 abort
->chunk_hdr
->flags
|= SCTP_CHUNK_FLAG_T
;
4364 unsigned int inittag
;
4366 inittag
= ntohl(initack
->init_hdr
.init_tag
);
4367 sctp_add_cmd_sf(commands
, SCTP_CMD_UPDATE_INITTAG
,
4372 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4373 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4375 if (asoc
->state
<= SCTP_STATE_COOKIE_ECHOED
) {
4376 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4377 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4378 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4379 SCTP_ERROR(ECONNREFUSED
));
4380 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4381 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4383 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4384 SCTP_ERROR(ECONNABORTED
));
4385 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4386 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4387 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4390 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
4395 if (sctp_test_T_bit(abort
))
4396 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
4398 abort
->skb
->sk
= ep
->base
.sk
;
4400 sctp_packet_append_chunk(packet
, abort
);
4402 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
4403 SCTP_PACKET(packet
));
4405 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4408 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4411 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4412 return SCTP_DISPOSITION_ABORT
;
4415 sctp_chunk_free(abort
);
4417 return SCTP_DISPOSITION_NOMEM
;
4421 * Handle a protocol violation when the chunk length is invalid.
4422 * "Invalid" length is identified as smaller than the minimal length a
4423 * given chunk can be. For example, a SACK chunk has invalid length
4424 * if its length is set to be smaller than the size of sctp_sack_chunk_t.
4426 * We inform the other end by sending an ABORT with a Protocol Violation
4429 * Section: Not specified
4430 * Verification Tag: Nothing to do
4432 * (endpoint, asoc, chunk)
4435 * (reply_msg, msg_up, counters)
4437 * Generate an ABORT chunk and terminate the association.
4439 static sctp_disposition_t
sctp_sf_violation_chunklen(
4441 const struct sctp_endpoint
*ep
,
4442 const struct sctp_association
*asoc
,
4443 const sctp_subtype_t type
,
4445 sctp_cmd_seq_t
*commands
)
4447 static const char err_str
[]="The following chunk had invalid length:";
4449 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4454 * Handle a protocol violation when the parameter length is invalid.
4455 * If the length is smaller than the minimum length of a given parameter,
4456 * or accumulated length in multi parameters exceeds the end of the chunk,
4457 * the length is considered as invalid.
4459 static sctp_disposition_t
sctp_sf_violation_paramlen(
4461 const struct sctp_endpoint
*ep
,
4462 const struct sctp_association
*asoc
,
4463 const sctp_subtype_t type
,
4464 void *arg
, void *ext
,
4465 sctp_cmd_seq_t
*commands
)
4467 struct sctp_chunk
*chunk
= arg
;
4468 struct sctp_paramhdr
*param
= ext
;
4469 struct sctp_chunk
*abort
= NULL
;
4471 if (sctp_auth_recv_cid(SCTP_CID_ABORT
, asoc
))
4474 /* Make the abort chunk. */
4475 abort
= sctp_make_violation_paramlen(asoc
, chunk
, param
);
4479 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4480 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
4482 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4483 SCTP_ERROR(ECONNABORTED
));
4484 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4485 SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION
));
4486 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4487 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4490 sctp_sf_pdiscard(net
, ep
, asoc
, SCTP_ST_CHUNK(0), arg
, commands
);
4491 return SCTP_DISPOSITION_ABORT
;
4493 return SCTP_DISPOSITION_NOMEM
;
4496 /* Handle a protocol violation when the peer trying to advance the
4497 * cumulative tsn ack to a point beyond the max tsn currently sent.
4499 * We inform the other end by sending an ABORT with a Protocol Violation
4502 static sctp_disposition_t
sctp_sf_violation_ctsn(
4504 const struct sctp_endpoint
*ep
,
4505 const struct sctp_association
*asoc
,
4506 const sctp_subtype_t type
,
4508 sctp_cmd_seq_t
*commands
)
4510 static const char err_str
[]="The cumulative tsn ack beyond the max tsn currently sent:";
4512 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4516 /* Handle protocol violation of an invalid chunk bundling. For example,
4517 * when we have an association and we receive bundled INIT-ACK, or
4518 * SHUDOWN-COMPLETE, our peer is clearly violationg the "MUST NOT bundle"
4519 * statement from the specs. Additionally, there might be an attacker
4520 * on the path and we may not want to continue this communication.
4522 static sctp_disposition_t
sctp_sf_violation_chunk(
4524 const struct sctp_endpoint
*ep
,
4525 const struct sctp_association
*asoc
,
4526 const sctp_subtype_t type
,
4528 sctp_cmd_seq_t
*commands
)
4530 static const char err_str
[]="The following chunk violates protocol:";
4533 return sctp_sf_violation(net
, ep
, asoc
, type
, arg
, commands
);
4535 return sctp_sf_abort_violation(net
, ep
, asoc
, arg
, commands
, err_str
,
4538 /***************************************************************************
4539 * These are the state functions for handling primitive (Section 10) events.
4540 ***************************************************************************/
4542 * sctp_sf_do_prm_asoc
4544 * Section: 10.1 ULP-to-SCTP
4547 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
4548 * outbound stream count)
4549 * -> association id [,destination transport addr list] [,outbound stream
4552 * This primitive allows the upper layer to initiate an association to a
4553 * specific peer endpoint.
4555 * The peer endpoint shall be specified by one of the transport addresses
4556 * which defines the endpoint (see Section 1.4). If the local SCTP
4557 * instance has not been initialized, the ASSOCIATE is considered an
4559 * [This is not relevant for the kernel implementation since we do all
4560 * initialization at boot time. It we hadn't initialized we wouldn't
4561 * get anywhere near this code.]
4563 * An association id, which is a local handle to the SCTP association,
4564 * will be returned on successful establishment of the association. If
4565 * SCTP is not able to open an SCTP association with the peer endpoint,
4566 * an error is returned.
4567 * [In the kernel implementation, the struct sctp_association needs to
4568 * be created BEFORE causing this primitive to run.]
4570 * Other association parameters may be returned, including the
4571 * complete destination transport addresses of the peer as well as the
4572 * outbound stream count of the local endpoint. One of the transport
4573 * address from the returned destination addresses will be selected by
4574 * the local endpoint as default primary path for sending SCTP packets
4575 * to this peer. The returned "destination transport addr list" can
4576 * be used by the ULP to change the default primary path or to force
4577 * sending a packet to a specific transport address. [All of this
4578 * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
4581 * Mandatory attributes:
4583 * o local SCTP instance name - obtained from the INITIALIZE operation.
4584 * [This is the argument asoc.]
4585 * o destination transport addr - specified as one of the transport
4586 * addresses of the peer endpoint with which the association is to be
4588 * [This is asoc->peer.active_path.]
4589 * o outbound stream count - the number of outbound streams the ULP
4590 * would like to open towards this peer endpoint.
4591 * [BUG: This is not currently implemented.]
4592 * Optional attributes:
4596 * The return value is a disposition.
4598 sctp_disposition_t
sctp_sf_do_prm_asoc(struct net
*net
,
4599 const struct sctp_endpoint
*ep
,
4600 const struct sctp_association
*asoc
,
4601 const sctp_subtype_t type
,
4603 sctp_cmd_seq_t
*commands
)
4605 struct sctp_chunk
*repl
;
4606 struct sctp_association
* my_asoc
;
4608 /* The comment below says that we enter COOKIE-WAIT AFTER
4609 * sending the INIT, but that doesn't actually work in our
4612 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4613 SCTP_STATE(SCTP_STATE_COOKIE_WAIT
));
4615 /* RFC 2960 5.1 Normal Establishment of an Association
4617 * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
4618 * must provide its Verification Tag (Tag_A) in the Initiate
4619 * Tag field. Tag_A SHOULD be a random number in the range of
4620 * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
4623 repl
= sctp_make_init(asoc
, &asoc
->base
.bind_addr
, GFP_ATOMIC
, 0);
4627 /* Cast away the const modifier, as we want to just
4628 * rerun it through as a sideffect.
4630 my_asoc
= (struct sctp_association
*)asoc
;
4631 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_ASOC
, SCTP_ASOC(my_asoc
));
4633 /* Choose transport for INIT. */
4634 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
4637 /* After sending the INIT, "A" starts the T1-init timer and
4638 * enters the COOKIE-WAIT state.
4640 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
4641 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4642 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
4643 return SCTP_DISPOSITION_CONSUME
;
4646 return SCTP_DISPOSITION_NOMEM
;
4650 * Process the SEND primitive.
4652 * Section: 10.1 ULP-to-SCTP
4655 * Format: SEND(association id, buffer address, byte count [,context]
4656 * [,stream id] [,life time] [,destination transport address]
4657 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
4660 * This is the main method to send user data via SCTP.
4662 * Mandatory attributes:
4664 * o association id - local handle to the SCTP association
4666 * o buffer address - the location where the user message to be
4667 * transmitted is stored;
4669 * o byte count - The size of the user data in number of bytes;
4671 * Optional attributes:
4673 * o context - an optional 32 bit integer that will be carried in the
4674 * sending failure notification to the ULP if the transportation of
4675 * this User Message fails.
4677 * o stream id - to indicate which stream to send the data on. If not
4678 * specified, stream 0 will be used.
4680 * o life time - specifies the life time of the user data. The user data
4681 * will not be sent by SCTP after the life time expires. This
4682 * parameter can be used to avoid efforts to transmit stale
4683 * user messages. SCTP notifies the ULP if the data cannot be
4684 * initiated to transport (i.e. sent to the destination via SCTP's
4685 * send primitive) within the life time variable. However, the
4686 * user data will be transmitted if SCTP has attempted to transmit a
4687 * chunk before the life time expired.
4689 * o destination transport address - specified as one of the destination
4690 * transport addresses of the peer endpoint to which this packet
4691 * should be sent. Whenever possible, SCTP should use this destination
4692 * transport address for sending the packets, instead of the current
4695 * o unorder flag - this flag, if present, indicates that the user
4696 * would like the data delivered in an unordered fashion to the peer
4697 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
4700 * o no-bundle flag - instructs SCTP not to bundle this user data with
4701 * other outbound DATA chunks. SCTP MAY still bundle even when
4702 * this flag is present, when faced with network congestion.
4704 * o payload protocol-id - A 32 bit unsigned integer that is to be
4705 * passed to the peer indicating the type of payload protocol data
4706 * being transmitted. This value is passed as opaque data by SCTP.
4708 * The return value is the disposition.
4710 sctp_disposition_t
sctp_sf_do_prm_send(struct net
*net
,
4711 const struct sctp_endpoint
*ep
,
4712 const struct sctp_association
*asoc
,
4713 const sctp_subtype_t type
,
4715 sctp_cmd_seq_t
*commands
)
4717 struct sctp_datamsg
*msg
= arg
;
4719 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_MSG
, SCTP_DATAMSG(msg
));
4720 return SCTP_DISPOSITION_CONSUME
;
4724 * Process the SHUTDOWN primitive.
4729 * Format: SHUTDOWN(association id)
4732 * Gracefully closes an association. Any locally queued user data
4733 * will be delivered to the peer. The association will be terminated only
4734 * after the peer acknowledges all the SCTP packets sent. A success code
4735 * will be returned on successful termination of the association. If
4736 * attempting to terminate the association results in a failure, an error
4737 * code shall be returned.
4739 * Mandatory attributes:
4741 * o association id - local handle to the SCTP association
4743 * Optional attributes:
4747 * The return value is the disposition.
4749 sctp_disposition_t
sctp_sf_do_9_2_prm_shutdown(
4751 const struct sctp_endpoint
*ep
,
4752 const struct sctp_association
*asoc
,
4753 const sctp_subtype_t type
,
4755 sctp_cmd_seq_t
*commands
)
4759 /* From 9.2 Shutdown of an Association
4760 * Upon receipt of the SHUTDOWN primitive from its upper
4761 * layer, the endpoint enters SHUTDOWN-PENDING state and
4762 * remains there until all outstanding data has been
4763 * acknowledged by its peer. The endpoint accepts no new data
4764 * from its upper layer, but retransmits data to the far end
4765 * if necessary to fill gaps.
4767 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4768 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
4770 disposition
= SCTP_DISPOSITION_CONSUME
;
4771 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4772 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
4779 * Process the ABORT primitive.
4784 * Format: Abort(association id [, cause code])
4787 * Ungracefully closes an association. Any locally queued user data
4788 * will be discarded and an ABORT chunk is sent to the peer. A success code
4789 * will be returned on successful abortion of the association. If
4790 * attempting to abort the association results in a failure, an error
4791 * code shall be returned.
4793 * Mandatory attributes:
4795 * o association id - local handle to the SCTP association
4797 * Optional attributes:
4799 * o cause code - reason of the abort to be passed to the peer
4803 * The return value is the disposition.
4805 sctp_disposition_t
sctp_sf_do_9_1_prm_abort(
4807 const struct sctp_endpoint
*ep
,
4808 const struct sctp_association
*asoc
,
4809 const sctp_subtype_t type
,
4811 sctp_cmd_seq_t
*commands
)
4813 /* From 9.1 Abort of an Association
4814 * Upon receipt of the ABORT primitive from its upper
4815 * layer, the endpoint enters CLOSED state and
4816 * discard all outstanding data has been
4817 * acknowledged by its peer. The endpoint accepts no new data
4818 * from its upper layer, but retransmits data to the far end
4819 * if necessary to fill gaps.
4821 struct sctp_chunk
*abort
= arg
;
4822 sctp_disposition_t retval
;
4824 retval
= SCTP_DISPOSITION_CONSUME
;
4826 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4828 /* Even if we can't send the ABORT due to low memory delete the
4829 * TCB. This is a departure from our typical NOMEM handling.
4832 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4833 SCTP_ERROR(ECONNABORTED
));
4834 /* Delete the established association. */
4835 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
4836 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4838 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4839 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
4844 /* We tried an illegal operation on an association which is closed. */
4845 sctp_disposition_t
sctp_sf_error_closed(struct net
*net
,
4846 const struct sctp_endpoint
*ep
,
4847 const struct sctp_association
*asoc
,
4848 const sctp_subtype_t type
,
4850 sctp_cmd_seq_t
*commands
)
4852 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
, SCTP_ERROR(-EINVAL
));
4853 return SCTP_DISPOSITION_CONSUME
;
4856 /* We tried an illegal operation on an association which is shutting
4859 sctp_disposition_t
sctp_sf_error_shutdown(struct net
*net
,
4860 const struct sctp_endpoint
*ep
,
4861 const struct sctp_association
*asoc
,
4862 const sctp_subtype_t type
,
4864 sctp_cmd_seq_t
*commands
)
4866 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_ERROR
,
4867 SCTP_ERROR(-ESHUTDOWN
));
4868 return SCTP_DISPOSITION_CONSUME
;
4872 * sctp_cookie_wait_prm_shutdown
4874 * Section: 4 Note: 2
4879 * The RFC does not explicitly address this issue, but is the route through the
4880 * state table when someone issues a shutdown while in COOKIE_WAIT state.
4885 sctp_disposition_t
sctp_sf_cookie_wait_prm_shutdown(
4887 const struct sctp_endpoint
*ep
,
4888 const struct sctp_association
*asoc
,
4889 const sctp_subtype_t type
,
4891 sctp_cmd_seq_t
*commands
)
4893 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4894 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4896 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4897 SCTP_STATE(SCTP_STATE_CLOSED
));
4899 SCTP_INC_STATS(net
, SCTP_MIB_SHUTDOWNS
);
4901 sctp_add_cmd_sf(commands
, SCTP_CMD_DELETE_TCB
, SCTP_NULL());
4903 return SCTP_DISPOSITION_DELETE_TCB
;
4907 * sctp_cookie_echoed_prm_shutdown
4909 * Section: 4 Note: 2
4914 * The RFC does not explcitly address this issue, but is the route through the
4915 * state table when someone issues a shutdown while in COOKIE_ECHOED state.
4920 sctp_disposition_t
sctp_sf_cookie_echoed_prm_shutdown(
4922 const struct sctp_endpoint
*ep
,
4923 const struct sctp_association
*asoc
,
4924 const sctp_subtype_t type
,
4925 void *arg
, sctp_cmd_seq_t
*commands
)
4927 /* There is a single T1 timer, so we should be able to use
4928 * common function with the COOKIE-WAIT state.
4930 return sctp_sf_cookie_wait_prm_shutdown(net
, ep
, asoc
, type
, arg
, commands
);
4934 * sctp_sf_cookie_wait_prm_abort
4936 * Section: 4 Note: 2
4941 * The RFC does not explicitly address this issue, but is the route through the
4942 * state table when someone issues an abort while in COOKIE_WAIT state.
4947 sctp_disposition_t
sctp_sf_cookie_wait_prm_abort(
4949 const struct sctp_endpoint
*ep
,
4950 const struct sctp_association
*asoc
,
4951 const sctp_subtype_t type
,
4953 sctp_cmd_seq_t
*commands
)
4955 struct sctp_chunk
*abort
= arg
;
4956 sctp_disposition_t retval
;
4958 /* Stop T1-init timer */
4959 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
4960 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
4961 retval
= SCTP_DISPOSITION_CONSUME
;
4963 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(abort
));
4965 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
4966 SCTP_STATE(SCTP_STATE_CLOSED
));
4968 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
4970 /* Even if we can't send the ABORT due to low memory delete the
4971 * TCB. This is a departure from our typical NOMEM handling.
4974 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
4975 SCTP_ERROR(ECONNREFUSED
));
4976 /* Delete the established association. */
4977 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
4978 SCTP_PERR(SCTP_ERROR_USER_ABORT
));
4984 * sctp_sf_cookie_echoed_prm_abort
4986 * Section: 4 Note: 3
4991 * The RFC does not explcitly address this issue, but is the route through the
4992 * state table when someone issues an abort while in COOKIE_ECHOED state.
4997 sctp_disposition_t
sctp_sf_cookie_echoed_prm_abort(
4999 const struct sctp_endpoint
*ep
,
5000 const struct sctp_association
*asoc
,
5001 const sctp_subtype_t type
,
5003 sctp_cmd_seq_t
*commands
)
5005 /* There is a single T1 timer, so we should be able to use
5006 * common function with the COOKIE-WAIT state.
5008 return sctp_sf_cookie_wait_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5012 * sctp_sf_shutdown_pending_prm_abort
5017 * The RFC does not explicitly address this issue, but is the route through the
5018 * state table when someone issues an abort while in SHUTDOWN-PENDING state.
5023 sctp_disposition_t
sctp_sf_shutdown_pending_prm_abort(
5025 const struct sctp_endpoint
*ep
,
5026 const struct sctp_association
*asoc
,
5027 const sctp_subtype_t type
,
5029 sctp_cmd_seq_t
*commands
)
5031 /* Stop the T5-shutdown guard timer. */
5032 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5033 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5035 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5039 * sctp_sf_shutdown_sent_prm_abort
5044 * The RFC does not explicitly address this issue, but is the route through the
5045 * state table when someone issues an abort while in SHUTDOWN-SENT state.
5050 sctp_disposition_t
sctp_sf_shutdown_sent_prm_abort(
5052 const struct sctp_endpoint
*ep
,
5053 const struct sctp_association
*asoc
,
5054 const sctp_subtype_t type
,
5056 sctp_cmd_seq_t
*commands
)
5058 /* Stop the T2-shutdown timer. */
5059 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5060 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5062 /* Stop the T5-shutdown guard timer. */
5063 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5064 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5066 return sctp_sf_do_9_1_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5070 * sctp_sf_cookie_echoed_prm_abort
5075 * The RFC does not explcitly address this issue, but is the route through the
5076 * state table when someone issues an abort while in COOKIE_ECHOED state.
5081 sctp_disposition_t
sctp_sf_shutdown_ack_sent_prm_abort(
5083 const struct sctp_endpoint
*ep
,
5084 const struct sctp_association
*asoc
,
5085 const sctp_subtype_t type
,
5087 sctp_cmd_seq_t
*commands
)
5089 /* The same T2 timer, so we should be able to use
5090 * common function with the SHUTDOWN-SENT state.
5092 return sctp_sf_shutdown_sent_prm_abort(net
, ep
, asoc
, type
, arg
, commands
);
5096 * Process the REQUESTHEARTBEAT primitive
5099 * J) Request Heartbeat
5101 * Format: REQUESTHEARTBEAT(association id, destination transport address)
5105 * Instructs the local endpoint to perform a HeartBeat on the specified
5106 * destination transport address of the given association. The returned
5107 * result should indicate whether the transmission of the HEARTBEAT
5108 * chunk to the destination address is successful.
5110 * Mandatory attributes:
5112 * o association id - local handle to the SCTP association
5114 * o destination transport address - the transport address of the
5115 * association on which a heartbeat should be issued.
5117 sctp_disposition_t
sctp_sf_do_prm_requestheartbeat(
5119 const struct sctp_endpoint
*ep
,
5120 const struct sctp_association
*asoc
,
5121 const sctp_subtype_t type
,
5123 sctp_cmd_seq_t
*commands
)
5125 if (SCTP_DISPOSITION_NOMEM
== sctp_sf_heartbeat(ep
, asoc
, type
,
5126 (struct sctp_transport
*)arg
, commands
))
5127 return SCTP_DISPOSITION_NOMEM
;
5130 * RFC 2960 (bis), section 8.3
5132 * D) Request an on-demand HEARTBEAT on a specific destination
5133 * transport address of a given association.
5135 * The endpoint should increment the respective error counter of
5136 * the destination transport address each time a HEARTBEAT is sent
5137 * to that address and not acknowledged within one RTO.
5140 sctp_add_cmd_sf(commands
, SCTP_CMD_TRANSPORT_HB_SENT
,
5141 SCTP_TRANSPORT(arg
));
5142 return SCTP_DISPOSITION_CONSUME
;
5146 * ADDIP Section 4.1 ASCONF Chunk Procedures
5147 * When an endpoint has an ASCONF signaled change to be sent to the
5148 * remote endpoint it should do A1 to A9
5150 sctp_disposition_t
sctp_sf_do_prm_asconf(struct net
*net
,
5151 const struct sctp_endpoint
*ep
,
5152 const struct sctp_association
*asoc
,
5153 const sctp_subtype_t type
,
5155 sctp_cmd_seq_t
*commands
)
5157 struct sctp_chunk
*chunk
= arg
;
5159 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5160 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5161 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5162 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(chunk
));
5163 return SCTP_DISPOSITION_CONSUME
;
5167 * Ignore the primitive event
5169 * The return value is the disposition of the primitive.
5171 sctp_disposition_t
sctp_sf_ignore_primitive(
5173 const struct sctp_endpoint
*ep
,
5174 const struct sctp_association
*asoc
,
5175 const sctp_subtype_t type
,
5177 sctp_cmd_seq_t
*commands
)
5179 SCTP_DEBUG_PRINTK("Primitive type %d is ignored.\n", type
.primitive
);
5180 return SCTP_DISPOSITION_DISCARD
;
5183 /***************************************************************************
5184 * These are the state functions for the OTHER events.
5185 ***************************************************************************/
5188 * When the SCTP stack has no more user data to send or retransmit, this
5189 * notification is given to the user. Also, at the time when a user app
5190 * subscribes to this event, if there is no data to be sent or
5191 * retransmit, the stack will immediately send up this notification.
5193 sctp_disposition_t
sctp_sf_do_no_pending_tsn(
5195 const struct sctp_endpoint
*ep
,
5196 const struct sctp_association
*asoc
,
5197 const sctp_subtype_t type
,
5199 sctp_cmd_seq_t
*commands
)
5201 struct sctp_ulpevent
*event
;
5203 event
= sctp_ulpevent_make_sender_dry_event(asoc
, GFP_ATOMIC
);
5205 return SCTP_DISPOSITION_NOMEM
;
5207 sctp_add_cmd_sf(commands
, SCTP_CMD_EVENT_ULP
, SCTP_ULPEVENT(event
));
5209 return SCTP_DISPOSITION_CONSUME
;
5213 * Start the shutdown negotiation.
5216 * Once all its outstanding data has been acknowledged, the endpoint
5217 * shall send a SHUTDOWN chunk to its peer including in the Cumulative
5218 * TSN Ack field the last sequential TSN it has received from the peer.
5219 * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
5220 * state. If the timer expires, the endpoint must re-send the SHUTDOWN
5221 * with the updated last sequential TSN received from its peer.
5223 * The return value is the disposition.
5225 sctp_disposition_t
sctp_sf_do_9_2_start_shutdown(
5227 const struct sctp_endpoint
*ep
,
5228 const struct sctp_association
*asoc
,
5229 const sctp_subtype_t type
,
5231 sctp_cmd_seq_t
*commands
)
5233 struct sctp_chunk
*reply
;
5235 /* Once all its outstanding data has been acknowledged, the
5236 * endpoint shall send a SHUTDOWN chunk to its peer including
5237 * in the Cumulative TSN Ack field the last sequential TSN it
5238 * has received from the peer.
5240 reply
= sctp_make_shutdown(asoc
, NULL
);
5244 /* Set the transport for the SHUTDOWN chunk and the timeout for the
5245 * T2-shutdown timer.
5247 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5249 /* It shall then start the T2-shutdown timer */
5250 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START
,
5251 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5253 /* RFC 4960 Section 9.2
5254 * The sender of the SHUTDOWN MAY also start an overall guard timer
5255 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5257 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5258 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5260 if (asoc
->autoclose
)
5261 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5262 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5264 /* and enter the SHUTDOWN-SENT state. */
5265 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5266 SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT
));
5268 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5270 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5273 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5275 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5277 return SCTP_DISPOSITION_CONSUME
;
5280 return SCTP_DISPOSITION_NOMEM
;
5284 * Generate a SHUTDOWN ACK now that everything is SACK'd.
5288 * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5289 * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
5290 * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
5291 * endpoint must re-send the SHUTDOWN ACK.
5293 * The return value is the disposition.
5295 sctp_disposition_t
sctp_sf_do_9_2_shutdown_ack(
5297 const struct sctp_endpoint
*ep
,
5298 const struct sctp_association
*asoc
,
5299 const sctp_subtype_t type
,
5301 sctp_cmd_seq_t
*commands
)
5303 struct sctp_chunk
*chunk
= (struct sctp_chunk
*) arg
;
5304 struct sctp_chunk
*reply
;
5306 /* There are 2 ways of getting here:
5307 * 1) called in response to a SHUTDOWN chunk
5308 * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
5310 * For the case (2), the arg parameter is set to NULL. We need
5311 * to check that we have a chunk before accessing it's fields.
5314 if (!sctp_vtag_verify(chunk
, asoc
))
5315 return sctp_sf_pdiscard(net
, ep
, asoc
, type
, arg
, commands
);
5317 /* Make sure that the SHUTDOWN chunk has a valid length. */
5318 if (!sctp_chunk_length_valid(chunk
, sizeof(struct sctp_shutdown_chunk_t
)))
5319 return sctp_sf_violation_chunklen(net
, ep
, asoc
, type
, arg
,
5323 /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
5324 * shall send a SHUTDOWN ACK ...
5326 reply
= sctp_make_shutdown_ack(asoc
, chunk
);
5330 /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
5331 * the T2-shutdown timer.
5333 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5335 /* and start/restart a T2-shutdown timer of its own, */
5336 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5337 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5339 if (asoc
->autoclose
)
5340 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5341 SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE
));
5343 /* Enter the SHUTDOWN-ACK-SENT state. */
5344 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5345 SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT
));
5347 /* sctp-implguide 2.10 Issues with Heartbeating and failover
5349 * HEARTBEAT ... is discontinued after sending either SHUTDOWN
5352 sctp_add_cmd_sf(commands
, SCTP_CMD_HB_TIMERS_STOP
, SCTP_NULL());
5354 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5356 return SCTP_DISPOSITION_CONSUME
;
5359 return SCTP_DISPOSITION_NOMEM
;
5363 * Ignore the event defined as other
5365 * The return value is the disposition of the event.
5367 sctp_disposition_t
sctp_sf_ignore_other(struct net
*net
,
5368 const struct sctp_endpoint
*ep
,
5369 const struct sctp_association
*asoc
,
5370 const sctp_subtype_t type
,
5372 sctp_cmd_seq_t
*commands
)
5374 SCTP_DEBUG_PRINTK("The event other type %d is ignored\n", type
.other
);
5375 return SCTP_DISPOSITION_DISCARD
;
5378 /************************************************************
5379 * These are the state functions for handling timeout events.
5380 ************************************************************/
5385 * Section: 6.3.3 Handle T3-rtx Expiration
5387 * Whenever the retransmission timer T3-rtx expires for a destination
5388 * address, do the following:
5391 * The return value is the disposition of the chunk.
5393 sctp_disposition_t
sctp_sf_do_6_3_3_rtx(struct net
*net
,
5394 const struct sctp_endpoint
*ep
,
5395 const struct sctp_association
*asoc
,
5396 const sctp_subtype_t type
,
5398 sctp_cmd_seq_t
*commands
)
5400 struct sctp_transport
*transport
= arg
;
5402 SCTP_INC_STATS(net
, SCTP_MIB_T3_RTX_EXPIREDS
);
5404 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5405 if (asoc
->state
== SCTP_STATE_SHUTDOWN_PENDING
) {
5407 * We are here likely because the receiver had its rwnd
5408 * closed for a while and we have not been able to
5409 * transmit the locally queued data within the maximum
5410 * retransmission attempts limit. Start the T5
5411 * shutdown guard timer to give the receiver one last
5412 * chance and some additional time to recover before
5415 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_START_ONCE
,
5416 SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD
));
5418 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5419 SCTP_ERROR(ETIMEDOUT
));
5420 /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5421 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5422 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5423 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5424 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5425 return SCTP_DISPOSITION_DELETE_TCB
;
5429 /* E1) For the destination address for which the timer
5430 * expires, adjust its ssthresh with rules defined in Section
5431 * 7.2.3 and set the cwnd <- MTU.
5434 /* E2) For the destination address for which the timer
5435 * expires, set RTO <- RTO * 2 ("back off the timer"). The
5436 * maximum value discussed in rule C7 above (RTO.max) may be
5437 * used to provide an upper bound to this doubling operation.
5440 /* E3) Determine how many of the earliest (i.e., lowest TSN)
5441 * outstanding DATA chunks for the address for which the
5442 * T3-rtx has expired will fit into a single packet, subject
5443 * to the MTU constraint for the path corresponding to the
5444 * destination transport address to which the retransmission
5445 * is being sent (this may be different from the address for
5446 * which the timer expires [see Section 6.4]). Call this
5447 * value K. Bundle and retransmit those K DATA chunks in a
5448 * single packet to the destination endpoint.
5450 * Note: Any DATA chunks that were sent to the address for
5451 * which the T3-rtx timer expired but did not fit in one MTU
5452 * (rule E3 above), should be marked for retransmission and
5453 * sent as soon as cwnd allows (normally when a SACK arrives).
5456 /* Do some failure management (Section 8.2). */
5457 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
, SCTP_TRANSPORT(transport
));
5459 /* NB: Rules E4 and F1 are implicit in R1. */
5460 sctp_add_cmd_sf(commands
, SCTP_CMD_RETRAN
, SCTP_TRANSPORT(transport
));
5462 return SCTP_DISPOSITION_CONSUME
;
5466 * Generate delayed SACK on timeout
5468 * Section: 6.2 Acknowledgement on Reception of DATA Chunks
5470 * The guidelines on delayed acknowledgement algorithm specified in
5471 * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
5472 * acknowledgement SHOULD be generated for at least every second packet
5473 * (not every second DATA chunk) received, and SHOULD be generated
5474 * within 200 ms of the arrival of any unacknowledged DATA chunk. In
5475 * some situations it may be beneficial for an SCTP transmitter to be
5476 * more conservative than the algorithms detailed in this document
5477 * allow. However, an SCTP transmitter MUST NOT be more aggressive than
5478 * the following algorithms allow.
5480 sctp_disposition_t
sctp_sf_do_6_2_sack(struct net
*net
,
5481 const struct sctp_endpoint
*ep
,
5482 const struct sctp_association
*asoc
,
5483 const sctp_subtype_t type
,
5485 sctp_cmd_seq_t
*commands
)
5487 SCTP_INC_STATS(net
, SCTP_MIB_DELAY_SACK_EXPIREDS
);
5488 sctp_add_cmd_sf(commands
, SCTP_CMD_GEN_SACK
, SCTP_FORCE());
5489 return SCTP_DISPOSITION_CONSUME
;
5493 * sctp_sf_t1_init_timer_expire
5495 * Section: 4 Note: 2
5500 * RFC 2960 Section 4 Notes
5501 * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
5502 * and re-start the T1-init timer without changing state. This MUST
5503 * be repeated up to 'Max.Init.Retransmits' times. After that, the
5504 * endpoint MUST abort the initialization process and report the
5505 * error to SCTP user.
5511 sctp_disposition_t
sctp_sf_t1_init_timer_expire(struct net
*net
,
5512 const struct sctp_endpoint
*ep
,
5513 const struct sctp_association
*asoc
,
5514 const sctp_subtype_t type
,
5516 sctp_cmd_seq_t
*commands
)
5518 struct sctp_chunk
*repl
= NULL
;
5519 struct sctp_bind_addr
*bp
;
5520 int attempts
= asoc
->init_err_counter
+ 1;
5522 SCTP_DEBUG_PRINTK("Timer T1 expired (INIT).\n");
5523 SCTP_INC_STATS(net
, SCTP_MIB_T1_INIT_EXPIREDS
);
5525 if (attempts
<= asoc
->max_init_attempts
) {
5526 bp
= (struct sctp_bind_addr
*) &asoc
->base
.bind_addr
;
5527 repl
= sctp_make_init(asoc
, bp
, GFP_ATOMIC
, 0);
5529 return SCTP_DISPOSITION_NOMEM
;
5531 /* Choose transport for INIT. */
5532 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5535 /* Issue a sideeffect to do the needed accounting. */
5536 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_RESTART
,
5537 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT
));
5539 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5541 SCTP_DEBUG_PRINTK("Giving up on INIT, attempts: %d"
5542 " max_init_attempts: %d\n",
5543 attempts
, asoc
->max_init_attempts
);
5544 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5545 SCTP_ERROR(ETIMEDOUT
));
5546 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5547 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5548 return SCTP_DISPOSITION_DELETE_TCB
;
5551 return SCTP_DISPOSITION_CONSUME
;
5555 * sctp_sf_t1_cookie_timer_expire
5557 * Section: 4 Note: 2
5562 * RFC 2960 Section 4 Notes
5563 * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
5564 * COOKIE ECHO and re-start the T1-cookie timer without changing
5565 * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
5566 * After that, the endpoint MUST abort the initialization process and
5567 * report the error to SCTP user.
5573 sctp_disposition_t
sctp_sf_t1_cookie_timer_expire(struct net
*net
,
5574 const struct sctp_endpoint
*ep
,
5575 const struct sctp_association
*asoc
,
5576 const sctp_subtype_t type
,
5578 sctp_cmd_seq_t
*commands
)
5580 struct sctp_chunk
*repl
= NULL
;
5581 int attempts
= asoc
->init_err_counter
+ 1;
5583 SCTP_DEBUG_PRINTK("Timer T1 expired (COOKIE-ECHO).\n");
5584 SCTP_INC_STATS(net
, SCTP_MIB_T1_COOKIE_EXPIREDS
);
5586 if (attempts
<= asoc
->max_init_attempts
) {
5587 repl
= sctp_make_cookie_echo(asoc
, NULL
);
5589 return SCTP_DISPOSITION_NOMEM
;
5591 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_CHOOSE_TRANSPORT
,
5593 /* Issue a sideeffect to do the needed accounting. */
5594 sctp_add_cmd_sf(commands
, SCTP_CMD_COOKIEECHO_RESTART
,
5595 SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE
));
5597 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(repl
));
5599 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5600 SCTP_ERROR(ETIMEDOUT
));
5601 sctp_add_cmd_sf(commands
, SCTP_CMD_INIT_FAILED
,
5602 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5603 return SCTP_DISPOSITION_DELETE_TCB
;
5606 return SCTP_DISPOSITION_CONSUME
;
5609 /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
5610 * with the updated last sequential TSN received from its peer.
5612 * An endpoint should limit the number of retransmissions of the
5613 * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
5614 * If this threshold is exceeded the endpoint should destroy the TCB and
5615 * MUST report the peer endpoint unreachable to the upper layer (and
5616 * thus the association enters the CLOSED state). The reception of any
5617 * packet from its peer (i.e. as the peer sends all of its queued DATA
5618 * chunks) should clear the endpoint's retransmission count and restart
5619 * the T2-Shutdown timer, giving its peer ample opportunity to transmit
5620 * all of its queued DATA chunks that have not yet been sent.
5622 sctp_disposition_t
sctp_sf_t2_timer_expire(struct net
*net
,
5623 const struct sctp_endpoint
*ep
,
5624 const struct sctp_association
*asoc
,
5625 const sctp_subtype_t type
,
5627 sctp_cmd_seq_t
*commands
)
5629 struct sctp_chunk
*reply
= NULL
;
5631 SCTP_DEBUG_PRINTK("Timer T2 expired.\n");
5632 SCTP_INC_STATS(net
, SCTP_MIB_T2_SHUTDOWN_EXPIREDS
);
5634 ((struct sctp_association
*)asoc
)->shutdown_retries
++;
5636 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5637 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5638 SCTP_ERROR(ETIMEDOUT
));
5639 /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
5640 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5641 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5642 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5643 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5644 return SCTP_DISPOSITION_DELETE_TCB
;
5647 switch (asoc
->state
) {
5648 case SCTP_STATE_SHUTDOWN_SENT
:
5649 reply
= sctp_make_shutdown(asoc
, NULL
);
5652 case SCTP_STATE_SHUTDOWN_ACK_SENT
:
5653 reply
= sctp_make_shutdown_ack(asoc
, NULL
);
5664 /* Do some failure management (Section 8.2).
5665 * If we remove the transport an SHUTDOWN was last sent to, don't
5666 * do failure management.
5668 if (asoc
->shutdown_last_sent_to
)
5669 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5670 SCTP_TRANSPORT(asoc
->shutdown_last_sent_to
));
5672 /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
5673 * the T2-shutdown timer.
5675 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T2
, SCTP_CHUNK(reply
));
5677 /* Restart the T2-shutdown timer. */
5678 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5679 SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN
));
5680 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5681 return SCTP_DISPOSITION_CONSUME
;
5684 return SCTP_DISPOSITION_NOMEM
;
5688 * ADDIP Section 4.1 ASCONF CHunk Procedures
5689 * If the T4 RTO timer expires the endpoint should do B1 to B5
5691 sctp_disposition_t
sctp_sf_t4_timer_expire(
5693 const struct sctp_endpoint
*ep
,
5694 const struct sctp_association
*asoc
,
5695 const sctp_subtype_t type
,
5697 sctp_cmd_seq_t
*commands
)
5699 struct sctp_chunk
*chunk
= asoc
->addip_last_asconf
;
5700 struct sctp_transport
*transport
= chunk
->transport
;
5702 SCTP_INC_STATS(net
, SCTP_MIB_T4_RTO_EXPIREDS
);
5704 /* ADDIP 4.1 B1) Increment the error counters and perform path failure
5705 * detection on the appropriate destination address as defined in
5706 * RFC2960 [5] section 8.1 and 8.2.
5709 sctp_add_cmd_sf(commands
, SCTP_CMD_STRIKE
,
5710 SCTP_TRANSPORT(transport
));
5712 /* Reconfig T4 timer and transport. */
5713 sctp_add_cmd_sf(commands
, SCTP_CMD_SETUP_T4
, SCTP_CHUNK(chunk
));
5715 /* ADDIP 4.1 B2) Increment the association error counters and perform
5716 * endpoint failure detection on the association as defined in
5717 * RFC2960 [5] section 8.1 and 8.2.
5718 * association error counter is incremented in SCTP_CMD_STRIKE.
5720 if (asoc
->overall_error_count
>= asoc
->max_retrans
) {
5721 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_STOP
,
5722 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5723 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5724 SCTP_ERROR(ETIMEDOUT
));
5725 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5726 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5727 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5728 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5729 return SCTP_DISPOSITION_ABORT
;
5732 /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
5733 * the ASCONF chunk was sent by doubling the RTO timer value.
5734 * This is done in SCTP_CMD_STRIKE.
5737 /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
5738 * choose an alternate destination address (please refer to RFC2960
5739 * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
5740 * chunk, it MUST be the same (including its serial number) as the last
5743 sctp_chunk_hold(asoc
->addip_last_asconf
);
5744 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
5745 SCTP_CHUNK(asoc
->addip_last_asconf
));
5747 /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
5748 * destination is selected, then the RTO used will be that of the new
5749 * destination address.
5751 sctp_add_cmd_sf(commands
, SCTP_CMD_TIMER_RESTART
,
5752 SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO
));
5754 return SCTP_DISPOSITION_CONSUME
;
5757 /* sctpimpguide-05 Section 2.12.2
5758 * The sender of the SHUTDOWN MAY also start an overall guard timer
5759 * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
5760 * At the expiration of this timer the sender SHOULD abort the association
5761 * by sending an ABORT chunk.
5763 sctp_disposition_t
sctp_sf_t5_timer_expire(struct net
*net
,
5764 const struct sctp_endpoint
*ep
,
5765 const struct sctp_association
*asoc
,
5766 const sctp_subtype_t type
,
5768 sctp_cmd_seq_t
*commands
)
5770 struct sctp_chunk
*reply
= NULL
;
5772 SCTP_DEBUG_PRINTK("Timer T5 expired.\n");
5773 SCTP_INC_STATS(net
, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS
);
5775 reply
= sctp_make_abort(asoc
, NULL
, 0);
5779 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
, SCTP_CHUNK(reply
));
5780 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
5781 SCTP_ERROR(ETIMEDOUT
));
5782 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
5783 SCTP_PERR(SCTP_ERROR_NO_ERROR
));
5785 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
5786 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
5788 return SCTP_DISPOSITION_DELETE_TCB
;
5790 return SCTP_DISPOSITION_NOMEM
;
5793 /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
5794 * the association is automatically closed by starting the shutdown process.
5795 * The work that needs to be done is same as when SHUTDOWN is initiated by
5796 * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
5798 sctp_disposition_t
sctp_sf_autoclose_timer_expire(
5800 const struct sctp_endpoint
*ep
,
5801 const struct sctp_association
*asoc
,
5802 const sctp_subtype_t type
,
5804 sctp_cmd_seq_t
*commands
)
5808 SCTP_INC_STATS(net
, SCTP_MIB_AUTOCLOSE_EXPIREDS
);
5810 /* From 9.2 Shutdown of an Association
5811 * Upon receipt of the SHUTDOWN primitive from its upper
5812 * layer, the endpoint enters SHUTDOWN-PENDING state and
5813 * remains there until all outstanding data has been
5814 * acknowledged by its peer. The endpoint accepts no new data
5815 * from its upper layer, but retransmits data to the far end
5816 * if necessary to fill gaps.
5818 sctp_add_cmd_sf(commands
, SCTP_CMD_NEW_STATE
,
5819 SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING
));
5821 disposition
= SCTP_DISPOSITION_CONSUME
;
5822 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
5823 disposition
= sctp_sf_do_9_2_start_shutdown(net
, ep
, asoc
, type
,
5829 /*****************************************************************************
5830 * These are sa state functions which could apply to all types of events.
5831 ****************************************************************************/
5834 * This table entry is not implemented.
5837 * (endpoint, asoc, chunk)
5839 * The return value is the disposition of the chunk.
5841 sctp_disposition_t
sctp_sf_not_impl(struct net
*net
,
5842 const struct sctp_endpoint
*ep
,
5843 const struct sctp_association
*asoc
,
5844 const sctp_subtype_t type
,
5846 sctp_cmd_seq_t
*commands
)
5848 return SCTP_DISPOSITION_NOT_IMPL
;
5852 * This table entry represents a bug.
5855 * (endpoint, asoc, chunk)
5857 * The return value is the disposition of the chunk.
5859 sctp_disposition_t
sctp_sf_bug(struct net
*net
,
5860 const struct sctp_endpoint
*ep
,
5861 const struct sctp_association
*asoc
,
5862 const sctp_subtype_t type
,
5864 sctp_cmd_seq_t
*commands
)
5866 return SCTP_DISPOSITION_BUG
;
5870 * This table entry represents the firing of a timer in the wrong state.
5871 * Since timer deletion cannot be guaranteed a timer 'may' end up firing
5872 * when the association is in the wrong state. This event should
5873 * be ignored, so as to prevent any rearming of the timer.
5876 * (endpoint, asoc, chunk)
5878 * The return value is the disposition of the chunk.
5880 sctp_disposition_t
sctp_sf_timer_ignore(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 SCTP_DEBUG_PRINTK("Timer %d ignored.\n", type
.chunk
);
5888 return SCTP_DISPOSITION_CONSUME
;
5891 /********************************************************************
5892 * 2nd Level Abstractions
5893 ********************************************************************/
5895 /* Pull the SACK chunk based on the SACK header. */
5896 static struct sctp_sackhdr
*sctp_sm_pull_sack(struct sctp_chunk
*chunk
)
5898 struct sctp_sackhdr
*sack
;
5903 /* Protect ourselves from reading too far into
5904 * the skb from a bogus sender.
5906 sack
= (struct sctp_sackhdr
*) chunk
->skb
->data
;
5908 num_blocks
= ntohs(sack
->num_gap_ack_blocks
);
5909 num_dup_tsns
= ntohs(sack
->num_dup_tsns
);
5910 len
= sizeof(struct sctp_sackhdr
);
5911 len
+= (num_blocks
+ num_dup_tsns
) * sizeof(__u32
);
5912 if (len
> chunk
->skb
->len
)
5915 skb_pull(chunk
->skb
, len
);
5920 /* Create an ABORT packet to be sent as a response, with the specified
5923 static struct sctp_packet
*sctp_abort_pkt_new(struct net
*net
,
5924 const struct sctp_endpoint
*ep
,
5925 const struct sctp_association
*asoc
,
5926 struct sctp_chunk
*chunk
,
5927 const void *payload
,
5930 struct sctp_packet
*packet
;
5931 struct sctp_chunk
*abort
;
5933 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
5937 * The T bit will be set if the asoc is NULL.
5939 abort
= sctp_make_abort(asoc
, chunk
, paylen
);
5941 sctp_ootb_pkt_free(packet
);
5945 /* Reflect vtag if T-Bit is set */
5946 if (sctp_test_T_bit(abort
))
5947 packet
->vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
5949 /* Add specified error causes, i.e., payload, to the
5952 sctp_addto_chunk(abort
, paylen
, payload
);
5954 /* Set the skb to the belonging sock for accounting. */
5955 abort
->skb
->sk
= ep
->base
.sk
;
5957 sctp_packet_append_chunk(packet
, abort
);
5964 /* Allocate a packet for responding in the OOTB conditions. */
5965 static struct sctp_packet
*sctp_ootb_pkt_new(struct net
*net
,
5966 const struct sctp_association
*asoc
,
5967 const struct sctp_chunk
*chunk
)
5969 struct sctp_packet
*packet
;
5970 struct sctp_transport
*transport
;
5975 /* Get the source and destination port from the inbound packet. */
5976 sport
= ntohs(chunk
->sctp_hdr
->dest
);
5977 dport
= ntohs(chunk
->sctp_hdr
->source
);
5979 /* The V-tag is going to be the same as the inbound packet if no
5980 * association exists, otherwise, use the peer's vtag.
5983 /* Special case the INIT-ACK as there is no peer's vtag
5986 switch(chunk
->chunk_hdr
->type
) {
5987 case SCTP_CID_INIT_ACK
:
5989 sctp_initack_chunk_t
*initack
;
5991 initack
= (sctp_initack_chunk_t
*)chunk
->chunk_hdr
;
5992 vtag
= ntohl(initack
->init_hdr
.init_tag
);
5996 vtag
= asoc
->peer
.i
.init_tag
;
6000 /* Special case the INIT and stale COOKIE_ECHO as there is no
6003 switch(chunk
->chunk_hdr
->type
) {
6006 sctp_init_chunk_t
*init
;
6008 init
= (sctp_init_chunk_t
*)chunk
->chunk_hdr
;
6009 vtag
= ntohl(init
->init_hdr
.init_tag
);
6013 vtag
= ntohl(chunk
->sctp_hdr
->vtag
);
6018 /* Make a transport for the bucket, Eliza... */
6019 transport
= sctp_transport_new(net
, sctp_source(chunk
), GFP_ATOMIC
);
6023 /* Cache a route for the transport with the chunk's destination as
6024 * the source address.
6026 sctp_transport_route(transport
, (union sctp_addr
*)&chunk
->dest
,
6027 sctp_sk(net
->sctp
.ctl_sock
));
6029 packet
= sctp_packet_init(&transport
->packet
, transport
, sport
, dport
);
6030 packet
= sctp_packet_config(packet
, vtag
, 0);
6038 /* Free the packet allocated earlier for responding in the OOTB condition. */
6039 void sctp_ootb_pkt_free(struct sctp_packet
*packet
)
6041 sctp_transport_free(packet
->transport
);
6044 /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
6045 static void sctp_send_stale_cookie_err(struct net
*net
,
6046 const struct sctp_endpoint
*ep
,
6047 const struct sctp_association
*asoc
,
6048 const struct sctp_chunk
*chunk
,
6049 sctp_cmd_seq_t
*commands
,
6050 struct sctp_chunk
*err_chunk
)
6052 struct sctp_packet
*packet
;
6055 packet
= sctp_ootb_pkt_new(net
, asoc
, chunk
);
6057 struct sctp_signed_cookie
*cookie
;
6059 /* Override the OOTB vtag from the cookie. */
6060 cookie
= chunk
->subh
.cookie_hdr
;
6061 packet
->vtag
= cookie
->c
.peer_vtag
;
6063 /* Set the skb to the belonging sock for accounting. */
6064 err_chunk
->skb
->sk
= ep
->base
.sk
;
6065 sctp_packet_append_chunk(packet
, err_chunk
);
6066 sctp_add_cmd_sf(commands
, SCTP_CMD_SEND_PKT
,
6067 SCTP_PACKET(packet
));
6068 SCTP_INC_STATS(net
, SCTP_MIB_OUTCTRLCHUNKS
);
6070 sctp_chunk_free (err_chunk
);
6075 /* Process a data chunk */
6076 static int sctp_eat_data(const struct sctp_association
*asoc
,
6077 struct sctp_chunk
*chunk
,
6078 sctp_cmd_seq_t
*commands
)
6080 sctp_datahdr_t
*data_hdr
;
6081 struct sctp_chunk
*err
;
6083 sctp_verb_t deliver
;
6086 struct sctp_tsnmap
*map
= (struct sctp_tsnmap
*)&asoc
->peer
.tsn_map
;
6087 struct sock
*sk
= asoc
->base
.sk
;
6088 struct net
*net
= sock_net(sk
);
6093 data_hdr
= chunk
->subh
.data_hdr
= (sctp_datahdr_t
*)chunk
->skb
->data
;
6094 skb_pull(chunk
->skb
, sizeof(sctp_datahdr_t
));
6096 tsn
= ntohl(data_hdr
->tsn
);
6097 SCTP_DEBUG_PRINTK("eat_data: TSN 0x%x.\n", tsn
);
6099 /* ASSERT: Now skb->data is really the user data. */
6101 /* Process ECN based congestion.
6103 * Since the chunk structure is reused for all chunks within
6104 * a packet, we use ecn_ce_done to track if we've already
6105 * done CE processing for this packet.
6107 * We need to do ECN processing even if we plan to discard the
6111 if (!chunk
->ecn_ce_done
) {
6113 chunk
->ecn_ce_done
= 1;
6115 af
= sctp_get_af_specific(
6116 ipver2af(ip_hdr(chunk
->skb
)->version
));
6118 if (af
&& af
->is_ce(chunk
->skb
) && asoc
->peer
.ecn_capable
) {
6119 /* Do real work as sideffect. */
6120 sctp_add_cmd_sf(commands
, SCTP_CMD_ECN_CE
,
6125 tmp
= sctp_tsnmap_check(&asoc
->peer
.tsn_map
, tsn
);
6127 /* The TSN is too high--silently discard the chunk and
6128 * count on it getting retransmitted later.
6130 return SCTP_IERROR_HIGH_TSN
;
6131 } else if (tmp
> 0) {
6132 /* This is a duplicate. Record it. */
6133 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_DUP
, SCTP_U32(tsn
));
6134 return SCTP_IERROR_DUP_TSN
;
6137 /* This is a new TSN. */
6139 /* Discard if there is no room in the receive window.
6140 * Actually, allow a little bit of overflow (up to a MTU).
6142 datalen
= ntohs(chunk
->chunk_hdr
->length
);
6143 datalen
-= sizeof(sctp_data_chunk_t
);
6145 deliver
= SCTP_CMD_CHUNK_ULP
;
6147 /* Think about partial delivery. */
6148 if ((datalen
>= asoc
->rwnd
) && (!asoc
->ulpq
.pd_mode
)) {
6150 /* Even if we don't accept this chunk there is
6153 sctp_add_cmd_sf(commands
, SCTP_CMD_PART_DELIVER
, SCTP_NULL());
6156 /* Spill over rwnd a little bit. Note: While allowed, this spill over
6157 * seems a bit troublesome in that frag_point varies based on
6158 * PMTU. In cases, such as loopback, this might be a rather
6161 if ((!chunk
->data_accepted
) && (!asoc
->rwnd
|| asoc
->rwnd_over
||
6162 (datalen
> asoc
->rwnd
+ asoc
->frag_point
))) {
6164 /* If this is the next TSN, consider reneging to make
6165 * room. Note: Playing nice with a confused sender. A
6166 * malicious sender can still eat up all our buffer
6167 * space and in the future we may want to detect and
6168 * do more drastic reneging.
6170 if (sctp_tsnmap_has_gap(map
) &&
6171 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6172 SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn
);
6173 deliver
= SCTP_CMD_RENEGE
;
6175 SCTP_DEBUG_PRINTK("Discard tsn: %u len: %Zd, "
6176 "rwnd: %d\n", tsn
, datalen
,
6178 return SCTP_IERROR_IGNORE_TSN
;
6183 * Also try to renege to limit our memory usage in the event that
6184 * we are under memory pressure
6185 * If we can't renege, don't worry about it, the sk_rmem_schedule
6186 * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
6187 * memory usage too much
6189 if (*sk
->sk_prot_creator
->memory_pressure
) {
6190 if (sctp_tsnmap_has_gap(map
) &&
6191 (sctp_tsnmap_get_ctsn(map
) + 1) == tsn
) {
6192 SCTP_DEBUG_PRINTK("Under Pressure! Reneging for tsn:%u\n", tsn
);
6193 deliver
= SCTP_CMD_RENEGE
;
6198 * Section 3.3.10.9 No User Data (9)
6202 * No User Data: This error cause is returned to the originator of a
6203 * DATA chunk if a received DATA chunk has no user data.
6205 if (unlikely(0 == datalen
)) {
6206 err
= sctp_make_abort_no_data(asoc
, chunk
, tsn
);
6208 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6211 /* We are going to ABORT, so we might as well stop
6212 * processing the rest of the chunks in the packet.
6214 sctp_add_cmd_sf(commands
, SCTP_CMD_DISCARD_PACKET
,SCTP_NULL());
6215 sctp_add_cmd_sf(commands
, SCTP_CMD_SET_SK_ERR
,
6216 SCTP_ERROR(ECONNABORTED
));
6217 sctp_add_cmd_sf(commands
, SCTP_CMD_ASSOC_FAILED
,
6218 SCTP_PERR(SCTP_ERROR_NO_DATA
));
6219 SCTP_INC_STATS(net
, SCTP_MIB_ABORTEDS
);
6220 SCTP_DEC_STATS(net
, SCTP_MIB_CURRESTAB
);
6221 return SCTP_IERROR_NO_DATA
;
6224 chunk
->data_accepted
= 1;
6226 /* Note: Some chunks may get overcounted (if we drop) or overcounted
6227 * if we renege and the chunk arrives again.
6229 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
)
6230 SCTP_INC_STATS(net
, SCTP_MIB_INUNORDERCHUNKS
);
6232 SCTP_INC_STATS(net
, SCTP_MIB_INORDERCHUNKS
);
6236 /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
6238 * If an endpoint receive a DATA chunk with an invalid stream
6239 * identifier, it shall acknowledge the reception of the DATA chunk
6240 * following the normal procedure, immediately send an ERROR chunk
6241 * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
6242 * and discard the DATA chunk.
6244 sid
= ntohs(data_hdr
->stream
);
6245 if (sid
>= asoc
->c
.sinit_max_instreams
) {
6246 /* Mark tsn as received even though we drop it */
6247 sctp_add_cmd_sf(commands
, SCTP_CMD_REPORT_TSN
, SCTP_U32(tsn
));
6249 err
= sctp_make_op_error(asoc
, chunk
, SCTP_ERROR_INV_STRM
,
6251 sizeof(data_hdr
->stream
),
6254 sctp_add_cmd_sf(commands
, SCTP_CMD_REPLY
,
6256 return SCTP_IERROR_BAD_STREAM
;
6259 /* Check to see if the SSN is possible for this TSN.
6260 * The biggest gap we can record is 4K wide. Since SSNs wrap
6261 * at an unsigned short, there is no way that an SSN can
6262 * wrap and for a valid TSN. We can simply check if the current
6263 * SSN is smaller then the next expected one. If it is, it wrapped
6266 ssn
= ntohs(data_hdr
->ssn
);
6267 if (ordered
&& SSN_lt(ssn
, sctp_ssn_peek(&asoc
->ssnmap
->in
, sid
))) {
6268 return SCTP_IERROR_PROTO_VIOLATION
;
6271 /* Send the data up to the user. Note: Schedule the
6272 * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
6273 * chunk needs the updated rwnd.
6275 sctp_add_cmd_sf(commands
, deliver
, SCTP_CHUNK(chunk
));
6277 return SCTP_IERROR_NO_ERROR
;